Commit 03c751a5e10caafbb6d1afcaf1ea67f2153c3193

Authored by Linus Torvalds

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs

Pull btrfs fixes from Chris Mason:
 "None of these are huge, but my commit does fix a regression from 3.18
  that could cause lost files during log replay.

  This also adds Dave Sterba to the list of Btrfs maintainers.  It
  doesn't mean we're doing things differently, but Dave has really been
  helping with the maintainer workload for years"

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs:
  Btrfs: don't delay inode ref updates during log replay
  Btrfs: correctly get tree level in tree_backref_for_extent
  Btrfs: call inode_dec_link_count() on mkdir error path
  Btrfs: abort transaction if we don't find the block group
  Btrfs, scrub: uninitialized variable in scrub_extent_for_parity()
  Btrfs: add more maintainers

Showing 6 changed files Inline Diff

1 1
2 2
3 List of maintainers and how to submit kernel changes 3 List of maintainers and how to submit kernel changes
4 4
5 Please try to follow the guidelines below. This will make things 5 Please try to follow the guidelines below. This will make things
6 easier on the maintainers. Not all of these guidelines matter for every 6 easier on the maintainers. Not all of these guidelines matter for every
7 trivial patch so apply some common sense. 7 trivial patch so apply some common sense.
8 8
9 1. Always _test_ your changes, however small, on at least 4 or 9 1. Always _test_ your changes, however small, on at least 4 or
10 5 people, preferably many more. 10 5 people, preferably many more.
11 11
12 2. Try to release a few ALPHA test versions to the net. Announce 12 2. Try to release a few ALPHA test versions to the net. Announce
13 them onto the kernel channel and await results. This is especially 13 them onto the kernel channel and await results. This is especially
14 important for device drivers, because often that's the only way 14 important for device drivers, because often that's the only way
15 you will find things like the fact version 3 firmware needs 15 you will find things like the fact version 3 firmware needs
16 a magic fix you didn't know about, or some clown changed the 16 a magic fix you didn't know about, or some clown changed the
17 chips on a board and not its name. (Don't laugh! Look at the 17 chips on a board and not its name. (Don't laugh! Look at the
18 SMC etherpower for that.) 18 SMC etherpower for that.)
19 19
20 3. Make sure your changes compile correctly in multiple 20 3. Make sure your changes compile correctly in multiple
21 configurations. In particular check that changes work both as a 21 configurations. In particular check that changes work both as a
22 module and built into the kernel. 22 module and built into the kernel.
23 23
24 4. When you are happy with a change make it generally available for 24 4. When you are happy with a change make it generally available for
25 testing and await feedback. 25 testing and await feedback.
26 26
27 5. Make a patch available to the relevant maintainer in the list. Use 27 5. Make a patch available to the relevant maintainer in the list. Use
28 'diff -u' to make the patch easy to merge. Be prepared to get your 28 'diff -u' to make the patch easy to merge. Be prepared to get your
29 changes sent back with seemingly silly requests about formatting 29 changes sent back with seemingly silly requests about formatting
30 and variable names. These aren't as silly as they seem. One 30 and variable names. These aren't as silly as they seem. One
31 job the maintainers (and especially Linus) do is to keep things 31 job the maintainers (and especially Linus) do is to keep things
32 looking the same. Sometimes this means that the clever hack in 32 looking the same. Sometimes this means that the clever hack in
33 your driver to get around a problem actually needs to become a 33 your driver to get around a problem actually needs to become a
34 generalized kernel feature ready for next time. 34 generalized kernel feature ready for next time.
35 35
36 PLEASE check your patch with the automated style checker 36 PLEASE check your patch with the automated style checker
37 (scripts/checkpatch.pl) to catch trival style violations. 37 (scripts/checkpatch.pl) to catch trival style violations.
38 See Documentation/CodingStyle for guidance here. 38 See Documentation/CodingStyle for guidance here.
39 39
40 PLEASE CC: the maintainers and mailing lists that are generated 40 PLEASE CC: the maintainers and mailing lists that are generated
41 by scripts/get_maintainer.pl. The results returned by the 41 by scripts/get_maintainer.pl. The results returned by the
42 script will be best if you have git installed and are making 42 script will be best if you have git installed and are making
43 your changes in a branch derived from Linus' latest git tree. 43 your changes in a branch derived from Linus' latest git tree.
44 See Documentation/SubmittingPatches for details. 44 See Documentation/SubmittingPatches for details.
45 45
46 PLEASE try to include any credit lines you want added with the 46 PLEASE try to include any credit lines you want added with the
47 patch. It avoids people being missed off by mistake and makes 47 patch. It avoids people being missed off by mistake and makes
48 it easier to know who wants adding and who doesn't. 48 it easier to know who wants adding and who doesn't.
49 49
50 PLEASE document known bugs. If it doesn't work for everything 50 PLEASE document known bugs. If it doesn't work for everything
51 or does something very odd once a month document it. 51 or does something very odd once a month document it.
52 52
53 PLEASE remember that submissions must be made under the terms 53 PLEASE remember that submissions must be made under the terms
54 of the OSDL certificate of contribution and should include a 54 of the OSDL certificate of contribution and should include a
55 Signed-off-by: line. The current version of this "Developer's 55 Signed-off-by: line. The current version of this "Developer's
56 Certificate of Origin" (DCO) is listed in the file 56 Certificate of Origin" (DCO) is listed in the file
57 Documentation/SubmittingPatches. 57 Documentation/SubmittingPatches.
58 58
59 6. Make sure you have the right to send any changes you make. If you 59 6. Make sure you have the right to send any changes you make. If you
60 do changes at work you may find your employer owns the patch 60 do changes at work you may find your employer owns the patch
61 not you. 61 not you.
62 62
63 7. When sending security related changes or reports to a maintainer 63 7. When sending security related changes or reports to a maintainer
64 please Cc: security@kernel.org, especially if the maintainer 64 please Cc: security@kernel.org, especially if the maintainer
65 does not respond. 65 does not respond.
66 66
67 8. Happy hacking. 67 8. Happy hacking.
68 68
69 Descriptions of section entries: 69 Descriptions of section entries:
70 70
71 P: Person (obsolete) 71 P: Person (obsolete)
72 M: Mail patches to: FullName <address@domain> 72 M: Mail patches to: FullName <address@domain>
73 R: Designated reviewer: FullName <address@domain> 73 R: Designated reviewer: FullName <address@domain>
74 These reviewers should be CCed on patches. 74 These reviewers should be CCed on patches.
75 L: Mailing list that is relevant to this area 75 L: Mailing list that is relevant to this area
76 W: Web-page with status/info 76 W: Web-page with status/info
77 Q: Patchwork web based patch tracking system site 77 Q: Patchwork web based patch tracking system site
78 T: SCM tree type and location. 78 T: SCM tree type and location.
79 Type is one of: git, hg, quilt, stgit, topgit 79 Type is one of: git, hg, quilt, stgit, topgit
80 S: Status, one of the following: 80 S: Status, one of the following:
81 Supported: Someone is actually paid to look after this. 81 Supported: Someone is actually paid to look after this.
82 Maintained: Someone actually looks after it. 82 Maintained: Someone actually looks after it.
83 Odd Fixes: It has a maintainer but they don't have time to do 83 Odd Fixes: It has a maintainer but they don't have time to do
84 much other than throw the odd patch in. See below.. 84 much other than throw the odd patch in. See below..
85 Orphan: No current maintainer [but maybe you could take the 85 Orphan: No current maintainer [but maybe you could take the
86 role as you write your new code]. 86 role as you write your new code].
87 Obsolete: Old code. Something tagged obsolete generally means 87 Obsolete: Old code. Something tagged obsolete generally means
88 it has been replaced by a better system and you 88 it has been replaced by a better system and you
89 should be using that. 89 should be using that.
90 F: Files and directories with wildcard patterns. 90 F: Files and directories with wildcard patterns.
91 A trailing slash includes all files and subdirectory files. 91 A trailing slash includes all files and subdirectory files.
92 F: drivers/net/ all files in and below drivers/net 92 F: drivers/net/ all files in and below drivers/net
93 F: drivers/net/* all files in drivers/net, but not below 93 F: drivers/net/* all files in drivers/net, but not below
94 F: */net/* all files in "any top level directory"/net 94 F: */net/* all files in "any top level directory"/net
95 One pattern per line. Multiple F: lines acceptable. 95 One pattern per line. Multiple F: lines acceptable.
96 N: Files and directories with regex patterns. 96 N: Files and directories with regex patterns.
97 N: [^a-z]tegra all files whose path contains the word tegra 97 N: [^a-z]tegra all files whose path contains the word tegra
98 One pattern per line. Multiple N: lines acceptable. 98 One pattern per line. Multiple N: lines acceptable.
99 scripts/get_maintainer.pl has different behavior for files that 99 scripts/get_maintainer.pl has different behavior for files that
100 match F: pattern and matches of N: patterns. By default, 100 match F: pattern and matches of N: patterns. By default,
101 get_maintainer will not look at git log history when an F: pattern 101 get_maintainer will not look at git log history when an F: pattern
102 match occurs. When an N: match occurs, git log history is used 102 match occurs. When an N: match occurs, git log history is used
103 to also notify the people that have git commit signatures. 103 to also notify the people that have git commit signatures.
104 X: Files and directories that are NOT maintained, same rules as F: 104 X: Files and directories that are NOT maintained, same rules as F:
105 Files exclusions are tested before file matches. 105 Files exclusions are tested before file matches.
106 Can be useful for excluding a specific subdirectory, for instance: 106 Can be useful for excluding a specific subdirectory, for instance:
107 F: net/ 107 F: net/
108 X: net/ipv6/ 108 X: net/ipv6/
109 matches all files in and below net excluding net/ipv6/ 109 matches all files in and below net excluding net/ipv6/
110 K: Keyword perl extended regex pattern to match content in a 110 K: Keyword perl extended regex pattern to match content in a
111 patch or file. For instance: 111 patch or file. For instance:
112 K: of_get_profile 112 K: of_get_profile
113 matches patches or files that contain "of_get_profile" 113 matches patches or files that contain "of_get_profile"
114 K: \b(printk|pr_(info|err))\b 114 K: \b(printk|pr_(info|err))\b
115 matches patches or files that contain one or more of the words 115 matches patches or files that contain one or more of the words
116 printk, pr_info or pr_err 116 printk, pr_info or pr_err
117 One regex pattern per line. Multiple K: lines acceptable. 117 One regex pattern per line. Multiple K: lines acceptable.
118 118
119 Note: For the hard of thinking, this list is meant to remain in alphabetical 119 Note: For the hard of thinking, this list is meant to remain in alphabetical
120 order. If you could add yourselves to it in alphabetical order that would be 120 order. If you could add yourselves to it in alphabetical order that would be
121 so much easier [Ed] 121 so much easier [Ed]
122 122
123 Maintainers List (try to look for most precise areas first) 123 Maintainers List (try to look for most precise areas first)
124 124
125 ----------------------------------- 125 -----------------------------------
126 126
127 3C59X NETWORK DRIVER 127 3C59X NETWORK DRIVER
128 M: Steffen Klassert <klassert@mathematik.tu-chemnitz.de> 128 M: Steffen Klassert <klassert@mathematik.tu-chemnitz.de>
129 L: netdev@vger.kernel.org 129 L: netdev@vger.kernel.org
130 S: Maintained 130 S: Maintained
131 F: Documentation/networking/vortex.txt 131 F: Documentation/networking/vortex.txt
132 F: drivers/net/ethernet/3com/3c59x.c 132 F: drivers/net/ethernet/3com/3c59x.c
133 133
134 3CR990 NETWORK DRIVER 134 3CR990 NETWORK DRIVER
135 M: David Dillow <dave@thedillows.org> 135 M: David Dillow <dave@thedillows.org>
136 L: netdev@vger.kernel.org 136 L: netdev@vger.kernel.org
137 S: Maintained 137 S: Maintained
138 F: drivers/net/ethernet/3com/typhoon* 138 F: drivers/net/ethernet/3com/typhoon*
139 139
140 3WARE SAS/SATA-RAID SCSI DRIVERS (3W-XXXX, 3W-9XXX, 3W-SAS) 140 3WARE SAS/SATA-RAID SCSI DRIVERS (3W-XXXX, 3W-9XXX, 3W-SAS)
141 M: Adam Radford <linuxraid@lsi.com> 141 M: Adam Radford <linuxraid@lsi.com>
142 L: linux-scsi@vger.kernel.org 142 L: linux-scsi@vger.kernel.org
143 W: http://www.lsi.com 143 W: http://www.lsi.com
144 S: Supported 144 S: Supported
145 F: drivers/scsi/3w-* 145 F: drivers/scsi/3w-*
146 146
147 53C700 AND 53C700-66 SCSI DRIVER 147 53C700 AND 53C700-66 SCSI DRIVER
148 M: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com> 148 M: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
149 L: linux-scsi@vger.kernel.org 149 L: linux-scsi@vger.kernel.org
150 S: Maintained 150 S: Maintained
151 F: drivers/scsi/53c700* 151 F: drivers/scsi/53c700*
152 152
153 6LOWPAN GENERIC (BTLE/IEEE 802.15.4) 153 6LOWPAN GENERIC (BTLE/IEEE 802.15.4)
154 M: Alexander Aring <alex.aring@gmail.com> 154 M: Alexander Aring <alex.aring@gmail.com>
155 M: Jukka Rissanen <jukka.rissanen@linux.intel.com> 155 M: Jukka Rissanen <jukka.rissanen@linux.intel.com>
156 L: linux-bluetooth@vger.kernel.org 156 L: linux-bluetooth@vger.kernel.org
157 L: linux-wpan@vger.kernel.org 157 L: linux-wpan@vger.kernel.org
158 S: Maintained 158 S: Maintained
159 F: net/6lowpan/ 159 F: net/6lowpan/
160 F: include/net/6lowpan.h 160 F: include/net/6lowpan.h
161 161
162 6PACK NETWORK DRIVER FOR AX.25 162 6PACK NETWORK DRIVER FOR AX.25
163 M: Andreas Koensgen <ajk@comnets.uni-bremen.de> 163 M: Andreas Koensgen <ajk@comnets.uni-bremen.de>
164 L: linux-hams@vger.kernel.org 164 L: linux-hams@vger.kernel.org
165 S: Maintained 165 S: Maintained
166 F: drivers/net/hamradio/6pack.c 166 F: drivers/net/hamradio/6pack.c
167 167
168 8169 10/100/1000 GIGABIT ETHERNET DRIVER 168 8169 10/100/1000 GIGABIT ETHERNET DRIVER
169 M: Realtek linux nic maintainers <nic_swsd@realtek.com> 169 M: Realtek linux nic maintainers <nic_swsd@realtek.com>
170 L: netdev@vger.kernel.org 170 L: netdev@vger.kernel.org
171 S: Maintained 171 S: Maintained
172 F: drivers/net/ethernet/realtek/r8169.c 172 F: drivers/net/ethernet/realtek/r8169.c
173 173
174 8250/16?50 (AND CLONE UARTS) SERIAL DRIVER 174 8250/16?50 (AND CLONE UARTS) SERIAL DRIVER
175 M: Greg Kroah-Hartman <gregkh@linuxfoundation.org> 175 M: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
176 L: linux-serial@vger.kernel.org 176 L: linux-serial@vger.kernel.org
177 W: http://serial.sourceforge.net 177 W: http://serial.sourceforge.net
178 S: Maintained 178 S: Maintained
179 T: git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git 179 T: git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git
180 F: drivers/tty/serial/8250* 180 F: drivers/tty/serial/8250*
181 F: include/linux/serial_8250.h 181 F: include/linux/serial_8250.h
182 182
183 8390 NETWORK DRIVERS [WD80x3/SMC-ELITE, SMC-ULTRA, NE2000, 3C503, etc.] 183 8390 NETWORK DRIVERS [WD80x3/SMC-ELITE, SMC-ULTRA, NE2000, 3C503, etc.]
184 L: netdev@vger.kernel.org 184 L: netdev@vger.kernel.org
185 S: Orphan / Obsolete 185 S: Orphan / Obsolete
186 F: drivers/net/ethernet/8390/ 186 F: drivers/net/ethernet/8390/
187 187
188 9P FILE SYSTEM 188 9P FILE SYSTEM
189 M: Eric Van Hensbergen <ericvh@gmail.com> 189 M: Eric Van Hensbergen <ericvh@gmail.com>
190 M: Ron Minnich <rminnich@sandia.gov> 190 M: Ron Minnich <rminnich@sandia.gov>
191 M: Latchesar Ionkov <lucho@ionkov.net> 191 M: Latchesar Ionkov <lucho@ionkov.net>
192 L: v9fs-developer@lists.sourceforge.net 192 L: v9fs-developer@lists.sourceforge.net
193 W: http://swik.net/v9fs 193 W: http://swik.net/v9fs
194 Q: http://patchwork.kernel.org/project/v9fs-devel/list/ 194 Q: http://patchwork.kernel.org/project/v9fs-devel/list/
195 T: git git://git.kernel.org/pub/scm/linux/kernel/git/ericvh/v9fs.git 195 T: git git://git.kernel.org/pub/scm/linux/kernel/git/ericvh/v9fs.git
196 S: Maintained 196 S: Maintained
197 F: Documentation/filesystems/9p.txt 197 F: Documentation/filesystems/9p.txt
198 F: fs/9p/ 198 F: fs/9p/
199 F: net/9p/ 199 F: net/9p/
200 F: include/net/9p/ 200 F: include/net/9p/
201 F: include/uapi/linux/virtio_9p.h 201 F: include/uapi/linux/virtio_9p.h
202 F: include/trace/events/9p.h 202 F: include/trace/events/9p.h
203 203
204 204
205 A8293 MEDIA DRIVER 205 A8293 MEDIA DRIVER
206 M: Antti Palosaari <crope@iki.fi> 206 M: Antti Palosaari <crope@iki.fi>
207 L: linux-media@vger.kernel.org 207 L: linux-media@vger.kernel.org
208 W: http://linuxtv.org/ 208 W: http://linuxtv.org/
209 W: http://palosaari.fi/linux/ 209 W: http://palosaari.fi/linux/
210 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 210 Q: http://patchwork.linuxtv.org/project/linux-media/list/
211 T: git git://linuxtv.org/anttip/media_tree.git 211 T: git git://linuxtv.org/anttip/media_tree.git
212 S: Maintained 212 S: Maintained
213 F: drivers/media/dvb-frontends/a8293* 213 F: drivers/media/dvb-frontends/a8293*
214 214
215 AACRAID SCSI RAID DRIVER 215 AACRAID SCSI RAID DRIVER
216 M: Adaptec OEM Raid Solutions <aacraid@adaptec.com> 216 M: Adaptec OEM Raid Solutions <aacraid@adaptec.com>
217 L: linux-scsi@vger.kernel.org 217 L: linux-scsi@vger.kernel.org
218 W: http://www.adaptec.com/ 218 W: http://www.adaptec.com/
219 S: Supported 219 S: Supported
220 F: Documentation/scsi/aacraid.txt 220 F: Documentation/scsi/aacraid.txt
221 F: drivers/scsi/aacraid/ 221 F: drivers/scsi/aacraid/
222 222
223 ABI/API 223 ABI/API
224 L: linux-api@vger.kernel.org 224 L: linux-api@vger.kernel.org
225 F: Documentation/ABI/ 225 F: Documentation/ABI/
226 F: include/linux/syscalls.h 226 F: include/linux/syscalls.h
227 F: include/uapi/ 227 F: include/uapi/
228 F: kernel/sys_ni.c 228 F: kernel/sys_ni.c
229 229
230 ABIT UGURU 1,2 HARDWARE MONITOR DRIVER 230 ABIT UGURU 1,2 HARDWARE MONITOR DRIVER
231 M: Hans de Goede <hdegoede@redhat.com> 231 M: Hans de Goede <hdegoede@redhat.com>
232 L: lm-sensors@lm-sensors.org 232 L: lm-sensors@lm-sensors.org
233 S: Maintained 233 S: Maintained
234 F: drivers/hwmon/abituguru.c 234 F: drivers/hwmon/abituguru.c
235 235
236 ABIT UGURU 3 HARDWARE MONITOR DRIVER 236 ABIT UGURU 3 HARDWARE MONITOR DRIVER
237 M: Alistair John Strachan <alistair@devzero.co.uk> 237 M: Alistair John Strachan <alistair@devzero.co.uk>
238 L: lm-sensors@lm-sensors.org 238 L: lm-sensors@lm-sensors.org
239 S: Maintained 239 S: Maintained
240 F: drivers/hwmon/abituguru3.c 240 F: drivers/hwmon/abituguru3.c
241 241
242 ACENIC DRIVER 242 ACENIC DRIVER
243 M: Jes Sorensen <jes@trained-monkey.org> 243 M: Jes Sorensen <jes@trained-monkey.org>
244 L: linux-acenic@sunsite.dk 244 L: linux-acenic@sunsite.dk
245 S: Maintained 245 S: Maintained
246 F: drivers/net/ethernet/alteon/acenic* 246 F: drivers/net/ethernet/alteon/acenic*
247 247
248 ACER ASPIRE ONE TEMPERATURE AND FAN DRIVER 248 ACER ASPIRE ONE TEMPERATURE AND FAN DRIVER
249 M: Peter Feuerer <peter@piie.net> 249 M: Peter Feuerer <peter@piie.net>
250 L: platform-driver-x86@vger.kernel.org 250 L: platform-driver-x86@vger.kernel.org
251 W: http://piie.net/?section=acerhdf 251 W: http://piie.net/?section=acerhdf
252 S: Maintained 252 S: Maintained
253 F: drivers/platform/x86/acerhdf.c 253 F: drivers/platform/x86/acerhdf.c
254 254
255 ACER WMI LAPTOP EXTRAS 255 ACER WMI LAPTOP EXTRAS
256 M: "Lee, Chun-Yi" <jlee@suse.com> 256 M: "Lee, Chun-Yi" <jlee@suse.com>
257 L: platform-driver-x86@vger.kernel.org 257 L: platform-driver-x86@vger.kernel.org
258 S: Maintained 258 S: Maintained
259 F: drivers/platform/x86/acer-wmi.c 259 F: drivers/platform/x86/acer-wmi.c
260 260
261 ACPI 261 ACPI
262 M: Rafael J. Wysocki <rjw@rjwysocki.net> 262 M: Rafael J. Wysocki <rjw@rjwysocki.net>
263 M: Len Brown <lenb@kernel.org> 263 M: Len Brown <lenb@kernel.org>
264 L: linux-acpi@vger.kernel.org 264 L: linux-acpi@vger.kernel.org
265 W: https://01.org/linux-acpi 265 W: https://01.org/linux-acpi
266 Q: https://patchwork.kernel.org/project/linux-acpi/list/ 266 Q: https://patchwork.kernel.org/project/linux-acpi/list/
267 T: git git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm 267 T: git git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
268 S: Supported 268 S: Supported
269 F: drivers/acpi/ 269 F: drivers/acpi/
270 F: drivers/pnp/pnpacpi/ 270 F: drivers/pnp/pnpacpi/
271 F: include/linux/acpi.h 271 F: include/linux/acpi.h
272 F: include/acpi/ 272 F: include/acpi/
273 F: Documentation/acpi 273 F: Documentation/acpi
274 F: Documentation/ABI/testing/sysfs-bus-acpi 274 F: Documentation/ABI/testing/sysfs-bus-acpi
275 F: drivers/pci/*acpi* 275 F: drivers/pci/*acpi*
276 F: drivers/pci/*/*acpi* 276 F: drivers/pci/*/*acpi*
277 F: drivers/pci/*/*/*acpi* 277 F: drivers/pci/*/*/*acpi*
278 F: tools/power/acpi 278 F: tools/power/acpi
279 279
280 ACPI COMPONENT ARCHITECTURE (ACPICA) 280 ACPI COMPONENT ARCHITECTURE (ACPICA)
281 M: Robert Moore <robert.moore@intel.com> 281 M: Robert Moore <robert.moore@intel.com>
282 M: Lv Zheng <lv.zheng@intel.com> 282 M: Lv Zheng <lv.zheng@intel.com>
283 M: Rafael J. Wysocki <rafael.j.wysocki@intel.com> 283 M: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
284 L: linux-acpi@vger.kernel.org 284 L: linux-acpi@vger.kernel.org
285 L: devel@acpica.org 285 L: devel@acpica.org
286 W: https://acpica.org/ 286 W: https://acpica.org/
287 W: https://github.com/acpica/acpica/ 287 W: https://github.com/acpica/acpica/
288 Q: https://patchwork.kernel.org/project/linux-acpi/list/ 288 Q: https://patchwork.kernel.org/project/linux-acpi/list/
289 T: git git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm 289 T: git git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
290 S: Supported 290 S: Supported
291 F: drivers/acpi/acpica/ 291 F: drivers/acpi/acpica/
292 F: include/acpi/ 292 F: include/acpi/
293 F: tools/power/acpi/ 293 F: tools/power/acpi/
294 294
295 ACPI FAN DRIVER 295 ACPI FAN DRIVER
296 M: Zhang Rui <rui.zhang@intel.com> 296 M: Zhang Rui <rui.zhang@intel.com>
297 L: linux-acpi@vger.kernel.org 297 L: linux-acpi@vger.kernel.org
298 W: https://01.org/linux-acpi 298 W: https://01.org/linux-acpi
299 S: Supported 299 S: Supported
300 F: drivers/acpi/fan.c 300 F: drivers/acpi/fan.c
301 301
302 ACPI THERMAL DRIVER 302 ACPI THERMAL DRIVER
303 M: Zhang Rui <rui.zhang@intel.com> 303 M: Zhang Rui <rui.zhang@intel.com>
304 L: linux-acpi@vger.kernel.org 304 L: linux-acpi@vger.kernel.org
305 W: https://01.org/linux-acpi 305 W: https://01.org/linux-acpi
306 S: Supported 306 S: Supported
307 F: drivers/acpi/*thermal* 307 F: drivers/acpi/*thermal*
308 308
309 ACPI VIDEO DRIVER 309 ACPI VIDEO DRIVER
310 M: Zhang Rui <rui.zhang@intel.com> 310 M: Zhang Rui <rui.zhang@intel.com>
311 L: linux-acpi@vger.kernel.org 311 L: linux-acpi@vger.kernel.org
312 W: https://01.org/linux-acpi 312 W: https://01.org/linux-acpi
313 S: Supported 313 S: Supported
314 F: drivers/acpi/video.c 314 F: drivers/acpi/video.c
315 315
316 ACPI WMI DRIVER 316 ACPI WMI DRIVER
317 L: platform-driver-x86@vger.kernel.org 317 L: platform-driver-x86@vger.kernel.org
318 S: Orphan 318 S: Orphan
319 F: drivers/platform/x86/wmi.c 319 F: drivers/platform/x86/wmi.c
320 320
321 AD1889 ALSA SOUND DRIVER 321 AD1889 ALSA SOUND DRIVER
322 M: Thibaut Varene <T-Bone@parisc-linux.org> 322 M: Thibaut Varene <T-Bone@parisc-linux.org>
323 W: http://wiki.parisc-linux.org/AD1889 323 W: http://wiki.parisc-linux.org/AD1889
324 L: linux-parisc@vger.kernel.org 324 L: linux-parisc@vger.kernel.org
325 S: Maintained 325 S: Maintained
326 F: sound/pci/ad1889.* 326 F: sound/pci/ad1889.*
327 327
328 AD525X ANALOG DEVICES DIGITAL POTENTIOMETERS DRIVER 328 AD525X ANALOG DEVICES DIGITAL POTENTIOMETERS DRIVER
329 M: Michael Hennerich <michael.hennerich@analog.com> 329 M: Michael Hennerich <michael.hennerich@analog.com>
330 W: http://wiki.analog.com/AD5254 330 W: http://wiki.analog.com/AD5254
331 W: http://ez.analog.com/community/linux-device-drivers 331 W: http://ez.analog.com/community/linux-device-drivers
332 S: Supported 332 S: Supported
333 F: drivers/misc/ad525x_dpot.c 333 F: drivers/misc/ad525x_dpot.c
334 334
335 AD5398 CURRENT REGULATOR DRIVER (AD5398/AD5821) 335 AD5398 CURRENT REGULATOR DRIVER (AD5398/AD5821)
336 M: Michael Hennerich <michael.hennerich@analog.com> 336 M: Michael Hennerich <michael.hennerich@analog.com>
337 W: http://wiki.analog.com/AD5398 337 W: http://wiki.analog.com/AD5398
338 W: http://ez.analog.com/community/linux-device-drivers 338 W: http://ez.analog.com/community/linux-device-drivers
339 S: Supported 339 S: Supported
340 F: drivers/regulator/ad5398.c 340 F: drivers/regulator/ad5398.c
341 341
342 AD714X CAPACITANCE TOUCH SENSOR DRIVER (AD7142/3/7/8/7A) 342 AD714X CAPACITANCE TOUCH SENSOR DRIVER (AD7142/3/7/8/7A)
343 M: Michael Hennerich <michael.hennerich@analog.com> 343 M: Michael Hennerich <michael.hennerich@analog.com>
344 W: http://wiki.analog.com/AD7142 344 W: http://wiki.analog.com/AD7142
345 W: http://ez.analog.com/community/linux-device-drivers 345 W: http://ez.analog.com/community/linux-device-drivers
346 S: Supported 346 S: Supported
347 F: drivers/input/misc/ad714x.c 347 F: drivers/input/misc/ad714x.c
348 348
349 AD7877 TOUCHSCREEN DRIVER 349 AD7877 TOUCHSCREEN DRIVER
350 M: Michael Hennerich <michael.hennerich@analog.com> 350 M: Michael Hennerich <michael.hennerich@analog.com>
351 W: http://wiki.analog.com/AD7877 351 W: http://wiki.analog.com/AD7877
352 W: http://ez.analog.com/community/linux-device-drivers 352 W: http://ez.analog.com/community/linux-device-drivers
353 S: Supported 353 S: Supported
354 F: drivers/input/touchscreen/ad7877.c 354 F: drivers/input/touchscreen/ad7877.c
355 355
356 AD7879 TOUCHSCREEN DRIVER (AD7879/AD7889) 356 AD7879 TOUCHSCREEN DRIVER (AD7879/AD7889)
357 M: Michael Hennerich <michael.hennerich@analog.com> 357 M: Michael Hennerich <michael.hennerich@analog.com>
358 W: http://wiki.analog.com/AD7879 358 W: http://wiki.analog.com/AD7879
359 W: http://ez.analog.com/community/linux-device-drivers 359 W: http://ez.analog.com/community/linux-device-drivers
360 S: Supported 360 S: Supported
361 F: drivers/input/touchscreen/ad7879.c 361 F: drivers/input/touchscreen/ad7879.c
362 362
363 ADDRESS SPACE LAYOUT RANDOMIZATION (ASLR) 363 ADDRESS SPACE LAYOUT RANDOMIZATION (ASLR)
364 M: Jiri Kosina <jkosina@suse.cz> 364 M: Jiri Kosina <jkosina@suse.cz>
365 S: Maintained 365 S: Maintained
366 366
367 ADM1025 HARDWARE MONITOR DRIVER 367 ADM1025 HARDWARE MONITOR DRIVER
368 M: Jean Delvare <jdelvare@suse.de> 368 M: Jean Delvare <jdelvare@suse.de>
369 L: lm-sensors@lm-sensors.org 369 L: lm-sensors@lm-sensors.org
370 S: Maintained 370 S: Maintained
371 F: Documentation/hwmon/adm1025 371 F: Documentation/hwmon/adm1025
372 F: drivers/hwmon/adm1025.c 372 F: drivers/hwmon/adm1025.c
373 373
374 ADM1029 HARDWARE MONITOR DRIVER 374 ADM1029 HARDWARE MONITOR DRIVER
375 M: Corentin Labbe <clabbe.montjoie@gmail.com> 375 M: Corentin Labbe <clabbe.montjoie@gmail.com>
376 L: lm-sensors@lm-sensors.org 376 L: lm-sensors@lm-sensors.org
377 S: Maintained 377 S: Maintained
378 F: drivers/hwmon/adm1029.c 378 F: drivers/hwmon/adm1029.c
379 379
380 ADM8211 WIRELESS DRIVER 380 ADM8211 WIRELESS DRIVER
381 L: linux-wireless@vger.kernel.org 381 L: linux-wireless@vger.kernel.org
382 W: http://wireless.kernel.org/ 382 W: http://wireless.kernel.org/
383 S: Orphan 383 S: Orphan
384 F: drivers/net/wireless/adm8211.* 384 F: drivers/net/wireless/adm8211.*
385 385
386 ADP1653 FLASH CONTROLLER DRIVER 386 ADP1653 FLASH CONTROLLER DRIVER
387 M: Sakari Ailus <sakari.ailus@iki.fi> 387 M: Sakari Ailus <sakari.ailus@iki.fi>
388 L: linux-media@vger.kernel.org 388 L: linux-media@vger.kernel.org
389 S: Maintained 389 S: Maintained
390 F: drivers/media/i2c/adp1653.c 390 F: drivers/media/i2c/adp1653.c
391 F: include/media/adp1653.h 391 F: include/media/adp1653.h
392 392
393 ADP5520 BACKLIGHT DRIVER WITH IO EXPANDER (ADP5520/ADP5501) 393 ADP5520 BACKLIGHT DRIVER WITH IO EXPANDER (ADP5520/ADP5501)
394 M: Michael Hennerich <michael.hennerich@analog.com> 394 M: Michael Hennerich <michael.hennerich@analog.com>
395 W: http://wiki.analog.com/ADP5520 395 W: http://wiki.analog.com/ADP5520
396 W: http://ez.analog.com/community/linux-device-drivers 396 W: http://ez.analog.com/community/linux-device-drivers
397 S: Supported 397 S: Supported
398 F: drivers/mfd/adp5520.c 398 F: drivers/mfd/adp5520.c
399 F: drivers/video/backlight/adp5520_bl.c 399 F: drivers/video/backlight/adp5520_bl.c
400 F: drivers/leds/leds-adp5520.c 400 F: drivers/leds/leds-adp5520.c
401 F: drivers/gpio/gpio-adp5520.c 401 F: drivers/gpio/gpio-adp5520.c
402 F: drivers/input/keyboard/adp5520-keys.c 402 F: drivers/input/keyboard/adp5520-keys.c
403 403
404 ADP5588 QWERTY KEYPAD AND IO EXPANDER DRIVER (ADP5588/ADP5587) 404 ADP5588 QWERTY KEYPAD AND IO EXPANDER DRIVER (ADP5588/ADP5587)
405 M: Michael Hennerich <michael.hennerich@analog.com> 405 M: Michael Hennerich <michael.hennerich@analog.com>
406 W: http://wiki.analog.com/ADP5588 406 W: http://wiki.analog.com/ADP5588
407 W: http://ez.analog.com/community/linux-device-drivers 407 W: http://ez.analog.com/community/linux-device-drivers
408 S: Supported 408 S: Supported
409 F: drivers/input/keyboard/adp5588-keys.c 409 F: drivers/input/keyboard/adp5588-keys.c
410 F: drivers/gpio/gpio-adp5588.c 410 F: drivers/gpio/gpio-adp5588.c
411 411
412 ADP8860 BACKLIGHT DRIVER (ADP8860/ADP8861/ADP8863) 412 ADP8860 BACKLIGHT DRIVER (ADP8860/ADP8861/ADP8863)
413 M: Michael Hennerich <michael.hennerich@analog.com> 413 M: Michael Hennerich <michael.hennerich@analog.com>
414 W: http://wiki.analog.com/ADP8860 414 W: http://wiki.analog.com/ADP8860
415 W: http://ez.analog.com/community/linux-device-drivers 415 W: http://ez.analog.com/community/linux-device-drivers
416 S: Supported 416 S: Supported
417 F: drivers/video/backlight/adp8860_bl.c 417 F: drivers/video/backlight/adp8860_bl.c
418 418
419 ADS1015 HARDWARE MONITOR DRIVER 419 ADS1015 HARDWARE MONITOR DRIVER
420 M: Dirk Eibach <eibach@gdsys.de> 420 M: Dirk Eibach <eibach@gdsys.de>
421 L: lm-sensors@lm-sensors.org 421 L: lm-sensors@lm-sensors.org
422 S: Maintained 422 S: Maintained
423 F: Documentation/hwmon/ads1015 423 F: Documentation/hwmon/ads1015
424 F: drivers/hwmon/ads1015.c 424 F: drivers/hwmon/ads1015.c
425 F: include/linux/i2c/ads1015.h 425 F: include/linux/i2c/ads1015.h
426 426
427 ADT746X FAN DRIVER 427 ADT746X FAN DRIVER
428 M: Colin Leroy <colin@colino.net> 428 M: Colin Leroy <colin@colino.net>
429 S: Maintained 429 S: Maintained
430 F: drivers/macintosh/therm_adt746x.c 430 F: drivers/macintosh/therm_adt746x.c
431 431
432 ADT7475 HARDWARE MONITOR DRIVER 432 ADT7475 HARDWARE MONITOR DRIVER
433 M: Jean Delvare <jdelvare@suse.de> 433 M: Jean Delvare <jdelvare@suse.de>
434 L: lm-sensors@lm-sensors.org 434 L: lm-sensors@lm-sensors.org
435 S: Maintained 435 S: Maintained
436 F: Documentation/hwmon/adt7475 436 F: Documentation/hwmon/adt7475
437 F: drivers/hwmon/adt7475.c 437 F: drivers/hwmon/adt7475.c
438 438
439 ADXL34X THREE-AXIS DIGITAL ACCELEROMETER DRIVER (ADXL345/ADXL346) 439 ADXL34X THREE-AXIS DIGITAL ACCELEROMETER DRIVER (ADXL345/ADXL346)
440 M: Michael Hennerich <michael.hennerich@analog.com> 440 M: Michael Hennerich <michael.hennerich@analog.com>
441 W: http://wiki.analog.com/ADXL345 441 W: http://wiki.analog.com/ADXL345
442 W: http://ez.analog.com/community/linux-device-drivers 442 W: http://ez.analog.com/community/linux-device-drivers
443 S: Supported 443 S: Supported
444 F: drivers/input/misc/adxl34x.c 444 F: drivers/input/misc/adxl34x.c
445 445
446 ADVANSYS SCSI DRIVER 446 ADVANSYS SCSI DRIVER
447 M: Matthew Wilcox <matthew@wil.cx> 447 M: Matthew Wilcox <matthew@wil.cx>
448 L: linux-scsi@vger.kernel.org 448 L: linux-scsi@vger.kernel.org
449 S: Maintained 449 S: Maintained
450 F: Documentation/scsi/advansys.txt 450 F: Documentation/scsi/advansys.txt
451 F: drivers/scsi/advansys.c 451 F: drivers/scsi/advansys.c
452 452
453 AEDSP16 DRIVER 453 AEDSP16 DRIVER
454 M: Riccardo Facchetti <fizban@tin.it> 454 M: Riccardo Facchetti <fizban@tin.it>
455 S: Maintained 455 S: Maintained
456 F: sound/oss/aedsp16.c 456 F: sound/oss/aedsp16.c
457 457
458 AF9013 MEDIA DRIVER 458 AF9013 MEDIA DRIVER
459 M: Antti Palosaari <crope@iki.fi> 459 M: Antti Palosaari <crope@iki.fi>
460 L: linux-media@vger.kernel.org 460 L: linux-media@vger.kernel.org
461 W: http://linuxtv.org/ 461 W: http://linuxtv.org/
462 W: http://palosaari.fi/linux/ 462 W: http://palosaari.fi/linux/
463 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 463 Q: http://patchwork.linuxtv.org/project/linux-media/list/
464 T: git git://linuxtv.org/anttip/media_tree.git 464 T: git git://linuxtv.org/anttip/media_tree.git
465 S: Maintained 465 S: Maintained
466 F: drivers/media/dvb-frontends/af9013* 466 F: drivers/media/dvb-frontends/af9013*
467 467
468 AF9033 MEDIA DRIVER 468 AF9033 MEDIA DRIVER
469 M: Antti Palosaari <crope@iki.fi> 469 M: Antti Palosaari <crope@iki.fi>
470 L: linux-media@vger.kernel.org 470 L: linux-media@vger.kernel.org
471 W: http://linuxtv.org/ 471 W: http://linuxtv.org/
472 W: http://palosaari.fi/linux/ 472 W: http://palosaari.fi/linux/
473 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 473 Q: http://patchwork.linuxtv.org/project/linux-media/list/
474 T: git git://linuxtv.org/anttip/media_tree.git 474 T: git git://linuxtv.org/anttip/media_tree.git
475 S: Maintained 475 S: Maintained
476 F: drivers/media/dvb-frontends/af9033* 476 F: drivers/media/dvb-frontends/af9033*
477 477
478 AFFS FILE SYSTEM 478 AFFS FILE SYSTEM
479 L: linux-fsdevel@vger.kernel.org 479 L: linux-fsdevel@vger.kernel.org
480 S: Orphan 480 S: Orphan
481 F: Documentation/filesystems/affs.txt 481 F: Documentation/filesystems/affs.txt
482 F: fs/affs/ 482 F: fs/affs/
483 483
484 AFS FILESYSTEM & AF_RXRPC SOCKET DOMAIN 484 AFS FILESYSTEM & AF_RXRPC SOCKET DOMAIN
485 M: David Howells <dhowells@redhat.com> 485 M: David Howells <dhowells@redhat.com>
486 L: linux-afs@lists.infradead.org 486 L: linux-afs@lists.infradead.org
487 S: Supported 487 S: Supported
488 F: fs/afs/ 488 F: fs/afs/
489 F: include/net/af_rxrpc.h 489 F: include/net/af_rxrpc.h
490 F: net/rxrpc/af_rxrpc.c 490 F: net/rxrpc/af_rxrpc.c
491 491
492 AGPGART DRIVER 492 AGPGART DRIVER
493 M: David Airlie <airlied@linux.ie> 493 M: David Airlie <airlied@linux.ie>
494 T: git git://people.freedesktop.org/~airlied/linux (part of drm maint) 494 T: git git://people.freedesktop.org/~airlied/linux (part of drm maint)
495 S: Maintained 495 S: Maintained
496 F: drivers/char/agp/ 496 F: drivers/char/agp/
497 F: include/linux/agp* 497 F: include/linux/agp*
498 F: include/uapi/linux/agp* 498 F: include/uapi/linux/agp*
499 499
500 AHA152X SCSI DRIVER 500 AHA152X SCSI DRIVER
501 M: "Juergen E. Fischer" <fischer@norbit.de> 501 M: "Juergen E. Fischer" <fischer@norbit.de>
502 L: linux-scsi@vger.kernel.org 502 L: linux-scsi@vger.kernel.org
503 S: Maintained 503 S: Maintained
504 F: drivers/scsi/aha152x* 504 F: drivers/scsi/aha152x*
505 F: drivers/scsi/pcmcia/aha152x* 505 F: drivers/scsi/pcmcia/aha152x*
506 506
507 AIC7XXX / AIC79XX SCSI DRIVER 507 AIC7XXX / AIC79XX SCSI DRIVER
508 M: Hannes Reinecke <hare@suse.de> 508 M: Hannes Reinecke <hare@suse.de>
509 L: linux-scsi@vger.kernel.org 509 L: linux-scsi@vger.kernel.org
510 S: Maintained 510 S: Maintained
511 F: drivers/scsi/aic7xxx/ 511 F: drivers/scsi/aic7xxx/
512 512
513 AIMSLAB FM RADIO RECEIVER DRIVER 513 AIMSLAB FM RADIO RECEIVER DRIVER
514 M: Hans Verkuil <hverkuil@xs4all.nl> 514 M: Hans Verkuil <hverkuil@xs4all.nl>
515 L: linux-media@vger.kernel.org 515 L: linux-media@vger.kernel.org
516 T: git git://linuxtv.org/media_tree.git 516 T: git git://linuxtv.org/media_tree.git
517 W: http://linuxtv.org 517 W: http://linuxtv.org
518 S: Maintained 518 S: Maintained
519 F: drivers/media/radio/radio-aimslab* 519 F: drivers/media/radio/radio-aimslab*
520 520
521 AIO 521 AIO
522 M: Benjamin LaHaise <bcrl@kvack.org> 522 M: Benjamin LaHaise <bcrl@kvack.org>
523 L: linux-aio@kvack.org 523 L: linux-aio@kvack.org
524 S: Supported 524 S: Supported
525 F: fs/aio.c 525 F: fs/aio.c
526 F: include/linux/*aio*.h 526 F: include/linux/*aio*.h
527 527
528 AIRSPY MEDIA DRIVER 528 AIRSPY MEDIA DRIVER
529 M: Antti Palosaari <crope@iki.fi> 529 M: Antti Palosaari <crope@iki.fi>
530 L: linux-media@vger.kernel.org 530 L: linux-media@vger.kernel.org
531 W: http://linuxtv.org/ 531 W: http://linuxtv.org/
532 W: http://palosaari.fi/linux/ 532 W: http://palosaari.fi/linux/
533 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 533 Q: http://patchwork.linuxtv.org/project/linux-media/list/
534 T: git git://linuxtv.org/anttip/media_tree.git 534 T: git git://linuxtv.org/anttip/media_tree.git
535 S: Maintained 535 S: Maintained
536 F: drivers/media/usb/airspy/ 536 F: drivers/media/usb/airspy/
537 537
538 ALCATEL SPEEDTOUCH USB DRIVER 538 ALCATEL SPEEDTOUCH USB DRIVER
539 M: Duncan Sands <duncan.sands@free.fr> 539 M: Duncan Sands <duncan.sands@free.fr>
540 L: linux-usb@vger.kernel.org 540 L: linux-usb@vger.kernel.org
541 W: http://www.linux-usb.org/SpeedTouch/ 541 W: http://www.linux-usb.org/SpeedTouch/
542 S: Maintained 542 S: Maintained
543 F: drivers/usb/atm/speedtch.c 543 F: drivers/usb/atm/speedtch.c
544 F: drivers/usb/atm/usbatm.c 544 F: drivers/usb/atm/usbatm.c
545 545
546 ALCHEMY AU1XX0 MMC DRIVER 546 ALCHEMY AU1XX0 MMC DRIVER
547 M: Manuel Lauss <manuel.lauss@gmail.com> 547 M: Manuel Lauss <manuel.lauss@gmail.com>
548 S: Maintained 548 S: Maintained
549 F: drivers/mmc/host/au1xmmc.c 549 F: drivers/mmc/host/au1xmmc.c
550 550
551 ALI1563 I2C DRIVER 551 ALI1563 I2C DRIVER
552 M: Rudolf Marek <r.marek@assembler.cz> 552 M: Rudolf Marek <r.marek@assembler.cz>
553 L: linux-i2c@vger.kernel.org 553 L: linux-i2c@vger.kernel.org
554 S: Maintained 554 S: Maintained
555 F: Documentation/i2c/busses/i2c-ali1563 555 F: Documentation/i2c/busses/i2c-ali1563
556 F: drivers/i2c/busses/i2c-ali1563.c 556 F: drivers/i2c/busses/i2c-ali1563.c
557 557
558 ALPHA PORT 558 ALPHA PORT
559 M: Richard Henderson <rth@twiddle.net> 559 M: Richard Henderson <rth@twiddle.net>
560 M: Ivan Kokshaysky <ink@jurassic.park.msu.ru> 560 M: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
561 M: Matt Turner <mattst88@gmail.com> 561 M: Matt Turner <mattst88@gmail.com>
562 S: Odd Fixes 562 S: Odd Fixes
563 L: linux-alpha@vger.kernel.org 563 L: linux-alpha@vger.kernel.org
564 F: arch/alpha/ 564 F: arch/alpha/
565 565
566 ALTERA TRIPLE SPEED ETHERNET DRIVER 566 ALTERA TRIPLE SPEED ETHERNET DRIVER
567 M: Vince Bridgers <vbridger@opensource.altera.com> 567 M: Vince Bridgers <vbridger@opensource.altera.com>
568 L: netdev@vger.kernel.org 568 L: netdev@vger.kernel.org
569 L: nios2-dev@lists.rocketboards.org (moderated for non-subscribers) 569 L: nios2-dev@lists.rocketboards.org (moderated for non-subscribers)
570 S: Maintained 570 S: Maintained
571 F: drivers/net/ethernet/altera/ 571 F: drivers/net/ethernet/altera/
572 572
573 ALTERA UART/JTAG UART SERIAL DRIVERS 573 ALTERA UART/JTAG UART SERIAL DRIVERS
574 M: Tobias Klauser <tklauser@distanz.ch> 574 M: Tobias Klauser <tklauser@distanz.ch>
575 L: linux-serial@vger.kernel.org 575 L: linux-serial@vger.kernel.org
576 L: nios2-dev@lists.rocketboards.org (moderated for non-subscribers) 576 L: nios2-dev@lists.rocketboards.org (moderated for non-subscribers)
577 S: Maintained 577 S: Maintained
578 F: drivers/tty/serial/altera_uart.c 578 F: drivers/tty/serial/altera_uart.c
579 F: drivers/tty/serial/altera_jtaguart.c 579 F: drivers/tty/serial/altera_jtaguart.c
580 F: include/linux/altera_uart.h 580 F: include/linux/altera_uart.h
581 F: include/linux/altera_jtaguart.h 581 F: include/linux/altera_jtaguart.h
582 582
583 AMD CRYPTOGRAPHIC COPROCESSOR (CCP) DRIVER 583 AMD CRYPTOGRAPHIC COPROCESSOR (CCP) DRIVER
584 M: Tom Lendacky <thomas.lendacky@amd.com> 584 M: Tom Lendacky <thomas.lendacky@amd.com>
585 L: linux-crypto@vger.kernel.org 585 L: linux-crypto@vger.kernel.org
586 S: Supported 586 S: Supported
587 F: drivers/crypto/ccp/ 587 F: drivers/crypto/ccp/
588 F: include/linux/ccp.h 588 F: include/linux/ccp.h
589 589
590 AMD FAM15H PROCESSOR POWER MONITORING DRIVER 590 AMD FAM15H PROCESSOR POWER MONITORING DRIVER
591 M: Andreas Herrmann <herrmann.der.user@googlemail.com> 591 M: Andreas Herrmann <herrmann.der.user@googlemail.com>
592 L: lm-sensors@lm-sensors.org 592 L: lm-sensors@lm-sensors.org
593 S: Maintained 593 S: Maintained
594 F: Documentation/hwmon/fam15h_power 594 F: Documentation/hwmon/fam15h_power
595 F: drivers/hwmon/fam15h_power.c 595 F: drivers/hwmon/fam15h_power.c
596 596
597 AMD GEODE CS5536 USB DEVICE CONTROLLER DRIVER 597 AMD GEODE CS5536 USB DEVICE CONTROLLER DRIVER
598 M: Thomas Dahlmann <dahlmann.thomas@arcor.de> 598 M: Thomas Dahlmann <dahlmann.thomas@arcor.de>
599 L: linux-geode@lists.infradead.org (moderated for non-subscribers) 599 L: linux-geode@lists.infradead.org (moderated for non-subscribers)
600 S: Supported 600 S: Supported
601 F: drivers/usb/gadget/udc/amd5536udc.* 601 F: drivers/usb/gadget/udc/amd5536udc.*
602 602
603 AMD GEODE PROCESSOR/CHIPSET SUPPORT 603 AMD GEODE PROCESSOR/CHIPSET SUPPORT
604 P: Andres Salomon <dilinger@queued.net> 604 P: Andres Salomon <dilinger@queued.net>
605 L: linux-geode@lists.infradead.org (moderated for non-subscribers) 605 L: linux-geode@lists.infradead.org (moderated for non-subscribers)
606 W: http://www.amd.com/us-en/ConnectivitySolutions/TechnicalResources/0,,50_2334_2452_11363,00.html 606 W: http://www.amd.com/us-en/ConnectivitySolutions/TechnicalResources/0,,50_2334_2452_11363,00.html
607 S: Supported 607 S: Supported
608 F: drivers/char/hw_random/geode-rng.c 608 F: drivers/char/hw_random/geode-rng.c
609 F: drivers/crypto/geode* 609 F: drivers/crypto/geode*
610 F: drivers/video/fbdev/geode/ 610 F: drivers/video/fbdev/geode/
611 F: arch/x86/include/asm/geode.h 611 F: arch/x86/include/asm/geode.h
612 612
613 AMD IOMMU (AMD-VI) 613 AMD IOMMU (AMD-VI)
614 M: Joerg Roedel <joro@8bytes.org> 614 M: Joerg Roedel <joro@8bytes.org>
615 L: iommu@lists.linux-foundation.org 615 L: iommu@lists.linux-foundation.org
616 T: git git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git 616 T: git git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git
617 S: Maintained 617 S: Maintained
618 F: drivers/iommu/amd_iommu*.[ch] 618 F: drivers/iommu/amd_iommu*.[ch]
619 F: include/linux/amd-iommu.h 619 F: include/linux/amd-iommu.h
620 620
621 AMD KFD 621 AMD KFD
622 M: Oded Gabbay <oded.gabbay@amd.com> 622 M: Oded Gabbay <oded.gabbay@amd.com>
623 L: dri-devel@lists.freedesktop.org 623 L: dri-devel@lists.freedesktop.org
624 T: git git://people.freedesktop.org/~gabbayo/linux.git 624 T: git git://people.freedesktop.org/~gabbayo/linux.git
625 S: Supported 625 S: Supported
626 F: drivers/gpu/drm/amd/amdkfd/ 626 F: drivers/gpu/drm/amd/amdkfd/
627 F: drivers/gpu/drm/radeon/radeon_kfd.c 627 F: drivers/gpu/drm/radeon/radeon_kfd.c
628 F: drivers/gpu/drm/radeon/radeon_kfd.h 628 F: drivers/gpu/drm/radeon/radeon_kfd.h
629 F: include/uapi/linux/kfd_ioctl.h 629 F: include/uapi/linux/kfd_ioctl.h
630 630
631 AMD MICROCODE UPDATE SUPPORT 631 AMD MICROCODE UPDATE SUPPORT
632 M: Andreas Herrmann <herrmann.der.user@googlemail.com> 632 M: Andreas Herrmann <herrmann.der.user@googlemail.com>
633 L: amd64-microcode@amd64.org 633 L: amd64-microcode@amd64.org
634 S: Maintained 634 S: Maintained
635 F: arch/x86/kernel/cpu/microcode/amd* 635 F: arch/x86/kernel/cpu/microcode/amd*
636 636
637 AMD XGBE DRIVER 637 AMD XGBE DRIVER
638 M: Tom Lendacky <thomas.lendacky@amd.com> 638 M: Tom Lendacky <thomas.lendacky@amd.com>
639 L: netdev@vger.kernel.org 639 L: netdev@vger.kernel.org
640 S: Supported 640 S: Supported
641 F: drivers/net/ethernet/amd/xgbe/ 641 F: drivers/net/ethernet/amd/xgbe/
642 F: drivers/net/phy/amd-xgbe-phy.c 642 F: drivers/net/phy/amd-xgbe-phy.c
643 643
644 AMS (Apple Motion Sensor) DRIVER 644 AMS (Apple Motion Sensor) DRIVER
645 M: Michael Hanselmann <linux-kernel@hansmi.ch> 645 M: Michael Hanselmann <linux-kernel@hansmi.ch>
646 S: Supported 646 S: Supported
647 F: drivers/macintosh/ams/ 647 F: drivers/macintosh/ams/
648 648
649 AMSO1100 RNIC DRIVER 649 AMSO1100 RNIC DRIVER
650 M: Tom Tucker <tom@opengridcomputing.com> 650 M: Tom Tucker <tom@opengridcomputing.com>
651 M: Steve Wise <swise@opengridcomputing.com> 651 M: Steve Wise <swise@opengridcomputing.com>
652 L: linux-rdma@vger.kernel.org 652 L: linux-rdma@vger.kernel.org
653 S: Maintained 653 S: Maintained
654 F: drivers/infiniband/hw/amso1100/ 654 F: drivers/infiniband/hw/amso1100/
655 655
656 ANALOG DEVICES INC AD9389B DRIVER 656 ANALOG DEVICES INC AD9389B DRIVER
657 M: Hans Verkuil <hans.verkuil@cisco.com> 657 M: Hans Verkuil <hans.verkuil@cisco.com>
658 L: linux-media@vger.kernel.org 658 L: linux-media@vger.kernel.org
659 S: Maintained 659 S: Maintained
660 F: drivers/media/i2c/ad9389b* 660 F: drivers/media/i2c/ad9389b*
661 661
662 ANALOG DEVICES INC ADV7511 DRIVER 662 ANALOG DEVICES INC ADV7511 DRIVER
663 M: Hans Verkuil <hans.verkuil@cisco.com> 663 M: Hans Verkuil <hans.verkuil@cisco.com>
664 L: linux-media@vger.kernel.org 664 L: linux-media@vger.kernel.org
665 S: Maintained 665 S: Maintained
666 F: drivers/media/i2c/adv7511* 666 F: drivers/media/i2c/adv7511*
667 667
668 ANALOG DEVICES INC ADV7604 DRIVER 668 ANALOG DEVICES INC ADV7604 DRIVER
669 M: Hans Verkuil <hans.verkuil@cisco.com> 669 M: Hans Verkuil <hans.verkuil@cisco.com>
670 L: linux-media@vger.kernel.org 670 L: linux-media@vger.kernel.org
671 S: Maintained 671 S: Maintained
672 F: drivers/media/i2c/adv7604* 672 F: drivers/media/i2c/adv7604*
673 673
674 ANALOG DEVICES INC ADV7842 DRIVER 674 ANALOG DEVICES INC ADV7842 DRIVER
675 M: Hans Verkuil <hans.verkuil@cisco.com> 675 M: Hans Verkuil <hans.verkuil@cisco.com>
676 L: linux-media@vger.kernel.org 676 L: linux-media@vger.kernel.org
677 S: Maintained 677 S: Maintained
678 F: drivers/media/i2c/adv7842* 678 F: drivers/media/i2c/adv7842*
679 679
680 ANALOG DEVICES INC ASOC CODEC DRIVERS 680 ANALOG DEVICES INC ASOC CODEC DRIVERS
681 M: Lars-Peter Clausen <lars@metafoo.de> 681 M: Lars-Peter Clausen <lars@metafoo.de>
682 L: alsa-devel@alsa-project.org (moderated for non-subscribers) 682 L: alsa-devel@alsa-project.org (moderated for non-subscribers)
683 W: http://wiki.analog.com/ 683 W: http://wiki.analog.com/
684 W: http://ez.analog.com/community/linux-device-drivers 684 W: http://ez.analog.com/community/linux-device-drivers
685 S: Supported 685 S: Supported
686 F: sound/soc/codecs/adau* 686 F: sound/soc/codecs/adau*
687 F: sound/soc/codecs/adav* 687 F: sound/soc/codecs/adav*
688 F: sound/soc/codecs/ad1* 688 F: sound/soc/codecs/ad1*
689 F: sound/soc/codecs/ad7* 689 F: sound/soc/codecs/ad7*
690 F: sound/soc/codecs/ssm* 690 F: sound/soc/codecs/ssm*
691 F: sound/soc/codecs/sigmadsp.* 691 F: sound/soc/codecs/sigmadsp.*
692 692
693 ANALOG DEVICES INC ASOC DRIVERS 693 ANALOG DEVICES INC ASOC DRIVERS
694 L: adi-buildroot-devel@lists.sourceforge.net (moderated for non-subscribers) 694 L: adi-buildroot-devel@lists.sourceforge.net (moderated for non-subscribers)
695 L: alsa-devel@alsa-project.org (moderated for non-subscribers) 695 L: alsa-devel@alsa-project.org (moderated for non-subscribers)
696 W: http://blackfin.uclinux.org/ 696 W: http://blackfin.uclinux.org/
697 S: Supported 697 S: Supported
698 F: sound/soc/blackfin/* 698 F: sound/soc/blackfin/*
699 699
700 ANALOG DEVICES INC IIO DRIVERS 700 ANALOG DEVICES INC IIO DRIVERS
701 M: Lars-Peter Clausen <lars@metafoo.de> 701 M: Lars-Peter Clausen <lars@metafoo.de>
702 M: Michael Hennerich <Michael.Hennerich@analog.com> 702 M: Michael Hennerich <Michael.Hennerich@analog.com>
703 W: http://wiki.analog.com/ 703 W: http://wiki.analog.com/
704 W: http://ez.analog.com/community/linux-device-drivers 704 W: http://ez.analog.com/community/linux-device-drivers
705 S: Supported 705 S: Supported
706 F: drivers/iio/*/ad* 706 F: drivers/iio/*/ad*
707 X: drivers/iio/*/adjd* 707 X: drivers/iio/*/adjd*
708 F: drivers/staging/iio/*/ad* 708 F: drivers/staging/iio/*/ad*
709 F: staging/iio/trigger/iio-trig-bfin-timer.c 709 F: staging/iio/trigger/iio-trig-bfin-timer.c
710 710
711 AOA (Apple Onboard Audio) ALSA DRIVER 711 AOA (Apple Onboard Audio) ALSA DRIVER
712 M: Johannes Berg <johannes@sipsolutions.net> 712 M: Johannes Berg <johannes@sipsolutions.net>
713 L: linuxppc-dev@lists.ozlabs.org 713 L: linuxppc-dev@lists.ozlabs.org
714 L: alsa-devel@alsa-project.org (moderated for non-subscribers) 714 L: alsa-devel@alsa-project.org (moderated for non-subscribers)
715 S: Maintained 715 S: Maintained
716 F: sound/aoa/ 716 F: sound/aoa/
717 717
718 APM DRIVER 718 APM DRIVER
719 M: Jiri Kosina <jkosina@suse.cz> 719 M: Jiri Kosina <jkosina@suse.cz>
720 S: Odd fixes 720 S: Odd fixes
721 F: arch/x86/kernel/apm_32.c 721 F: arch/x86/kernel/apm_32.c
722 F: include/linux/apm_bios.h 722 F: include/linux/apm_bios.h
723 F: include/uapi/linux/apm_bios.h 723 F: include/uapi/linux/apm_bios.h
724 F: drivers/char/apm-emulation.c 724 F: drivers/char/apm-emulation.c
725 725
726 APPLE BCM5974 MULTITOUCH DRIVER 726 APPLE BCM5974 MULTITOUCH DRIVER
727 M: Henrik Rydberg <rydberg@bitmath.org> 727 M: Henrik Rydberg <rydberg@bitmath.org>
728 L: linux-input@vger.kernel.org 728 L: linux-input@vger.kernel.org
729 S: Odd fixes 729 S: Odd fixes
730 F: drivers/input/mouse/bcm5974.c 730 F: drivers/input/mouse/bcm5974.c
731 731
732 APPLE SMC DRIVER 732 APPLE SMC DRIVER
733 M: Henrik Rydberg <rydberg@bitmath.org> 733 M: Henrik Rydberg <rydberg@bitmath.org>
734 L: lm-sensors@lm-sensors.org 734 L: lm-sensors@lm-sensors.org
735 S: Odd fixes 735 S: Odd fixes
736 F: drivers/hwmon/applesmc.c 736 F: drivers/hwmon/applesmc.c
737 737
738 APPLETALK NETWORK LAYER 738 APPLETALK NETWORK LAYER
739 M: Arnaldo Carvalho de Melo <acme@ghostprotocols.net> 739 M: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
740 S: Maintained 740 S: Maintained
741 F: drivers/net/appletalk/ 741 F: drivers/net/appletalk/
742 F: net/appletalk/ 742 F: net/appletalk/
743 743
744 APPLIED MICRO (APM) X-GENE SOC ETHERNET DRIVER 744 APPLIED MICRO (APM) X-GENE SOC ETHERNET DRIVER
745 M: Iyappan Subramanian <isubramanian@apm.com> 745 M: Iyappan Subramanian <isubramanian@apm.com>
746 M: Keyur Chudgar <kchudgar@apm.com> 746 M: Keyur Chudgar <kchudgar@apm.com>
747 S: Supported 747 S: Supported
748 F: drivers/net/ethernet/apm/xgene/ 748 F: drivers/net/ethernet/apm/xgene/
749 F: Documentation/devicetree/bindings/net/apm-xgene-enet.txt 749 F: Documentation/devicetree/bindings/net/apm-xgene-enet.txt
750 750
751 APTINA CAMERA SENSOR PLL 751 APTINA CAMERA SENSOR PLL
752 M: Laurent Pinchart <Laurent.pinchart@ideasonboard.com> 752 M: Laurent Pinchart <Laurent.pinchart@ideasonboard.com>
753 L: linux-media@vger.kernel.org 753 L: linux-media@vger.kernel.org
754 S: Maintained 754 S: Maintained
755 F: drivers/media/i2c/aptina-pll.* 755 F: drivers/media/i2c/aptina-pll.*
756 756
757 ARASAN COMPACT FLASH PATA CONTROLLER 757 ARASAN COMPACT FLASH PATA CONTROLLER
758 M: Viresh Kumar <viresh.linux@gmail.com> 758 M: Viresh Kumar <viresh.linux@gmail.com>
759 L: linux-ide@vger.kernel.org 759 L: linux-ide@vger.kernel.org
760 S: Maintained 760 S: Maintained
761 F: include/linux/pata_arasan_cf_data.h 761 F: include/linux/pata_arasan_cf_data.h
762 F: drivers/ata/pata_arasan_cf.c 762 F: drivers/ata/pata_arasan_cf.c
763 763
764 ARC FRAMEBUFFER DRIVER 764 ARC FRAMEBUFFER DRIVER
765 M: Jaya Kumar <jayalk@intworks.biz> 765 M: Jaya Kumar <jayalk@intworks.biz>
766 S: Maintained 766 S: Maintained
767 F: drivers/video/fbdev/arcfb.c 767 F: drivers/video/fbdev/arcfb.c
768 F: drivers/video/fbdev/core/fb_defio.c 768 F: drivers/video/fbdev/core/fb_defio.c
769 769
770 ARM MFM AND FLOPPY DRIVERS 770 ARM MFM AND FLOPPY DRIVERS
771 M: Ian Molton <spyro@f2s.com> 771 M: Ian Molton <spyro@f2s.com>
772 S: Maintained 772 S: Maintained
773 F: arch/arm/lib/floppydma.S 773 F: arch/arm/lib/floppydma.S
774 F: arch/arm/include/asm/floppy.h 774 F: arch/arm/include/asm/floppy.h
775 775
776 ARM PMU PROFILING AND DEBUGGING 776 ARM PMU PROFILING AND DEBUGGING
777 M: Will Deacon <will.deacon@arm.com> 777 M: Will Deacon <will.deacon@arm.com>
778 S: Maintained 778 S: Maintained
779 F: arch/arm/kernel/perf_event* 779 F: arch/arm/kernel/perf_event*
780 F: arch/arm/oprofile/common.c 780 F: arch/arm/oprofile/common.c
781 F: arch/arm/include/asm/pmu.h 781 F: arch/arm/include/asm/pmu.h
782 F: arch/arm/kernel/hw_breakpoint.c 782 F: arch/arm/kernel/hw_breakpoint.c
783 F: arch/arm/include/asm/hw_breakpoint.h 783 F: arch/arm/include/asm/hw_breakpoint.h
784 784
785 ARM PORT 785 ARM PORT
786 M: Russell King <linux@arm.linux.org.uk> 786 M: Russell King <linux@arm.linux.org.uk>
787 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 787 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
788 W: http://www.arm.linux.org.uk/ 788 W: http://www.arm.linux.org.uk/
789 S: Maintained 789 S: Maintained
790 F: arch/arm/ 790 F: arch/arm/
791 791
792 ARM SUB-ARCHITECTURES 792 ARM SUB-ARCHITECTURES
793 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 793 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
794 S: Maintained 794 S: Maintained
795 F: arch/arm/mach-*/ 795 F: arch/arm/mach-*/
796 F: arch/arm/plat-*/ 796 F: arch/arm/plat-*/
797 T: git git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc.git 797 T: git git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc.git
798 798
799 ARM PRIMECELL AACI PL041 DRIVER 799 ARM PRIMECELL AACI PL041 DRIVER
800 M: Russell King <linux@arm.linux.org.uk> 800 M: Russell King <linux@arm.linux.org.uk>
801 S: Maintained 801 S: Maintained
802 F: sound/arm/aaci.* 802 F: sound/arm/aaci.*
803 803
804 ARM PRIMECELL CLCD PL110 DRIVER 804 ARM PRIMECELL CLCD PL110 DRIVER
805 M: Russell King <linux@arm.linux.org.uk> 805 M: Russell King <linux@arm.linux.org.uk>
806 S: Maintained 806 S: Maintained
807 F: drivers/video/fbdev/amba-clcd.* 807 F: drivers/video/fbdev/amba-clcd.*
808 808
809 ARM PRIMECELL KMI PL050 DRIVER 809 ARM PRIMECELL KMI PL050 DRIVER
810 M: Russell King <linux@arm.linux.org.uk> 810 M: Russell King <linux@arm.linux.org.uk>
811 S: Maintained 811 S: Maintained
812 F: drivers/input/serio/ambakmi.* 812 F: drivers/input/serio/ambakmi.*
813 F: include/linux/amba/kmi.h 813 F: include/linux/amba/kmi.h
814 814
815 ARM PRIMECELL MMCI PL180/1 DRIVER 815 ARM PRIMECELL MMCI PL180/1 DRIVER
816 M: Russell King <linux@arm.linux.org.uk> 816 M: Russell King <linux@arm.linux.org.uk>
817 S: Maintained 817 S: Maintained
818 F: drivers/mmc/host/mmci.* 818 F: drivers/mmc/host/mmci.*
819 F: include/linux/amba/mmci.h 819 F: include/linux/amba/mmci.h
820 820
821 ARM PRIMECELL UART PL010 AND PL011 DRIVERS 821 ARM PRIMECELL UART PL010 AND PL011 DRIVERS
822 M: Russell King <linux@arm.linux.org.uk> 822 M: Russell King <linux@arm.linux.org.uk>
823 S: Maintained 823 S: Maintained
824 F: drivers/tty/serial/amba-pl01*.c 824 F: drivers/tty/serial/amba-pl01*.c
825 F: include/linux/amba/serial.h 825 F: include/linux/amba/serial.h
826 826
827 ARM PRIMECELL BUS SUPPORT 827 ARM PRIMECELL BUS SUPPORT
828 M: Russell King <linux@arm.linux.org.uk> 828 M: Russell King <linux@arm.linux.org.uk>
829 S: Maintained 829 S: Maintained
830 F: drivers/amba/ 830 F: drivers/amba/
831 F: include/linux/amba/bus.h 831 F: include/linux/amba/bus.h
832 832
833 ARM/ADS SPHERE MACHINE SUPPORT 833 ARM/ADS SPHERE MACHINE SUPPORT
834 M: Lennert Buytenhek <kernel@wantstofly.org> 834 M: Lennert Buytenhek <kernel@wantstofly.org>
835 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 835 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
836 S: Maintained 836 S: Maintained
837 837
838 ARM/AFEB9260 MACHINE SUPPORT 838 ARM/AFEB9260 MACHINE SUPPORT
839 M: Sergey Lapin <slapin@ossfans.org> 839 M: Sergey Lapin <slapin@ossfans.org>
840 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 840 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
841 S: Maintained 841 S: Maintained
842 842
843 ARM/AJECO 1ARM MACHINE SUPPORT 843 ARM/AJECO 1ARM MACHINE SUPPORT
844 M: Lennert Buytenhek <kernel@wantstofly.org> 844 M: Lennert Buytenhek <kernel@wantstofly.org>
845 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 845 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
846 S: Maintained 846 S: Maintained
847 847
848 ARM/Allwinner A1X SoC support 848 ARM/Allwinner A1X SoC support
849 M: Maxime Ripard <maxime.ripard@free-electrons.com> 849 M: Maxime Ripard <maxime.ripard@free-electrons.com>
850 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 850 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
851 S: Maintained 851 S: Maintained
852 N: sun[x4567]i 852 N: sun[x4567]i
853 853
854 ARM/Allwinner SoC Clock Support 854 ARM/Allwinner SoC Clock Support
855 M: Emilio Lรณpez <emilio@elopez.com.ar> 855 M: Emilio Lรณpez <emilio@elopez.com.ar>
856 S: Maintained 856 S: Maintained
857 F: drivers/clk/sunxi/ 857 F: drivers/clk/sunxi/
858 858
859 ARM/Amlogic MesonX SoC support 859 ARM/Amlogic MesonX SoC support
860 M: Carlo Caione <carlo@caione.org> 860 M: Carlo Caione <carlo@caione.org>
861 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 861 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
862 S: Maintained 862 S: Maintained
863 F: drivers/media/rc/meson-ir.c 863 F: drivers/media/rc/meson-ir.c
864 N: meson[x68] 864 N: meson[x68]
865 865
866 ARM/ATMEL AT91RM9200 AND AT91SAM ARM ARCHITECTURES 866 ARM/ATMEL AT91RM9200 AND AT91SAM ARM ARCHITECTURES
867 M: Andrew Victor <linux@maxim.org.za> 867 M: Andrew Victor <linux@maxim.org.za>
868 M: Nicolas Ferre <nicolas.ferre@atmel.com> 868 M: Nicolas Ferre <nicolas.ferre@atmel.com>
869 M: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com> 869 M: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>
870 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 870 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
871 W: http://maxim.org.za/at91_26.html 871 W: http://maxim.org.za/at91_26.html
872 W: http://www.linux4sam.org 872 W: http://www.linux4sam.org
873 S: Supported 873 S: Supported
874 F: arch/arm/mach-at91/ 874 F: arch/arm/mach-at91/
875 F: include/soc/at91/ 875 F: include/soc/at91/
876 F: arch/arm/boot/dts/at91*.dts 876 F: arch/arm/boot/dts/at91*.dts
877 F: arch/arm/boot/dts/at91*.dtsi 877 F: arch/arm/boot/dts/at91*.dtsi
878 F: arch/arm/boot/dts/sama*.dts 878 F: arch/arm/boot/dts/sama*.dts
879 F: arch/arm/boot/dts/sama*.dtsi 879 F: arch/arm/boot/dts/sama*.dtsi
880 880
881 ARM/ATMEL AT91 Clock Support 881 ARM/ATMEL AT91 Clock Support
882 M: Boris Brezillon <boris.brezillon@free-electrons.com> 882 M: Boris Brezillon <boris.brezillon@free-electrons.com>
883 S: Maintained 883 S: Maintained
884 F: drivers/clk/at91 884 F: drivers/clk/at91
885 885
886 ARM/CALXEDA HIGHBANK ARCHITECTURE 886 ARM/CALXEDA HIGHBANK ARCHITECTURE
887 M: Rob Herring <robh@kernel.org> 887 M: Rob Herring <robh@kernel.org>
888 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 888 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
889 S: Maintained 889 S: Maintained
890 F: arch/arm/mach-highbank/ 890 F: arch/arm/mach-highbank/
891 891
892 ARM/CAVIUM NETWORKS CNS3XXX MACHINE SUPPORT 892 ARM/CAVIUM NETWORKS CNS3XXX MACHINE SUPPORT
893 M: Krzysztof Halasa <khalasa@piap.pl> 893 M: Krzysztof Halasa <khalasa@piap.pl>
894 S: Maintained 894 S: Maintained
895 F: arch/arm/mach-cns3xxx/ 895 F: arch/arm/mach-cns3xxx/
896 896
897 ARM/CIRRUS LOGIC CLPS711X ARM ARCHITECTURE 897 ARM/CIRRUS LOGIC CLPS711X ARM ARCHITECTURE
898 M: Alexander Shiyan <shc_work@mail.ru> 898 M: Alexander Shiyan <shc_work@mail.ru>
899 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 899 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
900 S: Odd Fixes 900 S: Odd Fixes
901 N: clps711x 901 N: clps711x
902 902
903 ARM/CIRRUS LOGIC EP93XX ARM ARCHITECTURE 903 ARM/CIRRUS LOGIC EP93XX ARM ARCHITECTURE
904 M: Hartley Sweeten <hsweeten@visionengravers.com> 904 M: Hartley Sweeten <hsweeten@visionengravers.com>
905 M: Ryan Mallon <rmallon@gmail.com> 905 M: Ryan Mallon <rmallon@gmail.com>
906 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 906 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
907 S: Maintained 907 S: Maintained
908 F: arch/arm/mach-ep93xx/ 908 F: arch/arm/mach-ep93xx/
909 F: arch/arm/mach-ep93xx/include/mach/ 909 F: arch/arm/mach-ep93xx/include/mach/
910 910
911 ARM/CIRRUS LOGIC EDB9315A MACHINE SUPPORT 911 ARM/CIRRUS LOGIC EDB9315A MACHINE SUPPORT
912 M: Lennert Buytenhek <kernel@wantstofly.org> 912 M: Lennert Buytenhek <kernel@wantstofly.org>
913 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 913 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
914 S: Maintained 914 S: Maintained
915 915
916 ARM/CLKDEV SUPPORT 916 ARM/CLKDEV SUPPORT
917 M: Russell King <linux@arm.linux.org.uk> 917 M: Russell King <linux@arm.linux.org.uk>
918 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 918 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
919 S: Maintained 919 S: Maintained
920 F: arch/arm/include/asm/clkdev.h 920 F: arch/arm/include/asm/clkdev.h
921 F: drivers/clk/clkdev.c 921 F: drivers/clk/clkdev.c
922 922
923 ARM/COMPULAB CM-X270/EM-X270 and CM-X300 MACHINE SUPPORT 923 ARM/COMPULAB CM-X270/EM-X270 and CM-X300 MACHINE SUPPORT
924 M: Mike Rapoport <mike@compulab.co.il> 924 M: Mike Rapoport <mike@compulab.co.il>
925 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 925 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
926 S: Maintained 926 S: Maintained
927 927
928 ARM/CONTEC MICRO9 MACHINE SUPPORT 928 ARM/CONTEC MICRO9 MACHINE SUPPORT
929 M: Hubert Feurstein <hubert.feurstein@contec.at> 929 M: Hubert Feurstein <hubert.feurstein@contec.at>
930 S: Maintained 930 S: Maintained
931 F: arch/arm/mach-ep93xx/micro9.c 931 F: arch/arm/mach-ep93xx/micro9.c
932 932
933 ARM/CORESIGHT FRAMEWORK AND DRIVERS 933 ARM/CORESIGHT FRAMEWORK AND DRIVERS
934 M: Mathieu Poirier <mathieu.poirier@linaro.org> 934 M: Mathieu Poirier <mathieu.poirier@linaro.org>
935 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 935 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
936 S: Maintained 936 S: Maintained
937 F: drivers/coresight/* 937 F: drivers/coresight/*
938 F: Documentation/trace/coresight.txt 938 F: Documentation/trace/coresight.txt
939 F: Documentation/devicetree/bindings/arm/coresight.txt 939 F: Documentation/devicetree/bindings/arm/coresight.txt
940 F: Documentation/ABI/testing/sysfs-bus-coresight-devices-* 940 F: Documentation/ABI/testing/sysfs-bus-coresight-devices-*
941 941
942 ARM/CORGI MACHINE SUPPORT 942 ARM/CORGI MACHINE SUPPORT
943 M: Richard Purdie <rpurdie@rpsys.net> 943 M: Richard Purdie <rpurdie@rpsys.net>
944 S: Maintained 944 S: Maintained
945 945
946 ARM/CORTINA SYSTEMS GEMINI ARM ARCHITECTURE 946 ARM/CORTINA SYSTEMS GEMINI ARM ARCHITECTURE
947 M: Hans Ulli Kroll <ulli.kroll@googlemail.com> 947 M: Hans Ulli Kroll <ulli.kroll@googlemail.com>
948 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 948 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
949 T: git git://git.berlios.de/gemini-board 949 T: git git://git.berlios.de/gemini-board
950 S: Maintained 950 S: Maintained
951 F: arch/arm/mach-gemini/ 951 F: arch/arm/mach-gemini/
952 952
953 ARM/CSR SIRFPRIMA2 MACHINE SUPPORT 953 ARM/CSR SIRFPRIMA2 MACHINE SUPPORT
954 M: Barry Song <baohua@kernel.org> 954 M: Barry Song <baohua@kernel.org>
955 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 955 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
956 T: git git://git.kernel.org/pub/scm/linux/kernel/git/baohua/linux.git 956 T: git git://git.kernel.org/pub/scm/linux/kernel/git/baohua/linux.git
957 S: Maintained 957 S: Maintained
958 F: arch/arm/mach-prima2/ 958 F: arch/arm/mach-prima2/
959 F: drivers/clk/sirf/ 959 F: drivers/clk/sirf/
960 F: drivers/clocksource/timer-prima2.c 960 F: drivers/clocksource/timer-prima2.c
961 F: drivers/clocksource/timer-marco.c 961 F: drivers/clocksource/timer-marco.c
962 N: [^a-z]sirf 962 N: [^a-z]sirf
963 963
964 ARM/EBSA110 MACHINE SUPPORT 964 ARM/EBSA110 MACHINE SUPPORT
965 M: Russell King <linux@arm.linux.org.uk> 965 M: Russell King <linux@arm.linux.org.uk>
966 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 966 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
967 W: http://www.arm.linux.org.uk/ 967 W: http://www.arm.linux.org.uk/
968 S: Maintained 968 S: Maintained
969 F: arch/arm/mach-ebsa110/ 969 F: arch/arm/mach-ebsa110/
970 F: drivers/net/ethernet/amd/am79c961a.* 970 F: drivers/net/ethernet/amd/am79c961a.*
971 971
972 ARM/ENERGY MICRO (SILICON LABS) EFM32 SUPPORT 972 ARM/ENERGY MICRO (SILICON LABS) EFM32 SUPPORT
973 M: Uwe Kleine-Kรถnig <kernel@pengutronix.de> 973 M: Uwe Kleine-Kรถnig <kernel@pengutronix.de>
974 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 974 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
975 S: Maintained 975 S: Maintained
976 N: efm32 976 N: efm32
977 977
978 ARM/EZX SMARTPHONES (A780, A910, A1200, E680, ROKR E2 and ROKR E6) 978 ARM/EZX SMARTPHONES (A780, A910, A1200, E680, ROKR E2 and ROKR E6)
979 M: Daniel Ribeiro <drwyrm@gmail.com> 979 M: Daniel Ribeiro <drwyrm@gmail.com>
980 M: Stefan Schmidt <stefan@openezx.org> 980 M: Stefan Schmidt <stefan@openezx.org>
981 M: Harald Welte <laforge@openezx.org> 981 M: Harald Welte <laforge@openezx.org>
982 L: openezx-devel@lists.openezx.org (moderated for non-subscribers) 982 L: openezx-devel@lists.openezx.org (moderated for non-subscribers)
983 W: http://www.openezx.org/ 983 W: http://www.openezx.org/
984 S: Maintained 984 S: Maintained
985 T: topgit git://git.openezx.org/openezx.git 985 T: topgit git://git.openezx.org/openezx.git
986 F: arch/arm/mach-pxa/ezx.c 986 F: arch/arm/mach-pxa/ezx.c
987 987
988 ARM/FARADAY FA526 PORT 988 ARM/FARADAY FA526 PORT
989 M: Hans Ulli Kroll <ulli.kroll@googlemail.com> 989 M: Hans Ulli Kroll <ulli.kroll@googlemail.com>
990 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 990 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
991 S: Maintained 991 S: Maintained
992 T: git git://git.berlios.de/gemini-board 992 T: git git://git.berlios.de/gemini-board
993 F: arch/arm/mm/*-fa* 993 F: arch/arm/mm/*-fa*
994 994
995 ARM/FOOTBRIDGE ARCHITECTURE 995 ARM/FOOTBRIDGE ARCHITECTURE
996 M: Russell King <linux@arm.linux.org.uk> 996 M: Russell King <linux@arm.linux.org.uk>
997 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 997 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
998 W: http://www.arm.linux.org.uk/ 998 W: http://www.arm.linux.org.uk/
999 S: Maintained 999 S: Maintained
1000 F: arch/arm/include/asm/hardware/dec21285.h 1000 F: arch/arm/include/asm/hardware/dec21285.h
1001 F: arch/arm/mach-footbridge/ 1001 F: arch/arm/mach-footbridge/
1002 1002
1003 ARM/FREESCALE IMX / MXC ARM ARCHITECTURE 1003 ARM/FREESCALE IMX / MXC ARM ARCHITECTURE
1004 M: Shawn Guo <shawn.guo@linaro.org> 1004 M: Shawn Guo <shawn.guo@linaro.org>
1005 M: Sascha Hauer <kernel@pengutronix.de> 1005 M: Sascha Hauer <kernel@pengutronix.de>
1006 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1006 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1007 S: Maintained 1007 S: Maintained
1008 T: git git://git.kernel.org/pub/scm/linux/kernel/git/shawnguo/linux.git 1008 T: git git://git.kernel.org/pub/scm/linux/kernel/git/shawnguo/linux.git
1009 F: arch/arm/mach-imx/ 1009 F: arch/arm/mach-imx/
1010 F: arch/arm/mach-mxs/ 1010 F: arch/arm/mach-mxs/
1011 F: arch/arm/boot/dts/imx* 1011 F: arch/arm/boot/dts/imx*
1012 F: arch/arm/configs/imx*_defconfig 1012 F: arch/arm/configs/imx*_defconfig
1013 1013
1014 ARM/GLOMATION GESBC9312SX MACHINE SUPPORT 1014 ARM/GLOMATION GESBC9312SX MACHINE SUPPORT
1015 M: Lennert Buytenhek <kernel@wantstofly.org> 1015 M: Lennert Buytenhek <kernel@wantstofly.org>
1016 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1016 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1017 S: Maintained 1017 S: Maintained
1018 1018
1019 ARM/GUMSTIX MACHINE SUPPORT 1019 ARM/GUMSTIX MACHINE SUPPORT
1020 M: Steve Sakoman <sakoman@gmail.com> 1020 M: Steve Sakoman <sakoman@gmail.com>
1021 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1021 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1022 S: Maintained 1022 S: Maintained
1023 1023
1024 ARM/H4700 (HP IPAQ HX4700) MACHINE SUPPORT 1024 ARM/H4700 (HP IPAQ HX4700) MACHINE SUPPORT
1025 M: Philipp Zabel <philipp.zabel@gmail.com> 1025 M: Philipp Zabel <philipp.zabel@gmail.com>
1026 M: Paul Parsons <lost.distance@yahoo.com> 1026 M: Paul Parsons <lost.distance@yahoo.com>
1027 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1027 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1028 S: Maintained 1028 S: Maintained
1029 F: arch/arm/mach-pxa/hx4700.c 1029 F: arch/arm/mach-pxa/hx4700.c
1030 F: arch/arm/mach-pxa/include/mach/hx4700.h 1030 F: arch/arm/mach-pxa/include/mach/hx4700.h
1031 F: sound/soc/pxa/hx4700.c 1031 F: sound/soc/pxa/hx4700.c
1032 1032
1033 ARM/HISILICON SOC SUPPORT 1033 ARM/HISILICON SOC SUPPORT
1034 M: Wei Xu <xuwei5@hisilicon.com> 1034 M: Wei Xu <xuwei5@hisilicon.com>
1035 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1035 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1036 W: http://www.hisilicon.com 1036 W: http://www.hisilicon.com
1037 S: Supported 1037 S: Supported
1038 T: git git://github.com/hisilicon/linux-hisi.git 1038 T: git git://github.com/hisilicon/linux-hisi.git
1039 F: arch/arm/mach-hisi/ 1039 F: arch/arm/mach-hisi/
1040 1040
1041 ARM/HP JORNADA 7XX MACHINE SUPPORT 1041 ARM/HP JORNADA 7XX MACHINE SUPPORT
1042 M: Kristoffer Ericson <kristoffer.ericson@gmail.com> 1042 M: Kristoffer Ericson <kristoffer.ericson@gmail.com>
1043 W: www.jlime.com 1043 W: www.jlime.com
1044 S: Maintained 1044 S: Maintained
1045 T: git git://git.kernel.org/pub/scm/linux/kernel/git/kristoffer/linux-hpc.git 1045 T: git git://git.kernel.org/pub/scm/linux/kernel/git/kristoffer/linux-hpc.git
1046 F: arch/arm/mach-sa1100/jornada720.c 1046 F: arch/arm/mach-sa1100/jornada720.c
1047 F: arch/arm/mach-sa1100/include/mach/jornada720.h 1047 F: arch/arm/mach-sa1100/include/mach/jornada720.h
1048 1048
1049 ARM/IGEP MACHINE SUPPORT 1049 ARM/IGEP MACHINE SUPPORT
1050 M: Enric Balletbo i Serra <eballetbo@gmail.com> 1050 M: Enric Balletbo i Serra <eballetbo@gmail.com>
1051 M: Javier Martinez Canillas <javier@dowhile0.org> 1051 M: Javier Martinez Canillas <javier@dowhile0.org>
1052 L: linux-omap@vger.kernel.org 1052 L: linux-omap@vger.kernel.org
1053 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1053 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1054 S: Maintained 1054 S: Maintained
1055 F: arch/arm/boot/dts/omap3-igep* 1055 F: arch/arm/boot/dts/omap3-igep*
1056 1056
1057 ARM/INCOME PXA270 SUPPORT 1057 ARM/INCOME PXA270 SUPPORT
1058 M: Marek Vasut <marek.vasut@gmail.com> 1058 M: Marek Vasut <marek.vasut@gmail.com>
1059 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1059 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1060 S: Maintained 1060 S: Maintained
1061 F: arch/arm/mach-pxa/colibri-pxa270-income.c 1061 F: arch/arm/mach-pxa/colibri-pxa270-income.c
1062 1062
1063 ARM/INTEL IOP32X ARM ARCHITECTURE 1063 ARM/INTEL IOP32X ARM ARCHITECTURE
1064 M: Lennert Buytenhek <kernel@wantstofly.org> 1064 M: Lennert Buytenhek <kernel@wantstofly.org>
1065 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1065 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1066 S: Maintained 1066 S: Maintained
1067 1067
1068 ARM/INTEL IOP33X ARM ARCHITECTURE 1068 ARM/INTEL IOP33X ARM ARCHITECTURE
1069 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1069 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1070 S: Orphan 1070 S: Orphan
1071 1071
1072 ARM/INTEL IOP13XX ARM ARCHITECTURE 1072 ARM/INTEL IOP13XX ARM ARCHITECTURE
1073 M: Lennert Buytenhek <kernel@wantstofly.org> 1073 M: Lennert Buytenhek <kernel@wantstofly.org>
1074 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1074 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1075 S: Maintained 1075 S: Maintained
1076 1076
1077 ARM/INTEL IQ81342EX MACHINE SUPPORT 1077 ARM/INTEL IQ81342EX MACHINE SUPPORT
1078 M: Lennert Buytenhek <kernel@wantstofly.org> 1078 M: Lennert Buytenhek <kernel@wantstofly.org>
1079 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1079 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1080 S: Maintained 1080 S: Maintained
1081 1081
1082 ARM/INTEL IXDP2850 MACHINE SUPPORT 1082 ARM/INTEL IXDP2850 MACHINE SUPPORT
1083 M: Lennert Buytenhek <kernel@wantstofly.org> 1083 M: Lennert Buytenhek <kernel@wantstofly.org>
1084 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1084 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1085 S: Maintained 1085 S: Maintained
1086 1086
1087 ARM/INTEL IXP4XX ARM ARCHITECTURE 1087 ARM/INTEL IXP4XX ARM ARCHITECTURE
1088 M: Imre Kaloz <kaloz@openwrt.org> 1088 M: Imre Kaloz <kaloz@openwrt.org>
1089 M: Krzysztof Halasa <khalasa@piap.pl> 1089 M: Krzysztof Halasa <khalasa@piap.pl>
1090 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1090 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1091 S: Maintained 1091 S: Maintained
1092 F: arch/arm/mach-ixp4xx/ 1092 F: arch/arm/mach-ixp4xx/
1093 1093
1094 ARM/INTEL RESEARCH IMOTE/STARGATE 2 MACHINE SUPPORT 1094 ARM/INTEL RESEARCH IMOTE/STARGATE 2 MACHINE SUPPORT
1095 M: Jonathan Cameron <jic23@cam.ac.uk> 1095 M: Jonathan Cameron <jic23@cam.ac.uk>
1096 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1096 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1097 S: Maintained 1097 S: Maintained
1098 F: arch/arm/mach-pxa/stargate2.c 1098 F: arch/arm/mach-pxa/stargate2.c
1099 F: drivers/pcmcia/pxa2xx_stargate2.c 1099 F: drivers/pcmcia/pxa2xx_stargate2.c
1100 1100
1101 ARM/INTEL XSC3 (MANZANO) ARM CORE 1101 ARM/INTEL XSC3 (MANZANO) ARM CORE
1102 M: Lennert Buytenhek <kernel@wantstofly.org> 1102 M: Lennert Buytenhek <kernel@wantstofly.org>
1103 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1103 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1104 S: Maintained 1104 S: Maintained
1105 1105
1106 ARM/IP FABRICS DOUBLE ESPRESSO MACHINE SUPPORT 1106 ARM/IP FABRICS DOUBLE ESPRESSO MACHINE SUPPORT
1107 M: Lennert Buytenhek <kernel@wantstofly.org> 1107 M: Lennert Buytenhek <kernel@wantstofly.org>
1108 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1108 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1109 S: Maintained 1109 S: Maintained
1110 1110
1111 ARM/TEXAS INSTRUMENT KEYSTONE ARCHITECTURE 1111 ARM/TEXAS INSTRUMENT KEYSTONE ARCHITECTURE
1112 M: Santosh Shilimkar <ssantosh@kernel.org> 1112 M: Santosh Shilimkar <ssantosh@kernel.org>
1113 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1113 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1114 S: Maintained 1114 S: Maintained
1115 F: arch/arm/mach-keystone/ 1115 F: arch/arm/mach-keystone/
1116 T: git git://git.kernel.org/pub/scm/linux/kernel/git/ssantosh/linux-keystone.git 1116 T: git git://git.kernel.org/pub/scm/linux/kernel/git/ssantosh/linux-keystone.git
1117 1117
1118 ARM/TEXAS INSTRUMENT KEYSTONE CLOCK FRAMEWORK 1118 ARM/TEXAS INSTRUMENT KEYSTONE CLOCK FRAMEWORK
1119 M: Santosh Shilimkar <ssantosh@kernel.org> 1119 M: Santosh Shilimkar <ssantosh@kernel.org>
1120 L: linux-kernel@vger.kernel.org 1120 L: linux-kernel@vger.kernel.org
1121 S: Maintained 1121 S: Maintained
1122 F: drivers/clk/keystone/ 1122 F: drivers/clk/keystone/
1123 1123
1124 ARM/TEXAS INSTRUMENT KEYSTONE ClOCKSOURCE 1124 ARM/TEXAS INSTRUMENT KEYSTONE ClOCKSOURCE
1125 M: Santosh Shilimkar <ssantosh@kernel.org> 1125 M: Santosh Shilimkar <ssantosh@kernel.org>
1126 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1126 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1127 L: linux-kernel@vger.kernel.org 1127 L: linux-kernel@vger.kernel.org
1128 S: Maintained 1128 S: Maintained
1129 F: drivers/clocksource/timer-keystone.c 1129 F: drivers/clocksource/timer-keystone.c
1130 1130
1131 ARM/TEXAS INSTRUMENT KEYSTONE RESET DRIVER 1131 ARM/TEXAS INSTRUMENT KEYSTONE RESET DRIVER
1132 M: Santosh Shilimkar <ssantosh@kernel.org> 1132 M: Santosh Shilimkar <ssantosh@kernel.org>
1133 L: linux-kernel@vger.kernel.org 1133 L: linux-kernel@vger.kernel.org
1134 S: Maintained 1134 S: Maintained
1135 F: drivers/power/reset/keystone-reset.c 1135 F: drivers/power/reset/keystone-reset.c
1136 1136
1137 ARM/TEXAS INSTRUMENT AEMIF/EMIF DRIVERS 1137 ARM/TEXAS INSTRUMENT AEMIF/EMIF DRIVERS
1138 M: Santosh Shilimkar <ssantosh@kernel.org> 1138 M: Santosh Shilimkar <ssantosh@kernel.org>
1139 L: linux-kernel@vger.kernel.org 1139 L: linux-kernel@vger.kernel.org
1140 S: Maintained 1140 S: Maintained
1141 F: drivers/memory/*emif* 1141 F: drivers/memory/*emif*
1142 1142
1143 ARM/LOGICPD PXA270 MACHINE SUPPORT 1143 ARM/LOGICPD PXA270 MACHINE SUPPORT
1144 M: Lennert Buytenhek <kernel@wantstofly.org> 1144 M: Lennert Buytenhek <kernel@wantstofly.org>
1145 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1145 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1146 S: Maintained 1146 S: Maintained
1147 1147
1148 ARM/MAGICIAN MACHINE SUPPORT 1148 ARM/MAGICIAN MACHINE SUPPORT
1149 M: Philipp Zabel <philipp.zabel@gmail.com> 1149 M: Philipp Zabel <philipp.zabel@gmail.com>
1150 S: Maintained 1150 S: Maintained
1151 1151
1152 ARM/Marvell Armada 370 and Armada XP SOC support 1152 ARM/Marvell Armada 370 and Armada XP SOC support
1153 M: Jason Cooper <jason@lakedaemon.net> 1153 M: Jason Cooper <jason@lakedaemon.net>
1154 M: Andrew Lunn <andrew@lunn.ch> 1154 M: Andrew Lunn <andrew@lunn.ch>
1155 M: Gregory Clement <gregory.clement@free-electrons.com> 1155 M: Gregory Clement <gregory.clement@free-electrons.com>
1156 M: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com> 1156 M: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
1157 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1157 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1158 S: Maintained 1158 S: Maintained
1159 F: arch/arm/mach-mvebu/ 1159 F: arch/arm/mach-mvebu/
1160 1160
1161 ARM/Marvell Berlin SoC support 1161 ARM/Marvell Berlin SoC support
1162 M: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com> 1162 M: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
1163 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1163 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1164 S: Maintained 1164 S: Maintained
1165 F: arch/arm/mach-berlin/ 1165 F: arch/arm/mach-berlin/
1166 1166
1167 ARM/Marvell Dove/MV78xx0/Orion SOC support 1167 ARM/Marvell Dove/MV78xx0/Orion SOC support
1168 M: Jason Cooper <jason@lakedaemon.net> 1168 M: Jason Cooper <jason@lakedaemon.net>
1169 M: Andrew Lunn <andrew@lunn.ch> 1169 M: Andrew Lunn <andrew@lunn.ch>
1170 M: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com> 1170 M: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
1171 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1171 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1172 S: Maintained 1172 S: Maintained
1173 F: arch/arm/mach-dove/ 1173 F: arch/arm/mach-dove/
1174 F: arch/arm/mach-mv78xx0/ 1174 F: arch/arm/mach-mv78xx0/
1175 F: arch/arm/mach-orion5x/ 1175 F: arch/arm/mach-orion5x/
1176 F: arch/arm/plat-orion/ 1176 F: arch/arm/plat-orion/
1177 1177
1178 ARM/Orion SoC/Technologic Systems TS-78xx platform support 1178 ARM/Orion SoC/Technologic Systems TS-78xx platform support
1179 M: Alexander Clouter <alex@digriz.org.uk> 1179 M: Alexander Clouter <alex@digriz.org.uk>
1180 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1180 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1181 W: http://www.digriz.org.uk/ts78xx/kernel 1181 W: http://www.digriz.org.uk/ts78xx/kernel
1182 S: Maintained 1182 S: Maintained
1183 F: arch/arm/mach-orion5x/ts78xx-* 1183 F: arch/arm/mach-orion5x/ts78xx-*
1184 1184
1185 ARM/Mediatek SoC support 1185 ARM/Mediatek SoC support
1186 M: Matthias Brugger <matthias.bgg@gmail.com> 1186 M: Matthias Brugger <matthias.bgg@gmail.com>
1187 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1187 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1188 S: Maintained 1188 S: Maintained
1189 F: arch/arm/boot/dts/mt6* 1189 F: arch/arm/boot/dts/mt6*
1190 F: arch/arm/boot/dts/mt8* 1190 F: arch/arm/boot/dts/mt8*
1191 F: arch/arm/mach-mediatek/ 1191 F: arch/arm/mach-mediatek/
1192 N: mtk 1192 N: mtk
1193 K: mediatek 1193 K: mediatek
1194 1194
1195 ARM/MICREL KS8695 ARCHITECTURE 1195 ARM/MICREL KS8695 ARCHITECTURE
1196 M: Greg Ungerer <gerg@uclinux.org> 1196 M: Greg Ungerer <gerg@uclinux.org>
1197 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1197 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1198 F: arch/arm/mach-ks8695/ 1198 F: arch/arm/mach-ks8695/
1199 S: Odd Fixes 1199 S: Odd Fixes
1200 1200
1201 ARM/MIOA701 MACHINE SUPPORT 1201 ARM/MIOA701 MACHINE SUPPORT
1202 M: Robert Jarzmik <robert.jarzmik@free.fr> 1202 M: Robert Jarzmik <robert.jarzmik@free.fr>
1203 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1203 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1204 F: arch/arm/mach-pxa/mioa701.c 1204 F: arch/arm/mach-pxa/mioa701.c
1205 S: Maintained 1205 S: Maintained
1206 1206
1207 ARM/NEC MOBILEPRO 900/c MACHINE SUPPORT 1207 ARM/NEC MOBILEPRO 900/c MACHINE SUPPORT
1208 M: Michael Petchkovsky <mkpetch@internode.on.net> 1208 M: Michael Petchkovsky <mkpetch@internode.on.net>
1209 S: Maintained 1209 S: Maintained
1210 1210
1211 ARM/NOMADIK ARCHITECTURE 1211 ARM/NOMADIK ARCHITECTURE
1212 M: Alessandro Rubini <rubini@unipv.it> 1212 M: Alessandro Rubini <rubini@unipv.it>
1213 M: Linus Walleij <linus.walleij@linaro.org> 1213 M: Linus Walleij <linus.walleij@linaro.org>
1214 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1214 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1215 S: Maintained 1215 S: Maintained
1216 F: arch/arm/mach-nomadik/ 1216 F: arch/arm/mach-nomadik/
1217 F: drivers/pinctrl/nomadik/ 1217 F: drivers/pinctrl/nomadik/
1218 F: drivers/i2c/busses/i2c-nomadik.c 1218 F: drivers/i2c/busses/i2c-nomadik.c
1219 T: git git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-nomadik.git 1219 T: git git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-nomadik.git
1220 1220
1221 ARM/OPENMOKO NEO FREERUNNER (GTA02) MACHINE SUPPORT 1221 ARM/OPENMOKO NEO FREERUNNER (GTA02) MACHINE SUPPORT
1222 M: Nelson Castillo <arhuaco@freaks-unidos.net> 1222 M: Nelson Castillo <arhuaco@freaks-unidos.net>
1223 L: openmoko-kernel@lists.openmoko.org (subscribers-only) 1223 L: openmoko-kernel@lists.openmoko.org (subscribers-only)
1224 W: http://wiki.openmoko.org/wiki/Neo_FreeRunner 1224 W: http://wiki.openmoko.org/wiki/Neo_FreeRunner
1225 S: Supported 1225 S: Supported
1226 1226
1227 ARM/QUALCOMM MSM MACHINE SUPPORT 1227 ARM/QUALCOMM MSM MACHINE SUPPORT
1228 M: David Brown <davidb@codeaurora.org> 1228 M: David Brown <davidb@codeaurora.org>
1229 M: Daniel Walker <dwalker@fifo99.com> 1229 M: Daniel Walker <dwalker@fifo99.com>
1230 M: Bryan Huntsman <bryanh@codeaurora.org> 1230 M: Bryan Huntsman <bryanh@codeaurora.org>
1231 L: linux-arm-msm@vger.kernel.org 1231 L: linux-arm-msm@vger.kernel.org
1232 F: arch/arm/mach-msm/ 1232 F: arch/arm/mach-msm/
1233 F: drivers/video/fbdev/msm/ 1233 F: drivers/video/fbdev/msm/
1234 F: drivers/mmc/host/msm_sdcc.c 1234 F: drivers/mmc/host/msm_sdcc.c
1235 F: drivers/mmc/host/msm_sdcc.h 1235 F: drivers/mmc/host/msm_sdcc.h
1236 F: drivers/tty/serial/msm_serial.h 1236 F: drivers/tty/serial/msm_serial.h
1237 F: drivers/tty/serial/msm_serial.c 1237 F: drivers/tty/serial/msm_serial.c
1238 F: drivers/*/pm8???-* 1238 F: drivers/*/pm8???-*
1239 F: drivers/mfd/ssbi.c 1239 F: drivers/mfd/ssbi.c
1240 T: git git://git.kernel.org/pub/scm/linux/kernel/git/davidb/linux-msm.git 1240 T: git git://git.kernel.org/pub/scm/linux/kernel/git/davidb/linux-msm.git
1241 S: Maintained 1241 S: Maintained
1242 1242
1243 ARM/TOSA MACHINE SUPPORT 1243 ARM/TOSA MACHINE SUPPORT
1244 M: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 1244 M: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
1245 M: Dirk Opfer <dirk@opfer-online.de> 1245 M: Dirk Opfer <dirk@opfer-online.de>
1246 S: Maintained 1246 S: Maintained
1247 1247
1248 ARM/PALMTX,PALMT5,PALMLD,PALMTE2,PALMTC SUPPORT 1248 ARM/PALMTX,PALMT5,PALMLD,PALMTE2,PALMTC SUPPORT
1249 M: Marek Vasut <marek.vasut@gmail.com> 1249 M: Marek Vasut <marek.vasut@gmail.com>
1250 L: linux-arm-kernel@lists.infradead.org 1250 L: linux-arm-kernel@lists.infradead.org
1251 W: http://hackndev.com 1251 W: http://hackndev.com
1252 S: Maintained 1252 S: Maintained
1253 F: arch/arm/mach-pxa/include/mach/palmtx.h 1253 F: arch/arm/mach-pxa/include/mach/palmtx.h
1254 F: arch/arm/mach-pxa/palmtx.c 1254 F: arch/arm/mach-pxa/palmtx.c
1255 F: arch/arm/mach-pxa/include/mach/palmt5.h 1255 F: arch/arm/mach-pxa/include/mach/palmt5.h
1256 F: arch/arm/mach-pxa/palmt5.c 1256 F: arch/arm/mach-pxa/palmt5.c
1257 F: arch/arm/mach-pxa/include/mach/palmld.h 1257 F: arch/arm/mach-pxa/include/mach/palmld.h
1258 F: arch/arm/mach-pxa/palmld.c 1258 F: arch/arm/mach-pxa/palmld.c
1259 F: arch/arm/mach-pxa/include/mach/palmte2.h 1259 F: arch/arm/mach-pxa/include/mach/palmte2.h
1260 F: arch/arm/mach-pxa/palmte2.c 1260 F: arch/arm/mach-pxa/palmte2.c
1261 F: arch/arm/mach-pxa/include/mach/palmtc.h 1261 F: arch/arm/mach-pxa/include/mach/palmtc.h
1262 F: arch/arm/mach-pxa/palmtc.c 1262 F: arch/arm/mach-pxa/palmtc.c
1263 1263
1264 ARM/PALM TREO SUPPORT 1264 ARM/PALM TREO SUPPORT
1265 M: Tomas Cech <sleep_walker@suse.cz> 1265 M: Tomas Cech <sleep_walker@suse.cz>
1266 L: linux-arm-kernel@lists.infradead.org 1266 L: linux-arm-kernel@lists.infradead.org
1267 W: http://hackndev.com 1267 W: http://hackndev.com
1268 S: Maintained 1268 S: Maintained
1269 F: arch/arm/mach-pxa/include/mach/palmtreo.h 1269 F: arch/arm/mach-pxa/include/mach/palmtreo.h
1270 F: arch/arm/mach-pxa/palmtreo.c 1270 F: arch/arm/mach-pxa/palmtreo.c
1271 1271
1272 ARM/PALMZ72 SUPPORT 1272 ARM/PALMZ72 SUPPORT
1273 M: Sergey Lapin <slapin@ossfans.org> 1273 M: Sergey Lapin <slapin@ossfans.org>
1274 L: linux-arm-kernel@lists.infradead.org 1274 L: linux-arm-kernel@lists.infradead.org
1275 W: http://hackndev.com 1275 W: http://hackndev.com
1276 S: Maintained 1276 S: Maintained
1277 F: arch/arm/mach-pxa/include/mach/palmz72.h 1277 F: arch/arm/mach-pxa/include/mach/palmz72.h
1278 F: arch/arm/mach-pxa/palmz72.c 1278 F: arch/arm/mach-pxa/palmz72.c
1279 1279
1280 ARM/PLEB SUPPORT 1280 ARM/PLEB SUPPORT
1281 M: Peter Chubb <pleb@gelato.unsw.edu.au> 1281 M: Peter Chubb <pleb@gelato.unsw.edu.au>
1282 W: http://www.disy.cse.unsw.edu.au/Hardware/PLEB 1282 W: http://www.disy.cse.unsw.edu.au/Hardware/PLEB
1283 S: Maintained 1283 S: Maintained
1284 1284
1285 ARM/PT DIGITAL BOARD PORT 1285 ARM/PT DIGITAL BOARD PORT
1286 M: Stefan Eletzhofer <stefan.eletzhofer@eletztrick.de> 1286 M: Stefan Eletzhofer <stefan.eletzhofer@eletztrick.de>
1287 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1287 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1288 W: http://www.arm.linux.org.uk/ 1288 W: http://www.arm.linux.org.uk/
1289 S: Maintained 1289 S: Maintained
1290 1290
1291 ARM/QUALCOMM SUPPORT 1291 ARM/QUALCOMM SUPPORT
1292 M: Kumar Gala <galak@codeaurora.org> 1292 M: Kumar Gala <galak@codeaurora.org>
1293 M: David Brown <davidb@codeaurora.org> 1293 M: David Brown <davidb@codeaurora.org>
1294 L: linux-arm-msm@vger.kernel.org 1294 L: linux-arm-msm@vger.kernel.org
1295 S: Maintained 1295 S: Maintained
1296 F: arch/arm/mach-qcom/ 1296 F: arch/arm/mach-qcom/
1297 T: git git://git.kernel.org/pub/scm/linux/kernel/git/galak/linux-qcom.git 1297 T: git git://git.kernel.org/pub/scm/linux/kernel/git/galak/linux-qcom.git
1298 1298
1299 ARM/RADISYS ENP2611 MACHINE SUPPORT 1299 ARM/RADISYS ENP2611 MACHINE SUPPORT
1300 M: Lennert Buytenhek <kernel@wantstofly.org> 1300 M: Lennert Buytenhek <kernel@wantstofly.org>
1301 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1301 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1302 S: Maintained 1302 S: Maintained
1303 1303
1304 ARM/RISCPC ARCHITECTURE 1304 ARM/RISCPC ARCHITECTURE
1305 M: Russell King <linux@arm.linux.org.uk> 1305 M: Russell King <linux@arm.linux.org.uk>
1306 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1306 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1307 W: http://www.arm.linux.org.uk/ 1307 W: http://www.arm.linux.org.uk/
1308 S: Maintained 1308 S: Maintained
1309 F: arch/arm/include/asm/hardware/entry-macro-iomd.S 1309 F: arch/arm/include/asm/hardware/entry-macro-iomd.S
1310 F: arch/arm/include/asm/hardware/ioc.h 1310 F: arch/arm/include/asm/hardware/ioc.h
1311 F: arch/arm/include/asm/hardware/iomd.h 1311 F: arch/arm/include/asm/hardware/iomd.h
1312 F: arch/arm/include/asm/hardware/memc.h 1312 F: arch/arm/include/asm/hardware/memc.h
1313 F: arch/arm/mach-rpc/ 1313 F: arch/arm/mach-rpc/
1314 F: drivers/net/ethernet/8390/etherh.c 1314 F: drivers/net/ethernet/8390/etherh.c
1315 F: drivers/net/ethernet/i825xx/ether1* 1315 F: drivers/net/ethernet/i825xx/ether1*
1316 F: drivers/net/ethernet/seeq/ether3* 1316 F: drivers/net/ethernet/seeq/ether3*
1317 F: drivers/scsi/arm/ 1317 F: drivers/scsi/arm/
1318 1318
1319 ARM/Rockchip SoC support 1319 ARM/Rockchip SoC support
1320 M: Heiko Stuebner <heiko@sntech.de> 1320 M: Heiko Stuebner <heiko@sntech.de>
1321 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1321 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1322 L: linux-rockchip@lists.infradead.org 1322 L: linux-rockchip@lists.infradead.org
1323 S: Maintained 1323 S: Maintained
1324 F: arch/arm/boot/dts/rk3* 1324 F: arch/arm/boot/dts/rk3*
1325 F: arch/arm/mach-rockchip/ 1325 F: arch/arm/mach-rockchip/
1326 F: drivers/clk/rockchip/ 1326 F: drivers/clk/rockchip/
1327 F: drivers/i2c/busses/i2c-rk3x.c 1327 F: drivers/i2c/busses/i2c-rk3x.c
1328 F: drivers/*/*rockchip* 1328 F: drivers/*/*rockchip*
1329 F: drivers/*/*/*rockchip* 1329 F: drivers/*/*/*rockchip*
1330 F: sound/soc/rockchip/ 1330 F: sound/soc/rockchip/
1331 1331
1332 ARM/SAMSUNG EXYNOS ARM ARCHITECTURES 1332 ARM/SAMSUNG EXYNOS ARM ARCHITECTURES
1333 M: Kukjin Kim <kgene@kernel.org> 1333 M: Kukjin Kim <kgene@kernel.org>
1334 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1334 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1335 L: linux-samsung-soc@vger.kernel.org (moderated for non-subscribers) 1335 L: linux-samsung-soc@vger.kernel.org (moderated for non-subscribers)
1336 S: Maintained 1336 S: Maintained
1337 F: arch/arm/boot/dts/s3c* 1337 F: arch/arm/boot/dts/s3c*
1338 F: arch/arm/boot/dts/exynos* 1338 F: arch/arm/boot/dts/exynos*
1339 F: arch/arm/plat-samsung/ 1339 F: arch/arm/plat-samsung/
1340 F: arch/arm/mach-s3c24*/ 1340 F: arch/arm/mach-s3c24*/
1341 F: arch/arm/mach-s3c64xx/ 1341 F: arch/arm/mach-s3c64xx/
1342 F: arch/arm/mach-s5p*/ 1342 F: arch/arm/mach-s5p*/
1343 F: arch/arm/mach-exynos*/ 1343 F: arch/arm/mach-exynos*/
1344 F: drivers/*/*s3c2410* 1344 F: drivers/*/*s3c2410*
1345 F: drivers/*/*/*s3c2410* 1345 F: drivers/*/*/*s3c2410*
1346 F: drivers/spi/spi-s3c* 1346 F: drivers/spi/spi-s3c*
1347 F: sound/soc/samsung/* 1347 F: sound/soc/samsung/*
1348 N: exynos 1348 N: exynos
1349 1349
1350 ARM/SAMSUNG MOBILE MACHINE SUPPORT 1350 ARM/SAMSUNG MOBILE MACHINE SUPPORT
1351 M: Kyungmin Park <kyungmin.park@samsung.com> 1351 M: Kyungmin Park <kyungmin.park@samsung.com>
1352 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1352 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1353 S: Maintained 1353 S: Maintained
1354 F: arch/arm/mach-s5pv210/ 1354 F: arch/arm/mach-s5pv210/
1355 1355
1356 ARM/SAMSUNG S5P SERIES 2D GRAPHICS ACCELERATION (G2D) SUPPORT 1356 ARM/SAMSUNG S5P SERIES 2D GRAPHICS ACCELERATION (G2D) SUPPORT
1357 M: Kyungmin Park <kyungmin.park@samsung.com> 1357 M: Kyungmin Park <kyungmin.park@samsung.com>
1358 M: Kamil Debski <k.debski@samsung.com> 1358 M: Kamil Debski <k.debski@samsung.com>
1359 L: linux-arm-kernel@lists.infradead.org 1359 L: linux-arm-kernel@lists.infradead.org
1360 L: linux-media@vger.kernel.org 1360 L: linux-media@vger.kernel.org
1361 S: Maintained 1361 S: Maintained
1362 F: drivers/media/platform/s5p-g2d/ 1362 F: drivers/media/platform/s5p-g2d/
1363 1363
1364 ARM/SAMSUNG S5P SERIES Multi Format Codec (MFC) SUPPORT 1364 ARM/SAMSUNG S5P SERIES Multi Format Codec (MFC) SUPPORT
1365 M: Kyungmin Park <kyungmin.park@samsung.com> 1365 M: Kyungmin Park <kyungmin.park@samsung.com>
1366 M: Kamil Debski <k.debski@samsung.com> 1366 M: Kamil Debski <k.debski@samsung.com>
1367 M: Jeongtae Park <jtp.park@samsung.com> 1367 M: Jeongtae Park <jtp.park@samsung.com>
1368 L: linux-arm-kernel@lists.infradead.org 1368 L: linux-arm-kernel@lists.infradead.org
1369 L: linux-media@vger.kernel.org 1369 L: linux-media@vger.kernel.org
1370 S: Maintained 1370 S: Maintained
1371 F: arch/arm/plat-samsung/s5p-dev-mfc.c 1371 F: arch/arm/plat-samsung/s5p-dev-mfc.c
1372 F: drivers/media/platform/s5p-mfc/ 1372 F: drivers/media/platform/s5p-mfc/
1373 1373
1374 ARM/SAMSUNG S5P SERIES TV SUBSYSTEM SUPPORT 1374 ARM/SAMSUNG S5P SERIES TV SUBSYSTEM SUPPORT
1375 M: Kyungmin Park <kyungmin.park@samsung.com> 1375 M: Kyungmin Park <kyungmin.park@samsung.com>
1376 M: Tomasz Stanislawski <t.stanislaws@samsung.com> 1376 M: Tomasz Stanislawski <t.stanislaws@samsung.com>
1377 L: linux-arm-kernel@lists.infradead.org 1377 L: linux-arm-kernel@lists.infradead.org
1378 L: linux-media@vger.kernel.org 1378 L: linux-media@vger.kernel.org
1379 S: Maintained 1379 S: Maintained
1380 F: drivers/media/platform/s5p-tv/ 1380 F: drivers/media/platform/s5p-tv/
1381 1381
1382 ARM/SHMOBILE ARM ARCHITECTURE 1382 ARM/SHMOBILE ARM ARCHITECTURE
1383 M: Simon Horman <horms@verge.net.au> 1383 M: Simon Horman <horms@verge.net.au>
1384 M: Magnus Damm <magnus.damm@gmail.com> 1384 M: Magnus Damm <magnus.damm@gmail.com>
1385 L: linux-sh@vger.kernel.org 1385 L: linux-sh@vger.kernel.org
1386 W: http://oss.renesas.com 1386 W: http://oss.renesas.com
1387 Q: http://patchwork.kernel.org/project/linux-sh/list/ 1387 Q: http://patchwork.kernel.org/project/linux-sh/list/
1388 T: git git://git.kernel.org/pub/scm/linux/kernel/git/horms/renesas.git next 1388 T: git git://git.kernel.org/pub/scm/linux/kernel/git/horms/renesas.git next
1389 S: Supported 1389 S: Supported
1390 F: arch/arm/boot/dts/emev2* 1390 F: arch/arm/boot/dts/emev2*
1391 F: arch/arm/boot/dts/r7s* 1391 F: arch/arm/boot/dts/r7s*
1392 F: arch/arm/boot/dts/r8a* 1392 F: arch/arm/boot/dts/r8a*
1393 F: arch/arm/boot/dts/sh* 1393 F: arch/arm/boot/dts/sh*
1394 F: arch/arm/configs/ape6evm_defconfig 1394 F: arch/arm/configs/ape6evm_defconfig
1395 F: arch/arm/configs/armadillo800eva_defconfig 1395 F: arch/arm/configs/armadillo800eva_defconfig
1396 F: arch/arm/configs/bockw_defconfig 1396 F: arch/arm/configs/bockw_defconfig
1397 F: arch/arm/configs/kzm9g_defconfig 1397 F: arch/arm/configs/kzm9g_defconfig
1398 F: arch/arm/configs/lager_defconfig 1398 F: arch/arm/configs/lager_defconfig
1399 F: arch/arm/configs/mackerel_defconfig 1399 F: arch/arm/configs/mackerel_defconfig
1400 F: arch/arm/configs/marzen_defconfig 1400 F: arch/arm/configs/marzen_defconfig
1401 F: arch/arm/configs/shmobile_defconfig 1401 F: arch/arm/configs/shmobile_defconfig
1402 F: arch/arm/include/debug/renesas-scif.S 1402 F: arch/arm/include/debug/renesas-scif.S
1403 F: arch/arm/mach-shmobile/ 1403 F: arch/arm/mach-shmobile/
1404 F: drivers/sh/ 1404 F: drivers/sh/
1405 1405
1406 ARM/SOCFPGA ARCHITECTURE 1406 ARM/SOCFPGA ARCHITECTURE
1407 M: Dinh Nguyen <dinguyen@opensource.altera.com> 1407 M: Dinh Nguyen <dinguyen@opensource.altera.com>
1408 S: Maintained 1408 S: Maintained
1409 F: arch/arm/mach-socfpga/ 1409 F: arch/arm/mach-socfpga/
1410 W: http://www.rocketboards.org 1410 W: http://www.rocketboards.org
1411 T: git://git.rocketboards.org/linux-socfpga.git 1411 T: git://git.rocketboards.org/linux-socfpga.git
1412 T: git://git.rocketboards.org/linux-socfpga-next.git 1412 T: git://git.rocketboards.org/linux-socfpga-next.git
1413 1413
1414 ARM/SOCFPGA CLOCK FRAMEWORK SUPPORT 1414 ARM/SOCFPGA CLOCK FRAMEWORK SUPPORT
1415 M: Dinh Nguyen <dinguyen@opensource.altera.com> 1415 M: Dinh Nguyen <dinguyen@opensource.altera.com>
1416 S: Maintained 1416 S: Maintained
1417 F: drivers/clk/socfpga/ 1417 F: drivers/clk/socfpga/
1418 1418
1419 ARM/SOCFPGA EDAC SUPPORT 1419 ARM/SOCFPGA EDAC SUPPORT
1420 M: Thor Thayer <tthayer@opensource.altera.com> 1420 M: Thor Thayer <tthayer@opensource.altera.com>
1421 S: Maintained 1421 S: Maintained
1422 F: drivers/edac/altera_edac. 1422 F: drivers/edac/altera_edac.
1423 1423
1424 ARM/STI ARCHITECTURE 1424 ARM/STI ARCHITECTURE
1425 M: Srinivas Kandagatla <srinivas.kandagatla@gmail.com> 1425 M: Srinivas Kandagatla <srinivas.kandagatla@gmail.com>
1426 M: Maxime Coquelin <maxime.coquelin@st.com> 1426 M: Maxime Coquelin <maxime.coquelin@st.com>
1427 M: Patrice Chotard <patrice.chotard@st.com> 1427 M: Patrice Chotard <patrice.chotard@st.com>
1428 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1428 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1429 L: kernel@stlinux.com 1429 L: kernel@stlinux.com
1430 W: http://www.stlinux.com 1430 W: http://www.stlinux.com
1431 S: Maintained 1431 S: Maintained
1432 F: arch/arm/mach-sti/ 1432 F: arch/arm/mach-sti/
1433 F: arch/arm/boot/dts/sti* 1433 F: arch/arm/boot/dts/sti*
1434 F: drivers/clocksource/arm_global_timer.c 1434 F: drivers/clocksource/arm_global_timer.c
1435 F: drivers/i2c/busses/i2c-st.c 1435 F: drivers/i2c/busses/i2c-st.c
1436 F: drivers/media/rc/st_rc.c 1436 F: drivers/media/rc/st_rc.c
1437 F: drivers/mmc/host/sdhci-st.c 1437 F: drivers/mmc/host/sdhci-st.c
1438 F: drivers/phy/phy-stih407-usb.c 1438 F: drivers/phy/phy-stih407-usb.c
1439 F: drivers/phy/phy-stih41x-usb.c 1439 F: drivers/phy/phy-stih41x-usb.c
1440 F: drivers/pinctrl/pinctrl-st.c 1440 F: drivers/pinctrl/pinctrl-st.c
1441 F: drivers/reset/sti/ 1441 F: drivers/reset/sti/
1442 F: drivers/tty/serial/st-asc.c 1442 F: drivers/tty/serial/st-asc.c
1443 F: drivers/usb/dwc3/dwc3-st.c 1443 F: drivers/usb/dwc3/dwc3-st.c
1444 F: drivers/usb/host/ehci-st.c 1444 F: drivers/usb/host/ehci-st.c
1445 F: drivers/usb/host/ohci-st.c 1445 F: drivers/usb/host/ohci-st.c
1446 F: drivers/ata/ahci_st.c 1446 F: drivers/ata/ahci_st.c
1447 1447
1448 ARM/TECHNOLOGIC SYSTEMS TS7250 MACHINE SUPPORT 1448 ARM/TECHNOLOGIC SYSTEMS TS7250 MACHINE SUPPORT
1449 M: Lennert Buytenhek <kernel@wantstofly.org> 1449 M: Lennert Buytenhek <kernel@wantstofly.org>
1450 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1450 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1451 S: Maintained 1451 S: Maintained
1452 1452
1453 ARM/TETON BGA MACHINE SUPPORT 1453 ARM/TETON BGA MACHINE SUPPORT
1454 M: "Mark F. Brown" <mark.brown314@gmail.com> 1454 M: "Mark F. Brown" <mark.brown314@gmail.com>
1455 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1455 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1456 S: Maintained 1456 S: Maintained
1457 1457
1458 ARM/THECUS N2100 MACHINE SUPPORT 1458 ARM/THECUS N2100 MACHINE SUPPORT
1459 M: Lennert Buytenhek <kernel@wantstofly.org> 1459 M: Lennert Buytenhek <kernel@wantstofly.org>
1460 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1460 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1461 S: Maintained 1461 S: Maintained
1462 1462
1463 ARM/NUVOTON W90X900 ARM ARCHITECTURE 1463 ARM/NUVOTON W90X900 ARM ARCHITECTURE
1464 M: Wan ZongShun <mcuos.com@gmail.com> 1464 M: Wan ZongShun <mcuos.com@gmail.com>
1465 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1465 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1466 W: http://www.mcuos.com 1466 W: http://www.mcuos.com
1467 S: Maintained 1467 S: Maintained
1468 F: arch/arm/mach-w90x900/ 1468 F: arch/arm/mach-w90x900/
1469 F: drivers/input/keyboard/w90p910_keypad.c 1469 F: drivers/input/keyboard/w90p910_keypad.c
1470 F: drivers/input/touchscreen/w90p910_ts.c 1470 F: drivers/input/touchscreen/w90p910_ts.c
1471 F: drivers/watchdog/nuc900_wdt.c 1471 F: drivers/watchdog/nuc900_wdt.c
1472 F: drivers/net/ethernet/nuvoton/w90p910_ether.c 1472 F: drivers/net/ethernet/nuvoton/w90p910_ether.c
1473 F: drivers/mtd/nand/nuc900_nand.c 1473 F: drivers/mtd/nand/nuc900_nand.c
1474 F: drivers/rtc/rtc-nuc900.c 1474 F: drivers/rtc/rtc-nuc900.c
1475 F: drivers/spi/spi-nuc900.c 1475 F: drivers/spi/spi-nuc900.c
1476 F: drivers/usb/host/ehci-w90x900.c 1476 F: drivers/usb/host/ehci-w90x900.c
1477 F: drivers/video/fbdev/nuc900fb.c 1477 F: drivers/video/fbdev/nuc900fb.c
1478 1478
1479 ARM/U300 MACHINE SUPPORT 1479 ARM/U300 MACHINE SUPPORT
1480 M: Linus Walleij <linus.walleij@linaro.org> 1480 M: Linus Walleij <linus.walleij@linaro.org>
1481 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1481 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1482 S: Supported 1482 S: Supported
1483 F: arch/arm/mach-u300/ 1483 F: arch/arm/mach-u300/
1484 F: drivers/clocksource/timer-u300.c 1484 F: drivers/clocksource/timer-u300.c
1485 F: drivers/i2c/busses/i2c-stu300.c 1485 F: drivers/i2c/busses/i2c-stu300.c
1486 F: drivers/rtc/rtc-coh901331.c 1486 F: drivers/rtc/rtc-coh901331.c
1487 F: drivers/watchdog/coh901327_wdt.c 1487 F: drivers/watchdog/coh901327_wdt.c
1488 F: drivers/dma/coh901318* 1488 F: drivers/dma/coh901318*
1489 F: drivers/mfd/ab3100* 1489 F: drivers/mfd/ab3100*
1490 F: drivers/rtc/rtc-ab3100.c 1490 F: drivers/rtc/rtc-ab3100.c
1491 F: drivers/rtc/rtc-coh901331.c 1491 F: drivers/rtc/rtc-coh901331.c
1492 T: git git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-stericsson.git 1492 T: git git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-stericsson.git
1493 1493
1494 ARM/Ux500 ARM ARCHITECTURE 1494 ARM/Ux500 ARM ARCHITECTURE
1495 M: Linus Walleij <linus.walleij@linaro.org> 1495 M: Linus Walleij <linus.walleij@linaro.org>
1496 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1496 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1497 S: Maintained 1497 S: Maintained
1498 F: arch/arm/mach-ux500/ 1498 F: arch/arm/mach-ux500/
1499 F: drivers/clocksource/clksrc-dbx500-prcmu.c 1499 F: drivers/clocksource/clksrc-dbx500-prcmu.c
1500 F: drivers/dma/ste_dma40* 1500 F: drivers/dma/ste_dma40*
1501 F: drivers/hwspinlock/u8500_hsem.c 1501 F: drivers/hwspinlock/u8500_hsem.c
1502 F: drivers/mfd/abx500* 1502 F: drivers/mfd/abx500*
1503 F: drivers/mfd/ab8500* 1503 F: drivers/mfd/ab8500*
1504 F: drivers/mfd/dbx500* 1504 F: drivers/mfd/dbx500*
1505 F: drivers/mfd/db8500* 1505 F: drivers/mfd/db8500*
1506 F: drivers/pinctrl/nomadik/pinctrl-ab* 1506 F: drivers/pinctrl/nomadik/pinctrl-ab*
1507 F: drivers/pinctrl/nomadik/pinctrl-nomadik* 1507 F: drivers/pinctrl/nomadik/pinctrl-nomadik*
1508 F: drivers/rtc/rtc-ab8500.c 1508 F: drivers/rtc/rtc-ab8500.c
1509 F: drivers/rtc/rtc-pl031.c 1509 F: drivers/rtc/rtc-pl031.c
1510 T: git git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-stericsson.git 1510 T: git git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-stericsson.git
1511 1511
1512 ARM/Ux500 CLOCK FRAMEWORK SUPPORT 1512 ARM/Ux500 CLOCK FRAMEWORK SUPPORT
1513 M: Ulf Hansson <ulf.hansson@linaro.org> 1513 M: Ulf Hansson <ulf.hansson@linaro.org>
1514 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1514 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1515 T: git git://git.linaro.org/people/ulfh/clk.git 1515 T: git git://git.linaro.org/people/ulfh/clk.git
1516 S: Maintained 1516 S: Maintained
1517 F: drivers/clk/ux500/ 1517 F: drivers/clk/ux500/
1518 F: include/linux/platform_data/clk-ux500.h 1518 F: include/linux/platform_data/clk-ux500.h
1519 1519
1520 ARM/VERSATILE EXPRESS PLATFORM 1520 ARM/VERSATILE EXPRESS PLATFORM
1521 M: Liviu Dudau <liviu.dudau@arm.com> 1521 M: Liviu Dudau <liviu.dudau@arm.com>
1522 M: Sudeep Holla <sudeep.holla@arm.com> 1522 M: Sudeep Holla <sudeep.holla@arm.com>
1523 M: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> 1523 M: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
1524 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1524 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1525 S: Maintained 1525 S: Maintained
1526 F: arch/arm/boot/dts/vexpress* 1526 F: arch/arm/boot/dts/vexpress*
1527 F: arch/arm/mach-vexpress/ 1527 F: arch/arm/mach-vexpress/
1528 F: */*/vexpress* 1528 F: */*/vexpress*
1529 F: */*/*/vexpress* 1529 F: */*/*/vexpress*
1530 F: drivers/clk/versatile/clk-vexpress-osc.c 1530 F: drivers/clk/versatile/clk-vexpress-osc.c
1531 F: drivers/clocksource/versatile.c 1531 F: drivers/clocksource/versatile.c
1532 1532
1533 ARM/VFP SUPPORT 1533 ARM/VFP SUPPORT
1534 M: Russell King <linux@arm.linux.org.uk> 1534 M: Russell King <linux@arm.linux.org.uk>
1535 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1535 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1536 W: http://www.arm.linux.org.uk/ 1536 W: http://www.arm.linux.org.uk/
1537 S: Maintained 1537 S: Maintained
1538 F: arch/arm/vfp/ 1538 F: arch/arm/vfp/
1539 1539
1540 ARM/VOIPAC PXA270 SUPPORT 1540 ARM/VOIPAC PXA270 SUPPORT
1541 M: Marek Vasut <marek.vasut@gmail.com> 1541 M: Marek Vasut <marek.vasut@gmail.com>
1542 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1542 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1543 S: Maintained 1543 S: Maintained
1544 F: arch/arm/mach-pxa/vpac270.c 1544 F: arch/arm/mach-pxa/vpac270.c
1545 F: arch/arm/mach-pxa/include/mach/vpac270.h 1545 F: arch/arm/mach-pxa/include/mach/vpac270.h
1546 1546
1547 ARM/VT8500 ARM ARCHITECTURE 1547 ARM/VT8500 ARM ARCHITECTURE
1548 M: Tony Prisk <linux@prisktech.co.nz> 1548 M: Tony Prisk <linux@prisktech.co.nz>
1549 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1549 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1550 S: Maintained 1550 S: Maintained
1551 F: arch/arm/mach-vt8500/ 1551 F: arch/arm/mach-vt8500/
1552 F: drivers/clocksource/vt8500_timer.c 1552 F: drivers/clocksource/vt8500_timer.c
1553 F: drivers/i2c/busses/i2c-wmt.c 1553 F: drivers/i2c/busses/i2c-wmt.c
1554 F: drivers/mmc/host/wmt-sdmmc.c 1554 F: drivers/mmc/host/wmt-sdmmc.c
1555 F: drivers/pwm/pwm-vt8500.c 1555 F: drivers/pwm/pwm-vt8500.c
1556 F: drivers/rtc/rtc-vt8500.c 1556 F: drivers/rtc/rtc-vt8500.c
1557 F: drivers/tty/serial/vt8500_serial.c 1557 F: drivers/tty/serial/vt8500_serial.c
1558 F: drivers/usb/host/ehci-platform.c 1558 F: drivers/usb/host/ehci-platform.c
1559 F: drivers/usb/host/uhci-platform.c 1559 F: drivers/usb/host/uhci-platform.c
1560 F: drivers/video/fbdev/vt8500lcdfb.* 1560 F: drivers/video/fbdev/vt8500lcdfb.*
1561 F: drivers/video/fbdev/wm8505fb* 1561 F: drivers/video/fbdev/wm8505fb*
1562 F: drivers/video/fbdev/wmt_ge_rops.* 1562 F: drivers/video/fbdev/wmt_ge_rops.*
1563 1563
1564 ARM/ZIPIT Z2 SUPPORT 1564 ARM/ZIPIT Z2 SUPPORT
1565 M: Marek Vasut <marek.vasut@gmail.com> 1565 M: Marek Vasut <marek.vasut@gmail.com>
1566 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1566 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1567 S: Maintained 1567 S: Maintained
1568 F: arch/arm/mach-pxa/z2.c 1568 F: arch/arm/mach-pxa/z2.c
1569 F: arch/arm/mach-pxa/include/mach/z2.h 1569 F: arch/arm/mach-pxa/include/mach/z2.h
1570 1570
1571 ARM/ZYNQ ARCHITECTURE 1571 ARM/ZYNQ ARCHITECTURE
1572 M: Michal Simek <michal.simek@xilinx.com> 1572 M: Michal Simek <michal.simek@xilinx.com>
1573 R: Sรถren Brinkmann <soren.brinkmann@xilinx.com> 1573 R: Sรถren Brinkmann <soren.brinkmann@xilinx.com>
1574 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1574 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1575 W: http://wiki.xilinx.com 1575 W: http://wiki.xilinx.com
1576 T: git git://git.xilinx.com/linux-xlnx.git 1576 T: git git://git.xilinx.com/linux-xlnx.git
1577 S: Supported 1577 S: Supported
1578 F: arch/arm/mach-zynq/ 1578 F: arch/arm/mach-zynq/
1579 F: drivers/cpuidle/cpuidle-zynq.c 1579 F: drivers/cpuidle/cpuidle-zynq.c
1580 F: drivers/block/xsysace.c 1580 F: drivers/block/xsysace.c
1581 N: zynq 1581 N: zynq
1582 N: xilinx 1582 N: xilinx
1583 F: drivers/clocksource/cadence_ttc_timer.c 1583 F: drivers/clocksource/cadence_ttc_timer.c
1584 F: drivers/i2c/busses/i2c-cadence.c 1584 F: drivers/i2c/busses/i2c-cadence.c
1585 F: drivers/mmc/host/sdhci-of-arasan.c 1585 F: drivers/mmc/host/sdhci-of-arasan.c
1586 1586
1587 ARM SMMU DRIVER 1587 ARM SMMU DRIVER
1588 M: Will Deacon <will.deacon@arm.com> 1588 M: Will Deacon <will.deacon@arm.com>
1589 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1589 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1590 S: Maintained 1590 S: Maintained
1591 F: drivers/iommu/arm-smmu.c 1591 F: drivers/iommu/arm-smmu.c
1592 1592
1593 ARM64 PORT (AARCH64 ARCHITECTURE) 1593 ARM64 PORT (AARCH64 ARCHITECTURE)
1594 M: Catalin Marinas <catalin.marinas@arm.com> 1594 M: Catalin Marinas <catalin.marinas@arm.com>
1595 M: Will Deacon <will.deacon@arm.com> 1595 M: Will Deacon <will.deacon@arm.com>
1596 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1596 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1597 S: Maintained 1597 S: Maintained
1598 F: arch/arm64/ 1598 F: arch/arm64/
1599 F: Documentation/arm64/ 1599 F: Documentation/arm64/
1600 1600
1601 AS3645A LED FLASH CONTROLLER DRIVER 1601 AS3645A LED FLASH CONTROLLER DRIVER
1602 M: Laurent Pinchart <laurent.pinchart@ideasonboard.com> 1602 M: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
1603 L: linux-media@vger.kernel.org 1603 L: linux-media@vger.kernel.org
1604 T: git git://linuxtv.org/media_tree.git 1604 T: git git://linuxtv.org/media_tree.git
1605 S: Maintained 1605 S: Maintained
1606 F: drivers/media/i2c/as3645a.c 1606 F: drivers/media/i2c/as3645a.c
1607 F: include/media/as3645a.h 1607 F: include/media/as3645a.h
1608 1608
1609 ASC7621 HARDWARE MONITOR DRIVER 1609 ASC7621 HARDWARE MONITOR DRIVER
1610 M: George Joseph <george.joseph@fairview5.com> 1610 M: George Joseph <george.joseph@fairview5.com>
1611 L: lm-sensors@lm-sensors.org 1611 L: lm-sensors@lm-sensors.org
1612 S: Maintained 1612 S: Maintained
1613 F: Documentation/hwmon/asc7621 1613 F: Documentation/hwmon/asc7621
1614 F: drivers/hwmon/asc7621.c 1614 F: drivers/hwmon/asc7621.c
1615 1615
1616 ASUS NOTEBOOKS AND EEEPC ACPI/WMI EXTRAS DRIVERS 1616 ASUS NOTEBOOKS AND EEEPC ACPI/WMI EXTRAS DRIVERS
1617 M: Corentin Chary <corentin.chary@gmail.com> 1617 M: Corentin Chary <corentin.chary@gmail.com>
1618 L: acpi4asus-user@lists.sourceforge.net 1618 L: acpi4asus-user@lists.sourceforge.net
1619 L: platform-driver-x86@vger.kernel.org 1619 L: platform-driver-x86@vger.kernel.org
1620 W: http://acpi4asus.sf.net 1620 W: http://acpi4asus.sf.net
1621 S: Maintained 1621 S: Maintained
1622 F: drivers/platform/x86/asus*.c 1622 F: drivers/platform/x86/asus*.c
1623 F: drivers/platform/x86/eeepc*.c 1623 F: drivers/platform/x86/eeepc*.c
1624 1624
1625 ASYNCHRONOUS TRANSFERS/TRANSFORMS (IOAT) API 1625 ASYNCHRONOUS TRANSFERS/TRANSFORMS (IOAT) API
1626 R: Dan Williams <dan.j.williams@intel.com> 1626 R: Dan Williams <dan.j.williams@intel.com>
1627 W: http://sourceforge.net/projects/xscaleiop 1627 W: http://sourceforge.net/projects/xscaleiop
1628 S: Odd fixes 1628 S: Odd fixes
1629 F: Documentation/crypto/async-tx-api.txt 1629 F: Documentation/crypto/async-tx-api.txt
1630 F: crypto/async_tx/ 1630 F: crypto/async_tx/
1631 F: drivers/dma/ 1631 F: drivers/dma/
1632 F: include/linux/dmaengine.h 1632 F: include/linux/dmaengine.h
1633 F: include/linux/async_tx.h 1633 F: include/linux/async_tx.h
1634 1634
1635 AT24 EEPROM DRIVER 1635 AT24 EEPROM DRIVER
1636 M: Wolfram Sang <wsa@the-dreams.de> 1636 M: Wolfram Sang <wsa@the-dreams.de>
1637 L: linux-i2c@vger.kernel.org 1637 L: linux-i2c@vger.kernel.org
1638 S: Maintained 1638 S: Maintained
1639 F: drivers/misc/eeprom/at24.c 1639 F: drivers/misc/eeprom/at24.c
1640 F: include/linux/platform_data/at24.h 1640 F: include/linux/platform_data/at24.h
1641 1641
1642 ATA OVER ETHERNET (AOE) DRIVER 1642 ATA OVER ETHERNET (AOE) DRIVER
1643 M: "Ed L. Cashin" <ecashin@coraid.com> 1643 M: "Ed L. Cashin" <ecashin@coraid.com>
1644 W: http://support.coraid.com/support/linux 1644 W: http://support.coraid.com/support/linux
1645 S: Supported 1645 S: Supported
1646 F: Documentation/aoe/ 1646 F: Documentation/aoe/
1647 F: drivers/block/aoe/ 1647 F: drivers/block/aoe/
1648 1648
1649 ATHEROS ATH GENERIC UTILITIES 1649 ATHEROS ATH GENERIC UTILITIES
1650 M: "Luis R. Rodriguez" <mcgrof@do-not-panic.com> 1650 M: "Luis R. Rodriguez" <mcgrof@do-not-panic.com>
1651 L: linux-wireless@vger.kernel.org 1651 L: linux-wireless@vger.kernel.org
1652 S: Supported 1652 S: Supported
1653 F: drivers/net/wireless/ath/* 1653 F: drivers/net/wireless/ath/*
1654 1654
1655 ATHEROS ATH5K WIRELESS DRIVER 1655 ATHEROS ATH5K WIRELESS DRIVER
1656 M: Jiri Slaby <jirislaby@gmail.com> 1656 M: Jiri Slaby <jirislaby@gmail.com>
1657 M: Nick Kossifidis <mickflemm@gmail.com> 1657 M: Nick Kossifidis <mickflemm@gmail.com>
1658 M: "Luis R. Rodriguez" <mcgrof@do-not-panic.com> 1658 M: "Luis R. Rodriguez" <mcgrof@do-not-panic.com>
1659 L: linux-wireless@vger.kernel.org 1659 L: linux-wireless@vger.kernel.org
1660 L: ath5k-devel@lists.ath5k.org 1660 L: ath5k-devel@lists.ath5k.org
1661 W: http://wireless.kernel.org/en/users/Drivers/ath5k 1661 W: http://wireless.kernel.org/en/users/Drivers/ath5k
1662 S: Maintained 1662 S: Maintained
1663 F: drivers/net/wireless/ath/ath5k/ 1663 F: drivers/net/wireless/ath/ath5k/
1664 1664
1665 ATHEROS ATH6KL WIRELESS DRIVER 1665 ATHEROS ATH6KL WIRELESS DRIVER
1666 M: Kalle Valo <kvalo@qca.qualcomm.com> 1666 M: Kalle Valo <kvalo@qca.qualcomm.com>
1667 L: linux-wireless@vger.kernel.org 1667 L: linux-wireless@vger.kernel.org
1668 W: http://wireless.kernel.org/en/users/Drivers/ath6kl 1668 W: http://wireless.kernel.org/en/users/Drivers/ath6kl
1669 T: git git://github.com/kvalo/ath.git 1669 T: git git://github.com/kvalo/ath.git
1670 S: Supported 1670 S: Supported
1671 F: drivers/net/wireless/ath/ath6kl/ 1671 F: drivers/net/wireless/ath/ath6kl/
1672 1672
1673 WILOCITY WIL6210 WIRELESS DRIVER 1673 WILOCITY WIL6210 WIRELESS DRIVER
1674 M: Vladimir Kondratiev <qca_vkondrat@qca.qualcomm.com> 1674 M: Vladimir Kondratiev <qca_vkondrat@qca.qualcomm.com>
1675 L: linux-wireless@vger.kernel.org 1675 L: linux-wireless@vger.kernel.org
1676 L: wil6210@qca.qualcomm.com 1676 L: wil6210@qca.qualcomm.com
1677 S: Supported 1677 S: Supported
1678 W: http://wireless.kernel.org/en/users/Drivers/wil6210 1678 W: http://wireless.kernel.org/en/users/Drivers/wil6210
1679 F: drivers/net/wireless/ath/wil6210/ 1679 F: drivers/net/wireless/ath/wil6210/
1680 F: include/uapi/linux/wil6210_uapi.h 1680 F: include/uapi/linux/wil6210_uapi.h
1681 1681
1682 CARL9170 LINUX COMMUNITY WIRELESS DRIVER 1682 CARL9170 LINUX COMMUNITY WIRELESS DRIVER
1683 M: Christian Lamparter <chunkeey@googlemail.com> 1683 M: Christian Lamparter <chunkeey@googlemail.com>
1684 L: linux-wireless@vger.kernel.org 1684 L: linux-wireless@vger.kernel.org
1685 W: http://wireless.kernel.org/en/users/Drivers/carl9170 1685 W: http://wireless.kernel.org/en/users/Drivers/carl9170
1686 S: Maintained 1686 S: Maintained
1687 F: drivers/net/wireless/ath/carl9170/ 1687 F: drivers/net/wireless/ath/carl9170/
1688 1688
1689 ATK0110 HWMON DRIVER 1689 ATK0110 HWMON DRIVER
1690 M: Luca Tettamanti <kronos.it@gmail.com> 1690 M: Luca Tettamanti <kronos.it@gmail.com>
1691 L: lm-sensors@lm-sensors.org 1691 L: lm-sensors@lm-sensors.org
1692 S: Maintained 1692 S: Maintained
1693 F: drivers/hwmon/asus_atk0110.c 1693 F: drivers/hwmon/asus_atk0110.c
1694 1694
1695 ATI_REMOTE2 DRIVER 1695 ATI_REMOTE2 DRIVER
1696 M: Ville Syrjala <syrjala@sci.fi> 1696 M: Ville Syrjala <syrjala@sci.fi>
1697 S: Maintained 1697 S: Maintained
1698 F: drivers/input/misc/ati_remote2.c 1698 F: drivers/input/misc/ati_remote2.c
1699 1699
1700 ATLX ETHERNET DRIVERS 1700 ATLX ETHERNET DRIVERS
1701 M: Jay Cliburn <jcliburn@gmail.com> 1701 M: Jay Cliburn <jcliburn@gmail.com>
1702 M: Chris Snook <chris.snook@gmail.com> 1702 M: Chris Snook <chris.snook@gmail.com>
1703 L: netdev@vger.kernel.org 1703 L: netdev@vger.kernel.org
1704 W: http://sourceforge.net/projects/atl1 1704 W: http://sourceforge.net/projects/atl1
1705 W: http://atl1.sourceforge.net 1705 W: http://atl1.sourceforge.net
1706 S: Maintained 1706 S: Maintained
1707 F: drivers/net/ethernet/atheros/ 1707 F: drivers/net/ethernet/atheros/
1708 1708
1709 ATM 1709 ATM
1710 M: Chas Williams <chas@cmf.nrl.navy.mil> 1710 M: Chas Williams <chas@cmf.nrl.navy.mil>
1711 L: linux-atm-general@lists.sourceforge.net (moderated for non-subscribers) 1711 L: linux-atm-general@lists.sourceforge.net (moderated for non-subscribers)
1712 L: netdev@vger.kernel.org 1712 L: netdev@vger.kernel.org
1713 W: http://linux-atm.sourceforge.net 1713 W: http://linux-atm.sourceforge.net
1714 S: Maintained 1714 S: Maintained
1715 F: drivers/atm/ 1715 F: drivers/atm/
1716 F: include/linux/atm* 1716 F: include/linux/atm*
1717 F: include/uapi/linux/atm* 1717 F: include/uapi/linux/atm*
1718 1718
1719 ATMEL AT91 / AT32 MCI DRIVER 1719 ATMEL AT91 / AT32 MCI DRIVER
1720 M: Ludovic Desroches <ludovic.desroches@atmel.com> 1720 M: Ludovic Desroches <ludovic.desroches@atmel.com>
1721 S: Maintained 1721 S: Maintained
1722 F: drivers/mmc/host/atmel-mci.c 1722 F: drivers/mmc/host/atmel-mci.c
1723 F: drivers/mmc/host/atmel-mci-regs.h 1723 F: drivers/mmc/host/atmel-mci-regs.h
1724 1724
1725 ATMEL AT91 / AT32 SERIAL DRIVER 1725 ATMEL AT91 / AT32 SERIAL DRIVER
1726 M: Nicolas Ferre <nicolas.ferre@atmel.com> 1726 M: Nicolas Ferre <nicolas.ferre@atmel.com>
1727 S: Supported 1727 S: Supported
1728 F: drivers/tty/serial/atmel_serial.c 1728 F: drivers/tty/serial/atmel_serial.c
1729 1729
1730 ATMEL Audio ALSA driver 1730 ATMEL Audio ALSA driver
1731 M: Bo Shen <voice.shen@atmel.com> 1731 M: Bo Shen <voice.shen@atmel.com>
1732 L: alsa-devel@alsa-project.org (moderated for non-subscribers) 1732 L: alsa-devel@alsa-project.org (moderated for non-subscribers)
1733 S: Supported 1733 S: Supported
1734 F: sound/soc/atmel 1734 F: sound/soc/atmel
1735 1735
1736 ATMEL DMA DRIVER 1736 ATMEL DMA DRIVER
1737 M: Nicolas Ferre <nicolas.ferre@atmel.com> 1737 M: Nicolas Ferre <nicolas.ferre@atmel.com>
1738 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1738 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1739 S: Supported 1739 S: Supported
1740 F: drivers/dma/at_hdmac.c 1740 F: drivers/dma/at_hdmac.c
1741 F: drivers/dma/at_hdmac_regs.h 1741 F: drivers/dma/at_hdmac_regs.h
1742 F: include/linux/platform_data/dma-atmel.h 1742 F: include/linux/platform_data/dma-atmel.h
1743 1743
1744 ATMEL XDMA DRIVER 1744 ATMEL XDMA DRIVER
1745 M: Ludovic Desroches <ludovic.desroches@atmel.com> 1745 M: Ludovic Desroches <ludovic.desroches@atmel.com>
1746 L: linux-arm-kernel@lists.infradead.org 1746 L: linux-arm-kernel@lists.infradead.org
1747 L: dmaengine@vger.kernel.org 1747 L: dmaengine@vger.kernel.org
1748 S: Supported 1748 S: Supported
1749 F: drivers/dma/at_xdmac.c 1749 F: drivers/dma/at_xdmac.c
1750 1750
1751 ATMEL I2C DRIVER 1751 ATMEL I2C DRIVER
1752 M: Ludovic Desroches <ludovic.desroches@atmel.com> 1752 M: Ludovic Desroches <ludovic.desroches@atmel.com>
1753 L: linux-i2c@vger.kernel.org 1753 L: linux-i2c@vger.kernel.org
1754 S: Supported 1754 S: Supported
1755 F: drivers/i2c/busses/i2c-at91.c 1755 F: drivers/i2c/busses/i2c-at91.c
1756 1756
1757 ATMEL ISI DRIVER 1757 ATMEL ISI DRIVER
1758 M: Josh Wu <josh.wu@atmel.com> 1758 M: Josh Wu <josh.wu@atmel.com>
1759 L: linux-media@vger.kernel.org 1759 L: linux-media@vger.kernel.org
1760 S: Supported 1760 S: Supported
1761 F: drivers/media/platform/soc_camera/atmel-isi.c 1761 F: drivers/media/platform/soc_camera/atmel-isi.c
1762 F: include/media/atmel-isi.h 1762 F: include/media/atmel-isi.h
1763 1763
1764 ATMEL LCDFB DRIVER 1764 ATMEL LCDFB DRIVER
1765 M: Nicolas Ferre <nicolas.ferre@atmel.com> 1765 M: Nicolas Ferre <nicolas.ferre@atmel.com>
1766 L: linux-fbdev@vger.kernel.org 1766 L: linux-fbdev@vger.kernel.org
1767 S: Maintained 1767 S: Maintained
1768 F: drivers/video/fbdev/atmel_lcdfb.c 1768 F: drivers/video/fbdev/atmel_lcdfb.c
1769 F: include/video/atmel_lcdc.h 1769 F: include/video/atmel_lcdc.h
1770 1770
1771 ATMEL MACB ETHERNET DRIVER 1771 ATMEL MACB ETHERNET DRIVER
1772 M: Nicolas Ferre <nicolas.ferre@atmel.com> 1772 M: Nicolas Ferre <nicolas.ferre@atmel.com>
1773 S: Supported 1773 S: Supported
1774 F: drivers/net/ethernet/cadence/ 1774 F: drivers/net/ethernet/cadence/
1775 1775
1776 ATMEL NAND DRIVER 1776 ATMEL NAND DRIVER
1777 M: Josh Wu <josh.wu@atmel.com> 1777 M: Josh Wu <josh.wu@atmel.com>
1778 L: linux-mtd@lists.infradead.org 1778 L: linux-mtd@lists.infradead.org
1779 S: Supported 1779 S: Supported
1780 F: drivers/mtd/nand/atmel_nand* 1780 F: drivers/mtd/nand/atmel_nand*
1781 1781
1782 ATMEL SPI DRIVER 1782 ATMEL SPI DRIVER
1783 M: Nicolas Ferre <nicolas.ferre@atmel.com> 1783 M: Nicolas Ferre <nicolas.ferre@atmel.com>
1784 S: Supported 1784 S: Supported
1785 F: drivers/spi/spi-atmel.* 1785 F: drivers/spi/spi-atmel.*
1786 1786
1787 ATMEL SSC DRIVER 1787 ATMEL SSC DRIVER
1788 M: Bo Shen <voice.shen@atmel.com> 1788 M: Bo Shen <voice.shen@atmel.com>
1789 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1789 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1790 S: Supported 1790 S: Supported
1791 F: drivers/misc/atmel-ssc.c 1791 F: drivers/misc/atmel-ssc.c
1792 F: include/linux/atmel-ssc.h 1792 F: include/linux/atmel-ssc.h
1793 1793
1794 ATMEL Timer Counter (TC) AND CLOCKSOURCE DRIVERS 1794 ATMEL Timer Counter (TC) AND CLOCKSOURCE DRIVERS
1795 M: Nicolas Ferre <nicolas.ferre@atmel.com> 1795 M: Nicolas Ferre <nicolas.ferre@atmel.com>
1796 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1796 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1797 S: Supported 1797 S: Supported
1798 F: drivers/misc/atmel_tclib.c 1798 F: drivers/misc/atmel_tclib.c
1799 F: drivers/clocksource/tcb_clksrc.c 1799 F: drivers/clocksource/tcb_clksrc.c
1800 1800
1801 ATMEL USBA UDC DRIVER 1801 ATMEL USBA UDC DRIVER
1802 M: Nicolas Ferre <nicolas.ferre@atmel.com> 1802 M: Nicolas Ferre <nicolas.ferre@atmel.com>
1803 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1803 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1804 S: Supported 1804 S: Supported
1805 F: drivers/usb/gadget/udc/atmel_usba_udc.* 1805 F: drivers/usb/gadget/udc/atmel_usba_udc.*
1806 1806
1807 ATMEL WIRELESS DRIVER 1807 ATMEL WIRELESS DRIVER
1808 M: Simon Kelley <simon@thekelleys.org.uk> 1808 M: Simon Kelley <simon@thekelleys.org.uk>
1809 L: linux-wireless@vger.kernel.org 1809 L: linux-wireless@vger.kernel.org
1810 W: http://www.thekelleys.org.uk/atmel 1810 W: http://www.thekelleys.org.uk/atmel
1811 W: http://atmelwlandriver.sourceforge.net/ 1811 W: http://atmelwlandriver.sourceforge.net/
1812 S: Maintained 1812 S: Maintained
1813 F: drivers/net/wireless/atmel* 1813 F: drivers/net/wireless/atmel*
1814 1814
1815 ATTO EXPRESSSAS SAS/SATA RAID SCSI DRIVER 1815 ATTO EXPRESSSAS SAS/SATA RAID SCSI DRIVER
1816 M: Bradley Grove <linuxdrivers@attotech.com> 1816 M: Bradley Grove <linuxdrivers@attotech.com>
1817 L: linux-scsi@vger.kernel.org 1817 L: linux-scsi@vger.kernel.org
1818 W: http://www.attotech.com 1818 W: http://www.attotech.com
1819 S: Supported 1819 S: Supported
1820 F: drivers/scsi/esas2r 1820 F: drivers/scsi/esas2r
1821 1821
1822 AUDIT SUBSYSTEM 1822 AUDIT SUBSYSTEM
1823 M: Paul Moore <paul@paul-moore.com> 1823 M: Paul Moore <paul@paul-moore.com>
1824 M: Eric Paris <eparis@redhat.com> 1824 M: Eric Paris <eparis@redhat.com>
1825 L: linux-audit@redhat.com (moderated for non-subscribers) 1825 L: linux-audit@redhat.com (moderated for non-subscribers)
1826 W: http://people.redhat.com/sgrubb/audit/ 1826 W: http://people.redhat.com/sgrubb/audit/
1827 T: git git://git.infradead.org/users/pcmoore/audit 1827 T: git git://git.infradead.org/users/pcmoore/audit
1828 S: Maintained 1828 S: Maintained
1829 F: include/linux/audit.h 1829 F: include/linux/audit.h
1830 F: include/uapi/linux/audit.h 1830 F: include/uapi/linux/audit.h
1831 F: kernel/audit* 1831 F: kernel/audit*
1832 1832
1833 AUXILIARY DISPLAY DRIVERS 1833 AUXILIARY DISPLAY DRIVERS
1834 M: Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com> 1834 M: Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>
1835 W: http://miguelojeda.es/auxdisplay.htm 1835 W: http://miguelojeda.es/auxdisplay.htm
1836 W: http://jair.lab.fi.uva.es/~migojed/auxdisplay.htm 1836 W: http://jair.lab.fi.uva.es/~migojed/auxdisplay.htm
1837 S: Maintained 1837 S: Maintained
1838 F: drivers/auxdisplay/ 1838 F: drivers/auxdisplay/
1839 F: include/linux/cfag12864b.h 1839 F: include/linux/cfag12864b.h
1840 1840
1841 AVR32 ARCHITECTURE 1841 AVR32 ARCHITECTURE
1842 M: Haavard Skinnemoen <hskinnemoen@gmail.com> 1842 M: Haavard Skinnemoen <hskinnemoen@gmail.com>
1843 M: Hans-Christian Egtvedt <egtvedt@samfundet.no> 1843 M: Hans-Christian Egtvedt <egtvedt@samfundet.no>
1844 W: http://www.atmel.com/products/AVR32/ 1844 W: http://www.atmel.com/products/AVR32/
1845 W: http://mirror.egtvedt.no/avr32linux.org/ 1845 W: http://mirror.egtvedt.no/avr32linux.org/
1846 W: http://avrfreaks.net/ 1846 W: http://avrfreaks.net/
1847 S: Maintained 1847 S: Maintained
1848 F: arch/avr32/ 1848 F: arch/avr32/
1849 1849
1850 AVR32/AT32AP MACHINE SUPPORT 1850 AVR32/AT32AP MACHINE SUPPORT
1851 M: Haavard Skinnemoen <hskinnemoen@gmail.com> 1851 M: Haavard Skinnemoen <hskinnemoen@gmail.com>
1852 M: Hans-Christian Egtvedt <egtvedt@samfundet.no> 1852 M: Hans-Christian Egtvedt <egtvedt@samfundet.no>
1853 S: Maintained 1853 S: Maintained
1854 F: arch/avr32/mach-at32ap/ 1854 F: arch/avr32/mach-at32ap/
1855 1855
1856 AX.25 NETWORK LAYER 1856 AX.25 NETWORK LAYER
1857 M: Ralf Baechle <ralf@linux-mips.org> 1857 M: Ralf Baechle <ralf@linux-mips.org>
1858 L: linux-hams@vger.kernel.org 1858 L: linux-hams@vger.kernel.org
1859 W: http://www.linux-ax25.org/ 1859 W: http://www.linux-ax25.org/
1860 S: Maintained 1860 S: Maintained
1861 F: include/uapi/linux/ax25.h 1861 F: include/uapi/linux/ax25.h
1862 F: include/net/ax25.h 1862 F: include/net/ax25.h
1863 F: net/ax25/ 1863 F: net/ax25/
1864 1864
1865 AZ6007 DVB DRIVER 1865 AZ6007 DVB DRIVER
1866 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com> 1866 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
1867 L: linux-media@vger.kernel.org 1867 L: linux-media@vger.kernel.org
1868 W: http://linuxtv.org 1868 W: http://linuxtv.org
1869 T: git git://linuxtv.org/media_tree.git 1869 T: git git://linuxtv.org/media_tree.git
1870 S: Maintained 1870 S: Maintained
1871 F: drivers/media/usb/dvb-usb-v2/az6007.c 1871 F: drivers/media/usb/dvb-usb-v2/az6007.c
1872 1872
1873 AZTECH FM RADIO RECEIVER DRIVER 1873 AZTECH FM RADIO RECEIVER DRIVER
1874 M: Hans Verkuil <hverkuil@xs4all.nl> 1874 M: Hans Verkuil <hverkuil@xs4all.nl>
1875 L: linux-media@vger.kernel.org 1875 L: linux-media@vger.kernel.org
1876 T: git git://linuxtv.org/media_tree.git 1876 T: git git://linuxtv.org/media_tree.git
1877 W: http://linuxtv.org 1877 W: http://linuxtv.org
1878 S: Maintained 1878 S: Maintained
1879 F: drivers/media/radio/radio-aztech* 1879 F: drivers/media/radio/radio-aztech*
1880 1880
1881 B43 WIRELESS DRIVER 1881 B43 WIRELESS DRIVER
1882 M: Stefano Brivio <stefano.brivio@polimi.it> 1882 M: Stefano Brivio <stefano.brivio@polimi.it>
1883 L: linux-wireless@vger.kernel.org 1883 L: linux-wireless@vger.kernel.org
1884 L: b43-dev@lists.infradead.org 1884 L: b43-dev@lists.infradead.org
1885 W: http://wireless.kernel.org/en/users/Drivers/b43 1885 W: http://wireless.kernel.org/en/users/Drivers/b43
1886 S: Maintained 1886 S: Maintained
1887 F: drivers/net/wireless/b43/ 1887 F: drivers/net/wireless/b43/
1888 1888
1889 B43LEGACY WIRELESS DRIVER 1889 B43LEGACY WIRELESS DRIVER
1890 M: Larry Finger <Larry.Finger@lwfinger.net> 1890 M: Larry Finger <Larry.Finger@lwfinger.net>
1891 M: Stefano Brivio <stefano.brivio@polimi.it> 1891 M: Stefano Brivio <stefano.brivio@polimi.it>
1892 L: linux-wireless@vger.kernel.org 1892 L: linux-wireless@vger.kernel.org
1893 L: b43-dev@lists.infradead.org 1893 L: b43-dev@lists.infradead.org
1894 W: http://wireless.kernel.org/en/users/Drivers/b43 1894 W: http://wireless.kernel.org/en/users/Drivers/b43
1895 S: Maintained 1895 S: Maintained
1896 F: drivers/net/wireless/b43legacy/ 1896 F: drivers/net/wireless/b43legacy/
1897 1897
1898 BACKLIGHT CLASS/SUBSYSTEM 1898 BACKLIGHT CLASS/SUBSYSTEM
1899 M: Jingoo Han <jg1.han@samsung.com> 1899 M: Jingoo Han <jg1.han@samsung.com>
1900 M: Lee Jones <lee.jones@linaro.org> 1900 M: Lee Jones <lee.jones@linaro.org>
1901 S: Maintained 1901 S: Maintained
1902 F: drivers/video/backlight/ 1902 F: drivers/video/backlight/
1903 F: include/linux/backlight.h 1903 F: include/linux/backlight.h
1904 1904
1905 BATMAN ADVANCED 1905 BATMAN ADVANCED
1906 M: Marek Lindner <mareklindner@neomailbox.ch> 1906 M: Marek Lindner <mareklindner@neomailbox.ch>
1907 M: Simon Wunderlich <sw@simonwunderlich.de> 1907 M: Simon Wunderlich <sw@simonwunderlich.de>
1908 M: Antonio Quartulli <antonio@meshcoding.com> 1908 M: Antonio Quartulli <antonio@meshcoding.com>
1909 L: b.a.t.m.a.n@lists.open-mesh.org 1909 L: b.a.t.m.a.n@lists.open-mesh.org
1910 W: http://www.open-mesh.org/ 1910 W: http://www.open-mesh.org/
1911 S: Maintained 1911 S: Maintained
1912 F: net/batman-adv/ 1912 F: net/batman-adv/
1913 1913
1914 BAYCOM/HDLCDRV DRIVERS FOR AX.25 1914 BAYCOM/HDLCDRV DRIVERS FOR AX.25
1915 M: Thomas Sailer <t.sailer@alumni.ethz.ch> 1915 M: Thomas Sailer <t.sailer@alumni.ethz.ch>
1916 L: linux-hams@vger.kernel.org 1916 L: linux-hams@vger.kernel.org
1917 W: http://www.baycom.org/~tom/ham/ham.html 1917 W: http://www.baycom.org/~tom/ham/ham.html
1918 S: Maintained 1918 S: Maintained
1919 F: drivers/net/hamradio/baycom* 1919 F: drivers/net/hamradio/baycom*
1920 1920
1921 BCACHE (BLOCK LAYER CACHE) 1921 BCACHE (BLOCK LAYER CACHE)
1922 M: Kent Overstreet <kmo@daterainc.com> 1922 M: Kent Overstreet <kmo@daterainc.com>
1923 L: linux-bcache@vger.kernel.org 1923 L: linux-bcache@vger.kernel.org
1924 W: http://bcache.evilpiepirate.org 1924 W: http://bcache.evilpiepirate.org
1925 S: Maintained: 1925 S: Maintained:
1926 F: drivers/md/bcache/ 1926 F: drivers/md/bcache/
1927 1927
1928 BEFS FILE SYSTEM 1928 BEFS FILE SYSTEM
1929 S: Orphan 1929 S: Orphan
1930 F: Documentation/filesystems/befs.txt 1930 F: Documentation/filesystems/befs.txt
1931 F: fs/befs/ 1931 F: fs/befs/
1932 1932
1933 BECKHOFF CX5020 ETHERCAT MASTER DRIVER 1933 BECKHOFF CX5020 ETHERCAT MASTER DRIVER
1934 M: Dariusz Marcinkiewicz <reksio@newterm.pl> 1934 M: Dariusz Marcinkiewicz <reksio@newterm.pl>
1935 L: netdev@vger.kernel.org 1935 L: netdev@vger.kernel.org
1936 S: Maintained 1936 S: Maintained
1937 F: drivers/net/ethernet/ec_bhf.c 1937 F: drivers/net/ethernet/ec_bhf.c
1938 1938
1939 BFS FILE SYSTEM 1939 BFS FILE SYSTEM
1940 M: "Tigran A. Aivazian" <tigran@aivazian.fsnet.co.uk> 1940 M: "Tigran A. Aivazian" <tigran@aivazian.fsnet.co.uk>
1941 S: Maintained 1941 S: Maintained
1942 F: Documentation/filesystems/bfs.txt 1942 F: Documentation/filesystems/bfs.txt
1943 F: fs/bfs/ 1943 F: fs/bfs/
1944 F: include/uapi/linux/bfs_fs.h 1944 F: include/uapi/linux/bfs_fs.h
1945 1945
1946 BLACKFIN ARCHITECTURE 1946 BLACKFIN ARCHITECTURE
1947 M: Steven Miao <realmz6@gmail.com> 1947 M: Steven Miao <realmz6@gmail.com>
1948 L: adi-buildroot-devel@lists.sourceforge.net (moderated for non-subscribers) 1948 L: adi-buildroot-devel@lists.sourceforge.net (moderated for non-subscribers)
1949 T: git git://git.code.sf.net/p/adi-linux/code 1949 T: git git://git.code.sf.net/p/adi-linux/code
1950 W: http://blackfin.uclinux.org 1950 W: http://blackfin.uclinux.org
1951 S: Supported 1951 S: Supported
1952 F: arch/blackfin/ 1952 F: arch/blackfin/
1953 1953
1954 BLACKFIN EMAC DRIVER 1954 BLACKFIN EMAC DRIVER
1955 L: adi-buildroot-devel@lists.sourceforge.net (moderated for non-subscribers) 1955 L: adi-buildroot-devel@lists.sourceforge.net (moderated for non-subscribers)
1956 W: http://blackfin.uclinux.org 1956 W: http://blackfin.uclinux.org
1957 S: Supported 1957 S: Supported
1958 F: drivers/net/ethernet/adi/ 1958 F: drivers/net/ethernet/adi/
1959 1959
1960 BLACKFIN RTC DRIVER 1960 BLACKFIN RTC DRIVER
1961 L: adi-buildroot-devel@lists.sourceforge.net (moderated for non-subscribers) 1961 L: adi-buildroot-devel@lists.sourceforge.net (moderated for non-subscribers)
1962 W: http://blackfin.uclinux.org 1962 W: http://blackfin.uclinux.org
1963 S: Supported 1963 S: Supported
1964 F: drivers/rtc/rtc-bfin.c 1964 F: drivers/rtc/rtc-bfin.c
1965 1965
1966 BLACKFIN SDH DRIVER 1966 BLACKFIN SDH DRIVER
1967 M: Sonic Zhang <sonic.zhang@analog.com> 1967 M: Sonic Zhang <sonic.zhang@analog.com>
1968 L: adi-buildroot-devel@lists.sourceforge.net (moderated for non-subscribers) 1968 L: adi-buildroot-devel@lists.sourceforge.net (moderated for non-subscribers)
1969 W: http://blackfin.uclinux.org 1969 W: http://blackfin.uclinux.org
1970 S: Supported 1970 S: Supported
1971 F: drivers/mmc/host/bfin_sdh.c 1971 F: drivers/mmc/host/bfin_sdh.c
1972 1972
1973 BLACKFIN SERIAL DRIVER 1973 BLACKFIN SERIAL DRIVER
1974 M: Sonic Zhang <sonic.zhang@analog.com> 1974 M: Sonic Zhang <sonic.zhang@analog.com>
1975 L: adi-buildroot-devel@lists.sourceforge.net (moderated for non-subscribers) 1975 L: adi-buildroot-devel@lists.sourceforge.net (moderated for non-subscribers)
1976 W: http://blackfin.uclinux.org 1976 W: http://blackfin.uclinux.org
1977 S: Supported 1977 S: Supported
1978 F: drivers/tty/serial/bfin_uart.c 1978 F: drivers/tty/serial/bfin_uart.c
1979 1979
1980 BLACKFIN WATCHDOG DRIVER 1980 BLACKFIN WATCHDOG DRIVER
1981 L: adi-buildroot-devel@lists.sourceforge.net (moderated for non-subscribers) 1981 L: adi-buildroot-devel@lists.sourceforge.net (moderated for non-subscribers)
1982 W: http://blackfin.uclinux.org 1982 W: http://blackfin.uclinux.org
1983 S: Supported 1983 S: Supported
1984 F: drivers/watchdog/bfin_wdt.c 1984 F: drivers/watchdog/bfin_wdt.c
1985 1985
1986 BLACKFIN I2C TWI DRIVER 1986 BLACKFIN I2C TWI DRIVER
1987 M: Sonic Zhang <sonic.zhang@analog.com> 1987 M: Sonic Zhang <sonic.zhang@analog.com>
1988 L: adi-buildroot-devel@lists.sourceforge.net (moderated for non-subscribers) 1988 L: adi-buildroot-devel@lists.sourceforge.net (moderated for non-subscribers)
1989 W: http://blackfin.uclinux.org/ 1989 W: http://blackfin.uclinux.org/
1990 S: Supported 1990 S: Supported
1991 F: drivers/i2c/busses/i2c-bfin-twi.c 1991 F: drivers/i2c/busses/i2c-bfin-twi.c
1992 1992
1993 BLACKFIN MEDIA DRIVER 1993 BLACKFIN MEDIA DRIVER
1994 M: Scott Jiang <scott.jiang.linux@gmail.com> 1994 M: Scott Jiang <scott.jiang.linux@gmail.com>
1995 L: adi-buildroot-devel@lists.sourceforge.net (moderated for non-subscribers) 1995 L: adi-buildroot-devel@lists.sourceforge.net (moderated for non-subscribers)
1996 W: http://blackfin.uclinux.org/ 1996 W: http://blackfin.uclinux.org/
1997 S: Supported 1997 S: Supported
1998 F: drivers/media/platform/blackfin/ 1998 F: drivers/media/platform/blackfin/
1999 F: drivers/media/i2c/adv7183* 1999 F: drivers/media/i2c/adv7183*
2000 F: drivers/media/i2c/vs6624* 2000 F: drivers/media/i2c/vs6624*
2001 2001
2002 BLINKM RGB LED DRIVER 2002 BLINKM RGB LED DRIVER
2003 M: Jan-Simon Moeller <jansimon.moeller@gmx.de> 2003 M: Jan-Simon Moeller <jansimon.moeller@gmx.de>
2004 S: Maintained 2004 S: Maintained
2005 F: drivers/leds/leds-blinkm.c 2005 F: drivers/leds/leds-blinkm.c
2006 2006
2007 BLOCK LAYER 2007 BLOCK LAYER
2008 M: Jens Axboe <axboe@kernel.dk> 2008 M: Jens Axboe <axboe@kernel.dk>
2009 T: git git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git 2009 T: git git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git
2010 S: Maintained 2010 S: Maintained
2011 F: block/ 2011 F: block/
2012 2012
2013 BLOCK2MTD DRIVER 2013 BLOCK2MTD DRIVER
2014 M: Joern Engel <joern@lazybastard.org> 2014 M: Joern Engel <joern@lazybastard.org>
2015 L: linux-mtd@lists.infradead.org 2015 L: linux-mtd@lists.infradead.org
2016 S: Maintained 2016 S: Maintained
2017 F: drivers/mtd/devices/block2mtd.c 2017 F: drivers/mtd/devices/block2mtd.c
2018 2018
2019 BLUETOOTH DRIVERS 2019 BLUETOOTH DRIVERS
2020 M: Marcel Holtmann <marcel@holtmann.org> 2020 M: Marcel Holtmann <marcel@holtmann.org>
2021 M: Gustavo Padovan <gustavo@padovan.org> 2021 M: Gustavo Padovan <gustavo@padovan.org>
2022 M: Johan Hedberg <johan.hedberg@gmail.com> 2022 M: Johan Hedberg <johan.hedberg@gmail.com>
2023 L: linux-bluetooth@vger.kernel.org 2023 L: linux-bluetooth@vger.kernel.org
2024 W: http://www.bluez.org/ 2024 W: http://www.bluez.org/
2025 T: git git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth.git 2025 T: git git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth.git
2026 T: git git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git 2026 T: git git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git
2027 S: Maintained 2027 S: Maintained
2028 F: drivers/bluetooth/ 2028 F: drivers/bluetooth/
2029 2029
2030 BLUETOOTH SUBSYSTEM 2030 BLUETOOTH SUBSYSTEM
2031 M: Marcel Holtmann <marcel@holtmann.org> 2031 M: Marcel Holtmann <marcel@holtmann.org>
2032 M: Gustavo Padovan <gustavo@padovan.org> 2032 M: Gustavo Padovan <gustavo@padovan.org>
2033 M: Johan Hedberg <johan.hedberg@gmail.com> 2033 M: Johan Hedberg <johan.hedberg@gmail.com>
2034 L: linux-bluetooth@vger.kernel.org 2034 L: linux-bluetooth@vger.kernel.org
2035 W: http://www.bluez.org/ 2035 W: http://www.bluez.org/
2036 T: git git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth.git 2036 T: git git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth.git
2037 T: git git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git 2037 T: git git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git
2038 S: Maintained 2038 S: Maintained
2039 F: net/bluetooth/ 2039 F: net/bluetooth/
2040 F: include/net/bluetooth/ 2040 F: include/net/bluetooth/
2041 2041
2042 BONDING DRIVER 2042 BONDING DRIVER
2043 M: Jay Vosburgh <j.vosburgh@gmail.com> 2043 M: Jay Vosburgh <j.vosburgh@gmail.com>
2044 M: Veaceslav Falico <vfalico@gmail.com> 2044 M: Veaceslav Falico <vfalico@gmail.com>
2045 M: Andy Gospodarek <andy@greyhouse.net> 2045 M: Andy Gospodarek <andy@greyhouse.net>
2046 L: netdev@vger.kernel.org 2046 L: netdev@vger.kernel.org
2047 W: http://sourceforge.net/projects/bonding/ 2047 W: http://sourceforge.net/projects/bonding/
2048 S: Supported 2048 S: Supported
2049 F: drivers/net/bonding/ 2049 F: drivers/net/bonding/
2050 F: include/uapi/linux/if_bonding.h 2050 F: include/uapi/linux/if_bonding.h
2051 2051
2052 BPF (Safe dynamic programs and tools) 2052 BPF (Safe dynamic programs and tools)
2053 M: Alexei Starovoitov <ast@kernel.org> 2053 M: Alexei Starovoitov <ast@kernel.org>
2054 L: netdev@vger.kernel.org 2054 L: netdev@vger.kernel.org
2055 L: linux-kernel@vger.kernel.org 2055 L: linux-kernel@vger.kernel.org
2056 S: Supported 2056 S: Supported
2057 F: kernel/bpf/ 2057 F: kernel/bpf/
2058 2058
2059 BROADCOM B44 10/100 ETHERNET DRIVER 2059 BROADCOM B44 10/100 ETHERNET DRIVER
2060 M: Gary Zambrano <zambrano@broadcom.com> 2060 M: Gary Zambrano <zambrano@broadcom.com>
2061 L: netdev@vger.kernel.org 2061 L: netdev@vger.kernel.org
2062 S: Supported 2062 S: Supported
2063 F: drivers/net/ethernet/broadcom/b44.* 2063 F: drivers/net/ethernet/broadcom/b44.*
2064 2064
2065 BROADCOM GENET ETHERNET DRIVER 2065 BROADCOM GENET ETHERNET DRIVER
2066 M: Florian Fainelli <f.fainelli@gmail.com> 2066 M: Florian Fainelli <f.fainelli@gmail.com>
2067 L: netdev@vger.kernel.org 2067 L: netdev@vger.kernel.org
2068 S: Supported 2068 S: Supported
2069 F: drivers/net/ethernet/broadcom/genet/ 2069 F: drivers/net/ethernet/broadcom/genet/
2070 2070
2071 BROADCOM BNX2 GIGABIT ETHERNET DRIVER 2071 BROADCOM BNX2 GIGABIT ETHERNET DRIVER
2072 M: Sony Chacko <sony.chacko@qlogic.com> 2072 M: Sony Chacko <sony.chacko@qlogic.com>
2073 M: Dept-HSGLinuxNICDev@qlogic.com 2073 M: Dept-HSGLinuxNICDev@qlogic.com
2074 L: netdev@vger.kernel.org 2074 L: netdev@vger.kernel.org
2075 S: Supported 2075 S: Supported
2076 F: drivers/net/ethernet/broadcom/bnx2.* 2076 F: drivers/net/ethernet/broadcom/bnx2.*
2077 F: drivers/net/ethernet/broadcom/bnx2_* 2077 F: drivers/net/ethernet/broadcom/bnx2_*
2078 2078
2079 BROADCOM BNX2X 10 GIGABIT ETHERNET DRIVER 2079 BROADCOM BNX2X 10 GIGABIT ETHERNET DRIVER
2080 M: Ariel Elior <ariel.elior@qlogic.com> 2080 M: Ariel Elior <ariel.elior@qlogic.com>
2081 L: netdev@vger.kernel.org 2081 L: netdev@vger.kernel.org
2082 S: Supported 2082 S: Supported
2083 F: drivers/net/ethernet/broadcom/bnx2x/ 2083 F: drivers/net/ethernet/broadcom/bnx2x/
2084 2084
2085 BROADCOM BCM281XX/BCM11XXX/BCM216XX ARM ARCHITECTURE 2085 BROADCOM BCM281XX/BCM11XXX/BCM216XX ARM ARCHITECTURE
2086 M: Christian Daudt <bcm@fixthebug.org> 2086 M: Christian Daudt <bcm@fixthebug.org>
2087 M: Matt Porter <mporter@linaro.org> 2087 M: Matt Porter <mporter@linaro.org>
2088 M: Florian Fainelli <f.fainelli@gmail.com> 2088 M: Florian Fainelli <f.fainelli@gmail.com>
2089 L: bcm-kernel-feedback-list@broadcom.com 2089 L: bcm-kernel-feedback-list@broadcom.com
2090 T: git git://github.com/broadcom/mach-bcm 2090 T: git git://github.com/broadcom/mach-bcm
2091 S: Maintained 2091 S: Maintained
2092 F: arch/arm/mach-bcm/ 2092 F: arch/arm/mach-bcm/
2093 F: arch/arm/boot/dts/bcm113* 2093 F: arch/arm/boot/dts/bcm113*
2094 F: arch/arm/boot/dts/bcm216* 2094 F: arch/arm/boot/dts/bcm216*
2095 F: arch/arm/boot/dts/bcm281* 2095 F: arch/arm/boot/dts/bcm281*
2096 F: arch/arm/configs/bcm_defconfig 2096 F: arch/arm/configs/bcm_defconfig
2097 F: drivers/mmc/host/sdhci-bcm-kona.c 2097 F: drivers/mmc/host/sdhci-bcm-kona.c
2098 F: drivers/clocksource/bcm_kona_timer.c 2098 F: drivers/clocksource/bcm_kona_timer.c
2099 2099
2100 BROADCOM BCM2835 ARM ARCHITECTURE 2100 BROADCOM BCM2835 ARM ARCHITECTURE
2101 M: Stephen Warren <swarren@wwwdotorg.org> 2101 M: Stephen Warren <swarren@wwwdotorg.org>
2102 M: Lee Jones <lee@kernel.org> 2102 M: Lee Jones <lee@kernel.org>
2103 L: linux-rpi-kernel@lists.infradead.org (moderated for non-subscribers) 2103 L: linux-rpi-kernel@lists.infradead.org (moderated for non-subscribers)
2104 T: git git://git.kernel.org/pub/scm/linux/kernel/git/rpi/linux-rpi.git 2104 T: git git://git.kernel.org/pub/scm/linux/kernel/git/rpi/linux-rpi.git
2105 S: Maintained 2105 S: Maintained
2106 N: bcm2835 2106 N: bcm2835
2107 2107
2108 BROADCOM BCM33XX MIPS ARCHITECTURE 2108 BROADCOM BCM33XX MIPS ARCHITECTURE
2109 M: Kevin Cernekee <cernekee@gmail.com> 2109 M: Kevin Cernekee <cernekee@gmail.com>
2110 L: linux-mips@linux-mips.org 2110 L: linux-mips@linux-mips.org
2111 S: Maintained 2111 S: Maintained
2112 F: arch/mips/bcm3384/* 2112 F: arch/mips/bcm3384/*
2113 F: arch/mips/include/asm/mach-bcm3384/* 2113 F: arch/mips/include/asm/mach-bcm3384/*
2114 F: arch/mips/kernel/*bmips* 2114 F: arch/mips/kernel/*bmips*
2115 2115
2116 BROADCOM BCM5301X ARM ARCHITECTURE 2116 BROADCOM BCM5301X ARM ARCHITECTURE
2117 M: Hauke Mehrtens <hauke@hauke-m.de> 2117 M: Hauke Mehrtens <hauke@hauke-m.de>
2118 L: linux-arm-kernel@lists.infradead.org 2118 L: linux-arm-kernel@lists.infradead.org
2119 S: Maintained 2119 S: Maintained
2120 F: arch/arm/mach-bcm/bcm_5301x.c 2120 F: arch/arm/mach-bcm/bcm_5301x.c
2121 F: arch/arm/boot/dts/bcm5301x.dtsi 2121 F: arch/arm/boot/dts/bcm5301x.dtsi
2122 F: arch/arm/boot/dts/bcm470* 2122 F: arch/arm/boot/dts/bcm470*
2123 2123
2124 BROADCOM BCM63XX ARM ARCHITECTURE 2124 BROADCOM BCM63XX ARM ARCHITECTURE
2125 M: Florian Fainelli <f.fainelli@gmail.com> 2125 M: Florian Fainelli <f.fainelli@gmail.com>
2126 L: linux-arm-kernel@lists.infradead.org 2126 L: linux-arm-kernel@lists.infradead.org
2127 T: git git://git.github.com/brcm/linux.git 2127 T: git git://git.github.com/brcm/linux.git
2128 S: Maintained 2128 S: Maintained
2129 F: arch/arm/mach-bcm/bcm63xx.c 2129 F: arch/arm/mach-bcm/bcm63xx.c
2130 F: arch/arm/include/debug/bcm63xx.S 2130 F: arch/arm/include/debug/bcm63xx.S
2131 2131
2132 BROADCOM BCM63XX/BCM33XX UDC DRIVER 2132 BROADCOM BCM63XX/BCM33XX UDC DRIVER
2133 M: Kevin Cernekee <cernekee@gmail.com> 2133 M: Kevin Cernekee <cernekee@gmail.com>
2134 L: linux-usb@vger.kernel.org 2134 L: linux-usb@vger.kernel.org
2135 S: Maintained 2135 S: Maintained
2136 F: drivers/usb/gadget/udc/bcm63xx_udc.* 2136 F: drivers/usb/gadget/udc/bcm63xx_udc.*
2137 2137
2138 BROADCOM BCM7XXX ARM ARCHITECTURE 2138 BROADCOM BCM7XXX ARM ARCHITECTURE
2139 M: Marc Carino <marc.ceeeee@gmail.com> 2139 M: Marc Carino <marc.ceeeee@gmail.com>
2140 M: Brian Norris <computersforpeace@gmail.com> 2140 M: Brian Norris <computersforpeace@gmail.com>
2141 M: Gregory Fong <gregory.0xf0@gmail.com> 2141 M: Gregory Fong <gregory.0xf0@gmail.com>
2142 M: Florian Fainelli <f.fainelli@gmail.com> 2142 M: Florian Fainelli <f.fainelli@gmail.com>
2143 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 2143 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
2144 S: Maintained 2144 S: Maintained
2145 F: arch/arm/mach-bcm/*brcmstb* 2145 F: arch/arm/mach-bcm/*brcmstb*
2146 F: arch/arm/boot/dts/bcm7*.dts* 2146 F: arch/arm/boot/dts/bcm7*.dts*
2147 F: drivers/bus/brcmstb_gisb.c 2147 F: drivers/bus/brcmstb_gisb.c
2148 2148
2149 BROADCOM BMIPS MIPS ARCHITECTURE 2149 BROADCOM BMIPS MIPS ARCHITECTURE
2150 M: Kevin Cernekee <cernekee@gmail.com> 2150 M: Kevin Cernekee <cernekee@gmail.com>
2151 M: Florian Fainelli <f.fainelli@gmail.com> 2151 M: Florian Fainelli <f.fainelli@gmail.com>
2152 L: linux-mips@linux-mips.org 2152 L: linux-mips@linux-mips.org
2153 S: Maintained 2153 S: Maintained
2154 F: arch/mips/bmips/* 2154 F: arch/mips/bmips/*
2155 F: arch/mips/include/asm/mach-bmips/* 2155 F: arch/mips/include/asm/mach-bmips/*
2156 F: arch/mips/kernel/*bmips* 2156 F: arch/mips/kernel/*bmips*
2157 F: arch/mips/boot/dts/bcm*.dts* 2157 F: arch/mips/boot/dts/bcm*.dts*
2158 F: drivers/irqchip/irq-bcm7* 2158 F: drivers/irqchip/irq-bcm7*
2159 F: drivers/irqchip/irq-brcmstb* 2159 F: drivers/irqchip/irq-brcmstb*
2160 2160
2161 BROADCOM TG3 GIGABIT ETHERNET DRIVER 2161 BROADCOM TG3 GIGABIT ETHERNET DRIVER
2162 M: Prashant Sreedharan <prashant@broadcom.com> 2162 M: Prashant Sreedharan <prashant@broadcom.com>
2163 M: Michael Chan <mchan@broadcom.com> 2163 M: Michael Chan <mchan@broadcom.com>
2164 L: netdev@vger.kernel.org 2164 L: netdev@vger.kernel.org
2165 S: Supported 2165 S: Supported
2166 F: drivers/net/ethernet/broadcom/tg3.* 2166 F: drivers/net/ethernet/broadcom/tg3.*
2167 2167
2168 BROADCOM BRCM80211 IEEE802.11n WIRELESS DRIVER 2168 BROADCOM BRCM80211 IEEE802.11n WIRELESS DRIVER
2169 M: Brett Rudley <brudley@broadcom.com> 2169 M: Brett Rudley <brudley@broadcom.com>
2170 M: Arend van Spriel <arend@broadcom.com> 2170 M: Arend van Spriel <arend@broadcom.com>
2171 M: Franky (Zhenhui) Lin <frankyl@broadcom.com> 2171 M: Franky (Zhenhui) Lin <frankyl@broadcom.com>
2172 M: Hante Meuleman <meuleman@broadcom.com> 2172 M: Hante Meuleman <meuleman@broadcom.com>
2173 L: linux-wireless@vger.kernel.org 2173 L: linux-wireless@vger.kernel.org
2174 L: brcm80211-dev-list@broadcom.com 2174 L: brcm80211-dev-list@broadcom.com
2175 S: Supported 2175 S: Supported
2176 F: drivers/net/wireless/brcm80211/ 2176 F: drivers/net/wireless/brcm80211/
2177 2177
2178 BROADCOM BNX2FC 10 GIGABIT FCOE DRIVER 2178 BROADCOM BNX2FC 10 GIGABIT FCOE DRIVER
2179 M: QLogic-Storage-Upstream@qlogic.com 2179 M: QLogic-Storage-Upstream@qlogic.com
2180 L: linux-scsi@vger.kernel.org 2180 L: linux-scsi@vger.kernel.org
2181 S: Supported 2181 S: Supported
2182 F: drivers/scsi/bnx2fc/ 2182 F: drivers/scsi/bnx2fc/
2183 2183
2184 BROADCOM BNX2I 1/10 GIGABIT iSCSI DRIVER 2184 BROADCOM BNX2I 1/10 GIGABIT iSCSI DRIVER
2185 M: QLogic-Storage-Upstream@qlogic.com 2185 M: QLogic-Storage-Upstream@qlogic.com
2186 L: linux-scsi@vger.kernel.org 2186 L: linux-scsi@vger.kernel.org
2187 S: Supported 2187 S: Supported
2188 F: drivers/scsi/bnx2i/ 2188 F: drivers/scsi/bnx2i/
2189 2189
2190 BROADCOM CYGNUS/IPROC ARM ARCHITECTURE 2190 BROADCOM CYGNUS/IPROC ARM ARCHITECTURE
2191 M: Ray Jui <rjui@broadcom.com> 2191 M: Ray Jui <rjui@broadcom.com>
2192 M: Scott Branden <sbranden@broadcom.com> 2192 M: Scott Branden <sbranden@broadcom.com>
2193 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 2193 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
2194 L: bcm-kernel-feedback-list@broadcom.com 2194 L: bcm-kernel-feedback-list@broadcom.com
2195 T: git git://git.github.com/brcm/linux.git 2195 T: git git://git.github.com/brcm/linux.git
2196 S: Maintained 2196 S: Maintained
2197 N: iproc 2197 N: iproc
2198 N: cygnus 2198 N: cygnus
2199 N: bcm9113* 2199 N: bcm9113*
2200 N: bcm9583* 2200 N: bcm9583*
2201 N: bcm583* 2201 N: bcm583*
2202 N: bcm113* 2202 N: bcm113*
2203 2203
2204 BROADCOM KONA GPIO DRIVER 2204 BROADCOM KONA GPIO DRIVER
2205 M: Ray Jui <rjui@broadcom.com> 2205 M: Ray Jui <rjui@broadcom.com>
2206 L: bcm-kernel-feedback-list@broadcom.com 2206 L: bcm-kernel-feedback-list@broadcom.com
2207 S: Supported 2207 S: Supported
2208 F: drivers/gpio/gpio-bcm-kona.c 2208 F: drivers/gpio/gpio-bcm-kona.c
2209 F: Documentation/devicetree/bindings/gpio/gpio-bcm-kona.txt 2209 F: Documentation/devicetree/bindings/gpio/gpio-bcm-kona.txt
2210 2210
2211 BROADCOM SPECIFIC AMBA DRIVER (BCMA) 2211 BROADCOM SPECIFIC AMBA DRIVER (BCMA)
2212 M: Rafaล‚ Miล‚ecki <zajec5@gmail.com> 2212 M: Rafaล‚ Miล‚ecki <zajec5@gmail.com>
2213 L: linux-wireless@vger.kernel.org 2213 L: linux-wireless@vger.kernel.org
2214 S: Maintained 2214 S: Maintained
2215 F: drivers/bcma/ 2215 F: drivers/bcma/
2216 F: include/linux/bcma/ 2216 F: include/linux/bcma/
2217 2217
2218 BROADCOM SYSTEMPORT ETHERNET DRIVER 2218 BROADCOM SYSTEMPORT ETHERNET DRIVER
2219 M: Florian Fainelli <f.fainelli@gmail.com> 2219 M: Florian Fainelli <f.fainelli@gmail.com>
2220 L: netdev@vger.kernel.org 2220 L: netdev@vger.kernel.org
2221 S: Supported 2221 S: Supported
2222 F: drivers/net/ethernet/broadcom/bcmsysport.* 2222 F: drivers/net/ethernet/broadcom/bcmsysport.*
2223 2223
2224 BROCADE BFA FC SCSI DRIVER 2224 BROCADE BFA FC SCSI DRIVER
2225 M: Anil Gurumurthy <anil.gurumurthy@qlogic.com> 2225 M: Anil Gurumurthy <anil.gurumurthy@qlogic.com>
2226 M: Sudarsana Kalluru <sudarsana.kalluru@qlogic.com> 2226 M: Sudarsana Kalluru <sudarsana.kalluru@qlogic.com>
2227 L: linux-scsi@vger.kernel.org 2227 L: linux-scsi@vger.kernel.org
2228 S: Supported 2228 S: Supported
2229 F: drivers/scsi/bfa/ 2229 F: drivers/scsi/bfa/
2230 2230
2231 BROCADE BNA 10 GIGABIT ETHERNET DRIVER 2231 BROCADE BNA 10 GIGABIT ETHERNET DRIVER
2232 M: Rasesh Mody <rasesh.mody@qlogic.com> 2232 M: Rasesh Mody <rasesh.mody@qlogic.com>
2233 L: netdev@vger.kernel.org 2233 L: netdev@vger.kernel.org
2234 S: Supported 2234 S: Supported
2235 F: drivers/net/ethernet/brocade/bna/ 2235 F: drivers/net/ethernet/brocade/bna/
2236 2236
2237 BSG (block layer generic sg v4 driver) 2237 BSG (block layer generic sg v4 driver)
2238 M: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> 2238 M: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
2239 L: linux-scsi@vger.kernel.org 2239 L: linux-scsi@vger.kernel.org
2240 S: Supported 2240 S: Supported
2241 F: block/bsg.c 2241 F: block/bsg.c
2242 F: include/linux/bsg.h 2242 F: include/linux/bsg.h
2243 F: include/uapi/linux/bsg.h 2243 F: include/uapi/linux/bsg.h
2244 2244
2245 BT87X AUDIO DRIVER 2245 BT87X AUDIO DRIVER
2246 M: Clemens Ladisch <clemens@ladisch.de> 2246 M: Clemens Ladisch <clemens@ladisch.de>
2247 L: alsa-devel@alsa-project.org (moderated for non-subscribers) 2247 L: alsa-devel@alsa-project.org (moderated for non-subscribers)
2248 T: git git://git.alsa-project.org/alsa-kernel.git 2248 T: git git://git.alsa-project.org/alsa-kernel.git
2249 S: Maintained 2249 S: Maintained
2250 F: Documentation/sound/alsa/Bt87x.txt 2250 F: Documentation/sound/alsa/Bt87x.txt
2251 F: sound/pci/bt87x.c 2251 F: sound/pci/bt87x.c
2252 2252
2253 BT8XXGPIO DRIVER 2253 BT8XXGPIO DRIVER
2254 M: Michael Buesch <m@bues.ch> 2254 M: Michael Buesch <m@bues.ch>
2255 W: http://bu3sch.de/btgpio.php 2255 W: http://bu3sch.de/btgpio.php
2256 S: Maintained 2256 S: Maintained
2257 F: drivers/gpio/gpio-bt8xx.c 2257 F: drivers/gpio/gpio-bt8xx.c
2258 2258
2259 BTRFS FILE SYSTEM 2259 BTRFS FILE SYSTEM
2260 M: Chris Mason <clm@fb.com> 2260 M: Chris Mason <clm@fb.com>
2261 M: Josef Bacik <jbacik@fb.com> 2261 M: Josef Bacik <jbacik@fb.com>
2262 M: David Sterba <dsterba@suse.cz>
2262 L: linux-btrfs@vger.kernel.org 2263 L: linux-btrfs@vger.kernel.org
2263 W: http://btrfs.wiki.kernel.org/ 2264 W: http://btrfs.wiki.kernel.org/
2264 Q: http://patchwork.kernel.org/project/linux-btrfs/list/ 2265 Q: http://patchwork.kernel.org/project/linux-btrfs/list/
2265 T: git git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs.git 2266 T: git git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs.git
2266 S: Maintained 2267 S: Maintained
2267 F: Documentation/filesystems/btrfs.txt 2268 F: Documentation/filesystems/btrfs.txt
2268 F: fs/btrfs/ 2269 F: fs/btrfs/
2269 2270
2270 BTTV VIDEO4LINUX DRIVER 2271 BTTV VIDEO4LINUX DRIVER
2271 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com> 2272 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2272 L: linux-media@vger.kernel.org 2273 L: linux-media@vger.kernel.org
2273 W: http://linuxtv.org 2274 W: http://linuxtv.org
2274 T: git git://linuxtv.org/media_tree.git 2275 T: git git://linuxtv.org/media_tree.git
2275 S: Odd fixes 2276 S: Odd fixes
2276 F: Documentation/video4linux/bttv/ 2277 F: Documentation/video4linux/bttv/
2277 F: drivers/media/pci/bt8xx/bttv* 2278 F: drivers/media/pci/bt8xx/bttv*
2278 2279
2279 BUSLOGIC SCSI DRIVER 2280 BUSLOGIC SCSI DRIVER
2280 M: Khalid Aziz <khalid@gonehiking.org> 2281 M: Khalid Aziz <khalid@gonehiking.org>
2281 L: linux-scsi@vger.kernel.org 2282 L: linux-scsi@vger.kernel.org
2282 S: Maintained 2283 S: Maintained
2283 F: drivers/scsi/BusLogic.* 2284 F: drivers/scsi/BusLogic.*
2284 F: drivers/scsi/FlashPoint.* 2285 F: drivers/scsi/FlashPoint.*
2285 2286
2286 C-MEDIA CMI8788 DRIVER 2287 C-MEDIA CMI8788 DRIVER
2287 M: Clemens Ladisch <clemens@ladisch.de> 2288 M: Clemens Ladisch <clemens@ladisch.de>
2288 L: alsa-devel@alsa-project.org (moderated for non-subscribers) 2289 L: alsa-devel@alsa-project.org (moderated for non-subscribers)
2289 T: git git://git.alsa-project.org/alsa-kernel.git 2290 T: git git://git.alsa-project.org/alsa-kernel.git
2290 S: Maintained 2291 S: Maintained
2291 F: sound/pci/oxygen/ 2292 F: sound/pci/oxygen/
2292 2293
2293 C6X ARCHITECTURE 2294 C6X ARCHITECTURE
2294 M: Mark Salter <msalter@redhat.com> 2295 M: Mark Salter <msalter@redhat.com>
2295 M: Aurelien Jacquiot <a-jacquiot@ti.com> 2296 M: Aurelien Jacquiot <a-jacquiot@ti.com>
2296 L: linux-c6x-dev@linux-c6x.org 2297 L: linux-c6x-dev@linux-c6x.org
2297 W: http://www.linux-c6x.org/wiki/index.php/Main_Page 2298 W: http://www.linux-c6x.org/wiki/index.php/Main_Page
2298 S: Maintained 2299 S: Maintained
2299 F: arch/c6x/ 2300 F: arch/c6x/
2300 2301
2301 CACHEFILES: FS-CACHE BACKEND FOR CACHING ON MOUNTED FILESYSTEMS 2302 CACHEFILES: FS-CACHE BACKEND FOR CACHING ON MOUNTED FILESYSTEMS
2302 M: David Howells <dhowells@redhat.com> 2303 M: David Howells <dhowells@redhat.com>
2303 L: linux-cachefs@redhat.com 2304 L: linux-cachefs@redhat.com
2304 S: Supported 2305 S: Supported
2305 F: Documentation/filesystems/caching/cachefiles.txt 2306 F: Documentation/filesystems/caching/cachefiles.txt
2306 F: fs/cachefiles/ 2307 F: fs/cachefiles/
2307 2308
2308 CADET FM/AM RADIO RECEIVER DRIVER 2309 CADET FM/AM RADIO RECEIVER DRIVER
2309 M: Hans Verkuil <hverkuil@xs4all.nl> 2310 M: Hans Verkuil <hverkuil@xs4all.nl>
2310 L: linux-media@vger.kernel.org 2311 L: linux-media@vger.kernel.org
2311 T: git git://linuxtv.org/media_tree.git 2312 T: git git://linuxtv.org/media_tree.git
2312 W: http://linuxtv.org 2313 W: http://linuxtv.org
2313 S: Maintained 2314 S: Maintained
2314 F: drivers/media/radio/radio-cadet* 2315 F: drivers/media/radio/radio-cadet*
2315 2316
2316 CAFE CMOS INTEGRATED CAMERA CONTROLLER DRIVER 2317 CAFE CMOS INTEGRATED CAMERA CONTROLLER DRIVER
2317 M: Jonathan Corbet <corbet@lwn.net> 2318 M: Jonathan Corbet <corbet@lwn.net>
2318 L: linux-media@vger.kernel.org 2319 L: linux-media@vger.kernel.org
2319 T: git git://linuxtv.org/media_tree.git 2320 T: git git://linuxtv.org/media_tree.git
2320 S: Maintained 2321 S: Maintained
2321 F: Documentation/video4linux/cafe_ccic 2322 F: Documentation/video4linux/cafe_ccic
2322 F: drivers/media/platform/marvell-ccic/ 2323 F: drivers/media/platform/marvell-ccic/
2323 2324
2324 CAIF NETWORK LAYER 2325 CAIF NETWORK LAYER
2325 M: Dmitry Tarnyagin <dmitry.tarnyagin@lockless.no> 2326 M: Dmitry Tarnyagin <dmitry.tarnyagin@lockless.no>
2326 L: netdev@vger.kernel.org 2327 L: netdev@vger.kernel.org
2327 S: Supported 2328 S: Supported
2328 F: Documentation/networking/caif/ 2329 F: Documentation/networking/caif/
2329 F: drivers/net/caif/ 2330 F: drivers/net/caif/
2330 F: include/uapi/linux/caif/ 2331 F: include/uapi/linux/caif/
2331 F: include/net/caif/ 2332 F: include/net/caif/
2332 F: net/caif/ 2333 F: net/caif/
2333 2334
2334 CALGARY x86-64 IOMMU 2335 CALGARY x86-64 IOMMU
2335 M: Muli Ben-Yehuda <muli@il.ibm.com> 2336 M: Muli Ben-Yehuda <muli@il.ibm.com>
2336 M: "Jon D. Mason" <jdmason@kudzu.us> 2337 M: "Jon D. Mason" <jdmason@kudzu.us>
2337 L: discuss@x86-64.org 2338 L: discuss@x86-64.org
2338 S: Maintained 2339 S: Maintained
2339 F: arch/x86/kernel/pci-calgary_64.c 2340 F: arch/x86/kernel/pci-calgary_64.c
2340 F: arch/x86/kernel/tce_64.c 2341 F: arch/x86/kernel/tce_64.c
2341 F: arch/x86/include/asm/calgary.h 2342 F: arch/x86/include/asm/calgary.h
2342 F: arch/x86/include/asm/tce.h 2343 F: arch/x86/include/asm/tce.h
2343 2344
2344 CAN NETWORK LAYER 2345 CAN NETWORK LAYER
2345 M: Oliver Hartkopp <socketcan@hartkopp.net> 2346 M: Oliver Hartkopp <socketcan@hartkopp.net>
2346 L: linux-can@vger.kernel.org 2347 L: linux-can@vger.kernel.org
2347 W: http://gitorious.org/linux-can 2348 W: http://gitorious.org/linux-can
2348 T: git git://gitorious.org/linux-can/linux-can-next.git 2349 T: git git://gitorious.org/linux-can/linux-can-next.git
2349 S: Maintained 2350 S: Maintained
2350 F: Documentation/networking/can.txt 2351 F: Documentation/networking/can.txt
2351 F: net/can/ 2352 F: net/can/
2352 F: include/linux/can/core.h 2353 F: include/linux/can/core.h
2353 F: include/uapi/linux/can.h 2354 F: include/uapi/linux/can.h
2354 F: include/uapi/linux/can/bcm.h 2355 F: include/uapi/linux/can/bcm.h
2355 F: include/uapi/linux/can/raw.h 2356 F: include/uapi/linux/can/raw.h
2356 F: include/uapi/linux/can/gw.h 2357 F: include/uapi/linux/can/gw.h
2357 2358
2358 CAN NETWORK DRIVERS 2359 CAN NETWORK DRIVERS
2359 M: Wolfgang Grandegger <wg@grandegger.com> 2360 M: Wolfgang Grandegger <wg@grandegger.com>
2360 M: Marc Kleine-Budde <mkl@pengutronix.de> 2361 M: Marc Kleine-Budde <mkl@pengutronix.de>
2361 L: linux-can@vger.kernel.org 2362 L: linux-can@vger.kernel.org
2362 W: http://gitorious.org/linux-can 2363 W: http://gitorious.org/linux-can
2363 T: git git://gitorious.org/linux-can/linux-can-next.git 2364 T: git git://gitorious.org/linux-can/linux-can-next.git
2364 S: Maintained 2365 S: Maintained
2365 F: drivers/net/can/ 2366 F: drivers/net/can/
2366 F: include/linux/can/dev.h 2367 F: include/linux/can/dev.h
2367 F: include/linux/can/platform/ 2368 F: include/linux/can/platform/
2368 F: include/uapi/linux/can/error.h 2369 F: include/uapi/linux/can/error.h
2369 F: include/uapi/linux/can/netlink.h 2370 F: include/uapi/linux/can/netlink.h
2370 2371
2371 CAPABILITIES 2372 CAPABILITIES
2372 M: Serge Hallyn <serge.hallyn@canonical.com> 2373 M: Serge Hallyn <serge.hallyn@canonical.com>
2373 L: linux-security-module@vger.kernel.org 2374 L: linux-security-module@vger.kernel.org
2374 S: Supported 2375 S: Supported
2375 F: include/linux/capability.h 2376 F: include/linux/capability.h
2376 F: include/uapi/linux/capability.h 2377 F: include/uapi/linux/capability.h
2377 F: security/capability.c 2378 F: security/capability.c
2378 F: security/commoncap.c 2379 F: security/commoncap.c
2379 F: kernel/capability.c 2380 F: kernel/capability.c
2380 2381
2381 CC2520 IEEE-802.15.4 RADIO DRIVER 2382 CC2520 IEEE-802.15.4 RADIO DRIVER
2382 M: Varka Bhadram <varkabhadram@gmail.com> 2383 M: Varka Bhadram <varkabhadram@gmail.com>
2383 L: linux-wpan@vger.kernel.org 2384 L: linux-wpan@vger.kernel.org
2384 S: Maintained 2385 S: Maintained
2385 F: drivers/net/ieee802154/cc2520.c 2386 F: drivers/net/ieee802154/cc2520.c
2386 F: include/linux/spi/cc2520.h 2387 F: include/linux/spi/cc2520.h
2387 F: Documentation/devicetree/bindings/net/ieee802154/cc2520.txt 2388 F: Documentation/devicetree/bindings/net/ieee802154/cc2520.txt
2388 2389
2389 CELL BROADBAND ENGINE ARCHITECTURE 2390 CELL BROADBAND ENGINE ARCHITECTURE
2390 M: Arnd Bergmann <arnd@arndb.de> 2391 M: Arnd Bergmann <arnd@arndb.de>
2391 L: linuxppc-dev@lists.ozlabs.org 2392 L: linuxppc-dev@lists.ozlabs.org
2392 L: cbe-oss-dev@lists.ozlabs.org 2393 L: cbe-oss-dev@lists.ozlabs.org
2393 W: http://www.ibm.com/developerworks/power/cell/ 2394 W: http://www.ibm.com/developerworks/power/cell/
2394 S: Supported 2395 S: Supported
2395 F: arch/powerpc/include/asm/cell*.h 2396 F: arch/powerpc/include/asm/cell*.h
2396 F: arch/powerpc/include/asm/spu*.h 2397 F: arch/powerpc/include/asm/spu*.h
2397 F: arch/powerpc/include/uapi/asm/spu*.h 2398 F: arch/powerpc/include/uapi/asm/spu*.h
2398 F: arch/powerpc/oprofile/*cell* 2399 F: arch/powerpc/oprofile/*cell*
2399 F: arch/powerpc/platforms/cell/ 2400 F: arch/powerpc/platforms/cell/
2400 2401
2401 CEPH DISTRIBUTED FILE SYSTEM CLIENT 2402 CEPH DISTRIBUTED FILE SYSTEM CLIENT
2402 M: Sage Weil <sage@inktank.com> 2403 M: Sage Weil <sage@inktank.com>
2403 L: ceph-devel@vger.kernel.org 2404 L: ceph-devel@vger.kernel.org
2404 W: http://ceph.com/ 2405 W: http://ceph.com/
2405 T: git git://git.kernel.org/pub/scm/linux/kernel/git/sage/ceph-client.git 2406 T: git git://git.kernel.org/pub/scm/linux/kernel/git/sage/ceph-client.git
2406 S: Supported 2407 S: Supported
2407 F: Documentation/filesystems/ceph.txt 2408 F: Documentation/filesystems/ceph.txt
2408 F: fs/ceph/ 2409 F: fs/ceph/
2409 F: net/ceph/ 2410 F: net/ceph/
2410 F: include/linux/ceph/ 2411 F: include/linux/ceph/
2411 F: include/linux/crush/ 2412 F: include/linux/crush/
2412 2413
2413 CERTIFIED WIRELESS USB (WUSB) SUBSYSTEM: 2414 CERTIFIED WIRELESS USB (WUSB) SUBSYSTEM:
2414 L: linux-usb@vger.kernel.org 2415 L: linux-usb@vger.kernel.org
2415 S: Orphan 2416 S: Orphan
2416 F: Documentation/usb/WUSB-Design-overview.txt 2417 F: Documentation/usb/WUSB-Design-overview.txt
2417 F: Documentation/usb/wusb-cbaf 2418 F: Documentation/usb/wusb-cbaf
2418 F: drivers/usb/host/hwa-hc.c 2419 F: drivers/usb/host/hwa-hc.c
2419 F: drivers/usb/host/whci/ 2420 F: drivers/usb/host/whci/
2420 F: drivers/usb/wusbcore/ 2421 F: drivers/usb/wusbcore/
2421 F: include/linux/usb/wusb* 2422 F: include/linux/usb/wusb*
2422 2423
2423 CFAG12864B LCD DRIVER 2424 CFAG12864B LCD DRIVER
2424 M: Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com> 2425 M: Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>
2425 W: http://miguelojeda.es/auxdisplay.htm 2426 W: http://miguelojeda.es/auxdisplay.htm
2426 W: http://jair.lab.fi.uva.es/~migojed/auxdisplay.htm 2427 W: http://jair.lab.fi.uva.es/~migojed/auxdisplay.htm
2427 S: Maintained 2428 S: Maintained
2428 F: drivers/auxdisplay/cfag12864b.c 2429 F: drivers/auxdisplay/cfag12864b.c
2429 F: include/linux/cfag12864b.h 2430 F: include/linux/cfag12864b.h
2430 2431
2431 CFAG12864BFB LCD FRAMEBUFFER DRIVER 2432 CFAG12864BFB LCD FRAMEBUFFER DRIVER
2432 M: Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com> 2433 M: Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>
2433 W: http://miguelojeda.es/auxdisplay.htm 2434 W: http://miguelojeda.es/auxdisplay.htm
2434 W: http://jair.lab.fi.uva.es/~migojed/auxdisplay.htm 2435 W: http://jair.lab.fi.uva.es/~migojed/auxdisplay.htm
2435 S: Maintained 2436 S: Maintained
2436 F: drivers/auxdisplay/cfag12864bfb.c 2437 F: drivers/auxdisplay/cfag12864bfb.c
2437 F: include/linux/cfag12864b.h 2438 F: include/linux/cfag12864b.h
2438 2439
2439 CFG80211 and NL80211 2440 CFG80211 and NL80211
2440 M: Johannes Berg <johannes@sipsolutions.net> 2441 M: Johannes Berg <johannes@sipsolutions.net>
2441 L: linux-wireless@vger.kernel.org 2442 L: linux-wireless@vger.kernel.org
2442 W: http://wireless.kernel.org/ 2443 W: http://wireless.kernel.org/
2443 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211.git 2444 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211.git
2444 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211-next.git 2445 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211-next.git
2445 S: Maintained 2446 S: Maintained
2446 F: include/uapi/linux/nl80211.h 2447 F: include/uapi/linux/nl80211.h
2447 F: include/net/cfg80211.h 2448 F: include/net/cfg80211.h
2448 F: net/wireless/* 2449 F: net/wireless/*
2449 X: net/wireless/wext* 2450 X: net/wireless/wext*
2450 2451
2451 CHAR and MISC DRIVERS 2452 CHAR and MISC DRIVERS
2452 M: Arnd Bergmann <arnd@arndb.de> 2453 M: Arnd Bergmann <arnd@arndb.de>
2453 M: Greg Kroah-Hartman <gregkh@linuxfoundation.org> 2454 M: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2454 T: git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git 2455 T: git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git
2455 S: Supported 2456 S: Supported
2456 F: drivers/char/* 2457 F: drivers/char/*
2457 F: drivers/misc/* 2458 F: drivers/misc/*
2458 F: include/linux/miscdevice.h 2459 F: include/linux/miscdevice.h
2459 2460
2460 CHECKPATCH 2461 CHECKPATCH
2461 M: Andy Whitcroft <apw@canonical.com> 2462 M: Andy Whitcroft <apw@canonical.com>
2462 M: Joe Perches <joe@perches.com> 2463 M: Joe Perches <joe@perches.com>
2463 S: Maintained 2464 S: Maintained
2464 F: scripts/checkpatch.pl 2465 F: scripts/checkpatch.pl
2465 2466
2466 CHINESE DOCUMENTATION 2467 CHINESE DOCUMENTATION
2467 M: Harry Wei <harryxiyou@gmail.com> 2468 M: Harry Wei <harryxiyou@gmail.com>
2468 L: xiyoulinuxkernelgroup@googlegroups.com (subscribers-only) 2469 L: xiyoulinuxkernelgroup@googlegroups.com (subscribers-only)
2469 L: linux-kernel@zh-kernel.org (moderated for non-subscribers) 2470 L: linux-kernel@zh-kernel.org (moderated for non-subscribers)
2470 S: Maintained 2471 S: Maintained
2471 F: Documentation/zh_CN/ 2472 F: Documentation/zh_CN/
2472 2473
2473 CHIPIDEA USB HIGH SPEED DUAL ROLE CONTROLLER 2474 CHIPIDEA USB HIGH SPEED DUAL ROLE CONTROLLER
2474 M: Peter Chen <Peter.Chen@freescale.com> 2475 M: Peter Chen <Peter.Chen@freescale.com>
2475 T: git git://github.com/hzpeterchen/linux-usb.git 2476 T: git git://github.com/hzpeterchen/linux-usb.git
2476 L: linux-usb@vger.kernel.org 2477 L: linux-usb@vger.kernel.org
2477 S: Maintained 2478 S: Maintained
2478 F: drivers/usb/chipidea/ 2479 F: drivers/usb/chipidea/
2479 2480
2480 CHROME HARDWARE PLATFORM SUPPORT 2481 CHROME HARDWARE PLATFORM SUPPORT
2481 M: Olof Johansson <olof@lixom.net> 2482 M: Olof Johansson <olof@lixom.net>
2482 S: Maintained 2483 S: Maintained
2483 F: drivers/platform/chrome/ 2484 F: drivers/platform/chrome/
2484 2485
2485 CISCO VIC ETHERNET NIC DRIVER 2486 CISCO VIC ETHERNET NIC DRIVER
2486 M: Christian Benvenuti <benve@cisco.com> 2487 M: Christian Benvenuti <benve@cisco.com>
2487 M: Sujith Sankar <ssujith@cisco.com> 2488 M: Sujith Sankar <ssujith@cisco.com>
2488 M: Govindarajulu Varadarajan <_govind@gmx.com> 2489 M: Govindarajulu Varadarajan <_govind@gmx.com>
2489 M: Neel Patel <neepatel@cisco.com> 2490 M: Neel Patel <neepatel@cisco.com>
2490 S: Supported 2491 S: Supported
2491 F: drivers/net/ethernet/cisco/enic/ 2492 F: drivers/net/ethernet/cisco/enic/
2492 2493
2493 CISCO VIC LOW LATENCY NIC DRIVER 2494 CISCO VIC LOW LATENCY NIC DRIVER
2494 M: Upinder Malhi <umalhi@cisco.com> 2495 M: Upinder Malhi <umalhi@cisco.com>
2495 S: Supported 2496 S: Supported
2496 F: drivers/infiniband/hw/usnic 2497 F: drivers/infiniband/hw/usnic
2497 2498
2498 CIRRUS LOGIC EP93XX ETHERNET DRIVER 2499 CIRRUS LOGIC EP93XX ETHERNET DRIVER
2499 M: Hartley Sweeten <hsweeten@visionengravers.com> 2500 M: Hartley Sweeten <hsweeten@visionengravers.com>
2500 L: netdev@vger.kernel.org 2501 L: netdev@vger.kernel.org
2501 S: Maintained 2502 S: Maintained
2502 F: drivers/net/ethernet/cirrus/ep93xx_eth.c 2503 F: drivers/net/ethernet/cirrus/ep93xx_eth.c
2503 2504
2504 CIRRUS LOGIC AUDIO CODEC DRIVERS 2505 CIRRUS LOGIC AUDIO CODEC DRIVERS
2505 M: Brian Austin <brian.austin@cirrus.com> 2506 M: Brian Austin <brian.austin@cirrus.com>
2506 M: Paul Handrigan <Paul.Handrigan@cirrus.com> 2507 M: Paul Handrigan <Paul.Handrigan@cirrus.com>
2507 L: alsa-devel@alsa-project.org (moderated for non-subscribers) 2508 L: alsa-devel@alsa-project.org (moderated for non-subscribers)
2508 S: Maintained 2509 S: Maintained
2509 F: sound/soc/codecs/cs* 2510 F: sound/soc/codecs/cs*
2510 2511
2511 CLEANCACHE API 2512 CLEANCACHE API
2512 M: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> 2513 M: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
2513 L: linux-kernel@vger.kernel.org 2514 L: linux-kernel@vger.kernel.org
2514 S: Maintained 2515 S: Maintained
2515 F: mm/cleancache.c 2516 F: mm/cleancache.c
2516 F: include/linux/cleancache.h 2517 F: include/linux/cleancache.h
2517 2518
2518 CLK API 2519 CLK API
2519 M: Russell King <linux@arm.linux.org.uk> 2520 M: Russell King <linux@arm.linux.org.uk>
2520 S: Maintained 2521 S: Maintained
2521 F: include/linux/clk.h 2522 F: include/linux/clk.h
2522 2523
2523 CLOCKSOURCE, CLOCKEVENT DRIVERS 2524 CLOCKSOURCE, CLOCKEVENT DRIVERS
2524 M: Daniel Lezcano <daniel.lezcano@linaro.org> 2525 M: Daniel Lezcano <daniel.lezcano@linaro.org>
2525 M: Thomas Gleixner <tglx@linutronix.de> 2526 M: Thomas Gleixner <tglx@linutronix.de>
2526 L: linux-kernel@vger.kernel.org 2527 L: linux-kernel@vger.kernel.org
2527 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git timers/core 2528 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git timers/core
2528 S: Supported 2529 S: Supported
2529 F: drivers/clocksource 2530 F: drivers/clocksource
2530 2531
2531 CISCO FCOE HBA DRIVER 2532 CISCO FCOE HBA DRIVER
2532 M: Hiral Patel <hiralpat@cisco.com> 2533 M: Hiral Patel <hiralpat@cisco.com>
2533 M: Suma Ramars <sramars@cisco.com> 2534 M: Suma Ramars <sramars@cisco.com>
2534 M: Brian Uchino <buchino@cisco.com> 2535 M: Brian Uchino <buchino@cisco.com>
2535 L: linux-scsi@vger.kernel.org 2536 L: linux-scsi@vger.kernel.org
2536 S: Supported 2537 S: Supported
2537 F: drivers/scsi/fnic/ 2538 F: drivers/scsi/fnic/
2538 2539
2539 CMPC ACPI DRIVER 2540 CMPC ACPI DRIVER
2540 M: Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com> 2541 M: Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
2541 M: Daniel Oliveira Nascimento <don@syst.com.br> 2542 M: Daniel Oliveira Nascimento <don@syst.com.br>
2542 L: platform-driver-x86@vger.kernel.org 2543 L: platform-driver-x86@vger.kernel.org
2543 S: Supported 2544 S: Supported
2544 F: drivers/platform/x86/classmate-laptop.c 2545 F: drivers/platform/x86/classmate-laptop.c
2545 2546
2546 COCCINELLE/Semantic Patches (SmPL) 2547 COCCINELLE/Semantic Patches (SmPL)
2547 M: Julia Lawall <Julia.Lawall@lip6.fr> 2548 M: Julia Lawall <Julia.Lawall@lip6.fr>
2548 M: Gilles Muller <Gilles.Muller@lip6.fr> 2549 M: Gilles Muller <Gilles.Muller@lip6.fr>
2549 M: Nicolas Palix <nicolas.palix@imag.fr> 2550 M: Nicolas Palix <nicolas.palix@imag.fr>
2550 M: Michal Marek <mmarek@suse.cz> 2551 M: Michal Marek <mmarek@suse.cz>
2551 L: cocci@systeme.lip6.fr (moderated for non-subscribers) 2552 L: cocci@systeme.lip6.fr (moderated for non-subscribers)
2552 T: git git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild.git misc 2553 T: git git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild.git misc
2553 W: http://coccinelle.lip6.fr/ 2554 W: http://coccinelle.lip6.fr/
2554 S: Supported 2555 S: Supported
2555 F: Documentation/coccinelle.txt 2556 F: Documentation/coccinelle.txt
2556 F: scripts/coccinelle/ 2557 F: scripts/coccinelle/
2557 F: scripts/coccicheck 2558 F: scripts/coccicheck
2558 2559
2559 CODA FILE SYSTEM 2560 CODA FILE SYSTEM
2560 M: Jan Harkes <jaharkes@cs.cmu.edu> 2561 M: Jan Harkes <jaharkes@cs.cmu.edu>
2561 M: coda@cs.cmu.edu 2562 M: coda@cs.cmu.edu
2562 L: codalist@coda.cs.cmu.edu 2563 L: codalist@coda.cs.cmu.edu
2563 W: http://www.coda.cs.cmu.edu/ 2564 W: http://www.coda.cs.cmu.edu/
2564 S: Maintained 2565 S: Maintained
2565 F: Documentation/filesystems/coda.txt 2566 F: Documentation/filesystems/coda.txt
2566 F: fs/coda/ 2567 F: fs/coda/
2567 F: include/linux/coda*.h 2568 F: include/linux/coda*.h
2568 F: include/uapi/linux/coda*.h 2569 F: include/uapi/linux/coda*.h
2569 2570
2570 CODA V4L2 MEM2MEM DRIVER 2571 CODA V4L2 MEM2MEM DRIVER
2571 M: Philipp Zabel <p.zabel@pengutronix.de> 2572 M: Philipp Zabel <p.zabel@pengutronix.de>
2572 L: linux-media@vger.kernel.org 2573 L: linux-media@vger.kernel.org
2573 S: Maintained 2574 S: Maintained
2574 F: Documentation/devicetree/bindings/media/coda.txt 2575 F: Documentation/devicetree/bindings/media/coda.txt
2575 F: drivers/media/platform/coda/ 2576 F: drivers/media/platform/coda/
2576 2577
2577 COMMON CLK FRAMEWORK 2578 COMMON CLK FRAMEWORK
2578 M: Mike Turquette <mturquette@linaro.org> 2579 M: Mike Turquette <mturquette@linaro.org>
2579 M: Stephen Boyd <sboyd@codeaurora.org> 2580 M: Stephen Boyd <sboyd@codeaurora.org>
2580 L: linux-kernel@vger.kernel.org 2581 L: linux-kernel@vger.kernel.org
2581 T: git git://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git 2582 T: git git://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git
2582 S: Maintained 2583 S: Maintained
2583 F: drivers/clk/ 2584 F: drivers/clk/
2584 X: drivers/clk/clkdev.c 2585 X: drivers/clk/clkdev.c
2585 F: include/linux/clk-pr* 2586 F: include/linux/clk-pr*
2586 F: include/linux/clk/ 2587 F: include/linux/clk/
2587 2588
2588 COMMON INTERNET FILE SYSTEM (CIFS) 2589 COMMON INTERNET FILE SYSTEM (CIFS)
2589 M: Steve French <sfrench@samba.org> 2590 M: Steve French <sfrench@samba.org>
2590 L: linux-cifs@vger.kernel.org 2591 L: linux-cifs@vger.kernel.org
2591 L: samba-technical@lists.samba.org (moderated for non-subscribers) 2592 L: samba-technical@lists.samba.org (moderated for non-subscribers)
2592 W: http://linux-cifs.samba.org/ 2593 W: http://linux-cifs.samba.org/
2593 T: git git://git.samba.org/sfrench/cifs-2.6.git 2594 T: git git://git.samba.org/sfrench/cifs-2.6.git
2594 S: Supported 2595 S: Supported
2595 F: Documentation/filesystems/cifs/ 2596 F: Documentation/filesystems/cifs/
2596 F: fs/cifs/ 2597 F: fs/cifs/
2597 2598
2598 COMPACTPCI HOTPLUG CORE 2599 COMPACTPCI HOTPLUG CORE
2599 M: Scott Murray <scott@spiteful.org> 2600 M: Scott Murray <scott@spiteful.org>
2600 L: linux-pci@vger.kernel.org 2601 L: linux-pci@vger.kernel.org
2601 S: Maintained 2602 S: Maintained
2602 F: drivers/pci/hotplug/cpci_hotplug* 2603 F: drivers/pci/hotplug/cpci_hotplug*
2603 2604
2604 COMPACTPCI HOTPLUG ZIATECH ZT5550 DRIVER 2605 COMPACTPCI HOTPLUG ZIATECH ZT5550 DRIVER
2605 M: Scott Murray <scott@spiteful.org> 2606 M: Scott Murray <scott@spiteful.org>
2606 L: linux-pci@vger.kernel.org 2607 L: linux-pci@vger.kernel.org
2607 S: Maintained 2608 S: Maintained
2608 F: drivers/pci/hotplug/cpcihp_zt5550.* 2609 F: drivers/pci/hotplug/cpcihp_zt5550.*
2609 2610
2610 COMPACTPCI HOTPLUG GENERIC DRIVER 2611 COMPACTPCI HOTPLUG GENERIC DRIVER
2611 M: Scott Murray <scott@spiteful.org> 2612 M: Scott Murray <scott@spiteful.org>
2612 L: linux-pci@vger.kernel.org 2613 L: linux-pci@vger.kernel.org
2613 S: Maintained 2614 S: Maintained
2614 F: drivers/pci/hotplug/cpcihp_generic.c 2615 F: drivers/pci/hotplug/cpcihp_generic.c
2615 2616
2616 COMPAL LAPTOP SUPPORT 2617 COMPAL LAPTOP SUPPORT
2617 M: Cezary Jackiewicz <cezary.jackiewicz@gmail.com> 2618 M: Cezary Jackiewicz <cezary.jackiewicz@gmail.com>
2618 L: platform-driver-x86@vger.kernel.org 2619 L: platform-driver-x86@vger.kernel.org
2619 S: Maintained 2620 S: Maintained
2620 F: drivers/platform/x86/compal-laptop.c 2621 F: drivers/platform/x86/compal-laptop.c
2621 2622
2622 CONEXANT ACCESSRUNNER USB DRIVER 2623 CONEXANT ACCESSRUNNER USB DRIVER
2623 M: Simon Arlott <cxacru@fire.lp0.eu> 2624 M: Simon Arlott <cxacru@fire.lp0.eu>
2624 L: accessrunner-general@lists.sourceforge.net 2625 L: accessrunner-general@lists.sourceforge.net
2625 W: http://accessrunner.sourceforge.net/ 2626 W: http://accessrunner.sourceforge.net/
2626 S: Maintained 2627 S: Maintained
2627 F: drivers/usb/atm/cxacru.c 2628 F: drivers/usb/atm/cxacru.c
2628 2629
2629 CONFIGFS 2630 CONFIGFS
2630 M: Joel Becker <jlbec@evilplan.org> 2631 M: Joel Becker <jlbec@evilplan.org>
2631 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jlbec/configfs.git 2632 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jlbec/configfs.git
2632 S: Supported 2633 S: Supported
2633 F: fs/configfs/ 2634 F: fs/configfs/
2634 F: include/linux/configfs.h 2635 F: include/linux/configfs.h
2635 2636
2636 CONNECTOR 2637 CONNECTOR
2637 M: Evgeniy Polyakov <zbr@ioremap.net> 2638 M: Evgeniy Polyakov <zbr@ioremap.net>
2638 L: netdev@vger.kernel.org 2639 L: netdev@vger.kernel.org
2639 S: Maintained 2640 S: Maintained
2640 F: drivers/connector/ 2641 F: drivers/connector/
2641 2642
2642 CONTROL GROUP (CGROUP) 2643 CONTROL GROUP (CGROUP)
2643 M: Tejun Heo <tj@kernel.org> 2644 M: Tejun Heo <tj@kernel.org>
2644 M: Li Zefan <lizefan@huawei.com> 2645 M: Li Zefan <lizefan@huawei.com>
2645 L: cgroups@vger.kernel.org 2646 L: cgroups@vger.kernel.org
2646 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git 2647 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git
2647 S: Maintained 2648 S: Maintained
2648 F: Documentation/cgroups/ 2649 F: Documentation/cgroups/
2649 F: include/linux/cgroup* 2650 F: include/linux/cgroup*
2650 F: kernel/cgroup* 2651 F: kernel/cgroup*
2651 2652
2652 CONTROL GROUP - CPUSET 2653 CONTROL GROUP - CPUSET
2653 M: Li Zefan <lizefan@huawei.com> 2654 M: Li Zefan <lizefan@huawei.com>
2654 L: cgroups@vger.kernel.org 2655 L: cgroups@vger.kernel.org
2655 W: http://www.bullopensource.org/cpuset/ 2656 W: http://www.bullopensource.org/cpuset/
2656 W: http://oss.sgi.com/projects/cpusets/ 2657 W: http://oss.sgi.com/projects/cpusets/
2657 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git 2658 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git
2658 S: Maintained 2659 S: Maintained
2659 F: Documentation/cgroups/cpusets.txt 2660 F: Documentation/cgroups/cpusets.txt
2660 F: include/linux/cpuset.h 2661 F: include/linux/cpuset.h
2661 F: kernel/cpuset.c 2662 F: kernel/cpuset.c
2662 2663
2663 CONTROL GROUP - MEMORY RESOURCE CONTROLLER (MEMCG) 2664 CONTROL GROUP - MEMORY RESOURCE CONTROLLER (MEMCG)
2664 M: Johannes Weiner <hannes@cmpxchg.org> 2665 M: Johannes Weiner <hannes@cmpxchg.org>
2665 M: Michal Hocko <mhocko@suse.cz> 2666 M: Michal Hocko <mhocko@suse.cz>
2666 L: cgroups@vger.kernel.org 2667 L: cgroups@vger.kernel.org
2667 L: linux-mm@kvack.org 2668 L: linux-mm@kvack.org
2668 S: Maintained 2669 S: Maintained
2669 F: mm/memcontrol.c 2670 F: mm/memcontrol.c
2670 F: mm/swap_cgroup.c 2671 F: mm/swap_cgroup.c
2671 2672
2672 CORETEMP HARDWARE MONITORING DRIVER 2673 CORETEMP HARDWARE MONITORING DRIVER
2673 M: Fenghua Yu <fenghua.yu@intel.com> 2674 M: Fenghua Yu <fenghua.yu@intel.com>
2674 L: lm-sensors@lm-sensors.org 2675 L: lm-sensors@lm-sensors.org
2675 S: Maintained 2676 S: Maintained
2676 F: Documentation/hwmon/coretemp 2677 F: Documentation/hwmon/coretemp
2677 F: drivers/hwmon/coretemp.c 2678 F: drivers/hwmon/coretemp.c
2678 2679
2679 COSA/SRP SYNC SERIAL DRIVER 2680 COSA/SRP SYNC SERIAL DRIVER
2680 M: Jan "Yenya" Kasprzak <kas@fi.muni.cz> 2681 M: Jan "Yenya" Kasprzak <kas@fi.muni.cz>
2681 W: http://www.fi.muni.cz/~kas/cosa/ 2682 W: http://www.fi.muni.cz/~kas/cosa/
2682 S: Maintained 2683 S: Maintained
2683 F: drivers/net/wan/cosa* 2684 F: drivers/net/wan/cosa*
2684 2685
2685 CPMAC ETHERNET DRIVER 2686 CPMAC ETHERNET DRIVER
2686 M: Florian Fainelli <florian@openwrt.org> 2687 M: Florian Fainelli <florian@openwrt.org>
2687 L: netdev@vger.kernel.org 2688 L: netdev@vger.kernel.org
2688 S: Maintained 2689 S: Maintained
2689 F: drivers/net/ethernet/ti/cpmac.c 2690 F: drivers/net/ethernet/ti/cpmac.c
2690 2691
2691 CPU FREQUENCY DRIVERS 2692 CPU FREQUENCY DRIVERS
2692 M: Rafael J. Wysocki <rjw@rjwysocki.net> 2693 M: Rafael J. Wysocki <rjw@rjwysocki.net>
2693 M: Viresh Kumar <viresh.kumar@linaro.org> 2694 M: Viresh Kumar <viresh.kumar@linaro.org>
2694 L: linux-pm@vger.kernel.org 2695 L: linux-pm@vger.kernel.org
2695 S: Maintained 2696 S: Maintained
2696 T: git git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git 2697 T: git git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git
2697 T: git git://git.linaro.org/people/vireshk/linux.git (For ARM Updates) 2698 T: git git://git.linaro.org/people/vireshk/linux.git (For ARM Updates)
2698 F: drivers/cpufreq/ 2699 F: drivers/cpufreq/
2699 F: include/linux/cpufreq.h 2700 F: include/linux/cpufreq.h
2700 2701
2701 CPU FREQUENCY DRIVERS - ARM BIG LITTLE 2702 CPU FREQUENCY DRIVERS - ARM BIG LITTLE
2702 M: Viresh Kumar <viresh.kumar@linaro.org> 2703 M: Viresh Kumar <viresh.kumar@linaro.org>
2703 M: Sudeep Holla <sudeep.holla@arm.com> 2704 M: Sudeep Holla <sudeep.holla@arm.com>
2704 L: linux-pm@vger.kernel.org 2705 L: linux-pm@vger.kernel.org
2705 W: http://www.arm.com/products/processors/technologies/biglittleprocessing.php 2706 W: http://www.arm.com/products/processors/technologies/biglittleprocessing.php
2706 S: Maintained 2707 S: Maintained
2707 F: drivers/cpufreq/arm_big_little.h 2708 F: drivers/cpufreq/arm_big_little.h
2708 F: drivers/cpufreq/arm_big_little.c 2709 F: drivers/cpufreq/arm_big_little.c
2709 F: drivers/cpufreq/arm_big_little_dt.c 2710 F: drivers/cpufreq/arm_big_little_dt.c
2710 2711
2711 CPUIDLE DRIVER - ARM BIG LITTLE 2712 CPUIDLE DRIVER - ARM BIG LITTLE
2712 M: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> 2713 M: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
2713 M: Daniel Lezcano <daniel.lezcano@linaro.org> 2714 M: Daniel Lezcano <daniel.lezcano@linaro.org>
2714 L: linux-pm@vger.kernel.org 2715 L: linux-pm@vger.kernel.org
2715 L: linux-arm-kernel@lists.infradead.org 2716 L: linux-arm-kernel@lists.infradead.org
2716 T: git git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git 2717 T: git git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git
2717 S: Maintained 2718 S: Maintained
2718 F: drivers/cpuidle/cpuidle-big_little.c 2719 F: drivers/cpuidle/cpuidle-big_little.c
2719 2720
2720 CPUIDLE DRIVER - ARM EXYNOS 2721 CPUIDLE DRIVER - ARM EXYNOS
2721 M: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> 2722 M: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
2722 M: Daniel Lezcano <daniel.lezcano@linaro.org> 2723 M: Daniel Lezcano <daniel.lezcano@linaro.org>
2723 M: Kukjin Kim <kgene@kernel.org> 2724 M: Kukjin Kim <kgene@kernel.org>
2724 L: linux-pm@vger.kernel.org 2725 L: linux-pm@vger.kernel.org
2725 L: linux-samsung-soc@vger.kernel.org 2726 L: linux-samsung-soc@vger.kernel.org
2726 S: Supported 2727 S: Supported
2727 F: drivers/cpuidle/cpuidle-exynos.c 2728 F: drivers/cpuidle/cpuidle-exynos.c
2728 F: arch/arm/mach-exynos/pm.c 2729 F: arch/arm/mach-exynos/pm.c
2729 2730
2730 CPUIDLE DRIVERS 2731 CPUIDLE DRIVERS
2731 M: Rafael J. Wysocki <rjw@rjwysocki.net> 2732 M: Rafael J. Wysocki <rjw@rjwysocki.net>
2732 M: Daniel Lezcano <daniel.lezcano@linaro.org> 2733 M: Daniel Lezcano <daniel.lezcano@linaro.org>
2733 L: linux-pm@vger.kernel.org 2734 L: linux-pm@vger.kernel.org
2734 S: Maintained 2735 S: Maintained
2735 T: git git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git 2736 T: git git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git
2736 F: drivers/cpuidle/* 2737 F: drivers/cpuidle/*
2737 F: include/linux/cpuidle.h 2738 F: include/linux/cpuidle.h
2738 2739
2739 CPUID/MSR DRIVER 2740 CPUID/MSR DRIVER
2740 M: "H. Peter Anvin" <hpa@zytor.com> 2741 M: "H. Peter Anvin" <hpa@zytor.com>
2741 S: Maintained 2742 S: Maintained
2742 F: arch/x86/kernel/cpuid.c 2743 F: arch/x86/kernel/cpuid.c
2743 F: arch/x86/kernel/msr.c 2744 F: arch/x86/kernel/msr.c
2744 2745
2745 CPU POWER MONITORING SUBSYSTEM 2746 CPU POWER MONITORING SUBSYSTEM
2746 M: Thomas Renninger <trenn@suse.de> 2747 M: Thomas Renninger <trenn@suse.de>
2747 L: linux-pm@vger.kernel.org 2748 L: linux-pm@vger.kernel.org
2748 S: Maintained 2749 S: Maintained
2749 F: tools/power/cpupower/ 2750 F: tools/power/cpupower/
2750 2751
2751 CRAMFS FILESYSTEM 2752 CRAMFS FILESYSTEM
2752 W: http://sourceforge.net/projects/cramfs/ 2753 W: http://sourceforge.net/projects/cramfs/
2753 S: Orphan / Obsolete 2754 S: Orphan / Obsolete
2754 F: Documentation/filesystems/cramfs.txt 2755 F: Documentation/filesystems/cramfs.txt
2755 F: fs/cramfs/ 2756 F: fs/cramfs/
2756 2757
2757 CRIS PORT 2758 CRIS PORT
2758 M: Mikael Starvik <starvik@axis.com> 2759 M: Mikael Starvik <starvik@axis.com>
2759 M: Jesper Nilsson <jesper.nilsson@axis.com> 2760 M: Jesper Nilsson <jesper.nilsson@axis.com>
2760 L: linux-cris-kernel@axis.com 2761 L: linux-cris-kernel@axis.com
2761 W: http://developer.axis.com 2762 W: http://developer.axis.com
2762 S: Maintained 2763 S: Maintained
2763 F: arch/cris/ 2764 F: arch/cris/
2764 F: drivers/tty/serial/crisv10.* 2765 F: drivers/tty/serial/crisv10.*
2765 2766
2766 CRYPTO API 2767 CRYPTO API
2767 M: Herbert Xu <herbert@gondor.apana.org.au> 2768 M: Herbert Xu <herbert@gondor.apana.org.au>
2768 M: "David S. Miller" <davem@davemloft.net> 2769 M: "David S. Miller" <davem@davemloft.net>
2769 L: linux-crypto@vger.kernel.org 2770 L: linux-crypto@vger.kernel.org
2770 T: git git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6.git 2771 T: git git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6.git
2771 S: Maintained 2772 S: Maintained
2772 F: Documentation/crypto/ 2773 F: Documentation/crypto/
2773 F: arch/*/crypto/ 2774 F: arch/*/crypto/
2774 F: crypto/ 2775 F: crypto/
2775 F: drivers/crypto/ 2776 F: drivers/crypto/
2776 F: include/crypto/ 2777 F: include/crypto/
2777 2778
2778 CRYPTOGRAPHIC RANDOM NUMBER GENERATOR 2779 CRYPTOGRAPHIC RANDOM NUMBER GENERATOR
2779 M: Neil Horman <nhorman@tuxdriver.com> 2780 M: Neil Horman <nhorman@tuxdriver.com>
2780 L: linux-crypto@vger.kernel.org 2781 L: linux-crypto@vger.kernel.org
2781 S: Maintained 2782 S: Maintained
2782 F: crypto/ansi_cprng.c 2783 F: crypto/ansi_cprng.c
2783 F: crypto/rng.c 2784 F: crypto/rng.c
2784 2785
2785 CS5535 Audio ALSA driver 2786 CS5535 Audio ALSA driver
2786 M: Jaya Kumar <jayakumar.alsa@gmail.com> 2787 M: Jaya Kumar <jayakumar.alsa@gmail.com>
2787 S: Maintained 2788 S: Maintained
2788 F: sound/pci/cs5535audio/ 2789 F: sound/pci/cs5535audio/
2789 2790
2790 CW1200 WLAN driver 2791 CW1200 WLAN driver
2791 M: Solomon Peachy <pizza@shaftnet.org> 2792 M: Solomon Peachy <pizza@shaftnet.org>
2792 S: Maintained 2793 S: Maintained
2793 F: drivers/net/wireless/cw1200/ 2794 F: drivers/net/wireless/cw1200/
2794 2795
2795 CX18 VIDEO4LINUX DRIVER 2796 CX18 VIDEO4LINUX DRIVER
2796 M: Andy Walls <awalls@md.metrocast.net> 2797 M: Andy Walls <awalls@md.metrocast.net>
2797 L: ivtv-devel@ivtvdriver.org (subscribers-only) 2798 L: ivtv-devel@ivtvdriver.org (subscribers-only)
2798 L: linux-media@vger.kernel.org 2799 L: linux-media@vger.kernel.org
2799 T: git git://linuxtv.org/media_tree.git 2800 T: git git://linuxtv.org/media_tree.git
2800 W: http://linuxtv.org 2801 W: http://linuxtv.org
2801 W: http://www.ivtvdriver.org/index.php/Cx18 2802 W: http://www.ivtvdriver.org/index.php/Cx18
2802 S: Maintained 2803 S: Maintained
2803 F: Documentation/video4linux/cx18.txt 2804 F: Documentation/video4linux/cx18.txt
2804 F: drivers/media/pci/cx18/ 2805 F: drivers/media/pci/cx18/
2805 F: include/uapi/linux/ivtv* 2806 F: include/uapi/linux/ivtv*
2806 2807
2807 CX2341X MPEG ENCODER HELPER MODULE 2808 CX2341X MPEG ENCODER HELPER MODULE
2808 M: Hans Verkuil <hverkuil@xs4all.nl> 2809 M: Hans Verkuil <hverkuil@xs4all.nl>
2809 L: linux-media@vger.kernel.org 2810 L: linux-media@vger.kernel.org
2810 T: git git://linuxtv.org/media_tree.git 2811 T: git git://linuxtv.org/media_tree.git
2811 W: http://linuxtv.org 2812 W: http://linuxtv.org
2812 S: Maintained 2813 S: Maintained
2813 F: drivers/media/common/cx2341x* 2814 F: drivers/media/common/cx2341x*
2814 F: include/media/cx2341x* 2815 F: include/media/cx2341x*
2815 2816
2816 CX88 VIDEO4LINUX DRIVER 2817 CX88 VIDEO4LINUX DRIVER
2817 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com> 2818 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2818 L: linux-media@vger.kernel.org 2819 L: linux-media@vger.kernel.org
2819 W: http://linuxtv.org 2820 W: http://linuxtv.org
2820 T: git git://linuxtv.org/media_tree.git 2821 T: git git://linuxtv.org/media_tree.git
2821 S: Odd fixes 2822 S: Odd fixes
2822 F: Documentation/video4linux/cx88/ 2823 F: Documentation/video4linux/cx88/
2823 F: drivers/media/pci/cx88/ 2824 F: drivers/media/pci/cx88/
2824 2825
2825 CXD2820R MEDIA DRIVER 2826 CXD2820R MEDIA DRIVER
2826 M: Antti Palosaari <crope@iki.fi> 2827 M: Antti Palosaari <crope@iki.fi>
2827 L: linux-media@vger.kernel.org 2828 L: linux-media@vger.kernel.org
2828 W: http://linuxtv.org/ 2829 W: http://linuxtv.org/
2829 W: http://palosaari.fi/linux/ 2830 W: http://palosaari.fi/linux/
2830 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 2831 Q: http://patchwork.linuxtv.org/project/linux-media/list/
2831 T: git git://linuxtv.org/anttip/media_tree.git 2832 T: git git://linuxtv.org/anttip/media_tree.git
2832 S: Maintained 2833 S: Maintained
2833 F: drivers/media/dvb-frontends/cxd2820r* 2834 F: drivers/media/dvb-frontends/cxd2820r*
2834 2835
2835 CXGB3 ETHERNET DRIVER (CXGB3) 2836 CXGB3 ETHERNET DRIVER (CXGB3)
2836 M: Santosh Raspatur <santosh@chelsio.com> 2837 M: Santosh Raspatur <santosh@chelsio.com>
2837 L: netdev@vger.kernel.org 2838 L: netdev@vger.kernel.org
2838 W: http://www.chelsio.com 2839 W: http://www.chelsio.com
2839 S: Supported 2840 S: Supported
2840 F: drivers/net/ethernet/chelsio/cxgb3/ 2841 F: drivers/net/ethernet/chelsio/cxgb3/
2841 2842
2842 CXGB3 ISCSI DRIVER (CXGB3I) 2843 CXGB3 ISCSI DRIVER (CXGB3I)
2843 M: Karen Xie <kxie@chelsio.com> 2844 M: Karen Xie <kxie@chelsio.com>
2844 L: linux-scsi@vger.kernel.org 2845 L: linux-scsi@vger.kernel.org
2845 W: http://www.chelsio.com 2846 W: http://www.chelsio.com
2846 S: Supported 2847 S: Supported
2847 F: drivers/scsi/cxgbi/cxgb3i 2848 F: drivers/scsi/cxgbi/cxgb3i
2848 2849
2849 CXGB3 IWARP RNIC DRIVER (IW_CXGB3) 2850 CXGB3 IWARP RNIC DRIVER (IW_CXGB3)
2850 M: Steve Wise <swise@chelsio.com> 2851 M: Steve Wise <swise@chelsio.com>
2851 L: linux-rdma@vger.kernel.org 2852 L: linux-rdma@vger.kernel.org
2852 W: http://www.openfabrics.org 2853 W: http://www.openfabrics.org
2853 S: Supported 2854 S: Supported
2854 F: drivers/infiniband/hw/cxgb3/ 2855 F: drivers/infiniband/hw/cxgb3/
2855 2856
2856 CXGB4 ETHERNET DRIVER (CXGB4) 2857 CXGB4 ETHERNET DRIVER (CXGB4)
2857 M: Hariprasad S <hariprasad@chelsio.com> 2858 M: Hariprasad S <hariprasad@chelsio.com>
2858 L: netdev@vger.kernel.org 2859 L: netdev@vger.kernel.org
2859 W: http://www.chelsio.com 2860 W: http://www.chelsio.com
2860 S: Supported 2861 S: Supported
2861 F: drivers/net/ethernet/chelsio/cxgb4/ 2862 F: drivers/net/ethernet/chelsio/cxgb4/
2862 2863
2863 CXGB4 ISCSI DRIVER (CXGB4I) 2864 CXGB4 ISCSI DRIVER (CXGB4I)
2864 M: Karen Xie <kxie@chelsio.com> 2865 M: Karen Xie <kxie@chelsio.com>
2865 L: linux-scsi@vger.kernel.org 2866 L: linux-scsi@vger.kernel.org
2866 W: http://www.chelsio.com 2867 W: http://www.chelsio.com
2867 S: Supported 2868 S: Supported
2868 F: drivers/scsi/cxgbi/cxgb4i 2869 F: drivers/scsi/cxgbi/cxgb4i
2869 2870
2870 CXGB4 IWARP RNIC DRIVER (IW_CXGB4) 2871 CXGB4 IWARP RNIC DRIVER (IW_CXGB4)
2871 M: Steve Wise <swise@chelsio.com> 2872 M: Steve Wise <swise@chelsio.com>
2872 L: linux-rdma@vger.kernel.org 2873 L: linux-rdma@vger.kernel.org
2873 W: http://www.openfabrics.org 2874 W: http://www.openfabrics.org
2874 S: Supported 2875 S: Supported
2875 F: drivers/infiniband/hw/cxgb4/ 2876 F: drivers/infiniband/hw/cxgb4/
2876 2877
2877 CXGB4VF ETHERNET DRIVER (CXGB4VF) 2878 CXGB4VF ETHERNET DRIVER (CXGB4VF)
2878 M: Casey Leedom <leedom@chelsio.com> 2879 M: Casey Leedom <leedom@chelsio.com>
2879 L: netdev@vger.kernel.org 2880 L: netdev@vger.kernel.org
2880 W: http://www.chelsio.com 2881 W: http://www.chelsio.com
2881 S: Supported 2882 S: Supported
2882 F: drivers/net/ethernet/chelsio/cxgb4vf/ 2883 F: drivers/net/ethernet/chelsio/cxgb4vf/
2883 2884
2884 CXL (IBM Coherent Accelerator Processor Interface CAPI) DRIVER 2885 CXL (IBM Coherent Accelerator Processor Interface CAPI) DRIVER
2885 M: Ian Munsie <imunsie@au1.ibm.com> 2886 M: Ian Munsie <imunsie@au1.ibm.com>
2886 M: Michael Neuling <mikey@neuling.org> 2887 M: Michael Neuling <mikey@neuling.org>
2887 L: linuxppc-dev@lists.ozlabs.org 2888 L: linuxppc-dev@lists.ozlabs.org
2888 S: Supported 2889 S: Supported
2889 F: drivers/misc/cxl/ 2890 F: drivers/misc/cxl/
2890 F: include/misc/cxl.h 2891 F: include/misc/cxl.h
2891 F: include/uapi/misc/cxl.h 2892 F: include/uapi/misc/cxl.h
2892 F: Documentation/powerpc/cxl.txt 2893 F: Documentation/powerpc/cxl.txt
2893 F: Documentation/powerpc/cxl.txt 2894 F: Documentation/powerpc/cxl.txt
2894 F: Documentation/ABI/testing/sysfs-class-cxl 2895 F: Documentation/ABI/testing/sysfs-class-cxl
2895 2896
2896 STMMAC ETHERNET DRIVER 2897 STMMAC ETHERNET DRIVER
2897 M: Giuseppe Cavallaro <peppe.cavallaro@st.com> 2898 M: Giuseppe Cavallaro <peppe.cavallaro@st.com>
2898 L: netdev@vger.kernel.org 2899 L: netdev@vger.kernel.org
2899 W: http://www.stlinux.com 2900 W: http://www.stlinux.com
2900 S: Supported 2901 S: Supported
2901 F: drivers/net/ethernet/stmicro/stmmac/ 2902 F: drivers/net/ethernet/stmicro/stmmac/
2902 2903
2903 CYBERPRO FB DRIVER 2904 CYBERPRO FB DRIVER
2904 M: Russell King <linux@arm.linux.org.uk> 2905 M: Russell King <linux@arm.linux.org.uk>
2905 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 2906 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
2906 W: http://www.arm.linux.org.uk/ 2907 W: http://www.arm.linux.org.uk/
2907 S: Maintained 2908 S: Maintained
2908 F: drivers/video/fbdev/cyber2000fb.* 2909 F: drivers/video/fbdev/cyber2000fb.*
2909 2910
2910 CYCLADES ASYNC MUX DRIVER 2911 CYCLADES ASYNC MUX DRIVER
2911 W: http://www.cyclades.com/ 2912 W: http://www.cyclades.com/
2912 S: Orphan 2913 S: Orphan
2913 F: drivers/tty/cyclades.c 2914 F: drivers/tty/cyclades.c
2914 F: include/linux/cyclades.h 2915 F: include/linux/cyclades.h
2915 F: include/uapi/linux/cyclades.h 2916 F: include/uapi/linux/cyclades.h
2916 2917
2917 CYCLADES PC300 DRIVER 2918 CYCLADES PC300 DRIVER
2918 W: http://www.cyclades.com/ 2919 W: http://www.cyclades.com/
2919 S: Orphan 2920 S: Orphan
2920 F: drivers/net/wan/pc300* 2921 F: drivers/net/wan/pc300*
2921 2922
2922 CYPRESS_FIRMWARE MEDIA DRIVER 2923 CYPRESS_FIRMWARE MEDIA DRIVER
2923 M: Antti Palosaari <crope@iki.fi> 2924 M: Antti Palosaari <crope@iki.fi>
2924 L: linux-media@vger.kernel.org 2925 L: linux-media@vger.kernel.org
2925 W: http://linuxtv.org/ 2926 W: http://linuxtv.org/
2926 W: http://palosaari.fi/linux/ 2927 W: http://palosaari.fi/linux/
2927 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 2928 Q: http://patchwork.linuxtv.org/project/linux-media/list/
2928 T: git git://linuxtv.org/anttip/media_tree.git 2929 T: git git://linuxtv.org/anttip/media_tree.git
2929 S: Maintained 2930 S: Maintained
2930 F: drivers/media/common/cypress_firmware* 2931 F: drivers/media/common/cypress_firmware*
2931 2932
2932 CYTTSP TOUCHSCREEN DRIVER 2933 CYTTSP TOUCHSCREEN DRIVER
2933 M: Ferruh Yigit <fery@cypress.com> 2934 M: Ferruh Yigit <fery@cypress.com>
2934 L: linux-input@vger.kernel.org 2935 L: linux-input@vger.kernel.org
2935 S: Supported 2936 S: Supported
2936 F: drivers/input/touchscreen/cyttsp* 2937 F: drivers/input/touchscreen/cyttsp*
2937 F: include/linux/input/cyttsp.h 2938 F: include/linux/input/cyttsp.h
2938 2939
2939 DAMA SLAVE for AX.25 2940 DAMA SLAVE for AX.25
2940 M: Joerg Reuter <jreuter@yaina.de> 2941 M: Joerg Reuter <jreuter@yaina.de>
2941 W: http://yaina.de/jreuter/ 2942 W: http://yaina.de/jreuter/
2942 W: http://www.qsl.net/dl1bke/ 2943 W: http://www.qsl.net/dl1bke/
2943 L: linux-hams@vger.kernel.org 2944 L: linux-hams@vger.kernel.org
2944 S: Maintained 2945 S: Maintained
2945 F: net/ax25/af_ax25.c 2946 F: net/ax25/af_ax25.c
2946 F: net/ax25/ax25_dev.c 2947 F: net/ax25/ax25_dev.c
2947 F: net/ax25/ax25_ds_* 2948 F: net/ax25/ax25_ds_*
2948 F: net/ax25/ax25_in.c 2949 F: net/ax25/ax25_in.c
2949 F: net/ax25/ax25_out.c 2950 F: net/ax25/ax25_out.c
2950 F: net/ax25/ax25_timer.c 2951 F: net/ax25/ax25_timer.c
2951 F: net/ax25/sysctl_net_ax25.c 2952 F: net/ax25/sysctl_net_ax25.c
2952 2953
2953 DAVICOM FAST ETHERNET (DMFE) NETWORK DRIVER 2954 DAVICOM FAST ETHERNET (DMFE) NETWORK DRIVER
2954 L: netdev@vger.kernel.org 2955 L: netdev@vger.kernel.org
2955 S: Orphan 2956 S: Orphan
2956 F: Documentation/networking/dmfe.txt 2957 F: Documentation/networking/dmfe.txt
2957 F: drivers/net/ethernet/dec/tulip/dmfe.c 2958 F: drivers/net/ethernet/dec/tulip/dmfe.c
2958 2959
2959 DC390/AM53C974 SCSI driver 2960 DC390/AM53C974 SCSI driver
2960 M: Hannes Reinecke <hare@suse.de> 2961 M: Hannes Reinecke <hare@suse.de>
2961 L: linux-scsi@vger.kernel.org 2962 L: linux-scsi@vger.kernel.org
2962 S: Maintained 2963 S: Maintained
2963 F: drivers/scsi/am53c974.c 2964 F: drivers/scsi/am53c974.c
2964 2965
2965 DC395x SCSI driver 2966 DC395x SCSI driver
2966 M: Oliver Neukum <oliver@neukum.org> 2967 M: Oliver Neukum <oliver@neukum.org>
2967 M: Ali Akcaagac <aliakc@web.de> 2968 M: Ali Akcaagac <aliakc@web.de>
2968 M: Jamie Lenehan <lenehan@twibble.org> 2969 M: Jamie Lenehan <lenehan@twibble.org>
2969 L: dc395x@twibble.org 2970 L: dc395x@twibble.org
2970 W: http://twibble.org/dist/dc395x/ 2971 W: http://twibble.org/dist/dc395x/
2971 W: http://lists.twibble.org/mailman/listinfo/dc395x/ 2972 W: http://lists.twibble.org/mailman/listinfo/dc395x/
2972 S: Maintained 2973 S: Maintained
2973 F: Documentation/scsi/dc395x.txt 2974 F: Documentation/scsi/dc395x.txt
2974 F: drivers/scsi/dc395x.* 2975 F: drivers/scsi/dc395x.*
2975 2976
2976 DCCP PROTOCOL 2977 DCCP PROTOCOL
2977 M: Gerrit Renker <gerrit@erg.abdn.ac.uk> 2978 M: Gerrit Renker <gerrit@erg.abdn.ac.uk>
2978 L: dccp@vger.kernel.org 2979 L: dccp@vger.kernel.org
2979 W: http://www.linuxfoundation.org/collaborate/workgroups/networking/dccp 2980 W: http://www.linuxfoundation.org/collaborate/workgroups/networking/dccp
2980 S: Maintained 2981 S: Maintained
2981 F: include/linux/dccp.h 2982 F: include/linux/dccp.h
2982 F: include/uapi/linux/dccp.h 2983 F: include/uapi/linux/dccp.h
2983 F: include/linux/tfrc.h 2984 F: include/linux/tfrc.h
2984 F: net/dccp/ 2985 F: net/dccp/
2985 2986
2986 DECnet NETWORK LAYER 2987 DECnet NETWORK LAYER
2987 W: http://linux-decnet.sourceforge.net 2988 W: http://linux-decnet.sourceforge.net
2988 L: linux-decnet-user@lists.sourceforge.net 2989 L: linux-decnet-user@lists.sourceforge.net
2989 S: Orphan 2990 S: Orphan
2990 F: Documentation/networking/decnet.txt 2991 F: Documentation/networking/decnet.txt
2991 F: net/decnet/ 2992 F: net/decnet/
2992 2993
2993 DECSTATION PLATFORM SUPPORT 2994 DECSTATION PLATFORM SUPPORT
2994 M: "Maciej W. Rozycki" <macro@linux-mips.org> 2995 M: "Maciej W. Rozycki" <macro@linux-mips.org>
2995 L: linux-mips@linux-mips.org 2996 L: linux-mips@linux-mips.org
2996 W: http://www.linux-mips.org/wiki/DECstation 2997 W: http://www.linux-mips.org/wiki/DECstation
2997 S: Maintained 2998 S: Maintained
2998 F: arch/mips/dec/ 2999 F: arch/mips/dec/
2999 F: arch/mips/include/asm/dec/ 3000 F: arch/mips/include/asm/dec/
3000 F: arch/mips/include/asm/mach-dec/ 3001 F: arch/mips/include/asm/mach-dec/
3001 3002
3002 DEFXX FDDI NETWORK DRIVER 3003 DEFXX FDDI NETWORK DRIVER
3003 M: "Maciej W. Rozycki" <macro@linux-mips.org> 3004 M: "Maciej W. Rozycki" <macro@linux-mips.org>
3004 S: Maintained 3005 S: Maintained
3005 F: drivers/net/fddi/defxx.* 3006 F: drivers/net/fddi/defxx.*
3006 3007
3007 DELL LAPTOP DRIVER 3008 DELL LAPTOP DRIVER
3008 M: Matthew Garrett <mjg59@srcf.ucam.org> 3009 M: Matthew Garrett <mjg59@srcf.ucam.org>
3009 L: platform-driver-x86@vger.kernel.org 3010 L: platform-driver-x86@vger.kernel.org
3010 S: Maintained 3011 S: Maintained
3011 F: drivers/platform/x86/dell-laptop.c 3012 F: drivers/platform/x86/dell-laptop.c
3012 3013
3013 DELL LAPTOP SMM DRIVER 3014 DELL LAPTOP SMM DRIVER
3014 M: Guenter Roeck <linux@roeck-us.net> 3015 M: Guenter Roeck <linux@roeck-us.net>
3015 F: drivers/char/i8k.c 3016 F: drivers/char/i8k.c
3016 F: include/uapi/linux/i8k.h 3017 F: include/uapi/linux/i8k.h
3017 3018
3018 DELL SYSTEMS MANAGEMENT BASE DRIVER (dcdbas) 3019 DELL SYSTEMS MANAGEMENT BASE DRIVER (dcdbas)
3019 M: Doug Warzecha <Douglas_Warzecha@dell.com> 3020 M: Doug Warzecha <Douglas_Warzecha@dell.com>
3020 S: Maintained 3021 S: Maintained
3021 F: Documentation/dcdbas.txt 3022 F: Documentation/dcdbas.txt
3022 F: drivers/firmware/dcdbas.* 3023 F: drivers/firmware/dcdbas.*
3023 3024
3024 DELL WMI EXTRAS DRIVER 3025 DELL WMI EXTRAS DRIVER
3025 M: Matthew Garrett <mjg59@srcf.ucam.org> 3026 M: Matthew Garrett <mjg59@srcf.ucam.org>
3026 S: Maintained 3027 S: Maintained
3027 F: drivers/platform/x86/dell-wmi.c 3028 F: drivers/platform/x86/dell-wmi.c
3028 3029
3029 DESIGNWARE USB2 DRD IP DRIVER 3030 DESIGNWARE USB2 DRD IP DRIVER
3030 M: Paul Zimmerman <paulz@synopsys.com> 3031 M: Paul Zimmerman <paulz@synopsys.com>
3031 L: linux-usb@vger.kernel.org 3032 L: linux-usb@vger.kernel.org
3032 T: git git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git 3033 T: git git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git
3033 S: Maintained 3034 S: Maintained
3034 F: drivers/usb/dwc2/ 3035 F: drivers/usb/dwc2/
3035 3036
3036 DESIGNWARE USB3 DRD IP DRIVER 3037 DESIGNWARE USB3 DRD IP DRIVER
3037 M: Felipe Balbi <balbi@ti.com> 3038 M: Felipe Balbi <balbi@ti.com>
3038 L: linux-usb@vger.kernel.org 3039 L: linux-usb@vger.kernel.org
3039 L: linux-omap@vger.kernel.org 3040 L: linux-omap@vger.kernel.org
3040 T: git git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git 3041 T: git git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git
3041 S: Maintained 3042 S: Maintained
3042 F: drivers/usb/dwc3/ 3043 F: drivers/usb/dwc3/
3043 3044
3044 DEVICE COREDUMP (DEV_COREDUMP) 3045 DEVICE COREDUMP (DEV_COREDUMP)
3045 M: Johannes Berg <johannes@sipsolutions.net> 3046 M: Johannes Berg <johannes@sipsolutions.net>
3046 L: linux-kernel@vger.kernel.org 3047 L: linux-kernel@vger.kernel.org
3047 S: Maintained 3048 S: Maintained
3048 F: drivers/base/devcoredump.c 3049 F: drivers/base/devcoredump.c
3049 F: include/linux/devcoredump.h 3050 F: include/linux/devcoredump.h
3050 3051
3051 DEVICE FREQUENCY (DEVFREQ) 3052 DEVICE FREQUENCY (DEVFREQ)
3052 M: MyungJoo Ham <myungjoo.ham@samsung.com> 3053 M: MyungJoo Ham <myungjoo.ham@samsung.com>
3053 M: Kyungmin Park <kyungmin.park@samsung.com> 3054 M: Kyungmin Park <kyungmin.park@samsung.com>
3054 L: linux-pm@vger.kernel.org 3055 L: linux-pm@vger.kernel.org
3055 S: Maintained 3056 S: Maintained
3056 F: drivers/devfreq/ 3057 F: drivers/devfreq/
3057 3058
3058 DEVICE NUMBER REGISTRY 3059 DEVICE NUMBER REGISTRY
3059 M: Torben Mathiasen <device@lanana.org> 3060 M: Torben Mathiasen <device@lanana.org>
3060 W: http://lanana.org/docs/device-list/index.html 3061 W: http://lanana.org/docs/device-list/index.html
3061 S: Maintained 3062 S: Maintained
3062 3063
3063 DEVICE-MAPPER (LVM) 3064 DEVICE-MAPPER (LVM)
3064 M: Alasdair Kergon <agk@redhat.com> 3065 M: Alasdair Kergon <agk@redhat.com>
3065 M: Mike Snitzer <snitzer@redhat.com> 3066 M: Mike Snitzer <snitzer@redhat.com>
3066 M: dm-devel@redhat.com 3067 M: dm-devel@redhat.com
3067 L: dm-devel@redhat.com 3068 L: dm-devel@redhat.com
3068 W: http://sources.redhat.com/dm 3069 W: http://sources.redhat.com/dm
3069 Q: http://patchwork.kernel.org/project/dm-devel/list/ 3070 Q: http://patchwork.kernel.org/project/dm-devel/list/
3070 T: git git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git 3071 T: git git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git
3071 T: quilt http://people.redhat.com/agk/patches/linux/editing/ 3072 T: quilt http://people.redhat.com/agk/patches/linux/editing/
3072 S: Maintained 3073 S: Maintained
3073 F: Documentation/device-mapper/ 3074 F: Documentation/device-mapper/
3074 F: drivers/md/dm* 3075 F: drivers/md/dm*
3075 F: drivers/md/persistent-data/ 3076 F: drivers/md/persistent-data/
3076 F: include/linux/device-mapper.h 3077 F: include/linux/device-mapper.h
3077 F: include/linux/dm-*.h 3078 F: include/linux/dm-*.h
3078 F: include/uapi/linux/dm-*.h 3079 F: include/uapi/linux/dm-*.h
3079 3080
3080 DIALOG SEMICONDUCTOR DRIVERS 3081 DIALOG SEMICONDUCTOR DRIVERS
3081 M: Support Opensource <support.opensource@diasemi.com> 3082 M: Support Opensource <support.opensource@diasemi.com>
3082 W: http://www.dialog-semiconductor.com/products 3083 W: http://www.dialog-semiconductor.com/products
3083 S: Supported 3084 S: Supported
3084 F: Documentation/hwmon/da90?? 3085 F: Documentation/hwmon/da90??
3085 F: drivers/gpio/gpio-da90??.c 3086 F: drivers/gpio/gpio-da90??.c
3086 F: drivers/hwmon/da90??-hwmon.c 3087 F: drivers/hwmon/da90??-hwmon.c
3087 F: drivers/input/misc/da90??_onkey.c 3088 F: drivers/input/misc/da90??_onkey.c
3088 F: drivers/input/touchscreen/da9052_tsi.c 3089 F: drivers/input/touchscreen/da9052_tsi.c
3089 F: drivers/leds/leds-da90??.c 3090 F: drivers/leds/leds-da90??.c
3090 F: drivers/mfd/da903x.c 3091 F: drivers/mfd/da903x.c
3091 F: drivers/mfd/da90??-*.c 3092 F: drivers/mfd/da90??-*.c
3092 F: drivers/power/da9052-battery.c 3093 F: drivers/power/da9052-battery.c
3093 F: drivers/regulator/da903x.c 3094 F: drivers/regulator/da903x.c
3094 F: drivers/regulator/da9???-regulator.[ch] 3095 F: drivers/regulator/da9???-regulator.[ch]
3095 F: drivers/rtc/rtc-da90??.c 3096 F: drivers/rtc/rtc-da90??.c
3096 F: drivers/video/backlight/da90??_bl.c 3097 F: drivers/video/backlight/da90??_bl.c
3097 F: drivers/watchdog/da90??_wdt.c 3098 F: drivers/watchdog/da90??_wdt.c
3098 F: include/linux/mfd/da903x.h 3099 F: include/linux/mfd/da903x.h
3099 F: include/linux/mfd/da9052/ 3100 F: include/linux/mfd/da9052/
3100 F: include/linux/mfd/da9055/ 3101 F: include/linux/mfd/da9055/
3101 F: include/linux/mfd/da9063/ 3102 F: include/linux/mfd/da9063/
3102 F: include/sound/da[79]*.h 3103 F: include/sound/da[79]*.h
3103 F: sound/soc/codecs/da[79]*.[ch] 3104 F: sound/soc/codecs/da[79]*.[ch]
3104 3105
3105 DIGI NEO AND CLASSIC PCI PRODUCTS 3106 DIGI NEO AND CLASSIC PCI PRODUCTS
3106 M: Lidza Louina <lidza.louina@gmail.com> 3107 M: Lidza Louina <lidza.louina@gmail.com>
3107 M: Mark Hounschell <markh@compro.net> 3108 M: Mark Hounschell <markh@compro.net>
3108 L: driverdev-devel@linuxdriverproject.org 3109 L: driverdev-devel@linuxdriverproject.org
3109 S: Maintained 3110 S: Maintained
3110 F: drivers/staging/dgnc/ 3111 F: drivers/staging/dgnc/
3111 3112
3112 DIGI EPCA PCI PRODUCTS 3113 DIGI EPCA PCI PRODUCTS
3113 M: Lidza Louina <lidza.louina@gmail.com> 3114 M: Lidza Louina <lidza.louina@gmail.com>
3114 M: Mark Hounschell <markh@compro.net> 3115 M: Mark Hounschell <markh@compro.net>
3115 M: Daeseok Youn <daeseok.youn@gmail.com> 3116 M: Daeseok Youn <daeseok.youn@gmail.com>
3116 L: driverdev-devel@linuxdriverproject.org 3117 L: driverdev-devel@linuxdriverproject.org
3117 S: Maintained 3118 S: Maintained
3118 F: drivers/staging/dgap/ 3119 F: drivers/staging/dgap/
3119 3120
3120 DIOLAN U2C-12 I2C DRIVER 3121 DIOLAN U2C-12 I2C DRIVER
3121 M: Guenter Roeck <linux@roeck-us.net> 3122 M: Guenter Roeck <linux@roeck-us.net>
3122 L: linux-i2c@vger.kernel.org 3123 L: linux-i2c@vger.kernel.org
3123 S: Maintained 3124 S: Maintained
3124 F: drivers/i2c/busses/i2c-diolan-u2c.c 3125 F: drivers/i2c/busses/i2c-diolan-u2c.c
3125 3126
3126 DIRECTORY NOTIFICATION (DNOTIFY) 3127 DIRECTORY NOTIFICATION (DNOTIFY)
3127 M: Eric Paris <eparis@parisplace.org> 3128 M: Eric Paris <eparis@parisplace.org>
3128 S: Maintained 3129 S: Maintained
3129 F: Documentation/filesystems/dnotify.txt 3130 F: Documentation/filesystems/dnotify.txt
3130 F: fs/notify/dnotify/ 3131 F: fs/notify/dnotify/
3131 F: include/linux/dnotify.h 3132 F: include/linux/dnotify.h
3132 3133
3133 DISK GEOMETRY AND PARTITION HANDLING 3134 DISK GEOMETRY AND PARTITION HANDLING
3134 M: Andries Brouwer <aeb@cwi.nl> 3135 M: Andries Brouwer <aeb@cwi.nl>
3135 W: http://www.win.tue.nl/~aeb/linux/Large-Disk.html 3136 W: http://www.win.tue.nl/~aeb/linux/Large-Disk.html
3136 W: http://www.win.tue.nl/~aeb/linux/zip/zip-1.html 3137 W: http://www.win.tue.nl/~aeb/linux/zip/zip-1.html
3137 W: http://www.win.tue.nl/~aeb/partitions/partition_types-1.html 3138 W: http://www.win.tue.nl/~aeb/partitions/partition_types-1.html
3138 S: Maintained 3139 S: Maintained
3139 3140
3140 DISKQUOTA 3141 DISKQUOTA
3141 M: Jan Kara <jack@suse.cz> 3142 M: Jan Kara <jack@suse.cz>
3142 S: Maintained 3143 S: Maintained
3143 F: Documentation/filesystems/quota.txt 3144 F: Documentation/filesystems/quota.txt
3144 F: fs/quota/ 3145 F: fs/quota/
3145 F: include/linux/quota*.h 3146 F: include/linux/quota*.h
3146 F: include/uapi/linux/quota*.h 3147 F: include/uapi/linux/quota*.h
3147 3148
3148 DISPLAYLINK USB 2.0 FRAMEBUFFER DRIVER (UDLFB) 3149 DISPLAYLINK USB 2.0 FRAMEBUFFER DRIVER (UDLFB)
3149 M: Bernie Thompson <bernie@plugable.com> 3150 M: Bernie Thompson <bernie@plugable.com>
3150 L: linux-fbdev@vger.kernel.org 3151 L: linux-fbdev@vger.kernel.org
3151 S: Maintained 3152 S: Maintained
3152 W: http://plugable.com/category/projects/udlfb/ 3153 W: http://plugable.com/category/projects/udlfb/
3153 F: drivers/video/fbdev/udlfb.c 3154 F: drivers/video/fbdev/udlfb.c
3154 F: include/video/udlfb.h 3155 F: include/video/udlfb.h
3155 F: Documentation/fb/udlfb.txt 3156 F: Documentation/fb/udlfb.txt
3156 3157
3157 DISTRIBUTED LOCK MANAGER (DLM) 3158 DISTRIBUTED LOCK MANAGER (DLM)
3158 M: Christine Caulfield <ccaulfie@redhat.com> 3159 M: Christine Caulfield <ccaulfie@redhat.com>
3159 M: David Teigland <teigland@redhat.com> 3160 M: David Teigland <teigland@redhat.com>
3160 L: cluster-devel@redhat.com 3161 L: cluster-devel@redhat.com
3161 W: http://sources.redhat.com/cluster/ 3162 W: http://sources.redhat.com/cluster/
3162 T: git git://git.kernel.org/pub/scm/linux/kernel/git/teigland/dlm.git 3163 T: git git://git.kernel.org/pub/scm/linux/kernel/git/teigland/dlm.git
3163 S: Supported 3164 S: Supported
3164 F: fs/dlm/ 3165 F: fs/dlm/
3165 3166
3166 DMA BUFFER SHARING FRAMEWORK 3167 DMA BUFFER SHARING FRAMEWORK
3167 M: Sumit Semwal <sumit.semwal@linaro.org> 3168 M: Sumit Semwal <sumit.semwal@linaro.org>
3168 S: Maintained 3169 S: Maintained
3169 L: linux-media@vger.kernel.org 3170 L: linux-media@vger.kernel.org
3170 L: dri-devel@lists.freedesktop.org 3171 L: dri-devel@lists.freedesktop.org
3171 L: linaro-mm-sig@lists.linaro.org (moderated for non-subscribers) 3172 L: linaro-mm-sig@lists.linaro.org (moderated for non-subscribers)
3172 F: drivers/dma-buf/ 3173 F: drivers/dma-buf/
3173 F: include/linux/dma-buf* 3174 F: include/linux/dma-buf*
3174 F: include/linux/reservation.h 3175 F: include/linux/reservation.h
3175 F: include/linux/*fence.h 3176 F: include/linux/*fence.h
3176 F: Documentation/dma-buf-sharing.txt 3177 F: Documentation/dma-buf-sharing.txt
3177 T: git git://git.linaro.org/people/sumitsemwal/linux-dma-buf.git 3178 T: git git://git.linaro.org/people/sumitsemwal/linux-dma-buf.git
3178 3179
3179 DMA GENERIC OFFLOAD ENGINE SUBSYSTEM 3180 DMA GENERIC OFFLOAD ENGINE SUBSYSTEM
3180 M: Vinod Koul <vinod.koul@intel.com> 3181 M: Vinod Koul <vinod.koul@intel.com>
3181 L: dmaengine@vger.kernel.org 3182 L: dmaengine@vger.kernel.org
3182 Q: https://patchwork.kernel.org/project/linux-dmaengine/list/ 3183 Q: https://patchwork.kernel.org/project/linux-dmaengine/list/
3183 S: Maintained 3184 S: Maintained
3184 F: drivers/dma/ 3185 F: drivers/dma/
3185 F: include/linux/dma* 3186 F: include/linux/dma*
3186 F: Documentation/dmaengine/ 3187 F: Documentation/dmaengine/
3187 T: git git://git.infradead.org/users/vkoul/slave-dma.git 3188 T: git git://git.infradead.org/users/vkoul/slave-dma.git
3188 3189
3189 DME1737 HARDWARE MONITOR DRIVER 3190 DME1737 HARDWARE MONITOR DRIVER
3190 M: Juerg Haefliger <juergh@gmail.com> 3191 M: Juerg Haefliger <juergh@gmail.com>
3191 L: lm-sensors@lm-sensors.org 3192 L: lm-sensors@lm-sensors.org
3192 S: Maintained 3193 S: Maintained
3193 F: Documentation/hwmon/dme1737 3194 F: Documentation/hwmon/dme1737
3194 F: drivers/hwmon/dme1737.c 3195 F: drivers/hwmon/dme1737.c
3195 3196
3196 DOCKING STATION DRIVER 3197 DOCKING STATION DRIVER
3197 M: Shaohua Li <shaohua.li@intel.com> 3198 M: Shaohua Li <shaohua.li@intel.com>
3198 L: linux-acpi@vger.kernel.org 3199 L: linux-acpi@vger.kernel.org
3199 S: Supported 3200 S: Supported
3200 F: drivers/acpi/dock.c 3201 F: drivers/acpi/dock.c
3201 3202
3202 DOCUMENTATION 3203 DOCUMENTATION
3203 M: Jonathan Corbet <corbet@lwn.net> 3204 M: Jonathan Corbet <corbet@lwn.net>
3204 L: linux-doc@vger.kernel.org 3205 L: linux-doc@vger.kernel.org
3205 S: Maintained 3206 S: Maintained
3206 F: Documentation/ 3207 F: Documentation/
3207 X: Documentation/ABI/ 3208 X: Documentation/ABI/
3208 X: Documentation/devicetree/ 3209 X: Documentation/devicetree/
3209 X: Documentation/[a-z][a-z]_[A-Z][A-Z]/ 3210 X: Documentation/[a-z][a-z]_[A-Z][A-Z]/
3210 3211
3211 DOUBLETALK DRIVER 3212 DOUBLETALK DRIVER
3212 M: "James R. Van Zandt" <jrv@vanzandt.mv.com> 3213 M: "James R. Van Zandt" <jrv@vanzandt.mv.com>
3213 L: blinux-list@redhat.com 3214 L: blinux-list@redhat.com
3214 S: Maintained 3215 S: Maintained
3215 F: drivers/char/dtlk.c 3216 F: drivers/char/dtlk.c
3216 F: include/linux/dtlk.h 3217 F: include/linux/dtlk.h
3217 3218
3218 DPT_I2O SCSI RAID DRIVER 3219 DPT_I2O SCSI RAID DRIVER
3219 M: Adaptec OEM Raid Solutions <aacraid@adaptec.com> 3220 M: Adaptec OEM Raid Solutions <aacraid@adaptec.com>
3220 L: linux-scsi@vger.kernel.org 3221 L: linux-scsi@vger.kernel.org
3221 W: http://www.adaptec.com/ 3222 W: http://www.adaptec.com/
3222 S: Maintained 3223 S: Maintained
3223 F: drivers/scsi/dpt* 3224 F: drivers/scsi/dpt*
3224 F: drivers/scsi/dpt/ 3225 F: drivers/scsi/dpt/
3225 3226
3226 DRBD DRIVER 3227 DRBD DRIVER
3227 P: Philipp Reisner 3228 P: Philipp Reisner
3228 P: Lars Ellenberg 3229 P: Lars Ellenberg
3229 M: drbd-dev@lists.linbit.com 3230 M: drbd-dev@lists.linbit.com
3230 L: drbd-user@lists.linbit.com 3231 L: drbd-user@lists.linbit.com
3231 W: http://www.drbd.org 3232 W: http://www.drbd.org
3232 T: git git://git.drbd.org/linux-2.6-drbd.git drbd 3233 T: git git://git.drbd.org/linux-2.6-drbd.git drbd
3233 T: git git://git.drbd.org/drbd-8.3.git 3234 T: git git://git.drbd.org/drbd-8.3.git
3234 S: Supported 3235 S: Supported
3235 F: drivers/block/drbd/ 3236 F: drivers/block/drbd/
3236 F: lib/lru_cache.c 3237 F: lib/lru_cache.c
3237 F: Documentation/blockdev/drbd/ 3238 F: Documentation/blockdev/drbd/
3238 3239
3239 DRIVER CORE, KOBJECTS, DEBUGFS AND SYSFS 3240 DRIVER CORE, KOBJECTS, DEBUGFS AND SYSFS
3240 M: Greg Kroah-Hartman <gregkh@linuxfoundation.org> 3241 M: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
3241 T: git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git 3242 T: git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git
3242 S: Supported 3243 S: Supported
3243 F: Documentation/kobject.txt 3244 F: Documentation/kobject.txt
3244 F: drivers/base/ 3245 F: drivers/base/
3245 F: fs/sysfs/ 3246 F: fs/sysfs/
3246 F: fs/debugfs/ 3247 F: fs/debugfs/
3247 F: include/linux/kobj* 3248 F: include/linux/kobj*
3248 F: include/linux/debugfs.h 3249 F: include/linux/debugfs.h
3249 F: lib/kobj* 3250 F: lib/kobj*
3250 3251
3251 DRM DRIVERS 3252 DRM DRIVERS
3252 M: David Airlie <airlied@linux.ie> 3253 M: David Airlie <airlied@linux.ie>
3253 L: dri-devel@lists.freedesktop.org 3254 L: dri-devel@lists.freedesktop.org
3254 T: git git://people.freedesktop.org/~airlied/linux 3255 T: git git://people.freedesktop.org/~airlied/linux
3255 S: Maintained 3256 S: Maintained
3256 F: drivers/gpu/drm/ 3257 F: drivers/gpu/drm/
3257 F: drivers/gpu/vga/ 3258 F: drivers/gpu/vga/
3258 F: include/drm/ 3259 F: include/drm/
3259 F: include/uapi/drm/ 3260 F: include/uapi/drm/
3260 3261
3261 RADEON DRM DRIVERS 3262 RADEON DRM DRIVERS
3262 M: Alex Deucher <alexander.deucher@amd.com> 3263 M: Alex Deucher <alexander.deucher@amd.com>
3263 M: Christian Kรถnig <christian.koenig@amd.com> 3264 M: Christian Kรถnig <christian.koenig@amd.com>
3264 L: dri-devel@lists.freedesktop.org 3265 L: dri-devel@lists.freedesktop.org
3265 T: git git://people.freedesktop.org/~agd5f/linux 3266 T: git git://people.freedesktop.org/~agd5f/linux
3266 S: Supported 3267 S: Supported
3267 F: drivers/gpu/drm/radeon/ 3268 F: drivers/gpu/drm/radeon/
3268 F: include/uapi/drm/radeon* 3269 F: include/uapi/drm/radeon*
3269 3270
3270 DRM PANEL DRIVERS 3271 DRM PANEL DRIVERS
3271 M: Thierry Reding <thierry.reding@gmail.com> 3272 M: Thierry Reding <thierry.reding@gmail.com>
3272 L: dri-devel@lists.freedesktop.org 3273 L: dri-devel@lists.freedesktop.org
3273 T: git git://anongit.freedesktop.org/tegra/linux.git 3274 T: git git://anongit.freedesktop.org/tegra/linux.git
3274 S: Maintained 3275 S: Maintained
3275 F: drivers/gpu/drm/drm_panel.c 3276 F: drivers/gpu/drm/drm_panel.c
3276 F: drivers/gpu/drm/panel/ 3277 F: drivers/gpu/drm/panel/
3277 F: include/drm/drm_panel.h 3278 F: include/drm/drm_panel.h
3278 F: Documentation/devicetree/bindings/panel/ 3279 F: Documentation/devicetree/bindings/panel/
3279 3280
3280 INTEL DRM DRIVERS (excluding Poulsbo, Moorestown and derivative chipsets) 3281 INTEL DRM DRIVERS (excluding Poulsbo, Moorestown and derivative chipsets)
3281 M: Daniel Vetter <daniel.vetter@intel.com> 3282 M: Daniel Vetter <daniel.vetter@intel.com>
3282 M: Jani Nikula <jani.nikula@linux.intel.com> 3283 M: Jani Nikula <jani.nikula@linux.intel.com>
3283 L: intel-gfx@lists.freedesktop.org 3284 L: intel-gfx@lists.freedesktop.org
3284 L: dri-devel@lists.freedesktop.org 3285 L: dri-devel@lists.freedesktop.org
3285 Q: http://patchwork.freedesktop.org/project/intel-gfx/ 3286 Q: http://patchwork.freedesktop.org/project/intel-gfx/
3286 T: git git://anongit.freedesktop.org/drm-intel 3287 T: git git://anongit.freedesktop.org/drm-intel
3287 S: Supported 3288 S: Supported
3288 F: drivers/gpu/drm/i915/ 3289 F: drivers/gpu/drm/i915/
3289 F: include/drm/i915* 3290 F: include/drm/i915*
3290 F: include/uapi/drm/i915* 3291 F: include/uapi/drm/i915*
3291 3292
3292 DRM DRIVERS FOR EXYNOS 3293 DRM DRIVERS FOR EXYNOS
3293 M: Inki Dae <inki.dae@samsung.com> 3294 M: Inki Dae <inki.dae@samsung.com>
3294 M: Joonyoung Shim <jy0922.shim@samsung.com> 3295 M: Joonyoung Shim <jy0922.shim@samsung.com>
3295 M: Seung-Woo Kim <sw0312.kim@samsung.com> 3296 M: Seung-Woo Kim <sw0312.kim@samsung.com>
3296 M: Kyungmin Park <kyungmin.park@samsung.com> 3297 M: Kyungmin Park <kyungmin.park@samsung.com>
3297 L: dri-devel@lists.freedesktop.org 3298 L: dri-devel@lists.freedesktop.org
3298 T: git git://git.kernel.org/pub/scm/linux/kernel/git/daeinki/drm-exynos.git 3299 T: git git://git.kernel.org/pub/scm/linux/kernel/git/daeinki/drm-exynos.git
3299 S: Supported 3300 S: Supported
3300 F: drivers/gpu/drm/exynos/ 3301 F: drivers/gpu/drm/exynos/
3301 F: include/drm/exynos* 3302 F: include/drm/exynos*
3302 F: include/uapi/drm/exynos* 3303 F: include/uapi/drm/exynos*
3303 3304
3304 DRM DRIVERS FOR FREESCALE IMX 3305 DRM DRIVERS FOR FREESCALE IMX
3305 M: Philipp Zabel <p.zabel@pengutronix.de> 3306 M: Philipp Zabel <p.zabel@pengutronix.de>
3306 L: dri-devel@lists.freedesktop.org 3307 L: dri-devel@lists.freedesktop.org
3307 S: Maintained 3308 S: Maintained
3308 F: drivers/gpu/drm/imx/ 3309 F: drivers/gpu/drm/imx/
3309 F: Documentation/devicetree/bindings/drm/imx/ 3310 F: Documentation/devicetree/bindings/drm/imx/
3310 3311
3311 DRM DRIVERS FOR NVIDIA TEGRA 3312 DRM DRIVERS FOR NVIDIA TEGRA
3312 M: Thierry Reding <thierry.reding@gmail.com> 3313 M: Thierry Reding <thierry.reding@gmail.com>
3313 M: Terje Bergstrรถm <tbergstrom@nvidia.com> 3314 M: Terje Bergstrรถm <tbergstrom@nvidia.com>
3314 L: dri-devel@lists.freedesktop.org 3315 L: dri-devel@lists.freedesktop.org
3315 L: linux-tegra@vger.kernel.org 3316 L: linux-tegra@vger.kernel.org
3316 T: git git://anongit.freedesktop.org/tegra/linux.git 3317 T: git git://anongit.freedesktop.org/tegra/linux.git
3317 S: Supported 3318 S: Supported
3318 F: drivers/gpu/drm/tegra/ 3319 F: drivers/gpu/drm/tegra/
3319 F: drivers/gpu/host1x/ 3320 F: drivers/gpu/host1x/
3320 F: include/linux/host1x.h 3321 F: include/linux/host1x.h
3321 F: include/uapi/drm/tegra_drm.h 3322 F: include/uapi/drm/tegra_drm.h
3322 F: Documentation/devicetree/bindings/gpu/nvidia,tegra20-host1x.txt 3323 F: Documentation/devicetree/bindings/gpu/nvidia,tegra20-host1x.txt
3323 3324
3324 DRM DRIVERS FOR RENESAS 3325 DRM DRIVERS FOR RENESAS
3325 M: Laurent Pinchart <laurent.pinchart@ideasonboard.com> 3326 M: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
3326 L: dri-devel@lists.freedesktop.org 3327 L: dri-devel@lists.freedesktop.org
3327 L: linux-sh@vger.kernel.org 3328 L: linux-sh@vger.kernel.org
3328 T: git git://people.freedesktop.org/~airlied/linux 3329 T: git git://people.freedesktop.org/~airlied/linux
3329 S: Supported 3330 S: Supported
3330 F: drivers/gpu/drm/rcar-du/ 3331 F: drivers/gpu/drm/rcar-du/
3331 F: drivers/gpu/drm/shmobile/ 3332 F: drivers/gpu/drm/shmobile/
3332 F: include/linux/platform_data/rcar-du.h 3333 F: include/linux/platform_data/rcar-du.h
3333 F: include/linux/platform_data/shmob_drm.h 3334 F: include/linux/platform_data/shmob_drm.h
3334 3335
3335 DSBR100 USB FM RADIO DRIVER 3336 DSBR100 USB FM RADIO DRIVER
3336 M: Alexey Klimov <klimov.linux@gmail.com> 3337 M: Alexey Klimov <klimov.linux@gmail.com>
3337 L: linux-media@vger.kernel.org 3338 L: linux-media@vger.kernel.org
3338 T: git git://linuxtv.org/media_tree.git 3339 T: git git://linuxtv.org/media_tree.git
3339 S: Maintained 3340 S: Maintained
3340 F: drivers/media/radio/dsbr100.c 3341 F: drivers/media/radio/dsbr100.c
3341 3342
3342 DSCC4 DRIVER 3343 DSCC4 DRIVER
3343 M: Francois Romieu <romieu@fr.zoreil.com> 3344 M: Francois Romieu <romieu@fr.zoreil.com>
3344 L: netdev@vger.kernel.org 3345 L: netdev@vger.kernel.org
3345 S: Maintained 3346 S: Maintained
3346 F: drivers/net/wan/dscc4.c 3347 F: drivers/net/wan/dscc4.c
3347 3348
3348 DVB_USB_AF9015 MEDIA DRIVER 3349 DVB_USB_AF9015 MEDIA DRIVER
3349 M: Antti Palosaari <crope@iki.fi> 3350 M: Antti Palosaari <crope@iki.fi>
3350 L: linux-media@vger.kernel.org 3351 L: linux-media@vger.kernel.org
3351 W: http://linuxtv.org/ 3352 W: http://linuxtv.org/
3352 W: http://palosaari.fi/linux/ 3353 W: http://palosaari.fi/linux/
3353 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 3354 Q: http://patchwork.linuxtv.org/project/linux-media/list/
3354 T: git git://linuxtv.org/anttip/media_tree.git 3355 T: git git://linuxtv.org/anttip/media_tree.git
3355 S: Maintained 3356 S: Maintained
3356 F: drivers/media/usb/dvb-usb-v2/af9015* 3357 F: drivers/media/usb/dvb-usb-v2/af9015*
3357 3358
3358 DVB_USB_AF9035 MEDIA DRIVER 3359 DVB_USB_AF9035 MEDIA DRIVER
3359 M: Antti Palosaari <crope@iki.fi> 3360 M: Antti Palosaari <crope@iki.fi>
3360 L: linux-media@vger.kernel.org 3361 L: linux-media@vger.kernel.org
3361 W: http://linuxtv.org/ 3362 W: http://linuxtv.org/
3362 W: http://palosaari.fi/linux/ 3363 W: http://palosaari.fi/linux/
3363 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 3364 Q: http://patchwork.linuxtv.org/project/linux-media/list/
3364 T: git git://linuxtv.org/anttip/media_tree.git 3365 T: git git://linuxtv.org/anttip/media_tree.git
3365 S: Maintained 3366 S: Maintained
3366 F: drivers/media/usb/dvb-usb-v2/af9035* 3367 F: drivers/media/usb/dvb-usb-v2/af9035*
3367 3368
3368 DVB_USB_ANYSEE MEDIA DRIVER 3369 DVB_USB_ANYSEE MEDIA DRIVER
3369 M: Antti Palosaari <crope@iki.fi> 3370 M: Antti Palosaari <crope@iki.fi>
3370 L: linux-media@vger.kernel.org 3371 L: linux-media@vger.kernel.org
3371 W: http://linuxtv.org/ 3372 W: http://linuxtv.org/
3372 W: http://palosaari.fi/linux/ 3373 W: http://palosaari.fi/linux/
3373 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 3374 Q: http://patchwork.linuxtv.org/project/linux-media/list/
3374 T: git git://linuxtv.org/anttip/media_tree.git 3375 T: git git://linuxtv.org/anttip/media_tree.git
3375 S: Maintained 3376 S: Maintained
3376 F: drivers/media/usb/dvb-usb-v2/anysee* 3377 F: drivers/media/usb/dvb-usb-v2/anysee*
3377 3378
3378 DVB_USB_AU6610 MEDIA DRIVER 3379 DVB_USB_AU6610 MEDIA DRIVER
3379 M: Antti Palosaari <crope@iki.fi> 3380 M: Antti Palosaari <crope@iki.fi>
3380 L: linux-media@vger.kernel.org 3381 L: linux-media@vger.kernel.org
3381 W: http://linuxtv.org/ 3382 W: http://linuxtv.org/
3382 W: http://palosaari.fi/linux/ 3383 W: http://palosaari.fi/linux/
3383 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 3384 Q: http://patchwork.linuxtv.org/project/linux-media/list/
3384 T: git git://linuxtv.org/anttip/media_tree.git 3385 T: git git://linuxtv.org/anttip/media_tree.git
3385 S: Maintained 3386 S: Maintained
3386 F: drivers/media/usb/dvb-usb-v2/au6610* 3387 F: drivers/media/usb/dvb-usb-v2/au6610*
3387 3388
3388 DVB_USB_CE6230 MEDIA DRIVER 3389 DVB_USB_CE6230 MEDIA DRIVER
3389 M: Antti Palosaari <crope@iki.fi> 3390 M: Antti Palosaari <crope@iki.fi>
3390 L: linux-media@vger.kernel.org 3391 L: linux-media@vger.kernel.org
3391 W: http://linuxtv.org/ 3392 W: http://linuxtv.org/
3392 W: http://palosaari.fi/linux/ 3393 W: http://palosaari.fi/linux/
3393 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 3394 Q: http://patchwork.linuxtv.org/project/linux-media/list/
3394 T: git git://linuxtv.org/anttip/media_tree.git 3395 T: git git://linuxtv.org/anttip/media_tree.git
3395 S: Maintained 3396 S: Maintained
3396 F: drivers/media/usb/dvb-usb-v2/ce6230* 3397 F: drivers/media/usb/dvb-usb-v2/ce6230*
3397 3398
3398 DVB_USB_CXUSB MEDIA DRIVER 3399 DVB_USB_CXUSB MEDIA DRIVER
3399 M: Michael Krufky <mkrufky@linuxtv.org> 3400 M: Michael Krufky <mkrufky@linuxtv.org>
3400 L: linux-media@vger.kernel.org 3401 L: linux-media@vger.kernel.org
3401 W: http://linuxtv.org/ 3402 W: http://linuxtv.org/
3402 W: http://github.com/mkrufky 3403 W: http://github.com/mkrufky
3403 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 3404 Q: http://patchwork.linuxtv.org/project/linux-media/list/
3404 T: git git://linuxtv.org/media_tree.git 3405 T: git git://linuxtv.org/media_tree.git
3405 S: Maintained 3406 S: Maintained
3406 F: drivers/media/usb/dvb-usb/cxusb* 3407 F: drivers/media/usb/dvb-usb/cxusb*
3407 3408
3408 DVB_USB_EC168 MEDIA DRIVER 3409 DVB_USB_EC168 MEDIA DRIVER
3409 M: Antti Palosaari <crope@iki.fi> 3410 M: Antti Palosaari <crope@iki.fi>
3410 L: linux-media@vger.kernel.org 3411 L: linux-media@vger.kernel.org
3411 W: http://linuxtv.org/ 3412 W: http://linuxtv.org/
3412 W: http://palosaari.fi/linux/ 3413 W: http://palosaari.fi/linux/
3413 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 3414 Q: http://patchwork.linuxtv.org/project/linux-media/list/
3414 T: git git://linuxtv.org/anttip/media_tree.git 3415 T: git git://linuxtv.org/anttip/media_tree.git
3415 S: Maintained 3416 S: Maintained
3416 F: drivers/media/usb/dvb-usb-v2/ec168* 3417 F: drivers/media/usb/dvb-usb-v2/ec168*
3417 3418
3418 DVB_USB_GL861 MEDIA DRIVER 3419 DVB_USB_GL861 MEDIA DRIVER
3419 M: Antti Palosaari <crope@iki.fi> 3420 M: Antti Palosaari <crope@iki.fi>
3420 L: linux-media@vger.kernel.org 3421 L: linux-media@vger.kernel.org
3421 W: http://linuxtv.org/ 3422 W: http://linuxtv.org/
3422 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 3423 Q: http://patchwork.linuxtv.org/project/linux-media/list/
3423 T: git git://linuxtv.org/anttip/media_tree.git 3424 T: git git://linuxtv.org/anttip/media_tree.git
3424 S: Maintained 3425 S: Maintained
3425 F: drivers/media/usb/dvb-usb-v2/gl861* 3426 F: drivers/media/usb/dvb-usb-v2/gl861*
3426 3427
3427 DVB_USB_MXL111SF MEDIA DRIVER 3428 DVB_USB_MXL111SF MEDIA DRIVER
3428 M: Michael Krufky <mkrufky@linuxtv.org> 3429 M: Michael Krufky <mkrufky@linuxtv.org>
3429 L: linux-media@vger.kernel.org 3430 L: linux-media@vger.kernel.org
3430 W: http://linuxtv.org/ 3431 W: http://linuxtv.org/
3431 W: http://github.com/mkrufky 3432 W: http://github.com/mkrufky
3432 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 3433 Q: http://patchwork.linuxtv.org/project/linux-media/list/
3433 T: git git://linuxtv.org/mkrufky/mxl111sf.git 3434 T: git git://linuxtv.org/mkrufky/mxl111sf.git
3434 S: Maintained 3435 S: Maintained
3435 F: drivers/media/usb/dvb-usb-v2/mxl111sf* 3436 F: drivers/media/usb/dvb-usb-v2/mxl111sf*
3436 3437
3437 DVB_USB_RTL28XXU MEDIA DRIVER 3438 DVB_USB_RTL28XXU MEDIA DRIVER
3438 M: Antti Palosaari <crope@iki.fi> 3439 M: Antti Palosaari <crope@iki.fi>
3439 L: linux-media@vger.kernel.org 3440 L: linux-media@vger.kernel.org
3440 W: http://linuxtv.org/ 3441 W: http://linuxtv.org/
3441 W: http://palosaari.fi/linux/ 3442 W: http://palosaari.fi/linux/
3442 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 3443 Q: http://patchwork.linuxtv.org/project/linux-media/list/
3443 T: git git://linuxtv.org/anttip/media_tree.git 3444 T: git git://linuxtv.org/anttip/media_tree.git
3444 S: Maintained 3445 S: Maintained
3445 F: drivers/media/usb/dvb-usb-v2/rtl28xxu* 3446 F: drivers/media/usb/dvb-usb-v2/rtl28xxu*
3446 3447
3447 DVB_USB_V2 MEDIA DRIVER 3448 DVB_USB_V2 MEDIA DRIVER
3448 M: Antti Palosaari <crope@iki.fi> 3449 M: Antti Palosaari <crope@iki.fi>
3449 L: linux-media@vger.kernel.org 3450 L: linux-media@vger.kernel.org
3450 W: http://linuxtv.org/ 3451 W: http://linuxtv.org/
3451 W: http://palosaari.fi/linux/ 3452 W: http://palosaari.fi/linux/
3452 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 3453 Q: http://patchwork.linuxtv.org/project/linux-media/list/
3453 T: git git://linuxtv.org/anttip/media_tree.git 3454 T: git git://linuxtv.org/anttip/media_tree.git
3454 S: Maintained 3455 S: Maintained
3455 F: drivers/media/usb/dvb-usb-v2/dvb_usb* 3456 F: drivers/media/usb/dvb-usb-v2/dvb_usb*
3456 F: drivers/media/usb/dvb-usb-v2/usb_urb.c 3457 F: drivers/media/usb/dvb-usb-v2/usb_urb.c
3457 3458
3458 DYNAMIC DEBUG 3459 DYNAMIC DEBUG
3459 M: Jason Baron <jbaron@akamai.com> 3460 M: Jason Baron <jbaron@akamai.com>
3460 S: Maintained 3461 S: Maintained
3461 F: lib/dynamic_debug.c 3462 F: lib/dynamic_debug.c
3462 F: include/linux/dynamic_debug.h 3463 F: include/linux/dynamic_debug.h
3463 3464
3464 DZ DECSTATION DZ11 SERIAL DRIVER 3465 DZ DECSTATION DZ11 SERIAL DRIVER
3465 M: "Maciej W. Rozycki" <macro@linux-mips.org> 3466 M: "Maciej W. Rozycki" <macro@linux-mips.org>
3466 S: Maintained 3467 S: Maintained
3467 F: drivers/tty/serial/dz.* 3468 F: drivers/tty/serial/dz.*
3468 3469
3469 E4000 MEDIA DRIVER 3470 E4000 MEDIA DRIVER
3470 M: Antti Palosaari <crope@iki.fi> 3471 M: Antti Palosaari <crope@iki.fi>
3471 L: linux-media@vger.kernel.org 3472 L: linux-media@vger.kernel.org
3472 W: http://linuxtv.org/ 3473 W: http://linuxtv.org/
3473 W: http://palosaari.fi/linux/ 3474 W: http://palosaari.fi/linux/
3474 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 3475 Q: http://patchwork.linuxtv.org/project/linux-media/list/
3475 T: git git://linuxtv.org/anttip/media_tree.git 3476 T: git git://linuxtv.org/anttip/media_tree.git
3476 S: Maintained 3477 S: Maintained
3477 F: drivers/media/tuners/e4000* 3478 F: drivers/media/tuners/e4000*
3478 3479
3479 EATA ISA/EISA/PCI SCSI DRIVER 3480 EATA ISA/EISA/PCI SCSI DRIVER
3480 M: Dario Ballabio <ballabio_dario@emc.com> 3481 M: Dario Ballabio <ballabio_dario@emc.com>
3481 L: linux-scsi@vger.kernel.org 3482 L: linux-scsi@vger.kernel.org
3482 S: Maintained 3483 S: Maintained
3483 F: drivers/scsi/eata.c 3484 F: drivers/scsi/eata.c
3484 3485
3485 EC100 MEDIA DRIVER 3486 EC100 MEDIA DRIVER
3486 M: Antti Palosaari <crope@iki.fi> 3487 M: Antti Palosaari <crope@iki.fi>
3487 L: linux-media@vger.kernel.org 3488 L: linux-media@vger.kernel.org
3488 W: http://linuxtv.org/ 3489 W: http://linuxtv.org/
3489 W: http://palosaari.fi/linux/ 3490 W: http://palosaari.fi/linux/
3490 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 3491 Q: http://patchwork.linuxtv.org/project/linux-media/list/
3491 T: git git://linuxtv.org/anttip/media_tree.git 3492 T: git git://linuxtv.org/anttip/media_tree.git
3492 S: Maintained 3493 S: Maintained
3493 F: drivers/media/dvb-frontends/ec100* 3494 F: drivers/media/dvb-frontends/ec100*
3494 3495
3495 ECRYPT FILE SYSTEM 3496 ECRYPT FILE SYSTEM
3496 M: Tyler Hicks <tyhicks@canonical.com> 3497 M: Tyler Hicks <tyhicks@canonical.com>
3497 L: ecryptfs@vger.kernel.org 3498 L: ecryptfs@vger.kernel.org
3498 W: http://ecryptfs.org 3499 W: http://ecryptfs.org
3499 W: https://launchpad.net/ecryptfs 3500 W: https://launchpad.net/ecryptfs
3500 S: Supported 3501 S: Supported
3501 F: Documentation/filesystems/ecryptfs.txt 3502 F: Documentation/filesystems/ecryptfs.txt
3502 F: fs/ecryptfs/ 3503 F: fs/ecryptfs/
3503 3504
3504 EDAC-CORE 3505 EDAC-CORE
3505 M: Doug Thompson <dougthompson@xmission.com> 3506 M: Doug Thompson <dougthompson@xmission.com>
3506 M: Borislav Petkov <bp@alien8.de> 3507 M: Borislav Petkov <bp@alien8.de>
3507 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com> 3508 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
3508 L: linux-edac@vger.kernel.org 3509 L: linux-edac@vger.kernel.org
3509 W: bluesmoke.sourceforge.net 3510 W: bluesmoke.sourceforge.net
3510 S: Supported 3511 S: Supported
3511 F: Documentation/edac.txt 3512 F: Documentation/edac.txt
3512 F: drivers/edac/ 3513 F: drivers/edac/
3513 F: include/linux/edac.h 3514 F: include/linux/edac.h
3514 3515
3515 EDAC-AMD64 3516 EDAC-AMD64
3516 M: Doug Thompson <dougthompson@xmission.com> 3517 M: Doug Thompson <dougthompson@xmission.com>
3517 M: Borislav Petkov <bp@alien8.de> 3518 M: Borislav Petkov <bp@alien8.de>
3518 L: linux-edac@vger.kernel.org 3519 L: linux-edac@vger.kernel.org
3519 W: bluesmoke.sourceforge.net 3520 W: bluesmoke.sourceforge.net
3520 S: Maintained 3521 S: Maintained
3521 F: drivers/edac/amd64_edac* 3522 F: drivers/edac/amd64_edac*
3522 3523
3523 EDAC-CALXEDA 3524 EDAC-CALXEDA
3524 M: Doug Thompson <dougthompson@xmission.com> 3525 M: Doug Thompson <dougthompson@xmission.com>
3525 M: Robert Richter <rric@kernel.org> 3526 M: Robert Richter <rric@kernel.org>
3526 L: linux-edac@vger.kernel.org 3527 L: linux-edac@vger.kernel.org
3527 W: bluesmoke.sourceforge.net 3528 W: bluesmoke.sourceforge.net
3528 S: Maintained 3529 S: Maintained
3529 F: drivers/edac/highbank* 3530 F: drivers/edac/highbank*
3530 3531
3531 EDAC-CAVIUM 3532 EDAC-CAVIUM
3532 M: Ralf Baechle <ralf@linux-mips.org> 3533 M: Ralf Baechle <ralf@linux-mips.org>
3533 M: David Daney <david.daney@cavium.com> 3534 M: David Daney <david.daney@cavium.com>
3534 L: linux-edac@vger.kernel.org 3535 L: linux-edac@vger.kernel.org
3535 L: linux-mips@linux-mips.org 3536 L: linux-mips@linux-mips.org
3536 W: bluesmoke.sourceforge.net 3537 W: bluesmoke.sourceforge.net
3537 S: Supported 3538 S: Supported
3538 F: drivers/edac/octeon_edac* 3539 F: drivers/edac/octeon_edac*
3539 3540
3540 EDAC-E752X 3541 EDAC-E752X
3541 M: Mark Gross <mark.gross@intel.com> 3542 M: Mark Gross <mark.gross@intel.com>
3542 M: Doug Thompson <dougthompson@xmission.com> 3543 M: Doug Thompson <dougthompson@xmission.com>
3543 L: linux-edac@vger.kernel.org 3544 L: linux-edac@vger.kernel.org
3544 W: bluesmoke.sourceforge.net 3545 W: bluesmoke.sourceforge.net
3545 S: Maintained 3546 S: Maintained
3546 F: drivers/edac/e752x_edac.c 3547 F: drivers/edac/e752x_edac.c
3547 3548
3548 EDAC-E7XXX 3549 EDAC-E7XXX
3549 M: Doug Thompson <dougthompson@xmission.com> 3550 M: Doug Thompson <dougthompson@xmission.com>
3550 L: linux-edac@vger.kernel.org 3551 L: linux-edac@vger.kernel.org
3551 W: bluesmoke.sourceforge.net 3552 W: bluesmoke.sourceforge.net
3552 S: Maintained 3553 S: Maintained
3553 F: drivers/edac/e7xxx_edac.c 3554 F: drivers/edac/e7xxx_edac.c
3554 3555
3555 EDAC-GHES 3556 EDAC-GHES
3556 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com> 3557 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
3557 L: linux-edac@vger.kernel.org 3558 L: linux-edac@vger.kernel.org
3558 W: bluesmoke.sourceforge.net 3559 W: bluesmoke.sourceforge.net
3559 S: Maintained 3560 S: Maintained
3560 F: drivers/edac/ghes_edac.c 3561 F: drivers/edac/ghes_edac.c
3561 3562
3562 EDAC-I82443BXGX 3563 EDAC-I82443BXGX
3563 M: Tim Small <tim@buttersideup.com> 3564 M: Tim Small <tim@buttersideup.com>
3564 L: linux-edac@vger.kernel.org 3565 L: linux-edac@vger.kernel.org
3565 W: bluesmoke.sourceforge.net 3566 W: bluesmoke.sourceforge.net
3566 S: Maintained 3567 S: Maintained
3567 F: drivers/edac/i82443bxgx_edac.c 3568 F: drivers/edac/i82443bxgx_edac.c
3568 3569
3569 EDAC-I3000 3570 EDAC-I3000
3570 M: Jason Uhlenkott <juhlenko@akamai.com> 3571 M: Jason Uhlenkott <juhlenko@akamai.com>
3571 L: linux-edac@vger.kernel.org 3572 L: linux-edac@vger.kernel.org
3572 W: bluesmoke.sourceforge.net 3573 W: bluesmoke.sourceforge.net
3573 S: Maintained 3574 S: Maintained
3574 F: drivers/edac/i3000_edac.c 3575 F: drivers/edac/i3000_edac.c
3575 3576
3576 EDAC-I5000 3577 EDAC-I5000
3577 M: Doug Thompson <dougthompson@xmission.com> 3578 M: Doug Thompson <dougthompson@xmission.com>
3578 L: linux-edac@vger.kernel.org 3579 L: linux-edac@vger.kernel.org
3579 W: bluesmoke.sourceforge.net 3580 W: bluesmoke.sourceforge.net
3580 S: Maintained 3581 S: Maintained
3581 F: drivers/edac/i5000_edac.c 3582 F: drivers/edac/i5000_edac.c
3582 3583
3583 EDAC-I5400 3584 EDAC-I5400
3584 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com> 3585 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
3585 L: linux-edac@vger.kernel.org 3586 L: linux-edac@vger.kernel.org
3586 W: bluesmoke.sourceforge.net 3587 W: bluesmoke.sourceforge.net
3587 S: Maintained 3588 S: Maintained
3588 F: drivers/edac/i5400_edac.c 3589 F: drivers/edac/i5400_edac.c
3589 3590
3590 EDAC-I7300 3591 EDAC-I7300
3591 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com> 3592 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
3592 L: linux-edac@vger.kernel.org 3593 L: linux-edac@vger.kernel.org
3593 W: bluesmoke.sourceforge.net 3594 W: bluesmoke.sourceforge.net
3594 S: Maintained 3595 S: Maintained
3595 F: drivers/edac/i7300_edac.c 3596 F: drivers/edac/i7300_edac.c
3596 3597
3597 EDAC-I7CORE 3598 EDAC-I7CORE
3598 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com> 3599 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
3599 L: linux-edac@vger.kernel.org 3600 L: linux-edac@vger.kernel.org
3600 W: bluesmoke.sourceforge.net 3601 W: bluesmoke.sourceforge.net
3601 S: Maintained 3602 S: Maintained
3602 F: drivers/edac/i7core_edac.c 3603 F: drivers/edac/i7core_edac.c
3603 3604
3604 EDAC-I82975X 3605 EDAC-I82975X
3605 M: Ranganathan Desikan <ravi@jetztechnologies.com> 3606 M: Ranganathan Desikan <ravi@jetztechnologies.com>
3606 M: "Arvind R." <arvino55@gmail.com> 3607 M: "Arvind R." <arvino55@gmail.com>
3607 L: linux-edac@vger.kernel.org 3608 L: linux-edac@vger.kernel.org
3608 W: bluesmoke.sourceforge.net 3609 W: bluesmoke.sourceforge.net
3609 S: Maintained 3610 S: Maintained
3610 F: drivers/edac/i82975x_edac.c 3611 F: drivers/edac/i82975x_edac.c
3611 3612
3612 EDAC-IE31200 3613 EDAC-IE31200
3613 M: Jason Baron <jbaron@akamai.com> 3614 M: Jason Baron <jbaron@akamai.com>
3614 L: linux-edac@vger.kernel.org 3615 L: linux-edac@vger.kernel.org
3615 W: bluesmoke.sourceforge.net 3616 W: bluesmoke.sourceforge.net
3616 S: Maintained 3617 S: Maintained
3617 F: drivers/edac/ie31200_edac.c 3618 F: drivers/edac/ie31200_edac.c
3618 3619
3619 EDAC-MPC85XX 3620 EDAC-MPC85XX
3620 M: Johannes Thumshirn <johannes.thumshirn@men.de> 3621 M: Johannes Thumshirn <johannes.thumshirn@men.de>
3621 L: linux-edac@vger.kernel.org 3622 L: linux-edac@vger.kernel.org
3622 W: bluesmoke.sourceforge.net 3623 W: bluesmoke.sourceforge.net
3623 S: Maintained 3624 S: Maintained
3624 F: drivers/edac/mpc85xx_edac.[ch] 3625 F: drivers/edac/mpc85xx_edac.[ch]
3625 3626
3626 EDAC-PASEMI 3627 EDAC-PASEMI
3627 M: Egor Martovetsky <egor@pasemi.com> 3628 M: Egor Martovetsky <egor@pasemi.com>
3628 L: linux-edac@vger.kernel.org 3629 L: linux-edac@vger.kernel.org
3629 W: bluesmoke.sourceforge.net 3630 W: bluesmoke.sourceforge.net
3630 S: Maintained 3631 S: Maintained
3631 F: drivers/edac/pasemi_edac.c 3632 F: drivers/edac/pasemi_edac.c
3632 3633
3633 EDAC-R82600 3634 EDAC-R82600
3634 M: Tim Small <tim@buttersideup.com> 3635 M: Tim Small <tim@buttersideup.com>
3635 L: linux-edac@vger.kernel.org 3636 L: linux-edac@vger.kernel.org
3636 W: bluesmoke.sourceforge.net 3637 W: bluesmoke.sourceforge.net
3637 S: Maintained 3638 S: Maintained
3638 F: drivers/edac/r82600_edac.c 3639 F: drivers/edac/r82600_edac.c
3639 3640
3640 EDAC-SBRIDGE 3641 EDAC-SBRIDGE
3641 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com> 3642 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
3642 L: linux-edac@vger.kernel.org 3643 L: linux-edac@vger.kernel.org
3643 W: bluesmoke.sourceforge.net 3644 W: bluesmoke.sourceforge.net
3644 S: Maintained 3645 S: Maintained
3645 F: drivers/edac/sb_edac.c 3646 F: drivers/edac/sb_edac.c
3646 3647
3647 EDIROL UA-101/UA-1000 DRIVER 3648 EDIROL UA-101/UA-1000 DRIVER
3648 M: Clemens Ladisch <clemens@ladisch.de> 3649 M: Clemens Ladisch <clemens@ladisch.de>
3649 L: alsa-devel@alsa-project.org (moderated for non-subscribers) 3650 L: alsa-devel@alsa-project.org (moderated for non-subscribers)
3650 T: git git://git.alsa-project.org/alsa-kernel.git 3651 T: git git://git.alsa-project.org/alsa-kernel.git
3651 S: Maintained 3652 S: Maintained
3652 F: sound/usb/misc/ua101.c 3653 F: sound/usb/misc/ua101.c
3653 3654
3654 EXTENSIBLE FIRMWARE INTERFACE (EFI) 3655 EXTENSIBLE FIRMWARE INTERFACE (EFI)
3655 M: Matt Fleming <matt.fleming@intel.com> 3656 M: Matt Fleming <matt.fleming@intel.com>
3656 L: linux-efi@vger.kernel.org 3657 L: linux-efi@vger.kernel.org
3657 T: git git://git.kernel.org/pub/scm/linux/kernel/git/mfleming/efi.git 3658 T: git git://git.kernel.org/pub/scm/linux/kernel/git/mfleming/efi.git
3658 S: Maintained 3659 S: Maintained
3659 F: Documentation/efi-stub.txt 3660 F: Documentation/efi-stub.txt
3660 F: arch/ia64/kernel/efi.c 3661 F: arch/ia64/kernel/efi.c
3661 F: arch/x86/boot/compressed/eboot.[ch] 3662 F: arch/x86/boot/compressed/eboot.[ch]
3662 F: arch/x86/include/asm/efi.h 3663 F: arch/x86/include/asm/efi.h
3663 F: arch/x86/platform/efi/* 3664 F: arch/x86/platform/efi/*
3664 F: drivers/firmware/efi/* 3665 F: drivers/firmware/efi/*
3665 F: include/linux/efi*.h 3666 F: include/linux/efi*.h
3666 3667
3667 EFI VARIABLE FILESYSTEM 3668 EFI VARIABLE FILESYSTEM
3668 M: Matthew Garrett <matthew.garrett@nebula.com> 3669 M: Matthew Garrett <matthew.garrett@nebula.com>
3669 M: Jeremy Kerr <jk@ozlabs.org> 3670 M: Jeremy Kerr <jk@ozlabs.org>
3670 M: Matt Fleming <matt.fleming@intel.com> 3671 M: Matt Fleming <matt.fleming@intel.com>
3671 T: git git://git.kernel.org/pub/scm/linux/kernel/git/mfleming/efi.git 3672 T: git git://git.kernel.org/pub/scm/linux/kernel/git/mfleming/efi.git
3672 L: linux-efi@vger.kernel.org 3673 L: linux-efi@vger.kernel.org
3673 S: Maintained 3674 S: Maintained
3674 F: fs/efivarfs/ 3675 F: fs/efivarfs/
3675 3676
3676 EFIFB FRAMEBUFFER DRIVER 3677 EFIFB FRAMEBUFFER DRIVER
3677 L: linux-fbdev@vger.kernel.org 3678 L: linux-fbdev@vger.kernel.org
3678 M: Peter Jones <pjones@redhat.com> 3679 M: Peter Jones <pjones@redhat.com>
3679 S: Maintained 3680 S: Maintained
3680 F: drivers/video/fbdev/efifb.c 3681 F: drivers/video/fbdev/efifb.c
3681 3682
3682 EFS FILESYSTEM 3683 EFS FILESYSTEM
3683 W: http://aeschi.ch.eu.org/efs/ 3684 W: http://aeschi.ch.eu.org/efs/
3684 S: Orphan 3685 S: Orphan
3685 F: fs/efs/ 3686 F: fs/efs/
3686 3687
3687 EHCA (IBM GX bus InfiniBand adapter) DRIVER 3688 EHCA (IBM GX bus InfiniBand adapter) DRIVER
3688 M: Hoang-Nam Nguyen <hnguyen@de.ibm.com> 3689 M: Hoang-Nam Nguyen <hnguyen@de.ibm.com>
3689 M: Christoph Raisch <raisch@de.ibm.com> 3690 M: Christoph Raisch <raisch@de.ibm.com>
3690 L: linux-rdma@vger.kernel.org 3691 L: linux-rdma@vger.kernel.org
3691 S: Supported 3692 S: Supported
3692 F: drivers/infiniband/hw/ehca/ 3693 F: drivers/infiniband/hw/ehca/
3693 3694
3694 EHEA (IBM pSeries eHEA 10Gb ethernet adapter) DRIVER 3695 EHEA (IBM pSeries eHEA 10Gb ethernet adapter) DRIVER
3695 M: Thadeu Lima de Souza Cascardo <cascardo@linux.vnet.ibm.com> 3696 M: Thadeu Lima de Souza Cascardo <cascardo@linux.vnet.ibm.com>
3696 L: netdev@vger.kernel.org 3697 L: netdev@vger.kernel.org
3697 S: Maintained 3698 S: Maintained
3698 F: drivers/net/ethernet/ibm/ehea/ 3699 F: drivers/net/ethernet/ibm/ehea/
3699 3700
3700 EM28XX VIDEO4LINUX DRIVER 3701 EM28XX VIDEO4LINUX DRIVER
3701 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com> 3702 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
3702 L: linux-media@vger.kernel.org 3703 L: linux-media@vger.kernel.org
3703 W: http://linuxtv.org 3704 W: http://linuxtv.org
3704 T: git git://linuxtv.org/media_tree.git 3705 T: git git://linuxtv.org/media_tree.git
3705 S: Maintained 3706 S: Maintained
3706 F: drivers/media/usb/em28xx/ 3707 F: drivers/media/usb/em28xx/
3707 3708
3708 EMBEDDED LINUX 3709 EMBEDDED LINUX
3709 M: Paul Gortmaker <paul.gortmaker@windriver.com> 3710 M: Paul Gortmaker <paul.gortmaker@windriver.com>
3710 M: Matt Mackall <mpm@selenic.com> 3711 M: Matt Mackall <mpm@selenic.com>
3711 M: David Woodhouse <dwmw2@infradead.org> 3712 M: David Woodhouse <dwmw2@infradead.org>
3712 L: linux-embedded@vger.kernel.org 3713 L: linux-embedded@vger.kernel.org
3713 S: Maintained 3714 S: Maintained
3714 3715
3715 EMULEX LPFC FC SCSI DRIVER 3716 EMULEX LPFC FC SCSI DRIVER
3716 M: James Smart <james.smart@emulex.com> 3717 M: James Smart <james.smart@emulex.com>
3717 L: linux-scsi@vger.kernel.org 3718 L: linux-scsi@vger.kernel.org
3718 W: http://sourceforge.net/projects/lpfcxxxx 3719 W: http://sourceforge.net/projects/lpfcxxxx
3719 S: Supported 3720 S: Supported
3720 F: drivers/scsi/lpfc/ 3721 F: drivers/scsi/lpfc/
3721 3722
3722 ENE CB710 FLASH CARD READER DRIVER 3723 ENE CB710 FLASH CARD READER DRIVER
3723 M: Michaล‚ Mirosล‚aw <mirq-linux@rere.qmqm.pl> 3724 M: Michaล‚ Mirosล‚aw <mirq-linux@rere.qmqm.pl>
3724 S: Maintained 3725 S: Maintained
3725 F: drivers/misc/cb710/ 3726 F: drivers/misc/cb710/
3726 F: drivers/mmc/host/cb710-mmc.* 3727 F: drivers/mmc/host/cb710-mmc.*
3727 F: include/linux/cb710.h 3728 F: include/linux/cb710.h
3728 3729
3729 ENE KB2426 (ENE0100/ENE020XX) INFRARED RECEIVER 3730 ENE KB2426 (ENE0100/ENE020XX) INFRARED RECEIVER
3730 M: Maxim Levitsky <maximlevitsky@gmail.com> 3731 M: Maxim Levitsky <maximlevitsky@gmail.com>
3731 S: Maintained 3732 S: Maintained
3732 F: drivers/media/rc/ene_ir.* 3733 F: drivers/media/rc/ene_ir.*
3733 3734
3734 ENHANCED ERROR HANDLING (EEH) 3735 ENHANCED ERROR HANDLING (EEH)
3735 M: Gavin Shan <shangw@linux.vnet.ibm.com> 3736 M: Gavin Shan <shangw@linux.vnet.ibm.com>
3736 L: linuxppc-dev@lists.ozlabs.org 3737 L: linuxppc-dev@lists.ozlabs.org
3737 S: Supported 3738 S: Supported
3738 F: Documentation/powerpc/eeh-pci-error-recovery.txt 3739 F: Documentation/powerpc/eeh-pci-error-recovery.txt
3739 F: arch/powerpc/kernel/eeh*.c 3740 F: arch/powerpc/kernel/eeh*.c
3740 3741
3741 EPSON S1D13XXX FRAMEBUFFER DRIVER 3742 EPSON S1D13XXX FRAMEBUFFER DRIVER
3742 M: Kristoffer Ericson <kristoffer.ericson@gmail.com> 3743 M: Kristoffer Ericson <kristoffer.ericson@gmail.com>
3743 S: Maintained 3744 S: Maintained
3744 T: git git://git.kernel.org/pub/scm/linux/kernel/git/kristoffer/linux-hpc.git 3745 T: git git://git.kernel.org/pub/scm/linux/kernel/git/kristoffer/linux-hpc.git
3745 F: drivers/video/fbdev/s1d13xxxfb.c 3746 F: drivers/video/fbdev/s1d13xxxfb.c
3746 F: include/video/s1d13xxxfb.h 3747 F: include/video/s1d13xxxfb.h
3747 3748
3748 ET131X NETWORK DRIVER 3749 ET131X NETWORK DRIVER
3749 M: Mark Einon <mark.einon@gmail.com> 3750 M: Mark Einon <mark.einon@gmail.com>
3750 S: Odd Fixes 3751 S: Odd Fixes
3751 F: drivers/net/ethernet/agere/ 3752 F: drivers/net/ethernet/agere/
3752 3753
3753 ETHERNET BRIDGE 3754 ETHERNET BRIDGE
3754 M: Stephen Hemminger <stephen@networkplumber.org> 3755 M: Stephen Hemminger <stephen@networkplumber.org>
3755 L: bridge@lists.linux-foundation.org 3756 L: bridge@lists.linux-foundation.org
3756 L: netdev@vger.kernel.org 3757 L: netdev@vger.kernel.org
3757 W: http://www.linuxfoundation.org/en/Net:Bridge 3758 W: http://www.linuxfoundation.org/en/Net:Bridge
3758 S: Maintained 3759 S: Maintained
3759 F: include/linux/netfilter_bridge/ 3760 F: include/linux/netfilter_bridge/
3760 F: net/bridge/ 3761 F: net/bridge/
3761 3762
3762 ETHERNET PHY LIBRARY 3763 ETHERNET PHY LIBRARY
3763 M: Florian Fainelli <f.fainelli@gmail.com> 3764 M: Florian Fainelli <f.fainelli@gmail.com>
3764 L: netdev@vger.kernel.org 3765 L: netdev@vger.kernel.org
3765 S: Maintained 3766 S: Maintained
3766 F: include/linux/phy.h 3767 F: include/linux/phy.h
3767 F: include/linux/phy_fixed.h 3768 F: include/linux/phy_fixed.h
3768 F: drivers/net/phy/ 3769 F: drivers/net/phy/
3769 F: Documentation/networking/phy.txt 3770 F: Documentation/networking/phy.txt
3770 F: drivers/of/of_mdio.c 3771 F: drivers/of/of_mdio.c
3771 F: drivers/of/of_net.c 3772 F: drivers/of/of_net.c
3772 3773
3773 EXT2 FILE SYSTEM 3774 EXT2 FILE SYSTEM
3774 M: Jan Kara <jack@suse.cz> 3775 M: Jan Kara <jack@suse.cz>
3775 L: linux-ext4@vger.kernel.org 3776 L: linux-ext4@vger.kernel.org
3776 S: Maintained 3777 S: Maintained
3777 F: Documentation/filesystems/ext2.txt 3778 F: Documentation/filesystems/ext2.txt
3778 F: fs/ext2/ 3779 F: fs/ext2/
3779 F: include/linux/ext2* 3780 F: include/linux/ext2*
3780 3781
3781 EXT3 FILE SYSTEM 3782 EXT3 FILE SYSTEM
3782 M: Jan Kara <jack@suse.cz> 3783 M: Jan Kara <jack@suse.cz>
3783 M: Andrew Morton <akpm@linux-foundation.org> 3784 M: Andrew Morton <akpm@linux-foundation.org>
3784 M: Andreas Dilger <adilger.kernel@dilger.ca> 3785 M: Andreas Dilger <adilger.kernel@dilger.ca>
3785 L: linux-ext4@vger.kernel.org 3786 L: linux-ext4@vger.kernel.org
3786 S: Maintained 3787 S: Maintained
3787 F: Documentation/filesystems/ext3.txt 3788 F: Documentation/filesystems/ext3.txt
3788 F: fs/ext3/ 3789 F: fs/ext3/
3789 3790
3790 EXT4 FILE SYSTEM 3791 EXT4 FILE SYSTEM
3791 M: "Theodore Ts'o" <tytso@mit.edu> 3792 M: "Theodore Ts'o" <tytso@mit.edu>
3792 M: Andreas Dilger <adilger.kernel@dilger.ca> 3793 M: Andreas Dilger <adilger.kernel@dilger.ca>
3793 L: linux-ext4@vger.kernel.org 3794 L: linux-ext4@vger.kernel.org
3794 W: http://ext4.wiki.kernel.org 3795 W: http://ext4.wiki.kernel.org
3795 Q: http://patchwork.ozlabs.org/project/linux-ext4/list/ 3796 Q: http://patchwork.ozlabs.org/project/linux-ext4/list/
3796 S: Maintained 3797 S: Maintained
3797 F: Documentation/filesystems/ext4.txt 3798 F: Documentation/filesystems/ext4.txt
3798 F: fs/ext4/ 3799 F: fs/ext4/
3799 3800
3800 Extended Verification Module (EVM) 3801 Extended Verification Module (EVM)
3801 M: Mimi Zohar <zohar@linux.vnet.ibm.com> 3802 M: Mimi Zohar <zohar@linux.vnet.ibm.com>
3802 L: linux-ima-devel@lists.sourceforge.net 3803 L: linux-ima-devel@lists.sourceforge.net
3803 L: linux-security-module@vger.kernel.org 3804 L: linux-security-module@vger.kernel.org
3804 S: Supported 3805 S: Supported
3805 F: security/integrity/evm/ 3806 F: security/integrity/evm/
3806 3807
3807 EXTERNAL CONNECTOR SUBSYSTEM (EXTCON) 3808 EXTERNAL CONNECTOR SUBSYSTEM (EXTCON)
3808 M: MyungJoo Ham <myungjoo.ham@samsung.com> 3809 M: MyungJoo Ham <myungjoo.ham@samsung.com>
3809 M: Chanwoo Choi <cw00.choi@samsung.com> 3810 M: Chanwoo Choi <cw00.choi@samsung.com>
3810 L: linux-kernel@vger.kernel.org 3811 L: linux-kernel@vger.kernel.org
3811 T: git git://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/extcon.git 3812 T: git git://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/extcon.git
3812 S: Maintained 3813 S: Maintained
3813 F: drivers/extcon/ 3814 F: drivers/extcon/
3814 F: Documentation/extcon/ 3815 F: Documentation/extcon/
3815 3816
3816 EXYNOS DP DRIVER 3817 EXYNOS DP DRIVER
3817 M: Jingoo Han <jg1.han@samsung.com> 3818 M: Jingoo Han <jg1.han@samsung.com>
3818 L: dri-devel@lists.freedesktop.org 3819 L: dri-devel@lists.freedesktop.org
3819 S: Maintained 3820 S: Maintained
3820 F: drivers/gpu/drm/exynos/exynos_dp* 3821 F: drivers/gpu/drm/exynos/exynos_dp*
3821 3822
3822 EXYNOS MIPI DISPLAY DRIVERS 3823 EXYNOS MIPI DISPLAY DRIVERS
3823 M: Inki Dae <inki.dae@samsung.com> 3824 M: Inki Dae <inki.dae@samsung.com>
3824 M: Donghwa Lee <dh09.lee@samsung.com> 3825 M: Donghwa Lee <dh09.lee@samsung.com>
3825 M: Kyungmin Park <kyungmin.park@samsung.com> 3826 M: Kyungmin Park <kyungmin.park@samsung.com>
3826 L: linux-fbdev@vger.kernel.org 3827 L: linux-fbdev@vger.kernel.org
3827 S: Maintained 3828 S: Maintained
3828 F: drivers/video/fbdev/exynos/exynos_mipi* 3829 F: drivers/video/fbdev/exynos/exynos_mipi*
3829 F: include/video/exynos_mipi* 3830 F: include/video/exynos_mipi*
3830 3831
3831 F71805F HARDWARE MONITORING DRIVER 3832 F71805F HARDWARE MONITORING DRIVER
3832 M: Jean Delvare <jdelvare@suse.de> 3833 M: Jean Delvare <jdelvare@suse.de>
3833 L: lm-sensors@lm-sensors.org 3834 L: lm-sensors@lm-sensors.org
3834 S: Maintained 3835 S: Maintained
3835 F: Documentation/hwmon/f71805f 3836 F: Documentation/hwmon/f71805f
3836 F: drivers/hwmon/f71805f.c 3837 F: drivers/hwmon/f71805f.c
3837 3838
3838 FC0011 TUNER DRIVER 3839 FC0011 TUNER DRIVER
3839 M: Michael Buesch <m@bues.ch> 3840 M: Michael Buesch <m@bues.ch>
3840 L: linux-media@vger.kernel.org 3841 L: linux-media@vger.kernel.org
3841 S: Maintained 3842 S: Maintained
3842 F: drivers/media/tuners/fc0011.h 3843 F: drivers/media/tuners/fc0011.h
3843 F: drivers/media/tuners/fc0011.c 3844 F: drivers/media/tuners/fc0011.c
3844 3845
3845 FC2580 MEDIA DRIVER 3846 FC2580 MEDIA DRIVER
3846 M: Antti Palosaari <crope@iki.fi> 3847 M: Antti Palosaari <crope@iki.fi>
3847 L: linux-media@vger.kernel.org 3848 L: linux-media@vger.kernel.org
3848 W: http://linuxtv.org/ 3849 W: http://linuxtv.org/
3849 W: http://palosaari.fi/linux/ 3850 W: http://palosaari.fi/linux/
3850 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 3851 Q: http://patchwork.linuxtv.org/project/linux-media/list/
3851 T: git git://linuxtv.org/anttip/media_tree.git 3852 T: git git://linuxtv.org/anttip/media_tree.git
3852 S: Maintained 3853 S: Maintained
3853 F: drivers/media/tuners/fc2580* 3854 F: drivers/media/tuners/fc2580*
3854 3855
3855 FANOTIFY 3856 FANOTIFY
3856 M: Eric Paris <eparis@redhat.com> 3857 M: Eric Paris <eparis@redhat.com>
3857 S: Maintained 3858 S: Maintained
3858 F: fs/notify/fanotify/ 3859 F: fs/notify/fanotify/
3859 F: include/linux/fanotify.h 3860 F: include/linux/fanotify.h
3860 F: include/uapi/linux/fanotify.h 3861 F: include/uapi/linux/fanotify.h
3861 3862
3862 FARSYNC SYNCHRONOUS DRIVER 3863 FARSYNC SYNCHRONOUS DRIVER
3863 M: Kevin Curtis <kevin.curtis@farsite.co.uk> 3864 M: Kevin Curtis <kevin.curtis@farsite.co.uk>
3864 W: http://www.farsite.co.uk/ 3865 W: http://www.farsite.co.uk/
3865 S: Supported 3866 S: Supported
3866 F: drivers/net/wan/farsync.* 3867 F: drivers/net/wan/farsync.*
3867 3868
3868 FAULT INJECTION SUPPORT 3869 FAULT INJECTION SUPPORT
3869 M: Akinobu Mita <akinobu.mita@gmail.com> 3870 M: Akinobu Mita <akinobu.mita@gmail.com>
3870 S: Supported 3871 S: Supported
3871 F: Documentation/fault-injection/ 3872 F: Documentation/fault-injection/
3872 F: lib/fault-inject.c 3873 F: lib/fault-inject.c
3873 3874
3874 FCOE SUBSYSTEM (libfc, libfcoe, fcoe) 3875 FCOE SUBSYSTEM (libfc, libfcoe, fcoe)
3875 M: Robert Love <robert.w.love@intel.com> 3876 M: Robert Love <robert.w.love@intel.com>
3876 L: fcoe-devel@open-fcoe.org 3877 L: fcoe-devel@open-fcoe.org
3877 W: www.Open-FCoE.org 3878 W: www.Open-FCoE.org
3878 S: Supported 3879 S: Supported
3879 F: drivers/scsi/libfc/ 3880 F: drivers/scsi/libfc/
3880 F: drivers/scsi/fcoe/ 3881 F: drivers/scsi/fcoe/
3881 F: include/scsi/fc/ 3882 F: include/scsi/fc/
3882 F: include/scsi/libfc.h 3883 F: include/scsi/libfc.h
3883 F: include/scsi/libfcoe.h 3884 F: include/scsi/libfcoe.h
3884 F: include/uapi/scsi/fc/ 3885 F: include/uapi/scsi/fc/
3885 3886
3886 FILE LOCKING (flock() and fcntl()/lockf()) 3887 FILE LOCKING (flock() and fcntl()/lockf())
3887 M: Jeff Layton <jlayton@poochiereds.net> 3888 M: Jeff Layton <jlayton@poochiereds.net>
3888 M: J. Bruce Fields <bfields@fieldses.org> 3889 M: J. Bruce Fields <bfields@fieldses.org>
3889 L: linux-fsdevel@vger.kernel.org 3890 L: linux-fsdevel@vger.kernel.org
3890 S: Maintained 3891 S: Maintained
3891 F: include/linux/fcntl.h 3892 F: include/linux/fcntl.h
3892 F: include/linux/fs.h 3893 F: include/linux/fs.h
3893 F: include/uapi/linux/fcntl.h 3894 F: include/uapi/linux/fcntl.h
3894 F: include/uapi/linux/fs.h 3895 F: include/uapi/linux/fs.h
3895 F: fs/fcntl.c 3896 F: fs/fcntl.c
3896 F: fs/locks.c 3897 F: fs/locks.c
3897 3898
3898 FILESYSTEMS (VFS and infrastructure) 3899 FILESYSTEMS (VFS and infrastructure)
3899 M: Alexander Viro <viro@zeniv.linux.org.uk> 3900 M: Alexander Viro <viro@zeniv.linux.org.uk>
3900 L: linux-fsdevel@vger.kernel.org 3901 L: linux-fsdevel@vger.kernel.org
3901 S: Maintained 3902 S: Maintained
3902 F: fs/* 3903 F: fs/*
3903 3904
3904 FINTEK F75375S HARDWARE MONITOR AND FAN CONTROLLER DRIVER 3905 FINTEK F75375S HARDWARE MONITOR AND FAN CONTROLLER DRIVER
3905 M: Riku Voipio <riku.voipio@iki.fi> 3906 M: Riku Voipio <riku.voipio@iki.fi>
3906 L: lm-sensors@lm-sensors.org 3907 L: lm-sensors@lm-sensors.org
3907 S: Maintained 3908 S: Maintained
3908 F: drivers/hwmon/f75375s.c 3909 F: drivers/hwmon/f75375s.c
3909 F: include/linux/f75375s.h 3910 F: include/linux/f75375s.h
3910 3911
3911 FIREWIRE AUDIO DRIVERS 3912 FIREWIRE AUDIO DRIVERS
3912 M: Clemens Ladisch <clemens@ladisch.de> 3913 M: Clemens Ladisch <clemens@ladisch.de>
3913 L: alsa-devel@alsa-project.org (moderated for non-subscribers) 3914 L: alsa-devel@alsa-project.org (moderated for non-subscribers)
3914 T: git git://git.alsa-project.org/alsa-kernel.git 3915 T: git git://git.alsa-project.org/alsa-kernel.git
3915 S: Maintained 3916 S: Maintained
3916 F: sound/firewire/ 3917 F: sound/firewire/
3917 3918
3918 FIREWIRE MEDIA DRIVERS (firedtv) 3919 FIREWIRE MEDIA DRIVERS (firedtv)
3919 M: Stefan Richter <stefanr@s5r6.in-berlin.de> 3920 M: Stefan Richter <stefanr@s5r6.in-berlin.de>
3920 L: linux-media@vger.kernel.org 3921 L: linux-media@vger.kernel.org
3921 L: linux1394-devel@lists.sourceforge.net 3922 L: linux1394-devel@lists.sourceforge.net
3922 T: git git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media.git 3923 T: git git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media.git
3923 S: Maintained 3924 S: Maintained
3924 F: drivers/media/firewire/ 3925 F: drivers/media/firewire/
3925 3926
3926 FIREWIRE SBP-2 TARGET 3927 FIREWIRE SBP-2 TARGET
3927 M: Chris Boot <bootc@bootc.net> 3928 M: Chris Boot <bootc@bootc.net>
3928 L: linux-scsi@vger.kernel.org 3929 L: linux-scsi@vger.kernel.org
3929 L: target-devel@vger.kernel.org 3930 L: target-devel@vger.kernel.org
3930 L: linux1394-devel@lists.sourceforge.net 3931 L: linux1394-devel@lists.sourceforge.net
3931 T: git git://git.kernel.org/pub/scm/linux/kernel/git/nab/lio-core-2.6.git master 3932 T: git git://git.kernel.org/pub/scm/linux/kernel/git/nab/lio-core-2.6.git master
3932 S: Maintained 3933 S: Maintained
3933 F: drivers/target/sbp/ 3934 F: drivers/target/sbp/
3934 3935
3935 FIREWIRE SUBSYSTEM 3936 FIREWIRE SUBSYSTEM
3936 M: Stefan Richter <stefanr@s5r6.in-berlin.de> 3937 M: Stefan Richter <stefanr@s5r6.in-berlin.de>
3937 L: linux1394-devel@lists.sourceforge.net 3938 L: linux1394-devel@lists.sourceforge.net
3938 W: http://ieee1394.wiki.kernel.org/ 3939 W: http://ieee1394.wiki.kernel.org/
3939 T: git git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394.git 3940 T: git git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394.git
3940 S: Maintained 3941 S: Maintained
3941 F: drivers/firewire/ 3942 F: drivers/firewire/
3942 F: include/linux/firewire.h 3943 F: include/linux/firewire.h
3943 F: include/uapi/linux/firewire*.h 3944 F: include/uapi/linux/firewire*.h
3944 F: tools/firewire/ 3945 F: tools/firewire/
3945 3946
3946 FIRMWARE LOADER (request_firmware) 3947 FIRMWARE LOADER (request_firmware)
3947 M: Ming Lei <ming.lei@canonical.com> 3948 M: Ming Lei <ming.lei@canonical.com>
3948 L: linux-kernel@vger.kernel.org 3949 L: linux-kernel@vger.kernel.org
3949 S: Maintained 3950 S: Maintained
3950 F: Documentation/firmware_class/ 3951 F: Documentation/firmware_class/
3951 F: drivers/base/firmware*.c 3952 F: drivers/base/firmware*.c
3952 F: include/linux/firmware.h 3953 F: include/linux/firmware.h
3953 3954
3954 FLASH ADAPTER DRIVER (IBM Flash Adapter 900GB Full Height PCI Flash Card) 3955 FLASH ADAPTER DRIVER (IBM Flash Adapter 900GB Full Height PCI Flash Card)
3955 M: Joshua Morris <josh.h.morris@us.ibm.com> 3956 M: Joshua Morris <josh.h.morris@us.ibm.com>
3956 M: Philip Kelleher <pjk1939@linux.vnet.ibm.com> 3957 M: Philip Kelleher <pjk1939@linux.vnet.ibm.com>
3957 S: Maintained 3958 S: Maintained
3958 F: drivers/block/rsxx/ 3959 F: drivers/block/rsxx/
3959 3960
3960 FLOPPY DRIVER 3961 FLOPPY DRIVER
3961 M: Jiri Kosina <jkosina@suse.cz> 3962 M: Jiri Kosina <jkosina@suse.cz>
3962 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jikos/floppy.git 3963 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jikos/floppy.git
3963 S: Odd fixes 3964 S: Odd fixes
3964 F: drivers/block/floppy.c 3965 F: drivers/block/floppy.c
3965 3966
3966 FMC SUBSYSTEM 3967 FMC SUBSYSTEM
3967 M: Alessandro Rubini <rubini@gnudd.com> 3968 M: Alessandro Rubini <rubini@gnudd.com>
3968 W: http://www.ohwr.org/projects/fmc-bus 3969 W: http://www.ohwr.org/projects/fmc-bus
3969 S: Supported 3970 S: Supported
3970 F: drivers/fmc/ 3971 F: drivers/fmc/
3971 F: include/linux/fmc*.h 3972 F: include/linux/fmc*.h
3972 F: include/linux/ipmi-fru.h 3973 F: include/linux/ipmi-fru.h
3973 K: fmc_d.*register 3974 K: fmc_d.*register
3974 3975
3975 FPU EMULATOR 3976 FPU EMULATOR
3976 M: Bill Metzenthen <billm@melbpc.org.au> 3977 M: Bill Metzenthen <billm@melbpc.org.au>
3977 W: http://floatingpoint.sourceforge.net/emulator/index.html 3978 W: http://floatingpoint.sourceforge.net/emulator/index.html
3978 S: Maintained 3979 S: Maintained
3979 F: arch/x86/math-emu/ 3980 F: arch/x86/math-emu/
3980 3981
3981 FRAME RELAY DLCI/FRAD (Sangoma drivers too) 3982 FRAME RELAY DLCI/FRAD (Sangoma drivers too)
3982 L: netdev@vger.kernel.org 3983 L: netdev@vger.kernel.org
3983 S: Orphan 3984 S: Orphan
3984 F: drivers/net/wan/dlci.c 3985 F: drivers/net/wan/dlci.c
3985 F: drivers/net/wan/sdla.c 3986 F: drivers/net/wan/sdla.c
3986 3987
3987 FRAMEBUFFER LAYER 3988 FRAMEBUFFER LAYER
3988 M: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com> 3989 M: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>
3989 M: Tomi Valkeinen <tomi.valkeinen@ti.com> 3990 M: Tomi Valkeinen <tomi.valkeinen@ti.com>
3990 L: linux-fbdev@vger.kernel.org 3991 L: linux-fbdev@vger.kernel.org
3991 W: http://linux-fbdev.sourceforge.net/ 3992 W: http://linux-fbdev.sourceforge.net/
3992 Q: http://patchwork.kernel.org/project/linux-fbdev/list/ 3993 Q: http://patchwork.kernel.org/project/linux-fbdev/list/
3993 T: git git://git.kernel.org/pub/scm/linux/kernel/git/plagnioj/linux-fbdev.git 3994 T: git git://git.kernel.org/pub/scm/linux/kernel/git/plagnioj/linux-fbdev.git
3994 S: Maintained 3995 S: Maintained
3995 F: Documentation/fb/ 3996 F: Documentation/fb/
3996 F: Documentation/devicetree/bindings/fb/ 3997 F: Documentation/devicetree/bindings/fb/
3997 F: drivers/video/ 3998 F: drivers/video/
3998 F: include/video/ 3999 F: include/video/
3999 F: include/linux/fb.h 4000 F: include/linux/fb.h
4000 F: include/uapi/video/ 4001 F: include/uapi/video/
4001 F: include/uapi/linux/fb.h 4002 F: include/uapi/linux/fb.h
4002 4003
4003 FREESCALE DIU FRAMEBUFFER DRIVER 4004 FREESCALE DIU FRAMEBUFFER DRIVER
4004 M: Timur Tabi <timur@tabi.org> 4005 M: Timur Tabi <timur@tabi.org>
4005 L: linux-fbdev@vger.kernel.org 4006 L: linux-fbdev@vger.kernel.org
4006 S: Maintained 4007 S: Maintained
4007 F: drivers/video/fbdev/fsl-diu-fb.* 4008 F: drivers/video/fbdev/fsl-diu-fb.*
4008 4009
4009 FREESCALE DMA DRIVER 4010 FREESCALE DMA DRIVER
4010 M: Li Yang <leoli@freescale.com> 4011 M: Li Yang <leoli@freescale.com>
4011 M: Zhang Wei <zw@zh-kernel.org> 4012 M: Zhang Wei <zw@zh-kernel.org>
4012 L: linuxppc-dev@lists.ozlabs.org 4013 L: linuxppc-dev@lists.ozlabs.org
4013 S: Maintained 4014 S: Maintained
4014 F: drivers/dma/fsldma.* 4015 F: drivers/dma/fsldma.*
4015 4016
4016 FREESCALE I2C CPM DRIVER 4017 FREESCALE I2C CPM DRIVER
4017 M: Jochen Friedrich <jochen@scram.de> 4018 M: Jochen Friedrich <jochen@scram.de>
4018 L: linuxppc-dev@lists.ozlabs.org 4019 L: linuxppc-dev@lists.ozlabs.org
4019 L: linux-i2c@vger.kernel.org 4020 L: linux-i2c@vger.kernel.org
4020 S: Maintained 4021 S: Maintained
4021 F: drivers/i2c/busses/i2c-cpm.c 4022 F: drivers/i2c/busses/i2c-cpm.c
4022 4023
4023 FREESCALE IMX / MXC FRAMEBUFFER DRIVER 4024 FREESCALE IMX / MXC FRAMEBUFFER DRIVER
4024 M: Sascha Hauer <kernel@pengutronix.de> 4025 M: Sascha Hauer <kernel@pengutronix.de>
4025 L: linux-fbdev@vger.kernel.org 4026 L: linux-fbdev@vger.kernel.org
4026 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 4027 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
4027 S: Maintained 4028 S: Maintained
4028 F: include/linux/platform_data/video-imxfb.h 4029 F: include/linux/platform_data/video-imxfb.h
4029 F: drivers/video/fbdev/imxfb.c 4030 F: drivers/video/fbdev/imxfb.c
4030 4031
4031 FREESCALE SOC FS_ENET DRIVER 4032 FREESCALE SOC FS_ENET DRIVER
4032 M: Pantelis Antoniou <pantelis.antoniou@gmail.com> 4033 M: Pantelis Antoniou <pantelis.antoniou@gmail.com>
4033 M: Vitaly Bordug <vbordug@ru.mvista.com> 4034 M: Vitaly Bordug <vbordug@ru.mvista.com>
4034 L: linuxppc-dev@lists.ozlabs.org 4035 L: linuxppc-dev@lists.ozlabs.org
4035 L: netdev@vger.kernel.org 4036 L: netdev@vger.kernel.org
4036 S: Maintained 4037 S: Maintained
4037 F: drivers/net/ethernet/freescale/fs_enet/ 4038 F: drivers/net/ethernet/freescale/fs_enet/
4038 F: include/linux/fs_enet_pd.h 4039 F: include/linux/fs_enet_pd.h
4039 4040
4040 FREESCALE QUICC ENGINE LIBRARY 4041 FREESCALE QUICC ENGINE LIBRARY
4041 L: linuxppc-dev@lists.ozlabs.org 4042 L: linuxppc-dev@lists.ozlabs.org
4042 S: Orphan 4043 S: Orphan
4043 F: arch/powerpc/sysdev/qe_lib/ 4044 F: arch/powerpc/sysdev/qe_lib/
4044 F: arch/powerpc/include/asm/*qe.h 4045 F: arch/powerpc/include/asm/*qe.h
4045 4046
4046 FREESCALE USB PERIPHERAL DRIVERS 4047 FREESCALE USB PERIPHERAL DRIVERS
4047 M: Li Yang <leoli@freescale.com> 4048 M: Li Yang <leoli@freescale.com>
4048 L: linux-usb@vger.kernel.org 4049 L: linux-usb@vger.kernel.org
4049 L: linuxppc-dev@lists.ozlabs.org 4050 L: linuxppc-dev@lists.ozlabs.org
4050 S: Maintained 4051 S: Maintained
4051 F: drivers/usb/gadget/udc/fsl* 4052 F: drivers/usb/gadget/udc/fsl*
4052 4053
4053 FREESCALE QUICC ENGINE UCC ETHERNET DRIVER 4054 FREESCALE QUICC ENGINE UCC ETHERNET DRIVER
4054 M: Li Yang <leoli@freescale.com> 4055 M: Li Yang <leoli@freescale.com>
4055 L: netdev@vger.kernel.org 4056 L: netdev@vger.kernel.org
4056 L: linuxppc-dev@lists.ozlabs.org 4057 L: linuxppc-dev@lists.ozlabs.org
4057 S: Maintained 4058 S: Maintained
4058 F: drivers/net/ethernet/freescale/ucc_geth* 4059 F: drivers/net/ethernet/freescale/ucc_geth*
4059 4060
4060 FREESCALE QUICC ENGINE UCC UART DRIVER 4061 FREESCALE QUICC ENGINE UCC UART DRIVER
4061 M: Timur Tabi <timur@tabi.org> 4062 M: Timur Tabi <timur@tabi.org>
4062 L: linuxppc-dev@lists.ozlabs.org 4063 L: linuxppc-dev@lists.ozlabs.org
4063 S: Maintained 4064 S: Maintained
4064 F: drivers/tty/serial/ucc_uart.c 4065 F: drivers/tty/serial/ucc_uart.c
4065 4066
4066 FREESCALE SOC SOUND DRIVERS 4067 FREESCALE SOC SOUND DRIVERS
4067 M: Timur Tabi <timur@tabi.org> 4068 M: Timur Tabi <timur@tabi.org>
4068 M: Nicolin Chen <nicoleotsuka@gmail.com> 4069 M: Nicolin Chen <nicoleotsuka@gmail.com>
4069 M: Xiubo Li <Xiubo.Lee@gmail.com> 4070 M: Xiubo Li <Xiubo.Lee@gmail.com>
4070 L: alsa-devel@alsa-project.org (moderated for non-subscribers) 4071 L: alsa-devel@alsa-project.org (moderated for non-subscribers)
4071 L: linuxppc-dev@lists.ozlabs.org 4072 L: linuxppc-dev@lists.ozlabs.org
4072 S: Maintained 4073 S: Maintained
4073 F: sound/soc/fsl/fsl* 4074 F: sound/soc/fsl/fsl*
4074 F: sound/soc/fsl/imx* 4075 F: sound/soc/fsl/imx*
4075 F: sound/soc/fsl/mpc8610_hpcd.c 4076 F: sound/soc/fsl/mpc8610_hpcd.c
4076 4077
4077 FREEVXFS FILESYSTEM 4078 FREEVXFS FILESYSTEM
4078 M: Christoph Hellwig <hch@infradead.org> 4079 M: Christoph Hellwig <hch@infradead.org>
4079 W: ftp://ftp.openlinux.org/pub/people/hch/vxfs 4080 W: ftp://ftp.openlinux.org/pub/people/hch/vxfs
4080 S: Maintained 4081 S: Maintained
4081 F: fs/freevxfs/ 4082 F: fs/freevxfs/
4082 4083
4083 FREEZER 4084 FREEZER
4084 M: "Rafael J. Wysocki" <rjw@rjwysocki.net> 4085 M: "Rafael J. Wysocki" <rjw@rjwysocki.net>
4085 M: Pavel Machek <pavel@ucw.cz> 4086 M: Pavel Machek <pavel@ucw.cz>
4086 L: linux-pm@vger.kernel.org 4087 L: linux-pm@vger.kernel.org
4087 S: Supported 4088 S: Supported
4088 F: Documentation/power/freezing-of-tasks.txt 4089 F: Documentation/power/freezing-of-tasks.txt
4089 F: include/linux/freezer.h 4090 F: include/linux/freezer.h
4090 F: kernel/freezer.c 4091 F: kernel/freezer.c
4091 4092
4092 FRONTSWAP API 4093 FRONTSWAP API
4093 M: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> 4094 M: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
4094 L: linux-kernel@vger.kernel.org 4095 L: linux-kernel@vger.kernel.org
4095 S: Maintained 4096 S: Maintained
4096 F: mm/frontswap.c 4097 F: mm/frontswap.c
4097 F: include/linux/frontswap.h 4098 F: include/linux/frontswap.h
4098 4099
4099 FS-CACHE: LOCAL CACHING FOR NETWORK FILESYSTEMS 4100 FS-CACHE: LOCAL CACHING FOR NETWORK FILESYSTEMS
4100 M: David Howells <dhowells@redhat.com> 4101 M: David Howells <dhowells@redhat.com>
4101 L: linux-cachefs@redhat.com 4102 L: linux-cachefs@redhat.com
4102 S: Supported 4103 S: Supported
4103 F: Documentation/filesystems/caching/ 4104 F: Documentation/filesystems/caching/
4104 F: fs/fscache/ 4105 F: fs/fscache/
4105 F: include/linux/fscache*.h 4106 F: include/linux/fscache*.h
4106 4107
4107 F2FS FILE SYSTEM 4108 F2FS FILE SYSTEM
4108 M: Jaegeuk Kim <jaegeuk@kernel.org> 4109 M: Jaegeuk Kim <jaegeuk@kernel.org>
4109 M: Changman Lee <cm224.lee@samsung.com> 4110 M: Changman Lee <cm224.lee@samsung.com>
4110 L: linux-f2fs-devel@lists.sourceforge.net 4111 L: linux-f2fs-devel@lists.sourceforge.net
4111 W: http://en.wikipedia.org/wiki/F2FS 4112 W: http://en.wikipedia.org/wiki/F2FS
4112 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs.git 4113 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs.git
4113 S: Maintained 4114 S: Maintained
4114 F: Documentation/filesystems/f2fs.txt 4115 F: Documentation/filesystems/f2fs.txt
4115 F: Documentation/ABI/testing/sysfs-fs-f2fs 4116 F: Documentation/ABI/testing/sysfs-fs-f2fs
4116 F: fs/f2fs/ 4117 F: fs/f2fs/
4117 F: include/linux/f2fs_fs.h 4118 F: include/linux/f2fs_fs.h
4118 4119
4119 FUJITSU FR-V (FRV) PORT 4120 FUJITSU FR-V (FRV) PORT
4120 M: David Howells <dhowells@redhat.com> 4121 M: David Howells <dhowells@redhat.com>
4121 S: Maintained 4122 S: Maintained
4122 F: arch/frv/ 4123 F: arch/frv/
4123 4124
4124 FUJITSU LAPTOP EXTRAS 4125 FUJITSU LAPTOP EXTRAS
4125 M: Jonathan Woithe <jwoithe@just42.net> 4126 M: Jonathan Woithe <jwoithe@just42.net>
4126 L: platform-driver-x86@vger.kernel.org 4127 L: platform-driver-x86@vger.kernel.org
4127 S: Maintained 4128 S: Maintained
4128 F: drivers/platform/x86/fujitsu-laptop.c 4129 F: drivers/platform/x86/fujitsu-laptop.c
4129 4130
4130 FUJITSU M-5MO LS CAMERA ISP DRIVER 4131 FUJITSU M-5MO LS CAMERA ISP DRIVER
4131 M: Kyungmin Park <kyungmin.park@samsung.com> 4132 M: Kyungmin Park <kyungmin.park@samsung.com>
4132 M: Heungjun Kim <riverful.kim@samsung.com> 4133 M: Heungjun Kim <riverful.kim@samsung.com>
4133 L: linux-media@vger.kernel.org 4134 L: linux-media@vger.kernel.org
4134 S: Maintained 4135 S: Maintained
4135 F: drivers/media/i2c/m5mols/ 4136 F: drivers/media/i2c/m5mols/
4136 F: include/media/m5mols.h 4137 F: include/media/m5mols.h
4137 4138
4138 FUJITSU TABLET EXTRAS 4139 FUJITSU TABLET EXTRAS
4139 M: Robert Gerlach <khnz@gmx.de> 4140 M: Robert Gerlach <khnz@gmx.de>
4140 L: platform-driver-x86@vger.kernel.org 4141 L: platform-driver-x86@vger.kernel.org
4141 S: Maintained 4142 S: Maintained
4142 F: drivers/platform/x86/fujitsu-tablet.c 4143 F: drivers/platform/x86/fujitsu-tablet.c
4143 4144
4144 FUSE: FILESYSTEM IN USERSPACE 4145 FUSE: FILESYSTEM IN USERSPACE
4145 M: Miklos Szeredi <miklos@szeredi.hu> 4146 M: Miklos Szeredi <miklos@szeredi.hu>
4146 L: fuse-devel@lists.sourceforge.net 4147 L: fuse-devel@lists.sourceforge.net
4147 W: http://fuse.sourceforge.net/ 4148 W: http://fuse.sourceforge.net/
4148 S: Maintained 4149 S: Maintained
4149 F: fs/fuse/ 4150 F: fs/fuse/
4150 F: include/uapi/linux/fuse.h 4151 F: include/uapi/linux/fuse.h
4151 4152
4152 FUTURE DOMAIN TMC-16x0 SCSI DRIVER (16-bit) 4153 FUTURE DOMAIN TMC-16x0 SCSI DRIVER (16-bit)
4153 M: Rik Faith <faith@cs.unc.edu> 4154 M: Rik Faith <faith@cs.unc.edu>
4154 L: linux-scsi@vger.kernel.org 4155 L: linux-scsi@vger.kernel.org
4155 S: Odd Fixes (e.g., new signatures) 4156 S: Odd Fixes (e.g., new signatures)
4156 F: drivers/scsi/fdomain.* 4157 F: drivers/scsi/fdomain.*
4157 4158
4158 GCOV BASED KERNEL PROFILING 4159 GCOV BASED KERNEL PROFILING
4159 M: Peter Oberparleiter <oberpar@linux.vnet.ibm.com> 4160 M: Peter Oberparleiter <oberpar@linux.vnet.ibm.com>
4160 S: Maintained 4161 S: Maintained
4161 F: kernel/gcov/ 4162 F: kernel/gcov/
4162 F: Documentation/gcov.txt 4163 F: Documentation/gcov.txt
4163 4164
4164 GDT SCSI DISK ARRAY CONTROLLER DRIVER 4165 GDT SCSI DISK ARRAY CONTROLLER DRIVER
4165 M: Achim Leubner <achim_leubner@adaptec.com> 4166 M: Achim Leubner <achim_leubner@adaptec.com>
4166 L: linux-scsi@vger.kernel.org 4167 L: linux-scsi@vger.kernel.org
4167 W: http://www.icp-vortex.com/ 4168 W: http://www.icp-vortex.com/
4168 S: Supported 4169 S: Supported
4169 F: drivers/scsi/gdt* 4170 F: drivers/scsi/gdt*
4170 4171
4171 GEMTEK FM RADIO RECEIVER DRIVER 4172 GEMTEK FM RADIO RECEIVER DRIVER
4172 M: Hans Verkuil <hverkuil@xs4all.nl> 4173 M: Hans Verkuil <hverkuil@xs4all.nl>
4173 L: linux-media@vger.kernel.org 4174 L: linux-media@vger.kernel.org
4174 T: git git://linuxtv.org/media_tree.git 4175 T: git git://linuxtv.org/media_tree.git
4175 W: http://linuxtv.org 4176 W: http://linuxtv.org
4176 S: Maintained 4177 S: Maintained
4177 F: drivers/media/radio/radio-gemtek* 4178 F: drivers/media/radio/radio-gemtek*
4178 4179
4179 GENERIC GPIO I2C DRIVER 4180 GENERIC GPIO I2C DRIVER
4180 M: Haavard Skinnemoen <hskinnemoen@gmail.com> 4181 M: Haavard Skinnemoen <hskinnemoen@gmail.com>
4181 S: Supported 4182 S: Supported
4182 F: drivers/i2c/busses/i2c-gpio.c 4183 F: drivers/i2c/busses/i2c-gpio.c
4183 F: include/linux/i2c-gpio.h 4184 F: include/linux/i2c-gpio.h
4184 4185
4185 GENERIC GPIO I2C MULTIPLEXER DRIVER 4186 GENERIC GPIO I2C MULTIPLEXER DRIVER
4186 M: Peter Korsgaard <peter.korsgaard@barco.com> 4187 M: Peter Korsgaard <peter.korsgaard@barco.com>
4187 L: linux-i2c@vger.kernel.org 4188 L: linux-i2c@vger.kernel.org
4188 S: Supported 4189 S: Supported
4189 F: drivers/i2c/muxes/i2c-mux-gpio.c 4190 F: drivers/i2c/muxes/i2c-mux-gpio.c
4190 F: include/linux/i2c-mux-gpio.h 4191 F: include/linux/i2c-mux-gpio.h
4191 F: Documentation/i2c/muxes/i2c-mux-gpio 4192 F: Documentation/i2c/muxes/i2c-mux-gpio
4192 4193
4193 GENERIC HDLC (WAN) DRIVERS 4194 GENERIC HDLC (WAN) DRIVERS
4194 M: Krzysztof Halasa <khc@pm.waw.pl> 4195 M: Krzysztof Halasa <khc@pm.waw.pl>
4195 W: http://www.kernel.org/pub/linux/utils/net/hdlc/ 4196 W: http://www.kernel.org/pub/linux/utils/net/hdlc/
4196 S: Maintained 4197 S: Maintained
4197 F: drivers/net/wan/c101.c 4198 F: drivers/net/wan/c101.c
4198 F: drivers/net/wan/hd6457* 4199 F: drivers/net/wan/hd6457*
4199 F: drivers/net/wan/hdlc* 4200 F: drivers/net/wan/hdlc*
4200 F: drivers/net/wan/n2.c 4201 F: drivers/net/wan/n2.c
4201 F: drivers/net/wan/pc300too.c 4202 F: drivers/net/wan/pc300too.c
4202 F: drivers/net/wan/pci200syn.c 4203 F: drivers/net/wan/pci200syn.c
4203 F: drivers/net/wan/wanxl* 4204 F: drivers/net/wan/wanxl*
4204 4205
4205 GENERIC INCLUDE/ASM HEADER FILES 4206 GENERIC INCLUDE/ASM HEADER FILES
4206 M: Arnd Bergmann <arnd@arndb.de> 4207 M: Arnd Bergmann <arnd@arndb.de>
4207 L: linux-arch@vger.kernel.org 4208 L: linux-arch@vger.kernel.org
4208 T: git git://git.kernel.org/pub/scm/linux/kernel/git/arnd/asm-generic.git 4209 T: git git://git.kernel.org/pub/scm/linux/kernel/git/arnd/asm-generic.git
4209 S: Maintained 4210 S: Maintained
4210 F: include/asm-generic/ 4211 F: include/asm-generic/
4211 F: include/uapi/asm-generic/ 4212 F: include/uapi/asm-generic/
4212 4213
4213 GENERIC PHY FRAMEWORK 4214 GENERIC PHY FRAMEWORK
4214 M: Kishon Vijay Abraham I <kishon@ti.com> 4215 M: Kishon Vijay Abraham I <kishon@ti.com>
4215 L: linux-kernel@vger.kernel.org 4216 L: linux-kernel@vger.kernel.org
4216 T: git git://git.kernel.org/pub/scm/linux/kernel/git/kishon/linux-phy.git 4217 T: git git://git.kernel.org/pub/scm/linux/kernel/git/kishon/linux-phy.git
4217 S: Supported 4218 S: Supported
4218 F: drivers/phy/ 4219 F: drivers/phy/
4219 F: include/linux/phy/ 4220 F: include/linux/phy/
4220 4221
4221 GENERIC UIO DRIVER FOR PCI DEVICES 4222 GENERIC UIO DRIVER FOR PCI DEVICES
4222 M: "Michael S. Tsirkin" <mst@redhat.com> 4223 M: "Michael S. Tsirkin" <mst@redhat.com>
4223 L: kvm@vger.kernel.org 4224 L: kvm@vger.kernel.org
4224 S: Supported 4225 S: Supported
4225 F: drivers/uio/uio_pci_generic.c 4226 F: drivers/uio/uio_pci_generic.c
4226 4227
4227 GET_MAINTAINER SCRIPT 4228 GET_MAINTAINER SCRIPT
4228 M: Joe Perches <joe@perches.com> 4229 M: Joe Perches <joe@perches.com>
4229 S: Maintained 4230 S: Maintained
4230 F: scripts/get_maintainer.pl 4231 F: scripts/get_maintainer.pl
4231 4232
4232 GFS2 FILE SYSTEM 4233 GFS2 FILE SYSTEM
4233 M: Steven Whitehouse <swhiteho@redhat.com> 4234 M: Steven Whitehouse <swhiteho@redhat.com>
4234 L: cluster-devel@redhat.com 4235 L: cluster-devel@redhat.com
4235 W: http://sources.redhat.com/cluster/ 4236 W: http://sources.redhat.com/cluster/
4236 T: git git://git.kernel.org/pub/scm/linux/kernel/git/steve/gfs2-3.0-fixes.git 4237 T: git git://git.kernel.org/pub/scm/linux/kernel/git/steve/gfs2-3.0-fixes.git
4237 T: git git://git.kernel.org/pub/scm/linux/kernel/git/steve/gfs2-3.0-nmw.git 4238 T: git git://git.kernel.org/pub/scm/linux/kernel/git/steve/gfs2-3.0-nmw.git
4238 S: Supported 4239 S: Supported
4239 F: Documentation/filesystems/gfs2*.txt 4240 F: Documentation/filesystems/gfs2*.txt
4240 F: fs/gfs2/ 4241 F: fs/gfs2/
4241 F: include/uapi/linux/gfs2_ondisk.h 4242 F: include/uapi/linux/gfs2_ondisk.h
4242 4243
4243 GIGASET ISDN DRIVERS 4244 GIGASET ISDN DRIVERS
4244 M: Hansjoerg Lipp <hjlipp@web.de> 4245 M: Hansjoerg Lipp <hjlipp@web.de>
4245 M: Tilman Schmidt <tilman@imap.cc> 4246 M: Tilman Schmidt <tilman@imap.cc>
4246 L: gigaset307x-common@lists.sourceforge.net 4247 L: gigaset307x-common@lists.sourceforge.net
4247 W: http://gigaset307x.sourceforge.net/ 4248 W: http://gigaset307x.sourceforge.net/
4248 S: Maintained 4249 S: Maintained
4249 F: Documentation/isdn/README.gigaset 4250 F: Documentation/isdn/README.gigaset
4250 F: drivers/isdn/gigaset/ 4251 F: drivers/isdn/gigaset/
4251 F: include/uapi/linux/gigaset_dev.h 4252 F: include/uapi/linux/gigaset_dev.h
4252 4253
4253 GO7007 MPEG CODEC 4254 GO7007 MPEG CODEC
4254 M: Hans Verkuil <hans.verkuil@cisco.com> 4255 M: Hans Verkuil <hans.verkuil@cisco.com>
4255 L: linux-media@vger.kernel.org 4256 L: linux-media@vger.kernel.org
4256 S: Maintained 4257 S: Maintained
4257 F: drivers/media/usb/go7007/ 4258 F: drivers/media/usb/go7007/
4258 4259
4259 GOODIX TOUCHSCREEN 4260 GOODIX TOUCHSCREEN
4260 M: Bastien Nocera <hadess@hadess.net> 4261 M: Bastien Nocera <hadess@hadess.net>
4261 L: linux-input@vger.kernel.org 4262 L: linux-input@vger.kernel.org
4262 S: Maintained 4263 S: Maintained
4263 F: drivers/input/touchscreen/goodix.c 4264 F: drivers/input/touchscreen/goodix.c
4264 4265
4265 GPIO SUBSYSTEM 4266 GPIO SUBSYSTEM
4266 M: Linus Walleij <linus.walleij@linaro.org> 4267 M: Linus Walleij <linus.walleij@linaro.org>
4267 M: Alexandre Courbot <gnurou@gmail.com> 4268 M: Alexandre Courbot <gnurou@gmail.com>
4268 L: linux-gpio@vger.kernel.org 4269 L: linux-gpio@vger.kernel.org
4269 T: git git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio.git 4270 T: git git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio.git
4270 S: Maintained 4271 S: Maintained
4271 F: Documentation/gpio/ 4272 F: Documentation/gpio/
4272 F: drivers/gpio/ 4273 F: drivers/gpio/
4273 F: include/linux/gpio/ 4274 F: include/linux/gpio/
4274 F: include/linux/gpio.h 4275 F: include/linux/gpio.h
4275 F: include/asm-generic/gpio.h 4276 F: include/asm-generic/gpio.h
4276 4277
4277 GRE DEMULTIPLEXER DRIVER 4278 GRE DEMULTIPLEXER DRIVER
4278 M: Dmitry Kozlov <xeb@mail.ru> 4279 M: Dmitry Kozlov <xeb@mail.ru>
4279 L: netdev@vger.kernel.org 4280 L: netdev@vger.kernel.org
4280 S: Maintained 4281 S: Maintained
4281 F: net/ipv4/gre_demux.c 4282 F: net/ipv4/gre_demux.c
4282 F: net/ipv4/gre_offload.c 4283 F: net/ipv4/gre_offload.c
4283 F: include/net/gre.h 4284 F: include/net/gre.h
4284 4285
4285 GRETH 10/100/1G Ethernet MAC device driver 4286 GRETH 10/100/1G Ethernet MAC device driver
4286 M: Kristoffer Glembo <kristoffer@gaisler.com> 4287 M: Kristoffer Glembo <kristoffer@gaisler.com>
4287 L: netdev@vger.kernel.org 4288 L: netdev@vger.kernel.org
4288 S: Maintained 4289 S: Maintained
4289 F: drivers/net/ethernet/aeroflex/ 4290 F: drivers/net/ethernet/aeroflex/
4290 4291
4291 GSPCA FINEPIX SUBDRIVER 4292 GSPCA FINEPIX SUBDRIVER
4292 M: Frank Zago <frank@zago.net> 4293 M: Frank Zago <frank@zago.net>
4293 L: linux-media@vger.kernel.org 4294 L: linux-media@vger.kernel.org
4294 T: git git://linuxtv.org/media_tree.git 4295 T: git git://linuxtv.org/media_tree.git
4295 S: Maintained 4296 S: Maintained
4296 F: drivers/media/usb/gspca/finepix.c 4297 F: drivers/media/usb/gspca/finepix.c
4297 4298
4298 GSPCA GL860 SUBDRIVER 4299 GSPCA GL860 SUBDRIVER
4299 M: Olivier Lorin <o.lorin@laposte.net> 4300 M: Olivier Lorin <o.lorin@laposte.net>
4300 L: linux-media@vger.kernel.org 4301 L: linux-media@vger.kernel.org
4301 T: git git://linuxtv.org/media_tree.git 4302 T: git git://linuxtv.org/media_tree.git
4302 S: Maintained 4303 S: Maintained
4303 F: drivers/media/usb/gspca/gl860/ 4304 F: drivers/media/usb/gspca/gl860/
4304 4305
4305 GSPCA M5602 SUBDRIVER 4306 GSPCA M5602 SUBDRIVER
4306 M: Erik Andren <erik.andren@gmail.com> 4307 M: Erik Andren <erik.andren@gmail.com>
4307 L: linux-media@vger.kernel.org 4308 L: linux-media@vger.kernel.org
4308 T: git git://linuxtv.org/media_tree.git 4309 T: git git://linuxtv.org/media_tree.git
4309 S: Maintained 4310 S: Maintained
4310 F: drivers/media/usb/gspca/m5602/ 4311 F: drivers/media/usb/gspca/m5602/
4311 4312
4312 GSPCA PAC207 SONIXB SUBDRIVER 4313 GSPCA PAC207 SONIXB SUBDRIVER
4313 M: Hans de Goede <hdegoede@redhat.com> 4314 M: Hans de Goede <hdegoede@redhat.com>
4314 L: linux-media@vger.kernel.org 4315 L: linux-media@vger.kernel.org
4315 T: git git://linuxtv.org/media_tree.git 4316 T: git git://linuxtv.org/media_tree.git
4316 S: Maintained 4317 S: Maintained
4317 F: drivers/media/usb/gspca/pac207.c 4318 F: drivers/media/usb/gspca/pac207.c
4318 4319
4319 GSPCA SN9C20X SUBDRIVER 4320 GSPCA SN9C20X SUBDRIVER
4320 M: Brian Johnson <brijohn@gmail.com> 4321 M: Brian Johnson <brijohn@gmail.com>
4321 L: linux-media@vger.kernel.org 4322 L: linux-media@vger.kernel.org
4322 T: git git://linuxtv.org/media_tree.git 4323 T: git git://linuxtv.org/media_tree.git
4323 S: Maintained 4324 S: Maintained
4324 F: drivers/media/usb/gspca/sn9c20x.c 4325 F: drivers/media/usb/gspca/sn9c20x.c
4325 4326
4326 GSPCA T613 SUBDRIVER 4327 GSPCA T613 SUBDRIVER
4327 M: Leandro Costantino <lcostantino@gmail.com> 4328 M: Leandro Costantino <lcostantino@gmail.com>
4328 L: linux-media@vger.kernel.org 4329 L: linux-media@vger.kernel.org
4329 T: git git://linuxtv.org/media_tree.git 4330 T: git git://linuxtv.org/media_tree.git
4330 S: Maintained 4331 S: Maintained
4331 F: drivers/media/usb/gspca/t613.c 4332 F: drivers/media/usb/gspca/t613.c
4332 4333
4333 GSPCA USB WEBCAM DRIVER 4334 GSPCA USB WEBCAM DRIVER
4334 M: Hans de Goede <hdegoede@redhat.com> 4335 M: Hans de Goede <hdegoede@redhat.com>
4335 L: linux-media@vger.kernel.org 4336 L: linux-media@vger.kernel.org
4336 T: git git://linuxtv.org/media_tree.git 4337 T: git git://linuxtv.org/media_tree.git
4337 S: Maintained 4338 S: Maintained
4338 F: drivers/media/usb/gspca/ 4339 F: drivers/media/usb/gspca/
4339 4340
4340 GUID PARTITION TABLE (GPT) 4341 GUID PARTITION TABLE (GPT)
4341 M: Davidlohr Bueso <davidlohr@hp.com> 4342 M: Davidlohr Bueso <davidlohr@hp.com>
4342 L: linux-efi@vger.kernel.org 4343 L: linux-efi@vger.kernel.org
4343 S: Maintained 4344 S: Maintained
4344 F: block/partitions/efi.* 4345 F: block/partitions/efi.*
4345 4346
4346 STK1160 USB VIDEO CAPTURE DRIVER 4347 STK1160 USB VIDEO CAPTURE DRIVER
4347 M: Ezequiel Garcia <elezegarcia@gmail.com> 4348 M: Ezequiel Garcia <elezegarcia@gmail.com>
4348 L: linux-media@vger.kernel.org 4349 L: linux-media@vger.kernel.org
4349 T: git git://linuxtv.org/media_tree.git 4350 T: git git://linuxtv.org/media_tree.git
4350 S: Maintained 4351 S: Maintained
4351 F: drivers/media/usb/stk1160/ 4352 F: drivers/media/usb/stk1160/
4352 4353
4353 HARD DRIVE ACTIVE PROTECTION SYSTEM (HDAPS) DRIVER 4354 HARD DRIVE ACTIVE PROTECTION SYSTEM (HDAPS) DRIVER
4354 M: Frank Seidel <frank@f-seidel.de> 4355 M: Frank Seidel <frank@f-seidel.de>
4355 L: platform-driver-x86@vger.kernel.org 4356 L: platform-driver-x86@vger.kernel.org
4356 W: http://www.kernel.org/pub/linux/kernel/people/fseidel/hdaps/ 4357 W: http://www.kernel.org/pub/linux/kernel/people/fseidel/hdaps/
4357 S: Maintained 4358 S: Maintained
4358 F: drivers/platform/x86/hdaps.c 4359 F: drivers/platform/x86/hdaps.c
4359 4360
4360 HDPVR USB VIDEO ENCODER DRIVER 4361 HDPVR USB VIDEO ENCODER DRIVER
4361 M: Hans Verkuil <hverkuil@xs4all.nl> 4362 M: Hans Verkuil <hverkuil@xs4all.nl>
4362 L: linux-media@vger.kernel.org 4363 L: linux-media@vger.kernel.org
4363 T: git git://linuxtv.org/media_tree.git 4364 T: git git://linuxtv.org/media_tree.git
4364 W: http://linuxtv.org 4365 W: http://linuxtv.org
4365 S: Odd Fixes 4366 S: Odd Fixes
4366 F: drivers/media/usb/hdpvr/ 4367 F: drivers/media/usb/hdpvr/
4367 4368
4368 HWPOISON MEMORY FAILURE HANDLING 4369 HWPOISON MEMORY FAILURE HANDLING
4369 M: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> 4370 M: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
4370 L: linux-mm@kvack.org 4371 L: linux-mm@kvack.org
4371 S: Maintained 4372 S: Maintained
4372 F: mm/memory-failure.c 4373 F: mm/memory-failure.c
4373 F: mm/hwpoison-inject.c 4374 F: mm/hwpoison-inject.c
4374 4375
4375 HYPERVISOR VIRTUAL CONSOLE DRIVER 4376 HYPERVISOR VIRTUAL CONSOLE DRIVER
4376 L: linuxppc-dev@lists.ozlabs.org 4377 L: linuxppc-dev@lists.ozlabs.org
4377 S: Odd Fixes 4378 S: Odd Fixes
4378 F: drivers/tty/hvc/ 4379 F: drivers/tty/hvc/
4379 4380
4380 HACKRF MEDIA DRIVER 4381 HACKRF MEDIA DRIVER
4381 M: Antti Palosaari <crope@iki.fi> 4382 M: Antti Palosaari <crope@iki.fi>
4382 L: linux-media@vger.kernel.org 4383 L: linux-media@vger.kernel.org
4383 W: http://linuxtv.org/ 4384 W: http://linuxtv.org/
4384 W: http://palosaari.fi/linux/ 4385 W: http://palosaari.fi/linux/
4385 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 4386 Q: http://patchwork.linuxtv.org/project/linux-media/list/
4386 T: git git://linuxtv.org/anttip/media_tree.git 4387 T: git git://linuxtv.org/anttip/media_tree.git
4387 S: Maintained 4388 S: Maintained
4388 F: drivers/media/usb/hackrf/ 4389 F: drivers/media/usb/hackrf/
4389 4390
4390 HARDWARE MONITORING 4391 HARDWARE MONITORING
4391 M: Jean Delvare <jdelvare@suse.de> 4392 M: Jean Delvare <jdelvare@suse.de>
4392 M: Guenter Roeck <linux@roeck-us.net> 4393 M: Guenter Roeck <linux@roeck-us.net>
4393 L: lm-sensors@lm-sensors.org 4394 L: lm-sensors@lm-sensors.org
4394 W: http://www.lm-sensors.org/ 4395 W: http://www.lm-sensors.org/
4395 T: quilt kernel.org/pub/linux/kernel/people/jdelvare/linux-2.6/jdelvare-hwmon/ 4396 T: quilt kernel.org/pub/linux/kernel/people/jdelvare/linux-2.6/jdelvare-hwmon/
4396 T: git git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git 4397 T: git git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git
4397 S: Maintained 4398 S: Maintained
4398 F: Documentation/hwmon/ 4399 F: Documentation/hwmon/
4399 F: drivers/hwmon/ 4400 F: drivers/hwmon/
4400 F: include/linux/hwmon*.h 4401 F: include/linux/hwmon*.h
4401 4402
4402 HARDWARE RANDOM NUMBER GENERATOR CORE 4403 HARDWARE RANDOM NUMBER GENERATOR CORE
4403 M: Matt Mackall <mpm@selenic.com> 4404 M: Matt Mackall <mpm@selenic.com>
4404 M: Herbert Xu <herbert@gondor.apana.org.au> 4405 M: Herbert Xu <herbert@gondor.apana.org.au>
4405 S: Odd fixes 4406 S: Odd fixes
4406 F: Documentation/hw_random.txt 4407 F: Documentation/hw_random.txt
4407 F: drivers/char/hw_random/ 4408 F: drivers/char/hw_random/
4408 F: include/linux/hw_random.h 4409 F: include/linux/hw_random.h
4409 4410
4410 HARDWARE SPINLOCK CORE 4411 HARDWARE SPINLOCK CORE
4411 M: Ohad Ben-Cohen <ohad@wizery.com> 4412 M: Ohad Ben-Cohen <ohad@wizery.com>
4412 S: Maintained 4413 S: Maintained
4413 F: Documentation/hwspinlock.txt 4414 F: Documentation/hwspinlock.txt
4414 F: drivers/hwspinlock/hwspinlock_* 4415 F: drivers/hwspinlock/hwspinlock_*
4415 F: include/linux/hwspinlock.h 4416 F: include/linux/hwspinlock.h
4416 4417
4417 HARMONY SOUND DRIVER 4418 HARMONY SOUND DRIVER
4418 L: linux-parisc@vger.kernel.org 4419 L: linux-parisc@vger.kernel.org
4419 S: Maintained 4420 S: Maintained
4420 F: sound/parisc/harmony.* 4421 F: sound/parisc/harmony.*
4421 4422
4422 HD29L2 MEDIA DRIVER 4423 HD29L2 MEDIA DRIVER
4423 M: Antti Palosaari <crope@iki.fi> 4424 M: Antti Palosaari <crope@iki.fi>
4424 L: linux-media@vger.kernel.org 4425 L: linux-media@vger.kernel.org
4425 W: http://linuxtv.org/ 4426 W: http://linuxtv.org/
4426 W: http://palosaari.fi/linux/ 4427 W: http://palosaari.fi/linux/
4427 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 4428 Q: http://patchwork.linuxtv.org/project/linux-media/list/
4428 T: git git://linuxtv.org/anttip/media_tree.git 4429 T: git git://linuxtv.org/anttip/media_tree.git
4429 S: Maintained 4430 S: Maintained
4430 F: drivers/media/dvb-frontends/hd29l2* 4431 F: drivers/media/dvb-frontends/hd29l2*
4431 4432
4432 HEWLETT-PACKARD SMART2 RAID DRIVER 4433 HEWLETT-PACKARD SMART2 RAID DRIVER
4433 L: iss_storagedev@hp.com 4434 L: iss_storagedev@hp.com
4434 S: Orphan 4435 S: Orphan
4435 F: Documentation/blockdev/cpqarray.txt 4436 F: Documentation/blockdev/cpqarray.txt
4436 F: drivers/block/cpqarray.* 4437 F: drivers/block/cpqarray.*
4437 4438
4438 HEWLETT-PACKARD SMART ARRAY RAID DRIVER (hpsa) 4439 HEWLETT-PACKARD SMART ARRAY RAID DRIVER (hpsa)
4439 M: Don Brace <don.brace@pmcs.com> 4440 M: Don Brace <don.brace@pmcs.com>
4440 L: iss_storagedev@hp.com 4441 L: iss_storagedev@hp.com
4441 L: storagedev@pmcs.com 4442 L: storagedev@pmcs.com
4442 L: linux-scsi@vger.kernel.org 4443 L: linux-scsi@vger.kernel.org
4443 S: Supported 4444 S: Supported
4444 F: Documentation/scsi/hpsa.txt 4445 F: Documentation/scsi/hpsa.txt
4445 F: drivers/scsi/hpsa*.[ch] 4446 F: drivers/scsi/hpsa*.[ch]
4446 F: include/linux/cciss*.h 4447 F: include/linux/cciss*.h
4447 F: include/uapi/linux/cciss*.h 4448 F: include/uapi/linux/cciss*.h
4448 4449
4449 HEWLETT-PACKARD SMART CISS RAID DRIVER (cciss) 4450 HEWLETT-PACKARD SMART CISS RAID DRIVER (cciss)
4450 M: Don Brace <don.brace@pmcs.com> 4451 M: Don Brace <don.brace@pmcs.com>
4451 L: iss_storagedev@hp.com 4452 L: iss_storagedev@hp.com
4452 L: storagedev@pmcs.com 4453 L: storagedev@pmcs.com
4453 L: linux-scsi@vger.kernel.org 4454 L: linux-scsi@vger.kernel.org
4454 S: Supported 4455 S: Supported
4455 F: Documentation/blockdev/cciss.txt 4456 F: Documentation/blockdev/cciss.txt
4456 F: drivers/block/cciss* 4457 F: drivers/block/cciss*
4457 F: include/linux/cciss_ioctl.h 4458 F: include/linux/cciss_ioctl.h
4458 F: include/uapi/linux/cciss_ioctl.h 4459 F: include/uapi/linux/cciss_ioctl.h
4459 4460
4460 HFS FILESYSTEM 4461 HFS FILESYSTEM
4461 L: linux-fsdevel@vger.kernel.org 4462 L: linux-fsdevel@vger.kernel.org
4462 S: Orphan 4463 S: Orphan
4463 F: Documentation/filesystems/hfs.txt 4464 F: Documentation/filesystems/hfs.txt
4464 F: fs/hfs/ 4465 F: fs/hfs/
4465 4466
4466 HFSPLUS FILESYSTEM 4467 HFSPLUS FILESYSTEM
4467 L: linux-fsdevel@vger.kernel.org 4468 L: linux-fsdevel@vger.kernel.org
4468 S: Orphan 4469 S: Orphan
4469 F: Documentation/filesystems/hfsplus.txt 4470 F: Documentation/filesystems/hfsplus.txt
4470 F: fs/hfsplus/ 4471 F: fs/hfsplus/
4471 4472
4472 HGA FRAMEBUFFER DRIVER 4473 HGA FRAMEBUFFER DRIVER
4473 M: Ferenc Bakonyi <fero@drama.obuda.kando.hu> 4474 M: Ferenc Bakonyi <fero@drama.obuda.kando.hu>
4474 L: linux-nvidia@lists.surfsouth.com 4475 L: linux-nvidia@lists.surfsouth.com
4475 W: http://drama.obuda.kando.hu/~fero/cgi-bin/hgafb.shtml 4476 W: http://drama.obuda.kando.hu/~fero/cgi-bin/hgafb.shtml
4476 S: Maintained 4477 S: Maintained
4477 F: drivers/video/fbdev/hgafb.c 4478 F: drivers/video/fbdev/hgafb.c
4478 4479
4479 HIBERNATION (aka Software Suspend, aka swsusp) 4480 HIBERNATION (aka Software Suspend, aka swsusp)
4480 M: "Rafael J. Wysocki" <rjw@rjwysocki.net> 4481 M: "Rafael J. Wysocki" <rjw@rjwysocki.net>
4481 M: Pavel Machek <pavel@ucw.cz> 4482 M: Pavel Machek <pavel@ucw.cz>
4482 L: linux-pm@vger.kernel.org 4483 L: linux-pm@vger.kernel.org
4483 S: Supported 4484 S: Supported
4484 F: arch/x86/power/ 4485 F: arch/x86/power/
4485 F: drivers/base/power/ 4486 F: drivers/base/power/
4486 F: kernel/power/ 4487 F: kernel/power/
4487 F: include/linux/suspend.h 4488 F: include/linux/suspend.h
4488 F: include/linux/freezer.h 4489 F: include/linux/freezer.h
4489 F: include/linux/pm.h 4490 F: include/linux/pm.h
4490 F: arch/*/include/asm/suspend*.h 4491 F: arch/*/include/asm/suspend*.h
4491 4492
4492 HID CORE LAYER 4493 HID CORE LAYER
4493 M: Jiri Kosina <jkosina@suse.cz> 4494 M: Jiri Kosina <jkosina@suse.cz>
4494 L: linux-input@vger.kernel.org 4495 L: linux-input@vger.kernel.org
4495 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid.git 4496 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid.git
4496 S: Maintained 4497 S: Maintained
4497 F: drivers/hid/ 4498 F: drivers/hid/
4498 F: include/linux/hid* 4499 F: include/linux/hid*
4499 F: include/uapi/linux/hid* 4500 F: include/uapi/linux/hid*
4500 4501
4501 HIGH-RESOLUTION TIMERS, CLOCKEVENTS, DYNTICKS 4502 HIGH-RESOLUTION TIMERS, CLOCKEVENTS, DYNTICKS
4502 M: Thomas Gleixner <tglx@linutronix.de> 4503 M: Thomas Gleixner <tglx@linutronix.de>
4503 L: linux-kernel@vger.kernel.org 4504 L: linux-kernel@vger.kernel.org
4504 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git timers/core 4505 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git timers/core
4505 S: Maintained 4506 S: Maintained
4506 F: Documentation/timers/ 4507 F: Documentation/timers/
4507 F: kernel/time/hrtimer.c 4508 F: kernel/time/hrtimer.c
4508 F: kernel/time/clockevents.c 4509 F: kernel/time/clockevents.c
4509 F: kernel/time/tick*.* 4510 F: kernel/time/tick*.*
4510 F: kernel/time/timer_*.c 4511 F: kernel/time/timer_*.c
4511 F: include/linux/clockchips.h 4512 F: include/linux/clockchips.h
4512 F: include/linux/hrtimer.h 4513 F: include/linux/hrtimer.h
4513 4514
4514 HIGH-SPEED SCC DRIVER FOR AX.25 4515 HIGH-SPEED SCC DRIVER FOR AX.25
4515 L: linux-hams@vger.kernel.org 4516 L: linux-hams@vger.kernel.org
4516 S: Orphan 4517 S: Orphan
4517 F: drivers/net/hamradio/dmascc.c 4518 F: drivers/net/hamradio/dmascc.c
4518 F: drivers/net/hamradio/scc.c 4519 F: drivers/net/hamradio/scc.c
4519 4520
4520 HIGHPOINT ROCKETRAID 3xxx RAID DRIVER 4521 HIGHPOINT ROCKETRAID 3xxx RAID DRIVER
4521 M: HighPoint Linux Team <linux@highpoint-tech.com> 4522 M: HighPoint Linux Team <linux@highpoint-tech.com>
4522 W: http://www.highpoint-tech.com 4523 W: http://www.highpoint-tech.com
4523 S: Supported 4524 S: Supported
4524 F: Documentation/scsi/hptiop.txt 4525 F: Documentation/scsi/hptiop.txt
4525 F: drivers/scsi/hptiop.c 4526 F: drivers/scsi/hptiop.c
4526 4527
4527 HIPPI 4528 HIPPI
4528 M: Jes Sorensen <jes@trained-monkey.org> 4529 M: Jes Sorensen <jes@trained-monkey.org>
4529 L: linux-hippi@sunsite.dk 4530 L: linux-hippi@sunsite.dk
4530 S: Maintained 4531 S: Maintained
4531 F: include/linux/hippidevice.h 4532 F: include/linux/hippidevice.h
4532 F: include/uapi/linux/if_hippi.h 4533 F: include/uapi/linux/if_hippi.h
4533 F: net/802/hippi.c 4534 F: net/802/hippi.c
4534 F: drivers/net/hippi/ 4535 F: drivers/net/hippi/
4535 4536
4536 HOST AP DRIVER 4537 HOST AP DRIVER
4537 M: Jouni Malinen <j@w1.fi> 4538 M: Jouni Malinen <j@w1.fi>
4538 L: hostap@shmoo.com (subscribers-only) 4539 L: hostap@shmoo.com (subscribers-only)
4539 L: linux-wireless@vger.kernel.org 4540 L: linux-wireless@vger.kernel.org
4540 W: http://hostap.epitest.fi/ 4541 W: http://hostap.epitest.fi/
4541 S: Maintained 4542 S: Maintained
4542 F: drivers/net/wireless/hostap/ 4543 F: drivers/net/wireless/hostap/
4543 4544
4544 HP COMPAQ TC1100 TABLET WMI EXTRAS DRIVER 4545 HP COMPAQ TC1100 TABLET WMI EXTRAS DRIVER
4545 L: platform-driver-x86@vger.kernel.org 4546 L: platform-driver-x86@vger.kernel.org
4546 S: Orphan 4547 S: Orphan
4547 F: drivers/platform/x86/tc1100-wmi.c 4548 F: drivers/platform/x86/tc1100-wmi.c
4548 4549
4549 HP100: Driver for HP 10/100 Mbit/s Voice Grade Network Adapter Series 4550 HP100: Driver for HP 10/100 Mbit/s Voice Grade Network Adapter Series
4550 M: Jaroslav Kysela <perex@perex.cz> 4551 M: Jaroslav Kysela <perex@perex.cz>
4551 S: Maintained 4552 S: Maintained
4552 F: drivers/net/ethernet/hp/hp100.* 4553 F: drivers/net/ethernet/hp/hp100.*
4553 4554
4554 HPET: High Precision Event Timers driver 4555 HPET: High Precision Event Timers driver
4555 M: Clemens Ladisch <clemens@ladisch.de> 4556 M: Clemens Ladisch <clemens@ladisch.de>
4556 S: Maintained 4557 S: Maintained
4557 F: Documentation/timers/hpet.txt 4558 F: Documentation/timers/hpet.txt
4558 F: drivers/char/hpet.c 4559 F: drivers/char/hpet.c
4559 F: include/linux/hpet.h 4560 F: include/linux/hpet.h
4560 F: include/uapi/linux/hpet.h 4561 F: include/uapi/linux/hpet.h
4561 4562
4562 HPET: x86 4563 HPET: x86
4563 S: Orphan 4564 S: Orphan
4564 F: arch/x86/kernel/hpet.c 4565 F: arch/x86/kernel/hpet.c
4565 F: arch/x86/include/asm/hpet.h 4566 F: arch/x86/include/asm/hpet.h
4566 4567
4567 HPFS FILESYSTEM 4568 HPFS FILESYSTEM
4568 M: Mikulas Patocka <mikulas@artax.karlin.mff.cuni.cz> 4569 M: Mikulas Patocka <mikulas@artax.karlin.mff.cuni.cz>
4569 W: http://artax.karlin.mff.cuni.cz/~mikulas/vyplody/hpfs/index-e.cgi 4570 W: http://artax.karlin.mff.cuni.cz/~mikulas/vyplody/hpfs/index-e.cgi
4570 S: Maintained 4571 S: Maintained
4571 F: fs/hpfs/ 4572 F: fs/hpfs/
4572 4573
4573 HSI SUBSYSTEM 4574 HSI SUBSYSTEM
4574 M: Sebastian Reichel <sre@kernel.org> 4575 M: Sebastian Reichel <sre@kernel.org>
4575 T: git git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-hsi.git 4576 T: git git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-hsi.git
4576 S: Maintained 4577 S: Maintained
4577 F: Documentation/ABI/testing/sysfs-bus-hsi 4578 F: Documentation/ABI/testing/sysfs-bus-hsi
4578 F: Documentation/hsi.txt 4579 F: Documentation/hsi.txt
4579 F: drivers/hsi/ 4580 F: drivers/hsi/
4580 F: include/linux/hsi/ 4581 F: include/linux/hsi/
4581 F: include/uapi/linux/hsi/ 4582 F: include/uapi/linux/hsi/
4582 4583
4583 HSO 3G MODEM DRIVER 4584 HSO 3G MODEM DRIVER
4584 M: Jan Dumon <j.dumon@option.com> 4585 M: Jan Dumon <j.dumon@option.com>
4585 W: http://www.pharscape.org 4586 W: http://www.pharscape.org
4586 S: Maintained 4587 S: Maintained
4587 F: drivers/net/usb/hso.c 4588 F: drivers/net/usb/hso.c
4588 4589
4589 HSR NETWORK PROTOCOL 4590 HSR NETWORK PROTOCOL
4590 M: Arvid Brodin <arvid.brodin@alten.se> 4591 M: Arvid Brodin <arvid.brodin@alten.se>
4591 L: netdev@vger.kernel.org 4592 L: netdev@vger.kernel.org
4592 S: Maintained 4593 S: Maintained
4593 F: net/hsr/ 4594 F: net/hsr/
4594 4595
4595 HTCPEN TOUCHSCREEN DRIVER 4596 HTCPEN TOUCHSCREEN DRIVER
4596 M: Pau Oliva Fora <pof@eslack.org> 4597 M: Pau Oliva Fora <pof@eslack.org>
4597 L: linux-input@vger.kernel.org 4598 L: linux-input@vger.kernel.org
4598 S: Maintained 4599 S: Maintained
4599 F: drivers/input/touchscreen/htcpen.c 4600 F: drivers/input/touchscreen/htcpen.c
4600 4601
4601 HUGETLB FILESYSTEM 4602 HUGETLB FILESYSTEM
4602 M: Nadia Yvette Chambers <nyc@holomorphy.com> 4603 M: Nadia Yvette Chambers <nyc@holomorphy.com>
4603 S: Maintained 4604 S: Maintained
4604 F: fs/hugetlbfs/ 4605 F: fs/hugetlbfs/
4605 4606
4606 Hyper-V CORE AND DRIVERS 4607 Hyper-V CORE AND DRIVERS
4607 M: K. Y. Srinivasan <kys@microsoft.com> 4608 M: K. Y. Srinivasan <kys@microsoft.com>
4608 M: Haiyang Zhang <haiyangz@microsoft.com> 4609 M: Haiyang Zhang <haiyangz@microsoft.com>
4609 L: devel@linuxdriverproject.org 4610 L: devel@linuxdriverproject.org
4610 S: Maintained 4611 S: Maintained
4611 F: arch/x86/include/asm/mshyperv.h 4612 F: arch/x86/include/asm/mshyperv.h
4612 F: arch/x86/include/uapi/asm/hyperv.h 4613 F: arch/x86/include/uapi/asm/hyperv.h
4613 F: arch/x86/kernel/cpu/mshyperv.c 4614 F: arch/x86/kernel/cpu/mshyperv.c
4614 F: drivers/hid/hid-hyperv.c 4615 F: drivers/hid/hid-hyperv.c
4615 F: drivers/hv/ 4616 F: drivers/hv/
4616 F: drivers/input/serio/hyperv-keyboard.c 4617 F: drivers/input/serio/hyperv-keyboard.c
4617 F: drivers/net/hyperv/ 4618 F: drivers/net/hyperv/
4618 F: drivers/scsi/storvsc_drv.c 4619 F: drivers/scsi/storvsc_drv.c
4619 F: drivers/video/fbdev/hyperv_fb.c 4620 F: drivers/video/fbdev/hyperv_fb.c
4620 F: include/linux/hyperv.h 4621 F: include/linux/hyperv.h
4621 F: tools/hv/ 4622 F: tools/hv/
4622 4623
4623 I2C OVER PARALLEL PORT 4624 I2C OVER PARALLEL PORT
4624 M: Jean Delvare <jdelvare@suse.de> 4625 M: Jean Delvare <jdelvare@suse.de>
4625 L: linux-i2c@vger.kernel.org 4626 L: linux-i2c@vger.kernel.org
4626 S: Maintained 4627 S: Maintained
4627 F: Documentation/i2c/busses/i2c-parport 4628 F: Documentation/i2c/busses/i2c-parport
4628 F: Documentation/i2c/busses/i2c-parport-light 4629 F: Documentation/i2c/busses/i2c-parport-light
4629 F: drivers/i2c/busses/i2c-parport.c 4630 F: drivers/i2c/busses/i2c-parport.c
4630 F: drivers/i2c/busses/i2c-parport-light.c 4631 F: drivers/i2c/busses/i2c-parport-light.c
4631 4632
4632 I2C/SMBUS CONTROLLER DRIVERS FOR PC 4633 I2C/SMBUS CONTROLLER DRIVERS FOR PC
4633 M: Jean Delvare <jdelvare@suse.de> 4634 M: Jean Delvare <jdelvare@suse.de>
4634 L: linux-i2c@vger.kernel.org 4635 L: linux-i2c@vger.kernel.org
4635 S: Maintained 4636 S: Maintained
4636 F: Documentation/i2c/busses/i2c-ali1535 4637 F: Documentation/i2c/busses/i2c-ali1535
4637 F: Documentation/i2c/busses/i2c-ali1563 4638 F: Documentation/i2c/busses/i2c-ali1563
4638 F: Documentation/i2c/busses/i2c-ali15x3 4639 F: Documentation/i2c/busses/i2c-ali15x3
4639 F: Documentation/i2c/busses/i2c-amd756 4640 F: Documentation/i2c/busses/i2c-amd756
4640 F: Documentation/i2c/busses/i2c-amd8111 4641 F: Documentation/i2c/busses/i2c-amd8111
4641 F: Documentation/i2c/busses/i2c-i801 4642 F: Documentation/i2c/busses/i2c-i801
4642 F: Documentation/i2c/busses/i2c-nforce2 4643 F: Documentation/i2c/busses/i2c-nforce2
4643 F: Documentation/i2c/busses/i2c-piix4 4644 F: Documentation/i2c/busses/i2c-piix4
4644 F: Documentation/i2c/busses/i2c-sis5595 4645 F: Documentation/i2c/busses/i2c-sis5595
4645 F: Documentation/i2c/busses/i2c-sis630 4646 F: Documentation/i2c/busses/i2c-sis630
4646 F: Documentation/i2c/busses/i2c-sis96x 4647 F: Documentation/i2c/busses/i2c-sis96x
4647 F: Documentation/i2c/busses/i2c-via 4648 F: Documentation/i2c/busses/i2c-via
4648 F: Documentation/i2c/busses/i2c-viapro 4649 F: Documentation/i2c/busses/i2c-viapro
4649 F: drivers/i2c/busses/i2c-ali1535.c 4650 F: drivers/i2c/busses/i2c-ali1535.c
4650 F: drivers/i2c/busses/i2c-ali1563.c 4651 F: drivers/i2c/busses/i2c-ali1563.c
4651 F: drivers/i2c/busses/i2c-ali15x3.c 4652 F: drivers/i2c/busses/i2c-ali15x3.c
4652 F: drivers/i2c/busses/i2c-amd756.c 4653 F: drivers/i2c/busses/i2c-amd756.c
4653 F: drivers/i2c/busses/i2c-amd756-s4882.c 4654 F: drivers/i2c/busses/i2c-amd756-s4882.c
4654 F: drivers/i2c/busses/i2c-amd8111.c 4655 F: drivers/i2c/busses/i2c-amd8111.c
4655 F: drivers/i2c/busses/i2c-i801.c 4656 F: drivers/i2c/busses/i2c-i801.c
4656 F: drivers/i2c/busses/i2c-isch.c 4657 F: drivers/i2c/busses/i2c-isch.c
4657 F: drivers/i2c/busses/i2c-nforce2.c 4658 F: drivers/i2c/busses/i2c-nforce2.c
4658 F: drivers/i2c/busses/i2c-nforce2-s4985.c 4659 F: drivers/i2c/busses/i2c-nforce2-s4985.c
4659 F: drivers/i2c/busses/i2c-piix4.c 4660 F: drivers/i2c/busses/i2c-piix4.c
4660 F: drivers/i2c/busses/i2c-sis5595.c 4661 F: drivers/i2c/busses/i2c-sis5595.c
4661 F: drivers/i2c/busses/i2c-sis630.c 4662 F: drivers/i2c/busses/i2c-sis630.c
4662 F: drivers/i2c/busses/i2c-sis96x.c 4663 F: drivers/i2c/busses/i2c-sis96x.c
4663 F: drivers/i2c/busses/i2c-via.c 4664 F: drivers/i2c/busses/i2c-via.c
4664 F: drivers/i2c/busses/i2c-viapro.c 4665 F: drivers/i2c/busses/i2c-viapro.c
4665 4666
4666 I2C/SMBUS ISMT DRIVER 4667 I2C/SMBUS ISMT DRIVER
4667 M: Seth Heasley <seth.heasley@intel.com> 4668 M: Seth Heasley <seth.heasley@intel.com>
4668 M: Neil Horman <nhorman@tuxdriver.com> 4669 M: Neil Horman <nhorman@tuxdriver.com>
4669 L: linux-i2c@vger.kernel.org 4670 L: linux-i2c@vger.kernel.org
4670 F: drivers/i2c/busses/i2c-ismt.c 4671 F: drivers/i2c/busses/i2c-ismt.c
4671 F: Documentation/i2c/busses/i2c-ismt 4672 F: Documentation/i2c/busses/i2c-ismt
4672 4673
4673 I2C/SMBUS STUB DRIVER 4674 I2C/SMBUS STUB DRIVER
4674 M: Jean Delvare <jdelvare@suse.de> 4675 M: Jean Delvare <jdelvare@suse.de>
4675 L: linux-i2c@vger.kernel.org 4676 L: linux-i2c@vger.kernel.org
4676 S: Maintained 4677 S: Maintained
4677 F: drivers/i2c/i2c-stub.c 4678 F: drivers/i2c/i2c-stub.c
4678 4679
4679 I2C SUBSYSTEM 4680 I2C SUBSYSTEM
4680 M: Wolfram Sang <wsa@the-dreams.de> 4681 M: Wolfram Sang <wsa@the-dreams.de>
4681 L: linux-i2c@vger.kernel.org 4682 L: linux-i2c@vger.kernel.org
4682 W: https://i2c.wiki.kernel.org/ 4683 W: https://i2c.wiki.kernel.org/
4683 Q: https://patchwork.ozlabs.org/project/linux-i2c/list/ 4684 Q: https://patchwork.ozlabs.org/project/linux-i2c/list/
4684 T: git git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git 4685 T: git git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git
4685 S: Maintained 4686 S: Maintained
4686 F: Documentation/devicetree/bindings/i2c/ 4687 F: Documentation/devicetree/bindings/i2c/
4687 F: Documentation/i2c/ 4688 F: Documentation/i2c/
4688 F: drivers/i2c/ 4689 F: drivers/i2c/
4689 F: include/linux/i2c.h 4690 F: include/linux/i2c.h
4690 F: include/linux/i2c-*.h 4691 F: include/linux/i2c-*.h
4691 F: include/uapi/linux/i2c.h 4692 F: include/uapi/linux/i2c.h
4692 F: include/uapi/linux/i2c-*.h 4693 F: include/uapi/linux/i2c-*.h
4693 4694
4694 I2C ACPI SUPPORT 4695 I2C ACPI SUPPORT
4695 M: Mika Westerberg <mika.westerberg@linux.intel.com> 4696 M: Mika Westerberg <mika.westerberg@linux.intel.com>
4696 L: linux-i2c@vger.kernel.org 4697 L: linux-i2c@vger.kernel.org
4697 L: linux-acpi@vger.kernel.org 4698 L: linux-acpi@vger.kernel.org
4698 S: Maintained 4699 S: Maintained
4699 4700
4700 I2C-TAOS-EVM DRIVER 4701 I2C-TAOS-EVM DRIVER
4701 M: Jean Delvare <jdelvare@suse.de> 4702 M: Jean Delvare <jdelvare@suse.de>
4702 L: linux-i2c@vger.kernel.org 4703 L: linux-i2c@vger.kernel.org
4703 S: Maintained 4704 S: Maintained
4704 F: Documentation/i2c/busses/i2c-taos-evm 4705 F: Documentation/i2c/busses/i2c-taos-evm
4705 F: drivers/i2c/busses/i2c-taos-evm.c 4706 F: drivers/i2c/busses/i2c-taos-evm.c
4706 4707
4707 I2C-TINY-USB DRIVER 4708 I2C-TINY-USB DRIVER
4708 M: Till Harbaum <till@harbaum.org> 4709 M: Till Harbaum <till@harbaum.org>
4709 L: linux-i2c@vger.kernel.org 4710 L: linux-i2c@vger.kernel.org
4710 W: http://www.harbaum.org/till/i2c_tiny_usb 4711 W: http://www.harbaum.org/till/i2c_tiny_usb
4711 S: Maintained 4712 S: Maintained
4712 F: drivers/i2c/busses/i2c-tiny-usb.c 4713 F: drivers/i2c/busses/i2c-tiny-usb.c
4713 4714
4714 i386 BOOT CODE 4715 i386 BOOT CODE
4715 M: "H. Peter Anvin" <hpa@zytor.com> 4716 M: "H. Peter Anvin" <hpa@zytor.com>
4716 S: Maintained 4717 S: Maintained
4717 F: arch/x86/boot/ 4718 F: arch/x86/boot/
4718 4719
4719 i386 SETUP CODE / CPU ERRATA WORKAROUNDS 4720 i386 SETUP CODE / CPU ERRATA WORKAROUNDS
4720 M: "H. Peter Anvin" <hpa@zytor.com> 4721 M: "H. Peter Anvin" <hpa@zytor.com>
4721 T: git git://git.kernel.org/pub/scm/linux/kernel/git/hpa/linux-2.6-x86setup.git 4722 T: git git://git.kernel.org/pub/scm/linux/kernel/git/hpa/linux-2.6-x86setup.git
4722 S: Maintained 4723 S: Maintained
4723 4724
4724 IA64 (Itanium) PLATFORM 4725 IA64 (Itanium) PLATFORM
4725 M: Tony Luck <tony.luck@intel.com> 4726 M: Tony Luck <tony.luck@intel.com>
4726 M: Fenghua Yu <fenghua.yu@intel.com> 4727 M: Fenghua Yu <fenghua.yu@intel.com>
4727 L: linux-ia64@vger.kernel.org 4728 L: linux-ia64@vger.kernel.org
4728 T: git git://git.kernel.org/pub/scm/linux/kernel/git/aegl/linux.git 4729 T: git git://git.kernel.org/pub/scm/linux/kernel/git/aegl/linux.git
4729 S: Maintained 4730 S: Maintained
4730 F: arch/ia64/ 4731 F: arch/ia64/
4731 4732
4732 IBM Power in-Nest Crypto Acceleration 4733 IBM Power in-Nest Crypto Acceleration
4733 M: Marcelo Henrique Cerri <mhcerri@linux.vnet.ibm.com> 4734 M: Marcelo Henrique Cerri <mhcerri@linux.vnet.ibm.com>
4734 M: Fionnuala Gunter <fin@linux.vnet.ibm.com> 4735 M: Fionnuala Gunter <fin@linux.vnet.ibm.com>
4735 L: linux-crypto@vger.kernel.org 4736 L: linux-crypto@vger.kernel.org
4736 S: Supported 4737 S: Supported
4737 F: drivers/crypto/nx/ 4738 F: drivers/crypto/nx/
4738 4739
4739 IBM Power 842 compression accelerator 4740 IBM Power 842 compression accelerator
4740 M: Dan Streetman <ddstreet@us.ibm.com> 4741 M: Dan Streetman <ddstreet@us.ibm.com>
4741 S: Supported 4742 S: Supported
4742 F: drivers/crypto/nx/nx-842.c 4743 F: drivers/crypto/nx/nx-842.c
4743 F: include/linux/nx842.h 4744 F: include/linux/nx842.h
4744 4745
4745 IBM Power Linux RAID adapter 4746 IBM Power Linux RAID adapter
4746 M: Brian King <brking@us.ibm.com> 4747 M: Brian King <brking@us.ibm.com>
4747 S: Supported 4748 S: Supported
4748 F: drivers/scsi/ipr.* 4749 F: drivers/scsi/ipr.*
4749 4750
4750 IBM Power Virtual Ethernet Device Driver 4751 IBM Power Virtual Ethernet Device Driver
4751 M: Santiago Leon <santil@linux.vnet.ibm.com> 4752 M: Santiago Leon <santil@linux.vnet.ibm.com>
4752 L: netdev@vger.kernel.org 4753 L: netdev@vger.kernel.org
4753 S: Supported 4754 S: Supported
4754 F: drivers/net/ethernet/ibm/ibmveth.* 4755 F: drivers/net/ethernet/ibm/ibmveth.*
4755 4756
4756 IBM Power Virtual SCSI Device Drivers 4757 IBM Power Virtual SCSI Device Drivers
4757 M: Nathan Fontenot <nfont@linux.vnet.ibm.com> 4758 M: Nathan Fontenot <nfont@linux.vnet.ibm.com>
4758 L: linux-scsi@vger.kernel.org 4759 L: linux-scsi@vger.kernel.org
4759 S: Supported 4760 S: Supported
4760 F: drivers/scsi/ibmvscsi/ibmvscsi* 4761 F: drivers/scsi/ibmvscsi/ibmvscsi*
4761 F: drivers/scsi/ibmvscsi/viosrp.h 4762 F: drivers/scsi/ibmvscsi/viosrp.h
4762 4763
4763 IBM Power Virtual FC Device Drivers 4764 IBM Power Virtual FC Device Drivers
4764 M: Brian King <brking@linux.vnet.ibm.com> 4765 M: Brian King <brking@linux.vnet.ibm.com>
4765 L: linux-scsi@vger.kernel.org 4766 L: linux-scsi@vger.kernel.org
4766 S: Supported 4767 S: Supported
4767 F: drivers/scsi/ibmvscsi/ibmvfc* 4768 F: drivers/scsi/ibmvscsi/ibmvfc*
4768 4769
4769 IBM ServeRAID RAID DRIVER 4770 IBM ServeRAID RAID DRIVER
4770 S: Orphan 4771 S: Orphan
4771 F: drivers/scsi/ips.* 4772 F: drivers/scsi/ips.*
4772 4773
4773 ICH LPC AND GPIO DRIVER 4774 ICH LPC AND GPIO DRIVER
4774 M: Peter Tyser <ptyser@xes-inc.com> 4775 M: Peter Tyser <ptyser@xes-inc.com>
4775 S: Maintained 4776 S: Maintained
4776 F: drivers/mfd/lpc_ich.c 4777 F: drivers/mfd/lpc_ich.c
4777 F: drivers/gpio/gpio-ich.c 4778 F: drivers/gpio/gpio-ich.c
4778 4779
4779 IDE SUBSYSTEM 4780 IDE SUBSYSTEM
4780 M: "David S. Miller" <davem@davemloft.net> 4781 M: "David S. Miller" <davem@davemloft.net>
4781 L: linux-ide@vger.kernel.org 4782 L: linux-ide@vger.kernel.org
4782 Q: http://patchwork.ozlabs.org/project/linux-ide/list/ 4783 Q: http://patchwork.ozlabs.org/project/linux-ide/list/
4783 T: git git://git.kernel.org/pub/scm/linux/kernel/git/davem/ide.git 4784 T: git git://git.kernel.org/pub/scm/linux/kernel/git/davem/ide.git
4784 S: Maintained 4785 S: Maintained
4785 F: Documentation/ide/ 4786 F: Documentation/ide/
4786 F: drivers/ide/ 4787 F: drivers/ide/
4787 F: include/linux/ide.h 4788 F: include/linux/ide.h
4788 4789
4789 IDEAPAD LAPTOP EXTRAS DRIVER 4790 IDEAPAD LAPTOP EXTRAS DRIVER
4790 M: Ike Panhc <ike.pan@canonical.com> 4791 M: Ike Panhc <ike.pan@canonical.com>
4791 L: platform-driver-x86@vger.kernel.org 4792 L: platform-driver-x86@vger.kernel.org
4792 W: http://launchpad.net/ideapad-laptop 4793 W: http://launchpad.net/ideapad-laptop
4793 S: Maintained 4794 S: Maintained
4794 F: drivers/platform/x86/ideapad-laptop.c 4795 F: drivers/platform/x86/ideapad-laptop.c
4795 4796
4796 IDEAPAD LAPTOP SLIDEBAR DRIVER 4797 IDEAPAD LAPTOP SLIDEBAR DRIVER
4797 M: Andrey Moiseev <o2g.org.ru@gmail.com> 4798 M: Andrey Moiseev <o2g.org.ru@gmail.com>
4798 L: linux-input@vger.kernel.org 4799 L: linux-input@vger.kernel.org
4799 W: https://github.com/o2genum/ideapad-slidebar 4800 W: https://github.com/o2genum/ideapad-slidebar
4800 S: Maintained 4801 S: Maintained
4801 F: drivers/input/misc/ideapad_slidebar.c 4802 F: drivers/input/misc/ideapad_slidebar.c
4802 4803
4803 IDE/ATAPI DRIVERS 4804 IDE/ATAPI DRIVERS
4804 M: Borislav Petkov <bp@alien8.de> 4805 M: Borislav Petkov <bp@alien8.de>
4805 L: linux-ide@vger.kernel.org 4806 L: linux-ide@vger.kernel.org
4806 S: Maintained 4807 S: Maintained
4807 F: Documentation/cdrom/ide-cd 4808 F: Documentation/cdrom/ide-cd
4808 F: drivers/ide/ide-cd* 4809 F: drivers/ide/ide-cd*
4809 4810
4810 IDLE-I7300 4811 IDLE-I7300
4811 M: Andy Henroid <andrew.d.henroid@intel.com> 4812 M: Andy Henroid <andrew.d.henroid@intel.com>
4812 L: linux-pm@vger.kernel.org 4813 L: linux-pm@vger.kernel.org
4813 S: Supported 4814 S: Supported
4814 F: drivers/idle/i7300_idle.c 4815 F: drivers/idle/i7300_idle.c
4815 4816
4816 IEEE 802.15.4 SUBSYSTEM 4817 IEEE 802.15.4 SUBSYSTEM
4817 M: Alexander Aring <alex.aring@gmail.com> 4818 M: Alexander Aring <alex.aring@gmail.com>
4818 L: linux-wpan@vger.kernel.org 4819 L: linux-wpan@vger.kernel.org
4819 W: https://github.com/linux-wpan 4820 W: https://github.com/linux-wpan
4820 T: git git://github.com/linux-wpan/linux-wpan-next.git 4821 T: git git://github.com/linux-wpan/linux-wpan-next.git
4821 S: Maintained 4822 S: Maintained
4822 F: net/ieee802154/ 4823 F: net/ieee802154/
4823 F: net/mac802154/ 4824 F: net/mac802154/
4824 F: drivers/net/ieee802154/ 4825 F: drivers/net/ieee802154/
4825 F: include/linux/nl802154.h 4826 F: include/linux/nl802154.h
4826 F: include/linux/ieee802154.h 4827 F: include/linux/ieee802154.h
4827 F: include/net/nl802154.h 4828 F: include/net/nl802154.h
4828 F: include/net/mac802154.h 4829 F: include/net/mac802154.h
4829 F: include/net/af_ieee802154.h 4830 F: include/net/af_ieee802154.h
4830 F: include/net/cfg802154.h 4831 F: include/net/cfg802154.h
4831 F: include/net/ieee802154_netdev.h 4832 F: include/net/ieee802154_netdev.h
4832 F: Documentation/networking/ieee802154.txt 4833 F: Documentation/networking/ieee802154.txt
4833 4834
4834 IGORPLUG-USB IR RECEIVER 4835 IGORPLUG-USB IR RECEIVER
4835 M: Sean Young <sean@mess.org> 4836 M: Sean Young <sean@mess.org>
4836 L: linux-media@vger.kernel.org 4837 L: linux-media@vger.kernel.org
4837 S: Maintained 4838 S: Maintained
4838 F: drivers/media/rc/igorplugusb.c 4839 F: drivers/media/rc/igorplugusb.c
4839 4840
4840 IGUANAWORKS USB IR TRANSCEIVER 4841 IGUANAWORKS USB IR TRANSCEIVER
4841 M: Sean Young <sean@mess.org> 4842 M: Sean Young <sean@mess.org>
4842 L: linux-media@vger.kernel.org 4843 L: linux-media@vger.kernel.org
4843 S: Maintained 4844 S: Maintained
4844 F: drivers/media/rc/iguanair.c 4845 F: drivers/media/rc/iguanair.c
4845 4846
4846 IIO SUBSYSTEM AND DRIVERS 4847 IIO SUBSYSTEM AND DRIVERS
4847 M: Jonathan Cameron <jic23@kernel.org> 4848 M: Jonathan Cameron <jic23@kernel.org>
4848 R: Hartmut Knaack <knaack.h@gmx.de> 4849 R: Hartmut Knaack <knaack.h@gmx.de>
4849 R: Lars-Peter Clausen <lars@metafoo.de> 4850 R: Lars-Peter Clausen <lars@metafoo.de>
4850 R: Peter Meerwald <pmeerw@pmeerw.net> 4851 R: Peter Meerwald <pmeerw@pmeerw.net>
4851 L: linux-iio@vger.kernel.org 4852 L: linux-iio@vger.kernel.org
4852 S: Maintained 4853 S: Maintained
4853 F: drivers/iio/ 4854 F: drivers/iio/
4854 F: drivers/staging/iio/ 4855 F: drivers/staging/iio/
4855 F: include/linux/iio/ 4856 F: include/linux/iio/
4856 4857
4857 IKANOS/ADI EAGLE ADSL USB DRIVER 4858 IKANOS/ADI EAGLE ADSL USB DRIVER
4858 M: Matthieu Castet <castet.matthieu@free.fr> 4859 M: Matthieu Castet <castet.matthieu@free.fr>
4859 M: Stanislaw Gruszka <stf_xl@wp.pl> 4860 M: Stanislaw Gruszka <stf_xl@wp.pl>
4860 S: Maintained 4861 S: Maintained
4861 F: drivers/usb/atm/ueagle-atm.c 4862 F: drivers/usb/atm/ueagle-atm.c
4862 4863
4863 INA209 HARDWARE MONITOR DRIVER 4864 INA209 HARDWARE MONITOR DRIVER
4864 M: Guenter Roeck <linux@roeck-us.net> 4865 M: Guenter Roeck <linux@roeck-us.net>
4865 L: lm-sensors@lm-sensors.org 4866 L: lm-sensors@lm-sensors.org
4866 S: Maintained 4867 S: Maintained
4867 F: Documentation/hwmon/ina209 4868 F: Documentation/hwmon/ina209
4868 F: Documentation/devicetree/bindings/i2c/ina209.txt 4869 F: Documentation/devicetree/bindings/i2c/ina209.txt
4869 F: drivers/hwmon/ina209.c 4870 F: drivers/hwmon/ina209.c
4870 4871
4871 INA2XX HARDWARE MONITOR DRIVER 4872 INA2XX HARDWARE MONITOR DRIVER
4872 M: Guenter Roeck <linux@roeck-us.net> 4873 M: Guenter Roeck <linux@roeck-us.net>
4873 L: lm-sensors@lm-sensors.org 4874 L: lm-sensors@lm-sensors.org
4874 S: Maintained 4875 S: Maintained
4875 F: Documentation/hwmon/ina2xx 4876 F: Documentation/hwmon/ina2xx
4876 F: drivers/hwmon/ina2xx.c 4877 F: drivers/hwmon/ina2xx.c
4877 F: include/linux/platform_data/ina2xx.h 4878 F: include/linux/platform_data/ina2xx.h
4878 4879
4879 INDUSTRY PACK SUBSYSTEM (IPACK) 4880 INDUSTRY PACK SUBSYSTEM (IPACK)
4880 M: Samuel Iglesias Gonsalvez <siglesias@igalia.com> 4881 M: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
4881 M: Jens Taprogge <jens.taprogge@taprogge.org> 4882 M: Jens Taprogge <jens.taprogge@taprogge.org>
4882 M: Greg Kroah-Hartman <gregkh@linuxfoundation.org> 4883 M: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
4883 L: industrypack-devel@lists.sourceforge.net 4884 L: industrypack-devel@lists.sourceforge.net
4884 W: http://industrypack.sourceforge.net 4885 W: http://industrypack.sourceforge.net
4885 S: Maintained 4886 S: Maintained
4886 F: drivers/ipack/ 4887 F: drivers/ipack/
4887 4888
4888 INTEGRITY MEASUREMENT ARCHITECTURE (IMA) 4889 INTEGRITY MEASUREMENT ARCHITECTURE (IMA)
4889 M: Mimi Zohar <zohar@linux.vnet.ibm.com> 4890 M: Mimi Zohar <zohar@linux.vnet.ibm.com>
4890 M: Dmitry Kasatkin <d.kasatkin@samsung.com> 4891 M: Dmitry Kasatkin <d.kasatkin@samsung.com>
4891 L: linux-ima-devel@lists.sourceforge.net 4892 L: linux-ima-devel@lists.sourceforge.net
4892 L: linux-ima-user@lists.sourceforge.net 4893 L: linux-ima-user@lists.sourceforge.net
4893 L: linux-security-module@vger.kernel.org 4894 L: linux-security-module@vger.kernel.org
4894 S: Supported 4895 S: Supported
4895 F: security/integrity/ima/ 4896 F: security/integrity/ima/
4896 4897
4897 IMGTEC IR DECODER DRIVER 4898 IMGTEC IR DECODER DRIVER
4898 M: James Hogan <james.hogan@imgtec.com> 4899 M: James Hogan <james.hogan@imgtec.com>
4899 S: Maintained 4900 S: Maintained
4900 F: drivers/media/rc/img-ir/ 4901 F: drivers/media/rc/img-ir/
4901 4902
4902 IMS TWINTURBO FRAMEBUFFER DRIVER 4903 IMS TWINTURBO FRAMEBUFFER DRIVER
4903 L: linux-fbdev@vger.kernel.org 4904 L: linux-fbdev@vger.kernel.org
4904 S: Orphan 4905 S: Orphan
4905 F: drivers/video/fbdev/imsttfb.c 4906 F: drivers/video/fbdev/imsttfb.c
4906 4907
4907 INFINIBAND SUBSYSTEM 4908 INFINIBAND SUBSYSTEM
4908 M: Roland Dreier <roland@kernel.org> 4909 M: Roland Dreier <roland@kernel.org>
4909 M: Sean Hefty <sean.hefty@intel.com> 4910 M: Sean Hefty <sean.hefty@intel.com>
4910 M: Hal Rosenstock <hal.rosenstock@gmail.com> 4911 M: Hal Rosenstock <hal.rosenstock@gmail.com>
4911 L: linux-rdma@vger.kernel.org 4912 L: linux-rdma@vger.kernel.org
4912 W: http://www.openfabrics.org/ 4913 W: http://www.openfabrics.org/
4913 Q: http://patchwork.kernel.org/project/linux-rdma/list/ 4914 Q: http://patchwork.kernel.org/project/linux-rdma/list/
4914 T: git git://git.kernel.org/pub/scm/linux/kernel/git/roland/infiniband.git 4915 T: git git://git.kernel.org/pub/scm/linux/kernel/git/roland/infiniband.git
4915 S: Supported 4916 S: Supported
4916 F: Documentation/infiniband/ 4917 F: Documentation/infiniband/
4917 F: drivers/infiniband/ 4918 F: drivers/infiniband/
4918 F: include/uapi/linux/if_infiniband.h 4919 F: include/uapi/linux/if_infiniband.h
4919 4920
4920 INOTIFY 4921 INOTIFY
4921 M: John McCutchan <john@johnmccutchan.com> 4922 M: John McCutchan <john@johnmccutchan.com>
4922 M: Robert Love <rlove@rlove.org> 4923 M: Robert Love <rlove@rlove.org>
4923 M: Eric Paris <eparis@parisplace.org> 4924 M: Eric Paris <eparis@parisplace.org>
4924 S: Maintained 4925 S: Maintained
4925 F: Documentation/filesystems/inotify.txt 4926 F: Documentation/filesystems/inotify.txt
4926 F: fs/notify/inotify/ 4927 F: fs/notify/inotify/
4927 F: include/linux/inotify.h 4928 F: include/linux/inotify.h
4928 F: include/uapi/linux/inotify.h 4929 F: include/uapi/linux/inotify.h
4929 4930
4930 INPUT (KEYBOARD, MOUSE, JOYSTICK, TOUCHSCREEN) DRIVERS 4931 INPUT (KEYBOARD, MOUSE, JOYSTICK, TOUCHSCREEN) DRIVERS
4931 M: Dmitry Torokhov <dmitry.torokhov@gmail.com> 4932 M: Dmitry Torokhov <dmitry.torokhov@gmail.com>
4932 M: Dmitry Torokhov <dtor@mail.ru> 4933 M: Dmitry Torokhov <dtor@mail.ru>
4933 L: linux-input@vger.kernel.org 4934 L: linux-input@vger.kernel.org
4934 Q: http://patchwork.kernel.org/project/linux-input/list/ 4935 Q: http://patchwork.kernel.org/project/linux-input/list/
4935 T: git git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git 4936 T: git git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git
4936 S: Maintained 4937 S: Maintained
4937 F: drivers/input/ 4938 F: drivers/input/
4938 F: include/linux/input.h 4939 F: include/linux/input.h
4939 F: include/uapi/linux/input.h 4940 F: include/uapi/linux/input.h
4940 F: include/linux/input/ 4941 F: include/linux/input/
4941 4942
4942 INPUT MULTITOUCH (MT) PROTOCOL 4943 INPUT MULTITOUCH (MT) PROTOCOL
4943 M: Henrik Rydberg <rydberg@bitmath.org> 4944 M: Henrik Rydberg <rydberg@bitmath.org>
4944 L: linux-input@vger.kernel.org 4945 L: linux-input@vger.kernel.org
4945 T: git git://git.kernel.org/pub/scm/linux/kernel/git/rydberg/input-mt.git 4946 T: git git://git.kernel.org/pub/scm/linux/kernel/git/rydberg/input-mt.git
4946 S: Odd fixes 4947 S: Odd fixes
4947 F: Documentation/input/multi-touch-protocol.txt 4948 F: Documentation/input/multi-touch-protocol.txt
4948 F: drivers/input/input-mt.c 4949 F: drivers/input/input-mt.c
4949 K: \b(ABS|SYN)_MT_ 4950 K: \b(ABS|SYN)_MT_
4950 4951
4951 INTEL C600 SERIES SAS CONTROLLER DRIVER 4952 INTEL C600 SERIES SAS CONTROLLER DRIVER
4952 M: Intel SCU Linux support <intel-linux-scu@intel.com> 4953 M: Intel SCU Linux support <intel-linux-scu@intel.com>
4953 M: Artur Paszkiewicz <artur.paszkiewicz@intel.com> 4954 M: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
4954 M: Dave Jiang <dave.jiang@intel.com> 4955 M: Dave Jiang <dave.jiang@intel.com>
4955 L: linux-scsi@vger.kernel.org 4956 L: linux-scsi@vger.kernel.org
4956 T: git git://git.code.sf.net/p/intel-sas/isci 4957 T: git git://git.code.sf.net/p/intel-sas/isci
4957 S: Supported 4958 S: Supported
4958 F: drivers/scsi/isci/ 4959 F: drivers/scsi/isci/
4959 4960
4960 INTEL IDLE DRIVER 4961 INTEL IDLE DRIVER
4961 M: Len Brown <lenb@kernel.org> 4962 M: Len Brown <lenb@kernel.org>
4962 L: linux-pm@vger.kernel.org 4963 L: linux-pm@vger.kernel.org
4963 T: git git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux.git 4964 T: git git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux.git
4964 S: Supported 4965 S: Supported
4965 F: drivers/idle/intel_idle.c 4966 F: drivers/idle/intel_idle.c
4966 4967
4967 INTEL PSTATE DRIVER 4968 INTEL PSTATE DRIVER
4968 M: Kristen Carlson Accardi <kristen@linux.intel.com> 4969 M: Kristen Carlson Accardi <kristen@linux.intel.com>
4969 L: linux-pm@vger.kernel.org 4970 L: linux-pm@vger.kernel.org
4970 S: Supported 4971 S: Supported
4971 F: drivers/cpufreq/intel_pstate.c 4972 F: drivers/cpufreq/intel_pstate.c
4972 4973
4973 INTEL FRAMEBUFFER DRIVER (excluding 810 and 815) 4974 INTEL FRAMEBUFFER DRIVER (excluding 810 and 815)
4974 M: Maik Broemme <mbroemme@plusserver.de> 4975 M: Maik Broemme <mbroemme@plusserver.de>
4975 L: linux-fbdev@vger.kernel.org 4976 L: linux-fbdev@vger.kernel.org
4976 S: Maintained 4977 S: Maintained
4977 F: Documentation/fb/intelfb.txt 4978 F: Documentation/fb/intelfb.txt
4978 F: drivers/video/fbdev/intelfb/ 4979 F: drivers/video/fbdev/intelfb/
4979 4980
4980 INTEL 810/815 FRAMEBUFFER DRIVER 4981 INTEL 810/815 FRAMEBUFFER DRIVER
4981 M: Antonino Daplas <adaplas@gmail.com> 4982 M: Antonino Daplas <adaplas@gmail.com>
4982 L: linux-fbdev@vger.kernel.org 4983 L: linux-fbdev@vger.kernel.org
4983 S: Maintained 4984 S: Maintained
4984 F: drivers/video/fbdev/i810/ 4985 F: drivers/video/fbdev/i810/
4985 4986
4986 INTEL MENLOW THERMAL DRIVER 4987 INTEL MENLOW THERMAL DRIVER
4987 M: Sujith Thomas <sujith.thomas@intel.com> 4988 M: Sujith Thomas <sujith.thomas@intel.com>
4988 L: platform-driver-x86@vger.kernel.org 4989 L: platform-driver-x86@vger.kernel.org
4989 W: https://01.org/linux-acpi 4990 W: https://01.org/linux-acpi
4990 S: Supported 4991 S: Supported
4991 F: drivers/platform/x86/intel_menlow.c 4992 F: drivers/platform/x86/intel_menlow.c
4992 4993
4993 INTEL IA32 MICROCODE UPDATE SUPPORT 4994 INTEL IA32 MICROCODE UPDATE SUPPORT
4994 M: Tigran Aivazian <tigran@aivazian.fsnet.co.uk> 4995 M: Tigran Aivazian <tigran@aivazian.fsnet.co.uk>
4995 S: Maintained 4996 S: Maintained
4996 F: arch/x86/kernel/cpu/microcode/core* 4997 F: arch/x86/kernel/cpu/microcode/core*
4997 F: arch/x86/kernel/cpu/microcode/intel* 4998 F: arch/x86/kernel/cpu/microcode/intel*
4998 4999
4999 INTEL I/OAT DMA DRIVER 5000 INTEL I/OAT DMA DRIVER
5000 M: Dave Jiang <dave.jiang@intel.com> 5001 M: Dave Jiang <dave.jiang@intel.com>
5001 R: Dan Williams <dan.j.williams@intel.com> 5002 R: Dan Williams <dan.j.williams@intel.com>
5002 L: dmaengine@vger.kernel.org 5003 L: dmaengine@vger.kernel.org
5003 Q: https://patchwork.kernel.org/project/linux-dmaengine/list/ 5004 Q: https://patchwork.kernel.org/project/linux-dmaengine/list/
5004 S: Supported 5005 S: Supported
5005 F: drivers/dma/ioat* 5006 F: drivers/dma/ioat*
5006 5007
5007 INTEL IOMMU (VT-d) 5008 INTEL IOMMU (VT-d)
5008 M: David Woodhouse <dwmw2@infradead.org> 5009 M: David Woodhouse <dwmw2@infradead.org>
5009 L: iommu@lists.linux-foundation.org 5010 L: iommu@lists.linux-foundation.org
5010 T: git git://git.infradead.org/iommu-2.6.git 5011 T: git git://git.infradead.org/iommu-2.6.git
5011 S: Supported 5012 S: Supported
5012 F: drivers/iommu/intel-iommu.c 5013 F: drivers/iommu/intel-iommu.c
5013 F: include/linux/intel-iommu.h 5014 F: include/linux/intel-iommu.h
5014 5015
5015 INTEL IOP-ADMA DMA DRIVER 5016 INTEL IOP-ADMA DMA DRIVER
5016 R: Dan Williams <dan.j.williams@intel.com> 5017 R: Dan Williams <dan.j.williams@intel.com>
5017 S: Odd fixes 5018 S: Odd fixes
5018 F: drivers/dma/iop-adma.c 5019 F: drivers/dma/iop-adma.c
5019 5020
5020 INTEL IXP4XX QMGR, NPE, ETHERNET and HSS SUPPORT 5021 INTEL IXP4XX QMGR, NPE, ETHERNET and HSS SUPPORT
5021 M: Krzysztof Halasa <khalasa@piap.pl> 5022 M: Krzysztof Halasa <khalasa@piap.pl>
5022 S: Maintained 5023 S: Maintained
5023 F: arch/arm/mach-ixp4xx/include/mach/qmgr.h 5024 F: arch/arm/mach-ixp4xx/include/mach/qmgr.h
5024 F: arch/arm/mach-ixp4xx/include/mach/npe.h 5025 F: arch/arm/mach-ixp4xx/include/mach/npe.h
5025 F: arch/arm/mach-ixp4xx/ixp4xx_qmgr.c 5026 F: arch/arm/mach-ixp4xx/ixp4xx_qmgr.c
5026 F: arch/arm/mach-ixp4xx/ixp4xx_npe.c 5027 F: arch/arm/mach-ixp4xx/ixp4xx_npe.c
5027 F: drivers/net/ethernet/xscale/ixp4xx_eth.c 5028 F: drivers/net/ethernet/xscale/ixp4xx_eth.c
5028 F: drivers/net/wan/ixp4xx_hss.c 5029 F: drivers/net/wan/ixp4xx_hss.c
5029 5030
5030 INTEL IXP4XX RANDOM NUMBER GENERATOR SUPPORT 5031 INTEL IXP4XX RANDOM NUMBER GENERATOR SUPPORT
5031 M: Deepak Saxena <dsaxena@plexity.net> 5032 M: Deepak Saxena <dsaxena@plexity.net>
5032 S: Maintained 5033 S: Maintained
5033 F: drivers/char/hw_random/ixp4xx-rng.c 5034 F: drivers/char/hw_random/ixp4xx-rng.c
5034 5035
5035 INTEL ETHERNET DRIVERS (e100/e1000/e1000e/fm10k/igb/igbvf/ixgb/ixgbe/ixgbevf/i40e/i40evf) 5036 INTEL ETHERNET DRIVERS (e100/e1000/e1000e/fm10k/igb/igbvf/ixgb/ixgbe/ixgbevf/i40e/i40evf)
5036 M: Jeff Kirsher <jeffrey.t.kirsher@intel.com> 5037 M: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
5037 M: Jesse Brandeburg <jesse.brandeburg@intel.com> 5038 M: Jesse Brandeburg <jesse.brandeburg@intel.com>
5038 M: Bruce Allan <bruce.w.allan@intel.com> 5039 M: Bruce Allan <bruce.w.allan@intel.com>
5039 M: Carolyn Wyborny <carolyn.wyborny@intel.com> 5040 M: Carolyn Wyborny <carolyn.wyborny@intel.com>
5040 M: Don Skidmore <donald.c.skidmore@intel.com> 5041 M: Don Skidmore <donald.c.skidmore@intel.com>
5041 M: Greg Rose <gregory.v.rose@intel.com> 5042 M: Greg Rose <gregory.v.rose@intel.com>
5042 M: Matthew Vick <matthew.vick@intel.com> 5043 M: Matthew Vick <matthew.vick@intel.com>
5043 M: John Ronciak <john.ronciak@intel.com> 5044 M: John Ronciak <john.ronciak@intel.com>
5044 M: Mitch Williams <mitch.a.williams@intel.com> 5045 M: Mitch Williams <mitch.a.williams@intel.com>
5045 M: Linux NICS <linux.nics@intel.com> 5046 M: Linux NICS <linux.nics@intel.com>
5046 L: e1000-devel@lists.sourceforge.net 5047 L: e1000-devel@lists.sourceforge.net
5047 W: http://www.intel.com/support/feedback.htm 5048 W: http://www.intel.com/support/feedback.htm
5048 W: http://e1000.sourceforge.net/ 5049 W: http://e1000.sourceforge.net/
5049 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jkirsher/net.git 5050 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jkirsher/net.git
5050 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jkirsher/net-next.git 5051 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jkirsher/net-next.git
5051 S: Supported 5052 S: Supported
5052 F: Documentation/networking/e100.txt 5053 F: Documentation/networking/e100.txt
5053 F: Documentation/networking/e1000.txt 5054 F: Documentation/networking/e1000.txt
5054 F: Documentation/networking/e1000e.txt 5055 F: Documentation/networking/e1000e.txt
5055 F: Documentation/networking/igb.txt 5056 F: Documentation/networking/igb.txt
5056 F: Documentation/networking/igbvf.txt 5057 F: Documentation/networking/igbvf.txt
5057 F: Documentation/networking/ixgb.txt 5058 F: Documentation/networking/ixgb.txt
5058 F: Documentation/networking/ixgbe.txt 5059 F: Documentation/networking/ixgbe.txt
5059 F: Documentation/networking/ixgbevf.txt 5060 F: Documentation/networking/ixgbevf.txt
5060 F: Documentation/networking/i40e.txt 5061 F: Documentation/networking/i40e.txt
5061 F: Documentation/networking/i40evf.txt 5062 F: Documentation/networking/i40evf.txt
5062 F: drivers/net/ethernet/intel/ 5063 F: drivers/net/ethernet/intel/
5063 F: drivers/net/ethernet/intel/*/ 5064 F: drivers/net/ethernet/intel/*/
5064 5065
5065 INTEL-MID GPIO DRIVER 5066 INTEL-MID GPIO DRIVER
5066 M: David Cohen <david.a.cohen@linux.intel.com> 5067 M: David Cohen <david.a.cohen@linux.intel.com>
5067 L: linux-gpio@vger.kernel.org 5068 L: linux-gpio@vger.kernel.org
5068 S: Maintained 5069 S: Maintained
5069 F: drivers/gpio/gpio-intel-mid.c 5070 F: drivers/gpio/gpio-intel-mid.c
5070 5071
5071 INTEL PRO/WIRELESS 2100, 2200BG, 2915ABG NETWORK CONNECTION SUPPORT 5072 INTEL PRO/WIRELESS 2100, 2200BG, 2915ABG NETWORK CONNECTION SUPPORT
5072 M: Stanislav Yakovlev <stas.yakovlev@gmail.com> 5073 M: Stanislav Yakovlev <stas.yakovlev@gmail.com>
5073 L: linux-wireless@vger.kernel.org 5074 L: linux-wireless@vger.kernel.org
5074 S: Maintained 5075 S: Maintained
5075 F: Documentation/networking/README.ipw2100 5076 F: Documentation/networking/README.ipw2100
5076 F: Documentation/networking/README.ipw2200 5077 F: Documentation/networking/README.ipw2200
5077 F: drivers/net/wireless/ipw2x00/ 5078 F: drivers/net/wireless/ipw2x00/
5078 5079
5079 INTEL(R) TRUSTED EXECUTION TECHNOLOGY (TXT) 5080 INTEL(R) TRUSTED EXECUTION TECHNOLOGY (TXT)
5080 M: Richard L Maliszewski <richard.l.maliszewski@intel.com> 5081 M: Richard L Maliszewski <richard.l.maliszewski@intel.com>
5081 M: Gang Wei <gang.wei@intel.com> 5082 M: Gang Wei <gang.wei@intel.com>
5082 M: Shane Wang <shane.wang@intel.com> 5083 M: Shane Wang <shane.wang@intel.com>
5083 L: tboot-devel@lists.sourceforge.net 5084 L: tboot-devel@lists.sourceforge.net
5084 W: http://tboot.sourceforge.net 5085 W: http://tboot.sourceforge.net
5085 T: hg http://tboot.hg.sourceforge.net:8000/hgroot/tboot/tboot 5086 T: hg http://tboot.hg.sourceforge.net:8000/hgroot/tboot/tboot
5086 S: Supported 5087 S: Supported
5087 F: Documentation/intel_txt.txt 5088 F: Documentation/intel_txt.txt
5088 F: include/linux/tboot.h 5089 F: include/linux/tboot.h
5089 F: arch/x86/kernel/tboot.c 5090 F: arch/x86/kernel/tboot.c
5090 5091
5091 INTEL WIRELESS WIMAX CONNECTION 2400 5092 INTEL WIRELESS WIMAX CONNECTION 2400
5092 M: Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> 5093 M: Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
5093 M: linux-wimax@intel.com 5094 M: linux-wimax@intel.com
5094 L: wimax@linuxwimax.org (subscribers-only) 5095 L: wimax@linuxwimax.org (subscribers-only)
5095 S: Supported 5096 S: Supported
5096 W: http://linuxwimax.org 5097 W: http://linuxwimax.org
5097 F: Documentation/wimax/README.i2400m 5098 F: Documentation/wimax/README.i2400m
5098 F: drivers/net/wimax/i2400m/ 5099 F: drivers/net/wimax/i2400m/
5099 F: include/uapi/linux/wimax/i2400m.h 5100 F: include/uapi/linux/wimax/i2400m.h
5100 5101
5101 INTEL WIRELESS 3945ABG/BG, 4965AGN (iwlegacy) 5102 INTEL WIRELESS 3945ABG/BG, 4965AGN (iwlegacy)
5102 M: Stanislaw Gruszka <sgruszka@redhat.com> 5103 M: Stanislaw Gruszka <sgruszka@redhat.com>
5103 L: linux-wireless@vger.kernel.org 5104 L: linux-wireless@vger.kernel.org
5104 S: Supported 5105 S: Supported
5105 F: drivers/net/wireless/iwlegacy/ 5106 F: drivers/net/wireless/iwlegacy/
5106 5107
5107 INTEL WIRELESS WIFI LINK (iwlwifi) 5108 INTEL WIRELESS WIFI LINK (iwlwifi)
5108 M: Johannes Berg <johannes.berg@intel.com> 5109 M: Johannes Berg <johannes.berg@intel.com>
5109 M: Emmanuel Grumbach <emmanuel.grumbach@intel.com> 5110 M: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
5110 M: Intel Linux Wireless <ilw@linux.intel.com> 5111 M: Intel Linux Wireless <ilw@linux.intel.com>
5111 L: linux-wireless@vger.kernel.org 5112 L: linux-wireless@vger.kernel.org
5112 W: http://intellinuxwireless.org 5113 W: http://intellinuxwireless.org
5113 T: git git://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/iwlwifi.git 5114 T: git git://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/iwlwifi.git
5114 S: Supported 5115 S: Supported
5115 F: drivers/net/wireless/iwlwifi/ 5116 F: drivers/net/wireless/iwlwifi/
5116 5117
5117 INTEL MANAGEMENT ENGINE (mei) 5118 INTEL MANAGEMENT ENGINE (mei)
5118 M: Tomas Winkler <tomas.winkler@intel.com> 5119 M: Tomas Winkler <tomas.winkler@intel.com>
5119 L: linux-kernel@vger.kernel.org 5120 L: linux-kernel@vger.kernel.org
5120 S: Supported 5121 S: Supported
5121 F: include/uapi/linux/mei.h 5122 F: include/uapi/linux/mei.h
5122 F: drivers/misc/mei/* 5123 F: drivers/misc/mei/*
5123 F: Documentation/misc-devices/mei/* 5124 F: Documentation/misc-devices/mei/*
5124 5125
5125 IOC3 ETHERNET DRIVER 5126 IOC3 ETHERNET DRIVER
5126 M: Ralf Baechle <ralf@linux-mips.org> 5127 M: Ralf Baechle <ralf@linux-mips.org>
5127 L: linux-mips@linux-mips.org 5128 L: linux-mips@linux-mips.org
5128 S: Maintained 5129 S: Maintained
5129 F: drivers/net/ethernet/sgi/ioc3-eth.c 5130 F: drivers/net/ethernet/sgi/ioc3-eth.c
5130 5131
5131 IOC3 SERIAL DRIVER 5132 IOC3 SERIAL DRIVER
5132 M: Pat Gefre <pfg@sgi.com> 5133 M: Pat Gefre <pfg@sgi.com>
5133 L: linux-serial@vger.kernel.org 5134 L: linux-serial@vger.kernel.org
5134 S: Maintained 5135 S: Maintained
5135 F: drivers/tty/serial/ioc3_serial.c 5136 F: drivers/tty/serial/ioc3_serial.c
5136 5137
5137 IOMMU DRIVERS 5138 IOMMU DRIVERS
5138 M: Joerg Roedel <joro@8bytes.org> 5139 M: Joerg Roedel <joro@8bytes.org>
5139 L: iommu@lists.linux-foundation.org 5140 L: iommu@lists.linux-foundation.org
5140 T: git git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git 5141 T: git git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git
5141 S: Maintained 5142 S: Maintained
5142 F: drivers/iommu/ 5143 F: drivers/iommu/
5143 5144
5144 IP MASQUERADING 5145 IP MASQUERADING
5145 M: Juanjo Ciarlante <jjciarla@raiz.uncu.edu.ar> 5146 M: Juanjo Ciarlante <jjciarla@raiz.uncu.edu.ar>
5146 S: Maintained 5147 S: Maintained
5147 F: net/ipv4/netfilter/ipt_MASQUERADE.c 5148 F: net/ipv4/netfilter/ipt_MASQUERADE.c
5148 5149
5149 IP1000A 10/100/1000 GIGABIT ETHERNET DRIVER 5150 IP1000A 10/100/1000 GIGABIT ETHERNET DRIVER
5150 M: Francois Romieu <romieu@fr.zoreil.com> 5151 M: Francois Romieu <romieu@fr.zoreil.com>
5151 M: Sorbica Shieh <sorbica@icplus.com.tw> 5152 M: Sorbica Shieh <sorbica@icplus.com.tw>
5152 L: netdev@vger.kernel.org 5153 L: netdev@vger.kernel.org
5153 S: Maintained 5154 S: Maintained
5154 F: drivers/net/ethernet/icplus/ipg.* 5155 F: drivers/net/ethernet/icplus/ipg.*
5155 5156
5156 IPATH DRIVER 5157 IPATH DRIVER
5157 M: Mike Marciniszyn <infinipath@intel.com> 5158 M: Mike Marciniszyn <infinipath@intel.com>
5158 L: linux-rdma@vger.kernel.org 5159 L: linux-rdma@vger.kernel.org
5159 S: Maintained 5160 S: Maintained
5160 F: drivers/infiniband/hw/ipath/ 5161 F: drivers/infiniband/hw/ipath/
5161 5162
5162 IPMI SUBSYSTEM 5163 IPMI SUBSYSTEM
5163 M: Corey Minyard <minyard@acm.org> 5164 M: Corey Minyard <minyard@acm.org>
5164 L: openipmi-developer@lists.sourceforge.net (moderated for non-subscribers) 5165 L: openipmi-developer@lists.sourceforge.net (moderated for non-subscribers)
5165 W: http://openipmi.sourceforge.net/ 5166 W: http://openipmi.sourceforge.net/
5166 S: Supported 5167 S: Supported
5167 F: Documentation/IPMI.txt 5168 F: Documentation/IPMI.txt
5168 F: drivers/char/ipmi/ 5169 F: drivers/char/ipmi/
5169 F: include/linux/ipmi* 5170 F: include/linux/ipmi*
5170 F: include/uapi/linux/ipmi* 5171 F: include/uapi/linux/ipmi*
5171 5172
5172 IPS SCSI RAID DRIVER 5173 IPS SCSI RAID DRIVER
5173 M: Adaptec OEM Raid Solutions <aacraid@adaptec.com> 5174 M: Adaptec OEM Raid Solutions <aacraid@adaptec.com>
5174 L: linux-scsi@vger.kernel.org 5175 L: linux-scsi@vger.kernel.org
5175 W: http://www.adaptec.com/ 5176 W: http://www.adaptec.com/
5176 S: Maintained 5177 S: Maintained
5177 F: drivers/scsi/ips* 5178 F: drivers/scsi/ips*
5178 5179
5179 IPVS 5180 IPVS
5180 M: Wensong Zhang <wensong@linux-vs.org> 5181 M: Wensong Zhang <wensong@linux-vs.org>
5181 M: Simon Horman <horms@verge.net.au> 5182 M: Simon Horman <horms@verge.net.au>
5182 M: Julian Anastasov <ja@ssi.bg> 5183 M: Julian Anastasov <ja@ssi.bg>
5183 L: netdev@vger.kernel.org 5184 L: netdev@vger.kernel.org
5184 L: lvs-devel@vger.kernel.org 5185 L: lvs-devel@vger.kernel.org
5185 S: Maintained 5186 S: Maintained
5186 F: Documentation/networking/ipvs-sysctl.txt 5187 F: Documentation/networking/ipvs-sysctl.txt
5187 F: include/net/ip_vs.h 5188 F: include/net/ip_vs.h
5188 F: include/uapi/linux/ip_vs.h 5189 F: include/uapi/linux/ip_vs.h
5189 F: net/netfilter/ipvs/ 5190 F: net/netfilter/ipvs/
5190 5191
5191 IPWIRELESS DRIVER 5192 IPWIRELESS DRIVER
5192 M: Jiri Kosina <jkosina@suse.cz> 5193 M: Jiri Kosina <jkosina@suse.cz>
5193 M: David Sterba <dsterba@suse.cz> 5194 M: David Sterba <dsterba@suse.cz>
5194 S: Odd Fixes 5195 S: Odd Fixes
5195 F: drivers/tty/ipwireless/ 5196 F: drivers/tty/ipwireless/
5196 5197
5197 IPX NETWORK LAYER 5198 IPX NETWORK LAYER
5198 M: Arnaldo Carvalho de Melo <acme@ghostprotocols.net> 5199 M: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
5199 L: netdev@vger.kernel.org 5200 L: netdev@vger.kernel.org
5200 S: Maintained 5201 S: Maintained
5201 F: include/net/ipx.h 5202 F: include/net/ipx.h
5202 F: include/uapi/linux/ipx.h 5203 F: include/uapi/linux/ipx.h
5203 F: net/ipx/ 5204 F: net/ipx/
5204 5205
5205 IRDA SUBSYSTEM 5206 IRDA SUBSYSTEM
5206 M: Samuel Ortiz <samuel@sortiz.org> 5207 M: Samuel Ortiz <samuel@sortiz.org>
5207 L: irda-users@lists.sourceforge.net (subscribers-only) 5208 L: irda-users@lists.sourceforge.net (subscribers-only)
5208 L: netdev@vger.kernel.org 5209 L: netdev@vger.kernel.org
5209 W: http://irda.sourceforge.net/ 5210 W: http://irda.sourceforge.net/
5210 S: Maintained 5211 S: Maintained
5211 T: git git://git.kernel.org/pub/scm/linux/kernel/git/sameo/irda-2.6.git 5212 T: git git://git.kernel.org/pub/scm/linux/kernel/git/sameo/irda-2.6.git
5212 F: Documentation/networking/irda.txt 5213 F: Documentation/networking/irda.txt
5213 F: drivers/net/irda/ 5214 F: drivers/net/irda/
5214 F: include/net/irda/ 5215 F: include/net/irda/
5215 F: net/irda/ 5216 F: net/irda/
5216 5217
5217 IRQ SUBSYSTEM 5218 IRQ SUBSYSTEM
5218 M: Thomas Gleixner <tglx@linutronix.de> 5219 M: Thomas Gleixner <tglx@linutronix.de>
5219 L: linux-kernel@vger.kernel.org 5220 L: linux-kernel@vger.kernel.org
5220 S: Maintained 5221 S: Maintained
5221 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git irq/core 5222 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git irq/core
5222 F: kernel/irq/ 5223 F: kernel/irq/
5223 5224
5224 IRQCHIP DRIVERS 5225 IRQCHIP DRIVERS
5225 M: Thomas Gleixner <tglx@linutronix.de> 5226 M: Thomas Gleixner <tglx@linutronix.de>
5226 M: Jason Cooper <jason@lakedaemon.net> 5227 M: Jason Cooper <jason@lakedaemon.net>
5227 L: linux-kernel@vger.kernel.org 5228 L: linux-kernel@vger.kernel.org
5228 S: Maintained 5229 S: Maintained
5229 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git irq/core 5230 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git irq/core
5230 T: git git://git.infradead.org/users/jcooper/linux.git irqchip/core 5231 T: git git://git.infradead.org/users/jcooper/linux.git irqchip/core
5231 F: Documentation/devicetree/bindings/interrupt-controller/ 5232 F: Documentation/devicetree/bindings/interrupt-controller/
5232 F: drivers/irqchip/ 5233 F: drivers/irqchip/
5233 5234
5234 IRQ DOMAINS (IRQ NUMBER MAPPING LIBRARY) 5235 IRQ DOMAINS (IRQ NUMBER MAPPING LIBRARY)
5235 M: Benjamin Herrenschmidt <benh@kernel.crashing.org> 5236 M: Benjamin Herrenschmidt <benh@kernel.crashing.org>
5236 S: Maintained 5237 S: Maintained
5237 F: Documentation/IRQ-domain.txt 5238 F: Documentation/IRQ-domain.txt
5238 F: include/linux/irqdomain.h 5239 F: include/linux/irqdomain.h
5239 F: kernel/irq/irqdomain.c 5240 F: kernel/irq/irqdomain.c
5240 5241
5241 ISAPNP 5242 ISAPNP
5242 M: Jaroslav Kysela <perex@perex.cz> 5243 M: Jaroslav Kysela <perex@perex.cz>
5243 S: Maintained 5244 S: Maintained
5244 F: Documentation/isapnp.txt 5245 F: Documentation/isapnp.txt
5245 F: drivers/pnp/isapnp/ 5246 F: drivers/pnp/isapnp/
5246 F: include/linux/isapnp.h 5247 F: include/linux/isapnp.h
5247 5248
5248 ISA RADIO MODULE 5249 ISA RADIO MODULE
5249 M: Hans Verkuil <hverkuil@xs4all.nl> 5250 M: Hans Verkuil <hverkuil@xs4all.nl>
5250 L: linux-media@vger.kernel.org 5251 L: linux-media@vger.kernel.org
5251 T: git git://linuxtv.org/media_tree.git 5252 T: git git://linuxtv.org/media_tree.git
5252 W: http://linuxtv.org 5253 W: http://linuxtv.org
5253 S: Maintained 5254 S: Maintained
5254 F: drivers/media/radio/radio-isa* 5255 F: drivers/media/radio/radio-isa*
5255 5256
5256 iSCSI BOOT FIRMWARE TABLE (iBFT) DRIVER 5257 iSCSI BOOT FIRMWARE TABLE (iBFT) DRIVER
5257 M: Peter Jones <pjones@redhat.com> 5258 M: Peter Jones <pjones@redhat.com>
5258 M: Konrad Rzeszutek Wilk <konrad@kernel.org> 5259 M: Konrad Rzeszutek Wilk <konrad@kernel.org>
5259 S: Maintained 5260 S: Maintained
5260 F: drivers/firmware/iscsi_ibft* 5261 F: drivers/firmware/iscsi_ibft*
5261 5262
5262 ISCSI 5263 ISCSI
5263 M: Mike Christie <michaelc@cs.wisc.edu> 5264 M: Mike Christie <michaelc@cs.wisc.edu>
5264 L: open-iscsi@googlegroups.com 5265 L: open-iscsi@googlegroups.com
5265 W: www.open-iscsi.org 5266 W: www.open-iscsi.org
5266 T: git git://git.kernel.org/pub/scm/linux/kernel/git/mnc/linux-2.6-iscsi.git 5267 T: git git://git.kernel.org/pub/scm/linux/kernel/git/mnc/linux-2.6-iscsi.git
5267 S: Maintained 5268 S: Maintained
5268 F: drivers/scsi/*iscsi* 5269 F: drivers/scsi/*iscsi*
5269 F: include/scsi/*iscsi* 5270 F: include/scsi/*iscsi*
5270 5271
5271 ISCSI EXTENSIONS FOR RDMA (ISER) INITIATOR 5272 ISCSI EXTENSIONS FOR RDMA (ISER) INITIATOR
5272 M: Or Gerlitz <ogerlitz@mellanox.com> 5273 M: Or Gerlitz <ogerlitz@mellanox.com>
5273 M: Sagi Grimberg <sagig@mellanox.com> 5274 M: Sagi Grimberg <sagig@mellanox.com>
5274 M: Roi Dayan <roid@mellanox.com> 5275 M: Roi Dayan <roid@mellanox.com>
5275 L: linux-rdma@vger.kernel.org 5276 L: linux-rdma@vger.kernel.org
5276 S: Supported 5277 S: Supported
5277 W: http://www.openfabrics.org 5278 W: http://www.openfabrics.org
5278 W: www.open-iscsi.org 5279 W: www.open-iscsi.org
5279 Q: http://patchwork.kernel.org/project/linux-rdma/list/ 5280 Q: http://patchwork.kernel.org/project/linux-rdma/list/
5280 F: drivers/infiniband/ulp/iser/ 5281 F: drivers/infiniband/ulp/iser/
5281 5282
5282 ISDN SUBSYSTEM 5283 ISDN SUBSYSTEM
5283 M: Karsten Keil <isdn@linux-pingi.de> 5284 M: Karsten Keil <isdn@linux-pingi.de>
5284 L: isdn4linux@listserv.isdn4linux.de (subscribers-only) 5285 L: isdn4linux@listserv.isdn4linux.de (subscribers-only)
5285 L: netdev@vger.kernel.org 5286 L: netdev@vger.kernel.org
5286 W: http://www.isdn4linux.de 5287 W: http://www.isdn4linux.de
5287 T: git git://git.kernel.org/pub/scm/linux/kernel/git/kkeil/isdn-2.6.git 5288 T: git git://git.kernel.org/pub/scm/linux/kernel/git/kkeil/isdn-2.6.git
5288 S: Maintained 5289 S: Maintained
5289 F: Documentation/isdn/ 5290 F: Documentation/isdn/
5290 F: drivers/isdn/ 5291 F: drivers/isdn/
5291 F: include/linux/isdn.h 5292 F: include/linux/isdn.h
5292 F: include/linux/isdn/ 5293 F: include/linux/isdn/
5293 F: include/uapi/linux/isdn.h 5294 F: include/uapi/linux/isdn.h
5294 F: include/uapi/linux/isdn/ 5295 F: include/uapi/linux/isdn/
5295 5296
5296 ISDN SUBSYSTEM (Eicon active card driver) 5297 ISDN SUBSYSTEM (Eicon active card driver)
5297 M: Armin Schindler <mac@melware.de> 5298 M: Armin Schindler <mac@melware.de>
5298 L: isdn4linux@listserv.isdn4linux.de (subscribers-only) 5299 L: isdn4linux@listserv.isdn4linux.de (subscribers-only)
5299 W: http://www.melware.de 5300 W: http://www.melware.de
5300 S: Maintained 5301 S: Maintained
5301 F: drivers/isdn/hardware/eicon/ 5302 F: drivers/isdn/hardware/eicon/
5302 5303
5303 IT87 HARDWARE MONITORING DRIVER 5304 IT87 HARDWARE MONITORING DRIVER
5304 M: Jean Delvare <jdelvare@suse.de> 5305 M: Jean Delvare <jdelvare@suse.de>
5305 L: lm-sensors@lm-sensors.org 5306 L: lm-sensors@lm-sensors.org
5306 S: Maintained 5307 S: Maintained
5307 F: Documentation/hwmon/it87 5308 F: Documentation/hwmon/it87
5308 F: drivers/hwmon/it87.c 5309 F: drivers/hwmon/it87.c
5309 5310
5310 IT913X MEDIA DRIVER 5311 IT913X MEDIA DRIVER
5311 M: Antti Palosaari <crope@iki.fi> 5312 M: Antti Palosaari <crope@iki.fi>
5312 L: linux-media@vger.kernel.org 5313 L: linux-media@vger.kernel.org
5313 W: http://linuxtv.org/ 5314 W: http://linuxtv.org/
5314 W: http://palosaari.fi/linux/ 5315 W: http://palosaari.fi/linux/
5315 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 5316 Q: http://patchwork.linuxtv.org/project/linux-media/list/
5316 T: git git://linuxtv.org/anttip/media_tree.git 5317 T: git git://linuxtv.org/anttip/media_tree.git
5317 S: Maintained 5318 S: Maintained
5318 F: drivers/media/tuners/it913x* 5319 F: drivers/media/tuners/it913x*
5319 5320
5320 IVTV VIDEO4LINUX DRIVER 5321 IVTV VIDEO4LINUX DRIVER
5321 M: Andy Walls <awalls@md.metrocast.net> 5322 M: Andy Walls <awalls@md.metrocast.net>
5322 L: ivtv-devel@ivtvdriver.org (subscribers-only) 5323 L: ivtv-devel@ivtvdriver.org (subscribers-only)
5323 L: linux-media@vger.kernel.org 5324 L: linux-media@vger.kernel.org
5324 T: git git://linuxtv.org/media_tree.git 5325 T: git git://linuxtv.org/media_tree.git
5325 W: http://www.ivtvdriver.org 5326 W: http://www.ivtvdriver.org
5326 S: Maintained 5327 S: Maintained
5327 F: Documentation/video4linux/*.ivtv 5328 F: Documentation/video4linux/*.ivtv
5328 F: drivers/media/pci/ivtv/ 5329 F: drivers/media/pci/ivtv/
5329 F: include/uapi/linux/ivtv* 5330 F: include/uapi/linux/ivtv*
5330 5331
5331 IX2505V MEDIA DRIVER 5332 IX2505V MEDIA DRIVER
5332 M: Malcolm Priestley <tvboxspy@gmail.com> 5333 M: Malcolm Priestley <tvboxspy@gmail.com>
5333 L: linux-media@vger.kernel.org 5334 L: linux-media@vger.kernel.org
5334 W: http://linuxtv.org/ 5335 W: http://linuxtv.org/
5335 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 5336 Q: http://patchwork.linuxtv.org/project/linux-media/list/
5336 S: Maintained 5337 S: Maintained
5337 F: drivers/media/dvb-frontends/ix2505v* 5338 F: drivers/media/dvb-frontends/ix2505v*
5338 5339
5339 JC42.4 TEMPERATURE SENSOR DRIVER 5340 JC42.4 TEMPERATURE SENSOR DRIVER
5340 M: Guenter Roeck <linux@roeck-us.net> 5341 M: Guenter Roeck <linux@roeck-us.net>
5341 L: lm-sensors@lm-sensors.org 5342 L: lm-sensors@lm-sensors.org
5342 S: Maintained 5343 S: Maintained
5343 F: drivers/hwmon/jc42.c 5344 F: drivers/hwmon/jc42.c
5344 F: Documentation/hwmon/jc42 5345 F: Documentation/hwmon/jc42
5345 5346
5346 JFS FILESYSTEM 5347 JFS FILESYSTEM
5347 M: Dave Kleikamp <shaggy@kernel.org> 5348 M: Dave Kleikamp <shaggy@kernel.org>
5348 L: jfs-discussion@lists.sourceforge.net 5349 L: jfs-discussion@lists.sourceforge.net
5349 W: http://jfs.sourceforge.net/ 5350 W: http://jfs.sourceforge.net/
5350 T: git git://git.kernel.org/pub/scm/linux/kernel/git/shaggy/jfs-2.6.git 5351 T: git git://git.kernel.org/pub/scm/linux/kernel/git/shaggy/jfs-2.6.git
5351 S: Maintained 5352 S: Maintained
5352 F: Documentation/filesystems/jfs.txt 5353 F: Documentation/filesystems/jfs.txt
5353 F: fs/jfs/ 5354 F: fs/jfs/
5354 5355
5355 JME NETWORK DRIVER 5356 JME NETWORK DRIVER
5356 M: Guo-Fu Tseng <cooldavid@cooldavid.org> 5357 M: Guo-Fu Tseng <cooldavid@cooldavid.org>
5357 L: netdev@vger.kernel.org 5358 L: netdev@vger.kernel.org
5358 S: Maintained 5359 S: Maintained
5359 F: drivers/net/ethernet/jme.* 5360 F: drivers/net/ethernet/jme.*
5360 5361
5361 JOURNALLING FLASH FILE SYSTEM V2 (JFFS2) 5362 JOURNALLING FLASH FILE SYSTEM V2 (JFFS2)
5362 M: David Woodhouse <dwmw2@infradead.org> 5363 M: David Woodhouse <dwmw2@infradead.org>
5363 L: linux-mtd@lists.infradead.org 5364 L: linux-mtd@lists.infradead.org
5364 W: http://www.linux-mtd.infradead.org/doc/jffs2.html 5365 W: http://www.linux-mtd.infradead.org/doc/jffs2.html
5365 S: Maintained 5366 S: Maintained
5366 F: fs/jffs2/ 5367 F: fs/jffs2/
5367 F: include/uapi/linux/jffs2.h 5368 F: include/uapi/linux/jffs2.h
5368 5369
5369 JOURNALLING LAYER FOR BLOCK DEVICES (JBD) 5370 JOURNALLING LAYER FOR BLOCK DEVICES (JBD)
5370 M: Andrew Morton <akpm@linux-foundation.org> 5371 M: Andrew Morton <akpm@linux-foundation.org>
5371 M: Jan Kara <jack@suse.cz> 5372 M: Jan Kara <jack@suse.cz>
5372 L: linux-ext4@vger.kernel.org 5373 L: linux-ext4@vger.kernel.org
5373 S: Maintained 5374 S: Maintained
5374 F: fs/jbd/ 5375 F: fs/jbd/
5375 F: include/linux/jbd.h 5376 F: include/linux/jbd.h
5376 5377
5377 JOURNALLING LAYER FOR BLOCK DEVICES (JBD2) 5378 JOURNALLING LAYER FOR BLOCK DEVICES (JBD2)
5378 M: "Theodore Ts'o" <tytso@mit.edu> 5379 M: "Theodore Ts'o" <tytso@mit.edu>
5379 L: linux-ext4@vger.kernel.org 5380 L: linux-ext4@vger.kernel.org
5380 S: Maintained 5381 S: Maintained
5381 F: fs/jbd2/ 5382 F: fs/jbd2/
5382 F: include/linux/jbd2.h 5383 F: include/linux/jbd2.h
5383 5384
5384 JSM Neo PCI based serial card 5385 JSM Neo PCI based serial card
5385 M: Thadeu Lima de Souza Cascardo <cascardo@linux.vnet.ibm.com> 5386 M: Thadeu Lima de Souza Cascardo <cascardo@linux.vnet.ibm.com>
5386 L: linux-serial@vger.kernel.org 5387 L: linux-serial@vger.kernel.org
5387 S: Maintained 5388 S: Maintained
5388 F: drivers/tty/serial/jsm/ 5389 F: drivers/tty/serial/jsm/
5389 5390
5390 K10TEMP HARDWARE MONITORING DRIVER 5391 K10TEMP HARDWARE MONITORING DRIVER
5391 M: Clemens Ladisch <clemens@ladisch.de> 5392 M: Clemens Ladisch <clemens@ladisch.de>
5392 L: lm-sensors@lm-sensors.org 5393 L: lm-sensors@lm-sensors.org
5393 S: Maintained 5394 S: Maintained
5394 F: Documentation/hwmon/k10temp 5395 F: Documentation/hwmon/k10temp
5395 F: drivers/hwmon/k10temp.c 5396 F: drivers/hwmon/k10temp.c
5396 5397
5397 K8TEMP HARDWARE MONITORING DRIVER 5398 K8TEMP HARDWARE MONITORING DRIVER
5398 M: Rudolf Marek <r.marek@assembler.cz> 5399 M: Rudolf Marek <r.marek@assembler.cz>
5399 L: lm-sensors@lm-sensors.org 5400 L: lm-sensors@lm-sensors.org
5400 S: Maintained 5401 S: Maintained
5401 F: Documentation/hwmon/k8temp 5402 F: Documentation/hwmon/k8temp
5402 F: drivers/hwmon/k8temp.c 5403 F: drivers/hwmon/k8temp.c
5403 5404
5404 KCONFIG 5405 KCONFIG
5405 M: "Yann E. MORIN" <yann.morin.1998@free.fr> 5406 M: "Yann E. MORIN" <yann.morin.1998@free.fr>
5406 L: linux-kbuild@vger.kernel.org 5407 L: linux-kbuild@vger.kernel.org
5407 T: git git://gitorious.org/linux-kconfig/linux-kconfig 5408 T: git git://gitorious.org/linux-kconfig/linux-kconfig
5408 S: Maintained 5409 S: Maintained
5409 F: Documentation/kbuild/kconfig-language.txt 5410 F: Documentation/kbuild/kconfig-language.txt
5410 F: scripts/kconfig/ 5411 F: scripts/kconfig/
5411 5412
5412 KDUMP 5413 KDUMP
5413 M: Vivek Goyal <vgoyal@redhat.com> 5414 M: Vivek Goyal <vgoyal@redhat.com>
5414 M: Haren Myneni <hbabu@us.ibm.com> 5415 M: Haren Myneni <hbabu@us.ibm.com>
5415 L: kexec@lists.infradead.org 5416 L: kexec@lists.infradead.org
5416 W: http://lse.sourceforge.net/kdump/ 5417 W: http://lse.sourceforge.net/kdump/
5417 S: Maintained 5418 S: Maintained
5418 F: Documentation/kdump/ 5419 F: Documentation/kdump/
5419 5420
5420 KEENE FM RADIO TRANSMITTER DRIVER 5421 KEENE FM RADIO TRANSMITTER DRIVER
5421 M: Hans Verkuil <hverkuil@xs4all.nl> 5422 M: Hans Verkuil <hverkuil@xs4all.nl>
5422 L: linux-media@vger.kernel.org 5423 L: linux-media@vger.kernel.org
5423 T: git git://linuxtv.org/media_tree.git 5424 T: git git://linuxtv.org/media_tree.git
5424 W: http://linuxtv.org 5425 W: http://linuxtv.org
5425 S: Maintained 5426 S: Maintained
5426 F: drivers/media/radio/radio-keene* 5427 F: drivers/media/radio/radio-keene*
5427 5428
5428 KERNEL AUTOMOUNTER v4 (AUTOFS4) 5429 KERNEL AUTOMOUNTER v4 (AUTOFS4)
5429 M: Ian Kent <raven@themaw.net> 5430 M: Ian Kent <raven@themaw.net>
5430 L: autofs@vger.kernel.org 5431 L: autofs@vger.kernel.org
5431 S: Maintained 5432 S: Maintained
5432 F: fs/autofs4/ 5433 F: fs/autofs4/
5433 5434
5434 KERNEL BUILD + files below scripts/ (unless maintained elsewhere) 5435 KERNEL BUILD + files below scripts/ (unless maintained elsewhere)
5435 M: Michal Marek <mmarek@suse.cz> 5436 M: Michal Marek <mmarek@suse.cz>
5436 T: git git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild.git for-next 5437 T: git git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild.git for-next
5437 T: git git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild.git rc-fixes 5438 T: git git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild.git rc-fixes
5438 L: linux-kbuild@vger.kernel.org 5439 L: linux-kbuild@vger.kernel.org
5439 S: Maintained 5440 S: Maintained
5440 F: Documentation/kbuild/ 5441 F: Documentation/kbuild/
5441 F: Makefile 5442 F: Makefile
5442 F: scripts/Makefile.* 5443 F: scripts/Makefile.*
5443 F: scripts/basic/ 5444 F: scripts/basic/
5444 F: scripts/mk* 5445 F: scripts/mk*
5445 F: scripts/package/ 5446 F: scripts/package/
5446 5447
5447 KERNEL JANITORS 5448 KERNEL JANITORS
5448 L: kernel-janitors@vger.kernel.org 5449 L: kernel-janitors@vger.kernel.org
5449 W: http://kernelnewbies.org/KernelJanitors 5450 W: http://kernelnewbies.org/KernelJanitors
5450 S: Odd Fixes 5451 S: Odd Fixes
5451 5452
5452 KERNEL NFSD, SUNRPC, AND LOCKD SERVERS 5453 KERNEL NFSD, SUNRPC, AND LOCKD SERVERS
5453 M: "J. Bruce Fields" <bfields@fieldses.org> 5454 M: "J. Bruce Fields" <bfields@fieldses.org>
5454 L: linux-nfs@vger.kernel.org 5455 L: linux-nfs@vger.kernel.org
5455 W: http://nfs.sourceforge.net/ 5456 W: http://nfs.sourceforge.net/
5456 S: Supported 5457 S: Supported
5457 F: fs/nfsd/ 5458 F: fs/nfsd/
5458 F: include/uapi/linux/nfsd/ 5459 F: include/uapi/linux/nfsd/
5459 F: fs/lockd/ 5460 F: fs/lockd/
5460 F: fs/nfs_common/ 5461 F: fs/nfs_common/
5461 F: net/sunrpc/ 5462 F: net/sunrpc/
5462 F: include/linux/lockd/ 5463 F: include/linux/lockd/
5463 F: include/linux/sunrpc/ 5464 F: include/linux/sunrpc/
5464 F: include/uapi/linux/sunrpc/ 5465 F: include/uapi/linux/sunrpc/
5465 5466
5466 KERNEL SELFTEST FRAMEWORK 5467 KERNEL SELFTEST FRAMEWORK
5467 M: Shuah Khan <shuahkh@osg.samsung.com> 5468 M: Shuah Khan <shuahkh@osg.samsung.com>
5468 L: linux-api@vger.kernel.org 5469 L: linux-api@vger.kernel.org
5469 T: git git://git.kernel.org/pub/scm/shuah/linux-kselftest 5470 T: git git://git.kernel.org/pub/scm/shuah/linux-kselftest
5470 S: Maintained 5471 S: Maintained
5471 F: tools/testing/selftests 5472 F: tools/testing/selftests
5472 5473
5473 KERNEL VIRTUAL MACHINE (KVM) 5474 KERNEL VIRTUAL MACHINE (KVM)
5474 M: Gleb Natapov <gleb@kernel.org> 5475 M: Gleb Natapov <gleb@kernel.org>
5475 M: Paolo Bonzini <pbonzini@redhat.com> 5476 M: Paolo Bonzini <pbonzini@redhat.com>
5476 L: kvm@vger.kernel.org 5477 L: kvm@vger.kernel.org
5477 W: http://www.linux-kvm.org 5478 W: http://www.linux-kvm.org
5478 T: git git://git.kernel.org/pub/scm/virt/kvm/kvm.git 5479 T: git git://git.kernel.org/pub/scm/virt/kvm/kvm.git
5479 S: Supported 5480 S: Supported
5480 F: Documentation/*/kvm*.txt 5481 F: Documentation/*/kvm*.txt
5481 F: Documentation/virtual/kvm/ 5482 F: Documentation/virtual/kvm/
5482 F: arch/*/kvm/ 5483 F: arch/*/kvm/
5483 F: arch/*/include/asm/kvm* 5484 F: arch/*/include/asm/kvm*
5484 F: include/linux/kvm* 5485 F: include/linux/kvm*
5485 F: include/uapi/linux/kvm* 5486 F: include/uapi/linux/kvm*
5486 F: virt/kvm/ 5487 F: virt/kvm/
5487 5488
5488 KERNEL VIRTUAL MACHINE (KVM) FOR AMD-V 5489 KERNEL VIRTUAL MACHINE (KVM) FOR AMD-V
5489 M: Joerg Roedel <joro@8bytes.org> 5490 M: Joerg Roedel <joro@8bytes.org>
5490 L: kvm@vger.kernel.org 5491 L: kvm@vger.kernel.org
5491 W: http://kvm.qumranet.com 5492 W: http://kvm.qumranet.com
5492 S: Maintained 5493 S: Maintained
5493 F: arch/x86/include/asm/svm.h 5494 F: arch/x86/include/asm/svm.h
5494 F: arch/x86/kvm/svm.c 5495 F: arch/x86/kvm/svm.c
5495 5496
5496 KERNEL VIRTUAL MACHINE (KVM) FOR POWERPC 5497 KERNEL VIRTUAL MACHINE (KVM) FOR POWERPC
5497 M: Alexander Graf <agraf@suse.de> 5498 M: Alexander Graf <agraf@suse.de>
5498 L: kvm-ppc@vger.kernel.org 5499 L: kvm-ppc@vger.kernel.org
5499 W: http://kvm.qumranet.com 5500 W: http://kvm.qumranet.com
5500 T: git git://github.com/agraf/linux-2.6.git 5501 T: git git://github.com/agraf/linux-2.6.git
5501 S: Supported 5502 S: Supported
5502 F: arch/powerpc/include/asm/kvm* 5503 F: arch/powerpc/include/asm/kvm*
5503 F: arch/powerpc/kvm/ 5504 F: arch/powerpc/kvm/
5504 5505
5505 KERNEL VIRTUAL MACHINE for s390 (KVM/s390) 5506 KERNEL VIRTUAL MACHINE for s390 (KVM/s390)
5506 M: Christian Borntraeger <borntraeger@de.ibm.com> 5507 M: Christian Borntraeger <borntraeger@de.ibm.com>
5507 M: Cornelia Huck <cornelia.huck@de.ibm.com> 5508 M: Cornelia Huck <cornelia.huck@de.ibm.com>
5508 M: linux390@de.ibm.com 5509 M: linux390@de.ibm.com
5509 L: linux-s390@vger.kernel.org 5510 L: linux-s390@vger.kernel.org
5510 W: http://www.ibm.com/developerworks/linux/linux390/ 5511 W: http://www.ibm.com/developerworks/linux/linux390/
5511 S: Supported 5512 S: Supported
5512 F: Documentation/s390/kvm.txt 5513 F: Documentation/s390/kvm.txt
5513 F: arch/s390/include/asm/kvm* 5514 F: arch/s390/include/asm/kvm*
5514 F: arch/s390/kvm/ 5515 F: arch/s390/kvm/
5515 F: drivers/s390/kvm/ 5516 F: drivers/s390/kvm/
5516 5517
5517 KERNEL VIRTUAL MACHINE (KVM) FOR ARM 5518 KERNEL VIRTUAL MACHINE (KVM) FOR ARM
5518 M: Christoffer Dall <christoffer.dall@linaro.org> 5519 M: Christoffer Dall <christoffer.dall@linaro.org>
5519 M: Marc Zyngier <marc.zyngier@arm.com> 5520 M: Marc Zyngier <marc.zyngier@arm.com>
5520 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 5521 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
5521 L: kvmarm@lists.cs.columbia.edu 5522 L: kvmarm@lists.cs.columbia.edu
5522 W: http://systems.cs.columbia.edu/projects/kvm-arm 5523 W: http://systems.cs.columbia.edu/projects/kvm-arm
5523 S: Supported 5524 S: Supported
5524 F: arch/arm/include/uapi/asm/kvm* 5525 F: arch/arm/include/uapi/asm/kvm*
5525 F: arch/arm/include/asm/kvm* 5526 F: arch/arm/include/asm/kvm*
5526 F: arch/arm/kvm/ 5527 F: arch/arm/kvm/
5527 F: virt/kvm/arm/ 5528 F: virt/kvm/arm/
5528 F: include/kvm/arm_* 5529 F: include/kvm/arm_*
5529 5530
5530 KERNEL VIRTUAL MACHINE FOR ARM64 (KVM/arm64) 5531 KERNEL VIRTUAL MACHINE FOR ARM64 (KVM/arm64)
5531 M: Christoffer Dall <christoffer.dall@linaro.org> 5532 M: Christoffer Dall <christoffer.dall@linaro.org>
5532 M: Marc Zyngier <marc.zyngier@arm.com> 5533 M: Marc Zyngier <marc.zyngier@arm.com>
5533 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 5534 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
5534 L: kvmarm@lists.cs.columbia.edu 5535 L: kvmarm@lists.cs.columbia.edu
5535 S: Maintained 5536 S: Maintained
5536 F: arch/arm64/include/uapi/asm/kvm* 5537 F: arch/arm64/include/uapi/asm/kvm*
5537 F: arch/arm64/include/asm/kvm* 5538 F: arch/arm64/include/asm/kvm*
5538 F: arch/arm64/kvm/ 5539 F: arch/arm64/kvm/
5539 5540
5540 KEXEC 5541 KEXEC
5541 M: Eric Biederman <ebiederm@xmission.com> 5542 M: Eric Biederman <ebiederm@xmission.com>
5542 W: http://kernel.org/pub/linux/utils/kernel/kexec/ 5543 W: http://kernel.org/pub/linux/utils/kernel/kexec/
5543 L: kexec@lists.infradead.org 5544 L: kexec@lists.infradead.org
5544 S: Maintained 5545 S: Maintained
5545 F: include/linux/kexec.h 5546 F: include/linux/kexec.h
5546 F: include/uapi/linux/kexec.h 5547 F: include/uapi/linux/kexec.h
5547 F: kernel/kexec.c 5548 F: kernel/kexec.c
5548 5549
5549 KEYS/KEYRINGS: 5550 KEYS/KEYRINGS:
5550 M: David Howells <dhowells@redhat.com> 5551 M: David Howells <dhowells@redhat.com>
5551 L: keyrings@linux-nfs.org 5552 L: keyrings@linux-nfs.org
5552 S: Maintained 5553 S: Maintained
5553 F: Documentation/security/keys.txt 5554 F: Documentation/security/keys.txt
5554 F: include/linux/key.h 5555 F: include/linux/key.h
5555 F: include/linux/key-type.h 5556 F: include/linux/key-type.h
5556 F: include/keys/ 5557 F: include/keys/
5557 F: security/keys/ 5558 F: security/keys/
5558 5559
5559 KEYS-TRUSTED 5560 KEYS-TRUSTED
5560 M: David Safford <safford@us.ibm.com> 5561 M: David Safford <safford@us.ibm.com>
5561 M: Mimi Zohar <zohar@linux.vnet.ibm.com> 5562 M: Mimi Zohar <zohar@linux.vnet.ibm.com>
5562 L: linux-security-module@vger.kernel.org 5563 L: linux-security-module@vger.kernel.org
5563 L: keyrings@linux-nfs.org 5564 L: keyrings@linux-nfs.org
5564 S: Supported 5565 S: Supported
5565 F: Documentation/security/keys-trusted-encrypted.txt 5566 F: Documentation/security/keys-trusted-encrypted.txt
5566 F: include/keys/trusted-type.h 5567 F: include/keys/trusted-type.h
5567 F: security/keys/trusted.c 5568 F: security/keys/trusted.c
5568 F: security/keys/trusted.h 5569 F: security/keys/trusted.h
5569 5570
5570 KEYS-ENCRYPTED 5571 KEYS-ENCRYPTED
5571 M: Mimi Zohar <zohar@linux.vnet.ibm.com> 5572 M: Mimi Zohar <zohar@linux.vnet.ibm.com>
5572 M: David Safford <safford@us.ibm.com> 5573 M: David Safford <safford@us.ibm.com>
5573 L: linux-security-module@vger.kernel.org 5574 L: linux-security-module@vger.kernel.org
5574 L: keyrings@linux-nfs.org 5575 L: keyrings@linux-nfs.org
5575 S: Supported 5576 S: Supported
5576 F: Documentation/security/keys-trusted-encrypted.txt 5577 F: Documentation/security/keys-trusted-encrypted.txt
5577 F: include/keys/encrypted-type.h 5578 F: include/keys/encrypted-type.h
5578 F: security/keys/encrypted-keys/ 5579 F: security/keys/encrypted-keys/
5579 5580
5580 KGDB / KDB /debug_core 5581 KGDB / KDB /debug_core
5581 M: Jason Wessel <jason.wessel@windriver.com> 5582 M: Jason Wessel <jason.wessel@windriver.com>
5582 W: http://kgdb.wiki.kernel.org/ 5583 W: http://kgdb.wiki.kernel.org/
5583 L: kgdb-bugreport@lists.sourceforge.net 5584 L: kgdb-bugreport@lists.sourceforge.net
5584 S: Maintained 5585 S: Maintained
5585 F: Documentation/DocBook/kgdb.tmpl 5586 F: Documentation/DocBook/kgdb.tmpl
5586 F: drivers/misc/kgdbts.c 5587 F: drivers/misc/kgdbts.c
5587 F: drivers/tty/serial/kgdboc.c 5588 F: drivers/tty/serial/kgdboc.c
5588 F: include/linux/kdb.h 5589 F: include/linux/kdb.h
5589 F: include/linux/kgdb.h 5590 F: include/linux/kgdb.h
5590 F: kernel/debug/ 5591 F: kernel/debug/
5591 5592
5592 KMEMCHECK 5593 KMEMCHECK
5593 M: Vegard Nossum <vegardno@ifi.uio.no> 5594 M: Vegard Nossum <vegardno@ifi.uio.no>
5594 M: Pekka Enberg <penberg@kernel.org> 5595 M: Pekka Enberg <penberg@kernel.org>
5595 S: Maintained 5596 S: Maintained
5596 F: Documentation/kmemcheck.txt 5597 F: Documentation/kmemcheck.txt
5597 F: arch/x86/include/asm/kmemcheck.h 5598 F: arch/x86/include/asm/kmemcheck.h
5598 F: arch/x86/mm/kmemcheck/ 5599 F: arch/x86/mm/kmemcheck/
5599 F: include/linux/kmemcheck.h 5600 F: include/linux/kmemcheck.h
5600 F: mm/kmemcheck.c 5601 F: mm/kmemcheck.c
5601 5602
5602 KMEMLEAK 5603 KMEMLEAK
5603 M: Catalin Marinas <catalin.marinas@arm.com> 5604 M: Catalin Marinas <catalin.marinas@arm.com>
5604 S: Maintained 5605 S: Maintained
5605 F: Documentation/kmemleak.txt 5606 F: Documentation/kmemleak.txt
5606 F: include/linux/kmemleak.h 5607 F: include/linux/kmemleak.h
5607 F: mm/kmemleak.c 5608 F: mm/kmemleak.c
5608 F: mm/kmemleak-test.c 5609 F: mm/kmemleak-test.c
5609 5610
5610 KPROBES 5611 KPROBES
5611 M: Ananth N Mavinakayanahalli <ananth@in.ibm.com> 5612 M: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
5612 M: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com> 5613 M: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
5613 M: "David S. Miller" <davem@davemloft.net> 5614 M: "David S. Miller" <davem@davemloft.net>
5614 M: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> 5615 M: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
5615 S: Maintained 5616 S: Maintained
5616 F: Documentation/kprobes.txt 5617 F: Documentation/kprobes.txt
5617 F: include/linux/kprobes.h 5618 F: include/linux/kprobes.h
5618 F: kernel/kprobes.c 5619 F: kernel/kprobes.c
5619 5620
5620 KS0108 LCD CONTROLLER DRIVER 5621 KS0108 LCD CONTROLLER DRIVER
5621 M: Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com> 5622 M: Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>
5622 W: http://miguelojeda.es/auxdisplay.htm 5623 W: http://miguelojeda.es/auxdisplay.htm
5623 W: http://jair.lab.fi.uva.es/~migojed/auxdisplay.htm 5624 W: http://jair.lab.fi.uva.es/~migojed/auxdisplay.htm
5624 S: Maintained 5625 S: Maintained
5625 F: Documentation/auxdisplay/ks0108 5626 F: Documentation/auxdisplay/ks0108
5626 F: drivers/auxdisplay/ks0108.c 5627 F: drivers/auxdisplay/ks0108.c
5627 F: include/linux/ks0108.h 5628 F: include/linux/ks0108.h
5628 5629
5629 LAPB module 5630 LAPB module
5630 L: linux-x25@vger.kernel.org 5631 L: linux-x25@vger.kernel.org
5631 S: Orphan 5632 S: Orphan
5632 F: Documentation/networking/lapb-module.txt 5633 F: Documentation/networking/lapb-module.txt
5633 F: include/*/lapb.h 5634 F: include/*/lapb.h
5634 F: net/lapb/ 5635 F: net/lapb/
5635 5636
5636 LASI 53c700 driver for PARISC 5637 LASI 53c700 driver for PARISC
5637 M: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com> 5638 M: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
5638 L: linux-scsi@vger.kernel.org 5639 L: linux-scsi@vger.kernel.org
5639 S: Maintained 5640 S: Maintained
5640 F: Documentation/scsi/53c700.txt 5641 F: Documentation/scsi/53c700.txt
5641 F: drivers/scsi/53c700* 5642 F: drivers/scsi/53c700*
5642 5643
5643 LED SUBSYSTEM 5644 LED SUBSYSTEM
5644 M: Bryan Wu <cooloney@gmail.com> 5645 M: Bryan Wu <cooloney@gmail.com>
5645 M: Richard Purdie <rpurdie@rpsys.net> 5646 M: Richard Purdie <rpurdie@rpsys.net>
5646 L: linux-leds@vger.kernel.org 5647 L: linux-leds@vger.kernel.org
5647 T: git git://git.kernel.org/pub/scm/linux/kernel/git/cooloney/linux-leds.git 5648 T: git git://git.kernel.org/pub/scm/linux/kernel/git/cooloney/linux-leds.git
5648 S: Maintained 5649 S: Maintained
5649 F: drivers/leds/ 5650 F: drivers/leds/
5650 F: include/linux/leds.h 5651 F: include/linux/leds.h
5651 5652
5652 LEGACY EEPROM DRIVER 5653 LEGACY EEPROM DRIVER
5653 M: Jean Delvare <jdelvare@suse.de> 5654 M: Jean Delvare <jdelvare@suse.de>
5654 S: Maintained 5655 S: Maintained
5655 F: Documentation/misc-devices/eeprom 5656 F: Documentation/misc-devices/eeprom
5656 F: drivers/misc/eeprom/eeprom.c 5657 F: drivers/misc/eeprom/eeprom.c
5657 5658
5658 LEGO USB Tower driver 5659 LEGO USB Tower driver
5659 M: Juergen Stuber <starblue@users.sourceforge.net> 5660 M: Juergen Stuber <starblue@users.sourceforge.net>
5660 L: legousb-devel@lists.sourceforge.net 5661 L: legousb-devel@lists.sourceforge.net
5661 W: http://legousb.sourceforge.net/ 5662 W: http://legousb.sourceforge.net/
5662 S: Maintained 5663 S: Maintained
5663 F: drivers/usb/misc/legousbtower.c 5664 F: drivers/usb/misc/legousbtower.c
5664 5665
5665 LG2160 MEDIA DRIVER 5666 LG2160 MEDIA DRIVER
5666 M: Michael Krufky <mkrufky@linuxtv.org> 5667 M: Michael Krufky <mkrufky@linuxtv.org>
5667 L: linux-media@vger.kernel.org 5668 L: linux-media@vger.kernel.org
5668 W: http://linuxtv.org/ 5669 W: http://linuxtv.org/
5669 W: http://github.com/mkrufky 5670 W: http://github.com/mkrufky
5670 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 5671 Q: http://patchwork.linuxtv.org/project/linux-media/list/
5671 T: git git://linuxtv.org/mkrufky/tuners.git 5672 T: git git://linuxtv.org/mkrufky/tuners.git
5672 S: Maintained 5673 S: Maintained
5673 F: drivers/media/dvb-frontends/lg2160.* 5674 F: drivers/media/dvb-frontends/lg2160.*
5674 5675
5675 LGDT3305 MEDIA DRIVER 5676 LGDT3305 MEDIA DRIVER
5676 M: Michael Krufky <mkrufky@linuxtv.org> 5677 M: Michael Krufky <mkrufky@linuxtv.org>
5677 L: linux-media@vger.kernel.org 5678 L: linux-media@vger.kernel.org
5678 W: http://linuxtv.org/ 5679 W: http://linuxtv.org/
5679 W: http://github.com/mkrufky 5680 W: http://github.com/mkrufky
5680 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 5681 Q: http://patchwork.linuxtv.org/project/linux-media/list/
5681 T: git git://linuxtv.org/mkrufky/tuners.git 5682 T: git git://linuxtv.org/mkrufky/tuners.git
5682 S: Maintained 5683 S: Maintained
5683 F: drivers/media/dvb-frontends/lgdt3305.* 5684 F: drivers/media/dvb-frontends/lgdt3305.*
5684 5685
5685 LGUEST 5686 LGUEST
5686 M: Rusty Russell <rusty@rustcorp.com.au> 5687 M: Rusty Russell <rusty@rustcorp.com.au>
5687 L: lguest@lists.ozlabs.org 5688 L: lguest@lists.ozlabs.org
5688 W: http://lguest.ozlabs.org/ 5689 W: http://lguest.ozlabs.org/
5689 S: Odd Fixes 5690 S: Odd Fixes
5690 F: arch/x86/include/asm/lguest*.h 5691 F: arch/x86/include/asm/lguest*.h
5691 F: arch/x86/lguest/ 5692 F: arch/x86/lguest/
5692 F: drivers/lguest/ 5693 F: drivers/lguest/
5693 F: include/linux/lguest*.h 5694 F: include/linux/lguest*.h
5694 F: tools/lguest/ 5695 F: tools/lguest/
5695 5696
5696 LIBLOCKDEP 5697 LIBLOCKDEP
5697 M: Sasha Levin <sasha.levin@oracle.com> 5698 M: Sasha Levin <sasha.levin@oracle.com>
5698 S: Maintained 5699 S: Maintained
5699 F: tools/lib/lockdep/ 5700 F: tools/lib/lockdep/
5700 5701
5701 LINUX FOR IBM pSERIES (RS/6000) 5702 LINUX FOR IBM pSERIES (RS/6000)
5702 M: Paul Mackerras <paulus@au.ibm.com> 5703 M: Paul Mackerras <paulus@au.ibm.com>
5703 W: http://www.ibm.com/linux/ltc/projects/ppc 5704 W: http://www.ibm.com/linux/ltc/projects/ppc
5704 S: Supported 5705 S: Supported
5705 F: arch/powerpc/boot/rs6000.h 5706 F: arch/powerpc/boot/rs6000.h
5706 5707
5707 LINUX FOR POWERPC (32-BIT AND 64-BIT) 5708 LINUX FOR POWERPC (32-BIT AND 64-BIT)
5708 M: Benjamin Herrenschmidt <benh@kernel.crashing.org> 5709 M: Benjamin Herrenschmidt <benh@kernel.crashing.org>
5709 M: Paul Mackerras <paulus@samba.org> 5710 M: Paul Mackerras <paulus@samba.org>
5710 M: Michael Ellerman <mpe@ellerman.id.au> 5711 M: Michael Ellerman <mpe@ellerman.id.au>
5711 W: http://www.penguinppc.org/ 5712 W: http://www.penguinppc.org/
5712 L: linuxppc-dev@lists.ozlabs.org 5713 L: linuxppc-dev@lists.ozlabs.org
5713 Q: http://patchwork.ozlabs.org/project/linuxppc-dev/list/ 5714 Q: http://patchwork.ozlabs.org/project/linuxppc-dev/list/
5714 T: git git://git.kernel.org/pub/scm/linux/kernel/git/benh/powerpc.git 5715 T: git git://git.kernel.org/pub/scm/linux/kernel/git/benh/powerpc.git
5715 S: Supported 5716 S: Supported
5716 F: Documentation/powerpc/ 5717 F: Documentation/powerpc/
5717 F: arch/powerpc/ 5718 F: arch/powerpc/
5718 5719
5719 LINUX FOR POWER MACINTOSH 5720 LINUX FOR POWER MACINTOSH
5720 M: Benjamin Herrenschmidt <benh@kernel.crashing.org> 5721 M: Benjamin Herrenschmidt <benh@kernel.crashing.org>
5721 W: http://www.penguinppc.org/ 5722 W: http://www.penguinppc.org/
5722 L: linuxppc-dev@lists.ozlabs.org 5723 L: linuxppc-dev@lists.ozlabs.org
5723 S: Maintained 5724 S: Maintained
5724 F: arch/powerpc/platforms/powermac/ 5725 F: arch/powerpc/platforms/powermac/
5725 F: drivers/macintosh/ 5726 F: drivers/macintosh/
5726 5727
5727 LINUX FOR POWERPC EMBEDDED MPC5XXX 5728 LINUX FOR POWERPC EMBEDDED MPC5XXX
5728 M: Anatolij Gustschin <agust@denx.de> 5729 M: Anatolij Gustschin <agust@denx.de>
5729 L: linuxppc-dev@lists.ozlabs.org 5730 L: linuxppc-dev@lists.ozlabs.org
5730 T: git git://git.denx.de/linux-denx-agust.git 5731 T: git git://git.denx.de/linux-denx-agust.git
5731 S: Maintained 5732 S: Maintained
5732 F: arch/powerpc/platforms/512x/ 5733 F: arch/powerpc/platforms/512x/
5733 F: arch/powerpc/platforms/52xx/ 5734 F: arch/powerpc/platforms/52xx/
5734 5735
5735 LINUX FOR POWERPC EMBEDDED PPC4XX 5736 LINUX FOR POWERPC EMBEDDED PPC4XX
5736 M: Alistair Popple <alistair@popple.id.au> 5737 M: Alistair Popple <alistair@popple.id.au>
5737 M: Matt Porter <mporter@kernel.crashing.org> 5738 M: Matt Porter <mporter@kernel.crashing.org>
5738 W: http://www.penguinppc.org/ 5739 W: http://www.penguinppc.org/
5739 L: linuxppc-dev@lists.ozlabs.org 5740 L: linuxppc-dev@lists.ozlabs.org
5740 S: Maintained 5741 S: Maintained
5741 F: arch/powerpc/platforms/40x/ 5742 F: arch/powerpc/platforms/40x/
5742 F: arch/powerpc/platforms/44x/ 5743 F: arch/powerpc/platforms/44x/
5743 5744
5744 LINUX FOR POWERPC EMBEDDED XILINX VIRTEX 5745 LINUX FOR POWERPC EMBEDDED XILINX VIRTEX
5745 L: linuxppc-dev@lists.ozlabs.org 5746 L: linuxppc-dev@lists.ozlabs.org
5746 S: Orphan 5747 S: Orphan
5747 F: arch/powerpc/*/*virtex* 5748 F: arch/powerpc/*/*virtex*
5748 F: arch/powerpc/*/*/*virtex* 5749 F: arch/powerpc/*/*/*virtex*
5749 5750
5750 LINUX FOR POWERPC EMBEDDED PPC8XX 5751 LINUX FOR POWERPC EMBEDDED PPC8XX
5751 M: Vitaly Bordug <vitb@kernel.crashing.org> 5752 M: Vitaly Bordug <vitb@kernel.crashing.org>
5752 W: http://www.penguinppc.org/ 5753 W: http://www.penguinppc.org/
5753 L: linuxppc-dev@lists.ozlabs.org 5754 L: linuxppc-dev@lists.ozlabs.org
5754 S: Maintained 5755 S: Maintained
5755 F: arch/powerpc/platforms/8xx/ 5756 F: arch/powerpc/platforms/8xx/
5756 5757
5757 LINUX FOR POWERPC EMBEDDED PPC83XX AND PPC85XX 5758 LINUX FOR POWERPC EMBEDDED PPC83XX AND PPC85XX
5758 M: Scott Wood <scottwood@freescale.com> 5759 M: Scott Wood <scottwood@freescale.com>
5759 M: Kumar Gala <galak@kernel.crashing.org> 5760 M: Kumar Gala <galak@kernel.crashing.org>
5760 W: http://www.penguinppc.org/ 5761 W: http://www.penguinppc.org/
5761 L: linuxppc-dev@lists.ozlabs.org 5762 L: linuxppc-dev@lists.ozlabs.org
5762 T: git git://git.kernel.org/pub/scm/linux/kernel/git/scottwood/linux.git 5763 T: git git://git.kernel.org/pub/scm/linux/kernel/git/scottwood/linux.git
5763 S: Maintained 5764 S: Maintained
5764 F: arch/powerpc/platforms/83xx/ 5765 F: arch/powerpc/platforms/83xx/
5765 F: arch/powerpc/platforms/85xx/ 5766 F: arch/powerpc/platforms/85xx/
5766 5767
5767 LINUX FOR POWERPC PA SEMI PWRFICIENT 5768 LINUX FOR POWERPC PA SEMI PWRFICIENT
5768 M: Olof Johansson <olof@lixom.net> 5769 M: Olof Johansson <olof@lixom.net>
5769 L: linuxppc-dev@lists.ozlabs.org 5770 L: linuxppc-dev@lists.ozlabs.org
5770 S: Maintained 5771 S: Maintained
5771 F: arch/powerpc/platforms/pasemi/ 5772 F: arch/powerpc/platforms/pasemi/
5772 F: drivers/*/*pasemi* 5773 F: drivers/*/*pasemi*
5773 F: drivers/*/*/*pasemi* 5774 F: drivers/*/*/*pasemi*
5774 5775
5775 LINUX SECURITY MODULE (LSM) FRAMEWORK 5776 LINUX SECURITY MODULE (LSM) FRAMEWORK
5776 M: Chris Wright <chrisw@sous-sol.org> 5777 M: Chris Wright <chrisw@sous-sol.org>
5777 L: linux-security-module@vger.kernel.org 5778 L: linux-security-module@vger.kernel.org
5778 S: Supported 5779 S: Supported
5779 5780
5780 LIS3LV02D ACCELEROMETER DRIVER 5781 LIS3LV02D ACCELEROMETER DRIVER
5781 M: Eric Piel <eric.piel@tremplin-utc.net> 5782 M: Eric Piel <eric.piel@tremplin-utc.net>
5782 S: Maintained 5783 S: Maintained
5783 F: Documentation/misc-devices/lis3lv02d 5784 F: Documentation/misc-devices/lis3lv02d
5784 F: drivers/misc/lis3lv02d/ 5785 F: drivers/misc/lis3lv02d/
5785 F: drivers/platform/x86/hp_accel.c 5786 F: drivers/platform/x86/hp_accel.c
5786 5787
5787 LLC (802.2) 5788 LLC (802.2)
5788 M: Arnaldo Carvalho de Melo <acme@ghostprotocols.net> 5789 M: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
5789 S: Maintained 5790 S: Maintained
5790 F: include/linux/llc.h 5791 F: include/linux/llc.h
5791 F: include/uapi/linux/llc.h 5792 F: include/uapi/linux/llc.h
5792 F: include/net/llc* 5793 F: include/net/llc*
5793 F: net/llc/ 5794 F: net/llc/
5794 5795
5795 LM73 HARDWARE MONITOR DRIVER 5796 LM73 HARDWARE MONITOR DRIVER
5796 M: Guillaume Ligneul <guillaume.ligneul@gmail.com> 5797 M: Guillaume Ligneul <guillaume.ligneul@gmail.com>
5797 L: lm-sensors@lm-sensors.org 5798 L: lm-sensors@lm-sensors.org
5798 S: Maintained 5799 S: Maintained
5799 F: drivers/hwmon/lm73.c 5800 F: drivers/hwmon/lm73.c
5800 5801
5801 LM78 HARDWARE MONITOR DRIVER 5802 LM78 HARDWARE MONITOR DRIVER
5802 M: Jean Delvare <jdelvare@suse.de> 5803 M: Jean Delvare <jdelvare@suse.de>
5803 L: lm-sensors@lm-sensors.org 5804 L: lm-sensors@lm-sensors.org
5804 S: Maintained 5805 S: Maintained
5805 F: Documentation/hwmon/lm78 5806 F: Documentation/hwmon/lm78
5806 F: drivers/hwmon/lm78.c 5807 F: drivers/hwmon/lm78.c
5807 5808
5808 LM83 HARDWARE MONITOR DRIVER 5809 LM83 HARDWARE MONITOR DRIVER
5809 M: Jean Delvare <jdelvare@suse.de> 5810 M: Jean Delvare <jdelvare@suse.de>
5810 L: lm-sensors@lm-sensors.org 5811 L: lm-sensors@lm-sensors.org
5811 S: Maintained 5812 S: Maintained
5812 F: Documentation/hwmon/lm83 5813 F: Documentation/hwmon/lm83
5813 F: drivers/hwmon/lm83.c 5814 F: drivers/hwmon/lm83.c
5814 5815
5815 LM90 HARDWARE MONITOR DRIVER 5816 LM90 HARDWARE MONITOR DRIVER
5816 M: Jean Delvare <jdelvare@suse.de> 5817 M: Jean Delvare <jdelvare@suse.de>
5817 L: lm-sensors@lm-sensors.org 5818 L: lm-sensors@lm-sensors.org
5818 S: Maintained 5819 S: Maintained
5819 F: Documentation/hwmon/lm90 5820 F: Documentation/hwmon/lm90
5820 F: Documentation/devicetree/bindings/hwmon/lm90.txt 5821 F: Documentation/devicetree/bindings/hwmon/lm90.txt
5821 F: drivers/hwmon/lm90.c 5822 F: drivers/hwmon/lm90.c
5822 5823
5823 LM95234 HARDWARE MONITOR DRIVER 5824 LM95234 HARDWARE MONITOR DRIVER
5824 M: Guenter Roeck <linux@roeck-us.net> 5825 M: Guenter Roeck <linux@roeck-us.net>
5825 L: lm-sensors@lm-sensors.org 5826 L: lm-sensors@lm-sensors.org
5826 S: Maintained 5827 S: Maintained
5827 F: Documentation/hwmon/lm95234 5828 F: Documentation/hwmon/lm95234
5828 F: drivers/hwmon/lm95234.c 5829 F: drivers/hwmon/lm95234.c
5829 5830
5830 LME2510 MEDIA DRIVER 5831 LME2510 MEDIA DRIVER
5831 M: Malcolm Priestley <tvboxspy@gmail.com> 5832 M: Malcolm Priestley <tvboxspy@gmail.com>
5832 L: linux-media@vger.kernel.org 5833 L: linux-media@vger.kernel.org
5833 W: http://linuxtv.org/ 5834 W: http://linuxtv.org/
5834 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 5835 Q: http://patchwork.linuxtv.org/project/linux-media/list/
5835 S: Maintained 5836 S: Maintained
5836 F: drivers/media/usb/dvb-usb-v2/lmedm04* 5837 F: drivers/media/usb/dvb-usb-v2/lmedm04*
5837 5838
5838 LOCKDEP AND LOCKSTAT 5839 LOCKDEP AND LOCKSTAT
5839 M: Peter Zijlstra <peterz@infradead.org> 5840 M: Peter Zijlstra <peterz@infradead.org>
5840 M: Ingo Molnar <mingo@redhat.com> 5841 M: Ingo Molnar <mingo@redhat.com>
5841 L: linux-kernel@vger.kernel.org 5842 L: linux-kernel@vger.kernel.org
5842 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git core/locking 5843 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git core/locking
5843 S: Maintained 5844 S: Maintained
5844 F: Documentation/locking/lockdep*.txt 5845 F: Documentation/locking/lockdep*.txt
5845 F: Documentation/locking/lockstat.txt 5846 F: Documentation/locking/lockstat.txt
5846 F: include/linux/lockdep.h 5847 F: include/linux/lockdep.h
5847 F: kernel/locking/ 5848 F: kernel/locking/
5848 5849
5849 LOGICAL DISK MANAGER SUPPORT (LDM, Windows 2000/XP/Vista Dynamic Disks) 5850 LOGICAL DISK MANAGER SUPPORT (LDM, Windows 2000/XP/Vista Dynamic Disks)
5850 M: "Richard Russon (FlatCap)" <ldm@flatcap.org> 5851 M: "Richard Russon (FlatCap)" <ldm@flatcap.org>
5851 L: linux-ntfs-dev@lists.sourceforge.net 5852 L: linux-ntfs-dev@lists.sourceforge.net
5852 W: http://www.linux-ntfs.org/content/view/19/37/ 5853 W: http://www.linux-ntfs.org/content/view/19/37/
5853 S: Maintained 5854 S: Maintained
5854 F: Documentation/ldm.txt 5855 F: Documentation/ldm.txt
5855 F: block/partitions/ldm.* 5856 F: block/partitions/ldm.*
5856 5857
5857 LogFS 5858 LogFS
5858 M: Joern Engel <joern@logfs.org> 5859 M: Joern Engel <joern@logfs.org>
5859 M: Prasad Joshi <prasadjoshi.linux@gmail.com> 5860 M: Prasad Joshi <prasadjoshi.linux@gmail.com>
5860 L: logfs@logfs.org 5861 L: logfs@logfs.org
5861 W: logfs.org 5862 W: logfs.org
5862 S: Maintained 5863 S: Maintained
5863 F: fs/logfs/ 5864 F: fs/logfs/
5864 5865
5865 LPC32XX MACHINE SUPPORT 5866 LPC32XX MACHINE SUPPORT
5866 M: Roland Stigge <stigge@antcom.de> 5867 M: Roland Stigge <stigge@antcom.de>
5867 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 5868 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
5868 S: Maintained 5869 S: Maintained
5869 F: arch/arm/mach-lpc32xx/ 5870 F: arch/arm/mach-lpc32xx/
5870 5871
5871 LSILOGIC MPT FUSION DRIVERS (FC/SAS/SPI) 5872 LSILOGIC MPT FUSION DRIVERS (FC/SAS/SPI)
5872 M: Nagalakshmi Nandigama <nagalakshmi.nandigama@avagotech.com> 5873 M: Nagalakshmi Nandigama <nagalakshmi.nandigama@avagotech.com>
5873 M: Praveen Krishnamoorthy <praveen.krishnamoorthy@avagotech.com> 5874 M: Praveen Krishnamoorthy <praveen.krishnamoorthy@avagotech.com>
5874 M: Sreekanth Reddy <sreekanth.reddy@avagotech.com> 5875 M: Sreekanth Reddy <sreekanth.reddy@avagotech.com>
5875 M: Abhijit Mahajan <abhijit.mahajan@avagotech.com> 5876 M: Abhijit Mahajan <abhijit.mahajan@avagotech.com>
5876 L: MPT-FusionLinux.pdl@avagotech.com 5877 L: MPT-FusionLinux.pdl@avagotech.com
5877 L: linux-scsi@vger.kernel.org 5878 L: linux-scsi@vger.kernel.org
5878 W: http://www.lsilogic.com/support 5879 W: http://www.lsilogic.com/support
5879 S: Supported 5880 S: Supported
5880 F: drivers/message/fusion/ 5881 F: drivers/message/fusion/
5881 F: drivers/scsi/mpt2sas/ 5882 F: drivers/scsi/mpt2sas/
5882 F: drivers/scsi/mpt3sas/ 5883 F: drivers/scsi/mpt3sas/
5883 5884
5884 LSILOGIC/SYMBIOS/NCR 53C8XX and 53C1010 PCI-SCSI drivers 5885 LSILOGIC/SYMBIOS/NCR 53C8XX and 53C1010 PCI-SCSI drivers
5885 M: Matthew Wilcox <matthew@wil.cx> 5886 M: Matthew Wilcox <matthew@wil.cx>
5886 L: linux-scsi@vger.kernel.org 5887 L: linux-scsi@vger.kernel.org
5887 S: Maintained 5888 S: Maintained
5888 F: drivers/scsi/sym53c8xx_2/ 5889 F: drivers/scsi/sym53c8xx_2/
5889 5890
5890 LTC4261 HARDWARE MONITOR DRIVER 5891 LTC4261 HARDWARE MONITOR DRIVER
5891 M: Guenter Roeck <linux@roeck-us.net> 5892 M: Guenter Roeck <linux@roeck-us.net>
5892 L: lm-sensors@lm-sensors.org 5893 L: lm-sensors@lm-sensors.org
5893 S: Maintained 5894 S: Maintained
5894 F: Documentation/hwmon/ltc4261 5895 F: Documentation/hwmon/ltc4261
5895 F: drivers/hwmon/ltc4261.c 5896 F: drivers/hwmon/ltc4261.c
5896 5897
5897 LTP (Linux Test Project) 5898 LTP (Linux Test Project)
5898 M: Mike Frysinger <vapier@gentoo.org> 5899 M: Mike Frysinger <vapier@gentoo.org>
5899 M: Cyril Hrubis <chrubis@suse.cz> 5900 M: Cyril Hrubis <chrubis@suse.cz>
5900 M: Wanlong Gao <gaowanlong@cn.fujitsu.com> 5901 M: Wanlong Gao <gaowanlong@cn.fujitsu.com>
5901 M: Jan Stancek <jstancek@redhat.com> 5902 M: Jan Stancek <jstancek@redhat.com>
5902 M: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com> 5903 M: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
5903 M: Alexey Kodanev <alexey.kodanev@oracle.com> 5904 M: Alexey Kodanev <alexey.kodanev@oracle.com>
5904 L: ltp-list@lists.sourceforge.net (subscribers-only) 5905 L: ltp-list@lists.sourceforge.net (subscribers-only)
5905 W: http://linux-test-project.github.io/ 5906 W: http://linux-test-project.github.io/
5906 T: git git://github.com/linux-test-project/ltp.git 5907 T: git git://github.com/linux-test-project/ltp.git
5907 S: Maintained 5908 S: Maintained
5908 5909
5909 M32R ARCHITECTURE 5910 M32R ARCHITECTURE
5910 W: http://www.linux-m32r.org/ 5911 W: http://www.linux-m32r.org/
5911 S: Orphan 5912 S: Orphan
5912 F: arch/m32r/ 5913 F: arch/m32r/
5913 5914
5914 M68K ARCHITECTURE 5915 M68K ARCHITECTURE
5915 M: Geert Uytterhoeven <geert@linux-m68k.org> 5916 M: Geert Uytterhoeven <geert@linux-m68k.org>
5916 L: linux-m68k@lists.linux-m68k.org 5917 L: linux-m68k@lists.linux-m68k.org
5917 W: http://www.linux-m68k.org/ 5918 W: http://www.linux-m68k.org/
5918 T: git git://git.kernel.org/pub/scm/linux/kernel/git/geert/linux-m68k.git 5919 T: git git://git.kernel.org/pub/scm/linux/kernel/git/geert/linux-m68k.git
5919 S: Maintained 5920 S: Maintained
5920 F: arch/m68k/ 5921 F: arch/m68k/
5921 F: drivers/zorro/ 5922 F: drivers/zorro/
5922 5923
5923 M68K ON APPLE MACINTOSH 5924 M68K ON APPLE MACINTOSH
5924 M: Joshua Thompson <funaho@jurai.org> 5925 M: Joshua Thompson <funaho@jurai.org>
5925 W: http://www.mac.linux-m68k.org/ 5926 W: http://www.mac.linux-m68k.org/
5926 L: linux-m68k@lists.linux-m68k.org 5927 L: linux-m68k@lists.linux-m68k.org
5927 S: Maintained 5928 S: Maintained
5928 F: arch/m68k/mac/ 5929 F: arch/m68k/mac/
5929 5930
5930 M68K ON HP9000/300 5931 M68K ON HP9000/300
5931 M: Philip Blundell <philb@gnu.org> 5932 M: Philip Blundell <philb@gnu.org>
5932 W: http://www.tazenda.demon.co.uk/phil/linux-hp 5933 W: http://www.tazenda.demon.co.uk/phil/linux-hp
5933 S: Maintained 5934 S: Maintained
5934 F: arch/m68k/hp300/ 5935 F: arch/m68k/hp300/
5935 5936
5936 M88DS3103 MEDIA DRIVER 5937 M88DS3103 MEDIA DRIVER
5937 M: Antti Palosaari <crope@iki.fi> 5938 M: Antti Palosaari <crope@iki.fi>
5938 L: linux-media@vger.kernel.org 5939 L: linux-media@vger.kernel.org
5939 W: http://linuxtv.org/ 5940 W: http://linuxtv.org/
5940 W: http://palosaari.fi/linux/ 5941 W: http://palosaari.fi/linux/
5941 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 5942 Q: http://patchwork.linuxtv.org/project/linux-media/list/
5942 T: git git://linuxtv.org/anttip/media_tree.git 5943 T: git git://linuxtv.org/anttip/media_tree.git
5943 S: Maintained 5944 S: Maintained
5944 F: drivers/media/dvb-frontends/m88ds3103* 5945 F: drivers/media/dvb-frontends/m88ds3103*
5945 5946
5946 M88RS2000 MEDIA DRIVER 5947 M88RS2000 MEDIA DRIVER
5947 M: Malcolm Priestley <tvboxspy@gmail.com> 5948 M: Malcolm Priestley <tvboxspy@gmail.com>
5948 L: linux-media@vger.kernel.org 5949 L: linux-media@vger.kernel.org
5949 W: http://linuxtv.org/ 5950 W: http://linuxtv.org/
5950 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 5951 Q: http://patchwork.linuxtv.org/project/linux-media/list/
5951 S: Maintained 5952 S: Maintained
5952 F: drivers/media/dvb-frontends/m88rs2000* 5953 F: drivers/media/dvb-frontends/m88rs2000*
5953 5954
5954 M88TS2022 MEDIA DRIVER 5955 M88TS2022 MEDIA DRIVER
5955 M: Antti Palosaari <crope@iki.fi> 5956 M: Antti Palosaari <crope@iki.fi>
5956 L: linux-media@vger.kernel.org 5957 L: linux-media@vger.kernel.org
5957 W: http://linuxtv.org/ 5958 W: http://linuxtv.org/
5958 W: http://palosaari.fi/linux/ 5959 W: http://palosaari.fi/linux/
5959 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 5960 Q: http://patchwork.linuxtv.org/project/linux-media/list/
5960 T: git git://linuxtv.org/anttip/media_tree.git 5961 T: git git://linuxtv.org/anttip/media_tree.git
5961 S: Maintained 5962 S: Maintained
5962 F: drivers/media/tuners/m88ts2022* 5963 F: drivers/media/tuners/m88ts2022*
5963 5964
5964 MA901 MASTERKIT USB FM RADIO DRIVER 5965 MA901 MASTERKIT USB FM RADIO DRIVER
5965 M: Alexey Klimov <klimov.linux@gmail.com> 5966 M: Alexey Klimov <klimov.linux@gmail.com>
5966 L: linux-media@vger.kernel.org 5967 L: linux-media@vger.kernel.org
5967 T: git git://linuxtv.org/media_tree.git 5968 T: git git://linuxtv.org/media_tree.git
5968 S: Maintained 5969 S: Maintained
5969 F: drivers/media/radio/radio-ma901.c 5970 F: drivers/media/radio/radio-ma901.c
5970 5971
5971 MAC80211 5972 MAC80211
5972 M: Johannes Berg <johannes@sipsolutions.net> 5973 M: Johannes Berg <johannes@sipsolutions.net>
5973 L: linux-wireless@vger.kernel.org 5974 L: linux-wireless@vger.kernel.org
5974 W: http://wireless.kernel.org/ 5975 W: http://wireless.kernel.org/
5975 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211.git 5976 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211.git
5976 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211-next.git 5977 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211-next.git
5977 S: Maintained 5978 S: Maintained
5978 F: Documentation/networking/mac80211-injection.txt 5979 F: Documentation/networking/mac80211-injection.txt
5979 F: include/net/mac80211.h 5980 F: include/net/mac80211.h
5980 F: net/mac80211/ 5981 F: net/mac80211/
5981 5982
5982 MACVLAN DRIVER 5983 MACVLAN DRIVER
5983 M: Patrick McHardy <kaber@trash.net> 5984 M: Patrick McHardy <kaber@trash.net>
5984 L: netdev@vger.kernel.org 5985 L: netdev@vger.kernel.org
5985 S: Maintained 5986 S: Maintained
5986 F: drivers/net/macvlan.c 5987 F: drivers/net/macvlan.c
5987 F: include/linux/if_macvlan.h 5988 F: include/linux/if_macvlan.h
5988 5989
5989 MAILBOX API 5990 MAILBOX API
5990 M: Jassi Brar <jassisinghbrar@gmail.com> 5991 M: Jassi Brar <jassisinghbrar@gmail.com>
5991 L: linux-kernel@vger.kernel.org 5992 L: linux-kernel@vger.kernel.org
5992 S: Maintained 5993 S: Maintained
5993 F: drivers/mailbox/ 5994 F: drivers/mailbox/
5994 F: include/linux/mailbox_client.h 5995 F: include/linux/mailbox_client.h
5995 F: include/linux/mailbox_controller.h 5996 F: include/linux/mailbox_controller.h
5996 5997
5997 MAN-PAGES: MANUAL PAGES FOR LINUX -- Sections 2, 3, 4, 5, and 7 5998 MAN-PAGES: MANUAL PAGES FOR LINUX -- Sections 2, 3, 4, 5, and 7
5998 M: Michael Kerrisk <mtk.manpages@gmail.com> 5999 M: Michael Kerrisk <mtk.manpages@gmail.com>
5999 W: http://www.kernel.org/doc/man-pages 6000 W: http://www.kernel.org/doc/man-pages
6000 L: linux-man@vger.kernel.org 6001 L: linux-man@vger.kernel.org
6001 S: Maintained 6002 S: Maintained
6002 6003
6003 MARVELL ARMADA DRM SUPPORT 6004 MARVELL ARMADA DRM SUPPORT
6004 M: Russell King <rmk+kernel@arm.linux.org.uk> 6005 M: Russell King <rmk+kernel@arm.linux.org.uk>
6005 S: Maintained 6006 S: Maintained
6006 F: drivers/gpu/drm/armada/ 6007 F: drivers/gpu/drm/armada/
6007 6008
6008 MARVELL 88E6352 DSA support 6009 MARVELL 88E6352 DSA support
6009 M: Guenter Roeck <linux@roeck-us.net> 6010 M: Guenter Roeck <linux@roeck-us.net>
6010 S: Maintained 6011 S: Maintained
6011 F: drivers/net/dsa/mv88e6352.c 6012 F: drivers/net/dsa/mv88e6352.c
6012 6013
6013 MARVELL GIGABIT ETHERNET DRIVERS (skge/sky2) 6014 MARVELL GIGABIT ETHERNET DRIVERS (skge/sky2)
6014 M: Mirko Lindner <mlindner@marvell.com> 6015 M: Mirko Lindner <mlindner@marvell.com>
6015 M: Stephen Hemminger <stephen@networkplumber.org> 6016 M: Stephen Hemminger <stephen@networkplumber.org>
6016 L: netdev@vger.kernel.org 6017 L: netdev@vger.kernel.org
6017 S: Maintained 6018 S: Maintained
6018 F: drivers/net/ethernet/marvell/sk* 6019 F: drivers/net/ethernet/marvell/sk*
6019 6020
6020 MARVELL LIBERTAS WIRELESS DRIVER 6021 MARVELL LIBERTAS WIRELESS DRIVER
6021 L: libertas-dev@lists.infradead.org 6022 L: libertas-dev@lists.infradead.org
6022 S: Orphan 6023 S: Orphan
6023 F: drivers/net/wireless/libertas/ 6024 F: drivers/net/wireless/libertas/
6024 6025
6025 MARVELL MV643XX ETHERNET DRIVER 6026 MARVELL MV643XX ETHERNET DRIVER
6026 M: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com> 6027 M: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
6027 L: netdev@vger.kernel.org 6028 L: netdev@vger.kernel.org
6028 S: Maintained 6029 S: Maintained
6029 F: drivers/net/ethernet/marvell/mv643xx_eth.* 6030 F: drivers/net/ethernet/marvell/mv643xx_eth.*
6030 F: include/linux/mv643xx.h 6031 F: include/linux/mv643xx.h
6031 6032
6032 MARVELL MVNETA ETHERNET DRIVER 6033 MARVELL MVNETA ETHERNET DRIVER
6033 M: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> 6034 M: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
6034 L: netdev@vger.kernel.org 6035 L: netdev@vger.kernel.org
6035 S: Maintained 6036 S: Maintained
6036 F: drivers/net/ethernet/marvell/mvneta.* 6037 F: drivers/net/ethernet/marvell/mvneta.*
6037 6038
6038 MARVELL MWIFIEX WIRELESS DRIVER 6039 MARVELL MWIFIEX WIRELESS DRIVER
6039 M: Amitkumar Karwar <akarwar@marvell.com> 6040 M: Amitkumar Karwar <akarwar@marvell.com>
6040 M: Avinash Patil <patila@marvell.com> 6041 M: Avinash Patil <patila@marvell.com>
6041 L: linux-wireless@vger.kernel.org 6042 L: linux-wireless@vger.kernel.org
6042 S: Maintained 6043 S: Maintained
6043 F: drivers/net/wireless/mwifiex/ 6044 F: drivers/net/wireless/mwifiex/
6044 6045
6045 MARVELL MWL8K WIRELESS DRIVER 6046 MARVELL MWL8K WIRELESS DRIVER
6046 M: Lennert Buytenhek <buytenh@wantstofly.org> 6047 M: Lennert Buytenhek <buytenh@wantstofly.org>
6047 L: linux-wireless@vger.kernel.org 6048 L: linux-wireless@vger.kernel.org
6048 S: Odd Fixes 6049 S: Odd Fixes
6049 F: drivers/net/wireless/mwl8k.c 6050 F: drivers/net/wireless/mwl8k.c
6050 6051
6051 MARVELL SOC MMC/SD/SDIO CONTROLLER DRIVER 6052 MARVELL SOC MMC/SD/SDIO CONTROLLER DRIVER
6052 M: Nicolas Pitre <nico@fluxnic.net> 6053 M: Nicolas Pitre <nico@fluxnic.net>
6053 S: Odd Fixes 6054 S: Odd Fixes
6054 F: drivers/mmc/host/mvsdio.* 6055 F: drivers/mmc/host/mvsdio.*
6055 6056
6056 MATROX FRAMEBUFFER DRIVER 6057 MATROX FRAMEBUFFER DRIVER
6057 L: linux-fbdev@vger.kernel.org 6058 L: linux-fbdev@vger.kernel.org
6058 S: Orphan 6059 S: Orphan
6059 F: drivers/video/fbdev/matrox/matroxfb_* 6060 F: drivers/video/fbdev/matrox/matroxfb_*
6060 F: include/uapi/linux/matroxfb.h 6061 F: include/uapi/linux/matroxfb.h
6061 6062
6062 MAX16065 HARDWARE MONITOR DRIVER 6063 MAX16065 HARDWARE MONITOR DRIVER
6063 M: Guenter Roeck <linux@roeck-us.net> 6064 M: Guenter Roeck <linux@roeck-us.net>
6064 L: lm-sensors@lm-sensors.org 6065 L: lm-sensors@lm-sensors.org
6065 S: Maintained 6066 S: Maintained
6066 F: Documentation/hwmon/max16065 6067 F: Documentation/hwmon/max16065
6067 F: drivers/hwmon/max16065.c 6068 F: drivers/hwmon/max16065.c
6068 6069
6069 MAX6650 HARDWARE MONITOR AND FAN CONTROLLER DRIVER 6070 MAX6650 HARDWARE MONITOR AND FAN CONTROLLER DRIVER
6070 M: "Hans J. Koch" <hjk@hansjkoch.de> 6071 M: "Hans J. Koch" <hjk@hansjkoch.de>
6071 L: lm-sensors@lm-sensors.org 6072 L: lm-sensors@lm-sensors.org
6072 S: Maintained 6073 S: Maintained
6073 F: Documentation/hwmon/max6650 6074 F: Documentation/hwmon/max6650
6074 F: drivers/hwmon/max6650.c 6075 F: drivers/hwmon/max6650.c
6075 6076
6076 MAX6697 HARDWARE MONITOR DRIVER 6077 MAX6697 HARDWARE MONITOR DRIVER
6077 M: Guenter Roeck <linux@roeck-us.net> 6078 M: Guenter Roeck <linux@roeck-us.net>
6078 L: lm-sensors@lm-sensors.org 6079 L: lm-sensors@lm-sensors.org
6079 S: Maintained 6080 S: Maintained
6080 F: Documentation/hwmon/max6697 6081 F: Documentation/hwmon/max6697
6081 F: Documentation/devicetree/bindings/i2c/max6697.txt 6082 F: Documentation/devicetree/bindings/i2c/max6697.txt
6082 F: drivers/hwmon/max6697.c 6083 F: drivers/hwmon/max6697.c
6083 F: include/linux/platform_data/max6697.h 6084 F: include/linux/platform_data/max6697.h
6084 6085
6085 MAXIRADIO FM RADIO RECEIVER DRIVER 6086 MAXIRADIO FM RADIO RECEIVER DRIVER
6086 M: Hans Verkuil <hverkuil@xs4all.nl> 6087 M: Hans Verkuil <hverkuil@xs4all.nl>
6087 L: linux-media@vger.kernel.org 6088 L: linux-media@vger.kernel.org
6088 T: git git://linuxtv.org/media_tree.git 6089 T: git git://linuxtv.org/media_tree.git
6089 W: http://linuxtv.org 6090 W: http://linuxtv.org
6090 S: Maintained 6091 S: Maintained
6091 F: drivers/media/radio/radio-maxiradio* 6092 F: drivers/media/radio/radio-maxiradio*
6092 6093
6093 MEDIA INPUT INFRASTRUCTURE (V4L/DVB) 6094 MEDIA INPUT INFRASTRUCTURE (V4L/DVB)
6094 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com> 6095 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
6095 P: LinuxTV.org Project 6096 P: LinuxTV.org Project
6096 L: linux-media@vger.kernel.org 6097 L: linux-media@vger.kernel.org
6097 W: http://linuxtv.org 6098 W: http://linuxtv.org
6098 Q: http://patchwork.kernel.org/project/linux-media/list/ 6099 Q: http://patchwork.kernel.org/project/linux-media/list/
6099 T: git git://linuxtv.org/media_tree.git 6100 T: git git://linuxtv.org/media_tree.git
6100 S: Maintained 6101 S: Maintained
6101 F: Documentation/dvb/ 6102 F: Documentation/dvb/
6102 F: Documentation/video4linux/ 6103 F: Documentation/video4linux/
6103 F: Documentation/DocBook/media/ 6104 F: Documentation/DocBook/media/
6104 F: drivers/media/ 6105 F: drivers/media/
6105 F: drivers/staging/media/ 6106 F: drivers/staging/media/
6106 F: include/media/ 6107 F: include/media/
6107 F: include/uapi/linux/dvb/ 6108 F: include/uapi/linux/dvb/
6108 F: include/uapi/linux/videodev2.h 6109 F: include/uapi/linux/videodev2.h
6109 F: include/uapi/linux/media.h 6110 F: include/uapi/linux/media.h
6110 F: include/uapi/linux/v4l2-* 6111 F: include/uapi/linux/v4l2-*
6111 F: include/uapi/linux/meye.h 6112 F: include/uapi/linux/meye.h
6112 F: include/uapi/linux/ivtv* 6113 F: include/uapi/linux/ivtv*
6113 F: include/uapi/linux/uvcvideo.h 6114 F: include/uapi/linux/uvcvideo.h
6114 6115
6115 MEDIAVISION PRO MOVIE STUDIO DRIVER 6116 MEDIAVISION PRO MOVIE STUDIO DRIVER
6116 M: Hans Verkuil <hverkuil@xs4all.nl> 6117 M: Hans Verkuil <hverkuil@xs4all.nl>
6117 L: linux-media@vger.kernel.org 6118 L: linux-media@vger.kernel.org
6118 T: git git://linuxtv.org/media_tree.git 6119 T: git git://linuxtv.org/media_tree.git
6119 W: http://linuxtv.org 6120 W: http://linuxtv.org
6120 S: Odd Fixes 6121 S: Odd Fixes
6121 F: drivers/media/parport/pms* 6122 F: drivers/media/parport/pms*
6122 6123
6123 MEGARAID SCSI/SAS DRIVERS 6124 MEGARAID SCSI/SAS DRIVERS
6124 M: Kashyap Desai <kashyap.desai@avagotech.com> 6125 M: Kashyap Desai <kashyap.desai@avagotech.com>
6125 M: Sumit Saxena <sumit.saxena@avagotech.com> 6126 M: Sumit Saxena <sumit.saxena@avagotech.com>
6126 M: Uday Lingala <uday.lingala@avagotech.com> 6127 M: Uday Lingala <uday.lingala@avagotech.com>
6127 L: megaraidlinux.pdl@avagotech.com 6128 L: megaraidlinux.pdl@avagotech.com
6128 L: linux-scsi@vger.kernel.org 6129 L: linux-scsi@vger.kernel.org
6129 W: http://www.lsi.com 6130 W: http://www.lsi.com
6130 S: Maintained 6131 S: Maintained
6131 F: Documentation/scsi/megaraid.txt 6132 F: Documentation/scsi/megaraid.txt
6132 F: drivers/scsi/megaraid.* 6133 F: drivers/scsi/megaraid.*
6133 F: drivers/scsi/megaraid/ 6134 F: drivers/scsi/megaraid/
6134 6135
6135 MELLANOX ETHERNET DRIVER (mlx4_en) 6136 MELLANOX ETHERNET DRIVER (mlx4_en)
6136 M: Amir Vadai <amirv@mellanox.com> 6137 M: Amir Vadai <amirv@mellanox.com>
6137 L: netdev@vger.kernel.org 6138 L: netdev@vger.kernel.org
6138 S: Supported 6139 S: Supported
6139 W: http://www.mellanox.com 6140 W: http://www.mellanox.com
6140 Q: http://patchwork.ozlabs.org/project/netdev/list/ 6141 Q: http://patchwork.ozlabs.org/project/netdev/list/
6141 F: drivers/net/ethernet/mellanox/mlx4/en_* 6142 F: drivers/net/ethernet/mellanox/mlx4/en_*
6142 6143
6143 MEMORY MANAGEMENT 6144 MEMORY MANAGEMENT
6144 L: linux-mm@kvack.org 6145 L: linux-mm@kvack.org
6145 W: http://www.linux-mm.org 6146 W: http://www.linux-mm.org
6146 S: Maintained 6147 S: Maintained
6147 F: include/linux/mm.h 6148 F: include/linux/mm.h
6148 F: include/linux/gfp.h 6149 F: include/linux/gfp.h
6149 F: include/linux/mmzone.h 6150 F: include/linux/mmzone.h
6150 F: include/linux/memory_hotplug.h 6151 F: include/linux/memory_hotplug.h
6151 F: include/linux/vmalloc.h 6152 F: include/linux/vmalloc.h
6152 F: mm/ 6153 F: mm/
6153 6154
6154 MEMORY TECHNOLOGY DEVICES (MTD) 6155 MEMORY TECHNOLOGY DEVICES (MTD)
6155 M: David Woodhouse <dwmw2@infradead.org> 6156 M: David Woodhouse <dwmw2@infradead.org>
6156 M: Brian Norris <computersforpeace@gmail.com> 6157 M: Brian Norris <computersforpeace@gmail.com>
6157 L: linux-mtd@lists.infradead.org 6158 L: linux-mtd@lists.infradead.org
6158 W: http://www.linux-mtd.infradead.org/ 6159 W: http://www.linux-mtd.infradead.org/
6159 Q: http://patchwork.ozlabs.org/project/linux-mtd/list/ 6160 Q: http://patchwork.ozlabs.org/project/linux-mtd/list/
6160 T: git git://git.infradead.org/linux-mtd.git 6161 T: git git://git.infradead.org/linux-mtd.git
6161 T: git git://git.infradead.org/l2-mtd.git 6162 T: git git://git.infradead.org/l2-mtd.git
6162 S: Maintained 6163 S: Maintained
6163 F: drivers/mtd/ 6164 F: drivers/mtd/
6164 F: include/linux/mtd/ 6165 F: include/linux/mtd/
6165 F: include/uapi/mtd/ 6166 F: include/uapi/mtd/
6166 6167
6167 MEN A21 WATCHDOG DRIVER 6168 MEN A21 WATCHDOG DRIVER
6168 M: Johannes Thumshirn <johannes.thumshirn@men.de> 6169 M: Johannes Thumshirn <johannes.thumshirn@men.de>
6169 L: linux-watchdog@vger.kernel.org 6170 L: linux-watchdog@vger.kernel.org
6170 S: Supported 6171 S: Supported
6171 F: drivers/watchdog/mena21_wdt.c 6172 F: drivers/watchdog/mena21_wdt.c
6172 6173
6173 MEN CHAMELEON BUS (mcb) 6174 MEN CHAMELEON BUS (mcb)
6174 M: Johannes Thumshirn <johannes.thumshirn@men.de> 6175 M: Johannes Thumshirn <johannes.thumshirn@men.de>
6175 S: Supported 6176 S: Supported
6176 F: drivers/mcb/ 6177 F: drivers/mcb/
6177 F: include/linux/mcb.h 6178 F: include/linux/mcb.h
6178 6179
6179 MEN F21BMC (Board Management Controller) 6180 MEN F21BMC (Board Management Controller)
6180 M: Andreas Werner <andreas.werner@men.de> 6181 M: Andreas Werner <andreas.werner@men.de>
6181 S: Supported 6182 S: Supported
6182 F: drivers/mfd/menf21bmc.c 6183 F: drivers/mfd/menf21bmc.c
6183 F: drivers/watchdog/menf21bmc_wdt.c 6184 F: drivers/watchdog/menf21bmc_wdt.c
6184 F: drivers/leds/leds-menf21bmc.c 6185 F: drivers/leds/leds-menf21bmc.c
6185 F: drivers/hwmon/menf21bmc_hwmon.c 6186 F: drivers/hwmon/menf21bmc_hwmon.c
6186 F: Documentation/hwmon/menf21bmc 6187 F: Documentation/hwmon/menf21bmc
6187 6188
6188 METAG ARCHITECTURE 6189 METAG ARCHITECTURE
6189 M: James Hogan <james.hogan@imgtec.com> 6190 M: James Hogan <james.hogan@imgtec.com>
6190 L: linux-metag@vger.kernel.org 6191 L: linux-metag@vger.kernel.org
6191 S: Supported 6192 S: Supported
6192 F: arch/metag/ 6193 F: arch/metag/
6193 F: Documentation/metag/ 6194 F: Documentation/metag/
6194 F: Documentation/devicetree/bindings/metag/ 6195 F: Documentation/devicetree/bindings/metag/
6195 F: drivers/clocksource/metag_generic.c 6196 F: drivers/clocksource/metag_generic.c
6196 F: drivers/irqchip/irq-metag.c 6197 F: drivers/irqchip/irq-metag.c
6197 F: drivers/irqchip/irq-metag-ext.c 6198 F: drivers/irqchip/irq-metag-ext.c
6198 F: drivers/tty/metag_da.c 6199 F: drivers/tty/metag_da.c
6199 6200
6200 MICROBLAZE ARCHITECTURE 6201 MICROBLAZE ARCHITECTURE
6201 M: Michal Simek <monstr@monstr.eu> 6202 M: Michal Simek <monstr@monstr.eu>
6202 W: http://www.monstr.eu/fdt/ 6203 W: http://www.monstr.eu/fdt/
6203 T: git git://git.monstr.eu/linux-2.6-microblaze.git 6204 T: git git://git.monstr.eu/linux-2.6-microblaze.git
6204 S: Supported 6205 S: Supported
6205 F: arch/microblaze/ 6206 F: arch/microblaze/
6206 6207
6207 MICROTEK X6 SCANNER 6208 MICROTEK X6 SCANNER
6208 M: Oliver Neukum <oliver@neukum.org> 6209 M: Oliver Neukum <oliver@neukum.org>
6209 S: Maintained 6210 S: Maintained
6210 F: drivers/usb/image/microtek.* 6211 F: drivers/usb/image/microtek.*
6211 6212
6212 MIPS 6213 MIPS
6213 M: Ralf Baechle <ralf@linux-mips.org> 6214 M: Ralf Baechle <ralf@linux-mips.org>
6214 L: linux-mips@linux-mips.org 6215 L: linux-mips@linux-mips.org
6215 W: http://www.linux-mips.org/ 6216 W: http://www.linux-mips.org/
6216 T: git git://git.linux-mips.org/pub/scm/ralf/linux.git 6217 T: git git://git.linux-mips.org/pub/scm/ralf/linux.git
6217 Q: http://patchwork.linux-mips.org/project/linux-mips/list/ 6218 Q: http://patchwork.linux-mips.org/project/linux-mips/list/
6218 S: Supported 6219 S: Supported
6219 F: Documentation/mips/ 6220 F: Documentation/mips/
6220 F: arch/mips/ 6221 F: arch/mips/
6221 6222
6222 MIROSOUND PCM20 FM RADIO RECEIVER DRIVER 6223 MIROSOUND PCM20 FM RADIO RECEIVER DRIVER
6223 M: Hans Verkuil <hverkuil@xs4all.nl> 6224 M: Hans Verkuil <hverkuil@xs4all.nl>
6224 L: linux-media@vger.kernel.org 6225 L: linux-media@vger.kernel.org
6225 T: git git://linuxtv.org/media_tree.git 6226 T: git git://linuxtv.org/media_tree.git
6226 W: http://linuxtv.org 6227 W: http://linuxtv.org
6227 S: Odd Fixes 6228 S: Odd Fixes
6228 F: drivers/media/radio/radio-miropcm20* 6229 F: drivers/media/radio/radio-miropcm20*
6229 6230
6230 Mellanox MLX5 core VPI driver 6231 Mellanox MLX5 core VPI driver
6231 M: Eli Cohen <eli@mellanox.com> 6232 M: Eli Cohen <eli@mellanox.com>
6232 L: netdev@vger.kernel.org 6233 L: netdev@vger.kernel.org
6233 L: linux-rdma@vger.kernel.org 6234 L: linux-rdma@vger.kernel.org
6234 W: http://www.mellanox.com 6235 W: http://www.mellanox.com
6235 Q: http://patchwork.ozlabs.org/project/netdev/list/ 6236 Q: http://patchwork.ozlabs.org/project/netdev/list/
6236 Q: http://patchwork.kernel.org/project/linux-rdma/list/ 6237 Q: http://patchwork.kernel.org/project/linux-rdma/list/
6237 T: git git://openfabrics.org/~eli/connect-ib.git 6238 T: git git://openfabrics.org/~eli/connect-ib.git
6238 S: Supported 6239 S: Supported
6239 F: drivers/net/ethernet/mellanox/mlx5/core/ 6240 F: drivers/net/ethernet/mellanox/mlx5/core/
6240 F: include/linux/mlx5/ 6241 F: include/linux/mlx5/
6241 6242
6242 Mellanox MLX5 IB driver 6243 Mellanox MLX5 IB driver
6243 M: Eli Cohen <eli@mellanox.com> 6244 M: Eli Cohen <eli@mellanox.com>
6244 L: linux-rdma@vger.kernel.org 6245 L: linux-rdma@vger.kernel.org
6245 W: http://www.mellanox.com 6246 W: http://www.mellanox.com
6246 Q: http://patchwork.kernel.org/project/linux-rdma/list/ 6247 Q: http://patchwork.kernel.org/project/linux-rdma/list/
6247 T: git git://openfabrics.org/~eli/connect-ib.git 6248 T: git git://openfabrics.org/~eli/connect-ib.git
6248 S: Supported 6249 S: Supported
6249 F: include/linux/mlx5/ 6250 F: include/linux/mlx5/
6250 F: drivers/infiniband/hw/mlx5/ 6251 F: drivers/infiniband/hw/mlx5/
6251 6252
6252 MN88472 MEDIA DRIVER 6253 MN88472 MEDIA DRIVER
6253 M: Antti Palosaari <crope@iki.fi> 6254 M: Antti Palosaari <crope@iki.fi>
6254 L: linux-media@vger.kernel.org 6255 L: linux-media@vger.kernel.org
6255 W: http://linuxtv.org/ 6256 W: http://linuxtv.org/
6256 W: http://palosaari.fi/linux/ 6257 W: http://palosaari.fi/linux/
6257 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 6258 Q: http://patchwork.linuxtv.org/project/linux-media/list/
6258 T: git git://linuxtv.org/anttip/media_tree.git 6259 T: git git://linuxtv.org/anttip/media_tree.git
6259 S: Maintained 6260 S: Maintained
6260 F: drivers/staging/media/mn88472/ 6261 F: drivers/staging/media/mn88472/
6261 F: drivers/media/dvb-frontends/mn88472.h 6262 F: drivers/media/dvb-frontends/mn88472.h
6262 6263
6263 MN88473 MEDIA DRIVER 6264 MN88473 MEDIA DRIVER
6264 M: Antti Palosaari <crope@iki.fi> 6265 M: Antti Palosaari <crope@iki.fi>
6265 L: linux-media@vger.kernel.org 6266 L: linux-media@vger.kernel.org
6266 W: http://linuxtv.org/ 6267 W: http://linuxtv.org/
6267 W: http://palosaari.fi/linux/ 6268 W: http://palosaari.fi/linux/
6268 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 6269 Q: http://patchwork.linuxtv.org/project/linux-media/list/
6269 T: git git://linuxtv.org/anttip/media_tree.git 6270 T: git git://linuxtv.org/anttip/media_tree.git
6270 S: Maintained 6271 S: Maintained
6271 F: drivers/staging/media/mn88473/ 6272 F: drivers/staging/media/mn88473/
6272 F: drivers/media/dvb-frontends/mn88473.h 6273 F: drivers/media/dvb-frontends/mn88473.h
6273 6274
6274 MODULE SUPPORT 6275 MODULE SUPPORT
6275 M: Rusty Russell <rusty@rustcorp.com.au> 6276 M: Rusty Russell <rusty@rustcorp.com.au>
6276 S: Maintained 6277 S: Maintained
6277 F: include/linux/module.h 6278 F: include/linux/module.h
6278 F: kernel/module.c 6279 F: kernel/module.c
6279 6280
6280 MOTION EYE VAIO PICTUREBOOK CAMERA DRIVER 6281 MOTION EYE VAIO PICTUREBOOK CAMERA DRIVER
6281 W: http://popies.net/meye/ 6282 W: http://popies.net/meye/
6282 S: Orphan 6283 S: Orphan
6283 F: Documentation/video4linux/meye.txt 6284 F: Documentation/video4linux/meye.txt
6284 F: drivers/media/pci/meye/ 6285 F: drivers/media/pci/meye/
6285 F: include/uapi/linux/meye.h 6286 F: include/uapi/linux/meye.h
6286 6287
6287 MOXA SMARTIO/INDUSTIO/INTELLIO SERIAL CARD 6288 MOXA SMARTIO/INDUSTIO/INTELLIO SERIAL CARD
6288 M: Jiri Slaby <jirislaby@gmail.com> 6289 M: Jiri Slaby <jirislaby@gmail.com>
6289 S: Maintained 6290 S: Maintained
6290 F: Documentation/serial/moxa-smartio 6291 F: Documentation/serial/moxa-smartio
6291 F: drivers/tty/mxser.* 6292 F: drivers/tty/mxser.*
6292 6293
6293 MR800 AVERMEDIA USB FM RADIO DRIVER 6294 MR800 AVERMEDIA USB FM RADIO DRIVER
6294 M: Alexey Klimov <klimov.linux@gmail.com> 6295 M: Alexey Klimov <klimov.linux@gmail.com>
6295 L: linux-media@vger.kernel.org 6296 L: linux-media@vger.kernel.org
6296 T: git git://linuxtv.org/media_tree.git 6297 T: git git://linuxtv.org/media_tree.git
6297 S: Maintained 6298 S: Maintained
6298 F: drivers/media/radio/radio-mr800.c 6299 F: drivers/media/radio/radio-mr800.c
6299 6300
6300 MRF24J40 IEEE 802.15.4 RADIO DRIVER 6301 MRF24J40 IEEE 802.15.4 RADIO DRIVER
6301 M: Alan Ott <alan@signal11.us> 6302 M: Alan Ott <alan@signal11.us>
6302 L: linux-wpan@vger.kernel.org 6303 L: linux-wpan@vger.kernel.org
6303 S: Maintained 6304 S: Maintained
6304 F: drivers/net/ieee802154/mrf24j40.c 6305 F: drivers/net/ieee802154/mrf24j40.c
6305 6306
6306 MSI LAPTOP SUPPORT 6307 MSI LAPTOP SUPPORT
6307 M: "Lee, Chun-Yi" <jlee@suse.com> 6308 M: "Lee, Chun-Yi" <jlee@suse.com>
6308 L: platform-driver-x86@vger.kernel.org 6309 L: platform-driver-x86@vger.kernel.org
6309 S: Maintained 6310 S: Maintained
6310 F: drivers/platform/x86/msi-laptop.c 6311 F: drivers/platform/x86/msi-laptop.c
6311 6312
6312 MSI WMI SUPPORT 6313 MSI WMI SUPPORT
6313 M: Anisse Astier <anisse@astier.eu> 6314 M: Anisse Astier <anisse@astier.eu>
6314 L: platform-driver-x86@vger.kernel.org 6315 L: platform-driver-x86@vger.kernel.org
6315 S: Supported 6316 S: Supported
6316 F: drivers/platform/x86/msi-wmi.c 6317 F: drivers/platform/x86/msi-wmi.c
6317 6318
6318 MSI001 MEDIA DRIVER 6319 MSI001 MEDIA DRIVER
6319 M: Antti Palosaari <crope@iki.fi> 6320 M: Antti Palosaari <crope@iki.fi>
6320 L: linux-media@vger.kernel.org 6321 L: linux-media@vger.kernel.org
6321 W: http://linuxtv.org/ 6322 W: http://linuxtv.org/
6322 W: http://palosaari.fi/linux/ 6323 W: http://palosaari.fi/linux/
6323 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 6324 Q: http://patchwork.linuxtv.org/project/linux-media/list/
6324 T: git git://linuxtv.org/anttip/media_tree.git 6325 T: git git://linuxtv.org/anttip/media_tree.git
6325 S: Maintained 6326 S: Maintained
6326 F: drivers/media/tuners/msi001* 6327 F: drivers/media/tuners/msi001*
6327 6328
6328 MSI2500 MEDIA DRIVER 6329 MSI2500 MEDIA DRIVER
6329 M: Antti Palosaari <crope@iki.fi> 6330 M: Antti Palosaari <crope@iki.fi>
6330 L: linux-media@vger.kernel.org 6331 L: linux-media@vger.kernel.org
6331 W: http://linuxtv.org/ 6332 W: http://linuxtv.org/
6332 W: http://palosaari.fi/linux/ 6333 W: http://palosaari.fi/linux/
6333 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 6334 Q: http://patchwork.linuxtv.org/project/linux-media/list/
6334 T: git git://linuxtv.org/anttip/media_tree.git 6335 T: git git://linuxtv.org/anttip/media_tree.git
6335 S: Maintained 6336 S: Maintained
6336 F: drivers/media/usb/msi2500/ 6337 F: drivers/media/usb/msi2500/
6337 6338
6338 MT9M032 APTINA SENSOR DRIVER 6339 MT9M032 APTINA SENSOR DRIVER
6339 M: Laurent Pinchart <laurent.pinchart@ideasonboard.com> 6340 M: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
6340 L: linux-media@vger.kernel.org 6341 L: linux-media@vger.kernel.org
6341 T: git git://linuxtv.org/media_tree.git 6342 T: git git://linuxtv.org/media_tree.git
6342 S: Maintained 6343 S: Maintained
6343 F: drivers/media/i2c/mt9m032.c 6344 F: drivers/media/i2c/mt9m032.c
6344 F: include/media/mt9m032.h 6345 F: include/media/mt9m032.h
6345 6346
6346 MT9P031 APTINA CAMERA SENSOR 6347 MT9P031 APTINA CAMERA SENSOR
6347 M: Laurent Pinchart <laurent.pinchart@ideasonboard.com> 6348 M: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
6348 L: linux-media@vger.kernel.org 6349 L: linux-media@vger.kernel.org
6349 T: git git://linuxtv.org/media_tree.git 6350 T: git git://linuxtv.org/media_tree.git
6350 S: Maintained 6351 S: Maintained
6351 F: drivers/media/i2c/mt9p031.c 6352 F: drivers/media/i2c/mt9p031.c
6352 F: include/media/mt9p031.h 6353 F: include/media/mt9p031.h
6353 6354
6354 MT9T001 APTINA CAMERA SENSOR 6355 MT9T001 APTINA CAMERA SENSOR
6355 M: Laurent Pinchart <laurent.pinchart@ideasonboard.com> 6356 M: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
6356 L: linux-media@vger.kernel.org 6357 L: linux-media@vger.kernel.org
6357 T: git git://linuxtv.org/media_tree.git 6358 T: git git://linuxtv.org/media_tree.git
6358 S: Maintained 6359 S: Maintained
6359 F: drivers/media/i2c/mt9t001.c 6360 F: drivers/media/i2c/mt9t001.c
6360 F: include/media/mt9t001.h 6361 F: include/media/mt9t001.h
6361 6362
6362 MT9V032 APTINA CAMERA SENSOR 6363 MT9V032 APTINA CAMERA SENSOR
6363 M: Laurent Pinchart <laurent.pinchart@ideasonboard.com> 6364 M: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
6364 L: linux-media@vger.kernel.org 6365 L: linux-media@vger.kernel.org
6365 T: git git://linuxtv.org/media_tree.git 6366 T: git git://linuxtv.org/media_tree.git
6366 S: Maintained 6367 S: Maintained
6367 F: drivers/media/i2c/mt9v032.c 6368 F: drivers/media/i2c/mt9v032.c
6368 F: include/media/mt9v032.h 6369 F: include/media/mt9v032.h
6369 6370
6370 MULTIFUNCTION DEVICES (MFD) 6371 MULTIFUNCTION DEVICES (MFD)
6371 M: Samuel Ortiz <sameo@linux.intel.com> 6372 M: Samuel Ortiz <sameo@linux.intel.com>
6372 M: Lee Jones <lee.jones@linaro.org> 6373 M: Lee Jones <lee.jones@linaro.org>
6373 T: git git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git 6374 T: git git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git
6374 S: Supported 6375 S: Supported
6375 F: drivers/mfd/ 6376 F: drivers/mfd/
6376 F: include/linux/mfd/ 6377 F: include/linux/mfd/
6377 6378
6378 MULTIMEDIA CARD (MMC), SECURE DIGITAL (SD) AND SDIO SUBSYSTEM 6379 MULTIMEDIA CARD (MMC), SECURE DIGITAL (SD) AND SDIO SUBSYSTEM
6379 M: Chris Ball <chris@printf.net> 6380 M: Chris Ball <chris@printf.net>
6380 M: Ulf Hansson <ulf.hansson@linaro.org> 6381 M: Ulf Hansson <ulf.hansson@linaro.org>
6381 L: linux-mmc@vger.kernel.org 6382 L: linux-mmc@vger.kernel.org
6382 T: git git://git.kernel.org/pub/scm/linux/kernel/git/cjb/mmc.git 6383 T: git git://git.kernel.org/pub/scm/linux/kernel/git/cjb/mmc.git
6383 T: git git://git.linaro.org/people/ulf.hansson/mmc.git 6384 T: git git://git.linaro.org/people/ulf.hansson/mmc.git
6384 S: Maintained 6385 S: Maintained
6385 F: drivers/mmc/ 6386 F: drivers/mmc/
6386 F: include/linux/mmc/ 6387 F: include/linux/mmc/
6387 F: include/uapi/linux/mmc/ 6388 F: include/uapi/linux/mmc/
6388 6389
6389 MULTIMEDIA CARD (MMC) ETC. OVER SPI 6390 MULTIMEDIA CARD (MMC) ETC. OVER SPI
6390 S: Orphan 6391 S: Orphan
6391 F: drivers/mmc/host/mmc_spi.c 6392 F: drivers/mmc/host/mmc_spi.c
6392 F: include/linux/spi/mmc_spi.h 6393 F: include/linux/spi/mmc_spi.h
6393 6394
6394 MULTISOUND SOUND DRIVER 6395 MULTISOUND SOUND DRIVER
6395 M: Andrew Veliath <andrewtv@usa.net> 6396 M: Andrew Veliath <andrewtv@usa.net>
6396 S: Maintained 6397 S: Maintained
6397 F: Documentation/sound/oss/MultiSound 6398 F: Documentation/sound/oss/MultiSound
6398 F: sound/oss/msnd* 6399 F: sound/oss/msnd*
6399 6400
6400 MULTITECH MULTIPORT CARD (ISICOM) 6401 MULTITECH MULTIPORT CARD (ISICOM)
6401 S: Orphan 6402 S: Orphan
6402 F: drivers/tty/isicom.c 6403 F: drivers/tty/isicom.c
6403 F: include/linux/isicom.h 6404 F: include/linux/isicom.h
6404 6405
6405 MUSB MULTIPOINT HIGH SPEED DUAL-ROLE CONTROLLER 6406 MUSB MULTIPOINT HIGH SPEED DUAL-ROLE CONTROLLER
6406 M: Felipe Balbi <balbi@ti.com> 6407 M: Felipe Balbi <balbi@ti.com>
6407 L: linux-usb@vger.kernel.org 6408 L: linux-usb@vger.kernel.org
6408 T: git git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git 6409 T: git git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git
6409 S: Maintained 6410 S: Maintained
6410 F: drivers/usb/musb/ 6411 F: drivers/usb/musb/
6411 6412
6412 MXL5007T MEDIA DRIVER 6413 MXL5007T MEDIA DRIVER
6413 M: Michael Krufky <mkrufky@linuxtv.org> 6414 M: Michael Krufky <mkrufky@linuxtv.org>
6414 L: linux-media@vger.kernel.org 6415 L: linux-media@vger.kernel.org
6415 W: http://linuxtv.org/ 6416 W: http://linuxtv.org/
6416 W: http://github.com/mkrufky 6417 W: http://github.com/mkrufky
6417 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 6418 Q: http://patchwork.linuxtv.org/project/linux-media/list/
6418 T: git git://linuxtv.org/mkrufky/tuners.git 6419 T: git git://linuxtv.org/mkrufky/tuners.git
6419 S: Maintained 6420 S: Maintained
6420 F: drivers/media/tuners/mxl5007t.* 6421 F: drivers/media/tuners/mxl5007t.*
6421 6422
6422 MYRICOM MYRI-10G 10GbE DRIVER (MYRI10GE) 6423 MYRICOM MYRI-10G 10GbE DRIVER (MYRI10GE)
6423 M: Hyong-Youb Kim <hykim@myri.com> 6424 M: Hyong-Youb Kim <hykim@myri.com>
6424 L: netdev@vger.kernel.org 6425 L: netdev@vger.kernel.org
6425 W: https://www.myricom.com/support/downloads/myri10ge.html 6426 W: https://www.myricom.com/support/downloads/myri10ge.html
6426 S: Supported 6427 S: Supported
6427 F: drivers/net/ethernet/myricom/myri10ge/ 6428 F: drivers/net/ethernet/myricom/myri10ge/
6428 6429
6429 NATSEMI ETHERNET DRIVER (DP8381x) 6430 NATSEMI ETHERNET DRIVER (DP8381x)
6430 S: Orphan 6431 S: Orphan
6431 F: drivers/net/ethernet/natsemi/natsemi.c 6432 F: drivers/net/ethernet/natsemi/natsemi.c
6432 6433
6433 NATIVE INSTRUMENTS USB SOUND INTERFACE DRIVER 6434 NATIVE INSTRUMENTS USB SOUND INTERFACE DRIVER
6434 M: Daniel Mack <zonque@gmail.com> 6435 M: Daniel Mack <zonque@gmail.com>
6435 S: Maintained 6436 S: Maintained
6436 L: alsa-devel@alsa-project.org 6437 L: alsa-devel@alsa-project.org
6437 W: http://www.native-instruments.com 6438 W: http://www.native-instruments.com
6438 F: sound/usb/caiaq/ 6439 F: sound/usb/caiaq/
6439 6440
6440 NCP FILESYSTEM 6441 NCP FILESYSTEM
6441 M: Petr Vandrovec <petr@vandrovec.name> 6442 M: Petr Vandrovec <petr@vandrovec.name>
6442 S: Odd Fixes 6443 S: Odd Fixes
6443 F: fs/ncpfs/ 6444 F: fs/ncpfs/
6444 6445
6445 NCR 5380 SCSI DRIVERS 6446 NCR 5380 SCSI DRIVERS
6446 M: Finn Thain <fthain@telegraphics.com.au> 6447 M: Finn Thain <fthain@telegraphics.com.au>
6447 M: Michael Schmitz <schmitzmic@gmail.com> 6448 M: Michael Schmitz <schmitzmic@gmail.com>
6448 L: linux-scsi@vger.kernel.org 6449 L: linux-scsi@vger.kernel.org
6449 S: Maintained 6450 S: Maintained
6450 F: Documentation/scsi/g_NCR5380.txt 6451 F: Documentation/scsi/g_NCR5380.txt
6451 F: drivers/scsi/NCR5380.* 6452 F: drivers/scsi/NCR5380.*
6452 F: drivers/scsi/arm/cumana_1.c 6453 F: drivers/scsi/arm/cumana_1.c
6453 F: drivers/scsi/arm/oak.c 6454 F: drivers/scsi/arm/oak.c
6454 F: drivers/scsi/atari_NCR5380.c 6455 F: drivers/scsi/atari_NCR5380.c
6455 F: drivers/scsi/atari_scsi.* 6456 F: drivers/scsi/atari_scsi.*
6456 F: drivers/scsi/dmx3191d.c 6457 F: drivers/scsi/dmx3191d.c
6457 F: drivers/scsi/dtc.* 6458 F: drivers/scsi/dtc.*
6458 F: drivers/scsi/g_NCR5380.* 6459 F: drivers/scsi/g_NCR5380.*
6459 F: drivers/scsi/g_NCR5380_mmio.c 6460 F: drivers/scsi/g_NCR5380_mmio.c
6460 F: drivers/scsi/mac_scsi.* 6461 F: drivers/scsi/mac_scsi.*
6461 F: drivers/scsi/pas16.* 6462 F: drivers/scsi/pas16.*
6462 F: drivers/scsi/sun3_scsi.* 6463 F: drivers/scsi/sun3_scsi.*
6463 F: drivers/scsi/sun3_scsi_vme.c 6464 F: drivers/scsi/sun3_scsi_vme.c
6464 F: drivers/scsi/t128.* 6465 F: drivers/scsi/t128.*
6465 6466
6466 NCR DUAL 700 SCSI DRIVER (MICROCHANNEL) 6467 NCR DUAL 700 SCSI DRIVER (MICROCHANNEL)
6467 M: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com> 6468 M: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
6468 L: linux-scsi@vger.kernel.org 6469 L: linux-scsi@vger.kernel.org
6469 S: Maintained 6470 S: Maintained
6470 F: drivers/scsi/NCR_D700.* 6471 F: drivers/scsi/NCR_D700.*
6471 6472
6472 NCT6775 HARDWARE MONITOR DRIVER 6473 NCT6775 HARDWARE MONITOR DRIVER
6473 M: Guenter Roeck <linux@roeck-us.net> 6474 M: Guenter Roeck <linux@roeck-us.net>
6474 L: lm-sensors@lm-sensors.org 6475 L: lm-sensors@lm-sensors.org
6475 S: Maintained 6476 S: Maintained
6476 F: Documentation/hwmon/nct6775 6477 F: Documentation/hwmon/nct6775
6477 F: drivers/hwmon/nct6775.c 6478 F: drivers/hwmon/nct6775.c
6478 6479
6479 NETEFFECT IWARP RNIC DRIVER (IW_NES) 6480 NETEFFECT IWARP RNIC DRIVER (IW_NES)
6480 M: Faisal Latif <faisal.latif@intel.com> 6481 M: Faisal Latif <faisal.latif@intel.com>
6481 L: linux-rdma@vger.kernel.org 6482 L: linux-rdma@vger.kernel.org
6482 W: http://www.intel.com/Products/Server/Adapters/Server-Cluster/Server-Cluster-overview.htm 6483 W: http://www.intel.com/Products/Server/Adapters/Server-Cluster/Server-Cluster-overview.htm
6483 S: Supported 6484 S: Supported
6484 F: drivers/infiniband/hw/nes/ 6485 F: drivers/infiniband/hw/nes/
6485 6486
6486 NETEM NETWORK EMULATOR 6487 NETEM NETWORK EMULATOR
6487 M: Stephen Hemminger <stephen@networkplumber.org> 6488 M: Stephen Hemminger <stephen@networkplumber.org>
6488 L: netem@lists.linux-foundation.org 6489 L: netem@lists.linux-foundation.org
6489 S: Maintained 6490 S: Maintained
6490 F: net/sched/sch_netem.c 6491 F: net/sched/sch_netem.c
6491 6492
6492 NETERION 10GbE DRIVERS (s2io/vxge) 6493 NETERION 10GbE DRIVERS (s2io/vxge)
6493 M: Jon Mason <jdmason@kudzu.us> 6494 M: Jon Mason <jdmason@kudzu.us>
6494 L: netdev@vger.kernel.org 6495 L: netdev@vger.kernel.org
6495 S: Supported 6496 S: Supported
6496 F: Documentation/networking/s2io.txt 6497 F: Documentation/networking/s2io.txt
6497 F: Documentation/networking/vxge.txt 6498 F: Documentation/networking/vxge.txt
6498 F: drivers/net/ethernet/neterion/ 6499 F: drivers/net/ethernet/neterion/
6499 6500
6500 NETFILTER ({IP,IP6,ARP,EB,NF}TABLES) 6501 NETFILTER ({IP,IP6,ARP,EB,NF}TABLES)
6501 M: Pablo Neira Ayuso <pablo@netfilter.org> 6502 M: Pablo Neira Ayuso <pablo@netfilter.org>
6502 M: Patrick McHardy <kaber@trash.net> 6503 M: Patrick McHardy <kaber@trash.net>
6503 M: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu> 6504 M: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6504 L: netfilter-devel@vger.kernel.org 6505 L: netfilter-devel@vger.kernel.org
6505 L: coreteam@netfilter.org 6506 L: coreteam@netfilter.org
6506 W: http://www.netfilter.org/ 6507 W: http://www.netfilter.org/
6507 W: http://www.iptables.org/ 6508 W: http://www.iptables.org/
6508 Q: http://patchwork.ozlabs.org/project/netfilter-devel/list/ 6509 Q: http://patchwork.ozlabs.org/project/netfilter-devel/list/
6509 T: git git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git 6510 T: git git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
6510 T: git git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git 6511 T: git git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git
6511 S: Supported 6512 S: Supported
6512 F: include/linux/netfilter* 6513 F: include/linux/netfilter*
6513 F: include/linux/netfilter/ 6514 F: include/linux/netfilter/
6514 F: include/net/netfilter/ 6515 F: include/net/netfilter/
6515 F: include/uapi/linux/netfilter* 6516 F: include/uapi/linux/netfilter*
6516 F: include/uapi/linux/netfilter/ 6517 F: include/uapi/linux/netfilter/
6517 F: net/*/netfilter.c 6518 F: net/*/netfilter.c
6518 F: net/*/netfilter/ 6519 F: net/*/netfilter/
6519 F: net/netfilter/ 6520 F: net/netfilter/
6520 6521
6521 NETLABEL 6522 NETLABEL
6522 M: Paul Moore <paul@paul-moore.com> 6523 M: Paul Moore <paul@paul-moore.com>
6523 W: http://netlabel.sf.net 6524 W: http://netlabel.sf.net
6524 L: netdev@vger.kernel.org 6525 L: netdev@vger.kernel.org
6525 S: Maintained 6526 S: Maintained
6526 F: Documentation/netlabel/ 6527 F: Documentation/netlabel/
6527 F: include/net/netlabel.h 6528 F: include/net/netlabel.h
6528 F: net/netlabel/ 6529 F: net/netlabel/
6529 6530
6530 NETROM NETWORK LAYER 6531 NETROM NETWORK LAYER
6531 M: Ralf Baechle <ralf@linux-mips.org> 6532 M: Ralf Baechle <ralf@linux-mips.org>
6532 L: linux-hams@vger.kernel.org 6533 L: linux-hams@vger.kernel.org
6533 W: http://www.linux-ax25.org/ 6534 W: http://www.linux-ax25.org/
6534 S: Maintained 6535 S: Maintained
6535 F: include/net/netrom.h 6536 F: include/net/netrom.h
6536 F: include/uapi/linux/netrom.h 6537 F: include/uapi/linux/netrom.h
6537 F: net/netrom/ 6538 F: net/netrom/
6538 6539
6539 NETWORK BLOCK DEVICE (NBD) 6540 NETWORK BLOCK DEVICE (NBD)
6540 M: Paul Clements <Paul.Clements@steeleye.com> 6541 M: Paul Clements <Paul.Clements@steeleye.com>
6541 S: Maintained 6542 S: Maintained
6542 L: nbd-general@lists.sourceforge.net 6543 L: nbd-general@lists.sourceforge.net
6543 F: Documentation/blockdev/nbd.txt 6544 F: Documentation/blockdev/nbd.txt
6544 F: drivers/block/nbd.c 6545 F: drivers/block/nbd.c
6545 F: include/linux/nbd.h 6546 F: include/linux/nbd.h
6546 F: include/uapi/linux/nbd.h 6547 F: include/uapi/linux/nbd.h
6547 6548
6548 NETWORK DROP MONITOR 6549 NETWORK DROP MONITOR
6549 M: Neil Horman <nhorman@tuxdriver.com> 6550 M: Neil Horman <nhorman@tuxdriver.com>
6550 L: netdev@vger.kernel.org 6551 L: netdev@vger.kernel.org
6551 S: Maintained 6552 S: Maintained
6552 W: https://fedorahosted.org/dropwatch/ 6553 W: https://fedorahosted.org/dropwatch/
6553 F: net/core/drop_monitor.c 6554 F: net/core/drop_monitor.c
6554 6555
6555 NETWORKING [GENERAL] 6556 NETWORKING [GENERAL]
6556 M: "David S. Miller" <davem@davemloft.net> 6557 M: "David S. Miller" <davem@davemloft.net>
6557 L: netdev@vger.kernel.org 6558 L: netdev@vger.kernel.org
6558 W: http://www.linuxfoundation.org/en/Net 6559 W: http://www.linuxfoundation.org/en/Net
6559 Q: http://patchwork.ozlabs.org/project/netdev/list/ 6560 Q: http://patchwork.ozlabs.org/project/netdev/list/
6560 T: git git://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git 6561 T: git git://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git
6561 T: git git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 6562 T: git git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git
6562 S: Maintained 6563 S: Maintained
6563 F: net/ 6564 F: net/
6564 F: include/net/ 6565 F: include/net/
6565 F: include/linux/in.h 6566 F: include/linux/in.h
6566 F: include/linux/net.h 6567 F: include/linux/net.h
6567 F: include/linux/netdevice.h 6568 F: include/linux/netdevice.h
6568 F: include/uapi/linux/in.h 6569 F: include/uapi/linux/in.h
6569 F: include/uapi/linux/net.h 6570 F: include/uapi/linux/net.h
6570 F: include/uapi/linux/netdevice.h 6571 F: include/uapi/linux/netdevice.h
6571 F: tools/net/ 6572 F: tools/net/
6572 F: tools/testing/selftests/net/ 6573 F: tools/testing/selftests/net/
6573 F: lib/random32.c 6574 F: lib/random32.c
6574 F: lib/test_bpf.c 6575 F: lib/test_bpf.c
6575 6576
6576 NETWORKING [IPv4/IPv6] 6577 NETWORKING [IPv4/IPv6]
6577 M: "David S. Miller" <davem@davemloft.net> 6578 M: "David S. Miller" <davem@davemloft.net>
6578 M: Alexey Kuznetsov <kuznet@ms2.inr.ac.ru> 6579 M: Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
6579 M: James Morris <jmorris@namei.org> 6580 M: James Morris <jmorris@namei.org>
6580 M: Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org> 6581 M: Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>
6581 M: Patrick McHardy <kaber@trash.net> 6582 M: Patrick McHardy <kaber@trash.net>
6582 L: netdev@vger.kernel.org 6583 L: netdev@vger.kernel.org
6583 T: git git://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git 6584 T: git git://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git
6584 S: Maintained 6585 S: Maintained
6585 F: net/ipv4/ 6586 F: net/ipv4/
6586 F: net/ipv6/ 6587 F: net/ipv6/
6587 F: include/net/ip* 6588 F: include/net/ip*
6588 F: arch/x86/net/* 6589 F: arch/x86/net/*
6589 6590
6590 NETWORKING [IPSEC] 6591 NETWORKING [IPSEC]
6591 M: Steffen Klassert <steffen.klassert@secunet.com> 6592 M: Steffen Klassert <steffen.klassert@secunet.com>
6592 M: Herbert Xu <herbert@gondor.apana.org.au> 6593 M: Herbert Xu <herbert@gondor.apana.org.au>
6593 M: "David S. Miller" <davem@davemloft.net> 6594 M: "David S. Miller" <davem@davemloft.net>
6594 L: netdev@vger.kernel.org 6595 L: netdev@vger.kernel.org
6595 T: git git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec.git 6596 T: git git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec.git
6596 T: git git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec-next.git 6597 T: git git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec-next.git
6597 S: Maintained 6598 S: Maintained
6598 F: net/core/flow.c 6599 F: net/core/flow.c
6599 F: net/xfrm/ 6600 F: net/xfrm/
6600 F: net/key/ 6601 F: net/key/
6601 F: net/ipv4/xfrm* 6602 F: net/ipv4/xfrm*
6602 F: net/ipv4/esp4.c 6603 F: net/ipv4/esp4.c
6603 F: net/ipv4/ah4.c 6604 F: net/ipv4/ah4.c
6604 F: net/ipv4/ipcomp.c 6605 F: net/ipv4/ipcomp.c
6605 F: net/ipv4/ip_vti.c 6606 F: net/ipv4/ip_vti.c
6606 F: net/ipv6/xfrm* 6607 F: net/ipv6/xfrm*
6607 F: net/ipv6/esp6.c 6608 F: net/ipv6/esp6.c
6608 F: net/ipv6/ah6.c 6609 F: net/ipv6/ah6.c
6609 F: net/ipv6/ipcomp6.c 6610 F: net/ipv6/ipcomp6.c
6610 F: net/ipv6/ip6_vti.c 6611 F: net/ipv6/ip6_vti.c
6611 F: include/uapi/linux/xfrm.h 6612 F: include/uapi/linux/xfrm.h
6612 F: include/net/xfrm.h 6613 F: include/net/xfrm.h
6613 6614
6614 NETWORKING [LABELED] (NetLabel, CIPSO, Labeled IPsec, SECMARK) 6615 NETWORKING [LABELED] (NetLabel, CIPSO, Labeled IPsec, SECMARK)
6615 M: Paul Moore <paul@paul-moore.com> 6616 M: Paul Moore <paul@paul-moore.com>
6616 L: netdev@vger.kernel.org 6617 L: netdev@vger.kernel.org
6617 S: Maintained 6618 S: Maintained
6618 6619
6619 NETWORKING [WIRELESS] 6620 NETWORKING [WIRELESS]
6620 L: linux-wireless@vger.kernel.org 6621 L: linux-wireless@vger.kernel.org
6621 Q: http://patchwork.kernel.org/project/linux-wireless/list/ 6622 Q: http://patchwork.kernel.org/project/linux-wireless/list/
6622 6623
6623 NETWORKING DRIVERS 6624 NETWORKING DRIVERS
6624 L: netdev@vger.kernel.org 6625 L: netdev@vger.kernel.org
6625 W: http://www.linuxfoundation.org/en/Net 6626 W: http://www.linuxfoundation.org/en/Net
6626 Q: http://patchwork.ozlabs.org/project/netdev/list/ 6627 Q: http://patchwork.ozlabs.org/project/netdev/list/
6627 T: git git://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git 6628 T: git git://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git
6628 T: git git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 6629 T: git git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git
6629 S: Odd Fixes 6630 S: Odd Fixes
6630 F: drivers/net/ 6631 F: drivers/net/
6631 F: include/linux/if_* 6632 F: include/linux/if_*
6632 F: include/linux/netdevice.h 6633 F: include/linux/netdevice.h
6633 F: include/linux/arcdevice.h 6634 F: include/linux/arcdevice.h
6634 F: include/linux/etherdevice.h 6635 F: include/linux/etherdevice.h
6635 F: include/linux/fcdevice.h 6636 F: include/linux/fcdevice.h
6636 F: include/linux/fddidevice.h 6637 F: include/linux/fddidevice.h
6637 F: include/linux/hippidevice.h 6638 F: include/linux/hippidevice.h
6638 F: include/linux/inetdevice.h 6639 F: include/linux/inetdevice.h
6639 F: include/uapi/linux/if_* 6640 F: include/uapi/linux/if_*
6640 F: include/uapi/linux/netdevice.h 6641 F: include/uapi/linux/netdevice.h
6641 6642
6642 NETWORKING DRIVERS (WIRELESS) 6643 NETWORKING DRIVERS (WIRELESS)
6643 M: Kalle Valo <kvalo@codeaurora.org> 6644 M: Kalle Valo <kvalo@codeaurora.org>
6644 L: linux-wireless@vger.kernel.org 6645 L: linux-wireless@vger.kernel.org
6645 Q: http://patchwork.kernel.org/project/linux-wireless/list/ 6646 Q: http://patchwork.kernel.org/project/linux-wireless/list/
6646 T: git git://git.kernel.org/pub/scm/linux/kernel/git/kvalo/wireless-drivers.git/ 6647 T: git git://git.kernel.org/pub/scm/linux/kernel/git/kvalo/wireless-drivers.git/
6647 S: Maintained 6648 S: Maintained
6648 F: drivers/net/wireless/ 6649 F: drivers/net/wireless/
6649 6650
6650 NETXEN (1/10) GbE SUPPORT 6651 NETXEN (1/10) GbE SUPPORT
6651 M: Manish Chopra <manish.chopra@qlogic.com> 6652 M: Manish Chopra <manish.chopra@qlogic.com>
6652 M: Sony Chacko <sony.chacko@qlogic.com> 6653 M: Sony Chacko <sony.chacko@qlogic.com>
6653 M: Rajesh Borundia <rajesh.borundia@qlogic.com> 6654 M: Rajesh Borundia <rajesh.borundia@qlogic.com>
6654 L: netdev@vger.kernel.org 6655 L: netdev@vger.kernel.org
6655 W: http://www.qlogic.com 6656 W: http://www.qlogic.com
6656 S: Supported 6657 S: Supported
6657 F: drivers/net/ethernet/qlogic/netxen/ 6658 F: drivers/net/ethernet/qlogic/netxen/
6658 6659
6659 NFC SUBSYSTEM 6660 NFC SUBSYSTEM
6660 M: Lauro Ramos Venancio <lauro.venancio@openbossa.org> 6661 M: Lauro Ramos Venancio <lauro.venancio@openbossa.org>
6661 M: Aloisio Almeida Jr <aloisio.almeida@openbossa.org> 6662 M: Aloisio Almeida Jr <aloisio.almeida@openbossa.org>
6662 M: Samuel Ortiz <sameo@linux.intel.com> 6663 M: Samuel Ortiz <sameo@linux.intel.com>
6663 L: linux-wireless@vger.kernel.org 6664 L: linux-wireless@vger.kernel.org
6664 L: linux-nfc@lists.01.org (subscribers-only) 6665 L: linux-nfc@lists.01.org (subscribers-only)
6665 S: Supported 6666 S: Supported
6666 F: net/nfc/ 6667 F: net/nfc/
6667 F: include/net/nfc/ 6668 F: include/net/nfc/
6668 F: include/uapi/linux/nfc.h 6669 F: include/uapi/linux/nfc.h
6669 F: drivers/nfc/ 6670 F: drivers/nfc/
6670 F: include/linux/platform_data/pn544.h 6671 F: include/linux/platform_data/pn544.h
6671 F: Documentation/devicetree/bindings/net/nfc/ 6672 F: Documentation/devicetree/bindings/net/nfc/
6672 6673
6673 NFS, SUNRPC, AND LOCKD CLIENTS 6674 NFS, SUNRPC, AND LOCKD CLIENTS
6674 M: Trond Myklebust <trond.myklebust@primarydata.com> 6675 M: Trond Myklebust <trond.myklebust@primarydata.com>
6675 L: linux-nfs@vger.kernel.org 6676 L: linux-nfs@vger.kernel.org
6676 W: http://client.linux-nfs.org 6677 W: http://client.linux-nfs.org
6677 T: git git://git.linux-nfs.org/projects/trondmy/linux-nfs.git 6678 T: git git://git.linux-nfs.org/projects/trondmy/linux-nfs.git
6678 S: Maintained 6679 S: Maintained
6679 F: fs/lockd/ 6680 F: fs/lockd/
6680 F: fs/nfs/ 6681 F: fs/nfs/
6681 F: fs/nfs_common/ 6682 F: fs/nfs_common/
6682 F: net/sunrpc/ 6683 F: net/sunrpc/
6683 F: include/linux/lockd/ 6684 F: include/linux/lockd/
6684 F: include/linux/nfs* 6685 F: include/linux/nfs*
6685 F: include/linux/sunrpc/ 6686 F: include/linux/sunrpc/
6686 F: include/uapi/linux/nfs* 6687 F: include/uapi/linux/nfs*
6687 F: include/uapi/linux/sunrpc/ 6688 F: include/uapi/linux/sunrpc/
6688 6689
6689 NILFS2 FILESYSTEM 6690 NILFS2 FILESYSTEM
6690 M: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp> 6691 M: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
6691 L: linux-nilfs@vger.kernel.org 6692 L: linux-nilfs@vger.kernel.org
6692 W: http://nilfs.sourceforge.net/ 6693 W: http://nilfs.sourceforge.net/
6693 T: git git://github.com/konis/nilfs2.git 6694 T: git git://github.com/konis/nilfs2.git
6694 S: Supported 6695 S: Supported
6695 F: Documentation/filesystems/nilfs2.txt 6696 F: Documentation/filesystems/nilfs2.txt
6696 F: fs/nilfs2/ 6697 F: fs/nilfs2/
6697 F: include/linux/nilfs2_fs.h 6698 F: include/linux/nilfs2_fs.h
6698 6699
6699 NINJA SCSI-3 / NINJA SCSI-32Bi (16bit/CardBus) PCMCIA SCSI HOST ADAPTER DRIVER 6700 NINJA SCSI-3 / NINJA SCSI-32Bi (16bit/CardBus) PCMCIA SCSI HOST ADAPTER DRIVER
6700 M: YOKOTA Hiroshi <yokota@netlab.is.tsukuba.ac.jp> 6701 M: YOKOTA Hiroshi <yokota@netlab.is.tsukuba.ac.jp>
6701 W: http://www.netlab.is.tsukuba.ac.jp/~yokota/izumi/ninja/ 6702 W: http://www.netlab.is.tsukuba.ac.jp/~yokota/izumi/ninja/
6702 S: Maintained 6703 S: Maintained
6703 F: Documentation/scsi/NinjaSCSI.txt 6704 F: Documentation/scsi/NinjaSCSI.txt
6704 F: drivers/scsi/pcmcia/nsp_* 6705 F: drivers/scsi/pcmcia/nsp_*
6705 6706
6706 NINJA SCSI-32Bi/UDE PCI/CARDBUS SCSI HOST ADAPTER DRIVER 6707 NINJA SCSI-32Bi/UDE PCI/CARDBUS SCSI HOST ADAPTER DRIVER
6707 M: GOTO Masanori <gotom@debian.or.jp> 6708 M: GOTO Masanori <gotom@debian.or.jp>
6708 M: YOKOTA Hiroshi <yokota@netlab.is.tsukuba.ac.jp> 6709 M: YOKOTA Hiroshi <yokota@netlab.is.tsukuba.ac.jp>
6709 W: http://www.netlab.is.tsukuba.ac.jp/~yokota/izumi/ninja/ 6710 W: http://www.netlab.is.tsukuba.ac.jp/~yokota/izumi/ninja/
6710 S: Maintained 6711 S: Maintained
6711 F: Documentation/scsi/NinjaSCSI.txt 6712 F: Documentation/scsi/NinjaSCSI.txt
6712 F: drivers/scsi/nsp32* 6713 F: drivers/scsi/nsp32*
6713 6714
6714 NIOS2 ARCHITECTURE 6715 NIOS2 ARCHITECTURE
6715 M: Ley Foon Tan <lftan@altera.com> 6716 M: Ley Foon Tan <lftan@altera.com>
6716 L: nios2-dev@lists.rocketboards.org (moderated for non-subscribers) 6717 L: nios2-dev@lists.rocketboards.org (moderated for non-subscribers)
6717 T: git git://git.rocketboards.org/linux-socfpga.git 6718 T: git git://git.rocketboards.org/linux-socfpga.git
6718 S: Maintained 6719 S: Maintained
6719 F: arch/nios2/ 6720 F: arch/nios2/
6720 6721
6721 NTB DRIVER 6722 NTB DRIVER
6722 M: Jon Mason <jdmason@kudzu.us> 6723 M: Jon Mason <jdmason@kudzu.us>
6723 M: Dave Jiang <dave.jiang@intel.com> 6724 M: Dave Jiang <dave.jiang@intel.com>
6724 S: Supported 6725 S: Supported
6725 W: https://github.com/jonmason/ntb/wiki 6726 W: https://github.com/jonmason/ntb/wiki
6726 T: git git://github.com/jonmason/ntb.git 6727 T: git git://github.com/jonmason/ntb.git
6727 F: drivers/ntb/ 6728 F: drivers/ntb/
6728 F: drivers/net/ntb_netdev.c 6729 F: drivers/net/ntb_netdev.c
6729 F: include/linux/ntb.h 6730 F: include/linux/ntb.h
6730 6731
6731 NTFS FILESYSTEM 6732 NTFS FILESYSTEM
6732 M: Anton Altaparmakov <anton@tuxera.com> 6733 M: Anton Altaparmakov <anton@tuxera.com>
6733 L: linux-ntfs-dev@lists.sourceforge.net 6734 L: linux-ntfs-dev@lists.sourceforge.net
6734 W: http://www.tuxera.com/ 6735 W: http://www.tuxera.com/
6735 T: git git://git.kernel.org/pub/scm/linux/kernel/git/aia21/ntfs.git 6736 T: git git://git.kernel.org/pub/scm/linux/kernel/git/aia21/ntfs.git
6736 S: Supported 6737 S: Supported
6737 F: Documentation/filesystems/ntfs.txt 6738 F: Documentation/filesystems/ntfs.txt
6738 F: fs/ntfs/ 6739 F: fs/ntfs/
6739 6740
6740 NVIDIA (rivafb and nvidiafb) FRAMEBUFFER DRIVER 6741 NVIDIA (rivafb and nvidiafb) FRAMEBUFFER DRIVER
6741 M: Antonino Daplas <adaplas@gmail.com> 6742 M: Antonino Daplas <adaplas@gmail.com>
6742 L: linux-fbdev@vger.kernel.org 6743 L: linux-fbdev@vger.kernel.org
6743 S: Maintained 6744 S: Maintained
6744 F: drivers/video/fbdev/riva/ 6745 F: drivers/video/fbdev/riva/
6745 F: drivers/video/fbdev/nvidia/ 6746 F: drivers/video/fbdev/nvidia/
6746 6747
6747 NVM EXPRESS DRIVER 6748 NVM EXPRESS DRIVER
6748 M: Matthew Wilcox <willy@linux.intel.com> 6749 M: Matthew Wilcox <willy@linux.intel.com>
6749 L: linux-nvme@lists.infradead.org 6750 L: linux-nvme@lists.infradead.org
6750 T: git git://git.infradead.org/users/willy/linux-nvme.git 6751 T: git git://git.infradead.org/users/willy/linux-nvme.git
6751 S: Supported 6752 S: Supported
6752 F: drivers/block/nvme* 6753 F: drivers/block/nvme*
6753 F: include/linux/nvme.h 6754 F: include/linux/nvme.h
6754 6755
6755 NXP TDA998X DRM DRIVER 6756 NXP TDA998X DRM DRIVER
6756 M: Russell King <rmk+kernel@arm.linux.org.uk> 6757 M: Russell King <rmk+kernel@arm.linux.org.uk>
6757 S: Supported 6758 S: Supported
6758 F: drivers/gpu/drm/i2c/tda998x_drv.c 6759 F: drivers/gpu/drm/i2c/tda998x_drv.c
6759 F: include/drm/i2c/tda998x.h 6760 F: include/drm/i2c/tda998x.h
6760 6761
6761 NXP TFA9879 DRIVER 6762 NXP TFA9879 DRIVER
6762 M: Peter Rosin <peda@axentia.se> 6763 M: Peter Rosin <peda@axentia.se>
6763 L: alsa-devel@alsa-project.org (moderated for non-subscribers) 6764 L: alsa-devel@alsa-project.org (moderated for non-subscribers)
6764 S: Maintained 6765 S: Maintained
6765 F: sound/soc/codecs/tfa9879* 6766 F: sound/soc/codecs/tfa9879*
6766 6767
6767 OMAP SUPPORT 6768 OMAP SUPPORT
6768 M: Tony Lindgren <tony@atomide.com> 6769 M: Tony Lindgren <tony@atomide.com>
6769 L: linux-omap@vger.kernel.org 6770 L: linux-omap@vger.kernel.org
6770 W: http://www.muru.com/linux/omap/ 6771 W: http://www.muru.com/linux/omap/
6771 W: http://linux.omap.com/ 6772 W: http://linux.omap.com/
6772 Q: http://patchwork.kernel.org/project/linux-omap/list/ 6773 Q: http://patchwork.kernel.org/project/linux-omap/list/
6773 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tmlind/linux-omap.git 6774 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tmlind/linux-omap.git
6774 S: Maintained 6775 S: Maintained
6775 F: arch/arm/*omap*/ 6776 F: arch/arm/*omap*/
6776 F: drivers/i2c/busses/i2c-omap.c 6777 F: drivers/i2c/busses/i2c-omap.c
6777 F: drivers/irqchip/irq-omap-intc.c 6778 F: drivers/irqchip/irq-omap-intc.c
6778 F: drivers/mfd/*omap*.c 6779 F: drivers/mfd/*omap*.c
6779 F: drivers/mfd/menelaus.c 6780 F: drivers/mfd/menelaus.c
6780 F: drivers/mfd/palmas.c 6781 F: drivers/mfd/palmas.c
6781 F: drivers/mfd/tps65217.c 6782 F: drivers/mfd/tps65217.c
6782 F: drivers/mfd/tps65218.c 6783 F: drivers/mfd/tps65218.c
6783 F: drivers/mfd/tps65910.c 6784 F: drivers/mfd/tps65910.c
6784 F: drivers/mfd/twl-core.[ch] 6785 F: drivers/mfd/twl-core.[ch]
6785 F: drivers/mfd/twl4030*.c 6786 F: drivers/mfd/twl4030*.c
6786 F: drivers/mfd/twl6030*.c 6787 F: drivers/mfd/twl6030*.c
6787 F: drivers/mfd/twl6040*.c 6788 F: drivers/mfd/twl6040*.c
6788 F: drivers/regulator/palmas-regulator*.c 6789 F: drivers/regulator/palmas-regulator*.c
6789 F: drivers/regulator/pbias-regulator.c 6790 F: drivers/regulator/pbias-regulator.c
6790 F: drivers/regulator/tps65217-regulator.c 6791 F: drivers/regulator/tps65217-regulator.c
6791 F: drivers/regulator/tps65218-regulator.c 6792 F: drivers/regulator/tps65218-regulator.c
6792 F: drivers/regulator/tps65910-regulator.c 6793 F: drivers/regulator/tps65910-regulator.c
6793 F: drivers/regulator/twl-regulator.c 6794 F: drivers/regulator/twl-regulator.c
6794 F: include/linux/i2c-omap.h 6795 F: include/linux/i2c-omap.h
6795 6796
6796 OMAP DEVICE TREE SUPPORT 6797 OMAP DEVICE TREE SUPPORT
6797 M: Benoรฎt Cousson <bcousson@baylibre.com> 6798 M: Benoรฎt Cousson <bcousson@baylibre.com>
6798 M: Tony Lindgren <tony@atomide.com> 6799 M: Tony Lindgren <tony@atomide.com>
6799 L: linux-omap@vger.kernel.org 6800 L: linux-omap@vger.kernel.org
6800 L: devicetree@vger.kernel.org 6801 L: devicetree@vger.kernel.org
6801 S: Maintained 6802 S: Maintained
6802 F: arch/arm/boot/dts/*omap* 6803 F: arch/arm/boot/dts/*omap*
6803 F: arch/arm/boot/dts/*am3* 6804 F: arch/arm/boot/dts/*am3*
6804 F: arch/arm/boot/dts/*am4* 6805 F: arch/arm/boot/dts/*am4*
6805 F: arch/arm/boot/dts/*am5* 6806 F: arch/arm/boot/dts/*am5*
6806 F: arch/arm/boot/dts/*dra7* 6807 F: arch/arm/boot/dts/*dra7*
6807 6808
6808 OMAP CLOCK FRAMEWORK SUPPORT 6809 OMAP CLOCK FRAMEWORK SUPPORT
6809 M: Paul Walmsley <paul@pwsan.com> 6810 M: Paul Walmsley <paul@pwsan.com>
6810 L: linux-omap@vger.kernel.org 6811 L: linux-omap@vger.kernel.org
6811 S: Maintained 6812 S: Maintained
6812 F: arch/arm/*omap*/*clock* 6813 F: arch/arm/*omap*/*clock*
6813 6814
6814 OMAP POWER MANAGEMENT SUPPORT 6815 OMAP POWER MANAGEMENT SUPPORT
6815 M: Kevin Hilman <khilman@deeprootsystems.com> 6816 M: Kevin Hilman <khilman@deeprootsystems.com>
6816 L: linux-omap@vger.kernel.org 6817 L: linux-omap@vger.kernel.org
6817 S: Maintained 6818 S: Maintained
6818 F: arch/arm/*omap*/*pm* 6819 F: arch/arm/*omap*/*pm*
6819 F: drivers/cpufreq/omap-cpufreq.c 6820 F: drivers/cpufreq/omap-cpufreq.c
6820 6821
6821 OMAP POWERDOMAIN SOC ADAPTATION LAYER SUPPORT 6822 OMAP POWERDOMAIN SOC ADAPTATION LAYER SUPPORT
6822 M: Rajendra Nayak <rnayak@ti.com> 6823 M: Rajendra Nayak <rnayak@ti.com>
6823 M: Paul Walmsley <paul@pwsan.com> 6824 M: Paul Walmsley <paul@pwsan.com>
6824 L: linux-omap@vger.kernel.org 6825 L: linux-omap@vger.kernel.org
6825 S: Maintained 6826 S: Maintained
6826 F: arch/arm/mach-omap2/prm* 6827 F: arch/arm/mach-omap2/prm*
6827 6828
6828 OMAP AUDIO SUPPORT 6829 OMAP AUDIO SUPPORT
6829 M: Peter Ujfalusi <peter.ujfalusi@ti.com> 6830 M: Peter Ujfalusi <peter.ujfalusi@ti.com>
6830 M: Jarkko Nikula <jarkko.nikula@bitmer.com> 6831 M: Jarkko Nikula <jarkko.nikula@bitmer.com>
6831 L: alsa-devel@alsa-project.org (subscribers-only) 6832 L: alsa-devel@alsa-project.org (subscribers-only)
6832 L: linux-omap@vger.kernel.org 6833 L: linux-omap@vger.kernel.org
6833 S: Maintained 6834 S: Maintained
6834 F: sound/soc/omap/ 6835 F: sound/soc/omap/
6835 6836
6836 OMAP GENERAL PURPOSE MEMORY CONTROLLER SUPPORT 6837 OMAP GENERAL PURPOSE MEMORY CONTROLLER SUPPORT
6837 M: Roger Quadros <rogerq@ti.com> 6838 M: Roger Quadros <rogerq@ti.com>
6838 M: Tony Lindgren <tony@atomide.com> 6839 M: Tony Lindgren <tony@atomide.com>
6839 L: linux-omap@vger.kernel.org 6840 L: linux-omap@vger.kernel.org
6840 S: Maintained 6841 S: Maintained
6841 F: drivers/memory/omap-gpmc.c 6842 F: drivers/memory/omap-gpmc.c
6842 F: arch/arm/mach-omap2/*gpmc* 6843 F: arch/arm/mach-omap2/*gpmc*
6843 6844
6844 OMAP FRAMEBUFFER SUPPORT 6845 OMAP FRAMEBUFFER SUPPORT
6845 M: Tomi Valkeinen <tomi.valkeinen@ti.com> 6846 M: Tomi Valkeinen <tomi.valkeinen@ti.com>
6846 L: linux-fbdev@vger.kernel.org 6847 L: linux-fbdev@vger.kernel.org
6847 L: linux-omap@vger.kernel.org 6848 L: linux-omap@vger.kernel.org
6848 S: Maintained 6849 S: Maintained
6849 F: drivers/video/fbdev/omap/ 6850 F: drivers/video/fbdev/omap/
6850 6851
6851 OMAP DISPLAY SUBSYSTEM and FRAMEBUFFER SUPPORT (DSS2) 6852 OMAP DISPLAY SUBSYSTEM and FRAMEBUFFER SUPPORT (DSS2)
6852 M: Tomi Valkeinen <tomi.valkeinen@ti.com> 6853 M: Tomi Valkeinen <tomi.valkeinen@ti.com>
6853 L: linux-omap@vger.kernel.org 6854 L: linux-omap@vger.kernel.org
6854 L: linux-fbdev@vger.kernel.org 6855 L: linux-fbdev@vger.kernel.org
6855 S: Maintained 6856 S: Maintained
6856 F: drivers/video/fbdev/omap2/ 6857 F: drivers/video/fbdev/omap2/
6857 F: Documentation/arm/OMAP/DSS 6858 F: Documentation/arm/OMAP/DSS
6858 6859
6859 OMAP HARDWARE SPINLOCK SUPPORT 6860 OMAP HARDWARE SPINLOCK SUPPORT
6860 M: Ohad Ben-Cohen <ohad@wizery.com> 6861 M: Ohad Ben-Cohen <ohad@wizery.com>
6861 L: linux-omap@vger.kernel.org 6862 L: linux-omap@vger.kernel.org
6862 S: Maintained 6863 S: Maintained
6863 F: drivers/hwspinlock/omap_hwspinlock.c 6864 F: drivers/hwspinlock/omap_hwspinlock.c
6864 F: arch/arm/mach-omap2/hwspinlock.c 6865 F: arch/arm/mach-omap2/hwspinlock.c
6865 6866
6866 OMAP MMC SUPPORT 6867 OMAP MMC SUPPORT
6867 M: Jarkko Lavinen <jarkko.lavinen@nokia.com> 6868 M: Jarkko Lavinen <jarkko.lavinen@nokia.com>
6868 L: linux-omap@vger.kernel.org 6869 L: linux-omap@vger.kernel.org
6869 S: Maintained 6870 S: Maintained
6870 F: drivers/mmc/host/omap.c 6871 F: drivers/mmc/host/omap.c
6871 6872
6872 OMAP HS MMC SUPPORT 6873 OMAP HS MMC SUPPORT
6873 L: linux-mmc@vger.kernel.org 6874 L: linux-mmc@vger.kernel.org
6874 L: linux-omap@vger.kernel.org 6875 L: linux-omap@vger.kernel.org
6875 S: Orphan 6876 S: Orphan
6876 F: drivers/mmc/host/omap_hsmmc.c 6877 F: drivers/mmc/host/omap_hsmmc.c
6877 6878
6878 OMAP RANDOM NUMBER GENERATOR SUPPORT 6879 OMAP RANDOM NUMBER GENERATOR SUPPORT
6879 M: Deepak Saxena <dsaxena@plexity.net> 6880 M: Deepak Saxena <dsaxena@plexity.net>
6880 S: Maintained 6881 S: Maintained
6881 F: drivers/char/hw_random/omap-rng.c 6882 F: drivers/char/hw_random/omap-rng.c
6882 6883
6883 OMAP HWMOD SUPPORT 6884 OMAP HWMOD SUPPORT
6884 M: Benoรฎt Cousson <bcousson@baylibre.com> 6885 M: Benoรฎt Cousson <bcousson@baylibre.com>
6885 M: Paul Walmsley <paul@pwsan.com> 6886 M: Paul Walmsley <paul@pwsan.com>
6886 L: linux-omap@vger.kernel.org 6887 L: linux-omap@vger.kernel.org
6887 S: Maintained 6888 S: Maintained
6888 F: arch/arm/mach-omap2/omap_hwmod.* 6889 F: arch/arm/mach-omap2/omap_hwmod.*
6889 6890
6890 OMAP HWMOD DATA FOR OMAP4-BASED DEVICES 6891 OMAP HWMOD DATA FOR OMAP4-BASED DEVICES
6891 M: Benoรฎt Cousson <bcousson@baylibre.com> 6892 M: Benoรฎt Cousson <bcousson@baylibre.com>
6892 L: linux-omap@vger.kernel.org 6893 L: linux-omap@vger.kernel.org
6893 S: Maintained 6894 S: Maintained
6894 F: arch/arm/mach-omap2/omap_hwmod_44xx_data.c 6895 F: arch/arm/mach-omap2/omap_hwmod_44xx_data.c
6895 6896
6896 OMAP IMAGING SUBSYSTEM (OMAP3 ISP and OMAP4 ISS) 6897 OMAP IMAGING SUBSYSTEM (OMAP3 ISP and OMAP4 ISS)
6897 M: Laurent Pinchart <laurent.pinchart@ideasonboard.com> 6898 M: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
6898 L: linux-media@vger.kernel.org 6899 L: linux-media@vger.kernel.org
6899 S: Maintained 6900 S: Maintained
6900 F: drivers/media/platform/omap3isp/ 6901 F: drivers/media/platform/omap3isp/
6901 F: drivers/staging/media/omap4iss/ 6902 F: drivers/staging/media/omap4iss/
6902 6903
6903 OMAP USB SUPPORT 6904 OMAP USB SUPPORT
6904 M: Felipe Balbi <balbi@ti.com> 6905 M: Felipe Balbi <balbi@ti.com>
6905 L: linux-usb@vger.kernel.org 6906 L: linux-usb@vger.kernel.org
6906 L: linux-omap@vger.kernel.org 6907 L: linux-omap@vger.kernel.org
6907 T: git git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git 6908 T: git git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git
6908 S: Maintained 6909 S: Maintained
6909 F: drivers/usb/*/*omap* 6910 F: drivers/usb/*/*omap*
6910 F: arch/arm/*omap*/usb* 6911 F: arch/arm/*omap*/usb*
6911 6912
6912 OMAP GPIO DRIVER 6913 OMAP GPIO DRIVER
6913 M: Javier Martinez Canillas <javier@dowhile0.org> 6914 M: Javier Martinez Canillas <javier@dowhile0.org>
6914 M: Santosh Shilimkar <ssantosh@kernel.org> 6915 M: Santosh Shilimkar <ssantosh@kernel.org>
6915 M: Kevin Hilman <khilman@deeprootsystems.com> 6916 M: Kevin Hilman <khilman@deeprootsystems.com>
6916 L: linux-omap@vger.kernel.org 6917 L: linux-omap@vger.kernel.org
6917 S: Maintained 6918 S: Maintained
6918 F: drivers/gpio/gpio-omap.c 6919 F: drivers/gpio/gpio-omap.c
6919 6920
6920 OMAP/NEWFLOW NANOBONE MACHINE SUPPORT 6921 OMAP/NEWFLOW NANOBONE MACHINE SUPPORT
6921 M: Mark Jackson <mpfj@newflow.co.uk> 6922 M: Mark Jackson <mpfj@newflow.co.uk>
6922 L: linux-omap@vger.kernel.org 6923 L: linux-omap@vger.kernel.org
6923 S: Maintained 6924 S: Maintained
6924 F: arch/arm/boot/dts/am335x-nano.dts 6925 F: arch/arm/boot/dts/am335x-nano.dts
6925 6926
6926 OMFS FILESYSTEM 6927 OMFS FILESYSTEM
6927 M: Bob Copeland <me@bobcopeland.com> 6928 M: Bob Copeland <me@bobcopeland.com>
6928 L: linux-karma-devel@lists.sourceforge.net 6929 L: linux-karma-devel@lists.sourceforge.net
6929 S: Maintained 6930 S: Maintained
6930 F: Documentation/filesystems/omfs.txt 6931 F: Documentation/filesystems/omfs.txt
6931 F: fs/omfs/ 6932 F: fs/omfs/
6932 6933
6933 OMNIKEY CARDMAN 4000 DRIVER 6934 OMNIKEY CARDMAN 4000 DRIVER
6934 M: Harald Welte <laforge@gnumonks.org> 6935 M: Harald Welte <laforge@gnumonks.org>
6935 S: Maintained 6936 S: Maintained
6936 F: drivers/char/pcmcia/cm4000_cs.c 6937 F: drivers/char/pcmcia/cm4000_cs.c
6937 F: include/linux/cm4000_cs.h 6938 F: include/linux/cm4000_cs.h
6938 F: include/uapi/linux/cm4000_cs.h 6939 F: include/uapi/linux/cm4000_cs.h
6939 6940
6940 OMNIKEY CARDMAN 4040 DRIVER 6941 OMNIKEY CARDMAN 4040 DRIVER
6941 M: Harald Welte <laforge@gnumonks.org> 6942 M: Harald Welte <laforge@gnumonks.org>
6942 S: Maintained 6943 S: Maintained
6943 F: drivers/char/pcmcia/cm4040_cs.* 6944 F: drivers/char/pcmcia/cm4040_cs.*
6944 6945
6945 OMNIVISION OV7670 SENSOR DRIVER 6946 OMNIVISION OV7670 SENSOR DRIVER
6946 M: Jonathan Corbet <corbet@lwn.net> 6947 M: Jonathan Corbet <corbet@lwn.net>
6947 L: linux-media@vger.kernel.org 6948 L: linux-media@vger.kernel.org
6948 T: git git://linuxtv.org/media_tree.git 6949 T: git git://linuxtv.org/media_tree.git
6949 S: Maintained 6950 S: Maintained
6950 F: drivers/media/i2c/ov7670.c 6951 F: drivers/media/i2c/ov7670.c
6951 6952
6952 ONENAND FLASH DRIVER 6953 ONENAND FLASH DRIVER
6953 M: Kyungmin Park <kyungmin.park@samsung.com> 6954 M: Kyungmin Park <kyungmin.park@samsung.com>
6954 L: linux-mtd@lists.infradead.org 6955 L: linux-mtd@lists.infradead.org
6955 S: Maintained 6956 S: Maintained
6956 F: drivers/mtd/onenand/ 6957 F: drivers/mtd/onenand/
6957 F: include/linux/mtd/onenand*.h 6958 F: include/linux/mtd/onenand*.h
6958 6959
6959 ONSTREAM SCSI TAPE DRIVER 6960 ONSTREAM SCSI TAPE DRIVER
6960 M: Willem Riede <osst@riede.org> 6961 M: Willem Riede <osst@riede.org>
6961 L: osst-users@lists.sourceforge.net 6962 L: osst-users@lists.sourceforge.net
6962 L: linux-scsi@vger.kernel.org 6963 L: linux-scsi@vger.kernel.org
6963 S: Maintained 6964 S: Maintained
6964 F: Documentation/scsi/osst.txt 6965 F: Documentation/scsi/osst.txt
6965 F: drivers/scsi/osst.* 6966 F: drivers/scsi/osst.*
6966 F: drivers/scsi/osst_*.h 6967 F: drivers/scsi/osst_*.h
6967 F: drivers/scsi/st.h 6968 F: drivers/scsi/st.h
6968 6969
6969 OPENCORES I2C BUS DRIVER 6970 OPENCORES I2C BUS DRIVER
6970 M: Peter Korsgaard <jacmet@sunsite.dk> 6971 M: Peter Korsgaard <jacmet@sunsite.dk>
6971 L: linux-i2c@vger.kernel.org 6972 L: linux-i2c@vger.kernel.org
6972 S: Maintained 6973 S: Maintained
6973 F: Documentation/i2c/busses/i2c-ocores 6974 F: Documentation/i2c/busses/i2c-ocores
6974 F: drivers/i2c/busses/i2c-ocores.c 6975 F: drivers/i2c/busses/i2c-ocores.c
6975 6976
6976 OPEN FIRMWARE AND FLATTENED DEVICE TREE 6977 OPEN FIRMWARE AND FLATTENED DEVICE TREE
6977 M: Grant Likely <grant.likely@linaro.org> 6978 M: Grant Likely <grant.likely@linaro.org>
6978 M: Rob Herring <robh+dt@kernel.org> 6979 M: Rob Herring <robh+dt@kernel.org>
6979 L: devicetree@vger.kernel.org 6980 L: devicetree@vger.kernel.org
6980 W: http://fdt.secretlab.ca 6981 W: http://fdt.secretlab.ca
6981 T: git git://git.secretlab.ca/git/linux-2.6.git 6982 T: git git://git.secretlab.ca/git/linux-2.6.git
6982 S: Maintained 6983 S: Maintained
6983 F: drivers/of/ 6984 F: drivers/of/
6984 F: include/linux/of*.h 6985 F: include/linux/of*.h
6985 F: scripts/dtc/ 6986 F: scripts/dtc/
6986 K: of_get_property 6987 K: of_get_property
6987 K: of_match_table 6988 K: of_match_table
6988 6989
6989 OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS 6990 OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS
6990 M: Rob Herring <robh+dt@kernel.org> 6991 M: Rob Herring <robh+dt@kernel.org>
6991 M: Pawel Moll <pawel.moll@arm.com> 6992 M: Pawel Moll <pawel.moll@arm.com>
6992 M: Mark Rutland <mark.rutland@arm.com> 6993 M: Mark Rutland <mark.rutland@arm.com>
6993 M: Ian Campbell <ijc+devicetree@hellion.org.uk> 6994 M: Ian Campbell <ijc+devicetree@hellion.org.uk>
6994 M: Kumar Gala <galak@codeaurora.org> 6995 M: Kumar Gala <galak@codeaurora.org>
6995 L: devicetree@vger.kernel.org 6996 L: devicetree@vger.kernel.org
6996 S: Maintained 6997 S: Maintained
6997 F: Documentation/devicetree/ 6998 F: Documentation/devicetree/
6998 F: arch/*/boot/dts/ 6999 F: arch/*/boot/dts/
6999 F: include/dt-bindings/ 7000 F: include/dt-bindings/
7000 7001
7001 OPENRISC ARCHITECTURE 7002 OPENRISC ARCHITECTURE
7002 M: Jonas Bonn <jonas@southpole.se> 7003 M: Jonas Bonn <jonas@southpole.se>
7003 W: http://openrisc.net 7004 W: http://openrisc.net
7004 L: linux@lists.openrisc.net (moderated for non-subscribers) 7005 L: linux@lists.openrisc.net (moderated for non-subscribers)
7005 S: Maintained 7006 S: Maintained
7006 T: git git://openrisc.net/~jonas/linux 7007 T: git git://openrisc.net/~jonas/linux
7007 F: arch/openrisc/ 7008 F: arch/openrisc/
7008 7009
7009 OPENVSWITCH 7010 OPENVSWITCH
7010 M: Pravin Shelar <pshelar@nicira.com> 7011 M: Pravin Shelar <pshelar@nicira.com>
7011 L: dev@openvswitch.org 7012 L: dev@openvswitch.org
7012 W: http://openvswitch.org 7013 W: http://openvswitch.org
7013 T: git git://git.kernel.org/pub/scm/linux/kernel/git/pshelar/openvswitch.git 7014 T: git git://git.kernel.org/pub/scm/linux/kernel/git/pshelar/openvswitch.git
7014 S: Maintained 7015 S: Maintained
7015 F: net/openvswitch/ 7016 F: net/openvswitch/
7016 7017
7017 OPL4 DRIVER 7018 OPL4 DRIVER
7018 M: Clemens Ladisch <clemens@ladisch.de> 7019 M: Clemens Ladisch <clemens@ladisch.de>
7019 L: alsa-devel@alsa-project.org (moderated for non-subscribers) 7020 L: alsa-devel@alsa-project.org (moderated for non-subscribers)
7020 T: git git://git.alsa-project.org/alsa-kernel.git 7021 T: git git://git.alsa-project.org/alsa-kernel.git
7021 S: Maintained 7022 S: Maintained
7022 F: sound/drivers/opl4/ 7023 F: sound/drivers/opl4/
7023 7024
7024 OPROFILE 7025 OPROFILE
7025 M: Robert Richter <rric@kernel.org> 7026 M: Robert Richter <rric@kernel.org>
7026 L: oprofile-list@lists.sf.net 7027 L: oprofile-list@lists.sf.net
7027 S: Maintained 7028 S: Maintained
7028 F: arch/*/include/asm/oprofile*.h 7029 F: arch/*/include/asm/oprofile*.h
7029 F: arch/*/oprofile/ 7030 F: arch/*/oprofile/
7030 F: drivers/oprofile/ 7031 F: drivers/oprofile/
7031 F: include/linux/oprofile.h 7032 F: include/linux/oprofile.h
7032 7033
7033 ORACLE CLUSTER FILESYSTEM 2 (OCFS2) 7034 ORACLE CLUSTER FILESYSTEM 2 (OCFS2)
7034 M: Mark Fasheh <mfasheh@suse.com> 7035 M: Mark Fasheh <mfasheh@suse.com>
7035 M: Joel Becker <jlbec@evilplan.org> 7036 M: Joel Becker <jlbec@evilplan.org>
7036 L: ocfs2-devel@oss.oracle.com (moderated for non-subscribers) 7037 L: ocfs2-devel@oss.oracle.com (moderated for non-subscribers)
7037 W: http://oss.oracle.com/projects/ocfs2/ 7038 W: http://oss.oracle.com/projects/ocfs2/
7038 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jlbec/ocfs2.git 7039 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jlbec/ocfs2.git
7039 S: Supported 7040 S: Supported
7040 F: Documentation/filesystems/ocfs2.txt 7041 F: Documentation/filesystems/ocfs2.txt
7041 F: Documentation/filesystems/dlmfs.txt 7042 F: Documentation/filesystems/dlmfs.txt
7042 F: fs/ocfs2/ 7043 F: fs/ocfs2/
7043 7044
7044 ORINOCO DRIVER 7045 ORINOCO DRIVER
7045 L: linux-wireless@vger.kernel.org 7046 L: linux-wireless@vger.kernel.org
7046 W: http://wireless.kernel.org/en/users/Drivers/orinoco 7047 W: http://wireless.kernel.org/en/users/Drivers/orinoco
7047 W: http://www.nongnu.org/orinoco/ 7048 W: http://www.nongnu.org/orinoco/
7048 S: Orphan 7049 S: Orphan
7049 F: drivers/net/wireless/orinoco/ 7050 F: drivers/net/wireless/orinoco/
7050 7051
7051 OSD LIBRARY and FILESYSTEM 7052 OSD LIBRARY and FILESYSTEM
7052 M: Boaz Harrosh <ooo@electrozaur.com> 7053 M: Boaz Harrosh <ooo@electrozaur.com>
7053 M: Benny Halevy <bhalevy@primarydata.com> 7054 M: Benny Halevy <bhalevy@primarydata.com>
7054 L: osd-dev@open-osd.org 7055 L: osd-dev@open-osd.org
7055 W: http://open-osd.org 7056 W: http://open-osd.org
7056 T: git git://git.open-osd.org/open-osd.git 7057 T: git git://git.open-osd.org/open-osd.git
7057 S: Maintained 7058 S: Maintained
7058 F: drivers/scsi/osd/ 7059 F: drivers/scsi/osd/
7059 F: include/scsi/osd_* 7060 F: include/scsi/osd_*
7060 F: fs/exofs/ 7061 F: fs/exofs/
7061 7062
7062 OVERLAY FILESYSTEM 7063 OVERLAY FILESYSTEM
7063 M: Miklos Szeredi <miklos@szeredi.hu> 7064 M: Miklos Szeredi <miklos@szeredi.hu>
7064 L: linux-unionfs@vger.kernel.org 7065 L: linux-unionfs@vger.kernel.org
7065 T: git git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/vfs.git 7066 T: git git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/vfs.git
7066 S: Supported 7067 S: Supported
7067 F: fs/overlayfs/ 7068 F: fs/overlayfs/
7068 F: Documentation/filesystems/overlayfs.txt 7069 F: Documentation/filesystems/overlayfs.txt
7069 7070
7070 P54 WIRELESS DRIVER 7071 P54 WIRELESS DRIVER
7071 M: Christian Lamparter <chunkeey@googlemail.com> 7072 M: Christian Lamparter <chunkeey@googlemail.com>
7072 L: linux-wireless@vger.kernel.org 7073 L: linux-wireless@vger.kernel.org
7073 W: http://wireless.kernel.org/en/users/Drivers/p54 7074 W: http://wireless.kernel.org/en/users/Drivers/p54
7074 S: Maintained 7075 S: Maintained
7075 F: drivers/net/wireless/p54/ 7076 F: drivers/net/wireless/p54/
7076 7077
7077 PA SEMI ETHERNET DRIVER 7078 PA SEMI ETHERNET DRIVER
7078 M: Olof Johansson <olof@lixom.net> 7079 M: Olof Johansson <olof@lixom.net>
7079 L: netdev@vger.kernel.org 7080 L: netdev@vger.kernel.org
7080 S: Maintained 7081 S: Maintained
7081 F: drivers/net/ethernet/pasemi/* 7082 F: drivers/net/ethernet/pasemi/*
7082 7083
7083 PA SEMI SMBUS DRIVER 7084 PA SEMI SMBUS DRIVER
7084 M: Olof Johansson <olof@lixom.net> 7085 M: Olof Johansson <olof@lixom.net>
7085 L: linux-i2c@vger.kernel.org 7086 L: linux-i2c@vger.kernel.org
7086 S: Maintained 7087 S: Maintained
7087 F: drivers/i2c/busses/i2c-pasemi.c 7088 F: drivers/i2c/busses/i2c-pasemi.c
7088 7089
7089 PADATA PARALLEL EXECUTION MECHANISM 7090 PADATA PARALLEL EXECUTION MECHANISM
7090 M: Steffen Klassert <steffen.klassert@secunet.com> 7091 M: Steffen Klassert <steffen.klassert@secunet.com>
7091 L: linux-crypto@vger.kernel.org 7092 L: linux-crypto@vger.kernel.org
7092 S: Maintained 7093 S: Maintained
7093 F: kernel/padata.c 7094 F: kernel/padata.c
7094 F: include/linux/padata.h 7095 F: include/linux/padata.h
7095 F: Documentation/padata.txt 7096 F: Documentation/padata.txt
7096 7097
7097 PANASONIC LAPTOP ACPI EXTRAS DRIVER 7098 PANASONIC LAPTOP ACPI EXTRAS DRIVER
7098 M: Harald Welte <laforge@gnumonks.org> 7099 M: Harald Welte <laforge@gnumonks.org>
7099 L: platform-driver-x86@vger.kernel.org 7100 L: platform-driver-x86@vger.kernel.org
7100 S: Maintained 7101 S: Maintained
7101 F: drivers/platform/x86/panasonic-laptop.c 7102 F: drivers/platform/x86/panasonic-laptop.c
7102 7103
7103 PANASONIC MN10300/AM33/AM34 PORT 7104 PANASONIC MN10300/AM33/AM34 PORT
7104 M: David Howells <dhowells@redhat.com> 7105 M: David Howells <dhowells@redhat.com>
7105 M: Koichi Yasutake <yasutake.koichi@jp.panasonic.com> 7106 M: Koichi Yasutake <yasutake.koichi@jp.panasonic.com>
7106 L: linux-am33-list@redhat.com (moderated for non-subscribers) 7107 L: linux-am33-list@redhat.com (moderated for non-subscribers)
7107 W: ftp://ftp.redhat.com/pub/redhat/gnupro/AM33/ 7108 W: ftp://ftp.redhat.com/pub/redhat/gnupro/AM33/
7108 S: Maintained 7109 S: Maintained
7109 F: Documentation/mn10300/ 7110 F: Documentation/mn10300/
7110 F: arch/mn10300/ 7111 F: arch/mn10300/
7111 7112
7112 PARALLEL PORT SUPPORT 7113 PARALLEL PORT SUPPORT
7113 L: linux-parport@lists.infradead.org (subscribers-only) 7114 L: linux-parport@lists.infradead.org (subscribers-only)
7114 S: Orphan 7115 S: Orphan
7115 F: drivers/parport/ 7116 F: drivers/parport/
7116 F: include/linux/parport*.h 7117 F: include/linux/parport*.h
7117 F: drivers/char/ppdev.c 7118 F: drivers/char/ppdev.c
7118 F: include/uapi/linux/ppdev.h 7119 F: include/uapi/linux/ppdev.h
7119 7120
7120 PARAVIRT_OPS INTERFACE 7121 PARAVIRT_OPS INTERFACE
7121 M: Jeremy Fitzhardinge <jeremy@goop.org> 7122 M: Jeremy Fitzhardinge <jeremy@goop.org>
7122 M: Chris Wright <chrisw@sous-sol.org> 7123 M: Chris Wright <chrisw@sous-sol.org>
7123 M: Alok Kataria <akataria@vmware.com> 7124 M: Alok Kataria <akataria@vmware.com>
7124 M: Rusty Russell <rusty@rustcorp.com.au> 7125 M: Rusty Russell <rusty@rustcorp.com.au>
7125 L: virtualization@lists.linux-foundation.org 7126 L: virtualization@lists.linux-foundation.org
7126 S: Supported 7127 S: Supported
7127 F: Documentation/ia64/paravirt_ops.txt 7128 F: Documentation/ia64/paravirt_ops.txt
7128 F: arch/*/kernel/paravirt* 7129 F: arch/*/kernel/paravirt*
7129 F: arch/*/include/asm/paravirt.h 7130 F: arch/*/include/asm/paravirt.h
7130 7131
7131 PARIDE DRIVERS FOR PARALLEL PORT IDE DEVICES 7132 PARIDE DRIVERS FOR PARALLEL PORT IDE DEVICES
7132 M: Tim Waugh <tim@cyberelk.net> 7133 M: Tim Waugh <tim@cyberelk.net>
7133 L: linux-parport@lists.infradead.org (subscribers-only) 7134 L: linux-parport@lists.infradead.org (subscribers-only)
7134 W: http://www.torque.net/linux-pp.html 7135 W: http://www.torque.net/linux-pp.html
7135 S: Maintained 7136 S: Maintained
7136 F: Documentation/blockdev/paride.txt 7137 F: Documentation/blockdev/paride.txt
7137 F: drivers/block/paride/ 7138 F: drivers/block/paride/
7138 7139
7139 PARISC ARCHITECTURE 7140 PARISC ARCHITECTURE
7140 M: "James E.J. Bottomley" <jejb@parisc-linux.org> 7141 M: "James E.J. Bottomley" <jejb@parisc-linux.org>
7141 M: Helge Deller <deller@gmx.de> 7142 M: Helge Deller <deller@gmx.de>
7142 L: linux-parisc@vger.kernel.org 7143 L: linux-parisc@vger.kernel.org
7143 W: http://www.parisc-linux.org/ 7144 W: http://www.parisc-linux.org/
7144 Q: http://patchwork.kernel.org/project/linux-parisc/list/ 7145 Q: http://patchwork.kernel.org/project/linux-parisc/list/
7145 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jejb/parisc-2.6.git 7146 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jejb/parisc-2.6.git
7146 T: git git://git.kernel.org/pub/scm/linux/kernel/git/deller/parisc-linux.git 7147 T: git git://git.kernel.org/pub/scm/linux/kernel/git/deller/parisc-linux.git
7147 S: Maintained 7148 S: Maintained
7148 F: arch/parisc/ 7149 F: arch/parisc/
7149 F: Documentation/parisc/ 7150 F: Documentation/parisc/
7150 F: drivers/parisc/ 7151 F: drivers/parisc/
7151 F: drivers/char/agp/parisc-agp.c 7152 F: drivers/char/agp/parisc-agp.c
7152 F: drivers/input/serio/gscps2.c 7153 F: drivers/input/serio/gscps2.c
7153 F: drivers/parport/parport_gsc.* 7154 F: drivers/parport/parport_gsc.*
7154 F: drivers/tty/serial/8250/8250_gsc.c 7155 F: drivers/tty/serial/8250/8250_gsc.c
7155 F: drivers/video/fbdev/sti* 7156 F: drivers/video/fbdev/sti*
7156 F: drivers/video/console/sti* 7157 F: drivers/video/console/sti*
7157 F: drivers/video/logo/logo_parisc* 7158 F: drivers/video/logo/logo_parisc*
7158 7159
7159 PC87360 HARDWARE MONITORING DRIVER 7160 PC87360 HARDWARE MONITORING DRIVER
7160 M: Jim Cromie <jim.cromie@gmail.com> 7161 M: Jim Cromie <jim.cromie@gmail.com>
7161 L: lm-sensors@lm-sensors.org 7162 L: lm-sensors@lm-sensors.org
7162 S: Maintained 7163 S: Maintained
7163 F: Documentation/hwmon/pc87360 7164 F: Documentation/hwmon/pc87360
7164 F: drivers/hwmon/pc87360.c 7165 F: drivers/hwmon/pc87360.c
7165 7166
7166 PC8736x GPIO DRIVER 7167 PC8736x GPIO DRIVER
7167 M: Jim Cromie <jim.cromie@gmail.com> 7168 M: Jim Cromie <jim.cromie@gmail.com>
7168 S: Maintained 7169 S: Maintained
7169 F: drivers/char/pc8736x_gpio.c 7170 F: drivers/char/pc8736x_gpio.c
7170 7171
7171 PC87427 HARDWARE MONITORING DRIVER 7172 PC87427 HARDWARE MONITORING DRIVER
7172 M: Jean Delvare <jdelvare@suse.de> 7173 M: Jean Delvare <jdelvare@suse.de>
7173 L: lm-sensors@lm-sensors.org 7174 L: lm-sensors@lm-sensors.org
7174 S: Maintained 7175 S: Maintained
7175 F: Documentation/hwmon/pc87427 7176 F: Documentation/hwmon/pc87427
7176 F: drivers/hwmon/pc87427.c 7177 F: drivers/hwmon/pc87427.c
7177 7178
7178 PCA9532 LED DRIVER 7179 PCA9532 LED DRIVER
7179 M: Riku Voipio <riku.voipio@iki.fi> 7180 M: Riku Voipio <riku.voipio@iki.fi>
7180 S: Maintained 7181 S: Maintained
7181 F: drivers/leds/leds-pca9532.c 7182 F: drivers/leds/leds-pca9532.c
7182 F: include/linux/leds-pca9532.h 7183 F: include/linux/leds-pca9532.h
7183 7184
7184 PCA9541 I2C BUS MASTER SELECTOR DRIVER 7185 PCA9541 I2C BUS MASTER SELECTOR DRIVER
7185 M: Guenter Roeck <linux@roeck-us.net> 7186 M: Guenter Roeck <linux@roeck-us.net>
7186 L: linux-i2c@vger.kernel.org 7187 L: linux-i2c@vger.kernel.org
7187 S: Maintained 7188 S: Maintained
7188 F: drivers/i2c/muxes/i2c-mux-pca9541.c 7189 F: drivers/i2c/muxes/i2c-mux-pca9541.c
7189 7190
7190 PCDP - PRIMARY CONSOLE AND DEBUG PORT 7191 PCDP - PRIMARY CONSOLE AND DEBUG PORT
7191 M: Khalid Aziz <khalid@gonehiking.org> 7192 M: Khalid Aziz <khalid@gonehiking.org>
7192 S: Maintained 7193 S: Maintained
7193 F: drivers/firmware/pcdp.* 7194 F: drivers/firmware/pcdp.*
7194 7195
7195 PCI ERROR RECOVERY 7196 PCI ERROR RECOVERY
7196 M: Linas Vepstas <linasvepstas@gmail.com> 7197 M: Linas Vepstas <linasvepstas@gmail.com>
7197 L: linux-pci@vger.kernel.org 7198 L: linux-pci@vger.kernel.org
7198 S: Supported 7199 S: Supported
7199 F: Documentation/PCI/pci-error-recovery.txt 7200 F: Documentation/PCI/pci-error-recovery.txt
7200 7201
7201 PCI SUBSYSTEM 7202 PCI SUBSYSTEM
7202 M: Bjorn Helgaas <bhelgaas@google.com> 7203 M: Bjorn Helgaas <bhelgaas@google.com>
7203 L: linux-pci@vger.kernel.org 7204 L: linux-pci@vger.kernel.org
7204 Q: http://patchwork.ozlabs.org/project/linux-pci/list/ 7205 Q: http://patchwork.ozlabs.org/project/linux-pci/list/
7205 T: git git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git 7206 T: git git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git
7206 S: Supported 7207 S: Supported
7207 F: Documentation/PCI/ 7208 F: Documentation/PCI/
7208 F: drivers/pci/ 7209 F: drivers/pci/
7209 F: include/linux/pci* 7210 F: include/linux/pci*
7210 F: arch/x86/pci/ 7211 F: arch/x86/pci/
7211 F: arch/x86/kernel/quirks.c 7212 F: arch/x86/kernel/quirks.c
7212 7213
7213 PCI DRIVER FOR APPLIEDMICRO XGENE 7214 PCI DRIVER FOR APPLIEDMICRO XGENE
7214 M: Tanmay Inamdar <tinamdar@apm.com> 7215 M: Tanmay Inamdar <tinamdar@apm.com>
7215 L: linux-pci@vger.kernel.org 7216 L: linux-pci@vger.kernel.org
7216 L: linux-arm-kernel@lists.infradead.org 7217 L: linux-arm-kernel@lists.infradead.org
7217 S: Maintained 7218 S: Maintained
7218 F: Documentation/devicetree/bindings/pci/xgene-pci.txt 7219 F: Documentation/devicetree/bindings/pci/xgene-pci.txt
7219 F: drivers/pci/host/pci-xgene.c 7220 F: drivers/pci/host/pci-xgene.c
7220 7221
7221 PCI DRIVER FOR FREESCALE LAYERSCAPE 7222 PCI DRIVER FOR FREESCALE LAYERSCAPE
7222 M: Minghuan Lian <minghuan.Lian@freescale.com> 7223 M: Minghuan Lian <minghuan.Lian@freescale.com>
7223 M: Mingkai Hu <mingkai.hu@freescale.com> 7224 M: Mingkai Hu <mingkai.hu@freescale.com>
7224 M: Roy Zang <tie-fei.zang@freescale.com> 7225 M: Roy Zang <tie-fei.zang@freescale.com>
7225 L: linuxppc-dev@lists.ozlabs.org 7226 L: linuxppc-dev@lists.ozlabs.org
7226 L: linux-pci@vger.kernel.org 7227 L: linux-pci@vger.kernel.org
7227 L: linux-arm-kernel@lists.infradead.org 7228 L: linux-arm-kernel@lists.infradead.org
7228 S: Maintained 7229 S: Maintained
7229 F: drivers/pci/host/*layerscape* 7230 F: drivers/pci/host/*layerscape*
7230 7231
7231 PCI DRIVER FOR IMX6 7232 PCI DRIVER FOR IMX6
7232 M: Richard Zhu <r65037@freescale.com> 7233 M: Richard Zhu <r65037@freescale.com>
7233 M: Lucas Stach <l.stach@pengutronix.de> 7234 M: Lucas Stach <l.stach@pengutronix.de>
7234 L: linux-pci@vger.kernel.org 7235 L: linux-pci@vger.kernel.org
7235 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 7236 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
7236 S: Maintained 7237 S: Maintained
7237 F: drivers/pci/host/*imx6* 7238 F: drivers/pci/host/*imx6*
7238 7239
7239 PCI DRIVER FOR TI KEYSTONE 7240 PCI DRIVER FOR TI KEYSTONE
7240 M: Murali Karicheri <m-karicheri2@ti.com> 7241 M: Murali Karicheri <m-karicheri2@ti.com>
7241 L: linux-pci@vger.kernel.org 7242 L: linux-pci@vger.kernel.org
7242 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 7243 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
7243 S: Maintained 7244 S: Maintained
7244 F: drivers/pci/host/*keystone* 7245 F: drivers/pci/host/*keystone*
7245 7246
7246 PCI DRIVER FOR MVEBU (Marvell Armada 370 and Armada XP SOC support) 7247 PCI DRIVER FOR MVEBU (Marvell Armada 370 and Armada XP SOC support)
7247 M: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> 7248 M: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
7248 M: Jason Cooper <jason@lakedaemon.net> 7249 M: Jason Cooper <jason@lakedaemon.net>
7249 L: linux-pci@vger.kernel.org 7250 L: linux-pci@vger.kernel.org
7250 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 7251 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
7251 S: Maintained 7252 S: Maintained
7252 F: drivers/pci/host/*mvebu* 7253 F: drivers/pci/host/*mvebu*
7253 7254
7254 PCI DRIVER FOR NVIDIA TEGRA 7255 PCI DRIVER FOR NVIDIA TEGRA
7255 M: Thierry Reding <thierry.reding@gmail.com> 7256 M: Thierry Reding <thierry.reding@gmail.com>
7256 L: linux-tegra@vger.kernel.org 7257 L: linux-tegra@vger.kernel.org
7257 L: linux-pci@vger.kernel.org 7258 L: linux-pci@vger.kernel.org
7258 S: Supported 7259 S: Supported
7259 F: Documentation/devicetree/bindings/pci/nvidia,tegra20-pcie.txt 7260 F: Documentation/devicetree/bindings/pci/nvidia,tegra20-pcie.txt
7260 F: drivers/pci/host/pci-tegra.c 7261 F: drivers/pci/host/pci-tegra.c
7261 7262
7262 PCI DRIVER FOR TI DRA7XX 7263 PCI DRIVER FOR TI DRA7XX
7263 M: Kishon Vijay Abraham I <kishon@ti.com> 7264 M: Kishon Vijay Abraham I <kishon@ti.com>
7264 L: linux-omap@vger.kernel.org 7265 L: linux-omap@vger.kernel.org
7265 L: linux-pci@vger.kernel.org 7266 L: linux-pci@vger.kernel.org
7266 S: Supported 7267 S: Supported
7267 F: Documentation/devicetree/bindings/pci/ti-pci.txt 7268 F: Documentation/devicetree/bindings/pci/ti-pci.txt
7268 F: drivers/pci/host/pci-dra7xx.c 7269 F: drivers/pci/host/pci-dra7xx.c
7269 7270
7270 PCI DRIVER FOR RENESAS R-CAR 7271 PCI DRIVER FOR RENESAS R-CAR
7271 M: Simon Horman <horms@verge.net.au> 7272 M: Simon Horman <horms@verge.net.au>
7272 L: linux-pci@vger.kernel.org 7273 L: linux-pci@vger.kernel.org
7273 L: linux-sh@vger.kernel.org 7274 L: linux-sh@vger.kernel.org
7274 S: Maintained 7275 S: Maintained
7275 F: drivers/pci/host/*rcar* 7276 F: drivers/pci/host/*rcar*
7276 7277
7277 PCI DRIVER FOR SAMSUNG EXYNOS 7278 PCI DRIVER FOR SAMSUNG EXYNOS
7278 M: Jingoo Han <jg1.han@samsung.com> 7279 M: Jingoo Han <jg1.han@samsung.com>
7279 L: linux-pci@vger.kernel.org 7280 L: linux-pci@vger.kernel.org
7280 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 7281 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
7281 L: linux-samsung-soc@vger.kernel.org (moderated for non-subscribers) 7282 L: linux-samsung-soc@vger.kernel.org (moderated for non-subscribers)
7282 S: Maintained 7283 S: Maintained
7283 F: drivers/pci/host/pci-exynos.c 7284 F: drivers/pci/host/pci-exynos.c
7284 7285
7285 PCI DRIVER FOR SYNOPSIS DESIGNWARE 7286 PCI DRIVER FOR SYNOPSIS DESIGNWARE
7286 M: Mohit Kumar <mohit.kumar@st.com> 7287 M: Mohit Kumar <mohit.kumar@st.com>
7287 M: Jingoo Han <jg1.han@samsung.com> 7288 M: Jingoo Han <jg1.han@samsung.com>
7288 L: linux-pci@vger.kernel.org 7289 L: linux-pci@vger.kernel.org
7289 S: Maintained 7290 S: Maintained
7290 F: drivers/pci/host/*designware* 7291 F: drivers/pci/host/*designware*
7291 7292
7292 PCI DRIVER FOR GENERIC OF HOSTS 7293 PCI DRIVER FOR GENERIC OF HOSTS
7293 M: Will Deacon <will.deacon@arm.com> 7294 M: Will Deacon <will.deacon@arm.com>
7294 L: linux-pci@vger.kernel.org 7295 L: linux-pci@vger.kernel.org
7295 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 7296 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
7296 S: Maintained 7297 S: Maintained
7297 F: Documentation/devicetree/bindings/pci/host-generic-pci.txt 7298 F: Documentation/devicetree/bindings/pci/host-generic-pci.txt
7298 F: drivers/pci/host/pci-host-generic.c 7299 F: drivers/pci/host/pci-host-generic.c
7299 7300
7300 PCIE DRIVER FOR ST SPEAR13XX 7301 PCIE DRIVER FOR ST SPEAR13XX
7301 M: Mohit Kumar <mohit.kumar@st.com> 7302 M: Mohit Kumar <mohit.kumar@st.com>
7302 L: linux-pci@vger.kernel.org 7303 L: linux-pci@vger.kernel.org
7303 S: Maintained 7304 S: Maintained
7304 F: drivers/pci/host/*spear* 7305 F: drivers/pci/host/*spear*
7305 7306
7306 PCMCIA SUBSYSTEM 7307 PCMCIA SUBSYSTEM
7307 P: Linux PCMCIA Team 7308 P: Linux PCMCIA Team
7308 L: linux-pcmcia@lists.infradead.org 7309 L: linux-pcmcia@lists.infradead.org
7309 W: http://lists.infradead.org/mailman/listinfo/linux-pcmcia 7310 W: http://lists.infradead.org/mailman/listinfo/linux-pcmcia
7310 T: git git://git.kernel.org/pub/scm/linux/kernel/git/brodo/pcmcia-2.6.git 7311 T: git git://git.kernel.org/pub/scm/linux/kernel/git/brodo/pcmcia-2.6.git
7311 S: Maintained 7312 S: Maintained
7312 F: Documentation/pcmcia/ 7313 F: Documentation/pcmcia/
7313 F: drivers/pcmcia/ 7314 F: drivers/pcmcia/
7314 F: include/pcmcia/ 7315 F: include/pcmcia/
7315 7316
7316 PCNET32 NETWORK DRIVER 7317 PCNET32 NETWORK DRIVER
7317 M: Don Fry <pcnet32@frontier.com> 7318 M: Don Fry <pcnet32@frontier.com>
7318 L: netdev@vger.kernel.org 7319 L: netdev@vger.kernel.org
7319 S: Maintained 7320 S: Maintained
7320 F: drivers/net/ethernet/amd/pcnet32.c 7321 F: drivers/net/ethernet/amd/pcnet32.c
7321 7322
7322 PCRYPT PARALLEL CRYPTO ENGINE 7323 PCRYPT PARALLEL CRYPTO ENGINE
7323 M: Steffen Klassert <steffen.klassert@secunet.com> 7324 M: Steffen Klassert <steffen.klassert@secunet.com>
7324 L: linux-crypto@vger.kernel.org 7325 L: linux-crypto@vger.kernel.org
7325 S: Maintained 7326 S: Maintained
7326 F: crypto/pcrypt.c 7327 F: crypto/pcrypt.c
7327 F: include/crypto/pcrypt.h 7328 F: include/crypto/pcrypt.h
7328 7329
7329 PER-CPU MEMORY ALLOCATOR 7330 PER-CPU MEMORY ALLOCATOR
7330 M: Tejun Heo <tj@kernel.org> 7331 M: Tejun Heo <tj@kernel.org>
7331 M: Christoph Lameter <cl@linux-foundation.org> 7332 M: Christoph Lameter <cl@linux-foundation.org>
7332 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tj/percpu.git 7333 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tj/percpu.git
7333 S: Maintained 7334 S: Maintained
7334 F: include/linux/percpu*.h 7335 F: include/linux/percpu*.h
7335 F: mm/percpu*.c 7336 F: mm/percpu*.c
7336 F: arch/*/include/asm/percpu.h 7337 F: arch/*/include/asm/percpu.h
7337 7338
7338 PER-TASK DELAY ACCOUNTING 7339 PER-TASK DELAY ACCOUNTING
7339 M: Balbir Singh <bsingharora@gmail.com> 7340 M: Balbir Singh <bsingharora@gmail.com>
7340 S: Maintained 7341 S: Maintained
7341 F: include/linux/delayacct.h 7342 F: include/linux/delayacct.h
7342 F: kernel/delayacct.c 7343 F: kernel/delayacct.c
7343 7344
7344 PERFORMANCE EVENTS SUBSYSTEM 7345 PERFORMANCE EVENTS SUBSYSTEM
7345 M: Peter Zijlstra <a.p.zijlstra@chello.nl> 7346 M: Peter Zijlstra <a.p.zijlstra@chello.nl>
7346 M: Paul Mackerras <paulus@samba.org> 7347 M: Paul Mackerras <paulus@samba.org>
7347 M: Ingo Molnar <mingo@redhat.com> 7348 M: Ingo Molnar <mingo@redhat.com>
7348 M: Arnaldo Carvalho de Melo <acme@kernel.org> 7349 M: Arnaldo Carvalho de Melo <acme@kernel.org>
7349 L: linux-kernel@vger.kernel.org 7350 L: linux-kernel@vger.kernel.org
7350 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git perf/core 7351 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git perf/core
7351 S: Supported 7352 S: Supported
7352 F: kernel/events/* 7353 F: kernel/events/*
7353 F: include/linux/perf_event.h 7354 F: include/linux/perf_event.h
7354 F: include/uapi/linux/perf_event.h 7355 F: include/uapi/linux/perf_event.h
7355 F: arch/*/kernel/perf_event*.c 7356 F: arch/*/kernel/perf_event*.c
7356 F: arch/*/kernel/*/perf_event*.c 7357 F: arch/*/kernel/*/perf_event*.c
7357 F: arch/*/kernel/*/*/perf_event*.c 7358 F: arch/*/kernel/*/*/perf_event*.c
7358 F: arch/*/include/asm/perf_event.h 7359 F: arch/*/include/asm/perf_event.h
7359 F: arch/*/kernel/perf_callchain.c 7360 F: arch/*/kernel/perf_callchain.c
7360 F: tools/perf/ 7361 F: tools/perf/
7361 7362
7362 PERSONALITY HANDLING 7363 PERSONALITY HANDLING
7363 M: Christoph Hellwig <hch@infradead.org> 7364 M: Christoph Hellwig <hch@infradead.org>
7364 L: linux-abi-devel@lists.sourceforge.net 7365 L: linux-abi-devel@lists.sourceforge.net
7365 S: Maintained 7366 S: Maintained
7366 F: include/linux/personality.h 7367 F: include/linux/personality.h
7367 F: include/uapi/linux/personality.h 7368 F: include/uapi/linux/personality.h
7368 7369
7369 PHONET PROTOCOL 7370 PHONET PROTOCOL
7370 M: Remi Denis-Courmont <courmisch@gmail.com> 7371 M: Remi Denis-Courmont <courmisch@gmail.com>
7371 S: Supported 7372 S: Supported
7372 F: Documentation/networking/phonet.txt 7373 F: Documentation/networking/phonet.txt
7373 F: include/linux/phonet.h 7374 F: include/linux/phonet.h
7374 F: include/net/phonet/ 7375 F: include/net/phonet/
7375 F: include/uapi/linux/phonet.h 7376 F: include/uapi/linux/phonet.h
7376 F: net/phonet/ 7377 F: net/phonet/
7377 7378
7378 PHRAM MTD DRIVER 7379 PHRAM MTD DRIVER
7379 M: Joern Engel <joern@lazybastard.org> 7380 M: Joern Engel <joern@lazybastard.org>
7380 L: linux-mtd@lists.infradead.org 7381 L: linux-mtd@lists.infradead.org
7381 S: Maintained 7382 S: Maintained
7382 F: drivers/mtd/devices/phram.c 7383 F: drivers/mtd/devices/phram.c
7383 7384
7384 PICOLCD HID DRIVER 7385 PICOLCD HID DRIVER
7385 M: Bruno Prรฉmont <bonbons@linux-vserver.org> 7386 M: Bruno Prรฉmont <bonbons@linux-vserver.org>
7386 L: linux-input@vger.kernel.org 7387 L: linux-input@vger.kernel.org
7387 S: Maintained 7388 S: Maintained
7388 F: drivers/hid/hid-picolcd* 7389 F: drivers/hid/hid-picolcd*
7389 7390
7390 PICOXCELL SUPPORT 7391 PICOXCELL SUPPORT
7391 M: Jamie Iles <jamie@jamieiles.com> 7392 M: Jamie Iles <jamie@jamieiles.com>
7392 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 7393 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
7393 T: git git://github.com/jamieiles/linux-2.6-ji.git 7394 T: git git://github.com/jamieiles/linux-2.6-ji.git
7394 S: Supported 7395 S: Supported
7395 F: arch/arm/boot/dts/picoxcell* 7396 F: arch/arm/boot/dts/picoxcell*
7396 F: arch/arm/mach-picoxcell/ 7397 F: arch/arm/mach-picoxcell/
7397 F: drivers/crypto/picoxcell* 7398 F: drivers/crypto/picoxcell*
7398 7399
7399 PIN CONTROL SUBSYSTEM 7400 PIN CONTROL SUBSYSTEM
7400 M: Linus Walleij <linus.walleij@linaro.org> 7401 M: Linus Walleij <linus.walleij@linaro.org>
7401 L: linux-gpio@vger.kernel.org 7402 L: linux-gpio@vger.kernel.org
7402 S: Maintained 7403 S: Maintained
7403 F: drivers/pinctrl/ 7404 F: drivers/pinctrl/
7404 F: include/linux/pinctrl/ 7405 F: include/linux/pinctrl/
7405 7406
7406 PIN CONTROLLER - ATMEL AT91 7407 PIN CONTROLLER - ATMEL AT91
7407 M: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com> 7408 M: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>
7408 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 7409 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
7409 S: Maintained 7410 S: Maintained
7410 F: drivers/pinctrl/pinctrl-at91.* 7411 F: drivers/pinctrl/pinctrl-at91.*
7411 7412
7412 PIN CONTROLLER - INTEL 7413 PIN CONTROLLER - INTEL
7413 M: Mika Westerberg <mika.westerberg@linux.intel.com> 7414 M: Mika Westerberg <mika.westerberg@linux.intel.com>
7414 M: Heikki Krogerus <heikki.krogerus@linux.intel.com> 7415 M: Heikki Krogerus <heikki.krogerus@linux.intel.com>
7415 S: Maintained 7416 S: Maintained
7416 F: drivers/pinctrl/intel/ 7417 F: drivers/pinctrl/intel/
7417 7418
7418 PIN CONTROLLER - RENESAS 7419 PIN CONTROLLER - RENESAS
7419 M: Laurent Pinchart <laurent.pinchart@ideasonboard.com> 7420 M: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
7420 L: linux-sh@vger.kernel.org 7421 L: linux-sh@vger.kernel.org
7421 S: Maintained 7422 S: Maintained
7422 F: drivers/pinctrl/sh-pfc/ 7423 F: drivers/pinctrl/sh-pfc/
7423 7424
7424 PIN CONTROLLER - SAMSUNG 7425 PIN CONTROLLER - SAMSUNG
7425 M: Tomasz Figa <tomasz.figa@gmail.com> 7426 M: Tomasz Figa <tomasz.figa@gmail.com>
7426 M: Thomas Abraham <thomas.abraham@linaro.org> 7427 M: Thomas Abraham <thomas.abraham@linaro.org>
7427 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 7428 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
7428 L: linux-samsung-soc@vger.kernel.org (moderated for non-subscribers) 7429 L: linux-samsung-soc@vger.kernel.org (moderated for non-subscribers)
7429 S: Maintained 7430 S: Maintained
7430 F: drivers/pinctrl/samsung/ 7431 F: drivers/pinctrl/samsung/
7431 7432
7432 PIN CONTROLLER - ST SPEAR 7433 PIN CONTROLLER - ST SPEAR
7433 M: Viresh Kumar <viresh.linux@gmail.com> 7434 M: Viresh Kumar <viresh.linux@gmail.com>
7434 L: spear-devel@list.st.com 7435 L: spear-devel@list.st.com
7435 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 7436 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
7436 W: http://www.st.com/spear 7437 W: http://www.st.com/spear
7437 S: Maintained 7438 S: Maintained
7438 F: drivers/pinctrl/spear/ 7439 F: drivers/pinctrl/spear/
7439 7440
7440 PKTCDVD DRIVER 7441 PKTCDVD DRIVER
7441 M: Jiri Kosina <jkosina@suse.cz> 7442 M: Jiri Kosina <jkosina@suse.cz>
7442 S: Maintained 7443 S: Maintained
7443 F: drivers/block/pktcdvd.c 7444 F: drivers/block/pktcdvd.c
7444 F: include/linux/pktcdvd.h 7445 F: include/linux/pktcdvd.h
7445 F: include/uapi/linux/pktcdvd.h 7446 F: include/uapi/linux/pktcdvd.h
7446 7447
7447 PKUNITY SOC DRIVERS 7448 PKUNITY SOC DRIVERS
7448 M: Guan Xuetao <gxt@mprc.pku.edu.cn> 7449 M: Guan Xuetao <gxt@mprc.pku.edu.cn>
7449 W: http://mprc.pku.edu.cn/~guanxuetao/linux 7450 W: http://mprc.pku.edu.cn/~guanxuetao/linux
7450 S: Maintained 7451 S: Maintained
7451 T: git git://github.com/gxt/linux.git 7452 T: git git://github.com/gxt/linux.git
7452 F: drivers/input/serio/i8042-unicore32io.h 7453 F: drivers/input/serio/i8042-unicore32io.h
7453 F: drivers/i2c/busses/i2c-puv3.c 7454 F: drivers/i2c/busses/i2c-puv3.c
7454 F: drivers/video/fbdev/fb-puv3.c 7455 F: drivers/video/fbdev/fb-puv3.c
7455 F: drivers/rtc/rtc-puv3.c 7456 F: drivers/rtc/rtc-puv3.c
7456 7457
7457 PMBUS HARDWARE MONITORING DRIVERS 7458 PMBUS HARDWARE MONITORING DRIVERS
7458 M: Guenter Roeck <linux@roeck-us.net> 7459 M: Guenter Roeck <linux@roeck-us.net>
7459 L: lm-sensors@lm-sensors.org 7460 L: lm-sensors@lm-sensors.org
7460 W: http://www.lm-sensors.org/ 7461 W: http://www.lm-sensors.org/
7461 W: http://www.roeck-us.net/linux/drivers/ 7462 W: http://www.roeck-us.net/linux/drivers/
7462 T: git git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git 7463 T: git git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git
7463 S: Maintained 7464 S: Maintained
7464 F: Documentation/hwmon/pmbus 7465 F: Documentation/hwmon/pmbus
7465 F: drivers/hwmon/pmbus/ 7466 F: drivers/hwmon/pmbus/
7466 F: include/linux/i2c/pmbus.h 7467 F: include/linux/i2c/pmbus.h
7467 7468
7468 PMC SIERRA MaxRAID DRIVER 7469 PMC SIERRA MaxRAID DRIVER
7469 M: Anil Ravindranath <anil_ravindranath@pmc-sierra.com> 7470 M: Anil Ravindranath <anil_ravindranath@pmc-sierra.com>
7470 L: linux-scsi@vger.kernel.org 7471 L: linux-scsi@vger.kernel.org
7471 W: http://www.pmc-sierra.com/ 7472 W: http://www.pmc-sierra.com/
7472 S: Supported 7473 S: Supported
7473 F: drivers/scsi/pmcraid.* 7474 F: drivers/scsi/pmcraid.*
7474 7475
7475 PMC SIERRA PM8001 DRIVER 7476 PMC SIERRA PM8001 DRIVER
7476 M: xjtuwjp@gmail.com 7477 M: xjtuwjp@gmail.com
7477 M: lindar_liu@usish.com 7478 M: lindar_liu@usish.com
7478 L: pmchba@pmcs.com 7479 L: pmchba@pmcs.com
7479 L: linux-scsi@vger.kernel.org 7480 L: linux-scsi@vger.kernel.org
7480 S: Supported 7481 S: Supported
7481 F: drivers/scsi/pm8001/ 7482 F: drivers/scsi/pm8001/
7482 7483
7483 POSIX CLOCKS and TIMERS 7484 POSIX CLOCKS and TIMERS
7484 M: Thomas Gleixner <tglx@linutronix.de> 7485 M: Thomas Gleixner <tglx@linutronix.de>
7485 L: linux-kernel@vger.kernel.org 7486 L: linux-kernel@vger.kernel.org
7486 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git timers/core 7487 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git timers/core
7487 S: Maintained 7488 S: Maintained
7488 F: fs/timerfd.c 7489 F: fs/timerfd.c
7489 F: include/linux/timer* 7490 F: include/linux/timer*
7490 F: kernel/time/*timer* 7491 F: kernel/time/*timer*
7491 7492
7492 POWER SUPPLY CLASS/SUBSYSTEM and DRIVERS 7493 POWER SUPPLY CLASS/SUBSYSTEM and DRIVERS
7493 M: Sebastian Reichel <sre@kernel.org> 7494 M: Sebastian Reichel <sre@kernel.org>
7494 M: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 7495 M: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
7495 M: David Woodhouse <dwmw2@infradead.org> 7496 M: David Woodhouse <dwmw2@infradead.org>
7496 L: linux-pm@vger.kernel.org 7497 L: linux-pm@vger.kernel.org
7497 T: git git://git.infradead.org/battery-2.6.git 7498 T: git git://git.infradead.org/battery-2.6.git
7498 S: Maintained 7499 S: Maintained
7499 F: include/linux/power_supply.h 7500 F: include/linux/power_supply.h
7500 F: drivers/power/ 7501 F: drivers/power/
7501 7502
7502 PNP SUPPORT 7503 PNP SUPPORT
7503 M: Rafael J. Wysocki <rafael.j.wysocki@intel.com> 7504 M: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
7504 S: Maintained 7505 S: Maintained
7505 F: drivers/pnp/ 7506 F: drivers/pnp/
7506 7507
7507 PNXxxxx I2C DRIVER 7508 PNXxxxx I2C DRIVER
7508 M: Vitaly Wool <vitalywool@gmail.com> 7509 M: Vitaly Wool <vitalywool@gmail.com>
7509 L: linux-i2c@vger.kernel.org 7510 L: linux-i2c@vger.kernel.org
7510 S: Maintained 7511 S: Maintained
7511 F: drivers/i2c/busses/i2c-pnx.c 7512 F: drivers/i2c/busses/i2c-pnx.c
7512 7513
7513 PPP PROTOCOL DRIVERS AND COMPRESSORS 7514 PPP PROTOCOL DRIVERS AND COMPRESSORS
7514 M: Paul Mackerras <paulus@samba.org> 7515 M: Paul Mackerras <paulus@samba.org>
7515 L: linux-ppp@vger.kernel.org 7516 L: linux-ppp@vger.kernel.org
7516 S: Maintained 7517 S: Maintained
7517 F: drivers/net/ppp/ppp_* 7518 F: drivers/net/ppp/ppp_*
7518 7519
7519 PPP OVER ATM (RFC 2364) 7520 PPP OVER ATM (RFC 2364)
7520 M: Mitchell Blank Jr <mitch@sfgoth.com> 7521 M: Mitchell Blank Jr <mitch@sfgoth.com>
7521 S: Maintained 7522 S: Maintained
7522 F: net/atm/pppoatm.c 7523 F: net/atm/pppoatm.c
7523 F: include/uapi/linux/atmppp.h 7524 F: include/uapi/linux/atmppp.h
7524 7525
7525 PPP OVER ETHERNET 7526 PPP OVER ETHERNET
7526 M: Michal Ostrowski <mostrows@earthlink.net> 7527 M: Michal Ostrowski <mostrows@earthlink.net>
7527 S: Maintained 7528 S: Maintained
7528 F: drivers/net/ppp/pppoe.c 7529 F: drivers/net/ppp/pppoe.c
7529 F: drivers/net/ppp/pppox.c 7530 F: drivers/net/ppp/pppox.c
7530 7531
7531 PPP OVER L2TP 7532 PPP OVER L2TP
7532 M: James Chapman <jchapman@katalix.com> 7533 M: James Chapman <jchapman@katalix.com>
7533 S: Maintained 7534 S: Maintained
7534 F: net/l2tp/l2tp_ppp.c 7535 F: net/l2tp/l2tp_ppp.c
7535 F: include/linux/if_pppol2tp.h 7536 F: include/linux/if_pppol2tp.h
7536 F: include/uapi/linux/if_pppol2tp.h 7537 F: include/uapi/linux/if_pppol2tp.h
7537 7538
7538 PPS SUPPORT 7539 PPS SUPPORT
7539 M: Rodolfo Giometti <giometti@enneenne.com> 7540 M: Rodolfo Giometti <giometti@enneenne.com>
7540 W: http://wiki.enneenne.com/index.php/LinuxPPS_support 7541 W: http://wiki.enneenne.com/index.php/LinuxPPS_support
7541 L: linuxpps@ml.enneenne.com (subscribers-only) 7542 L: linuxpps@ml.enneenne.com (subscribers-only)
7542 S: Maintained 7543 S: Maintained
7543 F: Documentation/pps/ 7544 F: Documentation/pps/
7544 F: drivers/pps/ 7545 F: drivers/pps/
7545 F: include/linux/pps*.h 7546 F: include/linux/pps*.h
7546 7547
7547 PPTP DRIVER 7548 PPTP DRIVER
7548 M: Dmitry Kozlov <xeb@mail.ru> 7549 M: Dmitry Kozlov <xeb@mail.ru>
7549 L: netdev@vger.kernel.org 7550 L: netdev@vger.kernel.org
7550 S: Maintained 7551 S: Maintained
7551 F: drivers/net/ppp/pptp.c 7552 F: drivers/net/ppp/pptp.c
7552 W: http://sourceforge.net/projects/accel-pptp 7553 W: http://sourceforge.net/projects/accel-pptp
7553 7554
7554 PREEMPTIBLE KERNEL 7555 PREEMPTIBLE KERNEL
7555 M: Robert Love <rml@tech9.net> 7556 M: Robert Love <rml@tech9.net>
7556 L: kpreempt-tech@lists.sourceforge.net 7557 L: kpreempt-tech@lists.sourceforge.net
7557 W: ftp://ftp.kernel.org/pub/linux/kernel/people/rml/preempt-kernel 7558 W: ftp://ftp.kernel.org/pub/linux/kernel/people/rml/preempt-kernel
7558 S: Supported 7559 S: Supported
7559 F: Documentation/preempt-locking.txt 7560 F: Documentation/preempt-locking.txt
7560 F: include/linux/preempt.h 7561 F: include/linux/preempt.h
7561 7562
7562 PRISM54 WIRELESS DRIVER 7563 PRISM54 WIRELESS DRIVER
7563 M: "Luis R. Rodriguez" <mcgrof@gmail.com> 7564 M: "Luis R. Rodriguez" <mcgrof@gmail.com>
7564 L: linux-wireless@vger.kernel.org 7565 L: linux-wireless@vger.kernel.org
7565 W: http://wireless.kernel.org/en/users/Drivers/p54 7566 W: http://wireless.kernel.org/en/users/Drivers/p54
7566 S: Obsolete 7567 S: Obsolete
7567 F: drivers/net/wireless/prism54/ 7568 F: drivers/net/wireless/prism54/
7568 7569
7569 PROMISE SATA TX2/TX4 CONTROLLER LIBATA DRIVER 7570 PROMISE SATA TX2/TX4 CONTROLLER LIBATA DRIVER
7570 M: Mikael Pettersson <mikpelinux@gmail.com> 7571 M: Mikael Pettersson <mikpelinux@gmail.com>
7571 L: linux-ide@vger.kernel.org 7572 L: linux-ide@vger.kernel.org
7572 S: Maintained 7573 S: Maintained
7573 F: drivers/ata/sata_promise.* 7574 F: drivers/ata/sata_promise.*
7574 7575
7575 PS3 NETWORK SUPPORT 7576 PS3 NETWORK SUPPORT
7576 M: Geoff Levand <geoff@infradead.org> 7577 M: Geoff Levand <geoff@infradead.org>
7577 L: netdev@vger.kernel.org 7578 L: netdev@vger.kernel.org
7578 L: cbe-oss-dev@lists.ozlabs.org 7579 L: cbe-oss-dev@lists.ozlabs.org
7579 S: Maintained 7580 S: Maintained
7580 F: drivers/net/ethernet/toshiba/ps3_gelic_net.* 7581 F: drivers/net/ethernet/toshiba/ps3_gelic_net.*
7581 7582
7582 PS3 PLATFORM SUPPORT 7583 PS3 PLATFORM SUPPORT
7583 M: Geoff Levand <geoff@infradead.org> 7584 M: Geoff Levand <geoff@infradead.org>
7584 L: linuxppc-dev@lists.ozlabs.org 7585 L: linuxppc-dev@lists.ozlabs.org
7585 L: cbe-oss-dev@lists.ozlabs.org 7586 L: cbe-oss-dev@lists.ozlabs.org
7586 S: Maintained 7587 S: Maintained
7587 F: arch/powerpc/boot/ps3* 7588 F: arch/powerpc/boot/ps3*
7588 F: arch/powerpc/include/asm/lv1call.h 7589 F: arch/powerpc/include/asm/lv1call.h
7589 F: arch/powerpc/include/asm/ps3*.h 7590 F: arch/powerpc/include/asm/ps3*.h
7590 F: arch/powerpc/platforms/ps3/ 7591 F: arch/powerpc/platforms/ps3/
7591 F: drivers/*/ps3* 7592 F: drivers/*/ps3*
7592 F: drivers/ps3/ 7593 F: drivers/ps3/
7593 F: drivers/rtc/rtc-ps3.c 7594 F: drivers/rtc/rtc-ps3.c
7594 F: drivers/usb/host/*ps3.c 7595 F: drivers/usb/host/*ps3.c
7595 F: sound/ppc/snd_ps3* 7596 F: sound/ppc/snd_ps3*
7596 7597
7597 PS3VRAM DRIVER 7598 PS3VRAM DRIVER
7598 M: Jim Paris <jim@jtan.com> 7599 M: Jim Paris <jim@jtan.com>
7599 L: cbe-oss-dev@lists.ozlabs.org 7600 L: cbe-oss-dev@lists.ozlabs.org
7600 S: Maintained 7601 S: Maintained
7601 F: drivers/block/ps3vram.c 7602 F: drivers/block/ps3vram.c
7602 7603
7603 PSTORE FILESYSTEM 7604 PSTORE FILESYSTEM
7604 M: Anton Vorontsov <anton@enomsg.org> 7605 M: Anton Vorontsov <anton@enomsg.org>
7605 M: Colin Cross <ccross@android.com> 7606 M: Colin Cross <ccross@android.com>
7606 M: Kees Cook <keescook@chromium.org> 7607 M: Kees Cook <keescook@chromium.org>
7607 M: Tony Luck <tony.luck@intel.com> 7608 M: Tony Luck <tony.luck@intel.com>
7608 S: Maintained 7609 S: Maintained
7609 T: git git://git.infradead.org/users/cbou/linux-pstore.git 7610 T: git git://git.infradead.org/users/cbou/linux-pstore.git
7610 F: fs/pstore/ 7611 F: fs/pstore/
7611 F: include/linux/pstore* 7612 F: include/linux/pstore*
7612 F: drivers/firmware/efi/efi-pstore.c 7613 F: drivers/firmware/efi/efi-pstore.c
7613 F: drivers/acpi/apei/erst.c 7614 F: drivers/acpi/apei/erst.c
7614 7615
7615 PTP HARDWARE CLOCK SUPPORT 7616 PTP HARDWARE CLOCK SUPPORT
7616 M: Richard Cochran <richardcochran@gmail.com> 7617 M: Richard Cochran <richardcochran@gmail.com>
7617 L: netdev@vger.kernel.org 7618 L: netdev@vger.kernel.org
7618 S: Maintained 7619 S: Maintained
7619 W: http://linuxptp.sourceforge.net/ 7620 W: http://linuxptp.sourceforge.net/
7620 F: Documentation/ABI/testing/sysfs-ptp 7621 F: Documentation/ABI/testing/sysfs-ptp
7621 F: Documentation/ptp/* 7622 F: Documentation/ptp/*
7622 F: drivers/net/ethernet/freescale/gianfar_ptp.c 7623 F: drivers/net/ethernet/freescale/gianfar_ptp.c
7623 F: drivers/net/phy/dp83640* 7624 F: drivers/net/phy/dp83640*
7624 F: drivers/ptp/* 7625 F: drivers/ptp/*
7625 F: include/linux/ptp_cl* 7626 F: include/linux/ptp_cl*
7626 7627
7627 PTRACE SUPPORT 7628 PTRACE SUPPORT
7628 M: Roland McGrath <roland@hack.frob.com> 7629 M: Roland McGrath <roland@hack.frob.com>
7629 M: Oleg Nesterov <oleg@redhat.com> 7630 M: Oleg Nesterov <oleg@redhat.com>
7630 S: Maintained 7631 S: Maintained
7631 F: include/asm-generic/syscall.h 7632 F: include/asm-generic/syscall.h
7632 F: include/linux/ptrace.h 7633 F: include/linux/ptrace.h
7633 F: include/linux/regset.h 7634 F: include/linux/regset.h
7634 F: include/linux/tracehook.h 7635 F: include/linux/tracehook.h
7635 F: include/uapi/linux/ptrace.h 7636 F: include/uapi/linux/ptrace.h
7636 F: kernel/ptrace.c 7637 F: kernel/ptrace.c
7637 7638
7638 PVRUSB2 VIDEO4LINUX DRIVER 7639 PVRUSB2 VIDEO4LINUX DRIVER
7639 M: Mike Isely <isely@pobox.com> 7640 M: Mike Isely <isely@pobox.com>
7640 L: pvrusb2@isely.net (subscribers-only) 7641 L: pvrusb2@isely.net (subscribers-only)
7641 L: linux-media@vger.kernel.org 7642 L: linux-media@vger.kernel.org
7642 W: http://www.isely.net/pvrusb2/ 7643 W: http://www.isely.net/pvrusb2/
7643 T: git git://linuxtv.org/media_tree.git 7644 T: git git://linuxtv.org/media_tree.git
7644 S: Maintained 7645 S: Maintained
7645 F: Documentation/video4linux/README.pvrusb2 7646 F: Documentation/video4linux/README.pvrusb2
7646 F: drivers/media/usb/pvrusb2/ 7647 F: drivers/media/usb/pvrusb2/
7647 7648
7648 PWC WEBCAM DRIVER 7649 PWC WEBCAM DRIVER
7649 M: Hans de Goede <hdegoede@redhat.com> 7650 M: Hans de Goede <hdegoede@redhat.com>
7650 L: linux-media@vger.kernel.org 7651 L: linux-media@vger.kernel.org
7651 T: git git://linuxtv.org/media_tree.git 7652 T: git git://linuxtv.org/media_tree.git
7652 S: Maintained 7653 S: Maintained
7653 F: drivers/media/usb/pwc/* 7654 F: drivers/media/usb/pwc/*
7654 7655
7655 PWM FAN DRIVER 7656 PWM FAN DRIVER
7656 M: Kamil Debski <k.debski@samsung.com> 7657 M: Kamil Debski <k.debski@samsung.com>
7657 L: lm-sensors@lm-sensors.org 7658 L: lm-sensors@lm-sensors.org
7658 S: Supported 7659 S: Supported
7659 F: Documentation/devicetree/bindings/hwmon/pwm-fan.txt 7660 F: Documentation/devicetree/bindings/hwmon/pwm-fan.txt
7660 F: Documentation/hwmon/pwm-fan 7661 F: Documentation/hwmon/pwm-fan
7661 F: drivers/hwmon/pwm-fan.c 7662 F: drivers/hwmon/pwm-fan.c
7662 7663
7663 PWM SUBSYSTEM 7664 PWM SUBSYSTEM
7664 M: Thierry Reding <thierry.reding@gmail.com> 7665 M: Thierry Reding <thierry.reding@gmail.com>
7665 L: linux-pwm@vger.kernel.org 7666 L: linux-pwm@vger.kernel.org
7666 S: Maintained 7667 S: Maintained
7667 T: git git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm.git 7668 T: git git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm.git
7668 F: Documentation/pwm.txt 7669 F: Documentation/pwm.txt
7669 F: Documentation/devicetree/bindings/pwm/ 7670 F: Documentation/devicetree/bindings/pwm/
7670 F: include/linux/pwm.h 7671 F: include/linux/pwm.h
7671 F: drivers/pwm/ 7672 F: drivers/pwm/
7672 F: drivers/video/backlight/pwm_bl.c 7673 F: drivers/video/backlight/pwm_bl.c
7673 F: include/linux/pwm_backlight.h 7674 F: include/linux/pwm_backlight.h
7674 7675
7675 PXA2xx/PXA3xx SUPPORT 7676 PXA2xx/PXA3xx SUPPORT
7676 M: Daniel Mack <daniel@zonque.org> 7677 M: Daniel Mack <daniel@zonque.org>
7677 M: Haojian Zhuang <haojian.zhuang@gmail.com> 7678 M: Haojian Zhuang <haojian.zhuang@gmail.com>
7678 M: Robert Jarzmik <robert.jarzmik@free.fr> 7679 M: Robert Jarzmik <robert.jarzmik@free.fr>
7679 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 7680 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
7680 T: git git://github.com/hzhuang1/linux.git 7681 T: git git://github.com/hzhuang1/linux.git
7681 T: git git://github.com/rjarzmik/linux.git 7682 T: git git://github.com/rjarzmik/linux.git
7682 S: Maintained 7683 S: Maintained
7683 F: arch/arm/mach-pxa/ 7684 F: arch/arm/mach-pxa/
7684 F: drivers/pcmcia/pxa2xx* 7685 F: drivers/pcmcia/pxa2xx*
7685 F: drivers/spi/spi-pxa2xx* 7686 F: drivers/spi/spi-pxa2xx*
7686 F: drivers/usb/gadget/udc/pxa2* 7687 F: drivers/usb/gadget/udc/pxa2*
7687 F: include/sound/pxa2xx-lib.h 7688 F: include/sound/pxa2xx-lib.h
7688 F: sound/arm/pxa* 7689 F: sound/arm/pxa*
7689 F: sound/soc/pxa/ 7690 F: sound/soc/pxa/
7690 7691
7691 PXA3xx NAND FLASH DRIVER 7692 PXA3xx NAND FLASH DRIVER
7692 M: Ezequiel Garcia <ezequiel.garcia@free-electrons.com> 7693 M: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
7693 L: linux-mtd@lists.infradead.org 7694 L: linux-mtd@lists.infradead.org
7694 S: Maintained 7695 S: Maintained
7695 F: drivers/mtd/nand/pxa3xx_nand.c 7696 F: drivers/mtd/nand/pxa3xx_nand.c
7696 7697
7697 MMP SUPPORT 7698 MMP SUPPORT
7698 M: Eric Miao <eric.y.miao@gmail.com> 7699 M: Eric Miao <eric.y.miao@gmail.com>
7699 M: Haojian Zhuang <haojian.zhuang@gmail.com> 7700 M: Haojian Zhuang <haojian.zhuang@gmail.com>
7700 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 7701 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
7701 T: git git://github.com/hzhuang1/linux.git 7702 T: git git://github.com/hzhuang1/linux.git
7702 T: git git://git.linaro.org/people/ycmiao/pxa-linux.git 7703 T: git git://git.linaro.org/people/ycmiao/pxa-linux.git
7703 S: Maintained 7704 S: Maintained
7704 F: arch/arm/mach-mmp/ 7705 F: arch/arm/mach-mmp/
7705 7706
7706 PXA MMCI DRIVER 7707 PXA MMCI DRIVER
7707 S: Orphan 7708 S: Orphan
7708 7709
7709 PXA RTC DRIVER 7710 PXA RTC DRIVER
7710 M: Robert Jarzmik <robert.jarzmik@free.fr> 7711 M: Robert Jarzmik <robert.jarzmik@free.fr>
7711 L: rtc-linux@googlegroups.com 7712 L: rtc-linux@googlegroups.com
7712 S: Maintained 7713 S: Maintained
7713 7714
7714 QAT DRIVER 7715 QAT DRIVER
7715 M: Tadeusz Struk <tadeusz.struk@intel.com> 7716 M: Tadeusz Struk <tadeusz.struk@intel.com>
7716 L: qat-linux@intel.com 7717 L: qat-linux@intel.com
7717 S: Supported 7718 S: Supported
7718 F: drivers/crypto/qat/ 7719 F: drivers/crypto/qat/
7719 7720
7720 QIB DRIVER 7721 QIB DRIVER
7721 M: Mike Marciniszyn <infinipath@intel.com> 7722 M: Mike Marciniszyn <infinipath@intel.com>
7722 L: linux-rdma@vger.kernel.org 7723 L: linux-rdma@vger.kernel.org
7723 S: Supported 7724 S: Supported
7724 F: drivers/infiniband/hw/qib/ 7725 F: drivers/infiniband/hw/qib/
7725 7726
7726 QLOGIC QLA1280 SCSI DRIVER 7727 QLOGIC QLA1280 SCSI DRIVER
7727 M: Michael Reed <mdr@sgi.com> 7728 M: Michael Reed <mdr@sgi.com>
7728 L: linux-scsi@vger.kernel.org 7729 L: linux-scsi@vger.kernel.org
7729 S: Maintained 7730 S: Maintained
7730 F: drivers/scsi/qla1280.[ch] 7731 F: drivers/scsi/qla1280.[ch]
7731 7732
7732 QLOGIC QLA2XXX FC-SCSI DRIVER 7733 QLOGIC QLA2XXX FC-SCSI DRIVER
7733 M: qla2xxx-upstream@qlogic.com 7734 M: qla2xxx-upstream@qlogic.com
7734 L: linux-scsi@vger.kernel.org 7735 L: linux-scsi@vger.kernel.org
7735 S: Supported 7736 S: Supported
7736 F: Documentation/scsi/LICENSE.qla2xxx 7737 F: Documentation/scsi/LICENSE.qla2xxx
7737 F: drivers/scsi/qla2xxx/ 7738 F: drivers/scsi/qla2xxx/
7738 7739
7739 QLOGIC QLA4XXX iSCSI DRIVER 7740 QLOGIC QLA4XXX iSCSI DRIVER
7740 M: Vikas Chaudhary <vikas.chaudhary@qlogic.com> 7741 M: Vikas Chaudhary <vikas.chaudhary@qlogic.com>
7741 M: iscsi-driver@qlogic.com 7742 M: iscsi-driver@qlogic.com
7742 L: linux-scsi@vger.kernel.org 7743 L: linux-scsi@vger.kernel.org
7743 S: Supported 7744 S: Supported
7744 F: Documentation/scsi/LICENSE.qla4xxx 7745 F: Documentation/scsi/LICENSE.qla4xxx
7745 F: drivers/scsi/qla4xxx/ 7746 F: drivers/scsi/qla4xxx/
7746 7747
7747 QLOGIC QLA3XXX NETWORK DRIVER 7748 QLOGIC QLA3XXX NETWORK DRIVER
7748 M: Jitendra Kalsaria <jitendra.kalsaria@qlogic.com> 7749 M: Jitendra Kalsaria <jitendra.kalsaria@qlogic.com>
7749 M: Ron Mercer <ron.mercer@qlogic.com> 7750 M: Ron Mercer <ron.mercer@qlogic.com>
7750 M: linux-driver@qlogic.com 7751 M: linux-driver@qlogic.com
7751 L: netdev@vger.kernel.org 7752 L: netdev@vger.kernel.org
7752 S: Supported 7753 S: Supported
7753 F: Documentation/networking/LICENSE.qla3xxx 7754 F: Documentation/networking/LICENSE.qla3xxx
7754 F: drivers/net/ethernet/qlogic/qla3xxx.* 7755 F: drivers/net/ethernet/qlogic/qla3xxx.*
7755 7756
7756 QLOGIC QLCNIC (1/10)Gb ETHERNET DRIVER 7757 QLOGIC QLCNIC (1/10)Gb ETHERNET DRIVER
7757 M: Shahed Shaikh <shahed.shaikh@qlogic.com> 7758 M: Shahed Shaikh <shahed.shaikh@qlogic.com>
7758 M: Dept-GELinuxNICDev@qlogic.com 7759 M: Dept-GELinuxNICDev@qlogic.com
7759 L: netdev@vger.kernel.org 7760 L: netdev@vger.kernel.org
7760 S: Supported 7761 S: Supported
7761 F: drivers/net/ethernet/qlogic/qlcnic/ 7762 F: drivers/net/ethernet/qlogic/qlcnic/
7762 7763
7763 QLOGIC QLGE 10Gb ETHERNET DRIVER 7764 QLOGIC QLGE 10Gb ETHERNET DRIVER
7764 M: Harish Patil <harish.patil@qlogic.com> 7765 M: Harish Patil <harish.patil@qlogic.com>
7765 M: Sudarsana Kalluru <sudarsana.kalluru@qlogic.com> 7766 M: Sudarsana Kalluru <sudarsana.kalluru@qlogic.com>
7766 M: Dept-GELinuxNICDev@qlogic.com 7767 M: Dept-GELinuxNICDev@qlogic.com
7767 M: linux-driver@qlogic.com 7768 M: linux-driver@qlogic.com
7768 L: netdev@vger.kernel.org 7769 L: netdev@vger.kernel.org
7769 S: Supported 7770 S: Supported
7770 F: drivers/net/ethernet/qlogic/qlge/ 7771 F: drivers/net/ethernet/qlogic/qlge/
7771 7772
7772 QNX4 FILESYSTEM 7773 QNX4 FILESYSTEM
7773 M: Anders Larsen <al@alarsen.net> 7774 M: Anders Larsen <al@alarsen.net>
7774 W: http://www.alarsen.net/linux/qnx4fs/ 7775 W: http://www.alarsen.net/linux/qnx4fs/
7775 S: Maintained 7776 S: Maintained
7776 F: fs/qnx4/ 7777 F: fs/qnx4/
7777 F: include/uapi/linux/qnx4_fs.h 7778 F: include/uapi/linux/qnx4_fs.h
7778 F: include/uapi/linux/qnxtypes.h 7779 F: include/uapi/linux/qnxtypes.h
7779 7780
7780 QT1010 MEDIA DRIVER 7781 QT1010 MEDIA DRIVER
7781 M: Antti Palosaari <crope@iki.fi> 7782 M: Antti Palosaari <crope@iki.fi>
7782 L: linux-media@vger.kernel.org 7783 L: linux-media@vger.kernel.org
7783 W: http://linuxtv.org/ 7784 W: http://linuxtv.org/
7784 W: http://palosaari.fi/linux/ 7785 W: http://palosaari.fi/linux/
7785 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 7786 Q: http://patchwork.linuxtv.org/project/linux-media/list/
7786 T: git git://linuxtv.org/anttip/media_tree.git 7787 T: git git://linuxtv.org/anttip/media_tree.git
7787 S: Maintained 7788 S: Maintained
7788 F: drivers/media/tuners/qt1010* 7789 F: drivers/media/tuners/qt1010*
7789 7790
7790 QUALCOMM ATHEROS ATH9K WIRELESS DRIVER 7791 QUALCOMM ATHEROS ATH9K WIRELESS DRIVER
7791 M: QCA ath9k Development <ath9k-devel@qca.qualcomm.com> 7792 M: QCA ath9k Development <ath9k-devel@qca.qualcomm.com>
7792 L: linux-wireless@vger.kernel.org 7793 L: linux-wireless@vger.kernel.org
7793 L: ath9k-devel@lists.ath9k.org 7794 L: ath9k-devel@lists.ath9k.org
7794 W: http://wireless.kernel.org/en/users/Drivers/ath9k 7795 W: http://wireless.kernel.org/en/users/Drivers/ath9k
7795 S: Supported 7796 S: Supported
7796 F: drivers/net/wireless/ath/ath9k/ 7797 F: drivers/net/wireless/ath/ath9k/
7797 7798
7798 QUALCOMM ATHEROS ATH10K WIRELESS DRIVER 7799 QUALCOMM ATHEROS ATH10K WIRELESS DRIVER
7799 M: Kalle Valo <kvalo@qca.qualcomm.com> 7800 M: Kalle Valo <kvalo@qca.qualcomm.com>
7800 L: ath10k@lists.infradead.org 7801 L: ath10k@lists.infradead.org
7801 W: http://wireless.kernel.org/en/users/Drivers/ath10k 7802 W: http://wireless.kernel.org/en/users/Drivers/ath10k
7802 T: git git://github.com/kvalo/ath.git 7803 T: git git://github.com/kvalo/ath.git
7803 S: Supported 7804 S: Supported
7804 F: drivers/net/wireless/ath/ath10k/ 7805 F: drivers/net/wireless/ath/ath10k/
7805 7806
7806 QUALCOMM HEXAGON ARCHITECTURE 7807 QUALCOMM HEXAGON ARCHITECTURE
7807 M: Richard Kuo <rkuo@codeaurora.org> 7808 M: Richard Kuo <rkuo@codeaurora.org>
7808 L: linux-hexagon@vger.kernel.org 7809 L: linux-hexagon@vger.kernel.org
7809 S: Supported 7810 S: Supported
7810 F: arch/hexagon/ 7811 F: arch/hexagon/
7811 7812
7812 QUALCOMM WCN36XX WIRELESS DRIVER 7813 QUALCOMM WCN36XX WIRELESS DRIVER
7813 M: Eugene Krasnikov <k.eugene.e@gmail.com> 7814 M: Eugene Krasnikov <k.eugene.e@gmail.com>
7814 L: wcn36xx@lists.infradead.org 7815 L: wcn36xx@lists.infradead.org
7815 W: http://wireless.kernel.org/en/users/Drivers/wcn36xx 7816 W: http://wireless.kernel.org/en/users/Drivers/wcn36xx
7816 T: git git://github.com/KrasnikovEugene/wcn36xx.git 7817 T: git git://github.com/KrasnikovEugene/wcn36xx.git
7817 S: Supported 7818 S: Supported
7818 F: drivers/net/wireless/ath/wcn36xx/ 7819 F: drivers/net/wireless/ath/wcn36xx/
7819 7820
7820 QUICKCAM PARALLEL PORT WEBCAMS 7821 QUICKCAM PARALLEL PORT WEBCAMS
7821 M: Hans Verkuil <hverkuil@xs4all.nl> 7822 M: Hans Verkuil <hverkuil@xs4all.nl>
7822 L: linux-media@vger.kernel.org 7823 L: linux-media@vger.kernel.org
7823 T: git git://linuxtv.org/media_tree.git 7824 T: git git://linuxtv.org/media_tree.git
7824 W: http://linuxtv.org 7825 W: http://linuxtv.org
7825 S: Odd Fixes 7826 S: Odd Fixes
7826 F: drivers/media/parport/*-qcam* 7827 F: drivers/media/parport/*-qcam*
7827 7828
7828 RADOS BLOCK DEVICE (RBD) 7829 RADOS BLOCK DEVICE (RBD)
7829 M: Yehuda Sadeh <yehuda@inktank.com> 7830 M: Yehuda Sadeh <yehuda@inktank.com>
7830 M: Sage Weil <sage@inktank.com> 7831 M: Sage Weil <sage@inktank.com>
7831 M: Alex Elder <elder@kernel.org> 7832 M: Alex Elder <elder@kernel.org>
7832 M: ceph-devel@vger.kernel.org 7833 M: ceph-devel@vger.kernel.org
7833 W: http://ceph.com/ 7834 W: http://ceph.com/
7834 T: git git://git.kernel.org/pub/scm/linux/kernel/git/sage/ceph-client.git 7835 T: git git://git.kernel.org/pub/scm/linux/kernel/git/sage/ceph-client.git
7835 S: Supported 7836 S: Supported
7836 F: drivers/block/rbd.c 7837 F: drivers/block/rbd.c
7837 F: drivers/block/rbd_types.h 7838 F: drivers/block/rbd_types.h
7838 7839
7839 RADEON FRAMEBUFFER DISPLAY DRIVER 7840 RADEON FRAMEBUFFER DISPLAY DRIVER
7840 M: Benjamin Herrenschmidt <benh@kernel.crashing.org> 7841 M: Benjamin Herrenschmidt <benh@kernel.crashing.org>
7841 L: linux-fbdev@vger.kernel.org 7842 L: linux-fbdev@vger.kernel.org
7842 S: Maintained 7843 S: Maintained
7843 F: drivers/video/fbdev/aty/radeon* 7844 F: drivers/video/fbdev/aty/radeon*
7844 F: include/uapi/linux/radeonfb.h 7845 F: include/uapi/linux/radeonfb.h
7845 7846
7846 RADIOSHARK RADIO DRIVER 7847 RADIOSHARK RADIO DRIVER
7847 M: Hans de Goede <hdegoede@redhat.com> 7848 M: Hans de Goede <hdegoede@redhat.com>
7848 L: linux-media@vger.kernel.org 7849 L: linux-media@vger.kernel.org
7849 T: git git://linuxtv.org/media_tree.git 7850 T: git git://linuxtv.org/media_tree.git
7850 S: Maintained 7851 S: Maintained
7851 F: drivers/media/radio/radio-shark.c 7852 F: drivers/media/radio/radio-shark.c
7852 7853
7853 RADIOSHARK2 RADIO DRIVER 7854 RADIOSHARK2 RADIO DRIVER
7854 M: Hans de Goede <hdegoede@redhat.com> 7855 M: Hans de Goede <hdegoede@redhat.com>
7855 L: linux-media@vger.kernel.org 7856 L: linux-media@vger.kernel.org
7856 T: git git://linuxtv.org/media_tree.git 7857 T: git git://linuxtv.org/media_tree.git
7857 S: Maintained 7858 S: Maintained
7858 F: drivers/media/radio/radio-shark2.c 7859 F: drivers/media/radio/radio-shark2.c
7859 F: drivers/media/radio/radio-tea5777.c 7860 F: drivers/media/radio/radio-tea5777.c
7860 7861
7861 RAGE128 FRAMEBUFFER DISPLAY DRIVER 7862 RAGE128 FRAMEBUFFER DISPLAY DRIVER
7862 M: Paul Mackerras <paulus@samba.org> 7863 M: Paul Mackerras <paulus@samba.org>
7863 L: linux-fbdev@vger.kernel.org 7864 L: linux-fbdev@vger.kernel.org
7864 S: Maintained 7865 S: Maintained
7865 F: drivers/video/fbdev/aty/aty128fb.c 7866 F: drivers/video/fbdev/aty/aty128fb.c
7866 7867
7867 RALINK RT2X00 WIRELESS LAN DRIVER 7868 RALINK RT2X00 WIRELESS LAN DRIVER
7868 P: rt2x00 project 7869 P: rt2x00 project
7869 M: Stanislaw Gruszka <sgruszka@redhat.com> 7870 M: Stanislaw Gruszka <sgruszka@redhat.com>
7870 M: Helmut Schaa <helmut.schaa@googlemail.com> 7871 M: Helmut Schaa <helmut.schaa@googlemail.com>
7871 L: linux-wireless@vger.kernel.org 7872 L: linux-wireless@vger.kernel.org
7872 L: users@rt2x00.serialmonkey.com (moderated for non-subscribers) 7873 L: users@rt2x00.serialmonkey.com (moderated for non-subscribers)
7873 W: http://rt2x00.serialmonkey.com/ 7874 W: http://rt2x00.serialmonkey.com/
7874 S: Maintained 7875 S: Maintained
7875 F: drivers/net/wireless/rt2x00/ 7876 F: drivers/net/wireless/rt2x00/
7876 7877
7877 RAMDISK RAM BLOCK DEVICE DRIVER 7878 RAMDISK RAM BLOCK DEVICE DRIVER
7878 M: Nick Piggin <npiggin@kernel.dk> 7879 M: Nick Piggin <npiggin@kernel.dk>
7879 S: Maintained 7880 S: Maintained
7880 F: Documentation/blockdev/ramdisk.txt 7881 F: Documentation/blockdev/ramdisk.txt
7881 F: drivers/block/brd.c 7882 F: drivers/block/brd.c
7882 7883
7883 RANDOM NUMBER DRIVER 7884 RANDOM NUMBER DRIVER
7884 M: "Theodore Ts'o" <tytso@mit.edu> 7885 M: "Theodore Ts'o" <tytso@mit.edu>
7885 S: Maintained 7886 S: Maintained
7886 F: drivers/char/random.c 7887 F: drivers/char/random.c
7887 7888
7888 RAPIDIO SUBSYSTEM 7889 RAPIDIO SUBSYSTEM
7889 M: Matt Porter <mporter@kernel.crashing.org> 7890 M: Matt Porter <mporter@kernel.crashing.org>
7890 M: Alexandre Bounine <alexandre.bounine@idt.com> 7891 M: Alexandre Bounine <alexandre.bounine@idt.com>
7891 S: Maintained 7892 S: Maintained
7892 F: drivers/rapidio/ 7893 F: drivers/rapidio/
7893 7894
7894 RAYLINK/WEBGEAR 802.11 WIRELESS LAN DRIVER 7895 RAYLINK/WEBGEAR 802.11 WIRELESS LAN DRIVER
7895 L: linux-wireless@vger.kernel.org 7896 L: linux-wireless@vger.kernel.org
7896 S: Orphan 7897 S: Orphan
7897 F: drivers/net/wireless/ray* 7898 F: drivers/net/wireless/ray*
7898 7899
7899 RCUTORTURE MODULE 7900 RCUTORTURE MODULE
7900 M: Josh Triplett <josh@joshtriplett.org> 7901 M: Josh Triplett <josh@joshtriplett.org>
7901 M: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> 7902 M: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
7902 L: linux-kernel@vger.kernel.org 7903 L: linux-kernel@vger.kernel.org
7903 S: Supported 7904 S: Supported
7904 T: git git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git 7905 T: git git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git
7905 F: Documentation/RCU/torture.txt 7906 F: Documentation/RCU/torture.txt
7906 F: kernel/rcu/rcutorture.c 7907 F: kernel/rcu/rcutorture.c
7907 7908
7908 RCUTORTURE TEST FRAMEWORK 7909 RCUTORTURE TEST FRAMEWORK
7909 M: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> 7910 M: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
7910 M: Josh Triplett <josh@joshtriplett.org> 7911 M: Josh Triplett <josh@joshtriplett.org>
7911 R: Steven Rostedt <rostedt@goodmis.org> 7912 R: Steven Rostedt <rostedt@goodmis.org>
7912 R: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> 7913 R: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7913 R: Lai Jiangshan <laijs@cn.fujitsu.com> 7914 R: Lai Jiangshan <laijs@cn.fujitsu.com>
7914 L: linux-kernel@vger.kernel.org 7915 L: linux-kernel@vger.kernel.org
7915 S: Supported 7916 S: Supported
7916 T: git git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git 7917 T: git git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git
7917 F: tools/testing/selftests/rcutorture 7918 F: tools/testing/selftests/rcutorture
7918 7919
7919 RDC R-321X SoC 7920 RDC R-321X SoC
7920 M: Florian Fainelli <florian@openwrt.org> 7921 M: Florian Fainelli <florian@openwrt.org>
7921 S: Maintained 7922 S: Maintained
7922 7923
7923 RDC R6040 FAST ETHERNET DRIVER 7924 RDC R6040 FAST ETHERNET DRIVER
7924 M: Florian Fainelli <florian@openwrt.org> 7925 M: Florian Fainelli <florian@openwrt.org>
7925 L: netdev@vger.kernel.org 7926 L: netdev@vger.kernel.org
7926 S: Maintained 7927 S: Maintained
7927 F: drivers/net/ethernet/rdc/r6040.c 7928 F: drivers/net/ethernet/rdc/r6040.c
7928 7929
7929 RDS - RELIABLE DATAGRAM SOCKETS 7930 RDS - RELIABLE DATAGRAM SOCKETS
7930 M: Chien Yen <chien.yen@oracle.com> 7931 M: Chien Yen <chien.yen@oracle.com>
7931 L: rds-devel@oss.oracle.com (moderated for non-subscribers) 7932 L: rds-devel@oss.oracle.com (moderated for non-subscribers)
7932 S: Supported 7933 S: Supported
7933 F: net/rds/ 7934 F: net/rds/
7934 7935
7935 READ-COPY UPDATE (RCU) 7936 READ-COPY UPDATE (RCU)
7936 M: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> 7937 M: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
7937 M: Josh Triplett <josh@joshtriplett.org> 7938 M: Josh Triplett <josh@joshtriplett.org>
7938 R: Steven Rostedt <rostedt@goodmis.org> 7939 R: Steven Rostedt <rostedt@goodmis.org>
7939 R: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> 7940 R: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7940 R: Lai Jiangshan <laijs@cn.fujitsu.com> 7941 R: Lai Jiangshan <laijs@cn.fujitsu.com>
7941 L: linux-kernel@vger.kernel.org 7942 L: linux-kernel@vger.kernel.org
7942 W: http://www.rdrop.com/users/paulmck/RCU/ 7943 W: http://www.rdrop.com/users/paulmck/RCU/
7943 S: Supported 7944 S: Supported
7944 T: git git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git 7945 T: git git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git
7945 F: Documentation/RCU/ 7946 F: Documentation/RCU/
7946 X: Documentation/RCU/torture.txt 7947 X: Documentation/RCU/torture.txt
7947 F: include/linux/rcu* 7948 F: include/linux/rcu*
7948 X: include/linux/srcu.h 7949 X: include/linux/srcu.h
7949 F: kernel/rcu/ 7950 F: kernel/rcu/
7950 X: kernel/torture.c 7951 X: kernel/torture.c
7951 7952
7952 REAL TIME CLOCK (RTC) SUBSYSTEM 7953 REAL TIME CLOCK (RTC) SUBSYSTEM
7953 M: Alessandro Zummo <a.zummo@towertech.it> 7954 M: Alessandro Zummo <a.zummo@towertech.it>
7954 L: rtc-linux@googlegroups.com 7955 L: rtc-linux@googlegroups.com
7955 Q: http://patchwork.ozlabs.org/project/rtc-linux/list/ 7956 Q: http://patchwork.ozlabs.org/project/rtc-linux/list/
7956 S: Maintained 7957 S: Maintained
7957 F: Documentation/rtc.txt 7958 F: Documentation/rtc.txt
7958 F: drivers/rtc/ 7959 F: drivers/rtc/
7959 F: include/linux/rtc.h 7960 F: include/linux/rtc.h
7960 F: include/uapi/linux/rtc.h 7961 F: include/uapi/linux/rtc.h
7961 7962
7962 REALTEK AUDIO CODECS 7963 REALTEK AUDIO CODECS
7963 M: Bard Liao <bardliao@realtek.com> 7964 M: Bard Liao <bardliao@realtek.com>
7964 M: Oder Chiou <oder_chiou@realtek.com> 7965 M: Oder Chiou <oder_chiou@realtek.com>
7965 S: Maintained 7966 S: Maintained
7966 F: sound/soc/codecs/rt* 7967 F: sound/soc/codecs/rt*
7967 F: include/sound/rt*.h 7968 F: include/sound/rt*.h
7968 7969
7969 REISERFS FILE SYSTEM 7970 REISERFS FILE SYSTEM
7970 L: reiserfs-devel@vger.kernel.org 7971 L: reiserfs-devel@vger.kernel.org
7971 S: Supported 7972 S: Supported
7972 F: fs/reiserfs/ 7973 F: fs/reiserfs/
7973 7974
7974 REGISTER MAP ABSTRACTION 7975 REGISTER MAP ABSTRACTION
7975 M: Mark Brown <broonie@kernel.org> 7976 M: Mark Brown <broonie@kernel.org>
7976 L: linux-kernel@vger.kernel.org 7977 L: linux-kernel@vger.kernel.org
7977 T: git git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git 7978 T: git git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git
7978 S: Supported 7979 S: Supported
7979 F: drivers/base/regmap/ 7980 F: drivers/base/regmap/
7980 F: include/linux/regmap.h 7981 F: include/linux/regmap.h
7981 7982
7982 REMOTE PROCESSOR (REMOTEPROC) SUBSYSTEM 7983 REMOTE PROCESSOR (REMOTEPROC) SUBSYSTEM
7983 M: Ohad Ben-Cohen <ohad@wizery.com> 7984 M: Ohad Ben-Cohen <ohad@wizery.com>
7984 T: git git://git.kernel.org/pub/scm/linux/kernel/git/ohad/remoteproc.git 7985 T: git git://git.kernel.org/pub/scm/linux/kernel/git/ohad/remoteproc.git
7985 S: Maintained 7986 S: Maintained
7986 F: drivers/remoteproc/ 7987 F: drivers/remoteproc/
7987 F: Documentation/remoteproc.txt 7988 F: Documentation/remoteproc.txt
7988 F: include/linux/remoteproc.h 7989 F: include/linux/remoteproc.h
7989 7990
7990 REMOTE PROCESSOR MESSAGING (RPMSG) SUBSYSTEM 7991 REMOTE PROCESSOR MESSAGING (RPMSG) SUBSYSTEM
7991 M: Ohad Ben-Cohen <ohad@wizery.com> 7992 M: Ohad Ben-Cohen <ohad@wizery.com>
7992 T: git git://git.kernel.org/pub/scm/linux/kernel/git/ohad/rpmsg.git 7993 T: git git://git.kernel.org/pub/scm/linux/kernel/git/ohad/rpmsg.git
7993 S: Maintained 7994 S: Maintained
7994 F: drivers/rpmsg/ 7995 F: drivers/rpmsg/
7995 F: Documentation/rpmsg.txt 7996 F: Documentation/rpmsg.txt
7996 F: include/linux/rpmsg.h 7997 F: include/linux/rpmsg.h
7997 7998
7998 RESET CONTROLLER FRAMEWORK 7999 RESET CONTROLLER FRAMEWORK
7999 M: Philipp Zabel <p.zabel@pengutronix.de> 8000 M: Philipp Zabel <p.zabel@pengutronix.de>
8000 S: Maintained 8001 S: Maintained
8001 F: drivers/reset/ 8002 F: drivers/reset/
8002 F: Documentation/devicetree/bindings/reset/ 8003 F: Documentation/devicetree/bindings/reset/
8003 F: include/linux/reset.h 8004 F: include/linux/reset.h
8004 F: include/linux/reset-controller.h 8005 F: include/linux/reset-controller.h
8005 8006
8006 RFKILL 8007 RFKILL
8007 M: Johannes Berg <johannes@sipsolutions.net> 8008 M: Johannes Berg <johannes@sipsolutions.net>
8008 L: linux-wireless@vger.kernel.org 8009 L: linux-wireless@vger.kernel.org
8009 W: http://wireless.kernel.org/ 8010 W: http://wireless.kernel.org/
8010 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211.git 8011 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211.git
8011 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211-next.git 8012 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211-next.git
8012 S: Maintained 8013 S: Maintained
8013 F: Documentation/rfkill.txt 8014 F: Documentation/rfkill.txt
8014 F: net/rfkill/ 8015 F: net/rfkill/
8015 8016
8016 RICOH SMARTMEDIA/XD DRIVER 8017 RICOH SMARTMEDIA/XD DRIVER
8017 M: Maxim Levitsky <maximlevitsky@gmail.com> 8018 M: Maxim Levitsky <maximlevitsky@gmail.com>
8018 S: Maintained 8019 S: Maintained
8019 F: drivers/mtd/nand/r852.c 8020 F: drivers/mtd/nand/r852.c
8020 F: drivers/mtd/nand/r852.h 8021 F: drivers/mtd/nand/r852.h
8021 8022
8022 RICOH R5C592 MEMORYSTICK DRIVER 8023 RICOH R5C592 MEMORYSTICK DRIVER
8023 M: Maxim Levitsky <maximlevitsky@gmail.com> 8024 M: Maxim Levitsky <maximlevitsky@gmail.com>
8024 S: Maintained 8025 S: Maintained
8025 F: drivers/memstick/host/r592.* 8026 F: drivers/memstick/host/r592.*
8026 8027
8027 ROCCAT DRIVERS 8028 ROCCAT DRIVERS
8028 M: Stefan Achatz <erazor_de@users.sourceforge.net> 8029 M: Stefan Achatz <erazor_de@users.sourceforge.net>
8029 W: http://sourceforge.net/projects/roccat/ 8030 W: http://sourceforge.net/projects/roccat/
8030 S: Maintained 8031 S: Maintained
8031 F: drivers/hid/hid-roccat* 8032 F: drivers/hid/hid-roccat*
8032 F: include/linux/hid-roccat* 8033 F: include/linux/hid-roccat*
8033 F: Documentation/ABI/*/sysfs-driver-hid-roccat* 8034 F: Documentation/ABI/*/sysfs-driver-hid-roccat*
8034 8035
8035 ROCKER DRIVER 8036 ROCKER DRIVER
8036 M: Jiri Pirko <jiri@resnulli.us> 8037 M: Jiri Pirko <jiri@resnulli.us>
8037 M: Scott Feldman <sfeldma@gmail.com> 8038 M: Scott Feldman <sfeldma@gmail.com>
8038 L: netdev@vger.kernel.org 8039 L: netdev@vger.kernel.org
8039 S: Supported 8040 S: Supported
8040 F: drivers/net/ethernet/rocker/ 8041 F: drivers/net/ethernet/rocker/
8041 8042
8042 ROCKETPORT DRIVER 8043 ROCKETPORT DRIVER
8043 P: Comtrol Corp. 8044 P: Comtrol Corp.
8044 W: http://www.comtrol.com 8045 W: http://www.comtrol.com
8045 S: Maintained 8046 S: Maintained
8046 F: Documentation/serial/rocket.txt 8047 F: Documentation/serial/rocket.txt
8047 F: drivers/tty/rocket* 8048 F: drivers/tty/rocket*
8048 8049
8049 ROCKETPORT EXPRESS/INFINITY DRIVER 8050 ROCKETPORT EXPRESS/INFINITY DRIVER
8050 M: Kevin Cernekee <cernekee@gmail.com> 8051 M: Kevin Cernekee <cernekee@gmail.com>
8051 L: linux-serial@vger.kernel.org 8052 L: linux-serial@vger.kernel.org
8052 S: Odd Fixes 8053 S: Odd Fixes
8053 F: drivers/tty/serial/rp2.* 8054 F: drivers/tty/serial/rp2.*
8054 8055
8055 ROSE NETWORK LAYER 8056 ROSE NETWORK LAYER
8056 M: Ralf Baechle <ralf@linux-mips.org> 8057 M: Ralf Baechle <ralf@linux-mips.org>
8057 L: linux-hams@vger.kernel.org 8058 L: linux-hams@vger.kernel.org
8058 W: http://www.linux-ax25.org/ 8059 W: http://www.linux-ax25.org/
8059 S: Maintained 8060 S: Maintained
8060 F: include/net/rose.h 8061 F: include/net/rose.h
8061 F: include/uapi/linux/rose.h 8062 F: include/uapi/linux/rose.h
8062 F: net/rose/ 8063 F: net/rose/
8063 8064
8064 RTL2830 MEDIA DRIVER 8065 RTL2830 MEDIA DRIVER
8065 M: Antti Palosaari <crope@iki.fi> 8066 M: Antti Palosaari <crope@iki.fi>
8066 L: linux-media@vger.kernel.org 8067 L: linux-media@vger.kernel.org
8067 W: http://linuxtv.org/ 8068 W: http://linuxtv.org/
8068 W: http://palosaari.fi/linux/ 8069 W: http://palosaari.fi/linux/
8069 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 8070 Q: http://patchwork.linuxtv.org/project/linux-media/list/
8070 T: git git://linuxtv.org/anttip/media_tree.git 8071 T: git git://linuxtv.org/anttip/media_tree.git
8071 S: Maintained 8072 S: Maintained
8072 F: drivers/media/dvb-frontends/rtl2830* 8073 F: drivers/media/dvb-frontends/rtl2830*
8073 8074
8074 RTL2832 MEDIA DRIVER 8075 RTL2832 MEDIA DRIVER
8075 M: Antti Palosaari <crope@iki.fi> 8076 M: Antti Palosaari <crope@iki.fi>
8076 L: linux-media@vger.kernel.org 8077 L: linux-media@vger.kernel.org
8077 W: http://linuxtv.org/ 8078 W: http://linuxtv.org/
8078 W: http://palosaari.fi/linux/ 8079 W: http://palosaari.fi/linux/
8079 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 8080 Q: http://patchwork.linuxtv.org/project/linux-media/list/
8080 T: git git://linuxtv.org/anttip/media_tree.git 8081 T: git git://linuxtv.org/anttip/media_tree.git
8081 S: Maintained 8082 S: Maintained
8082 F: drivers/media/dvb-frontends/rtl2832* 8083 F: drivers/media/dvb-frontends/rtl2832*
8083 8084
8084 RTL2832_SDR MEDIA DRIVER 8085 RTL2832_SDR MEDIA DRIVER
8085 M: Antti Palosaari <crope@iki.fi> 8086 M: Antti Palosaari <crope@iki.fi>
8086 L: linux-media@vger.kernel.org 8087 L: linux-media@vger.kernel.org
8087 W: http://linuxtv.org/ 8088 W: http://linuxtv.org/
8088 W: http://palosaari.fi/linux/ 8089 W: http://palosaari.fi/linux/
8089 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 8090 Q: http://patchwork.linuxtv.org/project/linux-media/list/
8090 T: git git://linuxtv.org/anttip/media_tree.git 8091 T: git git://linuxtv.org/anttip/media_tree.git
8091 S: Maintained 8092 S: Maintained
8092 F: drivers/media/dvb-frontends/rtl2832_sdr* 8093 F: drivers/media/dvb-frontends/rtl2832_sdr*
8093 8094
8094 RTL8180 WIRELESS DRIVER 8095 RTL8180 WIRELESS DRIVER
8095 L: linux-wireless@vger.kernel.org 8096 L: linux-wireless@vger.kernel.org
8096 W: http://wireless.kernel.org/ 8097 W: http://wireless.kernel.org/
8097 T: git git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-testing.git 8098 T: git git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-testing.git
8098 S: Orphan 8099 S: Orphan
8099 F: drivers/net/wireless/rtl818x/rtl8180/ 8100 F: drivers/net/wireless/rtl818x/rtl8180/
8100 8101
8101 RTL8187 WIRELESS DRIVER 8102 RTL8187 WIRELESS DRIVER
8102 M: Herton Ronaldo Krzesinski <herton@canonical.com> 8103 M: Herton Ronaldo Krzesinski <herton@canonical.com>
8103 M: Hin-Tak Leung <htl10@users.sourceforge.net> 8104 M: Hin-Tak Leung <htl10@users.sourceforge.net>
8104 M: Larry Finger <Larry.Finger@lwfinger.net> 8105 M: Larry Finger <Larry.Finger@lwfinger.net>
8105 L: linux-wireless@vger.kernel.org 8106 L: linux-wireless@vger.kernel.org
8106 W: http://wireless.kernel.org/ 8107 W: http://wireless.kernel.org/
8107 T: git git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-testing.git 8108 T: git git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-testing.git
8108 S: Maintained 8109 S: Maintained
8109 F: drivers/net/wireless/rtl818x/rtl8187/ 8110 F: drivers/net/wireless/rtl818x/rtl8187/
8110 8111
8111 RTL8192CE WIRELESS DRIVER 8112 RTL8192CE WIRELESS DRIVER
8112 M: Larry Finger <Larry.Finger@lwfinger.net> 8113 M: Larry Finger <Larry.Finger@lwfinger.net>
8113 M: Chaoming Li <chaoming_li@realsil.com.cn> 8114 M: Chaoming Li <chaoming_li@realsil.com.cn>
8114 L: linux-wireless@vger.kernel.org 8115 L: linux-wireless@vger.kernel.org
8115 W: http://wireless.kernel.org/ 8116 W: http://wireless.kernel.org/
8116 T: git git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-testing.git 8117 T: git git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-testing.git
8117 S: Maintained 8118 S: Maintained
8118 F: drivers/net/wireless/rtlwifi/ 8119 F: drivers/net/wireless/rtlwifi/
8119 F: drivers/net/wireless/rtlwifi/rtl8192ce/ 8120 F: drivers/net/wireless/rtlwifi/rtl8192ce/
8120 8121
8121 S3 SAVAGE FRAMEBUFFER DRIVER 8122 S3 SAVAGE FRAMEBUFFER DRIVER
8122 M: Antonino Daplas <adaplas@gmail.com> 8123 M: Antonino Daplas <adaplas@gmail.com>
8123 L: linux-fbdev@vger.kernel.org 8124 L: linux-fbdev@vger.kernel.org
8124 S: Maintained 8125 S: Maintained
8125 F: drivers/video/fbdev/savage/ 8126 F: drivers/video/fbdev/savage/
8126 8127
8127 S390 8128 S390
8128 M: Martin Schwidefsky <schwidefsky@de.ibm.com> 8129 M: Martin Schwidefsky <schwidefsky@de.ibm.com>
8129 M: Heiko Carstens <heiko.carstens@de.ibm.com> 8130 M: Heiko Carstens <heiko.carstens@de.ibm.com>
8130 M: linux390@de.ibm.com 8131 M: linux390@de.ibm.com
8131 L: linux-s390@vger.kernel.org 8132 L: linux-s390@vger.kernel.org
8132 W: http://www.ibm.com/developerworks/linux/linux390/ 8133 W: http://www.ibm.com/developerworks/linux/linux390/
8133 S: Supported 8134 S: Supported
8134 F: arch/s390/ 8135 F: arch/s390/
8135 F: drivers/s390/ 8136 F: drivers/s390/
8136 F: Documentation/s390/ 8137 F: Documentation/s390/
8137 F: Documentation/DocBook/s390* 8138 F: Documentation/DocBook/s390*
8138 8139
8139 S390 COMMON I/O LAYER 8140 S390 COMMON I/O LAYER
8140 M: Sebastian Ott <sebott@linux.vnet.ibm.com> 8141 M: Sebastian Ott <sebott@linux.vnet.ibm.com>
8141 M: Peter Oberparleiter <oberpar@linux.vnet.ibm.com> 8142 M: Peter Oberparleiter <oberpar@linux.vnet.ibm.com>
8142 L: linux-s390@vger.kernel.org 8143 L: linux-s390@vger.kernel.org
8143 W: http://www.ibm.com/developerworks/linux/linux390/ 8144 W: http://www.ibm.com/developerworks/linux/linux390/
8144 S: Supported 8145 S: Supported
8145 F: drivers/s390/cio/ 8146 F: drivers/s390/cio/
8146 8147
8147 S390 DASD DRIVER 8148 S390 DASD DRIVER
8148 M: Stefan Weinhuber <wein@de.ibm.com> 8149 M: Stefan Weinhuber <wein@de.ibm.com>
8149 M: Stefan Haberland <stefan.haberland@de.ibm.com> 8150 M: Stefan Haberland <stefan.haberland@de.ibm.com>
8150 L: linux-s390@vger.kernel.org 8151 L: linux-s390@vger.kernel.org
8151 W: http://www.ibm.com/developerworks/linux/linux390/ 8152 W: http://www.ibm.com/developerworks/linux/linux390/
8152 S: Supported 8153 S: Supported
8153 F: drivers/s390/block/dasd* 8154 F: drivers/s390/block/dasd*
8154 F: block/partitions/ibm.c 8155 F: block/partitions/ibm.c
8155 8156
8156 S390 NETWORK DRIVERS 8157 S390 NETWORK DRIVERS
8157 M: Ursula Braun <ursula.braun@de.ibm.com> 8158 M: Ursula Braun <ursula.braun@de.ibm.com>
8158 M: Frank Blaschka <blaschka@linux.vnet.ibm.com> 8159 M: Frank Blaschka <blaschka@linux.vnet.ibm.com>
8159 M: linux390@de.ibm.com 8160 M: linux390@de.ibm.com
8160 L: linux-s390@vger.kernel.org 8161 L: linux-s390@vger.kernel.org
8161 W: http://www.ibm.com/developerworks/linux/linux390/ 8162 W: http://www.ibm.com/developerworks/linux/linux390/
8162 S: Supported 8163 S: Supported
8163 F: drivers/s390/net/ 8164 F: drivers/s390/net/
8164 8165
8165 S390 PCI SUBSYSTEM 8166 S390 PCI SUBSYSTEM
8166 M: Sebastian Ott <sebott@linux.vnet.ibm.com> 8167 M: Sebastian Ott <sebott@linux.vnet.ibm.com>
8167 M: Gerald Schaefer <gerald.schaefer@de.ibm.com> 8168 M: Gerald Schaefer <gerald.schaefer@de.ibm.com>
8168 L: linux-s390@vger.kernel.org 8169 L: linux-s390@vger.kernel.org
8169 W: http://www.ibm.com/developerworks/linux/linux390/ 8170 W: http://www.ibm.com/developerworks/linux/linux390/
8170 S: Supported 8171 S: Supported
8171 F: arch/s390/pci/ 8172 F: arch/s390/pci/
8172 F: drivers/pci/hotplug/s390_pci_hpc.c 8173 F: drivers/pci/hotplug/s390_pci_hpc.c
8173 8174
8174 S390 ZCRYPT DRIVER 8175 S390 ZCRYPT DRIVER
8175 M: Ingo Tuchscherer <ingo.tuchscherer@de.ibm.com> 8176 M: Ingo Tuchscherer <ingo.tuchscherer@de.ibm.com>
8176 M: linux390@de.ibm.com 8177 M: linux390@de.ibm.com
8177 L: linux-s390@vger.kernel.org 8178 L: linux-s390@vger.kernel.org
8178 W: http://www.ibm.com/developerworks/linux/linux390/ 8179 W: http://www.ibm.com/developerworks/linux/linux390/
8179 S: Supported 8180 S: Supported
8180 F: drivers/s390/crypto/ 8181 F: drivers/s390/crypto/
8181 8182
8182 S390 ZFCP DRIVER 8183 S390 ZFCP DRIVER
8183 M: Steffen Maier <maier@linux.vnet.ibm.com> 8184 M: Steffen Maier <maier@linux.vnet.ibm.com>
8184 M: linux390@de.ibm.com 8185 M: linux390@de.ibm.com
8185 L: linux-s390@vger.kernel.org 8186 L: linux-s390@vger.kernel.org
8186 W: http://www.ibm.com/developerworks/linux/linux390/ 8187 W: http://www.ibm.com/developerworks/linux/linux390/
8187 S: Supported 8188 S: Supported
8188 F: drivers/s390/scsi/zfcp_* 8189 F: drivers/s390/scsi/zfcp_*
8189 8190
8190 S390 IUCV NETWORK LAYER 8191 S390 IUCV NETWORK LAYER
8191 M: Ursula Braun <ursula.braun@de.ibm.com> 8192 M: Ursula Braun <ursula.braun@de.ibm.com>
8192 M: linux390@de.ibm.com 8193 M: linux390@de.ibm.com
8193 L: linux-s390@vger.kernel.org 8194 L: linux-s390@vger.kernel.org
8194 W: http://www.ibm.com/developerworks/linux/linux390/ 8195 W: http://www.ibm.com/developerworks/linux/linux390/
8195 S: Supported 8196 S: Supported
8196 F: drivers/s390/net/*iucv* 8197 F: drivers/s390/net/*iucv*
8197 F: include/net/iucv/ 8198 F: include/net/iucv/
8198 F: net/iucv/ 8199 F: net/iucv/
8199 8200
8200 S3C24XX SD/MMC Driver 8201 S3C24XX SD/MMC Driver
8201 M: Ben Dooks <ben-linux@fluff.org> 8202 M: Ben Dooks <ben-linux@fluff.org>
8202 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 8203 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
8203 S: Supported 8204 S: Supported
8204 F: drivers/mmc/host/s3cmci.* 8205 F: drivers/mmc/host/s3cmci.*
8205 8206
8206 SAA6588 RDS RECEIVER DRIVER 8207 SAA6588 RDS RECEIVER DRIVER
8207 M: Hans Verkuil <hverkuil@xs4all.nl> 8208 M: Hans Verkuil <hverkuil@xs4all.nl>
8208 L: linux-media@vger.kernel.org 8209 L: linux-media@vger.kernel.org
8209 T: git git://linuxtv.org/media_tree.git 8210 T: git git://linuxtv.org/media_tree.git
8210 W: http://linuxtv.org 8211 W: http://linuxtv.org
8211 S: Odd Fixes 8212 S: Odd Fixes
8212 F: drivers/media/i2c/saa6588* 8213 F: drivers/media/i2c/saa6588*
8213 8214
8214 SAA7134 VIDEO4LINUX DRIVER 8215 SAA7134 VIDEO4LINUX DRIVER
8215 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com> 8216 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
8216 L: linux-media@vger.kernel.org 8217 L: linux-media@vger.kernel.org
8217 W: http://linuxtv.org 8218 W: http://linuxtv.org
8218 T: git git://linuxtv.org/media_tree.git 8219 T: git git://linuxtv.org/media_tree.git
8219 S: Odd fixes 8220 S: Odd fixes
8220 F: Documentation/video4linux/*.saa7134 8221 F: Documentation/video4linux/*.saa7134
8221 F: drivers/media/pci/saa7134/ 8222 F: drivers/media/pci/saa7134/
8222 8223
8223 SAA7146 VIDEO4LINUX-2 DRIVER 8224 SAA7146 VIDEO4LINUX-2 DRIVER
8224 M: Hans Verkuil <hverkuil@xs4all.nl> 8225 M: Hans Verkuil <hverkuil@xs4all.nl>
8225 L: linux-media@vger.kernel.org 8226 L: linux-media@vger.kernel.org
8226 T: git git://linuxtv.org/media_tree.git 8227 T: git git://linuxtv.org/media_tree.git
8227 S: Maintained 8228 S: Maintained
8228 F: drivers/media/common/saa7146/ 8229 F: drivers/media/common/saa7146/
8229 F: drivers/media/pci/saa7146/ 8230 F: drivers/media/pci/saa7146/
8230 F: include/media/saa7146* 8231 F: include/media/saa7146*
8231 8232
8232 SAMSUNG LAPTOP DRIVER 8233 SAMSUNG LAPTOP DRIVER
8233 M: Corentin Chary <corentin.chary@gmail.com> 8234 M: Corentin Chary <corentin.chary@gmail.com>
8234 L: platform-driver-x86@vger.kernel.org 8235 L: platform-driver-x86@vger.kernel.org
8235 S: Maintained 8236 S: Maintained
8236 F: drivers/platform/x86/samsung-laptop.c 8237 F: drivers/platform/x86/samsung-laptop.c
8237 8238
8238 SAMSUNG AUDIO (ASoC) DRIVERS 8239 SAMSUNG AUDIO (ASoC) DRIVERS
8239 M: Sangbeom Kim <sbkim73@samsung.com> 8240 M: Sangbeom Kim <sbkim73@samsung.com>
8240 L: alsa-devel@alsa-project.org (moderated for non-subscribers) 8241 L: alsa-devel@alsa-project.org (moderated for non-subscribers)
8241 S: Supported 8242 S: Supported
8242 F: sound/soc/samsung/ 8243 F: sound/soc/samsung/
8243 8244
8244 SAMSUNG FRAMEBUFFER DRIVER 8245 SAMSUNG FRAMEBUFFER DRIVER
8245 M: Jingoo Han <jg1.han@samsung.com> 8246 M: Jingoo Han <jg1.han@samsung.com>
8246 L: linux-fbdev@vger.kernel.org 8247 L: linux-fbdev@vger.kernel.org
8247 S: Maintained 8248 S: Maintained
8248 F: drivers/video/fbdev/s3c-fb.c 8249 F: drivers/video/fbdev/s3c-fb.c
8249 8250
8250 SAMSUNG MULTIFUNCTION DEVICE DRIVERS 8251 SAMSUNG MULTIFUNCTION DEVICE DRIVERS
8251 M: Sangbeom Kim <sbkim73@samsung.com> 8252 M: Sangbeom Kim <sbkim73@samsung.com>
8252 L: linux-kernel@vger.kernel.org 8253 L: linux-kernel@vger.kernel.org
8253 S: Supported 8254 S: Supported
8254 F: drivers/mfd/sec*.c 8255 F: drivers/mfd/sec*.c
8255 F: drivers/regulator/s2m*.c 8256 F: drivers/regulator/s2m*.c
8256 F: drivers/regulator/s5m*.c 8257 F: drivers/regulator/s5m*.c
8257 F: include/linux/mfd/samsung/ 8258 F: include/linux/mfd/samsung/
8258 8259
8259 SAMSUNG S5P/EXYNOS4 SOC SERIES CAMERA SUBSYSTEM DRIVERS 8260 SAMSUNG S5P/EXYNOS4 SOC SERIES CAMERA SUBSYSTEM DRIVERS
8260 M: Kyungmin Park <kyungmin.park@samsung.com> 8261 M: Kyungmin Park <kyungmin.park@samsung.com>
8261 M: Sylwester Nawrocki <s.nawrocki@samsung.com> 8262 M: Sylwester Nawrocki <s.nawrocki@samsung.com>
8262 L: linux-media@vger.kernel.org 8263 L: linux-media@vger.kernel.org
8263 Q: https://patchwork.linuxtv.org/project/linux-media/list/ 8264 Q: https://patchwork.linuxtv.org/project/linux-media/list/
8264 S: Supported 8265 S: Supported
8265 F: drivers/media/platform/exynos4-is/ 8266 F: drivers/media/platform/exynos4-is/
8266 8267
8267 SAMSUNG S3C24XX/S3C64XX SOC SERIES CAMIF DRIVER 8268 SAMSUNG S3C24XX/S3C64XX SOC SERIES CAMIF DRIVER
8268 M: Sylwester Nawrocki <sylvester.nawrocki@gmail.com> 8269 M: Sylwester Nawrocki <sylvester.nawrocki@gmail.com>
8269 L: linux-media@vger.kernel.org 8270 L: linux-media@vger.kernel.org
8270 L: linux-samsung-soc@vger.kernel.org (moderated for non-subscribers) 8271 L: linux-samsung-soc@vger.kernel.org (moderated for non-subscribers)
8271 S: Maintained 8272 S: Maintained
8272 F: drivers/media/platform/s3c-camif/ 8273 F: drivers/media/platform/s3c-camif/
8273 F: include/media/s3c_camif.h 8274 F: include/media/s3c_camif.h
8274 8275
8275 SAMSUNG S5C73M3 CAMERA DRIVER 8276 SAMSUNG S5C73M3 CAMERA DRIVER
8276 M: Kyungmin Park <kyungmin.park@samsung.com> 8277 M: Kyungmin Park <kyungmin.park@samsung.com>
8277 M: Andrzej Hajda <a.hajda@samsung.com> 8278 M: Andrzej Hajda <a.hajda@samsung.com>
8278 L: linux-media@vger.kernel.org 8279 L: linux-media@vger.kernel.org
8279 S: Supported 8280 S: Supported
8280 F: drivers/media/i2c/s5c73m3/* 8281 F: drivers/media/i2c/s5c73m3/*
8281 8282
8282 SAMSUNG S5K5BAF CAMERA DRIVER 8283 SAMSUNG S5K5BAF CAMERA DRIVER
8283 M: Kyungmin Park <kyungmin.park@samsung.com> 8284 M: Kyungmin Park <kyungmin.park@samsung.com>
8284 M: Andrzej Hajda <a.hajda@samsung.com> 8285 M: Andrzej Hajda <a.hajda@samsung.com>
8285 L: linux-media@vger.kernel.org 8286 L: linux-media@vger.kernel.org
8286 S: Supported 8287 S: Supported
8287 F: drivers/media/i2c/s5k5baf.c 8288 F: drivers/media/i2c/s5k5baf.c
8288 8289
8289 SAMSUNG SOC CLOCK DRIVERS 8290 SAMSUNG SOC CLOCK DRIVERS
8290 M: Sylwester Nawrocki <s.nawrocki@samsung.com> 8291 M: Sylwester Nawrocki <s.nawrocki@samsung.com>
8291 M: Tomasz Figa <tomasz.figa@gmail.com> 8292 M: Tomasz Figa <tomasz.figa@gmail.com>
8292 S: Supported 8293 S: Supported
8293 L: linux-samsung-soc@vger.kernel.org (moderated for non-subscribers) 8294 L: linux-samsung-soc@vger.kernel.org (moderated for non-subscribers)
8294 F: drivers/clk/samsung/ 8295 F: drivers/clk/samsung/
8295 8296
8296 SAMSUNG SXGBE DRIVERS 8297 SAMSUNG SXGBE DRIVERS
8297 M: Byungho An <bh74.an@samsung.com> 8298 M: Byungho An <bh74.an@samsung.com>
8298 M: Girish K S <ks.giri@samsung.com> 8299 M: Girish K S <ks.giri@samsung.com>
8299 M: Vipul Pandya <vipul.pandya@samsung.com> 8300 M: Vipul Pandya <vipul.pandya@samsung.com>
8300 S: Supported 8301 S: Supported
8301 L: netdev@vger.kernel.org 8302 L: netdev@vger.kernel.org
8302 F: drivers/net/ethernet/samsung/sxgbe/ 8303 F: drivers/net/ethernet/samsung/sxgbe/
8303 8304
8304 SAMSUNG USB2 PHY DRIVER 8305 SAMSUNG USB2 PHY DRIVER
8305 M: Kamil Debski <k.debski@samsung.com> 8306 M: Kamil Debski <k.debski@samsung.com>
8306 L: linux-kernel@vger.kernel.org 8307 L: linux-kernel@vger.kernel.org
8307 S: Supported 8308 S: Supported
8308 F: Documentation/devicetree/bindings/phy/samsung-phy.txt 8309 F: Documentation/devicetree/bindings/phy/samsung-phy.txt
8309 F: Documentation/phy/samsung-usb2.txt 8310 F: Documentation/phy/samsung-usb2.txt
8310 F: drivers/phy/phy-exynos4210-usb2.c 8311 F: drivers/phy/phy-exynos4210-usb2.c
8311 F: drivers/phy/phy-exynos4x12-usb2.c 8312 F: drivers/phy/phy-exynos4x12-usb2.c
8312 F: drivers/phy/phy-exynos5250-usb2.c 8313 F: drivers/phy/phy-exynos5250-usb2.c
8313 F: drivers/phy/phy-s5pv210-usb2.c 8314 F: drivers/phy/phy-s5pv210-usb2.c
8314 F: drivers/phy/phy-samsung-usb2.c 8315 F: drivers/phy/phy-samsung-usb2.c
8315 F: drivers/phy/phy-samsung-usb2.h 8316 F: drivers/phy/phy-samsung-usb2.h
8316 8317
8317 SERIAL DRIVERS 8318 SERIAL DRIVERS
8318 M: Greg Kroah-Hartman <gregkh@linuxfoundation.org> 8319 M: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
8319 L: linux-serial@vger.kernel.org 8320 L: linux-serial@vger.kernel.org
8320 S: Maintained 8321 S: Maintained
8321 F: drivers/tty/serial/ 8322 F: drivers/tty/serial/
8322 8323
8323 SYNOPSYS DESIGNWARE DMAC DRIVER 8324 SYNOPSYS DESIGNWARE DMAC DRIVER
8324 M: Viresh Kumar <viresh.linux@gmail.com> 8325 M: Viresh Kumar <viresh.linux@gmail.com>
8325 M: Andy Shevchenko <andriy.shevchenko@linux.intel.com> 8326 M: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
8326 S: Maintained 8327 S: Maintained
8327 F: include/linux/platform_data/dma-dw.h 8328 F: include/linux/platform_data/dma-dw.h
8328 F: drivers/dma/dw/ 8329 F: drivers/dma/dw/
8329 8330
8330 SYNOPSYS DESIGNWARE MMC/SD/SDIO DRIVER 8331 SYNOPSYS DESIGNWARE MMC/SD/SDIO DRIVER
8331 M: Seungwon Jeon <tgih.jun@samsung.com> 8332 M: Seungwon Jeon <tgih.jun@samsung.com>
8332 M: Jaehoon Chung <jh80.chung@samsung.com> 8333 M: Jaehoon Chung <jh80.chung@samsung.com>
8333 L: linux-mmc@vger.kernel.org 8334 L: linux-mmc@vger.kernel.org
8334 S: Maintained 8335 S: Maintained
8335 F: include/linux/mmc/dw_mmc.h 8336 F: include/linux/mmc/dw_mmc.h
8336 F: drivers/mmc/host/dw_mmc* 8337 F: drivers/mmc/host/dw_mmc*
8337 8338
8338 THUNDERBOLT DRIVER 8339 THUNDERBOLT DRIVER
8339 M: Andreas Noever <andreas.noever@gmail.com> 8340 M: Andreas Noever <andreas.noever@gmail.com>
8340 S: Maintained 8341 S: Maintained
8341 F: drivers/thunderbolt/ 8342 F: drivers/thunderbolt/
8342 8343
8343 TIMEKEEPING, CLOCKSOURCE CORE, NTP 8344 TIMEKEEPING, CLOCKSOURCE CORE, NTP
8344 M: John Stultz <john.stultz@linaro.org> 8345 M: John Stultz <john.stultz@linaro.org>
8345 M: Thomas Gleixner <tglx@linutronix.de> 8346 M: Thomas Gleixner <tglx@linutronix.de>
8346 L: linux-kernel@vger.kernel.org 8347 L: linux-kernel@vger.kernel.org
8347 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git timers/core 8348 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git timers/core
8348 S: Supported 8349 S: Supported
8349 F: include/linux/clocksource.h 8350 F: include/linux/clocksource.h
8350 F: include/linux/time.h 8351 F: include/linux/time.h
8351 F: include/linux/timex.h 8352 F: include/linux/timex.h
8352 F: include/uapi/linux/time.h 8353 F: include/uapi/linux/time.h
8353 F: include/uapi/linux/timex.h 8354 F: include/uapi/linux/timex.h
8354 F: kernel/time/clocksource.c 8355 F: kernel/time/clocksource.c
8355 F: kernel/time/time*.c 8356 F: kernel/time/time*.c
8356 F: kernel/time/ntp.c 8357 F: kernel/time/ntp.c
8357 8358
8358 TLG2300 VIDEO4LINUX-2 DRIVER 8359 TLG2300 VIDEO4LINUX-2 DRIVER
8359 M: Huang Shijie <shijie8@gmail.com> 8360 M: Huang Shijie <shijie8@gmail.com>
8360 M: Hans Verkuil <hverkuil@xs4all.nl> 8361 M: Hans Verkuil <hverkuil@xs4all.nl>
8361 S: Odd Fixes 8362 S: Odd Fixes
8362 F: drivers/media/usb/tlg2300/ 8363 F: drivers/media/usb/tlg2300/
8363 8364
8364 SC1200 WDT DRIVER 8365 SC1200 WDT DRIVER
8365 M: Zwane Mwaikambo <zwanem@gmail.com> 8366 M: Zwane Mwaikambo <zwanem@gmail.com>
8366 S: Maintained 8367 S: Maintained
8367 F: drivers/watchdog/sc1200wdt.c 8368 F: drivers/watchdog/sc1200wdt.c
8368 8369
8369 SCHEDULER 8370 SCHEDULER
8370 M: Ingo Molnar <mingo@redhat.com> 8371 M: Ingo Molnar <mingo@redhat.com>
8371 M: Peter Zijlstra <peterz@infradead.org> 8372 M: Peter Zijlstra <peterz@infradead.org>
8372 L: linux-kernel@vger.kernel.org 8373 L: linux-kernel@vger.kernel.org
8373 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git sched/core 8374 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git sched/core
8374 S: Maintained 8375 S: Maintained
8375 F: kernel/sched/ 8376 F: kernel/sched/
8376 F: include/linux/sched.h 8377 F: include/linux/sched.h
8377 F: include/uapi/linux/sched.h 8378 F: include/uapi/linux/sched.h
8378 F: include/linux/wait.h 8379 F: include/linux/wait.h
8379 8380
8380 SCORE ARCHITECTURE 8381 SCORE ARCHITECTURE
8381 M: Chen Liqin <liqin.linux@gmail.com> 8382 M: Chen Liqin <liqin.linux@gmail.com>
8382 M: Lennox Wu <lennox.wu@gmail.com> 8383 M: Lennox Wu <lennox.wu@gmail.com>
8383 W: http://www.sunplus.com 8384 W: http://www.sunplus.com
8384 S: Supported 8385 S: Supported
8385 F: arch/score/ 8386 F: arch/score/
8386 8387
8387 SCSI CDROM DRIVER 8388 SCSI CDROM DRIVER
8388 M: Jens Axboe <axboe@kernel.dk> 8389 M: Jens Axboe <axboe@kernel.dk>
8389 L: linux-scsi@vger.kernel.org 8390 L: linux-scsi@vger.kernel.org
8390 W: http://www.kernel.dk 8391 W: http://www.kernel.dk
8391 S: Maintained 8392 S: Maintained
8392 F: drivers/scsi/sr* 8393 F: drivers/scsi/sr*
8393 8394
8394 SCSI RDMA PROTOCOL (SRP) INITIATOR 8395 SCSI RDMA PROTOCOL (SRP) INITIATOR
8395 M: Bart Van Assche <bvanassche@acm.org> 8396 M: Bart Van Assche <bvanassche@acm.org>
8396 L: linux-rdma@vger.kernel.org 8397 L: linux-rdma@vger.kernel.org
8397 S: Supported 8398 S: Supported
8398 W: http://www.openfabrics.org 8399 W: http://www.openfabrics.org
8399 Q: http://patchwork.kernel.org/project/linux-rdma/list/ 8400 Q: http://patchwork.kernel.org/project/linux-rdma/list/
8400 T: git git://git.kernel.org/pub/scm/linux/kernel/git/dad/srp-initiator.git 8401 T: git git://git.kernel.org/pub/scm/linux/kernel/git/dad/srp-initiator.git
8401 F: drivers/infiniband/ulp/srp/ 8402 F: drivers/infiniband/ulp/srp/
8402 F: include/scsi/srp.h 8403 F: include/scsi/srp.h
8403 8404
8404 SCSI SG DRIVER 8405 SCSI SG DRIVER
8405 M: Doug Gilbert <dgilbert@interlog.com> 8406 M: Doug Gilbert <dgilbert@interlog.com>
8406 L: linux-scsi@vger.kernel.org 8407 L: linux-scsi@vger.kernel.org
8407 W: http://sg.danny.cz/sg 8408 W: http://sg.danny.cz/sg
8408 S: Maintained 8409 S: Maintained
8409 F: Documentation/scsi/scsi-generic.txt 8410 F: Documentation/scsi/scsi-generic.txt
8410 F: drivers/scsi/sg.c 8411 F: drivers/scsi/sg.c
8411 F: include/scsi/sg.h 8412 F: include/scsi/sg.h
8412 8413
8413 SCSI SUBSYSTEM 8414 SCSI SUBSYSTEM
8414 M: "James E.J. Bottomley" <JBottomley@parallels.com> 8415 M: "James E.J. Bottomley" <JBottomley@parallels.com>
8415 L: linux-scsi@vger.kernel.org 8416 L: linux-scsi@vger.kernel.org
8416 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6.git 8417 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6.git
8417 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi-rc-fixes-2.6.git 8418 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi-rc-fixes-2.6.git
8418 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi-pending-2.6.git 8419 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi-pending-2.6.git
8419 S: Maintained 8420 S: Maintained
8420 F: drivers/scsi/ 8421 F: drivers/scsi/
8421 F: include/scsi/ 8422 F: include/scsi/
8422 8423
8423 SCSI TAPE DRIVER 8424 SCSI TAPE DRIVER
8424 M: Kai Mรคkisara <Kai.Makisara@kolumbus.fi> 8425 M: Kai Mรคkisara <Kai.Makisara@kolumbus.fi>
8425 L: linux-scsi@vger.kernel.org 8426 L: linux-scsi@vger.kernel.org
8426 S: Maintained 8427 S: Maintained
8427 F: Documentation/scsi/st.txt 8428 F: Documentation/scsi/st.txt
8428 F: drivers/scsi/st.* 8429 F: drivers/scsi/st.*
8429 F: drivers/scsi/st_*.h 8430 F: drivers/scsi/st_*.h
8430 8431
8431 SCTP PROTOCOL 8432 SCTP PROTOCOL
8432 M: Vlad Yasevich <vyasevich@gmail.com> 8433 M: Vlad Yasevich <vyasevich@gmail.com>
8433 M: Neil Horman <nhorman@tuxdriver.com> 8434 M: Neil Horman <nhorman@tuxdriver.com>
8434 L: linux-sctp@vger.kernel.org 8435 L: linux-sctp@vger.kernel.org
8435 W: http://lksctp.sourceforge.net 8436 W: http://lksctp.sourceforge.net
8436 S: Maintained 8437 S: Maintained
8437 F: Documentation/networking/sctp.txt 8438 F: Documentation/networking/sctp.txt
8438 F: include/linux/sctp.h 8439 F: include/linux/sctp.h
8439 F: include/uapi/linux/sctp.h 8440 F: include/uapi/linux/sctp.h
8440 F: include/net/sctp/ 8441 F: include/net/sctp/
8441 F: net/sctp/ 8442 F: net/sctp/
8442 8443
8443 SCx200 CPU SUPPORT 8444 SCx200 CPU SUPPORT
8444 M: Jim Cromie <jim.cromie@gmail.com> 8445 M: Jim Cromie <jim.cromie@gmail.com>
8445 S: Odd Fixes 8446 S: Odd Fixes
8446 F: Documentation/i2c/busses/scx200_acb 8447 F: Documentation/i2c/busses/scx200_acb
8447 F: arch/x86/platform/scx200/ 8448 F: arch/x86/platform/scx200/
8448 F: drivers/watchdog/scx200_wdt.c 8449 F: drivers/watchdog/scx200_wdt.c
8449 F: drivers/i2c/busses/scx200* 8450 F: drivers/i2c/busses/scx200*
8450 F: drivers/mtd/maps/scx200_docflash.c 8451 F: drivers/mtd/maps/scx200_docflash.c
8451 F: include/linux/scx200.h 8452 F: include/linux/scx200.h
8452 8453
8453 SCx200 GPIO DRIVER 8454 SCx200 GPIO DRIVER
8454 M: Jim Cromie <jim.cromie@gmail.com> 8455 M: Jim Cromie <jim.cromie@gmail.com>
8455 S: Maintained 8456 S: Maintained
8456 F: drivers/char/scx200_gpio.c 8457 F: drivers/char/scx200_gpio.c
8457 F: include/linux/scx200_gpio.h 8458 F: include/linux/scx200_gpio.h
8458 8459
8459 SCx200 HRT CLOCKSOURCE DRIVER 8460 SCx200 HRT CLOCKSOURCE DRIVER
8460 M: Jim Cromie <jim.cromie@gmail.com> 8461 M: Jim Cromie <jim.cromie@gmail.com>
8461 S: Maintained 8462 S: Maintained
8462 F: drivers/clocksource/scx200_hrt.c 8463 F: drivers/clocksource/scx200_hrt.c
8463 8464
8464 SDRICOH_CS MMC/SD HOST CONTROLLER INTERFACE DRIVER 8465 SDRICOH_CS MMC/SD HOST CONTROLLER INTERFACE DRIVER
8465 M: Sascha Sommer <saschasommer@freenet.de> 8466 M: Sascha Sommer <saschasommer@freenet.de>
8466 L: sdricohcs-devel@lists.sourceforge.net (subscribers-only) 8467 L: sdricohcs-devel@lists.sourceforge.net (subscribers-only)
8467 S: Maintained 8468 S: Maintained
8468 F: drivers/mmc/host/sdricoh_cs.c 8469 F: drivers/mmc/host/sdricoh_cs.c
8469 8470
8470 SECURE DIGITAL HOST CONTROLLER INTERFACE (SDHCI) DRIVER 8471 SECURE DIGITAL HOST CONTROLLER INTERFACE (SDHCI) DRIVER
8471 M: Chris Ball <chris@printf.net> 8472 M: Chris Ball <chris@printf.net>
8472 L: linux-mmc@vger.kernel.org 8473 L: linux-mmc@vger.kernel.org
8473 T: git git://git.kernel.org/pub/scm/linux/kernel/git/cjb/mmc.git 8474 T: git git://git.kernel.org/pub/scm/linux/kernel/git/cjb/mmc.git
8474 S: Maintained 8475 S: Maintained
8475 F: drivers/mmc/host/sdhci.* 8476 F: drivers/mmc/host/sdhci.*
8476 F: drivers/mmc/host/sdhci-pltfm.[ch] 8477 F: drivers/mmc/host/sdhci-pltfm.[ch]
8477 8478
8478 SECURE COMPUTING 8479 SECURE COMPUTING
8479 M: Kees Cook <keescook@chromium.org> 8480 M: Kees Cook <keescook@chromium.org>
8480 R: Andy Lutomirski <luto@amacapital.net> 8481 R: Andy Lutomirski <luto@amacapital.net>
8481 R: Will Drewry <wad@chromium.org> 8482 R: Will Drewry <wad@chromium.org>
8482 T: git git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git seccomp 8483 T: git git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git seccomp
8483 S: Supported 8484 S: Supported
8484 F: kernel/seccomp.c 8485 F: kernel/seccomp.c
8485 F: include/uapi/linux/seccomp.h 8486 F: include/uapi/linux/seccomp.h
8486 F: include/linux/seccomp.h 8487 F: include/linux/seccomp.h
8487 K: \bsecure_computing 8488 K: \bsecure_computing
8488 K: \bTIF_SECCOMP\b 8489 K: \bTIF_SECCOMP\b
8489 8490
8490 SECURE DIGITAL HOST CONTROLLER INTERFACE, OPEN FIRMWARE BINDINGS (SDHCI-OF) 8491 SECURE DIGITAL HOST CONTROLLER INTERFACE, OPEN FIRMWARE BINDINGS (SDHCI-OF)
8491 M: Anton Vorontsov <anton@enomsg.org> 8492 M: Anton Vorontsov <anton@enomsg.org>
8492 L: linuxppc-dev@lists.ozlabs.org 8493 L: linuxppc-dev@lists.ozlabs.org
8493 L: linux-mmc@vger.kernel.org 8494 L: linux-mmc@vger.kernel.org
8494 S: Maintained 8495 S: Maintained
8495 F: drivers/mmc/host/sdhci-pltfm.[ch] 8496 F: drivers/mmc/host/sdhci-pltfm.[ch]
8496 8497
8497 SECURE DIGITAL HOST CONTROLLER INTERFACE (SDHCI) SAMSUNG DRIVER 8498 SECURE DIGITAL HOST CONTROLLER INTERFACE (SDHCI) SAMSUNG DRIVER
8498 M: Ben Dooks <ben-linux@fluff.org> 8499 M: Ben Dooks <ben-linux@fluff.org>
8499 L: linux-mmc@vger.kernel.org 8500 L: linux-mmc@vger.kernel.org
8500 S: Maintained 8501 S: Maintained
8501 F: drivers/mmc/host/sdhci-s3c.c 8502 F: drivers/mmc/host/sdhci-s3c.c
8502 8503
8503 SECURE DIGITAL HOST CONTROLLER INTERFACE (SDHCI) ST SPEAR DRIVER 8504 SECURE DIGITAL HOST CONTROLLER INTERFACE (SDHCI) ST SPEAR DRIVER
8504 M: Viresh Kumar <viresh.linux@gmail.com> 8505 M: Viresh Kumar <viresh.linux@gmail.com>
8505 L: spear-devel@list.st.com 8506 L: spear-devel@list.st.com
8506 L: linux-mmc@vger.kernel.org 8507 L: linux-mmc@vger.kernel.org
8507 S: Maintained 8508 S: Maintained
8508 F: drivers/mmc/host/sdhci-spear.c 8509 F: drivers/mmc/host/sdhci-spear.c
8509 8510
8510 SECURITY SUBSYSTEM 8511 SECURITY SUBSYSTEM
8511 M: James Morris <james.l.morris@oracle.com> 8512 M: James Morris <james.l.morris@oracle.com>
8512 M: Serge E. Hallyn <serge@hallyn.com> 8513 M: Serge E. Hallyn <serge@hallyn.com>
8513 L: linux-security-module@vger.kernel.org (suggested Cc:) 8514 L: linux-security-module@vger.kernel.org (suggested Cc:)
8514 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security.git 8515 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security.git
8515 W: http://kernsec.org/ 8516 W: http://kernsec.org/
8516 S: Supported 8517 S: Supported
8517 F: security/ 8518 F: security/
8518 8519
8519 SECURITY CONTACT 8520 SECURITY CONTACT
8520 M: Security Officers <security@kernel.org> 8521 M: Security Officers <security@kernel.org>
8521 S: Supported 8522 S: Supported
8522 8523
8523 SELINUX SECURITY MODULE 8524 SELINUX SECURITY MODULE
8524 M: Paul Moore <paul@paul-moore.com> 8525 M: Paul Moore <paul@paul-moore.com>
8525 M: Stephen Smalley <sds@tycho.nsa.gov> 8526 M: Stephen Smalley <sds@tycho.nsa.gov>
8526 M: Eric Paris <eparis@parisplace.org> 8527 M: Eric Paris <eparis@parisplace.org>
8527 L: selinux@tycho.nsa.gov (moderated for non-subscribers) 8528 L: selinux@tycho.nsa.gov (moderated for non-subscribers)
8528 W: http://selinuxproject.org 8529 W: http://selinuxproject.org
8529 T: git git://git.infradead.org/users/pcmoore/selinux 8530 T: git git://git.infradead.org/users/pcmoore/selinux
8530 S: Supported 8531 S: Supported
8531 F: include/linux/selinux* 8532 F: include/linux/selinux*
8532 F: security/selinux/ 8533 F: security/selinux/
8533 F: scripts/selinux/ 8534 F: scripts/selinux/
8534 8535
8535 APPARMOR SECURITY MODULE 8536 APPARMOR SECURITY MODULE
8536 M: John Johansen <john.johansen@canonical.com> 8537 M: John Johansen <john.johansen@canonical.com>
8537 L: apparmor@lists.ubuntu.com (subscribers-only, general discussion) 8538 L: apparmor@lists.ubuntu.com (subscribers-only, general discussion)
8538 W: apparmor.wiki.kernel.org 8539 W: apparmor.wiki.kernel.org
8539 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jj/apparmor-dev.git 8540 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jj/apparmor-dev.git
8540 S: Supported 8541 S: Supported
8541 F: security/apparmor/ 8542 F: security/apparmor/
8542 8543
8543 SENSABLE PHANTOM 8544 SENSABLE PHANTOM
8544 M: Jiri Slaby <jirislaby@gmail.com> 8545 M: Jiri Slaby <jirislaby@gmail.com>
8545 S: Maintained 8546 S: Maintained
8546 F: drivers/misc/phantom.c 8547 F: drivers/misc/phantom.c
8547 F: include/uapi/linux/phantom.h 8548 F: include/uapi/linux/phantom.h
8548 8549
8549 SERIAL ATA (SATA) SUBSYSTEM 8550 SERIAL ATA (SATA) SUBSYSTEM
8550 M: Tejun Heo <tj@kernel.org> 8551 M: Tejun Heo <tj@kernel.org>
8551 L: linux-ide@vger.kernel.org 8552 L: linux-ide@vger.kernel.org
8552 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tj/libata.git 8553 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tj/libata.git
8553 S: Supported 8554 S: Supported
8554 F: drivers/ata/ 8555 F: drivers/ata/
8555 F: include/linux/ata.h 8556 F: include/linux/ata.h
8556 F: include/linux/libata.h 8557 F: include/linux/libata.h
8557 8558
8558 SERIAL ATA AHCI PLATFORM devices support 8559 SERIAL ATA AHCI PLATFORM devices support
8559 M: Hans de Goede <hdegoede@redhat.com> 8560 M: Hans de Goede <hdegoede@redhat.com>
8560 M: Tejun Heo <tj@kernel.org> 8561 M: Tejun Heo <tj@kernel.org>
8561 L: linux-ide@vger.kernel.org 8562 L: linux-ide@vger.kernel.org
8562 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tj/libata.git 8563 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tj/libata.git
8563 S: Supported 8564 S: Supported
8564 F: drivers/ata/ahci_platform.c 8565 F: drivers/ata/ahci_platform.c
8565 F: drivers/ata/libahci_platform.c 8566 F: drivers/ata/libahci_platform.c
8566 F: include/linux/ahci_platform.h 8567 F: include/linux/ahci_platform.h
8567 8568
8568 SERVER ENGINES 10Gbps iSCSI - BladeEngine 2 DRIVER 8569 SERVER ENGINES 10Gbps iSCSI - BladeEngine 2 DRIVER
8569 M: Jayamohan Kallickal <jayamohan.kallickal@emulex.com> 8570 M: Jayamohan Kallickal <jayamohan.kallickal@emulex.com>
8570 L: linux-scsi@vger.kernel.org 8571 L: linux-scsi@vger.kernel.org
8571 W: http://www.emulex.com 8572 W: http://www.emulex.com
8572 S: Supported 8573 S: Supported
8573 F: drivers/scsi/be2iscsi/ 8574 F: drivers/scsi/be2iscsi/
8574 8575
8575 SERVER ENGINES 10Gbps NIC - BladeEngine 2 DRIVER 8576 SERVER ENGINES 10Gbps NIC - BladeEngine 2 DRIVER
8576 M: Sathya Perla <sathya.perla@emulex.com> 8577 M: Sathya Perla <sathya.perla@emulex.com>
8577 M: Subbu Seetharaman <subbu.seetharaman@emulex.com> 8578 M: Subbu Seetharaman <subbu.seetharaman@emulex.com>
8578 M: Ajit Khaparde <ajit.khaparde@emulex.com> 8579 M: Ajit Khaparde <ajit.khaparde@emulex.com>
8579 L: netdev@vger.kernel.org 8580 L: netdev@vger.kernel.org
8580 W: http://www.emulex.com 8581 W: http://www.emulex.com
8581 S: Supported 8582 S: Supported
8582 F: drivers/net/ethernet/emulex/benet/ 8583 F: drivers/net/ethernet/emulex/benet/
8583 8584
8584 SFC NETWORK DRIVER 8585 SFC NETWORK DRIVER
8585 M: Solarflare linux maintainers <linux-net-drivers@solarflare.com> 8586 M: Solarflare linux maintainers <linux-net-drivers@solarflare.com>
8586 M: Shradha Shah <sshah@solarflare.com> 8587 M: Shradha Shah <sshah@solarflare.com>
8587 L: netdev@vger.kernel.org 8588 L: netdev@vger.kernel.org
8588 S: Supported 8589 S: Supported
8589 F: drivers/net/ethernet/sfc/ 8590 F: drivers/net/ethernet/sfc/
8590 8591
8591 SGI GRU DRIVER 8592 SGI GRU DRIVER
8592 M: Dimitri Sivanich <sivanich@sgi.com> 8593 M: Dimitri Sivanich <sivanich@sgi.com>
8593 S: Maintained 8594 S: Maintained
8594 F: drivers/misc/sgi-gru/ 8595 F: drivers/misc/sgi-gru/
8595 8596
8596 SGI SN-IA64 (Altix) SERIAL CONSOLE DRIVER 8597 SGI SN-IA64 (Altix) SERIAL CONSOLE DRIVER
8597 M: Pat Gefre <pfg@sgi.com> 8598 M: Pat Gefre <pfg@sgi.com>
8598 L: linux-ia64@vger.kernel.org 8599 L: linux-ia64@vger.kernel.org
8599 S: Supported 8600 S: Supported
8600 F: Documentation/ia64/serial.txt 8601 F: Documentation/ia64/serial.txt
8601 F: drivers/tty/serial/ioc?_serial.c 8602 F: drivers/tty/serial/ioc?_serial.c
8602 F: include/linux/ioc?.h 8603 F: include/linux/ioc?.h
8603 8604
8604 SGI XP/XPC/XPNET DRIVER 8605 SGI XP/XPC/XPNET DRIVER
8605 M: Cliff Whickman <cpw@sgi.com> 8606 M: Cliff Whickman <cpw@sgi.com>
8606 M: Robin Holt <robinmholt@gmail.com> 8607 M: Robin Holt <robinmholt@gmail.com>
8607 S: Maintained 8608 S: Maintained
8608 F: drivers/misc/sgi-xp/ 8609 F: drivers/misc/sgi-xp/
8609 8610
8610 SI2157 MEDIA DRIVER 8611 SI2157 MEDIA DRIVER
8611 M: Antti Palosaari <crope@iki.fi> 8612 M: Antti Palosaari <crope@iki.fi>
8612 L: linux-media@vger.kernel.org 8613 L: linux-media@vger.kernel.org
8613 W: http://linuxtv.org/ 8614 W: http://linuxtv.org/
8614 W: http://palosaari.fi/linux/ 8615 W: http://palosaari.fi/linux/
8615 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 8616 Q: http://patchwork.linuxtv.org/project/linux-media/list/
8616 T: git git://linuxtv.org/anttip/media_tree.git 8617 T: git git://linuxtv.org/anttip/media_tree.git
8617 S: Maintained 8618 S: Maintained
8618 F: drivers/media/tuners/si2157* 8619 F: drivers/media/tuners/si2157*
8619 8620
8620 SI2168 MEDIA DRIVER 8621 SI2168 MEDIA DRIVER
8621 M: Antti Palosaari <crope@iki.fi> 8622 M: Antti Palosaari <crope@iki.fi>
8622 L: linux-media@vger.kernel.org 8623 L: linux-media@vger.kernel.org
8623 W: http://linuxtv.org/ 8624 W: http://linuxtv.org/
8624 W: http://palosaari.fi/linux/ 8625 W: http://palosaari.fi/linux/
8625 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 8626 Q: http://patchwork.linuxtv.org/project/linux-media/list/
8626 T: git git://linuxtv.org/anttip/media_tree.git 8627 T: git git://linuxtv.org/anttip/media_tree.git
8627 S: Maintained 8628 S: Maintained
8628 F: drivers/media/dvb-frontends/si2168* 8629 F: drivers/media/dvb-frontends/si2168*
8629 8630
8630 SI470X FM RADIO RECEIVER I2C DRIVER 8631 SI470X FM RADIO RECEIVER I2C DRIVER
8631 M: Hans Verkuil <hverkuil@xs4all.nl> 8632 M: Hans Verkuil <hverkuil@xs4all.nl>
8632 L: linux-media@vger.kernel.org 8633 L: linux-media@vger.kernel.org
8633 T: git git://linuxtv.org/media_tree.git 8634 T: git git://linuxtv.org/media_tree.git
8634 W: http://linuxtv.org 8635 W: http://linuxtv.org
8635 S: Odd Fixes 8636 S: Odd Fixes
8636 F: drivers/media/radio/si470x/radio-si470x-i2c.c 8637 F: drivers/media/radio/si470x/radio-si470x-i2c.c
8637 8638
8638 SI470X FM RADIO RECEIVER USB DRIVER 8639 SI470X FM RADIO RECEIVER USB DRIVER
8639 M: Hans Verkuil <hverkuil@xs4all.nl> 8640 M: Hans Verkuil <hverkuil@xs4all.nl>
8640 L: linux-media@vger.kernel.org 8641 L: linux-media@vger.kernel.org
8641 T: git git://linuxtv.org/media_tree.git 8642 T: git git://linuxtv.org/media_tree.git
8642 W: http://linuxtv.org 8643 W: http://linuxtv.org
8643 S: Maintained 8644 S: Maintained
8644 F: drivers/media/radio/si470x/radio-si470x-common.c 8645 F: drivers/media/radio/si470x/radio-si470x-common.c
8645 F: drivers/media/radio/si470x/radio-si470x.h 8646 F: drivers/media/radio/si470x/radio-si470x.h
8646 F: drivers/media/radio/si470x/radio-si470x-usb.c 8647 F: drivers/media/radio/si470x/radio-si470x-usb.c
8647 8648
8648 SI4713 FM RADIO TRANSMITTER I2C DRIVER 8649 SI4713 FM RADIO TRANSMITTER I2C DRIVER
8649 M: Eduardo Valentin <edubezval@gmail.com> 8650 M: Eduardo Valentin <edubezval@gmail.com>
8650 L: linux-media@vger.kernel.org 8651 L: linux-media@vger.kernel.org
8651 T: git git://linuxtv.org/media_tree.git 8652 T: git git://linuxtv.org/media_tree.git
8652 W: http://linuxtv.org 8653 W: http://linuxtv.org
8653 S: Odd Fixes 8654 S: Odd Fixes
8654 F: drivers/media/radio/si4713/si4713.? 8655 F: drivers/media/radio/si4713/si4713.?
8655 8656
8656 SI4713 FM RADIO TRANSMITTER PLATFORM DRIVER 8657 SI4713 FM RADIO TRANSMITTER PLATFORM DRIVER
8657 M: Eduardo Valentin <edubezval@gmail.com> 8658 M: Eduardo Valentin <edubezval@gmail.com>
8658 L: linux-media@vger.kernel.org 8659 L: linux-media@vger.kernel.org
8659 T: git git://linuxtv.org/media_tree.git 8660 T: git git://linuxtv.org/media_tree.git
8660 W: http://linuxtv.org 8661 W: http://linuxtv.org
8661 S: Odd Fixes 8662 S: Odd Fixes
8662 F: drivers/media/radio/si4713/radio-platform-si4713.c 8663 F: drivers/media/radio/si4713/radio-platform-si4713.c
8663 8664
8664 SI4713 FM RADIO TRANSMITTER USB DRIVER 8665 SI4713 FM RADIO TRANSMITTER USB DRIVER
8665 M: Hans Verkuil <hverkuil@xs4all.nl> 8666 M: Hans Verkuil <hverkuil@xs4all.nl>
8666 L: linux-media@vger.kernel.org 8667 L: linux-media@vger.kernel.org
8667 T: git git://linuxtv.org/media_tree.git 8668 T: git git://linuxtv.org/media_tree.git
8668 W: http://linuxtv.org 8669 W: http://linuxtv.org
8669 S: Maintained 8670 S: Maintained
8670 F: drivers/media/radio/si4713/radio-usb-si4713.c 8671 F: drivers/media/radio/si4713/radio-usb-si4713.c
8671 8672
8672 SIANO DVB DRIVER 8673 SIANO DVB DRIVER
8673 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com> 8674 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
8674 L: linux-media@vger.kernel.org 8675 L: linux-media@vger.kernel.org
8675 W: http://linuxtv.org 8676 W: http://linuxtv.org
8676 T: git git://linuxtv.org/media_tree.git 8677 T: git git://linuxtv.org/media_tree.git
8677 S: Odd fixes 8678 S: Odd fixes
8678 F: drivers/media/common/siano/ 8679 F: drivers/media/common/siano/
8679 F: drivers/media/usb/siano/ 8680 F: drivers/media/usb/siano/
8680 F: drivers/media/usb/siano/ 8681 F: drivers/media/usb/siano/
8681 F: drivers/media/mmc/siano/ 8682 F: drivers/media/mmc/siano/
8682 8683
8683 SIMPLEFB FB DRIVER 8684 SIMPLEFB FB DRIVER
8684 M: Hans de Goede <hdegoede@redhat.com> 8685 M: Hans de Goede <hdegoede@redhat.com>
8685 L: linux-fbdev@vger.kernel.org 8686 L: linux-fbdev@vger.kernel.org
8686 S: Maintained 8687 S: Maintained
8687 F: Documentation/devicetree/bindings/video/simple-framebuffer.txt 8688 F: Documentation/devicetree/bindings/video/simple-framebuffer.txt
8688 F: drivers/video/fbdev/simplefb.c 8689 F: drivers/video/fbdev/simplefb.c
8689 F: include/linux/platform_data/simplefb.h 8690 F: include/linux/platform_data/simplefb.h
8690 8691
8691 SH_VEU V4L2 MEM2MEM DRIVER 8692 SH_VEU V4L2 MEM2MEM DRIVER
8692 L: linux-media@vger.kernel.org 8693 L: linux-media@vger.kernel.org
8693 S: Orphan 8694 S: Orphan
8694 F: drivers/media/platform/sh_veu.c 8695 F: drivers/media/platform/sh_veu.c
8695 8696
8696 SH_VOU V4L2 OUTPUT DRIVER 8697 SH_VOU V4L2 OUTPUT DRIVER
8697 L: linux-media@vger.kernel.org 8698 L: linux-media@vger.kernel.org
8698 S: Orphan 8699 S: Orphan
8699 F: drivers/media/platform/sh_vou.c 8700 F: drivers/media/platform/sh_vou.c
8700 F: include/media/sh_vou.h 8701 F: include/media/sh_vou.h
8701 8702
8702 SIMPLE FIRMWARE INTERFACE (SFI) 8703 SIMPLE FIRMWARE INTERFACE (SFI)
8703 M: Len Brown <lenb@kernel.org> 8704 M: Len Brown <lenb@kernel.org>
8704 L: sfi-devel@simplefirmware.org 8705 L: sfi-devel@simplefirmware.org
8705 W: http://simplefirmware.org/ 8706 W: http://simplefirmware.org/
8706 T: git git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux-sfi-2.6.git 8707 T: git git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux-sfi-2.6.git
8707 S: Supported 8708 S: Supported
8708 F: arch/x86/platform/sfi/ 8709 F: arch/x86/platform/sfi/
8709 F: drivers/sfi/ 8710 F: drivers/sfi/
8710 F: include/linux/sfi*.h 8711 F: include/linux/sfi*.h
8711 8712
8712 SIMTEC EB110ATX (Chalice CATS) 8713 SIMTEC EB110ATX (Chalice CATS)
8713 P: Ben Dooks 8714 P: Ben Dooks
8714 P: Vincent Sanders <vince@simtec.co.uk> 8715 P: Vincent Sanders <vince@simtec.co.uk>
8715 M: Simtec Linux Team <linux@simtec.co.uk> 8716 M: Simtec Linux Team <linux@simtec.co.uk>
8716 W: http://www.simtec.co.uk/products/EB110ATX/ 8717 W: http://www.simtec.co.uk/products/EB110ATX/
8717 S: Supported 8718 S: Supported
8718 8719
8719 SIMTEC EB2410ITX (BAST) 8720 SIMTEC EB2410ITX (BAST)
8720 P: Ben Dooks 8721 P: Ben Dooks
8721 P: Vincent Sanders <vince@simtec.co.uk> 8722 P: Vincent Sanders <vince@simtec.co.uk>
8722 M: Simtec Linux Team <linux@simtec.co.uk> 8723 M: Simtec Linux Team <linux@simtec.co.uk>
8723 W: http://www.simtec.co.uk/products/EB2410ITX/ 8724 W: http://www.simtec.co.uk/products/EB2410ITX/
8724 S: Supported 8725 S: Supported
8725 F: arch/arm/mach-s3c24xx/mach-bast.c 8726 F: arch/arm/mach-s3c24xx/mach-bast.c
8726 F: arch/arm/mach-s3c24xx/bast-ide.c 8727 F: arch/arm/mach-s3c24xx/bast-ide.c
8727 F: arch/arm/mach-s3c24xx/bast-irq.c 8728 F: arch/arm/mach-s3c24xx/bast-irq.c
8728 8729
8729 TI DAVINCI MACHINE SUPPORT 8730 TI DAVINCI MACHINE SUPPORT
8730 M: Sekhar Nori <nsekhar@ti.com> 8731 M: Sekhar Nori <nsekhar@ti.com>
8731 M: Kevin Hilman <khilman@deeprootsystems.com> 8732 M: Kevin Hilman <khilman@deeprootsystems.com>
8732 T: git git://gitorious.org/linux-davinci/linux-davinci.git 8733 T: git git://gitorious.org/linux-davinci/linux-davinci.git
8733 Q: http://patchwork.kernel.org/project/linux-davinci/list/ 8734 Q: http://patchwork.kernel.org/project/linux-davinci/list/
8734 S: Supported 8735 S: Supported
8735 F: arch/arm/mach-davinci/ 8736 F: arch/arm/mach-davinci/
8736 F: drivers/i2c/busses/i2c-davinci.c 8737 F: drivers/i2c/busses/i2c-davinci.c
8737 8738
8738 TI DAVINCI SERIES MEDIA DRIVER 8739 TI DAVINCI SERIES MEDIA DRIVER
8739 M: Lad, Prabhakar <prabhakar.csengg@gmail.com> 8740 M: Lad, Prabhakar <prabhakar.csengg@gmail.com>
8740 L: linux-media@vger.kernel.org 8741 L: linux-media@vger.kernel.org
8741 W: http://linuxtv.org/ 8742 W: http://linuxtv.org/
8742 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 8743 Q: http://patchwork.linuxtv.org/project/linux-media/list/
8743 T: git git://linuxtv.org/mhadli/v4l-dvb-davinci_devices.git 8744 T: git git://linuxtv.org/mhadli/v4l-dvb-davinci_devices.git
8744 S: Maintained 8745 S: Maintained
8745 F: drivers/media/platform/davinci/ 8746 F: drivers/media/platform/davinci/
8746 F: include/media/davinci/ 8747 F: include/media/davinci/
8747 8748
8748 SIS 190 ETHERNET DRIVER 8749 SIS 190 ETHERNET DRIVER
8749 M: Francois Romieu <romieu@fr.zoreil.com> 8750 M: Francois Romieu <romieu@fr.zoreil.com>
8750 L: netdev@vger.kernel.org 8751 L: netdev@vger.kernel.org
8751 S: Maintained 8752 S: Maintained
8752 F: drivers/net/ethernet/sis/sis190.c 8753 F: drivers/net/ethernet/sis/sis190.c
8753 8754
8754 SIS 900/7016 FAST ETHERNET DRIVER 8755 SIS 900/7016 FAST ETHERNET DRIVER
8755 M: Daniele Venzano <venza@brownhat.org> 8756 M: Daniele Venzano <venza@brownhat.org>
8756 W: http://www.brownhat.org/sis900.html 8757 W: http://www.brownhat.org/sis900.html
8757 L: netdev@vger.kernel.org 8758 L: netdev@vger.kernel.org
8758 S: Maintained 8759 S: Maintained
8759 F: drivers/net/ethernet/sis/sis900.* 8760 F: drivers/net/ethernet/sis/sis900.*
8760 8761
8761 SIS FRAMEBUFFER DRIVER 8762 SIS FRAMEBUFFER DRIVER
8762 M: Thomas Winischhofer <thomas@winischhofer.net> 8763 M: Thomas Winischhofer <thomas@winischhofer.net>
8763 W: http://www.winischhofer.net/linuxsisvga.shtml 8764 W: http://www.winischhofer.net/linuxsisvga.shtml
8764 S: Maintained 8765 S: Maintained
8765 F: Documentation/fb/sisfb.txt 8766 F: Documentation/fb/sisfb.txt
8766 F: drivers/video/fbdev/sis/ 8767 F: drivers/video/fbdev/sis/
8767 F: include/video/sisfb.h 8768 F: include/video/sisfb.h
8768 8769
8769 SIS USB2VGA DRIVER 8770 SIS USB2VGA DRIVER
8770 M: Thomas Winischhofer <thomas@winischhofer.net> 8771 M: Thomas Winischhofer <thomas@winischhofer.net>
8771 W: http://www.winischhofer.at/linuxsisusbvga.shtml 8772 W: http://www.winischhofer.at/linuxsisusbvga.shtml
8772 S: Maintained 8773 S: Maintained
8773 F: drivers/usb/misc/sisusbvga/ 8774 F: drivers/usb/misc/sisusbvga/
8774 8775
8775 SLAB ALLOCATOR 8776 SLAB ALLOCATOR
8776 M: Christoph Lameter <cl@linux.com> 8777 M: Christoph Lameter <cl@linux.com>
8777 M: Pekka Enberg <penberg@kernel.org> 8778 M: Pekka Enberg <penberg@kernel.org>
8778 M: David Rientjes <rientjes@google.com> 8779 M: David Rientjes <rientjes@google.com>
8779 M: Joonsoo Kim <iamjoonsoo.kim@lge.com> 8780 M: Joonsoo Kim <iamjoonsoo.kim@lge.com>
8780 M: Andrew Morton <akpm@linux-foundation.org> 8781 M: Andrew Morton <akpm@linux-foundation.org>
8781 L: linux-mm@kvack.org 8782 L: linux-mm@kvack.org
8782 S: Maintained 8783 S: Maintained
8783 F: include/linux/sl?b*.h 8784 F: include/linux/sl?b*.h
8784 F: mm/sl?b* 8785 F: mm/sl?b*
8785 8786
8786 SLEEPABLE READ-COPY UPDATE (SRCU) 8787 SLEEPABLE READ-COPY UPDATE (SRCU)
8787 M: Lai Jiangshan <laijs@cn.fujitsu.com> 8788 M: Lai Jiangshan <laijs@cn.fujitsu.com>
8788 M: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> 8789 M: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
8789 M: Josh Triplett <josh@joshtriplett.org> 8790 M: Josh Triplett <josh@joshtriplett.org>
8790 R: Steven Rostedt <rostedt@goodmis.org> 8791 R: Steven Rostedt <rostedt@goodmis.org>
8791 R: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> 8792 R: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8792 L: linux-kernel@vger.kernel.org 8793 L: linux-kernel@vger.kernel.org
8793 W: http://www.rdrop.com/users/paulmck/RCU/ 8794 W: http://www.rdrop.com/users/paulmck/RCU/
8794 S: Supported 8795 S: Supported
8795 T: git git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git 8796 T: git git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git
8796 F: include/linux/srcu.h 8797 F: include/linux/srcu.h
8797 F: kernel/rcu/srcu.c 8798 F: kernel/rcu/srcu.c
8798 8799
8799 SMACK SECURITY MODULE 8800 SMACK SECURITY MODULE
8800 M: Casey Schaufler <casey@schaufler-ca.com> 8801 M: Casey Schaufler <casey@schaufler-ca.com>
8801 L: linux-security-module@vger.kernel.org 8802 L: linux-security-module@vger.kernel.org
8802 W: http://schaufler-ca.com 8803 W: http://schaufler-ca.com
8803 T: git git://git.gitorious.org/smack-next/kernel.git 8804 T: git git://git.gitorious.org/smack-next/kernel.git
8804 S: Maintained 8805 S: Maintained
8805 F: Documentation/security/Smack.txt 8806 F: Documentation/security/Smack.txt
8806 F: security/smack/ 8807 F: security/smack/
8807 8808
8808 DRIVERS FOR ADAPTIVE VOLTAGE SCALING (AVS) 8809 DRIVERS FOR ADAPTIVE VOLTAGE SCALING (AVS)
8809 M: Kevin Hilman <khilman@kernel.org> 8810 M: Kevin Hilman <khilman@kernel.org>
8810 M: Nishanth Menon <nm@ti.com> 8811 M: Nishanth Menon <nm@ti.com>
8811 S: Maintained 8812 S: Maintained
8812 F: drivers/power/avs/ 8813 F: drivers/power/avs/
8813 F: include/linux/power/smartreflex.h 8814 F: include/linux/power/smartreflex.h
8814 L: linux-pm@vger.kernel.org 8815 L: linux-pm@vger.kernel.org
8815 8816
8816 SMC91x ETHERNET DRIVER 8817 SMC91x ETHERNET DRIVER
8817 M: Nicolas Pitre <nico@fluxnic.net> 8818 M: Nicolas Pitre <nico@fluxnic.net>
8818 S: Odd Fixes 8819 S: Odd Fixes
8819 F: drivers/net/ethernet/smsc/smc91x.* 8820 F: drivers/net/ethernet/smsc/smc91x.*
8820 8821
8821 SMIA AND SMIA++ IMAGE SENSOR DRIVER 8822 SMIA AND SMIA++ IMAGE SENSOR DRIVER
8822 M: Sakari Ailus <sakari.ailus@iki.fi> 8823 M: Sakari Ailus <sakari.ailus@iki.fi>
8823 L: linux-media@vger.kernel.org 8824 L: linux-media@vger.kernel.org
8824 S: Maintained 8825 S: Maintained
8825 F: drivers/media/i2c/smiapp/ 8826 F: drivers/media/i2c/smiapp/
8826 F: include/media/smiapp.h 8827 F: include/media/smiapp.h
8827 F: drivers/media/i2c/smiapp-pll.c 8828 F: drivers/media/i2c/smiapp-pll.c
8828 F: drivers/media/i2c/smiapp-pll.h 8829 F: drivers/media/i2c/smiapp-pll.h
8829 8830
8830 SMM665 HARDWARE MONITOR DRIVER 8831 SMM665 HARDWARE MONITOR DRIVER
8831 M: Guenter Roeck <linux@roeck-us.net> 8832 M: Guenter Roeck <linux@roeck-us.net>
8832 L: lm-sensors@lm-sensors.org 8833 L: lm-sensors@lm-sensors.org
8833 S: Maintained 8834 S: Maintained
8834 F: Documentation/hwmon/smm665 8835 F: Documentation/hwmon/smm665
8835 F: drivers/hwmon/smm665.c 8836 F: drivers/hwmon/smm665.c
8836 8837
8837 SMSC EMC2103 HARDWARE MONITOR DRIVER 8838 SMSC EMC2103 HARDWARE MONITOR DRIVER
8838 M: Steve Glendinning <steve.glendinning@shawell.net> 8839 M: Steve Glendinning <steve.glendinning@shawell.net>
8839 L: lm-sensors@lm-sensors.org 8840 L: lm-sensors@lm-sensors.org
8840 S: Maintained 8841 S: Maintained
8841 F: Documentation/hwmon/emc2103 8842 F: Documentation/hwmon/emc2103
8842 F: drivers/hwmon/emc2103.c 8843 F: drivers/hwmon/emc2103.c
8843 8844
8844 SMSC SCH5627 HARDWARE MONITOR DRIVER 8845 SMSC SCH5627 HARDWARE MONITOR DRIVER
8845 M: Hans de Goede <hdegoede@redhat.com> 8846 M: Hans de Goede <hdegoede@redhat.com>
8846 L: lm-sensors@lm-sensors.org 8847 L: lm-sensors@lm-sensors.org
8847 S: Supported 8848 S: Supported
8848 F: Documentation/hwmon/sch5627 8849 F: Documentation/hwmon/sch5627
8849 F: drivers/hwmon/sch5627.c 8850 F: drivers/hwmon/sch5627.c
8850 8851
8851 SMSC47B397 HARDWARE MONITOR DRIVER 8852 SMSC47B397 HARDWARE MONITOR DRIVER
8852 M: Jean Delvare <jdelvare@suse.de> 8853 M: Jean Delvare <jdelvare@suse.de>
8853 L: lm-sensors@lm-sensors.org 8854 L: lm-sensors@lm-sensors.org
8854 S: Maintained 8855 S: Maintained
8855 F: Documentation/hwmon/smsc47b397 8856 F: Documentation/hwmon/smsc47b397
8856 F: drivers/hwmon/smsc47b397.c 8857 F: drivers/hwmon/smsc47b397.c
8857 8858
8858 SMSC911x ETHERNET DRIVER 8859 SMSC911x ETHERNET DRIVER
8859 M: Steve Glendinning <steve.glendinning@shawell.net> 8860 M: Steve Glendinning <steve.glendinning@shawell.net>
8860 L: netdev@vger.kernel.org 8861 L: netdev@vger.kernel.org
8861 S: Maintained 8862 S: Maintained
8862 F: include/linux/smsc911x.h 8863 F: include/linux/smsc911x.h
8863 F: drivers/net/ethernet/smsc/smsc911x.* 8864 F: drivers/net/ethernet/smsc/smsc911x.*
8864 8865
8865 SMSC9420 PCI ETHERNET DRIVER 8866 SMSC9420 PCI ETHERNET DRIVER
8866 M: Steve Glendinning <steve.glendinning@shawell.net> 8867 M: Steve Glendinning <steve.glendinning@shawell.net>
8867 L: netdev@vger.kernel.org 8868 L: netdev@vger.kernel.org
8868 S: Maintained 8869 S: Maintained
8869 F: drivers/net/ethernet/smsc/smsc9420.* 8870 F: drivers/net/ethernet/smsc/smsc9420.*
8870 8871
8871 SMSC UFX6000 and UFX7000 USB to VGA DRIVER 8872 SMSC UFX6000 and UFX7000 USB to VGA DRIVER
8872 M: Steve Glendinning <steve.glendinning@shawell.net> 8873 M: Steve Glendinning <steve.glendinning@shawell.net>
8873 L: linux-fbdev@vger.kernel.org 8874 L: linux-fbdev@vger.kernel.org
8874 S: Maintained 8875 S: Maintained
8875 F: drivers/video/fbdev/smscufx.c 8876 F: drivers/video/fbdev/smscufx.c
8876 8877
8877 SOC-CAMERA V4L2 SUBSYSTEM 8878 SOC-CAMERA V4L2 SUBSYSTEM
8878 M: Guennadi Liakhovetski <g.liakhovetski@gmx.de> 8879 M: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
8879 L: linux-media@vger.kernel.org 8880 L: linux-media@vger.kernel.org
8880 T: git git://linuxtv.org/media_tree.git 8881 T: git git://linuxtv.org/media_tree.git
8881 S: Maintained 8882 S: Maintained
8882 F: include/media/soc* 8883 F: include/media/soc*
8883 F: drivers/media/i2c/soc_camera/ 8884 F: drivers/media/i2c/soc_camera/
8884 F: drivers/media/platform/soc_camera/ 8885 F: drivers/media/platform/soc_camera/
8885 8886
8886 SOEKRIS NET48XX LED SUPPORT 8887 SOEKRIS NET48XX LED SUPPORT
8887 M: Chris Boot <bootc@bootc.net> 8888 M: Chris Boot <bootc@bootc.net>
8888 S: Maintained 8889 S: Maintained
8889 F: drivers/leds/leds-net48xx.c 8890 F: drivers/leds/leds-net48xx.c
8890 8891
8891 SOFTLOGIC 6x10 MPEG CODEC 8892 SOFTLOGIC 6x10 MPEG CODEC
8892 M: Bluecherry Maintainers <maintainers@bluecherrydvr.com> 8893 M: Bluecherry Maintainers <maintainers@bluecherrydvr.com>
8893 M: Andrey Utkin <andrey.utkin@corp.bluecherry.net> 8894 M: Andrey Utkin <andrey.utkin@corp.bluecherry.net>
8894 M: Andrey Utkin <andrey.krieger.utkin@gmail.com> 8895 M: Andrey Utkin <andrey.krieger.utkin@gmail.com>
8895 L: linux-media@vger.kernel.org 8896 L: linux-media@vger.kernel.org
8896 S: Supported 8897 S: Supported
8897 F: drivers/media/pci/solo6x10/ 8898 F: drivers/media/pci/solo6x10/
8898 8899
8899 SOFTWARE RAID (Multiple Disks) SUPPORT 8900 SOFTWARE RAID (Multiple Disks) SUPPORT
8900 M: Neil Brown <neilb@suse.de> 8901 M: Neil Brown <neilb@suse.de>
8901 L: linux-raid@vger.kernel.org 8902 L: linux-raid@vger.kernel.org
8902 S: Supported 8903 S: Supported
8903 F: drivers/md/ 8904 F: drivers/md/
8904 F: include/linux/raid/ 8905 F: include/linux/raid/
8905 F: include/uapi/linux/raid/ 8906 F: include/uapi/linux/raid/
8906 8907
8907 SONIC NETWORK DRIVER 8908 SONIC NETWORK DRIVER
8908 M: Thomas Bogendoerfer <tsbogend@alpha.franken.de> 8909 M: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
8909 L: netdev@vger.kernel.org 8910 L: netdev@vger.kernel.org
8910 S: Maintained 8911 S: Maintained
8911 F: drivers/net/ethernet/natsemi/sonic.* 8912 F: drivers/net/ethernet/natsemi/sonic.*
8912 8913
8913 SONICS SILICON BACKPLANE DRIVER (SSB) 8914 SONICS SILICON BACKPLANE DRIVER (SSB)
8914 M: Michael Buesch <m@bues.ch> 8915 M: Michael Buesch <m@bues.ch>
8915 L: netdev@vger.kernel.org 8916 L: netdev@vger.kernel.org
8916 S: Maintained 8917 S: Maintained
8917 F: drivers/ssb/ 8918 F: drivers/ssb/
8918 F: include/linux/ssb/ 8919 F: include/linux/ssb/
8919 8920
8920 SONY VAIO CONTROL DEVICE DRIVER 8921 SONY VAIO CONTROL DEVICE DRIVER
8921 M: Mattia Dongili <malattia@linux.it> 8922 M: Mattia Dongili <malattia@linux.it>
8922 L: platform-driver-x86@vger.kernel.org 8923 L: platform-driver-x86@vger.kernel.org
8923 W: http://www.linux.it/~malattia/wiki/index.php/Sony_drivers 8924 W: http://www.linux.it/~malattia/wiki/index.php/Sony_drivers
8924 S: Maintained 8925 S: Maintained
8925 F: Documentation/laptops/sony-laptop.txt 8926 F: Documentation/laptops/sony-laptop.txt
8926 F: drivers/char/sonypi.c 8927 F: drivers/char/sonypi.c
8927 F: drivers/platform/x86/sony-laptop.c 8928 F: drivers/platform/x86/sony-laptop.c
8928 F: include/linux/sony-laptop.h 8929 F: include/linux/sony-laptop.h
8929 8930
8930 SONY MEMORYSTICK CARD SUPPORT 8931 SONY MEMORYSTICK CARD SUPPORT
8931 M: Alex Dubov <oakad@yahoo.com> 8932 M: Alex Dubov <oakad@yahoo.com>
8932 W: http://tifmxx.berlios.de/ 8933 W: http://tifmxx.berlios.de/
8933 S: Maintained 8934 S: Maintained
8934 F: drivers/memstick/host/tifm_ms.c 8935 F: drivers/memstick/host/tifm_ms.c
8935 8936
8936 SONY MEMORYSTICK STANDARD SUPPORT 8937 SONY MEMORYSTICK STANDARD SUPPORT
8937 M: Maxim Levitsky <maximlevitsky@gmail.com> 8938 M: Maxim Levitsky <maximlevitsky@gmail.com>
8938 S: Maintained 8939 S: Maintained
8939 F: drivers/memstick/core/ms_block.* 8940 F: drivers/memstick/core/ms_block.*
8940 8941
8941 SOUND 8942 SOUND
8942 M: Jaroslav Kysela <perex@perex.cz> 8943 M: Jaroslav Kysela <perex@perex.cz>
8943 M: Takashi Iwai <tiwai@suse.de> 8944 M: Takashi Iwai <tiwai@suse.de>
8944 L: alsa-devel@alsa-project.org (moderated for non-subscribers) 8945 L: alsa-devel@alsa-project.org (moderated for non-subscribers)
8945 W: http://www.alsa-project.org/ 8946 W: http://www.alsa-project.org/
8946 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git 8947 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git
8947 T: git git://git.alsa-project.org/alsa-kernel.git 8948 T: git git://git.alsa-project.org/alsa-kernel.git
8948 Q: http://patchwork.kernel.org/project/alsa-devel/list/ 8949 Q: http://patchwork.kernel.org/project/alsa-devel/list/
8949 S: Maintained 8950 S: Maintained
8950 F: Documentation/sound/ 8951 F: Documentation/sound/
8951 F: include/sound/ 8952 F: include/sound/
8952 F: include/uapi/sound/ 8953 F: include/uapi/sound/
8953 F: sound/ 8954 F: sound/
8954 8955
8955 SOUND - COMPRESSED AUDIO 8956 SOUND - COMPRESSED AUDIO
8956 M: Vinod Koul <vinod.koul@intel.com> 8957 M: Vinod Koul <vinod.koul@intel.com>
8957 L: alsa-devel@alsa-project.org (moderated for non-subscribers) 8958 L: alsa-devel@alsa-project.org (moderated for non-subscribers)
8958 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git 8959 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git
8959 S: Supported 8960 S: Supported
8960 F: Documentation/sound/alsa/compress_offload.txt 8961 F: Documentation/sound/alsa/compress_offload.txt
8961 F: include/sound/compress_driver.h 8962 F: include/sound/compress_driver.h
8962 F: include/uapi/sound/compress_* 8963 F: include/uapi/sound/compress_*
8963 F: sound/core/compress_offload.c 8964 F: sound/core/compress_offload.c
8964 F: sound/soc/soc-compress.c 8965 F: sound/soc/soc-compress.c
8965 8966
8966 SOUND - SOC LAYER / DYNAMIC AUDIO POWER MANAGEMENT (ASoC) 8967 SOUND - SOC LAYER / DYNAMIC AUDIO POWER MANAGEMENT (ASoC)
8967 M: Liam Girdwood <lgirdwood@gmail.com> 8968 M: Liam Girdwood <lgirdwood@gmail.com>
8968 M: Mark Brown <broonie@kernel.org> 8969 M: Mark Brown <broonie@kernel.org>
8969 T: git git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git 8970 T: git git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git
8970 L: alsa-devel@alsa-project.org (moderated for non-subscribers) 8971 L: alsa-devel@alsa-project.org (moderated for non-subscribers)
8971 W: http://alsa-project.org/main/index.php/ASoC 8972 W: http://alsa-project.org/main/index.php/ASoC
8972 S: Supported 8973 S: Supported
8973 F: Documentation/sound/alsa/soc/ 8974 F: Documentation/sound/alsa/soc/
8974 F: sound/soc/ 8975 F: sound/soc/
8975 F: include/sound/soc* 8976 F: include/sound/soc*
8976 8977
8977 SOUND - DMAENGINE HELPERS 8978 SOUND - DMAENGINE HELPERS
8978 M: Lars-Peter Clausen <lars@metafoo.de> 8979 M: Lars-Peter Clausen <lars@metafoo.de>
8979 S: Supported 8980 S: Supported
8980 F: include/sound/dmaengine_pcm.h 8981 F: include/sound/dmaengine_pcm.h
8981 F: sound/core/pcm_dmaengine.c 8982 F: sound/core/pcm_dmaengine.c
8982 F: sound/soc/soc-generic-dmaengine-pcm.c 8983 F: sound/soc/soc-generic-dmaengine-pcm.c
8983 8984
8984 SP2 MEDIA DRIVER 8985 SP2 MEDIA DRIVER
8985 M: Olli Salonen <olli.salonen@iki.fi> 8986 M: Olli Salonen <olli.salonen@iki.fi>
8986 L: linux-media@vger.kernel.org 8987 L: linux-media@vger.kernel.org
8987 W: http://linuxtv.org/ 8988 W: http://linuxtv.org/
8988 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 8989 Q: http://patchwork.linuxtv.org/project/linux-media/list/
8989 S: Maintained 8990 S: Maintained
8990 F: drivers/media/dvb-frontends/sp2* 8991 F: drivers/media/dvb-frontends/sp2*
8991 8992
8992 SPARC + UltraSPARC (sparc/sparc64) 8993 SPARC + UltraSPARC (sparc/sparc64)
8993 M: "David S. Miller" <davem@davemloft.net> 8994 M: "David S. Miller" <davem@davemloft.net>
8994 L: sparclinux@vger.kernel.org 8995 L: sparclinux@vger.kernel.org
8995 Q: http://patchwork.ozlabs.org/project/sparclinux/list/ 8996 Q: http://patchwork.ozlabs.org/project/sparclinux/list/
8996 T: git git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc.git 8997 T: git git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc.git
8997 T: git git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc-next.git 8998 T: git git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc-next.git
8998 S: Maintained 8999 S: Maintained
8999 F: arch/sparc/ 9000 F: arch/sparc/
9000 F: drivers/sbus/ 9001 F: drivers/sbus/
9001 9002
9002 SPARC SERIAL DRIVERS 9003 SPARC SERIAL DRIVERS
9003 M: "David S. Miller" <davem@davemloft.net> 9004 M: "David S. Miller" <davem@davemloft.net>
9004 L: sparclinux@vger.kernel.org 9005 L: sparclinux@vger.kernel.org
9005 T: git git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc.git 9006 T: git git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc.git
9006 T: git git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc-next.git 9007 T: git git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc-next.git
9007 S: Maintained 9008 S: Maintained
9008 F: include/linux/sunserialcore.h 9009 F: include/linux/sunserialcore.h
9009 F: drivers/tty/serial/suncore.c 9010 F: drivers/tty/serial/suncore.c
9010 F: drivers/tty/serial/sunhv.c 9011 F: drivers/tty/serial/sunhv.c
9011 F: drivers/tty/serial/sunsab.c 9012 F: drivers/tty/serial/sunsab.c
9012 F: drivers/tty/serial/sunsab.h 9013 F: drivers/tty/serial/sunsab.h
9013 F: drivers/tty/serial/sunsu.c 9014 F: drivers/tty/serial/sunsu.c
9014 F: drivers/tty/serial/sunzilog.c 9015 F: drivers/tty/serial/sunzilog.c
9015 F: drivers/tty/serial/sunzilog.h 9016 F: drivers/tty/serial/sunzilog.h
9016 9017
9017 SPARSE CHECKER 9018 SPARSE CHECKER
9018 M: "Christopher Li" <sparse@chrisli.org> 9019 M: "Christopher Li" <sparse@chrisli.org>
9019 L: linux-sparse@vger.kernel.org 9020 L: linux-sparse@vger.kernel.org
9020 W: https://sparse.wiki.kernel.org/ 9021 W: https://sparse.wiki.kernel.org/
9021 T: git git://git.kernel.org/pub/scm/devel/sparse/sparse.git 9022 T: git git://git.kernel.org/pub/scm/devel/sparse/sparse.git
9022 T: git git://git.kernel.org/pub/scm/devel/sparse/chrisl/sparse.git 9023 T: git git://git.kernel.org/pub/scm/devel/sparse/chrisl/sparse.git
9023 S: Maintained 9024 S: Maintained
9024 F: include/linux/compiler.h 9025 F: include/linux/compiler.h
9025 9026
9026 SPEAR PLATFORM SUPPORT 9027 SPEAR PLATFORM SUPPORT
9027 M: Viresh Kumar <viresh.linux@gmail.com> 9028 M: Viresh Kumar <viresh.linux@gmail.com>
9028 M: Shiraz Hashim <shiraz.linux.kernel@gmail.com> 9029 M: Shiraz Hashim <shiraz.linux.kernel@gmail.com>
9029 L: spear-devel@list.st.com 9030 L: spear-devel@list.st.com
9030 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 9031 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
9031 W: http://www.st.com/spear 9032 W: http://www.st.com/spear
9032 S: Maintained 9033 S: Maintained
9033 F: arch/arm/mach-spear/ 9034 F: arch/arm/mach-spear/
9034 9035
9035 SPEAR CLOCK FRAMEWORK SUPPORT 9036 SPEAR CLOCK FRAMEWORK SUPPORT
9036 M: Viresh Kumar <viresh.linux@gmail.com> 9037 M: Viresh Kumar <viresh.linux@gmail.com>
9037 L: spear-devel@list.st.com 9038 L: spear-devel@list.st.com
9038 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 9039 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
9039 W: http://www.st.com/spear 9040 W: http://www.st.com/spear
9040 S: Maintained 9041 S: Maintained
9041 F: drivers/clk/spear/ 9042 F: drivers/clk/spear/
9042 9043
9043 SPI SUBSYSTEM 9044 SPI SUBSYSTEM
9044 M: Mark Brown <broonie@kernel.org> 9045 M: Mark Brown <broonie@kernel.org>
9045 L: linux-spi@vger.kernel.org 9046 L: linux-spi@vger.kernel.org
9046 T: git git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git 9047 T: git git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git
9047 Q: http://patchwork.kernel.org/project/spi-devel-general/list/ 9048 Q: http://patchwork.kernel.org/project/spi-devel-general/list/
9048 S: Maintained 9049 S: Maintained
9049 F: Documentation/spi/ 9050 F: Documentation/spi/
9050 F: drivers/spi/ 9051 F: drivers/spi/
9051 F: include/linux/spi/ 9052 F: include/linux/spi/
9052 F: include/uapi/linux/spi/ 9053 F: include/uapi/linux/spi/
9053 9054
9054 SPIDERNET NETWORK DRIVER for CELL 9055 SPIDERNET NETWORK DRIVER for CELL
9055 M: Ishizaki Kou <kou.ishizaki@toshiba.co.jp> 9056 M: Ishizaki Kou <kou.ishizaki@toshiba.co.jp>
9056 M: Jens Osterkamp <jens@de.ibm.com> 9057 M: Jens Osterkamp <jens@de.ibm.com>
9057 L: netdev@vger.kernel.org 9058 L: netdev@vger.kernel.org
9058 S: Supported 9059 S: Supported
9059 F: Documentation/networking/spider_net.txt 9060 F: Documentation/networking/spider_net.txt
9060 F: drivers/net/ethernet/toshiba/spider_net* 9061 F: drivers/net/ethernet/toshiba/spider_net*
9061 9062
9062 SPU FILE SYSTEM 9063 SPU FILE SYSTEM
9063 M: Jeremy Kerr <jk@ozlabs.org> 9064 M: Jeremy Kerr <jk@ozlabs.org>
9064 L: linuxppc-dev@lists.ozlabs.org 9065 L: linuxppc-dev@lists.ozlabs.org
9065 L: cbe-oss-dev@lists.ozlabs.org 9066 L: cbe-oss-dev@lists.ozlabs.org
9066 W: http://www.ibm.com/developerworks/power/cell/ 9067 W: http://www.ibm.com/developerworks/power/cell/
9067 S: Supported 9068 S: Supported
9068 F: Documentation/filesystems/spufs.txt 9069 F: Documentation/filesystems/spufs.txt
9069 F: arch/powerpc/platforms/cell/spufs/ 9070 F: arch/powerpc/platforms/cell/spufs/
9070 9071
9071 SQUASHFS FILE SYSTEM 9072 SQUASHFS FILE SYSTEM
9072 M: Phillip Lougher <phillip@squashfs.org.uk> 9073 M: Phillip Lougher <phillip@squashfs.org.uk>
9073 L: squashfs-devel@lists.sourceforge.net (subscribers-only) 9074 L: squashfs-devel@lists.sourceforge.net (subscribers-only)
9074 W: http://squashfs.org.uk 9075 W: http://squashfs.org.uk
9075 S: Maintained 9076 S: Maintained
9076 F: Documentation/filesystems/squashfs.txt 9077 F: Documentation/filesystems/squashfs.txt
9077 F: fs/squashfs/ 9078 F: fs/squashfs/
9078 9079
9079 SRM (Alpha) environment access 9080 SRM (Alpha) environment access
9080 M: Jan-Benedict Glaw <jbglaw@lug-owl.de> 9081 M: Jan-Benedict Glaw <jbglaw@lug-owl.de>
9081 S: Maintained 9082 S: Maintained
9082 F: arch/alpha/kernel/srm_env.c 9083 F: arch/alpha/kernel/srm_env.c
9083 9084
9084 STABLE BRANCH 9085 STABLE BRANCH
9085 M: Greg Kroah-Hartman <gregkh@linuxfoundation.org> 9086 M: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9086 L: stable@vger.kernel.org 9087 L: stable@vger.kernel.org
9087 S: Supported 9088 S: Supported
9088 F: Documentation/stable_kernel_rules.txt 9089 F: Documentation/stable_kernel_rules.txt
9089 9090
9090 STAGING SUBSYSTEM 9091 STAGING SUBSYSTEM
9091 M: Greg Kroah-Hartman <gregkh@linuxfoundation.org> 9092 M: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9092 T: git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git 9093 T: git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git
9093 L: devel@driverdev.osuosl.org 9094 L: devel@driverdev.osuosl.org
9094 S: Supported 9095 S: Supported
9095 F: drivers/staging/ 9096 F: drivers/staging/
9096 9097
9097 STAGING - COMEDI 9098 STAGING - COMEDI
9098 M: Ian Abbott <abbotti@mev.co.uk> 9099 M: Ian Abbott <abbotti@mev.co.uk>
9099 M: H Hartley Sweeten <hsweeten@visionengravers.com> 9100 M: H Hartley Sweeten <hsweeten@visionengravers.com>
9100 S: Odd Fixes 9101 S: Odd Fixes
9101 F: drivers/staging/comedi/ 9102 F: drivers/staging/comedi/
9102 9103
9103 STAGING - FLARION FT1000 DRIVERS 9104 STAGING - FLARION FT1000 DRIVERS
9104 M: Marek Belisko <marek.belisko@gmail.com> 9105 M: Marek Belisko <marek.belisko@gmail.com>
9105 S: Odd Fixes 9106 S: Odd Fixes
9106 F: drivers/staging/ft1000/ 9107 F: drivers/staging/ft1000/
9107 9108
9108 STAGING - INDUSTRIAL IO 9109 STAGING - INDUSTRIAL IO
9109 M: Jonathan Cameron <jic23@kernel.org> 9110 M: Jonathan Cameron <jic23@kernel.org>
9110 L: linux-iio@vger.kernel.org 9111 L: linux-iio@vger.kernel.org
9111 S: Odd Fixes 9112 S: Odd Fixes
9112 F: drivers/staging/iio/ 9113 F: drivers/staging/iio/
9113 9114
9114 STAGING - LIRC (LINUX INFRARED REMOTE CONTROL) DRIVERS 9115 STAGING - LIRC (LINUX INFRARED REMOTE CONTROL) DRIVERS
9115 M: Jarod Wilson <jarod@wilsonet.com> 9116 M: Jarod Wilson <jarod@wilsonet.com>
9116 W: http://www.lirc.org/ 9117 W: http://www.lirc.org/
9117 S: Odd Fixes 9118 S: Odd Fixes
9118 F: drivers/staging/media/lirc/ 9119 F: drivers/staging/media/lirc/
9119 9120
9120 STAGING - LUSTRE PARALLEL FILESYSTEM 9121 STAGING - LUSTRE PARALLEL FILESYSTEM
9121 M: Oleg Drokin <oleg.drokin@intel.com> 9122 M: Oleg Drokin <oleg.drokin@intel.com>
9122 M: Andreas Dilger <andreas.dilger@intel.com> 9123 M: Andreas Dilger <andreas.dilger@intel.com>
9123 L: HPDD-discuss@lists.01.org (moderated for non-subscribers) 9124 L: HPDD-discuss@lists.01.org (moderated for non-subscribers)
9124 W: http://lustre.opensfs.org/ 9125 W: http://lustre.opensfs.org/
9125 S: Maintained 9126 S: Maintained
9126 F: drivers/staging/lustre 9127 F: drivers/staging/lustre
9127 9128
9128 STAGING - NVIDIA COMPLIANT EMBEDDED CONTROLLER INTERFACE (nvec) 9129 STAGING - NVIDIA COMPLIANT EMBEDDED CONTROLLER INTERFACE (nvec)
9129 M: Julian Andres Klode <jak@jak-linux.org> 9130 M: Julian Andres Klode <jak@jak-linux.org>
9130 M: Marc Dietrich <marvin24@gmx.de> 9131 M: Marc Dietrich <marvin24@gmx.de>
9131 L: ac100@lists.launchpad.net (moderated for non-subscribers) 9132 L: ac100@lists.launchpad.net (moderated for non-subscribers)
9132 L: linux-tegra@vger.kernel.org 9133 L: linux-tegra@vger.kernel.org
9133 S: Maintained 9134 S: Maintained
9134 F: drivers/staging/nvec/ 9135 F: drivers/staging/nvec/
9135 9136
9136 STAGING - OLPC SECONDARY DISPLAY CONTROLLER (DCON) 9137 STAGING - OLPC SECONDARY DISPLAY CONTROLLER (DCON)
9137 M: Jens Frederich <jfrederich@gmail.com> 9138 M: Jens Frederich <jfrederich@gmail.com>
9138 M: Daniel Drake <dsd@laptop.org> 9139 M: Daniel Drake <dsd@laptop.org>
9139 M: Jon Nettleton <jon.nettleton@gmail.com> 9140 M: Jon Nettleton <jon.nettleton@gmail.com>
9140 W: http://wiki.laptop.org/go/DCON 9141 W: http://wiki.laptop.org/go/DCON
9141 S: Maintained 9142 S: Maintained
9142 F: drivers/staging/olpc_dcon/ 9143 F: drivers/staging/olpc_dcon/
9143 9144
9144 STAGING - OZMO DEVICES USB OVER WIFI DRIVER 9145 STAGING - OZMO DEVICES USB OVER WIFI DRIVER
9145 M: Shigekatsu Tateno <shigekatsu.tateno@atmel.com> 9146 M: Shigekatsu Tateno <shigekatsu.tateno@atmel.com>
9146 S: Maintained 9147 S: Maintained
9147 F: drivers/staging/ozwpan/ 9148 F: drivers/staging/ozwpan/
9148 9149
9149 STAGING - PARALLEL LCD/KEYPAD PANEL DRIVER 9150 STAGING - PARALLEL LCD/KEYPAD PANEL DRIVER
9150 M: Willy Tarreau <willy@meta-x.org> 9151 M: Willy Tarreau <willy@meta-x.org>
9151 S: Odd Fixes 9152 S: Odd Fixes
9152 F: drivers/staging/panel/ 9153 F: drivers/staging/panel/
9153 9154
9154 STAGING - REALTEK RTL8712U DRIVERS 9155 STAGING - REALTEK RTL8712U DRIVERS
9155 M: Larry Finger <Larry.Finger@lwfinger.net> 9156 M: Larry Finger <Larry.Finger@lwfinger.net>
9156 M: Florian Schilhabel <florian.c.schilhabel@googlemail.com>. 9157 M: Florian Schilhabel <florian.c.schilhabel@googlemail.com>.
9157 S: Odd Fixes 9158 S: Odd Fixes
9158 F: drivers/staging/rtl8712/ 9159 F: drivers/staging/rtl8712/
9159 9160
9160 STAGING - REALTEK RTL8723U WIRELESS DRIVER 9161 STAGING - REALTEK RTL8723U WIRELESS DRIVER
9161 M: Larry Finger <Larry.Finger@lwfinger.net> 9162 M: Larry Finger <Larry.Finger@lwfinger.net>
9162 M: Jes Sorensen <Jes.Sorensen@redhat.com> 9163 M: Jes Sorensen <Jes.Sorensen@redhat.com>
9163 L: linux-wireless@vger.kernel.org 9164 L: linux-wireless@vger.kernel.org
9164 S: Maintained 9165 S: Maintained
9165 F: drivers/staging/rtl8723au/ 9166 F: drivers/staging/rtl8723au/
9166 9167
9167 STAGING - SLICOSS 9168 STAGING - SLICOSS
9168 M: Lior Dotan <liodot@gmail.com> 9169 M: Lior Dotan <liodot@gmail.com>
9169 M: Christopher Harrer <charrer@alacritech.com> 9170 M: Christopher Harrer <charrer@alacritech.com>
9170 S: Odd Fixes 9171 S: Odd Fixes
9171 F: drivers/staging/slicoss/ 9172 F: drivers/staging/slicoss/
9172 9173
9173 STAGING - SPEAKUP CONSOLE SPEECH DRIVER 9174 STAGING - SPEAKUP CONSOLE SPEECH DRIVER
9174 M: William Hubbs <w.d.hubbs@gmail.com> 9175 M: William Hubbs <w.d.hubbs@gmail.com>
9175 M: Chris Brannon <chris@the-brannons.com> 9176 M: Chris Brannon <chris@the-brannons.com>
9176 M: Kirk Reiser <kirk@reisers.ca> 9177 M: Kirk Reiser <kirk@reisers.ca>
9177 M: Samuel Thibault <samuel.thibault@ens-lyon.org> 9178 M: Samuel Thibault <samuel.thibault@ens-lyon.org>
9178 L: speakup@linux-speakup.org 9179 L: speakup@linux-speakup.org
9179 W: http://www.linux-speakup.org/ 9180 W: http://www.linux-speakup.org/
9180 S: Odd Fixes 9181 S: Odd Fixes
9181 F: drivers/staging/speakup/ 9182 F: drivers/staging/speakup/
9182 9183
9183 STAGING - VIA VT665X DRIVERS 9184 STAGING - VIA VT665X DRIVERS
9184 M: Forest Bond <forest@alittletooquiet.net> 9185 M: Forest Bond <forest@alittletooquiet.net>
9185 S: Odd Fixes 9186 S: Odd Fixes
9186 F: drivers/staging/vt665?/ 9187 F: drivers/staging/vt665?/
9187 9188
9188 STAGING - XGI Z7,Z9,Z11 PCI DISPLAY DRIVER 9189 STAGING - XGI Z7,Z9,Z11 PCI DISPLAY DRIVER
9189 M: Arnaud Patard <arnaud.patard@rtp-net.org> 9190 M: Arnaud Patard <arnaud.patard@rtp-net.org>
9190 S: Odd Fixes 9191 S: Odd Fixes
9191 F: drivers/staging/xgifb/ 9192 F: drivers/staging/xgifb/
9192 9193
9193 STARFIRE/DURALAN NETWORK DRIVER 9194 STARFIRE/DURALAN NETWORK DRIVER
9194 M: Ion Badulescu <ionut@badula.org> 9195 M: Ion Badulescu <ionut@badula.org>
9195 S: Odd Fixes 9196 S: Odd Fixes
9196 F: drivers/net/ethernet/adaptec/starfire* 9197 F: drivers/net/ethernet/adaptec/starfire*
9197 9198
9198 SUN3/3X 9199 SUN3/3X
9199 M: Sam Creasey <sammy@sammy.net> 9200 M: Sam Creasey <sammy@sammy.net>
9200 W: http://sammy.net/sun3/ 9201 W: http://sammy.net/sun3/
9201 S: Maintained 9202 S: Maintained
9202 F: arch/m68k/kernel/*sun3* 9203 F: arch/m68k/kernel/*sun3*
9203 F: arch/m68k/sun3*/ 9204 F: arch/m68k/sun3*/
9204 F: arch/m68k/include/asm/sun3* 9205 F: arch/m68k/include/asm/sun3*
9205 F: drivers/net/ethernet/i825xx/sun3* 9206 F: drivers/net/ethernet/i825xx/sun3*
9206 9207
9207 SUNDANCE NETWORK DRIVER 9208 SUNDANCE NETWORK DRIVER
9208 M: Denis Kirjanov <kda@linux-powerpc.org> 9209 M: Denis Kirjanov <kda@linux-powerpc.org>
9209 L: netdev@vger.kernel.org 9210 L: netdev@vger.kernel.org
9210 S: Maintained 9211 S: Maintained
9211 F: drivers/net/ethernet/dlink/sundance.c 9212 F: drivers/net/ethernet/dlink/sundance.c
9212 9213
9213 SUPERH 9214 SUPERH
9214 L: linux-sh@vger.kernel.org 9215 L: linux-sh@vger.kernel.org
9215 W: http://www.linux-sh.org 9216 W: http://www.linux-sh.org
9216 Q: http://patchwork.kernel.org/project/linux-sh/list/ 9217 Q: http://patchwork.kernel.org/project/linux-sh/list/
9217 S: Orphan 9218 S: Orphan
9218 F: Documentation/sh/ 9219 F: Documentation/sh/
9219 F: arch/sh/ 9220 F: arch/sh/
9220 F: drivers/sh/ 9221 F: drivers/sh/
9221 9222
9222 SUSPEND TO RAM 9223 SUSPEND TO RAM
9223 M: "Rafael J. Wysocki" <rjw@rjwysocki.net> 9224 M: "Rafael J. Wysocki" <rjw@rjwysocki.net>
9224 M: Len Brown <len.brown@intel.com> 9225 M: Len Brown <len.brown@intel.com>
9225 M: Pavel Machek <pavel@ucw.cz> 9226 M: Pavel Machek <pavel@ucw.cz>
9226 L: linux-pm@vger.kernel.org 9227 L: linux-pm@vger.kernel.org
9227 S: Supported 9228 S: Supported
9228 F: Documentation/power/ 9229 F: Documentation/power/
9229 F: arch/x86/kernel/acpi/ 9230 F: arch/x86/kernel/acpi/
9230 F: drivers/base/power/ 9231 F: drivers/base/power/
9231 F: kernel/power/ 9232 F: kernel/power/
9232 F: include/linux/suspend.h 9233 F: include/linux/suspend.h
9233 F: include/linux/freezer.h 9234 F: include/linux/freezer.h
9234 F: include/linux/pm.h 9235 F: include/linux/pm.h
9235 9236
9236 SVGA HANDLING 9237 SVGA HANDLING
9237 M: Martin Mares <mj@ucw.cz> 9238 M: Martin Mares <mj@ucw.cz>
9238 L: linux-video@atrey.karlin.mff.cuni.cz 9239 L: linux-video@atrey.karlin.mff.cuni.cz
9239 S: Maintained 9240 S: Maintained
9240 F: Documentation/svga.txt 9241 F: Documentation/svga.txt
9241 F: arch/x86/boot/video* 9242 F: arch/x86/boot/video*
9242 9243
9243 SWIOTLB SUBSYSTEM 9244 SWIOTLB SUBSYSTEM
9244 M: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> 9245 M: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
9245 L: linux-kernel@vger.kernel.org 9246 L: linux-kernel@vger.kernel.org
9246 S: Supported 9247 S: Supported
9247 F: lib/swiotlb.c 9248 F: lib/swiotlb.c
9248 F: arch/*/kernel/pci-swiotlb.c 9249 F: arch/*/kernel/pci-swiotlb.c
9249 F: include/linux/swiotlb.h 9250 F: include/linux/swiotlb.h
9250 9251
9251 SWITCHDEV 9252 SWITCHDEV
9252 M: Jiri Pirko <jiri@resnulli.us> 9253 M: Jiri Pirko <jiri@resnulli.us>
9253 L: netdev@vger.kernel.org 9254 L: netdev@vger.kernel.org
9254 S: Supported 9255 S: Supported
9255 F: net/switchdev/ 9256 F: net/switchdev/
9256 F: include/net/switchdev.h 9257 F: include/net/switchdev.h
9257 9258
9258 SYNOPSYS ARC ARCHITECTURE 9259 SYNOPSYS ARC ARCHITECTURE
9259 M: Vineet Gupta <vgupta@synopsys.com> 9260 M: Vineet Gupta <vgupta@synopsys.com>
9260 S: Supported 9261 S: Supported
9261 F: arch/arc/ 9262 F: arch/arc/
9262 F: Documentation/devicetree/bindings/arc/ 9263 F: Documentation/devicetree/bindings/arc/
9263 F: drivers/tty/serial/arc_uart.c 9264 F: drivers/tty/serial/arc_uart.c
9264 9265
9265 SYSV FILESYSTEM 9266 SYSV FILESYSTEM
9266 M: Christoph Hellwig <hch@infradead.org> 9267 M: Christoph Hellwig <hch@infradead.org>
9267 S: Maintained 9268 S: Maintained
9268 F: Documentation/filesystems/sysv-fs.txt 9269 F: Documentation/filesystems/sysv-fs.txt
9269 F: fs/sysv/ 9270 F: fs/sysv/
9270 F: include/linux/sysv_fs.h 9271 F: include/linux/sysv_fs.h
9271 9272
9272 TARGET SUBSYSTEM 9273 TARGET SUBSYSTEM
9273 M: Nicholas A. Bellinger <nab@linux-iscsi.org> 9274 M: Nicholas A. Bellinger <nab@linux-iscsi.org>
9274 L: linux-scsi@vger.kernel.org 9275 L: linux-scsi@vger.kernel.org
9275 L: target-devel@vger.kernel.org 9276 L: target-devel@vger.kernel.org
9276 W: http://www.linux-iscsi.org 9277 W: http://www.linux-iscsi.org
9277 W: http://groups.google.com/group/linux-iscsi-target-dev 9278 W: http://groups.google.com/group/linux-iscsi-target-dev
9278 T: git git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending.git master 9279 T: git git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending.git master
9279 S: Supported 9280 S: Supported
9280 F: drivers/target/ 9281 F: drivers/target/
9281 F: include/target/ 9282 F: include/target/
9282 F: Documentation/target/ 9283 F: Documentation/target/
9283 9284
9284 TASKSTATS STATISTICS INTERFACE 9285 TASKSTATS STATISTICS INTERFACE
9285 M: Balbir Singh <bsingharora@gmail.com> 9286 M: Balbir Singh <bsingharora@gmail.com>
9286 S: Maintained 9287 S: Maintained
9287 F: Documentation/accounting/taskstats* 9288 F: Documentation/accounting/taskstats*
9288 F: include/linux/taskstats* 9289 F: include/linux/taskstats*
9289 F: kernel/taskstats.c 9290 F: kernel/taskstats.c
9290 9291
9291 TC CLASSIFIER 9292 TC CLASSIFIER
9292 M: Jamal Hadi Salim <jhs@mojatatu.com> 9293 M: Jamal Hadi Salim <jhs@mojatatu.com>
9293 L: netdev@vger.kernel.org 9294 L: netdev@vger.kernel.org
9294 S: Maintained 9295 S: Maintained
9295 F: include/net/pkt_cls.h 9296 F: include/net/pkt_cls.h
9296 F: include/uapi/linux/pkt_cls.h 9297 F: include/uapi/linux/pkt_cls.h
9297 F: net/sched/ 9298 F: net/sched/
9298 9299
9299 TCP LOW PRIORITY MODULE 9300 TCP LOW PRIORITY MODULE
9300 M: "Wong Hoi Sing, Edison" <hswong3i@gmail.com> 9301 M: "Wong Hoi Sing, Edison" <hswong3i@gmail.com>
9301 M: "Hung Hing Lun, Mike" <hlhung3i@gmail.com> 9302 M: "Hung Hing Lun, Mike" <hlhung3i@gmail.com>
9302 W: http://tcp-lp-mod.sourceforge.net/ 9303 W: http://tcp-lp-mod.sourceforge.net/
9303 S: Maintained 9304 S: Maintained
9304 F: net/ipv4/tcp_lp.c 9305 F: net/ipv4/tcp_lp.c
9305 9306
9306 TDA10071 MEDIA DRIVER 9307 TDA10071 MEDIA DRIVER
9307 M: Antti Palosaari <crope@iki.fi> 9308 M: Antti Palosaari <crope@iki.fi>
9308 L: linux-media@vger.kernel.org 9309 L: linux-media@vger.kernel.org
9309 W: http://linuxtv.org/ 9310 W: http://linuxtv.org/
9310 W: http://palosaari.fi/linux/ 9311 W: http://palosaari.fi/linux/
9311 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 9312 Q: http://patchwork.linuxtv.org/project/linux-media/list/
9312 T: git git://linuxtv.org/anttip/media_tree.git 9313 T: git git://linuxtv.org/anttip/media_tree.git
9313 S: Maintained 9314 S: Maintained
9314 F: drivers/media/dvb-frontends/tda10071* 9315 F: drivers/media/dvb-frontends/tda10071*
9315 9316
9316 TDA18212 MEDIA DRIVER 9317 TDA18212 MEDIA DRIVER
9317 M: Antti Palosaari <crope@iki.fi> 9318 M: Antti Palosaari <crope@iki.fi>
9318 L: linux-media@vger.kernel.org 9319 L: linux-media@vger.kernel.org
9319 W: http://linuxtv.org/ 9320 W: http://linuxtv.org/
9320 W: http://palosaari.fi/linux/ 9321 W: http://palosaari.fi/linux/
9321 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 9322 Q: http://patchwork.linuxtv.org/project/linux-media/list/
9322 T: git git://linuxtv.org/anttip/media_tree.git 9323 T: git git://linuxtv.org/anttip/media_tree.git
9323 S: Maintained 9324 S: Maintained
9324 F: drivers/media/tuners/tda18212* 9325 F: drivers/media/tuners/tda18212*
9325 9326
9326 TDA18218 MEDIA DRIVER 9327 TDA18218 MEDIA DRIVER
9327 M: Antti Palosaari <crope@iki.fi> 9328 M: Antti Palosaari <crope@iki.fi>
9328 L: linux-media@vger.kernel.org 9329 L: linux-media@vger.kernel.org
9329 W: http://linuxtv.org/ 9330 W: http://linuxtv.org/
9330 W: http://palosaari.fi/linux/ 9331 W: http://palosaari.fi/linux/
9331 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 9332 Q: http://patchwork.linuxtv.org/project/linux-media/list/
9332 T: git git://linuxtv.org/anttip/media_tree.git 9333 T: git git://linuxtv.org/anttip/media_tree.git
9333 S: Maintained 9334 S: Maintained
9334 F: drivers/media/tuners/tda18218* 9335 F: drivers/media/tuners/tda18218*
9335 9336
9336 TDA18271 MEDIA DRIVER 9337 TDA18271 MEDIA DRIVER
9337 M: Michael Krufky <mkrufky@linuxtv.org> 9338 M: Michael Krufky <mkrufky@linuxtv.org>
9338 L: linux-media@vger.kernel.org 9339 L: linux-media@vger.kernel.org
9339 W: http://linuxtv.org/ 9340 W: http://linuxtv.org/
9340 W: http://github.com/mkrufky 9341 W: http://github.com/mkrufky
9341 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 9342 Q: http://patchwork.linuxtv.org/project/linux-media/list/
9342 T: git git://linuxtv.org/mkrufky/tuners.git 9343 T: git git://linuxtv.org/mkrufky/tuners.git
9343 S: Maintained 9344 S: Maintained
9344 F: drivers/media/tuners/tda18271* 9345 F: drivers/media/tuners/tda18271*
9345 9346
9346 TDA827x MEDIA DRIVER 9347 TDA827x MEDIA DRIVER
9347 M: Michael Krufky <mkrufky@linuxtv.org> 9348 M: Michael Krufky <mkrufky@linuxtv.org>
9348 L: linux-media@vger.kernel.org 9349 L: linux-media@vger.kernel.org
9349 W: http://linuxtv.org/ 9350 W: http://linuxtv.org/
9350 W: http://github.com/mkrufky 9351 W: http://github.com/mkrufky
9351 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 9352 Q: http://patchwork.linuxtv.org/project/linux-media/list/
9352 T: git git://linuxtv.org/mkrufky/tuners.git 9353 T: git git://linuxtv.org/mkrufky/tuners.git
9353 S: Maintained 9354 S: Maintained
9354 F: drivers/media/tuners/tda8290.* 9355 F: drivers/media/tuners/tda8290.*
9355 9356
9356 TDA8290 MEDIA DRIVER 9357 TDA8290 MEDIA DRIVER
9357 M: Michael Krufky <mkrufky@linuxtv.org> 9358 M: Michael Krufky <mkrufky@linuxtv.org>
9358 L: linux-media@vger.kernel.org 9359 L: linux-media@vger.kernel.org
9359 W: http://linuxtv.org/ 9360 W: http://linuxtv.org/
9360 W: http://github.com/mkrufky 9361 W: http://github.com/mkrufky
9361 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 9362 Q: http://patchwork.linuxtv.org/project/linux-media/list/
9362 T: git git://linuxtv.org/mkrufky/tuners.git 9363 T: git git://linuxtv.org/mkrufky/tuners.git
9363 S: Maintained 9364 S: Maintained
9364 F: drivers/media/tuners/tda8290.* 9365 F: drivers/media/tuners/tda8290.*
9365 9366
9366 TDA9840 MEDIA DRIVER 9367 TDA9840 MEDIA DRIVER
9367 M: Hans Verkuil <hverkuil@xs4all.nl> 9368 M: Hans Verkuil <hverkuil@xs4all.nl>
9368 L: linux-media@vger.kernel.org 9369 L: linux-media@vger.kernel.org
9369 T: git git://linuxtv.org/media_tree.git 9370 T: git git://linuxtv.org/media_tree.git
9370 W: http://linuxtv.org 9371 W: http://linuxtv.org
9371 S: Maintained 9372 S: Maintained
9372 F: drivers/media/i2c/tda9840* 9373 F: drivers/media/i2c/tda9840*
9373 9374
9374 TEA5761 TUNER DRIVER 9375 TEA5761 TUNER DRIVER
9375 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com> 9376 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
9376 L: linux-media@vger.kernel.org 9377 L: linux-media@vger.kernel.org
9377 W: http://linuxtv.org 9378 W: http://linuxtv.org
9378 T: git git://linuxtv.org/media_tree.git 9379 T: git git://linuxtv.org/media_tree.git
9379 S: Odd fixes 9380 S: Odd fixes
9380 F: drivers/media/tuners/tea5761.* 9381 F: drivers/media/tuners/tea5761.*
9381 9382
9382 TEA5767 TUNER DRIVER 9383 TEA5767 TUNER DRIVER
9383 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com> 9384 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
9384 L: linux-media@vger.kernel.org 9385 L: linux-media@vger.kernel.org
9385 W: http://linuxtv.org 9386 W: http://linuxtv.org
9386 T: git git://linuxtv.org/media_tree.git 9387 T: git git://linuxtv.org/media_tree.git
9387 S: Maintained 9388 S: Maintained
9388 F: drivers/media/tuners/tea5767.* 9389 F: drivers/media/tuners/tea5767.*
9389 9390
9390 TEA6415C MEDIA DRIVER 9391 TEA6415C MEDIA DRIVER
9391 M: Hans Verkuil <hverkuil@xs4all.nl> 9392 M: Hans Verkuil <hverkuil@xs4all.nl>
9392 L: linux-media@vger.kernel.org 9393 L: linux-media@vger.kernel.org
9393 T: git git://linuxtv.org/media_tree.git 9394 T: git git://linuxtv.org/media_tree.git
9394 W: http://linuxtv.org 9395 W: http://linuxtv.org
9395 S: Maintained 9396 S: Maintained
9396 F: drivers/media/i2c/tea6415c* 9397 F: drivers/media/i2c/tea6415c*
9397 9398
9398 TEA6420 MEDIA DRIVER 9399 TEA6420 MEDIA DRIVER
9399 M: Hans Verkuil <hverkuil@xs4all.nl> 9400 M: Hans Verkuil <hverkuil@xs4all.nl>
9400 L: linux-media@vger.kernel.org 9401 L: linux-media@vger.kernel.org
9401 T: git git://linuxtv.org/media_tree.git 9402 T: git git://linuxtv.org/media_tree.git
9402 W: http://linuxtv.org 9403 W: http://linuxtv.org
9403 S: Maintained 9404 S: Maintained
9404 F: drivers/media/i2c/tea6420* 9405 F: drivers/media/i2c/tea6420*
9405 9406
9406 TEAM DRIVER 9407 TEAM DRIVER
9407 M: Jiri Pirko <jiri@resnulli.us> 9408 M: Jiri Pirko <jiri@resnulli.us>
9408 L: netdev@vger.kernel.org 9409 L: netdev@vger.kernel.org
9409 S: Supported 9410 S: Supported
9410 F: drivers/net/team/ 9411 F: drivers/net/team/
9411 F: include/linux/if_team.h 9412 F: include/linux/if_team.h
9412 F: include/uapi/linux/if_team.h 9413 F: include/uapi/linux/if_team.h
9413 9414
9414 TECHNOLOGIC SYSTEMS TS-5500 PLATFORM SUPPORT 9415 TECHNOLOGIC SYSTEMS TS-5500 PLATFORM SUPPORT
9415 M: Savoir-faire Linux Inc. <kernel@savoirfairelinux.com> 9416 M: Savoir-faire Linux Inc. <kernel@savoirfairelinux.com>
9416 S: Maintained 9417 S: Maintained
9417 F: arch/x86/platform/ts5500/ 9418 F: arch/x86/platform/ts5500/
9418 9419
9419 TECHNOTREND USB IR RECEIVER 9420 TECHNOTREND USB IR RECEIVER
9420 M: Sean Young <sean@mess.org> 9421 M: Sean Young <sean@mess.org>
9421 L: linux-media@vger.kernel.org 9422 L: linux-media@vger.kernel.org
9422 S: Maintained 9423 S: Maintained
9423 F: drivers/media/rc/ttusbir.c 9424 F: drivers/media/rc/ttusbir.c
9424 9425
9425 TEGRA ARCHITECTURE SUPPORT 9426 TEGRA ARCHITECTURE SUPPORT
9426 M: Stephen Warren <swarren@wwwdotorg.org> 9427 M: Stephen Warren <swarren@wwwdotorg.org>
9427 M: Thierry Reding <thierry.reding@gmail.com> 9428 M: Thierry Reding <thierry.reding@gmail.com>
9428 M: Alexandre Courbot <gnurou@gmail.com> 9429 M: Alexandre Courbot <gnurou@gmail.com>
9429 L: linux-tegra@vger.kernel.org 9430 L: linux-tegra@vger.kernel.org
9430 Q: http://patchwork.ozlabs.org/project/linux-tegra/list/ 9431 Q: http://patchwork.ozlabs.org/project/linux-tegra/list/
9431 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tegra/linux.git 9432 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tegra/linux.git
9432 S: Supported 9433 S: Supported
9433 N: [^a-z]tegra 9434 N: [^a-z]tegra
9434 9435
9435 TEGRA CLOCK DRIVER 9436 TEGRA CLOCK DRIVER
9436 M: Peter De Schrijver <pdeschrijver@nvidia.com> 9437 M: Peter De Schrijver <pdeschrijver@nvidia.com>
9437 M: Prashant Gaikwad <pgaikwad@nvidia.com> 9438 M: Prashant Gaikwad <pgaikwad@nvidia.com>
9438 S: Supported 9439 S: Supported
9439 F: drivers/clk/tegra/ 9440 F: drivers/clk/tegra/
9440 9441
9441 TEGRA DMA DRIVER 9442 TEGRA DMA DRIVER
9442 M: Laxman Dewangan <ldewangan@nvidia.com> 9443 M: Laxman Dewangan <ldewangan@nvidia.com>
9443 S: Supported 9444 S: Supported
9444 F: drivers/dma/tegra20-apb-dma.c 9445 F: drivers/dma/tegra20-apb-dma.c
9445 9446
9446 TEGRA I2C DRIVER 9447 TEGRA I2C DRIVER
9447 M: Laxman Dewangan <ldewangan@nvidia.com> 9448 M: Laxman Dewangan <ldewangan@nvidia.com>
9448 S: Supported 9449 S: Supported
9449 F: drivers/i2c/busses/i2c-tegra.c 9450 F: drivers/i2c/busses/i2c-tegra.c
9450 9451
9451 TEGRA IOMMU DRIVERS 9452 TEGRA IOMMU DRIVERS
9452 M: Hiroshi Doyu <hdoyu@nvidia.com> 9453 M: Hiroshi Doyu <hdoyu@nvidia.com>
9453 S: Supported 9454 S: Supported
9454 F: drivers/iommu/tegra* 9455 F: drivers/iommu/tegra*
9455 9456
9456 TEGRA KBC DRIVER 9457 TEGRA KBC DRIVER
9457 M: Rakesh Iyer <riyer@nvidia.com> 9458 M: Rakesh Iyer <riyer@nvidia.com>
9458 M: Laxman Dewangan <ldewangan@nvidia.com> 9459 M: Laxman Dewangan <ldewangan@nvidia.com>
9459 S: Supported 9460 S: Supported
9460 F: drivers/input/keyboard/tegra-kbc.c 9461 F: drivers/input/keyboard/tegra-kbc.c
9461 9462
9462 TEGRA PWM DRIVER 9463 TEGRA PWM DRIVER
9463 M: Thierry Reding <thierry.reding@gmail.com> 9464 M: Thierry Reding <thierry.reding@gmail.com>
9464 S: Supported 9465 S: Supported
9465 F: drivers/pwm/pwm-tegra.c 9466 F: drivers/pwm/pwm-tegra.c
9466 9467
9467 TEGRA SERIAL DRIVER 9468 TEGRA SERIAL DRIVER
9468 M: Laxman Dewangan <ldewangan@nvidia.com> 9469 M: Laxman Dewangan <ldewangan@nvidia.com>
9469 S: Supported 9470 S: Supported
9470 F: drivers/tty/serial/serial-tegra.c 9471 F: drivers/tty/serial/serial-tegra.c
9471 9472
9472 TEGRA SPI DRIVER 9473 TEGRA SPI DRIVER
9473 M: Laxman Dewangan <ldewangan@nvidia.com> 9474 M: Laxman Dewangan <ldewangan@nvidia.com>
9474 S: Supported 9475 S: Supported
9475 F: drivers/spi/spi-tegra* 9476 F: drivers/spi/spi-tegra*
9476 9477
9477 TEHUTI ETHERNET DRIVER 9478 TEHUTI ETHERNET DRIVER
9478 M: Andy Gospodarek <andy@greyhouse.net> 9479 M: Andy Gospodarek <andy@greyhouse.net>
9479 L: netdev@vger.kernel.org 9480 L: netdev@vger.kernel.org
9480 S: Supported 9481 S: Supported
9481 F: drivers/net/ethernet/tehuti/* 9482 F: drivers/net/ethernet/tehuti/*
9482 9483
9483 Telecom Clock Driver for MCPL0010 9484 Telecom Clock Driver for MCPL0010
9484 M: Mark Gross <mark.gross@intel.com> 9485 M: Mark Gross <mark.gross@intel.com>
9485 S: Supported 9486 S: Supported
9486 F: drivers/char/tlclk.c 9487 F: drivers/char/tlclk.c
9487 9488
9488 TENSILICA XTENSA PORT (xtensa) 9489 TENSILICA XTENSA PORT (xtensa)
9489 M: Chris Zankel <chris@zankel.net> 9490 M: Chris Zankel <chris@zankel.net>
9490 M: Max Filippov <jcmvbkbc@gmail.com> 9491 M: Max Filippov <jcmvbkbc@gmail.com>
9491 L: linux-xtensa@linux-xtensa.org 9492 L: linux-xtensa@linux-xtensa.org
9492 S: Maintained 9493 S: Maintained
9493 F: arch/xtensa/ 9494 F: arch/xtensa/
9494 F: drivers/irqchip/irq-xtensa-* 9495 F: drivers/irqchip/irq-xtensa-*
9495 9496
9496 THANKO'S RAREMONO AM/FM/SW RADIO RECEIVER USB DRIVER 9497 THANKO'S RAREMONO AM/FM/SW RADIO RECEIVER USB DRIVER
9497 M: Hans Verkuil <hverkuil@xs4all.nl> 9498 M: Hans Verkuil <hverkuil@xs4all.nl>
9498 L: linux-media@vger.kernel.org 9499 L: linux-media@vger.kernel.org
9499 T: git git://linuxtv.org/media_tree.git 9500 T: git git://linuxtv.org/media_tree.git
9500 W: http://linuxtv.org 9501 W: http://linuxtv.org
9501 S: Maintained 9502 S: Maintained
9502 F: drivers/media/radio/radio-raremono.c 9503 F: drivers/media/radio/radio-raremono.c
9503 9504
9504 THERMAL 9505 THERMAL
9505 M: Zhang Rui <rui.zhang@intel.com> 9506 M: Zhang Rui <rui.zhang@intel.com>
9506 M: Eduardo Valentin <edubezval@gmail.com> 9507 M: Eduardo Valentin <edubezval@gmail.com>
9507 L: linux-pm@vger.kernel.org 9508 L: linux-pm@vger.kernel.org
9508 T: git git://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux.git 9509 T: git git://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux.git
9509 T: git git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal.git 9510 T: git git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal.git
9510 Q: https://patchwork.kernel.org/project/linux-pm/list/ 9511 Q: https://patchwork.kernel.org/project/linux-pm/list/
9511 S: Supported 9512 S: Supported
9512 F: drivers/thermal/ 9513 F: drivers/thermal/
9513 F: include/linux/thermal.h 9514 F: include/linux/thermal.h
9514 F: include/uapi/linux/thermal.h 9515 F: include/uapi/linux/thermal.h
9515 F: include/linux/cpu_cooling.h 9516 F: include/linux/cpu_cooling.h
9516 F: Documentation/devicetree/bindings/thermal/ 9517 F: Documentation/devicetree/bindings/thermal/
9517 9518
9518 THINGM BLINK(1) USB RGB LED DRIVER 9519 THINGM BLINK(1) USB RGB LED DRIVER
9519 M: Vivien Didelot <vivien.didelot@savoirfairelinux.com> 9520 M: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
9520 S: Maintained 9521 S: Maintained
9521 F: drivers/hid/hid-thingm.c 9522 F: drivers/hid/hid-thingm.c
9522 9523
9523 THINKPAD ACPI EXTRAS DRIVER 9524 THINKPAD ACPI EXTRAS DRIVER
9524 M: Henrique de Moraes Holschuh <ibm-acpi@hmh.eng.br> 9525 M: Henrique de Moraes Holschuh <ibm-acpi@hmh.eng.br>
9525 L: ibm-acpi-devel@lists.sourceforge.net 9526 L: ibm-acpi-devel@lists.sourceforge.net
9526 L: platform-driver-x86@vger.kernel.org 9527 L: platform-driver-x86@vger.kernel.org
9527 W: http://ibm-acpi.sourceforge.net 9528 W: http://ibm-acpi.sourceforge.net
9528 W: http://thinkwiki.org/wiki/Ibm-acpi 9529 W: http://thinkwiki.org/wiki/Ibm-acpi
9529 T: git git://repo.or.cz/linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git 9530 T: git git://repo.or.cz/linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git
9530 S: Maintained 9531 S: Maintained
9531 F: drivers/platform/x86/thinkpad_acpi.c 9532 F: drivers/platform/x86/thinkpad_acpi.c
9532 9533
9533 TI BANDGAP AND THERMAL DRIVER 9534 TI BANDGAP AND THERMAL DRIVER
9534 M: Eduardo Valentin <edubezval@gmail.com> 9535 M: Eduardo Valentin <edubezval@gmail.com>
9535 L: linux-pm@vger.kernel.org 9536 L: linux-pm@vger.kernel.org
9536 S: Supported 9537 S: Supported
9537 F: drivers/thermal/ti-soc-thermal/ 9538 F: drivers/thermal/ti-soc-thermal/
9538 9539
9539 TI CLOCK DRIVER 9540 TI CLOCK DRIVER
9540 M: Tero Kristo <t-kristo@ti.com> 9541 M: Tero Kristo <t-kristo@ti.com>
9541 L: linux-omap@vger.kernel.org 9542 L: linux-omap@vger.kernel.org
9542 S: Maintained 9543 S: Maintained
9543 F: drivers/clk/ti/ 9544 F: drivers/clk/ti/
9544 F: include/linux/clk/ti.h 9545 F: include/linux/clk/ti.h
9545 9546
9546 TI FLASH MEDIA INTERFACE DRIVER 9547 TI FLASH MEDIA INTERFACE DRIVER
9547 M: Alex Dubov <oakad@yahoo.com> 9548 M: Alex Dubov <oakad@yahoo.com>
9548 S: Maintained 9549 S: Maintained
9549 F: drivers/misc/tifm* 9550 F: drivers/misc/tifm*
9550 F: drivers/mmc/host/tifm_sd.c 9551 F: drivers/mmc/host/tifm_sd.c
9551 F: include/linux/tifm.h 9552 F: include/linux/tifm.h
9552 9553
9553 TI KEYSTONE MULTICORE NAVIGATOR DRIVERS 9554 TI KEYSTONE MULTICORE NAVIGATOR DRIVERS
9554 M: Santosh Shilimkar <ssantosh@kernel.org> 9555 M: Santosh Shilimkar <ssantosh@kernel.org>
9555 L: linux-kernel@vger.kernel.org 9556 L: linux-kernel@vger.kernel.org
9556 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 9557 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
9557 S: Maintained 9558 S: Maintained
9558 F: drivers/soc/ti/* 9559 F: drivers/soc/ti/*
9559 T: git git://git.kernel.org/pub/scm/linux/kernel/git/ssantosh/linux-keystone.git 9560 T: git git://git.kernel.org/pub/scm/linux/kernel/git/ssantosh/linux-keystone.git
9560 9561
9561 9562
9562 TI LM49xxx FAMILY ASoC CODEC DRIVERS 9563 TI LM49xxx FAMILY ASoC CODEC DRIVERS
9563 M: M R Swami Reddy <mr.swami.reddy@ti.com> 9564 M: M R Swami Reddy <mr.swami.reddy@ti.com>
9564 M: Vishwas A Deshpande <vishwas.a.deshpande@ti.com> 9565 M: Vishwas A Deshpande <vishwas.a.deshpande@ti.com>
9565 L: alsa-devel@alsa-project.org (moderated for non-subscribers) 9566 L: alsa-devel@alsa-project.org (moderated for non-subscribers)
9566 S: Maintained 9567 S: Maintained
9567 F: sound/soc/codecs/lm49453* 9568 F: sound/soc/codecs/lm49453*
9568 F: sound/soc/codecs/isabelle* 9569 F: sound/soc/codecs/isabelle*
9569 9570
9570 TI LP855x BACKLIGHT DRIVER 9571 TI LP855x BACKLIGHT DRIVER
9571 M: Milo Kim <milo.kim@ti.com> 9572 M: Milo Kim <milo.kim@ti.com>
9572 S: Maintained 9573 S: Maintained
9573 F: Documentation/backlight/lp855x-driver.txt 9574 F: Documentation/backlight/lp855x-driver.txt
9574 F: drivers/video/backlight/lp855x_bl.c 9575 F: drivers/video/backlight/lp855x_bl.c
9575 F: include/linux/platform_data/lp855x.h 9576 F: include/linux/platform_data/lp855x.h
9576 9577
9577 TI LP8727 CHARGER DRIVER 9578 TI LP8727 CHARGER DRIVER
9578 M: Milo Kim <milo.kim@ti.com> 9579 M: Milo Kim <milo.kim@ti.com>
9579 S: Maintained 9580 S: Maintained
9580 F: drivers/power/lp8727_charger.c 9581 F: drivers/power/lp8727_charger.c
9581 F: include/linux/platform_data/lp8727.h 9582 F: include/linux/platform_data/lp8727.h
9582 9583
9583 TI LP8788 MFD DRIVER 9584 TI LP8788 MFD DRIVER
9584 M: Milo Kim <milo.kim@ti.com> 9585 M: Milo Kim <milo.kim@ti.com>
9585 S: Maintained 9586 S: Maintained
9586 F: drivers/iio/adc/lp8788_adc.c 9587 F: drivers/iio/adc/lp8788_adc.c
9587 F: drivers/leds/leds-lp8788.c 9588 F: drivers/leds/leds-lp8788.c
9588 F: drivers/mfd/lp8788*.c 9589 F: drivers/mfd/lp8788*.c
9589 F: drivers/power/lp8788-charger.c 9590 F: drivers/power/lp8788-charger.c
9590 F: drivers/regulator/lp8788-*.c 9591 F: drivers/regulator/lp8788-*.c
9591 F: include/linux/mfd/lp8788*.h 9592 F: include/linux/mfd/lp8788*.h
9592 9593
9593 TI TWL4030 SERIES SOC CODEC DRIVER 9594 TI TWL4030 SERIES SOC CODEC DRIVER
9594 M: Peter Ujfalusi <peter.ujfalusi@ti.com> 9595 M: Peter Ujfalusi <peter.ujfalusi@ti.com>
9595 L: alsa-devel@alsa-project.org (moderated for non-subscribers) 9596 L: alsa-devel@alsa-project.org (moderated for non-subscribers)
9596 S: Maintained 9597 S: Maintained
9597 F: sound/soc/codecs/twl4030* 9598 F: sound/soc/codecs/twl4030*
9598 9599
9599 TI WILINK WIRELESS DRIVERS 9600 TI WILINK WIRELESS DRIVERS
9600 L: linux-wireless@vger.kernel.org 9601 L: linux-wireless@vger.kernel.org
9601 W: http://wireless.kernel.org/en/users/Drivers/wl12xx 9602 W: http://wireless.kernel.org/en/users/Drivers/wl12xx
9602 W: http://wireless.kernel.org/en/users/Drivers/wl1251 9603 W: http://wireless.kernel.org/en/users/Drivers/wl1251
9603 T: git git://git.kernel.org/pub/scm/linux/kernel/git/luca/wl12xx.git 9604 T: git git://git.kernel.org/pub/scm/linux/kernel/git/luca/wl12xx.git
9604 S: Orphan 9605 S: Orphan
9605 F: drivers/net/wireless/ti/ 9606 F: drivers/net/wireless/ti/
9606 F: include/linux/wl12xx.h 9607 F: include/linux/wl12xx.h
9607 9608
9608 TIPC NETWORK LAYER 9609 TIPC NETWORK LAYER
9609 M: Jon Maloy <jon.maloy@ericsson.com> 9610 M: Jon Maloy <jon.maloy@ericsson.com>
9610 M: Allan Stephens <allan.stephens@windriver.com> 9611 M: Allan Stephens <allan.stephens@windriver.com>
9611 L: netdev@vger.kernel.org (core kernel code) 9612 L: netdev@vger.kernel.org (core kernel code)
9612 L: tipc-discussion@lists.sourceforge.net (user apps, general discussion) 9613 L: tipc-discussion@lists.sourceforge.net (user apps, general discussion)
9613 W: http://tipc.sourceforge.net/ 9614 W: http://tipc.sourceforge.net/
9614 S: Maintained 9615 S: Maintained
9615 F: include/uapi/linux/tipc*.h 9616 F: include/uapi/linux/tipc*.h
9616 F: net/tipc/ 9617 F: net/tipc/
9617 9618
9618 TILE ARCHITECTURE 9619 TILE ARCHITECTURE
9619 M: Chris Metcalf <cmetcalf@ezchip.com> 9620 M: Chris Metcalf <cmetcalf@ezchip.com>
9620 W: http://www.tilera.com/scm/ 9621 W: http://www.tilera.com/scm/
9621 S: Supported 9622 S: Supported
9622 F: arch/tile/ 9623 F: arch/tile/
9623 F: drivers/char/tile-srom.c 9624 F: drivers/char/tile-srom.c
9624 F: drivers/edac/tile_edac.c 9625 F: drivers/edac/tile_edac.c
9625 F: drivers/net/ethernet/tile/ 9626 F: drivers/net/ethernet/tile/
9626 F: drivers/rtc/rtc-tile.c 9627 F: drivers/rtc/rtc-tile.c
9627 F: drivers/tty/hvc/hvc_tile.c 9628 F: drivers/tty/hvc/hvc_tile.c
9628 F: drivers/tty/serial/tilegx.c 9629 F: drivers/tty/serial/tilegx.c
9629 F: drivers/usb/host/*-tilegx.c 9630 F: drivers/usb/host/*-tilegx.c
9630 F: include/linux/usb/tilegx.h 9631 F: include/linux/usb/tilegx.h
9631 9632
9632 TLAN NETWORK DRIVER 9633 TLAN NETWORK DRIVER
9633 M: Samuel Chessman <chessman@tux.org> 9634 M: Samuel Chessman <chessman@tux.org>
9634 L: tlan-devel@lists.sourceforge.net (subscribers-only) 9635 L: tlan-devel@lists.sourceforge.net (subscribers-only)
9635 W: http://sourceforge.net/projects/tlan/ 9636 W: http://sourceforge.net/projects/tlan/
9636 S: Maintained 9637 S: Maintained
9637 F: Documentation/networking/tlan.txt 9638 F: Documentation/networking/tlan.txt
9638 F: drivers/net/ethernet/ti/tlan.* 9639 F: drivers/net/ethernet/ti/tlan.*
9639 9640
9640 TOMOYO SECURITY MODULE 9641 TOMOYO SECURITY MODULE
9641 M: Kentaro Takeda <takedakn@nttdata.co.jp> 9642 M: Kentaro Takeda <takedakn@nttdata.co.jp>
9642 M: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> 9643 M: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
9643 L: tomoyo-dev-en@lists.sourceforge.jp (subscribers-only, for developers in English) 9644 L: tomoyo-dev-en@lists.sourceforge.jp (subscribers-only, for developers in English)
9644 L: tomoyo-users-en@lists.sourceforge.jp (subscribers-only, for users in English) 9645 L: tomoyo-users-en@lists.sourceforge.jp (subscribers-only, for users in English)
9645 L: tomoyo-dev@lists.sourceforge.jp (subscribers-only, for developers in Japanese) 9646 L: tomoyo-dev@lists.sourceforge.jp (subscribers-only, for developers in Japanese)
9646 L: tomoyo-users@lists.sourceforge.jp (subscribers-only, for users in Japanese) 9647 L: tomoyo-users@lists.sourceforge.jp (subscribers-only, for users in Japanese)
9647 W: http://tomoyo.sourceforge.jp/ 9648 W: http://tomoyo.sourceforge.jp/
9648 T: quilt http://svn.sourceforge.jp/svnroot/tomoyo/trunk/2.5.x/tomoyo-lsm/patches/ 9649 T: quilt http://svn.sourceforge.jp/svnroot/tomoyo/trunk/2.5.x/tomoyo-lsm/patches/
9649 S: Maintained 9650 S: Maintained
9650 F: security/tomoyo/ 9651 F: security/tomoyo/
9651 9652
9652 TOPSTAR LAPTOP EXTRAS DRIVER 9653 TOPSTAR LAPTOP EXTRAS DRIVER
9653 M: Herton Ronaldo Krzesinski <herton@canonical.com> 9654 M: Herton Ronaldo Krzesinski <herton@canonical.com>
9654 L: platform-driver-x86@vger.kernel.org 9655 L: platform-driver-x86@vger.kernel.org
9655 S: Maintained 9656 S: Maintained
9656 F: drivers/platform/x86/topstar-laptop.c 9657 F: drivers/platform/x86/topstar-laptop.c
9657 9658
9658 TOSHIBA ACPI EXTRAS DRIVER 9659 TOSHIBA ACPI EXTRAS DRIVER
9659 L: platform-driver-x86@vger.kernel.org 9660 L: platform-driver-x86@vger.kernel.org
9660 S: Orphan 9661 S: Orphan
9661 F: drivers/platform/x86/toshiba_acpi.c 9662 F: drivers/platform/x86/toshiba_acpi.c
9662 9663
9663 TOSHIBA SMM DRIVER 9664 TOSHIBA SMM DRIVER
9664 M: Jonathan Buzzard <jonathan@buzzard.org.uk> 9665 M: Jonathan Buzzard <jonathan@buzzard.org.uk>
9665 L: tlinux-users@tce.toshiba-dme.co.jp 9666 L: tlinux-users@tce.toshiba-dme.co.jp
9666 W: http://www.buzzard.org.uk/toshiba/ 9667 W: http://www.buzzard.org.uk/toshiba/
9667 S: Maintained 9668 S: Maintained
9668 F: drivers/char/toshiba.c 9669 F: drivers/char/toshiba.c
9669 F: include/linux/toshiba.h 9670 F: include/linux/toshiba.h
9670 F: include/uapi/linux/toshiba.h 9671 F: include/uapi/linux/toshiba.h
9671 9672
9672 TMIO MMC DRIVER 9673 TMIO MMC DRIVER
9673 M: Ian Molton <ian.molton@codethink.co.uk> 9674 M: Ian Molton <ian.molton@codethink.co.uk>
9674 L: linux-mmc@vger.kernel.org 9675 L: linux-mmc@vger.kernel.org
9675 S: Maintained 9676 S: Maintained
9676 F: drivers/mmc/host/tmio_mmc* 9677 F: drivers/mmc/host/tmio_mmc*
9677 F: drivers/mmc/host/sh_mobile_sdhi.c 9678 F: drivers/mmc/host/sh_mobile_sdhi.c
9678 F: include/linux/mmc/tmio.h 9679 F: include/linux/mmc/tmio.h
9679 F: include/linux/mmc/sh_mobile_sdhi.h 9680 F: include/linux/mmc/sh_mobile_sdhi.h
9680 9681
9681 TMP401 HARDWARE MONITOR DRIVER 9682 TMP401 HARDWARE MONITOR DRIVER
9682 M: Guenter Roeck <linux@roeck-us.net> 9683 M: Guenter Roeck <linux@roeck-us.net>
9683 L: lm-sensors@lm-sensors.org 9684 L: lm-sensors@lm-sensors.org
9684 S: Maintained 9685 S: Maintained
9685 F: Documentation/hwmon/tmp401 9686 F: Documentation/hwmon/tmp401
9686 F: drivers/hwmon/tmp401.c 9687 F: drivers/hwmon/tmp401.c
9687 9688
9688 TMPFS (SHMEM FILESYSTEM) 9689 TMPFS (SHMEM FILESYSTEM)
9689 M: Hugh Dickins <hughd@google.com> 9690 M: Hugh Dickins <hughd@google.com>
9690 L: linux-mm@kvack.org 9691 L: linux-mm@kvack.org
9691 S: Maintained 9692 S: Maintained
9692 F: include/linux/shmem_fs.h 9693 F: include/linux/shmem_fs.h
9693 F: mm/shmem.c 9694 F: mm/shmem.c
9694 9695
9695 TM6000 VIDEO4LINUX DRIVER 9696 TM6000 VIDEO4LINUX DRIVER
9696 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com> 9697 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
9697 L: linux-media@vger.kernel.org 9698 L: linux-media@vger.kernel.org
9698 W: http://linuxtv.org 9699 W: http://linuxtv.org
9699 T: git git://linuxtv.org/media_tree.git 9700 T: git git://linuxtv.org/media_tree.git
9700 S: Odd fixes 9701 S: Odd fixes
9701 F: drivers/media/usb/tm6000/ 9702 F: drivers/media/usb/tm6000/
9702 9703
9703 TW68 VIDEO4LINUX DRIVER 9704 TW68 VIDEO4LINUX DRIVER
9704 M: Hans Verkuil <hverkuil@xs4all.nl> 9705 M: Hans Verkuil <hverkuil@xs4all.nl>
9705 L: linux-media@vger.kernel.org 9706 L: linux-media@vger.kernel.org
9706 T: git git://linuxtv.org/media_tree.git 9707 T: git git://linuxtv.org/media_tree.git
9707 W: http://linuxtv.org 9708 W: http://linuxtv.org
9708 S: Odd Fixes 9709 S: Odd Fixes
9709 F: drivers/media/pci/tw68/ 9710 F: drivers/media/pci/tw68/
9710 9711
9711 TPM DEVICE DRIVER 9712 TPM DEVICE DRIVER
9712 M: Peter Huewe <peterhuewe@gmx.de> 9713 M: Peter Huewe <peterhuewe@gmx.de>
9713 M: Ashley Lai <ashley@ashleylai.com> 9714 M: Ashley Lai <ashley@ashleylai.com>
9714 M: Marcel Selhorst <tpmdd@selhorst.net> 9715 M: Marcel Selhorst <tpmdd@selhorst.net>
9715 W: http://tpmdd.sourceforge.net 9716 W: http://tpmdd.sourceforge.net
9716 L: tpmdd-devel@lists.sourceforge.net (moderated for non-subscribers) 9717 L: tpmdd-devel@lists.sourceforge.net (moderated for non-subscribers)
9717 S: Maintained 9718 S: Maintained
9718 F: drivers/char/tpm/ 9719 F: drivers/char/tpm/
9719 9720
9720 TRACING 9721 TRACING
9721 M: Steven Rostedt <rostedt@goodmis.org> 9722 M: Steven Rostedt <rostedt@goodmis.org>
9722 M: Ingo Molnar <mingo@redhat.com> 9723 M: Ingo Molnar <mingo@redhat.com>
9723 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git perf/core 9724 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git perf/core
9724 S: Maintained 9725 S: Maintained
9725 F: Documentation/trace/ftrace.txt 9726 F: Documentation/trace/ftrace.txt
9726 F: arch/*/*/*/ftrace.h 9727 F: arch/*/*/*/ftrace.h
9727 F: arch/*/kernel/ftrace.c 9728 F: arch/*/kernel/ftrace.c
9728 F: include/*/ftrace.h 9729 F: include/*/ftrace.h
9729 F: include/linux/trace*.h 9730 F: include/linux/trace*.h
9730 F: include/trace/ 9731 F: include/trace/
9731 F: kernel/trace/ 9732 F: kernel/trace/
9732 F: tools/testing/selftests/ftrace/ 9733 F: tools/testing/selftests/ftrace/
9733 9734
9734 TRIVIAL PATCHES 9735 TRIVIAL PATCHES
9735 M: Jiri Kosina <trivial@kernel.org> 9736 M: Jiri Kosina <trivial@kernel.org>
9736 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jikos/trivial.git 9737 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jikos/trivial.git
9737 S: Maintained 9738 S: Maintained
9738 K: ^Subject:.*(?i)trivial 9739 K: ^Subject:.*(?i)trivial
9739 9740
9740 TTY LAYER 9741 TTY LAYER
9741 M: Greg Kroah-Hartman <gregkh@linuxfoundation.org> 9742 M: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9742 M: Jiri Slaby <jslaby@suse.cz> 9743 M: Jiri Slaby <jslaby@suse.cz>
9743 S: Supported 9744 S: Supported
9744 T: git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git 9745 T: git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git
9745 F: drivers/tty/ 9746 F: drivers/tty/
9746 F: drivers/tty/serial/serial_core.c 9747 F: drivers/tty/serial/serial_core.c
9747 F: include/linux/serial_core.h 9748 F: include/linux/serial_core.h
9748 F: include/linux/serial.h 9749 F: include/linux/serial.h
9749 F: include/linux/tty.h 9750 F: include/linux/tty.h
9750 F: include/uapi/linux/serial_core.h 9751 F: include/uapi/linux/serial_core.h
9751 F: include/uapi/linux/serial.h 9752 F: include/uapi/linux/serial.h
9752 F: include/uapi/linux/tty.h 9753 F: include/uapi/linux/tty.h
9753 9754
9754 TUA9001 MEDIA DRIVER 9755 TUA9001 MEDIA DRIVER
9755 M: Antti Palosaari <crope@iki.fi> 9756 M: Antti Palosaari <crope@iki.fi>
9756 L: linux-media@vger.kernel.org 9757 L: linux-media@vger.kernel.org
9757 W: http://linuxtv.org/ 9758 W: http://linuxtv.org/
9758 W: http://palosaari.fi/linux/ 9759 W: http://palosaari.fi/linux/
9759 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 9760 Q: http://patchwork.linuxtv.org/project/linux-media/list/
9760 T: git git://linuxtv.org/anttip/media_tree.git 9761 T: git git://linuxtv.org/anttip/media_tree.git
9761 S: Maintained 9762 S: Maintained
9762 F: drivers/media/tuners/tua9001* 9763 F: drivers/media/tuners/tua9001*
9763 9764
9764 TULIP NETWORK DRIVERS 9765 TULIP NETWORK DRIVERS
9765 M: Grant Grundler <grundler@parisc-linux.org> 9766 M: Grant Grundler <grundler@parisc-linux.org>
9766 L: netdev@vger.kernel.org 9767 L: netdev@vger.kernel.org
9767 S: Maintained 9768 S: Maintained
9768 F: drivers/net/ethernet/dec/tulip/ 9769 F: drivers/net/ethernet/dec/tulip/
9769 9770
9770 TUN/TAP driver 9771 TUN/TAP driver
9771 M: Maxim Krasnyansky <maxk@qti.qualcomm.com> 9772 M: Maxim Krasnyansky <maxk@qti.qualcomm.com>
9772 W: http://vtun.sourceforge.net/tun 9773 W: http://vtun.sourceforge.net/tun
9773 S: Maintained 9774 S: Maintained
9774 F: Documentation/networking/tuntap.txt 9775 F: Documentation/networking/tuntap.txt
9775 F: arch/um/os-Linux/drivers/ 9776 F: arch/um/os-Linux/drivers/
9776 9777
9777 TURBOCHANNEL SUBSYSTEM 9778 TURBOCHANNEL SUBSYSTEM
9778 M: "Maciej W. Rozycki" <macro@linux-mips.org> 9779 M: "Maciej W. Rozycki" <macro@linux-mips.org>
9779 M: Ralf Baechle <ralf@linux-mips.org> 9780 M: Ralf Baechle <ralf@linux-mips.org>
9780 L: linux-mips@linux-mips.org 9781 L: linux-mips@linux-mips.org
9781 Q: http://patchwork.linux-mips.org/project/linux-mips/list/ 9782 Q: http://patchwork.linux-mips.org/project/linux-mips/list/
9782 S: Maintained 9783 S: Maintained
9783 F: drivers/tc/ 9784 F: drivers/tc/
9784 F: include/linux/tc.h 9785 F: include/linux/tc.h
9785 9786
9786 U14-34F SCSI DRIVER 9787 U14-34F SCSI DRIVER
9787 M: Dario Ballabio <ballabio_dario@emc.com> 9788 M: Dario Ballabio <ballabio_dario@emc.com>
9788 L: linux-scsi@vger.kernel.org 9789 L: linux-scsi@vger.kernel.org
9789 S: Maintained 9790 S: Maintained
9790 F: drivers/scsi/u14-34f.c 9791 F: drivers/scsi/u14-34f.c
9791 9792
9792 UBI FILE SYSTEM (UBIFS) 9793 UBI FILE SYSTEM (UBIFS)
9793 M: Artem Bityutskiy <dedekind1@gmail.com> 9794 M: Artem Bityutskiy <dedekind1@gmail.com>
9794 M: Adrian Hunter <adrian.hunter@intel.com> 9795 M: Adrian Hunter <adrian.hunter@intel.com>
9795 L: linux-mtd@lists.infradead.org 9796 L: linux-mtd@lists.infradead.org
9796 T: git git://git.infradead.org/ubifs-2.6.git 9797 T: git git://git.infradead.org/ubifs-2.6.git
9797 W: http://www.linux-mtd.infradead.org/doc/ubifs.html 9798 W: http://www.linux-mtd.infradead.org/doc/ubifs.html
9798 S: Maintained 9799 S: Maintained
9799 F: Documentation/filesystems/ubifs.txt 9800 F: Documentation/filesystems/ubifs.txt
9800 F: fs/ubifs/ 9801 F: fs/ubifs/
9801 9802
9802 UCLINUX (AND M68KNOMMU) 9803 UCLINUX (AND M68KNOMMU)
9803 M: Greg Ungerer <gerg@uclinux.org> 9804 M: Greg Ungerer <gerg@uclinux.org>
9804 W: http://www.uclinux.org/ 9805 W: http://www.uclinux.org/
9805 L: uclinux-dev@uclinux.org (subscribers-only) 9806 L: uclinux-dev@uclinux.org (subscribers-only)
9806 S: Maintained 9807 S: Maintained
9807 F: arch/m68k/*/*_no.* 9808 F: arch/m68k/*/*_no.*
9808 F: arch/m68k/include/asm/*_no.* 9809 F: arch/m68k/include/asm/*_no.*
9809 9810
9810 UDF FILESYSTEM 9811 UDF FILESYSTEM
9811 M: Jan Kara <jack@suse.cz> 9812 M: Jan Kara <jack@suse.cz>
9812 S: Maintained 9813 S: Maintained
9813 F: Documentation/filesystems/udf.txt 9814 F: Documentation/filesystems/udf.txt
9814 F: fs/udf/ 9815 F: fs/udf/
9815 9816
9816 UFS FILESYSTEM 9817 UFS FILESYSTEM
9817 M: Evgeniy Dushistov <dushistov@mail.ru> 9818 M: Evgeniy Dushistov <dushistov@mail.ru>
9818 S: Maintained 9819 S: Maintained
9819 F: Documentation/filesystems/ufs.txt 9820 F: Documentation/filesystems/ufs.txt
9820 F: fs/ufs/ 9821 F: fs/ufs/
9821 9822
9822 UHID USERSPACE HID IO DRIVER: 9823 UHID USERSPACE HID IO DRIVER:
9823 M: David Herrmann <dh.herrmann@googlemail.com> 9824 M: David Herrmann <dh.herrmann@googlemail.com>
9824 L: linux-input@vger.kernel.org 9825 L: linux-input@vger.kernel.org
9825 S: Maintained 9826 S: Maintained
9826 F: drivers/hid/uhid.c 9827 F: drivers/hid/uhid.c
9827 F: include/uapi/linux/uhid.h 9828 F: include/uapi/linux/uhid.h
9828 9829
9829 ULTRA-WIDEBAND (UWB) SUBSYSTEM: 9830 ULTRA-WIDEBAND (UWB) SUBSYSTEM:
9830 L: linux-usb@vger.kernel.org 9831 L: linux-usb@vger.kernel.org
9831 S: Orphan 9832 S: Orphan
9832 F: drivers/uwb/ 9833 F: drivers/uwb/
9833 F: include/linux/uwb.h 9834 F: include/linux/uwb.h
9834 F: include/linux/uwb/ 9835 F: include/linux/uwb/
9835 9836
9836 UNICORE32 ARCHITECTURE: 9837 UNICORE32 ARCHITECTURE:
9837 M: Guan Xuetao <gxt@mprc.pku.edu.cn> 9838 M: Guan Xuetao <gxt@mprc.pku.edu.cn>
9838 W: http://mprc.pku.edu.cn/~guanxuetao/linux 9839 W: http://mprc.pku.edu.cn/~guanxuetao/linux
9839 S: Maintained 9840 S: Maintained
9840 T: git git://github.com/gxt/linux.git 9841 T: git git://github.com/gxt/linux.git
9841 F: arch/unicore32/ 9842 F: arch/unicore32/
9842 9843
9843 UNIFDEF 9844 UNIFDEF
9844 M: Tony Finch <dot@dotat.at> 9845 M: Tony Finch <dot@dotat.at>
9845 W: http://dotat.at/prog/unifdef 9846 W: http://dotat.at/prog/unifdef
9846 S: Maintained 9847 S: Maintained
9847 F: scripts/unifdef.c 9848 F: scripts/unifdef.c
9848 9849
9849 UNIFORM CDROM DRIVER 9850 UNIFORM CDROM DRIVER
9850 M: Jens Axboe <axboe@kernel.dk> 9851 M: Jens Axboe <axboe@kernel.dk>
9851 W: http://www.kernel.dk 9852 W: http://www.kernel.dk
9852 S: Maintained 9853 S: Maintained
9853 F: Documentation/cdrom/ 9854 F: Documentation/cdrom/
9854 F: drivers/cdrom/cdrom.c 9855 F: drivers/cdrom/cdrom.c
9855 F: include/linux/cdrom.h 9856 F: include/linux/cdrom.h
9856 F: include/uapi/linux/cdrom.h 9857 F: include/uapi/linux/cdrom.h
9857 9858
9858 UNISYS S-PAR DRIVERS 9859 UNISYS S-PAR DRIVERS
9859 M: Benjamin Romer <benjamin.romer@unisys.com> 9860 M: Benjamin Romer <benjamin.romer@unisys.com>
9860 M: David Kershner <david.kershner@unisys.com> 9861 M: David Kershner <david.kershner@unisys.com>
9861 L: sparmaintainer@unisys.com (Unisys internal) 9862 L: sparmaintainer@unisys.com (Unisys internal)
9862 S: Supported 9863 S: Supported
9863 F: drivers/staging/unisys/ 9864 F: drivers/staging/unisys/
9864 9865
9865 UNIVERSAL FLASH STORAGE HOST CONTROLLER DRIVER 9866 UNIVERSAL FLASH STORAGE HOST CONTROLLER DRIVER
9866 M: Vinayak Holikatti <vinholikatti@gmail.com> 9867 M: Vinayak Holikatti <vinholikatti@gmail.com>
9867 L: linux-scsi@vger.kernel.org 9868 L: linux-scsi@vger.kernel.org
9868 S: Supported 9869 S: Supported
9869 F: Documentation/scsi/ufs.txt 9870 F: Documentation/scsi/ufs.txt
9870 F: drivers/scsi/ufs/ 9871 F: drivers/scsi/ufs/
9871 9872
9872 UNSORTED BLOCK IMAGES (UBI) 9873 UNSORTED BLOCK IMAGES (UBI)
9873 M: Artem Bityutskiy <dedekind1@gmail.com> 9874 M: Artem Bityutskiy <dedekind1@gmail.com>
9874 W: http://www.linux-mtd.infradead.org/ 9875 W: http://www.linux-mtd.infradead.org/
9875 L: linux-mtd@lists.infradead.org 9876 L: linux-mtd@lists.infradead.org
9876 T: git git://git.infradead.org/ubifs-2.6.git 9877 T: git git://git.infradead.org/ubifs-2.6.git
9877 S: Maintained 9878 S: Maintained
9878 F: drivers/mtd/ubi/ 9879 F: drivers/mtd/ubi/
9879 F: include/linux/mtd/ubi.h 9880 F: include/linux/mtd/ubi.h
9880 F: include/uapi/mtd/ubi-user.h 9881 F: include/uapi/mtd/ubi-user.h
9881 9882
9882 UNSORTED BLOCK IMAGES (UBI) Fastmap 9883 UNSORTED BLOCK IMAGES (UBI) Fastmap
9883 M: Richard Weinberger <richard@nod.at> 9884 M: Richard Weinberger <richard@nod.at>
9884 L: linux-mtd@lists.infradead.org 9885 L: linux-mtd@lists.infradead.org
9885 S: Maintained 9886 S: Maintained
9886 F: drivers/mtd/ubi/fastmap.c 9887 F: drivers/mtd/ubi/fastmap.c
9887 9888
9888 USB ACM DRIVER 9889 USB ACM DRIVER
9889 M: Oliver Neukum <oliver@neukum.org> 9890 M: Oliver Neukum <oliver@neukum.org>
9890 L: linux-usb@vger.kernel.org 9891 L: linux-usb@vger.kernel.org
9891 S: Maintained 9892 S: Maintained
9892 F: Documentation/usb/acm.txt 9893 F: Documentation/usb/acm.txt
9893 F: drivers/usb/class/cdc-acm.* 9894 F: drivers/usb/class/cdc-acm.*
9894 9895
9895 USB AR5523 WIRELESS DRIVER 9896 USB AR5523 WIRELESS DRIVER
9896 M: Pontus Fuchs <pontus.fuchs@gmail.com> 9897 M: Pontus Fuchs <pontus.fuchs@gmail.com>
9897 L: linux-wireless@vger.kernel.org 9898 L: linux-wireless@vger.kernel.org
9898 S: Maintained 9899 S: Maintained
9899 F: drivers/net/wireless/ath/ar5523/ 9900 F: drivers/net/wireless/ath/ar5523/
9900 9901
9901 USB ATTACHED SCSI 9902 USB ATTACHED SCSI
9902 M: Hans de Goede <hdegoede@redhat.com> 9903 M: Hans de Goede <hdegoede@redhat.com>
9903 M: Gerd Hoffmann <kraxel@redhat.com> 9904 M: Gerd Hoffmann <kraxel@redhat.com>
9904 L: linux-usb@vger.kernel.org 9905 L: linux-usb@vger.kernel.org
9905 L: linux-scsi@vger.kernel.org 9906 L: linux-scsi@vger.kernel.org
9906 S: Maintained 9907 S: Maintained
9907 F: drivers/usb/storage/uas.c 9908 F: drivers/usb/storage/uas.c
9908 9909
9909 USB CDC ETHERNET DRIVER 9910 USB CDC ETHERNET DRIVER
9910 M: Oliver Neukum <oliver@neukum.org> 9911 M: Oliver Neukum <oliver@neukum.org>
9911 L: linux-usb@vger.kernel.org 9912 L: linux-usb@vger.kernel.org
9912 S: Maintained 9913 S: Maintained
9913 F: drivers/net/usb/cdc_*.c 9914 F: drivers/net/usb/cdc_*.c
9914 F: include/uapi/linux/usb/cdc.h 9915 F: include/uapi/linux/usb/cdc.h
9915 9916
9916 USB CYPRESS C67X00 DRIVER 9917 USB CYPRESS C67X00 DRIVER
9917 M: Peter Korsgaard <jacmet@sunsite.dk> 9918 M: Peter Korsgaard <jacmet@sunsite.dk>
9918 L: linux-usb@vger.kernel.org 9919 L: linux-usb@vger.kernel.org
9919 S: Maintained 9920 S: Maintained
9920 F: drivers/usb/c67x00/ 9921 F: drivers/usb/c67x00/
9921 9922
9922 USB DAVICOM DM9601 DRIVER 9923 USB DAVICOM DM9601 DRIVER
9923 M: Peter Korsgaard <jacmet@sunsite.dk> 9924 M: Peter Korsgaard <jacmet@sunsite.dk>
9924 L: netdev@vger.kernel.org 9925 L: netdev@vger.kernel.org
9925 W: http://www.linux-usb.org/usbnet 9926 W: http://www.linux-usb.org/usbnet
9926 S: Maintained 9927 S: Maintained
9927 F: drivers/net/usb/dm9601.c 9928 F: drivers/net/usb/dm9601.c
9928 9929
9929 USB DIAMOND RIO500 DRIVER 9930 USB DIAMOND RIO500 DRIVER
9930 M: Cesar Miquel <miquel@df.uba.ar> 9931 M: Cesar Miquel <miquel@df.uba.ar>
9931 L: rio500-users@lists.sourceforge.net 9932 L: rio500-users@lists.sourceforge.net
9932 W: http://rio500.sourceforge.net 9933 W: http://rio500.sourceforge.net
9933 S: Maintained 9934 S: Maintained
9934 F: drivers/usb/misc/rio500* 9935 F: drivers/usb/misc/rio500*
9935 9936
9936 USB EHCI DRIVER 9937 USB EHCI DRIVER
9937 M: Alan Stern <stern@rowland.harvard.edu> 9938 M: Alan Stern <stern@rowland.harvard.edu>
9938 L: linux-usb@vger.kernel.org 9939 L: linux-usb@vger.kernel.org
9939 S: Maintained 9940 S: Maintained
9940 F: Documentation/usb/ehci.txt 9941 F: Documentation/usb/ehci.txt
9941 F: drivers/usb/host/ehci* 9942 F: drivers/usb/host/ehci*
9942 9943
9943 USB GADGET/PERIPHERAL SUBSYSTEM 9944 USB GADGET/PERIPHERAL SUBSYSTEM
9944 M: Felipe Balbi <balbi@ti.com> 9945 M: Felipe Balbi <balbi@ti.com>
9945 L: linux-usb@vger.kernel.org 9946 L: linux-usb@vger.kernel.org
9946 W: http://www.linux-usb.org/gadget 9947 W: http://www.linux-usb.org/gadget
9947 T: git git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git 9948 T: git git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git
9948 S: Maintained 9949 S: Maintained
9949 F: drivers/usb/gadget/ 9950 F: drivers/usb/gadget/
9950 F: include/linux/usb/gadget* 9951 F: include/linux/usb/gadget*
9951 9952
9952 USB HID/HIDBP DRIVERS (USB KEYBOARDS, MICE, REMOTE CONTROLS, ...) 9953 USB HID/HIDBP DRIVERS (USB KEYBOARDS, MICE, REMOTE CONTROLS, ...)
9953 M: Jiri Kosina <jkosina@suse.cz> 9954 M: Jiri Kosina <jkosina@suse.cz>
9954 L: linux-usb@vger.kernel.org 9955 L: linux-usb@vger.kernel.org
9955 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid.git 9956 T: git git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid.git
9956 S: Maintained 9957 S: Maintained
9957 F: Documentation/hid/hiddev.txt 9958 F: Documentation/hid/hiddev.txt
9958 F: drivers/hid/usbhid/ 9959 F: drivers/hid/usbhid/
9959 9960
9960 USB ISP116X DRIVER 9961 USB ISP116X DRIVER
9961 M: Olav Kongas <ok@artecdesign.ee> 9962 M: Olav Kongas <ok@artecdesign.ee>
9962 L: linux-usb@vger.kernel.org 9963 L: linux-usb@vger.kernel.org
9963 S: Maintained 9964 S: Maintained
9964 F: drivers/usb/host/isp116x* 9965 F: drivers/usb/host/isp116x*
9965 F: include/linux/usb/isp116x.h 9966 F: include/linux/usb/isp116x.h
9966 9967
9967 USB MASS STORAGE DRIVER 9968 USB MASS STORAGE DRIVER
9968 M: Matthew Dharm <mdharm-usb@one-eyed-alien.net> 9969 M: Matthew Dharm <mdharm-usb@one-eyed-alien.net>
9969 L: linux-usb@vger.kernel.org 9970 L: linux-usb@vger.kernel.org
9970 L: usb-storage@lists.one-eyed-alien.net 9971 L: usb-storage@lists.one-eyed-alien.net
9971 S: Maintained 9972 S: Maintained
9972 W: http://www.one-eyed-alien.net/~mdharm/linux-usb/ 9973 W: http://www.one-eyed-alien.net/~mdharm/linux-usb/
9973 F: drivers/usb/storage/ 9974 F: drivers/usb/storage/
9974 9975
9975 USB MIDI DRIVER 9976 USB MIDI DRIVER
9976 M: Clemens Ladisch <clemens@ladisch.de> 9977 M: Clemens Ladisch <clemens@ladisch.de>
9977 L: alsa-devel@alsa-project.org (moderated for non-subscribers) 9978 L: alsa-devel@alsa-project.org (moderated for non-subscribers)
9978 T: git git://git.alsa-project.org/alsa-kernel.git 9979 T: git git://git.alsa-project.org/alsa-kernel.git
9979 S: Maintained 9980 S: Maintained
9980 F: sound/usb/midi.* 9981 F: sound/usb/midi.*
9981 9982
9982 USB NETWORKING DRIVERS 9983 USB NETWORKING DRIVERS
9983 L: linux-usb@vger.kernel.org 9984 L: linux-usb@vger.kernel.org
9984 S: Odd Fixes 9985 S: Odd Fixes
9985 F: drivers/net/usb/ 9986 F: drivers/net/usb/
9986 9987
9987 USB OHCI DRIVER 9988 USB OHCI DRIVER
9988 M: Alan Stern <stern@rowland.harvard.edu> 9989 M: Alan Stern <stern@rowland.harvard.edu>
9989 L: linux-usb@vger.kernel.org 9990 L: linux-usb@vger.kernel.org
9990 S: Maintained 9991 S: Maintained
9991 F: Documentation/usb/ohci.txt 9992 F: Documentation/usb/ohci.txt
9992 F: drivers/usb/host/ohci* 9993 F: drivers/usb/host/ohci*
9993 9994
9994 USB OVER IP DRIVER 9995 USB OVER IP DRIVER
9995 M: Valentina Manea <valentina.manea.m@gmail.com> 9996 M: Valentina Manea <valentina.manea.m@gmail.com>
9996 M: Shuah Khan <shuah.kh@samsung.com> 9997 M: Shuah Khan <shuah.kh@samsung.com>
9997 L: linux-usb@vger.kernel.org 9998 L: linux-usb@vger.kernel.org
9998 S: Maintained 9999 S: Maintained
9999 F: drivers/usb/usbip/ 10000 F: drivers/usb/usbip/
10000 F: tools/usb/usbip/ 10001 F: tools/usb/usbip/
10001 10002
10002 USB PEGASUS DRIVER 10003 USB PEGASUS DRIVER
10003 M: Petko Manolov <petkan@nucleusys.com> 10004 M: Petko Manolov <petkan@nucleusys.com>
10004 L: linux-usb@vger.kernel.org 10005 L: linux-usb@vger.kernel.org
10005 L: netdev@vger.kernel.org 10006 L: netdev@vger.kernel.org
10006 T: git git://github.com/petkan/pegasus.git 10007 T: git git://github.com/petkan/pegasus.git
10007 W: https://github.com/petkan/pegasus 10008 W: https://github.com/petkan/pegasus
10008 S: Maintained 10009 S: Maintained
10009 F: drivers/net/usb/pegasus.* 10010 F: drivers/net/usb/pegasus.*
10010 10011
10011 USB PHY LAYER 10012 USB PHY LAYER
10012 M: Felipe Balbi <balbi@ti.com> 10013 M: Felipe Balbi <balbi@ti.com>
10013 L: linux-usb@vger.kernel.org 10014 L: linux-usb@vger.kernel.org
10014 T: git git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git 10015 T: git git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git
10015 S: Maintained 10016 S: Maintained
10016 F: drivers/usb/phy/ 10017 F: drivers/usb/phy/
10017 10018
10018 USB PRINTER DRIVER (usblp) 10019 USB PRINTER DRIVER (usblp)
10019 M: Pete Zaitcev <zaitcev@redhat.com> 10020 M: Pete Zaitcev <zaitcev@redhat.com>
10020 L: linux-usb@vger.kernel.org 10021 L: linux-usb@vger.kernel.org
10021 S: Supported 10022 S: Supported
10022 F: drivers/usb/class/usblp.c 10023 F: drivers/usb/class/usblp.c
10023 10024
10024 USB RTL8150 DRIVER 10025 USB RTL8150 DRIVER
10025 M: Petko Manolov <petkan@nucleusys.com> 10026 M: Petko Manolov <petkan@nucleusys.com>
10026 L: linux-usb@vger.kernel.org 10027 L: linux-usb@vger.kernel.org
10027 L: netdev@vger.kernel.org 10028 L: netdev@vger.kernel.org
10028 T: git git://github.com/petkan/rtl8150.git 10029 T: git git://github.com/petkan/rtl8150.git
10029 W: https://github.com/petkan/rtl8150 10030 W: https://github.com/petkan/rtl8150
10030 S: Maintained 10031 S: Maintained
10031 F: drivers/net/usb/rtl8150.c 10032 F: drivers/net/usb/rtl8150.c
10032 10033
10033 USB SERIAL SUBSYSTEM 10034 USB SERIAL SUBSYSTEM
10034 M: Johan Hovold <johan@kernel.org> 10035 M: Johan Hovold <johan@kernel.org>
10035 L: linux-usb@vger.kernel.org 10036 L: linux-usb@vger.kernel.org
10036 S: Maintained 10037 S: Maintained
10037 F: Documentation/usb/usb-serial.txt 10038 F: Documentation/usb/usb-serial.txt
10038 F: drivers/usb/serial/ 10039 F: drivers/usb/serial/
10039 F: include/linux/usb/serial.h 10040 F: include/linux/usb/serial.h
10040 10041
10041 USB SMSC75XX ETHERNET DRIVER 10042 USB SMSC75XX ETHERNET DRIVER
10042 M: Steve Glendinning <steve.glendinning@shawell.net> 10043 M: Steve Glendinning <steve.glendinning@shawell.net>
10043 L: netdev@vger.kernel.org 10044 L: netdev@vger.kernel.org
10044 S: Maintained 10045 S: Maintained
10045 F: drivers/net/usb/smsc75xx.* 10046 F: drivers/net/usb/smsc75xx.*
10046 10047
10047 USB SMSC95XX ETHERNET DRIVER 10048 USB SMSC95XX ETHERNET DRIVER
10048 M: Steve Glendinning <steve.glendinning@shawell.net> 10049 M: Steve Glendinning <steve.glendinning@shawell.net>
10049 L: netdev@vger.kernel.org 10050 L: netdev@vger.kernel.org
10050 S: Maintained 10051 S: Maintained
10051 F: drivers/net/usb/smsc95xx.* 10052 F: drivers/net/usb/smsc95xx.*
10052 10053
10053 USB SUBSYSTEM 10054 USB SUBSYSTEM
10054 M: Greg Kroah-Hartman <gregkh@linuxfoundation.org> 10055 M: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
10055 L: linux-usb@vger.kernel.org 10056 L: linux-usb@vger.kernel.org
10056 W: http://www.linux-usb.org 10057 W: http://www.linux-usb.org
10057 T: git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git 10058 T: git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git
10058 S: Supported 10059 S: Supported
10059 F: Documentation/usb/ 10060 F: Documentation/usb/
10060 F: drivers/usb/ 10061 F: drivers/usb/
10061 F: include/linux/usb.h 10062 F: include/linux/usb.h
10062 F: include/linux/usb/ 10063 F: include/linux/usb/
10063 10064
10064 USB UHCI DRIVER 10065 USB UHCI DRIVER
10065 M: Alan Stern <stern@rowland.harvard.edu> 10066 M: Alan Stern <stern@rowland.harvard.edu>
10066 L: linux-usb@vger.kernel.org 10067 L: linux-usb@vger.kernel.org
10067 S: Maintained 10068 S: Maintained
10068 F: drivers/usb/host/uhci* 10069 F: drivers/usb/host/uhci*
10069 10070
10070 USB "USBNET" DRIVER FRAMEWORK 10071 USB "USBNET" DRIVER FRAMEWORK
10071 M: Oliver Neukum <oneukum@suse.de> 10072 M: Oliver Neukum <oneukum@suse.de>
10072 L: netdev@vger.kernel.org 10073 L: netdev@vger.kernel.org
10073 W: http://www.linux-usb.org/usbnet 10074 W: http://www.linux-usb.org/usbnet
10074 S: Maintained 10075 S: Maintained
10075 F: drivers/net/usb/usbnet.c 10076 F: drivers/net/usb/usbnet.c
10076 F: include/linux/usb/usbnet.h 10077 F: include/linux/usb/usbnet.h
10077 10078
10078 USB VIDEO CLASS 10079 USB VIDEO CLASS
10079 M: Laurent Pinchart <laurent.pinchart@ideasonboard.com> 10080 M: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
10080 L: linux-uvc-devel@lists.sourceforge.net (subscribers-only) 10081 L: linux-uvc-devel@lists.sourceforge.net (subscribers-only)
10081 L: linux-media@vger.kernel.org 10082 L: linux-media@vger.kernel.org
10082 T: git git://linuxtv.org/media_tree.git 10083 T: git git://linuxtv.org/media_tree.git
10083 W: http://www.ideasonboard.org/uvc/ 10084 W: http://www.ideasonboard.org/uvc/
10084 S: Maintained 10085 S: Maintained
10085 F: drivers/media/usb/uvc/ 10086 F: drivers/media/usb/uvc/
10086 F: include/uapi/linux/uvcvideo.h 10087 F: include/uapi/linux/uvcvideo.h
10087 10088
10088 USB VISION DRIVER 10089 USB VISION DRIVER
10089 M: Hans Verkuil <hverkuil@xs4all.nl> 10090 M: Hans Verkuil <hverkuil@xs4all.nl>
10090 L: linux-media@vger.kernel.org 10091 L: linux-media@vger.kernel.org
10091 T: git git://linuxtv.org/media_tree.git 10092 T: git git://linuxtv.org/media_tree.git
10092 W: http://linuxtv.org 10093 W: http://linuxtv.org
10093 S: Odd Fixes 10094 S: Odd Fixes
10094 F: drivers/media/usb/usbvision/ 10095 F: drivers/media/usb/usbvision/
10095 10096
10096 USB WEBCAM GADGET 10097 USB WEBCAM GADGET
10097 M: Laurent Pinchart <laurent.pinchart@ideasonboard.com> 10098 M: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
10098 L: linux-usb@vger.kernel.org 10099 L: linux-usb@vger.kernel.org
10099 S: Maintained 10100 S: Maintained
10100 F: drivers/usb/gadget/function/*uvc* 10101 F: drivers/usb/gadget/function/*uvc*
10101 F: drivers/usb/gadget/legacy/webcam.c 10102 F: drivers/usb/gadget/legacy/webcam.c
10102 10103
10103 USB WIRELESS RNDIS DRIVER (rndis_wlan) 10104 USB WIRELESS RNDIS DRIVER (rndis_wlan)
10104 M: Jussi Kivilinna <jussi.kivilinna@iki.fi> 10105 M: Jussi Kivilinna <jussi.kivilinna@iki.fi>
10105 L: linux-wireless@vger.kernel.org 10106 L: linux-wireless@vger.kernel.org
10106 S: Maintained 10107 S: Maintained
10107 F: drivers/net/wireless/rndis_wlan.c 10108 F: drivers/net/wireless/rndis_wlan.c
10108 10109
10109 USB XHCI DRIVER 10110 USB XHCI DRIVER
10110 M: Mathias Nyman <mathias.nyman@intel.com> 10111 M: Mathias Nyman <mathias.nyman@intel.com>
10111 L: linux-usb@vger.kernel.org 10112 L: linux-usb@vger.kernel.org
10112 S: Supported 10113 S: Supported
10113 F: drivers/usb/host/xhci* 10114 F: drivers/usb/host/xhci*
10114 F: drivers/usb/host/pci-quirks* 10115 F: drivers/usb/host/pci-quirks*
10115 10116
10116 USB ZD1201 DRIVER 10117 USB ZD1201 DRIVER
10117 L: linux-wireless@vger.kernel.org 10118 L: linux-wireless@vger.kernel.org
10118 W: http://linux-lc100020.sourceforge.net 10119 W: http://linux-lc100020.sourceforge.net
10119 S: Orphan 10120 S: Orphan
10120 F: drivers/net/wireless/zd1201.* 10121 F: drivers/net/wireless/zd1201.*
10121 10122
10122 USB ZR364XX DRIVER 10123 USB ZR364XX DRIVER
10123 M: Antoine Jacquet <royale@zerezo.com> 10124 M: Antoine Jacquet <royale@zerezo.com>
10124 L: linux-usb@vger.kernel.org 10125 L: linux-usb@vger.kernel.org
10125 L: linux-media@vger.kernel.org 10126 L: linux-media@vger.kernel.org
10126 T: git git://linuxtv.org/media_tree.git 10127 T: git git://linuxtv.org/media_tree.git
10127 W: http://royale.zerezo.com/zr364xx/ 10128 W: http://royale.zerezo.com/zr364xx/
10128 S: Maintained 10129 S: Maintained
10129 F: Documentation/video4linux/zr364xx.txt 10130 F: Documentation/video4linux/zr364xx.txt
10130 F: drivers/media/usb/zr364xx/ 10131 F: drivers/media/usb/zr364xx/
10131 10132
10132 USER-MODE LINUX (UML) 10133 USER-MODE LINUX (UML)
10133 M: Jeff Dike <jdike@addtoit.com> 10134 M: Jeff Dike <jdike@addtoit.com>
10134 M: Richard Weinberger <richard@nod.at> 10135 M: Richard Weinberger <richard@nod.at>
10135 L: user-mode-linux-devel@lists.sourceforge.net 10136 L: user-mode-linux-devel@lists.sourceforge.net
10136 L: user-mode-linux-user@lists.sourceforge.net 10137 L: user-mode-linux-user@lists.sourceforge.net
10137 W: http://user-mode-linux.sourceforge.net 10138 W: http://user-mode-linux.sourceforge.net
10138 S: Maintained 10139 S: Maintained
10139 F: Documentation/virtual/uml/ 10140 F: Documentation/virtual/uml/
10140 F: arch/um/ 10141 F: arch/um/
10141 F: arch/x86/um/ 10142 F: arch/x86/um/
10142 F: fs/hostfs/ 10143 F: fs/hostfs/
10143 F: fs/hppfs/ 10144 F: fs/hppfs/
10144 10145
10145 USERSPACE I/O (UIO) 10146 USERSPACE I/O (UIO)
10146 M: "Hans J. Koch" <hjk@hansjkoch.de> 10147 M: "Hans J. Koch" <hjk@hansjkoch.de>
10147 M: Greg Kroah-Hartman <gregkh@linuxfoundation.org> 10148 M: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
10148 S: Maintained 10149 S: Maintained
10149 F: Documentation/DocBook/uio-howto.tmpl 10150 F: Documentation/DocBook/uio-howto.tmpl
10150 F: drivers/uio/ 10151 F: drivers/uio/
10151 F: include/linux/uio*.h 10152 F: include/linux/uio*.h
10152 10153
10153 UTIL-LINUX PACKAGE 10154 UTIL-LINUX PACKAGE
10154 M: Karel Zak <kzak@redhat.com> 10155 M: Karel Zak <kzak@redhat.com>
10155 L: util-linux@vger.kernel.org 10156 L: util-linux@vger.kernel.org
10156 W: http://en.wikipedia.org/wiki/Util-linux 10157 W: http://en.wikipedia.org/wiki/Util-linux
10157 T: git git://git.kernel.org/pub/scm/utils/util-linux/util-linux.git 10158 T: git git://git.kernel.org/pub/scm/utils/util-linux/util-linux.git
10158 S: Maintained 10159 S: Maintained
10159 10160
10160 UVESAFB DRIVER 10161 UVESAFB DRIVER
10161 M: Michal Januszewski <spock@gentoo.org> 10162 M: Michal Januszewski <spock@gentoo.org>
10162 L: linux-fbdev@vger.kernel.org 10163 L: linux-fbdev@vger.kernel.org
10163 W: http://dev.gentoo.org/~spock/projects/uvesafb/ 10164 W: http://dev.gentoo.org/~spock/projects/uvesafb/
10164 S: Maintained 10165 S: Maintained
10165 F: Documentation/fb/uvesafb.txt 10166 F: Documentation/fb/uvesafb.txt
10166 F: drivers/video/fbdev/uvesafb.* 10167 F: drivers/video/fbdev/uvesafb.*
10167 10168
10168 VFAT/FAT/MSDOS FILESYSTEM 10169 VFAT/FAT/MSDOS FILESYSTEM
10169 M: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> 10170 M: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
10170 S: Maintained 10171 S: Maintained
10171 F: Documentation/filesystems/vfat.txt 10172 F: Documentation/filesystems/vfat.txt
10172 F: fs/fat/ 10173 F: fs/fat/
10173 10174
10174 VFIO DRIVER 10175 VFIO DRIVER
10175 M: Alex Williamson <alex.williamson@redhat.com> 10176 M: Alex Williamson <alex.williamson@redhat.com>
10176 L: kvm@vger.kernel.org 10177 L: kvm@vger.kernel.org
10177 S: Maintained 10178 S: Maintained
10178 F: Documentation/vfio.txt 10179 F: Documentation/vfio.txt
10179 F: drivers/vfio/ 10180 F: drivers/vfio/
10180 F: include/linux/vfio.h 10181 F: include/linux/vfio.h
10181 F: include/uapi/linux/vfio.h 10182 F: include/uapi/linux/vfio.h
10182 10183
10183 VIDEOBUF2 FRAMEWORK 10184 VIDEOBUF2 FRAMEWORK
10184 M: Pawel Osciak <pawel@osciak.com> 10185 M: Pawel Osciak <pawel@osciak.com>
10185 M: Marek Szyprowski <m.szyprowski@samsung.com> 10186 M: Marek Szyprowski <m.szyprowski@samsung.com>
10186 M: Kyungmin Park <kyungmin.park@samsung.com> 10187 M: Kyungmin Park <kyungmin.park@samsung.com>
10187 L: linux-media@vger.kernel.org 10188 L: linux-media@vger.kernel.org
10188 S: Maintained 10189 S: Maintained
10189 F: drivers/media/v4l2-core/videobuf2-* 10190 F: drivers/media/v4l2-core/videobuf2-*
10190 F: include/media/videobuf2-* 10191 F: include/media/videobuf2-*
10191 10192
10192 VIRTIO CONSOLE DRIVER 10193 VIRTIO CONSOLE DRIVER
10193 M: Amit Shah <amit.shah@redhat.com> 10194 M: Amit Shah <amit.shah@redhat.com>
10194 L: virtualization@lists.linux-foundation.org 10195 L: virtualization@lists.linux-foundation.org
10195 S: Maintained 10196 S: Maintained
10196 F: drivers/char/virtio_console.c 10197 F: drivers/char/virtio_console.c
10197 F: include/linux/virtio_console.h 10198 F: include/linux/virtio_console.h
10198 F: include/uapi/linux/virtio_console.h 10199 F: include/uapi/linux/virtio_console.h
10199 10200
10200 VIRTIO CORE, NET AND BLOCK DRIVERS 10201 VIRTIO CORE, NET AND BLOCK DRIVERS
10201 M: Rusty Russell <rusty@rustcorp.com.au> 10202 M: Rusty Russell <rusty@rustcorp.com.au>
10202 M: "Michael S. Tsirkin" <mst@redhat.com> 10203 M: "Michael S. Tsirkin" <mst@redhat.com>
10203 L: virtualization@lists.linux-foundation.org 10204 L: virtualization@lists.linux-foundation.org
10204 S: Maintained 10205 S: Maintained
10205 F: drivers/virtio/ 10206 F: drivers/virtio/
10206 F: tools/virtio/ 10207 F: tools/virtio/
10207 F: drivers/net/virtio_net.c 10208 F: drivers/net/virtio_net.c
10208 F: drivers/block/virtio_blk.c 10209 F: drivers/block/virtio_blk.c
10209 F: include/linux/virtio_*.h 10210 F: include/linux/virtio_*.h
10210 F: include/uapi/linux/virtio_*.h 10211 F: include/uapi/linux/virtio_*.h
10211 10212
10212 VIRTIO HOST (VHOST) 10213 VIRTIO HOST (VHOST)
10213 M: "Michael S. Tsirkin" <mst@redhat.com> 10214 M: "Michael S. Tsirkin" <mst@redhat.com>
10214 L: kvm@vger.kernel.org 10215 L: kvm@vger.kernel.org
10215 L: virtualization@lists.linux-foundation.org 10216 L: virtualization@lists.linux-foundation.org
10216 L: netdev@vger.kernel.org 10217 L: netdev@vger.kernel.org
10217 S: Maintained 10218 S: Maintained
10218 F: drivers/vhost/ 10219 F: drivers/vhost/
10219 F: include/uapi/linux/vhost.h 10220 F: include/uapi/linux/vhost.h
10220 10221
10221 VIA RHINE NETWORK DRIVER 10222 VIA RHINE NETWORK DRIVER
10222 M: Roger Luethi <rl@hellgate.ch> 10223 M: Roger Luethi <rl@hellgate.ch>
10223 S: Maintained 10224 S: Maintained
10224 F: drivers/net/ethernet/via/via-rhine.c 10225 F: drivers/net/ethernet/via/via-rhine.c
10225 10226
10226 VIA SD/MMC CARD CONTROLLER DRIVER 10227 VIA SD/MMC CARD CONTROLLER DRIVER
10227 M: Bruce Chang <brucechang@via.com.tw> 10228 M: Bruce Chang <brucechang@via.com.tw>
10228 M: Harald Welte <HaraldWelte@viatech.com> 10229 M: Harald Welte <HaraldWelte@viatech.com>
10229 S: Maintained 10230 S: Maintained
10230 F: drivers/mmc/host/via-sdmmc.c 10231 F: drivers/mmc/host/via-sdmmc.c
10231 10232
10232 VIA UNICHROME(PRO)/CHROME9 FRAMEBUFFER DRIVER 10233 VIA UNICHROME(PRO)/CHROME9 FRAMEBUFFER DRIVER
10233 M: Florian Tobias Schandinat <FlorianSchandinat@gmx.de> 10234 M: Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
10234 L: linux-fbdev@vger.kernel.org 10235 L: linux-fbdev@vger.kernel.org
10235 S: Maintained 10236 S: Maintained
10236 F: include/linux/via-core.h 10237 F: include/linux/via-core.h
10237 F: include/linux/via-gpio.h 10238 F: include/linux/via-gpio.h
10238 F: include/linux/via_i2c.h 10239 F: include/linux/via_i2c.h
10239 F: drivers/video/fbdev/via/ 10240 F: drivers/video/fbdev/via/
10240 10241
10241 VIA VELOCITY NETWORK DRIVER 10242 VIA VELOCITY NETWORK DRIVER
10242 M: Francois Romieu <romieu@fr.zoreil.com> 10243 M: Francois Romieu <romieu@fr.zoreil.com>
10243 L: netdev@vger.kernel.org 10244 L: netdev@vger.kernel.org
10244 S: Maintained 10245 S: Maintained
10245 F: drivers/net/ethernet/via/via-velocity.* 10246 F: drivers/net/ethernet/via/via-velocity.*
10246 10247
10247 VIVID VIRTUAL VIDEO DRIVER 10248 VIVID VIRTUAL VIDEO DRIVER
10248 M: Hans Verkuil <hverkuil@xs4all.nl> 10249 M: Hans Verkuil <hverkuil@xs4all.nl>
10249 L: linux-media@vger.kernel.org 10250 L: linux-media@vger.kernel.org
10250 T: git git://linuxtv.org/media_tree.git 10251 T: git git://linuxtv.org/media_tree.git
10251 W: http://linuxtv.org 10252 W: http://linuxtv.org
10252 S: Maintained 10253 S: Maintained
10253 F: drivers/media/platform/vivid/* 10254 F: drivers/media/platform/vivid/*
10254 10255
10255 VLAN (802.1Q) 10256 VLAN (802.1Q)
10256 M: Patrick McHardy <kaber@trash.net> 10257 M: Patrick McHardy <kaber@trash.net>
10257 L: netdev@vger.kernel.org 10258 L: netdev@vger.kernel.org
10258 S: Maintained 10259 S: Maintained
10259 F: drivers/net/macvlan.c 10260 F: drivers/net/macvlan.c
10260 F: include/linux/if_*vlan.h 10261 F: include/linux/if_*vlan.h
10261 F: net/8021q/ 10262 F: net/8021q/
10262 10263
10263 VLYNQ BUS 10264 VLYNQ BUS
10264 M: Florian Fainelli <florian@openwrt.org> 10265 M: Florian Fainelli <florian@openwrt.org>
10265 L: openwrt-devel@lists.openwrt.org (subscribers-only) 10266 L: openwrt-devel@lists.openwrt.org (subscribers-only)
10266 S: Maintained 10267 S: Maintained
10267 F: drivers/vlynq/vlynq.c 10268 F: drivers/vlynq/vlynq.c
10268 F: include/linux/vlynq.h 10269 F: include/linux/vlynq.h
10269 10270
10270 VME SUBSYSTEM 10271 VME SUBSYSTEM
10271 M: Martyn Welch <martyn.welch@ge.com> 10272 M: Martyn Welch <martyn.welch@ge.com>
10272 M: Manohar Vanga <manohar.vanga@gmail.com> 10273 M: Manohar Vanga <manohar.vanga@gmail.com>
10273 M: Greg Kroah-Hartman <gregkh@linuxfoundation.org> 10274 M: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
10274 L: devel@driverdev.osuosl.org 10275 L: devel@driverdev.osuosl.org
10275 S: Maintained 10276 S: Maintained
10276 T: git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git 10277 T: git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git
10277 F: Documentation/vme_api.txt 10278 F: Documentation/vme_api.txt
10278 F: drivers/staging/vme/ 10279 F: drivers/staging/vme/
10279 F: drivers/vme/ 10280 F: drivers/vme/
10280 F: include/linux/vme* 10281 F: include/linux/vme*
10281 10282
10282 VMWARE HYPERVISOR INTERFACE 10283 VMWARE HYPERVISOR INTERFACE
10283 M: Alok Kataria <akataria@vmware.com> 10284 M: Alok Kataria <akataria@vmware.com>
10284 L: virtualization@lists.linux-foundation.org 10285 L: virtualization@lists.linux-foundation.org
10285 S: Supported 10286 S: Supported
10286 F: arch/x86/kernel/cpu/vmware.c 10287 F: arch/x86/kernel/cpu/vmware.c
10287 10288
10288 VMWARE BALLOON DRIVER 10289 VMWARE BALLOON DRIVER
10289 M: Xavier Deguillard <xdeguillard@vmware.com> 10290 M: Xavier Deguillard <xdeguillard@vmware.com>
10290 M: Philip Moltmann <moltmann@vmware.com> 10291 M: Philip Moltmann <moltmann@vmware.com>
10291 M: "VMware, Inc." <pv-drivers@vmware.com> 10292 M: "VMware, Inc." <pv-drivers@vmware.com>
10292 L: linux-kernel@vger.kernel.org 10293 L: linux-kernel@vger.kernel.org
10293 S: Maintained 10294 S: Maintained
10294 F: drivers/misc/vmw_balloon.c 10295 F: drivers/misc/vmw_balloon.c
10295 10296
10296 VMWARE VMXNET3 ETHERNET DRIVER 10297 VMWARE VMXNET3 ETHERNET DRIVER
10297 M: Shreyas Bhatewara <sbhatewara@vmware.com> 10298 M: Shreyas Bhatewara <sbhatewara@vmware.com>
10298 M: "VMware, Inc." <pv-drivers@vmware.com> 10299 M: "VMware, Inc." <pv-drivers@vmware.com>
10299 L: netdev@vger.kernel.org 10300 L: netdev@vger.kernel.org
10300 S: Maintained 10301 S: Maintained
10301 F: drivers/net/vmxnet3/ 10302 F: drivers/net/vmxnet3/
10302 10303
10303 VMware PVSCSI driver 10304 VMware PVSCSI driver
10304 M: Arvind Kumar <arvindkumar@vmware.com> 10305 M: Arvind Kumar <arvindkumar@vmware.com>
10305 M: VMware PV-Drivers <pv-drivers@vmware.com> 10306 M: VMware PV-Drivers <pv-drivers@vmware.com>
10306 L: linux-scsi@vger.kernel.org 10307 L: linux-scsi@vger.kernel.org
10307 S: Maintained 10308 S: Maintained
10308 F: drivers/scsi/vmw_pvscsi.c 10309 F: drivers/scsi/vmw_pvscsi.c
10309 F: drivers/scsi/vmw_pvscsi.h 10310 F: drivers/scsi/vmw_pvscsi.h
10310 10311
10311 VOLTAGE AND CURRENT REGULATOR FRAMEWORK 10312 VOLTAGE AND CURRENT REGULATOR FRAMEWORK
10312 M: Liam Girdwood <lgirdwood@gmail.com> 10313 M: Liam Girdwood <lgirdwood@gmail.com>
10313 M: Mark Brown <broonie@kernel.org> 10314 M: Mark Brown <broonie@kernel.org>
10314 L: linux-kernel@vger.kernel.org 10315 L: linux-kernel@vger.kernel.org
10315 W: http://opensource.wolfsonmicro.com/node/15 10316 W: http://opensource.wolfsonmicro.com/node/15
10316 W: http://www.slimlogic.co.uk/?p=48 10317 W: http://www.slimlogic.co.uk/?p=48
10317 T: git git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git 10318 T: git git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git
10318 S: Supported 10319 S: Supported
10319 F: drivers/regulator/ 10320 F: drivers/regulator/
10320 F: include/linux/regulator/ 10321 F: include/linux/regulator/
10321 10322
10322 VT1211 HARDWARE MONITOR DRIVER 10323 VT1211 HARDWARE MONITOR DRIVER
10323 M: Juerg Haefliger <juergh@gmail.com> 10324 M: Juerg Haefliger <juergh@gmail.com>
10324 L: lm-sensors@lm-sensors.org 10325 L: lm-sensors@lm-sensors.org
10325 S: Maintained 10326 S: Maintained
10326 F: Documentation/hwmon/vt1211 10327 F: Documentation/hwmon/vt1211
10327 F: drivers/hwmon/vt1211.c 10328 F: drivers/hwmon/vt1211.c
10328 10329
10329 VT8231 HARDWARE MONITOR DRIVER 10330 VT8231 HARDWARE MONITOR DRIVER
10330 M: Roger Lucas <vt8231@hiddenengine.co.uk> 10331 M: Roger Lucas <vt8231@hiddenengine.co.uk>
10331 L: lm-sensors@lm-sensors.org 10332 L: lm-sensors@lm-sensors.org
10332 S: Maintained 10333 S: Maintained
10333 F: drivers/hwmon/vt8231.c 10334 F: drivers/hwmon/vt8231.c
10334 10335
10335 VUB300 USB to SDIO/SD/MMC bridge chip 10336 VUB300 USB to SDIO/SD/MMC bridge chip
10336 M: Tony Olech <tony.olech@elandigitalsystems.com> 10337 M: Tony Olech <tony.olech@elandigitalsystems.com>
10337 L: linux-mmc@vger.kernel.org 10338 L: linux-mmc@vger.kernel.org
10338 L: linux-usb@vger.kernel.org 10339 L: linux-usb@vger.kernel.org
10339 S: Supported 10340 S: Supported
10340 F: drivers/mmc/host/vub300.c 10341 F: drivers/mmc/host/vub300.c
10341 10342
10342 W1 DALLAS'S 1-WIRE BUS 10343 W1 DALLAS'S 1-WIRE BUS
10343 M: Evgeniy Polyakov <zbr@ioremap.net> 10344 M: Evgeniy Polyakov <zbr@ioremap.net>
10344 S: Maintained 10345 S: Maintained
10345 F: Documentation/w1/ 10346 F: Documentation/w1/
10346 F: drivers/w1/ 10347 F: drivers/w1/
10347 10348
10348 W83791D HARDWARE MONITORING DRIVER 10349 W83791D HARDWARE MONITORING DRIVER
10349 M: Marc Hulsman <m.hulsman@tudelft.nl> 10350 M: Marc Hulsman <m.hulsman@tudelft.nl>
10350 L: lm-sensors@lm-sensors.org 10351 L: lm-sensors@lm-sensors.org
10351 S: Maintained 10352 S: Maintained
10352 F: Documentation/hwmon/w83791d 10353 F: Documentation/hwmon/w83791d
10353 F: drivers/hwmon/w83791d.c 10354 F: drivers/hwmon/w83791d.c
10354 10355
10355 W83793 HARDWARE MONITORING DRIVER 10356 W83793 HARDWARE MONITORING DRIVER
10356 M: Rudolf Marek <r.marek@assembler.cz> 10357 M: Rudolf Marek <r.marek@assembler.cz>
10357 L: lm-sensors@lm-sensors.org 10358 L: lm-sensors@lm-sensors.org
10358 S: Maintained 10359 S: Maintained
10359 F: Documentation/hwmon/w83793 10360 F: Documentation/hwmon/w83793
10360 F: drivers/hwmon/w83793.c 10361 F: drivers/hwmon/w83793.c
10361 10362
10362 W83795 HARDWARE MONITORING DRIVER 10363 W83795 HARDWARE MONITORING DRIVER
10363 M: Jean Delvare <jdelvare@suse.de> 10364 M: Jean Delvare <jdelvare@suse.de>
10364 L: lm-sensors@lm-sensors.org 10365 L: lm-sensors@lm-sensors.org
10365 S: Maintained 10366 S: Maintained
10366 F: drivers/hwmon/w83795.c 10367 F: drivers/hwmon/w83795.c
10367 10368
10368 W83L51xD SD/MMC CARD INTERFACE DRIVER 10369 W83L51xD SD/MMC CARD INTERFACE DRIVER
10369 M: Pierre Ossman <pierre@ossman.eu> 10370 M: Pierre Ossman <pierre@ossman.eu>
10370 S: Maintained 10371 S: Maintained
10371 F: drivers/mmc/host/wbsd.* 10372 F: drivers/mmc/host/wbsd.*
10372 10373
10373 WACOM PROTOCOL 4 SERIAL TABLETS 10374 WACOM PROTOCOL 4 SERIAL TABLETS
10374 M: Julian Squires <julian@cipht.net> 10375 M: Julian Squires <julian@cipht.net>
10375 M: Hans de Goede <hdegoede@redhat.com> 10376 M: Hans de Goede <hdegoede@redhat.com>
10376 L: linux-input@vger.kernel.org 10377 L: linux-input@vger.kernel.org
10377 S: Maintained 10378 S: Maintained
10378 F: drivers/input/tablet/wacom_serial4.c 10379 F: drivers/input/tablet/wacom_serial4.c
10379 10380
10380 WATCHDOG DEVICE DRIVERS 10381 WATCHDOG DEVICE DRIVERS
10381 M: Wim Van Sebroeck <wim@iguana.be> 10382 M: Wim Van Sebroeck <wim@iguana.be>
10382 L: linux-watchdog@vger.kernel.org 10383 L: linux-watchdog@vger.kernel.org
10383 W: http://www.linux-watchdog.org/ 10384 W: http://www.linux-watchdog.org/
10384 T: git git://www.linux-watchdog.org/linux-watchdog.git 10385 T: git git://www.linux-watchdog.org/linux-watchdog.git
10385 S: Maintained 10386 S: Maintained
10386 F: Documentation/watchdog/ 10387 F: Documentation/watchdog/
10387 F: drivers/watchdog/ 10388 F: drivers/watchdog/
10388 F: include/linux/watchdog.h 10389 F: include/linux/watchdog.h
10389 F: include/uapi/linux/watchdog.h 10390 F: include/uapi/linux/watchdog.h
10390 10391
10391 WD7000 SCSI DRIVER 10392 WD7000 SCSI DRIVER
10392 M: Miroslav Zagorac <zaga@fly.cc.fer.hr> 10393 M: Miroslav Zagorac <zaga@fly.cc.fer.hr>
10393 L: linux-scsi@vger.kernel.org 10394 L: linux-scsi@vger.kernel.org
10394 S: Maintained 10395 S: Maintained
10395 F: drivers/scsi/wd7000.c 10396 F: drivers/scsi/wd7000.c
10396 10397
10397 WIIMOTE HID DRIVER 10398 WIIMOTE HID DRIVER
10398 M: David Herrmann <dh.herrmann@googlemail.com> 10399 M: David Herrmann <dh.herrmann@googlemail.com>
10399 L: linux-input@vger.kernel.org 10400 L: linux-input@vger.kernel.org
10400 S: Maintained 10401 S: Maintained
10401 F: drivers/hid/hid-wiimote* 10402 F: drivers/hid/hid-wiimote*
10402 10403
10403 WINBOND CIR DRIVER 10404 WINBOND CIR DRIVER
10404 M: David Hรคrdeman <david@hardeman.nu> 10405 M: David Hรคrdeman <david@hardeman.nu>
10405 S: Maintained 10406 S: Maintained
10406 F: drivers/media/rc/winbond-cir.c 10407 F: drivers/media/rc/winbond-cir.c
10407 10408
10408 WIMAX STACK 10409 WIMAX STACK
10409 M: Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> 10410 M: Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
10410 M: linux-wimax@intel.com 10411 M: linux-wimax@intel.com
10411 L: wimax@linuxwimax.org (subscribers-only) 10412 L: wimax@linuxwimax.org (subscribers-only)
10412 S: Supported 10413 S: Supported
10413 W: http://linuxwimax.org 10414 W: http://linuxwimax.org
10414 F: Documentation/wimax/README.wimax 10415 F: Documentation/wimax/README.wimax
10415 F: include/linux/wimax/debug.h 10416 F: include/linux/wimax/debug.h
10416 F: include/net/wimax.h 10417 F: include/net/wimax.h
10417 F: include/uapi/linux/wimax.h 10418 F: include/uapi/linux/wimax.h
10418 F: net/wimax/ 10419 F: net/wimax/
10419 10420
10420 WISTRON LAPTOP BUTTON DRIVER 10421 WISTRON LAPTOP BUTTON DRIVER
10421 M: Miloslav Trmac <mitr@volny.cz> 10422 M: Miloslav Trmac <mitr@volny.cz>
10422 S: Maintained 10423 S: Maintained
10423 F: drivers/input/misc/wistron_btns.c 10424 F: drivers/input/misc/wistron_btns.c
10424 10425
10425 WL3501 WIRELESS PCMCIA CARD DRIVER 10426 WL3501 WIRELESS PCMCIA CARD DRIVER
10426 M: Arnaldo Carvalho de Melo <acme@ghostprotocols.net> 10427 M: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
10427 L: linux-wireless@vger.kernel.org 10428 L: linux-wireless@vger.kernel.org
10428 W: http://oops.ghostprotocols.net:81/blog 10429 W: http://oops.ghostprotocols.net:81/blog
10429 S: Maintained 10430 S: Maintained
10430 F: drivers/net/wireless/wl3501* 10431 F: drivers/net/wireless/wl3501*
10431 10432
10432 WM97XX TOUCHSCREEN DRIVERS 10433 WM97XX TOUCHSCREEN DRIVERS
10433 M: Mark Brown <broonie@kernel.org> 10434 M: Mark Brown <broonie@kernel.org>
10434 M: Liam Girdwood <lrg@slimlogic.co.uk> 10435 M: Liam Girdwood <lrg@slimlogic.co.uk>
10435 L: linux-input@vger.kernel.org 10436 L: linux-input@vger.kernel.org
10436 T: git git://opensource.wolfsonmicro.com/linux-2.6-touch 10437 T: git git://opensource.wolfsonmicro.com/linux-2.6-touch
10437 W: http://opensource.wolfsonmicro.com/node/7 10438 W: http://opensource.wolfsonmicro.com/node/7
10438 S: Supported 10439 S: Supported
10439 F: drivers/input/touchscreen/*wm97* 10440 F: drivers/input/touchscreen/*wm97*
10440 F: include/linux/wm97xx.h 10441 F: include/linux/wm97xx.h
10441 10442
10442 WOLFSON MICROELECTRONICS DRIVERS 10443 WOLFSON MICROELECTRONICS DRIVERS
10443 L: patches@opensource.wolfsonmicro.com 10444 L: patches@opensource.wolfsonmicro.com
10444 T: git git://opensource.wolfsonmicro.com/linux-2.6-asoc 10445 T: git git://opensource.wolfsonmicro.com/linux-2.6-asoc
10445 T: git git://opensource.wolfsonmicro.com/linux-2.6-audioplus 10446 T: git git://opensource.wolfsonmicro.com/linux-2.6-audioplus
10446 W: http://opensource.wolfsonmicro.com/content/linux-drivers-wolfson-devices 10447 W: http://opensource.wolfsonmicro.com/content/linux-drivers-wolfson-devices
10447 S: Supported 10448 S: Supported
10448 F: Documentation/hwmon/wm83?? 10449 F: Documentation/hwmon/wm83??
10449 F: arch/arm/mach-s3c64xx/mach-crag6410* 10450 F: arch/arm/mach-s3c64xx/mach-crag6410*
10450 F: drivers/clk/clk-wm83*.c 10451 F: drivers/clk/clk-wm83*.c
10451 F: drivers/extcon/extcon-arizona.c 10452 F: drivers/extcon/extcon-arizona.c
10452 F: drivers/leds/leds-wm83*.c 10453 F: drivers/leds/leds-wm83*.c
10453 F: drivers/gpio/gpio-*wm*.c 10454 F: drivers/gpio/gpio-*wm*.c
10454 F: drivers/gpio/gpio-arizona.c 10455 F: drivers/gpio/gpio-arizona.c
10455 F: drivers/hwmon/wm83??-hwmon.c 10456 F: drivers/hwmon/wm83??-hwmon.c
10456 F: drivers/input/misc/wm831x-on.c 10457 F: drivers/input/misc/wm831x-on.c
10457 F: drivers/input/touchscreen/wm831x-ts.c 10458 F: drivers/input/touchscreen/wm831x-ts.c
10458 F: drivers/input/touchscreen/wm97*.c 10459 F: drivers/input/touchscreen/wm97*.c
10459 F: drivers/mfd/arizona* 10460 F: drivers/mfd/arizona*
10460 F: drivers/mfd/wm*.c 10461 F: drivers/mfd/wm*.c
10461 F: drivers/power/wm83*.c 10462 F: drivers/power/wm83*.c
10462 F: drivers/rtc/rtc-wm83*.c 10463 F: drivers/rtc/rtc-wm83*.c
10463 F: drivers/regulator/wm8*.c 10464 F: drivers/regulator/wm8*.c
10464 F: drivers/video/backlight/wm83*_bl.c 10465 F: drivers/video/backlight/wm83*_bl.c
10465 F: drivers/watchdog/wm83*_wdt.c 10466 F: drivers/watchdog/wm83*_wdt.c
10466 F: include/linux/mfd/arizona/ 10467 F: include/linux/mfd/arizona/
10467 F: include/linux/mfd/wm831x/ 10468 F: include/linux/mfd/wm831x/
10468 F: include/linux/mfd/wm8350/ 10469 F: include/linux/mfd/wm8350/
10469 F: include/linux/mfd/wm8400* 10470 F: include/linux/mfd/wm8400*
10470 F: include/linux/wm97xx.h 10471 F: include/linux/wm97xx.h
10471 F: include/sound/wm????.h 10472 F: include/sound/wm????.h
10472 F: sound/soc/codecs/arizona.? 10473 F: sound/soc/codecs/arizona.?
10473 F: sound/soc/codecs/wm* 10474 F: sound/soc/codecs/wm*
10474 10475
10475 WORKQUEUE 10476 WORKQUEUE
10476 M: Tejun Heo <tj@kernel.org> 10477 M: Tejun Heo <tj@kernel.org>
10477 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq.git 10478 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq.git
10478 S: Maintained 10479 S: Maintained
10479 F: include/linux/workqueue.h 10480 F: include/linux/workqueue.h
10480 F: kernel/workqueue.c 10481 F: kernel/workqueue.c
10481 F: Documentation/workqueue.txt 10482 F: Documentation/workqueue.txt
10482 10483
10483 X.25 NETWORK LAYER 10484 X.25 NETWORK LAYER
10484 M: Andrew Hendry <andrew.hendry@gmail.com> 10485 M: Andrew Hendry <andrew.hendry@gmail.com>
10485 L: linux-x25@vger.kernel.org 10486 L: linux-x25@vger.kernel.org
10486 S: Odd Fixes 10487 S: Odd Fixes
10487 F: Documentation/networking/x25* 10488 F: Documentation/networking/x25*
10488 F: include/net/x25* 10489 F: include/net/x25*
10489 F: net/x25/ 10490 F: net/x25/
10490 10491
10491 X86 ARCHITECTURE (32-BIT AND 64-BIT) 10492 X86 ARCHITECTURE (32-BIT AND 64-BIT)
10492 M: Thomas Gleixner <tglx@linutronix.de> 10493 M: Thomas Gleixner <tglx@linutronix.de>
10493 M: Ingo Molnar <mingo@redhat.com> 10494 M: Ingo Molnar <mingo@redhat.com>
10494 M: "H. Peter Anvin" <hpa@zytor.com> 10495 M: "H. Peter Anvin" <hpa@zytor.com>
10495 M: x86@kernel.org 10496 M: x86@kernel.org
10496 L: linux-kernel@vger.kernel.org 10497 L: linux-kernel@vger.kernel.org
10497 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86/core 10498 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86/core
10498 S: Maintained 10499 S: Maintained
10499 F: Documentation/x86/ 10500 F: Documentation/x86/
10500 F: arch/x86/ 10501 F: arch/x86/
10501 10502
10502 X86 PLATFORM DRIVERS 10503 X86 PLATFORM DRIVERS
10503 M: Darren Hart <dvhart@infradead.org> 10504 M: Darren Hart <dvhart@infradead.org>
10504 L: platform-driver-x86@vger.kernel.org 10505 L: platform-driver-x86@vger.kernel.org
10505 T: git git://git.infradead.org/users/dvhart/linux-platform-drivers-x86.git 10506 T: git git://git.infradead.org/users/dvhart/linux-platform-drivers-x86.git
10506 S: Maintained 10507 S: Maintained
10507 F: drivers/platform/x86/ 10508 F: drivers/platform/x86/
10508 10509
10509 X86 MCE INFRASTRUCTURE 10510 X86 MCE INFRASTRUCTURE
10510 M: Tony Luck <tony.luck@intel.com> 10511 M: Tony Luck <tony.luck@intel.com>
10511 M: Borislav Petkov <bp@alien8.de> 10512 M: Borislav Petkov <bp@alien8.de>
10512 L: linux-edac@vger.kernel.org 10513 L: linux-edac@vger.kernel.org
10513 S: Maintained 10514 S: Maintained
10514 F: arch/x86/kernel/cpu/mcheck/* 10515 F: arch/x86/kernel/cpu/mcheck/*
10515 10516
10516 X86 VDSO 10517 X86 VDSO
10517 M: Andy Lutomirski <luto@amacapital.net> 10518 M: Andy Lutomirski <luto@amacapital.net>
10518 L: linux-kernel@vger.kernel.org 10519 L: linux-kernel@vger.kernel.org
10519 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86/vdso 10520 T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86/vdso
10520 S: Maintained 10521 S: Maintained
10521 F: arch/x86/vdso/ 10522 F: arch/x86/vdso/
10522 10523
10523 XC2028/3028 TUNER DRIVER 10524 XC2028/3028 TUNER DRIVER
10524 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com> 10525 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
10525 L: linux-media@vger.kernel.org 10526 L: linux-media@vger.kernel.org
10526 W: http://linuxtv.org 10527 W: http://linuxtv.org
10527 T: git git://linuxtv.org/media_tree.git 10528 T: git git://linuxtv.org/media_tree.git
10528 S: Maintained 10529 S: Maintained
10529 F: drivers/media/tuners/tuner-xc2028.* 10530 F: drivers/media/tuners/tuner-xc2028.*
10530 10531
10531 XEN HYPERVISOR INTERFACE 10532 XEN HYPERVISOR INTERFACE
10532 M: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> 10533 M: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
10533 M: Boris Ostrovsky <boris.ostrovsky@oracle.com> 10534 M: Boris Ostrovsky <boris.ostrovsky@oracle.com>
10534 M: David Vrabel <david.vrabel@citrix.com> 10535 M: David Vrabel <david.vrabel@citrix.com>
10535 L: xen-devel@lists.xenproject.org (moderated for non-subscribers) 10536 L: xen-devel@lists.xenproject.org (moderated for non-subscribers)
10536 T: git git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip.git 10537 T: git git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip.git
10537 S: Supported 10538 S: Supported
10538 F: arch/x86/xen/ 10539 F: arch/x86/xen/
10539 F: drivers/*/xen-*front.c 10540 F: drivers/*/xen-*front.c
10540 F: drivers/xen/ 10541 F: drivers/xen/
10541 F: arch/x86/include/asm/xen/ 10542 F: arch/x86/include/asm/xen/
10542 F: include/xen/ 10543 F: include/xen/
10543 F: include/uapi/xen/ 10544 F: include/uapi/xen/
10544 10545
10545 XEN HYPERVISOR ARM 10546 XEN HYPERVISOR ARM
10546 M: Stefano Stabellini <stefano.stabellini@eu.citrix.com> 10547 M: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
10547 L: xen-devel@lists.xenproject.org (moderated for non-subscribers) 10548 L: xen-devel@lists.xenproject.org (moderated for non-subscribers)
10548 S: Supported 10549 S: Supported
10549 F: arch/arm/xen/ 10550 F: arch/arm/xen/
10550 F: arch/arm/include/asm/xen/ 10551 F: arch/arm/include/asm/xen/
10551 10552
10552 XEN HYPERVISOR ARM64 10553 XEN HYPERVISOR ARM64
10553 M: Stefano Stabellini <stefano.stabellini@eu.citrix.com> 10554 M: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
10554 L: xen-devel@lists.xenproject.org (moderated for non-subscribers) 10555 L: xen-devel@lists.xenproject.org (moderated for non-subscribers)
10555 S: Supported 10556 S: Supported
10556 F: arch/arm64/xen/ 10557 F: arch/arm64/xen/
10557 F: arch/arm64/include/asm/xen/ 10558 F: arch/arm64/include/asm/xen/
10558 10559
10559 XEN NETWORK BACKEND DRIVER 10560 XEN NETWORK BACKEND DRIVER
10560 M: Ian Campbell <ian.campbell@citrix.com> 10561 M: Ian Campbell <ian.campbell@citrix.com>
10561 M: Wei Liu <wei.liu2@citrix.com> 10562 M: Wei Liu <wei.liu2@citrix.com>
10562 L: xen-devel@lists.xenproject.org (moderated for non-subscribers) 10563 L: xen-devel@lists.xenproject.org (moderated for non-subscribers)
10563 L: netdev@vger.kernel.org 10564 L: netdev@vger.kernel.org
10564 S: Supported 10565 S: Supported
10565 F: drivers/net/xen-netback/* 10566 F: drivers/net/xen-netback/*
10566 10567
10567 XEN PCI SUBSYSTEM 10568 XEN PCI SUBSYSTEM
10568 M: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> 10569 M: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
10569 L: xen-devel@lists.xenproject.org (moderated for non-subscribers) 10570 L: xen-devel@lists.xenproject.org (moderated for non-subscribers)
10570 S: Supported 10571 S: Supported
10571 F: arch/x86/pci/*xen* 10572 F: arch/x86/pci/*xen*
10572 F: drivers/pci/*xen* 10573 F: drivers/pci/*xen*
10573 10574
10574 XEN BLOCK SUBSYSTEM 10575 XEN BLOCK SUBSYSTEM
10575 M: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> 10576 M: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
10576 L: xen-devel@lists.xenproject.org (moderated for non-subscribers) 10577 L: xen-devel@lists.xenproject.org (moderated for non-subscribers)
10577 S: Supported 10578 S: Supported
10578 F: drivers/block/xen-blkback/* 10579 F: drivers/block/xen-blkback/*
10579 F: drivers/block/xen* 10580 F: drivers/block/xen*
10580 10581
10581 XEN PVSCSI DRIVERS 10582 XEN PVSCSI DRIVERS
10582 M: Juergen Gross <jgross@suse.com> 10583 M: Juergen Gross <jgross@suse.com>
10583 L: xen-devel@lists.xenproject.org (moderated for non-subscribers) 10584 L: xen-devel@lists.xenproject.org (moderated for non-subscribers)
10584 L: linux-scsi@vger.kernel.org 10585 L: linux-scsi@vger.kernel.org
10585 S: Supported 10586 S: Supported
10586 F: drivers/scsi/xen-scsifront.c 10587 F: drivers/scsi/xen-scsifront.c
10587 F: drivers/xen/xen-scsiback.c 10588 F: drivers/xen/xen-scsiback.c
10588 F: include/xen/interface/io/vscsiif.h 10589 F: include/xen/interface/io/vscsiif.h
10589 10590
10590 XEN SWIOTLB SUBSYSTEM 10591 XEN SWIOTLB SUBSYSTEM
10591 M: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> 10592 M: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
10592 L: xen-devel@lists.xenproject.org (moderated for non-subscribers) 10593 L: xen-devel@lists.xenproject.org (moderated for non-subscribers)
10593 S: Supported 10594 S: Supported
10594 F: arch/x86/xen/*swiotlb* 10595 F: arch/x86/xen/*swiotlb*
10595 F: drivers/xen/*swiotlb* 10596 F: drivers/xen/*swiotlb*
10596 10597
10597 XFS FILESYSTEM 10598 XFS FILESYSTEM
10598 P: Silicon Graphics Inc 10599 P: Silicon Graphics Inc
10599 M: Dave Chinner <david@fromorbit.com> 10600 M: Dave Chinner <david@fromorbit.com>
10600 M: xfs@oss.sgi.com 10601 M: xfs@oss.sgi.com
10601 L: xfs@oss.sgi.com 10602 L: xfs@oss.sgi.com
10602 W: http://oss.sgi.com/projects/xfs 10603 W: http://oss.sgi.com/projects/xfs
10603 T: git git://oss.sgi.com/xfs/xfs.git 10604 T: git git://oss.sgi.com/xfs/xfs.git
10604 S: Supported 10605 S: Supported
10605 F: Documentation/filesystems/xfs.txt 10606 F: Documentation/filesystems/xfs.txt
10606 F: fs/xfs/ 10607 F: fs/xfs/
10607 10608
10608 XILINX AXI ETHERNET DRIVER 10609 XILINX AXI ETHERNET DRIVER
10609 M: Anirudha Sarangi <anirudh@xilinx.com> 10610 M: Anirudha Sarangi <anirudh@xilinx.com>
10610 M: John Linn <John.Linn@xilinx.com> 10611 M: John Linn <John.Linn@xilinx.com>
10611 S: Maintained 10612 S: Maintained
10612 F: drivers/net/ethernet/xilinx/xilinx_axienet* 10613 F: drivers/net/ethernet/xilinx/xilinx_axienet*
10613 10614
10614 XILINX UARTLITE SERIAL DRIVER 10615 XILINX UARTLITE SERIAL DRIVER
10615 M: Peter Korsgaard <jacmet@sunsite.dk> 10616 M: Peter Korsgaard <jacmet@sunsite.dk>
10616 L: linux-serial@vger.kernel.org 10617 L: linux-serial@vger.kernel.org
10617 S: Maintained 10618 S: Maintained
10618 F: drivers/tty/serial/uartlite.c 10619 F: drivers/tty/serial/uartlite.c
10619 10620
10620 XILLYBUS DRIVER 10621 XILLYBUS DRIVER
10621 M: Eli Billauer <eli.billauer@gmail.com> 10622 M: Eli Billauer <eli.billauer@gmail.com>
10622 L: linux-kernel@vger.kernel.org 10623 L: linux-kernel@vger.kernel.org
10623 S: Supported 10624 S: Supported
10624 F: drivers/char/xillybus/ 10625 F: drivers/char/xillybus/
10625 10626
10626 XTENSA XTFPGA PLATFORM SUPPORT 10627 XTENSA XTFPGA PLATFORM SUPPORT
10627 M: Max Filippov <jcmvbkbc@gmail.com> 10628 M: Max Filippov <jcmvbkbc@gmail.com>
10628 L: linux-xtensa@linux-xtensa.org 10629 L: linux-xtensa@linux-xtensa.org
10629 S: Maintained 10630 S: Maintained
10630 F: drivers/spi/spi-xtensa-xtfpga.c 10631 F: drivers/spi/spi-xtensa-xtfpga.c
10631 10632
10632 YAM DRIVER FOR AX.25 10633 YAM DRIVER FOR AX.25
10633 M: Jean-Paul Roubelat <jpr@f6fbb.org> 10634 M: Jean-Paul Roubelat <jpr@f6fbb.org>
10634 L: linux-hams@vger.kernel.org 10635 L: linux-hams@vger.kernel.org
10635 S: Maintained 10636 S: Maintained
10636 F: drivers/net/hamradio/yam* 10637 F: drivers/net/hamradio/yam*
10637 F: include/linux/yam.h 10638 F: include/linux/yam.h
10638 10639
10639 YEALINK PHONE DRIVER 10640 YEALINK PHONE DRIVER
10640 M: Henk Vergonet <Henk.Vergonet@gmail.com> 10641 M: Henk Vergonet <Henk.Vergonet@gmail.com>
10641 L: usbb2k-api-dev@nongnu.org 10642 L: usbb2k-api-dev@nongnu.org
10642 S: Maintained 10643 S: Maintained
10643 F: Documentation/input/yealink.txt 10644 F: Documentation/input/yealink.txt
10644 F: drivers/input/misc/yealink.* 10645 F: drivers/input/misc/yealink.*
10645 10646
10646 Z8530 DRIVER FOR AX.25 10647 Z8530 DRIVER FOR AX.25
10647 M: Joerg Reuter <jreuter@yaina.de> 10648 M: Joerg Reuter <jreuter@yaina.de>
10648 W: http://yaina.de/jreuter/ 10649 W: http://yaina.de/jreuter/
10649 W: http://www.qsl.net/dl1bke/ 10650 W: http://www.qsl.net/dl1bke/
10650 L: linux-hams@vger.kernel.org 10651 L: linux-hams@vger.kernel.org
10651 S: Maintained 10652 S: Maintained
10652 F: Documentation/networking/z8530drv.txt 10653 F: Documentation/networking/z8530drv.txt
10653 F: drivers/net/hamradio/*scc.c 10654 F: drivers/net/hamradio/*scc.c
10654 F: drivers/net/hamradio/z8530.h 10655 F: drivers/net/hamradio/z8530.h
10655 10656
10656 ZBUD COMPRESSED PAGE ALLOCATOR 10657 ZBUD COMPRESSED PAGE ALLOCATOR
10657 M: Seth Jennings <sjennings@variantweb.net> 10658 M: Seth Jennings <sjennings@variantweb.net>
10658 L: linux-mm@kvack.org 10659 L: linux-mm@kvack.org
10659 S: Maintained 10660 S: Maintained
10660 F: mm/zbud.c 10661 F: mm/zbud.c
10661 F: include/linux/zbud.h 10662 F: include/linux/zbud.h
10662 10663
10663 ZD1211RW WIRELESS DRIVER 10664 ZD1211RW WIRELESS DRIVER
10664 M: Daniel Drake <dsd@gentoo.org> 10665 M: Daniel Drake <dsd@gentoo.org>
10665 M: Ulrich Kunitz <kune@deine-taler.de> 10666 M: Ulrich Kunitz <kune@deine-taler.de>
10666 W: http://zd1211.ath.cx/wiki/DriverRewrite 10667 W: http://zd1211.ath.cx/wiki/DriverRewrite
10667 L: linux-wireless@vger.kernel.org 10668 L: linux-wireless@vger.kernel.org
10668 L: zd1211-devs@lists.sourceforge.net (subscribers-only) 10669 L: zd1211-devs@lists.sourceforge.net (subscribers-only)
10669 S: Maintained 10670 S: Maintained
10670 F: drivers/net/wireless/zd1211rw/ 10671 F: drivers/net/wireless/zd1211rw/
10671 10672
10672 ZR36067 VIDEO FOR LINUX DRIVER 10673 ZR36067 VIDEO FOR LINUX DRIVER
10673 L: mjpeg-users@lists.sourceforge.net 10674 L: mjpeg-users@lists.sourceforge.net
10674 L: linux-media@vger.kernel.org 10675 L: linux-media@vger.kernel.org
10675 W: http://mjpeg.sourceforge.net/driver-zoran/ 10676 W: http://mjpeg.sourceforge.net/driver-zoran/
10676 T: hg http://linuxtv.org/hg/v4l-dvb 10677 T: hg http://linuxtv.org/hg/v4l-dvb
10677 S: Odd Fixes 10678 S: Odd Fixes
10678 F: drivers/media/pci/zoran/ 10679 F: drivers/media/pci/zoran/
10679 10680
10680 ZRAM COMPRESSED RAM BLOCK DEVICE DRVIER 10681 ZRAM COMPRESSED RAM BLOCK DEVICE DRVIER
10681 M: Minchan Kim <minchan@kernel.org> 10682 M: Minchan Kim <minchan@kernel.org>
10682 M: Nitin Gupta <ngupta@vflare.org> 10683 M: Nitin Gupta <ngupta@vflare.org>
10683 L: linux-kernel@vger.kernel.org 10684 L: linux-kernel@vger.kernel.org
10684 S: Maintained 10685 S: Maintained
10685 F: drivers/block/zram/ 10686 F: drivers/block/zram/
10686 F: Documentation/blockdev/zram.txt 10687 F: Documentation/blockdev/zram.txt
10687 10688
10688 ZS DECSTATION Z85C30 SERIAL DRIVER 10689 ZS DECSTATION Z85C30 SERIAL DRIVER
10689 M: "Maciej W. Rozycki" <macro@linux-mips.org> 10690 M: "Maciej W. Rozycki" <macro@linux-mips.org>
10690 S: Maintained 10691 S: Maintained
10691 F: drivers/tty/serial/zs.* 10692 F: drivers/tty/serial/zs.*
10692 10693
10693 ZSMALLOC COMPRESSED SLAB MEMORY ALLOCATOR 10694 ZSMALLOC COMPRESSED SLAB MEMORY ALLOCATOR
10694 M: Minchan Kim <minchan@kernel.org> 10695 M: Minchan Kim <minchan@kernel.org>
10695 M: Nitin Gupta <ngupta@vflare.org> 10696 M: Nitin Gupta <ngupta@vflare.org>
10696 L: linux-mm@kvack.org 10697 L: linux-mm@kvack.org
10697 S: Maintained 10698 S: Maintained
10698 F: mm/zsmalloc.c 10699 F: mm/zsmalloc.c
10699 F: include/linux/zsmalloc.h 10700 F: include/linux/zsmalloc.h
10700 10701
10701 ZSWAP COMPRESSED SWAP CACHING 10702 ZSWAP COMPRESSED SWAP CACHING
10702 M: Seth Jennings <sjennings@variantweb.net> 10703 M: Seth Jennings <sjennings@variantweb.net>
10703 L: linux-mm@kvack.org 10704 L: linux-mm@kvack.org
10704 S: Maintained 10705 S: Maintained
10705 F: mm/zswap.c 10706 F: mm/zswap.c
10706 10707
10707 THE REST 10708 THE REST
10708 M: Linus Torvalds <torvalds@linux-foundation.org> 10709 M: Linus Torvalds <torvalds@linux-foundation.org>
10709 L: linux-kernel@vger.kernel.org 10710 L: linux-kernel@vger.kernel.org
10710 Q: http://patchwork.kernel.org/project/LKML/list/ 10711 Q: http://patchwork.kernel.org/project/LKML/list/
10711 T: git git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 10712 T: git git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
10712 S: Buried alive in reporters 10713 S: Buried alive in reporters
10713 F: * 10714 F: *
10714 F: */ 10715 F: */
10715 10716
1 /* 1 /*
2 * Copyright (C) 2011 STRATO. All rights reserved. 2 * Copyright (C) 2011 STRATO. All rights reserved.
3 * 3 *
4 * This program is free software; you can redistribute it and/or 4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public 5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation. 6 * License v2 as published by the Free Software Foundation.
7 * 7 *
8 * This program is distributed in the hope that it will be useful, 8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details. 11 * General Public License for more details.
12 * 12 *
13 * You should have received a copy of the GNU General Public 13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the 14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 * Boston, MA 021110-1307, USA. 16 * Boston, MA 021110-1307, USA.
17 */ 17 */
18 18
19 #include <linux/vmalloc.h> 19 #include <linux/vmalloc.h>
20 #include "ctree.h" 20 #include "ctree.h"
21 #include "disk-io.h" 21 #include "disk-io.h"
22 #include "backref.h" 22 #include "backref.h"
23 #include "ulist.h" 23 #include "ulist.h"
24 #include "transaction.h" 24 #include "transaction.h"
25 #include "delayed-ref.h" 25 #include "delayed-ref.h"
26 #include "locking.h" 26 #include "locking.h"
27 27
28 /* Just an arbitrary number so we can be sure this happened */ 28 /* Just an arbitrary number so we can be sure this happened */
29 #define BACKREF_FOUND_SHARED 6 29 #define BACKREF_FOUND_SHARED 6
30 30
31 struct extent_inode_elem { 31 struct extent_inode_elem {
32 u64 inum; 32 u64 inum;
33 u64 offset; 33 u64 offset;
34 struct extent_inode_elem *next; 34 struct extent_inode_elem *next;
35 }; 35 };
36 36
37 static int check_extent_in_eb(struct btrfs_key *key, struct extent_buffer *eb, 37 static int check_extent_in_eb(struct btrfs_key *key, struct extent_buffer *eb,
38 struct btrfs_file_extent_item *fi, 38 struct btrfs_file_extent_item *fi,
39 u64 extent_item_pos, 39 u64 extent_item_pos,
40 struct extent_inode_elem **eie) 40 struct extent_inode_elem **eie)
41 { 41 {
42 u64 offset = 0; 42 u64 offset = 0;
43 struct extent_inode_elem *e; 43 struct extent_inode_elem *e;
44 44
45 if (!btrfs_file_extent_compression(eb, fi) && 45 if (!btrfs_file_extent_compression(eb, fi) &&
46 !btrfs_file_extent_encryption(eb, fi) && 46 !btrfs_file_extent_encryption(eb, fi) &&
47 !btrfs_file_extent_other_encoding(eb, fi)) { 47 !btrfs_file_extent_other_encoding(eb, fi)) {
48 u64 data_offset; 48 u64 data_offset;
49 u64 data_len; 49 u64 data_len;
50 50
51 data_offset = btrfs_file_extent_offset(eb, fi); 51 data_offset = btrfs_file_extent_offset(eb, fi);
52 data_len = btrfs_file_extent_num_bytes(eb, fi); 52 data_len = btrfs_file_extent_num_bytes(eb, fi);
53 53
54 if (extent_item_pos < data_offset || 54 if (extent_item_pos < data_offset ||
55 extent_item_pos >= data_offset + data_len) 55 extent_item_pos >= data_offset + data_len)
56 return 1; 56 return 1;
57 offset = extent_item_pos - data_offset; 57 offset = extent_item_pos - data_offset;
58 } 58 }
59 59
60 e = kmalloc(sizeof(*e), GFP_NOFS); 60 e = kmalloc(sizeof(*e), GFP_NOFS);
61 if (!e) 61 if (!e)
62 return -ENOMEM; 62 return -ENOMEM;
63 63
64 e->next = *eie; 64 e->next = *eie;
65 e->inum = key->objectid; 65 e->inum = key->objectid;
66 e->offset = key->offset + offset; 66 e->offset = key->offset + offset;
67 *eie = e; 67 *eie = e;
68 68
69 return 0; 69 return 0;
70 } 70 }
71 71
72 static void free_inode_elem_list(struct extent_inode_elem *eie) 72 static void free_inode_elem_list(struct extent_inode_elem *eie)
73 { 73 {
74 struct extent_inode_elem *eie_next; 74 struct extent_inode_elem *eie_next;
75 75
76 for (; eie; eie = eie_next) { 76 for (; eie; eie = eie_next) {
77 eie_next = eie->next; 77 eie_next = eie->next;
78 kfree(eie); 78 kfree(eie);
79 } 79 }
80 } 80 }
81 81
82 static int find_extent_in_eb(struct extent_buffer *eb, u64 wanted_disk_byte, 82 static int find_extent_in_eb(struct extent_buffer *eb, u64 wanted_disk_byte,
83 u64 extent_item_pos, 83 u64 extent_item_pos,
84 struct extent_inode_elem **eie) 84 struct extent_inode_elem **eie)
85 { 85 {
86 u64 disk_byte; 86 u64 disk_byte;
87 struct btrfs_key key; 87 struct btrfs_key key;
88 struct btrfs_file_extent_item *fi; 88 struct btrfs_file_extent_item *fi;
89 int slot; 89 int slot;
90 int nritems; 90 int nritems;
91 int extent_type; 91 int extent_type;
92 int ret; 92 int ret;
93 93
94 /* 94 /*
95 * from the shared data ref, we only have the leaf but we need 95 * from the shared data ref, we only have the leaf but we need
96 * the key. thus, we must look into all items and see that we 96 * the key. thus, we must look into all items and see that we
97 * find one (some) with a reference to our extent item. 97 * find one (some) with a reference to our extent item.
98 */ 98 */
99 nritems = btrfs_header_nritems(eb); 99 nritems = btrfs_header_nritems(eb);
100 for (slot = 0; slot < nritems; ++slot) { 100 for (slot = 0; slot < nritems; ++slot) {
101 btrfs_item_key_to_cpu(eb, &key, slot); 101 btrfs_item_key_to_cpu(eb, &key, slot);
102 if (key.type != BTRFS_EXTENT_DATA_KEY) 102 if (key.type != BTRFS_EXTENT_DATA_KEY)
103 continue; 103 continue;
104 fi = btrfs_item_ptr(eb, slot, struct btrfs_file_extent_item); 104 fi = btrfs_item_ptr(eb, slot, struct btrfs_file_extent_item);
105 extent_type = btrfs_file_extent_type(eb, fi); 105 extent_type = btrfs_file_extent_type(eb, fi);
106 if (extent_type == BTRFS_FILE_EXTENT_INLINE) 106 if (extent_type == BTRFS_FILE_EXTENT_INLINE)
107 continue; 107 continue;
108 /* don't skip BTRFS_FILE_EXTENT_PREALLOC, we can handle that */ 108 /* don't skip BTRFS_FILE_EXTENT_PREALLOC, we can handle that */
109 disk_byte = btrfs_file_extent_disk_bytenr(eb, fi); 109 disk_byte = btrfs_file_extent_disk_bytenr(eb, fi);
110 if (disk_byte != wanted_disk_byte) 110 if (disk_byte != wanted_disk_byte)
111 continue; 111 continue;
112 112
113 ret = check_extent_in_eb(&key, eb, fi, extent_item_pos, eie); 113 ret = check_extent_in_eb(&key, eb, fi, extent_item_pos, eie);
114 if (ret < 0) 114 if (ret < 0)
115 return ret; 115 return ret;
116 } 116 }
117 117
118 return 0; 118 return 0;
119 } 119 }
120 120
121 /* 121 /*
122 * this structure records all encountered refs on the way up to the root 122 * this structure records all encountered refs on the way up to the root
123 */ 123 */
124 struct __prelim_ref { 124 struct __prelim_ref {
125 struct list_head list; 125 struct list_head list;
126 u64 root_id; 126 u64 root_id;
127 struct btrfs_key key_for_search; 127 struct btrfs_key key_for_search;
128 int level; 128 int level;
129 int count; 129 int count;
130 struct extent_inode_elem *inode_list; 130 struct extent_inode_elem *inode_list;
131 u64 parent; 131 u64 parent;
132 u64 wanted_disk_byte; 132 u64 wanted_disk_byte;
133 }; 133 };
134 134
135 static struct kmem_cache *btrfs_prelim_ref_cache; 135 static struct kmem_cache *btrfs_prelim_ref_cache;
136 136
137 int __init btrfs_prelim_ref_init(void) 137 int __init btrfs_prelim_ref_init(void)
138 { 138 {
139 btrfs_prelim_ref_cache = kmem_cache_create("btrfs_prelim_ref", 139 btrfs_prelim_ref_cache = kmem_cache_create("btrfs_prelim_ref",
140 sizeof(struct __prelim_ref), 140 sizeof(struct __prelim_ref),
141 0, 141 0,
142 SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, 142 SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD,
143 NULL); 143 NULL);
144 if (!btrfs_prelim_ref_cache) 144 if (!btrfs_prelim_ref_cache)
145 return -ENOMEM; 145 return -ENOMEM;
146 return 0; 146 return 0;
147 } 147 }
148 148
149 void btrfs_prelim_ref_exit(void) 149 void btrfs_prelim_ref_exit(void)
150 { 150 {
151 if (btrfs_prelim_ref_cache) 151 if (btrfs_prelim_ref_cache)
152 kmem_cache_destroy(btrfs_prelim_ref_cache); 152 kmem_cache_destroy(btrfs_prelim_ref_cache);
153 } 153 }
154 154
155 /* 155 /*
156 * the rules for all callers of this function are: 156 * the rules for all callers of this function are:
157 * - obtaining the parent is the goal 157 * - obtaining the parent is the goal
158 * - if you add a key, you must know that it is a correct key 158 * - if you add a key, you must know that it is a correct key
159 * - if you cannot add the parent or a correct key, then we will look into the 159 * - if you cannot add the parent or a correct key, then we will look into the
160 * block later to set a correct key 160 * block later to set a correct key
161 * 161 *
162 * delayed refs 162 * delayed refs
163 * ============ 163 * ============
164 * backref type | shared | indirect | shared | indirect 164 * backref type | shared | indirect | shared | indirect
165 * information | tree | tree | data | data 165 * information | tree | tree | data | data
166 * --------------------+--------+----------+--------+---------- 166 * --------------------+--------+----------+--------+----------
167 * parent logical | y | - | - | - 167 * parent logical | y | - | - | -
168 * key to resolve | - | y | y | y 168 * key to resolve | - | y | y | y
169 * tree block logical | - | - | - | - 169 * tree block logical | - | - | - | -
170 * root for resolving | y | y | y | y 170 * root for resolving | y | y | y | y
171 * 171 *
172 * - column 1: we've the parent -> done 172 * - column 1: we've the parent -> done
173 * - column 2, 3, 4: we use the key to find the parent 173 * - column 2, 3, 4: we use the key to find the parent
174 * 174 *
175 * on disk refs (inline or keyed) 175 * on disk refs (inline or keyed)
176 * ============================== 176 * ==============================
177 * backref type | shared | indirect | shared | indirect 177 * backref type | shared | indirect | shared | indirect
178 * information | tree | tree | data | data 178 * information | tree | tree | data | data
179 * --------------------+--------+----------+--------+---------- 179 * --------------------+--------+----------+--------+----------
180 * parent logical | y | - | y | - 180 * parent logical | y | - | y | -
181 * key to resolve | - | - | - | y 181 * key to resolve | - | - | - | y
182 * tree block logical | y | y | y | y 182 * tree block logical | y | y | y | y
183 * root for resolving | - | y | y | y 183 * root for resolving | - | y | y | y
184 * 184 *
185 * - column 1, 3: we've the parent -> done 185 * - column 1, 3: we've the parent -> done
186 * - column 2: we take the first key from the block to find the parent 186 * - column 2: we take the first key from the block to find the parent
187 * (see __add_missing_keys) 187 * (see __add_missing_keys)
188 * - column 4: we use the key to find the parent 188 * - column 4: we use the key to find the parent
189 * 189 *
190 * additional information that's available but not required to find the parent 190 * additional information that's available but not required to find the parent
191 * block might help in merging entries to gain some speed. 191 * block might help in merging entries to gain some speed.
192 */ 192 */
193 193
194 static int __add_prelim_ref(struct list_head *head, u64 root_id, 194 static int __add_prelim_ref(struct list_head *head, u64 root_id,
195 struct btrfs_key *key, int level, 195 struct btrfs_key *key, int level,
196 u64 parent, u64 wanted_disk_byte, int count, 196 u64 parent, u64 wanted_disk_byte, int count,
197 gfp_t gfp_mask) 197 gfp_t gfp_mask)
198 { 198 {
199 struct __prelim_ref *ref; 199 struct __prelim_ref *ref;
200 200
201 if (root_id == BTRFS_DATA_RELOC_TREE_OBJECTID) 201 if (root_id == BTRFS_DATA_RELOC_TREE_OBJECTID)
202 return 0; 202 return 0;
203 203
204 ref = kmem_cache_alloc(btrfs_prelim_ref_cache, gfp_mask); 204 ref = kmem_cache_alloc(btrfs_prelim_ref_cache, gfp_mask);
205 if (!ref) 205 if (!ref)
206 return -ENOMEM; 206 return -ENOMEM;
207 207
208 ref->root_id = root_id; 208 ref->root_id = root_id;
209 if (key) 209 if (key)
210 ref->key_for_search = *key; 210 ref->key_for_search = *key;
211 else 211 else
212 memset(&ref->key_for_search, 0, sizeof(ref->key_for_search)); 212 memset(&ref->key_for_search, 0, sizeof(ref->key_for_search));
213 213
214 ref->inode_list = NULL; 214 ref->inode_list = NULL;
215 ref->level = level; 215 ref->level = level;
216 ref->count = count; 216 ref->count = count;
217 ref->parent = parent; 217 ref->parent = parent;
218 ref->wanted_disk_byte = wanted_disk_byte; 218 ref->wanted_disk_byte = wanted_disk_byte;
219 list_add_tail(&ref->list, head); 219 list_add_tail(&ref->list, head);
220 220
221 return 0; 221 return 0;
222 } 222 }
223 223
224 static int add_all_parents(struct btrfs_root *root, struct btrfs_path *path, 224 static int add_all_parents(struct btrfs_root *root, struct btrfs_path *path,
225 struct ulist *parents, struct __prelim_ref *ref, 225 struct ulist *parents, struct __prelim_ref *ref,
226 int level, u64 time_seq, const u64 *extent_item_pos, 226 int level, u64 time_seq, const u64 *extent_item_pos,
227 u64 total_refs) 227 u64 total_refs)
228 { 228 {
229 int ret = 0; 229 int ret = 0;
230 int slot; 230 int slot;
231 struct extent_buffer *eb; 231 struct extent_buffer *eb;
232 struct btrfs_key key; 232 struct btrfs_key key;
233 struct btrfs_key *key_for_search = &ref->key_for_search; 233 struct btrfs_key *key_for_search = &ref->key_for_search;
234 struct btrfs_file_extent_item *fi; 234 struct btrfs_file_extent_item *fi;
235 struct extent_inode_elem *eie = NULL, *old = NULL; 235 struct extent_inode_elem *eie = NULL, *old = NULL;
236 u64 disk_byte; 236 u64 disk_byte;
237 u64 wanted_disk_byte = ref->wanted_disk_byte; 237 u64 wanted_disk_byte = ref->wanted_disk_byte;
238 u64 count = 0; 238 u64 count = 0;
239 239
240 if (level != 0) { 240 if (level != 0) {
241 eb = path->nodes[level]; 241 eb = path->nodes[level];
242 ret = ulist_add(parents, eb->start, 0, GFP_NOFS); 242 ret = ulist_add(parents, eb->start, 0, GFP_NOFS);
243 if (ret < 0) 243 if (ret < 0)
244 return ret; 244 return ret;
245 return 0; 245 return 0;
246 } 246 }
247 247
248 /* 248 /*
249 * We normally enter this function with the path already pointing to 249 * We normally enter this function with the path already pointing to
250 * the first item to check. But sometimes, we may enter it with 250 * the first item to check. But sometimes, we may enter it with
251 * slot==nritems. In that case, go to the next leaf before we continue. 251 * slot==nritems. In that case, go to the next leaf before we continue.
252 */ 252 */
253 if (path->slots[0] >= btrfs_header_nritems(path->nodes[0])) 253 if (path->slots[0] >= btrfs_header_nritems(path->nodes[0]))
254 ret = btrfs_next_old_leaf(root, path, time_seq); 254 ret = btrfs_next_old_leaf(root, path, time_seq);
255 255
256 while (!ret && count < total_refs) { 256 while (!ret && count < total_refs) {
257 eb = path->nodes[0]; 257 eb = path->nodes[0];
258 slot = path->slots[0]; 258 slot = path->slots[0];
259 259
260 btrfs_item_key_to_cpu(eb, &key, slot); 260 btrfs_item_key_to_cpu(eb, &key, slot);
261 261
262 if (key.objectid != key_for_search->objectid || 262 if (key.objectid != key_for_search->objectid ||
263 key.type != BTRFS_EXTENT_DATA_KEY) 263 key.type != BTRFS_EXTENT_DATA_KEY)
264 break; 264 break;
265 265
266 fi = btrfs_item_ptr(eb, slot, struct btrfs_file_extent_item); 266 fi = btrfs_item_ptr(eb, slot, struct btrfs_file_extent_item);
267 disk_byte = btrfs_file_extent_disk_bytenr(eb, fi); 267 disk_byte = btrfs_file_extent_disk_bytenr(eb, fi);
268 268
269 if (disk_byte == wanted_disk_byte) { 269 if (disk_byte == wanted_disk_byte) {
270 eie = NULL; 270 eie = NULL;
271 old = NULL; 271 old = NULL;
272 count++; 272 count++;
273 if (extent_item_pos) { 273 if (extent_item_pos) {
274 ret = check_extent_in_eb(&key, eb, fi, 274 ret = check_extent_in_eb(&key, eb, fi,
275 *extent_item_pos, 275 *extent_item_pos,
276 &eie); 276 &eie);
277 if (ret < 0) 277 if (ret < 0)
278 break; 278 break;
279 } 279 }
280 if (ret > 0) 280 if (ret > 0)
281 goto next; 281 goto next;
282 ret = ulist_add_merge_ptr(parents, eb->start, 282 ret = ulist_add_merge_ptr(parents, eb->start,
283 eie, (void **)&old, GFP_NOFS); 283 eie, (void **)&old, GFP_NOFS);
284 if (ret < 0) 284 if (ret < 0)
285 break; 285 break;
286 if (!ret && extent_item_pos) { 286 if (!ret && extent_item_pos) {
287 while (old->next) 287 while (old->next)
288 old = old->next; 288 old = old->next;
289 old->next = eie; 289 old->next = eie;
290 } 290 }
291 eie = NULL; 291 eie = NULL;
292 } 292 }
293 next: 293 next:
294 ret = btrfs_next_old_item(root, path, time_seq); 294 ret = btrfs_next_old_item(root, path, time_seq);
295 } 295 }
296 296
297 if (ret > 0) 297 if (ret > 0)
298 ret = 0; 298 ret = 0;
299 else if (ret < 0) 299 else if (ret < 0)
300 free_inode_elem_list(eie); 300 free_inode_elem_list(eie);
301 return ret; 301 return ret;
302 } 302 }
303 303
304 /* 304 /*
305 * resolve an indirect backref in the form (root_id, key, level) 305 * resolve an indirect backref in the form (root_id, key, level)
306 * to a logical address 306 * to a logical address
307 */ 307 */
308 static int __resolve_indirect_ref(struct btrfs_fs_info *fs_info, 308 static int __resolve_indirect_ref(struct btrfs_fs_info *fs_info,
309 struct btrfs_path *path, u64 time_seq, 309 struct btrfs_path *path, u64 time_seq,
310 struct __prelim_ref *ref, 310 struct __prelim_ref *ref,
311 struct ulist *parents, 311 struct ulist *parents,
312 const u64 *extent_item_pos, u64 total_refs) 312 const u64 *extent_item_pos, u64 total_refs)
313 { 313 {
314 struct btrfs_root *root; 314 struct btrfs_root *root;
315 struct btrfs_key root_key; 315 struct btrfs_key root_key;
316 struct extent_buffer *eb; 316 struct extent_buffer *eb;
317 int ret = 0; 317 int ret = 0;
318 int root_level; 318 int root_level;
319 int level = ref->level; 319 int level = ref->level;
320 int index; 320 int index;
321 321
322 root_key.objectid = ref->root_id; 322 root_key.objectid = ref->root_id;
323 root_key.type = BTRFS_ROOT_ITEM_KEY; 323 root_key.type = BTRFS_ROOT_ITEM_KEY;
324 root_key.offset = (u64)-1; 324 root_key.offset = (u64)-1;
325 325
326 index = srcu_read_lock(&fs_info->subvol_srcu); 326 index = srcu_read_lock(&fs_info->subvol_srcu);
327 327
328 root = btrfs_read_fs_root_no_name(fs_info, &root_key); 328 root = btrfs_read_fs_root_no_name(fs_info, &root_key);
329 if (IS_ERR(root)) { 329 if (IS_ERR(root)) {
330 srcu_read_unlock(&fs_info->subvol_srcu, index); 330 srcu_read_unlock(&fs_info->subvol_srcu, index);
331 ret = PTR_ERR(root); 331 ret = PTR_ERR(root);
332 goto out; 332 goto out;
333 } 333 }
334 334
335 if (path->search_commit_root) 335 if (path->search_commit_root)
336 root_level = btrfs_header_level(root->commit_root); 336 root_level = btrfs_header_level(root->commit_root);
337 else 337 else
338 root_level = btrfs_old_root_level(root, time_seq); 338 root_level = btrfs_old_root_level(root, time_seq);
339 339
340 if (root_level + 1 == level) { 340 if (root_level + 1 == level) {
341 srcu_read_unlock(&fs_info->subvol_srcu, index); 341 srcu_read_unlock(&fs_info->subvol_srcu, index);
342 goto out; 342 goto out;
343 } 343 }
344 344
345 path->lowest_level = level; 345 path->lowest_level = level;
346 ret = btrfs_search_old_slot(root, &ref->key_for_search, path, time_seq); 346 ret = btrfs_search_old_slot(root, &ref->key_for_search, path, time_seq);
347 347
348 /* root node has been locked, we can release @subvol_srcu safely here */ 348 /* root node has been locked, we can release @subvol_srcu safely here */
349 srcu_read_unlock(&fs_info->subvol_srcu, index); 349 srcu_read_unlock(&fs_info->subvol_srcu, index);
350 350
351 pr_debug("search slot in root %llu (level %d, ref count %d) returned " 351 pr_debug("search slot in root %llu (level %d, ref count %d) returned "
352 "%d for key (%llu %u %llu)\n", 352 "%d for key (%llu %u %llu)\n",
353 ref->root_id, level, ref->count, ret, 353 ref->root_id, level, ref->count, ret,
354 ref->key_for_search.objectid, ref->key_for_search.type, 354 ref->key_for_search.objectid, ref->key_for_search.type,
355 ref->key_for_search.offset); 355 ref->key_for_search.offset);
356 if (ret < 0) 356 if (ret < 0)
357 goto out; 357 goto out;
358 358
359 eb = path->nodes[level]; 359 eb = path->nodes[level];
360 while (!eb) { 360 while (!eb) {
361 if (WARN_ON(!level)) { 361 if (WARN_ON(!level)) {
362 ret = 1; 362 ret = 1;
363 goto out; 363 goto out;
364 } 364 }
365 level--; 365 level--;
366 eb = path->nodes[level]; 366 eb = path->nodes[level];
367 } 367 }
368 368
369 ret = add_all_parents(root, path, parents, ref, level, time_seq, 369 ret = add_all_parents(root, path, parents, ref, level, time_seq,
370 extent_item_pos, total_refs); 370 extent_item_pos, total_refs);
371 out: 371 out:
372 path->lowest_level = 0; 372 path->lowest_level = 0;
373 btrfs_release_path(path); 373 btrfs_release_path(path);
374 return ret; 374 return ret;
375 } 375 }
376 376
377 /* 377 /*
378 * resolve all indirect backrefs from the list 378 * resolve all indirect backrefs from the list
379 */ 379 */
380 static int __resolve_indirect_refs(struct btrfs_fs_info *fs_info, 380 static int __resolve_indirect_refs(struct btrfs_fs_info *fs_info,
381 struct btrfs_path *path, u64 time_seq, 381 struct btrfs_path *path, u64 time_seq,
382 struct list_head *head, 382 struct list_head *head,
383 const u64 *extent_item_pos, u64 total_refs, 383 const u64 *extent_item_pos, u64 total_refs,
384 u64 root_objectid) 384 u64 root_objectid)
385 { 385 {
386 int err; 386 int err;
387 int ret = 0; 387 int ret = 0;
388 struct __prelim_ref *ref; 388 struct __prelim_ref *ref;
389 struct __prelim_ref *ref_safe; 389 struct __prelim_ref *ref_safe;
390 struct __prelim_ref *new_ref; 390 struct __prelim_ref *new_ref;
391 struct ulist *parents; 391 struct ulist *parents;
392 struct ulist_node *node; 392 struct ulist_node *node;
393 struct ulist_iterator uiter; 393 struct ulist_iterator uiter;
394 394
395 parents = ulist_alloc(GFP_NOFS); 395 parents = ulist_alloc(GFP_NOFS);
396 if (!parents) 396 if (!parents)
397 return -ENOMEM; 397 return -ENOMEM;
398 398
399 /* 399 /*
400 * _safe allows us to insert directly after the current item without 400 * _safe allows us to insert directly after the current item without
401 * iterating over the newly inserted items. 401 * iterating over the newly inserted items.
402 * we're also allowed to re-assign ref during iteration. 402 * we're also allowed to re-assign ref during iteration.
403 */ 403 */
404 list_for_each_entry_safe(ref, ref_safe, head, list) { 404 list_for_each_entry_safe(ref, ref_safe, head, list) {
405 if (ref->parent) /* already direct */ 405 if (ref->parent) /* already direct */
406 continue; 406 continue;
407 if (ref->count == 0) 407 if (ref->count == 0)
408 continue; 408 continue;
409 if (root_objectid && ref->root_id != root_objectid) { 409 if (root_objectid && ref->root_id != root_objectid) {
410 ret = BACKREF_FOUND_SHARED; 410 ret = BACKREF_FOUND_SHARED;
411 goto out; 411 goto out;
412 } 412 }
413 err = __resolve_indirect_ref(fs_info, path, time_seq, ref, 413 err = __resolve_indirect_ref(fs_info, path, time_seq, ref,
414 parents, extent_item_pos, 414 parents, extent_item_pos,
415 total_refs); 415 total_refs);
416 /* 416 /*
417 * we can only tolerate ENOENT,otherwise,we should catch error 417 * we can only tolerate ENOENT,otherwise,we should catch error
418 * and return directly. 418 * and return directly.
419 */ 419 */
420 if (err == -ENOENT) { 420 if (err == -ENOENT) {
421 continue; 421 continue;
422 } else if (err) { 422 } else if (err) {
423 ret = err; 423 ret = err;
424 goto out; 424 goto out;
425 } 425 }
426 426
427 /* we put the first parent into the ref at hand */ 427 /* we put the first parent into the ref at hand */
428 ULIST_ITER_INIT(&uiter); 428 ULIST_ITER_INIT(&uiter);
429 node = ulist_next(parents, &uiter); 429 node = ulist_next(parents, &uiter);
430 ref->parent = node ? node->val : 0; 430 ref->parent = node ? node->val : 0;
431 ref->inode_list = node ? 431 ref->inode_list = node ?
432 (struct extent_inode_elem *)(uintptr_t)node->aux : NULL; 432 (struct extent_inode_elem *)(uintptr_t)node->aux : NULL;
433 433
434 /* additional parents require new refs being added here */ 434 /* additional parents require new refs being added here */
435 while ((node = ulist_next(parents, &uiter))) { 435 while ((node = ulist_next(parents, &uiter))) {
436 new_ref = kmem_cache_alloc(btrfs_prelim_ref_cache, 436 new_ref = kmem_cache_alloc(btrfs_prelim_ref_cache,
437 GFP_NOFS); 437 GFP_NOFS);
438 if (!new_ref) { 438 if (!new_ref) {
439 ret = -ENOMEM; 439 ret = -ENOMEM;
440 goto out; 440 goto out;
441 } 441 }
442 memcpy(new_ref, ref, sizeof(*ref)); 442 memcpy(new_ref, ref, sizeof(*ref));
443 new_ref->parent = node->val; 443 new_ref->parent = node->val;
444 new_ref->inode_list = (struct extent_inode_elem *) 444 new_ref->inode_list = (struct extent_inode_elem *)
445 (uintptr_t)node->aux; 445 (uintptr_t)node->aux;
446 list_add(&new_ref->list, &ref->list); 446 list_add(&new_ref->list, &ref->list);
447 } 447 }
448 ulist_reinit(parents); 448 ulist_reinit(parents);
449 } 449 }
450 out: 450 out:
451 ulist_free(parents); 451 ulist_free(parents);
452 return ret; 452 return ret;
453 } 453 }
454 454
455 static inline int ref_for_same_block(struct __prelim_ref *ref1, 455 static inline int ref_for_same_block(struct __prelim_ref *ref1,
456 struct __prelim_ref *ref2) 456 struct __prelim_ref *ref2)
457 { 457 {
458 if (ref1->level != ref2->level) 458 if (ref1->level != ref2->level)
459 return 0; 459 return 0;
460 if (ref1->root_id != ref2->root_id) 460 if (ref1->root_id != ref2->root_id)
461 return 0; 461 return 0;
462 if (ref1->key_for_search.type != ref2->key_for_search.type) 462 if (ref1->key_for_search.type != ref2->key_for_search.type)
463 return 0; 463 return 0;
464 if (ref1->key_for_search.objectid != ref2->key_for_search.objectid) 464 if (ref1->key_for_search.objectid != ref2->key_for_search.objectid)
465 return 0; 465 return 0;
466 if (ref1->key_for_search.offset != ref2->key_for_search.offset) 466 if (ref1->key_for_search.offset != ref2->key_for_search.offset)
467 return 0; 467 return 0;
468 if (ref1->parent != ref2->parent) 468 if (ref1->parent != ref2->parent)
469 return 0; 469 return 0;
470 470
471 return 1; 471 return 1;
472 } 472 }
473 473
474 /* 474 /*
475 * read tree blocks and add keys where required. 475 * read tree blocks and add keys where required.
476 */ 476 */
477 static int __add_missing_keys(struct btrfs_fs_info *fs_info, 477 static int __add_missing_keys(struct btrfs_fs_info *fs_info,
478 struct list_head *head) 478 struct list_head *head)
479 { 479 {
480 struct list_head *pos; 480 struct list_head *pos;
481 struct extent_buffer *eb; 481 struct extent_buffer *eb;
482 482
483 list_for_each(pos, head) { 483 list_for_each(pos, head) {
484 struct __prelim_ref *ref; 484 struct __prelim_ref *ref;
485 ref = list_entry(pos, struct __prelim_ref, list); 485 ref = list_entry(pos, struct __prelim_ref, list);
486 486
487 if (ref->parent) 487 if (ref->parent)
488 continue; 488 continue;
489 if (ref->key_for_search.type) 489 if (ref->key_for_search.type)
490 continue; 490 continue;
491 BUG_ON(!ref->wanted_disk_byte); 491 BUG_ON(!ref->wanted_disk_byte);
492 eb = read_tree_block(fs_info->tree_root, ref->wanted_disk_byte, 492 eb = read_tree_block(fs_info->tree_root, ref->wanted_disk_byte,
493 0); 493 0);
494 if (!eb || !extent_buffer_uptodate(eb)) { 494 if (!eb || !extent_buffer_uptodate(eb)) {
495 free_extent_buffer(eb); 495 free_extent_buffer(eb);
496 return -EIO; 496 return -EIO;
497 } 497 }
498 btrfs_tree_read_lock(eb); 498 btrfs_tree_read_lock(eb);
499 if (btrfs_header_level(eb) == 0) 499 if (btrfs_header_level(eb) == 0)
500 btrfs_item_key_to_cpu(eb, &ref->key_for_search, 0); 500 btrfs_item_key_to_cpu(eb, &ref->key_for_search, 0);
501 else 501 else
502 btrfs_node_key_to_cpu(eb, &ref->key_for_search, 0); 502 btrfs_node_key_to_cpu(eb, &ref->key_for_search, 0);
503 btrfs_tree_read_unlock(eb); 503 btrfs_tree_read_unlock(eb);
504 free_extent_buffer(eb); 504 free_extent_buffer(eb);
505 } 505 }
506 return 0; 506 return 0;
507 } 507 }
508 508
509 /* 509 /*
510 * merge two lists of backrefs and adjust counts accordingly 510 * merge two lists of backrefs and adjust counts accordingly
511 * 511 *
512 * mode = 1: merge identical keys, if key is set 512 * mode = 1: merge identical keys, if key is set
513 * FIXME: if we add more keys in __add_prelim_ref, we can merge more here. 513 * FIXME: if we add more keys in __add_prelim_ref, we can merge more here.
514 * additionally, we could even add a key range for the blocks we 514 * additionally, we could even add a key range for the blocks we
515 * looked into to merge even more (-> replace unresolved refs by those 515 * looked into to merge even more (-> replace unresolved refs by those
516 * having a parent). 516 * having a parent).
517 * mode = 2: merge identical parents 517 * mode = 2: merge identical parents
518 */ 518 */
519 static void __merge_refs(struct list_head *head, int mode) 519 static void __merge_refs(struct list_head *head, int mode)
520 { 520 {
521 struct list_head *pos1; 521 struct list_head *pos1;
522 522
523 list_for_each(pos1, head) { 523 list_for_each(pos1, head) {
524 struct list_head *n2; 524 struct list_head *n2;
525 struct list_head *pos2; 525 struct list_head *pos2;
526 struct __prelim_ref *ref1; 526 struct __prelim_ref *ref1;
527 527
528 ref1 = list_entry(pos1, struct __prelim_ref, list); 528 ref1 = list_entry(pos1, struct __prelim_ref, list);
529 529
530 for (pos2 = pos1->next, n2 = pos2->next; pos2 != head; 530 for (pos2 = pos1->next, n2 = pos2->next; pos2 != head;
531 pos2 = n2, n2 = pos2->next) { 531 pos2 = n2, n2 = pos2->next) {
532 struct __prelim_ref *ref2; 532 struct __prelim_ref *ref2;
533 struct __prelim_ref *xchg; 533 struct __prelim_ref *xchg;
534 struct extent_inode_elem *eie; 534 struct extent_inode_elem *eie;
535 535
536 ref2 = list_entry(pos2, struct __prelim_ref, list); 536 ref2 = list_entry(pos2, struct __prelim_ref, list);
537 537
538 if (mode == 1) { 538 if (mode == 1) {
539 if (!ref_for_same_block(ref1, ref2)) 539 if (!ref_for_same_block(ref1, ref2))
540 continue; 540 continue;
541 if (!ref1->parent && ref2->parent) { 541 if (!ref1->parent && ref2->parent) {
542 xchg = ref1; 542 xchg = ref1;
543 ref1 = ref2; 543 ref1 = ref2;
544 ref2 = xchg; 544 ref2 = xchg;
545 } 545 }
546 } else { 546 } else {
547 if (ref1->parent != ref2->parent) 547 if (ref1->parent != ref2->parent)
548 continue; 548 continue;
549 } 549 }
550 550
551 eie = ref1->inode_list; 551 eie = ref1->inode_list;
552 while (eie && eie->next) 552 while (eie && eie->next)
553 eie = eie->next; 553 eie = eie->next;
554 if (eie) 554 if (eie)
555 eie->next = ref2->inode_list; 555 eie->next = ref2->inode_list;
556 else 556 else
557 ref1->inode_list = ref2->inode_list; 557 ref1->inode_list = ref2->inode_list;
558 ref1->count += ref2->count; 558 ref1->count += ref2->count;
559 559
560 list_del(&ref2->list); 560 list_del(&ref2->list);
561 kmem_cache_free(btrfs_prelim_ref_cache, ref2); 561 kmem_cache_free(btrfs_prelim_ref_cache, ref2);
562 } 562 }
563 563
564 } 564 }
565 } 565 }
566 566
567 /* 567 /*
568 * add all currently queued delayed refs from this head whose seq nr is 568 * add all currently queued delayed refs from this head whose seq nr is
569 * smaller or equal that seq to the list 569 * smaller or equal that seq to the list
570 */ 570 */
571 static int __add_delayed_refs(struct btrfs_delayed_ref_head *head, u64 seq, 571 static int __add_delayed_refs(struct btrfs_delayed_ref_head *head, u64 seq,
572 struct list_head *prefs, u64 *total_refs, 572 struct list_head *prefs, u64 *total_refs,
573 u64 inum) 573 u64 inum)
574 { 574 {
575 struct btrfs_delayed_extent_op *extent_op = head->extent_op; 575 struct btrfs_delayed_extent_op *extent_op = head->extent_op;
576 struct rb_node *n = &head->node.rb_node; 576 struct rb_node *n = &head->node.rb_node;
577 struct btrfs_key key; 577 struct btrfs_key key;
578 struct btrfs_key op_key = {0}; 578 struct btrfs_key op_key = {0};
579 int sgn; 579 int sgn;
580 int ret = 0; 580 int ret = 0;
581 581
582 if (extent_op && extent_op->update_key) 582 if (extent_op && extent_op->update_key)
583 btrfs_disk_key_to_cpu(&op_key, &extent_op->key); 583 btrfs_disk_key_to_cpu(&op_key, &extent_op->key);
584 584
585 spin_lock(&head->lock); 585 spin_lock(&head->lock);
586 n = rb_first(&head->ref_root); 586 n = rb_first(&head->ref_root);
587 while (n) { 587 while (n) {
588 struct btrfs_delayed_ref_node *node; 588 struct btrfs_delayed_ref_node *node;
589 node = rb_entry(n, struct btrfs_delayed_ref_node, 589 node = rb_entry(n, struct btrfs_delayed_ref_node,
590 rb_node); 590 rb_node);
591 n = rb_next(n); 591 n = rb_next(n);
592 if (node->seq > seq) 592 if (node->seq > seq)
593 continue; 593 continue;
594 594
595 switch (node->action) { 595 switch (node->action) {
596 case BTRFS_ADD_DELAYED_EXTENT: 596 case BTRFS_ADD_DELAYED_EXTENT:
597 case BTRFS_UPDATE_DELAYED_HEAD: 597 case BTRFS_UPDATE_DELAYED_HEAD:
598 WARN_ON(1); 598 WARN_ON(1);
599 continue; 599 continue;
600 case BTRFS_ADD_DELAYED_REF: 600 case BTRFS_ADD_DELAYED_REF:
601 sgn = 1; 601 sgn = 1;
602 break; 602 break;
603 case BTRFS_DROP_DELAYED_REF: 603 case BTRFS_DROP_DELAYED_REF:
604 sgn = -1; 604 sgn = -1;
605 break; 605 break;
606 default: 606 default:
607 BUG_ON(1); 607 BUG_ON(1);
608 } 608 }
609 *total_refs += (node->ref_mod * sgn); 609 *total_refs += (node->ref_mod * sgn);
610 switch (node->type) { 610 switch (node->type) {
611 case BTRFS_TREE_BLOCK_REF_KEY: { 611 case BTRFS_TREE_BLOCK_REF_KEY: {
612 struct btrfs_delayed_tree_ref *ref; 612 struct btrfs_delayed_tree_ref *ref;
613 613
614 ref = btrfs_delayed_node_to_tree_ref(node); 614 ref = btrfs_delayed_node_to_tree_ref(node);
615 ret = __add_prelim_ref(prefs, ref->root, &op_key, 615 ret = __add_prelim_ref(prefs, ref->root, &op_key,
616 ref->level + 1, 0, node->bytenr, 616 ref->level + 1, 0, node->bytenr,
617 node->ref_mod * sgn, GFP_ATOMIC); 617 node->ref_mod * sgn, GFP_ATOMIC);
618 break; 618 break;
619 } 619 }
620 case BTRFS_SHARED_BLOCK_REF_KEY: { 620 case BTRFS_SHARED_BLOCK_REF_KEY: {
621 struct btrfs_delayed_tree_ref *ref; 621 struct btrfs_delayed_tree_ref *ref;
622 622
623 ref = btrfs_delayed_node_to_tree_ref(node); 623 ref = btrfs_delayed_node_to_tree_ref(node);
624 ret = __add_prelim_ref(prefs, ref->root, NULL, 624 ret = __add_prelim_ref(prefs, ref->root, NULL,
625 ref->level + 1, ref->parent, 625 ref->level + 1, ref->parent,
626 node->bytenr, 626 node->bytenr,
627 node->ref_mod * sgn, GFP_ATOMIC); 627 node->ref_mod * sgn, GFP_ATOMIC);
628 break; 628 break;
629 } 629 }
630 case BTRFS_EXTENT_DATA_REF_KEY: { 630 case BTRFS_EXTENT_DATA_REF_KEY: {
631 struct btrfs_delayed_data_ref *ref; 631 struct btrfs_delayed_data_ref *ref;
632 ref = btrfs_delayed_node_to_data_ref(node); 632 ref = btrfs_delayed_node_to_data_ref(node);
633 633
634 key.objectid = ref->objectid; 634 key.objectid = ref->objectid;
635 key.type = BTRFS_EXTENT_DATA_KEY; 635 key.type = BTRFS_EXTENT_DATA_KEY;
636 key.offset = ref->offset; 636 key.offset = ref->offset;
637 637
638 /* 638 /*
639 * Found a inum that doesn't match our known inum, we 639 * Found a inum that doesn't match our known inum, we
640 * know it's shared. 640 * know it's shared.
641 */ 641 */
642 if (inum && ref->objectid != inum) { 642 if (inum && ref->objectid != inum) {
643 ret = BACKREF_FOUND_SHARED; 643 ret = BACKREF_FOUND_SHARED;
644 break; 644 break;
645 } 645 }
646 646
647 ret = __add_prelim_ref(prefs, ref->root, &key, 0, 0, 647 ret = __add_prelim_ref(prefs, ref->root, &key, 0, 0,
648 node->bytenr, 648 node->bytenr,
649 node->ref_mod * sgn, GFP_ATOMIC); 649 node->ref_mod * sgn, GFP_ATOMIC);
650 break; 650 break;
651 } 651 }
652 case BTRFS_SHARED_DATA_REF_KEY: { 652 case BTRFS_SHARED_DATA_REF_KEY: {
653 struct btrfs_delayed_data_ref *ref; 653 struct btrfs_delayed_data_ref *ref;
654 654
655 ref = btrfs_delayed_node_to_data_ref(node); 655 ref = btrfs_delayed_node_to_data_ref(node);
656 656
657 key.objectid = ref->objectid; 657 key.objectid = ref->objectid;
658 key.type = BTRFS_EXTENT_DATA_KEY; 658 key.type = BTRFS_EXTENT_DATA_KEY;
659 key.offset = ref->offset; 659 key.offset = ref->offset;
660 ret = __add_prelim_ref(prefs, ref->root, &key, 0, 660 ret = __add_prelim_ref(prefs, ref->root, &key, 0,
661 ref->parent, node->bytenr, 661 ref->parent, node->bytenr,
662 node->ref_mod * sgn, GFP_ATOMIC); 662 node->ref_mod * sgn, GFP_ATOMIC);
663 break; 663 break;
664 } 664 }
665 default: 665 default:
666 WARN_ON(1); 666 WARN_ON(1);
667 } 667 }
668 if (ret) 668 if (ret)
669 break; 669 break;
670 } 670 }
671 spin_unlock(&head->lock); 671 spin_unlock(&head->lock);
672 return ret; 672 return ret;
673 } 673 }
674 674
675 /* 675 /*
676 * add all inline backrefs for bytenr to the list 676 * add all inline backrefs for bytenr to the list
677 */ 677 */
678 static int __add_inline_refs(struct btrfs_fs_info *fs_info, 678 static int __add_inline_refs(struct btrfs_fs_info *fs_info,
679 struct btrfs_path *path, u64 bytenr, 679 struct btrfs_path *path, u64 bytenr,
680 int *info_level, struct list_head *prefs, 680 int *info_level, struct list_head *prefs,
681 u64 *total_refs, u64 inum) 681 u64 *total_refs, u64 inum)
682 { 682 {
683 int ret = 0; 683 int ret = 0;
684 int slot; 684 int slot;
685 struct extent_buffer *leaf; 685 struct extent_buffer *leaf;
686 struct btrfs_key key; 686 struct btrfs_key key;
687 struct btrfs_key found_key; 687 struct btrfs_key found_key;
688 unsigned long ptr; 688 unsigned long ptr;
689 unsigned long end; 689 unsigned long end;
690 struct btrfs_extent_item *ei; 690 struct btrfs_extent_item *ei;
691 u64 flags; 691 u64 flags;
692 u64 item_size; 692 u64 item_size;
693 693
694 /* 694 /*
695 * enumerate all inline refs 695 * enumerate all inline refs
696 */ 696 */
697 leaf = path->nodes[0]; 697 leaf = path->nodes[0];
698 slot = path->slots[0]; 698 slot = path->slots[0];
699 699
700 item_size = btrfs_item_size_nr(leaf, slot); 700 item_size = btrfs_item_size_nr(leaf, slot);
701 BUG_ON(item_size < sizeof(*ei)); 701 BUG_ON(item_size < sizeof(*ei));
702 702
703 ei = btrfs_item_ptr(leaf, slot, struct btrfs_extent_item); 703 ei = btrfs_item_ptr(leaf, slot, struct btrfs_extent_item);
704 flags = btrfs_extent_flags(leaf, ei); 704 flags = btrfs_extent_flags(leaf, ei);
705 *total_refs += btrfs_extent_refs(leaf, ei); 705 *total_refs += btrfs_extent_refs(leaf, ei);
706 btrfs_item_key_to_cpu(leaf, &found_key, slot); 706 btrfs_item_key_to_cpu(leaf, &found_key, slot);
707 707
708 ptr = (unsigned long)(ei + 1); 708 ptr = (unsigned long)(ei + 1);
709 end = (unsigned long)ei + item_size; 709 end = (unsigned long)ei + item_size;
710 710
711 if (found_key.type == BTRFS_EXTENT_ITEM_KEY && 711 if (found_key.type == BTRFS_EXTENT_ITEM_KEY &&
712 flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) { 712 flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) {
713 struct btrfs_tree_block_info *info; 713 struct btrfs_tree_block_info *info;
714 714
715 info = (struct btrfs_tree_block_info *)ptr; 715 info = (struct btrfs_tree_block_info *)ptr;
716 *info_level = btrfs_tree_block_level(leaf, info); 716 *info_level = btrfs_tree_block_level(leaf, info);
717 ptr += sizeof(struct btrfs_tree_block_info); 717 ptr += sizeof(struct btrfs_tree_block_info);
718 BUG_ON(ptr > end); 718 BUG_ON(ptr > end);
719 } else if (found_key.type == BTRFS_METADATA_ITEM_KEY) { 719 } else if (found_key.type == BTRFS_METADATA_ITEM_KEY) {
720 *info_level = found_key.offset; 720 *info_level = found_key.offset;
721 } else { 721 } else {
722 BUG_ON(!(flags & BTRFS_EXTENT_FLAG_DATA)); 722 BUG_ON(!(flags & BTRFS_EXTENT_FLAG_DATA));
723 } 723 }
724 724
725 while (ptr < end) { 725 while (ptr < end) {
726 struct btrfs_extent_inline_ref *iref; 726 struct btrfs_extent_inline_ref *iref;
727 u64 offset; 727 u64 offset;
728 int type; 728 int type;
729 729
730 iref = (struct btrfs_extent_inline_ref *)ptr; 730 iref = (struct btrfs_extent_inline_ref *)ptr;
731 type = btrfs_extent_inline_ref_type(leaf, iref); 731 type = btrfs_extent_inline_ref_type(leaf, iref);
732 offset = btrfs_extent_inline_ref_offset(leaf, iref); 732 offset = btrfs_extent_inline_ref_offset(leaf, iref);
733 733
734 switch (type) { 734 switch (type) {
735 case BTRFS_SHARED_BLOCK_REF_KEY: 735 case BTRFS_SHARED_BLOCK_REF_KEY:
736 ret = __add_prelim_ref(prefs, 0, NULL, 736 ret = __add_prelim_ref(prefs, 0, NULL,
737 *info_level + 1, offset, 737 *info_level + 1, offset,
738 bytenr, 1, GFP_NOFS); 738 bytenr, 1, GFP_NOFS);
739 break; 739 break;
740 case BTRFS_SHARED_DATA_REF_KEY: { 740 case BTRFS_SHARED_DATA_REF_KEY: {
741 struct btrfs_shared_data_ref *sdref; 741 struct btrfs_shared_data_ref *sdref;
742 int count; 742 int count;
743 743
744 sdref = (struct btrfs_shared_data_ref *)(iref + 1); 744 sdref = (struct btrfs_shared_data_ref *)(iref + 1);
745 count = btrfs_shared_data_ref_count(leaf, sdref); 745 count = btrfs_shared_data_ref_count(leaf, sdref);
746 ret = __add_prelim_ref(prefs, 0, NULL, 0, offset, 746 ret = __add_prelim_ref(prefs, 0, NULL, 0, offset,
747 bytenr, count, GFP_NOFS); 747 bytenr, count, GFP_NOFS);
748 break; 748 break;
749 } 749 }
750 case BTRFS_TREE_BLOCK_REF_KEY: 750 case BTRFS_TREE_BLOCK_REF_KEY:
751 ret = __add_prelim_ref(prefs, offset, NULL, 751 ret = __add_prelim_ref(prefs, offset, NULL,
752 *info_level + 1, 0, 752 *info_level + 1, 0,
753 bytenr, 1, GFP_NOFS); 753 bytenr, 1, GFP_NOFS);
754 break; 754 break;
755 case BTRFS_EXTENT_DATA_REF_KEY: { 755 case BTRFS_EXTENT_DATA_REF_KEY: {
756 struct btrfs_extent_data_ref *dref; 756 struct btrfs_extent_data_ref *dref;
757 int count; 757 int count;
758 u64 root; 758 u64 root;
759 759
760 dref = (struct btrfs_extent_data_ref *)(&iref->offset); 760 dref = (struct btrfs_extent_data_ref *)(&iref->offset);
761 count = btrfs_extent_data_ref_count(leaf, dref); 761 count = btrfs_extent_data_ref_count(leaf, dref);
762 key.objectid = btrfs_extent_data_ref_objectid(leaf, 762 key.objectid = btrfs_extent_data_ref_objectid(leaf,
763 dref); 763 dref);
764 key.type = BTRFS_EXTENT_DATA_KEY; 764 key.type = BTRFS_EXTENT_DATA_KEY;
765 key.offset = btrfs_extent_data_ref_offset(leaf, dref); 765 key.offset = btrfs_extent_data_ref_offset(leaf, dref);
766 766
767 if (inum && key.objectid != inum) { 767 if (inum && key.objectid != inum) {
768 ret = BACKREF_FOUND_SHARED; 768 ret = BACKREF_FOUND_SHARED;
769 break; 769 break;
770 } 770 }
771 771
772 root = btrfs_extent_data_ref_root(leaf, dref); 772 root = btrfs_extent_data_ref_root(leaf, dref);
773 ret = __add_prelim_ref(prefs, root, &key, 0, 0, 773 ret = __add_prelim_ref(prefs, root, &key, 0, 0,
774 bytenr, count, GFP_NOFS); 774 bytenr, count, GFP_NOFS);
775 break; 775 break;
776 } 776 }
777 default: 777 default:
778 WARN_ON(1); 778 WARN_ON(1);
779 } 779 }
780 if (ret) 780 if (ret)
781 return ret; 781 return ret;
782 ptr += btrfs_extent_inline_ref_size(type); 782 ptr += btrfs_extent_inline_ref_size(type);
783 } 783 }
784 784
785 return 0; 785 return 0;
786 } 786 }
787 787
788 /* 788 /*
789 * add all non-inline backrefs for bytenr to the list 789 * add all non-inline backrefs for bytenr to the list
790 */ 790 */
791 static int __add_keyed_refs(struct btrfs_fs_info *fs_info, 791 static int __add_keyed_refs(struct btrfs_fs_info *fs_info,
792 struct btrfs_path *path, u64 bytenr, 792 struct btrfs_path *path, u64 bytenr,
793 int info_level, struct list_head *prefs, u64 inum) 793 int info_level, struct list_head *prefs, u64 inum)
794 { 794 {
795 struct btrfs_root *extent_root = fs_info->extent_root; 795 struct btrfs_root *extent_root = fs_info->extent_root;
796 int ret; 796 int ret;
797 int slot; 797 int slot;
798 struct extent_buffer *leaf; 798 struct extent_buffer *leaf;
799 struct btrfs_key key; 799 struct btrfs_key key;
800 800
801 while (1) { 801 while (1) {
802 ret = btrfs_next_item(extent_root, path); 802 ret = btrfs_next_item(extent_root, path);
803 if (ret < 0) 803 if (ret < 0)
804 break; 804 break;
805 if (ret) { 805 if (ret) {
806 ret = 0; 806 ret = 0;
807 break; 807 break;
808 } 808 }
809 809
810 slot = path->slots[0]; 810 slot = path->slots[0];
811 leaf = path->nodes[0]; 811 leaf = path->nodes[0];
812 btrfs_item_key_to_cpu(leaf, &key, slot); 812 btrfs_item_key_to_cpu(leaf, &key, slot);
813 813
814 if (key.objectid != bytenr) 814 if (key.objectid != bytenr)
815 break; 815 break;
816 if (key.type < BTRFS_TREE_BLOCK_REF_KEY) 816 if (key.type < BTRFS_TREE_BLOCK_REF_KEY)
817 continue; 817 continue;
818 if (key.type > BTRFS_SHARED_DATA_REF_KEY) 818 if (key.type > BTRFS_SHARED_DATA_REF_KEY)
819 break; 819 break;
820 820
821 switch (key.type) { 821 switch (key.type) {
822 case BTRFS_SHARED_BLOCK_REF_KEY: 822 case BTRFS_SHARED_BLOCK_REF_KEY:
823 ret = __add_prelim_ref(prefs, 0, NULL, 823 ret = __add_prelim_ref(prefs, 0, NULL,
824 info_level + 1, key.offset, 824 info_level + 1, key.offset,
825 bytenr, 1, GFP_NOFS); 825 bytenr, 1, GFP_NOFS);
826 break; 826 break;
827 case BTRFS_SHARED_DATA_REF_KEY: { 827 case BTRFS_SHARED_DATA_REF_KEY: {
828 struct btrfs_shared_data_ref *sdref; 828 struct btrfs_shared_data_ref *sdref;
829 int count; 829 int count;
830 830
831 sdref = btrfs_item_ptr(leaf, slot, 831 sdref = btrfs_item_ptr(leaf, slot,
832 struct btrfs_shared_data_ref); 832 struct btrfs_shared_data_ref);
833 count = btrfs_shared_data_ref_count(leaf, sdref); 833 count = btrfs_shared_data_ref_count(leaf, sdref);
834 ret = __add_prelim_ref(prefs, 0, NULL, 0, key.offset, 834 ret = __add_prelim_ref(prefs, 0, NULL, 0, key.offset,
835 bytenr, count, GFP_NOFS); 835 bytenr, count, GFP_NOFS);
836 break; 836 break;
837 } 837 }
838 case BTRFS_TREE_BLOCK_REF_KEY: 838 case BTRFS_TREE_BLOCK_REF_KEY:
839 ret = __add_prelim_ref(prefs, key.offset, NULL, 839 ret = __add_prelim_ref(prefs, key.offset, NULL,
840 info_level + 1, 0, 840 info_level + 1, 0,
841 bytenr, 1, GFP_NOFS); 841 bytenr, 1, GFP_NOFS);
842 break; 842 break;
843 case BTRFS_EXTENT_DATA_REF_KEY: { 843 case BTRFS_EXTENT_DATA_REF_KEY: {
844 struct btrfs_extent_data_ref *dref; 844 struct btrfs_extent_data_ref *dref;
845 int count; 845 int count;
846 u64 root; 846 u64 root;
847 847
848 dref = btrfs_item_ptr(leaf, slot, 848 dref = btrfs_item_ptr(leaf, slot,
849 struct btrfs_extent_data_ref); 849 struct btrfs_extent_data_ref);
850 count = btrfs_extent_data_ref_count(leaf, dref); 850 count = btrfs_extent_data_ref_count(leaf, dref);
851 key.objectid = btrfs_extent_data_ref_objectid(leaf, 851 key.objectid = btrfs_extent_data_ref_objectid(leaf,
852 dref); 852 dref);
853 key.type = BTRFS_EXTENT_DATA_KEY; 853 key.type = BTRFS_EXTENT_DATA_KEY;
854 key.offset = btrfs_extent_data_ref_offset(leaf, dref); 854 key.offset = btrfs_extent_data_ref_offset(leaf, dref);
855 855
856 if (inum && key.objectid != inum) { 856 if (inum && key.objectid != inum) {
857 ret = BACKREF_FOUND_SHARED; 857 ret = BACKREF_FOUND_SHARED;
858 break; 858 break;
859 } 859 }
860 860
861 root = btrfs_extent_data_ref_root(leaf, dref); 861 root = btrfs_extent_data_ref_root(leaf, dref);
862 ret = __add_prelim_ref(prefs, root, &key, 0, 0, 862 ret = __add_prelim_ref(prefs, root, &key, 0, 0,
863 bytenr, count, GFP_NOFS); 863 bytenr, count, GFP_NOFS);
864 break; 864 break;
865 } 865 }
866 default: 866 default:
867 WARN_ON(1); 867 WARN_ON(1);
868 } 868 }
869 if (ret) 869 if (ret)
870 return ret; 870 return ret;
871 871
872 } 872 }
873 873
874 return ret; 874 return ret;
875 } 875 }
876 876
877 /* 877 /*
878 * this adds all existing backrefs (inline backrefs, backrefs and delayed 878 * this adds all existing backrefs (inline backrefs, backrefs and delayed
879 * refs) for the given bytenr to the refs list, merges duplicates and resolves 879 * refs) for the given bytenr to the refs list, merges duplicates and resolves
880 * indirect refs to their parent bytenr. 880 * indirect refs to their parent bytenr.
881 * When roots are found, they're added to the roots list 881 * When roots are found, they're added to the roots list
882 * 882 *
883 * FIXME some caching might speed things up 883 * FIXME some caching might speed things up
884 */ 884 */
885 static int find_parent_nodes(struct btrfs_trans_handle *trans, 885 static int find_parent_nodes(struct btrfs_trans_handle *trans,
886 struct btrfs_fs_info *fs_info, u64 bytenr, 886 struct btrfs_fs_info *fs_info, u64 bytenr,
887 u64 time_seq, struct ulist *refs, 887 u64 time_seq, struct ulist *refs,
888 struct ulist *roots, const u64 *extent_item_pos, 888 struct ulist *roots, const u64 *extent_item_pos,
889 u64 root_objectid, u64 inum) 889 u64 root_objectid, u64 inum)
890 { 890 {
891 struct btrfs_key key; 891 struct btrfs_key key;
892 struct btrfs_path *path; 892 struct btrfs_path *path;
893 struct btrfs_delayed_ref_root *delayed_refs = NULL; 893 struct btrfs_delayed_ref_root *delayed_refs = NULL;
894 struct btrfs_delayed_ref_head *head; 894 struct btrfs_delayed_ref_head *head;
895 int info_level = 0; 895 int info_level = 0;
896 int ret; 896 int ret;
897 struct list_head prefs_delayed; 897 struct list_head prefs_delayed;
898 struct list_head prefs; 898 struct list_head prefs;
899 struct __prelim_ref *ref; 899 struct __prelim_ref *ref;
900 struct extent_inode_elem *eie = NULL; 900 struct extent_inode_elem *eie = NULL;
901 u64 total_refs = 0; 901 u64 total_refs = 0;
902 902
903 INIT_LIST_HEAD(&prefs); 903 INIT_LIST_HEAD(&prefs);
904 INIT_LIST_HEAD(&prefs_delayed); 904 INIT_LIST_HEAD(&prefs_delayed);
905 905
906 key.objectid = bytenr; 906 key.objectid = bytenr;
907 key.offset = (u64)-1; 907 key.offset = (u64)-1;
908 if (btrfs_fs_incompat(fs_info, SKINNY_METADATA)) 908 if (btrfs_fs_incompat(fs_info, SKINNY_METADATA))
909 key.type = BTRFS_METADATA_ITEM_KEY; 909 key.type = BTRFS_METADATA_ITEM_KEY;
910 else 910 else
911 key.type = BTRFS_EXTENT_ITEM_KEY; 911 key.type = BTRFS_EXTENT_ITEM_KEY;
912 912
913 path = btrfs_alloc_path(); 913 path = btrfs_alloc_path();
914 if (!path) 914 if (!path)
915 return -ENOMEM; 915 return -ENOMEM;
916 if (!trans) { 916 if (!trans) {
917 path->search_commit_root = 1; 917 path->search_commit_root = 1;
918 path->skip_locking = 1; 918 path->skip_locking = 1;
919 } 919 }
920 920
921 /* 921 /*
922 * grab both a lock on the path and a lock on the delayed ref head. 922 * grab both a lock on the path and a lock on the delayed ref head.
923 * We need both to get a consistent picture of how the refs look 923 * We need both to get a consistent picture of how the refs look
924 * at a specified point in time 924 * at a specified point in time
925 */ 925 */
926 again: 926 again:
927 head = NULL; 927 head = NULL;
928 928
929 ret = btrfs_search_slot(trans, fs_info->extent_root, &key, path, 0, 0); 929 ret = btrfs_search_slot(trans, fs_info->extent_root, &key, path, 0, 0);
930 if (ret < 0) 930 if (ret < 0)
931 goto out; 931 goto out;
932 BUG_ON(ret == 0); 932 BUG_ON(ret == 0);
933 933
934 #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS 934 #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
935 if (trans && likely(trans->type != __TRANS_DUMMY)) { 935 if (trans && likely(trans->type != __TRANS_DUMMY)) {
936 #else 936 #else
937 if (trans) { 937 if (trans) {
938 #endif 938 #endif
939 /* 939 /*
940 * look if there are updates for this ref queued and lock the 940 * look if there are updates for this ref queued and lock the
941 * head 941 * head
942 */ 942 */
943 delayed_refs = &trans->transaction->delayed_refs; 943 delayed_refs = &trans->transaction->delayed_refs;
944 spin_lock(&delayed_refs->lock); 944 spin_lock(&delayed_refs->lock);
945 head = btrfs_find_delayed_ref_head(trans, bytenr); 945 head = btrfs_find_delayed_ref_head(trans, bytenr);
946 if (head) { 946 if (head) {
947 if (!mutex_trylock(&head->mutex)) { 947 if (!mutex_trylock(&head->mutex)) {
948 atomic_inc(&head->node.refs); 948 atomic_inc(&head->node.refs);
949 spin_unlock(&delayed_refs->lock); 949 spin_unlock(&delayed_refs->lock);
950 950
951 btrfs_release_path(path); 951 btrfs_release_path(path);
952 952
953 /* 953 /*
954 * Mutex was contended, block until it's 954 * Mutex was contended, block until it's
955 * released and try again 955 * released and try again
956 */ 956 */
957 mutex_lock(&head->mutex); 957 mutex_lock(&head->mutex);
958 mutex_unlock(&head->mutex); 958 mutex_unlock(&head->mutex);
959 btrfs_put_delayed_ref(&head->node); 959 btrfs_put_delayed_ref(&head->node);
960 goto again; 960 goto again;
961 } 961 }
962 spin_unlock(&delayed_refs->lock); 962 spin_unlock(&delayed_refs->lock);
963 ret = __add_delayed_refs(head, time_seq, 963 ret = __add_delayed_refs(head, time_seq,
964 &prefs_delayed, &total_refs, 964 &prefs_delayed, &total_refs,
965 inum); 965 inum);
966 mutex_unlock(&head->mutex); 966 mutex_unlock(&head->mutex);
967 if (ret) 967 if (ret)
968 goto out; 968 goto out;
969 } else { 969 } else {
970 spin_unlock(&delayed_refs->lock); 970 spin_unlock(&delayed_refs->lock);
971 } 971 }
972 } 972 }
973 973
974 if (path->slots[0]) { 974 if (path->slots[0]) {
975 struct extent_buffer *leaf; 975 struct extent_buffer *leaf;
976 int slot; 976 int slot;
977 977
978 path->slots[0]--; 978 path->slots[0]--;
979 leaf = path->nodes[0]; 979 leaf = path->nodes[0];
980 slot = path->slots[0]; 980 slot = path->slots[0];
981 btrfs_item_key_to_cpu(leaf, &key, slot); 981 btrfs_item_key_to_cpu(leaf, &key, slot);
982 if (key.objectid == bytenr && 982 if (key.objectid == bytenr &&
983 (key.type == BTRFS_EXTENT_ITEM_KEY || 983 (key.type == BTRFS_EXTENT_ITEM_KEY ||
984 key.type == BTRFS_METADATA_ITEM_KEY)) { 984 key.type == BTRFS_METADATA_ITEM_KEY)) {
985 ret = __add_inline_refs(fs_info, path, bytenr, 985 ret = __add_inline_refs(fs_info, path, bytenr,
986 &info_level, &prefs, 986 &info_level, &prefs,
987 &total_refs, inum); 987 &total_refs, inum);
988 if (ret) 988 if (ret)
989 goto out; 989 goto out;
990 ret = __add_keyed_refs(fs_info, path, bytenr, 990 ret = __add_keyed_refs(fs_info, path, bytenr,
991 info_level, &prefs, inum); 991 info_level, &prefs, inum);
992 if (ret) 992 if (ret)
993 goto out; 993 goto out;
994 } 994 }
995 } 995 }
996 btrfs_release_path(path); 996 btrfs_release_path(path);
997 997
998 list_splice_init(&prefs_delayed, &prefs); 998 list_splice_init(&prefs_delayed, &prefs);
999 999
1000 ret = __add_missing_keys(fs_info, &prefs); 1000 ret = __add_missing_keys(fs_info, &prefs);
1001 if (ret) 1001 if (ret)
1002 goto out; 1002 goto out;
1003 1003
1004 __merge_refs(&prefs, 1); 1004 __merge_refs(&prefs, 1);
1005 1005
1006 ret = __resolve_indirect_refs(fs_info, path, time_seq, &prefs, 1006 ret = __resolve_indirect_refs(fs_info, path, time_seq, &prefs,
1007 extent_item_pos, total_refs, 1007 extent_item_pos, total_refs,
1008 root_objectid); 1008 root_objectid);
1009 if (ret) 1009 if (ret)
1010 goto out; 1010 goto out;
1011 1011
1012 __merge_refs(&prefs, 2); 1012 __merge_refs(&prefs, 2);
1013 1013
1014 while (!list_empty(&prefs)) { 1014 while (!list_empty(&prefs)) {
1015 ref = list_first_entry(&prefs, struct __prelim_ref, list); 1015 ref = list_first_entry(&prefs, struct __prelim_ref, list);
1016 WARN_ON(ref->count < 0); 1016 WARN_ON(ref->count < 0);
1017 if (roots && ref->count && ref->root_id && ref->parent == 0) { 1017 if (roots && ref->count && ref->root_id && ref->parent == 0) {
1018 if (root_objectid && ref->root_id != root_objectid) { 1018 if (root_objectid && ref->root_id != root_objectid) {
1019 ret = BACKREF_FOUND_SHARED; 1019 ret = BACKREF_FOUND_SHARED;
1020 goto out; 1020 goto out;
1021 } 1021 }
1022 1022
1023 /* no parent == root of tree */ 1023 /* no parent == root of tree */
1024 ret = ulist_add(roots, ref->root_id, 0, GFP_NOFS); 1024 ret = ulist_add(roots, ref->root_id, 0, GFP_NOFS);
1025 if (ret < 0) 1025 if (ret < 0)
1026 goto out; 1026 goto out;
1027 } 1027 }
1028 if (ref->count && ref->parent) { 1028 if (ref->count && ref->parent) {
1029 if (extent_item_pos && !ref->inode_list && 1029 if (extent_item_pos && !ref->inode_list &&
1030 ref->level == 0) { 1030 ref->level == 0) {
1031 struct extent_buffer *eb; 1031 struct extent_buffer *eb;
1032 1032
1033 eb = read_tree_block(fs_info->extent_root, 1033 eb = read_tree_block(fs_info->extent_root,
1034 ref->parent, 0); 1034 ref->parent, 0);
1035 if (!eb || !extent_buffer_uptodate(eb)) { 1035 if (!eb || !extent_buffer_uptodate(eb)) {
1036 free_extent_buffer(eb); 1036 free_extent_buffer(eb);
1037 ret = -EIO; 1037 ret = -EIO;
1038 goto out; 1038 goto out;
1039 } 1039 }
1040 btrfs_tree_read_lock(eb); 1040 btrfs_tree_read_lock(eb);
1041 btrfs_set_lock_blocking_rw(eb, BTRFS_READ_LOCK); 1041 btrfs_set_lock_blocking_rw(eb, BTRFS_READ_LOCK);
1042 ret = find_extent_in_eb(eb, bytenr, 1042 ret = find_extent_in_eb(eb, bytenr,
1043 *extent_item_pos, &eie); 1043 *extent_item_pos, &eie);
1044 btrfs_tree_read_unlock_blocking(eb); 1044 btrfs_tree_read_unlock_blocking(eb);
1045 free_extent_buffer(eb); 1045 free_extent_buffer(eb);
1046 if (ret < 0) 1046 if (ret < 0)
1047 goto out; 1047 goto out;
1048 ref->inode_list = eie; 1048 ref->inode_list = eie;
1049 } 1049 }
1050 ret = ulist_add_merge_ptr(refs, ref->parent, 1050 ret = ulist_add_merge_ptr(refs, ref->parent,
1051 ref->inode_list, 1051 ref->inode_list,
1052 (void **)&eie, GFP_NOFS); 1052 (void **)&eie, GFP_NOFS);
1053 if (ret < 0) 1053 if (ret < 0)
1054 goto out; 1054 goto out;
1055 if (!ret && extent_item_pos) { 1055 if (!ret && extent_item_pos) {
1056 /* 1056 /*
1057 * we've recorded that parent, so we must extend 1057 * we've recorded that parent, so we must extend
1058 * its inode list here 1058 * its inode list here
1059 */ 1059 */
1060 BUG_ON(!eie); 1060 BUG_ON(!eie);
1061 while (eie->next) 1061 while (eie->next)
1062 eie = eie->next; 1062 eie = eie->next;
1063 eie->next = ref->inode_list; 1063 eie->next = ref->inode_list;
1064 } 1064 }
1065 eie = NULL; 1065 eie = NULL;
1066 } 1066 }
1067 list_del(&ref->list); 1067 list_del(&ref->list);
1068 kmem_cache_free(btrfs_prelim_ref_cache, ref); 1068 kmem_cache_free(btrfs_prelim_ref_cache, ref);
1069 } 1069 }
1070 1070
1071 out: 1071 out:
1072 btrfs_free_path(path); 1072 btrfs_free_path(path);
1073 while (!list_empty(&prefs)) { 1073 while (!list_empty(&prefs)) {
1074 ref = list_first_entry(&prefs, struct __prelim_ref, list); 1074 ref = list_first_entry(&prefs, struct __prelim_ref, list);
1075 list_del(&ref->list); 1075 list_del(&ref->list);
1076 kmem_cache_free(btrfs_prelim_ref_cache, ref); 1076 kmem_cache_free(btrfs_prelim_ref_cache, ref);
1077 } 1077 }
1078 while (!list_empty(&prefs_delayed)) { 1078 while (!list_empty(&prefs_delayed)) {
1079 ref = list_first_entry(&prefs_delayed, struct __prelim_ref, 1079 ref = list_first_entry(&prefs_delayed, struct __prelim_ref,
1080 list); 1080 list);
1081 list_del(&ref->list); 1081 list_del(&ref->list);
1082 kmem_cache_free(btrfs_prelim_ref_cache, ref); 1082 kmem_cache_free(btrfs_prelim_ref_cache, ref);
1083 } 1083 }
1084 if (ret < 0) 1084 if (ret < 0)
1085 free_inode_elem_list(eie); 1085 free_inode_elem_list(eie);
1086 return ret; 1086 return ret;
1087 } 1087 }
1088 1088
1089 static void free_leaf_list(struct ulist *blocks) 1089 static void free_leaf_list(struct ulist *blocks)
1090 { 1090 {
1091 struct ulist_node *node = NULL; 1091 struct ulist_node *node = NULL;
1092 struct extent_inode_elem *eie; 1092 struct extent_inode_elem *eie;
1093 struct ulist_iterator uiter; 1093 struct ulist_iterator uiter;
1094 1094
1095 ULIST_ITER_INIT(&uiter); 1095 ULIST_ITER_INIT(&uiter);
1096 while ((node = ulist_next(blocks, &uiter))) { 1096 while ((node = ulist_next(blocks, &uiter))) {
1097 if (!node->aux) 1097 if (!node->aux)
1098 continue; 1098 continue;
1099 eie = (struct extent_inode_elem *)(uintptr_t)node->aux; 1099 eie = (struct extent_inode_elem *)(uintptr_t)node->aux;
1100 free_inode_elem_list(eie); 1100 free_inode_elem_list(eie);
1101 node->aux = 0; 1101 node->aux = 0;
1102 } 1102 }
1103 1103
1104 ulist_free(blocks); 1104 ulist_free(blocks);
1105 } 1105 }
1106 1106
1107 /* 1107 /*
1108 * Finds all leafs with a reference to the specified combination of bytenr and 1108 * Finds all leafs with a reference to the specified combination of bytenr and
1109 * offset. key_list_head will point to a list of corresponding keys (caller must 1109 * offset. key_list_head will point to a list of corresponding keys (caller must
1110 * free each list element). The leafs will be stored in the leafs ulist, which 1110 * free each list element). The leafs will be stored in the leafs ulist, which
1111 * must be freed with ulist_free. 1111 * must be freed with ulist_free.
1112 * 1112 *
1113 * returns 0 on success, <0 on error 1113 * returns 0 on success, <0 on error
1114 */ 1114 */
1115 static int btrfs_find_all_leafs(struct btrfs_trans_handle *trans, 1115 static int btrfs_find_all_leafs(struct btrfs_trans_handle *trans,
1116 struct btrfs_fs_info *fs_info, u64 bytenr, 1116 struct btrfs_fs_info *fs_info, u64 bytenr,
1117 u64 time_seq, struct ulist **leafs, 1117 u64 time_seq, struct ulist **leafs,
1118 const u64 *extent_item_pos) 1118 const u64 *extent_item_pos)
1119 { 1119 {
1120 int ret; 1120 int ret;
1121 1121
1122 *leafs = ulist_alloc(GFP_NOFS); 1122 *leafs = ulist_alloc(GFP_NOFS);
1123 if (!*leafs) 1123 if (!*leafs)
1124 return -ENOMEM; 1124 return -ENOMEM;
1125 1125
1126 ret = find_parent_nodes(trans, fs_info, bytenr, 1126 ret = find_parent_nodes(trans, fs_info, bytenr,
1127 time_seq, *leafs, NULL, extent_item_pos, 0, 0); 1127 time_seq, *leafs, NULL, extent_item_pos, 0, 0);
1128 if (ret < 0 && ret != -ENOENT) { 1128 if (ret < 0 && ret != -ENOENT) {
1129 free_leaf_list(*leafs); 1129 free_leaf_list(*leafs);
1130 return ret; 1130 return ret;
1131 } 1131 }
1132 1132
1133 return 0; 1133 return 0;
1134 } 1134 }
1135 1135
1136 /* 1136 /*
1137 * walk all backrefs for a given extent to find all roots that reference this 1137 * walk all backrefs for a given extent to find all roots that reference this
1138 * extent. Walking a backref means finding all extents that reference this 1138 * extent. Walking a backref means finding all extents that reference this
1139 * extent and in turn walk the backrefs of those, too. Naturally this is a 1139 * extent and in turn walk the backrefs of those, too. Naturally this is a
1140 * recursive process, but here it is implemented in an iterative fashion: We 1140 * recursive process, but here it is implemented in an iterative fashion: We
1141 * find all referencing extents for the extent in question and put them on a 1141 * find all referencing extents for the extent in question and put them on a
1142 * list. In turn, we find all referencing extents for those, further appending 1142 * list. In turn, we find all referencing extents for those, further appending
1143 * to the list. The way we iterate the list allows adding more elements after 1143 * to the list. The way we iterate the list allows adding more elements after
1144 * the current while iterating. The process stops when we reach the end of the 1144 * the current while iterating. The process stops when we reach the end of the
1145 * list. Found roots are added to the roots list. 1145 * list. Found roots are added to the roots list.
1146 * 1146 *
1147 * returns 0 on success, < 0 on error. 1147 * returns 0 on success, < 0 on error.
1148 */ 1148 */
1149 static int __btrfs_find_all_roots(struct btrfs_trans_handle *trans, 1149 static int __btrfs_find_all_roots(struct btrfs_trans_handle *trans,
1150 struct btrfs_fs_info *fs_info, u64 bytenr, 1150 struct btrfs_fs_info *fs_info, u64 bytenr,
1151 u64 time_seq, struct ulist **roots) 1151 u64 time_seq, struct ulist **roots)
1152 { 1152 {
1153 struct ulist *tmp; 1153 struct ulist *tmp;
1154 struct ulist_node *node = NULL; 1154 struct ulist_node *node = NULL;
1155 struct ulist_iterator uiter; 1155 struct ulist_iterator uiter;
1156 int ret; 1156 int ret;
1157 1157
1158 tmp = ulist_alloc(GFP_NOFS); 1158 tmp = ulist_alloc(GFP_NOFS);
1159 if (!tmp) 1159 if (!tmp)
1160 return -ENOMEM; 1160 return -ENOMEM;
1161 *roots = ulist_alloc(GFP_NOFS); 1161 *roots = ulist_alloc(GFP_NOFS);
1162 if (!*roots) { 1162 if (!*roots) {
1163 ulist_free(tmp); 1163 ulist_free(tmp);
1164 return -ENOMEM; 1164 return -ENOMEM;
1165 } 1165 }
1166 1166
1167 ULIST_ITER_INIT(&uiter); 1167 ULIST_ITER_INIT(&uiter);
1168 while (1) { 1168 while (1) {
1169 ret = find_parent_nodes(trans, fs_info, bytenr, 1169 ret = find_parent_nodes(trans, fs_info, bytenr,
1170 time_seq, tmp, *roots, NULL, 0, 0); 1170 time_seq, tmp, *roots, NULL, 0, 0);
1171 if (ret < 0 && ret != -ENOENT) { 1171 if (ret < 0 && ret != -ENOENT) {
1172 ulist_free(tmp); 1172 ulist_free(tmp);
1173 ulist_free(*roots); 1173 ulist_free(*roots);
1174 return ret; 1174 return ret;
1175 } 1175 }
1176 node = ulist_next(tmp, &uiter); 1176 node = ulist_next(tmp, &uiter);
1177 if (!node) 1177 if (!node)
1178 break; 1178 break;
1179 bytenr = node->val; 1179 bytenr = node->val;
1180 cond_resched(); 1180 cond_resched();
1181 } 1181 }
1182 1182
1183 ulist_free(tmp); 1183 ulist_free(tmp);
1184 return 0; 1184 return 0;
1185 } 1185 }
1186 1186
1187 int btrfs_find_all_roots(struct btrfs_trans_handle *trans, 1187 int btrfs_find_all_roots(struct btrfs_trans_handle *trans,
1188 struct btrfs_fs_info *fs_info, u64 bytenr, 1188 struct btrfs_fs_info *fs_info, u64 bytenr,
1189 u64 time_seq, struct ulist **roots) 1189 u64 time_seq, struct ulist **roots)
1190 { 1190 {
1191 int ret; 1191 int ret;
1192 1192
1193 if (!trans) 1193 if (!trans)
1194 down_read(&fs_info->commit_root_sem); 1194 down_read(&fs_info->commit_root_sem);
1195 ret = __btrfs_find_all_roots(trans, fs_info, bytenr, time_seq, roots); 1195 ret = __btrfs_find_all_roots(trans, fs_info, bytenr, time_seq, roots);
1196 if (!trans) 1196 if (!trans)
1197 up_read(&fs_info->commit_root_sem); 1197 up_read(&fs_info->commit_root_sem);
1198 return ret; 1198 return ret;
1199 } 1199 }
1200 1200
1201 int btrfs_check_shared(struct btrfs_trans_handle *trans, 1201 int btrfs_check_shared(struct btrfs_trans_handle *trans,
1202 struct btrfs_fs_info *fs_info, u64 root_objectid, 1202 struct btrfs_fs_info *fs_info, u64 root_objectid,
1203 u64 inum, u64 bytenr) 1203 u64 inum, u64 bytenr)
1204 { 1204 {
1205 struct ulist *tmp = NULL; 1205 struct ulist *tmp = NULL;
1206 struct ulist *roots = NULL; 1206 struct ulist *roots = NULL;
1207 struct ulist_iterator uiter; 1207 struct ulist_iterator uiter;
1208 struct ulist_node *node; 1208 struct ulist_node *node;
1209 struct seq_list elem = {}; 1209 struct seq_list elem = {};
1210 int ret = 0; 1210 int ret = 0;
1211 1211
1212 tmp = ulist_alloc(GFP_NOFS); 1212 tmp = ulist_alloc(GFP_NOFS);
1213 roots = ulist_alloc(GFP_NOFS); 1213 roots = ulist_alloc(GFP_NOFS);
1214 if (!tmp || !roots) { 1214 if (!tmp || !roots) {
1215 ulist_free(tmp); 1215 ulist_free(tmp);
1216 ulist_free(roots); 1216 ulist_free(roots);
1217 return -ENOMEM; 1217 return -ENOMEM;
1218 } 1218 }
1219 1219
1220 if (trans) 1220 if (trans)
1221 btrfs_get_tree_mod_seq(fs_info, &elem); 1221 btrfs_get_tree_mod_seq(fs_info, &elem);
1222 else 1222 else
1223 down_read(&fs_info->commit_root_sem); 1223 down_read(&fs_info->commit_root_sem);
1224 ULIST_ITER_INIT(&uiter); 1224 ULIST_ITER_INIT(&uiter);
1225 while (1) { 1225 while (1) {
1226 ret = find_parent_nodes(trans, fs_info, bytenr, elem.seq, tmp, 1226 ret = find_parent_nodes(trans, fs_info, bytenr, elem.seq, tmp,
1227 roots, NULL, root_objectid, inum); 1227 roots, NULL, root_objectid, inum);
1228 if (ret == BACKREF_FOUND_SHARED) { 1228 if (ret == BACKREF_FOUND_SHARED) {
1229 ret = 1; 1229 ret = 1;
1230 break; 1230 break;
1231 } 1231 }
1232 if (ret < 0 && ret != -ENOENT) 1232 if (ret < 0 && ret != -ENOENT)
1233 break; 1233 break;
1234 node = ulist_next(tmp, &uiter); 1234 node = ulist_next(tmp, &uiter);
1235 if (!node) 1235 if (!node)
1236 break; 1236 break;
1237 bytenr = node->val; 1237 bytenr = node->val;
1238 cond_resched(); 1238 cond_resched();
1239 } 1239 }
1240 if (trans) 1240 if (trans)
1241 btrfs_put_tree_mod_seq(fs_info, &elem); 1241 btrfs_put_tree_mod_seq(fs_info, &elem);
1242 else 1242 else
1243 up_read(&fs_info->commit_root_sem); 1243 up_read(&fs_info->commit_root_sem);
1244 ulist_free(tmp); 1244 ulist_free(tmp);
1245 ulist_free(roots); 1245 ulist_free(roots);
1246 return ret; 1246 return ret;
1247 } 1247 }
1248 1248
1249 /* 1249 /*
1250 * this makes the path point to (inum INODE_ITEM ioff) 1250 * this makes the path point to (inum INODE_ITEM ioff)
1251 */ 1251 */
1252 int inode_item_info(u64 inum, u64 ioff, struct btrfs_root *fs_root, 1252 int inode_item_info(u64 inum, u64 ioff, struct btrfs_root *fs_root,
1253 struct btrfs_path *path) 1253 struct btrfs_path *path)
1254 { 1254 {
1255 struct btrfs_key key; 1255 struct btrfs_key key;
1256 return btrfs_find_item(fs_root, path, inum, ioff, 1256 return btrfs_find_item(fs_root, path, inum, ioff,
1257 BTRFS_INODE_ITEM_KEY, &key); 1257 BTRFS_INODE_ITEM_KEY, &key);
1258 } 1258 }
1259 1259
1260 static int inode_ref_info(u64 inum, u64 ioff, struct btrfs_root *fs_root, 1260 static int inode_ref_info(u64 inum, u64 ioff, struct btrfs_root *fs_root,
1261 struct btrfs_path *path, 1261 struct btrfs_path *path,
1262 struct btrfs_key *found_key) 1262 struct btrfs_key *found_key)
1263 { 1263 {
1264 return btrfs_find_item(fs_root, path, inum, ioff, 1264 return btrfs_find_item(fs_root, path, inum, ioff,
1265 BTRFS_INODE_REF_KEY, found_key); 1265 BTRFS_INODE_REF_KEY, found_key);
1266 } 1266 }
1267 1267
1268 int btrfs_find_one_extref(struct btrfs_root *root, u64 inode_objectid, 1268 int btrfs_find_one_extref(struct btrfs_root *root, u64 inode_objectid,
1269 u64 start_off, struct btrfs_path *path, 1269 u64 start_off, struct btrfs_path *path,
1270 struct btrfs_inode_extref **ret_extref, 1270 struct btrfs_inode_extref **ret_extref,
1271 u64 *found_off) 1271 u64 *found_off)
1272 { 1272 {
1273 int ret, slot; 1273 int ret, slot;
1274 struct btrfs_key key; 1274 struct btrfs_key key;
1275 struct btrfs_key found_key; 1275 struct btrfs_key found_key;
1276 struct btrfs_inode_extref *extref; 1276 struct btrfs_inode_extref *extref;
1277 struct extent_buffer *leaf; 1277 struct extent_buffer *leaf;
1278 unsigned long ptr; 1278 unsigned long ptr;
1279 1279
1280 key.objectid = inode_objectid; 1280 key.objectid = inode_objectid;
1281 key.type = BTRFS_INODE_EXTREF_KEY; 1281 key.type = BTRFS_INODE_EXTREF_KEY;
1282 key.offset = start_off; 1282 key.offset = start_off;
1283 1283
1284 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); 1284 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
1285 if (ret < 0) 1285 if (ret < 0)
1286 return ret; 1286 return ret;
1287 1287
1288 while (1) { 1288 while (1) {
1289 leaf = path->nodes[0]; 1289 leaf = path->nodes[0];
1290 slot = path->slots[0]; 1290 slot = path->slots[0];
1291 if (slot >= btrfs_header_nritems(leaf)) { 1291 if (slot >= btrfs_header_nritems(leaf)) {
1292 /* 1292 /*
1293 * If the item at offset is not found, 1293 * If the item at offset is not found,
1294 * btrfs_search_slot will point us to the slot 1294 * btrfs_search_slot will point us to the slot
1295 * where it should be inserted. In our case 1295 * where it should be inserted. In our case
1296 * that will be the slot directly before the 1296 * that will be the slot directly before the
1297 * next INODE_REF_KEY_V2 item. In the case 1297 * next INODE_REF_KEY_V2 item. In the case
1298 * that we're pointing to the last slot in a 1298 * that we're pointing to the last slot in a
1299 * leaf, we must move one leaf over. 1299 * leaf, we must move one leaf over.
1300 */ 1300 */
1301 ret = btrfs_next_leaf(root, path); 1301 ret = btrfs_next_leaf(root, path);
1302 if (ret) { 1302 if (ret) {
1303 if (ret >= 1) 1303 if (ret >= 1)
1304 ret = -ENOENT; 1304 ret = -ENOENT;
1305 break; 1305 break;
1306 } 1306 }
1307 continue; 1307 continue;
1308 } 1308 }
1309 1309
1310 btrfs_item_key_to_cpu(leaf, &found_key, slot); 1310 btrfs_item_key_to_cpu(leaf, &found_key, slot);
1311 1311
1312 /* 1312 /*
1313 * Check that we're still looking at an extended ref key for 1313 * Check that we're still looking at an extended ref key for
1314 * this particular objectid. If we have different 1314 * this particular objectid. If we have different
1315 * objectid or type then there are no more to be found 1315 * objectid or type then there are no more to be found
1316 * in the tree and we can exit. 1316 * in the tree and we can exit.
1317 */ 1317 */
1318 ret = -ENOENT; 1318 ret = -ENOENT;
1319 if (found_key.objectid != inode_objectid) 1319 if (found_key.objectid != inode_objectid)
1320 break; 1320 break;
1321 if (found_key.type != BTRFS_INODE_EXTREF_KEY) 1321 if (found_key.type != BTRFS_INODE_EXTREF_KEY)
1322 break; 1322 break;
1323 1323
1324 ret = 0; 1324 ret = 0;
1325 ptr = btrfs_item_ptr_offset(leaf, path->slots[0]); 1325 ptr = btrfs_item_ptr_offset(leaf, path->slots[0]);
1326 extref = (struct btrfs_inode_extref *)ptr; 1326 extref = (struct btrfs_inode_extref *)ptr;
1327 *ret_extref = extref; 1327 *ret_extref = extref;
1328 if (found_off) 1328 if (found_off)
1329 *found_off = found_key.offset; 1329 *found_off = found_key.offset;
1330 break; 1330 break;
1331 } 1331 }
1332 1332
1333 return ret; 1333 return ret;
1334 } 1334 }
1335 1335
1336 /* 1336 /*
1337 * this iterates to turn a name (from iref/extref) into a full filesystem path. 1337 * this iterates to turn a name (from iref/extref) into a full filesystem path.
1338 * Elements of the path are separated by '/' and the path is guaranteed to be 1338 * Elements of the path are separated by '/' and the path is guaranteed to be
1339 * 0-terminated. the path is only given within the current file system. 1339 * 0-terminated. the path is only given within the current file system.
1340 * Therefore, it never starts with a '/'. the caller is responsible to provide 1340 * Therefore, it never starts with a '/'. the caller is responsible to provide
1341 * "size" bytes in "dest". the dest buffer will be filled backwards. finally, 1341 * "size" bytes in "dest". the dest buffer will be filled backwards. finally,
1342 * the start point of the resulting string is returned. this pointer is within 1342 * the start point of the resulting string is returned. this pointer is within
1343 * dest, normally. 1343 * dest, normally.
1344 * in case the path buffer would overflow, the pointer is decremented further 1344 * in case the path buffer would overflow, the pointer is decremented further
1345 * as if output was written to the buffer, though no more output is actually 1345 * as if output was written to the buffer, though no more output is actually
1346 * generated. that way, the caller can determine how much space would be 1346 * generated. that way, the caller can determine how much space would be
1347 * required for the path to fit into the buffer. in that case, the returned 1347 * required for the path to fit into the buffer. in that case, the returned
1348 * value will be smaller than dest. callers must check this! 1348 * value will be smaller than dest. callers must check this!
1349 */ 1349 */
1350 char *btrfs_ref_to_path(struct btrfs_root *fs_root, struct btrfs_path *path, 1350 char *btrfs_ref_to_path(struct btrfs_root *fs_root, struct btrfs_path *path,
1351 u32 name_len, unsigned long name_off, 1351 u32 name_len, unsigned long name_off,
1352 struct extent_buffer *eb_in, u64 parent, 1352 struct extent_buffer *eb_in, u64 parent,
1353 char *dest, u32 size) 1353 char *dest, u32 size)
1354 { 1354 {
1355 int slot; 1355 int slot;
1356 u64 next_inum; 1356 u64 next_inum;
1357 int ret; 1357 int ret;
1358 s64 bytes_left = ((s64)size) - 1; 1358 s64 bytes_left = ((s64)size) - 1;
1359 struct extent_buffer *eb = eb_in; 1359 struct extent_buffer *eb = eb_in;
1360 struct btrfs_key found_key; 1360 struct btrfs_key found_key;
1361 int leave_spinning = path->leave_spinning; 1361 int leave_spinning = path->leave_spinning;
1362 struct btrfs_inode_ref *iref; 1362 struct btrfs_inode_ref *iref;
1363 1363
1364 if (bytes_left >= 0) 1364 if (bytes_left >= 0)
1365 dest[bytes_left] = '\0'; 1365 dest[bytes_left] = '\0';
1366 1366
1367 path->leave_spinning = 1; 1367 path->leave_spinning = 1;
1368 while (1) { 1368 while (1) {
1369 bytes_left -= name_len; 1369 bytes_left -= name_len;
1370 if (bytes_left >= 0) 1370 if (bytes_left >= 0)
1371 read_extent_buffer(eb, dest + bytes_left, 1371 read_extent_buffer(eb, dest + bytes_left,
1372 name_off, name_len); 1372 name_off, name_len);
1373 if (eb != eb_in) { 1373 if (eb != eb_in) {
1374 btrfs_tree_read_unlock_blocking(eb); 1374 btrfs_tree_read_unlock_blocking(eb);
1375 free_extent_buffer(eb); 1375 free_extent_buffer(eb);
1376 } 1376 }
1377 ret = inode_ref_info(parent, 0, fs_root, path, &found_key); 1377 ret = inode_ref_info(parent, 0, fs_root, path, &found_key);
1378 if (ret > 0) 1378 if (ret > 0)
1379 ret = -ENOENT; 1379 ret = -ENOENT;
1380 if (ret) 1380 if (ret)
1381 break; 1381 break;
1382 1382
1383 next_inum = found_key.offset; 1383 next_inum = found_key.offset;
1384 1384
1385 /* regular exit ahead */ 1385 /* regular exit ahead */
1386 if (parent == next_inum) 1386 if (parent == next_inum)
1387 break; 1387 break;
1388 1388
1389 slot = path->slots[0]; 1389 slot = path->slots[0];
1390 eb = path->nodes[0]; 1390 eb = path->nodes[0];
1391 /* make sure we can use eb after releasing the path */ 1391 /* make sure we can use eb after releasing the path */
1392 if (eb != eb_in) { 1392 if (eb != eb_in) {
1393 atomic_inc(&eb->refs); 1393 atomic_inc(&eb->refs);
1394 btrfs_tree_read_lock(eb); 1394 btrfs_tree_read_lock(eb);
1395 btrfs_set_lock_blocking_rw(eb, BTRFS_READ_LOCK); 1395 btrfs_set_lock_blocking_rw(eb, BTRFS_READ_LOCK);
1396 } 1396 }
1397 btrfs_release_path(path); 1397 btrfs_release_path(path);
1398 iref = btrfs_item_ptr(eb, slot, struct btrfs_inode_ref); 1398 iref = btrfs_item_ptr(eb, slot, struct btrfs_inode_ref);
1399 1399
1400 name_len = btrfs_inode_ref_name_len(eb, iref); 1400 name_len = btrfs_inode_ref_name_len(eb, iref);
1401 name_off = (unsigned long)(iref + 1); 1401 name_off = (unsigned long)(iref + 1);
1402 1402
1403 parent = next_inum; 1403 parent = next_inum;
1404 --bytes_left; 1404 --bytes_left;
1405 if (bytes_left >= 0) 1405 if (bytes_left >= 0)
1406 dest[bytes_left] = '/'; 1406 dest[bytes_left] = '/';
1407 } 1407 }
1408 1408
1409 btrfs_release_path(path); 1409 btrfs_release_path(path);
1410 path->leave_spinning = leave_spinning; 1410 path->leave_spinning = leave_spinning;
1411 1411
1412 if (ret) 1412 if (ret)
1413 return ERR_PTR(ret); 1413 return ERR_PTR(ret);
1414 1414
1415 return dest + bytes_left; 1415 return dest + bytes_left;
1416 } 1416 }
1417 1417
1418 /* 1418 /*
1419 * this makes the path point to (logical EXTENT_ITEM *) 1419 * this makes the path point to (logical EXTENT_ITEM *)
1420 * returns BTRFS_EXTENT_FLAG_DATA for data, BTRFS_EXTENT_FLAG_TREE_BLOCK for 1420 * returns BTRFS_EXTENT_FLAG_DATA for data, BTRFS_EXTENT_FLAG_TREE_BLOCK for
1421 * tree blocks and <0 on error. 1421 * tree blocks and <0 on error.
1422 */ 1422 */
1423 int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical, 1423 int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical,
1424 struct btrfs_path *path, struct btrfs_key *found_key, 1424 struct btrfs_path *path, struct btrfs_key *found_key,
1425 u64 *flags_ret) 1425 u64 *flags_ret)
1426 { 1426 {
1427 int ret; 1427 int ret;
1428 u64 flags; 1428 u64 flags;
1429 u64 size = 0; 1429 u64 size = 0;
1430 u32 item_size; 1430 u32 item_size;
1431 struct extent_buffer *eb; 1431 struct extent_buffer *eb;
1432 struct btrfs_extent_item *ei; 1432 struct btrfs_extent_item *ei;
1433 struct btrfs_key key; 1433 struct btrfs_key key;
1434 1434
1435 if (btrfs_fs_incompat(fs_info, SKINNY_METADATA)) 1435 if (btrfs_fs_incompat(fs_info, SKINNY_METADATA))
1436 key.type = BTRFS_METADATA_ITEM_KEY; 1436 key.type = BTRFS_METADATA_ITEM_KEY;
1437 else 1437 else
1438 key.type = BTRFS_EXTENT_ITEM_KEY; 1438 key.type = BTRFS_EXTENT_ITEM_KEY;
1439 key.objectid = logical; 1439 key.objectid = logical;
1440 key.offset = (u64)-1; 1440 key.offset = (u64)-1;
1441 1441
1442 ret = btrfs_search_slot(NULL, fs_info->extent_root, &key, path, 0, 0); 1442 ret = btrfs_search_slot(NULL, fs_info->extent_root, &key, path, 0, 0);
1443 if (ret < 0) 1443 if (ret < 0)
1444 return ret; 1444 return ret;
1445 1445
1446 ret = btrfs_previous_extent_item(fs_info->extent_root, path, 0); 1446 ret = btrfs_previous_extent_item(fs_info->extent_root, path, 0);
1447 if (ret) { 1447 if (ret) {
1448 if (ret > 0) 1448 if (ret > 0)
1449 ret = -ENOENT; 1449 ret = -ENOENT;
1450 return ret; 1450 return ret;
1451 } 1451 }
1452 btrfs_item_key_to_cpu(path->nodes[0], found_key, path->slots[0]); 1452 btrfs_item_key_to_cpu(path->nodes[0], found_key, path->slots[0]);
1453 if (found_key->type == BTRFS_METADATA_ITEM_KEY) 1453 if (found_key->type == BTRFS_METADATA_ITEM_KEY)
1454 size = fs_info->extent_root->nodesize; 1454 size = fs_info->extent_root->nodesize;
1455 else if (found_key->type == BTRFS_EXTENT_ITEM_KEY) 1455 else if (found_key->type == BTRFS_EXTENT_ITEM_KEY)
1456 size = found_key->offset; 1456 size = found_key->offset;
1457 1457
1458 if (found_key->objectid > logical || 1458 if (found_key->objectid > logical ||
1459 found_key->objectid + size <= logical) { 1459 found_key->objectid + size <= logical) {
1460 pr_debug("logical %llu is not within any extent\n", logical); 1460 pr_debug("logical %llu is not within any extent\n", logical);
1461 return -ENOENT; 1461 return -ENOENT;
1462 } 1462 }
1463 1463
1464 eb = path->nodes[0]; 1464 eb = path->nodes[0];
1465 item_size = btrfs_item_size_nr(eb, path->slots[0]); 1465 item_size = btrfs_item_size_nr(eb, path->slots[0]);
1466 BUG_ON(item_size < sizeof(*ei)); 1466 BUG_ON(item_size < sizeof(*ei));
1467 1467
1468 ei = btrfs_item_ptr(eb, path->slots[0], struct btrfs_extent_item); 1468 ei = btrfs_item_ptr(eb, path->slots[0], struct btrfs_extent_item);
1469 flags = btrfs_extent_flags(eb, ei); 1469 flags = btrfs_extent_flags(eb, ei);
1470 1470
1471 pr_debug("logical %llu is at position %llu within the extent (%llu " 1471 pr_debug("logical %llu is at position %llu within the extent (%llu "
1472 "EXTENT_ITEM %llu) flags %#llx size %u\n", 1472 "EXTENT_ITEM %llu) flags %#llx size %u\n",
1473 logical, logical - found_key->objectid, found_key->objectid, 1473 logical, logical - found_key->objectid, found_key->objectid,
1474 found_key->offset, flags, item_size); 1474 found_key->offset, flags, item_size);
1475 1475
1476 WARN_ON(!flags_ret); 1476 WARN_ON(!flags_ret);
1477 if (flags_ret) { 1477 if (flags_ret) {
1478 if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) 1478 if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK)
1479 *flags_ret = BTRFS_EXTENT_FLAG_TREE_BLOCK; 1479 *flags_ret = BTRFS_EXTENT_FLAG_TREE_BLOCK;
1480 else if (flags & BTRFS_EXTENT_FLAG_DATA) 1480 else if (flags & BTRFS_EXTENT_FLAG_DATA)
1481 *flags_ret = BTRFS_EXTENT_FLAG_DATA; 1481 *flags_ret = BTRFS_EXTENT_FLAG_DATA;
1482 else 1482 else
1483 BUG_ON(1); 1483 BUG_ON(1);
1484 return 0; 1484 return 0;
1485 } 1485 }
1486 1486
1487 return -EIO; 1487 return -EIO;
1488 } 1488 }
1489 1489
1490 /* 1490 /*
1491 * helper function to iterate extent inline refs. ptr must point to a 0 value 1491 * helper function to iterate extent inline refs. ptr must point to a 0 value
1492 * for the first call and may be modified. it is used to track state. 1492 * for the first call and may be modified. it is used to track state.
1493 * if more refs exist, 0 is returned and the next call to 1493 * if more refs exist, 0 is returned and the next call to
1494 * __get_extent_inline_ref must pass the modified ptr parameter to get the 1494 * __get_extent_inline_ref must pass the modified ptr parameter to get the
1495 * next ref. after the last ref was processed, 1 is returned. 1495 * next ref. after the last ref was processed, 1 is returned.
1496 * returns <0 on error 1496 * returns <0 on error
1497 */ 1497 */
1498 static int __get_extent_inline_ref(unsigned long *ptr, struct extent_buffer *eb, 1498 static int __get_extent_inline_ref(unsigned long *ptr, struct extent_buffer *eb,
1499 struct btrfs_key *key, 1499 struct btrfs_key *key,
1500 struct btrfs_extent_item *ei, u32 item_size, 1500 struct btrfs_extent_item *ei, u32 item_size,
1501 struct btrfs_extent_inline_ref **out_eiref, 1501 struct btrfs_extent_inline_ref **out_eiref,
1502 int *out_type) 1502 int *out_type)
1503 { 1503 {
1504 unsigned long end; 1504 unsigned long end;
1505 u64 flags; 1505 u64 flags;
1506 struct btrfs_tree_block_info *info; 1506 struct btrfs_tree_block_info *info;
1507 1507
1508 if (!*ptr) { 1508 if (!*ptr) {
1509 /* first call */ 1509 /* first call */
1510 flags = btrfs_extent_flags(eb, ei); 1510 flags = btrfs_extent_flags(eb, ei);
1511 if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) { 1511 if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) {
1512 if (key->type == BTRFS_METADATA_ITEM_KEY) { 1512 if (key->type == BTRFS_METADATA_ITEM_KEY) {
1513 /* a skinny metadata extent */ 1513 /* a skinny metadata extent */
1514 *out_eiref = 1514 *out_eiref =
1515 (struct btrfs_extent_inline_ref *)(ei + 1); 1515 (struct btrfs_extent_inline_ref *)(ei + 1);
1516 } else { 1516 } else {
1517 WARN_ON(key->type != BTRFS_EXTENT_ITEM_KEY); 1517 WARN_ON(key->type != BTRFS_EXTENT_ITEM_KEY);
1518 info = (struct btrfs_tree_block_info *)(ei + 1); 1518 info = (struct btrfs_tree_block_info *)(ei + 1);
1519 *out_eiref = 1519 *out_eiref =
1520 (struct btrfs_extent_inline_ref *)(info + 1); 1520 (struct btrfs_extent_inline_ref *)(info + 1);
1521 } 1521 }
1522 } else { 1522 } else {
1523 *out_eiref = (struct btrfs_extent_inline_ref *)(ei + 1); 1523 *out_eiref = (struct btrfs_extent_inline_ref *)(ei + 1);
1524 } 1524 }
1525 *ptr = (unsigned long)*out_eiref; 1525 *ptr = (unsigned long)*out_eiref;
1526 if ((unsigned long)(*ptr) >= (unsigned long)ei + item_size) 1526 if ((unsigned long)(*ptr) >= (unsigned long)ei + item_size)
1527 return -ENOENT; 1527 return -ENOENT;
1528 } 1528 }
1529 1529
1530 end = (unsigned long)ei + item_size; 1530 end = (unsigned long)ei + item_size;
1531 *out_eiref = (struct btrfs_extent_inline_ref *)(*ptr); 1531 *out_eiref = (struct btrfs_extent_inline_ref *)(*ptr);
1532 *out_type = btrfs_extent_inline_ref_type(eb, *out_eiref); 1532 *out_type = btrfs_extent_inline_ref_type(eb, *out_eiref);
1533 1533
1534 *ptr += btrfs_extent_inline_ref_size(*out_type); 1534 *ptr += btrfs_extent_inline_ref_size(*out_type);
1535 WARN_ON(*ptr > end); 1535 WARN_ON(*ptr > end);
1536 if (*ptr == end) 1536 if (*ptr == end)
1537 return 1; /* last */ 1537 return 1; /* last */
1538 1538
1539 return 0; 1539 return 0;
1540 } 1540 }
1541 1541
1542 /* 1542 /*
1543 * reads the tree block backref for an extent. tree level and root are returned 1543 * reads the tree block backref for an extent. tree level and root are returned
1544 * through out_level and out_root. ptr must point to a 0 value for the first 1544 * through out_level and out_root. ptr must point to a 0 value for the first
1545 * call and may be modified (see __get_extent_inline_ref comment). 1545 * call and may be modified (see __get_extent_inline_ref comment).
1546 * returns 0 if data was provided, 1 if there was no more data to provide or 1546 * returns 0 if data was provided, 1 if there was no more data to provide or
1547 * <0 on error. 1547 * <0 on error.
1548 */ 1548 */
1549 int tree_backref_for_extent(unsigned long *ptr, struct extent_buffer *eb, 1549 int tree_backref_for_extent(unsigned long *ptr, struct extent_buffer *eb,
1550 struct btrfs_key *key, struct btrfs_extent_item *ei, 1550 struct btrfs_key *key, struct btrfs_extent_item *ei,
1551 u32 item_size, u64 *out_root, u8 *out_level) 1551 u32 item_size, u64 *out_root, u8 *out_level)
1552 { 1552 {
1553 int ret; 1553 int ret;
1554 int type; 1554 int type;
1555 struct btrfs_tree_block_info *info;
1556 struct btrfs_extent_inline_ref *eiref; 1555 struct btrfs_extent_inline_ref *eiref;
1557 1556
1558 if (*ptr == (unsigned long)-1) 1557 if (*ptr == (unsigned long)-1)
1559 return 1; 1558 return 1;
1560 1559
1561 while (1) { 1560 while (1) {
1562 ret = __get_extent_inline_ref(ptr, eb, key, ei, item_size, 1561 ret = __get_extent_inline_ref(ptr, eb, key, ei, item_size,
1563 &eiref, &type); 1562 &eiref, &type);
1564 if (ret < 0) 1563 if (ret < 0)
1565 return ret; 1564 return ret;
1566 1565
1567 if (type == BTRFS_TREE_BLOCK_REF_KEY || 1566 if (type == BTRFS_TREE_BLOCK_REF_KEY ||
1568 type == BTRFS_SHARED_BLOCK_REF_KEY) 1567 type == BTRFS_SHARED_BLOCK_REF_KEY)
1569 break; 1568 break;
1570 1569
1571 if (ret == 1) 1570 if (ret == 1)
1572 return 1; 1571 return 1;
1573 } 1572 }
1574 1573
1575 /* we can treat both ref types equally here */ 1574 /* we can treat both ref types equally here */
1576 info = (struct btrfs_tree_block_info *)(ei + 1);
1577 *out_root = btrfs_extent_inline_ref_offset(eb, eiref); 1575 *out_root = btrfs_extent_inline_ref_offset(eb, eiref);
1578 *out_level = btrfs_tree_block_level(eb, info); 1576
1577 if (key->type == BTRFS_EXTENT_ITEM_KEY) {
1578 struct btrfs_tree_block_info *info;
1579
1580 info = (struct btrfs_tree_block_info *)(ei + 1);
1581 *out_level = btrfs_tree_block_level(eb, info);
1582 } else {
1583 ASSERT(key->type == BTRFS_METADATA_ITEM_KEY);
1584 *out_level = (u8)key->offset;
1585 }
1579 1586
1580 if (ret == 1) 1587 if (ret == 1)
1581 *ptr = (unsigned long)-1; 1588 *ptr = (unsigned long)-1;
1582 1589
1583 return 0; 1590 return 0;
1584 } 1591 }
1585 1592
1586 static int iterate_leaf_refs(struct extent_inode_elem *inode_list, 1593 static int iterate_leaf_refs(struct extent_inode_elem *inode_list,
1587 u64 root, u64 extent_item_objectid, 1594 u64 root, u64 extent_item_objectid,
1588 iterate_extent_inodes_t *iterate, void *ctx) 1595 iterate_extent_inodes_t *iterate, void *ctx)
1589 { 1596 {
1590 struct extent_inode_elem *eie; 1597 struct extent_inode_elem *eie;
1591 int ret = 0; 1598 int ret = 0;
1592 1599
1593 for (eie = inode_list; eie; eie = eie->next) { 1600 for (eie = inode_list; eie; eie = eie->next) {
1594 pr_debug("ref for %llu resolved, key (%llu EXTEND_DATA %llu), " 1601 pr_debug("ref for %llu resolved, key (%llu EXTEND_DATA %llu), "
1595 "root %llu\n", extent_item_objectid, 1602 "root %llu\n", extent_item_objectid,
1596 eie->inum, eie->offset, root); 1603 eie->inum, eie->offset, root);
1597 ret = iterate(eie->inum, eie->offset, root, ctx); 1604 ret = iterate(eie->inum, eie->offset, root, ctx);
1598 if (ret) { 1605 if (ret) {
1599 pr_debug("stopping iteration for %llu due to ret=%d\n", 1606 pr_debug("stopping iteration for %llu due to ret=%d\n",
1600 extent_item_objectid, ret); 1607 extent_item_objectid, ret);
1601 break; 1608 break;
1602 } 1609 }
1603 } 1610 }
1604 1611
1605 return ret; 1612 return ret;
1606 } 1613 }
1607 1614
1608 /* 1615 /*
1609 * calls iterate() for every inode that references the extent identified by 1616 * calls iterate() for every inode that references the extent identified by
1610 * the given parameters. 1617 * the given parameters.
1611 * when the iterator function returns a non-zero value, iteration stops. 1618 * when the iterator function returns a non-zero value, iteration stops.
1612 */ 1619 */
1613 int iterate_extent_inodes(struct btrfs_fs_info *fs_info, 1620 int iterate_extent_inodes(struct btrfs_fs_info *fs_info,
1614 u64 extent_item_objectid, u64 extent_item_pos, 1621 u64 extent_item_objectid, u64 extent_item_pos,
1615 int search_commit_root, 1622 int search_commit_root,
1616 iterate_extent_inodes_t *iterate, void *ctx) 1623 iterate_extent_inodes_t *iterate, void *ctx)
1617 { 1624 {
1618 int ret; 1625 int ret;
1619 struct btrfs_trans_handle *trans = NULL; 1626 struct btrfs_trans_handle *trans = NULL;
1620 struct ulist *refs = NULL; 1627 struct ulist *refs = NULL;
1621 struct ulist *roots = NULL; 1628 struct ulist *roots = NULL;
1622 struct ulist_node *ref_node = NULL; 1629 struct ulist_node *ref_node = NULL;
1623 struct ulist_node *root_node = NULL; 1630 struct ulist_node *root_node = NULL;
1624 struct seq_list tree_mod_seq_elem = {}; 1631 struct seq_list tree_mod_seq_elem = {};
1625 struct ulist_iterator ref_uiter; 1632 struct ulist_iterator ref_uiter;
1626 struct ulist_iterator root_uiter; 1633 struct ulist_iterator root_uiter;
1627 1634
1628 pr_debug("resolving all inodes for extent %llu\n", 1635 pr_debug("resolving all inodes for extent %llu\n",
1629 extent_item_objectid); 1636 extent_item_objectid);
1630 1637
1631 if (!search_commit_root) { 1638 if (!search_commit_root) {
1632 trans = btrfs_join_transaction(fs_info->extent_root); 1639 trans = btrfs_join_transaction(fs_info->extent_root);
1633 if (IS_ERR(trans)) 1640 if (IS_ERR(trans))
1634 return PTR_ERR(trans); 1641 return PTR_ERR(trans);
1635 btrfs_get_tree_mod_seq(fs_info, &tree_mod_seq_elem); 1642 btrfs_get_tree_mod_seq(fs_info, &tree_mod_seq_elem);
1636 } else { 1643 } else {
1637 down_read(&fs_info->commit_root_sem); 1644 down_read(&fs_info->commit_root_sem);
1638 } 1645 }
1639 1646
1640 ret = btrfs_find_all_leafs(trans, fs_info, extent_item_objectid, 1647 ret = btrfs_find_all_leafs(trans, fs_info, extent_item_objectid,
1641 tree_mod_seq_elem.seq, &refs, 1648 tree_mod_seq_elem.seq, &refs,
1642 &extent_item_pos); 1649 &extent_item_pos);
1643 if (ret) 1650 if (ret)
1644 goto out; 1651 goto out;
1645 1652
1646 ULIST_ITER_INIT(&ref_uiter); 1653 ULIST_ITER_INIT(&ref_uiter);
1647 while (!ret && (ref_node = ulist_next(refs, &ref_uiter))) { 1654 while (!ret && (ref_node = ulist_next(refs, &ref_uiter))) {
1648 ret = __btrfs_find_all_roots(trans, fs_info, ref_node->val, 1655 ret = __btrfs_find_all_roots(trans, fs_info, ref_node->val,
1649 tree_mod_seq_elem.seq, &roots); 1656 tree_mod_seq_elem.seq, &roots);
1650 if (ret) 1657 if (ret)
1651 break; 1658 break;
1652 ULIST_ITER_INIT(&root_uiter); 1659 ULIST_ITER_INIT(&root_uiter);
1653 while (!ret && (root_node = ulist_next(roots, &root_uiter))) { 1660 while (!ret && (root_node = ulist_next(roots, &root_uiter))) {
1654 pr_debug("root %llu references leaf %llu, data list " 1661 pr_debug("root %llu references leaf %llu, data list "
1655 "%#llx\n", root_node->val, ref_node->val, 1662 "%#llx\n", root_node->val, ref_node->val,
1656 ref_node->aux); 1663 ref_node->aux);
1657 ret = iterate_leaf_refs((struct extent_inode_elem *) 1664 ret = iterate_leaf_refs((struct extent_inode_elem *)
1658 (uintptr_t)ref_node->aux, 1665 (uintptr_t)ref_node->aux,
1659 root_node->val, 1666 root_node->val,
1660 extent_item_objectid, 1667 extent_item_objectid,
1661 iterate, ctx); 1668 iterate, ctx);
1662 } 1669 }
1663 ulist_free(roots); 1670 ulist_free(roots);
1664 } 1671 }
1665 1672
1666 free_leaf_list(refs); 1673 free_leaf_list(refs);
1667 out: 1674 out:
1668 if (!search_commit_root) { 1675 if (!search_commit_root) {
1669 btrfs_put_tree_mod_seq(fs_info, &tree_mod_seq_elem); 1676 btrfs_put_tree_mod_seq(fs_info, &tree_mod_seq_elem);
1670 btrfs_end_transaction(trans, fs_info->extent_root); 1677 btrfs_end_transaction(trans, fs_info->extent_root);
1671 } else { 1678 } else {
1672 up_read(&fs_info->commit_root_sem); 1679 up_read(&fs_info->commit_root_sem);
1673 } 1680 }
1674 1681
1675 return ret; 1682 return ret;
1676 } 1683 }
1677 1684
1678 int iterate_inodes_from_logical(u64 logical, struct btrfs_fs_info *fs_info, 1685 int iterate_inodes_from_logical(u64 logical, struct btrfs_fs_info *fs_info,
1679 struct btrfs_path *path, 1686 struct btrfs_path *path,
1680 iterate_extent_inodes_t *iterate, void *ctx) 1687 iterate_extent_inodes_t *iterate, void *ctx)
1681 { 1688 {
1682 int ret; 1689 int ret;
1683 u64 extent_item_pos; 1690 u64 extent_item_pos;
1684 u64 flags = 0; 1691 u64 flags = 0;
1685 struct btrfs_key found_key; 1692 struct btrfs_key found_key;
1686 int search_commit_root = path->search_commit_root; 1693 int search_commit_root = path->search_commit_root;
1687 1694
1688 ret = extent_from_logical(fs_info, logical, path, &found_key, &flags); 1695 ret = extent_from_logical(fs_info, logical, path, &found_key, &flags);
1689 btrfs_release_path(path); 1696 btrfs_release_path(path);
1690 if (ret < 0) 1697 if (ret < 0)
1691 return ret; 1698 return ret;
1692 if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) 1699 if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK)
1693 return -EINVAL; 1700 return -EINVAL;
1694 1701
1695 extent_item_pos = logical - found_key.objectid; 1702 extent_item_pos = logical - found_key.objectid;
1696 ret = iterate_extent_inodes(fs_info, found_key.objectid, 1703 ret = iterate_extent_inodes(fs_info, found_key.objectid,
1697 extent_item_pos, search_commit_root, 1704 extent_item_pos, search_commit_root,
1698 iterate, ctx); 1705 iterate, ctx);
1699 1706
1700 return ret; 1707 return ret;
1701 } 1708 }
1702 1709
1703 typedef int (iterate_irefs_t)(u64 parent, u32 name_len, unsigned long name_off, 1710 typedef int (iterate_irefs_t)(u64 parent, u32 name_len, unsigned long name_off,
1704 struct extent_buffer *eb, void *ctx); 1711 struct extent_buffer *eb, void *ctx);
1705 1712
1706 static int iterate_inode_refs(u64 inum, struct btrfs_root *fs_root, 1713 static int iterate_inode_refs(u64 inum, struct btrfs_root *fs_root,
1707 struct btrfs_path *path, 1714 struct btrfs_path *path,
1708 iterate_irefs_t *iterate, void *ctx) 1715 iterate_irefs_t *iterate, void *ctx)
1709 { 1716 {
1710 int ret = 0; 1717 int ret = 0;
1711 int slot; 1718 int slot;
1712 u32 cur; 1719 u32 cur;
1713 u32 len; 1720 u32 len;
1714 u32 name_len; 1721 u32 name_len;
1715 u64 parent = 0; 1722 u64 parent = 0;
1716 int found = 0; 1723 int found = 0;
1717 struct extent_buffer *eb; 1724 struct extent_buffer *eb;
1718 struct btrfs_item *item; 1725 struct btrfs_item *item;
1719 struct btrfs_inode_ref *iref; 1726 struct btrfs_inode_ref *iref;
1720 struct btrfs_key found_key; 1727 struct btrfs_key found_key;
1721 1728
1722 while (!ret) { 1729 while (!ret) {
1723 ret = inode_ref_info(inum, parent ? parent+1 : 0, fs_root, path, 1730 ret = inode_ref_info(inum, parent ? parent+1 : 0, fs_root, path,
1724 &found_key); 1731 &found_key);
1725 if (ret < 0) 1732 if (ret < 0)
1726 break; 1733 break;
1727 if (ret) { 1734 if (ret) {
1728 ret = found ? 0 : -ENOENT; 1735 ret = found ? 0 : -ENOENT;
1729 break; 1736 break;
1730 } 1737 }
1731 ++found; 1738 ++found;
1732 1739
1733 parent = found_key.offset; 1740 parent = found_key.offset;
1734 slot = path->slots[0]; 1741 slot = path->slots[0];
1735 eb = btrfs_clone_extent_buffer(path->nodes[0]); 1742 eb = btrfs_clone_extent_buffer(path->nodes[0]);
1736 if (!eb) { 1743 if (!eb) {
1737 ret = -ENOMEM; 1744 ret = -ENOMEM;
1738 break; 1745 break;
1739 } 1746 }
1740 extent_buffer_get(eb); 1747 extent_buffer_get(eb);
1741 btrfs_tree_read_lock(eb); 1748 btrfs_tree_read_lock(eb);
1742 btrfs_set_lock_blocking_rw(eb, BTRFS_READ_LOCK); 1749 btrfs_set_lock_blocking_rw(eb, BTRFS_READ_LOCK);
1743 btrfs_release_path(path); 1750 btrfs_release_path(path);
1744 1751
1745 item = btrfs_item_nr(slot); 1752 item = btrfs_item_nr(slot);
1746 iref = btrfs_item_ptr(eb, slot, struct btrfs_inode_ref); 1753 iref = btrfs_item_ptr(eb, slot, struct btrfs_inode_ref);
1747 1754
1748 for (cur = 0; cur < btrfs_item_size(eb, item); cur += len) { 1755 for (cur = 0; cur < btrfs_item_size(eb, item); cur += len) {
1749 name_len = btrfs_inode_ref_name_len(eb, iref); 1756 name_len = btrfs_inode_ref_name_len(eb, iref);
1750 /* path must be released before calling iterate()! */ 1757 /* path must be released before calling iterate()! */
1751 pr_debug("following ref at offset %u for inode %llu in " 1758 pr_debug("following ref at offset %u for inode %llu in "
1752 "tree %llu\n", cur, found_key.objectid, 1759 "tree %llu\n", cur, found_key.objectid,
1753 fs_root->objectid); 1760 fs_root->objectid);
1754 ret = iterate(parent, name_len, 1761 ret = iterate(parent, name_len,
1755 (unsigned long)(iref + 1), eb, ctx); 1762 (unsigned long)(iref + 1), eb, ctx);
1756 if (ret) 1763 if (ret)
1757 break; 1764 break;
1758 len = sizeof(*iref) + name_len; 1765 len = sizeof(*iref) + name_len;
1759 iref = (struct btrfs_inode_ref *)((char *)iref + len); 1766 iref = (struct btrfs_inode_ref *)((char *)iref + len);
1760 } 1767 }
1761 btrfs_tree_read_unlock_blocking(eb); 1768 btrfs_tree_read_unlock_blocking(eb);
1762 free_extent_buffer(eb); 1769 free_extent_buffer(eb);
1763 } 1770 }
1764 1771
1765 btrfs_release_path(path); 1772 btrfs_release_path(path);
1766 1773
1767 return ret; 1774 return ret;
1768 } 1775 }
1769 1776
1770 static int iterate_inode_extrefs(u64 inum, struct btrfs_root *fs_root, 1777 static int iterate_inode_extrefs(u64 inum, struct btrfs_root *fs_root,
1771 struct btrfs_path *path, 1778 struct btrfs_path *path,
1772 iterate_irefs_t *iterate, void *ctx) 1779 iterate_irefs_t *iterate, void *ctx)
1773 { 1780 {
1774 int ret; 1781 int ret;
1775 int slot; 1782 int slot;
1776 u64 offset = 0; 1783 u64 offset = 0;
1777 u64 parent; 1784 u64 parent;
1778 int found = 0; 1785 int found = 0;
1779 struct extent_buffer *eb; 1786 struct extent_buffer *eb;
1780 struct btrfs_inode_extref *extref; 1787 struct btrfs_inode_extref *extref;
1781 struct extent_buffer *leaf; 1788 struct extent_buffer *leaf;
1782 u32 item_size; 1789 u32 item_size;
1783 u32 cur_offset; 1790 u32 cur_offset;
1784 unsigned long ptr; 1791 unsigned long ptr;
1785 1792
1786 while (1) { 1793 while (1) {
1787 ret = btrfs_find_one_extref(fs_root, inum, offset, path, &extref, 1794 ret = btrfs_find_one_extref(fs_root, inum, offset, path, &extref,
1788 &offset); 1795 &offset);
1789 if (ret < 0) 1796 if (ret < 0)
1790 break; 1797 break;
1791 if (ret) { 1798 if (ret) {
1792 ret = found ? 0 : -ENOENT; 1799 ret = found ? 0 : -ENOENT;
1793 break; 1800 break;
1794 } 1801 }
1795 ++found; 1802 ++found;
1796 1803
1797 slot = path->slots[0]; 1804 slot = path->slots[0];
1798 eb = btrfs_clone_extent_buffer(path->nodes[0]); 1805 eb = btrfs_clone_extent_buffer(path->nodes[0]);
1799 if (!eb) { 1806 if (!eb) {
1800 ret = -ENOMEM; 1807 ret = -ENOMEM;
1801 break; 1808 break;
1802 } 1809 }
1803 extent_buffer_get(eb); 1810 extent_buffer_get(eb);
1804 1811
1805 btrfs_tree_read_lock(eb); 1812 btrfs_tree_read_lock(eb);
1806 btrfs_set_lock_blocking_rw(eb, BTRFS_READ_LOCK); 1813 btrfs_set_lock_blocking_rw(eb, BTRFS_READ_LOCK);
1807 btrfs_release_path(path); 1814 btrfs_release_path(path);
1808 1815
1809 leaf = path->nodes[0]; 1816 leaf = path->nodes[0];
1810 item_size = btrfs_item_size_nr(leaf, slot); 1817 item_size = btrfs_item_size_nr(leaf, slot);
1811 ptr = btrfs_item_ptr_offset(leaf, slot); 1818 ptr = btrfs_item_ptr_offset(leaf, slot);
1812 cur_offset = 0; 1819 cur_offset = 0;
1813 1820
1814 while (cur_offset < item_size) { 1821 while (cur_offset < item_size) {
1815 u32 name_len; 1822 u32 name_len;
1816 1823
1817 extref = (struct btrfs_inode_extref *)(ptr + cur_offset); 1824 extref = (struct btrfs_inode_extref *)(ptr + cur_offset);
1818 parent = btrfs_inode_extref_parent(eb, extref); 1825 parent = btrfs_inode_extref_parent(eb, extref);
1819 name_len = btrfs_inode_extref_name_len(eb, extref); 1826 name_len = btrfs_inode_extref_name_len(eb, extref);
1820 ret = iterate(parent, name_len, 1827 ret = iterate(parent, name_len,
1821 (unsigned long)&extref->name, eb, ctx); 1828 (unsigned long)&extref->name, eb, ctx);
1822 if (ret) 1829 if (ret)
1823 break; 1830 break;
1824 1831
1825 cur_offset += btrfs_inode_extref_name_len(leaf, extref); 1832 cur_offset += btrfs_inode_extref_name_len(leaf, extref);
1826 cur_offset += sizeof(*extref); 1833 cur_offset += sizeof(*extref);
1827 } 1834 }
1828 btrfs_tree_read_unlock_blocking(eb); 1835 btrfs_tree_read_unlock_blocking(eb);
1829 free_extent_buffer(eb); 1836 free_extent_buffer(eb);
1830 1837
1831 offset++; 1838 offset++;
1832 } 1839 }
1833 1840
1834 btrfs_release_path(path); 1841 btrfs_release_path(path);
1835 1842
1836 return ret; 1843 return ret;
1837 } 1844 }
1838 1845
1839 static int iterate_irefs(u64 inum, struct btrfs_root *fs_root, 1846 static int iterate_irefs(u64 inum, struct btrfs_root *fs_root,
1840 struct btrfs_path *path, iterate_irefs_t *iterate, 1847 struct btrfs_path *path, iterate_irefs_t *iterate,
1841 void *ctx) 1848 void *ctx)
1842 { 1849 {
1843 int ret; 1850 int ret;
1844 int found_refs = 0; 1851 int found_refs = 0;
1845 1852
1846 ret = iterate_inode_refs(inum, fs_root, path, iterate, ctx); 1853 ret = iterate_inode_refs(inum, fs_root, path, iterate, ctx);
1847 if (!ret) 1854 if (!ret)
1848 ++found_refs; 1855 ++found_refs;
1849 else if (ret != -ENOENT) 1856 else if (ret != -ENOENT)
1850 return ret; 1857 return ret;
1851 1858
1852 ret = iterate_inode_extrefs(inum, fs_root, path, iterate, ctx); 1859 ret = iterate_inode_extrefs(inum, fs_root, path, iterate, ctx);
1853 if (ret == -ENOENT && found_refs) 1860 if (ret == -ENOENT && found_refs)
1854 return 0; 1861 return 0;
1855 1862
1856 return ret; 1863 return ret;
1857 } 1864 }
1858 1865
1859 /* 1866 /*
1860 * returns 0 if the path could be dumped (probably truncated) 1867 * returns 0 if the path could be dumped (probably truncated)
1861 * returns <0 in case of an error 1868 * returns <0 in case of an error
1862 */ 1869 */
1863 static int inode_to_path(u64 inum, u32 name_len, unsigned long name_off, 1870 static int inode_to_path(u64 inum, u32 name_len, unsigned long name_off,
1864 struct extent_buffer *eb, void *ctx) 1871 struct extent_buffer *eb, void *ctx)
1865 { 1872 {
1866 struct inode_fs_paths *ipath = ctx; 1873 struct inode_fs_paths *ipath = ctx;
1867 char *fspath; 1874 char *fspath;
1868 char *fspath_min; 1875 char *fspath_min;
1869 int i = ipath->fspath->elem_cnt; 1876 int i = ipath->fspath->elem_cnt;
1870 const int s_ptr = sizeof(char *); 1877 const int s_ptr = sizeof(char *);
1871 u32 bytes_left; 1878 u32 bytes_left;
1872 1879
1873 bytes_left = ipath->fspath->bytes_left > s_ptr ? 1880 bytes_left = ipath->fspath->bytes_left > s_ptr ?
1874 ipath->fspath->bytes_left - s_ptr : 0; 1881 ipath->fspath->bytes_left - s_ptr : 0;
1875 1882
1876 fspath_min = (char *)ipath->fspath->val + (i + 1) * s_ptr; 1883 fspath_min = (char *)ipath->fspath->val + (i + 1) * s_ptr;
1877 fspath = btrfs_ref_to_path(ipath->fs_root, ipath->btrfs_path, name_len, 1884 fspath = btrfs_ref_to_path(ipath->fs_root, ipath->btrfs_path, name_len,
1878 name_off, eb, inum, fspath_min, bytes_left); 1885 name_off, eb, inum, fspath_min, bytes_left);
1879 if (IS_ERR(fspath)) 1886 if (IS_ERR(fspath))
1880 return PTR_ERR(fspath); 1887 return PTR_ERR(fspath);
1881 1888
1882 if (fspath > fspath_min) { 1889 if (fspath > fspath_min) {
1883 ipath->fspath->val[i] = (u64)(unsigned long)fspath; 1890 ipath->fspath->val[i] = (u64)(unsigned long)fspath;
1884 ++ipath->fspath->elem_cnt; 1891 ++ipath->fspath->elem_cnt;
1885 ipath->fspath->bytes_left = fspath - fspath_min; 1892 ipath->fspath->bytes_left = fspath - fspath_min;
1886 } else { 1893 } else {
1887 ++ipath->fspath->elem_missed; 1894 ++ipath->fspath->elem_missed;
1888 ipath->fspath->bytes_missing += fspath_min - fspath; 1895 ipath->fspath->bytes_missing += fspath_min - fspath;
1889 ipath->fspath->bytes_left = 0; 1896 ipath->fspath->bytes_left = 0;
1890 } 1897 }
1891 1898
1892 return 0; 1899 return 0;
1893 } 1900 }
1894 1901
1895 /* 1902 /*
1896 * this dumps all file system paths to the inode into the ipath struct, provided 1903 * this dumps all file system paths to the inode into the ipath struct, provided
1897 * is has been created large enough. each path is zero-terminated and accessed 1904 * is has been created large enough. each path is zero-terminated and accessed
1898 * from ipath->fspath->val[i]. 1905 * from ipath->fspath->val[i].
1899 * when it returns, there are ipath->fspath->elem_cnt number of paths available 1906 * when it returns, there are ipath->fspath->elem_cnt number of paths available
1900 * in ipath->fspath->val[]. when the allocated space wasn't sufficient, the 1907 * in ipath->fspath->val[]. when the allocated space wasn't sufficient, the
1901 * number of missed paths in recored in ipath->fspath->elem_missed, otherwise, 1908 * number of missed paths in recored in ipath->fspath->elem_missed, otherwise,
1902 * it's zero. ipath->fspath->bytes_missing holds the number of bytes that would 1909 * it's zero. ipath->fspath->bytes_missing holds the number of bytes that would
1903 * have been needed to return all paths. 1910 * have been needed to return all paths.
1904 */ 1911 */
1905 int paths_from_inode(u64 inum, struct inode_fs_paths *ipath) 1912 int paths_from_inode(u64 inum, struct inode_fs_paths *ipath)
1906 { 1913 {
1907 return iterate_irefs(inum, ipath->fs_root, ipath->btrfs_path, 1914 return iterate_irefs(inum, ipath->fs_root, ipath->btrfs_path,
1908 inode_to_path, ipath); 1915 inode_to_path, ipath);
1909 } 1916 }
1910 1917
1911 struct btrfs_data_container *init_data_container(u32 total_bytes) 1918 struct btrfs_data_container *init_data_container(u32 total_bytes)
1912 { 1919 {
1913 struct btrfs_data_container *data; 1920 struct btrfs_data_container *data;
1914 size_t alloc_bytes; 1921 size_t alloc_bytes;
1915 1922
1916 alloc_bytes = max_t(size_t, total_bytes, sizeof(*data)); 1923 alloc_bytes = max_t(size_t, total_bytes, sizeof(*data));
1917 data = vmalloc(alloc_bytes); 1924 data = vmalloc(alloc_bytes);
1918 if (!data) 1925 if (!data)
1919 return ERR_PTR(-ENOMEM); 1926 return ERR_PTR(-ENOMEM);
1920 1927
1921 if (total_bytes >= sizeof(*data)) { 1928 if (total_bytes >= sizeof(*data)) {
1922 data->bytes_left = total_bytes - sizeof(*data); 1929 data->bytes_left = total_bytes - sizeof(*data);
1923 data->bytes_missing = 0; 1930 data->bytes_missing = 0;
1924 } else { 1931 } else {
1925 data->bytes_missing = sizeof(*data) - total_bytes; 1932 data->bytes_missing = sizeof(*data) - total_bytes;
1926 data->bytes_left = 0; 1933 data->bytes_left = 0;
1927 } 1934 }
1928 1935
1929 data->elem_cnt = 0; 1936 data->elem_cnt = 0;
1930 data->elem_missed = 0; 1937 data->elem_missed = 0;
1931 1938
1932 return data; 1939 return data;
1933 } 1940 }
1934 1941
1935 /* 1942 /*
1936 * allocates space to return multiple file system paths for an inode. 1943 * allocates space to return multiple file system paths for an inode.
1937 * total_bytes to allocate are passed, note that space usable for actual path 1944 * total_bytes to allocate are passed, note that space usable for actual path
1938 * information will be total_bytes - sizeof(struct inode_fs_paths). 1945 * information will be total_bytes - sizeof(struct inode_fs_paths).
1939 * the returned pointer must be freed with free_ipath() in the end. 1946 * the returned pointer must be freed with free_ipath() in the end.
1940 */ 1947 */
1941 struct inode_fs_paths *init_ipath(s32 total_bytes, struct btrfs_root *fs_root, 1948 struct inode_fs_paths *init_ipath(s32 total_bytes, struct btrfs_root *fs_root,
1942 struct btrfs_path *path) 1949 struct btrfs_path *path)
1943 { 1950 {
1944 struct inode_fs_paths *ifp; 1951 struct inode_fs_paths *ifp;
1945 struct btrfs_data_container *fspath; 1952 struct btrfs_data_container *fspath;
1946 1953
1947 fspath = init_data_container(total_bytes); 1954 fspath = init_data_container(total_bytes);
1948 if (IS_ERR(fspath)) 1955 if (IS_ERR(fspath))
1949 return (void *)fspath; 1956 return (void *)fspath;
1950 1957
1951 ifp = kmalloc(sizeof(*ifp), GFP_NOFS); 1958 ifp = kmalloc(sizeof(*ifp), GFP_NOFS);
1952 if (!ifp) { 1959 if (!ifp) {
1953 kfree(fspath); 1960 kfree(fspath);
1954 return ERR_PTR(-ENOMEM); 1961 return ERR_PTR(-ENOMEM);
1955 } 1962 }
1956 1963
1957 ifp->btrfs_path = path; 1964 ifp->btrfs_path = path;
1958 ifp->fspath = fspath; 1965 ifp->fspath = fspath;
1959 ifp->fs_root = fs_root; 1966 ifp->fs_root = fs_root;
1960 1967
1961 return ifp; 1968 return ifp;
1962 } 1969 }
1963 1970
1964 void free_ipath(struct inode_fs_paths *ipath) 1971 void free_ipath(struct inode_fs_paths *ipath)
1965 { 1972 {
1966 if (!ipath) 1973 if (!ipath)
1967 return; 1974 return;
1968 vfree(ipath->fspath); 1975 vfree(ipath->fspath);
1969 kfree(ipath); 1976 kfree(ipath);
fs/btrfs/delayed-inode.c
1 /* 1 /*
2 * Copyright (C) 2011 Fujitsu. All rights reserved. 2 * Copyright (C) 2011 Fujitsu. All rights reserved.
3 * Written by Miao Xie <miaox@cn.fujitsu.com> 3 * Written by Miao Xie <miaox@cn.fujitsu.com>
4 * 4 *
5 * This program is free software; you can redistribute it and/or 5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public 6 * modify it under the terms of the GNU General Public
7 * License v2 as published by the Free Software Foundation. 7 * License v2 as published by the Free Software Foundation.
8 * 8 *
9 * This program is distributed in the hope that it will be useful, 9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details. 12 * General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public 14 * You should have received a copy of the GNU General Public
15 * License along with this program; if not, write to the 15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 021110-1307, USA. 17 * Boston, MA 021110-1307, USA.
18 */ 18 */
19 19
20 #include <linux/slab.h> 20 #include <linux/slab.h>
21 #include "delayed-inode.h" 21 #include "delayed-inode.h"
22 #include "disk-io.h" 22 #include "disk-io.h"
23 #include "transaction.h" 23 #include "transaction.h"
24 #include "ctree.h" 24 #include "ctree.h"
25 25
26 #define BTRFS_DELAYED_WRITEBACK 512 26 #define BTRFS_DELAYED_WRITEBACK 512
27 #define BTRFS_DELAYED_BACKGROUND 128 27 #define BTRFS_DELAYED_BACKGROUND 128
28 #define BTRFS_DELAYED_BATCH 16 28 #define BTRFS_DELAYED_BATCH 16
29 29
30 static struct kmem_cache *delayed_node_cache; 30 static struct kmem_cache *delayed_node_cache;
31 31
32 int __init btrfs_delayed_inode_init(void) 32 int __init btrfs_delayed_inode_init(void)
33 { 33 {
34 delayed_node_cache = kmem_cache_create("btrfs_delayed_node", 34 delayed_node_cache = kmem_cache_create("btrfs_delayed_node",
35 sizeof(struct btrfs_delayed_node), 35 sizeof(struct btrfs_delayed_node),
36 0, 36 0,
37 SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, 37 SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD,
38 NULL); 38 NULL);
39 if (!delayed_node_cache) 39 if (!delayed_node_cache)
40 return -ENOMEM; 40 return -ENOMEM;
41 return 0; 41 return 0;
42 } 42 }
43 43
44 void btrfs_delayed_inode_exit(void) 44 void btrfs_delayed_inode_exit(void)
45 { 45 {
46 if (delayed_node_cache) 46 if (delayed_node_cache)
47 kmem_cache_destroy(delayed_node_cache); 47 kmem_cache_destroy(delayed_node_cache);
48 } 48 }
49 49
50 static inline void btrfs_init_delayed_node( 50 static inline void btrfs_init_delayed_node(
51 struct btrfs_delayed_node *delayed_node, 51 struct btrfs_delayed_node *delayed_node,
52 struct btrfs_root *root, u64 inode_id) 52 struct btrfs_root *root, u64 inode_id)
53 { 53 {
54 delayed_node->root = root; 54 delayed_node->root = root;
55 delayed_node->inode_id = inode_id; 55 delayed_node->inode_id = inode_id;
56 atomic_set(&delayed_node->refs, 0); 56 atomic_set(&delayed_node->refs, 0);
57 delayed_node->count = 0; 57 delayed_node->count = 0;
58 delayed_node->flags = 0; 58 delayed_node->flags = 0;
59 delayed_node->ins_root = RB_ROOT; 59 delayed_node->ins_root = RB_ROOT;
60 delayed_node->del_root = RB_ROOT; 60 delayed_node->del_root = RB_ROOT;
61 mutex_init(&delayed_node->mutex); 61 mutex_init(&delayed_node->mutex);
62 delayed_node->index_cnt = 0; 62 delayed_node->index_cnt = 0;
63 INIT_LIST_HEAD(&delayed_node->n_list); 63 INIT_LIST_HEAD(&delayed_node->n_list);
64 INIT_LIST_HEAD(&delayed_node->p_list); 64 INIT_LIST_HEAD(&delayed_node->p_list);
65 delayed_node->bytes_reserved = 0; 65 delayed_node->bytes_reserved = 0;
66 memset(&delayed_node->inode_item, 0, sizeof(delayed_node->inode_item)); 66 memset(&delayed_node->inode_item, 0, sizeof(delayed_node->inode_item));
67 } 67 }
68 68
69 static inline int btrfs_is_continuous_delayed_item( 69 static inline int btrfs_is_continuous_delayed_item(
70 struct btrfs_delayed_item *item1, 70 struct btrfs_delayed_item *item1,
71 struct btrfs_delayed_item *item2) 71 struct btrfs_delayed_item *item2)
72 { 72 {
73 if (item1->key.type == BTRFS_DIR_INDEX_KEY && 73 if (item1->key.type == BTRFS_DIR_INDEX_KEY &&
74 item1->key.objectid == item2->key.objectid && 74 item1->key.objectid == item2->key.objectid &&
75 item1->key.type == item2->key.type && 75 item1->key.type == item2->key.type &&
76 item1->key.offset + 1 == item2->key.offset) 76 item1->key.offset + 1 == item2->key.offset)
77 return 1; 77 return 1;
78 return 0; 78 return 0;
79 } 79 }
80 80
81 static inline struct btrfs_delayed_root *btrfs_get_delayed_root( 81 static inline struct btrfs_delayed_root *btrfs_get_delayed_root(
82 struct btrfs_root *root) 82 struct btrfs_root *root)
83 { 83 {
84 return root->fs_info->delayed_root; 84 return root->fs_info->delayed_root;
85 } 85 }
86 86
87 static struct btrfs_delayed_node *btrfs_get_delayed_node(struct inode *inode) 87 static struct btrfs_delayed_node *btrfs_get_delayed_node(struct inode *inode)
88 { 88 {
89 struct btrfs_inode *btrfs_inode = BTRFS_I(inode); 89 struct btrfs_inode *btrfs_inode = BTRFS_I(inode);
90 struct btrfs_root *root = btrfs_inode->root; 90 struct btrfs_root *root = btrfs_inode->root;
91 u64 ino = btrfs_ino(inode); 91 u64 ino = btrfs_ino(inode);
92 struct btrfs_delayed_node *node; 92 struct btrfs_delayed_node *node;
93 93
94 node = ACCESS_ONCE(btrfs_inode->delayed_node); 94 node = ACCESS_ONCE(btrfs_inode->delayed_node);
95 if (node) { 95 if (node) {
96 atomic_inc(&node->refs); 96 atomic_inc(&node->refs);
97 return node; 97 return node;
98 } 98 }
99 99
100 spin_lock(&root->inode_lock); 100 spin_lock(&root->inode_lock);
101 node = radix_tree_lookup(&root->delayed_nodes_tree, ino); 101 node = radix_tree_lookup(&root->delayed_nodes_tree, ino);
102 if (node) { 102 if (node) {
103 if (btrfs_inode->delayed_node) { 103 if (btrfs_inode->delayed_node) {
104 atomic_inc(&node->refs); /* can be accessed */ 104 atomic_inc(&node->refs); /* can be accessed */
105 BUG_ON(btrfs_inode->delayed_node != node); 105 BUG_ON(btrfs_inode->delayed_node != node);
106 spin_unlock(&root->inode_lock); 106 spin_unlock(&root->inode_lock);
107 return node; 107 return node;
108 } 108 }
109 btrfs_inode->delayed_node = node; 109 btrfs_inode->delayed_node = node;
110 /* can be accessed and cached in the inode */ 110 /* can be accessed and cached in the inode */
111 atomic_add(2, &node->refs); 111 atomic_add(2, &node->refs);
112 spin_unlock(&root->inode_lock); 112 spin_unlock(&root->inode_lock);
113 return node; 113 return node;
114 } 114 }
115 spin_unlock(&root->inode_lock); 115 spin_unlock(&root->inode_lock);
116 116
117 return NULL; 117 return NULL;
118 } 118 }
119 119
120 /* Will return either the node or PTR_ERR(-ENOMEM) */ 120 /* Will return either the node or PTR_ERR(-ENOMEM) */
121 static struct btrfs_delayed_node *btrfs_get_or_create_delayed_node( 121 static struct btrfs_delayed_node *btrfs_get_or_create_delayed_node(
122 struct inode *inode) 122 struct inode *inode)
123 { 123 {
124 struct btrfs_delayed_node *node; 124 struct btrfs_delayed_node *node;
125 struct btrfs_inode *btrfs_inode = BTRFS_I(inode); 125 struct btrfs_inode *btrfs_inode = BTRFS_I(inode);
126 struct btrfs_root *root = btrfs_inode->root; 126 struct btrfs_root *root = btrfs_inode->root;
127 u64 ino = btrfs_ino(inode); 127 u64 ino = btrfs_ino(inode);
128 int ret; 128 int ret;
129 129
130 again: 130 again:
131 node = btrfs_get_delayed_node(inode); 131 node = btrfs_get_delayed_node(inode);
132 if (node) 132 if (node)
133 return node; 133 return node;
134 134
135 node = kmem_cache_alloc(delayed_node_cache, GFP_NOFS); 135 node = kmem_cache_alloc(delayed_node_cache, GFP_NOFS);
136 if (!node) 136 if (!node)
137 return ERR_PTR(-ENOMEM); 137 return ERR_PTR(-ENOMEM);
138 btrfs_init_delayed_node(node, root, ino); 138 btrfs_init_delayed_node(node, root, ino);
139 139
140 /* cached in the btrfs inode and can be accessed */ 140 /* cached in the btrfs inode and can be accessed */
141 atomic_add(2, &node->refs); 141 atomic_add(2, &node->refs);
142 142
143 ret = radix_tree_preload(GFP_NOFS & ~__GFP_HIGHMEM); 143 ret = radix_tree_preload(GFP_NOFS & ~__GFP_HIGHMEM);
144 if (ret) { 144 if (ret) {
145 kmem_cache_free(delayed_node_cache, node); 145 kmem_cache_free(delayed_node_cache, node);
146 return ERR_PTR(ret); 146 return ERR_PTR(ret);
147 } 147 }
148 148
149 spin_lock(&root->inode_lock); 149 spin_lock(&root->inode_lock);
150 ret = radix_tree_insert(&root->delayed_nodes_tree, ino, node); 150 ret = radix_tree_insert(&root->delayed_nodes_tree, ino, node);
151 if (ret == -EEXIST) { 151 if (ret == -EEXIST) {
152 spin_unlock(&root->inode_lock); 152 spin_unlock(&root->inode_lock);
153 kmem_cache_free(delayed_node_cache, node); 153 kmem_cache_free(delayed_node_cache, node);
154 radix_tree_preload_end(); 154 radix_tree_preload_end();
155 goto again; 155 goto again;
156 } 156 }
157 btrfs_inode->delayed_node = node; 157 btrfs_inode->delayed_node = node;
158 spin_unlock(&root->inode_lock); 158 spin_unlock(&root->inode_lock);
159 radix_tree_preload_end(); 159 radix_tree_preload_end();
160 160
161 return node; 161 return node;
162 } 162 }
163 163
164 /* 164 /*
165 * Call it when holding delayed_node->mutex 165 * Call it when holding delayed_node->mutex
166 * 166 *
167 * If mod = 1, add this node into the prepared list. 167 * If mod = 1, add this node into the prepared list.
168 */ 168 */
169 static void btrfs_queue_delayed_node(struct btrfs_delayed_root *root, 169 static void btrfs_queue_delayed_node(struct btrfs_delayed_root *root,
170 struct btrfs_delayed_node *node, 170 struct btrfs_delayed_node *node,
171 int mod) 171 int mod)
172 { 172 {
173 spin_lock(&root->lock); 173 spin_lock(&root->lock);
174 if (test_bit(BTRFS_DELAYED_NODE_IN_LIST, &node->flags)) { 174 if (test_bit(BTRFS_DELAYED_NODE_IN_LIST, &node->flags)) {
175 if (!list_empty(&node->p_list)) 175 if (!list_empty(&node->p_list))
176 list_move_tail(&node->p_list, &root->prepare_list); 176 list_move_tail(&node->p_list, &root->prepare_list);
177 else if (mod) 177 else if (mod)
178 list_add_tail(&node->p_list, &root->prepare_list); 178 list_add_tail(&node->p_list, &root->prepare_list);
179 } else { 179 } else {
180 list_add_tail(&node->n_list, &root->node_list); 180 list_add_tail(&node->n_list, &root->node_list);
181 list_add_tail(&node->p_list, &root->prepare_list); 181 list_add_tail(&node->p_list, &root->prepare_list);
182 atomic_inc(&node->refs); /* inserted into list */ 182 atomic_inc(&node->refs); /* inserted into list */
183 root->nodes++; 183 root->nodes++;
184 set_bit(BTRFS_DELAYED_NODE_IN_LIST, &node->flags); 184 set_bit(BTRFS_DELAYED_NODE_IN_LIST, &node->flags);
185 } 185 }
186 spin_unlock(&root->lock); 186 spin_unlock(&root->lock);
187 } 187 }
188 188
189 /* Call it when holding delayed_node->mutex */ 189 /* Call it when holding delayed_node->mutex */
190 static void btrfs_dequeue_delayed_node(struct btrfs_delayed_root *root, 190 static void btrfs_dequeue_delayed_node(struct btrfs_delayed_root *root,
191 struct btrfs_delayed_node *node) 191 struct btrfs_delayed_node *node)
192 { 192 {
193 spin_lock(&root->lock); 193 spin_lock(&root->lock);
194 if (test_bit(BTRFS_DELAYED_NODE_IN_LIST, &node->flags)) { 194 if (test_bit(BTRFS_DELAYED_NODE_IN_LIST, &node->flags)) {
195 root->nodes--; 195 root->nodes--;
196 atomic_dec(&node->refs); /* not in the list */ 196 atomic_dec(&node->refs); /* not in the list */
197 list_del_init(&node->n_list); 197 list_del_init(&node->n_list);
198 if (!list_empty(&node->p_list)) 198 if (!list_empty(&node->p_list))
199 list_del_init(&node->p_list); 199 list_del_init(&node->p_list);
200 clear_bit(BTRFS_DELAYED_NODE_IN_LIST, &node->flags); 200 clear_bit(BTRFS_DELAYED_NODE_IN_LIST, &node->flags);
201 } 201 }
202 spin_unlock(&root->lock); 202 spin_unlock(&root->lock);
203 } 203 }
204 204
205 static struct btrfs_delayed_node *btrfs_first_delayed_node( 205 static struct btrfs_delayed_node *btrfs_first_delayed_node(
206 struct btrfs_delayed_root *delayed_root) 206 struct btrfs_delayed_root *delayed_root)
207 { 207 {
208 struct list_head *p; 208 struct list_head *p;
209 struct btrfs_delayed_node *node = NULL; 209 struct btrfs_delayed_node *node = NULL;
210 210
211 spin_lock(&delayed_root->lock); 211 spin_lock(&delayed_root->lock);
212 if (list_empty(&delayed_root->node_list)) 212 if (list_empty(&delayed_root->node_list))
213 goto out; 213 goto out;
214 214
215 p = delayed_root->node_list.next; 215 p = delayed_root->node_list.next;
216 node = list_entry(p, struct btrfs_delayed_node, n_list); 216 node = list_entry(p, struct btrfs_delayed_node, n_list);
217 atomic_inc(&node->refs); 217 atomic_inc(&node->refs);
218 out: 218 out:
219 spin_unlock(&delayed_root->lock); 219 spin_unlock(&delayed_root->lock);
220 220
221 return node; 221 return node;
222 } 222 }
223 223
224 static struct btrfs_delayed_node *btrfs_next_delayed_node( 224 static struct btrfs_delayed_node *btrfs_next_delayed_node(
225 struct btrfs_delayed_node *node) 225 struct btrfs_delayed_node *node)
226 { 226 {
227 struct btrfs_delayed_root *delayed_root; 227 struct btrfs_delayed_root *delayed_root;
228 struct list_head *p; 228 struct list_head *p;
229 struct btrfs_delayed_node *next = NULL; 229 struct btrfs_delayed_node *next = NULL;
230 230
231 delayed_root = node->root->fs_info->delayed_root; 231 delayed_root = node->root->fs_info->delayed_root;
232 spin_lock(&delayed_root->lock); 232 spin_lock(&delayed_root->lock);
233 if (!test_bit(BTRFS_DELAYED_NODE_IN_LIST, &node->flags)) { 233 if (!test_bit(BTRFS_DELAYED_NODE_IN_LIST, &node->flags)) {
234 /* not in the list */ 234 /* not in the list */
235 if (list_empty(&delayed_root->node_list)) 235 if (list_empty(&delayed_root->node_list))
236 goto out; 236 goto out;
237 p = delayed_root->node_list.next; 237 p = delayed_root->node_list.next;
238 } else if (list_is_last(&node->n_list, &delayed_root->node_list)) 238 } else if (list_is_last(&node->n_list, &delayed_root->node_list))
239 goto out; 239 goto out;
240 else 240 else
241 p = node->n_list.next; 241 p = node->n_list.next;
242 242
243 next = list_entry(p, struct btrfs_delayed_node, n_list); 243 next = list_entry(p, struct btrfs_delayed_node, n_list);
244 atomic_inc(&next->refs); 244 atomic_inc(&next->refs);
245 out: 245 out:
246 spin_unlock(&delayed_root->lock); 246 spin_unlock(&delayed_root->lock);
247 247
248 return next; 248 return next;
249 } 249 }
250 250
251 static void __btrfs_release_delayed_node( 251 static void __btrfs_release_delayed_node(
252 struct btrfs_delayed_node *delayed_node, 252 struct btrfs_delayed_node *delayed_node,
253 int mod) 253 int mod)
254 { 254 {
255 struct btrfs_delayed_root *delayed_root; 255 struct btrfs_delayed_root *delayed_root;
256 256
257 if (!delayed_node) 257 if (!delayed_node)
258 return; 258 return;
259 259
260 delayed_root = delayed_node->root->fs_info->delayed_root; 260 delayed_root = delayed_node->root->fs_info->delayed_root;
261 261
262 mutex_lock(&delayed_node->mutex); 262 mutex_lock(&delayed_node->mutex);
263 if (delayed_node->count) 263 if (delayed_node->count)
264 btrfs_queue_delayed_node(delayed_root, delayed_node, mod); 264 btrfs_queue_delayed_node(delayed_root, delayed_node, mod);
265 else 265 else
266 btrfs_dequeue_delayed_node(delayed_root, delayed_node); 266 btrfs_dequeue_delayed_node(delayed_root, delayed_node);
267 mutex_unlock(&delayed_node->mutex); 267 mutex_unlock(&delayed_node->mutex);
268 268
269 if (atomic_dec_and_test(&delayed_node->refs)) { 269 if (atomic_dec_and_test(&delayed_node->refs)) {
270 bool free = false; 270 bool free = false;
271 struct btrfs_root *root = delayed_node->root; 271 struct btrfs_root *root = delayed_node->root;
272 spin_lock(&root->inode_lock); 272 spin_lock(&root->inode_lock);
273 if (atomic_read(&delayed_node->refs) == 0) { 273 if (atomic_read(&delayed_node->refs) == 0) {
274 radix_tree_delete(&root->delayed_nodes_tree, 274 radix_tree_delete(&root->delayed_nodes_tree,
275 delayed_node->inode_id); 275 delayed_node->inode_id);
276 free = true; 276 free = true;
277 } 277 }
278 spin_unlock(&root->inode_lock); 278 spin_unlock(&root->inode_lock);
279 if (free) 279 if (free)
280 kmem_cache_free(delayed_node_cache, delayed_node); 280 kmem_cache_free(delayed_node_cache, delayed_node);
281 } 281 }
282 } 282 }
283 283
284 static inline void btrfs_release_delayed_node(struct btrfs_delayed_node *node) 284 static inline void btrfs_release_delayed_node(struct btrfs_delayed_node *node)
285 { 285 {
286 __btrfs_release_delayed_node(node, 0); 286 __btrfs_release_delayed_node(node, 0);
287 } 287 }
288 288
289 static struct btrfs_delayed_node *btrfs_first_prepared_delayed_node( 289 static struct btrfs_delayed_node *btrfs_first_prepared_delayed_node(
290 struct btrfs_delayed_root *delayed_root) 290 struct btrfs_delayed_root *delayed_root)
291 { 291 {
292 struct list_head *p; 292 struct list_head *p;
293 struct btrfs_delayed_node *node = NULL; 293 struct btrfs_delayed_node *node = NULL;
294 294
295 spin_lock(&delayed_root->lock); 295 spin_lock(&delayed_root->lock);
296 if (list_empty(&delayed_root->prepare_list)) 296 if (list_empty(&delayed_root->prepare_list))
297 goto out; 297 goto out;
298 298
299 p = delayed_root->prepare_list.next; 299 p = delayed_root->prepare_list.next;
300 list_del_init(p); 300 list_del_init(p);
301 node = list_entry(p, struct btrfs_delayed_node, p_list); 301 node = list_entry(p, struct btrfs_delayed_node, p_list);
302 atomic_inc(&node->refs); 302 atomic_inc(&node->refs);
303 out: 303 out:
304 spin_unlock(&delayed_root->lock); 304 spin_unlock(&delayed_root->lock);
305 305
306 return node; 306 return node;
307 } 307 }
308 308
309 static inline void btrfs_release_prepared_delayed_node( 309 static inline void btrfs_release_prepared_delayed_node(
310 struct btrfs_delayed_node *node) 310 struct btrfs_delayed_node *node)
311 { 311 {
312 __btrfs_release_delayed_node(node, 1); 312 __btrfs_release_delayed_node(node, 1);
313 } 313 }
314 314
315 static struct btrfs_delayed_item *btrfs_alloc_delayed_item(u32 data_len) 315 static struct btrfs_delayed_item *btrfs_alloc_delayed_item(u32 data_len)
316 { 316 {
317 struct btrfs_delayed_item *item; 317 struct btrfs_delayed_item *item;
318 item = kmalloc(sizeof(*item) + data_len, GFP_NOFS); 318 item = kmalloc(sizeof(*item) + data_len, GFP_NOFS);
319 if (item) { 319 if (item) {
320 item->data_len = data_len; 320 item->data_len = data_len;
321 item->ins_or_del = 0; 321 item->ins_or_del = 0;
322 item->bytes_reserved = 0; 322 item->bytes_reserved = 0;
323 item->delayed_node = NULL; 323 item->delayed_node = NULL;
324 atomic_set(&item->refs, 1); 324 atomic_set(&item->refs, 1);
325 } 325 }
326 return item; 326 return item;
327 } 327 }
328 328
329 /* 329 /*
330 * __btrfs_lookup_delayed_item - look up the delayed item by key 330 * __btrfs_lookup_delayed_item - look up the delayed item by key
331 * @delayed_node: pointer to the delayed node 331 * @delayed_node: pointer to the delayed node
332 * @key: the key to look up 332 * @key: the key to look up
333 * @prev: used to store the prev item if the right item isn't found 333 * @prev: used to store the prev item if the right item isn't found
334 * @next: used to store the next item if the right item isn't found 334 * @next: used to store the next item if the right item isn't found
335 * 335 *
336 * Note: if we don't find the right item, we will return the prev item and 336 * Note: if we don't find the right item, we will return the prev item and
337 * the next item. 337 * the next item.
338 */ 338 */
339 static struct btrfs_delayed_item *__btrfs_lookup_delayed_item( 339 static struct btrfs_delayed_item *__btrfs_lookup_delayed_item(
340 struct rb_root *root, 340 struct rb_root *root,
341 struct btrfs_key *key, 341 struct btrfs_key *key,
342 struct btrfs_delayed_item **prev, 342 struct btrfs_delayed_item **prev,
343 struct btrfs_delayed_item **next) 343 struct btrfs_delayed_item **next)
344 { 344 {
345 struct rb_node *node, *prev_node = NULL; 345 struct rb_node *node, *prev_node = NULL;
346 struct btrfs_delayed_item *delayed_item = NULL; 346 struct btrfs_delayed_item *delayed_item = NULL;
347 int ret = 0; 347 int ret = 0;
348 348
349 node = root->rb_node; 349 node = root->rb_node;
350 350
351 while (node) { 351 while (node) {
352 delayed_item = rb_entry(node, struct btrfs_delayed_item, 352 delayed_item = rb_entry(node, struct btrfs_delayed_item,
353 rb_node); 353 rb_node);
354 prev_node = node; 354 prev_node = node;
355 ret = btrfs_comp_cpu_keys(&delayed_item->key, key); 355 ret = btrfs_comp_cpu_keys(&delayed_item->key, key);
356 if (ret < 0) 356 if (ret < 0)
357 node = node->rb_right; 357 node = node->rb_right;
358 else if (ret > 0) 358 else if (ret > 0)
359 node = node->rb_left; 359 node = node->rb_left;
360 else 360 else
361 return delayed_item; 361 return delayed_item;
362 } 362 }
363 363
364 if (prev) { 364 if (prev) {
365 if (!prev_node) 365 if (!prev_node)
366 *prev = NULL; 366 *prev = NULL;
367 else if (ret < 0) 367 else if (ret < 0)
368 *prev = delayed_item; 368 *prev = delayed_item;
369 else if ((node = rb_prev(prev_node)) != NULL) { 369 else if ((node = rb_prev(prev_node)) != NULL) {
370 *prev = rb_entry(node, struct btrfs_delayed_item, 370 *prev = rb_entry(node, struct btrfs_delayed_item,
371 rb_node); 371 rb_node);
372 } else 372 } else
373 *prev = NULL; 373 *prev = NULL;
374 } 374 }
375 375
376 if (next) { 376 if (next) {
377 if (!prev_node) 377 if (!prev_node)
378 *next = NULL; 378 *next = NULL;
379 else if (ret > 0) 379 else if (ret > 0)
380 *next = delayed_item; 380 *next = delayed_item;
381 else if ((node = rb_next(prev_node)) != NULL) { 381 else if ((node = rb_next(prev_node)) != NULL) {
382 *next = rb_entry(node, struct btrfs_delayed_item, 382 *next = rb_entry(node, struct btrfs_delayed_item,
383 rb_node); 383 rb_node);
384 } else 384 } else
385 *next = NULL; 385 *next = NULL;
386 } 386 }
387 return NULL; 387 return NULL;
388 } 388 }
389 389
390 static struct btrfs_delayed_item *__btrfs_lookup_delayed_insertion_item( 390 static struct btrfs_delayed_item *__btrfs_lookup_delayed_insertion_item(
391 struct btrfs_delayed_node *delayed_node, 391 struct btrfs_delayed_node *delayed_node,
392 struct btrfs_key *key) 392 struct btrfs_key *key)
393 { 393 {
394 struct btrfs_delayed_item *item; 394 struct btrfs_delayed_item *item;
395 395
396 item = __btrfs_lookup_delayed_item(&delayed_node->ins_root, key, 396 item = __btrfs_lookup_delayed_item(&delayed_node->ins_root, key,
397 NULL, NULL); 397 NULL, NULL);
398 return item; 398 return item;
399 } 399 }
400 400
401 static int __btrfs_add_delayed_item(struct btrfs_delayed_node *delayed_node, 401 static int __btrfs_add_delayed_item(struct btrfs_delayed_node *delayed_node,
402 struct btrfs_delayed_item *ins, 402 struct btrfs_delayed_item *ins,
403 int action) 403 int action)
404 { 404 {
405 struct rb_node **p, *node; 405 struct rb_node **p, *node;
406 struct rb_node *parent_node = NULL; 406 struct rb_node *parent_node = NULL;
407 struct rb_root *root; 407 struct rb_root *root;
408 struct btrfs_delayed_item *item; 408 struct btrfs_delayed_item *item;
409 int cmp; 409 int cmp;
410 410
411 if (action == BTRFS_DELAYED_INSERTION_ITEM) 411 if (action == BTRFS_DELAYED_INSERTION_ITEM)
412 root = &delayed_node->ins_root; 412 root = &delayed_node->ins_root;
413 else if (action == BTRFS_DELAYED_DELETION_ITEM) 413 else if (action == BTRFS_DELAYED_DELETION_ITEM)
414 root = &delayed_node->del_root; 414 root = &delayed_node->del_root;
415 else 415 else
416 BUG(); 416 BUG();
417 p = &root->rb_node; 417 p = &root->rb_node;
418 node = &ins->rb_node; 418 node = &ins->rb_node;
419 419
420 while (*p) { 420 while (*p) {
421 parent_node = *p; 421 parent_node = *p;
422 item = rb_entry(parent_node, struct btrfs_delayed_item, 422 item = rb_entry(parent_node, struct btrfs_delayed_item,
423 rb_node); 423 rb_node);
424 424
425 cmp = btrfs_comp_cpu_keys(&item->key, &ins->key); 425 cmp = btrfs_comp_cpu_keys(&item->key, &ins->key);
426 if (cmp < 0) 426 if (cmp < 0)
427 p = &(*p)->rb_right; 427 p = &(*p)->rb_right;
428 else if (cmp > 0) 428 else if (cmp > 0)
429 p = &(*p)->rb_left; 429 p = &(*p)->rb_left;
430 else 430 else
431 return -EEXIST; 431 return -EEXIST;
432 } 432 }
433 433
434 rb_link_node(node, parent_node, p); 434 rb_link_node(node, parent_node, p);
435 rb_insert_color(node, root); 435 rb_insert_color(node, root);
436 ins->delayed_node = delayed_node; 436 ins->delayed_node = delayed_node;
437 ins->ins_or_del = action; 437 ins->ins_or_del = action;
438 438
439 if (ins->key.type == BTRFS_DIR_INDEX_KEY && 439 if (ins->key.type == BTRFS_DIR_INDEX_KEY &&
440 action == BTRFS_DELAYED_INSERTION_ITEM && 440 action == BTRFS_DELAYED_INSERTION_ITEM &&
441 ins->key.offset >= delayed_node->index_cnt) 441 ins->key.offset >= delayed_node->index_cnt)
442 delayed_node->index_cnt = ins->key.offset + 1; 442 delayed_node->index_cnt = ins->key.offset + 1;
443 443
444 delayed_node->count++; 444 delayed_node->count++;
445 atomic_inc(&delayed_node->root->fs_info->delayed_root->items); 445 atomic_inc(&delayed_node->root->fs_info->delayed_root->items);
446 return 0; 446 return 0;
447 } 447 }
448 448
449 static int __btrfs_add_delayed_insertion_item(struct btrfs_delayed_node *node, 449 static int __btrfs_add_delayed_insertion_item(struct btrfs_delayed_node *node,
450 struct btrfs_delayed_item *item) 450 struct btrfs_delayed_item *item)
451 { 451 {
452 return __btrfs_add_delayed_item(node, item, 452 return __btrfs_add_delayed_item(node, item,
453 BTRFS_DELAYED_INSERTION_ITEM); 453 BTRFS_DELAYED_INSERTION_ITEM);
454 } 454 }
455 455
456 static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node, 456 static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
457 struct btrfs_delayed_item *item) 457 struct btrfs_delayed_item *item)
458 { 458 {
459 return __btrfs_add_delayed_item(node, item, 459 return __btrfs_add_delayed_item(node, item,
460 BTRFS_DELAYED_DELETION_ITEM); 460 BTRFS_DELAYED_DELETION_ITEM);
461 } 461 }
462 462
463 static void finish_one_item(struct btrfs_delayed_root *delayed_root) 463 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
464 { 464 {
465 int seq = atomic_inc_return(&delayed_root->items_seq); 465 int seq = atomic_inc_return(&delayed_root->items_seq);
466 if ((atomic_dec_return(&delayed_root->items) < 466 if ((atomic_dec_return(&delayed_root->items) <
467 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) && 467 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
468 waitqueue_active(&delayed_root->wait)) 468 waitqueue_active(&delayed_root->wait))
469 wake_up(&delayed_root->wait); 469 wake_up(&delayed_root->wait);
470 } 470 }
471 471
472 static void __btrfs_remove_delayed_item(struct btrfs_delayed_item *delayed_item) 472 static void __btrfs_remove_delayed_item(struct btrfs_delayed_item *delayed_item)
473 { 473 {
474 struct rb_root *root; 474 struct rb_root *root;
475 struct btrfs_delayed_root *delayed_root; 475 struct btrfs_delayed_root *delayed_root;
476 476
477 delayed_root = delayed_item->delayed_node->root->fs_info->delayed_root; 477 delayed_root = delayed_item->delayed_node->root->fs_info->delayed_root;
478 478
479 BUG_ON(!delayed_root); 479 BUG_ON(!delayed_root);
480 BUG_ON(delayed_item->ins_or_del != BTRFS_DELAYED_DELETION_ITEM && 480 BUG_ON(delayed_item->ins_or_del != BTRFS_DELAYED_DELETION_ITEM &&
481 delayed_item->ins_or_del != BTRFS_DELAYED_INSERTION_ITEM); 481 delayed_item->ins_or_del != BTRFS_DELAYED_INSERTION_ITEM);
482 482
483 if (delayed_item->ins_or_del == BTRFS_DELAYED_INSERTION_ITEM) 483 if (delayed_item->ins_or_del == BTRFS_DELAYED_INSERTION_ITEM)
484 root = &delayed_item->delayed_node->ins_root; 484 root = &delayed_item->delayed_node->ins_root;
485 else 485 else
486 root = &delayed_item->delayed_node->del_root; 486 root = &delayed_item->delayed_node->del_root;
487 487
488 rb_erase(&delayed_item->rb_node, root); 488 rb_erase(&delayed_item->rb_node, root);
489 delayed_item->delayed_node->count--; 489 delayed_item->delayed_node->count--;
490 490
491 finish_one_item(delayed_root); 491 finish_one_item(delayed_root);
492 } 492 }
493 493
494 static void btrfs_release_delayed_item(struct btrfs_delayed_item *item) 494 static void btrfs_release_delayed_item(struct btrfs_delayed_item *item)
495 { 495 {
496 if (item) { 496 if (item) {
497 __btrfs_remove_delayed_item(item); 497 __btrfs_remove_delayed_item(item);
498 if (atomic_dec_and_test(&item->refs)) 498 if (atomic_dec_and_test(&item->refs))
499 kfree(item); 499 kfree(item);
500 } 500 }
501 } 501 }
502 502
503 static struct btrfs_delayed_item *__btrfs_first_delayed_insertion_item( 503 static struct btrfs_delayed_item *__btrfs_first_delayed_insertion_item(
504 struct btrfs_delayed_node *delayed_node) 504 struct btrfs_delayed_node *delayed_node)
505 { 505 {
506 struct rb_node *p; 506 struct rb_node *p;
507 struct btrfs_delayed_item *item = NULL; 507 struct btrfs_delayed_item *item = NULL;
508 508
509 p = rb_first(&delayed_node->ins_root); 509 p = rb_first(&delayed_node->ins_root);
510 if (p) 510 if (p)
511 item = rb_entry(p, struct btrfs_delayed_item, rb_node); 511 item = rb_entry(p, struct btrfs_delayed_item, rb_node);
512 512
513 return item; 513 return item;
514 } 514 }
515 515
516 static struct btrfs_delayed_item *__btrfs_first_delayed_deletion_item( 516 static struct btrfs_delayed_item *__btrfs_first_delayed_deletion_item(
517 struct btrfs_delayed_node *delayed_node) 517 struct btrfs_delayed_node *delayed_node)
518 { 518 {
519 struct rb_node *p; 519 struct rb_node *p;
520 struct btrfs_delayed_item *item = NULL; 520 struct btrfs_delayed_item *item = NULL;
521 521
522 p = rb_first(&delayed_node->del_root); 522 p = rb_first(&delayed_node->del_root);
523 if (p) 523 if (p)
524 item = rb_entry(p, struct btrfs_delayed_item, rb_node); 524 item = rb_entry(p, struct btrfs_delayed_item, rb_node);
525 525
526 return item; 526 return item;
527 } 527 }
528 528
529 static struct btrfs_delayed_item *__btrfs_next_delayed_item( 529 static struct btrfs_delayed_item *__btrfs_next_delayed_item(
530 struct btrfs_delayed_item *item) 530 struct btrfs_delayed_item *item)
531 { 531 {
532 struct rb_node *p; 532 struct rb_node *p;
533 struct btrfs_delayed_item *next = NULL; 533 struct btrfs_delayed_item *next = NULL;
534 534
535 p = rb_next(&item->rb_node); 535 p = rb_next(&item->rb_node);
536 if (p) 536 if (p)
537 next = rb_entry(p, struct btrfs_delayed_item, rb_node); 537 next = rb_entry(p, struct btrfs_delayed_item, rb_node);
538 538
539 return next; 539 return next;
540 } 540 }
541 541
542 static int btrfs_delayed_item_reserve_metadata(struct btrfs_trans_handle *trans, 542 static int btrfs_delayed_item_reserve_metadata(struct btrfs_trans_handle *trans,
543 struct btrfs_root *root, 543 struct btrfs_root *root,
544 struct btrfs_delayed_item *item) 544 struct btrfs_delayed_item *item)
545 { 545 {
546 struct btrfs_block_rsv *src_rsv; 546 struct btrfs_block_rsv *src_rsv;
547 struct btrfs_block_rsv *dst_rsv; 547 struct btrfs_block_rsv *dst_rsv;
548 u64 num_bytes; 548 u64 num_bytes;
549 int ret; 549 int ret;
550 550
551 if (!trans->bytes_reserved) 551 if (!trans->bytes_reserved)
552 return 0; 552 return 0;
553 553
554 src_rsv = trans->block_rsv; 554 src_rsv = trans->block_rsv;
555 dst_rsv = &root->fs_info->delayed_block_rsv; 555 dst_rsv = &root->fs_info->delayed_block_rsv;
556 556
557 num_bytes = btrfs_calc_trans_metadata_size(root, 1); 557 num_bytes = btrfs_calc_trans_metadata_size(root, 1);
558 ret = btrfs_block_rsv_migrate(src_rsv, dst_rsv, num_bytes); 558 ret = btrfs_block_rsv_migrate(src_rsv, dst_rsv, num_bytes);
559 if (!ret) { 559 if (!ret) {
560 trace_btrfs_space_reservation(root->fs_info, "delayed_item", 560 trace_btrfs_space_reservation(root->fs_info, "delayed_item",
561 item->key.objectid, 561 item->key.objectid,
562 num_bytes, 1); 562 num_bytes, 1);
563 item->bytes_reserved = num_bytes; 563 item->bytes_reserved = num_bytes;
564 } 564 }
565 565
566 return ret; 566 return ret;
567 } 567 }
568 568
569 static void btrfs_delayed_item_release_metadata(struct btrfs_root *root, 569 static void btrfs_delayed_item_release_metadata(struct btrfs_root *root,
570 struct btrfs_delayed_item *item) 570 struct btrfs_delayed_item *item)
571 { 571 {
572 struct btrfs_block_rsv *rsv; 572 struct btrfs_block_rsv *rsv;
573 573
574 if (!item->bytes_reserved) 574 if (!item->bytes_reserved)
575 return; 575 return;
576 576
577 rsv = &root->fs_info->delayed_block_rsv; 577 rsv = &root->fs_info->delayed_block_rsv;
578 trace_btrfs_space_reservation(root->fs_info, "delayed_item", 578 trace_btrfs_space_reservation(root->fs_info, "delayed_item",
579 item->key.objectid, item->bytes_reserved, 579 item->key.objectid, item->bytes_reserved,
580 0); 580 0);
581 btrfs_block_rsv_release(root, rsv, 581 btrfs_block_rsv_release(root, rsv,
582 item->bytes_reserved); 582 item->bytes_reserved);
583 } 583 }
584 584
585 static int btrfs_delayed_inode_reserve_metadata( 585 static int btrfs_delayed_inode_reserve_metadata(
586 struct btrfs_trans_handle *trans, 586 struct btrfs_trans_handle *trans,
587 struct btrfs_root *root, 587 struct btrfs_root *root,
588 struct inode *inode, 588 struct inode *inode,
589 struct btrfs_delayed_node *node) 589 struct btrfs_delayed_node *node)
590 { 590 {
591 struct btrfs_block_rsv *src_rsv; 591 struct btrfs_block_rsv *src_rsv;
592 struct btrfs_block_rsv *dst_rsv; 592 struct btrfs_block_rsv *dst_rsv;
593 u64 num_bytes; 593 u64 num_bytes;
594 int ret; 594 int ret;
595 bool release = false; 595 bool release = false;
596 596
597 src_rsv = trans->block_rsv; 597 src_rsv = trans->block_rsv;
598 dst_rsv = &root->fs_info->delayed_block_rsv; 598 dst_rsv = &root->fs_info->delayed_block_rsv;
599 599
600 num_bytes = btrfs_calc_trans_metadata_size(root, 1); 600 num_bytes = btrfs_calc_trans_metadata_size(root, 1);
601 601
602 /* 602 /*
603 * btrfs_dirty_inode will update the inode under btrfs_join_transaction 603 * btrfs_dirty_inode will update the inode under btrfs_join_transaction
604 * which doesn't reserve space for speed. This is a problem since we 604 * which doesn't reserve space for speed. This is a problem since we
605 * still need to reserve space for this update, so try to reserve the 605 * still need to reserve space for this update, so try to reserve the
606 * space. 606 * space.
607 * 607 *
608 * Now if src_rsv == delalloc_block_rsv we'll let it just steal since 608 * Now if src_rsv == delalloc_block_rsv we'll let it just steal since
609 * we're accounted for. 609 * we're accounted for.
610 */ 610 */
611 if (!src_rsv || (!trans->bytes_reserved && 611 if (!src_rsv || (!trans->bytes_reserved &&
612 src_rsv->type != BTRFS_BLOCK_RSV_DELALLOC)) { 612 src_rsv->type != BTRFS_BLOCK_RSV_DELALLOC)) {
613 ret = btrfs_block_rsv_add(root, dst_rsv, num_bytes, 613 ret = btrfs_block_rsv_add(root, dst_rsv, num_bytes,
614 BTRFS_RESERVE_NO_FLUSH); 614 BTRFS_RESERVE_NO_FLUSH);
615 /* 615 /*
616 * Since we're under a transaction reserve_metadata_bytes could 616 * Since we're under a transaction reserve_metadata_bytes could
617 * try to commit the transaction which will make it return 617 * try to commit the transaction which will make it return
618 * EAGAIN to make us stop the transaction we have, so return 618 * EAGAIN to make us stop the transaction we have, so return
619 * ENOSPC instead so that btrfs_dirty_inode knows what to do. 619 * ENOSPC instead so that btrfs_dirty_inode knows what to do.
620 */ 620 */
621 if (ret == -EAGAIN) 621 if (ret == -EAGAIN)
622 ret = -ENOSPC; 622 ret = -ENOSPC;
623 if (!ret) { 623 if (!ret) {
624 node->bytes_reserved = num_bytes; 624 node->bytes_reserved = num_bytes;
625 trace_btrfs_space_reservation(root->fs_info, 625 trace_btrfs_space_reservation(root->fs_info,
626 "delayed_inode", 626 "delayed_inode",
627 btrfs_ino(inode), 627 btrfs_ino(inode),
628 num_bytes, 1); 628 num_bytes, 1);
629 } 629 }
630 return ret; 630 return ret;
631 } else if (src_rsv->type == BTRFS_BLOCK_RSV_DELALLOC) { 631 } else if (src_rsv->type == BTRFS_BLOCK_RSV_DELALLOC) {
632 spin_lock(&BTRFS_I(inode)->lock); 632 spin_lock(&BTRFS_I(inode)->lock);
633 if (test_and_clear_bit(BTRFS_INODE_DELALLOC_META_RESERVED, 633 if (test_and_clear_bit(BTRFS_INODE_DELALLOC_META_RESERVED,
634 &BTRFS_I(inode)->runtime_flags)) { 634 &BTRFS_I(inode)->runtime_flags)) {
635 spin_unlock(&BTRFS_I(inode)->lock); 635 spin_unlock(&BTRFS_I(inode)->lock);
636 release = true; 636 release = true;
637 goto migrate; 637 goto migrate;
638 } 638 }
639 spin_unlock(&BTRFS_I(inode)->lock); 639 spin_unlock(&BTRFS_I(inode)->lock);
640 640
641 /* Ok we didn't have space pre-reserved. This shouldn't happen 641 /* Ok we didn't have space pre-reserved. This shouldn't happen
642 * too often but it can happen if we do delalloc to an existing 642 * too often but it can happen if we do delalloc to an existing
643 * inode which gets dirtied because of the time update, and then 643 * inode which gets dirtied because of the time update, and then
644 * isn't touched again until after the transaction commits and 644 * isn't touched again until after the transaction commits and
645 * then we try to write out the data. First try to be nice and 645 * then we try to write out the data. First try to be nice and
646 * reserve something strictly for us. If not be a pain and try 646 * reserve something strictly for us. If not be a pain and try
647 * to steal from the delalloc block rsv. 647 * to steal from the delalloc block rsv.
648 */ 648 */
649 ret = btrfs_block_rsv_add(root, dst_rsv, num_bytes, 649 ret = btrfs_block_rsv_add(root, dst_rsv, num_bytes,
650 BTRFS_RESERVE_NO_FLUSH); 650 BTRFS_RESERVE_NO_FLUSH);
651 if (!ret) 651 if (!ret)
652 goto out; 652 goto out;
653 653
654 ret = btrfs_block_rsv_migrate(src_rsv, dst_rsv, num_bytes); 654 ret = btrfs_block_rsv_migrate(src_rsv, dst_rsv, num_bytes);
655 if (!WARN_ON(ret)) 655 if (!WARN_ON(ret))
656 goto out; 656 goto out;
657 657
658 /* 658 /*
659 * Ok this is a problem, let's just steal from the global rsv 659 * Ok this is a problem, let's just steal from the global rsv
660 * since this really shouldn't happen that often. 660 * since this really shouldn't happen that often.
661 */ 661 */
662 ret = btrfs_block_rsv_migrate(&root->fs_info->global_block_rsv, 662 ret = btrfs_block_rsv_migrate(&root->fs_info->global_block_rsv,
663 dst_rsv, num_bytes); 663 dst_rsv, num_bytes);
664 goto out; 664 goto out;
665 } 665 }
666 666
667 migrate: 667 migrate:
668 ret = btrfs_block_rsv_migrate(src_rsv, dst_rsv, num_bytes); 668 ret = btrfs_block_rsv_migrate(src_rsv, dst_rsv, num_bytes);
669 669
670 out: 670 out:
671 /* 671 /*
672 * Migrate only takes a reservation, it doesn't touch the size of the 672 * Migrate only takes a reservation, it doesn't touch the size of the
673 * block_rsv. This is to simplify people who don't normally have things 673 * block_rsv. This is to simplify people who don't normally have things
674 * migrated from their block rsv. If they go to release their 674 * migrated from their block rsv. If they go to release their
675 * reservation, that will decrease the size as well, so if migrate 675 * reservation, that will decrease the size as well, so if migrate
676 * reduced size we'd end up with a negative size. But for the 676 * reduced size we'd end up with a negative size. But for the
677 * delalloc_meta_reserved stuff we will only know to drop 1 reservation, 677 * delalloc_meta_reserved stuff we will only know to drop 1 reservation,
678 * but we could in fact do this reserve/migrate dance several times 678 * but we could in fact do this reserve/migrate dance several times
679 * between the time we did the original reservation and we'd clean it 679 * between the time we did the original reservation and we'd clean it
680 * up. So to take care of this, release the space for the meta 680 * up. So to take care of this, release the space for the meta
681 * reservation here. I think it may be time for a documentation page on 681 * reservation here. I think it may be time for a documentation page on
682 * how block rsvs. work. 682 * how block rsvs. work.
683 */ 683 */
684 if (!ret) { 684 if (!ret) {
685 trace_btrfs_space_reservation(root->fs_info, "delayed_inode", 685 trace_btrfs_space_reservation(root->fs_info, "delayed_inode",
686 btrfs_ino(inode), num_bytes, 1); 686 btrfs_ino(inode), num_bytes, 1);
687 node->bytes_reserved = num_bytes; 687 node->bytes_reserved = num_bytes;
688 } 688 }
689 689
690 if (release) { 690 if (release) {
691 trace_btrfs_space_reservation(root->fs_info, "delalloc", 691 trace_btrfs_space_reservation(root->fs_info, "delalloc",
692 btrfs_ino(inode), num_bytes, 0); 692 btrfs_ino(inode), num_bytes, 0);
693 btrfs_block_rsv_release(root, src_rsv, num_bytes); 693 btrfs_block_rsv_release(root, src_rsv, num_bytes);
694 } 694 }
695 695
696 return ret; 696 return ret;
697 } 697 }
698 698
699 static void btrfs_delayed_inode_release_metadata(struct btrfs_root *root, 699 static void btrfs_delayed_inode_release_metadata(struct btrfs_root *root,
700 struct btrfs_delayed_node *node) 700 struct btrfs_delayed_node *node)
701 { 701 {
702 struct btrfs_block_rsv *rsv; 702 struct btrfs_block_rsv *rsv;
703 703
704 if (!node->bytes_reserved) 704 if (!node->bytes_reserved)
705 return; 705 return;
706 706
707 rsv = &root->fs_info->delayed_block_rsv; 707 rsv = &root->fs_info->delayed_block_rsv;
708 trace_btrfs_space_reservation(root->fs_info, "delayed_inode", 708 trace_btrfs_space_reservation(root->fs_info, "delayed_inode",
709 node->inode_id, node->bytes_reserved, 0); 709 node->inode_id, node->bytes_reserved, 0);
710 btrfs_block_rsv_release(root, rsv, 710 btrfs_block_rsv_release(root, rsv,
711 node->bytes_reserved); 711 node->bytes_reserved);
712 node->bytes_reserved = 0; 712 node->bytes_reserved = 0;
713 } 713 }
714 714
715 /* 715 /*
716 * This helper will insert some continuous items into the same leaf according 716 * This helper will insert some continuous items into the same leaf according
717 * to the free space of the leaf. 717 * to the free space of the leaf.
718 */ 718 */
719 static int btrfs_batch_insert_items(struct btrfs_root *root, 719 static int btrfs_batch_insert_items(struct btrfs_root *root,
720 struct btrfs_path *path, 720 struct btrfs_path *path,
721 struct btrfs_delayed_item *item) 721 struct btrfs_delayed_item *item)
722 { 722 {
723 struct btrfs_delayed_item *curr, *next; 723 struct btrfs_delayed_item *curr, *next;
724 int free_space; 724 int free_space;
725 int total_data_size = 0, total_size = 0; 725 int total_data_size = 0, total_size = 0;
726 struct extent_buffer *leaf; 726 struct extent_buffer *leaf;
727 char *data_ptr; 727 char *data_ptr;
728 struct btrfs_key *keys; 728 struct btrfs_key *keys;
729 u32 *data_size; 729 u32 *data_size;
730 struct list_head head; 730 struct list_head head;
731 int slot; 731 int slot;
732 int nitems; 732 int nitems;
733 int i; 733 int i;
734 int ret = 0; 734 int ret = 0;
735 735
736 BUG_ON(!path->nodes[0]); 736 BUG_ON(!path->nodes[0]);
737 737
738 leaf = path->nodes[0]; 738 leaf = path->nodes[0];
739 free_space = btrfs_leaf_free_space(root, leaf); 739 free_space = btrfs_leaf_free_space(root, leaf);
740 INIT_LIST_HEAD(&head); 740 INIT_LIST_HEAD(&head);
741 741
742 next = item; 742 next = item;
743 nitems = 0; 743 nitems = 0;
744 744
745 /* 745 /*
746 * count the number of the continuous items that we can insert in batch 746 * count the number of the continuous items that we can insert in batch
747 */ 747 */
748 while (total_size + next->data_len + sizeof(struct btrfs_item) <= 748 while (total_size + next->data_len + sizeof(struct btrfs_item) <=
749 free_space) { 749 free_space) {
750 total_data_size += next->data_len; 750 total_data_size += next->data_len;
751 total_size += next->data_len + sizeof(struct btrfs_item); 751 total_size += next->data_len + sizeof(struct btrfs_item);
752 list_add_tail(&next->tree_list, &head); 752 list_add_tail(&next->tree_list, &head);
753 nitems++; 753 nitems++;
754 754
755 curr = next; 755 curr = next;
756 next = __btrfs_next_delayed_item(curr); 756 next = __btrfs_next_delayed_item(curr);
757 if (!next) 757 if (!next)
758 break; 758 break;
759 759
760 if (!btrfs_is_continuous_delayed_item(curr, next)) 760 if (!btrfs_is_continuous_delayed_item(curr, next))
761 break; 761 break;
762 } 762 }
763 763
764 if (!nitems) { 764 if (!nitems) {
765 ret = 0; 765 ret = 0;
766 goto out; 766 goto out;
767 } 767 }
768 768
769 /* 769 /*
770 * we need allocate some memory space, but it might cause the task 770 * we need allocate some memory space, but it might cause the task
771 * to sleep, so we set all locked nodes in the path to blocking locks 771 * to sleep, so we set all locked nodes in the path to blocking locks
772 * first. 772 * first.
773 */ 773 */
774 btrfs_set_path_blocking(path); 774 btrfs_set_path_blocking(path);
775 775
776 keys = kmalloc_array(nitems, sizeof(struct btrfs_key), GFP_NOFS); 776 keys = kmalloc_array(nitems, sizeof(struct btrfs_key), GFP_NOFS);
777 if (!keys) { 777 if (!keys) {
778 ret = -ENOMEM; 778 ret = -ENOMEM;
779 goto out; 779 goto out;
780 } 780 }
781 781
782 data_size = kmalloc_array(nitems, sizeof(u32), GFP_NOFS); 782 data_size = kmalloc_array(nitems, sizeof(u32), GFP_NOFS);
783 if (!data_size) { 783 if (!data_size) {
784 ret = -ENOMEM; 784 ret = -ENOMEM;
785 goto error; 785 goto error;
786 } 786 }
787 787
788 /* get keys of all the delayed items */ 788 /* get keys of all the delayed items */
789 i = 0; 789 i = 0;
790 list_for_each_entry(next, &head, tree_list) { 790 list_for_each_entry(next, &head, tree_list) {
791 keys[i] = next->key; 791 keys[i] = next->key;
792 data_size[i] = next->data_len; 792 data_size[i] = next->data_len;
793 i++; 793 i++;
794 } 794 }
795 795
796 /* reset all the locked nodes in the patch to spinning locks. */ 796 /* reset all the locked nodes in the patch to spinning locks. */
797 btrfs_clear_path_blocking(path, NULL, 0); 797 btrfs_clear_path_blocking(path, NULL, 0);
798 798
799 /* insert the keys of the items */ 799 /* insert the keys of the items */
800 setup_items_for_insert(root, path, keys, data_size, 800 setup_items_for_insert(root, path, keys, data_size,
801 total_data_size, total_size, nitems); 801 total_data_size, total_size, nitems);
802 802
803 /* insert the dir index items */ 803 /* insert the dir index items */
804 slot = path->slots[0]; 804 slot = path->slots[0];
805 list_for_each_entry_safe(curr, next, &head, tree_list) { 805 list_for_each_entry_safe(curr, next, &head, tree_list) {
806 data_ptr = btrfs_item_ptr(leaf, slot, char); 806 data_ptr = btrfs_item_ptr(leaf, slot, char);
807 write_extent_buffer(leaf, &curr->data, 807 write_extent_buffer(leaf, &curr->data,
808 (unsigned long)data_ptr, 808 (unsigned long)data_ptr,
809 curr->data_len); 809 curr->data_len);
810 slot++; 810 slot++;
811 811
812 btrfs_delayed_item_release_metadata(root, curr); 812 btrfs_delayed_item_release_metadata(root, curr);
813 813
814 list_del(&curr->tree_list); 814 list_del(&curr->tree_list);
815 btrfs_release_delayed_item(curr); 815 btrfs_release_delayed_item(curr);
816 } 816 }
817 817
818 error: 818 error:
819 kfree(data_size); 819 kfree(data_size);
820 kfree(keys); 820 kfree(keys);
821 out: 821 out:
822 return ret; 822 return ret;
823 } 823 }
824 824
825 /* 825 /*
826 * This helper can just do simple insertion that needn't extend item for new 826 * This helper can just do simple insertion that needn't extend item for new
827 * data, such as directory name index insertion, inode insertion. 827 * data, such as directory name index insertion, inode insertion.
828 */ 828 */
829 static int btrfs_insert_delayed_item(struct btrfs_trans_handle *trans, 829 static int btrfs_insert_delayed_item(struct btrfs_trans_handle *trans,
830 struct btrfs_root *root, 830 struct btrfs_root *root,
831 struct btrfs_path *path, 831 struct btrfs_path *path,
832 struct btrfs_delayed_item *delayed_item) 832 struct btrfs_delayed_item *delayed_item)
833 { 833 {
834 struct extent_buffer *leaf; 834 struct extent_buffer *leaf;
835 char *ptr; 835 char *ptr;
836 int ret; 836 int ret;
837 837
838 ret = btrfs_insert_empty_item(trans, root, path, &delayed_item->key, 838 ret = btrfs_insert_empty_item(trans, root, path, &delayed_item->key,
839 delayed_item->data_len); 839 delayed_item->data_len);
840 if (ret < 0 && ret != -EEXIST) 840 if (ret < 0 && ret != -EEXIST)
841 return ret; 841 return ret;
842 842
843 leaf = path->nodes[0]; 843 leaf = path->nodes[0];
844 844
845 ptr = btrfs_item_ptr(leaf, path->slots[0], char); 845 ptr = btrfs_item_ptr(leaf, path->slots[0], char);
846 846
847 write_extent_buffer(leaf, delayed_item->data, (unsigned long)ptr, 847 write_extent_buffer(leaf, delayed_item->data, (unsigned long)ptr,
848 delayed_item->data_len); 848 delayed_item->data_len);
849 btrfs_mark_buffer_dirty(leaf); 849 btrfs_mark_buffer_dirty(leaf);
850 850
851 btrfs_delayed_item_release_metadata(root, delayed_item); 851 btrfs_delayed_item_release_metadata(root, delayed_item);
852 return 0; 852 return 0;
853 } 853 }
854 854
855 /* 855 /*
856 * we insert an item first, then if there are some continuous items, we try 856 * we insert an item first, then if there are some continuous items, we try
857 * to insert those items into the same leaf. 857 * to insert those items into the same leaf.
858 */ 858 */
859 static int btrfs_insert_delayed_items(struct btrfs_trans_handle *trans, 859 static int btrfs_insert_delayed_items(struct btrfs_trans_handle *trans,
860 struct btrfs_path *path, 860 struct btrfs_path *path,
861 struct btrfs_root *root, 861 struct btrfs_root *root,
862 struct btrfs_delayed_node *node) 862 struct btrfs_delayed_node *node)
863 { 863 {
864 struct btrfs_delayed_item *curr, *prev; 864 struct btrfs_delayed_item *curr, *prev;
865 int ret = 0; 865 int ret = 0;
866 866
867 do_again: 867 do_again:
868 mutex_lock(&node->mutex); 868 mutex_lock(&node->mutex);
869 curr = __btrfs_first_delayed_insertion_item(node); 869 curr = __btrfs_first_delayed_insertion_item(node);
870 if (!curr) 870 if (!curr)
871 goto insert_end; 871 goto insert_end;
872 872
873 ret = btrfs_insert_delayed_item(trans, root, path, curr); 873 ret = btrfs_insert_delayed_item(trans, root, path, curr);
874 if (ret < 0) { 874 if (ret < 0) {
875 btrfs_release_path(path); 875 btrfs_release_path(path);
876 goto insert_end; 876 goto insert_end;
877 } 877 }
878 878
879 prev = curr; 879 prev = curr;
880 curr = __btrfs_next_delayed_item(prev); 880 curr = __btrfs_next_delayed_item(prev);
881 if (curr && btrfs_is_continuous_delayed_item(prev, curr)) { 881 if (curr && btrfs_is_continuous_delayed_item(prev, curr)) {
882 /* insert the continuous items into the same leaf */ 882 /* insert the continuous items into the same leaf */
883 path->slots[0]++; 883 path->slots[0]++;
884 btrfs_batch_insert_items(root, path, curr); 884 btrfs_batch_insert_items(root, path, curr);
885 } 885 }
886 btrfs_release_delayed_item(prev); 886 btrfs_release_delayed_item(prev);
887 btrfs_mark_buffer_dirty(path->nodes[0]); 887 btrfs_mark_buffer_dirty(path->nodes[0]);
888 888
889 btrfs_release_path(path); 889 btrfs_release_path(path);
890 mutex_unlock(&node->mutex); 890 mutex_unlock(&node->mutex);
891 goto do_again; 891 goto do_again;
892 892
893 insert_end: 893 insert_end:
894 mutex_unlock(&node->mutex); 894 mutex_unlock(&node->mutex);
895 return ret; 895 return ret;
896 } 896 }
897 897
898 static int btrfs_batch_delete_items(struct btrfs_trans_handle *trans, 898 static int btrfs_batch_delete_items(struct btrfs_trans_handle *trans,
899 struct btrfs_root *root, 899 struct btrfs_root *root,
900 struct btrfs_path *path, 900 struct btrfs_path *path,
901 struct btrfs_delayed_item *item) 901 struct btrfs_delayed_item *item)
902 { 902 {
903 struct btrfs_delayed_item *curr, *next; 903 struct btrfs_delayed_item *curr, *next;
904 struct extent_buffer *leaf; 904 struct extent_buffer *leaf;
905 struct btrfs_key key; 905 struct btrfs_key key;
906 struct list_head head; 906 struct list_head head;
907 int nitems, i, last_item; 907 int nitems, i, last_item;
908 int ret = 0; 908 int ret = 0;
909 909
910 BUG_ON(!path->nodes[0]); 910 BUG_ON(!path->nodes[0]);
911 911
912 leaf = path->nodes[0]; 912 leaf = path->nodes[0];
913 913
914 i = path->slots[0]; 914 i = path->slots[0];
915 last_item = btrfs_header_nritems(leaf) - 1; 915 last_item = btrfs_header_nritems(leaf) - 1;
916 if (i > last_item) 916 if (i > last_item)
917 return -ENOENT; /* FIXME: Is errno suitable? */ 917 return -ENOENT; /* FIXME: Is errno suitable? */
918 918
919 next = item; 919 next = item;
920 INIT_LIST_HEAD(&head); 920 INIT_LIST_HEAD(&head);
921 btrfs_item_key_to_cpu(leaf, &key, i); 921 btrfs_item_key_to_cpu(leaf, &key, i);
922 nitems = 0; 922 nitems = 0;
923 /* 923 /*
924 * count the number of the dir index items that we can delete in batch 924 * count the number of the dir index items that we can delete in batch
925 */ 925 */
926 while (btrfs_comp_cpu_keys(&next->key, &key) == 0) { 926 while (btrfs_comp_cpu_keys(&next->key, &key) == 0) {
927 list_add_tail(&next->tree_list, &head); 927 list_add_tail(&next->tree_list, &head);
928 nitems++; 928 nitems++;
929 929
930 curr = next; 930 curr = next;
931 next = __btrfs_next_delayed_item(curr); 931 next = __btrfs_next_delayed_item(curr);
932 if (!next) 932 if (!next)
933 break; 933 break;
934 934
935 if (!btrfs_is_continuous_delayed_item(curr, next)) 935 if (!btrfs_is_continuous_delayed_item(curr, next))
936 break; 936 break;
937 937
938 i++; 938 i++;
939 if (i > last_item) 939 if (i > last_item)
940 break; 940 break;
941 btrfs_item_key_to_cpu(leaf, &key, i); 941 btrfs_item_key_to_cpu(leaf, &key, i);
942 } 942 }
943 943
944 if (!nitems) 944 if (!nitems)
945 return 0; 945 return 0;
946 946
947 ret = btrfs_del_items(trans, root, path, path->slots[0], nitems); 947 ret = btrfs_del_items(trans, root, path, path->slots[0], nitems);
948 if (ret) 948 if (ret)
949 goto out; 949 goto out;
950 950
951 list_for_each_entry_safe(curr, next, &head, tree_list) { 951 list_for_each_entry_safe(curr, next, &head, tree_list) {
952 btrfs_delayed_item_release_metadata(root, curr); 952 btrfs_delayed_item_release_metadata(root, curr);
953 list_del(&curr->tree_list); 953 list_del(&curr->tree_list);
954 btrfs_release_delayed_item(curr); 954 btrfs_release_delayed_item(curr);
955 } 955 }
956 956
957 out: 957 out:
958 return ret; 958 return ret;
959 } 959 }
960 960
961 static int btrfs_delete_delayed_items(struct btrfs_trans_handle *trans, 961 static int btrfs_delete_delayed_items(struct btrfs_trans_handle *trans,
962 struct btrfs_path *path, 962 struct btrfs_path *path,
963 struct btrfs_root *root, 963 struct btrfs_root *root,
964 struct btrfs_delayed_node *node) 964 struct btrfs_delayed_node *node)
965 { 965 {
966 struct btrfs_delayed_item *curr, *prev; 966 struct btrfs_delayed_item *curr, *prev;
967 int ret = 0; 967 int ret = 0;
968 968
969 do_again: 969 do_again:
970 mutex_lock(&node->mutex); 970 mutex_lock(&node->mutex);
971 curr = __btrfs_first_delayed_deletion_item(node); 971 curr = __btrfs_first_delayed_deletion_item(node);
972 if (!curr) 972 if (!curr)
973 goto delete_fail; 973 goto delete_fail;
974 974
975 ret = btrfs_search_slot(trans, root, &curr->key, path, -1, 1); 975 ret = btrfs_search_slot(trans, root, &curr->key, path, -1, 1);
976 if (ret < 0) 976 if (ret < 0)
977 goto delete_fail; 977 goto delete_fail;
978 else if (ret > 0) { 978 else if (ret > 0) {
979 /* 979 /*
980 * can't find the item which the node points to, so this node 980 * can't find the item which the node points to, so this node
981 * is invalid, just drop it. 981 * is invalid, just drop it.
982 */ 982 */
983 prev = curr; 983 prev = curr;
984 curr = __btrfs_next_delayed_item(prev); 984 curr = __btrfs_next_delayed_item(prev);
985 btrfs_release_delayed_item(prev); 985 btrfs_release_delayed_item(prev);
986 ret = 0; 986 ret = 0;
987 btrfs_release_path(path); 987 btrfs_release_path(path);
988 if (curr) { 988 if (curr) {
989 mutex_unlock(&node->mutex); 989 mutex_unlock(&node->mutex);
990 goto do_again; 990 goto do_again;
991 } else 991 } else
992 goto delete_fail; 992 goto delete_fail;
993 } 993 }
994 994
995 btrfs_batch_delete_items(trans, root, path, curr); 995 btrfs_batch_delete_items(trans, root, path, curr);
996 btrfs_release_path(path); 996 btrfs_release_path(path);
997 mutex_unlock(&node->mutex); 997 mutex_unlock(&node->mutex);
998 goto do_again; 998 goto do_again;
999 999
1000 delete_fail: 1000 delete_fail:
1001 btrfs_release_path(path); 1001 btrfs_release_path(path);
1002 mutex_unlock(&node->mutex); 1002 mutex_unlock(&node->mutex);
1003 return ret; 1003 return ret;
1004 } 1004 }
1005 1005
1006 static void btrfs_release_delayed_inode(struct btrfs_delayed_node *delayed_node) 1006 static void btrfs_release_delayed_inode(struct btrfs_delayed_node *delayed_node)
1007 { 1007 {
1008 struct btrfs_delayed_root *delayed_root; 1008 struct btrfs_delayed_root *delayed_root;
1009 1009
1010 if (delayed_node && 1010 if (delayed_node &&
1011 test_bit(BTRFS_DELAYED_NODE_INODE_DIRTY, &delayed_node->flags)) { 1011 test_bit(BTRFS_DELAYED_NODE_INODE_DIRTY, &delayed_node->flags)) {
1012 BUG_ON(!delayed_node->root); 1012 BUG_ON(!delayed_node->root);
1013 clear_bit(BTRFS_DELAYED_NODE_INODE_DIRTY, &delayed_node->flags); 1013 clear_bit(BTRFS_DELAYED_NODE_INODE_DIRTY, &delayed_node->flags);
1014 delayed_node->count--; 1014 delayed_node->count--;
1015 1015
1016 delayed_root = delayed_node->root->fs_info->delayed_root; 1016 delayed_root = delayed_node->root->fs_info->delayed_root;
1017 finish_one_item(delayed_root); 1017 finish_one_item(delayed_root);
1018 } 1018 }
1019 } 1019 }
1020 1020
1021 static void btrfs_release_delayed_iref(struct btrfs_delayed_node *delayed_node) 1021 static void btrfs_release_delayed_iref(struct btrfs_delayed_node *delayed_node)
1022 { 1022 {
1023 struct btrfs_delayed_root *delayed_root; 1023 struct btrfs_delayed_root *delayed_root;
1024 1024
1025 ASSERT(delayed_node->root); 1025 ASSERT(delayed_node->root);
1026 clear_bit(BTRFS_DELAYED_NODE_DEL_IREF, &delayed_node->flags); 1026 clear_bit(BTRFS_DELAYED_NODE_DEL_IREF, &delayed_node->flags);
1027 delayed_node->count--; 1027 delayed_node->count--;
1028 1028
1029 delayed_root = delayed_node->root->fs_info->delayed_root; 1029 delayed_root = delayed_node->root->fs_info->delayed_root;
1030 finish_one_item(delayed_root); 1030 finish_one_item(delayed_root);
1031 } 1031 }
1032 1032
1033 static int __btrfs_update_delayed_inode(struct btrfs_trans_handle *trans, 1033 static int __btrfs_update_delayed_inode(struct btrfs_trans_handle *trans,
1034 struct btrfs_root *root, 1034 struct btrfs_root *root,
1035 struct btrfs_path *path, 1035 struct btrfs_path *path,
1036 struct btrfs_delayed_node *node) 1036 struct btrfs_delayed_node *node)
1037 { 1037 {
1038 struct btrfs_key key; 1038 struct btrfs_key key;
1039 struct btrfs_inode_item *inode_item; 1039 struct btrfs_inode_item *inode_item;
1040 struct extent_buffer *leaf; 1040 struct extent_buffer *leaf;
1041 int mod; 1041 int mod;
1042 int ret; 1042 int ret;
1043 1043
1044 key.objectid = node->inode_id; 1044 key.objectid = node->inode_id;
1045 key.type = BTRFS_INODE_ITEM_KEY; 1045 key.type = BTRFS_INODE_ITEM_KEY;
1046 key.offset = 0; 1046 key.offset = 0;
1047 1047
1048 if (test_bit(BTRFS_DELAYED_NODE_DEL_IREF, &node->flags)) 1048 if (test_bit(BTRFS_DELAYED_NODE_DEL_IREF, &node->flags))
1049 mod = -1; 1049 mod = -1;
1050 else 1050 else
1051 mod = 1; 1051 mod = 1;
1052 1052
1053 ret = btrfs_lookup_inode(trans, root, path, &key, mod); 1053 ret = btrfs_lookup_inode(trans, root, path, &key, mod);
1054 if (ret > 0) { 1054 if (ret > 0) {
1055 btrfs_release_path(path); 1055 btrfs_release_path(path);
1056 return -ENOENT; 1056 return -ENOENT;
1057 } else if (ret < 0) { 1057 } else if (ret < 0) {
1058 return ret; 1058 return ret;
1059 } 1059 }
1060 1060
1061 leaf = path->nodes[0]; 1061 leaf = path->nodes[0];
1062 inode_item = btrfs_item_ptr(leaf, path->slots[0], 1062 inode_item = btrfs_item_ptr(leaf, path->slots[0],
1063 struct btrfs_inode_item); 1063 struct btrfs_inode_item);
1064 write_extent_buffer(leaf, &node->inode_item, (unsigned long)inode_item, 1064 write_extent_buffer(leaf, &node->inode_item, (unsigned long)inode_item,
1065 sizeof(struct btrfs_inode_item)); 1065 sizeof(struct btrfs_inode_item));
1066 btrfs_mark_buffer_dirty(leaf); 1066 btrfs_mark_buffer_dirty(leaf);
1067 1067
1068 if (!test_bit(BTRFS_DELAYED_NODE_DEL_IREF, &node->flags)) 1068 if (!test_bit(BTRFS_DELAYED_NODE_DEL_IREF, &node->flags))
1069 goto no_iref; 1069 goto no_iref;
1070 1070
1071 path->slots[0]++; 1071 path->slots[0]++;
1072 if (path->slots[0] >= btrfs_header_nritems(leaf)) 1072 if (path->slots[0] >= btrfs_header_nritems(leaf))
1073 goto search; 1073 goto search;
1074 again: 1074 again:
1075 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); 1075 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
1076 if (key.objectid != node->inode_id) 1076 if (key.objectid != node->inode_id)
1077 goto out; 1077 goto out;
1078 1078
1079 if (key.type != BTRFS_INODE_REF_KEY && 1079 if (key.type != BTRFS_INODE_REF_KEY &&
1080 key.type != BTRFS_INODE_EXTREF_KEY) 1080 key.type != BTRFS_INODE_EXTREF_KEY)
1081 goto out; 1081 goto out;
1082 1082
1083 /* 1083 /*
1084 * Delayed iref deletion is for the inode who has only one link, 1084 * Delayed iref deletion is for the inode who has only one link,
1085 * so there is only one iref. The case that several irefs are 1085 * so there is only one iref. The case that several irefs are
1086 * in the same item doesn't exist. 1086 * in the same item doesn't exist.
1087 */ 1087 */
1088 btrfs_del_item(trans, root, path); 1088 btrfs_del_item(trans, root, path);
1089 out: 1089 out:
1090 btrfs_release_delayed_iref(node); 1090 btrfs_release_delayed_iref(node);
1091 no_iref: 1091 no_iref:
1092 btrfs_release_path(path); 1092 btrfs_release_path(path);
1093 err_out: 1093 err_out:
1094 btrfs_delayed_inode_release_metadata(root, node); 1094 btrfs_delayed_inode_release_metadata(root, node);
1095 btrfs_release_delayed_inode(node); 1095 btrfs_release_delayed_inode(node);
1096 1096
1097 return ret; 1097 return ret;
1098 1098
1099 search: 1099 search:
1100 btrfs_release_path(path); 1100 btrfs_release_path(path);
1101 1101
1102 key.type = BTRFS_INODE_EXTREF_KEY; 1102 key.type = BTRFS_INODE_EXTREF_KEY;
1103 key.offset = -1; 1103 key.offset = -1;
1104 ret = btrfs_search_slot(trans, root, &key, path, -1, 1); 1104 ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
1105 if (ret < 0) 1105 if (ret < 0)
1106 goto err_out; 1106 goto err_out;
1107 ASSERT(ret); 1107 ASSERT(ret);
1108 1108
1109 ret = 0; 1109 ret = 0;
1110 leaf = path->nodes[0]; 1110 leaf = path->nodes[0];
1111 path->slots[0]--; 1111 path->slots[0]--;
1112 goto again; 1112 goto again;
1113 } 1113 }
1114 1114
1115 static inline int btrfs_update_delayed_inode(struct btrfs_trans_handle *trans, 1115 static inline int btrfs_update_delayed_inode(struct btrfs_trans_handle *trans,
1116 struct btrfs_root *root, 1116 struct btrfs_root *root,
1117 struct btrfs_path *path, 1117 struct btrfs_path *path,
1118 struct btrfs_delayed_node *node) 1118 struct btrfs_delayed_node *node)
1119 { 1119 {
1120 int ret; 1120 int ret;
1121 1121
1122 mutex_lock(&node->mutex); 1122 mutex_lock(&node->mutex);
1123 if (!test_bit(BTRFS_DELAYED_NODE_INODE_DIRTY, &node->flags)) { 1123 if (!test_bit(BTRFS_DELAYED_NODE_INODE_DIRTY, &node->flags)) {
1124 mutex_unlock(&node->mutex); 1124 mutex_unlock(&node->mutex);
1125 return 0; 1125 return 0;
1126 } 1126 }
1127 1127
1128 ret = __btrfs_update_delayed_inode(trans, root, path, node); 1128 ret = __btrfs_update_delayed_inode(trans, root, path, node);
1129 mutex_unlock(&node->mutex); 1129 mutex_unlock(&node->mutex);
1130 return ret; 1130 return ret;
1131 } 1131 }
1132 1132
1133 static inline int 1133 static inline int
1134 __btrfs_commit_inode_delayed_items(struct btrfs_trans_handle *trans, 1134 __btrfs_commit_inode_delayed_items(struct btrfs_trans_handle *trans,
1135 struct btrfs_path *path, 1135 struct btrfs_path *path,
1136 struct btrfs_delayed_node *node) 1136 struct btrfs_delayed_node *node)
1137 { 1137 {
1138 int ret; 1138 int ret;
1139 1139
1140 ret = btrfs_insert_delayed_items(trans, path, node->root, node); 1140 ret = btrfs_insert_delayed_items(trans, path, node->root, node);
1141 if (ret) 1141 if (ret)
1142 return ret; 1142 return ret;
1143 1143
1144 ret = btrfs_delete_delayed_items(trans, path, node->root, node); 1144 ret = btrfs_delete_delayed_items(trans, path, node->root, node);
1145 if (ret) 1145 if (ret)
1146 return ret; 1146 return ret;
1147 1147
1148 ret = btrfs_update_delayed_inode(trans, node->root, path, node); 1148 ret = btrfs_update_delayed_inode(trans, node->root, path, node);
1149 return ret; 1149 return ret;
1150 } 1150 }
1151 1151
1152 /* 1152 /*
1153 * Called when committing the transaction. 1153 * Called when committing the transaction.
1154 * Returns 0 on success. 1154 * Returns 0 on success.
1155 * Returns < 0 on error and returns with an aborted transaction with any 1155 * Returns < 0 on error and returns with an aborted transaction with any
1156 * outstanding delayed items cleaned up. 1156 * outstanding delayed items cleaned up.
1157 */ 1157 */
1158 static int __btrfs_run_delayed_items(struct btrfs_trans_handle *trans, 1158 static int __btrfs_run_delayed_items(struct btrfs_trans_handle *trans,
1159 struct btrfs_root *root, int nr) 1159 struct btrfs_root *root, int nr)
1160 { 1160 {
1161 struct btrfs_delayed_root *delayed_root; 1161 struct btrfs_delayed_root *delayed_root;
1162 struct btrfs_delayed_node *curr_node, *prev_node; 1162 struct btrfs_delayed_node *curr_node, *prev_node;
1163 struct btrfs_path *path; 1163 struct btrfs_path *path;
1164 struct btrfs_block_rsv *block_rsv; 1164 struct btrfs_block_rsv *block_rsv;
1165 int ret = 0; 1165 int ret = 0;
1166 bool count = (nr > 0); 1166 bool count = (nr > 0);
1167 1167
1168 if (trans->aborted) 1168 if (trans->aborted)
1169 return -EIO; 1169 return -EIO;
1170 1170
1171 path = btrfs_alloc_path(); 1171 path = btrfs_alloc_path();
1172 if (!path) 1172 if (!path)
1173 return -ENOMEM; 1173 return -ENOMEM;
1174 path->leave_spinning = 1; 1174 path->leave_spinning = 1;
1175 1175
1176 block_rsv = trans->block_rsv; 1176 block_rsv = trans->block_rsv;
1177 trans->block_rsv = &root->fs_info->delayed_block_rsv; 1177 trans->block_rsv = &root->fs_info->delayed_block_rsv;
1178 1178
1179 delayed_root = btrfs_get_delayed_root(root); 1179 delayed_root = btrfs_get_delayed_root(root);
1180 1180
1181 curr_node = btrfs_first_delayed_node(delayed_root); 1181 curr_node = btrfs_first_delayed_node(delayed_root);
1182 while (curr_node && (!count || (count && nr--))) { 1182 while (curr_node && (!count || (count && nr--))) {
1183 ret = __btrfs_commit_inode_delayed_items(trans, path, 1183 ret = __btrfs_commit_inode_delayed_items(trans, path,
1184 curr_node); 1184 curr_node);
1185 if (ret) { 1185 if (ret) {
1186 btrfs_release_delayed_node(curr_node); 1186 btrfs_release_delayed_node(curr_node);
1187 curr_node = NULL; 1187 curr_node = NULL;
1188 btrfs_abort_transaction(trans, root, ret); 1188 btrfs_abort_transaction(trans, root, ret);
1189 break; 1189 break;
1190 } 1190 }
1191 1191
1192 prev_node = curr_node; 1192 prev_node = curr_node;
1193 curr_node = btrfs_next_delayed_node(curr_node); 1193 curr_node = btrfs_next_delayed_node(curr_node);
1194 btrfs_release_delayed_node(prev_node); 1194 btrfs_release_delayed_node(prev_node);
1195 } 1195 }
1196 1196
1197 if (curr_node) 1197 if (curr_node)
1198 btrfs_release_delayed_node(curr_node); 1198 btrfs_release_delayed_node(curr_node);
1199 btrfs_free_path(path); 1199 btrfs_free_path(path);
1200 trans->block_rsv = block_rsv; 1200 trans->block_rsv = block_rsv;
1201 1201
1202 return ret; 1202 return ret;
1203 } 1203 }
1204 1204
1205 int btrfs_run_delayed_items(struct btrfs_trans_handle *trans, 1205 int btrfs_run_delayed_items(struct btrfs_trans_handle *trans,
1206 struct btrfs_root *root) 1206 struct btrfs_root *root)
1207 { 1207 {
1208 return __btrfs_run_delayed_items(trans, root, -1); 1208 return __btrfs_run_delayed_items(trans, root, -1);
1209 } 1209 }
1210 1210
1211 int btrfs_run_delayed_items_nr(struct btrfs_trans_handle *trans, 1211 int btrfs_run_delayed_items_nr(struct btrfs_trans_handle *trans,
1212 struct btrfs_root *root, int nr) 1212 struct btrfs_root *root, int nr)
1213 { 1213 {
1214 return __btrfs_run_delayed_items(trans, root, nr); 1214 return __btrfs_run_delayed_items(trans, root, nr);
1215 } 1215 }
1216 1216
1217 int btrfs_commit_inode_delayed_items(struct btrfs_trans_handle *trans, 1217 int btrfs_commit_inode_delayed_items(struct btrfs_trans_handle *trans,
1218 struct inode *inode) 1218 struct inode *inode)
1219 { 1219 {
1220 struct btrfs_delayed_node *delayed_node = btrfs_get_delayed_node(inode); 1220 struct btrfs_delayed_node *delayed_node = btrfs_get_delayed_node(inode);
1221 struct btrfs_path *path; 1221 struct btrfs_path *path;
1222 struct btrfs_block_rsv *block_rsv; 1222 struct btrfs_block_rsv *block_rsv;
1223 int ret; 1223 int ret;
1224 1224
1225 if (!delayed_node) 1225 if (!delayed_node)
1226 return 0; 1226 return 0;
1227 1227
1228 mutex_lock(&delayed_node->mutex); 1228 mutex_lock(&delayed_node->mutex);
1229 if (!delayed_node->count) { 1229 if (!delayed_node->count) {
1230 mutex_unlock(&delayed_node->mutex); 1230 mutex_unlock(&delayed_node->mutex);
1231 btrfs_release_delayed_node(delayed_node); 1231 btrfs_release_delayed_node(delayed_node);
1232 return 0; 1232 return 0;
1233 } 1233 }
1234 mutex_unlock(&delayed_node->mutex); 1234 mutex_unlock(&delayed_node->mutex);
1235 1235
1236 path = btrfs_alloc_path(); 1236 path = btrfs_alloc_path();
1237 if (!path) { 1237 if (!path) {
1238 btrfs_release_delayed_node(delayed_node); 1238 btrfs_release_delayed_node(delayed_node);
1239 return -ENOMEM; 1239 return -ENOMEM;
1240 } 1240 }
1241 path->leave_spinning = 1; 1241 path->leave_spinning = 1;
1242 1242
1243 block_rsv = trans->block_rsv; 1243 block_rsv = trans->block_rsv;
1244 trans->block_rsv = &delayed_node->root->fs_info->delayed_block_rsv; 1244 trans->block_rsv = &delayed_node->root->fs_info->delayed_block_rsv;
1245 1245
1246 ret = __btrfs_commit_inode_delayed_items(trans, path, delayed_node); 1246 ret = __btrfs_commit_inode_delayed_items(trans, path, delayed_node);
1247 1247
1248 btrfs_release_delayed_node(delayed_node); 1248 btrfs_release_delayed_node(delayed_node);
1249 btrfs_free_path(path); 1249 btrfs_free_path(path);
1250 trans->block_rsv = block_rsv; 1250 trans->block_rsv = block_rsv;
1251 1251
1252 return ret; 1252 return ret;
1253 } 1253 }
1254 1254
1255 int btrfs_commit_inode_delayed_inode(struct inode *inode) 1255 int btrfs_commit_inode_delayed_inode(struct inode *inode)
1256 { 1256 {
1257 struct btrfs_trans_handle *trans; 1257 struct btrfs_trans_handle *trans;
1258 struct btrfs_delayed_node *delayed_node = btrfs_get_delayed_node(inode); 1258 struct btrfs_delayed_node *delayed_node = btrfs_get_delayed_node(inode);
1259 struct btrfs_path *path; 1259 struct btrfs_path *path;
1260 struct btrfs_block_rsv *block_rsv; 1260 struct btrfs_block_rsv *block_rsv;
1261 int ret; 1261 int ret;
1262 1262
1263 if (!delayed_node) 1263 if (!delayed_node)
1264 return 0; 1264 return 0;
1265 1265
1266 mutex_lock(&delayed_node->mutex); 1266 mutex_lock(&delayed_node->mutex);
1267 if (!test_bit(BTRFS_DELAYED_NODE_INODE_DIRTY, &delayed_node->flags)) { 1267 if (!test_bit(BTRFS_DELAYED_NODE_INODE_DIRTY, &delayed_node->flags)) {
1268 mutex_unlock(&delayed_node->mutex); 1268 mutex_unlock(&delayed_node->mutex);
1269 btrfs_release_delayed_node(delayed_node); 1269 btrfs_release_delayed_node(delayed_node);
1270 return 0; 1270 return 0;
1271 } 1271 }
1272 mutex_unlock(&delayed_node->mutex); 1272 mutex_unlock(&delayed_node->mutex);
1273 1273
1274 trans = btrfs_join_transaction(delayed_node->root); 1274 trans = btrfs_join_transaction(delayed_node->root);
1275 if (IS_ERR(trans)) { 1275 if (IS_ERR(trans)) {
1276 ret = PTR_ERR(trans); 1276 ret = PTR_ERR(trans);
1277 goto out; 1277 goto out;
1278 } 1278 }
1279 1279
1280 path = btrfs_alloc_path(); 1280 path = btrfs_alloc_path();
1281 if (!path) { 1281 if (!path) {
1282 ret = -ENOMEM; 1282 ret = -ENOMEM;
1283 goto trans_out; 1283 goto trans_out;
1284 } 1284 }
1285 path->leave_spinning = 1; 1285 path->leave_spinning = 1;
1286 1286
1287 block_rsv = trans->block_rsv; 1287 block_rsv = trans->block_rsv;
1288 trans->block_rsv = &delayed_node->root->fs_info->delayed_block_rsv; 1288 trans->block_rsv = &delayed_node->root->fs_info->delayed_block_rsv;
1289 1289
1290 mutex_lock(&delayed_node->mutex); 1290 mutex_lock(&delayed_node->mutex);
1291 if (test_bit(BTRFS_DELAYED_NODE_INODE_DIRTY, &delayed_node->flags)) 1291 if (test_bit(BTRFS_DELAYED_NODE_INODE_DIRTY, &delayed_node->flags))
1292 ret = __btrfs_update_delayed_inode(trans, delayed_node->root, 1292 ret = __btrfs_update_delayed_inode(trans, delayed_node->root,
1293 path, delayed_node); 1293 path, delayed_node);
1294 else 1294 else
1295 ret = 0; 1295 ret = 0;
1296 mutex_unlock(&delayed_node->mutex); 1296 mutex_unlock(&delayed_node->mutex);
1297 1297
1298 btrfs_free_path(path); 1298 btrfs_free_path(path);
1299 trans->block_rsv = block_rsv; 1299 trans->block_rsv = block_rsv;
1300 trans_out: 1300 trans_out:
1301 btrfs_end_transaction(trans, delayed_node->root); 1301 btrfs_end_transaction(trans, delayed_node->root);
1302 btrfs_btree_balance_dirty(delayed_node->root); 1302 btrfs_btree_balance_dirty(delayed_node->root);
1303 out: 1303 out:
1304 btrfs_release_delayed_node(delayed_node); 1304 btrfs_release_delayed_node(delayed_node);
1305 1305
1306 return ret; 1306 return ret;
1307 } 1307 }
1308 1308
1309 void btrfs_remove_delayed_node(struct inode *inode) 1309 void btrfs_remove_delayed_node(struct inode *inode)
1310 { 1310 {
1311 struct btrfs_delayed_node *delayed_node; 1311 struct btrfs_delayed_node *delayed_node;
1312 1312
1313 delayed_node = ACCESS_ONCE(BTRFS_I(inode)->delayed_node); 1313 delayed_node = ACCESS_ONCE(BTRFS_I(inode)->delayed_node);
1314 if (!delayed_node) 1314 if (!delayed_node)
1315 return; 1315 return;
1316 1316
1317 BTRFS_I(inode)->delayed_node = NULL; 1317 BTRFS_I(inode)->delayed_node = NULL;
1318 btrfs_release_delayed_node(delayed_node); 1318 btrfs_release_delayed_node(delayed_node);
1319 } 1319 }
1320 1320
1321 struct btrfs_async_delayed_work { 1321 struct btrfs_async_delayed_work {
1322 struct btrfs_delayed_root *delayed_root; 1322 struct btrfs_delayed_root *delayed_root;
1323 int nr; 1323 int nr;
1324 struct btrfs_work work; 1324 struct btrfs_work work;
1325 }; 1325 };
1326 1326
1327 static void btrfs_async_run_delayed_root(struct btrfs_work *work) 1327 static void btrfs_async_run_delayed_root(struct btrfs_work *work)
1328 { 1328 {
1329 struct btrfs_async_delayed_work *async_work; 1329 struct btrfs_async_delayed_work *async_work;
1330 struct btrfs_delayed_root *delayed_root; 1330 struct btrfs_delayed_root *delayed_root;
1331 struct btrfs_trans_handle *trans; 1331 struct btrfs_trans_handle *trans;
1332 struct btrfs_path *path; 1332 struct btrfs_path *path;
1333 struct btrfs_delayed_node *delayed_node = NULL; 1333 struct btrfs_delayed_node *delayed_node = NULL;
1334 struct btrfs_root *root; 1334 struct btrfs_root *root;
1335 struct btrfs_block_rsv *block_rsv; 1335 struct btrfs_block_rsv *block_rsv;
1336 int total_done = 0; 1336 int total_done = 0;
1337 1337
1338 async_work = container_of(work, struct btrfs_async_delayed_work, work); 1338 async_work = container_of(work, struct btrfs_async_delayed_work, work);
1339 delayed_root = async_work->delayed_root; 1339 delayed_root = async_work->delayed_root;
1340 1340
1341 path = btrfs_alloc_path(); 1341 path = btrfs_alloc_path();
1342 if (!path) 1342 if (!path)
1343 goto out; 1343 goto out;
1344 1344
1345 again: 1345 again:
1346 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND / 2) 1346 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND / 2)
1347 goto free_path; 1347 goto free_path;
1348 1348
1349 delayed_node = btrfs_first_prepared_delayed_node(delayed_root); 1349 delayed_node = btrfs_first_prepared_delayed_node(delayed_root);
1350 if (!delayed_node) 1350 if (!delayed_node)
1351 goto free_path; 1351 goto free_path;
1352 1352
1353 path->leave_spinning = 1; 1353 path->leave_spinning = 1;
1354 root = delayed_node->root; 1354 root = delayed_node->root;
1355 1355
1356 trans = btrfs_join_transaction(root); 1356 trans = btrfs_join_transaction(root);
1357 if (IS_ERR(trans)) 1357 if (IS_ERR(trans))
1358 goto release_path; 1358 goto release_path;
1359 1359
1360 block_rsv = trans->block_rsv; 1360 block_rsv = trans->block_rsv;
1361 trans->block_rsv = &root->fs_info->delayed_block_rsv; 1361 trans->block_rsv = &root->fs_info->delayed_block_rsv;
1362 1362
1363 __btrfs_commit_inode_delayed_items(trans, path, delayed_node); 1363 __btrfs_commit_inode_delayed_items(trans, path, delayed_node);
1364 1364
1365 trans->block_rsv = block_rsv; 1365 trans->block_rsv = block_rsv;
1366 btrfs_end_transaction(trans, root); 1366 btrfs_end_transaction(trans, root);
1367 btrfs_btree_balance_dirty_nodelay(root); 1367 btrfs_btree_balance_dirty_nodelay(root);
1368 1368
1369 release_path: 1369 release_path:
1370 btrfs_release_path(path); 1370 btrfs_release_path(path);
1371 total_done++; 1371 total_done++;
1372 1372
1373 btrfs_release_prepared_delayed_node(delayed_node); 1373 btrfs_release_prepared_delayed_node(delayed_node);
1374 if (async_work->nr == 0 || total_done < async_work->nr) 1374 if (async_work->nr == 0 || total_done < async_work->nr)
1375 goto again; 1375 goto again;
1376 1376
1377 free_path: 1377 free_path:
1378 btrfs_free_path(path); 1378 btrfs_free_path(path);
1379 out: 1379 out:
1380 wake_up(&delayed_root->wait); 1380 wake_up(&delayed_root->wait);
1381 kfree(async_work); 1381 kfree(async_work);
1382 } 1382 }
1383 1383
1384 1384
1385 static int btrfs_wq_run_delayed_node(struct btrfs_delayed_root *delayed_root, 1385 static int btrfs_wq_run_delayed_node(struct btrfs_delayed_root *delayed_root,
1386 struct btrfs_root *root, int nr) 1386 struct btrfs_root *root, int nr)
1387 { 1387 {
1388 struct btrfs_async_delayed_work *async_work; 1388 struct btrfs_async_delayed_work *async_work;
1389 1389
1390 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND) 1390 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
1391 return 0; 1391 return 0;
1392 1392
1393 async_work = kmalloc(sizeof(*async_work), GFP_NOFS); 1393 async_work = kmalloc(sizeof(*async_work), GFP_NOFS);
1394 if (!async_work) 1394 if (!async_work)
1395 return -ENOMEM; 1395 return -ENOMEM;
1396 1396
1397 async_work->delayed_root = delayed_root; 1397 async_work->delayed_root = delayed_root;
1398 btrfs_init_work(&async_work->work, btrfs_delayed_meta_helper, 1398 btrfs_init_work(&async_work->work, btrfs_delayed_meta_helper,
1399 btrfs_async_run_delayed_root, NULL, NULL); 1399 btrfs_async_run_delayed_root, NULL, NULL);
1400 async_work->nr = nr; 1400 async_work->nr = nr;
1401 1401
1402 btrfs_queue_work(root->fs_info->delayed_workers, &async_work->work); 1402 btrfs_queue_work(root->fs_info->delayed_workers, &async_work->work);
1403 return 0; 1403 return 0;
1404 } 1404 }
1405 1405
1406 void btrfs_assert_delayed_root_empty(struct btrfs_root *root) 1406 void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
1407 { 1407 {
1408 struct btrfs_delayed_root *delayed_root; 1408 struct btrfs_delayed_root *delayed_root;
1409 delayed_root = btrfs_get_delayed_root(root); 1409 delayed_root = btrfs_get_delayed_root(root);
1410 WARN_ON(btrfs_first_delayed_node(delayed_root)); 1410 WARN_ON(btrfs_first_delayed_node(delayed_root));
1411 } 1411 }
1412 1412
1413 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq) 1413 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
1414 { 1414 {
1415 int val = atomic_read(&delayed_root->items_seq); 1415 int val = atomic_read(&delayed_root->items_seq);
1416 1416
1417 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH) 1417 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
1418 return 1; 1418 return 1;
1419 1419
1420 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND) 1420 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
1421 return 1; 1421 return 1;
1422 1422
1423 return 0; 1423 return 0;
1424 } 1424 }
1425 1425
1426 void btrfs_balance_delayed_items(struct btrfs_root *root) 1426 void btrfs_balance_delayed_items(struct btrfs_root *root)
1427 { 1427 {
1428 struct btrfs_delayed_root *delayed_root; 1428 struct btrfs_delayed_root *delayed_root;
1429 1429
1430 delayed_root = btrfs_get_delayed_root(root); 1430 delayed_root = btrfs_get_delayed_root(root);
1431 1431
1432 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND) 1432 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
1433 return; 1433 return;
1434 1434
1435 if (atomic_read(&delayed_root->items) >= BTRFS_DELAYED_WRITEBACK) { 1435 if (atomic_read(&delayed_root->items) >= BTRFS_DELAYED_WRITEBACK) {
1436 int seq; 1436 int seq;
1437 int ret; 1437 int ret;
1438 1438
1439 seq = atomic_read(&delayed_root->items_seq); 1439 seq = atomic_read(&delayed_root->items_seq);
1440 1440
1441 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0); 1441 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
1442 if (ret) 1442 if (ret)
1443 return; 1443 return;
1444 1444
1445 wait_event_interruptible(delayed_root->wait, 1445 wait_event_interruptible(delayed_root->wait,
1446 could_end_wait(delayed_root, seq)); 1446 could_end_wait(delayed_root, seq));
1447 return; 1447 return;
1448 } 1448 }
1449 1449
1450 btrfs_wq_run_delayed_node(delayed_root, root, BTRFS_DELAYED_BATCH); 1450 btrfs_wq_run_delayed_node(delayed_root, root, BTRFS_DELAYED_BATCH);
1451 } 1451 }
1452 1452
1453 /* Will return 0 or -ENOMEM */ 1453 /* Will return 0 or -ENOMEM */
1454 int btrfs_insert_delayed_dir_index(struct btrfs_trans_handle *trans, 1454 int btrfs_insert_delayed_dir_index(struct btrfs_trans_handle *trans,
1455 struct btrfs_root *root, const char *name, 1455 struct btrfs_root *root, const char *name,
1456 int name_len, struct inode *dir, 1456 int name_len, struct inode *dir,
1457 struct btrfs_disk_key *disk_key, u8 type, 1457 struct btrfs_disk_key *disk_key, u8 type,
1458 u64 index) 1458 u64 index)
1459 { 1459 {
1460 struct btrfs_delayed_node *delayed_node; 1460 struct btrfs_delayed_node *delayed_node;
1461 struct btrfs_delayed_item *delayed_item; 1461 struct btrfs_delayed_item *delayed_item;
1462 struct btrfs_dir_item *dir_item; 1462 struct btrfs_dir_item *dir_item;
1463 int ret; 1463 int ret;
1464 1464
1465 delayed_node = btrfs_get_or_create_delayed_node(dir); 1465 delayed_node = btrfs_get_or_create_delayed_node(dir);
1466 if (IS_ERR(delayed_node)) 1466 if (IS_ERR(delayed_node))
1467 return PTR_ERR(delayed_node); 1467 return PTR_ERR(delayed_node);
1468 1468
1469 delayed_item = btrfs_alloc_delayed_item(sizeof(*dir_item) + name_len); 1469 delayed_item = btrfs_alloc_delayed_item(sizeof(*dir_item) + name_len);
1470 if (!delayed_item) { 1470 if (!delayed_item) {
1471 ret = -ENOMEM; 1471 ret = -ENOMEM;
1472 goto release_node; 1472 goto release_node;
1473 } 1473 }
1474 1474
1475 delayed_item->key.objectid = btrfs_ino(dir); 1475 delayed_item->key.objectid = btrfs_ino(dir);
1476 delayed_item->key.type = BTRFS_DIR_INDEX_KEY; 1476 delayed_item->key.type = BTRFS_DIR_INDEX_KEY;
1477 delayed_item->key.offset = index; 1477 delayed_item->key.offset = index;
1478 1478
1479 dir_item = (struct btrfs_dir_item *)delayed_item->data; 1479 dir_item = (struct btrfs_dir_item *)delayed_item->data;
1480 dir_item->location = *disk_key; 1480 dir_item->location = *disk_key;
1481 btrfs_set_stack_dir_transid(dir_item, trans->transid); 1481 btrfs_set_stack_dir_transid(dir_item, trans->transid);
1482 btrfs_set_stack_dir_data_len(dir_item, 0); 1482 btrfs_set_stack_dir_data_len(dir_item, 0);
1483 btrfs_set_stack_dir_name_len(dir_item, name_len); 1483 btrfs_set_stack_dir_name_len(dir_item, name_len);
1484 btrfs_set_stack_dir_type(dir_item, type); 1484 btrfs_set_stack_dir_type(dir_item, type);
1485 memcpy((char *)(dir_item + 1), name, name_len); 1485 memcpy((char *)(dir_item + 1), name, name_len);
1486 1486
1487 ret = btrfs_delayed_item_reserve_metadata(trans, root, delayed_item); 1487 ret = btrfs_delayed_item_reserve_metadata(trans, root, delayed_item);
1488 /* 1488 /*
1489 * we have reserved enough space when we start a new transaction, 1489 * we have reserved enough space when we start a new transaction,
1490 * so reserving metadata failure is impossible 1490 * so reserving metadata failure is impossible
1491 */ 1491 */
1492 BUG_ON(ret); 1492 BUG_ON(ret);
1493 1493
1494 1494
1495 mutex_lock(&delayed_node->mutex); 1495 mutex_lock(&delayed_node->mutex);
1496 ret = __btrfs_add_delayed_insertion_item(delayed_node, delayed_item); 1496 ret = __btrfs_add_delayed_insertion_item(delayed_node, delayed_item);
1497 if (unlikely(ret)) { 1497 if (unlikely(ret)) {
1498 btrfs_err(root->fs_info, "err add delayed dir index item(name: %.*s) " 1498 btrfs_err(root->fs_info, "err add delayed dir index item(name: %.*s) "
1499 "into the insertion tree of the delayed node" 1499 "into the insertion tree of the delayed node"
1500 "(root id: %llu, inode id: %llu, errno: %d)", 1500 "(root id: %llu, inode id: %llu, errno: %d)",
1501 name_len, name, delayed_node->root->objectid, 1501 name_len, name, delayed_node->root->objectid,
1502 delayed_node->inode_id, ret); 1502 delayed_node->inode_id, ret);
1503 BUG(); 1503 BUG();
1504 } 1504 }
1505 mutex_unlock(&delayed_node->mutex); 1505 mutex_unlock(&delayed_node->mutex);
1506 1506
1507 release_node: 1507 release_node:
1508 btrfs_release_delayed_node(delayed_node); 1508 btrfs_release_delayed_node(delayed_node);
1509 return ret; 1509 return ret;
1510 } 1510 }
1511 1511
1512 static int btrfs_delete_delayed_insertion_item(struct btrfs_root *root, 1512 static int btrfs_delete_delayed_insertion_item(struct btrfs_root *root,
1513 struct btrfs_delayed_node *node, 1513 struct btrfs_delayed_node *node,
1514 struct btrfs_key *key) 1514 struct btrfs_key *key)
1515 { 1515 {
1516 struct btrfs_delayed_item *item; 1516 struct btrfs_delayed_item *item;
1517 1517
1518 mutex_lock(&node->mutex); 1518 mutex_lock(&node->mutex);
1519 item = __btrfs_lookup_delayed_insertion_item(node, key); 1519 item = __btrfs_lookup_delayed_insertion_item(node, key);
1520 if (!item) { 1520 if (!item) {
1521 mutex_unlock(&node->mutex); 1521 mutex_unlock(&node->mutex);
1522 return 1; 1522 return 1;
1523 } 1523 }
1524 1524
1525 btrfs_delayed_item_release_metadata(root, item); 1525 btrfs_delayed_item_release_metadata(root, item);
1526 btrfs_release_delayed_item(item); 1526 btrfs_release_delayed_item(item);
1527 mutex_unlock(&node->mutex); 1527 mutex_unlock(&node->mutex);
1528 return 0; 1528 return 0;
1529 } 1529 }
1530 1530
1531 int btrfs_delete_delayed_dir_index(struct btrfs_trans_handle *trans, 1531 int btrfs_delete_delayed_dir_index(struct btrfs_trans_handle *trans,
1532 struct btrfs_root *root, struct inode *dir, 1532 struct btrfs_root *root, struct inode *dir,
1533 u64 index) 1533 u64 index)
1534 { 1534 {
1535 struct btrfs_delayed_node *node; 1535 struct btrfs_delayed_node *node;
1536 struct btrfs_delayed_item *item; 1536 struct btrfs_delayed_item *item;
1537 struct btrfs_key item_key; 1537 struct btrfs_key item_key;
1538 int ret; 1538 int ret;
1539 1539
1540 node = btrfs_get_or_create_delayed_node(dir); 1540 node = btrfs_get_or_create_delayed_node(dir);
1541 if (IS_ERR(node)) 1541 if (IS_ERR(node))
1542 return PTR_ERR(node); 1542 return PTR_ERR(node);
1543 1543
1544 item_key.objectid = btrfs_ino(dir); 1544 item_key.objectid = btrfs_ino(dir);
1545 item_key.type = BTRFS_DIR_INDEX_KEY; 1545 item_key.type = BTRFS_DIR_INDEX_KEY;
1546 item_key.offset = index; 1546 item_key.offset = index;
1547 1547
1548 ret = btrfs_delete_delayed_insertion_item(root, node, &item_key); 1548 ret = btrfs_delete_delayed_insertion_item(root, node, &item_key);
1549 if (!ret) 1549 if (!ret)
1550 goto end; 1550 goto end;
1551 1551
1552 item = btrfs_alloc_delayed_item(0); 1552 item = btrfs_alloc_delayed_item(0);
1553 if (!item) { 1553 if (!item) {
1554 ret = -ENOMEM; 1554 ret = -ENOMEM;
1555 goto end; 1555 goto end;
1556 } 1556 }
1557 1557
1558 item->key = item_key; 1558 item->key = item_key;
1559 1559
1560 ret = btrfs_delayed_item_reserve_metadata(trans, root, item); 1560 ret = btrfs_delayed_item_reserve_metadata(trans, root, item);
1561 /* 1561 /*
1562 * we have reserved enough space when we start a new transaction, 1562 * we have reserved enough space when we start a new transaction,
1563 * so reserving metadata failure is impossible. 1563 * so reserving metadata failure is impossible.
1564 */ 1564 */
1565 BUG_ON(ret); 1565 BUG_ON(ret);
1566 1566
1567 mutex_lock(&node->mutex); 1567 mutex_lock(&node->mutex);
1568 ret = __btrfs_add_delayed_deletion_item(node, item); 1568 ret = __btrfs_add_delayed_deletion_item(node, item);
1569 if (unlikely(ret)) { 1569 if (unlikely(ret)) {
1570 btrfs_err(root->fs_info, "err add delayed dir index item(index: %llu) " 1570 btrfs_err(root->fs_info, "err add delayed dir index item(index: %llu) "
1571 "into the deletion tree of the delayed node" 1571 "into the deletion tree of the delayed node"
1572 "(root id: %llu, inode id: %llu, errno: %d)", 1572 "(root id: %llu, inode id: %llu, errno: %d)",
1573 index, node->root->objectid, node->inode_id, 1573 index, node->root->objectid, node->inode_id,
1574 ret); 1574 ret);
1575 BUG(); 1575 BUG();
1576 } 1576 }
1577 mutex_unlock(&node->mutex); 1577 mutex_unlock(&node->mutex);
1578 end: 1578 end:
1579 btrfs_release_delayed_node(node); 1579 btrfs_release_delayed_node(node);
1580 return ret; 1580 return ret;
1581 } 1581 }
1582 1582
1583 int btrfs_inode_delayed_dir_index_count(struct inode *inode) 1583 int btrfs_inode_delayed_dir_index_count(struct inode *inode)
1584 { 1584 {
1585 struct btrfs_delayed_node *delayed_node = btrfs_get_delayed_node(inode); 1585 struct btrfs_delayed_node *delayed_node = btrfs_get_delayed_node(inode);
1586 1586
1587 if (!delayed_node) 1587 if (!delayed_node)
1588 return -ENOENT; 1588 return -ENOENT;
1589 1589
1590 /* 1590 /*
1591 * Since we have held i_mutex of this directory, it is impossible that 1591 * Since we have held i_mutex of this directory, it is impossible that
1592 * a new directory index is added into the delayed node and index_cnt 1592 * a new directory index is added into the delayed node and index_cnt
1593 * is updated now. So we needn't lock the delayed node. 1593 * is updated now. So we needn't lock the delayed node.
1594 */ 1594 */
1595 if (!delayed_node->index_cnt) { 1595 if (!delayed_node->index_cnt) {
1596 btrfs_release_delayed_node(delayed_node); 1596 btrfs_release_delayed_node(delayed_node);
1597 return -EINVAL; 1597 return -EINVAL;
1598 } 1598 }
1599 1599
1600 BTRFS_I(inode)->index_cnt = delayed_node->index_cnt; 1600 BTRFS_I(inode)->index_cnt = delayed_node->index_cnt;
1601 btrfs_release_delayed_node(delayed_node); 1601 btrfs_release_delayed_node(delayed_node);
1602 return 0; 1602 return 0;
1603 } 1603 }
1604 1604
1605 void btrfs_get_delayed_items(struct inode *inode, struct list_head *ins_list, 1605 void btrfs_get_delayed_items(struct inode *inode, struct list_head *ins_list,
1606 struct list_head *del_list) 1606 struct list_head *del_list)
1607 { 1607 {
1608 struct btrfs_delayed_node *delayed_node; 1608 struct btrfs_delayed_node *delayed_node;
1609 struct btrfs_delayed_item *item; 1609 struct btrfs_delayed_item *item;
1610 1610
1611 delayed_node = btrfs_get_delayed_node(inode); 1611 delayed_node = btrfs_get_delayed_node(inode);
1612 if (!delayed_node) 1612 if (!delayed_node)
1613 return; 1613 return;
1614 1614
1615 mutex_lock(&delayed_node->mutex); 1615 mutex_lock(&delayed_node->mutex);
1616 item = __btrfs_first_delayed_insertion_item(delayed_node); 1616 item = __btrfs_first_delayed_insertion_item(delayed_node);
1617 while (item) { 1617 while (item) {
1618 atomic_inc(&item->refs); 1618 atomic_inc(&item->refs);
1619 list_add_tail(&item->readdir_list, ins_list); 1619 list_add_tail(&item->readdir_list, ins_list);
1620 item = __btrfs_next_delayed_item(item); 1620 item = __btrfs_next_delayed_item(item);
1621 } 1621 }
1622 1622
1623 item = __btrfs_first_delayed_deletion_item(delayed_node); 1623 item = __btrfs_first_delayed_deletion_item(delayed_node);
1624 while (item) { 1624 while (item) {
1625 atomic_inc(&item->refs); 1625 atomic_inc(&item->refs);
1626 list_add_tail(&item->readdir_list, del_list); 1626 list_add_tail(&item->readdir_list, del_list);
1627 item = __btrfs_next_delayed_item(item); 1627 item = __btrfs_next_delayed_item(item);
1628 } 1628 }
1629 mutex_unlock(&delayed_node->mutex); 1629 mutex_unlock(&delayed_node->mutex);
1630 /* 1630 /*
1631 * This delayed node is still cached in the btrfs inode, so refs 1631 * This delayed node is still cached in the btrfs inode, so refs
1632 * must be > 1 now, and we needn't check it is going to be freed 1632 * must be > 1 now, and we needn't check it is going to be freed
1633 * or not. 1633 * or not.
1634 * 1634 *
1635 * Besides that, this function is used to read dir, we do not 1635 * Besides that, this function is used to read dir, we do not
1636 * insert/delete delayed items in this period. So we also needn't 1636 * insert/delete delayed items in this period. So we also needn't
1637 * requeue or dequeue this delayed node. 1637 * requeue or dequeue this delayed node.
1638 */ 1638 */
1639 atomic_dec(&delayed_node->refs); 1639 atomic_dec(&delayed_node->refs);
1640 } 1640 }
1641 1641
1642 void btrfs_put_delayed_items(struct list_head *ins_list, 1642 void btrfs_put_delayed_items(struct list_head *ins_list,
1643 struct list_head *del_list) 1643 struct list_head *del_list)
1644 { 1644 {
1645 struct btrfs_delayed_item *curr, *next; 1645 struct btrfs_delayed_item *curr, *next;
1646 1646
1647 list_for_each_entry_safe(curr, next, ins_list, readdir_list) { 1647 list_for_each_entry_safe(curr, next, ins_list, readdir_list) {
1648 list_del(&curr->readdir_list); 1648 list_del(&curr->readdir_list);
1649 if (atomic_dec_and_test(&curr->refs)) 1649 if (atomic_dec_and_test(&curr->refs))
1650 kfree(curr); 1650 kfree(curr);
1651 } 1651 }
1652 1652
1653 list_for_each_entry_safe(curr, next, del_list, readdir_list) { 1653 list_for_each_entry_safe(curr, next, del_list, readdir_list) {
1654 list_del(&curr->readdir_list); 1654 list_del(&curr->readdir_list);
1655 if (atomic_dec_and_test(&curr->refs)) 1655 if (atomic_dec_and_test(&curr->refs))
1656 kfree(curr); 1656 kfree(curr);
1657 } 1657 }
1658 } 1658 }
1659 1659
1660 int btrfs_should_delete_dir_index(struct list_head *del_list, 1660 int btrfs_should_delete_dir_index(struct list_head *del_list,
1661 u64 index) 1661 u64 index)
1662 { 1662 {
1663 struct btrfs_delayed_item *curr, *next; 1663 struct btrfs_delayed_item *curr, *next;
1664 int ret; 1664 int ret;
1665 1665
1666 if (list_empty(del_list)) 1666 if (list_empty(del_list))
1667 return 0; 1667 return 0;
1668 1668
1669 list_for_each_entry_safe(curr, next, del_list, readdir_list) { 1669 list_for_each_entry_safe(curr, next, del_list, readdir_list) {
1670 if (curr->key.offset > index) 1670 if (curr->key.offset > index)
1671 break; 1671 break;
1672 1672
1673 list_del(&curr->readdir_list); 1673 list_del(&curr->readdir_list);
1674 ret = (curr->key.offset == index); 1674 ret = (curr->key.offset == index);
1675 1675
1676 if (atomic_dec_and_test(&curr->refs)) 1676 if (atomic_dec_and_test(&curr->refs))
1677 kfree(curr); 1677 kfree(curr);
1678 1678
1679 if (ret) 1679 if (ret)
1680 return 1; 1680 return 1;
1681 else 1681 else
1682 continue; 1682 continue;
1683 } 1683 }
1684 return 0; 1684 return 0;
1685 } 1685 }
1686 1686
1687 /* 1687 /*
1688 * btrfs_readdir_delayed_dir_index - read dir info stored in the delayed tree 1688 * btrfs_readdir_delayed_dir_index - read dir info stored in the delayed tree
1689 * 1689 *
1690 */ 1690 */
1691 int btrfs_readdir_delayed_dir_index(struct dir_context *ctx, 1691 int btrfs_readdir_delayed_dir_index(struct dir_context *ctx,
1692 struct list_head *ins_list) 1692 struct list_head *ins_list)
1693 { 1693 {
1694 struct btrfs_dir_item *di; 1694 struct btrfs_dir_item *di;
1695 struct btrfs_delayed_item *curr, *next; 1695 struct btrfs_delayed_item *curr, *next;
1696 struct btrfs_key location; 1696 struct btrfs_key location;
1697 char *name; 1697 char *name;
1698 int name_len; 1698 int name_len;
1699 int over = 0; 1699 int over = 0;
1700 unsigned char d_type; 1700 unsigned char d_type;
1701 1701
1702 if (list_empty(ins_list)) 1702 if (list_empty(ins_list))
1703 return 0; 1703 return 0;
1704 1704
1705 /* 1705 /*
1706 * Changing the data of the delayed item is impossible. So 1706 * Changing the data of the delayed item is impossible. So
1707 * we needn't lock them. And we have held i_mutex of the 1707 * we needn't lock them. And we have held i_mutex of the
1708 * directory, nobody can delete any directory indexes now. 1708 * directory, nobody can delete any directory indexes now.
1709 */ 1709 */
1710 list_for_each_entry_safe(curr, next, ins_list, readdir_list) { 1710 list_for_each_entry_safe(curr, next, ins_list, readdir_list) {
1711 list_del(&curr->readdir_list); 1711 list_del(&curr->readdir_list);
1712 1712
1713 if (curr->key.offset < ctx->pos) { 1713 if (curr->key.offset < ctx->pos) {
1714 if (atomic_dec_and_test(&curr->refs)) 1714 if (atomic_dec_and_test(&curr->refs))
1715 kfree(curr); 1715 kfree(curr);
1716 continue; 1716 continue;
1717 } 1717 }
1718 1718
1719 ctx->pos = curr->key.offset; 1719 ctx->pos = curr->key.offset;
1720 1720
1721 di = (struct btrfs_dir_item *)curr->data; 1721 di = (struct btrfs_dir_item *)curr->data;
1722 name = (char *)(di + 1); 1722 name = (char *)(di + 1);
1723 name_len = btrfs_stack_dir_name_len(di); 1723 name_len = btrfs_stack_dir_name_len(di);
1724 1724
1725 d_type = btrfs_filetype_table[di->type]; 1725 d_type = btrfs_filetype_table[di->type];
1726 btrfs_disk_key_to_cpu(&location, &di->location); 1726 btrfs_disk_key_to_cpu(&location, &di->location);
1727 1727
1728 over = !dir_emit(ctx, name, name_len, 1728 over = !dir_emit(ctx, name, name_len,
1729 location.objectid, d_type); 1729 location.objectid, d_type);
1730 1730
1731 if (atomic_dec_and_test(&curr->refs)) 1731 if (atomic_dec_and_test(&curr->refs))
1732 kfree(curr); 1732 kfree(curr);
1733 1733
1734 if (over) 1734 if (over)
1735 return 1; 1735 return 1;
1736 } 1736 }
1737 return 0; 1737 return 0;
1738 } 1738 }
1739 1739
1740 static void fill_stack_inode_item(struct btrfs_trans_handle *trans, 1740 static void fill_stack_inode_item(struct btrfs_trans_handle *trans,
1741 struct btrfs_inode_item *inode_item, 1741 struct btrfs_inode_item *inode_item,
1742 struct inode *inode) 1742 struct inode *inode)
1743 { 1743 {
1744 btrfs_set_stack_inode_uid(inode_item, i_uid_read(inode)); 1744 btrfs_set_stack_inode_uid(inode_item, i_uid_read(inode));
1745 btrfs_set_stack_inode_gid(inode_item, i_gid_read(inode)); 1745 btrfs_set_stack_inode_gid(inode_item, i_gid_read(inode));
1746 btrfs_set_stack_inode_size(inode_item, BTRFS_I(inode)->disk_i_size); 1746 btrfs_set_stack_inode_size(inode_item, BTRFS_I(inode)->disk_i_size);
1747 btrfs_set_stack_inode_mode(inode_item, inode->i_mode); 1747 btrfs_set_stack_inode_mode(inode_item, inode->i_mode);
1748 btrfs_set_stack_inode_nlink(inode_item, inode->i_nlink); 1748 btrfs_set_stack_inode_nlink(inode_item, inode->i_nlink);
1749 btrfs_set_stack_inode_nbytes(inode_item, inode_get_bytes(inode)); 1749 btrfs_set_stack_inode_nbytes(inode_item, inode_get_bytes(inode));
1750 btrfs_set_stack_inode_generation(inode_item, 1750 btrfs_set_stack_inode_generation(inode_item,
1751 BTRFS_I(inode)->generation); 1751 BTRFS_I(inode)->generation);
1752 btrfs_set_stack_inode_sequence(inode_item, inode->i_version); 1752 btrfs_set_stack_inode_sequence(inode_item, inode->i_version);
1753 btrfs_set_stack_inode_transid(inode_item, trans->transid); 1753 btrfs_set_stack_inode_transid(inode_item, trans->transid);
1754 btrfs_set_stack_inode_rdev(inode_item, inode->i_rdev); 1754 btrfs_set_stack_inode_rdev(inode_item, inode->i_rdev);
1755 btrfs_set_stack_inode_flags(inode_item, BTRFS_I(inode)->flags); 1755 btrfs_set_stack_inode_flags(inode_item, BTRFS_I(inode)->flags);
1756 btrfs_set_stack_inode_block_group(inode_item, 0); 1756 btrfs_set_stack_inode_block_group(inode_item, 0);
1757 1757
1758 btrfs_set_stack_timespec_sec(btrfs_inode_atime(inode_item), 1758 btrfs_set_stack_timespec_sec(btrfs_inode_atime(inode_item),
1759 inode->i_atime.tv_sec); 1759 inode->i_atime.tv_sec);
1760 btrfs_set_stack_timespec_nsec(btrfs_inode_atime(inode_item), 1760 btrfs_set_stack_timespec_nsec(btrfs_inode_atime(inode_item),
1761 inode->i_atime.tv_nsec); 1761 inode->i_atime.tv_nsec);
1762 1762
1763 btrfs_set_stack_timespec_sec(btrfs_inode_mtime(inode_item), 1763 btrfs_set_stack_timespec_sec(btrfs_inode_mtime(inode_item),
1764 inode->i_mtime.tv_sec); 1764 inode->i_mtime.tv_sec);
1765 btrfs_set_stack_timespec_nsec(btrfs_inode_mtime(inode_item), 1765 btrfs_set_stack_timespec_nsec(btrfs_inode_mtime(inode_item),
1766 inode->i_mtime.tv_nsec); 1766 inode->i_mtime.tv_nsec);
1767 1767
1768 btrfs_set_stack_timespec_sec(btrfs_inode_ctime(inode_item), 1768 btrfs_set_stack_timespec_sec(btrfs_inode_ctime(inode_item),
1769 inode->i_ctime.tv_sec); 1769 inode->i_ctime.tv_sec);
1770 btrfs_set_stack_timespec_nsec(btrfs_inode_ctime(inode_item), 1770 btrfs_set_stack_timespec_nsec(btrfs_inode_ctime(inode_item),
1771 inode->i_ctime.tv_nsec); 1771 inode->i_ctime.tv_nsec);
1772 } 1772 }
1773 1773
1774 int btrfs_fill_inode(struct inode *inode, u32 *rdev) 1774 int btrfs_fill_inode(struct inode *inode, u32 *rdev)
1775 { 1775 {
1776 struct btrfs_delayed_node *delayed_node; 1776 struct btrfs_delayed_node *delayed_node;
1777 struct btrfs_inode_item *inode_item; 1777 struct btrfs_inode_item *inode_item;
1778 struct btrfs_timespec *tspec; 1778 struct btrfs_timespec *tspec;
1779 1779
1780 delayed_node = btrfs_get_delayed_node(inode); 1780 delayed_node = btrfs_get_delayed_node(inode);
1781 if (!delayed_node) 1781 if (!delayed_node)
1782 return -ENOENT; 1782 return -ENOENT;
1783 1783
1784 mutex_lock(&delayed_node->mutex); 1784 mutex_lock(&delayed_node->mutex);
1785 if (!test_bit(BTRFS_DELAYED_NODE_INODE_DIRTY, &delayed_node->flags)) { 1785 if (!test_bit(BTRFS_DELAYED_NODE_INODE_DIRTY, &delayed_node->flags)) {
1786 mutex_unlock(&delayed_node->mutex); 1786 mutex_unlock(&delayed_node->mutex);
1787 btrfs_release_delayed_node(delayed_node); 1787 btrfs_release_delayed_node(delayed_node);
1788 return -ENOENT; 1788 return -ENOENT;
1789 } 1789 }
1790 1790
1791 inode_item = &delayed_node->inode_item; 1791 inode_item = &delayed_node->inode_item;
1792 1792
1793 i_uid_write(inode, btrfs_stack_inode_uid(inode_item)); 1793 i_uid_write(inode, btrfs_stack_inode_uid(inode_item));
1794 i_gid_write(inode, btrfs_stack_inode_gid(inode_item)); 1794 i_gid_write(inode, btrfs_stack_inode_gid(inode_item));
1795 btrfs_i_size_write(inode, btrfs_stack_inode_size(inode_item)); 1795 btrfs_i_size_write(inode, btrfs_stack_inode_size(inode_item));
1796 inode->i_mode = btrfs_stack_inode_mode(inode_item); 1796 inode->i_mode = btrfs_stack_inode_mode(inode_item);
1797 set_nlink(inode, btrfs_stack_inode_nlink(inode_item)); 1797 set_nlink(inode, btrfs_stack_inode_nlink(inode_item));
1798 inode_set_bytes(inode, btrfs_stack_inode_nbytes(inode_item)); 1798 inode_set_bytes(inode, btrfs_stack_inode_nbytes(inode_item));
1799 BTRFS_I(inode)->generation = btrfs_stack_inode_generation(inode_item); 1799 BTRFS_I(inode)->generation = btrfs_stack_inode_generation(inode_item);
1800 inode->i_version = btrfs_stack_inode_sequence(inode_item); 1800 inode->i_version = btrfs_stack_inode_sequence(inode_item);
1801 inode->i_rdev = 0; 1801 inode->i_rdev = 0;
1802 *rdev = btrfs_stack_inode_rdev(inode_item); 1802 *rdev = btrfs_stack_inode_rdev(inode_item);
1803 BTRFS_I(inode)->flags = btrfs_stack_inode_flags(inode_item); 1803 BTRFS_I(inode)->flags = btrfs_stack_inode_flags(inode_item);
1804 1804
1805 tspec = btrfs_inode_atime(inode_item); 1805 tspec = btrfs_inode_atime(inode_item);
1806 inode->i_atime.tv_sec = btrfs_stack_timespec_sec(tspec); 1806 inode->i_atime.tv_sec = btrfs_stack_timespec_sec(tspec);
1807 inode->i_atime.tv_nsec = btrfs_stack_timespec_nsec(tspec); 1807 inode->i_atime.tv_nsec = btrfs_stack_timespec_nsec(tspec);
1808 1808
1809 tspec = btrfs_inode_mtime(inode_item); 1809 tspec = btrfs_inode_mtime(inode_item);
1810 inode->i_mtime.tv_sec = btrfs_stack_timespec_sec(tspec); 1810 inode->i_mtime.tv_sec = btrfs_stack_timespec_sec(tspec);
1811 inode->i_mtime.tv_nsec = btrfs_stack_timespec_nsec(tspec); 1811 inode->i_mtime.tv_nsec = btrfs_stack_timespec_nsec(tspec);
1812 1812
1813 tspec = btrfs_inode_ctime(inode_item); 1813 tspec = btrfs_inode_ctime(inode_item);
1814 inode->i_ctime.tv_sec = btrfs_stack_timespec_sec(tspec); 1814 inode->i_ctime.tv_sec = btrfs_stack_timespec_sec(tspec);
1815 inode->i_ctime.tv_nsec = btrfs_stack_timespec_nsec(tspec); 1815 inode->i_ctime.tv_nsec = btrfs_stack_timespec_nsec(tspec);
1816 1816
1817 inode->i_generation = BTRFS_I(inode)->generation; 1817 inode->i_generation = BTRFS_I(inode)->generation;
1818 BTRFS_I(inode)->index_cnt = (u64)-1; 1818 BTRFS_I(inode)->index_cnt = (u64)-1;
1819 1819
1820 mutex_unlock(&delayed_node->mutex); 1820 mutex_unlock(&delayed_node->mutex);
1821 btrfs_release_delayed_node(delayed_node); 1821 btrfs_release_delayed_node(delayed_node);
1822 return 0; 1822 return 0;
1823 } 1823 }
1824 1824
1825 int btrfs_delayed_update_inode(struct btrfs_trans_handle *trans, 1825 int btrfs_delayed_update_inode(struct btrfs_trans_handle *trans,
1826 struct btrfs_root *root, struct inode *inode) 1826 struct btrfs_root *root, struct inode *inode)
1827 { 1827 {
1828 struct btrfs_delayed_node *delayed_node; 1828 struct btrfs_delayed_node *delayed_node;
1829 int ret = 0; 1829 int ret = 0;
1830 1830
1831 delayed_node = btrfs_get_or_create_delayed_node(inode); 1831 delayed_node = btrfs_get_or_create_delayed_node(inode);
1832 if (IS_ERR(delayed_node)) 1832 if (IS_ERR(delayed_node))
1833 return PTR_ERR(delayed_node); 1833 return PTR_ERR(delayed_node);
1834 1834
1835 mutex_lock(&delayed_node->mutex); 1835 mutex_lock(&delayed_node->mutex);
1836 if (test_bit(BTRFS_DELAYED_NODE_INODE_DIRTY, &delayed_node->flags)) { 1836 if (test_bit(BTRFS_DELAYED_NODE_INODE_DIRTY, &delayed_node->flags)) {
1837 fill_stack_inode_item(trans, &delayed_node->inode_item, inode); 1837 fill_stack_inode_item(trans, &delayed_node->inode_item, inode);
1838 goto release_node; 1838 goto release_node;
1839 } 1839 }
1840 1840
1841 ret = btrfs_delayed_inode_reserve_metadata(trans, root, inode, 1841 ret = btrfs_delayed_inode_reserve_metadata(trans, root, inode,
1842 delayed_node); 1842 delayed_node);
1843 if (ret) 1843 if (ret)
1844 goto release_node; 1844 goto release_node;
1845 1845
1846 fill_stack_inode_item(trans, &delayed_node->inode_item, inode); 1846 fill_stack_inode_item(trans, &delayed_node->inode_item, inode);
1847 set_bit(BTRFS_DELAYED_NODE_INODE_DIRTY, &delayed_node->flags); 1847 set_bit(BTRFS_DELAYED_NODE_INODE_DIRTY, &delayed_node->flags);
1848 delayed_node->count++; 1848 delayed_node->count++;
1849 atomic_inc(&root->fs_info->delayed_root->items); 1849 atomic_inc(&root->fs_info->delayed_root->items);
1850 release_node: 1850 release_node:
1851 mutex_unlock(&delayed_node->mutex); 1851 mutex_unlock(&delayed_node->mutex);
1852 btrfs_release_delayed_node(delayed_node); 1852 btrfs_release_delayed_node(delayed_node);
1853 return ret; 1853 return ret;
1854 } 1854 }
1855 1855
1856 int btrfs_delayed_delete_inode_ref(struct inode *inode) 1856 int btrfs_delayed_delete_inode_ref(struct inode *inode)
1857 { 1857 {
1858 struct btrfs_delayed_node *delayed_node; 1858 struct btrfs_delayed_node *delayed_node;
1859 1859
1860 /*
1861 * we don't do delayed inode updates during log recovery because it
1862 * leads to enospc problems. This means we also can't do
1863 * delayed inode refs
1864 */
1865 if (BTRFS_I(inode)->root->fs_info->log_root_recovering)
1866 return -EAGAIN;
1867
1860 delayed_node = btrfs_get_or_create_delayed_node(inode); 1868 delayed_node = btrfs_get_or_create_delayed_node(inode);
1861 if (IS_ERR(delayed_node)) 1869 if (IS_ERR(delayed_node))
1862 return PTR_ERR(delayed_node); 1870 return PTR_ERR(delayed_node);
1863 1871
1864 /* 1872 /*
1865 * We don't reserve space for inode ref deletion is because: 1873 * We don't reserve space for inode ref deletion is because:
1866 * - We ONLY do async inode ref deletion for the inode who has only 1874 * - We ONLY do async inode ref deletion for the inode who has only
1867 * one link(i_nlink == 1), it means there is only one inode ref. 1875 * one link(i_nlink == 1), it means there is only one inode ref.
1868 * And in most case, the inode ref and the inode item are in the 1876 * And in most case, the inode ref and the inode item are in the
1869 * same leaf, and we will deal with them at the same time. 1877 * same leaf, and we will deal with them at the same time.
1870 * Since we are sure we will reserve the space for the inode item, 1878 * Since we are sure we will reserve the space for the inode item,
1871 * it is unnecessary to reserve space for inode ref deletion. 1879 * it is unnecessary to reserve space for inode ref deletion.
1872 * - If the inode ref and the inode item are not in the same leaf, 1880 * - If the inode ref and the inode item are not in the same leaf,
1873 * We also needn't worry about enospc problem, because we reserve 1881 * We also needn't worry about enospc problem, because we reserve
1874 * much more space for the inode update than it needs. 1882 * much more space for the inode update than it needs.
1875 * - At the worst, we can steal some space from the global reservation. 1883 * - At the worst, we can steal some space from the global reservation.
1876 * It is very rare. 1884 * It is very rare.
1877 */ 1885 */
1878 mutex_lock(&delayed_node->mutex); 1886 mutex_lock(&delayed_node->mutex);
1879 if (test_bit(BTRFS_DELAYED_NODE_DEL_IREF, &delayed_node->flags)) 1887 if (test_bit(BTRFS_DELAYED_NODE_DEL_IREF, &delayed_node->flags))
1880 goto release_node; 1888 goto release_node;
1881 1889
1882 set_bit(BTRFS_DELAYED_NODE_DEL_IREF, &delayed_node->flags); 1890 set_bit(BTRFS_DELAYED_NODE_DEL_IREF, &delayed_node->flags);
1883 delayed_node->count++; 1891 delayed_node->count++;
1884 atomic_inc(&BTRFS_I(inode)->root->fs_info->delayed_root->items); 1892 atomic_inc(&BTRFS_I(inode)->root->fs_info->delayed_root->items);
1885 release_node: 1893 release_node:
1886 mutex_unlock(&delayed_node->mutex); 1894 mutex_unlock(&delayed_node->mutex);
1887 btrfs_release_delayed_node(delayed_node); 1895 btrfs_release_delayed_node(delayed_node);
1888 return 0; 1896 return 0;
1889 } 1897 }
1890 1898
1891 static void __btrfs_kill_delayed_node(struct btrfs_delayed_node *delayed_node) 1899 static void __btrfs_kill_delayed_node(struct btrfs_delayed_node *delayed_node)
1892 { 1900 {
1893 struct btrfs_root *root = delayed_node->root; 1901 struct btrfs_root *root = delayed_node->root;
1894 struct btrfs_delayed_item *curr_item, *prev_item; 1902 struct btrfs_delayed_item *curr_item, *prev_item;
1895 1903
1896 mutex_lock(&delayed_node->mutex); 1904 mutex_lock(&delayed_node->mutex);
1897 curr_item = __btrfs_first_delayed_insertion_item(delayed_node); 1905 curr_item = __btrfs_first_delayed_insertion_item(delayed_node);
1898 while (curr_item) { 1906 while (curr_item) {
1899 btrfs_delayed_item_release_metadata(root, curr_item); 1907 btrfs_delayed_item_release_metadata(root, curr_item);
1900 prev_item = curr_item; 1908 prev_item = curr_item;
1901 curr_item = __btrfs_next_delayed_item(prev_item); 1909 curr_item = __btrfs_next_delayed_item(prev_item);
1902 btrfs_release_delayed_item(prev_item); 1910 btrfs_release_delayed_item(prev_item);
1903 } 1911 }
1904 1912
1905 curr_item = __btrfs_first_delayed_deletion_item(delayed_node); 1913 curr_item = __btrfs_first_delayed_deletion_item(delayed_node);
1906 while (curr_item) { 1914 while (curr_item) {
1907 btrfs_delayed_item_release_metadata(root, curr_item); 1915 btrfs_delayed_item_release_metadata(root, curr_item);
1908 prev_item = curr_item; 1916 prev_item = curr_item;
1909 curr_item = __btrfs_next_delayed_item(prev_item); 1917 curr_item = __btrfs_next_delayed_item(prev_item);
1910 btrfs_release_delayed_item(prev_item); 1918 btrfs_release_delayed_item(prev_item);
1911 } 1919 }
1912 1920
1913 if (test_bit(BTRFS_DELAYED_NODE_DEL_IREF, &delayed_node->flags)) 1921 if (test_bit(BTRFS_DELAYED_NODE_DEL_IREF, &delayed_node->flags))
1914 btrfs_release_delayed_iref(delayed_node); 1922 btrfs_release_delayed_iref(delayed_node);
1915 1923
1916 if (test_bit(BTRFS_DELAYED_NODE_INODE_DIRTY, &delayed_node->flags)) { 1924 if (test_bit(BTRFS_DELAYED_NODE_INODE_DIRTY, &delayed_node->flags)) {
1917 btrfs_delayed_inode_release_metadata(root, delayed_node); 1925 btrfs_delayed_inode_release_metadata(root, delayed_node);
1918 btrfs_release_delayed_inode(delayed_node); 1926 btrfs_release_delayed_inode(delayed_node);
1919 } 1927 }
1920 mutex_unlock(&delayed_node->mutex); 1928 mutex_unlock(&delayed_node->mutex);
1921 } 1929 }
1922 1930
1923 void btrfs_kill_delayed_inode_items(struct inode *inode) 1931 void btrfs_kill_delayed_inode_items(struct inode *inode)
1924 { 1932 {
1925 struct btrfs_delayed_node *delayed_node; 1933 struct btrfs_delayed_node *delayed_node;
1926 1934
1927 delayed_node = btrfs_get_delayed_node(inode); 1935 delayed_node = btrfs_get_delayed_node(inode);
1928 if (!delayed_node) 1936 if (!delayed_node)
1929 return; 1937 return;
1930 1938
1931 __btrfs_kill_delayed_node(delayed_node); 1939 __btrfs_kill_delayed_node(delayed_node);
1932 btrfs_release_delayed_node(delayed_node); 1940 btrfs_release_delayed_node(delayed_node);
1933 } 1941 }
1934 1942
1935 void btrfs_kill_all_delayed_nodes(struct btrfs_root *root) 1943 void btrfs_kill_all_delayed_nodes(struct btrfs_root *root)
1936 { 1944 {
1937 u64 inode_id = 0; 1945 u64 inode_id = 0;
1938 struct btrfs_delayed_node *delayed_nodes[8]; 1946 struct btrfs_delayed_node *delayed_nodes[8];
1939 int i, n; 1947 int i, n;
1940 1948
1941 while (1) { 1949 while (1) {
1942 spin_lock(&root->inode_lock); 1950 spin_lock(&root->inode_lock);
1943 n = radix_tree_gang_lookup(&root->delayed_nodes_tree, 1951 n = radix_tree_gang_lookup(&root->delayed_nodes_tree,
1944 (void **)delayed_nodes, inode_id, 1952 (void **)delayed_nodes, inode_id,
1945 ARRAY_SIZE(delayed_nodes)); 1953 ARRAY_SIZE(delayed_nodes));
1946 if (!n) { 1954 if (!n) {
1947 spin_unlock(&root->inode_lock); 1955 spin_unlock(&root->inode_lock);
1948 break; 1956 break;
1949 } 1957 }
1950 1958
1951 inode_id = delayed_nodes[n - 1]->inode_id + 1; 1959 inode_id = delayed_nodes[n - 1]->inode_id + 1;
1952 1960
1953 for (i = 0; i < n; i++) 1961 for (i = 0; i < n; i++)
1954 atomic_inc(&delayed_nodes[i]->refs); 1962 atomic_inc(&delayed_nodes[i]->refs);
1955 spin_unlock(&root->inode_lock); 1963 spin_unlock(&root->inode_lock);
1956 1964
1957 for (i = 0; i < n; i++) { 1965 for (i = 0; i < n; i++) {
1958 __btrfs_kill_delayed_node(delayed_nodes[i]); 1966 __btrfs_kill_delayed_node(delayed_nodes[i]);
1959 btrfs_release_delayed_node(delayed_nodes[i]); 1967 btrfs_release_delayed_node(delayed_nodes[i]);
1960 } 1968 }
1961 } 1969 }
1962 } 1970 }
1963 1971
1964 void btrfs_destroy_delayed_inodes(struct btrfs_root *root) 1972 void btrfs_destroy_delayed_inodes(struct btrfs_root *root)
1965 { 1973 {
1966 struct btrfs_delayed_root *delayed_root; 1974 struct btrfs_delayed_root *delayed_root;
1967 struct btrfs_delayed_node *curr_node, *prev_node; 1975 struct btrfs_delayed_node *curr_node, *prev_node;
1968 1976
1969 delayed_root = btrfs_get_delayed_root(root); 1977 delayed_root = btrfs_get_delayed_root(root);
1970 1978
1971 curr_node = btrfs_first_delayed_node(delayed_root); 1979 curr_node = btrfs_first_delayed_node(delayed_root);
1972 while (curr_node) { 1980 while (curr_node) {
1973 __btrfs_kill_delayed_node(curr_node); 1981 __btrfs_kill_delayed_node(curr_node);
1974 1982
1975 prev_node = curr_node; 1983 prev_node = curr_node;
1976 curr_node = btrfs_next_delayed_node(curr_node); 1984 curr_node = btrfs_next_delayed_node(curr_node);
1977 btrfs_release_delayed_node(prev_node); 1985 btrfs_release_delayed_node(prev_node);
1978 } 1986 }
1979 } 1987 }
1980 1988
1981 1989
fs/btrfs/extent-tree.c
1 /* 1 /*
2 * Copyright (C) 2007 Oracle. All rights reserved. 2 * Copyright (C) 2007 Oracle. All rights reserved.
3 * 3 *
4 * This program is free software; you can redistribute it and/or 4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public 5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation. 6 * License v2 as published by the Free Software Foundation.
7 * 7 *
8 * This program is distributed in the hope that it will be useful, 8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details. 11 * General Public License for more details.
12 * 12 *
13 * You should have received a copy of the GNU General Public 13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the 14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 * Boston, MA 021110-1307, USA. 16 * Boston, MA 021110-1307, USA.
17 */ 17 */
18 #include <linux/sched.h> 18 #include <linux/sched.h>
19 #include <linux/pagemap.h> 19 #include <linux/pagemap.h>
20 #include <linux/writeback.h> 20 #include <linux/writeback.h>
21 #include <linux/blkdev.h> 21 #include <linux/blkdev.h>
22 #include <linux/sort.h> 22 #include <linux/sort.h>
23 #include <linux/rcupdate.h> 23 #include <linux/rcupdate.h>
24 #include <linux/kthread.h> 24 #include <linux/kthread.h>
25 #include <linux/slab.h> 25 #include <linux/slab.h>
26 #include <linux/ratelimit.h> 26 #include <linux/ratelimit.h>
27 #include <linux/percpu_counter.h> 27 #include <linux/percpu_counter.h>
28 #include "hash.h" 28 #include "hash.h"
29 #include "tree-log.h" 29 #include "tree-log.h"
30 #include "disk-io.h" 30 #include "disk-io.h"
31 #include "print-tree.h" 31 #include "print-tree.h"
32 #include "volumes.h" 32 #include "volumes.h"
33 #include "raid56.h" 33 #include "raid56.h"
34 #include "locking.h" 34 #include "locking.h"
35 #include "free-space-cache.h" 35 #include "free-space-cache.h"
36 #include "math.h" 36 #include "math.h"
37 #include "sysfs.h" 37 #include "sysfs.h"
38 #include "qgroup.h" 38 #include "qgroup.h"
39 39
40 #undef SCRAMBLE_DELAYED_REFS 40 #undef SCRAMBLE_DELAYED_REFS
41 41
42 /* 42 /*
43 * control flags for do_chunk_alloc's force field 43 * control flags for do_chunk_alloc's force field
44 * CHUNK_ALLOC_NO_FORCE means to only allocate a chunk 44 * CHUNK_ALLOC_NO_FORCE means to only allocate a chunk
45 * if we really need one. 45 * if we really need one.
46 * 46 *
47 * CHUNK_ALLOC_LIMITED means to only try and allocate one 47 * CHUNK_ALLOC_LIMITED means to only try and allocate one
48 * if we have very few chunks already allocated. This is 48 * if we have very few chunks already allocated. This is
49 * used as part of the clustering code to help make sure 49 * used as part of the clustering code to help make sure
50 * we have a good pool of storage to cluster in, without 50 * we have a good pool of storage to cluster in, without
51 * filling the FS with empty chunks 51 * filling the FS with empty chunks
52 * 52 *
53 * CHUNK_ALLOC_FORCE means it must try to allocate one 53 * CHUNK_ALLOC_FORCE means it must try to allocate one
54 * 54 *
55 */ 55 */
56 enum { 56 enum {
57 CHUNK_ALLOC_NO_FORCE = 0, 57 CHUNK_ALLOC_NO_FORCE = 0,
58 CHUNK_ALLOC_LIMITED = 1, 58 CHUNK_ALLOC_LIMITED = 1,
59 CHUNK_ALLOC_FORCE = 2, 59 CHUNK_ALLOC_FORCE = 2,
60 }; 60 };
61 61
62 /* 62 /*
63 * Control how reservations are dealt with. 63 * Control how reservations are dealt with.
64 * 64 *
65 * RESERVE_FREE - freeing a reservation. 65 * RESERVE_FREE - freeing a reservation.
66 * RESERVE_ALLOC - allocating space and we need to update bytes_may_use for 66 * RESERVE_ALLOC - allocating space and we need to update bytes_may_use for
67 * ENOSPC accounting 67 * ENOSPC accounting
68 * RESERVE_ALLOC_NO_ACCOUNT - allocating space and we should not update 68 * RESERVE_ALLOC_NO_ACCOUNT - allocating space and we should not update
69 * bytes_may_use as the ENOSPC accounting is done elsewhere 69 * bytes_may_use as the ENOSPC accounting is done elsewhere
70 */ 70 */
71 enum { 71 enum {
72 RESERVE_FREE = 0, 72 RESERVE_FREE = 0,
73 RESERVE_ALLOC = 1, 73 RESERVE_ALLOC = 1,
74 RESERVE_ALLOC_NO_ACCOUNT = 2, 74 RESERVE_ALLOC_NO_ACCOUNT = 2,
75 }; 75 };
76 76
77 static int update_block_group(struct btrfs_root *root, 77 static int update_block_group(struct btrfs_root *root,
78 u64 bytenr, u64 num_bytes, int alloc); 78 u64 bytenr, u64 num_bytes, int alloc);
79 static int __btrfs_free_extent(struct btrfs_trans_handle *trans, 79 static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
80 struct btrfs_root *root, 80 struct btrfs_root *root,
81 u64 bytenr, u64 num_bytes, u64 parent, 81 u64 bytenr, u64 num_bytes, u64 parent,
82 u64 root_objectid, u64 owner_objectid, 82 u64 root_objectid, u64 owner_objectid,
83 u64 owner_offset, int refs_to_drop, 83 u64 owner_offset, int refs_to_drop,
84 struct btrfs_delayed_extent_op *extra_op, 84 struct btrfs_delayed_extent_op *extra_op,
85 int no_quota); 85 int no_quota);
86 static void __run_delayed_extent_op(struct btrfs_delayed_extent_op *extent_op, 86 static void __run_delayed_extent_op(struct btrfs_delayed_extent_op *extent_op,
87 struct extent_buffer *leaf, 87 struct extent_buffer *leaf,
88 struct btrfs_extent_item *ei); 88 struct btrfs_extent_item *ei);
89 static int alloc_reserved_file_extent(struct btrfs_trans_handle *trans, 89 static int alloc_reserved_file_extent(struct btrfs_trans_handle *trans,
90 struct btrfs_root *root, 90 struct btrfs_root *root,
91 u64 parent, u64 root_objectid, 91 u64 parent, u64 root_objectid,
92 u64 flags, u64 owner, u64 offset, 92 u64 flags, u64 owner, u64 offset,
93 struct btrfs_key *ins, int ref_mod); 93 struct btrfs_key *ins, int ref_mod);
94 static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans, 94 static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans,
95 struct btrfs_root *root, 95 struct btrfs_root *root,
96 u64 parent, u64 root_objectid, 96 u64 parent, u64 root_objectid,
97 u64 flags, struct btrfs_disk_key *key, 97 u64 flags, struct btrfs_disk_key *key,
98 int level, struct btrfs_key *ins, 98 int level, struct btrfs_key *ins,
99 int no_quota); 99 int no_quota);
100 static int do_chunk_alloc(struct btrfs_trans_handle *trans, 100 static int do_chunk_alloc(struct btrfs_trans_handle *trans,
101 struct btrfs_root *extent_root, u64 flags, 101 struct btrfs_root *extent_root, u64 flags,
102 int force); 102 int force);
103 static int find_next_key(struct btrfs_path *path, int level, 103 static int find_next_key(struct btrfs_path *path, int level,
104 struct btrfs_key *key); 104 struct btrfs_key *key);
105 static void dump_space_info(struct btrfs_space_info *info, u64 bytes, 105 static void dump_space_info(struct btrfs_space_info *info, u64 bytes,
106 int dump_block_groups); 106 int dump_block_groups);
107 static int btrfs_update_reserved_bytes(struct btrfs_block_group_cache *cache, 107 static int btrfs_update_reserved_bytes(struct btrfs_block_group_cache *cache,
108 u64 num_bytes, int reserve, 108 u64 num_bytes, int reserve,
109 int delalloc); 109 int delalloc);
110 static int block_rsv_use_bytes(struct btrfs_block_rsv *block_rsv, 110 static int block_rsv_use_bytes(struct btrfs_block_rsv *block_rsv,
111 u64 num_bytes); 111 u64 num_bytes);
112 int btrfs_pin_extent(struct btrfs_root *root, 112 int btrfs_pin_extent(struct btrfs_root *root,
113 u64 bytenr, u64 num_bytes, int reserved); 113 u64 bytenr, u64 num_bytes, int reserved);
114 114
115 static noinline int 115 static noinline int
116 block_group_cache_done(struct btrfs_block_group_cache *cache) 116 block_group_cache_done(struct btrfs_block_group_cache *cache)
117 { 117 {
118 smp_mb(); 118 smp_mb();
119 return cache->cached == BTRFS_CACHE_FINISHED || 119 return cache->cached == BTRFS_CACHE_FINISHED ||
120 cache->cached == BTRFS_CACHE_ERROR; 120 cache->cached == BTRFS_CACHE_ERROR;
121 } 121 }
122 122
123 static int block_group_bits(struct btrfs_block_group_cache *cache, u64 bits) 123 static int block_group_bits(struct btrfs_block_group_cache *cache, u64 bits)
124 { 124 {
125 return (cache->flags & bits) == bits; 125 return (cache->flags & bits) == bits;
126 } 126 }
127 127
128 static void btrfs_get_block_group(struct btrfs_block_group_cache *cache) 128 static void btrfs_get_block_group(struct btrfs_block_group_cache *cache)
129 { 129 {
130 atomic_inc(&cache->count); 130 atomic_inc(&cache->count);
131 } 131 }
132 132
133 void btrfs_put_block_group(struct btrfs_block_group_cache *cache) 133 void btrfs_put_block_group(struct btrfs_block_group_cache *cache)
134 { 134 {
135 if (atomic_dec_and_test(&cache->count)) { 135 if (atomic_dec_and_test(&cache->count)) {
136 WARN_ON(cache->pinned > 0); 136 WARN_ON(cache->pinned > 0);
137 WARN_ON(cache->reserved > 0); 137 WARN_ON(cache->reserved > 0);
138 kfree(cache->free_space_ctl); 138 kfree(cache->free_space_ctl);
139 kfree(cache); 139 kfree(cache);
140 } 140 }
141 } 141 }
142 142
143 /* 143 /*
144 * this adds the block group to the fs_info rb tree for the block group 144 * this adds the block group to the fs_info rb tree for the block group
145 * cache 145 * cache
146 */ 146 */
147 static int btrfs_add_block_group_cache(struct btrfs_fs_info *info, 147 static int btrfs_add_block_group_cache(struct btrfs_fs_info *info,
148 struct btrfs_block_group_cache *block_group) 148 struct btrfs_block_group_cache *block_group)
149 { 149 {
150 struct rb_node **p; 150 struct rb_node **p;
151 struct rb_node *parent = NULL; 151 struct rb_node *parent = NULL;
152 struct btrfs_block_group_cache *cache; 152 struct btrfs_block_group_cache *cache;
153 153
154 spin_lock(&info->block_group_cache_lock); 154 spin_lock(&info->block_group_cache_lock);
155 p = &info->block_group_cache_tree.rb_node; 155 p = &info->block_group_cache_tree.rb_node;
156 156
157 while (*p) { 157 while (*p) {
158 parent = *p; 158 parent = *p;
159 cache = rb_entry(parent, struct btrfs_block_group_cache, 159 cache = rb_entry(parent, struct btrfs_block_group_cache,
160 cache_node); 160 cache_node);
161 if (block_group->key.objectid < cache->key.objectid) { 161 if (block_group->key.objectid < cache->key.objectid) {
162 p = &(*p)->rb_left; 162 p = &(*p)->rb_left;
163 } else if (block_group->key.objectid > cache->key.objectid) { 163 } else if (block_group->key.objectid > cache->key.objectid) {
164 p = &(*p)->rb_right; 164 p = &(*p)->rb_right;
165 } else { 165 } else {
166 spin_unlock(&info->block_group_cache_lock); 166 spin_unlock(&info->block_group_cache_lock);
167 return -EEXIST; 167 return -EEXIST;
168 } 168 }
169 } 169 }
170 170
171 rb_link_node(&block_group->cache_node, parent, p); 171 rb_link_node(&block_group->cache_node, parent, p);
172 rb_insert_color(&block_group->cache_node, 172 rb_insert_color(&block_group->cache_node,
173 &info->block_group_cache_tree); 173 &info->block_group_cache_tree);
174 174
175 if (info->first_logical_byte > block_group->key.objectid) 175 if (info->first_logical_byte > block_group->key.objectid)
176 info->first_logical_byte = block_group->key.objectid; 176 info->first_logical_byte = block_group->key.objectid;
177 177
178 spin_unlock(&info->block_group_cache_lock); 178 spin_unlock(&info->block_group_cache_lock);
179 179
180 return 0; 180 return 0;
181 } 181 }
182 182
183 /* 183 /*
184 * This will return the block group at or after bytenr if contains is 0, else 184 * This will return the block group at or after bytenr if contains is 0, else
185 * it will return the block group that contains the bytenr 185 * it will return the block group that contains the bytenr
186 */ 186 */
187 static struct btrfs_block_group_cache * 187 static struct btrfs_block_group_cache *
188 block_group_cache_tree_search(struct btrfs_fs_info *info, u64 bytenr, 188 block_group_cache_tree_search(struct btrfs_fs_info *info, u64 bytenr,
189 int contains) 189 int contains)
190 { 190 {
191 struct btrfs_block_group_cache *cache, *ret = NULL; 191 struct btrfs_block_group_cache *cache, *ret = NULL;
192 struct rb_node *n; 192 struct rb_node *n;
193 u64 end, start; 193 u64 end, start;
194 194
195 spin_lock(&info->block_group_cache_lock); 195 spin_lock(&info->block_group_cache_lock);
196 n = info->block_group_cache_tree.rb_node; 196 n = info->block_group_cache_tree.rb_node;
197 197
198 while (n) { 198 while (n) {
199 cache = rb_entry(n, struct btrfs_block_group_cache, 199 cache = rb_entry(n, struct btrfs_block_group_cache,
200 cache_node); 200 cache_node);
201 end = cache->key.objectid + cache->key.offset - 1; 201 end = cache->key.objectid + cache->key.offset - 1;
202 start = cache->key.objectid; 202 start = cache->key.objectid;
203 203
204 if (bytenr < start) { 204 if (bytenr < start) {
205 if (!contains && (!ret || start < ret->key.objectid)) 205 if (!contains && (!ret || start < ret->key.objectid))
206 ret = cache; 206 ret = cache;
207 n = n->rb_left; 207 n = n->rb_left;
208 } else if (bytenr > start) { 208 } else if (bytenr > start) {
209 if (contains && bytenr <= end) { 209 if (contains && bytenr <= end) {
210 ret = cache; 210 ret = cache;
211 break; 211 break;
212 } 212 }
213 n = n->rb_right; 213 n = n->rb_right;
214 } else { 214 } else {
215 ret = cache; 215 ret = cache;
216 break; 216 break;
217 } 217 }
218 } 218 }
219 if (ret) { 219 if (ret) {
220 btrfs_get_block_group(ret); 220 btrfs_get_block_group(ret);
221 if (bytenr == 0 && info->first_logical_byte > ret->key.objectid) 221 if (bytenr == 0 && info->first_logical_byte > ret->key.objectid)
222 info->first_logical_byte = ret->key.objectid; 222 info->first_logical_byte = ret->key.objectid;
223 } 223 }
224 spin_unlock(&info->block_group_cache_lock); 224 spin_unlock(&info->block_group_cache_lock);
225 225
226 return ret; 226 return ret;
227 } 227 }
228 228
229 static int add_excluded_extent(struct btrfs_root *root, 229 static int add_excluded_extent(struct btrfs_root *root,
230 u64 start, u64 num_bytes) 230 u64 start, u64 num_bytes)
231 { 231 {
232 u64 end = start + num_bytes - 1; 232 u64 end = start + num_bytes - 1;
233 set_extent_bits(&root->fs_info->freed_extents[0], 233 set_extent_bits(&root->fs_info->freed_extents[0],
234 start, end, EXTENT_UPTODATE, GFP_NOFS); 234 start, end, EXTENT_UPTODATE, GFP_NOFS);
235 set_extent_bits(&root->fs_info->freed_extents[1], 235 set_extent_bits(&root->fs_info->freed_extents[1],
236 start, end, EXTENT_UPTODATE, GFP_NOFS); 236 start, end, EXTENT_UPTODATE, GFP_NOFS);
237 return 0; 237 return 0;
238 } 238 }
239 239
240 static void free_excluded_extents(struct btrfs_root *root, 240 static void free_excluded_extents(struct btrfs_root *root,
241 struct btrfs_block_group_cache *cache) 241 struct btrfs_block_group_cache *cache)
242 { 242 {
243 u64 start, end; 243 u64 start, end;
244 244
245 start = cache->key.objectid; 245 start = cache->key.objectid;
246 end = start + cache->key.offset - 1; 246 end = start + cache->key.offset - 1;
247 247
248 clear_extent_bits(&root->fs_info->freed_extents[0], 248 clear_extent_bits(&root->fs_info->freed_extents[0],
249 start, end, EXTENT_UPTODATE, GFP_NOFS); 249 start, end, EXTENT_UPTODATE, GFP_NOFS);
250 clear_extent_bits(&root->fs_info->freed_extents[1], 250 clear_extent_bits(&root->fs_info->freed_extents[1],
251 start, end, EXTENT_UPTODATE, GFP_NOFS); 251 start, end, EXTENT_UPTODATE, GFP_NOFS);
252 } 252 }
253 253
254 static int exclude_super_stripes(struct btrfs_root *root, 254 static int exclude_super_stripes(struct btrfs_root *root,
255 struct btrfs_block_group_cache *cache) 255 struct btrfs_block_group_cache *cache)
256 { 256 {
257 u64 bytenr; 257 u64 bytenr;
258 u64 *logical; 258 u64 *logical;
259 int stripe_len; 259 int stripe_len;
260 int i, nr, ret; 260 int i, nr, ret;
261 261
262 if (cache->key.objectid < BTRFS_SUPER_INFO_OFFSET) { 262 if (cache->key.objectid < BTRFS_SUPER_INFO_OFFSET) {
263 stripe_len = BTRFS_SUPER_INFO_OFFSET - cache->key.objectid; 263 stripe_len = BTRFS_SUPER_INFO_OFFSET - cache->key.objectid;
264 cache->bytes_super += stripe_len; 264 cache->bytes_super += stripe_len;
265 ret = add_excluded_extent(root, cache->key.objectid, 265 ret = add_excluded_extent(root, cache->key.objectid,
266 stripe_len); 266 stripe_len);
267 if (ret) 267 if (ret)
268 return ret; 268 return ret;
269 } 269 }
270 270
271 for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) { 271 for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) {
272 bytenr = btrfs_sb_offset(i); 272 bytenr = btrfs_sb_offset(i);
273 ret = btrfs_rmap_block(&root->fs_info->mapping_tree, 273 ret = btrfs_rmap_block(&root->fs_info->mapping_tree,
274 cache->key.objectid, bytenr, 274 cache->key.objectid, bytenr,
275 0, &logical, &nr, &stripe_len); 275 0, &logical, &nr, &stripe_len);
276 if (ret) 276 if (ret)
277 return ret; 277 return ret;
278 278
279 while (nr--) { 279 while (nr--) {
280 u64 start, len; 280 u64 start, len;
281 281
282 if (logical[nr] > cache->key.objectid + 282 if (logical[nr] > cache->key.objectid +
283 cache->key.offset) 283 cache->key.offset)
284 continue; 284 continue;
285 285
286 if (logical[nr] + stripe_len <= cache->key.objectid) 286 if (logical[nr] + stripe_len <= cache->key.objectid)
287 continue; 287 continue;
288 288
289 start = logical[nr]; 289 start = logical[nr];
290 if (start < cache->key.objectid) { 290 if (start < cache->key.objectid) {
291 start = cache->key.objectid; 291 start = cache->key.objectid;
292 len = (logical[nr] + stripe_len) - start; 292 len = (logical[nr] + stripe_len) - start;
293 } else { 293 } else {
294 len = min_t(u64, stripe_len, 294 len = min_t(u64, stripe_len,
295 cache->key.objectid + 295 cache->key.objectid +
296 cache->key.offset - start); 296 cache->key.offset - start);
297 } 297 }
298 298
299 cache->bytes_super += len; 299 cache->bytes_super += len;
300 ret = add_excluded_extent(root, start, len); 300 ret = add_excluded_extent(root, start, len);
301 if (ret) { 301 if (ret) {
302 kfree(logical); 302 kfree(logical);
303 return ret; 303 return ret;
304 } 304 }
305 } 305 }
306 306
307 kfree(logical); 307 kfree(logical);
308 } 308 }
309 return 0; 309 return 0;
310 } 310 }
311 311
312 static struct btrfs_caching_control * 312 static struct btrfs_caching_control *
313 get_caching_control(struct btrfs_block_group_cache *cache) 313 get_caching_control(struct btrfs_block_group_cache *cache)
314 { 314 {
315 struct btrfs_caching_control *ctl; 315 struct btrfs_caching_control *ctl;
316 316
317 spin_lock(&cache->lock); 317 spin_lock(&cache->lock);
318 if (!cache->caching_ctl) { 318 if (!cache->caching_ctl) {
319 spin_unlock(&cache->lock); 319 spin_unlock(&cache->lock);
320 return NULL; 320 return NULL;
321 } 321 }
322 322
323 ctl = cache->caching_ctl; 323 ctl = cache->caching_ctl;
324 atomic_inc(&ctl->count); 324 atomic_inc(&ctl->count);
325 spin_unlock(&cache->lock); 325 spin_unlock(&cache->lock);
326 return ctl; 326 return ctl;
327 } 327 }
328 328
329 static void put_caching_control(struct btrfs_caching_control *ctl) 329 static void put_caching_control(struct btrfs_caching_control *ctl)
330 { 330 {
331 if (atomic_dec_and_test(&ctl->count)) 331 if (atomic_dec_and_test(&ctl->count))
332 kfree(ctl); 332 kfree(ctl);
333 } 333 }
334 334
335 /* 335 /*
336 * this is only called by cache_block_group, since we could have freed extents 336 * this is only called by cache_block_group, since we could have freed extents
337 * we need to check the pinned_extents for any extents that can't be used yet 337 * we need to check the pinned_extents for any extents that can't be used yet
338 * since their free space will be released as soon as the transaction commits. 338 * since their free space will be released as soon as the transaction commits.
339 */ 339 */
340 static u64 add_new_free_space(struct btrfs_block_group_cache *block_group, 340 static u64 add_new_free_space(struct btrfs_block_group_cache *block_group,
341 struct btrfs_fs_info *info, u64 start, u64 end) 341 struct btrfs_fs_info *info, u64 start, u64 end)
342 { 342 {
343 u64 extent_start, extent_end, size, total_added = 0; 343 u64 extent_start, extent_end, size, total_added = 0;
344 int ret; 344 int ret;
345 345
346 while (start < end) { 346 while (start < end) {
347 ret = find_first_extent_bit(info->pinned_extents, start, 347 ret = find_first_extent_bit(info->pinned_extents, start,
348 &extent_start, &extent_end, 348 &extent_start, &extent_end,
349 EXTENT_DIRTY | EXTENT_UPTODATE, 349 EXTENT_DIRTY | EXTENT_UPTODATE,
350 NULL); 350 NULL);
351 if (ret) 351 if (ret)
352 break; 352 break;
353 353
354 if (extent_start <= start) { 354 if (extent_start <= start) {
355 start = extent_end + 1; 355 start = extent_end + 1;
356 } else if (extent_start > start && extent_start < end) { 356 } else if (extent_start > start && extent_start < end) {
357 size = extent_start - start; 357 size = extent_start - start;
358 total_added += size; 358 total_added += size;
359 ret = btrfs_add_free_space(block_group, start, 359 ret = btrfs_add_free_space(block_group, start,
360 size); 360 size);
361 BUG_ON(ret); /* -ENOMEM or logic error */ 361 BUG_ON(ret); /* -ENOMEM or logic error */
362 start = extent_end + 1; 362 start = extent_end + 1;
363 } else { 363 } else {
364 break; 364 break;
365 } 365 }
366 } 366 }
367 367
368 if (start < end) { 368 if (start < end) {
369 size = end - start; 369 size = end - start;
370 total_added += size; 370 total_added += size;
371 ret = btrfs_add_free_space(block_group, start, size); 371 ret = btrfs_add_free_space(block_group, start, size);
372 BUG_ON(ret); /* -ENOMEM or logic error */ 372 BUG_ON(ret); /* -ENOMEM or logic error */
373 } 373 }
374 374
375 return total_added; 375 return total_added;
376 } 376 }
377 377
378 static noinline void caching_thread(struct btrfs_work *work) 378 static noinline void caching_thread(struct btrfs_work *work)
379 { 379 {
380 struct btrfs_block_group_cache *block_group; 380 struct btrfs_block_group_cache *block_group;
381 struct btrfs_fs_info *fs_info; 381 struct btrfs_fs_info *fs_info;
382 struct btrfs_caching_control *caching_ctl; 382 struct btrfs_caching_control *caching_ctl;
383 struct btrfs_root *extent_root; 383 struct btrfs_root *extent_root;
384 struct btrfs_path *path; 384 struct btrfs_path *path;
385 struct extent_buffer *leaf; 385 struct extent_buffer *leaf;
386 struct btrfs_key key; 386 struct btrfs_key key;
387 u64 total_found = 0; 387 u64 total_found = 0;
388 u64 last = 0; 388 u64 last = 0;
389 u32 nritems; 389 u32 nritems;
390 int ret = -ENOMEM; 390 int ret = -ENOMEM;
391 391
392 caching_ctl = container_of(work, struct btrfs_caching_control, work); 392 caching_ctl = container_of(work, struct btrfs_caching_control, work);
393 block_group = caching_ctl->block_group; 393 block_group = caching_ctl->block_group;
394 fs_info = block_group->fs_info; 394 fs_info = block_group->fs_info;
395 extent_root = fs_info->extent_root; 395 extent_root = fs_info->extent_root;
396 396
397 path = btrfs_alloc_path(); 397 path = btrfs_alloc_path();
398 if (!path) 398 if (!path)
399 goto out; 399 goto out;
400 400
401 last = max_t(u64, block_group->key.objectid, BTRFS_SUPER_INFO_OFFSET); 401 last = max_t(u64, block_group->key.objectid, BTRFS_SUPER_INFO_OFFSET);
402 402
403 /* 403 /*
404 * We don't want to deadlock with somebody trying to allocate a new 404 * We don't want to deadlock with somebody trying to allocate a new
405 * extent for the extent root while also trying to search the extent 405 * extent for the extent root while also trying to search the extent
406 * root to add free space. So we skip locking and search the commit 406 * root to add free space. So we skip locking and search the commit
407 * root, since its read-only 407 * root, since its read-only
408 */ 408 */
409 path->skip_locking = 1; 409 path->skip_locking = 1;
410 path->search_commit_root = 1; 410 path->search_commit_root = 1;
411 path->reada = 1; 411 path->reada = 1;
412 412
413 key.objectid = last; 413 key.objectid = last;
414 key.offset = 0; 414 key.offset = 0;
415 key.type = BTRFS_EXTENT_ITEM_KEY; 415 key.type = BTRFS_EXTENT_ITEM_KEY;
416 again: 416 again:
417 mutex_lock(&caching_ctl->mutex); 417 mutex_lock(&caching_ctl->mutex);
418 /* need to make sure the commit_root doesn't disappear */ 418 /* need to make sure the commit_root doesn't disappear */
419 down_read(&fs_info->commit_root_sem); 419 down_read(&fs_info->commit_root_sem);
420 420
421 next: 421 next:
422 ret = btrfs_search_slot(NULL, extent_root, &key, path, 0, 0); 422 ret = btrfs_search_slot(NULL, extent_root, &key, path, 0, 0);
423 if (ret < 0) 423 if (ret < 0)
424 goto err; 424 goto err;
425 425
426 leaf = path->nodes[0]; 426 leaf = path->nodes[0];
427 nritems = btrfs_header_nritems(leaf); 427 nritems = btrfs_header_nritems(leaf);
428 428
429 while (1) { 429 while (1) {
430 if (btrfs_fs_closing(fs_info) > 1) { 430 if (btrfs_fs_closing(fs_info) > 1) {
431 last = (u64)-1; 431 last = (u64)-1;
432 break; 432 break;
433 } 433 }
434 434
435 if (path->slots[0] < nritems) { 435 if (path->slots[0] < nritems) {
436 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); 436 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
437 } else { 437 } else {
438 ret = find_next_key(path, 0, &key); 438 ret = find_next_key(path, 0, &key);
439 if (ret) 439 if (ret)
440 break; 440 break;
441 441
442 if (need_resched() || 442 if (need_resched() ||
443 rwsem_is_contended(&fs_info->commit_root_sem)) { 443 rwsem_is_contended(&fs_info->commit_root_sem)) {
444 caching_ctl->progress = last; 444 caching_ctl->progress = last;
445 btrfs_release_path(path); 445 btrfs_release_path(path);
446 up_read(&fs_info->commit_root_sem); 446 up_read(&fs_info->commit_root_sem);
447 mutex_unlock(&caching_ctl->mutex); 447 mutex_unlock(&caching_ctl->mutex);
448 cond_resched(); 448 cond_resched();
449 goto again; 449 goto again;
450 } 450 }
451 451
452 ret = btrfs_next_leaf(extent_root, path); 452 ret = btrfs_next_leaf(extent_root, path);
453 if (ret < 0) 453 if (ret < 0)
454 goto err; 454 goto err;
455 if (ret) 455 if (ret)
456 break; 456 break;
457 leaf = path->nodes[0]; 457 leaf = path->nodes[0];
458 nritems = btrfs_header_nritems(leaf); 458 nritems = btrfs_header_nritems(leaf);
459 continue; 459 continue;
460 } 460 }
461 461
462 if (key.objectid < last) { 462 if (key.objectid < last) {
463 key.objectid = last; 463 key.objectid = last;
464 key.offset = 0; 464 key.offset = 0;
465 key.type = BTRFS_EXTENT_ITEM_KEY; 465 key.type = BTRFS_EXTENT_ITEM_KEY;
466 466
467 caching_ctl->progress = last; 467 caching_ctl->progress = last;
468 btrfs_release_path(path); 468 btrfs_release_path(path);
469 goto next; 469 goto next;
470 } 470 }
471 471
472 if (key.objectid < block_group->key.objectid) { 472 if (key.objectid < block_group->key.objectid) {
473 path->slots[0]++; 473 path->slots[0]++;
474 continue; 474 continue;
475 } 475 }
476 476
477 if (key.objectid >= block_group->key.objectid + 477 if (key.objectid >= block_group->key.objectid +
478 block_group->key.offset) 478 block_group->key.offset)
479 break; 479 break;
480 480
481 if (key.type == BTRFS_EXTENT_ITEM_KEY || 481 if (key.type == BTRFS_EXTENT_ITEM_KEY ||
482 key.type == BTRFS_METADATA_ITEM_KEY) { 482 key.type == BTRFS_METADATA_ITEM_KEY) {
483 total_found += add_new_free_space(block_group, 483 total_found += add_new_free_space(block_group,
484 fs_info, last, 484 fs_info, last,
485 key.objectid); 485 key.objectid);
486 if (key.type == BTRFS_METADATA_ITEM_KEY) 486 if (key.type == BTRFS_METADATA_ITEM_KEY)
487 last = key.objectid + 487 last = key.objectid +
488 fs_info->tree_root->nodesize; 488 fs_info->tree_root->nodesize;
489 else 489 else
490 last = key.objectid + key.offset; 490 last = key.objectid + key.offset;
491 491
492 if (total_found > (1024 * 1024 * 2)) { 492 if (total_found > (1024 * 1024 * 2)) {
493 total_found = 0; 493 total_found = 0;
494 wake_up(&caching_ctl->wait); 494 wake_up(&caching_ctl->wait);
495 } 495 }
496 } 496 }
497 path->slots[0]++; 497 path->slots[0]++;
498 } 498 }
499 ret = 0; 499 ret = 0;
500 500
501 total_found += add_new_free_space(block_group, fs_info, last, 501 total_found += add_new_free_space(block_group, fs_info, last,
502 block_group->key.objectid + 502 block_group->key.objectid +
503 block_group->key.offset); 503 block_group->key.offset);
504 caching_ctl->progress = (u64)-1; 504 caching_ctl->progress = (u64)-1;
505 505
506 spin_lock(&block_group->lock); 506 spin_lock(&block_group->lock);
507 block_group->caching_ctl = NULL; 507 block_group->caching_ctl = NULL;
508 block_group->cached = BTRFS_CACHE_FINISHED; 508 block_group->cached = BTRFS_CACHE_FINISHED;
509 spin_unlock(&block_group->lock); 509 spin_unlock(&block_group->lock);
510 510
511 err: 511 err:
512 btrfs_free_path(path); 512 btrfs_free_path(path);
513 up_read(&fs_info->commit_root_sem); 513 up_read(&fs_info->commit_root_sem);
514 514
515 free_excluded_extents(extent_root, block_group); 515 free_excluded_extents(extent_root, block_group);
516 516
517 mutex_unlock(&caching_ctl->mutex); 517 mutex_unlock(&caching_ctl->mutex);
518 out: 518 out:
519 if (ret) { 519 if (ret) {
520 spin_lock(&block_group->lock); 520 spin_lock(&block_group->lock);
521 block_group->caching_ctl = NULL; 521 block_group->caching_ctl = NULL;
522 block_group->cached = BTRFS_CACHE_ERROR; 522 block_group->cached = BTRFS_CACHE_ERROR;
523 spin_unlock(&block_group->lock); 523 spin_unlock(&block_group->lock);
524 } 524 }
525 wake_up(&caching_ctl->wait); 525 wake_up(&caching_ctl->wait);
526 526
527 put_caching_control(caching_ctl); 527 put_caching_control(caching_ctl);
528 btrfs_put_block_group(block_group); 528 btrfs_put_block_group(block_group);
529 } 529 }
530 530
531 static int cache_block_group(struct btrfs_block_group_cache *cache, 531 static int cache_block_group(struct btrfs_block_group_cache *cache,
532 int load_cache_only) 532 int load_cache_only)
533 { 533 {
534 DEFINE_WAIT(wait); 534 DEFINE_WAIT(wait);
535 struct btrfs_fs_info *fs_info = cache->fs_info; 535 struct btrfs_fs_info *fs_info = cache->fs_info;
536 struct btrfs_caching_control *caching_ctl; 536 struct btrfs_caching_control *caching_ctl;
537 int ret = 0; 537 int ret = 0;
538 538
539 caching_ctl = kzalloc(sizeof(*caching_ctl), GFP_NOFS); 539 caching_ctl = kzalloc(sizeof(*caching_ctl), GFP_NOFS);
540 if (!caching_ctl) 540 if (!caching_ctl)
541 return -ENOMEM; 541 return -ENOMEM;
542 542
543 INIT_LIST_HEAD(&caching_ctl->list); 543 INIT_LIST_HEAD(&caching_ctl->list);
544 mutex_init(&caching_ctl->mutex); 544 mutex_init(&caching_ctl->mutex);
545 init_waitqueue_head(&caching_ctl->wait); 545 init_waitqueue_head(&caching_ctl->wait);
546 caching_ctl->block_group = cache; 546 caching_ctl->block_group = cache;
547 caching_ctl->progress = cache->key.objectid; 547 caching_ctl->progress = cache->key.objectid;
548 atomic_set(&caching_ctl->count, 1); 548 atomic_set(&caching_ctl->count, 1);
549 btrfs_init_work(&caching_ctl->work, btrfs_cache_helper, 549 btrfs_init_work(&caching_ctl->work, btrfs_cache_helper,
550 caching_thread, NULL, NULL); 550 caching_thread, NULL, NULL);
551 551
552 spin_lock(&cache->lock); 552 spin_lock(&cache->lock);
553 /* 553 /*
554 * This should be a rare occasion, but this could happen I think in the 554 * This should be a rare occasion, but this could happen I think in the
555 * case where one thread starts to load the space cache info, and then 555 * case where one thread starts to load the space cache info, and then
556 * some other thread starts a transaction commit which tries to do an 556 * some other thread starts a transaction commit which tries to do an
557 * allocation while the other thread is still loading the space cache 557 * allocation while the other thread is still loading the space cache
558 * info. The previous loop should have kept us from choosing this block 558 * info. The previous loop should have kept us from choosing this block
559 * group, but if we've moved to the state where we will wait on caching 559 * group, but if we've moved to the state where we will wait on caching
560 * block groups we need to first check if we're doing a fast load here, 560 * block groups we need to first check if we're doing a fast load here,
561 * so we can wait for it to finish, otherwise we could end up allocating 561 * so we can wait for it to finish, otherwise we could end up allocating
562 * from a block group who's cache gets evicted for one reason or 562 * from a block group who's cache gets evicted for one reason or
563 * another. 563 * another.
564 */ 564 */
565 while (cache->cached == BTRFS_CACHE_FAST) { 565 while (cache->cached == BTRFS_CACHE_FAST) {
566 struct btrfs_caching_control *ctl; 566 struct btrfs_caching_control *ctl;
567 567
568 ctl = cache->caching_ctl; 568 ctl = cache->caching_ctl;
569 atomic_inc(&ctl->count); 569 atomic_inc(&ctl->count);
570 prepare_to_wait(&ctl->wait, &wait, TASK_UNINTERRUPTIBLE); 570 prepare_to_wait(&ctl->wait, &wait, TASK_UNINTERRUPTIBLE);
571 spin_unlock(&cache->lock); 571 spin_unlock(&cache->lock);
572 572
573 schedule(); 573 schedule();
574 574
575 finish_wait(&ctl->wait, &wait); 575 finish_wait(&ctl->wait, &wait);
576 put_caching_control(ctl); 576 put_caching_control(ctl);
577 spin_lock(&cache->lock); 577 spin_lock(&cache->lock);
578 } 578 }
579 579
580 if (cache->cached != BTRFS_CACHE_NO) { 580 if (cache->cached != BTRFS_CACHE_NO) {
581 spin_unlock(&cache->lock); 581 spin_unlock(&cache->lock);
582 kfree(caching_ctl); 582 kfree(caching_ctl);
583 return 0; 583 return 0;
584 } 584 }
585 WARN_ON(cache->caching_ctl); 585 WARN_ON(cache->caching_ctl);
586 cache->caching_ctl = caching_ctl; 586 cache->caching_ctl = caching_ctl;
587 cache->cached = BTRFS_CACHE_FAST; 587 cache->cached = BTRFS_CACHE_FAST;
588 spin_unlock(&cache->lock); 588 spin_unlock(&cache->lock);
589 589
590 if (fs_info->mount_opt & BTRFS_MOUNT_SPACE_CACHE) { 590 if (fs_info->mount_opt & BTRFS_MOUNT_SPACE_CACHE) {
591 mutex_lock(&caching_ctl->mutex); 591 mutex_lock(&caching_ctl->mutex);
592 ret = load_free_space_cache(fs_info, cache); 592 ret = load_free_space_cache(fs_info, cache);
593 593
594 spin_lock(&cache->lock); 594 spin_lock(&cache->lock);
595 if (ret == 1) { 595 if (ret == 1) {
596 cache->caching_ctl = NULL; 596 cache->caching_ctl = NULL;
597 cache->cached = BTRFS_CACHE_FINISHED; 597 cache->cached = BTRFS_CACHE_FINISHED;
598 cache->last_byte_to_unpin = (u64)-1; 598 cache->last_byte_to_unpin = (u64)-1;
599 caching_ctl->progress = (u64)-1; 599 caching_ctl->progress = (u64)-1;
600 } else { 600 } else {
601 if (load_cache_only) { 601 if (load_cache_only) {
602 cache->caching_ctl = NULL; 602 cache->caching_ctl = NULL;
603 cache->cached = BTRFS_CACHE_NO; 603 cache->cached = BTRFS_CACHE_NO;
604 } else { 604 } else {
605 cache->cached = BTRFS_CACHE_STARTED; 605 cache->cached = BTRFS_CACHE_STARTED;
606 cache->has_caching_ctl = 1; 606 cache->has_caching_ctl = 1;
607 } 607 }
608 } 608 }
609 spin_unlock(&cache->lock); 609 spin_unlock(&cache->lock);
610 mutex_unlock(&caching_ctl->mutex); 610 mutex_unlock(&caching_ctl->mutex);
611 611
612 wake_up(&caching_ctl->wait); 612 wake_up(&caching_ctl->wait);
613 if (ret == 1) { 613 if (ret == 1) {
614 put_caching_control(caching_ctl); 614 put_caching_control(caching_ctl);
615 free_excluded_extents(fs_info->extent_root, cache); 615 free_excluded_extents(fs_info->extent_root, cache);
616 return 0; 616 return 0;
617 } 617 }
618 } else { 618 } else {
619 /* 619 /*
620 * We are not going to do the fast caching, set cached to the 620 * We are not going to do the fast caching, set cached to the
621 * appropriate value and wakeup any waiters. 621 * appropriate value and wakeup any waiters.
622 */ 622 */
623 spin_lock(&cache->lock); 623 spin_lock(&cache->lock);
624 if (load_cache_only) { 624 if (load_cache_only) {
625 cache->caching_ctl = NULL; 625 cache->caching_ctl = NULL;
626 cache->cached = BTRFS_CACHE_NO; 626 cache->cached = BTRFS_CACHE_NO;
627 } else { 627 } else {
628 cache->cached = BTRFS_CACHE_STARTED; 628 cache->cached = BTRFS_CACHE_STARTED;
629 cache->has_caching_ctl = 1; 629 cache->has_caching_ctl = 1;
630 } 630 }
631 spin_unlock(&cache->lock); 631 spin_unlock(&cache->lock);
632 wake_up(&caching_ctl->wait); 632 wake_up(&caching_ctl->wait);
633 } 633 }
634 634
635 if (load_cache_only) { 635 if (load_cache_only) {
636 put_caching_control(caching_ctl); 636 put_caching_control(caching_ctl);
637 return 0; 637 return 0;
638 } 638 }
639 639
640 down_write(&fs_info->commit_root_sem); 640 down_write(&fs_info->commit_root_sem);
641 atomic_inc(&caching_ctl->count); 641 atomic_inc(&caching_ctl->count);
642 list_add_tail(&caching_ctl->list, &fs_info->caching_block_groups); 642 list_add_tail(&caching_ctl->list, &fs_info->caching_block_groups);
643 up_write(&fs_info->commit_root_sem); 643 up_write(&fs_info->commit_root_sem);
644 644
645 btrfs_get_block_group(cache); 645 btrfs_get_block_group(cache);
646 646
647 btrfs_queue_work(fs_info->caching_workers, &caching_ctl->work); 647 btrfs_queue_work(fs_info->caching_workers, &caching_ctl->work);
648 648
649 return ret; 649 return ret;
650 } 650 }
651 651
652 /* 652 /*
653 * return the block group that starts at or after bytenr 653 * return the block group that starts at or after bytenr
654 */ 654 */
655 static struct btrfs_block_group_cache * 655 static struct btrfs_block_group_cache *
656 btrfs_lookup_first_block_group(struct btrfs_fs_info *info, u64 bytenr) 656 btrfs_lookup_first_block_group(struct btrfs_fs_info *info, u64 bytenr)
657 { 657 {
658 struct btrfs_block_group_cache *cache; 658 struct btrfs_block_group_cache *cache;
659 659
660 cache = block_group_cache_tree_search(info, bytenr, 0); 660 cache = block_group_cache_tree_search(info, bytenr, 0);
661 661
662 return cache; 662 return cache;
663 } 663 }
664 664
665 /* 665 /*
666 * return the block group that contains the given bytenr 666 * return the block group that contains the given bytenr
667 */ 667 */
668 struct btrfs_block_group_cache *btrfs_lookup_block_group( 668 struct btrfs_block_group_cache *btrfs_lookup_block_group(
669 struct btrfs_fs_info *info, 669 struct btrfs_fs_info *info,
670 u64 bytenr) 670 u64 bytenr)
671 { 671 {
672 struct btrfs_block_group_cache *cache; 672 struct btrfs_block_group_cache *cache;
673 673
674 cache = block_group_cache_tree_search(info, bytenr, 1); 674 cache = block_group_cache_tree_search(info, bytenr, 1);
675 675
676 return cache; 676 return cache;
677 } 677 }
678 678
679 static struct btrfs_space_info *__find_space_info(struct btrfs_fs_info *info, 679 static struct btrfs_space_info *__find_space_info(struct btrfs_fs_info *info,
680 u64 flags) 680 u64 flags)
681 { 681 {
682 struct list_head *head = &info->space_info; 682 struct list_head *head = &info->space_info;
683 struct btrfs_space_info *found; 683 struct btrfs_space_info *found;
684 684
685 flags &= BTRFS_BLOCK_GROUP_TYPE_MASK; 685 flags &= BTRFS_BLOCK_GROUP_TYPE_MASK;
686 686
687 rcu_read_lock(); 687 rcu_read_lock();
688 list_for_each_entry_rcu(found, head, list) { 688 list_for_each_entry_rcu(found, head, list) {
689 if (found->flags & flags) { 689 if (found->flags & flags) {
690 rcu_read_unlock(); 690 rcu_read_unlock();
691 return found; 691 return found;
692 } 692 }
693 } 693 }
694 rcu_read_unlock(); 694 rcu_read_unlock();
695 return NULL; 695 return NULL;
696 } 696 }
697 697
698 /* 698 /*
699 * after adding space to the filesystem, we need to clear the full flags 699 * after adding space to the filesystem, we need to clear the full flags
700 * on all the space infos. 700 * on all the space infos.
701 */ 701 */
702 void btrfs_clear_space_info_full(struct btrfs_fs_info *info) 702 void btrfs_clear_space_info_full(struct btrfs_fs_info *info)
703 { 703 {
704 struct list_head *head = &info->space_info; 704 struct list_head *head = &info->space_info;
705 struct btrfs_space_info *found; 705 struct btrfs_space_info *found;
706 706
707 rcu_read_lock(); 707 rcu_read_lock();
708 list_for_each_entry_rcu(found, head, list) 708 list_for_each_entry_rcu(found, head, list)
709 found->full = 0; 709 found->full = 0;
710 rcu_read_unlock(); 710 rcu_read_unlock();
711 } 711 }
712 712
713 /* simple helper to search for an existing data extent at a given offset */ 713 /* simple helper to search for an existing data extent at a given offset */
714 int btrfs_lookup_data_extent(struct btrfs_root *root, u64 start, u64 len) 714 int btrfs_lookup_data_extent(struct btrfs_root *root, u64 start, u64 len)
715 { 715 {
716 int ret; 716 int ret;
717 struct btrfs_key key; 717 struct btrfs_key key;
718 struct btrfs_path *path; 718 struct btrfs_path *path;
719 719
720 path = btrfs_alloc_path(); 720 path = btrfs_alloc_path();
721 if (!path) 721 if (!path)
722 return -ENOMEM; 722 return -ENOMEM;
723 723
724 key.objectid = start; 724 key.objectid = start;
725 key.offset = len; 725 key.offset = len;
726 key.type = BTRFS_EXTENT_ITEM_KEY; 726 key.type = BTRFS_EXTENT_ITEM_KEY;
727 ret = btrfs_search_slot(NULL, root->fs_info->extent_root, &key, path, 727 ret = btrfs_search_slot(NULL, root->fs_info->extent_root, &key, path,
728 0, 0); 728 0, 0);
729 btrfs_free_path(path); 729 btrfs_free_path(path);
730 return ret; 730 return ret;
731 } 731 }
732 732
733 /* 733 /*
734 * helper function to lookup reference count and flags of a tree block. 734 * helper function to lookup reference count and flags of a tree block.
735 * 735 *
736 * the head node for delayed ref is used to store the sum of all the 736 * the head node for delayed ref is used to store the sum of all the
737 * reference count modifications queued up in the rbtree. the head 737 * reference count modifications queued up in the rbtree. the head
738 * node may also store the extent flags to set. This way you can check 738 * node may also store the extent flags to set. This way you can check
739 * to see what the reference count and extent flags would be if all of 739 * to see what the reference count and extent flags would be if all of
740 * the delayed refs are not processed. 740 * the delayed refs are not processed.
741 */ 741 */
742 int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans, 742 int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans,
743 struct btrfs_root *root, u64 bytenr, 743 struct btrfs_root *root, u64 bytenr,
744 u64 offset, int metadata, u64 *refs, u64 *flags) 744 u64 offset, int metadata, u64 *refs, u64 *flags)
745 { 745 {
746 struct btrfs_delayed_ref_head *head; 746 struct btrfs_delayed_ref_head *head;
747 struct btrfs_delayed_ref_root *delayed_refs; 747 struct btrfs_delayed_ref_root *delayed_refs;
748 struct btrfs_path *path; 748 struct btrfs_path *path;
749 struct btrfs_extent_item *ei; 749 struct btrfs_extent_item *ei;
750 struct extent_buffer *leaf; 750 struct extent_buffer *leaf;
751 struct btrfs_key key; 751 struct btrfs_key key;
752 u32 item_size; 752 u32 item_size;
753 u64 num_refs; 753 u64 num_refs;
754 u64 extent_flags; 754 u64 extent_flags;
755 int ret; 755 int ret;
756 756
757 /* 757 /*
758 * If we don't have skinny metadata, don't bother doing anything 758 * If we don't have skinny metadata, don't bother doing anything
759 * different 759 * different
760 */ 760 */
761 if (metadata && !btrfs_fs_incompat(root->fs_info, SKINNY_METADATA)) { 761 if (metadata && !btrfs_fs_incompat(root->fs_info, SKINNY_METADATA)) {
762 offset = root->nodesize; 762 offset = root->nodesize;
763 metadata = 0; 763 metadata = 0;
764 } 764 }
765 765
766 path = btrfs_alloc_path(); 766 path = btrfs_alloc_path();
767 if (!path) 767 if (!path)
768 return -ENOMEM; 768 return -ENOMEM;
769 769
770 if (!trans) { 770 if (!trans) {
771 path->skip_locking = 1; 771 path->skip_locking = 1;
772 path->search_commit_root = 1; 772 path->search_commit_root = 1;
773 } 773 }
774 774
775 search_again: 775 search_again:
776 key.objectid = bytenr; 776 key.objectid = bytenr;
777 key.offset = offset; 777 key.offset = offset;
778 if (metadata) 778 if (metadata)
779 key.type = BTRFS_METADATA_ITEM_KEY; 779 key.type = BTRFS_METADATA_ITEM_KEY;
780 else 780 else
781 key.type = BTRFS_EXTENT_ITEM_KEY; 781 key.type = BTRFS_EXTENT_ITEM_KEY;
782 782
783 ret = btrfs_search_slot(trans, root->fs_info->extent_root, 783 ret = btrfs_search_slot(trans, root->fs_info->extent_root,
784 &key, path, 0, 0); 784 &key, path, 0, 0);
785 if (ret < 0) 785 if (ret < 0)
786 goto out_free; 786 goto out_free;
787 787
788 if (ret > 0 && metadata && key.type == BTRFS_METADATA_ITEM_KEY) { 788 if (ret > 0 && metadata && key.type == BTRFS_METADATA_ITEM_KEY) {
789 if (path->slots[0]) { 789 if (path->slots[0]) {
790 path->slots[0]--; 790 path->slots[0]--;
791 btrfs_item_key_to_cpu(path->nodes[0], &key, 791 btrfs_item_key_to_cpu(path->nodes[0], &key,
792 path->slots[0]); 792 path->slots[0]);
793 if (key.objectid == bytenr && 793 if (key.objectid == bytenr &&
794 key.type == BTRFS_EXTENT_ITEM_KEY && 794 key.type == BTRFS_EXTENT_ITEM_KEY &&
795 key.offset == root->nodesize) 795 key.offset == root->nodesize)
796 ret = 0; 796 ret = 0;
797 } 797 }
798 } 798 }
799 799
800 if (ret == 0) { 800 if (ret == 0) {
801 leaf = path->nodes[0]; 801 leaf = path->nodes[0];
802 item_size = btrfs_item_size_nr(leaf, path->slots[0]); 802 item_size = btrfs_item_size_nr(leaf, path->slots[0]);
803 if (item_size >= sizeof(*ei)) { 803 if (item_size >= sizeof(*ei)) {
804 ei = btrfs_item_ptr(leaf, path->slots[0], 804 ei = btrfs_item_ptr(leaf, path->slots[0],
805 struct btrfs_extent_item); 805 struct btrfs_extent_item);
806 num_refs = btrfs_extent_refs(leaf, ei); 806 num_refs = btrfs_extent_refs(leaf, ei);
807 extent_flags = btrfs_extent_flags(leaf, ei); 807 extent_flags = btrfs_extent_flags(leaf, ei);
808 } else { 808 } else {
809 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0 809 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
810 struct btrfs_extent_item_v0 *ei0; 810 struct btrfs_extent_item_v0 *ei0;
811 BUG_ON(item_size != sizeof(*ei0)); 811 BUG_ON(item_size != sizeof(*ei0));
812 ei0 = btrfs_item_ptr(leaf, path->slots[0], 812 ei0 = btrfs_item_ptr(leaf, path->slots[0],
813 struct btrfs_extent_item_v0); 813 struct btrfs_extent_item_v0);
814 num_refs = btrfs_extent_refs_v0(leaf, ei0); 814 num_refs = btrfs_extent_refs_v0(leaf, ei0);
815 /* FIXME: this isn't correct for data */ 815 /* FIXME: this isn't correct for data */
816 extent_flags = BTRFS_BLOCK_FLAG_FULL_BACKREF; 816 extent_flags = BTRFS_BLOCK_FLAG_FULL_BACKREF;
817 #else 817 #else
818 BUG(); 818 BUG();
819 #endif 819 #endif
820 } 820 }
821 BUG_ON(num_refs == 0); 821 BUG_ON(num_refs == 0);
822 } else { 822 } else {
823 num_refs = 0; 823 num_refs = 0;
824 extent_flags = 0; 824 extent_flags = 0;
825 ret = 0; 825 ret = 0;
826 } 826 }
827 827
828 if (!trans) 828 if (!trans)
829 goto out; 829 goto out;
830 830
831 delayed_refs = &trans->transaction->delayed_refs; 831 delayed_refs = &trans->transaction->delayed_refs;
832 spin_lock(&delayed_refs->lock); 832 spin_lock(&delayed_refs->lock);
833 head = btrfs_find_delayed_ref_head(trans, bytenr); 833 head = btrfs_find_delayed_ref_head(trans, bytenr);
834 if (head) { 834 if (head) {
835 if (!mutex_trylock(&head->mutex)) { 835 if (!mutex_trylock(&head->mutex)) {
836 atomic_inc(&head->node.refs); 836 atomic_inc(&head->node.refs);
837 spin_unlock(&delayed_refs->lock); 837 spin_unlock(&delayed_refs->lock);
838 838
839 btrfs_release_path(path); 839 btrfs_release_path(path);
840 840
841 /* 841 /*
842 * Mutex was contended, block until it's released and try 842 * Mutex was contended, block until it's released and try
843 * again 843 * again
844 */ 844 */
845 mutex_lock(&head->mutex); 845 mutex_lock(&head->mutex);
846 mutex_unlock(&head->mutex); 846 mutex_unlock(&head->mutex);
847 btrfs_put_delayed_ref(&head->node); 847 btrfs_put_delayed_ref(&head->node);
848 goto search_again; 848 goto search_again;
849 } 849 }
850 spin_lock(&head->lock); 850 spin_lock(&head->lock);
851 if (head->extent_op && head->extent_op->update_flags) 851 if (head->extent_op && head->extent_op->update_flags)
852 extent_flags |= head->extent_op->flags_to_set; 852 extent_flags |= head->extent_op->flags_to_set;
853 else 853 else
854 BUG_ON(num_refs == 0); 854 BUG_ON(num_refs == 0);
855 855
856 num_refs += head->node.ref_mod; 856 num_refs += head->node.ref_mod;
857 spin_unlock(&head->lock); 857 spin_unlock(&head->lock);
858 mutex_unlock(&head->mutex); 858 mutex_unlock(&head->mutex);
859 } 859 }
860 spin_unlock(&delayed_refs->lock); 860 spin_unlock(&delayed_refs->lock);
861 out: 861 out:
862 WARN_ON(num_refs == 0); 862 WARN_ON(num_refs == 0);
863 if (refs) 863 if (refs)
864 *refs = num_refs; 864 *refs = num_refs;
865 if (flags) 865 if (flags)
866 *flags = extent_flags; 866 *flags = extent_flags;
867 out_free: 867 out_free:
868 btrfs_free_path(path); 868 btrfs_free_path(path);
869 return ret; 869 return ret;
870 } 870 }
871 871
872 /* 872 /*
873 * Back reference rules. Back refs have three main goals: 873 * Back reference rules. Back refs have three main goals:
874 * 874 *
875 * 1) differentiate between all holders of references to an extent so that 875 * 1) differentiate between all holders of references to an extent so that
876 * when a reference is dropped we can make sure it was a valid reference 876 * when a reference is dropped we can make sure it was a valid reference
877 * before freeing the extent. 877 * before freeing the extent.
878 * 878 *
879 * 2) Provide enough information to quickly find the holders of an extent 879 * 2) Provide enough information to quickly find the holders of an extent
880 * if we notice a given block is corrupted or bad. 880 * if we notice a given block is corrupted or bad.
881 * 881 *
882 * 3) Make it easy to migrate blocks for FS shrinking or storage pool 882 * 3) Make it easy to migrate blocks for FS shrinking or storage pool
883 * maintenance. This is actually the same as #2, but with a slightly 883 * maintenance. This is actually the same as #2, but with a slightly
884 * different use case. 884 * different use case.
885 * 885 *
886 * There are two kinds of back refs. The implicit back refs is optimized 886 * There are two kinds of back refs. The implicit back refs is optimized
887 * for pointers in non-shared tree blocks. For a given pointer in a block, 887 * for pointers in non-shared tree blocks. For a given pointer in a block,
888 * back refs of this kind provide information about the block's owner tree 888 * back refs of this kind provide information about the block's owner tree
889 * and the pointer's key. These information allow us to find the block by 889 * and the pointer's key. These information allow us to find the block by
890 * b-tree searching. The full back refs is for pointers in tree blocks not 890 * b-tree searching. The full back refs is for pointers in tree blocks not
891 * referenced by their owner trees. The location of tree block is recorded 891 * referenced by their owner trees. The location of tree block is recorded
892 * in the back refs. Actually the full back refs is generic, and can be 892 * in the back refs. Actually the full back refs is generic, and can be
893 * used in all cases the implicit back refs is used. The major shortcoming 893 * used in all cases the implicit back refs is used. The major shortcoming
894 * of the full back refs is its overhead. Every time a tree block gets 894 * of the full back refs is its overhead. Every time a tree block gets
895 * COWed, we have to update back refs entry for all pointers in it. 895 * COWed, we have to update back refs entry for all pointers in it.
896 * 896 *
897 * For a newly allocated tree block, we use implicit back refs for 897 * For a newly allocated tree block, we use implicit back refs for
898 * pointers in it. This means most tree related operations only involve 898 * pointers in it. This means most tree related operations only involve
899 * implicit back refs. For a tree block created in old transaction, the 899 * implicit back refs. For a tree block created in old transaction, the
900 * only way to drop a reference to it is COW it. So we can detect the 900 * only way to drop a reference to it is COW it. So we can detect the
901 * event that tree block loses its owner tree's reference and do the 901 * event that tree block loses its owner tree's reference and do the
902 * back refs conversion. 902 * back refs conversion.
903 * 903 *
904 * When a tree block is COW'd through a tree, there are four cases: 904 * When a tree block is COW'd through a tree, there are four cases:
905 * 905 *
906 * The reference count of the block is one and the tree is the block's 906 * The reference count of the block is one and the tree is the block's
907 * owner tree. Nothing to do in this case. 907 * owner tree. Nothing to do in this case.
908 * 908 *
909 * The reference count of the block is one and the tree is not the 909 * The reference count of the block is one and the tree is not the
910 * block's owner tree. In this case, full back refs is used for pointers 910 * block's owner tree. In this case, full back refs is used for pointers
911 * in the block. Remove these full back refs, add implicit back refs for 911 * in the block. Remove these full back refs, add implicit back refs for
912 * every pointers in the new block. 912 * every pointers in the new block.
913 * 913 *
914 * The reference count of the block is greater than one and the tree is 914 * The reference count of the block is greater than one and the tree is
915 * the block's owner tree. In this case, implicit back refs is used for 915 * the block's owner tree. In this case, implicit back refs is used for
916 * pointers in the block. Add full back refs for every pointers in the 916 * pointers in the block. Add full back refs for every pointers in the
917 * block, increase lower level extents' reference counts. The original 917 * block, increase lower level extents' reference counts. The original
918 * implicit back refs are entailed to the new block. 918 * implicit back refs are entailed to the new block.
919 * 919 *
920 * The reference count of the block is greater than one and the tree is 920 * The reference count of the block is greater than one and the tree is
921 * not the block's owner tree. Add implicit back refs for every pointer in 921 * not the block's owner tree. Add implicit back refs for every pointer in
922 * the new block, increase lower level extents' reference count. 922 * the new block, increase lower level extents' reference count.
923 * 923 *
924 * Back Reference Key composing: 924 * Back Reference Key composing:
925 * 925 *
926 * The key objectid corresponds to the first byte in the extent, 926 * The key objectid corresponds to the first byte in the extent,
927 * The key type is used to differentiate between types of back refs. 927 * The key type is used to differentiate between types of back refs.
928 * There are different meanings of the key offset for different types 928 * There are different meanings of the key offset for different types
929 * of back refs. 929 * of back refs.
930 * 930 *
931 * File extents can be referenced by: 931 * File extents can be referenced by:
932 * 932 *
933 * - multiple snapshots, subvolumes, or different generations in one subvol 933 * - multiple snapshots, subvolumes, or different generations in one subvol
934 * - different files inside a single subvolume 934 * - different files inside a single subvolume
935 * - different offsets inside a file (bookend extents in file.c) 935 * - different offsets inside a file (bookend extents in file.c)
936 * 936 *
937 * The extent ref structure for the implicit back refs has fields for: 937 * The extent ref structure for the implicit back refs has fields for:
938 * 938 *
939 * - Objectid of the subvolume root 939 * - Objectid of the subvolume root
940 * - objectid of the file holding the reference 940 * - objectid of the file holding the reference
941 * - original offset in the file 941 * - original offset in the file
942 * - how many bookend extents 942 * - how many bookend extents
943 * 943 *
944 * The key offset for the implicit back refs is hash of the first 944 * The key offset for the implicit back refs is hash of the first
945 * three fields. 945 * three fields.
946 * 946 *
947 * The extent ref structure for the full back refs has field for: 947 * The extent ref structure for the full back refs has field for:
948 * 948 *
949 * - number of pointers in the tree leaf 949 * - number of pointers in the tree leaf
950 * 950 *
951 * The key offset for the implicit back refs is the first byte of 951 * The key offset for the implicit back refs is the first byte of
952 * the tree leaf 952 * the tree leaf
953 * 953 *
954 * When a file extent is allocated, The implicit back refs is used. 954 * When a file extent is allocated, The implicit back refs is used.
955 * the fields are filled in: 955 * the fields are filled in:
956 * 956 *
957 * (root_key.objectid, inode objectid, offset in file, 1) 957 * (root_key.objectid, inode objectid, offset in file, 1)
958 * 958 *
959 * When a file extent is removed file truncation, we find the 959 * When a file extent is removed file truncation, we find the
960 * corresponding implicit back refs and check the following fields: 960 * corresponding implicit back refs and check the following fields:
961 * 961 *
962 * (btrfs_header_owner(leaf), inode objectid, offset in file) 962 * (btrfs_header_owner(leaf), inode objectid, offset in file)
963 * 963 *
964 * Btree extents can be referenced by: 964 * Btree extents can be referenced by:
965 * 965 *
966 * - Different subvolumes 966 * - Different subvolumes
967 * 967 *
968 * Both the implicit back refs and the full back refs for tree blocks 968 * Both the implicit back refs and the full back refs for tree blocks
969 * only consist of key. The key offset for the implicit back refs is 969 * only consist of key. The key offset for the implicit back refs is
970 * objectid of block's owner tree. The key offset for the full back refs 970 * objectid of block's owner tree. The key offset for the full back refs
971 * is the first byte of parent block. 971 * is the first byte of parent block.
972 * 972 *
973 * When implicit back refs is used, information about the lowest key and 973 * When implicit back refs is used, information about the lowest key and
974 * level of the tree block are required. These information are stored in 974 * level of the tree block are required. These information are stored in
975 * tree block info structure. 975 * tree block info structure.
976 */ 976 */
977 977
978 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0 978 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
979 static int convert_extent_item_v0(struct btrfs_trans_handle *trans, 979 static int convert_extent_item_v0(struct btrfs_trans_handle *trans,
980 struct btrfs_root *root, 980 struct btrfs_root *root,
981 struct btrfs_path *path, 981 struct btrfs_path *path,
982 u64 owner, u32 extra_size) 982 u64 owner, u32 extra_size)
983 { 983 {
984 struct btrfs_extent_item *item; 984 struct btrfs_extent_item *item;
985 struct btrfs_extent_item_v0 *ei0; 985 struct btrfs_extent_item_v0 *ei0;
986 struct btrfs_extent_ref_v0 *ref0; 986 struct btrfs_extent_ref_v0 *ref0;
987 struct btrfs_tree_block_info *bi; 987 struct btrfs_tree_block_info *bi;
988 struct extent_buffer *leaf; 988 struct extent_buffer *leaf;
989 struct btrfs_key key; 989 struct btrfs_key key;
990 struct btrfs_key found_key; 990 struct btrfs_key found_key;
991 u32 new_size = sizeof(*item); 991 u32 new_size = sizeof(*item);
992 u64 refs; 992 u64 refs;
993 int ret; 993 int ret;
994 994
995 leaf = path->nodes[0]; 995 leaf = path->nodes[0];
996 BUG_ON(btrfs_item_size_nr(leaf, path->slots[0]) != sizeof(*ei0)); 996 BUG_ON(btrfs_item_size_nr(leaf, path->slots[0]) != sizeof(*ei0));
997 997
998 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); 998 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
999 ei0 = btrfs_item_ptr(leaf, path->slots[0], 999 ei0 = btrfs_item_ptr(leaf, path->slots[0],
1000 struct btrfs_extent_item_v0); 1000 struct btrfs_extent_item_v0);
1001 refs = btrfs_extent_refs_v0(leaf, ei0); 1001 refs = btrfs_extent_refs_v0(leaf, ei0);
1002 1002
1003 if (owner == (u64)-1) { 1003 if (owner == (u64)-1) {
1004 while (1) { 1004 while (1) {
1005 if (path->slots[0] >= btrfs_header_nritems(leaf)) { 1005 if (path->slots[0] >= btrfs_header_nritems(leaf)) {
1006 ret = btrfs_next_leaf(root, path); 1006 ret = btrfs_next_leaf(root, path);
1007 if (ret < 0) 1007 if (ret < 0)
1008 return ret; 1008 return ret;
1009 BUG_ON(ret > 0); /* Corruption */ 1009 BUG_ON(ret > 0); /* Corruption */
1010 leaf = path->nodes[0]; 1010 leaf = path->nodes[0];
1011 } 1011 }
1012 btrfs_item_key_to_cpu(leaf, &found_key, 1012 btrfs_item_key_to_cpu(leaf, &found_key,
1013 path->slots[0]); 1013 path->slots[0]);
1014 BUG_ON(key.objectid != found_key.objectid); 1014 BUG_ON(key.objectid != found_key.objectid);
1015 if (found_key.type != BTRFS_EXTENT_REF_V0_KEY) { 1015 if (found_key.type != BTRFS_EXTENT_REF_V0_KEY) {
1016 path->slots[0]++; 1016 path->slots[0]++;
1017 continue; 1017 continue;
1018 } 1018 }
1019 ref0 = btrfs_item_ptr(leaf, path->slots[0], 1019 ref0 = btrfs_item_ptr(leaf, path->slots[0],
1020 struct btrfs_extent_ref_v0); 1020 struct btrfs_extent_ref_v0);
1021 owner = btrfs_ref_objectid_v0(leaf, ref0); 1021 owner = btrfs_ref_objectid_v0(leaf, ref0);
1022 break; 1022 break;
1023 } 1023 }
1024 } 1024 }
1025 btrfs_release_path(path); 1025 btrfs_release_path(path);
1026 1026
1027 if (owner < BTRFS_FIRST_FREE_OBJECTID) 1027 if (owner < BTRFS_FIRST_FREE_OBJECTID)
1028 new_size += sizeof(*bi); 1028 new_size += sizeof(*bi);
1029 1029
1030 new_size -= sizeof(*ei0); 1030 new_size -= sizeof(*ei0);
1031 ret = btrfs_search_slot(trans, root, &key, path, 1031 ret = btrfs_search_slot(trans, root, &key, path,
1032 new_size + extra_size, 1); 1032 new_size + extra_size, 1);
1033 if (ret < 0) 1033 if (ret < 0)
1034 return ret; 1034 return ret;
1035 BUG_ON(ret); /* Corruption */ 1035 BUG_ON(ret); /* Corruption */
1036 1036
1037 btrfs_extend_item(root, path, new_size); 1037 btrfs_extend_item(root, path, new_size);
1038 1038
1039 leaf = path->nodes[0]; 1039 leaf = path->nodes[0];
1040 item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_extent_item); 1040 item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_extent_item);
1041 btrfs_set_extent_refs(leaf, item, refs); 1041 btrfs_set_extent_refs(leaf, item, refs);
1042 /* FIXME: get real generation */ 1042 /* FIXME: get real generation */
1043 btrfs_set_extent_generation(leaf, item, 0); 1043 btrfs_set_extent_generation(leaf, item, 0);
1044 if (owner < BTRFS_FIRST_FREE_OBJECTID) { 1044 if (owner < BTRFS_FIRST_FREE_OBJECTID) {
1045 btrfs_set_extent_flags(leaf, item, 1045 btrfs_set_extent_flags(leaf, item,
1046 BTRFS_EXTENT_FLAG_TREE_BLOCK | 1046 BTRFS_EXTENT_FLAG_TREE_BLOCK |
1047 BTRFS_BLOCK_FLAG_FULL_BACKREF); 1047 BTRFS_BLOCK_FLAG_FULL_BACKREF);
1048 bi = (struct btrfs_tree_block_info *)(item + 1); 1048 bi = (struct btrfs_tree_block_info *)(item + 1);
1049 /* FIXME: get first key of the block */ 1049 /* FIXME: get first key of the block */
1050 memset_extent_buffer(leaf, 0, (unsigned long)bi, sizeof(*bi)); 1050 memset_extent_buffer(leaf, 0, (unsigned long)bi, sizeof(*bi));
1051 btrfs_set_tree_block_level(leaf, bi, (int)owner); 1051 btrfs_set_tree_block_level(leaf, bi, (int)owner);
1052 } else { 1052 } else {
1053 btrfs_set_extent_flags(leaf, item, BTRFS_EXTENT_FLAG_DATA); 1053 btrfs_set_extent_flags(leaf, item, BTRFS_EXTENT_FLAG_DATA);
1054 } 1054 }
1055 btrfs_mark_buffer_dirty(leaf); 1055 btrfs_mark_buffer_dirty(leaf);
1056 return 0; 1056 return 0;
1057 } 1057 }
1058 #endif 1058 #endif
1059 1059
1060 static u64 hash_extent_data_ref(u64 root_objectid, u64 owner, u64 offset) 1060 static u64 hash_extent_data_ref(u64 root_objectid, u64 owner, u64 offset)
1061 { 1061 {
1062 u32 high_crc = ~(u32)0; 1062 u32 high_crc = ~(u32)0;
1063 u32 low_crc = ~(u32)0; 1063 u32 low_crc = ~(u32)0;
1064 __le64 lenum; 1064 __le64 lenum;
1065 1065
1066 lenum = cpu_to_le64(root_objectid); 1066 lenum = cpu_to_le64(root_objectid);
1067 high_crc = btrfs_crc32c(high_crc, &lenum, sizeof(lenum)); 1067 high_crc = btrfs_crc32c(high_crc, &lenum, sizeof(lenum));
1068 lenum = cpu_to_le64(owner); 1068 lenum = cpu_to_le64(owner);
1069 low_crc = btrfs_crc32c(low_crc, &lenum, sizeof(lenum)); 1069 low_crc = btrfs_crc32c(low_crc, &lenum, sizeof(lenum));
1070 lenum = cpu_to_le64(offset); 1070 lenum = cpu_to_le64(offset);
1071 low_crc = btrfs_crc32c(low_crc, &lenum, sizeof(lenum)); 1071 low_crc = btrfs_crc32c(low_crc, &lenum, sizeof(lenum));
1072 1072
1073 return ((u64)high_crc << 31) ^ (u64)low_crc; 1073 return ((u64)high_crc << 31) ^ (u64)low_crc;
1074 } 1074 }
1075 1075
1076 static u64 hash_extent_data_ref_item(struct extent_buffer *leaf, 1076 static u64 hash_extent_data_ref_item(struct extent_buffer *leaf,
1077 struct btrfs_extent_data_ref *ref) 1077 struct btrfs_extent_data_ref *ref)
1078 { 1078 {
1079 return hash_extent_data_ref(btrfs_extent_data_ref_root(leaf, ref), 1079 return hash_extent_data_ref(btrfs_extent_data_ref_root(leaf, ref),
1080 btrfs_extent_data_ref_objectid(leaf, ref), 1080 btrfs_extent_data_ref_objectid(leaf, ref),
1081 btrfs_extent_data_ref_offset(leaf, ref)); 1081 btrfs_extent_data_ref_offset(leaf, ref));
1082 } 1082 }
1083 1083
1084 static int match_extent_data_ref(struct extent_buffer *leaf, 1084 static int match_extent_data_ref(struct extent_buffer *leaf,
1085 struct btrfs_extent_data_ref *ref, 1085 struct btrfs_extent_data_ref *ref,
1086 u64 root_objectid, u64 owner, u64 offset) 1086 u64 root_objectid, u64 owner, u64 offset)
1087 { 1087 {
1088 if (btrfs_extent_data_ref_root(leaf, ref) != root_objectid || 1088 if (btrfs_extent_data_ref_root(leaf, ref) != root_objectid ||
1089 btrfs_extent_data_ref_objectid(leaf, ref) != owner || 1089 btrfs_extent_data_ref_objectid(leaf, ref) != owner ||
1090 btrfs_extent_data_ref_offset(leaf, ref) != offset) 1090 btrfs_extent_data_ref_offset(leaf, ref) != offset)
1091 return 0; 1091 return 0;
1092 return 1; 1092 return 1;
1093 } 1093 }
1094 1094
1095 static noinline int lookup_extent_data_ref(struct btrfs_trans_handle *trans, 1095 static noinline int lookup_extent_data_ref(struct btrfs_trans_handle *trans,
1096 struct btrfs_root *root, 1096 struct btrfs_root *root,
1097 struct btrfs_path *path, 1097 struct btrfs_path *path,
1098 u64 bytenr, u64 parent, 1098 u64 bytenr, u64 parent,
1099 u64 root_objectid, 1099 u64 root_objectid,
1100 u64 owner, u64 offset) 1100 u64 owner, u64 offset)
1101 { 1101 {
1102 struct btrfs_key key; 1102 struct btrfs_key key;
1103 struct btrfs_extent_data_ref *ref; 1103 struct btrfs_extent_data_ref *ref;
1104 struct extent_buffer *leaf; 1104 struct extent_buffer *leaf;
1105 u32 nritems; 1105 u32 nritems;
1106 int ret; 1106 int ret;
1107 int recow; 1107 int recow;
1108 int err = -ENOENT; 1108 int err = -ENOENT;
1109 1109
1110 key.objectid = bytenr; 1110 key.objectid = bytenr;
1111 if (parent) { 1111 if (parent) {
1112 key.type = BTRFS_SHARED_DATA_REF_KEY; 1112 key.type = BTRFS_SHARED_DATA_REF_KEY;
1113 key.offset = parent; 1113 key.offset = parent;
1114 } else { 1114 } else {
1115 key.type = BTRFS_EXTENT_DATA_REF_KEY; 1115 key.type = BTRFS_EXTENT_DATA_REF_KEY;
1116 key.offset = hash_extent_data_ref(root_objectid, 1116 key.offset = hash_extent_data_ref(root_objectid,
1117 owner, offset); 1117 owner, offset);
1118 } 1118 }
1119 again: 1119 again:
1120 recow = 0; 1120 recow = 0;
1121 ret = btrfs_search_slot(trans, root, &key, path, -1, 1); 1121 ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
1122 if (ret < 0) { 1122 if (ret < 0) {
1123 err = ret; 1123 err = ret;
1124 goto fail; 1124 goto fail;
1125 } 1125 }
1126 1126
1127 if (parent) { 1127 if (parent) {
1128 if (!ret) 1128 if (!ret)
1129 return 0; 1129 return 0;
1130 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0 1130 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
1131 key.type = BTRFS_EXTENT_REF_V0_KEY; 1131 key.type = BTRFS_EXTENT_REF_V0_KEY;
1132 btrfs_release_path(path); 1132 btrfs_release_path(path);
1133 ret = btrfs_search_slot(trans, root, &key, path, -1, 1); 1133 ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
1134 if (ret < 0) { 1134 if (ret < 0) {
1135 err = ret; 1135 err = ret;
1136 goto fail; 1136 goto fail;
1137 } 1137 }
1138 if (!ret) 1138 if (!ret)
1139 return 0; 1139 return 0;
1140 #endif 1140 #endif
1141 goto fail; 1141 goto fail;
1142 } 1142 }
1143 1143
1144 leaf = path->nodes[0]; 1144 leaf = path->nodes[0];
1145 nritems = btrfs_header_nritems(leaf); 1145 nritems = btrfs_header_nritems(leaf);
1146 while (1) { 1146 while (1) {
1147 if (path->slots[0] >= nritems) { 1147 if (path->slots[0] >= nritems) {
1148 ret = btrfs_next_leaf(root, path); 1148 ret = btrfs_next_leaf(root, path);
1149 if (ret < 0) 1149 if (ret < 0)
1150 err = ret; 1150 err = ret;
1151 if (ret) 1151 if (ret)
1152 goto fail; 1152 goto fail;
1153 1153
1154 leaf = path->nodes[0]; 1154 leaf = path->nodes[0];
1155 nritems = btrfs_header_nritems(leaf); 1155 nritems = btrfs_header_nritems(leaf);
1156 recow = 1; 1156 recow = 1;
1157 } 1157 }
1158 1158
1159 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); 1159 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
1160 if (key.objectid != bytenr || 1160 if (key.objectid != bytenr ||
1161 key.type != BTRFS_EXTENT_DATA_REF_KEY) 1161 key.type != BTRFS_EXTENT_DATA_REF_KEY)
1162 goto fail; 1162 goto fail;
1163 1163
1164 ref = btrfs_item_ptr(leaf, path->slots[0], 1164 ref = btrfs_item_ptr(leaf, path->slots[0],
1165 struct btrfs_extent_data_ref); 1165 struct btrfs_extent_data_ref);
1166 1166
1167 if (match_extent_data_ref(leaf, ref, root_objectid, 1167 if (match_extent_data_ref(leaf, ref, root_objectid,
1168 owner, offset)) { 1168 owner, offset)) {
1169 if (recow) { 1169 if (recow) {
1170 btrfs_release_path(path); 1170 btrfs_release_path(path);
1171 goto again; 1171 goto again;
1172 } 1172 }
1173 err = 0; 1173 err = 0;
1174 break; 1174 break;
1175 } 1175 }
1176 path->slots[0]++; 1176 path->slots[0]++;
1177 } 1177 }
1178 fail: 1178 fail:
1179 return err; 1179 return err;
1180 } 1180 }
1181 1181
1182 static noinline int insert_extent_data_ref(struct btrfs_trans_handle *trans, 1182 static noinline int insert_extent_data_ref(struct btrfs_trans_handle *trans,
1183 struct btrfs_root *root, 1183 struct btrfs_root *root,
1184 struct btrfs_path *path, 1184 struct btrfs_path *path,
1185 u64 bytenr, u64 parent, 1185 u64 bytenr, u64 parent,
1186 u64 root_objectid, u64 owner, 1186 u64 root_objectid, u64 owner,
1187 u64 offset, int refs_to_add) 1187 u64 offset, int refs_to_add)
1188 { 1188 {
1189 struct btrfs_key key; 1189 struct btrfs_key key;
1190 struct extent_buffer *leaf; 1190 struct extent_buffer *leaf;
1191 u32 size; 1191 u32 size;
1192 u32 num_refs; 1192 u32 num_refs;
1193 int ret; 1193 int ret;
1194 1194
1195 key.objectid = bytenr; 1195 key.objectid = bytenr;
1196 if (parent) { 1196 if (parent) {
1197 key.type = BTRFS_SHARED_DATA_REF_KEY; 1197 key.type = BTRFS_SHARED_DATA_REF_KEY;
1198 key.offset = parent; 1198 key.offset = parent;
1199 size = sizeof(struct btrfs_shared_data_ref); 1199 size = sizeof(struct btrfs_shared_data_ref);
1200 } else { 1200 } else {
1201 key.type = BTRFS_EXTENT_DATA_REF_KEY; 1201 key.type = BTRFS_EXTENT_DATA_REF_KEY;
1202 key.offset = hash_extent_data_ref(root_objectid, 1202 key.offset = hash_extent_data_ref(root_objectid,
1203 owner, offset); 1203 owner, offset);
1204 size = sizeof(struct btrfs_extent_data_ref); 1204 size = sizeof(struct btrfs_extent_data_ref);
1205 } 1205 }
1206 1206
1207 ret = btrfs_insert_empty_item(trans, root, path, &key, size); 1207 ret = btrfs_insert_empty_item(trans, root, path, &key, size);
1208 if (ret && ret != -EEXIST) 1208 if (ret && ret != -EEXIST)
1209 goto fail; 1209 goto fail;
1210 1210
1211 leaf = path->nodes[0]; 1211 leaf = path->nodes[0];
1212 if (parent) { 1212 if (parent) {
1213 struct btrfs_shared_data_ref *ref; 1213 struct btrfs_shared_data_ref *ref;
1214 ref = btrfs_item_ptr(leaf, path->slots[0], 1214 ref = btrfs_item_ptr(leaf, path->slots[0],
1215 struct btrfs_shared_data_ref); 1215 struct btrfs_shared_data_ref);
1216 if (ret == 0) { 1216 if (ret == 0) {
1217 btrfs_set_shared_data_ref_count(leaf, ref, refs_to_add); 1217 btrfs_set_shared_data_ref_count(leaf, ref, refs_to_add);
1218 } else { 1218 } else {
1219 num_refs = btrfs_shared_data_ref_count(leaf, ref); 1219 num_refs = btrfs_shared_data_ref_count(leaf, ref);
1220 num_refs += refs_to_add; 1220 num_refs += refs_to_add;
1221 btrfs_set_shared_data_ref_count(leaf, ref, num_refs); 1221 btrfs_set_shared_data_ref_count(leaf, ref, num_refs);
1222 } 1222 }
1223 } else { 1223 } else {
1224 struct btrfs_extent_data_ref *ref; 1224 struct btrfs_extent_data_ref *ref;
1225 while (ret == -EEXIST) { 1225 while (ret == -EEXIST) {
1226 ref = btrfs_item_ptr(leaf, path->slots[0], 1226 ref = btrfs_item_ptr(leaf, path->slots[0],
1227 struct btrfs_extent_data_ref); 1227 struct btrfs_extent_data_ref);
1228 if (match_extent_data_ref(leaf, ref, root_objectid, 1228 if (match_extent_data_ref(leaf, ref, root_objectid,
1229 owner, offset)) 1229 owner, offset))
1230 break; 1230 break;
1231 btrfs_release_path(path); 1231 btrfs_release_path(path);
1232 key.offset++; 1232 key.offset++;
1233 ret = btrfs_insert_empty_item(trans, root, path, &key, 1233 ret = btrfs_insert_empty_item(trans, root, path, &key,
1234 size); 1234 size);
1235 if (ret && ret != -EEXIST) 1235 if (ret && ret != -EEXIST)
1236 goto fail; 1236 goto fail;
1237 1237
1238 leaf = path->nodes[0]; 1238 leaf = path->nodes[0];
1239 } 1239 }
1240 ref = btrfs_item_ptr(leaf, path->slots[0], 1240 ref = btrfs_item_ptr(leaf, path->slots[0],
1241 struct btrfs_extent_data_ref); 1241 struct btrfs_extent_data_ref);
1242 if (ret == 0) { 1242 if (ret == 0) {
1243 btrfs_set_extent_data_ref_root(leaf, ref, 1243 btrfs_set_extent_data_ref_root(leaf, ref,
1244 root_objectid); 1244 root_objectid);
1245 btrfs_set_extent_data_ref_objectid(leaf, ref, owner); 1245 btrfs_set_extent_data_ref_objectid(leaf, ref, owner);
1246 btrfs_set_extent_data_ref_offset(leaf, ref, offset); 1246 btrfs_set_extent_data_ref_offset(leaf, ref, offset);
1247 btrfs_set_extent_data_ref_count(leaf, ref, refs_to_add); 1247 btrfs_set_extent_data_ref_count(leaf, ref, refs_to_add);
1248 } else { 1248 } else {
1249 num_refs = btrfs_extent_data_ref_count(leaf, ref); 1249 num_refs = btrfs_extent_data_ref_count(leaf, ref);
1250 num_refs += refs_to_add; 1250 num_refs += refs_to_add;
1251 btrfs_set_extent_data_ref_count(leaf, ref, num_refs); 1251 btrfs_set_extent_data_ref_count(leaf, ref, num_refs);
1252 } 1252 }
1253 } 1253 }
1254 btrfs_mark_buffer_dirty(leaf); 1254 btrfs_mark_buffer_dirty(leaf);
1255 ret = 0; 1255 ret = 0;
1256 fail: 1256 fail:
1257 btrfs_release_path(path); 1257 btrfs_release_path(path);
1258 return ret; 1258 return ret;
1259 } 1259 }
1260 1260
1261 static noinline int remove_extent_data_ref(struct btrfs_trans_handle *trans, 1261 static noinline int remove_extent_data_ref(struct btrfs_trans_handle *trans,
1262 struct btrfs_root *root, 1262 struct btrfs_root *root,
1263 struct btrfs_path *path, 1263 struct btrfs_path *path,
1264 int refs_to_drop, int *last_ref) 1264 int refs_to_drop, int *last_ref)
1265 { 1265 {
1266 struct btrfs_key key; 1266 struct btrfs_key key;
1267 struct btrfs_extent_data_ref *ref1 = NULL; 1267 struct btrfs_extent_data_ref *ref1 = NULL;
1268 struct btrfs_shared_data_ref *ref2 = NULL; 1268 struct btrfs_shared_data_ref *ref2 = NULL;
1269 struct extent_buffer *leaf; 1269 struct extent_buffer *leaf;
1270 u32 num_refs = 0; 1270 u32 num_refs = 0;
1271 int ret = 0; 1271 int ret = 0;
1272 1272
1273 leaf = path->nodes[0]; 1273 leaf = path->nodes[0];
1274 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); 1274 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
1275 1275
1276 if (key.type == BTRFS_EXTENT_DATA_REF_KEY) { 1276 if (key.type == BTRFS_EXTENT_DATA_REF_KEY) {
1277 ref1 = btrfs_item_ptr(leaf, path->slots[0], 1277 ref1 = btrfs_item_ptr(leaf, path->slots[0],
1278 struct btrfs_extent_data_ref); 1278 struct btrfs_extent_data_ref);
1279 num_refs = btrfs_extent_data_ref_count(leaf, ref1); 1279 num_refs = btrfs_extent_data_ref_count(leaf, ref1);
1280 } else if (key.type == BTRFS_SHARED_DATA_REF_KEY) { 1280 } else if (key.type == BTRFS_SHARED_DATA_REF_KEY) {
1281 ref2 = btrfs_item_ptr(leaf, path->slots[0], 1281 ref2 = btrfs_item_ptr(leaf, path->slots[0],
1282 struct btrfs_shared_data_ref); 1282 struct btrfs_shared_data_ref);
1283 num_refs = btrfs_shared_data_ref_count(leaf, ref2); 1283 num_refs = btrfs_shared_data_ref_count(leaf, ref2);
1284 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0 1284 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
1285 } else if (key.type == BTRFS_EXTENT_REF_V0_KEY) { 1285 } else if (key.type == BTRFS_EXTENT_REF_V0_KEY) {
1286 struct btrfs_extent_ref_v0 *ref0; 1286 struct btrfs_extent_ref_v0 *ref0;
1287 ref0 = btrfs_item_ptr(leaf, path->slots[0], 1287 ref0 = btrfs_item_ptr(leaf, path->slots[0],
1288 struct btrfs_extent_ref_v0); 1288 struct btrfs_extent_ref_v0);
1289 num_refs = btrfs_ref_count_v0(leaf, ref0); 1289 num_refs = btrfs_ref_count_v0(leaf, ref0);
1290 #endif 1290 #endif
1291 } else { 1291 } else {
1292 BUG(); 1292 BUG();
1293 } 1293 }
1294 1294
1295 BUG_ON(num_refs < refs_to_drop); 1295 BUG_ON(num_refs < refs_to_drop);
1296 num_refs -= refs_to_drop; 1296 num_refs -= refs_to_drop;
1297 1297
1298 if (num_refs == 0) { 1298 if (num_refs == 0) {
1299 ret = btrfs_del_item(trans, root, path); 1299 ret = btrfs_del_item(trans, root, path);
1300 *last_ref = 1; 1300 *last_ref = 1;
1301 } else { 1301 } else {
1302 if (key.type == BTRFS_EXTENT_DATA_REF_KEY) 1302 if (key.type == BTRFS_EXTENT_DATA_REF_KEY)
1303 btrfs_set_extent_data_ref_count(leaf, ref1, num_refs); 1303 btrfs_set_extent_data_ref_count(leaf, ref1, num_refs);
1304 else if (key.type == BTRFS_SHARED_DATA_REF_KEY) 1304 else if (key.type == BTRFS_SHARED_DATA_REF_KEY)
1305 btrfs_set_shared_data_ref_count(leaf, ref2, num_refs); 1305 btrfs_set_shared_data_ref_count(leaf, ref2, num_refs);
1306 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0 1306 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
1307 else { 1307 else {
1308 struct btrfs_extent_ref_v0 *ref0; 1308 struct btrfs_extent_ref_v0 *ref0;
1309 ref0 = btrfs_item_ptr(leaf, path->slots[0], 1309 ref0 = btrfs_item_ptr(leaf, path->slots[0],
1310 struct btrfs_extent_ref_v0); 1310 struct btrfs_extent_ref_v0);
1311 btrfs_set_ref_count_v0(leaf, ref0, num_refs); 1311 btrfs_set_ref_count_v0(leaf, ref0, num_refs);
1312 } 1312 }
1313 #endif 1313 #endif
1314 btrfs_mark_buffer_dirty(leaf); 1314 btrfs_mark_buffer_dirty(leaf);
1315 } 1315 }
1316 return ret; 1316 return ret;
1317 } 1317 }
1318 1318
1319 static noinline u32 extent_data_ref_count(struct btrfs_root *root, 1319 static noinline u32 extent_data_ref_count(struct btrfs_root *root,
1320 struct btrfs_path *path, 1320 struct btrfs_path *path,
1321 struct btrfs_extent_inline_ref *iref) 1321 struct btrfs_extent_inline_ref *iref)
1322 { 1322 {
1323 struct btrfs_key key; 1323 struct btrfs_key key;
1324 struct extent_buffer *leaf; 1324 struct extent_buffer *leaf;
1325 struct btrfs_extent_data_ref *ref1; 1325 struct btrfs_extent_data_ref *ref1;
1326 struct btrfs_shared_data_ref *ref2; 1326 struct btrfs_shared_data_ref *ref2;
1327 u32 num_refs = 0; 1327 u32 num_refs = 0;
1328 1328
1329 leaf = path->nodes[0]; 1329 leaf = path->nodes[0];
1330 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); 1330 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
1331 if (iref) { 1331 if (iref) {
1332 if (btrfs_extent_inline_ref_type(leaf, iref) == 1332 if (btrfs_extent_inline_ref_type(leaf, iref) ==
1333 BTRFS_EXTENT_DATA_REF_KEY) { 1333 BTRFS_EXTENT_DATA_REF_KEY) {
1334 ref1 = (struct btrfs_extent_data_ref *)(&iref->offset); 1334 ref1 = (struct btrfs_extent_data_ref *)(&iref->offset);
1335 num_refs = btrfs_extent_data_ref_count(leaf, ref1); 1335 num_refs = btrfs_extent_data_ref_count(leaf, ref1);
1336 } else { 1336 } else {
1337 ref2 = (struct btrfs_shared_data_ref *)(iref + 1); 1337 ref2 = (struct btrfs_shared_data_ref *)(iref + 1);
1338 num_refs = btrfs_shared_data_ref_count(leaf, ref2); 1338 num_refs = btrfs_shared_data_ref_count(leaf, ref2);
1339 } 1339 }
1340 } else if (key.type == BTRFS_EXTENT_DATA_REF_KEY) { 1340 } else if (key.type == BTRFS_EXTENT_DATA_REF_KEY) {
1341 ref1 = btrfs_item_ptr(leaf, path->slots[0], 1341 ref1 = btrfs_item_ptr(leaf, path->slots[0],
1342 struct btrfs_extent_data_ref); 1342 struct btrfs_extent_data_ref);
1343 num_refs = btrfs_extent_data_ref_count(leaf, ref1); 1343 num_refs = btrfs_extent_data_ref_count(leaf, ref1);
1344 } else if (key.type == BTRFS_SHARED_DATA_REF_KEY) { 1344 } else if (key.type == BTRFS_SHARED_DATA_REF_KEY) {
1345 ref2 = btrfs_item_ptr(leaf, path->slots[0], 1345 ref2 = btrfs_item_ptr(leaf, path->slots[0],
1346 struct btrfs_shared_data_ref); 1346 struct btrfs_shared_data_ref);
1347 num_refs = btrfs_shared_data_ref_count(leaf, ref2); 1347 num_refs = btrfs_shared_data_ref_count(leaf, ref2);
1348 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0 1348 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
1349 } else if (key.type == BTRFS_EXTENT_REF_V0_KEY) { 1349 } else if (key.type == BTRFS_EXTENT_REF_V0_KEY) {
1350 struct btrfs_extent_ref_v0 *ref0; 1350 struct btrfs_extent_ref_v0 *ref0;
1351 ref0 = btrfs_item_ptr(leaf, path->slots[0], 1351 ref0 = btrfs_item_ptr(leaf, path->slots[0],
1352 struct btrfs_extent_ref_v0); 1352 struct btrfs_extent_ref_v0);
1353 num_refs = btrfs_ref_count_v0(leaf, ref0); 1353 num_refs = btrfs_ref_count_v0(leaf, ref0);
1354 #endif 1354 #endif
1355 } else { 1355 } else {
1356 WARN_ON(1); 1356 WARN_ON(1);
1357 } 1357 }
1358 return num_refs; 1358 return num_refs;
1359 } 1359 }
1360 1360
1361 static noinline int lookup_tree_block_ref(struct btrfs_trans_handle *trans, 1361 static noinline int lookup_tree_block_ref(struct btrfs_trans_handle *trans,
1362 struct btrfs_root *root, 1362 struct btrfs_root *root,
1363 struct btrfs_path *path, 1363 struct btrfs_path *path,
1364 u64 bytenr, u64 parent, 1364 u64 bytenr, u64 parent,
1365 u64 root_objectid) 1365 u64 root_objectid)
1366 { 1366 {
1367 struct btrfs_key key; 1367 struct btrfs_key key;
1368 int ret; 1368 int ret;
1369 1369
1370 key.objectid = bytenr; 1370 key.objectid = bytenr;
1371 if (parent) { 1371 if (parent) {
1372 key.type = BTRFS_SHARED_BLOCK_REF_KEY; 1372 key.type = BTRFS_SHARED_BLOCK_REF_KEY;
1373 key.offset = parent; 1373 key.offset = parent;
1374 } else { 1374 } else {
1375 key.type = BTRFS_TREE_BLOCK_REF_KEY; 1375 key.type = BTRFS_TREE_BLOCK_REF_KEY;
1376 key.offset = root_objectid; 1376 key.offset = root_objectid;
1377 } 1377 }
1378 1378
1379 ret = btrfs_search_slot(trans, root, &key, path, -1, 1); 1379 ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
1380 if (ret > 0) 1380 if (ret > 0)
1381 ret = -ENOENT; 1381 ret = -ENOENT;
1382 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0 1382 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
1383 if (ret == -ENOENT && parent) { 1383 if (ret == -ENOENT && parent) {
1384 btrfs_release_path(path); 1384 btrfs_release_path(path);
1385 key.type = BTRFS_EXTENT_REF_V0_KEY; 1385 key.type = BTRFS_EXTENT_REF_V0_KEY;
1386 ret = btrfs_search_slot(trans, root, &key, path, -1, 1); 1386 ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
1387 if (ret > 0) 1387 if (ret > 0)
1388 ret = -ENOENT; 1388 ret = -ENOENT;
1389 } 1389 }
1390 #endif 1390 #endif
1391 return ret; 1391 return ret;
1392 } 1392 }
1393 1393
1394 static noinline int insert_tree_block_ref(struct btrfs_trans_handle *trans, 1394 static noinline int insert_tree_block_ref(struct btrfs_trans_handle *trans,
1395 struct btrfs_root *root, 1395 struct btrfs_root *root,
1396 struct btrfs_path *path, 1396 struct btrfs_path *path,
1397 u64 bytenr, u64 parent, 1397 u64 bytenr, u64 parent,
1398 u64 root_objectid) 1398 u64 root_objectid)
1399 { 1399 {
1400 struct btrfs_key key; 1400 struct btrfs_key key;
1401 int ret; 1401 int ret;
1402 1402
1403 key.objectid = bytenr; 1403 key.objectid = bytenr;
1404 if (parent) { 1404 if (parent) {
1405 key.type = BTRFS_SHARED_BLOCK_REF_KEY; 1405 key.type = BTRFS_SHARED_BLOCK_REF_KEY;
1406 key.offset = parent; 1406 key.offset = parent;
1407 } else { 1407 } else {
1408 key.type = BTRFS_TREE_BLOCK_REF_KEY; 1408 key.type = BTRFS_TREE_BLOCK_REF_KEY;
1409 key.offset = root_objectid; 1409 key.offset = root_objectid;
1410 } 1410 }
1411 1411
1412 ret = btrfs_insert_empty_item(trans, root, path, &key, 0); 1412 ret = btrfs_insert_empty_item(trans, root, path, &key, 0);
1413 btrfs_release_path(path); 1413 btrfs_release_path(path);
1414 return ret; 1414 return ret;
1415 } 1415 }
1416 1416
1417 static inline int extent_ref_type(u64 parent, u64 owner) 1417 static inline int extent_ref_type(u64 parent, u64 owner)
1418 { 1418 {
1419 int type; 1419 int type;
1420 if (owner < BTRFS_FIRST_FREE_OBJECTID) { 1420 if (owner < BTRFS_FIRST_FREE_OBJECTID) {
1421 if (parent > 0) 1421 if (parent > 0)
1422 type = BTRFS_SHARED_BLOCK_REF_KEY; 1422 type = BTRFS_SHARED_BLOCK_REF_KEY;
1423 else 1423 else
1424 type = BTRFS_TREE_BLOCK_REF_KEY; 1424 type = BTRFS_TREE_BLOCK_REF_KEY;
1425 } else { 1425 } else {
1426 if (parent > 0) 1426 if (parent > 0)
1427 type = BTRFS_SHARED_DATA_REF_KEY; 1427 type = BTRFS_SHARED_DATA_REF_KEY;
1428 else 1428 else
1429 type = BTRFS_EXTENT_DATA_REF_KEY; 1429 type = BTRFS_EXTENT_DATA_REF_KEY;
1430 } 1430 }
1431 return type; 1431 return type;
1432 } 1432 }
1433 1433
1434 static int find_next_key(struct btrfs_path *path, int level, 1434 static int find_next_key(struct btrfs_path *path, int level,
1435 struct btrfs_key *key) 1435 struct btrfs_key *key)
1436 1436
1437 { 1437 {
1438 for (; level < BTRFS_MAX_LEVEL; level++) { 1438 for (; level < BTRFS_MAX_LEVEL; level++) {
1439 if (!path->nodes[level]) 1439 if (!path->nodes[level])
1440 break; 1440 break;
1441 if (path->slots[level] + 1 >= 1441 if (path->slots[level] + 1 >=
1442 btrfs_header_nritems(path->nodes[level])) 1442 btrfs_header_nritems(path->nodes[level]))
1443 continue; 1443 continue;
1444 if (level == 0) 1444 if (level == 0)
1445 btrfs_item_key_to_cpu(path->nodes[level], key, 1445 btrfs_item_key_to_cpu(path->nodes[level], key,
1446 path->slots[level] + 1); 1446 path->slots[level] + 1);
1447 else 1447 else
1448 btrfs_node_key_to_cpu(path->nodes[level], key, 1448 btrfs_node_key_to_cpu(path->nodes[level], key,
1449 path->slots[level] + 1); 1449 path->slots[level] + 1);
1450 return 0; 1450 return 0;
1451 } 1451 }
1452 return 1; 1452 return 1;
1453 } 1453 }
1454 1454
1455 /* 1455 /*
1456 * look for inline back ref. if back ref is found, *ref_ret is set 1456 * look for inline back ref. if back ref is found, *ref_ret is set
1457 * to the address of inline back ref, and 0 is returned. 1457 * to the address of inline back ref, and 0 is returned.
1458 * 1458 *
1459 * if back ref isn't found, *ref_ret is set to the address where it 1459 * if back ref isn't found, *ref_ret is set to the address where it
1460 * should be inserted, and -ENOENT is returned. 1460 * should be inserted, and -ENOENT is returned.
1461 * 1461 *
1462 * if insert is true and there are too many inline back refs, the path 1462 * if insert is true and there are too many inline back refs, the path
1463 * points to the extent item, and -EAGAIN is returned. 1463 * points to the extent item, and -EAGAIN is returned.
1464 * 1464 *
1465 * NOTE: inline back refs are ordered in the same way that back ref 1465 * NOTE: inline back refs are ordered in the same way that back ref
1466 * items in the tree are ordered. 1466 * items in the tree are ordered.
1467 */ 1467 */
1468 static noinline_for_stack 1468 static noinline_for_stack
1469 int lookup_inline_extent_backref(struct btrfs_trans_handle *trans, 1469 int lookup_inline_extent_backref(struct btrfs_trans_handle *trans,
1470 struct btrfs_root *root, 1470 struct btrfs_root *root,
1471 struct btrfs_path *path, 1471 struct btrfs_path *path,
1472 struct btrfs_extent_inline_ref **ref_ret, 1472 struct btrfs_extent_inline_ref **ref_ret,
1473 u64 bytenr, u64 num_bytes, 1473 u64 bytenr, u64 num_bytes,
1474 u64 parent, u64 root_objectid, 1474 u64 parent, u64 root_objectid,
1475 u64 owner, u64 offset, int insert) 1475 u64 owner, u64 offset, int insert)
1476 { 1476 {
1477 struct btrfs_key key; 1477 struct btrfs_key key;
1478 struct extent_buffer *leaf; 1478 struct extent_buffer *leaf;
1479 struct btrfs_extent_item *ei; 1479 struct btrfs_extent_item *ei;
1480 struct btrfs_extent_inline_ref *iref; 1480 struct btrfs_extent_inline_ref *iref;
1481 u64 flags; 1481 u64 flags;
1482 u64 item_size; 1482 u64 item_size;
1483 unsigned long ptr; 1483 unsigned long ptr;
1484 unsigned long end; 1484 unsigned long end;
1485 int extra_size; 1485 int extra_size;
1486 int type; 1486 int type;
1487 int want; 1487 int want;
1488 int ret; 1488 int ret;
1489 int err = 0; 1489 int err = 0;
1490 bool skinny_metadata = btrfs_fs_incompat(root->fs_info, 1490 bool skinny_metadata = btrfs_fs_incompat(root->fs_info,
1491 SKINNY_METADATA); 1491 SKINNY_METADATA);
1492 1492
1493 key.objectid = bytenr; 1493 key.objectid = bytenr;
1494 key.type = BTRFS_EXTENT_ITEM_KEY; 1494 key.type = BTRFS_EXTENT_ITEM_KEY;
1495 key.offset = num_bytes; 1495 key.offset = num_bytes;
1496 1496
1497 want = extent_ref_type(parent, owner); 1497 want = extent_ref_type(parent, owner);
1498 if (insert) { 1498 if (insert) {
1499 extra_size = btrfs_extent_inline_ref_size(want); 1499 extra_size = btrfs_extent_inline_ref_size(want);
1500 path->keep_locks = 1; 1500 path->keep_locks = 1;
1501 } else 1501 } else
1502 extra_size = -1; 1502 extra_size = -1;
1503 1503
1504 /* 1504 /*
1505 * Owner is our parent level, so we can just add one to get the level 1505 * Owner is our parent level, so we can just add one to get the level
1506 * for the block we are interested in. 1506 * for the block we are interested in.
1507 */ 1507 */
1508 if (skinny_metadata && owner < BTRFS_FIRST_FREE_OBJECTID) { 1508 if (skinny_metadata && owner < BTRFS_FIRST_FREE_OBJECTID) {
1509 key.type = BTRFS_METADATA_ITEM_KEY; 1509 key.type = BTRFS_METADATA_ITEM_KEY;
1510 key.offset = owner; 1510 key.offset = owner;
1511 } 1511 }
1512 1512
1513 again: 1513 again:
1514 ret = btrfs_search_slot(trans, root, &key, path, extra_size, 1); 1514 ret = btrfs_search_slot(trans, root, &key, path, extra_size, 1);
1515 if (ret < 0) { 1515 if (ret < 0) {
1516 err = ret; 1516 err = ret;
1517 goto out; 1517 goto out;
1518 } 1518 }
1519 1519
1520 /* 1520 /*
1521 * We may be a newly converted file system which still has the old fat 1521 * We may be a newly converted file system which still has the old fat
1522 * extent entries for metadata, so try and see if we have one of those. 1522 * extent entries for metadata, so try and see if we have one of those.
1523 */ 1523 */
1524 if (ret > 0 && skinny_metadata) { 1524 if (ret > 0 && skinny_metadata) {
1525 skinny_metadata = false; 1525 skinny_metadata = false;
1526 if (path->slots[0]) { 1526 if (path->slots[0]) {
1527 path->slots[0]--; 1527 path->slots[0]--;
1528 btrfs_item_key_to_cpu(path->nodes[0], &key, 1528 btrfs_item_key_to_cpu(path->nodes[0], &key,
1529 path->slots[0]); 1529 path->slots[0]);
1530 if (key.objectid == bytenr && 1530 if (key.objectid == bytenr &&
1531 key.type == BTRFS_EXTENT_ITEM_KEY && 1531 key.type == BTRFS_EXTENT_ITEM_KEY &&
1532 key.offset == num_bytes) 1532 key.offset == num_bytes)
1533 ret = 0; 1533 ret = 0;
1534 } 1534 }
1535 if (ret) { 1535 if (ret) {
1536 key.objectid = bytenr; 1536 key.objectid = bytenr;
1537 key.type = BTRFS_EXTENT_ITEM_KEY; 1537 key.type = BTRFS_EXTENT_ITEM_KEY;
1538 key.offset = num_bytes; 1538 key.offset = num_bytes;
1539 btrfs_release_path(path); 1539 btrfs_release_path(path);
1540 goto again; 1540 goto again;
1541 } 1541 }
1542 } 1542 }
1543 1543
1544 if (ret && !insert) { 1544 if (ret && !insert) {
1545 err = -ENOENT; 1545 err = -ENOENT;
1546 goto out; 1546 goto out;
1547 } else if (WARN_ON(ret)) { 1547 } else if (WARN_ON(ret)) {
1548 err = -EIO; 1548 err = -EIO;
1549 goto out; 1549 goto out;
1550 } 1550 }
1551 1551
1552 leaf = path->nodes[0]; 1552 leaf = path->nodes[0];
1553 item_size = btrfs_item_size_nr(leaf, path->slots[0]); 1553 item_size = btrfs_item_size_nr(leaf, path->slots[0]);
1554 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0 1554 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
1555 if (item_size < sizeof(*ei)) { 1555 if (item_size < sizeof(*ei)) {
1556 if (!insert) { 1556 if (!insert) {
1557 err = -ENOENT; 1557 err = -ENOENT;
1558 goto out; 1558 goto out;
1559 } 1559 }
1560 ret = convert_extent_item_v0(trans, root, path, owner, 1560 ret = convert_extent_item_v0(trans, root, path, owner,
1561 extra_size); 1561 extra_size);
1562 if (ret < 0) { 1562 if (ret < 0) {
1563 err = ret; 1563 err = ret;
1564 goto out; 1564 goto out;
1565 } 1565 }
1566 leaf = path->nodes[0]; 1566 leaf = path->nodes[0];
1567 item_size = btrfs_item_size_nr(leaf, path->slots[0]); 1567 item_size = btrfs_item_size_nr(leaf, path->slots[0]);
1568 } 1568 }
1569 #endif 1569 #endif
1570 BUG_ON(item_size < sizeof(*ei)); 1570 BUG_ON(item_size < sizeof(*ei));
1571 1571
1572 ei = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_extent_item); 1572 ei = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_extent_item);
1573 flags = btrfs_extent_flags(leaf, ei); 1573 flags = btrfs_extent_flags(leaf, ei);
1574 1574
1575 ptr = (unsigned long)(ei + 1); 1575 ptr = (unsigned long)(ei + 1);
1576 end = (unsigned long)ei + item_size; 1576 end = (unsigned long)ei + item_size;
1577 1577
1578 if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK && !skinny_metadata) { 1578 if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK && !skinny_metadata) {
1579 ptr += sizeof(struct btrfs_tree_block_info); 1579 ptr += sizeof(struct btrfs_tree_block_info);
1580 BUG_ON(ptr > end); 1580 BUG_ON(ptr > end);
1581 } 1581 }
1582 1582
1583 err = -ENOENT; 1583 err = -ENOENT;
1584 while (1) { 1584 while (1) {
1585 if (ptr >= end) { 1585 if (ptr >= end) {
1586 WARN_ON(ptr > end); 1586 WARN_ON(ptr > end);
1587 break; 1587 break;
1588 } 1588 }
1589 iref = (struct btrfs_extent_inline_ref *)ptr; 1589 iref = (struct btrfs_extent_inline_ref *)ptr;
1590 type = btrfs_extent_inline_ref_type(leaf, iref); 1590 type = btrfs_extent_inline_ref_type(leaf, iref);
1591 if (want < type) 1591 if (want < type)
1592 break; 1592 break;
1593 if (want > type) { 1593 if (want > type) {
1594 ptr += btrfs_extent_inline_ref_size(type); 1594 ptr += btrfs_extent_inline_ref_size(type);
1595 continue; 1595 continue;
1596 } 1596 }
1597 1597
1598 if (type == BTRFS_EXTENT_DATA_REF_KEY) { 1598 if (type == BTRFS_EXTENT_DATA_REF_KEY) {
1599 struct btrfs_extent_data_ref *dref; 1599 struct btrfs_extent_data_ref *dref;
1600 dref = (struct btrfs_extent_data_ref *)(&iref->offset); 1600 dref = (struct btrfs_extent_data_ref *)(&iref->offset);
1601 if (match_extent_data_ref(leaf, dref, root_objectid, 1601 if (match_extent_data_ref(leaf, dref, root_objectid,
1602 owner, offset)) { 1602 owner, offset)) {
1603 err = 0; 1603 err = 0;
1604 break; 1604 break;
1605 } 1605 }
1606 if (hash_extent_data_ref_item(leaf, dref) < 1606 if (hash_extent_data_ref_item(leaf, dref) <
1607 hash_extent_data_ref(root_objectid, owner, offset)) 1607 hash_extent_data_ref(root_objectid, owner, offset))
1608 break; 1608 break;
1609 } else { 1609 } else {
1610 u64 ref_offset; 1610 u64 ref_offset;
1611 ref_offset = btrfs_extent_inline_ref_offset(leaf, iref); 1611 ref_offset = btrfs_extent_inline_ref_offset(leaf, iref);
1612 if (parent > 0) { 1612 if (parent > 0) {
1613 if (parent == ref_offset) { 1613 if (parent == ref_offset) {
1614 err = 0; 1614 err = 0;
1615 break; 1615 break;
1616 } 1616 }
1617 if (ref_offset < parent) 1617 if (ref_offset < parent)
1618 break; 1618 break;
1619 } else { 1619 } else {
1620 if (root_objectid == ref_offset) { 1620 if (root_objectid == ref_offset) {
1621 err = 0; 1621 err = 0;
1622 break; 1622 break;
1623 } 1623 }
1624 if (ref_offset < root_objectid) 1624 if (ref_offset < root_objectid)
1625 break; 1625 break;
1626 } 1626 }
1627 } 1627 }
1628 ptr += btrfs_extent_inline_ref_size(type); 1628 ptr += btrfs_extent_inline_ref_size(type);
1629 } 1629 }
1630 if (err == -ENOENT && insert) { 1630 if (err == -ENOENT && insert) {
1631 if (item_size + extra_size >= 1631 if (item_size + extra_size >=
1632 BTRFS_MAX_EXTENT_ITEM_SIZE(root)) { 1632 BTRFS_MAX_EXTENT_ITEM_SIZE(root)) {
1633 err = -EAGAIN; 1633 err = -EAGAIN;
1634 goto out; 1634 goto out;
1635 } 1635 }
1636 /* 1636 /*
1637 * To add new inline back ref, we have to make sure 1637 * To add new inline back ref, we have to make sure
1638 * there is no corresponding back ref item. 1638 * there is no corresponding back ref item.
1639 * For simplicity, we just do not add new inline back 1639 * For simplicity, we just do not add new inline back
1640 * ref if there is any kind of item for this block 1640 * ref if there is any kind of item for this block
1641 */ 1641 */
1642 if (find_next_key(path, 0, &key) == 0 && 1642 if (find_next_key(path, 0, &key) == 0 &&
1643 key.objectid == bytenr && 1643 key.objectid == bytenr &&
1644 key.type < BTRFS_BLOCK_GROUP_ITEM_KEY) { 1644 key.type < BTRFS_BLOCK_GROUP_ITEM_KEY) {
1645 err = -EAGAIN; 1645 err = -EAGAIN;
1646 goto out; 1646 goto out;
1647 } 1647 }
1648 } 1648 }
1649 *ref_ret = (struct btrfs_extent_inline_ref *)ptr; 1649 *ref_ret = (struct btrfs_extent_inline_ref *)ptr;
1650 out: 1650 out:
1651 if (insert) { 1651 if (insert) {
1652 path->keep_locks = 0; 1652 path->keep_locks = 0;
1653 btrfs_unlock_up_safe(path, 1); 1653 btrfs_unlock_up_safe(path, 1);
1654 } 1654 }
1655 return err; 1655 return err;
1656 } 1656 }
1657 1657
1658 /* 1658 /*
1659 * helper to add new inline back ref 1659 * helper to add new inline back ref
1660 */ 1660 */
1661 static noinline_for_stack 1661 static noinline_for_stack
1662 void setup_inline_extent_backref(struct btrfs_root *root, 1662 void setup_inline_extent_backref(struct btrfs_root *root,
1663 struct btrfs_path *path, 1663 struct btrfs_path *path,
1664 struct btrfs_extent_inline_ref *iref, 1664 struct btrfs_extent_inline_ref *iref,
1665 u64 parent, u64 root_objectid, 1665 u64 parent, u64 root_objectid,
1666 u64 owner, u64 offset, int refs_to_add, 1666 u64 owner, u64 offset, int refs_to_add,
1667 struct btrfs_delayed_extent_op *extent_op) 1667 struct btrfs_delayed_extent_op *extent_op)
1668 { 1668 {
1669 struct extent_buffer *leaf; 1669 struct extent_buffer *leaf;
1670 struct btrfs_extent_item *ei; 1670 struct btrfs_extent_item *ei;
1671 unsigned long ptr; 1671 unsigned long ptr;
1672 unsigned long end; 1672 unsigned long end;
1673 unsigned long item_offset; 1673 unsigned long item_offset;
1674 u64 refs; 1674 u64 refs;
1675 int size; 1675 int size;
1676 int type; 1676 int type;
1677 1677
1678 leaf = path->nodes[0]; 1678 leaf = path->nodes[0];
1679 ei = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_extent_item); 1679 ei = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_extent_item);
1680 item_offset = (unsigned long)iref - (unsigned long)ei; 1680 item_offset = (unsigned long)iref - (unsigned long)ei;
1681 1681
1682 type = extent_ref_type(parent, owner); 1682 type = extent_ref_type(parent, owner);
1683 size = btrfs_extent_inline_ref_size(type); 1683 size = btrfs_extent_inline_ref_size(type);
1684 1684
1685 btrfs_extend_item(root, path, size); 1685 btrfs_extend_item(root, path, size);
1686 1686
1687 ei = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_extent_item); 1687 ei = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_extent_item);
1688 refs = btrfs_extent_refs(leaf, ei); 1688 refs = btrfs_extent_refs(leaf, ei);
1689 refs += refs_to_add; 1689 refs += refs_to_add;
1690 btrfs_set_extent_refs(leaf, ei, refs); 1690 btrfs_set_extent_refs(leaf, ei, refs);
1691 if (extent_op) 1691 if (extent_op)
1692 __run_delayed_extent_op(extent_op, leaf, ei); 1692 __run_delayed_extent_op(extent_op, leaf, ei);
1693 1693
1694 ptr = (unsigned long)ei + item_offset; 1694 ptr = (unsigned long)ei + item_offset;
1695 end = (unsigned long)ei + btrfs_item_size_nr(leaf, path->slots[0]); 1695 end = (unsigned long)ei + btrfs_item_size_nr(leaf, path->slots[0]);
1696 if (ptr < end - size) 1696 if (ptr < end - size)
1697 memmove_extent_buffer(leaf, ptr + size, ptr, 1697 memmove_extent_buffer(leaf, ptr + size, ptr,
1698 end - size - ptr); 1698 end - size - ptr);
1699 1699
1700 iref = (struct btrfs_extent_inline_ref *)ptr; 1700 iref = (struct btrfs_extent_inline_ref *)ptr;
1701 btrfs_set_extent_inline_ref_type(leaf, iref, type); 1701 btrfs_set_extent_inline_ref_type(leaf, iref, type);
1702 if (type == BTRFS_EXTENT_DATA_REF_KEY) { 1702 if (type == BTRFS_EXTENT_DATA_REF_KEY) {
1703 struct btrfs_extent_data_ref *dref; 1703 struct btrfs_extent_data_ref *dref;
1704 dref = (struct btrfs_extent_data_ref *)(&iref->offset); 1704 dref = (struct btrfs_extent_data_ref *)(&iref->offset);
1705 btrfs_set_extent_data_ref_root(leaf, dref, root_objectid); 1705 btrfs_set_extent_data_ref_root(leaf, dref, root_objectid);
1706 btrfs_set_extent_data_ref_objectid(leaf, dref, owner); 1706 btrfs_set_extent_data_ref_objectid(leaf, dref, owner);
1707 btrfs_set_extent_data_ref_offset(leaf, dref, offset); 1707 btrfs_set_extent_data_ref_offset(leaf, dref, offset);
1708 btrfs_set_extent_data_ref_count(leaf, dref, refs_to_add); 1708 btrfs_set_extent_data_ref_count(leaf, dref, refs_to_add);
1709 } else if (type == BTRFS_SHARED_DATA_REF_KEY) { 1709 } else if (type == BTRFS_SHARED_DATA_REF_KEY) {
1710 struct btrfs_shared_data_ref *sref; 1710 struct btrfs_shared_data_ref *sref;
1711 sref = (struct btrfs_shared_data_ref *)(iref + 1); 1711 sref = (struct btrfs_shared_data_ref *)(iref + 1);
1712 btrfs_set_shared_data_ref_count(leaf, sref, refs_to_add); 1712 btrfs_set_shared_data_ref_count(leaf, sref, refs_to_add);
1713 btrfs_set_extent_inline_ref_offset(leaf, iref, parent); 1713 btrfs_set_extent_inline_ref_offset(leaf, iref, parent);
1714 } else if (type == BTRFS_SHARED_BLOCK_REF_KEY) { 1714 } else if (type == BTRFS_SHARED_BLOCK_REF_KEY) {
1715 btrfs_set_extent_inline_ref_offset(leaf, iref, parent); 1715 btrfs_set_extent_inline_ref_offset(leaf, iref, parent);
1716 } else { 1716 } else {
1717 btrfs_set_extent_inline_ref_offset(leaf, iref, root_objectid); 1717 btrfs_set_extent_inline_ref_offset(leaf, iref, root_objectid);
1718 } 1718 }
1719 btrfs_mark_buffer_dirty(leaf); 1719 btrfs_mark_buffer_dirty(leaf);
1720 } 1720 }
1721 1721
1722 static int lookup_extent_backref(struct btrfs_trans_handle *trans, 1722 static int lookup_extent_backref(struct btrfs_trans_handle *trans,
1723 struct btrfs_root *root, 1723 struct btrfs_root *root,
1724 struct btrfs_path *path, 1724 struct btrfs_path *path,
1725 struct btrfs_extent_inline_ref **ref_ret, 1725 struct btrfs_extent_inline_ref **ref_ret,
1726 u64 bytenr, u64 num_bytes, u64 parent, 1726 u64 bytenr, u64 num_bytes, u64 parent,
1727 u64 root_objectid, u64 owner, u64 offset) 1727 u64 root_objectid, u64 owner, u64 offset)
1728 { 1728 {
1729 int ret; 1729 int ret;
1730 1730
1731 ret = lookup_inline_extent_backref(trans, root, path, ref_ret, 1731 ret = lookup_inline_extent_backref(trans, root, path, ref_ret,
1732 bytenr, num_bytes, parent, 1732 bytenr, num_bytes, parent,
1733 root_objectid, owner, offset, 0); 1733 root_objectid, owner, offset, 0);
1734 if (ret != -ENOENT) 1734 if (ret != -ENOENT)
1735 return ret; 1735 return ret;
1736 1736
1737 btrfs_release_path(path); 1737 btrfs_release_path(path);
1738 *ref_ret = NULL; 1738 *ref_ret = NULL;
1739 1739
1740 if (owner < BTRFS_FIRST_FREE_OBJECTID) { 1740 if (owner < BTRFS_FIRST_FREE_OBJECTID) {
1741 ret = lookup_tree_block_ref(trans, root, path, bytenr, parent, 1741 ret = lookup_tree_block_ref(trans, root, path, bytenr, parent,
1742 root_objectid); 1742 root_objectid);
1743 } else { 1743 } else {
1744 ret = lookup_extent_data_ref(trans, root, path, bytenr, parent, 1744 ret = lookup_extent_data_ref(trans, root, path, bytenr, parent,
1745 root_objectid, owner, offset); 1745 root_objectid, owner, offset);
1746 } 1746 }
1747 return ret; 1747 return ret;
1748 } 1748 }
1749 1749
1750 /* 1750 /*
1751 * helper to update/remove inline back ref 1751 * helper to update/remove inline back ref
1752 */ 1752 */
1753 static noinline_for_stack 1753 static noinline_for_stack
1754 void update_inline_extent_backref(struct btrfs_root *root, 1754 void update_inline_extent_backref(struct btrfs_root *root,
1755 struct btrfs_path *path, 1755 struct btrfs_path *path,
1756 struct btrfs_extent_inline_ref *iref, 1756 struct btrfs_extent_inline_ref *iref,
1757 int refs_to_mod, 1757 int refs_to_mod,
1758 struct btrfs_delayed_extent_op *extent_op, 1758 struct btrfs_delayed_extent_op *extent_op,
1759 int *last_ref) 1759 int *last_ref)
1760 { 1760 {
1761 struct extent_buffer *leaf; 1761 struct extent_buffer *leaf;
1762 struct btrfs_extent_item *ei; 1762 struct btrfs_extent_item *ei;
1763 struct btrfs_extent_data_ref *dref = NULL; 1763 struct btrfs_extent_data_ref *dref = NULL;
1764 struct btrfs_shared_data_ref *sref = NULL; 1764 struct btrfs_shared_data_ref *sref = NULL;
1765 unsigned long ptr; 1765 unsigned long ptr;
1766 unsigned long end; 1766 unsigned long end;
1767 u32 item_size; 1767 u32 item_size;
1768 int size; 1768 int size;
1769 int type; 1769 int type;
1770 u64 refs; 1770 u64 refs;
1771 1771
1772 leaf = path->nodes[0]; 1772 leaf = path->nodes[0];
1773 ei = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_extent_item); 1773 ei = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_extent_item);
1774 refs = btrfs_extent_refs(leaf, ei); 1774 refs = btrfs_extent_refs(leaf, ei);
1775 WARN_ON(refs_to_mod < 0 && refs + refs_to_mod <= 0); 1775 WARN_ON(refs_to_mod < 0 && refs + refs_to_mod <= 0);
1776 refs += refs_to_mod; 1776 refs += refs_to_mod;
1777 btrfs_set_extent_refs(leaf, ei, refs); 1777 btrfs_set_extent_refs(leaf, ei, refs);
1778 if (extent_op) 1778 if (extent_op)
1779 __run_delayed_extent_op(extent_op, leaf, ei); 1779 __run_delayed_extent_op(extent_op, leaf, ei);
1780 1780
1781 type = btrfs_extent_inline_ref_type(leaf, iref); 1781 type = btrfs_extent_inline_ref_type(leaf, iref);
1782 1782
1783 if (type == BTRFS_EXTENT_DATA_REF_KEY) { 1783 if (type == BTRFS_EXTENT_DATA_REF_KEY) {
1784 dref = (struct btrfs_extent_data_ref *)(&iref->offset); 1784 dref = (struct btrfs_extent_data_ref *)(&iref->offset);
1785 refs = btrfs_extent_data_ref_count(leaf, dref); 1785 refs = btrfs_extent_data_ref_count(leaf, dref);
1786 } else if (type == BTRFS_SHARED_DATA_REF_KEY) { 1786 } else if (type == BTRFS_SHARED_DATA_REF_KEY) {
1787 sref = (struct btrfs_shared_data_ref *)(iref + 1); 1787 sref = (struct btrfs_shared_data_ref *)(iref + 1);
1788 refs = btrfs_shared_data_ref_count(leaf, sref); 1788 refs = btrfs_shared_data_ref_count(leaf, sref);
1789 } else { 1789 } else {
1790 refs = 1; 1790 refs = 1;
1791 BUG_ON(refs_to_mod != -1); 1791 BUG_ON(refs_to_mod != -1);
1792 } 1792 }
1793 1793
1794 BUG_ON(refs_to_mod < 0 && refs < -refs_to_mod); 1794 BUG_ON(refs_to_mod < 0 && refs < -refs_to_mod);
1795 refs += refs_to_mod; 1795 refs += refs_to_mod;
1796 1796
1797 if (refs > 0) { 1797 if (refs > 0) {
1798 if (type == BTRFS_EXTENT_DATA_REF_KEY) 1798 if (type == BTRFS_EXTENT_DATA_REF_KEY)
1799 btrfs_set_extent_data_ref_count(leaf, dref, refs); 1799 btrfs_set_extent_data_ref_count(leaf, dref, refs);
1800 else 1800 else
1801 btrfs_set_shared_data_ref_count(leaf, sref, refs); 1801 btrfs_set_shared_data_ref_count(leaf, sref, refs);
1802 } else { 1802 } else {
1803 *last_ref = 1; 1803 *last_ref = 1;
1804 size = btrfs_extent_inline_ref_size(type); 1804 size = btrfs_extent_inline_ref_size(type);
1805 item_size = btrfs_item_size_nr(leaf, path->slots[0]); 1805 item_size = btrfs_item_size_nr(leaf, path->slots[0]);
1806 ptr = (unsigned long)iref; 1806 ptr = (unsigned long)iref;
1807 end = (unsigned long)ei + item_size; 1807 end = (unsigned long)ei + item_size;
1808 if (ptr + size < end) 1808 if (ptr + size < end)
1809 memmove_extent_buffer(leaf, ptr, ptr + size, 1809 memmove_extent_buffer(leaf, ptr, ptr + size,
1810 end - ptr - size); 1810 end - ptr - size);
1811 item_size -= size; 1811 item_size -= size;
1812 btrfs_truncate_item(root, path, item_size, 1); 1812 btrfs_truncate_item(root, path, item_size, 1);
1813 } 1813 }
1814 btrfs_mark_buffer_dirty(leaf); 1814 btrfs_mark_buffer_dirty(leaf);
1815 } 1815 }
1816 1816
1817 static noinline_for_stack 1817 static noinline_for_stack
1818 int insert_inline_extent_backref(struct btrfs_trans_handle *trans, 1818 int insert_inline_extent_backref(struct btrfs_trans_handle *trans,
1819 struct btrfs_root *root, 1819 struct btrfs_root *root,
1820 struct btrfs_path *path, 1820 struct btrfs_path *path,
1821 u64 bytenr, u64 num_bytes, u64 parent, 1821 u64 bytenr, u64 num_bytes, u64 parent,
1822 u64 root_objectid, u64 owner, 1822 u64 root_objectid, u64 owner,
1823 u64 offset, int refs_to_add, 1823 u64 offset, int refs_to_add,
1824 struct btrfs_delayed_extent_op *extent_op) 1824 struct btrfs_delayed_extent_op *extent_op)
1825 { 1825 {
1826 struct btrfs_extent_inline_ref *iref; 1826 struct btrfs_extent_inline_ref *iref;
1827 int ret; 1827 int ret;
1828 1828
1829 ret = lookup_inline_extent_backref(trans, root, path, &iref, 1829 ret = lookup_inline_extent_backref(trans, root, path, &iref,
1830 bytenr, num_bytes, parent, 1830 bytenr, num_bytes, parent,
1831 root_objectid, owner, offset, 1); 1831 root_objectid, owner, offset, 1);
1832 if (ret == 0) { 1832 if (ret == 0) {
1833 BUG_ON(owner < BTRFS_FIRST_FREE_OBJECTID); 1833 BUG_ON(owner < BTRFS_FIRST_FREE_OBJECTID);
1834 update_inline_extent_backref(root, path, iref, 1834 update_inline_extent_backref(root, path, iref,
1835 refs_to_add, extent_op, NULL); 1835 refs_to_add, extent_op, NULL);
1836 } else if (ret == -ENOENT) { 1836 } else if (ret == -ENOENT) {
1837 setup_inline_extent_backref(root, path, iref, parent, 1837 setup_inline_extent_backref(root, path, iref, parent,
1838 root_objectid, owner, offset, 1838 root_objectid, owner, offset,
1839 refs_to_add, extent_op); 1839 refs_to_add, extent_op);
1840 ret = 0; 1840 ret = 0;
1841 } 1841 }
1842 return ret; 1842 return ret;
1843 } 1843 }
1844 1844
1845 static int insert_extent_backref(struct btrfs_trans_handle *trans, 1845 static int insert_extent_backref(struct btrfs_trans_handle *trans,
1846 struct btrfs_root *root, 1846 struct btrfs_root *root,
1847 struct btrfs_path *path, 1847 struct btrfs_path *path,
1848 u64 bytenr, u64 parent, u64 root_objectid, 1848 u64 bytenr, u64 parent, u64 root_objectid,
1849 u64 owner, u64 offset, int refs_to_add) 1849 u64 owner, u64 offset, int refs_to_add)
1850 { 1850 {
1851 int ret; 1851 int ret;
1852 if (owner < BTRFS_FIRST_FREE_OBJECTID) { 1852 if (owner < BTRFS_FIRST_FREE_OBJECTID) {
1853 BUG_ON(refs_to_add != 1); 1853 BUG_ON(refs_to_add != 1);
1854 ret = insert_tree_block_ref(trans, root, path, bytenr, 1854 ret = insert_tree_block_ref(trans, root, path, bytenr,
1855 parent, root_objectid); 1855 parent, root_objectid);
1856 } else { 1856 } else {
1857 ret = insert_extent_data_ref(trans, root, path, bytenr, 1857 ret = insert_extent_data_ref(trans, root, path, bytenr,
1858 parent, root_objectid, 1858 parent, root_objectid,
1859 owner, offset, refs_to_add); 1859 owner, offset, refs_to_add);
1860 } 1860 }
1861 return ret; 1861 return ret;
1862 } 1862 }
1863 1863
1864 static int remove_extent_backref(struct btrfs_trans_handle *trans, 1864 static int remove_extent_backref(struct btrfs_trans_handle *trans,
1865 struct btrfs_root *root, 1865 struct btrfs_root *root,
1866 struct btrfs_path *path, 1866 struct btrfs_path *path,
1867 struct btrfs_extent_inline_ref *iref, 1867 struct btrfs_extent_inline_ref *iref,
1868 int refs_to_drop, int is_data, int *last_ref) 1868 int refs_to_drop, int is_data, int *last_ref)
1869 { 1869 {
1870 int ret = 0; 1870 int ret = 0;
1871 1871
1872 BUG_ON(!is_data && refs_to_drop != 1); 1872 BUG_ON(!is_data && refs_to_drop != 1);
1873 if (iref) { 1873 if (iref) {
1874 update_inline_extent_backref(root, path, iref, 1874 update_inline_extent_backref(root, path, iref,
1875 -refs_to_drop, NULL, last_ref); 1875 -refs_to_drop, NULL, last_ref);
1876 } else if (is_data) { 1876 } else if (is_data) {
1877 ret = remove_extent_data_ref(trans, root, path, refs_to_drop, 1877 ret = remove_extent_data_ref(trans, root, path, refs_to_drop,
1878 last_ref); 1878 last_ref);
1879 } else { 1879 } else {
1880 *last_ref = 1; 1880 *last_ref = 1;
1881 ret = btrfs_del_item(trans, root, path); 1881 ret = btrfs_del_item(trans, root, path);
1882 } 1882 }
1883 return ret; 1883 return ret;
1884 } 1884 }
1885 1885
1886 static int btrfs_issue_discard(struct block_device *bdev, 1886 static int btrfs_issue_discard(struct block_device *bdev,
1887 u64 start, u64 len) 1887 u64 start, u64 len)
1888 { 1888 {
1889 return blkdev_issue_discard(bdev, start >> 9, len >> 9, GFP_NOFS, 0); 1889 return blkdev_issue_discard(bdev, start >> 9, len >> 9, GFP_NOFS, 0);
1890 } 1890 }
1891 1891
1892 int btrfs_discard_extent(struct btrfs_root *root, u64 bytenr, 1892 int btrfs_discard_extent(struct btrfs_root *root, u64 bytenr,
1893 u64 num_bytes, u64 *actual_bytes) 1893 u64 num_bytes, u64 *actual_bytes)
1894 { 1894 {
1895 int ret; 1895 int ret;
1896 u64 discarded_bytes = 0; 1896 u64 discarded_bytes = 0;
1897 struct btrfs_bio *bbio = NULL; 1897 struct btrfs_bio *bbio = NULL;
1898 1898
1899 1899
1900 /* Tell the block device(s) that the sectors can be discarded */ 1900 /* Tell the block device(s) that the sectors can be discarded */
1901 ret = btrfs_map_block(root->fs_info, REQ_DISCARD, 1901 ret = btrfs_map_block(root->fs_info, REQ_DISCARD,
1902 bytenr, &num_bytes, &bbio, 0); 1902 bytenr, &num_bytes, &bbio, 0);
1903 /* Error condition is -ENOMEM */ 1903 /* Error condition is -ENOMEM */
1904 if (!ret) { 1904 if (!ret) {
1905 struct btrfs_bio_stripe *stripe = bbio->stripes; 1905 struct btrfs_bio_stripe *stripe = bbio->stripes;
1906 int i; 1906 int i;
1907 1907
1908 1908
1909 for (i = 0; i < bbio->num_stripes; i++, stripe++) { 1909 for (i = 0; i < bbio->num_stripes; i++, stripe++) {
1910 if (!stripe->dev->can_discard) 1910 if (!stripe->dev->can_discard)
1911 continue; 1911 continue;
1912 1912
1913 ret = btrfs_issue_discard(stripe->dev->bdev, 1913 ret = btrfs_issue_discard(stripe->dev->bdev,
1914 stripe->physical, 1914 stripe->physical,
1915 stripe->length); 1915 stripe->length);
1916 if (!ret) 1916 if (!ret)
1917 discarded_bytes += stripe->length; 1917 discarded_bytes += stripe->length;
1918 else if (ret != -EOPNOTSUPP) 1918 else if (ret != -EOPNOTSUPP)
1919 break; /* Logic errors or -ENOMEM, or -EIO but I don't know how that could happen JDM */ 1919 break; /* Logic errors or -ENOMEM, or -EIO but I don't know how that could happen JDM */
1920 1920
1921 /* 1921 /*
1922 * Just in case we get back EOPNOTSUPP for some reason, 1922 * Just in case we get back EOPNOTSUPP for some reason,
1923 * just ignore the return value so we don't screw up 1923 * just ignore the return value so we don't screw up
1924 * people calling discard_extent. 1924 * people calling discard_extent.
1925 */ 1925 */
1926 ret = 0; 1926 ret = 0;
1927 } 1927 }
1928 kfree(bbio); 1928 kfree(bbio);
1929 } 1929 }
1930 1930
1931 if (actual_bytes) 1931 if (actual_bytes)
1932 *actual_bytes = discarded_bytes; 1932 *actual_bytes = discarded_bytes;
1933 1933
1934 1934
1935 if (ret == -EOPNOTSUPP) 1935 if (ret == -EOPNOTSUPP)
1936 ret = 0; 1936 ret = 0;
1937 return ret; 1937 return ret;
1938 } 1938 }
1939 1939
1940 /* Can return -ENOMEM */ 1940 /* Can return -ENOMEM */
1941 int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, 1941 int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
1942 struct btrfs_root *root, 1942 struct btrfs_root *root,
1943 u64 bytenr, u64 num_bytes, u64 parent, 1943 u64 bytenr, u64 num_bytes, u64 parent,
1944 u64 root_objectid, u64 owner, u64 offset, 1944 u64 root_objectid, u64 owner, u64 offset,
1945 int no_quota) 1945 int no_quota)
1946 { 1946 {
1947 int ret; 1947 int ret;
1948 struct btrfs_fs_info *fs_info = root->fs_info; 1948 struct btrfs_fs_info *fs_info = root->fs_info;
1949 1949
1950 BUG_ON(owner < BTRFS_FIRST_FREE_OBJECTID && 1950 BUG_ON(owner < BTRFS_FIRST_FREE_OBJECTID &&
1951 root_objectid == BTRFS_TREE_LOG_OBJECTID); 1951 root_objectid == BTRFS_TREE_LOG_OBJECTID);
1952 1952
1953 if (owner < BTRFS_FIRST_FREE_OBJECTID) { 1953 if (owner < BTRFS_FIRST_FREE_OBJECTID) {
1954 ret = btrfs_add_delayed_tree_ref(fs_info, trans, bytenr, 1954 ret = btrfs_add_delayed_tree_ref(fs_info, trans, bytenr,
1955 num_bytes, 1955 num_bytes,
1956 parent, root_objectid, (int)owner, 1956 parent, root_objectid, (int)owner,
1957 BTRFS_ADD_DELAYED_REF, NULL, no_quota); 1957 BTRFS_ADD_DELAYED_REF, NULL, no_quota);
1958 } else { 1958 } else {
1959 ret = btrfs_add_delayed_data_ref(fs_info, trans, bytenr, 1959 ret = btrfs_add_delayed_data_ref(fs_info, trans, bytenr,
1960 num_bytes, 1960 num_bytes,
1961 parent, root_objectid, owner, offset, 1961 parent, root_objectid, owner, offset,
1962 BTRFS_ADD_DELAYED_REF, NULL, no_quota); 1962 BTRFS_ADD_DELAYED_REF, NULL, no_quota);
1963 } 1963 }
1964 return ret; 1964 return ret;
1965 } 1965 }
1966 1966
1967 static int __btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, 1967 static int __btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
1968 struct btrfs_root *root, 1968 struct btrfs_root *root,
1969 u64 bytenr, u64 num_bytes, 1969 u64 bytenr, u64 num_bytes,
1970 u64 parent, u64 root_objectid, 1970 u64 parent, u64 root_objectid,
1971 u64 owner, u64 offset, int refs_to_add, 1971 u64 owner, u64 offset, int refs_to_add,
1972 int no_quota, 1972 int no_quota,
1973 struct btrfs_delayed_extent_op *extent_op) 1973 struct btrfs_delayed_extent_op *extent_op)
1974 { 1974 {
1975 struct btrfs_fs_info *fs_info = root->fs_info; 1975 struct btrfs_fs_info *fs_info = root->fs_info;
1976 struct btrfs_path *path; 1976 struct btrfs_path *path;
1977 struct extent_buffer *leaf; 1977 struct extent_buffer *leaf;
1978 struct btrfs_extent_item *item; 1978 struct btrfs_extent_item *item;
1979 struct btrfs_key key; 1979 struct btrfs_key key;
1980 u64 refs; 1980 u64 refs;
1981 int ret; 1981 int ret;
1982 enum btrfs_qgroup_operation_type type = BTRFS_QGROUP_OPER_ADD_EXCL; 1982 enum btrfs_qgroup_operation_type type = BTRFS_QGROUP_OPER_ADD_EXCL;
1983 1983
1984 path = btrfs_alloc_path(); 1984 path = btrfs_alloc_path();
1985 if (!path) 1985 if (!path)
1986 return -ENOMEM; 1986 return -ENOMEM;
1987 1987
1988 if (!is_fstree(root_objectid) || !root->fs_info->quota_enabled) 1988 if (!is_fstree(root_objectid) || !root->fs_info->quota_enabled)
1989 no_quota = 1; 1989 no_quota = 1;
1990 1990
1991 path->reada = 1; 1991 path->reada = 1;
1992 path->leave_spinning = 1; 1992 path->leave_spinning = 1;
1993 /* this will setup the path even if it fails to insert the back ref */ 1993 /* this will setup the path even if it fails to insert the back ref */
1994 ret = insert_inline_extent_backref(trans, fs_info->extent_root, path, 1994 ret = insert_inline_extent_backref(trans, fs_info->extent_root, path,
1995 bytenr, num_bytes, parent, 1995 bytenr, num_bytes, parent,
1996 root_objectid, owner, offset, 1996 root_objectid, owner, offset,
1997 refs_to_add, extent_op); 1997 refs_to_add, extent_op);
1998 if ((ret < 0 && ret != -EAGAIN) || (!ret && no_quota)) 1998 if ((ret < 0 && ret != -EAGAIN) || (!ret && no_quota))
1999 goto out; 1999 goto out;
2000 /* 2000 /*
2001 * Ok we were able to insert an inline extent and it appears to be a new 2001 * Ok we were able to insert an inline extent and it appears to be a new
2002 * reference, deal with the qgroup accounting. 2002 * reference, deal with the qgroup accounting.
2003 */ 2003 */
2004 if (!ret && !no_quota) { 2004 if (!ret && !no_quota) {
2005 ASSERT(root->fs_info->quota_enabled); 2005 ASSERT(root->fs_info->quota_enabled);
2006 leaf = path->nodes[0]; 2006 leaf = path->nodes[0];
2007 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); 2007 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
2008 item = btrfs_item_ptr(leaf, path->slots[0], 2008 item = btrfs_item_ptr(leaf, path->slots[0],
2009 struct btrfs_extent_item); 2009 struct btrfs_extent_item);
2010 if (btrfs_extent_refs(leaf, item) > (u64)refs_to_add) 2010 if (btrfs_extent_refs(leaf, item) > (u64)refs_to_add)
2011 type = BTRFS_QGROUP_OPER_ADD_SHARED; 2011 type = BTRFS_QGROUP_OPER_ADD_SHARED;
2012 btrfs_release_path(path); 2012 btrfs_release_path(path);
2013 2013
2014 ret = btrfs_qgroup_record_ref(trans, fs_info, root_objectid, 2014 ret = btrfs_qgroup_record_ref(trans, fs_info, root_objectid,
2015 bytenr, num_bytes, type, 0); 2015 bytenr, num_bytes, type, 0);
2016 goto out; 2016 goto out;
2017 } 2017 }
2018 2018
2019 /* 2019 /*
2020 * Ok we had -EAGAIN which means we didn't have space to insert and 2020 * Ok we had -EAGAIN which means we didn't have space to insert and
2021 * inline extent ref, so just update the reference count and add a 2021 * inline extent ref, so just update the reference count and add a
2022 * normal backref. 2022 * normal backref.
2023 */ 2023 */
2024 leaf = path->nodes[0]; 2024 leaf = path->nodes[0];
2025 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); 2025 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
2026 item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_extent_item); 2026 item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_extent_item);
2027 refs = btrfs_extent_refs(leaf, item); 2027 refs = btrfs_extent_refs(leaf, item);
2028 if (refs) 2028 if (refs)
2029 type = BTRFS_QGROUP_OPER_ADD_SHARED; 2029 type = BTRFS_QGROUP_OPER_ADD_SHARED;
2030 btrfs_set_extent_refs(leaf, item, refs + refs_to_add); 2030 btrfs_set_extent_refs(leaf, item, refs + refs_to_add);
2031 if (extent_op) 2031 if (extent_op)
2032 __run_delayed_extent_op(extent_op, leaf, item); 2032 __run_delayed_extent_op(extent_op, leaf, item);
2033 2033
2034 btrfs_mark_buffer_dirty(leaf); 2034 btrfs_mark_buffer_dirty(leaf);
2035 btrfs_release_path(path); 2035 btrfs_release_path(path);
2036 2036
2037 if (!no_quota) { 2037 if (!no_quota) {
2038 ret = btrfs_qgroup_record_ref(trans, fs_info, root_objectid, 2038 ret = btrfs_qgroup_record_ref(trans, fs_info, root_objectid,
2039 bytenr, num_bytes, type, 0); 2039 bytenr, num_bytes, type, 0);
2040 if (ret) 2040 if (ret)
2041 goto out; 2041 goto out;
2042 } 2042 }
2043 2043
2044 path->reada = 1; 2044 path->reada = 1;
2045 path->leave_spinning = 1; 2045 path->leave_spinning = 1;
2046 /* now insert the actual backref */ 2046 /* now insert the actual backref */
2047 ret = insert_extent_backref(trans, root->fs_info->extent_root, 2047 ret = insert_extent_backref(trans, root->fs_info->extent_root,
2048 path, bytenr, parent, root_objectid, 2048 path, bytenr, parent, root_objectid,
2049 owner, offset, refs_to_add); 2049 owner, offset, refs_to_add);
2050 if (ret) 2050 if (ret)
2051 btrfs_abort_transaction(trans, root, ret); 2051 btrfs_abort_transaction(trans, root, ret);
2052 out: 2052 out:
2053 btrfs_free_path(path); 2053 btrfs_free_path(path);
2054 return ret; 2054 return ret;
2055 } 2055 }
2056 2056
2057 static int run_delayed_data_ref(struct btrfs_trans_handle *trans, 2057 static int run_delayed_data_ref(struct btrfs_trans_handle *trans,
2058 struct btrfs_root *root, 2058 struct btrfs_root *root,
2059 struct btrfs_delayed_ref_node *node, 2059 struct btrfs_delayed_ref_node *node,
2060 struct btrfs_delayed_extent_op *extent_op, 2060 struct btrfs_delayed_extent_op *extent_op,
2061 int insert_reserved) 2061 int insert_reserved)
2062 { 2062 {
2063 int ret = 0; 2063 int ret = 0;
2064 struct btrfs_delayed_data_ref *ref; 2064 struct btrfs_delayed_data_ref *ref;
2065 struct btrfs_key ins; 2065 struct btrfs_key ins;
2066 u64 parent = 0; 2066 u64 parent = 0;
2067 u64 ref_root = 0; 2067 u64 ref_root = 0;
2068 u64 flags = 0; 2068 u64 flags = 0;
2069 2069
2070 ins.objectid = node->bytenr; 2070 ins.objectid = node->bytenr;
2071 ins.offset = node->num_bytes; 2071 ins.offset = node->num_bytes;
2072 ins.type = BTRFS_EXTENT_ITEM_KEY; 2072 ins.type = BTRFS_EXTENT_ITEM_KEY;
2073 2073
2074 ref = btrfs_delayed_node_to_data_ref(node); 2074 ref = btrfs_delayed_node_to_data_ref(node);
2075 trace_run_delayed_data_ref(node, ref, node->action); 2075 trace_run_delayed_data_ref(node, ref, node->action);
2076 2076
2077 if (node->type == BTRFS_SHARED_DATA_REF_KEY) 2077 if (node->type == BTRFS_SHARED_DATA_REF_KEY)
2078 parent = ref->parent; 2078 parent = ref->parent;
2079 ref_root = ref->root; 2079 ref_root = ref->root;
2080 2080
2081 if (node->action == BTRFS_ADD_DELAYED_REF && insert_reserved) { 2081 if (node->action == BTRFS_ADD_DELAYED_REF && insert_reserved) {
2082 if (extent_op) 2082 if (extent_op)
2083 flags |= extent_op->flags_to_set; 2083 flags |= extent_op->flags_to_set;
2084 ret = alloc_reserved_file_extent(trans, root, 2084 ret = alloc_reserved_file_extent(trans, root,
2085 parent, ref_root, flags, 2085 parent, ref_root, flags,
2086 ref->objectid, ref->offset, 2086 ref->objectid, ref->offset,
2087 &ins, node->ref_mod); 2087 &ins, node->ref_mod);
2088 } else if (node->action == BTRFS_ADD_DELAYED_REF) { 2088 } else if (node->action == BTRFS_ADD_DELAYED_REF) {
2089 ret = __btrfs_inc_extent_ref(trans, root, node->bytenr, 2089 ret = __btrfs_inc_extent_ref(trans, root, node->bytenr,
2090 node->num_bytes, parent, 2090 node->num_bytes, parent,
2091 ref_root, ref->objectid, 2091 ref_root, ref->objectid,
2092 ref->offset, node->ref_mod, 2092 ref->offset, node->ref_mod,
2093 node->no_quota, extent_op); 2093 node->no_quota, extent_op);
2094 } else if (node->action == BTRFS_DROP_DELAYED_REF) { 2094 } else if (node->action == BTRFS_DROP_DELAYED_REF) {
2095 ret = __btrfs_free_extent(trans, root, node->bytenr, 2095 ret = __btrfs_free_extent(trans, root, node->bytenr,
2096 node->num_bytes, parent, 2096 node->num_bytes, parent,
2097 ref_root, ref->objectid, 2097 ref_root, ref->objectid,
2098 ref->offset, node->ref_mod, 2098 ref->offset, node->ref_mod,
2099 extent_op, node->no_quota); 2099 extent_op, node->no_quota);
2100 } else { 2100 } else {
2101 BUG(); 2101 BUG();
2102 } 2102 }
2103 return ret; 2103 return ret;
2104 } 2104 }
2105 2105
2106 static void __run_delayed_extent_op(struct btrfs_delayed_extent_op *extent_op, 2106 static void __run_delayed_extent_op(struct btrfs_delayed_extent_op *extent_op,
2107 struct extent_buffer *leaf, 2107 struct extent_buffer *leaf,
2108 struct btrfs_extent_item *ei) 2108 struct btrfs_extent_item *ei)
2109 { 2109 {
2110 u64 flags = btrfs_extent_flags(leaf, ei); 2110 u64 flags = btrfs_extent_flags(leaf, ei);
2111 if (extent_op->update_flags) { 2111 if (extent_op->update_flags) {
2112 flags |= extent_op->flags_to_set; 2112 flags |= extent_op->flags_to_set;
2113 btrfs_set_extent_flags(leaf, ei, flags); 2113 btrfs_set_extent_flags(leaf, ei, flags);
2114 } 2114 }
2115 2115
2116 if (extent_op->update_key) { 2116 if (extent_op->update_key) {
2117 struct btrfs_tree_block_info *bi; 2117 struct btrfs_tree_block_info *bi;
2118 BUG_ON(!(flags & BTRFS_EXTENT_FLAG_TREE_BLOCK)); 2118 BUG_ON(!(flags & BTRFS_EXTENT_FLAG_TREE_BLOCK));
2119 bi = (struct btrfs_tree_block_info *)(ei + 1); 2119 bi = (struct btrfs_tree_block_info *)(ei + 1);
2120 btrfs_set_tree_block_key(leaf, bi, &extent_op->key); 2120 btrfs_set_tree_block_key(leaf, bi, &extent_op->key);
2121 } 2121 }
2122 } 2122 }
2123 2123
2124 static int run_delayed_extent_op(struct btrfs_trans_handle *trans, 2124 static int run_delayed_extent_op(struct btrfs_trans_handle *trans,
2125 struct btrfs_root *root, 2125 struct btrfs_root *root,
2126 struct btrfs_delayed_ref_node *node, 2126 struct btrfs_delayed_ref_node *node,
2127 struct btrfs_delayed_extent_op *extent_op) 2127 struct btrfs_delayed_extent_op *extent_op)
2128 { 2128 {
2129 struct btrfs_key key; 2129 struct btrfs_key key;
2130 struct btrfs_path *path; 2130 struct btrfs_path *path;
2131 struct btrfs_extent_item *ei; 2131 struct btrfs_extent_item *ei;
2132 struct extent_buffer *leaf; 2132 struct extent_buffer *leaf;
2133 u32 item_size; 2133 u32 item_size;
2134 int ret; 2134 int ret;
2135 int err = 0; 2135 int err = 0;
2136 int metadata = !extent_op->is_data; 2136 int metadata = !extent_op->is_data;
2137 2137
2138 if (trans->aborted) 2138 if (trans->aborted)
2139 return 0; 2139 return 0;
2140 2140
2141 if (metadata && !btrfs_fs_incompat(root->fs_info, SKINNY_METADATA)) 2141 if (metadata && !btrfs_fs_incompat(root->fs_info, SKINNY_METADATA))
2142 metadata = 0; 2142 metadata = 0;
2143 2143
2144 path = btrfs_alloc_path(); 2144 path = btrfs_alloc_path();
2145 if (!path) 2145 if (!path)
2146 return -ENOMEM; 2146 return -ENOMEM;
2147 2147
2148 key.objectid = node->bytenr; 2148 key.objectid = node->bytenr;
2149 2149
2150 if (metadata) { 2150 if (metadata) {
2151 key.type = BTRFS_METADATA_ITEM_KEY; 2151 key.type = BTRFS_METADATA_ITEM_KEY;
2152 key.offset = extent_op->level; 2152 key.offset = extent_op->level;
2153 } else { 2153 } else {
2154 key.type = BTRFS_EXTENT_ITEM_KEY; 2154 key.type = BTRFS_EXTENT_ITEM_KEY;
2155 key.offset = node->num_bytes; 2155 key.offset = node->num_bytes;
2156 } 2156 }
2157 2157
2158 again: 2158 again:
2159 path->reada = 1; 2159 path->reada = 1;
2160 path->leave_spinning = 1; 2160 path->leave_spinning = 1;
2161 ret = btrfs_search_slot(trans, root->fs_info->extent_root, &key, 2161 ret = btrfs_search_slot(trans, root->fs_info->extent_root, &key,
2162 path, 0, 1); 2162 path, 0, 1);
2163 if (ret < 0) { 2163 if (ret < 0) {
2164 err = ret; 2164 err = ret;
2165 goto out; 2165 goto out;
2166 } 2166 }
2167 if (ret > 0) { 2167 if (ret > 0) {
2168 if (metadata) { 2168 if (metadata) {
2169 if (path->slots[0] > 0) { 2169 if (path->slots[0] > 0) {
2170 path->slots[0]--; 2170 path->slots[0]--;
2171 btrfs_item_key_to_cpu(path->nodes[0], &key, 2171 btrfs_item_key_to_cpu(path->nodes[0], &key,
2172 path->slots[0]); 2172 path->slots[0]);
2173 if (key.objectid == node->bytenr && 2173 if (key.objectid == node->bytenr &&
2174 key.type == BTRFS_EXTENT_ITEM_KEY && 2174 key.type == BTRFS_EXTENT_ITEM_KEY &&
2175 key.offset == node->num_bytes) 2175 key.offset == node->num_bytes)
2176 ret = 0; 2176 ret = 0;
2177 } 2177 }
2178 if (ret > 0) { 2178 if (ret > 0) {
2179 btrfs_release_path(path); 2179 btrfs_release_path(path);
2180 metadata = 0; 2180 metadata = 0;
2181 2181
2182 key.objectid = node->bytenr; 2182 key.objectid = node->bytenr;
2183 key.offset = node->num_bytes; 2183 key.offset = node->num_bytes;
2184 key.type = BTRFS_EXTENT_ITEM_KEY; 2184 key.type = BTRFS_EXTENT_ITEM_KEY;
2185 goto again; 2185 goto again;
2186 } 2186 }
2187 } else { 2187 } else {
2188 err = -EIO; 2188 err = -EIO;
2189 goto out; 2189 goto out;
2190 } 2190 }
2191 } 2191 }
2192 2192
2193 leaf = path->nodes[0]; 2193 leaf = path->nodes[0];
2194 item_size = btrfs_item_size_nr(leaf, path->slots[0]); 2194 item_size = btrfs_item_size_nr(leaf, path->slots[0]);
2195 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0 2195 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
2196 if (item_size < sizeof(*ei)) { 2196 if (item_size < sizeof(*ei)) {
2197 ret = convert_extent_item_v0(trans, root->fs_info->extent_root, 2197 ret = convert_extent_item_v0(trans, root->fs_info->extent_root,
2198 path, (u64)-1, 0); 2198 path, (u64)-1, 0);
2199 if (ret < 0) { 2199 if (ret < 0) {
2200 err = ret; 2200 err = ret;
2201 goto out; 2201 goto out;
2202 } 2202 }
2203 leaf = path->nodes[0]; 2203 leaf = path->nodes[0];
2204 item_size = btrfs_item_size_nr(leaf, path->slots[0]); 2204 item_size = btrfs_item_size_nr(leaf, path->slots[0]);
2205 } 2205 }
2206 #endif 2206 #endif
2207 BUG_ON(item_size < sizeof(*ei)); 2207 BUG_ON(item_size < sizeof(*ei));
2208 ei = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_extent_item); 2208 ei = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_extent_item);
2209 __run_delayed_extent_op(extent_op, leaf, ei); 2209 __run_delayed_extent_op(extent_op, leaf, ei);
2210 2210
2211 btrfs_mark_buffer_dirty(leaf); 2211 btrfs_mark_buffer_dirty(leaf);
2212 out: 2212 out:
2213 btrfs_free_path(path); 2213 btrfs_free_path(path);
2214 return err; 2214 return err;
2215 } 2215 }
2216 2216
2217 static int run_delayed_tree_ref(struct btrfs_trans_handle *trans, 2217 static int run_delayed_tree_ref(struct btrfs_trans_handle *trans,
2218 struct btrfs_root *root, 2218 struct btrfs_root *root,
2219 struct btrfs_delayed_ref_node *node, 2219 struct btrfs_delayed_ref_node *node,
2220 struct btrfs_delayed_extent_op *extent_op, 2220 struct btrfs_delayed_extent_op *extent_op,
2221 int insert_reserved) 2221 int insert_reserved)
2222 { 2222 {
2223 int ret = 0; 2223 int ret = 0;
2224 struct btrfs_delayed_tree_ref *ref; 2224 struct btrfs_delayed_tree_ref *ref;
2225 struct btrfs_key ins; 2225 struct btrfs_key ins;
2226 u64 parent = 0; 2226 u64 parent = 0;
2227 u64 ref_root = 0; 2227 u64 ref_root = 0;
2228 bool skinny_metadata = btrfs_fs_incompat(root->fs_info, 2228 bool skinny_metadata = btrfs_fs_incompat(root->fs_info,
2229 SKINNY_METADATA); 2229 SKINNY_METADATA);
2230 2230
2231 ref = btrfs_delayed_node_to_tree_ref(node); 2231 ref = btrfs_delayed_node_to_tree_ref(node);
2232 trace_run_delayed_tree_ref(node, ref, node->action); 2232 trace_run_delayed_tree_ref(node, ref, node->action);
2233 2233
2234 if (node->type == BTRFS_SHARED_BLOCK_REF_KEY) 2234 if (node->type == BTRFS_SHARED_BLOCK_REF_KEY)
2235 parent = ref->parent; 2235 parent = ref->parent;
2236 ref_root = ref->root; 2236 ref_root = ref->root;
2237 2237
2238 ins.objectid = node->bytenr; 2238 ins.objectid = node->bytenr;
2239 if (skinny_metadata) { 2239 if (skinny_metadata) {
2240 ins.offset = ref->level; 2240 ins.offset = ref->level;
2241 ins.type = BTRFS_METADATA_ITEM_KEY; 2241 ins.type = BTRFS_METADATA_ITEM_KEY;
2242 } else { 2242 } else {
2243 ins.offset = node->num_bytes; 2243 ins.offset = node->num_bytes;
2244 ins.type = BTRFS_EXTENT_ITEM_KEY; 2244 ins.type = BTRFS_EXTENT_ITEM_KEY;
2245 } 2245 }
2246 2246
2247 BUG_ON(node->ref_mod != 1); 2247 BUG_ON(node->ref_mod != 1);
2248 if (node->action == BTRFS_ADD_DELAYED_REF && insert_reserved) { 2248 if (node->action == BTRFS_ADD_DELAYED_REF && insert_reserved) {
2249 BUG_ON(!extent_op || !extent_op->update_flags); 2249 BUG_ON(!extent_op || !extent_op->update_flags);
2250 ret = alloc_reserved_tree_block(trans, root, 2250 ret = alloc_reserved_tree_block(trans, root,
2251 parent, ref_root, 2251 parent, ref_root,
2252 extent_op->flags_to_set, 2252 extent_op->flags_to_set,
2253 &extent_op->key, 2253 &extent_op->key,
2254 ref->level, &ins, 2254 ref->level, &ins,
2255 node->no_quota); 2255 node->no_quota);
2256 } else if (node->action == BTRFS_ADD_DELAYED_REF) { 2256 } else if (node->action == BTRFS_ADD_DELAYED_REF) {
2257 ret = __btrfs_inc_extent_ref(trans, root, node->bytenr, 2257 ret = __btrfs_inc_extent_ref(trans, root, node->bytenr,
2258 node->num_bytes, parent, ref_root, 2258 node->num_bytes, parent, ref_root,
2259 ref->level, 0, 1, node->no_quota, 2259 ref->level, 0, 1, node->no_quota,
2260 extent_op); 2260 extent_op);
2261 } else if (node->action == BTRFS_DROP_DELAYED_REF) { 2261 } else if (node->action == BTRFS_DROP_DELAYED_REF) {
2262 ret = __btrfs_free_extent(trans, root, node->bytenr, 2262 ret = __btrfs_free_extent(trans, root, node->bytenr,
2263 node->num_bytes, parent, ref_root, 2263 node->num_bytes, parent, ref_root,
2264 ref->level, 0, 1, extent_op, 2264 ref->level, 0, 1, extent_op,
2265 node->no_quota); 2265 node->no_quota);
2266 } else { 2266 } else {
2267 BUG(); 2267 BUG();
2268 } 2268 }
2269 return ret; 2269 return ret;
2270 } 2270 }
2271 2271
2272 /* helper function to actually process a single delayed ref entry */ 2272 /* helper function to actually process a single delayed ref entry */
2273 static int run_one_delayed_ref(struct btrfs_trans_handle *trans, 2273 static int run_one_delayed_ref(struct btrfs_trans_handle *trans,
2274 struct btrfs_root *root, 2274 struct btrfs_root *root,
2275 struct btrfs_delayed_ref_node *node, 2275 struct btrfs_delayed_ref_node *node,
2276 struct btrfs_delayed_extent_op *extent_op, 2276 struct btrfs_delayed_extent_op *extent_op,
2277 int insert_reserved) 2277 int insert_reserved)
2278 { 2278 {
2279 int ret = 0; 2279 int ret = 0;
2280 2280
2281 if (trans->aborted) { 2281 if (trans->aborted) {
2282 if (insert_reserved) 2282 if (insert_reserved)
2283 btrfs_pin_extent(root, node->bytenr, 2283 btrfs_pin_extent(root, node->bytenr,
2284 node->num_bytes, 1); 2284 node->num_bytes, 1);
2285 return 0; 2285 return 0;
2286 } 2286 }
2287 2287
2288 if (btrfs_delayed_ref_is_head(node)) { 2288 if (btrfs_delayed_ref_is_head(node)) {
2289 struct btrfs_delayed_ref_head *head; 2289 struct btrfs_delayed_ref_head *head;
2290 /* 2290 /*
2291 * we've hit the end of the chain and we were supposed 2291 * we've hit the end of the chain and we were supposed
2292 * to insert this extent into the tree. But, it got 2292 * to insert this extent into the tree. But, it got
2293 * deleted before we ever needed to insert it, so all 2293 * deleted before we ever needed to insert it, so all
2294 * we have to do is clean up the accounting 2294 * we have to do is clean up the accounting
2295 */ 2295 */
2296 BUG_ON(extent_op); 2296 BUG_ON(extent_op);
2297 head = btrfs_delayed_node_to_head(node); 2297 head = btrfs_delayed_node_to_head(node);
2298 trace_run_delayed_ref_head(node, head, node->action); 2298 trace_run_delayed_ref_head(node, head, node->action);
2299 2299
2300 if (insert_reserved) { 2300 if (insert_reserved) {
2301 btrfs_pin_extent(root, node->bytenr, 2301 btrfs_pin_extent(root, node->bytenr,
2302 node->num_bytes, 1); 2302 node->num_bytes, 1);
2303 if (head->is_data) { 2303 if (head->is_data) {
2304 ret = btrfs_del_csums(trans, root, 2304 ret = btrfs_del_csums(trans, root,
2305 node->bytenr, 2305 node->bytenr,
2306 node->num_bytes); 2306 node->num_bytes);
2307 } 2307 }
2308 } 2308 }
2309 return ret; 2309 return ret;
2310 } 2310 }
2311 2311
2312 if (node->type == BTRFS_TREE_BLOCK_REF_KEY || 2312 if (node->type == BTRFS_TREE_BLOCK_REF_KEY ||
2313 node->type == BTRFS_SHARED_BLOCK_REF_KEY) 2313 node->type == BTRFS_SHARED_BLOCK_REF_KEY)
2314 ret = run_delayed_tree_ref(trans, root, node, extent_op, 2314 ret = run_delayed_tree_ref(trans, root, node, extent_op,
2315 insert_reserved); 2315 insert_reserved);
2316 else if (node->type == BTRFS_EXTENT_DATA_REF_KEY || 2316 else if (node->type == BTRFS_EXTENT_DATA_REF_KEY ||
2317 node->type == BTRFS_SHARED_DATA_REF_KEY) 2317 node->type == BTRFS_SHARED_DATA_REF_KEY)
2318 ret = run_delayed_data_ref(trans, root, node, extent_op, 2318 ret = run_delayed_data_ref(trans, root, node, extent_op,
2319 insert_reserved); 2319 insert_reserved);
2320 else 2320 else
2321 BUG(); 2321 BUG();
2322 return ret; 2322 return ret;
2323 } 2323 }
2324 2324
2325 static noinline struct btrfs_delayed_ref_node * 2325 static noinline struct btrfs_delayed_ref_node *
2326 select_delayed_ref(struct btrfs_delayed_ref_head *head) 2326 select_delayed_ref(struct btrfs_delayed_ref_head *head)
2327 { 2327 {
2328 struct rb_node *node; 2328 struct rb_node *node;
2329 struct btrfs_delayed_ref_node *ref, *last = NULL;; 2329 struct btrfs_delayed_ref_node *ref, *last = NULL;;
2330 2330
2331 /* 2331 /*
2332 * select delayed ref of type BTRFS_ADD_DELAYED_REF first. 2332 * select delayed ref of type BTRFS_ADD_DELAYED_REF first.
2333 * this prevents ref count from going down to zero when 2333 * this prevents ref count from going down to zero when
2334 * there still are pending delayed ref. 2334 * there still are pending delayed ref.
2335 */ 2335 */
2336 node = rb_first(&head->ref_root); 2336 node = rb_first(&head->ref_root);
2337 while (node) { 2337 while (node) {
2338 ref = rb_entry(node, struct btrfs_delayed_ref_node, 2338 ref = rb_entry(node, struct btrfs_delayed_ref_node,
2339 rb_node); 2339 rb_node);
2340 if (ref->action == BTRFS_ADD_DELAYED_REF) 2340 if (ref->action == BTRFS_ADD_DELAYED_REF)
2341 return ref; 2341 return ref;
2342 else if (last == NULL) 2342 else if (last == NULL)
2343 last = ref; 2343 last = ref;
2344 node = rb_next(node); 2344 node = rb_next(node);
2345 } 2345 }
2346 return last; 2346 return last;
2347 } 2347 }
2348 2348
2349 /* 2349 /*
2350 * Returns 0 on success or if called with an already aborted transaction. 2350 * Returns 0 on success or if called with an already aborted transaction.
2351 * Returns -ENOMEM or -EIO on failure and will abort the transaction. 2351 * Returns -ENOMEM or -EIO on failure and will abort the transaction.
2352 */ 2352 */
2353 static noinline int __btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, 2353 static noinline int __btrfs_run_delayed_refs(struct btrfs_trans_handle *trans,
2354 struct btrfs_root *root, 2354 struct btrfs_root *root,
2355 unsigned long nr) 2355 unsigned long nr)
2356 { 2356 {
2357 struct btrfs_delayed_ref_root *delayed_refs; 2357 struct btrfs_delayed_ref_root *delayed_refs;
2358 struct btrfs_delayed_ref_node *ref; 2358 struct btrfs_delayed_ref_node *ref;
2359 struct btrfs_delayed_ref_head *locked_ref = NULL; 2359 struct btrfs_delayed_ref_head *locked_ref = NULL;
2360 struct btrfs_delayed_extent_op *extent_op; 2360 struct btrfs_delayed_extent_op *extent_op;
2361 struct btrfs_fs_info *fs_info = root->fs_info; 2361 struct btrfs_fs_info *fs_info = root->fs_info;
2362 ktime_t start = ktime_get(); 2362 ktime_t start = ktime_get();
2363 int ret; 2363 int ret;
2364 unsigned long count = 0; 2364 unsigned long count = 0;
2365 unsigned long actual_count = 0; 2365 unsigned long actual_count = 0;
2366 int must_insert_reserved = 0; 2366 int must_insert_reserved = 0;
2367 2367
2368 delayed_refs = &trans->transaction->delayed_refs; 2368 delayed_refs = &trans->transaction->delayed_refs;
2369 while (1) { 2369 while (1) {
2370 if (!locked_ref) { 2370 if (!locked_ref) {
2371 if (count >= nr) 2371 if (count >= nr)
2372 break; 2372 break;
2373 2373
2374 spin_lock(&delayed_refs->lock); 2374 spin_lock(&delayed_refs->lock);
2375 locked_ref = btrfs_select_ref_head(trans); 2375 locked_ref = btrfs_select_ref_head(trans);
2376 if (!locked_ref) { 2376 if (!locked_ref) {
2377 spin_unlock(&delayed_refs->lock); 2377 spin_unlock(&delayed_refs->lock);
2378 break; 2378 break;
2379 } 2379 }
2380 2380
2381 /* grab the lock that says we are going to process 2381 /* grab the lock that says we are going to process
2382 * all the refs for this head */ 2382 * all the refs for this head */
2383 ret = btrfs_delayed_ref_lock(trans, locked_ref); 2383 ret = btrfs_delayed_ref_lock(trans, locked_ref);
2384 spin_unlock(&delayed_refs->lock); 2384 spin_unlock(&delayed_refs->lock);
2385 /* 2385 /*
2386 * we may have dropped the spin lock to get the head 2386 * we may have dropped the spin lock to get the head
2387 * mutex lock, and that might have given someone else 2387 * mutex lock, and that might have given someone else
2388 * time to free the head. If that's true, it has been 2388 * time to free the head. If that's true, it has been
2389 * removed from our list and we can move on. 2389 * removed from our list and we can move on.
2390 */ 2390 */
2391 if (ret == -EAGAIN) { 2391 if (ret == -EAGAIN) {
2392 locked_ref = NULL; 2392 locked_ref = NULL;
2393 count++; 2393 count++;
2394 continue; 2394 continue;
2395 } 2395 }
2396 } 2396 }
2397 2397
2398 /* 2398 /*
2399 * We need to try and merge add/drops of the same ref since we 2399 * We need to try and merge add/drops of the same ref since we
2400 * can run into issues with relocate dropping the implicit ref 2400 * can run into issues with relocate dropping the implicit ref
2401 * and then it being added back again before the drop can 2401 * and then it being added back again before the drop can
2402 * finish. If we merged anything we need to re-loop so we can 2402 * finish. If we merged anything we need to re-loop so we can
2403 * get a good ref. 2403 * get a good ref.
2404 */ 2404 */
2405 spin_lock(&locked_ref->lock); 2405 spin_lock(&locked_ref->lock);
2406 btrfs_merge_delayed_refs(trans, fs_info, delayed_refs, 2406 btrfs_merge_delayed_refs(trans, fs_info, delayed_refs,
2407 locked_ref); 2407 locked_ref);
2408 2408
2409 /* 2409 /*
2410 * locked_ref is the head node, so we have to go one 2410 * locked_ref is the head node, so we have to go one
2411 * node back for any delayed ref updates 2411 * node back for any delayed ref updates
2412 */ 2412 */
2413 ref = select_delayed_ref(locked_ref); 2413 ref = select_delayed_ref(locked_ref);
2414 2414
2415 if (ref && ref->seq && 2415 if (ref && ref->seq &&
2416 btrfs_check_delayed_seq(fs_info, delayed_refs, ref->seq)) { 2416 btrfs_check_delayed_seq(fs_info, delayed_refs, ref->seq)) {
2417 spin_unlock(&locked_ref->lock); 2417 spin_unlock(&locked_ref->lock);
2418 btrfs_delayed_ref_unlock(locked_ref); 2418 btrfs_delayed_ref_unlock(locked_ref);
2419 spin_lock(&delayed_refs->lock); 2419 spin_lock(&delayed_refs->lock);
2420 locked_ref->processing = 0; 2420 locked_ref->processing = 0;
2421 delayed_refs->num_heads_ready++; 2421 delayed_refs->num_heads_ready++;
2422 spin_unlock(&delayed_refs->lock); 2422 spin_unlock(&delayed_refs->lock);
2423 locked_ref = NULL; 2423 locked_ref = NULL;
2424 cond_resched(); 2424 cond_resched();
2425 count++; 2425 count++;
2426 continue; 2426 continue;
2427 } 2427 }
2428 2428
2429 /* 2429 /*
2430 * record the must insert reserved flag before we 2430 * record the must insert reserved flag before we
2431 * drop the spin lock. 2431 * drop the spin lock.
2432 */ 2432 */
2433 must_insert_reserved = locked_ref->must_insert_reserved; 2433 must_insert_reserved = locked_ref->must_insert_reserved;
2434 locked_ref->must_insert_reserved = 0; 2434 locked_ref->must_insert_reserved = 0;
2435 2435
2436 extent_op = locked_ref->extent_op; 2436 extent_op = locked_ref->extent_op;
2437 locked_ref->extent_op = NULL; 2437 locked_ref->extent_op = NULL;
2438 2438
2439 if (!ref) { 2439 if (!ref) {
2440 2440
2441 2441
2442 /* All delayed refs have been processed, Go ahead 2442 /* All delayed refs have been processed, Go ahead
2443 * and send the head node to run_one_delayed_ref, 2443 * and send the head node to run_one_delayed_ref,
2444 * so that any accounting fixes can happen 2444 * so that any accounting fixes can happen
2445 */ 2445 */
2446 ref = &locked_ref->node; 2446 ref = &locked_ref->node;
2447 2447
2448 if (extent_op && must_insert_reserved) { 2448 if (extent_op && must_insert_reserved) {
2449 btrfs_free_delayed_extent_op(extent_op); 2449 btrfs_free_delayed_extent_op(extent_op);
2450 extent_op = NULL; 2450 extent_op = NULL;
2451 } 2451 }
2452 2452
2453 if (extent_op) { 2453 if (extent_op) {
2454 spin_unlock(&locked_ref->lock); 2454 spin_unlock(&locked_ref->lock);
2455 ret = run_delayed_extent_op(trans, root, 2455 ret = run_delayed_extent_op(trans, root,
2456 ref, extent_op); 2456 ref, extent_op);
2457 btrfs_free_delayed_extent_op(extent_op); 2457 btrfs_free_delayed_extent_op(extent_op);
2458 2458
2459 if (ret) { 2459 if (ret) {
2460 /* 2460 /*
2461 * Need to reset must_insert_reserved if 2461 * Need to reset must_insert_reserved if
2462 * there was an error so the abort stuff 2462 * there was an error so the abort stuff
2463 * can cleanup the reserved space 2463 * can cleanup the reserved space
2464 * properly. 2464 * properly.
2465 */ 2465 */
2466 if (must_insert_reserved) 2466 if (must_insert_reserved)
2467 locked_ref->must_insert_reserved = 1; 2467 locked_ref->must_insert_reserved = 1;
2468 locked_ref->processing = 0; 2468 locked_ref->processing = 0;
2469 btrfs_debug(fs_info, "run_delayed_extent_op returned %d", ret); 2469 btrfs_debug(fs_info, "run_delayed_extent_op returned %d", ret);
2470 btrfs_delayed_ref_unlock(locked_ref); 2470 btrfs_delayed_ref_unlock(locked_ref);
2471 return ret; 2471 return ret;
2472 } 2472 }
2473 continue; 2473 continue;
2474 } 2474 }
2475 2475
2476 /* 2476 /*
2477 * Need to drop our head ref lock and re-aqcuire the 2477 * Need to drop our head ref lock and re-aqcuire the
2478 * delayed ref lock and then re-check to make sure 2478 * delayed ref lock and then re-check to make sure
2479 * nobody got added. 2479 * nobody got added.
2480 */ 2480 */
2481 spin_unlock(&locked_ref->lock); 2481 spin_unlock(&locked_ref->lock);
2482 spin_lock(&delayed_refs->lock); 2482 spin_lock(&delayed_refs->lock);
2483 spin_lock(&locked_ref->lock); 2483 spin_lock(&locked_ref->lock);
2484 if (rb_first(&locked_ref->ref_root) || 2484 if (rb_first(&locked_ref->ref_root) ||
2485 locked_ref->extent_op) { 2485 locked_ref->extent_op) {
2486 spin_unlock(&locked_ref->lock); 2486 spin_unlock(&locked_ref->lock);
2487 spin_unlock(&delayed_refs->lock); 2487 spin_unlock(&delayed_refs->lock);
2488 continue; 2488 continue;
2489 } 2489 }
2490 ref->in_tree = 0; 2490 ref->in_tree = 0;
2491 delayed_refs->num_heads--; 2491 delayed_refs->num_heads--;
2492 rb_erase(&locked_ref->href_node, 2492 rb_erase(&locked_ref->href_node,
2493 &delayed_refs->href_root); 2493 &delayed_refs->href_root);
2494 spin_unlock(&delayed_refs->lock); 2494 spin_unlock(&delayed_refs->lock);
2495 } else { 2495 } else {
2496 actual_count++; 2496 actual_count++;
2497 ref->in_tree = 0; 2497 ref->in_tree = 0;
2498 rb_erase(&ref->rb_node, &locked_ref->ref_root); 2498 rb_erase(&ref->rb_node, &locked_ref->ref_root);
2499 } 2499 }
2500 atomic_dec(&delayed_refs->num_entries); 2500 atomic_dec(&delayed_refs->num_entries);
2501 2501
2502 if (!btrfs_delayed_ref_is_head(ref)) { 2502 if (!btrfs_delayed_ref_is_head(ref)) {
2503 /* 2503 /*
2504 * when we play the delayed ref, also correct the 2504 * when we play the delayed ref, also correct the
2505 * ref_mod on head 2505 * ref_mod on head
2506 */ 2506 */
2507 switch (ref->action) { 2507 switch (ref->action) {
2508 case BTRFS_ADD_DELAYED_REF: 2508 case BTRFS_ADD_DELAYED_REF:
2509 case BTRFS_ADD_DELAYED_EXTENT: 2509 case BTRFS_ADD_DELAYED_EXTENT:
2510 locked_ref->node.ref_mod -= ref->ref_mod; 2510 locked_ref->node.ref_mod -= ref->ref_mod;
2511 break; 2511 break;
2512 case BTRFS_DROP_DELAYED_REF: 2512 case BTRFS_DROP_DELAYED_REF:
2513 locked_ref->node.ref_mod += ref->ref_mod; 2513 locked_ref->node.ref_mod += ref->ref_mod;
2514 break; 2514 break;
2515 default: 2515 default:
2516 WARN_ON(1); 2516 WARN_ON(1);
2517 } 2517 }
2518 } 2518 }
2519 spin_unlock(&locked_ref->lock); 2519 spin_unlock(&locked_ref->lock);
2520 2520
2521 ret = run_one_delayed_ref(trans, root, ref, extent_op, 2521 ret = run_one_delayed_ref(trans, root, ref, extent_op,
2522 must_insert_reserved); 2522 must_insert_reserved);
2523 2523
2524 btrfs_free_delayed_extent_op(extent_op); 2524 btrfs_free_delayed_extent_op(extent_op);
2525 if (ret) { 2525 if (ret) {
2526 locked_ref->processing = 0; 2526 locked_ref->processing = 0;
2527 btrfs_delayed_ref_unlock(locked_ref); 2527 btrfs_delayed_ref_unlock(locked_ref);
2528 btrfs_put_delayed_ref(ref); 2528 btrfs_put_delayed_ref(ref);
2529 btrfs_debug(fs_info, "run_one_delayed_ref returned %d", ret); 2529 btrfs_debug(fs_info, "run_one_delayed_ref returned %d", ret);
2530 return ret; 2530 return ret;
2531 } 2531 }
2532 2532
2533 /* 2533 /*
2534 * If this node is a head, that means all the refs in this head 2534 * If this node is a head, that means all the refs in this head
2535 * have been dealt with, and we will pick the next head to deal 2535 * have been dealt with, and we will pick the next head to deal
2536 * with, so we must unlock the head and drop it from the cluster 2536 * with, so we must unlock the head and drop it from the cluster
2537 * list before we release it. 2537 * list before we release it.
2538 */ 2538 */
2539 if (btrfs_delayed_ref_is_head(ref)) { 2539 if (btrfs_delayed_ref_is_head(ref)) {
2540 btrfs_delayed_ref_unlock(locked_ref); 2540 btrfs_delayed_ref_unlock(locked_ref);
2541 locked_ref = NULL; 2541 locked_ref = NULL;
2542 } 2542 }
2543 btrfs_put_delayed_ref(ref); 2543 btrfs_put_delayed_ref(ref);
2544 count++; 2544 count++;
2545 cond_resched(); 2545 cond_resched();
2546 } 2546 }
2547 2547
2548 /* 2548 /*
2549 * We don't want to include ref heads since we can have empty ref heads 2549 * We don't want to include ref heads since we can have empty ref heads
2550 * and those will drastically skew our runtime down since we just do 2550 * and those will drastically skew our runtime down since we just do
2551 * accounting, no actual extent tree updates. 2551 * accounting, no actual extent tree updates.
2552 */ 2552 */
2553 if (actual_count > 0) { 2553 if (actual_count > 0) {
2554 u64 runtime = ktime_to_ns(ktime_sub(ktime_get(), start)); 2554 u64 runtime = ktime_to_ns(ktime_sub(ktime_get(), start));
2555 u64 avg; 2555 u64 avg;
2556 2556
2557 /* 2557 /*
2558 * We weigh the current average higher than our current runtime 2558 * We weigh the current average higher than our current runtime
2559 * to avoid large swings in the average. 2559 * to avoid large swings in the average.
2560 */ 2560 */
2561 spin_lock(&delayed_refs->lock); 2561 spin_lock(&delayed_refs->lock);
2562 avg = fs_info->avg_delayed_ref_runtime * 3 + runtime; 2562 avg = fs_info->avg_delayed_ref_runtime * 3 + runtime;
2563 avg = div64_u64(avg, 4); 2563 avg = div64_u64(avg, 4);
2564 fs_info->avg_delayed_ref_runtime = avg; 2564 fs_info->avg_delayed_ref_runtime = avg;
2565 spin_unlock(&delayed_refs->lock); 2565 spin_unlock(&delayed_refs->lock);
2566 } 2566 }
2567 return 0; 2567 return 0;
2568 } 2568 }
2569 2569
2570 #ifdef SCRAMBLE_DELAYED_REFS 2570 #ifdef SCRAMBLE_DELAYED_REFS
2571 /* 2571 /*
2572 * Normally delayed refs get processed in ascending bytenr order. This 2572 * Normally delayed refs get processed in ascending bytenr order. This
2573 * correlates in most cases to the order added. To expose dependencies on this 2573 * correlates in most cases to the order added. To expose dependencies on this
2574 * order, we start to process the tree in the middle instead of the beginning 2574 * order, we start to process the tree in the middle instead of the beginning
2575 */ 2575 */
2576 static u64 find_middle(struct rb_root *root) 2576 static u64 find_middle(struct rb_root *root)
2577 { 2577 {
2578 struct rb_node *n = root->rb_node; 2578 struct rb_node *n = root->rb_node;
2579 struct btrfs_delayed_ref_node *entry; 2579 struct btrfs_delayed_ref_node *entry;
2580 int alt = 1; 2580 int alt = 1;
2581 u64 middle; 2581 u64 middle;
2582 u64 first = 0, last = 0; 2582 u64 first = 0, last = 0;
2583 2583
2584 n = rb_first(root); 2584 n = rb_first(root);
2585 if (n) { 2585 if (n) {
2586 entry = rb_entry(n, struct btrfs_delayed_ref_node, rb_node); 2586 entry = rb_entry(n, struct btrfs_delayed_ref_node, rb_node);
2587 first = entry->bytenr; 2587 first = entry->bytenr;
2588 } 2588 }
2589 n = rb_last(root); 2589 n = rb_last(root);
2590 if (n) { 2590 if (n) {
2591 entry = rb_entry(n, struct btrfs_delayed_ref_node, rb_node); 2591 entry = rb_entry(n, struct btrfs_delayed_ref_node, rb_node);
2592 last = entry->bytenr; 2592 last = entry->bytenr;
2593 } 2593 }
2594 n = root->rb_node; 2594 n = root->rb_node;
2595 2595
2596 while (n) { 2596 while (n) {
2597 entry = rb_entry(n, struct btrfs_delayed_ref_node, rb_node); 2597 entry = rb_entry(n, struct btrfs_delayed_ref_node, rb_node);
2598 WARN_ON(!entry->in_tree); 2598 WARN_ON(!entry->in_tree);
2599 2599
2600 middle = entry->bytenr; 2600 middle = entry->bytenr;
2601 2601
2602 if (alt) 2602 if (alt)
2603 n = n->rb_left; 2603 n = n->rb_left;
2604 else 2604 else
2605 n = n->rb_right; 2605 n = n->rb_right;
2606 2606
2607 alt = 1 - alt; 2607 alt = 1 - alt;
2608 } 2608 }
2609 return middle; 2609 return middle;
2610 } 2610 }
2611 #endif 2611 #endif
2612 2612
2613 static inline u64 heads_to_leaves(struct btrfs_root *root, u64 heads) 2613 static inline u64 heads_to_leaves(struct btrfs_root *root, u64 heads)
2614 { 2614 {
2615 u64 num_bytes; 2615 u64 num_bytes;
2616 2616
2617 num_bytes = heads * (sizeof(struct btrfs_extent_item) + 2617 num_bytes = heads * (sizeof(struct btrfs_extent_item) +
2618 sizeof(struct btrfs_extent_inline_ref)); 2618 sizeof(struct btrfs_extent_inline_ref));
2619 if (!btrfs_fs_incompat(root->fs_info, SKINNY_METADATA)) 2619 if (!btrfs_fs_incompat(root->fs_info, SKINNY_METADATA))
2620 num_bytes += heads * sizeof(struct btrfs_tree_block_info); 2620 num_bytes += heads * sizeof(struct btrfs_tree_block_info);
2621 2621
2622 /* 2622 /*
2623 * We don't ever fill up leaves all the way so multiply by 2 just to be 2623 * We don't ever fill up leaves all the way so multiply by 2 just to be
2624 * closer to what we're really going to want to ouse. 2624 * closer to what we're really going to want to ouse.
2625 */ 2625 */
2626 return div64_u64(num_bytes, BTRFS_LEAF_DATA_SIZE(root)); 2626 return div64_u64(num_bytes, BTRFS_LEAF_DATA_SIZE(root));
2627 } 2627 }
2628 2628
2629 int btrfs_check_space_for_delayed_refs(struct btrfs_trans_handle *trans, 2629 int btrfs_check_space_for_delayed_refs(struct btrfs_trans_handle *trans,
2630 struct btrfs_root *root) 2630 struct btrfs_root *root)
2631 { 2631 {
2632 struct btrfs_block_rsv *global_rsv; 2632 struct btrfs_block_rsv *global_rsv;
2633 u64 num_heads = trans->transaction->delayed_refs.num_heads_ready; 2633 u64 num_heads = trans->transaction->delayed_refs.num_heads_ready;
2634 u64 num_bytes; 2634 u64 num_bytes;
2635 int ret = 0; 2635 int ret = 0;
2636 2636
2637 num_bytes = btrfs_calc_trans_metadata_size(root, 1); 2637 num_bytes = btrfs_calc_trans_metadata_size(root, 1);
2638 num_heads = heads_to_leaves(root, num_heads); 2638 num_heads = heads_to_leaves(root, num_heads);
2639 if (num_heads > 1) 2639 if (num_heads > 1)
2640 num_bytes += (num_heads - 1) * root->nodesize; 2640 num_bytes += (num_heads - 1) * root->nodesize;
2641 num_bytes <<= 1; 2641 num_bytes <<= 1;
2642 global_rsv = &root->fs_info->global_block_rsv; 2642 global_rsv = &root->fs_info->global_block_rsv;
2643 2643
2644 /* 2644 /*
2645 * If we can't allocate any more chunks lets make sure we have _lots_ of 2645 * If we can't allocate any more chunks lets make sure we have _lots_ of
2646 * wiggle room since running delayed refs can create more delayed refs. 2646 * wiggle room since running delayed refs can create more delayed refs.
2647 */ 2647 */
2648 if (global_rsv->space_info->full) 2648 if (global_rsv->space_info->full)
2649 num_bytes <<= 1; 2649 num_bytes <<= 1;
2650 2650
2651 spin_lock(&global_rsv->lock); 2651 spin_lock(&global_rsv->lock);
2652 if (global_rsv->reserved <= num_bytes) 2652 if (global_rsv->reserved <= num_bytes)
2653 ret = 1; 2653 ret = 1;
2654 spin_unlock(&global_rsv->lock); 2654 spin_unlock(&global_rsv->lock);
2655 return ret; 2655 return ret;
2656 } 2656 }
2657 2657
2658 int btrfs_should_throttle_delayed_refs(struct btrfs_trans_handle *trans, 2658 int btrfs_should_throttle_delayed_refs(struct btrfs_trans_handle *trans,
2659 struct btrfs_root *root) 2659 struct btrfs_root *root)
2660 { 2660 {
2661 struct btrfs_fs_info *fs_info = root->fs_info; 2661 struct btrfs_fs_info *fs_info = root->fs_info;
2662 u64 num_entries = 2662 u64 num_entries =
2663 atomic_read(&trans->transaction->delayed_refs.num_entries); 2663 atomic_read(&trans->transaction->delayed_refs.num_entries);
2664 u64 avg_runtime; 2664 u64 avg_runtime;
2665 u64 val; 2665 u64 val;
2666 2666
2667 smp_mb(); 2667 smp_mb();
2668 avg_runtime = fs_info->avg_delayed_ref_runtime; 2668 avg_runtime = fs_info->avg_delayed_ref_runtime;
2669 val = num_entries * avg_runtime; 2669 val = num_entries * avg_runtime;
2670 if (num_entries * avg_runtime >= NSEC_PER_SEC) 2670 if (num_entries * avg_runtime >= NSEC_PER_SEC)
2671 return 1; 2671 return 1;
2672 if (val >= NSEC_PER_SEC / 2) 2672 if (val >= NSEC_PER_SEC / 2)
2673 return 2; 2673 return 2;
2674 2674
2675 return btrfs_check_space_for_delayed_refs(trans, root); 2675 return btrfs_check_space_for_delayed_refs(trans, root);
2676 } 2676 }
2677 2677
2678 struct async_delayed_refs { 2678 struct async_delayed_refs {
2679 struct btrfs_root *root; 2679 struct btrfs_root *root;
2680 int count; 2680 int count;
2681 int error; 2681 int error;
2682 int sync; 2682 int sync;
2683 struct completion wait; 2683 struct completion wait;
2684 struct btrfs_work work; 2684 struct btrfs_work work;
2685 }; 2685 };
2686 2686
2687 static void delayed_ref_async_start(struct btrfs_work *work) 2687 static void delayed_ref_async_start(struct btrfs_work *work)
2688 { 2688 {
2689 struct async_delayed_refs *async; 2689 struct async_delayed_refs *async;
2690 struct btrfs_trans_handle *trans; 2690 struct btrfs_trans_handle *trans;
2691 int ret; 2691 int ret;
2692 2692
2693 async = container_of(work, struct async_delayed_refs, work); 2693 async = container_of(work, struct async_delayed_refs, work);
2694 2694
2695 trans = btrfs_join_transaction(async->root); 2695 trans = btrfs_join_transaction(async->root);
2696 if (IS_ERR(trans)) { 2696 if (IS_ERR(trans)) {
2697 async->error = PTR_ERR(trans); 2697 async->error = PTR_ERR(trans);
2698 goto done; 2698 goto done;
2699 } 2699 }
2700 2700
2701 /* 2701 /*
2702 * trans->sync means that when we call end_transaciton, we won't 2702 * trans->sync means that when we call end_transaciton, we won't
2703 * wait on delayed refs 2703 * wait on delayed refs
2704 */ 2704 */
2705 trans->sync = true; 2705 trans->sync = true;
2706 ret = btrfs_run_delayed_refs(trans, async->root, async->count); 2706 ret = btrfs_run_delayed_refs(trans, async->root, async->count);
2707 if (ret) 2707 if (ret)
2708 async->error = ret; 2708 async->error = ret;
2709 2709
2710 ret = btrfs_end_transaction(trans, async->root); 2710 ret = btrfs_end_transaction(trans, async->root);
2711 if (ret && !async->error) 2711 if (ret && !async->error)
2712 async->error = ret; 2712 async->error = ret;
2713 done: 2713 done:
2714 if (async->sync) 2714 if (async->sync)
2715 complete(&async->wait); 2715 complete(&async->wait);
2716 else 2716 else
2717 kfree(async); 2717 kfree(async);
2718 } 2718 }
2719 2719
2720 int btrfs_async_run_delayed_refs(struct btrfs_root *root, 2720 int btrfs_async_run_delayed_refs(struct btrfs_root *root,
2721 unsigned long count, int wait) 2721 unsigned long count, int wait)
2722 { 2722 {
2723 struct async_delayed_refs *async; 2723 struct async_delayed_refs *async;
2724 int ret; 2724 int ret;
2725 2725
2726 async = kmalloc(sizeof(*async), GFP_NOFS); 2726 async = kmalloc(sizeof(*async), GFP_NOFS);
2727 if (!async) 2727 if (!async)
2728 return -ENOMEM; 2728 return -ENOMEM;
2729 2729
2730 async->root = root->fs_info->tree_root; 2730 async->root = root->fs_info->tree_root;
2731 async->count = count; 2731 async->count = count;
2732 async->error = 0; 2732 async->error = 0;
2733 if (wait) 2733 if (wait)
2734 async->sync = 1; 2734 async->sync = 1;
2735 else 2735 else
2736 async->sync = 0; 2736 async->sync = 0;
2737 init_completion(&async->wait); 2737 init_completion(&async->wait);
2738 2738
2739 btrfs_init_work(&async->work, btrfs_extent_refs_helper, 2739 btrfs_init_work(&async->work, btrfs_extent_refs_helper,
2740 delayed_ref_async_start, NULL, NULL); 2740 delayed_ref_async_start, NULL, NULL);
2741 2741
2742 btrfs_queue_work(root->fs_info->extent_workers, &async->work); 2742 btrfs_queue_work(root->fs_info->extent_workers, &async->work);
2743 2743
2744 if (wait) { 2744 if (wait) {
2745 wait_for_completion(&async->wait); 2745 wait_for_completion(&async->wait);
2746 ret = async->error; 2746 ret = async->error;
2747 kfree(async); 2747 kfree(async);
2748 return ret; 2748 return ret;
2749 } 2749 }
2750 return 0; 2750 return 0;
2751 } 2751 }
2752 2752
2753 /* 2753 /*
2754 * this starts processing the delayed reference count updates and 2754 * this starts processing the delayed reference count updates and
2755 * extent insertions we have queued up so far. count can be 2755 * extent insertions we have queued up so far. count can be
2756 * 0, which means to process everything in the tree at the start 2756 * 0, which means to process everything in the tree at the start
2757 * of the run (but not newly added entries), or it can be some target 2757 * of the run (but not newly added entries), or it can be some target
2758 * number you'd like to process. 2758 * number you'd like to process.
2759 * 2759 *
2760 * Returns 0 on success or if called with an aborted transaction 2760 * Returns 0 on success or if called with an aborted transaction
2761 * Returns <0 on error and aborts the transaction 2761 * Returns <0 on error and aborts the transaction
2762 */ 2762 */
2763 int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, 2763 int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans,
2764 struct btrfs_root *root, unsigned long count) 2764 struct btrfs_root *root, unsigned long count)
2765 { 2765 {
2766 struct rb_node *node; 2766 struct rb_node *node;
2767 struct btrfs_delayed_ref_root *delayed_refs; 2767 struct btrfs_delayed_ref_root *delayed_refs;
2768 struct btrfs_delayed_ref_head *head; 2768 struct btrfs_delayed_ref_head *head;
2769 int ret; 2769 int ret;
2770 int run_all = count == (unsigned long)-1; 2770 int run_all = count == (unsigned long)-1;
2771 int run_most = 0; 2771 int run_most = 0;
2772 2772
2773 /* We'll clean this up in btrfs_cleanup_transaction */ 2773 /* We'll clean this up in btrfs_cleanup_transaction */
2774 if (trans->aborted) 2774 if (trans->aborted)
2775 return 0; 2775 return 0;
2776 2776
2777 if (root == root->fs_info->extent_root) 2777 if (root == root->fs_info->extent_root)
2778 root = root->fs_info->tree_root; 2778 root = root->fs_info->tree_root;
2779 2779
2780 delayed_refs = &trans->transaction->delayed_refs; 2780 delayed_refs = &trans->transaction->delayed_refs;
2781 if (count == 0) { 2781 if (count == 0) {
2782 count = atomic_read(&delayed_refs->num_entries) * 2; 2782 count = atomic_read(&delayed_refs->num_entries) * 2;
2783 run_most = 1; 2783 run_most = 1;
2784 } 2784 }
2785 2785
2786 again: 2786 again:
2787 #ifdef SCRAMBLE_DELAYED_REFS 2787 #ifdef SCRAMBLE_DELAYED_REFS
2788 delayed_refs->run_delayed_start = find_middle(&delayed_refs->root); 2788 delayed_refs->run_delayed_start = find_middle(&delayed_refs->root);
2789 #endif 2789 #endif
2790 ret = __btrfs_run_delayed_refs(trans, root, count); 2790 ret = __btrfs_run_delayed_refs(trans, root, count);
2791 if (ret < 0) { 2791 if (ret < 0) {
2792 btrfs_abort_transaction(trans, root, ret); 2792 btrfs_abort_transaction(trans, root, ret);
2793 return ret; 2793 return ret;
2794 } 2794 }
2795 2795
2796 if (run_all) { 2796 if (run_all) {
2797 if (!list_empty(&trans->new_bgs)) 2797 if (!list_empty(&trans->new_bgs))
2798 btrfs_create_pending_block_groups(trans, root); 2798 btrfs_create_pending_block_groups(trans, root);
2799 2799
2800 spin_lock(&delayed_refs->lock); 2800 spin_lock(&delayed_refs->lock);
2801 node = rb_first(&delayed_refs->href_root); 2801 node = rb_first(&delayed_refs->href_root);
2802 if (!node) { 2802 if (!node) {
2803 spin_unlock(&delayed_refs->lock); 2803 spin_unlock(&delayed_refs->lock);
2804 goto out; 2804 goto out;
2805 } 2805 }
2806 count = (unsigned long)-1; 2806 count = (unsigned long)-1;
2807 2807
2808 while (node) { 2808 while (node) {
2809 head = rb_entry(node, struct btrfs_delayed_ref_head, 2809 head = rb_entry(node, struct btrfs_delayed_ref_head,
2810 href_node); 2810 href_node);
2811 if (btrfs_delayed_ref_is_head(&head->node)) { 2811 if (btrfs_delayed_ref_is_head(&head->node)) {
2812 struct btrfs_delayed_ref_node *ref; 2812 struct btrfs_delayed_ref_node *ref;
2813 2813
2814 ref = &head->node; 2814 ref = &head->node;
2815 atomic_inc(&ref->refs); 2815 atomic_inc(&ref->refs);
2816 2816
2817 spin_unlock(&delayed_refs->lock); 2817 spin_unlock(&delayed_refs->lock);
2818 /* 2818 /*
2819 * Mutex was contended, block until it's 2819 * Mutex was contended, block until it's
2820 * released and try again 2820 * released and try again
2821 */ 2821 */
2822 mutex_lock(&head->mutex); 2822 mutex_lock(&head->mutex);
2823 mutex_unlock(&head->mutex); 2823 mutex_unlock(&head->mutex);
2824 2824
2825 btrfs_put_delayed_ref(ref); 2825 btrfs_put_delayed_ref(ref);
2826 cond_resched(); 2826 cond_resched();
2827 goto again; 2827 goto again;
2828 } else { 2828 } else {
2829 WARN_ON(1); 2829 WARN_ON(1);
2830 } 2830 }
2831 node = rb_next(node); 2831 node = rb_next(node);
2832 } 2832 }
2833 spin_unlock(&delayed_refs->lock); 2833 spin_unlock(&delayed_refs->lock);
2834 cond_resched(); 2834 cond_resched();
2835 goto again; 2835 goto again;
2836 } 2836 }
2837 out: 2837 out:
2838 ret = btrfs_delayed_qgroup_accounting(trans, root->fs_info); 2838 ret = btrfs_delayed_qgroup_accounting(trans, root->fs_info);
2839 if (ret) 2839 if (ret)
2840 return ret; 2840 return ret;
2841 assert_qgroups_uptodate(trans); 2841 assert_qgroups_uptodate(trans);
2842 return 0; 2842 return 0;
2843 } 2843 }
2844 2844
2845 int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans, 2845 int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans,
2846 struct btrfs_root *root, 2846 struct btrfs_root *root,
2847 u64 bytenr, u64 num_bytes, u64 flags, 2847 u64 bytenr, u64 num_bytes, u64 flags,
2848 int level, int is_data) 2848 int level, int is_data)
2849 { 2849 {
2850 struct btrfs_delayed_extent_op *extent_op; 2850 struct btrfs_delayed_extent_op *extent_op;
2851 int ret; 2851 int ret;
2852 2852
2853 extent_op = btrfs_alloc_delayed_extent_op(); 2853 extent_op = btrfs_alloc_delayed_extent_op();
2854 if (!extent_op) 2854 if (!extent_op)
2855 return -ENOMEM; 2855 return -ENOMEM;
2856 2856
2857 extent_op->flags_to_set = flags; 2857 extent_op->flags_to_set = flags;
2858 extent_op->update_flags = 1; 2858 extent_op->update_flags = 1;
2859 extent_op->update_key = 0; 2859 extent_op->update_key = 0;
2860 extent_op->is_data = is_data ? 1 : 0; 2860 extent_op->is_data = is_data ? 1 : 0;
2861 extent_op->level = level; 2861 extent_op->level = level;
2862 2862
2863 ret = btrfs_add_delayed_extent_op(root->fs_info, trans, bytenr, 2863 ret = btrfs_add_delayed_extent_op(root->fs_info, trans, bytenr,
2864 num_bytes, extent_op); 2864 num_bytes, extent_op);
2865 if (ret) 2865 if (ret)
2866 btrfs_free_delayed_extent_op(extent_op); 2866 btrfs_free_delayed_extent_op(extent_op);
2867 return ret; 2867 return ret;
2868 } 2868 }
2869 2869
2870 static noinline int check_delayed_ref(struct btrfs_trans_handle *trans, 2870 static noinline int check_delayed_ref(struct btrfs_trans_handle *trans,
2871 struct btrfs_root *root, 2871 struct btrfs_root *root,
2872 struct btrfs_path *path, 2872 struct btrfs_path *path,
2873 u64 objectid, u64 offset, u64 bytenr) 2873 u64 objectid, u64 offset, u64 bytenr)
2874 { 2874 {
2875 struct btrfs_delayed_ref_head *head; 2875 struct btrfs_delayed_ref_head *head;
2876 struct btrfs_delayed_ref_node *ref; 2876 struct btrfs_delayed_ref_node *ref;
2877 struct btrfs_delayed_data_ref *data_ref; 2877 struct btrfs_delayed_data_ref *data_ref;
2878 struct btrfs_delayed_ref_root *delayed_refs; 2878 struct btrfs_delayed_ref_root *delayed_refs;
2879 struct rb_node *node; 2879 struct rb_node *node;
2880 int ret = 0; 2880 int ret = 0;
2881 2881
2882 delayed_refs = &trans->transaction->delayed_refs; 2882 delayed_refs = &trans->transaction->delayed_refs;
2883 spin_lock(&delayed_refs->lock); 2883 spin_lock(&delayed_refs->lock);
2884 head = btrfs_find_delayed_ref_head(trans, bytenr); 2884 head = btrfs_find_delayed_ref_head(trans, bytenr);
2885 if (!head) { 2885 if (!head) {
2886 spin_unlock(&delayed_refs->lock); 2886 spin_unlock(&delayed_refs->lock);
2887 return 0; 2887 return 0;
2888 } 2888 }
2889 2889
2890 if (!mutex_trylock(&head->mutex)) { 2890 if (!mutex_trylock(&head->mutex)) {
2891 atomic_inc(&head->node.refs); 2891 atomic_inc(&head->node.refs);
2892 spin_unlock(&delayed_refs->lock); 2892 spin_unlock(&delayed_refs->lock);
2893 2893
2894 btrfs_release_path(path); 2894 btrfs_release_path(path);
2895 2895
2896 /* 2896 /*
2897 * Mutex was contended, block until it's released and let 2897 * Mutex was contended, block until it's released and let
2898 * caller try again 2898 * caller try again
2899 */ 2899 */
2900 mutex_lock(&head->mutex); 2900 mutex_lock(&head->mutex);
2901 mutex_unlock(&head->mutex); 2901 mutex_unlock(&head->mutex);
2902 btrfs_put_delayed_ref(&head->node); 2902 btrfs_put_delayed_ref(&head->node);
2903 return -EAGAIN; 2903 return -EAGAIN;
2904 } 2904 }
2905 spin_unlock(&delayed_refs->lock); 2905 spin_unlock(&delayed_refs->lock);
2906 2906
2907 spin_lock(&head->lock); 2907 spin_lock(&head->lock);
2908 node = rb_first(&head->ref_root); 2908 node = rb_first(&head->ref_root);
2909 while (node) { 2909 while (node) {
2910 ref = rb_entry(node, struct btrfs_delayed_ref_node, rb_node); 2910 ref = rb_entry(node, struct btrfs_delayed_ref_node, rb_node);
2911 node = rb_next(node); 2911 node = rb_next(node);
2912 2912
2913 /* If it's a shared ref we know a cross reference exists */ 2913 /* If it's a shared ref we know a cross reference exists */
2914 if (ref->type != BTRFS_EXTENT_DATA_REF_KEY) { 2914 if (ref->type != BTRFS_EXTENT_DATA_REF_KEY) {
2915 ret = 1; 2915 ret = 1;
2916 break; 2916 break;
2917 } 2917 }
2918 2918
2919 data_ref = btrfs_delayed_node_to_data_ref(ref); 2919 data_ref = btrfs_delayed_node_to_data_ref(ref);
2920 2920
2921 /* 2921 /*
2922 * If our ref doesn't match the one we're currently looking at 2922 * If our ref doesn't match the one we're currently looking at
2923 * then we have a cross reference. 2923 * then we have a cross reference.
2924 */ 2924 */
2925 if (data_ref->root != root->root_key.objectid || 2925 if (data_ref->root != root->root_key.objectid ||
2926 data_ref->objectid != objectid || 2926 data_ref->objectid != objectid ||
2927 data_ref->offset != offset) { 2927 data_ref->offset != offset) {
2928 ret = 1; 2928 ret = 1;
2929 break; 2929 break;
2930 } 2930 }
2931 } 2931 }
2932 spin_unlock(&head->lock); 2932 spin_unlock(&head->lock);
2933 mutex_unlock(&head->mutex); 2933 mutex_unlock(&head->mutex);
2934 return ret; 2934 return ret;
2935 } 2935 }
2936 2936
2937 static noinline int check_committed_ref(struct btrfs_trans_handle *trans, 2937 static noinline int check_committed_ref(struct btrfs_trans_handle *trans,
2938 struct btrfs_root *root, 2938 struct btrfs_root *root,
2939 struct btrfs_path *path, 2939 struct btrfs_path *path,
2940 u64 objectid, u64 offset, u64 bytenr) 2940 u64 objectid, u64 offset, u64 bytenr)
2941 { 2941 {
2942 struct btrfs_root *extent_root = root->fs_info->extent_root; 2942 struct btrfs_root *extent_root = root->fs_info->extent_root;
2943 struct extent_buffer *leaf; 2943 struct extent_buffer *leaf;
2944 struct btrfs_extent_data_ref *ref; 2944 struct btrfs_extent_data_ref *ref;
2945 struct btrfs_extent_inline_ref *iref; 2945 struct btrfs_extent_inline_ref *iref;
2946 struct btrfs_extent_item *ei; 2946 struct btrfs_extent_item *ei;
2947 struct btrfs_key key; 2947 struct btrfs_key key;
2948 u32 item_size; 2948 u32 item_size;
2949 int ret; 2949 int ret;
2950 2950
2951 key.objectid = bytenr; 2951 key.objectid = bytenr;
2952 key.offset = (u64)-1; 2952 key.offset = (u64)-1;
2953 key.type = BTRFS_EXTENT_ITEM_KEY; 2953 key.type = BTRFS_EXTENT_ITEM_KEY;
2954 2954
2955 ret = btrfs_search_slot(NULL, extent_root, &key, path, 0, 0); 2955 ret = btrfs_search_slot(NULL, extent_root, &key, path, 0, 0);
2956 if (ret < 0) 2956 if (ret < 0)
2957 goto out; 2957 goto out;
2958 BUG_ON(ret == 0); /* Corruption */ 2958 BUG_ON(ret == 0); /* Corruption */
2959 2959
2960 ret = -ENOENT; 2960 ret = -ENOENT;
2961 if (path->slots[0] == 0) 2961 if (path->slots[0] == 0)
2962 goto out; 2962 goto out;
2963 2963
2964 path->slots[0]--; 2964 path->slots[0]--;
2965 leaf = path->nodes[0]; 2965 leaf = path->nodes[0];
2966 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); 2966 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
2967 2967
2968 if (key.objectid != bytenr || key.type != BTRFS_EXTENT_ITEM_KEY) 2968 if (key.objectid != bytenr || key.type != BTRFS_EXTENT_ITEM_KEY)
2969 goto out; 2969 goto out;
2970 2970
2971 ret = 1; 2971 ret = 1;
2972 item_size = btrfs_item_size_nr(leaf, path->slots[0]); 2972 item_size = btrfs_item_size_nr(leaf, path->slots[0]);
2973 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0 2973 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
2974 if (item_size < sizeof(*ei)) { 2974 if (item_size < sizeof(*ei)) {
2975 WARN_ON(item_size != sizeof(struct btrfs_extent_item_v0)); 2975 WARN_ON(item_size != sizeof(struct btrfs_extent_item_v0));
2976 goto out; 2976 goto out;
2977 } 2977 }
2978 #endif 2978 #endif
2979 ei = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_extent_item); 2979 ei = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_extent_item);
2980 2980
2981 if (item_size != sizeof(*ei) + 2981 if (item_size != sizeof(*ei) +
2982 btrfs_extent_inline_ref_size(BTRFS_EXTENT_DATA_REF_KEY)) 2982 btrfs_extent_inline_ref_size(BTRFS_EXTENT_DATA_REF_KEY))
2983 goto out; 2983 goto out;
2984 2984
2985 if (btrfs_extent_generation(leaf, ei) <= 2985 if (btrfs_extent_generation(leaf, ei) <=
2986 btrfs_root_last_snapshot(&root->root_item)) 2986 btrfs_root_last_snapshot(&root->root_item))
2987 goto out; 2987 goto out;
2988 2988
2989 iref = (struct btrfs_extent_inline_ref *)(ei + 1); 2989 iref = (struct btrfs_extent_inline_ref *)(ei + 1);
2990 if (btrfs_extent_inline_ref_type(leaf, iref) != 2990 if (btrfs_extent_inline_ref_type(leaf, iref) !=
2991 BTRFS_EXTENT_DATA_REF_KEY) 2991 BTRFS_EXTENT_DATA_REF_KEY)
2992 goto out; 2992 goto out;
2993 2993
2994 ref = (struct btrfs_extent_data_ref *)(&iref->offset); 2994 ref = (struct btrfs_extent_data_ref *)(&iref->offset);
2995 if (btrfs_extent_refs(leaf, ei) != 2995 if (btrfs_extent_refs(leaf, ei) !=
2996 btrfs_extent_data_ref_count(leaf, ref) || 2996 btrfs_extent_data_ref_count(leaf, ref) ||
2997 btrfs_extent_data_ref_root(leaf, ref) != 2997 btrfs_extent_data_ref_root(leaf, ref) !=
2998 root->root_key.objectid || 2998 root->root_key.objectid ||
2999 btrfs_extent_data_ref_objectid(leaf, ref) != objectid || 2999 btrfs_extent_data_ref_objectid(leaf, ref) != objectid ||
3000 btrfs_extent_data_ref_offset(leaf, ref) != offset) 3000 btrfs_extent_data_ref_offset(leaf, ref) != offset)
3001 goto out; 3001 goto out;
3002 3002
3003 ret = 0; 3003 ret = 0;
3004 out: 3004 out:
3005 return ret; 3005 return ret;
3006 } 3006 }
3007 3007
3008 int btrfs_cross_ref_exist(struct btrfs_trans_handle *trans, 3008 int btrfs_cross_ref_exist(struct btrfs_trans_handle *trans,
3009 struct btrfs_root *root, 3009 struct btrfs_root *root,
3010 u64 objectid, u64 offset, u64 bytenr) 3010 u64 objectid, u64 offset, u64 bytenr)
3011 { 3011 {
3012 struct btrfs_path *path; 3012 struct btrfs_path *path;
3013 int ret; 3013 int ret;
3014 int ret2; 3014 int ret2;
3015 3015
3016 path = btrfs_alloc_path(); 3016 path = btrfs_alloc_path();
3017 if (!path) 3017 if (!path)
3018 return -ENOENT; 3018 return -ENOENT;
3019 3019
3020 do { 3020 do {
3021 ret = check_committed_ref(trans, root, path, objectid, 3021 ret = check_committed_ref(trans, root, path, objectid,
3022 offset, bytenr); 3022 offset, bytenr);
3023 if (ret && ret != -ENOENT) 3023 if (ret && ret != -ENOENT)
3024 goto out; 3024 goto out;
3025 3025
3026 ret2 = check_delayed_ref(trans, root, path, objectid, 3026 ret2 = check_delayed_ref(trans, root, path, objectid,
3027 offset, bytenr); 3027 offset, bytenr);
3028 } while (ret2 == -EAGAIN); 3028 } while (ret2 == -EAGAIN);
3029 3029
3030 if (ret2 && ret2 != -ENOENT) { 3030 if (ret2 && ret2 != -ENOENT) {
3031 ret = ret2; 3031 ret = ret2;
3032 goto out; 3032 goto out;
3033 } 3033 }
3034 3034
3035 if (ret != -ENOENT || ret2 != -ENOENT) 3035 if (ret != -ENOENT || ret2 != -ENOENT)
3036 ret = 0; 3036 ret = 0;
3037 out: 3037 out:
3038 btrfs_free_path(path); 3038 btrfs_free_path(path);
3039 if (root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID) 3039 if (root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID)
3040 WARN_ON(ret > 0); 3040 WARN_ON(ret > 0);
3041 return ret; 3041 return ret;
3042 } 3042 }
3043 3043
3044 static int __btrfs_mod_ref(struct btrfs_trans_handle *trans, 3044 static int __btrfs_mod_ref(struct btrfs_trans_handle *trans,
3045 struct btrfs_root *root, 3045 struct btrfs_root *root,
3046 struct extent_buffer *buf, 3046 struct extent_buffer *buf,
3047 int full_backref, int inc) 3047 int full_backref, int inc)
3048 { 3048 {
3049 u64 bytenr; 3049 u64 bytenr;
3050 u64 num_bytes; 3050 u64 num_bytes;
3051 u64 parent; 3051 u64 parent;
3052 u64 ref_root; 3052 u64 ref_root;
3053 u32 nritems; 3053 u32 nritems;
3054 struct btrfs_key key; 3054 struct btrfs_key key;
3055 struct btrfs_file_extent_item *fi; 3055 struct btrfs_file_extent_item *fi;
3056 int i; 3056 int i;
3057 int level; 3057 int level;
3058 int ret = 0; 3058 int ret = 0;
3059 int (*process_func)(struct btrfs_trans_handle *, struct btrfs_root *, 3059 int (*process_func)(struct btrfs_trans_handle *, struct btrfs_root *,
3060 u64, u64, u64, u64, u64, u64, int); 3060 u64, u64, u64, u64, u64, u64, int);
3061 3061
3062 3062
3063 if (btrfs_test_is_dummy_root(root)) 3063 if (btrfs_test_is_dummy_root(root))
3064 return 0; 3064 return 0;
3065 3065
3066 ref_root = btrfs_header_owner(buf); 3066 ref_root = btrfs_header_owner(buf);
3067 nritems = btrfs_header_nritems(buf); 3067 nritems = btrfs_header_nritems(buf);
3068 level = btrfs_header_level(buf); 3068 level = btrfs_header_level(buf);
3069 3069
3070 if (!test_bit(BTRFS_ROOT_REF_COWS, &root->state) && level == 0) 3070 if (!test_bit(BTRFS_ROOT_REF_COWS, &root->state) && level == 0)
3071 return 0; 3071 return 0;
3072 3072
3073 if (inc) 3073 if (inc)
3074 process_func = btrfs_inc_extent_ref; 3074 process_func = btrfs_inc_extent_ref;
3075 else 3075 else
3076 process_func = btrfs_free_extent; 3076 process_func = btrfs_free_extent;
3077 3077
3078 if (full_backref) 3078 if (full_backref)
3079 parent = buf->start; 3079 parent = buf->start;
3080 else 3080 else
3081 parent = 0; 3081 parent = 0;
3082 3082
3083 for (i = 0; i < nritems; i++) { 3083 for (i = 0; i < nritems; i++) {
3084 if (level == 0) { 3084 if (level == 0) {
3085 btrfs_item_key_to_cpu(buf, &key, i); 3085 btrfs_item_key_to_cpu(buf, &key, i);
3086 if (key.type != BTRFS_EXTENT_DATA_KEY) 3086 if (key.type != BTRFS_EXTENT_DATA_KEY)
3087 continue; 3087 continue;
3088 fi = btrfs_item_ptr(buf, i, 3088 fi = btrfs_item_ptr(buf, i,
3089 struct btrfs_file_extent_item); 3089 struct btrfs_file_extent_item);
3090 if (btrfs_file_extent_type(buf, fi) == 3090 if (btrfs_file_extent_type(buf, fi) ==
3091 BTRFS_FILE_EXTENT_INLINE) 3091 BTRFS_FILE_EXTENT_INLINE)
3092 continue; 3092 continue;
3093 bytenr = btrfs_file_extent_disk_bytenr(buf, fi); 3093 bytenr = btrfs_file_extent_disk_bytenr(buf, fi);
3094 if (bytenr == 0) 3094 if (bytenr == 0)
3095 continue; 3095 continue;
3096 3096
3097 num_bytes = btrfs_file_extent_disk_num_bytes(buf, fi); 3097 num_bytes = btrfs_file_extent_disk_num_bytes(buf, fi);
3098 key.offset -= btrfs_file_extent_offset(buf, fi); 3098 key.offset -= btrfs_file_extent_offset(buf, fi);
3099 ret = process_func(trans, root, bytenr, num_bytes, 3099 ret = process_func(trans, root, bytenr, num_bytes,
3100 parent, ref_root, key.objectid, 3100 parent, ref_root, key.objectid,
3101 key.offset, 1); 3101 key.offset, 1);
3102 if (ret) 3102 if (ret)
3103 goto fail; 3103 goto fail;
3104 } else { 3104 } else {
3105 bytenr = btrfs_node_blockptr(buf, i); 3105 bytenr = btrfs_node_blockptr(buf, i);
3106 num_bytes = root->nodesize; 3106 num_bytes = root->nodesize;
3107 ret = process_func(trans, root, bytenr, num_bytes, 3107 ret = process_func(trans, root, bytenr, num_bytes,
3108 parent, ref_root, level - 1, 0, 3108 parent, ref_root, level - 1, 0,
3109 1); 3109 1);
3110 if (ret) 3110 if (ret)
3111 goto fail; 3111 goto fail;
3112 } 3112 }
3113 } 3113 }
3114 return 0; 3114 return 0;
3115 fail: 3115 fail:
3116 return ret; 3116 return ret;
3117 } 3117 }
3118 3118
3119 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, 3119 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
3120 struct extent_buffer *buf, int full_backref) 3120 struct extent_buffer *buf, int full_backref)
3121 { 3121 {
3122 return __btrfs_mod_ref(trans, root, buf, full_backref, 1); 3122 return __btrfs_mod_ref(trans, root, buf, full_backref, 1);
3123 } 3123 }
3124 3124
3125 int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, 3125 int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
3126 struct extent_buffer *buf, int full_backref) 3126 struct extent_buffer *buf, int full_backref)
3127 { 3127 {
3128 return __btrfs_mod_ref(trans, root, buf, full_backref, 0); 3128 return __btrfs_mod_ref(trans, root, buf, full_backref, 0);
3129 } 3129 }
3130 3130
3131 static int write_one_cache_group(struct btrfs_trans_handle *trans, 3131 static int write_one_cache_group(struct btrfs_trans_handle *trans,
3132 struct btrfs_root *root, 3132 struct btrfs_root *root,
3133 struct btrfs_path *path, 3133 struct btrfs_path *path,
3134 struct btrfs_block_group_cache *cache) 3134 struct btrfs_block_group_cache *cache)
3135 { 3135 {
3136 int ret; 3136 int ret;
3137 struct btrfs_root *extent_root = root->fs_info->extent_root; 3137 struct btrfs_root *extent_root = root->fs_info->extent_root;
3138 unsigned long bi; 3138 unsigned long bi;
3139 struct extent_buffer *leaf; 3139 struct extent_buffer *leaf;
3140 3140
3141 ret = btrfs_search_slot(trans, extent_root, &cache->key, path, 0, 1); 3141 ret = btrfs_search_slot(trans, extent_root, &cache->key, path, 0, 1);
3142 if (ret < 0) 3142 if (ret) {
3143 if (ret > 0)
3144 ret = -ENOENT;
3143 goto fail; 3145 goto fail;
3144 BUG_ON(ret); /* Corruption */ 3146 }
3145 3147
3146 leaf = path->nodes[0]; 3148 leaf = path->nodes[0];
3147 bi = btrfs_item_ptr_offset(leaf, path->slots[0]); 3149 bi = btrfs_item_ptr_offset(leaf, path->slots[0]);
3148 write_extent_buffer(leaf, &cache->item, bi, sizeof(cache->item)); 3150 write_extent_buffer(leaf, &cache->item, bi, sizeof(cache->item));
3149 btrfs_mark_buffer_dirty(leaf); 3151 btrfs_mark_buffer_dirty(leaf);
3150 btrfs_release_path(path); 3152 btrfs_release_path(path);
3151 fail: 3153 fail:
3152 if (ret) { 3154 if (ret)
3153 btrfs_abort_transaction(trans, root, ret); 3155 btrfs_abort_transaction(trans, root, ret);
3154 return ret; 3156 return ret;
3155 }
3156 return 0;
3157 3157
3158 } 3158 }
3159 3159
3160 static struct btrfs_block_group_cache * 3160 static struct btrfs_block_group_cache *
3161 next_block_group(struct btrfs_root *root, 3161 next_block_group(struct btrfs_root *root,
3162 struct btrfs_block_group_cache *cache) 3162 struct btrfs_block_group_cache *cache)
3163 { 3163 {
3164 struct rb_node *node; 3164 struct rb_node *node;
3165 3165
3166 spin_lock(&root->fs_info->block_group_cache_lock); 3166 spin_lock(&root->fs_info->block_group_cache_lock);
3167 3167
3168 /* If our block group was removed, we need a full search. */ 3168 /* If our block group was removed, we need a full search. */
3169 if (RB_EMPTY_NODE(&cache->cache_node)) { 3169 if (RB_EMPTY_NODE(&cache->cache_node)) {
3170 const u64 next_bytenr = cache->key.objectid + cache->key.offset; 3170 const u64 next_bytenr = cache->key.objectid + cache->key.offset;
3171 3171
3172 spin_unlock(&root->fs_info->block_group_cache_lock); 3172 spin_unlock(&root->fs_info->block_group_cache_lock);
3173 btrfs_put_block_group(cache); 3173 btrfs_put_block_group(cache);
3174 cache = btrfs_lookup_first_block_group(root->fs_info, 3174 cache = btrfs_lookup_first_block_group(root->fs_info,
3175 next_bytenr); 3175 next_bytenr);
3176 return cache; 3176 return cache;
3177 } 3177 }
3178 node = rb_next(&cache->cache_node); 3178 node = rb_next(&cache->cache_node);
3179 btrfs_put_block_group(cache); 3179 btrfs_put_block_group(cache);
3180 if (node) { 3180 if (node) {
3181 cache = rb_entry(node, struct btrfs_block_group_cache, 3181 cache = rb_entry(node, struct btrfs_block_group_cache,
3182 cache_node); 3182 cache_node);
3183 btrfs_get_block_group(cache); 3183 btrfs_get_block_group(cache);
3184 } else 3184 } else
3185 cache = NULL; 3185 cache = NULL;
3186 spin_unlock(&root->fs_info->block_group_cache_lock); 3186 spin_unlock(&root->fs_info->block_group_cache_lock);
3187 return cache; 3187 return cache;
3188 } 3188 }
3189 3189
3190 static int cache_save_setup(struct btrfs_block_group_cache *block_group, 3190 static int cache_save_setup(struct btrfs_block_group_cache *block_group,
3191 struct btrfs_trans_handle *trans, 3191 struct btrfs_trans_handle *trans,
3192 struct btrfs_path *path) 3192 struct btrfs_path *path)
3193 { 3193 {
3194 struct btrfs_root *root = block_group->fs_info->tree_root; 3194 struct btrfs_root *root = block_group->fs_info->tree_root;
3195 struct inode *inode = NULL; 3195 struct inode *inode = NULL;
3196 u64 alloc_hint = 0; 3196 u64 alloc_hint = 0;
3197 int dcs = BTRFS_DC_ERROR; 3197 int dcs = BTRFS_DC_ERROR;
3198 int num_pages = 0; 3198 int num_pages = 0;
3199 int retries = 0; 3199 int retries = 0;
3200 int ret = 0; 3200 int ret = 0;
3201 3201
3202 /* 3202 /*
3203 * If this block group is smaller than 100 megs don't bother caching the 3203 * If this block group is smaller than 100 megs don't bother caching the
3204 * block group. 3204 * block group.
3205 */ 3205 */
3206 if (block_group->key.offset < (100 * 1024 * 1024)) { 3206 if (block_group->key.offset < (100 * 1024 * 1024)) {
3207 spin_lock(&block_group->lock); 3207 spin_lock(&block_group->lock);
3208 block_group->disk_cache_state = BTRFS_DC_WRITTEN; 3208 block_group->disk_cache_state = BTRFS_DC_WRITTEN;
3209 spin_unlock(&block_group->lock); 3209 spin_unlock(&block_group->lock);
3210 return 0; 3210 return 0;
3211 } 3211 }
3212 3212
3213 again: 3213 again:
3214 inode = lookup_free_space_inode(root, block_group, path); 3214 inode = lookup_free_space_inode(root, block_group, path);
3215 if (IS_ERR(inode) && PTR_ERR(inode) != -ENOENT) { 3215 if (IS_ERR(inode) && PTR_ERR(inode) != -ENOENT) {
3216 ret = PTR_ERR(inode); 3216 ret = PTR_ERR(inode);
3217 btrfs_release_path(path); 3217 btrfs_release_path(path);
3218 goto out; 3218 goto out;
3219 } 3219 }
3220 3220
3221 if (IS_ERR(inode)) { 3221 if (IS_ERR(inode)) {
3222 BUG_ON(retries); 3222 BUG_ON(retries);
3223 retries++; 3223 retries++;
3224 3224
3225 if (block_group->ro) 3225 if (block_group->ro)
3226 goto out_free; 3226 goto out_free;
3227 3227
3228 ret = create_free_space_inode(root, trans, block_group, path); 3228 ret = create_free_space_inode(root, trans, block_group, path);
3229 if (ret) 3229 if (ret)
3230 goto out_free; 3230 goto out_free;
3231 goto again; 3231 goto again;
3232 } 3232 }
3233 3233
3234 /* We've already setup this transaction, go ahead and exit */ 3234 /* We've already setup this transaction, go ahead and exit */
3235 if (block_group->cache_generation == trans->transid && 3235 if (block_group->cache_generation == trans->transid &&
3236 i_size_read(inode)) { 3236 i_size_read(inode)) {
3237 dcs = BTRFS_DC_SETUP; 3237 dcs = BTRFS_DC_SETUP;
3238 goto out_put; 3238 goto out_put;
3239 } 3239 }
3240 3240
3241 /* 3241 /*
3242 * We want to set the generation to 0, that way if anything goes wrong 3242 * We want to set the generation to 0, that way if anything goes wrong
3243 * from here on out we know not to trust this cache when we load up next 3243 * from here on out we know not to trust this cache when we load up next
3244 * time. 3244 * time.
3245 */ 3245 */
3246 BTRFS_I(inode)->generation = 0; 3246 BTRFS_I(inode)->generation = 0;
3247 ret = btrfs_update_inode(trans, root, inode); 3247 ret = btrfs_update_inode(trans, root, inode);
3248 WARN_ON(ret); 3248 WARN_ON(ret);
3249 3249
3250 if (i_size_read(inode) > 0) { 3250 if (i_size_read(inode) > 0) {
3251 ret = btrfs_check_trunc_cache_free_space(root, 3251 ret = btrfs_check_trunc_cache_free_space(root,
3252 &root->fs_info->global_block_rsv); 3252 &root->fs_info->global_block_rsv);
3253 if (ret) 3253 if (ret)
3254 goto out_put; 3254 goto out_put;
3255 3255
3256 ret = btrfs_truncate_free_space_cache(root, trans, inode); 3256 ret = btrfs_truncate_free_space_cache(root, trans, inode);
3257 if (ret) 3257 if (ret)
3258 goto out_put; 3258 goto out_put;
3259 } 3259 }
3260 3260
3261 spin_lock(&block_group->lock); 3261 spin_lock(&block_group->lock);
3262 if (block_group->cached != BTRFS_CACHE_FINISHED || 3262 if (block_group->cached != BTRFS_CACHE_FINISHED ||
3263 !btrfs_test_opt(root, SPACE_CACHE) || 3263 !btrfs_test_opt(root, SPACE_CACHE) ||
3264 block_group->delalloc_bytes) { 3264 block_group->delalloc_bytes) {
3265 /* 3265 /*
3266 * don't bother trying to write stuff out _if_ 3266 * don't bother trying to write stuff out _if_
3267 * a) we're not cached, 3267 * a) we're not cached,
3268 * b) we're with nospace_cache mount option. 3268 * b) we're with nospace_cache mount option.
3269 */ 3269 */
3270 dcs = BTRFS_DC_WRITTEN; 3270 dcs = BTRFS_DC_WRITTEN;
3271 spin_unlock(&block_group->lock); 3271 spin_unlock(&block_group->lock);
3272 goto out_put; 3272 goto out_put;
3273 } 3273 }
3274 spin_unlock(&block_group->lock); 3274 spin_unlock(&block_group->lock);
3275 3275
3276 /* 3276 /*
3277 * Try to preallocate enough space based on how big the block group is. 3277 * Try to preallocate enough space based on how big the block group is.
3278 * Keep in mind this has to include any pinned space which could end up 3278 * Keep in mind this has to include any pinned space which could end up
3279 * taking up quite a bit since it's not folded into the other space 3279 * taking up quite a bit since it's not folded into the other space
3280 * cache. 3280 * cache.
3281 */ 3281 */
3282 num_pages = (int)div64_u64(block_group->key.offset, 256 * 1024 * 1024); 3282 num_pages = (int)div64_u64(block_group->key.offset, 256 * 1024 * 1024);
3283 if (!num_pages) 3283 if (!num_pages)
3284 num_pages = 1; 3284 num_pages = 1;
3285 3285
3286 num_pages *= 16; 3286 num_pages *= 16;
3287 num_pages *= PAGE_CACHE_SIZE; 3287 num_pages *= PAGE_CACHE_SIZE;
3288 3288
3289 ret = btrfs_check_data_free_space(inode, num_pages); 3289 ret = btrfs_check_data_free_space(inode, num_pages);
3290 if (ret) 3290 if (ret)
3291 goto out_put; 3291 goto out_put;
3292 3292
3293 ret = btrfs_prealloc_file_range_trans(inode, trans, 0, 0, num_pages, 3293 ret = btrfs_prealloc_file_range_trans(inode, trans, 0, 0, num_pages,
3294 num_pages, num_pages, 3294 num_pages, num_pages,
3295 &alloc_hint); 3295 &alloc_hint);
3296 if (!ret) 3296 if (!ret)
3297 dcs = BTRFS_DC_SETUP; 3297 dcs = BTRFS_DC_SETUP;
3298 btrfs_free_reserved_data_space(inode, num_pages); 3298 btrfs_free_reserved_data_space(inode, num_pages);
3299 3299
3300 out_put: 3300 out_put:
3301 iput(inode); 3301 iput(inode);
3302 out_free: 3302 out_free:
3303 btrfs_release_path(path); 3303 btrfs_release_path(path);
3304 out: 3304 out:
3305 spin_lock(&block_group->lock); 3305 spin_lock(&block_group->lock);
3306 if (!ret && dcs == BTRFS_DC_SETUP) 3306 if (!ret && dcs == BTRFS_DC_SETUP)
3307 block_group->cache_generation = trans->transid; 3307 block_group->cache_generation = trans->transid;
3308 block_group->disk_cache_state = dcs; 3308 block_group->disk_cache_state = dcs;
3309 spin_unlock(&block_group->lock); 3309 spin_unlock(&block_group->lock);
3310 3310
3311 return ret; 3311 return ret;
3312 } 3312 }
3313 3313
3314 int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans, 3314 int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
3315 struct btrfs_root *root) 3315 struct btrfs_root *root)
3316 { 3316 {
3317 struct btrfs_block_group_cache *cache; 3317 struct btrfs_block_group_cache *cache;
3318 int err = 0; 3318 int err = 0;
3319 struct btrfs_path *path; 3319 struct btrfs_path *path;
3320 u64 last = 0; 3320 u64 last = 0;
3321 3321
3322 path = btrfs_alloc_path(); 3322 path = btrfs_alloc_path();
3323 if (!path) 3323 if (!path)
3324 return -ENOMEM; 3324 return -ENOMEM;
3325 3325
3326 again: 3326 again:
3327 while (1) { 3327 while (1) {
3328 cache = btrfs_lookup_first_block_group(root->fs_info, last); 3328 cache = btrfs_lookup_first_block_group(root->fs_info, last);
3329 while (cache) { 3329 while (cache) {
3330 if (cache->disk_cache_state == BTRFS_DC_CLEAR) 3330 if (cache->disk_cache_state == BTRFS_DC_CLEAR)
3331 break; 3331 break;
3332 cache = next_block_group(root, cache); 3332 cache = next_block_group(root, cache);
3333 } 3333 }
3334 if (!cache) { 3334 if (!cache) {
3335 if (last == 0) 3335 if (last == 0)
3336 break; 3336 break;
3337 last = 0; 3337 last = 0;
3338 continue; 3338 continue;
3339 } 3339 }
3340 err = cache_save_setup(cache, trans, path); 3340 err = cache_save_setup(cache, trans, path);
3341 last = cache->key.objectid + cache->key.offset; 3341 last = cache->key.objectid + cache->key.offset;
3342 btrfs_put_block_group(cache); 3342 btrfs_put_block_group(cache);
3343 } 3343 }
3344 3344
3345 while (1) { 3345 while (1) {
3346 if (last == 0) { 3346 if (last == 0) {
3347 err = btrfs_run_delayed_refs(trans, root, 3347 err = btrfs_run_delayed_refs(trans, root,
3348 (unsigned long)-1); 3348 (unsigned long)-1);
3349 if (err) /* File system offline */ 3349 if (err) /* File system offline */
3350 goto out; 3350 goto out;
3351 } 3351 }
3352 3352
3353 cache = btrfs_lookup_first_block_group(root->fs_info, last); 3353 cache = btrfs_lookup_first_block_group(root->fs_info, last);
3354 while (cache) { 3354 while (cache) {
3355 if (cache->disk_cache_state == BTRFS_DC_CLEAR) { 3355 if (cache->disk_cache_state == BTRFS_DC_CLEAR) {
3356 btrfs_put_block_group(cache); 3356 btrfs_put_block_group(cache);
3357 goto again; 3357 goto again;
3358 } 3358 }
3359 3359
3360 if (cache->dirty) 3360 if (cache->dirty)
3361 break; 3361 break;
3362 cache = next_block_group(root, cache); 3362 cache = next_block_group(root, cache);
3363 } 3363 }
3364 if (!cache) { 3364 if (!cache) {
3365 if (last == 0) 3365 if (last == 0)
3366 break; 3366 break;
3367 last = 0; 3367 last = 0;
3368 continue; 3368 continue;
3369 } 3369 }
3370 3370
3371 if (cache->disk_cache_state == BTRFS_DC_SETUP) 3371 if (cache->disk_cache_state == BTRFS_DC_SETUP)
3372 cache->disk_cache_state = BTRFS_DC_NEED_WRITE; 3372 cache->disk_cache_state = BTRFS_DC_NEED_WRITE;
3373 cache->dirty = 0; 3373 cache->dirty = 0;
3374 last = cache->key.objectid + cache->key.offset; 3374 last = cache->key.objectid + cache->key.offset;
3375 3375
3376 err = write_one_cache_group(trans, root, path, cache); 3376 err = write_one_cache_group(trans, root, path, cache);
3377 btrfs_put_block_group(cache); 3377 btrfs_put_block_group(cache);
3378 if (err) /* File system offline */ 3378 if (err) /* File system offline */
3379 goto out; 3379 goto out;
3380 } 3380 }
3381 3381
3382 while (1) { 3382 while (1) {
3383 /* 3383 /*
3384 * I don't think this is needed since we're just marking our 3384 * I don't think this is needed since we're just marking our
3385 * preallocated extent as written, but just in case it can't 3385 * preallocated extent as written, but just in case it can't
3386 * hurt. 3386 * hurt.
3387 */ 3387 */
3388 if (last == 0) { 3388 if (last == 0) {
3389 err = btrfs_run_delayed_refs(trans, root, 3389 err = btrfs_run_delayed_refs(trans, root,
3390 (unsigned long)-1); 3390 (unsigned long)-1);
3391 if (err) /* File system offline */ 3391 if (err) /* File system offline */
3392 goto out; 3392 goto out;
3393 } 3393 }
3394 3394
3395 cache = btrfs_lookup_first_block_group(root->fs_info, last); 3395 cache = btrfs_lookup_first_block_group(root->fs_info, last);
3396 while (cache) { 3396 while (cache) {
3397 /* 3397 /*
3398 * Really this shouldn't happen, but it could if we 3398 * Really this shouldn't happen, but it could if we
3399 * couldn't write the entire preallocated extent and 3399 * couldn't write the entire preallocated extent and
3400 * splitting the extent resulted in a new block. 3400 * splitting the extent resulted in a new block.
3401 */ 3401 */
3402 if (cache->dirty) { 3402 if (cache->dirty) {
3403 btrfs_put_block_group(cache); 3403 btrfs_put_block_group(cache);
3404 goto again; 3404 goto again;
3405 } 3405 }
3406 if (cache->disk_cache_state == BTRFS_DC_NEED_WRITE) 3406 if (cache->disk_cache_state == BTRFS_DC_NEED_WRITE)
3407 break; 3407 break;
3408 cache = next_block_group(root, cache); 3408 cache = next_block_group(root, cache);
3409 } 3409 }
3410 if (!cache) { 3410 if (!cache) {
3411 if (last == 0) 3411 if (last == 0)
3412 break; 3412 break;
3413 last = 0; 3413 last = 0;
3414 continue; 3414 continue;
3415 } 3415 }
3416 3416
3417 err = btrfs_write_out_cache(root, trans, cache, path); 3417 err = btrfs_write_out_cache(root, trans, cache, path);
3418 3418
3419 /* 3419 /*
3420 * If we didn't have an error then the cache state is still 3420 * If we didn't have an error then the cache state is still
3421 * NEED_WRITE, so we can set it to WRITTEN. 3421 * NEED_WRITE, so we can set it to WRITTEN.
3422 */ 3422 */
3423 if (!err && cache->disk_cache_state == BTRFS_DC_NEED_WRITE) 3423 if (!err && cache->disk_cache_state == BTRFS_DC_NEED_WRITE)
3424 cache->disk_cache_state = BTRFS_DC_WRITTEN; 3424 cache->disk_cache_state = BTRFS_DC_WRITTEN;
3425 last = cache->key.objectid + cache->key.offset; 3425 last = cache->key.objectid + cache->key.offset;
3426 btrfs_put_block_group(cache); 3426 btrfs_put_block_group(cache);
3427 } 3427 }
3428 out: 3428 out:
3429 3429
3430 btrfs_free_path(path); 3430 btrfs_free_path(path);
3431 return err; 3431 return err;
3432 } 3432 }
3433 3433
3434 int btrfs_extent_readonly(struct btrfs_root *root, u64 bytenr) 3434 int btrfs_extent_readonly(struct btrfs_root *root, u64 bytenr)
3435 { 3435 {
3436 struct btrfs_block_group_cache *block_group; 3436 struct btrfs_block_group_cache *block_group;
3437 int readonly = 0; 3437 int readonly = 0;
3438 3438
3439 block_group = btrfs_lookup_block_group(root->fs_info, bytenr); 3439 block_group = btrfs_lookup_block_group(root->fs_info, bytenr);
3440 if (!block_group || block_group->ro) 3440 if (!block_group || block_group->ro)
3441 readonly = 1; 3441 readonly = 1;
3442 if (block_group) 3442 if (block_group)
3443 btrfs_put_block_group(block_group); 3443 btrfs_put_block_group(block_group);
3444 return readonly; 3444 return readonly;
3445 } 3445 }
3446 3446
3447 static const char *alloc_name(u64 flags) 3447 static const char *alloc_name(u64 flags)
3448 { 3448 {
3449 switch (flags) { 3449 switch (flags) {
3450 case BTRFS_BLOCK_GROUP_METADATA|BTRFS_BLOCK_GROUP_DATA: 3450 case BTRFS_BLOCK_GROUP_METADATA|BTRFS_BLOCK_GROUP_DATA:
3451 return "mixed"; 3451 return "mixed";
3452 case BTRFS_BLOCK_GROUP_METADATA: 3452 case BTRFS_BLOCK_GROUP_METADATA:
3453 return "metadata"; 3453 return "metadata";
3454 case BTRFS_BLOCK_GROUP_DATA: 3454 case BTRFS_BLOCK_GROUP_DATA:
3455 return "data"; 3455 return "data";
3456 case BTRFS_BLOCK_GROUP_SYSTEM: 3456 case BTRFS_BLOCK_GROUP_SYSTEM:
3457 return "system"; 3457 return "system";
3458 default: 3458 default:
3459 WARN_ON(1); 3459 WARN_ON(1);
3460 return "invalid-combination"; 3460 return "invalid-combination";
3461 }; 3461 };
3462 } 3462 }
3463 3463
3464 static int update_space_info(struct btrfs_fs_info *info, u64 flags, 3464 static int update_space_info(struct btrfs_fs_info *info, u64 flags,
3465 u64 total_bytes, u64 bytes_used, 3465 u64 total_bytes, u64 bytes_used,
3466 struct btrfs_space_info **space_info) 3466 struct btrfs_space_info **space_info)
3467 { 3467 {
3468 struct btrfs_space_info *found; 3468 struct btrfs_space_info *found;
3469 int i; 3469 int i;
3470 int factor; 3470 int factor;
3471 int ret; 3471 int ret;
3472 3472
3473 if (flags & (BTRFS_BLOCK_GROUP_DUP | BTRFS_BLOCK_GROUP_RAID1 | 3473 if (flags & (BTRFS_BLOCK_GROUP_DUP | BTRFS_BLOCK_GROUP_RAID1 |
3474 BTRFS_BLOCK_GROUP_RAID10)) 3474 BTRFS_BLOCK_GROUP_RAID10))
3475 factor = 2; 3475 factor = 2;
3476 else 3476 else
3477 factor = 1; 3477 factor = 1;
3478 3478
3479 found = __find_space_info(info, flags); 3479 found = __find_space_info(info, flags);
3480 if (found) { 3480 if (found) {
3481 spin_lock(&found->lock); 3481 spin_lock(&found->lock);
3482 found->total_bytes += total_bytes; 3482 found->total_bytes += total_bytes;
3483 found->disk_total += total_bytes * factor; 3483 found->disk_total += total_bytes * factor;
3484 found->bytes_used += bytes_used; 3484 found->bytes_used += bytes_used;
3485 found->disk_used += bytes_used * factor; 3485 found->disk_used += bytes_used * factor;
3486 found->full = 0; 3486 found->full = 0;
3487 spin_unlock(&found->lock); 3487 spin_unlock(&found->lock);
3488 *space_info = found; 3488 *space_info = found;
3489 return 0; 3489 return 0;
3490 } 3490 }
3491 found = kzalloc(sizeof(*found), GFP_NOFS); 3491 found = kzalloc(sizeof(*found), GFP_NOFS);
3492 if (!found) 3492 if (!found)
3493 return -ENOMEM; 3493 return -ENOMEM;
3494 3494
3495 ret = percpu_counter_init(&found->total_bytes_pinned, 0, GFP_KERNEL); 3495 ret = percpu_counter_init(&found->total_bytes_pinned, 0, GFP_KERNEL);
3496 if (ret) { 3496 if (ret) {
3497 kfree(found); 3497 kfree(found);
3498 return ret; 3498 return ret;
3499 } 3499 }
3500 3500
3501 for (i = 0; i < BTRFS_NR_RAID_TYPES; i++) 3501 for (i = 0; i < BTRFS_NR_RAID_TYPES; i++)
3502 INIT_LIST_HEAD(&found->block_groups[i]); 3502 INIT_LIST_HEAD(&found->block_groups[i]);
3503 init_rwsem(&found->groups_sem); 3503 init_rwsem(&found->groups_sem);
3504 spin_lock_init(&found->lock); 3504 spin_lock_init(&found->lock);
3505 found->flags = flags & BTRFS_BLOCK_GROUP_TYPE_MASK; 3505 found->flags = flags & BTRFS_BLOCK_GROUP_TYPE_MASK;
3506 found->total_bytes = total_bytes; 3506 found->total_bytes = total_bytes;
3507 found->disk_total = total_bytes * factor; 3507 found->disk_total = total_bytes * factor;
3508 found->bytes_used = bytes_used; 3508 found->bytes_used = bytes_used;
3509 found->disk_used = bytes_used * factor; 3509 found->disk_used = bytes_used * factor;
3510 found->bytes_pinned = 0; 3510 found->bytes_pinned = 0;
3511 found->bytes_reserved = 0; 3511 found->bytes_reserved = 0;
3512 found->bytes_readonly = 0; 3512 found->bytes_readonly = 0;
3513 found->bytes_may_use = 0; 3513 found->bytes_may_use = 0;
3514 found->full = 0; 3514 found->full = 0;
3515 found->force_alloc = CHUNK_ALLOC_NO_FORCE; 3515 found->force_alloc = CHUNK_ALLOC_NO_FORCE;
3516 found->chunk_alloc = 0; 3516 found->chunk_alloc = 0;
3517 found->flush = 0; 3517 found->flush = 0;
3518 init_waitqueue_head(&found->wait); 3518 init_waitqueue_head(&found->wait);
3519 INIT_LIST_HEAD(&found->ro_bgs); 3519 INIT_LIST_HEAD(&found->ro_bgs);
3520 3520
3521 ret = kobject_init_and_add(&found->kobj, &space_info_ktype, 3521 ret = kobject_init_and_add(&found->kobj, &space_info_ktype,
3522 info->space_info_kobj, "%s", 3522 info->space_info_kobj, "%s",
3523 alloc_name(found->flags)); 3523 alloc_name(found->flags));
3524 if (ret) { 3524 if (ret) {
3525 kfree(found); 3525 kfree(found);
3526 return ret; 3526 return ret;
3527 } 3527 }
3528 3528
3529 *space_info = found; 3529 *space_info = found;
3530 list_add_rcu(&found->list, &info->space_info); 3530 list_add_rcu(&found->list, &info->space_info);
3531 if (flags & BTRFS_BLOCK_GROUP_DATA) 3531 if (flags & BTRFS_BLOCK_GROUP_DATA)
3532 info->data_sinfo = found; 3532 info->data_sinfo = found;
3533 3533
3534 return ret; 3534 return ret;
3535 } 3535 }
3536 3536
3537 static void set_avail_alloc_bits(struct btrfs_fs_info *fs_info, u64 flags) 3537 static void set_avail_alloc_bits(struct btrfs_fs_info *fs_info, u64 flags)
3538 { 3538 {
3539 u64 extra_flags = chunk_to_extended(flags) & 3539 u64 extra_flags = chunk_to_extended(flags) &
3540 BTRFS_EXTENDED_PROFILE_MASK; 3540 BTRFS_EXTENDED_PROFILE_MASK;
3541 3541
3542 write_seqlock(&fs_info->profiles_lock); 3542 write_seqlock(&fs_info->profiles_lock);
3543 if (flags & BTRFS_BLOCK_GROUP_DATA) 3543 if (flags & BTRFS_BLOCK_GROUP_DATA)
3544 fs_info->avail_data_alloc_bits |= extra_flags; 3544 fs_info->avail_data_alloc_bits |= extra_flags;
3545 if (flags & BTRFS_BLOCK_GROUP_METADATA) 3545 if (flags & BTRFS_BLOCK_GROUP_METADATA)
3546 fs_info->avail_metadata_alloc_bits |= extra_flags; 3546 fs_info->avail_metadata_alloc_bits |= extra_flags;
3547 if (flags & BTRFS_BLOCK_GROUP_SYSTEM) 3547 if (flags & BTRFS_BLOCK_GROUP_SYSTEM)
3548 fs_info->avail_system_alloc_bits |= extra_flags; 3548 fs_info->avail_system_alloc_bits |= extra_flags;
3549 write_sequnlock(&fs_info->profiles_lock); 3549 write_sequnlock(&fs_info->profiles_lock);
3550 } 3550 }
3551 3551
3552 /* 3552 /*
3553 * returns target flags in extended format or 0 if restripe for this 3553 * returns target flags in extended format or 0 if restripe for this
3554 * chunk_type is not in progress 3554 * chunk_type is not in progress
3555 * 3555 *
3556 * should be called with either volume_mutex or balance_lock held 3556 * should be called with either volume_mutex or balance_lock held
3557 */ 3557 */
3558 static u64 get_restripe_target(struct btrfs_fs_info *fs_info, u64 flags) 3558 static u64 get_restripe_target(struct btrfs_fs_info *fs_info, u64 flags)
3559 { 3559 {
3560 struct btrfs_balance_control *bctl = fs_info->balance_ctl; 3560 struct btrfs_balance_control *bctl = fs_info->balance_ctl;
3561 u64 target = 0; 3561 u64 target = 0;
3562 3562
3563 if (!bctl) 3563 if (!bctl)
3564 return 0; 3564 return 0;
3565 3565
3566 if (flags & BTRFS_BLOCK_GROUP_DATA && 3566 if (flags & BTRFS_BLOCK_GROUP_DATA &&
3567 bctl->data.flags & BTRFS_BALANCE_ARGS_CONVERT) { 3567 bctl->data.flags & BTRFS_BALANCE_ARGS_CONVERT) {
3568 target = BTRFS_BLOCK_GROUP_DATA | bctl->data.target; 3568 target = BTRFS_BLOCK_GROUP_DATA | bctl->data.target;
3569 } else if (flags & BTRFS_BLOCK_GROUP_SYSTEM && 3569 } else if (flags & BTRFS_BLOCK_GROUP_SYSTEM &&
3570 bctl->sys.flags & BTRFS_BALANCE_ARGS_CONVERT) { 3570 bctl->sys.flags & BTRFS_BALANCE_ARGS_CONVERT) {
3571 target = BTRFS_BLOCK_GROUP_SYSTEM | bctl->sys.target; 3571 target = BTRFS_BLOCK_GROUP_SYSTEM | bctl->sys.target;
3572 } else if (flags & BTRFS_BLOCK_GROUP_METADATA && 3572 } else if (flags & BTRFS_BLOCK_GROUP_METADATA &&
3573 bctl->meta.flags & BTRFS_BALANCE_ARGS_CONVERT) { 3573 bctl->meta.flags & BTRFS_BALANCE_ARGS_CONVERT) {
3574 target = BTRFS_BLOCK_GROUP_METADATA | bctl->meta.target; 3574 target = BTRFS_BLOCK_GROUP_METADATA | bctl->meta.target;
3575 } 3575 }
3576 3576
3577 return target; 3577 return target;
3578 } 3578 }
3579 3579
3580 /* 3580 /*
3581 * @flags: available profiles in extended format (see ctree.h) 3581 * @flags: available profiles in extended format (see ctree.h)
3582 * 3582 *
3583 * Returns reduced profile in chunk format. If profile changing is in 3583 * Returns reduced profile in chunk format. If profile changing is in
3584 * progress (either running or paused) picks the target profile (if it's 3584 * progress (either running or paused) picks the target profile (if it's
3585 * already available), otherwise falls back to plain reducing. 3585 * already available), otherwise falls back to plain reducing.
3586 */ 3586 */
3587 static u64 btrfs_reduce_alloc_profile(struct btrfs_root *root, u64 flags) 3587 static u64 btrfs_reduce_alloc_profile(struct btrfs_root *root, u64 flags)
3588 { 3588 {
3589 u64 num_devices = root->fs_info->fs_devices->rw_devices; 3589 u64 num_devices = root->fs_info->fs_devices->rw_devices;
3590 u64 target; 3590 u64 target;
3591 u64 tmp; 3591 u64 tmp;
3592 3592
3593 /* 3593 /*
3594 * see if restripe for this chunk_type is in progress, if so 3594 * see if restripe for this chunk_type is in progress, if so
3595 * try to reduce to the target profile 3595 * try to reduce to the target profile
3596 */ 3596 */
3597 spin_lock(&root->fs_info->balance_lock); 3597 spin_lock(&root->fs_info->balance_lock);
3598 target = get_restripe_target(root->fs_info, flags); 3598 target = get_restripe_target(root->fs_info, flags);
3599 if (target) { 3599 if (target) {
3600 /* pick target profile only if it's already available */ 3600 /* pick target profile only if it's already available */
3601 if ((flags & target) & BTRFS_EXTENDED_PROFILE_MASK) { 3601 if ((flags & target) & BTRFS_EXTENDED_PROFILE_MASK) {
3602 spin_unlock(&root->fs_info->balance_lock); 3602 spin_unlock(&root->fs_info->balance_lock);
3603 return extended_to_chunk(target); 3603 return extended_to_chunk(target);
3604 } 3604 }
3605 } 3605 }
3606 spin_unlock(&root->fs_info->balance_lock); 3606 spin_unlock(&root->fs_info->balance_lock);
3607 3607
3608 /* First, mask out the RAID levels which aren't possible */ 3608 /* First, mask out the RAID levels which aren't possible */
3609 if (num_devices == 1) 3609 if (num_devices == 1)
3610 flags &= ~(BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_RAID0 | 3610 flags &= ~(BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_RAID0 |
3611 BTRFS_BLOCK_GROUP_RAID5); 3611 BTRFS_BLOCK_GROUP_RAID5);
3612 if (num_devices < 3) 3612 if (num_devices < 3)
3613 flags &= ~BTRFS_BLOCK_GROUP_RAID6; 3613 flags &= ~BTRFS_BLOCK_GROUP_RAID6;
3614 if (num_devices < 4) 3614 if (num_devices < 4)
3615 flags &= ~BTRFS_BLOCK_GROUP_RAID10; 3615 flags &= ~BTRFS_BLOCK_GROUP_RAID10;
3616 3616
3617 tmp = flags & (BTRFS_BLOCK_GROUP_DUP | BTRFS_BLOCK_GROUP_RAID0 | 3617 tmp = flags & (BTRFS_BLOCK_GROUP_DUP | BTRFS_BLOCK_GROUP_RAID0 |
3618 BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_RAID5 | 3618 BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_RAID5 |
3619 BTRFS_BLOCK_GROUP_RAID6 | BTRFS_BLOCK_GROUP_RAID10); 3619 BTRFS_BLOCK_GROUP_RAID6 | BTRFS_BLOCK_GROUP_RAID10);
3620 flags &= ~tmp; 3620 flags &= ~tmp;
3621 3621
3622 if (tmp & BTRFS_BLOCK_GROUP_RAID6) 3622 if (tmp & BTRFS_BLOCK_GROUP_RAID6)
3623 tmp = BTRFS_BLOCK_GROUP_RAID6; 3623 tmp = BTRFS_BLOCK_GROUP_RAID6;
3624 else if (tmp & BTRFS_BLOCK_GROUP_RAID5) 3624 else if (tmp & BTRFS_BLOCK_GROUP_RAID5)
3625 tmp = BTRFS_BLOCK_GROUP_RAID5; 3625 tmp = BTRFS_BLOCK_GROUP_RAID5;
3626 else if (tmp & BTRFS_BLOCK_GROUP_RAID10) 3626 else if (tmp & BTRFS_BLOCK_GROUP_RAID10)
3627 tmp = BTRFS_BLOCK_GROUP_RAID10; 3627 tmp = BTRFS_BLOCK_GROUP_RAID10;
3628 else if (tmp & BTRFS_BLOCK_GROUP_RAID1) 3628 else if (tmp & BTRFS_BLOCK_GROUP_RAID1)
3629 tmp = BTRFS_BLOCK_GROUP_RAID1; 3629 tmp = BTRFS_BLOCK_GROUP_RAID1;
3630 else if (tmp & BTRFS_BLOCK_GROUP_RAID0) 3630 else if (tmp & BTRFS_BLOCK_GROUP_RAID0)
3631 tmp = BTRFS_BLOCK_GROUP_RAID0; 3631 tmp = BTRFS_BLOCK_GROUP_RAID0;
3632 3632
3633 return extended_to_chunk(flags | tmp); 3633 return extended_to_chunk(flags | tmp);
3634 } 3634 }
3635 3635
3636 static u64 get_alloc_profile(struct btrfs_root *root, u64 orig_flags) 3636 static u64 get_alloc_profile(struct btrfs_root *root, u64 orig_flags)
3637 { 3637 {
3638 unsigned seq; 3638 unsigned seq;
3639 u64 flags; 3639 u64 flags;
3640 3640
3641 do { 3641 do {
3642 flags = orig_flags; 3642 flags = orig_flags;
3643 seq = read_seqbegin(&root->fs_info->profiles_lock); 3643 seq = read_seqbegin(&root->fs_info->profiles_lock);
3644 3644
3645 if (flags & BTRFS_BLOCK_GROUP_DATA) 3645 if (flags & BTRFS_BLOCK_GROUP_DATA)
3646 flags |= root->fs_info->avail_data_alloc_bits; 3646 flags |= root->fs_info->avail_data_alloc_bits;
3647 else if (flags & BTRFS_BLOCK_GROUP_SYSTEM) 3647 else if (flags & BTRFS_BLOCK_GROUP_SYSTEM)
3648 flags |= root->fs_info->avail_system_alloc_bits; 3648 flags |= root->fs_info->avail_system_alloc_bits;
3649 else if (flags & BTRFS_BLOCK_GROUP_METADATA) 3649 else if (flags & BTRFS_BLOCK_GROUP_METADATA)
3650 flags |= root->fs_info->avail_metadata_alloc_bits; 3650 flags |= root->fs_info->avail_metadata_alloc_bits;
3651 } while (read_seqretry(&root->fs_info->profiles_lock, seq)); 3651 } while (read_seqretry(&root->fs_info->profiles_lock, seq));
3652 3652
3653 return btrfs_reduce_alloc_profile(root, flags); 3653 return btrfs_reduce_alloc_profile(root, flags);
3654 } 3654 }
3655 3655
3656 u64 btrfs_get_alloc_profile(struct btrfs_root *root, int data) 3656 u64 btrfs_get_alloc_profile(struct btrfs_root *root, int data)
3657 { 3657 {
3658 u64 flags; 3658 u64 flags;
3659 u64 ret; 3659 u64 ret;
3660 3660
3661 if (data) 3661 if (data)
3662 flags = BTRFS_BLOCK_GROUP_DATA; 3662 flags = BTRFS_BLOCK_GROUP_DATA;
3663 else if (root == root->fs_info->chunk_root) 3663 else if (root == root->fs_info->chunk_root)
3664 flags = BTRFS_BLOCK_GROUP_SYSTEM; 3664 flags = BTRFS_BLOCK_GROUP_SYSTEM;
3665 else 3665 else
3666 flags = BTRFS_BLOCK_GROUP_METADATA; 3666 flags = BTRFS_BLOCK_GROUP_METADATA;
3667 3667
3668 ret = get_alloc_profile(root, flags); 3668 ret = get_alloc_profile(root, flags);
3669 return ret; 3669 return ret;
3670 } 3670 }
3671 3671
3672 /* 3672 /*
3673 * This will check the space that the inode allocates from to make sure we have 3673 * This will check the space that the inode allocates from to make sure we have
3674 * enough space for bytes. 3674 * enough space for bytes.
3675 */ 3675 */
3676 int btrfs_check_data_free_space(struct inode *inode, u64 bytes) 3676 int btrfs_check_data_free_space(struct inode *inode, u64 bytes)
3677 { 3677 {
3678 struct btrfs_space_info *data_sinfo; 3678 struct btrfs_space_info *data_sinfo;
3679 struct btrfs_root *root = BTRFS_I(inode)->root; 3679 struct btrfs_root *root = BTRFS_I(inode)->root;
3680 struct btrfs_fs_info *fs_info = root->fs_info; 3680 struct btrfs_fs_info *fs_info = root->fs_info;
3681 u64 used; 3681 u64 used;
3682 int ret = 0, committed = 0, alloc_chunk = 1; 3682 int ret = 0, committed = 0, alloc_chunk = 1;
3683 3683
3684 /* make sure bytes are sectorsize aligned */ 3684 /* make sure bytes are sectorsize aligned */
3685 bytes = ALIGN(bytes, root->sectorsize); 3685 bytes = ALIGN(bytes, root->sectorsize);
3686 3686
3687 if (btrfs_is_free_space_inode(inode)) { 3687 if (btrfs_is_free_space_inode(inode)) {
3688 committed = 1; 3688 committed = 1;
3689 ASSERT(current->journal_info); 3689 ASSERT(current->journal_info);
3690 } 3690 }
3691 3691
3692 data_sinfo = fs_info->data_sinfo; 3692 data_sinfo = fs_info->data_sinfo;
3693 if (!data_sinfo) 3693 if (!data_sinfo)
3694 goto alloc; 3694 goto alloc;
3695 3695
3696 again: 3696 again:
3697 /* make sure we have enough space to handle the data first */ 3697 /* make sure we have enough space to handle the data first */
3698 spin_lock(&data_sinfo->lock); 3698 spin_lock(&data_sinfo->lock);
3699 used = data_sinfo->bytes_used + data_sinfo->bytes_reserved + 3699 used = data_sinfo->bytes_used + data_sinfo->bytes_reserved +
3700 data_sinfo->bytes_pinned + data_sinfo->bytes_readonly + 3700 data_sinfo->bytes_pinned + data_sinfo->bytes_readonly +
3701 data_sinfo->bytes_may_use; 3701 data_sinfo->bytes_may_use;
3702 3702
3703 if (used + bytes > data_sinfo->total_bytes) { 3703 if (used + bytes > data_sinfo->total_bytes) {
3704 struct btrfs_trans_handle *trans; 3704 struct btrfs_trans_handle *trans;
3705 3705
3706 /* 3706 /*
3707 * if we don't have enough free bytes in this space then we need 3707 * if we don't have enough free bytes in this space then we need
3708 * to alloc a new chunk. 3708 * to alloc a new chunk.
3709 */ 3709 */
3710 if (!data_sinfo->full && alloc_chunk) { 3710 if (!data_sinfo->full && alloc_chunk) {
3711 u64 alloc_target; 3711 u64 alloc_target;
3712 3712
3713 data_sinfo->force_alloc = CHUNK_ALLOC_FORCE; 3713 data_sinfo->force_alloc = CHUNK_ALLOC_FORCE;
3714 spin_unlock(&data_sinfo->lock); 3714 spin_unlock(&data_sinfo->lock);
3715 alloc: 3715 alloc:
3716 alloc_target = btrfs_get_alloc_profile(root, 1); 3716 alloc_target = btrfs_get_alloc_profile(root, 1);
3717 /* 3717 /*
3718 * It is ugly that we don't call nolock join 3718 * It is ugly that we don't call nolock join
3719 * transaction for the free space inode case here. 3719 * transaction for the free space inode case here.
3720 * But it is safe because we only do the data space 3720 * But it is safe because we only do the data space
3721 * reservation for the free space cache in the 3721 * reservation for the free space cache in the
3722 * transaction context, the common join transaction 3722 * transaction context, the common join transaction
3723 * just increase the counter of the current transaction 3723 * just increase the counter of the current transaction
3724 * handler, doesn't try to acquire the trans_lock of 3724 * handler, doesn't try to acquire the trans_lock of
3725 * the fs. 3725 * the fs.
3726 */ 3726 */
3727 trans = btrfs_join_transaction(root); 3727 trans = btrfs_join_transaction(root);
3728 if (IS_ERR(trans)) 3728 if (IS_ERR(trans))
3729 return PTR_ERR(trans); 3729 return PTR_ERR(trans);
3730 3730
3731 ret = do_chunk_alloc(trans, root->fs_info->extent_root, 3731 ret = do_chunk_alloc(trans, root->fs_info->extent_root,
3732 alloc_target, 3732 alloc_target,
3733 CHUNK_ALLOC_NO_FORCE); 3733 CHUNK_ALLOC_NO_FORCE);
3734 btrfs_end_transaction(trans, root); 3734 btrfs_end_transaction(trans, root);
3735 if (ret < 0) { 3735 if (ret < 0) {
3736 if (ret != -ENOSPC) 3736 if (ret != -ENOSPC)
3737 return ret; 3737 return ret;
3738 else 3738 else
3739 goto commit_trans; 3739 goto commit_trans;
3740 } 3740 }
3741 3741
3742 if (!data_sinfo) 3742 if (!data_sinfo)
3743 data_sinfo = fs_info->data_sinfo; 3743 data_sinfo = fs_info->data_sinfo;
3744 3744
3745 goto again; 3745 goto again;
3746 } 3746 }
3747 3747
3748 /* 3748 /*
3749 * If we don't have enough pinned space to deal with this 3749 * If we don't have enough pinned space to deal with this
3750 * allocation don't bother committing the transaction. 3750 * allocation don't bother committing the transaction.
3751 */ 3751 */
3752 if (percpu_counter_compare(&data_sinfo->total_bytes_pinned, 3752 if (percpu_counter_compare(&data_sinfo->total_bytes_pinned,
3753 bytes) < 0) 3753 bytes) < 0)
3754 committed = 1; 3754 committed = 1;
3755 spin_unlock(&data_sinfo->lock); 3755 spin_unlock(&data_sinfo->lock);
3756 3756
3757 /* commit the current transaction and try again */ 3757 /* commit the current transaction and try again */
3758 commit_trans: 3758 commit_trans:
3759 if (!committed && 3759 if (!committed &&
3760 !atomic_read(&root->fs_info->open_ioctl_trans)) { 3760 !atomic_read(&root->fs_info->open_ioctl_trans)) {
3761 committed = 1; 3761 committed = 1;
3762 3762
3763 trans = btrfs_join_transaction(root); 3763 trans = btrfs_join_transaction(root);
3764 if (IS_ERR(trans)) 3764 if (IS_ERR(trans))
3765 return PTR_ERR(trans); 3765 return PTR_ERR(trans);
3766 ret = btrfs_commit_transaction(trans, root); 3766 ret = btrfs_commit_transaction(trans, root);
3767 if (ret) 3767 if (ret)
3768 return ret; 3768 return ret;
3769 goto again; 3769 goto again;
3770 } 3770 }
3771 3771
3772 trace_btrfs_space_reservation(root->fs_info, 3772 trace_btrfs_space_reservation(root->fs_info,
3773 "space_info:enospc", 3773 "space_info:enospc",
3774 data_sinfo->flags, bytes, 1); 3774 data_sinfo->flags, bytes, 1);
3775 return -ENOSPC; 3775 return -ENOSPC;
3776 } 3776 }
3777 data_sinfo->bytes_may_use += bytes; 3777 data_sinfo->bytes_may_use += bytes;
3778 trace_btrfs_space_reservation(root->fs_info, "space_info", 3778 trace_btrfs_space_reservation(root->fs_info, "space_info",
3779 data_sinfo->flags, bytes, 1); 3779 data_sinfo->flags, bytes, 1);
3780 spin_unlock(&data_sinfo->lock); 3780 spin_unlock(&data_sinfo->lock);
3781 3781
3782 return 0; 3782 return 0;
3783 } 3783 }
3784 3784
3785 /* 3785 /*
3786 * Called if we need to clear a data reservation for this inode. 3786 * Called if we need to clear a data reservation for this inode.
3787 */ 3787 */
3788 void btrfs_free_reserved_data_space(struct inode *inode, u64 bytes) 3788 void btrfs_free_reserved_data_space(struct inode *inode, u64 bytes)
3789 { 3789 {
3790 struct btrfs_root *root = BTRFS_I(inode)->root; 3790 struct btrfs_root *root = BTRFS_I(inode)->root;
3791 struct btrfs_space_info *data_sinfo; 3791 struct btrfs_space_info *data_sinfo;
3792 3792
3793 /* make sure bytes are sectorsize aligned */ 3793 /* make sure bytes are sectorsize aligned */
3794 bytes = ALIGN(bytes, root->sectorsize); 3794 bytes = ALIGN(bytes, root->sectorsize);
3795 3795
3796 data_sinfo = root->fs_info->data_sinfo; 3796 data_sinfo = root->fs_info->data_sinfo;
3797 spin_lock(&data_sinfo->lock); 3797 spin_lock(&data_sinfo->lock);
3798 WARN_ON(data_sinfo->bytes_may_use < bytes); 3798 WARN_ON(data_sinfo->bytes_may_use < bytes);
3799 data_sinfo->bytes_may_use -= bytes; 3799 data_sinfo->bytes_may_use -= bytes;
3800 trace_btrfs_space_reservation(root->fs_info, "space_info", 3800 trace_btrfs_space_reservation(root->fs_info, "space_info",
3801 data_sinfo->flags, bytes, 0); 3801 data_sinfo->flags, bytes, 0);
3802 spin_unlock(&data_sinfo->lock); 3802 spin_unlock(&data_sinfo->lock);
3803 } 3803 }
3804 3804
3805 static void force_metadata_allocation(struct btrfs_fs_info *info) 3805 static void force_metadata_allocation(struct btrfs_fs_info *info)
3806 { 3806 {
3807 struct list_head *head = &info->space_info; 3807 struct list_head *head = &info->space_info;
3808 struct btrfs_space_info *found; 3808 struct btrfs_space_info *found;
3809 3809
3810 rcu_read_lock(); 3810 rcu_read_lock();
3811 list_for_each_entry_rcu(found, head, list) { 3811 list_for_each_entry_rcu(found, head, list) {
3812 if (found->flags & BTRFS_BLOCK_GROUP_METADATA) 3812 if (found->flags & BTRFS_BLOCK_GROUP_METADATA)
3813 found->force_alloc = CHUNK_ALLOC_FORCE; 3813 found->force_alloc = CHUNK_ALLOC_FORCE;
3814 } 3814 }
3815 rcu_read_unlock(); 3815 rcu_read_unlock();
3816 } 3816 }
3817 3817
3818 static inline u64 calc_global_rsv_need_space(struct btrfs_block_rsv *global) 3818 static inline u64 calc_global_rsv_need_space(struct btrfs_block_rsv *global)
3819 { 3819 {
3820 return (global->size << 1); 3820 return (global->size << 1);
3821 } 3821 }
3822 3822
3823 static int should_alloc_chunk(struct btrfs_root *root, 3823 static int should_alloc_chunk(struct btrfs_root *root,
3824 struct btrfs_space_info *sinfo, int force) 3824 struct btrfs_space_info *sinfo, int force)
3825 { 3825 {
3826 struct btrfs_block_rsv *global_rsv = &root->fs_info->global_block_rsv; 3826 struct btrfs_block_rsv *global_rsv = &root->fs_info->global_block_rsv;
3827 u64 num_bytes = sinfo->total_bytes - sinfo->bytes_readonly; 3827 u64 num_bytes = sinfo->total_bytes - sinfo->bytes_readonly;
3828 u64 num_allocated = sinfo->bytes_used + sinfo->bytes_reserved; 3828 u64 num_allocated = sinfo->bytes_used + sinfo->bytes_reserved;
3829 u64 thresh; 3829 u64 thresh;
3830 3830
3831 if (force == CHUNK_ALLOC_FORCE) 3831 if (force == CHUNK_ALLOC_FORCE)
3832 return 1; 3832 return 1;
3833 3833
3834 /* 3834 /*
3835 * We need to take into account the global rsv because for all intents 3835 * We need to take into account the global rsv because for all intents
3836 * and purposes it's used space. Don't worry about locking the 3836 * and purposes it's used space. Don't worry about locking the
3837 * global_rsv, it doesn't change except when the transaction commits. 3837 * global_rsv, it doesn't change except when the transaction commits.
3838 */ 3838 */
3839 if (sinfo->flags & BTRFS_BLOCK_GROUP_METADATA) 3839 if (sinfo->flags & BTRFS_BLOCK_GROUP_METADATA)
3840 num_allocated += calc_global_rsv_need_space(global_rsv); 3840 num_allocated += calc_global_rsv_need_space(global_rsv);
3841 3841
3842 /* 3842 /*
3843 * in limited mode, we want to have some free space up to 3843 * in limited mode, we want to have some free space up to
3844 * about 1% of the FS size. 3844 * about 1% of the FS size.
3845 */ 3845 */
3846 if (force == CHUNK_ALLOC_LIMITED) { 3846 if (force == CHUNK_ALLOC_LIMITED) {
3847 thresh = btrfs_super_total_bytes(root->fs_info->super_copy); 3847 thresh = btrfs_super_total_bytes(root->fs_info->super_copy);
3848 thresh = max_t(u64, 64 * 1024 * 1024, 3848 thresh = max_t(u64, 64 * 1024 * 1024,
3849 div_factor_fine(thresh, 1)); 3849 div_factor_fine(thresh, 1));
3850 3850
3851 if (num_bytes - num_allocated < thresh) 3851 if (num_bytes - num_allocated < thresh)
3852 return 1; 3852 return 1;
3853 } 3853 }
3854 3854
3855 if (num_allocated + 2 * 1024 * 1024 < div_factor(num_bytes, 8)) 3855 if (num_allocated + 2 * 1024 * 1024 < div_factor(num_bytes, 8))
3856 return 0; 3856 return 0;
3857 return 1; 3857 return 1;
3858 } 3858 }
3859 3859
3860 static u64 get_system_chunk_thresh(struct btrfs_root *root, u64 type) 3860 static u64 get_system_chunk_thresh(struct btrfs_root *root, u64 type)
3861 { 3861 {
3862 u64 num_dev; 3862 u64 num_dev;
3863 3863
3864 if (type & (BTRFS_BLOCK_GROUP_RAID10 | 3864 if (type & (BTRFS_BLOCK_GROUP_RAID10 |
3865 BTRFS_BLOCK_GROUP_RAID0 | 3865 BTRFS_BLOCK_GROUP_RAID0 |
3866 BTRFS_BLOCK_GROUP_RAID5 | 3866 BTRFS_BLOCK_GROUP_RAID5 |
3867 BTRFS_BLOCK_GROUP_RAID6)) 3867 BTRFS_BLOCK_GROUP_RAID6))
3868 num_dev = root->fs_info->fs_devices->rw_devices; 3868 num_dev = root->fs_info->fs_devices->rw_devices;
3869 else if (type & BTRFS_BLOCK_GROUP_RAID1) 3869 else if (type & BTRFS_BLOCK_GROUP_RAID1)
3870 num_dev = 2; 3870 num_dev = 2;
3871 else 3871 else
3872 num_dev = 1; /* DUP or single */ 3872 num_dev = 1; /* DUP or single */
3873 3873
3874 /* metadata for updaing devices and chunk tree */ 3874 /* metadata for updaing devices and chunk tree */
3875 return btrfs_calc_trans_metadata_size(root, num_dev + 1); 3875 return btrfs_calc_trans_metadata_size(root, num_dev + 1);
3876 } 3876 }
3877 3877
3878 static void check_system_chunk(struct btrfs_trans_handle *trans, 3878 static void check_system_chunk(struct btrfs_trans_handle *trans,
3879 struct btrfs_root *root, u64 type) 3879 struct btrfs_root *root, u64 type)
3880 { 3880 {
3881 struct btrfs_space_info *info; 3881 struct btrfs_space_info *info;
3882 u64 left; 3882 u64 left;
3883 u64 thresh; 3883 u64 thresh;
3884 3884
3885 info = __find_space_info(root->fs_info, BTRFS_BLOCK_GROUP_SYSTEM); 3885 info = __find_space_info(root->fs_info, BTRFS_BLOCK_GROUP_SYSTEM);
3886 spin_lock(&info->lock); 3886 spin_lock(&info->lock);
3887 left = info->total_bytes - info->bytes_used - info->bytes_pinned - 3887 left = info->total_bytes - info->bytes_used - info->bytes_pinned -
3888 info->bytes_reserved - info->bytes_readonly; 3888 info->bytes_reserved - info->bytes_readonly;
3889 spin_unlock(&info->lock); 3889 spin_unlock(&info->lock);
3890 3890
3891 thresh = get_system_chunk_thresh(root, type); 3891 thresh = get_system_chunk_thresh(root, type);
3892 if (left < thresh && btrfs_test_opt(root, ENOSPC_DEBUG)) { 3892 if (left < thresh && btrfs_test_opt(root, ENOSPC_DEBUG)) {
3893 btrfs_info(root->fs_info, "left=%llu, need=%llu, flags=%llu", 3893 btrfs_info(root->fs_info, "left=%llu, need=%llu, flags=%llu",
3894 left, thresh, type); 3894 left, thresh, type);
3895 dump_space_info(info, 0, 0); 3895 dump_space_info(info, 0, 0);
3896 } 3896 }
3897 3897
3898 if (left < thresh) { 3898 if (left < thresh) {
3899 u64 flags; 3899 u64 flags;
3900 3900
3901 flags = btrfs_get_alloc_profile(root->fs_info->chunk_root, 0); 3901 flags = btrfs_get_alloc_profile(root->fs_info->chunk_root, 0);
3902 btrfs_alloc_chunk(trans, root, flags); 3902 btrfs_alloc_chunk(trans, root, flags);
3903 } 3903 }
3904 } 3904 }
3905 3905
3906 static int do_chunk_alloc(struct btrfs_trans_handle *trans, 3906 static int do_chunk_alloc(struct btrfs_trans_handle *trans,
3907 struct btrfs_root *extent_root, u64 flags, int force) 3907 struct btrfs_root *extent_root, u64 flags, int force)
3908 { 3908 {
3909 struct btrfs_space_info *space_info; 3909 struct btrfs_space_info *space_info;
3910 struct btrfs_fs_info *fs_info = extent_root->fs_info; 3910 struct btrfs_fs_info *fs_info = extent_root->fs_info;
3911 int wait_for_alloc = 0; 3911 int wait_for_alloc = 0;
3912 int ret = 0; 3912 int ret = 0;
3913 3913
3914 /* Don't re-enter if we're already allocating a chunk */ 3914 /* Don't re-enter if we're already allocating a chunk */
3915 if (trans->allocating_chunk) 3915 if (trans->allocating_chunk)
3916 return -ENOSPC; 3916 return -ENOSPC;
3917 3917
3918 space_info = __find_space_info(extent_root->fs_info, flags); 3918 space_info = __find_space_info(extent_root->fs_info, flags);
3919 if (!space_info) { 3919 if (!space_info) {
3920 ret = update_space_info(extent_root->fs_info, flags, 3920 ret = update_space_info(extent_root->fs_info, flags,
3921 0, 0, &space_info); 3921 0, 0, &space_info);
3922 BUG_ON(ret); /* -ENOMEM */ 3922 BUG_ON(ret); /* -ENOMEM */
3923 } 3923 }
3924 BUG_ON(!space_info); /* Logic error */ 3924 BUG_ON(!space_info); /* Logic error */
3925 3925
3926 again: 3926 again:
3927 spin_lock(&space_info->lock); 3927 spin_lock(&space_info->lock);
3928 if (force < space_info->force_alloc) 3928 if (force < space_info->force_alloc)
3929 force = space_info->force_alloc; 3929 force = space_info->force_alloc;
3930 if (space_info->full) { 3930 if (space_info->full) {
3931 if (should_alloc_chunk(extent_root, space_info, force)) 3931 if (should_alloc_chunk(extent_root, space_info, force))
3932 ret = -ENOSPC; 3932 ret = -ENOSPC;
3933 else 3933 else
3934 ret = 0; 3934 ret = 0;
3935 spin_unlock(&space_info->lock); 3935 spin_unlock(&space_info->lock);
3936 return ret; 3936 return ret;
3937 } 3937 }
3938 3938
3939 if (!should_alloc_chunk(extent_root, space_info, force)) { 3939 if (!should_alloc_chunk(extent_root, space_info, force)) {
3940 spin_unlock(&space_info->lock); 3940 spin_unlock(&space_info->lock);
3941 return 0; 3941 return 0;
3942 } else if (space_info->chunk_alloc) { 3942 } else if (space_info->chunk_alloc) {
3943 wait_for_alloc = 1; 3943 wait_for_alloc = 1;
3944 } else { 3944 } else {
3945 space_info->chunk_alloc = 1; 3945 space_info->chunk_alloc = 1;
3946 } 3946 }
3947 3947
3948 spin_unlock(&space_info->lock); 3948 spin_unlock(&space_info->lock);
3949 3949
3950 mutex_lock(&fs_info->chunk_mutex); 3950 mutex_lock(&fs_info->chunk_mutex);
3951 3951
3952 /* 3952 /*
3953 * The chunk_mutex is held throughout the entirety of a chunk 3953 * The chunk_mutex is held throughout the entirety of a chunk
3954 * allocation, so once we've acquired the chunk_mutex we know that the 3954 * allocation, so once we've acquired the chunk_mutex we know that the
3955 * other guy is done and we need to recheck and see if we should 3955 * other guy is done and we need to recheck and see if we should
3956 * allocate. 3956 * allocate.
3957 */ 3957 */
3958 if (wait_for_alloc) { 3958 if (wait_for_alloc) {
3959 mutex_unlock(&fs_info->chunk_mutex); 3959 mutex_unlock(&fs_info->chunk_mutex);
3960 wait_for_alloc = 0; 3960 wait_for_alloc = 0;
3961 goto again; 3961 goto again;
3962 } 3962 }
3963 3963
3964 trans->allocating_chunk = true; 3964 trans->allocating_chunk = true;
3965 3965
3966 /* 3966 /*
3967 * If we have mixed data/metadata chunks we want to make sure we keep 3967 * If we have mixed data/metadata chunks we want to make sure we keep
3968 * allocating mixed chunks instead of individual chunks. 3968 * allocating mixed chunks instead of individual chunks.
3969 */ 3969 */
3970 if (btrfs_mixed_space_info(space_info)) 3970 if (btrfs_mixed_space_info(space_info))
3971 flags |= (BTRFS_BLOCK_GROUP_DATA | BTRFS_BLOCK_GROUP_METADATA); 3971 flags |= (BTRFS_BLOCK_GROUP_DATA | BTRFS_BLOCK_GROUP_METADATA);
3972 3972
3973 /* 3973 /*
3974 * if we're doing a data chunk, go ahead and make sure that 3974 * if we're doing a data chunk, go ahead and make sure that
3975 * we keep a reasonable number of metadata chunks allocated in the 3975 * we keep a reasonable number of metadata chunks allocated in the
3976 * FS as well. 3976 * FS as well.
3977 */ 3977 */
3978 if (flags & BTRFS_BLOCK_GROUP_DATA && fs_info->metadata_ratio) { 3978 if (flags & BTRFS_BLOCK_GROUP_DATA && fs_info->metadata_ratio) {
3979 fs_info->data_chunk_allocations++; 3979 fs_info->data_chunk_allocations++;
3980 if (!(fs_info->data_chunk_allocations % 3980 if (!(fs_info->data_chunk_allocations %
3981 fs_info->metadata_ratio)) 3981 fs_info->metadata_ratio))
3982 force_metadata_allocation(fs_info); 3982 force_metadata_allocation(fs_info);
3983 } 3983 }
3984 3984
3985 /* 3985 /*
3986 * Check if we have enough space in SYSTEM chunk because we may need 3986 * Check if we have enough space in SYSTEM chunk because we may need
3987 * to update devices. 3987 * to update devices.
3988 */ 3988 */
3989 check_system_chunk(trans, extent_root, flags); 3989 check_system_chunk(trans, extent_root, flags);
3990 3990
3991 ret = btrfs_alloc_chunk(trans, extent_root, flags); 3991 ret = btrfs_alloc_chunk(trans, extent_root, flags);
3992 trans->allocating_chunk = false; 3992 trans->allocating_chunk = false;
3993 3993
3994 spin_lock(&space_info->lock); 3994 spin_lock(&space_info->lock);
3995 if (ret < 0 && ret != -ENOSPC) 3995 if (ret < 0 && ret != -ENOSPC)
3996 goto out; 3996 goto out;
3997 if (ret) 3997 if (ret)
3998 space_info->full = 1; 3998 space_info->full = 1;
3999 else 3999 else
4000 ret = 1; 4000 ret = 1;
4001 4001
4002 space_info->force_alloc = CHUNK_ALLOC_NO_FORCE; 4002 space_info->force_alloc = CHUNK_ALLOC_NO_FORCE;
4003 out: 4003 out:
4004 space_info->chunk_alloc = 0; 4004 space_info->chunk_alloc = 0;
4005 spin_unlock(&space_info->lock); 4005 spin_unlock(&space_info->lock);
4006 mutex_unlock(&fs_info->chunk_mutex); 4006 mutex_unlock(&fs_info->chunk_mutex);
4007 return ret; 4007 return ret;
4008 } 4008 }
4009 4009
4010 static int can_overcommit(struct btrfs_root *root, 4010 static int can_overcommit(struct btrfs_root *root,
4011 struct btrfs_space_info *space_info, u64 bytes, 4011 struct btrfs_space_info *space_info, u64 bytes,
4012 enum btrfs_reserve_flush_enum flush) 4012 enum btrfs_reserve_flush_enum flush)
4013 { 4013 {
4014 struct btrfs_block_rsv *global_rsv = &root->fs_info->global_block_rsv; 4014 struct btrfs_block_rsv *global_rsv = &root->fs_info->global_block_rsv;
4015 u64 profile = btrfs_get_alloc_profile(root, 0); 4015 u64 profile = btrfs_get_alloc_profile(root, 0);
4016 u64 space_size; 4016 u64 space_size;
4017 u64 avail; 4017 u64 avail;
4018 u64 used; 4018 u64 used;
4019 4019
4020 used = space_info->bytes_used + space_info->bytes_reserved + 4020 used = space_info->bytes_used + space_info->bytes_reserved +
4021 space_info->bytes_pinned + space_info->bytes_readonly; 4021 space_info->bytes_pinned + space_info->bytes_readonly;
4022 4022
4023 /* 4023 /*
4024 * We only want to allow over committing if we have lots of actual space 4024 * We only want to allow over committing if we have lots of actual space
4025 * free, but if we don't have enough space to handle the global reserve 4025 * free, but if we don't have enough space to handle the global reserve
4026 * space then we could end up having a real enospc problem when trying 4026 * space then we could end up having a real enospc problem when trying
4027 * to allocate a chunk or some other such important allocation. 4027 * to allocate a chunk or some other such important allocation.
4028 */ 4028 */
4029 spin_lock(&global_rsv->lock); 4029 spin_lock(&global_rsv->lock);
4030 space_size = calc_global_rsv_need_space(global_rsv); 4030 space_size = calc_global_rsv_need_space(global_rsv);
4031 spin_unlock(&global_rsv->lock); 4031 spin_unlock(&global_rsv->lock);
4032 if (used + space_size >= space_info->total_bytes) 4032 if (used + space_size >= space_info->total_bytes)
4033 return 0; 4033 return 0;
4034 4034
4035 used += space_info->bytes_may_use; 4035 used += space_info->bytes_may_use;
4036 4036
4037 spin_lock(&root->fs_info->free_chunk_lock); 4037 spin_lock(&root->fs_info->free_chunk_lock);
4038 avail = root->fs_info->free_chunk_space; 4038 avail = root->fs_info->free_chunk_space;
4039 spin_unlock(&root->fs_info->free_chunk_lock); 4039 spin_unlock(&root->fs_info->free_chunk_lock);
4040 4040
4041 /* 4041 /*
4042 * If we have dup, raid1 or raid10 then only half of the free 4042 * If we have dup, raid1 or raid10 then only half of the free
4043 * space is actually useable. For raid56, the space info used 4043 * space is actually useable. For raid56, the space info used
4044 * doesn't include the parity drive, so we don't have to 4044 * doesn't include the parity drive, so we don't have to
4045 * change the math 4045 * change the math
4046 */ 4046 */
4047 if (profile & (BTRFS_BLOCK_GROUP_DUP | 4047 if (profile & (BTRFS_BLOCK_GROUP_DUP |
4048 BTRFS_BLOCK_GROUP_RAID1 | 4048 BTRFS_BLOCK_GROUP_RAID1 |
4049 BTRFS_BLOCK_GROUP_RAID10)) 4049 BTRFS_BLOCK_GROUP_RAID10))
4050 avail >>= 1; 4050 avail >>= 1;
4051 4051
4052 /* 4052 /*
4053 * If we aren't flushing all things, let us overcommit up to 4053 * If we aren't flushing all things, let us overcommit up to
4054 * 1/2th of the space. If we can flush, don't let us overcommit 4054 * 1/2th of the space. If we can flush, don't let us overcommit
4055 * too much, let it overcommit up to 1/8 of the space. 4055 * too much, let it overcommit up to 1/8 of the space.
4056 */ 4056 */
4057 if (flush == BTRFS_RESERVE_FLUSH_ALL) 4057 if (flush == BTRFS_RESERVE_FLUSH_ALL)
4058 avail >>= 3; 4058 avail >>= 3;
4059 else 4059 else
4060 avail >>= 1; 4060 avail >>= 1;
4061 4061
4062 if (used + bytes < space_info->total_bytes + avail) 4062 if (used + bytes < space_info->total_bytes + avail)
4063 return 1; 4063 return 1;
4064 return 0; 4064 return 0;
4065 } 4065 }
4066 4066
4067 static void btrfs_writeback_inodes_sb_nr(struct btrfs_root *root, 4067 static void btrfs_writeback_inodes_sb_nr(struct btrfs_root *root,
4068 unsigned long nr_pages, int nr_items) 4068 unsigned long nr_pages, int nr_items)
4069 { 4069 {
4070 struct super_block *sb = root->fs_info->sb; 4070 struct super_block *sb = root->fs_info->sb;
4071 4071
4072 if (down_read_trylock(&sb->s_umount)) { 4072 if (down_read_trylock(&sb->s_umount)) {
4073 writeback_inodes_sb_nr(sb, nr_pages, WB_REASON_FS_FREE_SPACE); 4073 writeback_inodes_sb_nr(sb, nr_pages, WB_REASON_FS_FREE_SPACE);
4074 up_read(&sb->s_umount); 4074 up_read(&sb->s_umount);
4075 } else { 4075 } else {
4076 /* 4076 /*
4077 * We needn't worry the filesystem going from r/w to r/o though 4077 * We needn't worry the filesystem going from r/w to r/o though
4078 * we don't acquire ->s_umount mutex, because the filesystem 4078 * we don't acquire ->s_umount mutex, because the filesystem
4079 * should guarantee the delalloc inodes list be empty after 4079 * should guarantee the delalloc inodes list be empty after
4080 * the filesystem is readonly(all dirty pages are written to 4080 * the filesystem is readonly(all dirty pages are written to
4081 * the disk). 4081 * the disk).
4082 */ 4082 */
4083 btrfs_start_delalloc_roots(root->fs_info, 0, nr_items); 4083 btrfs_start_delalloc_roots(root->fs_info, 0, nr_items);
4084 if (!current->journal_info) 4084 if (!current->journal_info)
4085 btrfs_wait_ordered_roots(root->fs_info, nr_items); 4085 btrfs_wait_ordered_roots(root->fs_info, nr_items);
4086 } 4086 }
4087 } 4087 }
4088 4088
4089 static inline int calc_reclaim_items_nr(struct btrfs_root *root, u64 to_reclaim) 4089 static inline int calc_reclaim_items_nr(struct btrfs_root *root, u64 to_reclaim)
4090 { 4090 {
4091 u64 bytes; 4091 u64 bytes;
4092 int nr; 4092 int nr;
4093 4093
4094 bytes = btrfs_calc_trans_metadata_size(root, 1); 4094 bytes = btrfs_calc_trans_metadata_size(root, 1);
4095 nr = (int)div64_u64(to_reclaim, bytes); 4095 nr = (int)div64_u64(to_reclaim, bytes);
4096 if (!nr) 4096 if (!nr)
4097 nr = 1; 4097 nr = 1;
4098 return nr; 4098 return nr;
4099 } 4099 }
4100 4100
4101 #define EXTENT_SIZE_PER_ITEM (256 * 1024) 4101 #define EXTENT_SIZE_PER_ITEM (256 * 1024)
4102 4102
4103 /* 4103 /*
4104 * shrink metadata reservation for delalloc 4104 * shrink metadata reservation for delalloc
4105 */ 4105 */
4106 static void shrink_delalloc(struct btrfs_root *root, u64 to_reclaim, u64 orig, 4106 static void shrink_delalloc(struct btrfs_root *root, u64 to_reclaim, u64 orig,
4107 bool wait_ordered) 4107 bool wait_ordered)
4108 { 4108 {
4109 struct btrfs_block_rsv *block_rsv; 4109 struct btrfs_block_rsv *block_rsv;
4110 struct btrfs_space_info *space_info; 4110 struct btrfs_space_info *space_info;
4111 struct btrfs_trans_handle *trans; 4111 struct btrfs_trans_handle *trans;
4112 u64 delalloc_bytes; 4112 u64 delalloc_bytes;
4113 u64 max_reclaim; 4113 u64 max_reclaim;
4114 long time_left; 4114 long time_left;
4115 unsigned long nr_pages; 4115 unsigned long nr_pages;
4116 int loops; 4116 int loops;
4117 int items; 4117 int items;
4118 enum btrfs_reserve_flush_enum flush; 4118 enum btrfs_reserve_flush_enum flush;
4119 4119
4120 /* Calc the number of the pages we need flush for space reservation */ 4120 /* Calc the number of the pages we need flush for space reservation */
4121 items = calc_reclaim_items_nr(root, to_reclaim); 4121 items = calc_reclaim_items_nr(root, to_reclaim);
4122 to_reclaim = items * EXTENT_SIZE_PER_ITEM; 4122 to_reclaim = items * EXTENT_SIZE_PER_ITEM;
4123 4123
4124 trans = (struct btrfs_trans_handle *)current->journal_info; 4124 trans = (struct btrfs_trans_handle *)current->journal_info;
4125 block_rsv = &root->fs_info->delalloc_block_rsv; 4125 block_rsv = &root->fs_info->delalloc_block_rsv;
4126 space_info = block_rsv->space_info; 4126 space_info = block_rsv->space_info;
4127 4127
4128 delalloc_bytes = percpu_counter_sum_positive( 4128 delalloc_bytes = percpu_counter_sum_positive(
4129 &root->fs_info->delalloc_bytes); 4129 &root->fs_info->delalloc_bytes);
4130 if (delalloc_bytes == 0) { 4130 if (delalloc_bytes == 0) {
4131 if (trans) 4131 if (trans)
4132 return; 4132 return;
4133 if (wait_ordered) 4133 if (wait_ordered)
4134 btrfs_wait_ordered_roots(root->fs_info, items); 4134 btrfs_wait_ordered_roots(root->fs_info, items);
4135 return; 4135 return;
4136 } 4136 }
4137 4137
4138 loops = 0; 4138 loops = 0;
4139 while (delalloc_bytes && loops < 3) { 4139 while (delalloc_bytes && loops < 3) {
4140 max_reclaim = min(delalloc_bytes, to_reclaim); 4140 max_reclaim = min(delalloc_bytes, to_reclaim);
4141 nr_pages = max_reclaim >> PAGE_CACHE_SHIFT; 4141 nr_pages = max_reclaim >> PAGE_CACHE_SHIFT;
4142 btrfs_writeback_inodes_sb_nr(root, nr_pages, items); 4142 btrfs_writeback_inodes_sb_nr(root, nr_pages, items);
4143 /* 4143 /*
4144 * We need to wait for the async pages to actually start before 4144 * We need to wait for the async pages to actually start before
4145 * we do anything. 4145 * we do anything.
4146 */ 4146 */
4147 max_reclaim = atomic_read(&root->fs_info->async_delalloc_pages); 4147 max_reclaim = atomic_read(&root->fs_info->async_delalloc_pages);
4148 if (!max_reclaim) 4148 if (!max_reclaim)
4149 goto skip_async; 4149 goto skip_async;
4150 4150
4151 if (max_reclaim <= nr_pages) 4151 if (max_reclaim <= nr_pages)
4152 max_reclaim = 0; 4152 max_reclaim = 0;
4153 else 4153 else
4154 max_reclaim -= nr_pages; 4154 max_reclaim -= nr_pages;
4155 4155
4156 wait_event(root->fs_info->async_submit_wait, 4156 wait_event(root->fs_info->async_submit_wait,
4157 atomic_read(&root->fs_info->async_delalloc_pages) <= 4157 atomic_read(&root->fs_info->async_delalloc_pages) <=
4158 (int)max_reclaim); 4158 (int)max_reclaim);
4159 skip_async: 4159 skip_async:
4160 if (!trans) 4160 if (!trans)
4161 flush = BTRFS_RESERVE_FLUSH_ALL; 4161 flush = BTRFS_RESERVE_FLUSH_ALL;
4162 else 4162 else
4163 flush = BTRFS_RESERVE_NO_FLUSH; 4163 flush = BTRFS_RESERVE_NO_FLUSH;
4164 spin_lock(&space_info->lock); 4164 spin_lock(&space_info->lock);
4165 if (can_overcommit(root, space_info, orig, flush)) { 4165 if (can_overcommit(root, space_info, orig, flush)) {
4166 spin_unlock(&space_info->lock); 4166 spin_unlock(&space_info->lock);
4167 break; 4167 break;
4168 } 4168 }
4169 spin_unlock(&space_info->lock); 4169 spin_unlock(&space_info->lock);
4170 4170
4171 loops++; 4171 loops++;
4172 if (wait_ordered && !trans) { 4172 if (wait_ordered && !trans) {
4173 btrfs_wait_ordered_roots(root->fs_info, items); 4173 btrfs_wait_ordered_roots(root->fs_info, items);
4174 } else { 4174 } else {
4175 time_left = schedule_timeout_killable(1); 4175 time_left = schedule_timeout_killable(1);
4176 if (time_left) 4176 if (time_left)
4177 break; 4177 break;
4178 } 4178 }
4179 delalloc_bytes = percpu_counter_sum_positive( 4179 delalloc_bytes = percpu_counter_sum_positive(
4180 &root->fs_info->delalloc_bytes); 4180 &root->fs_info->delalloc_bytes);
4181 } 4181 }
4182 } 4182 }
4183 4183
4184 /** 4184 /**
4185 * maybe_commit_transaction - possibly commit the transaction if its ok to 4185 * maybe_commit_transaction - possibly commit the transaction if its ok to
4186 * @root - the root we're allocating for 4186 * @root - the root we're allocating for
4187 * @bytes - the number of bytes we want to reserve 4187 * @bytes - the number of bytes we want to reserve
4188 * @force - force the commit 4188 * @force - force the commit
4189 * 4189 *
4190 * This will check to make sure that committing the transaction will actually 4190 * This will check to make sure that committing the transaction will actually
4191 * get us somewhere and then commit the transaction if it does. Otherwise it 4191 * get us somewhere and then commit the transaction if it does. Otherwise it
4192 * will return -ENOSPC. 4192 * will return -ENOSPC.
4193 */ 4193 */
4194 static int may_commit_transaction(struct btrfs_root *root, 4194 static int may_commit_transaction(struct btrfs_root *root,
4195 struct btrfs_space_info *space_info, 4195 struct btrfs_space_info *space_info,
4196 u64 bytes, int force) 4196 u64 bytes, int force)
4197 { 4197 {
4198 struct btrfs_block_rsv *delayed_rsv = &root->fs_info->delayed_block_rsv; 4198 struct btrfs_block_rsv *delayed_rsv = &root->fs_info->delayed_block_rsv;
4199 struct btrfs_trans_handle *trans; 4199 struct btrfs_trans_handle *trans;
4200 4200
4201 trans = (struct btrfs_trans_handle *)current->journal_info; 4201 trans = (struct btrfs_trans_handle *)current->journal_info;
4202 if (trans) 4202 if (trans)
4203 return -EAGAIN; 4203 return -EAGAIN;
4204 4204
4205 if (force) 4205 if (force)
4206 goto commit; 4206 goto commit;
4207 4207
4208 /* See if there is enough pinned space to make this reservation */ 4208 /* See if there is enough pinned space to make this reservation */
4209 if (percpu_counter_compare(&space_info->total_bytes_pinned, 4209 if (percpu_counter_compare(&space_info->total_bytes_pinned,
4210 bytes) >= 0) 4210 bytes) >= 0)
4211 goto commit; 4211 goto commit;
4212 4212
4213 /* 4213 /*
4214 * See if there is some space in the delayed insertion reservation for 4214 * See if there is some space in the delayed insertion reservation for
4215 * this reservation. 4215 * this reservation.
4216 */ 4216 */
4217 if (space_info != delayed_rsv->space_info) 4217 if (space_info != delayed_rsv->space_info)
4218 return -ENOSPC; 4218 return -ENOSPC;
4219 4219
4220 spin_lock(&delayed_rsv->lock); 4220 spin_lock(&delayed_rsv->lock);
4221 if (percpu_counter_compare(&space_info->total_bytes_pinned, 4221 if (percpu_counter_compare(&space_info->total_bytes_pinned,
4222 bytes - delayed_rsv->size) >= 0) { 4222 bytes - delayed_rsv->size) >= 0) {
4223 spin_unlock(&delayed_rsv->lock); 4223 spin_unlock(&delayed_rsv->lock);
4224 return -ENOSPC; 4224 return -ENOSPC;
4225 } 4225 }
4226 spin_unlock(&delayed_rsv->lock); 4226 spin_unlock(&delayed_rsv->lock);
4227 4227
4228 commit: 4228 commit:
4229 trans = btrfs_join_transaction(root); 4229 trans = btrfs_join_transaction(root);
4230 if (IS_ERR(trans)) 4230 if (IS_ERR(trans))
4231 return -ENOSPC; 4231 return -ENOSPC;
4232 4232
4233 return btrfs_commit_transaction(trans, root); 4233 return btrfs_commit_transaction(trans, root);
4234 } 4234 }
4235 4235
4236 enum flush_state { 4236 enum flush_state {
4237 FLUSH_DELAYED_ITEMS_NR = 1, 4237 FLUSH_DELAYED_ITEMS_NR = 1,
4238 FLUSH_DELAYED_ITEMS = 2, 4238 FLUSH_DELAYED_ITEMS = 2,
4239 FLUSH_DELALLOC = 3, 4239 FLUSH_DELALLOC = 3,
4240 FLUSH_DELALLOC_WAIT = 4, 4240 FLUSH_DELALLOC_WAIT = 4,
4241 ALLOC_CHUNK = 5, 4241 ALLOC_CHUNK = 5,
4242 COMMIT_TRANS = 6, 4242 COMMIT_TRANS = 6,
4243 }; 4243 };
4244 4244
4245 static int flush_space(struct btrfs_root *root, 4245 static int flush_space(struct btrfs_root *root,
4246 struct btrfs_space_info *space_info, u64 num_bytes, 4246 struct btrfs_space_info *space_info, u64 num_bytes,
4247 u64 orig_bytes, int state) 4247 u64 orig_bytes, int state)
4248 { 4248 {
4249 struct btrfs_trans_handle *trans; 4249 struct btrfs_trans_handle *trans;
4250 int nr; 4250 int nr;
4251 int ret = 0; 4251 int ret = 0;
4252 4252
4253 switch (state) { 4253 switch (state) {
4254 case FLUSH_DELAYED_ITEMS_NR: 4254 case FLUSH_DELAYED_ITEMS_NR:
4255 case FLUSH_DELAYED_ITEMS: 4255 case FLUSH_DELAYED_ITEMS:
4256 if (state == FLUSH_DELAYED_ITEMS_NR) 4256 if (state == FLUSH_DELAYED_ITEMS_NR)
4257 nr = calc_reclaim_items_nr(root, num_bytes) * 2; 4257 nr = calc_reclaim_items_nr(root, num_bytes) * 2;
4258 else 4258 else
4259 nr = -1; 4259 nr = -1;
4260 4260
4261 trans = btrfs_join_transaction(root); 4261 trans = btrfs_join_transaction(root);
4262 if (IS_ERR(trans)) { 4262 if (IS_ERR(trans)) {
4263 ret = PTR_ERR(trans); 4263 ret = PTR_ERR(trans);
4264 break; 4264 break;
4265 } 4265 }
4266 ret = btrfs_run_delayed_items_nr(trans, root, nr); 4266 ret = btrfs_run_delayed_items_nr(trans, root, nr);
4267 btrfs_end_transaction(trans, root); 4267 btrfs_end_transaction(trans, root);
4268 break; 4268 break;
4269 case FLUSH_DELALLOC: 4269 case FLUSH_DELALLOC:
4270 case FLUSH_DELALLOC_WAIT: 4270 case FLUSH_DELALLOC_WAIT:
4271 shrink_delalloc(root, num_bytes * 2, orig_bytes, 4271 shrink_delalloc(root, num_bytes * 2, orig_bytes,
4272 state == FLUSH_DELALLOC_WAIT); 4272 state == FLUSH_DELALLOC_WAIT);
4273 break; 4273 break;
4274 case ALLOC_CHUNK: 4274 case ALLOC_CHUNK:
4275 trans = btrfs_join_transaction(root); 4275 trans = btrfs_join_transaction(root);
4276 if (IS_ERR(trans)) { 4276 if (IS_ERR(trans)) {
4277 ret = PTR_ERR(trans); 4277 ret = PTR_ERR(trans);
4278 break; 4278 break;
4279 } 4279 }
4280 ret = do_chunk_alloc(trans, root->fs_info->extent_root, 4280 ret = do_chunk_alloc(trans, root->fs_info->extent_root,
4281 btrfs_get_alloc_profile(root, 0), 4281 btrfs_get_alloc_profile(root, 0),
4282 CHUNK_ALLOC_NO_FORCE); 4282 CHUNK_ALLOC_NO_FORCE);
4283 btrfs_end_transaction(trans, root); 4283 btrfs_end_transaction(trans, root);
4284 if (ret == -ENOSPC) 4284 if (ret == -ENOSPC)
4285 ret = 0; 4285 ret = 0;
4286 break; 4286 break;
4287 case COMMIT_TRANS: 4287 case COMMIT_TRANS:
4288 ret = may_commit_transaction(root, space_info, orig_bytes, 0); 4288 ret = may_commit_transaction(root, space_info, orig_bytes, 0);
4289 break; 4289 break;
4290 default: 4290 default:
4291 ret = -ENOSPC; 4291 ret = -ENOSPC;
4292 break; 4292 break;
4293 } 4293 }
4294 4294
4295 return ret; 4295 return ret;
4296 } 4296 }
4297 4297
4298 static inline u64 4298 static inline u64
4299 btrfs_calc_reclaim_metadata_size(struct btrfs_root *root, 4299 btrfs_calc_reclaim_metadata_size(struct btrfs_root *root,
4300 struct btrfs_space_info *space_info) 4300 struct btrfs_space_info *space_info)
4301 { 4301 {
4302 u64 used; 4302 u64 used;
4303 u64 expected; 4303 u64 expected;
4304 u64 to_reclaim; 4304 u64 to_reclaim;
4305 4305
4306 to_reclaim = min_t(u64, num_online_cpus() * 1024 * 1024, 4306 to_reclaim = min_t(u64, num_online_cpus() * 1024 * 1024,
4307 16 * 1024 * 1024); 4307 16 * 1024 * 1024);
4308 spin_lock(&space_info->lock); 4308 spin_lock(&space_info->lock);
4309 if (can_overcommit(root, space_info, to_reclaim, 4309 if (can_overcommit(root, space_info, to_reclaim,
4310 BTRFS_RESERVE_FLUSH_ALL)) { 4310 BTRFS_RESERVE_FLUSH_ALL)) {
4311 to_reclaim = 0; 4311 to_reclaim = 0;
4312 goto out; 4312 goto out;
4313 } 4313 }
4314 4314
4315 used = space_info->bytes_used + space_info->bytes_reserved + 4315 used = space_info->bytes_used + space_info->bytes_reserved +
4316 space_info->bytes_pinned + space_info->bytes_readonly + 4316 space_info->bytes_pinned + space_info->bytes_readonly +
4317 space_info->bytes_may_use; 4317 space_info->bytes_may_use;
4318 if (can_overcommit(root, space_info, 1024 * 1024, 4318 if (can_overcommit(root, space_info, 1024 * 1024,
4319 BTRFS_RESERVE_FLUSH_ALL)) 4319 BTRFS_RESERVE_FLUSH_ALL))
4320 expected = div_factor_fine(space_info->total_bytes, 95); 4320 expected = div_factor_fine(space_info->total_bytes, 95);
4321 else 4321 else
4322 expected = div_factor_fine(space_info->total_bytes, 90); 4322 expected = div_factor_fine(space_info->total_bytes, 90);
4323 4323
4324 if (used > expected) 4324 if (used > expected)
4325 to_reclaim = used - expected; 4325 to_reclaim = used - expected;
4326 else 4326 else
4327 to_reclaim = 0; 4327 to_reclaim = 0;
4328 to_reclaim = min(to_reclaim, space_info->bytes_may_use + 4328 to_reclaim = min(to_reclaim, space_info->bytes_may_use +
4329 space_info->bytes_reserved); 4329 space_info->bytes_reserved);
4330 out: 4330 out:
4331 spin_unlock(&space_info->lock); 4331 spin_unlock(&space_info->lock);
4332 4332
4333 return to_reclaim; 4333 return to_reclaim;
4334 } 4334 }
4335 4335
4336 static inline int need_do_async_reclaim(struct btrfs_space_info *space_info, 4336 static inline int need_do_async_reclaim(struct btrfs_space_info *space_info,
4337 struct btrfs_fs_info *fs_info, u64 used) 4337 struct btrfs_fs_info *fs_info, u64 used)
4338 { 4338 {
4339 return (used >= div_factor_fine(space_info->total_bytes, 98) && 4339 return (used >= div_factor_fine(space_info->total_bytes, 98) &&
4340 !btrfs_fs_closing(fs_info) && 4340 !btrfs_fs_closing(fs_info) &&
4341 !test_bit(BTRFS_FS_STATE_REMOUNTING, &fs_info->fs_state)); 4341 !test_bit(BTRFS_FS_STATE_REMOUNTING, &fs_info->fs_state));
4342 } 4342 }
4343 4343
4344 static int btrfs_need_do_async_reclaim(struct btrfs_space_info *space_info, 4344 static int btrfs_need_do_async_reclaim(struct btrfs_space_info *space_info,
4345 struct btrfs_fs_info *fs_info, 4345 struct btrfs_fs_info *fs_info,
4346 int flush_state) 4346 int flush_state)
4347 { 4347 {
4348 u64 used; 4348 u64 used;
4349 4349
4350 spin_lock(&space_info->lock); 4350 spin_lock(&space_info->lock);
4351 /* 4351 /*
4352 * We run out of space and have not got any free space via flush_space, 4352 * We run out of space and have not got any free space via flush_space,
4353 * so don't bother doing async reclaim. 4353 * so don't bother doing async reclaim.
4354 */ 4354 */
4355 if (flush_state > COMMIT_TRANS && space_info->full) { 4355 if (flush_state > COMMIT_TRANS && space_info->full) {
4356 spin_unlock(&space_info->lock); 4356 spin_unlock(&space_info->lock);
4357 return 0; 4357 return 0;
4358 } 4358 }
4359 4359
4360 used = space_info->bytes_used + space_info->bytes_reserved + 4360 used = space_info->bytes_used + space_info->bytes_reserved +
4361 space_info->bytes_pinned + space_info->bytes_readonly + 4361 space_info->bytes_pinned + space_info->bytes_readonly +
4362 space_info->bytes_may_use; 4362 space_info->bytes_may_use;
4363 if (need_do_async_reclaim(space_info, fs_info, used)) { 4363 if (need_do_async_reclaim(space_info, fs_info, used)) {
4364 spin_unlock(&space_info->lock); 4364 spin_unlock(&space_info->lock);
4365 return 1; 4365 return 1;
4366 } 4366 }
4367 spin_unlock(&space_info->lock); 4367 spin_unlock(&space_info->lock);
4368 4368
4369 return 0; 4369 return 0;
4370 } 4370 }
4371 4371
4372 static void btrfs_async_reclaim_metadata_space(struct work_struct *work) 4372 static void btrfs_async_reclaim_metadata_space(struct work_struct *work)
4373 { 4373 {
4374 struct btrfs_fs_info *fs_info; 4374 struct btrfs_fs_info *fs_info;
4375 struct btrfs_space_info *space_info; 4375 struct btrfs_space_info *space_info;
4376 u64 to_reclaim; 4376 u64 to_reclaim;
4377 int flush_state; 4377 int flush_state;
4378 4378
4379 fs_info = container_of(work, struct btrfs_fs_info, async_reclaim_work); 4379 fs_info = container_of(work, struct btrfs_fs_info, async_reclaim_work);
4380 space_info = __find_space_info(fs_info, BTRFS_BLOCK_GROUP_METADATA); 4380 space_info = __find_space_info(fs_info, BTRFS_BLOCK_GROUP_METADATA);
4381 4381
4382 to_reclaim = btrfs_calc_reclaim_metadata_size(fs_info->fs_root, 4382 to_reclaim = btrfs_calc_reclaim_metadata_size(fs_info->fs_root,
4383 space_info); 4383 space_info);
4384 if (!to_reclaim) 4384 if (!to_reclaim)
4385 return; 4385 return;
4386 4386
4387 flush_state = FLUSH_DELAYED_ITEMS_NR; 4387 flush_state = FLUSH_DELAYED_ITEMS_NR;
4388 do { 4388 do {
4389 flush_space(fs_info->fs_root, space_info, to_reclaim, 4389 flush_space(fs_info->fs_root, space_info, to_reclaim,
4390 to_reclaim, flush_state); 4390 to_reclaim, flush_state);
4391 flush_state++; 4391 flush_state++;
4392 if (!btrfs_need_do_async_reclaim(space_info, fs_info, 4392 if (!btrfs_need_do_async_reclaim(space_info, fs_info,
4393 flush_state)) 4393 flush_state))
4394 return; 4394 return;
4395 } while (flush_state <= COMMIT_TRANS); 4395 } while (flush_state <= COMMIT_TRANS);
4396 4396
4397 if (btrfs_need_do_async_reclaim(space_info, fs_info, flush_state)) 4397 if (btrfs_need_do_async_reclaim(space_info, fs_info, flush_state))
4398 queue_work(system_unbound_wq, work); 4398 queue_work(system_unbound_wq, work);
4399 } 4399 }
4400 4400
4401 void btrfs_init_async_reclaim_work(struct work_struct *work) 4401 void btrfs_init_async_reclaim_work(struct work_struct *work)
4402 { 4402 {
4403 INIT_WORK(work, btrfs_async_reclaim_metadata_space); 4403 INIT_WORK(work, btrfs_async_reclaim_metadata_space);
4404 } 4404 }
4405 4405
4406 /** 4406 /**
4407 * reserve_metadata_bytes - try to reserve bytes from the block_rsv's space 4407 * reserve_metadata_bytes - try to reserve bytes from the block_rsv's space
4408 * @root - the root we're allocating for 4408 * @root - the root we're allocating for
4409 * @block_rsv - the block_rsv we're allocating for 4409 * @block_rsv - the block_rsv we're allocating for
4410 * @orig_bytes - the number of bytes we want 4410 * @orig_bytes - the number of bytes we want
4411 * @flush - whether or not we can flush to make our reservation 4411 * @flush - whether or not we can flush to make our reservation
4412 * 4412 *
4413 * This will reserve orgi_bytes number of bytes from the space info associated 4413 * This will reserve orgi_bytes number of bytes from the space info associated
4414 * with the block_rsv. If there is not enough space it will make an attempt to 4414 * with the block_rsv. If there is not enough space it will make an attempt to
4415 * flush out space to make room. It will do this by flushing delalloc if 4415 * flush out space to make room. It will do this by flushing delalloc if
4416 * possible or committing the transaction. If flush is 0 then no attempts to 4416 * possible or committing the transaction. If flush is 0 then no attempts to
4417 * regain reservations will be made and this will fail if there is not enough 4417 * regain reservations will be made and this will fail if there is not enough
4418 * space already. 4418 * space already.
4419 */ 4419 */
4420 static int reserve_metadata_bytes(struct btrfs_root *root, 4420 static int reserve_metadata_bytes(struct btrfs_root *root,
4421 struct btrfs_block_rsv *block_rsv, 4421 struct btrfs_block_rsv *block_rsv,
4422 u64 orig_bytes, 4422 u64 orig_bytes,
4423 enum btrfs_reserve_flush_enum flush) 4423 enum btrfs_reserve_flush_enum flush)
4424 { 4424 {
4425 struct btrfs_space_info *space_info = block_rsv->space_info; 4425 struct btrfs_space_info *space_info = block_rsv->space_info;
4426 u64 used; 4426 u64 used;
4427 u64 num_bytes = orig_bytes; 4427 u64 num_bytes = orig_bytes;
4428 int flush_state = FLUSH_DELAYED_ITEMS_NR; 4428 int flush_state = FLUSH_DELAYED_ITEMS_NR;
4429 int ret = 0; 4429 int ret = 0;
4430 bool flushing = false; 4430 bool flushing = false;
4431 4431
4432 again: 4432 again:
4433 ret = 0; 4433 ret = 0;
4434 spin_lock(&space_info->lock); 4434 spin_lock(&space_info->lock);
4435 /* 4435 /*
4436 * We only want to wait if somebody other than us is flushing and we 4436 * We only want to wait if somebody other than us is flushing and we
4437 * are actually allowed to flush all things. 4437 * are actually allowed to flush all things.
4438 */ 4438 */
4439 while (flush == BTRFS_RESERVE_FLUSH_ALL && !flushing && 4439 while (flush == BTRFS_RESERVE_FLUSH_ALL && !flushing &&
4440 space_info->flush) { 4440 space_info->flush) {
4441 spin_unlock(&space_info->lock); 4441 spin_unlock(&space_info->lock);
4442 /* 4442 /*
4443 * If we have a trans handle we can't wait because the flusher 4443 * If we have a trans handle we can't wait because the flusher
4444 * may have to commit the transaction, which would mean we would 4444 * may have to commit the transaction, which would mean we would
4445 * deadlock since we are waiting for the flusher to finish, but 4445 * deadlock since we are waiting for the flusher to finish, but
4446 * hold the current transaction open. 4446 * hold the current transaction open.
4447 */ 4447 */
4448 if (current->journal_info) 4448 if (current->journal_info)
4449 return -EAGAIN; 4449 return -EAGAIN;
4450 ret = wait_event_killable(space_info->wait, !space_info->flush); 4450 ret = wait_event_killable(space_info->wait, !space_info->flush);
4451 /* Must have been killed, return */ 4451 /* Must have been killed, return */
4452 if (ret) 4452 if (ret)
4453 return -EINTR; 4453 return -EINTR;
4454 4454
4455 spin_lock(&space_info->lock); 4455 spin_lock(&space_info->lock);
4456 } 4456 }
4457 4457
4458 ret = -ENOSPC; 4458 ret = -ENOSPC;
4459 used = space_info->bytes_used + space_info->bytes_reserved + 4459 used = space_info->bytes_used + space_info->bytes_reserved +
4460 space_info->bytes_pinned + space_info->bytes_readonly + 4460 space_info->bytes_pinned + space_info->bytes_readonly +
4461 space_info->bytes_may_use; 4461 space_info->bytes_may_use;
4462 4462
4463 /* 4463 /*
4464 * The idea here is that we've not already over-reserved the block group 4464 * The idea here is that we've not already over-reserved the block group
4465 * then we can go ahead and save our reservation first and then start 4465 * then we can go ahead and save our reservation first and then start
4466 * flushing if we need to. Otherwise if we've already overcommitted 4466 * flushing if we need to. Otherwise if we've already overcommitted
4467 * lets start flushing stuff first and then come back and try to make 4467 * lets start flushing stuff first and then come back and try to make
4468 * our reservation. 4468 * our reservation.
4469 */ 4469 */
4470 if (used <= space_info->total_bytes) { 4470 if (used <= space_info->total_bytes) {
4471 if (used + orig_bytes <= space_info->total_bytes) { 4471 if (used + orig_bytes <= space_info->total_bytes) {
4472 space_info->bytes_may_use += orig_bytes; 4472 space_info->bytes_may_use += orig_bytes;
4473 trace_btrfs_space_reservation(root->fs_info, 4473 trace_btrfs_space_reservation(root->fs_info,
4474 "space_info", space_info->flags, orig_bytes, 1); 4474 "space_info", space_info->flags, orig_bytes, 1);
4475 ret = 0; 4475 ret = 0;
4476 } else { 4476 } else {
4477 /* 4477 /*
4478 * Ok set num_bytes to orig_bytes since we aren't 4478 * Ok set num_bytes to orig_bytes since we aren't
4479 * overocmmitted, this way we only try and reclaim what 4479 * overocmmitted, this way we only try and reclaim what
4480 * we need. 4480 * we need.
4481 */ 4481 */
4482 num_bytes = orig_bytes; 4482 num_bytes = orig_bytes;
4483 } 4483 }
4484 } else { 4484 } else {
4485 /* 4485 /*
4486 * Ok we're over committed, set num_bytes to the overcommitted 4486 * Ok we're over committed, set num_bytes to the overcommitted
4487 * amount plus the amount of bytes that we need for this 4487 * amount plus the amount of bytes that we need for this
4488 * reservation. 4488 * reservation.
4489 */ 4489 */
4490 num_bytes = used - space_info->total_bytes + 4490 num_bytes = used - space_info->total_bytes +
4491 (orig_bytes * 2); 4491 (orig_bytes * 2);
4492 } 4492 }
4493 4493
4494 if (ret && can_overcommit(root, space_info, orig_bytes, flush)) { 4494 if (ret && can_overcommit(root, space_info, orig_bytes, flush)) {
4495 space_info->bytes_may_use += orig_bytes; 4495 space_info->bytes_may_use += orig_bytes;
4496 trace_btrfs_space_reservation(root->fs_info, "space_info", 4496 trace_btrfs_space_reservation(root->fs_info, "space_info",
4497 space_info->flags, orig_bytes, 4497 space_info->flags, orig_bytes,
4498 1); 4498 1);
4499 ret = 0; 4499 ret = 0;
4500 } 4500 }
4501 4501
4502 /* 4502 /*
4503 * Couldn't make our reservation, save our place so while we're trying 4503 * Couldn't make our reservation, save our place so while we're trying
4504 * to reclaim space we can actually use it instead of somebody else 4504 * to reclaim space we can actually use it instead of somebody else
4505 * stealing it from us. 4505 * stealing it from us.
4506 * 4506 *
4507 * We make the other tasks wait for the flush only when we can flush 4507 * We make the other tasks wait for the flush only when we can flush
4508 * all things. 4508 * all things.
4509 */ 4509 */
4510 if (ret && flush != BTRFS_RESERVE_NO_FLUSH) { 4510 if (ret && flush != BTRFS_RESERVE_NO_FLUSH) {
4511 flushing = true; 4511 flushing = true;
4512 space_info->flush = 1; 4512 space_info->flush = 1;
4513 } else if (!ret && space_info->flags & BTRFS_BLOCK_GROUP_METADATA) { 4513 } else if (!ret && space_info->flags & BTRFS_BLOCK_GROUP_METADATA) {
4514 used += orig_bytes; 4514 used += orig_bytes;
4515 /* 4515 /*
4516 * We will do the space reservation dance during log replay, 4516 * We will do the space reservation dance during log replay,
4517 * which means we won't have fs_info->fs_root set, so don't do 4517 * which means we won't have fs_info->fs_root set, so don't do
4518 * the async reclaim as we will panic. 4518 * the async reclaim as we will panic.
4519 */ 4519 */
4520 if (!root->fs_info->log_root_recovering && 4520 if (!root->fs_info->log_root_recovering &&
4521 need_do_async_reclaim(space_info, root->fs_info, used) && 4521 need_do_async_reclaim(space_info, root->fs_info, used) &&
4522 !work_busy(&root->fs_info->async_reclaim_work)) 4522 !work_busy(&root->fs_info->async_reclaim_work))
4523 queue_work(system_unbound_wq, 4523 queue_work(system_unbound_wq,
4524 &root->fs_info->async_reclaim_work); 4524 &root->fs_info->async_reclaim_work);
4525 } 4525 }
4526 spin_unlock(&space_info->lock); 4526 spin_unlock(&space_info->lock);
4527 4527
4528 if (!ret || flush == BTRFS_RESERVE_NO_FLUSH) 4528 if (!ret || flush == BTRFS_RESERVE_NO_FLUSH)
4529 goto out; 4529 goto out;
4530 4530
4531 ret = flush_space(root, space_info, num_bytes, orig_bytes, 4531 ret = flush_space(root, space_info, num_bytes, orig_bytes,
4532 flush_state); 4532 flush_state);
4533 flush_state++; 4533 flush_state++;
4534 4534
4535 /* 4535 /*
4536 * If we are FLUSH_LIMIT, we can not flush delalloc, or the deadlock 4536 * If we are FLUSH_LIMIT, we can not flush delalloc, or the deadlock
4537 * would happen. So skip delalloc flush. 4537 * would happen. So skip delalloc flush.
4538 */ 4538 */
4539 if (flush == BTRFS_RESERVE_FLUSH_LIMIT && 4539 if (flush == BTRFS_RESERVE_FLUSH_LIMIT &&
4540 (flush_state == FLUSH_DELALLOC || 4540 (flush_state == FLUSH_DELALLOC ||
4541 flush_state == FLUSH_DELALLOC_WAIT)) 4541 flush_state == FLUSH_DELALLOC_WAIT))
4542 flush_state = ALLOC_CHUNK; 4542 flush_state = ALLOC_CHUNK;
4543 4543
4544 if (!ret) 4544 if (!ret)
4545 goto again; 4545 goto again;
4546 else if (flush == BTRFS_RESERVE_FLUSH_LIMIT && 4546 else if (flush == BTRFS_RESERVE_FLUSH_LIMIT &&
4547 flush_state < COMMIT_TRANS) 4547 flush_state < COMMIT_TRANS)
4548 goto again; 4548 goto again;
4549 else if (flush == BTRFS_RESERVE_FLUSH_ALL && 4549 else if (flush == BTRFS_RESERVE_FLUSH_ALL &&
4550 flush_state <= COMMIT_TRANS) 4550 flush_state <= COMMIT_TRANS)
4551 goto again; 4551 goto again;
4552 4552
4553 out: 4553 out:
4554 if (ret == -ENOSPC && 4554 if (ret == -ENOSPC &&
4555 unlikely(root->orphan_cleanup_state == ORPHAN_CLEANUP_STARTED)) { 4555 unlikely(root->orphan_cleanup_state == ORPHAN_CLEANUP_STARTED)) {
4556 struct btrfs_block_rsv *global_rsv = 4556 struct btrfs_block_rsv *global_rsv =
4557 &root->fs_info->global_block_rsv; 4557 &root->fs_info->global_block_rsv;
4558 4558
4559 if (block_rsv != global_rsv && 4559 if (block_rsv != global_rsv &&
4560 !block_rsv_use_bytes(global_rsv, orig_bytes)) 4560 !block_rsv_use_bytes(global_rsv, orig_bytes))
4561 ret = 0; 4561 ret = 0;
4562 } 4562 }
4563 if (ret == -ENOSPC) 4563 if (ret == -ENOSPC)
4564 trace_btrfs_space_reservation(root->fs_info, 4564 trace_btrfs_space_reservation(root->fs_info,
4565 "space_info:enospc", 4565 "space_info:enospc",
4566 space_info->flags, orig_bytes, 1); 4566 space_info->flags, orig_bytes, 1);
4567 if (flushing) { 4567 if (flushing) {
4568 spin_lock(&space_info->lock); 4568 spin_lock(&space_info->lock);
4569 space_info->flush = 0; 4569 space_info->flush = 0;
4570 wake_up_all(&space_info->wait); 4570 wake_up_all(&space_info->wait);
4571 spin_unlock(&space_info->lock); 4571 spin_unlock(&space_info->lock);
4572 } 4572 }
4573 return ret; 4573 return ret;
4574 } 4574 }
4575 4575
4576 static struct btrfs_block_rsv *get_block_rsv( 4576 static struct btrfs_block_rsv *get_block_rsv(
4577 const struct btrfs_trans_handle *trans, 4577 const struct btrfs_trans_handle *trans,
4578 const struct btrfs_root *root) 4578 const struct btrfs_root *root)
4579 { 4579 {
4580 struct btrfs_block_rsv *block_rsv = NULL; 4580 struct btrfs_block_rsv *block_rsv = NULL;
4581 4581
4582 if (test_bit(BTRFS_ROOT_REF_COWS, &root->state)) 4582 if (test_bit(BTRFS_ROOT_REF_COWS, &root->state))
4583 block_rsv = trans->block_rsv; 4583 block_rsv = trans->block_rsv;
4584 4584
4585 if (root == root->fs_info->csum_root && trans->adding_csums) 4585 if (root == root->fs_info->csum_root && trans->adding_csums)
4586 block_rsv = trans->block_rsv; 4586 block_rsv = trans->block_rsv;
4587 4587
4588 if (root == root->fs_info->uuid_root) 4588 if (root == root->fs_info->uuid_root)
4589 block_rsv = trans->block_rsv; 4589 block_rsv = trans->block_rsv;
4590 4590
4591 if (!block_rsv) 4591 if (!block_rsv)
4592 block_rsv = root->block_rsv; 4592 block_rsv = root->block_rsv;
4593 4593
4594 if (!block_rsv) 4594 if (!block_rsv)
4595 block_rsv = &root->fs_info->empty_block_rsv; 4595 block_rsv = &root->fs_info->empty_block_rsv;
4596 4596
4597 return block_rsv; 4597 return block_rsv;
4598 } 4598 }
4599 4599
4600 static int block_rsv_use_bytes(struct btrfs_block_rsv *block_rsv, 4600 static int block_rsv_use_bytes(struct btrfs_block_rsv *block_rsv,
4601 u64 num_bytes) 4601 u64 num_bytes)
4602 { 4602 {
4603 int ret = -ENOSPC; 4603 int ret = -ENOSPC;
4604 spin_lock(&block_rsv->lock); 4604 spin_lock(&block_rsv->lock);
4605 if (block_rsv->reserved >= num_bytes) { 4605 if (block_rsv->reserved >= num_bytes) {
4606 block_rsv->reserved -= num_bytes; 4606 block_rsv->reserved -= num_bytes;
4607 if (block_rsv->reserved < block_rsv->size) 4607 if (block_rsv->reserved < block_rsv->size)
4608 block_rsv->full = 0; 4608 block_rsv->full = 0;
4609 ret = 0; 4609 ret = 0;
4610 } 4610 }
4611 spin_unlock(&block_rsv->lock); 4611 spin_unlock(&block_rsv->lock);
4612 return ret; 4612 return ret;
4613 } 4613 }
4614 4614
4615 static void block_rsv_add_bytes(struct btrfs_block_rsv *block_rsv, 4615 static void block_rsv_add_bytes(struct btrfs_block_rsv *block_rsv,
4616 u64 num_bytes, int update_size) 4616 u64 num_bytes, int update_size)
4617 { 4617 {
4618 spin_lock(&block_rsv->lock); 4618 spin_lock(&block_rsv->lock);
4619 block_rsv->reserved += num_bytes; 4619 block_rsv->reserved += num_bytes;
4620 if (update_size) 4620 if (update_size)
4621 block_rsv->size += num_bytes; 4621 block_rsv->size += num_bytes;
4622 else if (block_rsv->reserved >= block_rsv->size) 4622 else if (block_rsv->reserved >= block_rsv->size)
4623 block_rsv->full = 1; 4623 block_rsv->full = 1;
4624 spin_unlock(&block_rsv->lock); 4624 spin_unlock(&block_rsv->lock);
4625 } 4625 }
4626 4626
4627 int btrfs_cond_migrate_bytes(struct btrfs_fs_info *fs_info, 4627 int btrfs_cond_migrate_bytes(struct btrfs_fs_info *fs_info,
4628 struct btrfs_block_rsv *dest, u64 num_bytes, 4628 struct btrfs_block_rsv *dest, u64 num_bytes,
4629 int min_factor) 4629 int min_factor)
4630 { 4630 {
4631 struct btrfs_block_rsv *global_rsv = &fs_info->global_block_rsv; 4631 struct btrfs_block_rsv *global_rsv = &fs_info->global_block_rsv;
4632 u64 min_bytes; 4632 u64 min_bytes;
4633 4633
4634 if (global_rsv->space_info != dest->space_info) 4634 if (global_rsv->space_info != dest->space_info)
4635 return -ENOSPC; 4635 return -ENOSPC;
4636 4636
4637 spin_lock(&global_rsv->lock); 4637 spin_lock(&global_rsv->lock);
4638 min_bytes = div_factor(global_rsv->size, min_factor); 4638 min_bytes = div_factor(global_rsv->size, min_factor);
4639 if (global_rsv->reserved < min_bytes + num_bytes) { 4639 if (global_rsv->reserved < min_bytes + num_bytes) {
4640 spin_unlock(&global_rsv->lock); 4640 spin_unlock(&global_rsv->lock);
4641 return -ENOSPC; 4641 return -ENOSPC;
4642 } 4642 }
4643 global_rsv->reserved -= num_bytes; 4643 global_rsv->reserved -= num_bytes;
4644 if (global_rsv->reserved < global_rsv->size) 4644 if (global_rsv->reserved < global_rsv->size)
4645 global_rsv->full = 0; 4645 global_rsv->full = 0;
4646 spin_unlock(&global_rsv->lock); 4646 spin_unlock(&global_rsv->lock);
4647 4647
4648 block_rsv_add_bytes(dest, num_bytes, 1); 4648 block_rsv_add_bytes(dest, num_bytes, 1);
4649 return 0; 4649 return 0;
4650 } 4650 }
4651 4651
4652 static void block_rsv_release_bytes(struct btrfs_fs_info *fs_info, 4652 static void block_rsv_release_bytes(struct btrfs_fs_info *fs_info,
4653 struct btrfs_block_rsv *block_rsv, 4653 struct btrfs_block_rsv *block_rsv,
4654 struct btrfs_block_rsv *dest, u64 num_bytes) 4654 struct btrfs_block_rsv *dest, u64 num_bytes)
4655 { 4655 {
4656 struct btrfs_space_info *space_info = block_rsv->space_info; 4656 struct btrfs_space_info *space_info = block_rsv->space_info;
4657 4657
4658 spin_lock(&block_rsv->lock); 4658 spin_lock(&block_rsv->lock);
4659 if (num_bytes == (u64)-1) 4659 if (num_bytes == (u64)-1)
4660 num_bytes = block_rsv->size; 4660 num_bytes = block_rsv->size;
4661 block_rsv->size -= num_bytes; 4661 block_rsv->size -= num_bytes;
4662 if (block_rsv->reserved >= block_rsv->size) { 4662 if (block_rsv->reserved >= block_rsv->size) {
4663 num_bytes = block_rsv->reserved - block_rsv->size; 4663 num_bytes = block_rsv->reserved - block_rsv->size;
4664 block_rsv->reserved = block_rsv->size; 4664 block_rsv->reserved = block_rsv->size;
4665 block_rsv->full = 1; 4665 block_rsv->full = 1;
4666 } else { 4666 } else {
4667 num_bytes = 0; 4667 num_bytes = 0;
4668 } 4668 }
4669 spin_unlock(&block_rsv->lock); 4669 spin_unlock(&block_rsv->lock);
4670 4670
4671 if (num_bytes > 0) { 4671 if (num_bytes > 0) {
4672 if (dest) { 4672 if (dest) {
4673 spin_lock(&dest->lock); 4673 spin_lock(&dest->lock);
4674 if (!dest->full) { 4674 if (!dest->full) {
4675 u64 bytes_to_add; 4675 u64 bytes_to_add;
4676 4676
4677 bytes_to_add = dest->size - dest->reserved; 4677 bytes_to_add = dest->size - dest->reserved;
4678 bytes_to_add = min(num_bytes, bytes_to_add); 4678 bytes_to_add = min(num_bytes, bytes_to_add);
4679 dest->reserved += bytes_to_add; 4679 dest->reserved += bytes_to_add;
4680 if (dest->reserved >= dest->size) 4680 if (dest->reserved >= dest->size)
4681 dest->full = 1; 4681 dest->full = 1;
4682 num_bytes -= bytes_to_add; 4682 num_bytes -= bytes_to_add;
4683 } 4683 }
4684 spin_unlock(&dest->lock); 4684 spin_unlock(&dest->lock);
4685 } 4685 }
4686 if (num_bytes) { 4686 if (num_bytes) {
4687 spin_lock(&space_info->lock); 4687 spin_lock(&space_info->lock);
4688 space_info->bytes_may_use -= num_bytes; 4688 space_info->bytes_may_use -= num_bytes;
4689 trace_btrfs_space_reservation(fs_info, "space_info", 4689 trace_btrfs_space_reservation(fs_info, "space_info",
4690 space_info->flags, num_bytes, 0); 4690 space_info->flags, num_bytes, 0);
4691 spin_unlock(&space_info->lock); 4691 spin_unlock(&space_info->lock);
4692 } 4692 }
4693 } 4693 }
4694 } 4694 }
4695 4695
4696 static int block_rsv_migrate_bytes(struct btrfs_block_rsv *src, 4696 static int block_rsv_migrate_bytes(struct btrfs_block_rsv *src,
4697 struct btrfs_block_rsv *dst, u64 num_bytes) 4697 struct btrfs_block_rsv *dst, u64 num_bytes)
4698 { 4698 {
4699 int ret; 4699 int ret;
4700 4700
4701 ret = block_rsv_use_bytes(src, num_bytes); 4701 ret = block_rsv_use_bytes(src, num_bytes);
4702 if (ret) 4702 if (ret)
4703 return ret; 4703 return ret;
4704 4704
4705 block_rsv_add_bytes(dst, num_bytes, 1); 4705 block_rsv_add_bytes(dst, num_bytes, 1);
4706 return 0; 4706 return 0;
4707 } 4707 }
4708 4708
4709 void btrfs_init_block_rsv(struct btrfs_block_rsv *rsv, unsigned short type) 4709 void btrfs_init_block_rsv(struct btrfs_block_rsv *rsv, unsigned short type)
4710 { 4710 {
4711 memset(rsv, 0, sizeof(*rsv)); 4711 memset(rsv, 0, sizeof(*rsv));
4712 spin_lock_init(&rsv->lock); 4712 spin_lock_init(&rsv->lock);
4713 rsv->type = type; 4713 rsv->type = type;
4714 } 4714 }
4715 4715
4716 struct btrfs_block_rsv *btrfs_alloc_block_rsv(struct btrfs_root *root, 4716 struct btrfs_block_rsv *btrfs_alloc_block_rsv(struct btrfs_root *root,
4717 unsigned short type) 4717 unsigned short type)
4718 { 4718 {
4719 struct btrfs_block_rsv *block_rsv; 4719 struct btrfs_block_rsv *block_rsv;
4720 struct btrfs_fs_info *fs_info = root->fs_info; 4720 struct btrfs_fs_info *fs_info = root->fs_info;
4721 4721
4722 block_rsv = kmalloc(sizeof(*block_rsv), GFP_NOFS); 4722 block_rsv = kmalloc(sizeof(*block_rsv), GFP_NOFS);
4723 if (!block_rsv) 4723 if (!block_rsv)
4724 return NULL; 4724 return NULL;
4725 4725
4726 btrfs_init_block_rsv(block_rsv, type); 4726 btrfs_init_block_rsv(block_rsv, type);
4727 block_rsv->space_info = __find_space_info(fs_info, 4727 block_rsv->space_info = __find_space_info(fs_info,
4728 BTRFS_BLOCK_GROUP_METADATA); 4728 BTRFS_BLOCK_GROUP_METADATA);
4729 return block_rsv; 4729 return block_rsv;
4730 } 4730 }
4731 4731
4732 void btrfs_free_block_rsv(struct btrfs_root *root, 4732 void btrfs_free_block_rsv(struct btrfs_root *root,
4733 struct btrfs_block_rsv *rsv) 4733 struct btrfs_block_rsv *rsv)
4734 { 4734 {
4735 if (!rsv) 4735 if (!rsv)
4736 return; 4736 return;
4737 btrfs_block_rsv_release(root, rsv, (u64)-1); 4737 btrfs_block_rsv_release(root, rsv, (u64)-1);
4738 kfree(rsv); 4738 kfree(rsv);
4739 } 4739 }
4740 4740
4741 int btrfs_block_rsv_add(struct btrfs_root *root, 4741 int btrfs_block_rsv_add(struct btrfs_root *root,
4742 struct btrfs_block_rsv *block_rsv, u64 num_bytes, 4742 struct btrfs_block_rsv *block_rsv, u64 num_bytes,
4743 enum btrfs_reserve_flush_enum flush) 4743 enum btrfs_reserve_flush_enum flush)
4744 { 4744 {
4745 int ret; 4745 int ret;
4746 4746
4747 if (num_bytes == 0) 4747 if (num_bytes == 0)
4748 return 0; 4748 return 0;
4749 4749
4750 ret = reserve_metadata_bytes(root, block_rsv, num_bytes, flush); 4750 ret = reserve_metadata_bytes(root, block_rsv, num_bytes, flush);
4751 if (!ret) { 4751 if (!ret) {
4752 block_rsv_add_bytes(block_rsv, num_bytes, 1); 4752 block_rsv_add_bytes(block_rsv, num_bytes, 1);
4753 return 0; 4753 return 0;
4754 } 4754 }
4755 4755
4756 return ret; 4756 return ret;
4757 } 4757 }
4758 4758
4759 int btrfs_block_rsv_check(struct btrfs_root *root, 4759 int btrfs_block_rsv_check(struct btrfs_root *root,
4760 struct btrfs_block_rsv *block_rsv, int min_factor) 4760 struct btrfs_block_rsv *block_rsv, int min_factor)
4761 { 4761 {
4762 u64 num_bytes = 0; 4762 u64 num_bytes = 0;
4763 int ret = -ENOSPC; 4763 int ret = -ENOSPC;
4764 4764
4765 if (!block_rsv) 4765 if (!block_rsv)
4766 return 0; 4766 return 0;
4767 4767
4768 spin_lock(&block_rsv->lock); 4768 spin_lock(&block_rsv->lock);
4769 num_bytes = div_factor(block_rsv->size, min_factor); 4769 num_bytes = div_factor(block_rsv->size, min_factor);
4770 if (block_rsv->reserved >= num_bytes) 4770 if (block_rsv->reserved >= num_bytes)
4771 ret = 0; 4771 ret = 0;
4772 spin_unlock(&block_rsv->lock); 4772 spin_unlock(&block_rsv->lock);
4773 4773
4774 return ret; 4774 return ret;
4775 } 4775 }
4776 4776
4777 int btrfs_block_rsv_refill(struct btrfs_root *root, 4777 int btrfs_block_rsv_refill(struct btrfs_root *root,
4778 struct btrfs_block_rsv *block_rsv, u64 min_reserved, 4778 struct btrfs_block_rsv *block_rsv, u64 min_reserved,
4779 enum btrfs_reserve_flush_enum flush) 4779 enum btrfs_reserve_flush_enum flush)
4780 { 4780 {
4781 u64 num_bytes = 0; 4781 u64 num_bytes = 0;
4782 int ret = -ENOSPC; 4782 int ret = -ENOSPC;
4783 4783
4784 if (!block_rsv) 4784 if (!block_rsv)
4785 return 0; 4785 return 0;
4786 4786
4787 spin_lock(&block_rsv->lock); 4787 spin_lock(&block_rsv->lock);
4788 num_bytes = min_reserved; 4788 num_bytes = min_reserved;
4789 if (block_rsv->reserved >= num_bytes) 4789 if (block_rsv->reserved >= num_bytes)
4790 ret = 0; 4790 ret = 0;
4791 else 4791 else
4792 num_bytes -= block_rsv->reserved; 4792 num_bytes -= block_rsv->reserved;
4793 spin_unlock(&block_rsv->lock); 4793 spin_unlock(&block_rsv->lock);
4794 4794
4795 if (!ret) 4795 if (!ret)
4796 return 0; 4796 return 0;
4797 4797
4798 ret = reserve_metadata_bytes(root, block_rsv, num_bytes, flush); 4798 ret = reserve_metadata_bytes(root, block_rsv, num_bytes, flush);
4799 if (!ret) { 4799 if (!ret) {
4800 block_rsv_add_bytes(block_rsv, num_bytes, 0); 4800 block_rsv_add_bytes(block_rsv, num_bytes, 0);
4801 return 0; 4801 return 0;
4802 } 4802 }
4803 4803
4804 return ret; 4804 return ret;
4805 } 4805 }
4806 4806
4807 int btrfs_block_rsv_migrate(struct btrfs_block_rsv *src_rsv, 4807 int btrfs_block_rsv_migrate(struct btrfs_block_rsv *src_rsv,
4808 struct btrfs_block_rsv *dst_rsv, 4808 struct btrfs_block_rsv *dst_rsv,
4809 u64 num_bytes) 4809 u64 num_bytes)
4810 { 4810 {
4811 return block_rsv_migrate_bytes(src_rsv, dst_rsv, num_bytes); 4811 return block_rsv_migrate_bytes(src_rsv, dst_rsv, num_bytes);
4812 } 4812 }
4813 4813
4814 void btrfs_block_rsv_release(struct btrfs_root *root, 4814 void btrfs_block_rsv_release(struct btrfs_root *root,
4815 struct btrfs_block_rsv *block_rsv, 4815 struct btrfs_block_rsv *block_rsv,
4816 u64 num_bytes) 4816 u64 num_bytes)
4817 { 4817 {
4818 struct btrfs_block_rsv *global_rsv = &root->fs_info->global_block_rsv; 4818 struct btrfs_block_rsv *global_rsv = &root->fs_info->global_block_rsv;
4819 if (global_rsv == block_rsv || 4819 if (global_rsv == block_rsv ||
4820 block_rsv->space_info != global_rsv->space_info) 4820 block_rsv->space_info != global_rsv->space_info)
4821 global_rsv = NULL; 4821 global_rsv = NULL;
4822 block_rsv_release_bytes(root->fs_info, block_rsv, global_rsv, 4822 block_rsv_release_bytes(root->fs_info, block_rsv, global_rsv,
4823 num_bytes); 4823 num_bytes);
4824 } 4824 }
4825 4825
4826 /* 4826 /*
4827 * helper to calculate size of global block reservation. 4827 * helper to calculate size of global block reservation.
4828 * the desired value is sum of space used by extent tree, 4828 * the desired value is sum of space used by extent tree,
4829 * checksum tree and root tree 4829 * checksum tree and root tree
4830 */ 4830 */
4831 static u64 calc_global_metadata_size(struct btrfs_fs_info *fs_info) 4831 static u64 calc_global_metadata_size(struct btrfs_fs_info *fs_info)
4832 { 4832 {
4833 struct btrfs_space_info *sinfo; 4833 struct btrfs_space_info *sinfo;
4834 u64 num_bytes; 4834 u64 num_bytes;
4835 u64 meta_used; 4835 u64 meta_used;
4836 u64 data_used; 4836 u64 data_used;
4837 int csum_size = btrfs_super_csum_size(fs_info->super_copy); 4837 int csum_size = btrfs_super_csum_size(fs_info->super_copy);
4838 4838
4839 sinfo = __find_space_info(fs_info, BTRFS_BLOCK_GROUP_DATA); 4839 sinfo = __find_space_info(fs_info, BTRFS_BLOCK_GROUP_DATA);
4840 spin_lock(&sinfo->lock); 4840 spin_lock(&sinfo->lock);
4841 data_used = sinfo->bytes_used; 4841 data_used = sinfo->bytes_used;
4842 spin_unlock(&sinfo->lock); 4842 spin_unlock(&sinfo->lock);
4843 4843
4844 sinfo = __find_space_info(fs_info, BTRFS_BLOCK_GROUP_METADATA); 4844 sinfo = __find_space_info(fs_info, BTRFS_BLOCK_GROUP_METADATA);
4845 spin_lock(&sinfo->lock); 4845 spin_lock(&sinfo->lock);
4846 if (sinfo->flags & BTRFS_BLOCK_GROUP_DATA) 4846 if (sinfo->flags & BTRFS_BLOCK_GROUP_DATA)
4847 data_used = 0; 4847 data_used = 0;
4848 meta_used = sinfo->bytes_used; 4848 meta_used = sinfo->bytes_used;
4849 spin_unlock(&sinfo->lock); 4849 spin_unlock(&sinfo->lock);
4850 4850
4851 num_bytes = (data_used >> fs_info->sb->s_blocksize_bits) * 4851 num_bytes = (data_used >> fs_info->sb->s_blocksize_bits) *
4852 csum_size * 2; 4852 csum_size * 2;
4853 num_bytes += div64_u64(data_used + meta_used, 50); 4853 num_bytes += div64_u64(data_used + meta_used, 50);
4854 4854
4855 if (num_bytes * 3 > meta_used) 4855 if (num_bytes * 3 > meta_used)
4856 num_bytes = div64_u64(meta_used, 3); 4856 num_bytes = div64_u64(meta_used, 3);
4857 4857
4858 return ALIGN(num_bytes, fs_info->extent_root->nodesize << 10); 4858 return ALIGN(num_bytes, fs_info->extent_root->nodesize << 10);
4859 } 4859 }
4860 4860
4861 static void update_global_block_rsv(struct btrfs_fs_info *fs_info) 4861 static void update_global_block_rsv(struct btrfs_fs_info *fs_info)
4862 { 4862 {
4863 struct btrfs_block_rsv *block_rsv = &fs_info->global_block_rsv; 4863 struct btrfs_block_rsv *block_rsv = &fs_info->global_block_rsv;
4864 struct btrfs_space_info *sinfo = block_rsv->space_info; 4864 struct btrfs_space_info *sinfo = block_rsv->space_info;
4865 u64 num_bytes; 4865 u64 num_bytes;
4866 4866
4867 num_bytes = calc_global_metadata_size(fs_info); 4867 num_bytes = calc_global_metadata_size(fs_info);
4868 4868
4869 spin_lock(&sinfo->lock); 4869 spin_lock(&sinfo->lock);
4870 spin_lock(&block_rsv->lock); 4870 spin_lock(&block_rsv->lock);
4871 4871
4872 block_rsv->size = min_t(u64, num_bytes, 512 * 1024 * 1024); 4872 block_rsv->size = min_t(u64, num_bytes, 512 * 1024 * 1024);
4873 4873
4874 num_bytes = sinfo->bytes_used + sinfo->bytes_pinned + 4874 num_bytes = sinfo->bytes_used + sinfo->bytes_pinned +
4875 sinfo->bytes_reserved + sinfo->bytes_readonly + 4875 sinfo->bytes_reserved + sinfo->bytes_readonly +
4876 sinfo->bytes_may_use; 4876 sinfo->bytes_may_use;
4877 4877
4878 if (sinfo->total_bytes > num_bytes) { 4878 if (sinfo->total_bytes > num_bytes) {
4879 num_bytes = sinfo->total_bytes - num_bytes; 4879 num_bytes = sinfo->total_bytes - num_bytes;
4880 block_rsv->reserved += num_bytes; 4880 block_rsv->reserved += num_bytes;
4881 sinfo->bytes_may_use += num_bytes; 4881 sinfo->bytes_may_use += num_bytes;
4882 trace_btrfs_space_reservation(fs_info, "space_info", 4882 trace_btrfs_space_reservation(fs_info, "space_info",
4883 sinfo->flags, num_bytes, 1); 4883 sinfo->flags, num_bytes, 1);
4884 } 4884 }
4885 4885
4886 if (block_rsv->reserved >= block_rsv->size) { 4886 if (block_rsv->reserved >= block_rsv->size) {
4887 num_bytes = block_rsv->reserved - block_rsv->size; 4887 num_bytes = block_rsv->reserved - block_rsv->size;
4888 sinfo->bytes_may_use -= num_bytes; 4888 sinfo->bytes_may_use -= num_bytes;
4889 trace_btrfs_space_reservation(fs_info, "space_info", 4889 trace_btrfs_space_reservation(fs_info, "space_info",
4890 sinfo->flags, num_bytes, 0); 4890 sinfo->flags, num_bytes, 0);
4891 block_rsv->reserved = block_rsv->size; 4891 block_rsv->reserved = block_rsv->size;
4892 block_rsv->full = 1; 4892 block_rsv->full = 1;
4893 } 4893 }
4894 4894
4895 spin_unlock(&block_rsv->lock); 4895 spin_unlock(&block_rsv->lock);
4896 spin_unlock(&sinfo->lock); 4896 spin_unlock(&sinfo->lock);
4897 } 4897 }
4898 4898
4899 static void init_global_block_rsv(struct btrfs_fs_info *fs_info) 4899 static void init_global_block_rsv(struct btrfs_fs_info *fs_info)
4900 { 4900 {
4901 struct btrfs_space_info *space_info; 4901 struct btrfs_space_info *space_info;
4902 4902
4903 space_info = __find_space_info(fs_info, BTRFS_BLOCK_GROUP_SYSTEM); 4903 space_info = __find_space_info(fs_info, BTRFS_BLOCK_GROUP_SYSTEM);
4904 fs_info->chunk_block_rsv.space_info = space_info; 4904 fs_info->chunk_block_rsv.space_info = space_info;
4905 4905
4906 space_info = __find_space_info(fs_info, BTRFS_BLOCK_GROUP_METADATA); 4906 space_info = __find_space_info(fs_info, BTRFS_BLOCK_GROUP_METADATA);
4907 fs_info->global_block_rsv.space_info = space_info; 4907 fs_info->global_block_rsv.space_info = space_info;
4908 fs_info->delalloc_block_rsv.space_info = space_info; 4908 fs_info->delalloc_block_rsv.space_info = space_info;
4909 fs_info->trans_block_rsv.space_info = space_info; 4909 fs_info->trans_block_rsv.space_info = space_info;
4910 fs_info->empty_block_rsv.space_info = space_info; 4910 fs_info->empty_block_rsv.space_info = space_info;
4911 fs_info->delayed_block_rsv.space_info = space_info; 4911 fs_info->delayed_block_rsv.space_info = space_info;
4912 4912
4913 fs_info->extent_root->block_rsv = &fs_info->global_block_rsv; 4913 fs_info->extent_root->block_rsv = &fs_info->global_block_rsv;
4914 fs_info->csum_root->block_rsv = &fs_info->global_block_rsv; 4914 fs_info->csum_root->block_rsv = &fs_info->global_block_rsv;
4915 fs_info->dev_root->block_rsv = &fs_info->global_block_rsv; 4915 fs_info->dev_root->block_rsv = &fs_info->global_block_rsv;
4916 fs_info->tree_root->block_rsv = &fs_info->global_block_rsv; 4916 fs_info->tree_root->block_rsv = &fs_info->global_block_rsv;
4917 if (fs_info->quota_root) 4917 if (fs_info->quota_root)
4918 fs_info->quota_root->block_rsv = &fs_info->global_block_rsv; 4918 fs_info->quota_root->block_rsv = &fs_info->global_block_rsv;
4919 fs_info->chunk_root->block_rsv = &fs_info->chunk_block_rsv; 4919 fs_info->chunk_root->block_rsv = &fs_info->chunk_block_rsv;
4920 4920
4921 update_global_block_rsv(fs_info); 4921 update_global_block_rsv(fs_info);
4922 } 4922 }
4923 4923
4924 static void release_global_block_rsv(struct btrfs_fs_info *fs_info) 4924 static void release_global_block_rsv(struct btrfs_fs_info *fs_info)
4925 { 4925 {
4926 block_rsv_release_bytes(fs_info, &fs_info->global_block_rsv, NULL, 4926 block_rsv_release_bytes(fs_info, &fs_info->global_block_rsv, NULL,
4927 (u64)-1); 4927 (u64)-1);
4928 WARN_ON(fs_info->delalloc_block_rsv.size > 0); 4928 WARN_ON(fs_info->delalloc_block_rsv.size > 0);
4929 WARN_ON(fs_info->delalloc_block_rsv.reserved > 0); 4929 WARN_ON(fs_info->delalloc_block_rsv.reserved > 0);
4930 WARN_ON(fs_info->trans_block_rsv.size > 0); 4930 WARN_ON(fs_info->trans_block_rsv.size > 0);
4931 WARN_ON(fs_info->trans_block_rsv.reserved > 0); 4931 WARN_ON(fs_info->trans_block_rsv.reserved > 0);
4932 WARN_ON(fs_info->chunk_block_rsv.size > 0); 4932 WARN_ON(fs_info->chunk_block_rsv.size > 0);
4933 WARN_ON(fs_info->chunk_block_rsv.reserved > 0); 4933 WARN_ON(fs_info->chunk_block_rsv.reserved > 0);
4934 WARN_ON(fs_info->delayed_block_rsv.size > 0); 4934 WARN_ON(fs_info->delayed_block_rsv.size > 0);
4935 WARN_ON(fs_info->delayed_block_rsv.reserved > 0); 4935 WARN_ON(fs_info->delayed_block_rsv.reserved > 0);
4936 } 4936 }
4937 4937
4938 void btrfs_trans_release_metadata(struct btrfs_trans_handle *trans, 4938 void btrfs_trans_release_metadata(struct btrfs_trans_handle *trans,
4939 struct btrfs_root *root) 4939 struct btrfs_root *root)
4940 { 4940 {
4941 if (!trans->block_rsv) 4941 if (!trans->block_rsv)
4942 return; 4942 return;
4943 4943
4944 if (!trans->bytes_reserved) 4944 if (!trans->bytes_reserved)
4945 return; 4945 return;
4946 4946
4947 trace_btrfs_space_reservation(root->fs_info, "transaction", 4947 trace_btrfs_space_reservation(root->fs_info, "transaction",
4948 trans->transid, trans->bytes_reserved, 0); 4948 trans->transid, trans->bytes_reserved, 0);
4949 btrfs_block_rsv_release(root, trans->block_rsv, trans->bytes_reserved); 4949 btrfs_block_rsv_release(root, trans->block_rsv, trans->bytes_reserved);
4950 trans->bytes_reserved = 0; 4950 trans->bytes_reserved = 0;
4951 } 4951 }
4952 4952
4953 /* Can only return 0 or -ENOSPC */ 4953 /* Can only return 0 or -ENOSPC */
4954 int btrfs_orphan_reserve_metadata(struct btrfs_trans_handle *trans, 4954 int btrfs_orphan_reserve_metadata(struct btrfs_trans_handle *trans,
4955 struct inode *inode) 4955 struct inode *inode)
4956 { 4956 {
4957 struct btrfs_root *root = BTRFS_I(inode)->root; 4957 struct btrfs_root *root = BTRFS_I(inode)->root;
4958 struct btrfs_block_rsv *src_rsv = get_block_rsv(trans, root); 4958 struct btrfs_block_rsv *src_rsv = get_block_rsv(trans, root);
4959 struct btrfs_block_rsv *dst_rsv = root->orphan_block_rsv; 4959 struct btrfs_block_rsv *dst_rsv = root->orphan_block_rsv;
4960 4960
4961 /* 4961 /*
4962 * We need to hold space in order to delete our orphan item once we've 4962 * We need to hold space in order to delete our orphan item once we've
4963 * added it, so this takes the reservation so we can release it later 4963 * added it, so this takes the reservation so we can release it later
4964 * when we are truly done with the orphan item. 4964 * when we are truly done with the orphan item.
4965 */ 4965 */
4966 u64 num_bytes = btrfs_calc_trans_metadata_size(root, 1); 4966 u64 num_bytes = btrfs_calc_trans_metadata_size(root, 1);
4967 trace_btrfs_space_reservation(root->fs_info, "orphan", 4967 trace_btrfs_space_reservation(root->fs_info, "orphan",
4968 btrfs_ino(inode), num_bytes, 1); 4968 btrfs_ino(inode), num_bytes, 1);
4969 return block_rsv_migrate_bytes(src_rsv, dst_rsv, num_bytes); 4969 return block_rsv_migrate_bytes(src_rsv, dst_rsv, num_bytes);
4970 } 4970 }
4971 4971
4972 void btrfs_orphan_release_metadata(struct inode *inode) 4972 void btrfs_orphan_release_metadata(struct inode *inode)
4973 { 4973 {
4974 struct btrfs_root *root = BTRFS_I(inode)->root; 4974 struct btrfs_root *root = BTRFS_I(inode)->root;
4975 u64 num_bytes = btrfs_calc_trans_metadata_size(root, 1); 4975 u64 num_bytes = btrfs_calc_trans_metadata_size(root, 1);
4976 trace_btrfs_space_reservation(root->fs_info, "orphan", 4976 trace_btrfs_space_reservation(root->fs_info, "orphan",
4977 btrfs_ino(inode), num_bytes, 0); 4977 btrfs_ino(inode), num_bytes, 0);
4978 btrfs_block_rsv_release(root, root->orphan_block_rsv, num_bytes); 4978 btrfs_block_rsv_release(root, root->orphan_block_rsv, num_bytes);
4979 } 4979 }
4980 4980
4981 /* 4981 /*
4982 * btrfs_subvolume_reserve_metadata() - reserve space for subvolume operation 4982 * btrfs_subvolume_reserve_metadata() - reserve space for subvolume operation
4983 * root: the root of the parent directory 4983 * root: the root of the parent directory
4984 * rsv: block reservation 4984 * rsv: block reservation
4985 * items: the number of items that we need do reservation 4985 * items: the number of items that we need do reservation
4986 * qgroup_reserved: used to return the reserved size in qgroup 4986 * qgroup_reserved: used to return the reserved size in qgroup
4987 * 4987 *
4988 * This function is used to reserve the space for snapshot/subvolume 4988 * This function is used to reserve the space for snapshot/subvolume
4989 * creation and deletion. Those operations are different with the 4989 * creation and deletion. Those operations are different with the
4990 * common file/directory operations, they change two fs/file trees 4990 * common file/directory operations, they change two fs/file trees
4991 * and root tree, the number of items that the qgroup reserves is 4991 * and root tree, the number of items that the qgroup reserves is
4992 * different with the free space reservation. So we can not use 4992 * different with the free space reservation. So we can not use
4993 * the space reseravtion mechanism in start_transaction(). 4993 * the space reseravtion mechanism in start_transaction().
4994 */ 4994 */
4995 int btrfs_subvolume_reserve_metadata(struct btrfs_root *root, 4995 int btrfs_subvolume_reserve_metadata(struct btrfs_root *root,
4996 struct btrfs_block_rsv *rsv, 4996 struct btrfs_block_rsv *rsv,
4997 int items, 4997 int items,
4998 u64 *qgroup_reserved, 4998 u64 *qgroup_reserved,
4999 bool use_global_rsv) 4999 bool use_global_rsv)
5000 { 5000 {
5001 u64 num_bytes; 5001 u64 num_bytes;
5002 int ret; 5002 int ret;
5003 struct btrfs_block_rsv *global_rsv = &root->fs_info->global_block_rsv; 5003 struct btrfs_block_rsv *global_rsv = &root->fs_info->global_block_rsv;
5004 5004
5005 if (root->fs_info->quota_enabled) { 5005 if (root->fs_info->quota_enabled) {
5006 /* One for parent inode, two for dir entries */ 5006 /* One for parent inode, two for dir entries */
5007 num_bytes = 3 * root->nodesize; 5007 num_bytes = 3 * root->nodesize;
5008 ret = btrfs_qgroup_reserve(root, num_bytes); 5008 ret = btrfs_qgroup_reserve(root, num_bytes);
5009 if (ret) 5009 if (ret)
5010 return ret; 5010 return ret;
5011 } else { 5011 } else {
5012 num_bytes = 0; 5012 num_bytes = 0;
5013 } 5013 }
5014 5014
5015 *qgroup_reserved = num_bytes; 5015 *qgroup_reserved = num_bytes;
5016 5016
5017 num_bytes = btrfs_calc_trans_metadata_size(root, items); 5017 num_bytes = btrfs_calc_trans_metadata_size(root, items);
5018 rsv->space_info = __find_space_info(root->fs_info, 5018 rsv->space_info = __find_space_info(root->fs_info,
5019 BTRFS_BLOCK_GROUP_METADATA); 5019 BTRFS_BLOCK_GROUP_METADATA);
5020 ret = btrfs_block_rsv_add(root, rsv, num_bytes, 5020 ret = btrfs_block_rsv_add(root, rsv, num_bytes,
5021 BTRFS_RESERVE_FLUSH_ALL); 5021 BTRFS_RESERVE_FLUSH_ALL);
5022 5022
5023 if (ret == -ENOSPC && use_global_rsv) 5023 if (ret == -ENOSPC && use_global_rsv)
5024 ret = btrfs_block_rsv_migrate(global_rsv, rsv, num_bytes); 5024 ret = btrfs_block_rsv_migrate(global_rsv, rsv, num_bytes);
5025 5025
5026 if (ret) { 5026 if (ret) {
5027 if (*qgroup_reserved) 5027 if (*qgroup_reserved)
5028 btrfs_qgroup_free(root, *qgroup_reserved); 5028 btrfs_qgroup_free(root, *qgroup_reserved);
5029 } 5029 }
5030 5030
5031 return ret; 5031 return ret;
5032 } 5032 }
5033 5033
5034 void btrfs_subvolume_release_metadata(struct btrfs_root *root, 5034 void btrfs_subvolume_release_metadata(struct btrfs_root *root,
5035 struct btrfs_block_rsv *rsv, 5035 struct btrfs_block_rsv *rsv,
5036 u64 qgroup_reserved) 5036 u64 qgroup_reserved)
5037 { 5037 {
5038 btrfs_block_rsv_release(root, rsv, (u64)-1); 5038 btrfs_block_rsv_release(root, rsv, (u64)-1);
5039 if (qgroup_reserved) 5039 if (qgroup_reserved)
5040 btrfs_qgroup_free(root, qgroup_reserved); 5040 btrfs_qgroup_free(root, qgroup_reserved);
5041 } 5041 }
5042 5042
5043 /** 5043 /**
5044 * drop_outstanding_extent - drop an outstanding extent 5044 * drop_outstanding_extent - drop an outstanding extent
5045 * @inode: the inode we're dropping the extent for 5045 * @inode: the inode we're dropping the extent for
5046 * 5046 *
5047 * This is called when we are freeing up an outstanding extent, either called 5047 * This is called when we are freeing up an outstanding extent, either called
5048 * after an error or after an extent is written. This will return the number of 5048 * after an error or after an extent is written. This will return the number of
5049 * reserved extents that need to be freed. This must be called with 5049 * reserved extents that need to be freed. This must be called with
5050 * BTRFS_I(inode)->lock held. 5050 * BTRFS_I(inode)->lock held.
5051 */ 5051 */
5052 static unsigned drop_outstanding_extent(struct inode *inode) 5052 static unsigned drop_outstanding_extent(struct inode *inode)
5053 { 5053 {
5054 unsigned drop_inode_space = 0; 5054 unsigned drop_inode_space = 0;
5055 unsigned dropped_extents = 0; 5055 unsigned dropped_extents = 0;
5056 5056
5057 BUG_ON(!BTRFS_I(inode)->outstanding_extents); 5057 BUG_ON(!BTRFS_I(inode)->outstanding_extents);
5058 BTRFS_I(inode)->outstanding_extents--; 5058 BTRFS_I(inode)->outstanding_extents--;
5059 5059
5060 if (BTRFS_I(inode)->outstanding_extents == 0 && 5060 if (BTRFS_I(inode)->outstanding_extents == 0 &&
5061 test_and_clear_bit(BTRFS_INODE_DELALLOC_META_RESERVED, 5061 test_and_clear_bit(BTRFS_INODE_DELALLOC_META_RESERVED,
5062 &BTRFS_I(inode)->runtime_flags)) 5062 &BTRFS_I(inode)->runtime_flags))
5063 drop_inode_space = 1; 5063 drop_inode_space = 1;
5064 5064
5065 /* 5065 /*
5066 * If we have more or the same amount of outsanding extents than we have 5066 * If we have more or the same amount of outsanding extents than we have
5067 * reserved then we need to leave the reserved extents count alone. 5067 * reserved then we need to leave the reserved extents count alone.
5068 */ 5068 */
5069 if (BTRFS_I(inode)->outstanding_extents >= 5069 if (BTRFS_I(inode)->outstanding_extents >=
5070 BTRFS_I(inode)->reserved_extents) 5070 BTRFS_I(inode)->reserved_extents)
5071 return drop_inode_space; 5071 return drop_inode_space;
5072 5072
5073 dropped_extents = BTRFS_I(inode)->reserved_extents - 5073 dropped_extents = BTRFS_I(inode)->reserved_extents -
5074 BTRFS_I(inode)->outstanding_extents; 5074 BTRFS_I(inode)->outstanding_extents;
5075 BTRFS_I(inode)->reserved_extents -= dropped_extents; 5075 BTRFS_I(inode)->reserved_extents -= dropped_extents;
5076 return dropped_extents + drop_inode_space; 5076 return dropped_extents + drop_inode_space;
5077 } 5077 }
5078 5078
5079 /** 5079 /**
5080 * calc_csum_metadata_size - return the amount of metada space that must be 5080 * calc_csum_metadata_size - return the amount of metada space that must be
5081 * reserved/free'd for the given bytes. 5081 * reserved/free'd for the given bytes.
5082 * @inode: the inode we're manipulating 5082 * @inode: the inode we're manipulating
5083 * @num_bytes: the number of bytes in question 5083 * @num_bytes: the number of bytes in question
5084 * @reserve: 1 if we are reserving space, 0 if we are freeing space 5084 * @reserve: 1 if we are reserving space, 0 if we are freeing space
5085 * 5085 *
5086 * This adjusts the number of csum_bytes in the inode and then returns the 5086 * This adjusts the number of csum_bytes in the inode and then returns the
5087 * correct amount of metadata that must either be reserved or freed. We 5087 * correct amount of metadata that must either be reserved or freed. We
5088 * calculate how many checksums we can fit into one leaf and then divide the 5088 * calculate how many checksums we can fit into one leaf and then divide the
5089 * number of bytes that will need to be checksumed by this value to figure out 5089 * number of bytes that will need to be checksumed by this value to figure out
5090 * how many checksums will be required. If we are adding bytes then the number 5090 * how many checksums will be required. If we are adding bytes then the number
5091 * may go up and we will return the number of additional bytes that must be 5091 * may go up and we will return the number of additional bytes that must be
5092 * reserved. If it is going down we will return the number of bytes that must 5092 * reserved. If it is going down we will return the number of bytes that must
5093 * be freed. 5093 * be freed.
5094 * 5094 *
5095 * This must be called with BTRFS_I(inode)->lock held. 5095 * This must be called with BTRFS_I(inode)->lock held.
5096 */ 5096 */
5097 static u64 calc_csum_metadata_size(struct inode *inode, u64 num_bytes, 5097 static u64 calc_csum_metadata_size(struct inode *inode, u64 num_bytes,
5098 int reserve) 5098 int reserve)
5099 { 5099 {
5100 struct btrfs_root *root = BTRFS_I(inode)->root; 5100 struct btrfs_root *root = BTRFS_I(inode)->root;
5101 u64 csum_size; 5101 u64 csum_size;
5102 int num_csums_per_leaf; 5102 int num_csums_per_leaf;
5103 int num_csums; 5103 int num_csums;
5104 int old_csums; 5104 int old_csums;
5105 5105
5106 if (BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM && 5106 if (BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM &&
5107 BTRFS_I(inode)->csum_bytes == 0) 5107 BTRFS_I(inode)->csum_bytes == 0)
5108 return 0; 5108 return 0;
5109 5109
5110 old_csums = (int)div64_u64(BTRFS_I(inode)->csum_bytes, root->sectorsize); 5110 old_csums = (int)div64_u64(BTRFS_I(inode)->csum_bytes, root->sectorsize);
5111 if (reserve) 5111 if (reserve)
5112 BTRFS_I(inode)->csum_bytes += num_bytes; 5112 BTRFS_I(inode)->csum_bytes += num_bytes;
5113 else 5113 else
5114 BTRFS_I(inode)->csum_bytes -= num_bytes; 5114 BTRFS_I(inode)->csum_bytes -= num_bytes;
5115 csum_size = BTRFS_LEAF_DATA_SIZE(root) - sizeof(struct btrfs_item); 5115 csum_size = BTRFS_LEAF_DATA_SIZE(root) - sizeof(struct btrfs_item);
5116 num_csums_per_leaf = (int)div64_u64(csum_size, 5116 num_csums_per_leaf = (int)div64_u64(csum_size,
5117 sizeof(struct btrfs_csum_item) + 5117 sizeof(struct btrfs_csum_item) +
5118 sizeof(struct btrfs_disk_key)); 5118 sizeof(struct btrfs_disk_key));
5119 num_csums = (int)div64_u64(BTRFS_I(inode)->csum_bytes, root->sectorsize); 5119 num_csums = (int)div64_u64(BTRFS_I(inode)->csum_bytes, root->sectorsize);
5120 num_csums = num_csums + num_csums_per_leaf - 1; 5120 num_csums = num_csums + num_csums_per_leaf - 1;
5121 num_csums = num_csums / num_csums_per_leaf; 5121 num_csums = num_csums / num_csums_per_leaf;
5122 5122
5123 old_csums = old_csums + num_csums_per_leaf - 1; 5123 old_csums = old_csums + num_csums_per_leaf - 1;
5124 old_csums = old_csums / num_csums_per_leaf; 5124 old_csums = old_csums / num_csums_per_leaf;
5125 5125
5126 /* No change, no need to reserve more */ 5126 /* No change, no need to reserve more */
5127 if (old_csums == num_csums) 5127 if (old_csums == num_csums)
5128 return 0; 5128 return 0;
5129 5129
5130 if (reserve) 5130 if (reserve)
5131 return btrfs_calc_trans_metadata_size(root, 5131 return btrfs_calc_trans_metadata_size(root,
5132 num_csums - old_csums); 5132 num_csums - old_csums);
5133 5133
5134 return btrfs_calc_trans_metadata_size(root, old_csums - num_csums); 5134 return btrfs_calc_trans_metadata_size(root, old_csums - num_csums);
5135 } 5135 }
5136 5136
5137 int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes) 5137 int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes)
5138 { 5138 {
5139 struct btrfs_root *root = BTRFS_I(inode)->root; 5139 struct btrfs_root *root = BTRFS_I(inode)->root;
5140 struct btrfs_block_rsv *block_rsv = &root->fs_info->delalloc_block_rsv; 5140 struct btrfs_block_rsv *block_rsv = &root->fs_info->delalloc_block_rsv;
5141 u64 to_reserve = 0; 5141 u64 to_reserve = 0;
5142 u64 csum_bytes; 5142 u64 csum_bytes;
5143 unsigned nr_extents = 0; 5143 unsigned nr_extents = 0;
5144 int extra_reserve = 0; 5144 int extra_reserve = 0;
5145 enum btrfs_reserve_flush_enum flush = BTRFS_RESERVE_FLUSH_ALL; 5145 enum btrfs_reserve_flush_enum flush = BTRFS_RESERVE_FLUSH_ALL;
5146 int ret = 0; 5146 int ret = 0;
5147 bool delalloc_lock = true; 5147 bool delalloc_lock = true;
5148 u64 to_free = 0; 5148 u64 to_free = 0;
5149 unsigned dropped; 5149 unsigned dropped;
5150 5150
5151 /* If we are a free space inode we need to not flush since we will be in 5151 /* If we are a free space inode we need to not flush since we will be in
5152 * the middle of a transaction commit. We also don't need the delalloc 5152 * the middle of a transaction commit. We also don't need the delalloc
5153 * mutex since we won't race with anybody. We need this mostly to make 5153 * mutex since we won't race with anybody. We need this mostly to make
5154 * lockdep shut its filthy mouth. 5154 * lockdep shut its filthy mouth.
5155 */ 5155 */
5156 if (btrfs_is_free_space_inode(inode)) { 5156 if (btrfs_is_free_space_inode(inode)) {
5157 flush = BTRFS_RESERVE_NO_FLUSH; 5157 flush = BTRFS_RESERVE_NO_FLUSH;
5158 delalloc_lock = false; 5158 delalloc_lock = false;
5159 } 5159 }
5160 5160
5161 if (flush != BTRFS_RESERVE_NO_FLUSH && 5161 if (flush != BTRFS_RESERVE_NO_FLUSH &&
5162 btrfs_transaction_in_commit(root->fs_info)) 5162 btrfs_transaction_in_commit(root->fs_info))
5163 schedule_timeout(1); 5163 schedule_timeout(1);
5164 5164
5165 if (delalloc_lock) 5165 if (delalloc_lock)
5166 mutex_lock(&BTRFS_I(inode)->delalloc_mutex); 5166 mutex_lock(&BTRFS_I(inode)->delalloc_mutex);
5167 5167
5168 num_bytes = ALIGN(num_bytes, root->sectorsize); 5168 num_bytes = ALIGN(num_bytes, root->sectorsize);
5169 5169
5170 spin_lock(&BTRFS_I(inode)->lock); 5170 spin_lock(&BTRFS_I(inode)->lock);
5171 BTRFS_I(inode)->outstanding_extents++; 5171 BTRFS_I(inode)->outstanding_extents++;
5172 5172
5173 if (BTRFS_I(inode)->outstanding_extents > 5173 if (BTRFS_I(inode)->outstanding_extents >
5174 BTRFS_I(inode)->reserved_extents) 5174 BTRFS_I(inode)->reserved_extents)
5175 nr_extents = BTRFS_I(inode)->outstanding_extents - 5175 nr_extents = BTRFS_I(inode)->outstanding_extents -
5176 BTRFS_I(inode)->reserved_extents; 5176 BTRFS_I(inode)->reserved_extents;
5177 5177
5178 /* 5178 /*
5179 * Add an item to reserve for updating the inode when we complete the 5179 * Add an item to reserve for updating the inode when we complete the
5180 * delalloc io. 5180 * delalloc io.
5181 */ 5181 */
5182 if (!test_bit(BTRFS_INODE_DELALLOC_META_RESERVED, 5182 if (!test_bit(BTRFS_INODE_DELALLOC_META_RESERVED,
5183 &BTRFS_I(inode)->runtime_flags)) { 5183 &BTRFS_I(inode)->runtime_flags)) {
5184 nr_extents++; 5184 nr_extents++;
5185 extra_reserve = 1; 5185 extra_reserve = 1;
5186 } 5186 }
5187 5187
5188 to_reserve = btrfs_calc_trans_metadata_size(root, nr_extents); 5188 to_reserve = btrfs_calc_trans_metadata_size(root, nr_extents);
5189 to_reserve += calc_csum_metadata_size(inode, num_bytes, 1); 5189 to_reserve += calc_csum_metadata_size(inode, num_bytes, 1);
5190 csum_bytes = BTRFS_I(inode)->csum_bytes; 5190 csum_bytes = BTRFS_I(inode)->csum_bytes;
5191 spin_unlock(&BTRFS_I(inode)->lock); 5191 spin_unlock(&BTRFS_I(inode)->lock);
5192 5192
5193 if (root->fs_info->quota_enabled) { 5193 if (root->fs_info->quota_enabled) {
5194 ret = btrfs_qgroup_reserve(root, num_bytes + 5194 ret = btrfs_qgroup_reserve(root, num_bytes +
5195 nr_extents * root->nodesize); 5195 nr_extents * root->nodesize);
5196 if (ret) 5196 if (ret)
5197 goto out_fail; 5197 goto out_fail;
5198 } 5198 }
5199 5199
5200 ret = reserve_metadata_bytes(root, block_rsv, to_reserve, flush); 5200 ret = reserve_metadata_bytes(root, block_rsv, to_reserve, flush);
5201 if (unlikely(ret)) { 5201 if (unlikely(ret)) {
5202 if (root->fs_info->quota_enabled) 5202 if (root->fs_info->quota_enabled)
5203 btrfs_qgroup_free(root, num_bytes + 5203 btrfs_qgroup_free(root, num_bytes +
5204 nr_extents * root->nodesize); 5204 nr_extents * root->nodesize);
5205 goto out_fail; 5205 goto out_fail;
5206 } 5206 }
5207 5207
5208 spin_lock(&BTRFS_I(inode)->lock); 5208 spin_lock(&BTRFS_I(inode)->lock);
5209 if (extra_reserve) { 5209 if (extra_reserve) {
5210 set_bit(BTRFS_INODE_DELALLOC_META_RESERVED, 5210 set_bit(BTRFS_INODE_DELALLOC_META_RESERVED,
5211 &BTRFS_I(inode)->runtime_flags); 5211 &BTRFS_I(inode)->runtime_flags);
5212 nr_extents--; 5212 nr_extents--;
5213 } 5213 }
5214 BTRFS_I(inode)->reserved_extents += nr_extents; 5214 BTRFS_I(inode)->reserved_extents += nr_extents;
5215 spin_unlock(&BTRFS_I(inode)->lock); 5215 spin_unlock(&BTRFS_I(inode)->lock);
5216 5216
5217 if (delalloc_lock) 5217 if (delalloc_lock)
5218 mutex_unlock(&BTRFS_I(inode)->delalloc_mutex); 5218 mutex_unlock(&BTRFS_I(inode)->delalloc_mutex);
5219 5219
5220 if (to_reserve) 5220 if (to_reserve)
5221 trace_btrfs_space_reservation(root->fs_info, "delalloc", 5221 trace_btrfs_space_reservation(root->fs_info, "delalloc",
5222 btrfs_ino(inode), to_reserve, 1); 5222 btrfs_ino(inode), to_reserve, 1);
5223 block_rsv_add_bytes(block_rsv, to_reserve, 1); 5223 block_rsv_add_bytes(block_rsv, to_reserve, 1);
5224 5224
5225 return 0; 5225 return 0;
5226 5226
5227 out_fail: 5227 out_fail:
5228 spin_lock(&BTRFS_I(inode)->lock); 5228 spin_lock(&BTRFS_I(inode)->lock);
5229 dropped = drop_outstanding_extent(inode); 5229 dropped = drop_outstanding_extent(inode);
5230 /* 5230 /*
5231 * If the inodes csum_bytes is the same as the original 5231 * If the inodes csum_bytes is the same as the original
5232 * csum_bytes then we know we haven't raced with any free()ers 5232 * csum_bytes then we know we haven't raced with any free()ers
5233 * so we can just reduce our inodes csum bytes and carry on. 5233 * so we can just reduce our inodes csum bytes and carry on.
5234 */ 5234 */
5235 if (BTRFS_I(inode)->csum_bytes == csum_bytes) { 5235 if (BTRFS_I(inode)->csum_bytes == csum_bytes) {
5236 calc_csum_metadata_size(inode, num_bytes, 0); 5236 calc_csum_metadata_size(inode, num_bytes, 0);
5237 } else { 5237 } else {
5238 u64 orig_csum_bytes = BTRFS_I(inode)->csum_bytes; 5238 u64 orig_csum_bytes = BTRFS_I(inode)->csum_bytes;
5239 u64 bytes; 5239 u64 bytes;
5240 5240
5241 /* 5241 /*
5242 * This is tricky, but first we need to figure out how much we 5242 * This is tricky, but first we need to figure out how much we
5243 * free'd from any free-ers that occured during this 5243 * free'd from any free-ers that occured during this
5244 * reservation, so we reset ->csum_bytes to the csum_bytes 5244 * reservation, so we reset ->csum_bytes to the csum_bytes
5245 * before we dropped our lock, and then call the free for the 5245 * before we dropped our lock, and then call the free for the
5246 * number of bytes that were freed while we were trying our 5246 * number of bytes that were freed while we were trying our
5247 * reservation. 5247 * reservation.
5248 */ 5248 */
5249 bytes = csum_bytes - BTRFS_I(inode)->csum_bytes; 5249 bytes = csum_bytes - BTRFS_I(inode)->csum_bytes;
5250 BTRFS_I(inode)->csum_bytes = csum_bytes; 5250 BTRFS_I(inode)->csum_bytes = csum_bytes;
5251 to_free = calc_csum_metadata_size(inode, bytes, 0); 5251 to_free = calc_csum_metadata_size(inode, bytes, 0);
5252 5252
5253 5253
5254 /* 5254 /*
5255 * Now we need to see how much we would have freed had we not 5255 * Now we need to see how much we would have freed had we not
5256 * been making this reservation and our ->csum_bytes were not 5256 * been making this reservation and our ->csum_bytes were not
5257 * artificially inflated. 5257 * artificially inflated.
5258 */ 5258 */
5259 BTRFS_I(inode)->csum_bytes = csum_bytes - num_bytes; 5259 BTRFS_I(inode)->csum_bytes = csum_bytes - num_bytes;
5260 bytes = csum_bytes - orig_csum_bytes; 5260 bytes = csum_bytes - orig_csum_bytes;
5261 bytes = calc_csum_metadata_size(inode, bytes, 0); 5261 bytes = calc_csum_metadata_size(inode, bytes, 0);
5262 5262
5263 /* 5263 /*
5264 * Now reset ->csum_bytes to what it should be. If bytes is 5264 * Now reset ->csum_bytes to what it should be. If bytes is
5265 * more than to_free then we would have free'd more space had we 5265 * more than to_free then we would have free'd more space had we
5266 * not had an artificially high ->csum_bytes, so we need to free 5266 * not had an artificially high ->csum_bytes, so we need to free
5267 * the remainder. If bytes is the same or less then we don't 5267 * the remainder. If bytes is the same or less then we don't
5268 * need to do anything, the other free-ers did the correct 5268 * need to do anything, the other free-ers did the correct
5269 * thing. 5269 * thing.
5270 */ 5270 */
5271 BTRFS_I(inode)->csum_bytes = orig_csum_bytes - num_bytes; 5271 BTRFS_I(inode)->csum_bytes = orig_csum_bytes - num_bytes;
5272 if (bytes > to_free) 5272 if (bytes > to_free)
5273 to_free = bytes - to_free; 5273 to_free = bytes - to_free;
5274 else 5274 else
5275 to_free = 0; 5275 to_free = 0;
5276 } 5276 }
5277 spin_unlock(&BTRFS_I(inode)->lock); 5277 spin_unlock(&BTRFS_I(inode)->lock);
5278 if (dropped) 5278 if (dropped)
5279 to_free += btrfs_calc_trans_metadata_size(root, dropped); 5279 to_free += btrfs_calc_trans_metadata_size(root, dropped);
5280 5280
5281 if (to_free) { 5281 if (to_free) {
5282 btrfs_block_rsv_release(root, block_rsv, to_free); 5282 btrfs_block_rsv_release(root, block_rsv, to_free);
5283 trace_btrfs_space_reservation(root->fs_info, "delalloc", 5283 trace_btrfs_space_reservation(root->fs_info, "delalloc",
5284 btrfs_ino(inode), to_free, 0); 5284 btrfs_ino(inode), to_free, 0);
5285 } 5285 }
5286 if (delalloc_lock) 5286 if (delalloc_lock)
5287 mutex_unlock(&BTRFS_I(inode)->delalloc_mutex); 5287 mutex_unlock(&BTRFS_I(inode)->delalloc_mutex);
5288 return ret; 5288 return ret;
5289 } 5289 }
5290 5290
5291 /** 5291 /**
5292 * btrfs_delalloc_release_metadata - release a metadata reservation for an inode 5292 * btrfs_delalloc_release_metadata - release a metadata reservation for an inode
5293 * @inode: the inode to release the reservation for 5293 * @inode: the inode to release the reservation for
5294 * @num_bytes: the number of bytes we're releasing 5294 * @num_bytes: the number of bytes we're releasing
5295 * 5295 *
5296 * This will release the metadata reservation for an inode. This can be called 5296 * This will release the metadata reservation for an inode. This can be called
5297 * once we complete IO for a given set of bytes to release their metadata 5297 * once we complete IO for a given set of bytes to release their metadata
5298 * reservations. 5298 * reservations.
5299 */ 5299 */
5300 void btrfs_delalloc_release_metadata(struct inode *inode, u64 num_bytes) 5300 void btrfs_delalloc_release_metadata(struct inode *inode, u64 num_bytes)
5301 { 5301 {
5302 struct btrfs_root *root = BTRFS_I(inode)->root; 5302 struct btrfs_root *root = BTRFS_I(inode)->root;
5303 u64 to_free = 0; 5303 u64 to_free = 0;
5304 unsigned dropped; 5304 unsigned dropped;
5305 5305
5306 num_bytes = ALIGN(num_bytes, root->sectorsize); 5306 num_bytes = ALIGN(num_bytes, root->sectorsize);
5307 spin_lock(&BTRFS_I(inode)->lock); 5307 spin_lock(&BTRFS_I(inode)->lock);
5308 dropped = drop_outstanding_extent(inode); 5308 dropped = drop_outstanding_extent(inode);
5309 5309
5310 if (num_bytes) 5310 if (num_bytes)
5311 to_free = calc_csum_metadata_size(inode, num_bytes, 0); 5311 to_free = calc_csum_metadata_size(inode, num_bytes, 0);
5312 spin_unlock(&BTRFS_I(inode)->lock); 5312 spin_unlock(&BTRFS_I(inode)->lock);
5313 if (dropped > 0) 5313 if (dropped > 0)
5314 to_free += btrfs_calc_trans_metadata_size(root, dropped); 5314 to_free += btrfs_calc_trans_metadata_size(root, dropped);
5315 5315
5316 trace_btrfs_space_reservation(root->fs_info, "delalloc", 5316 trace_btrfs_space_reservation(root->fs_info, "delalloc",
5317 btrfs_ino(inode), to_free, 0); 5317 btrfs_ino(inode), to_free, 0);
5318 if (root->fs_info->quota_enabled) { 5318 if (root->fs_info->quota_enabled) {
5319 btrfs_qgroup_free(root, num_bytes + 5319 btrfs_qgroup_free(root, num_bytes +
5320 dropped * root->nodesize); 5320 dropped * root->nodesize);
5321 } 5321 }
5322 5322
5323 btrfs_block_rsv_release(root, &root->fs_info->delalloc_block_rsv, 5323 btrfs_block_rsv_release(root, &root->fs_info->delalloc_block_rsv,
5324 to_free); 5324 to_free);
5325 } 5325 }
5326 5326
5327 /** 5327 /**
5328 * btrfs_delalloc_reserve_space - reserve data and metadata space for delalloc 5328 * btrfs_delalloc_reserve_space - reserve data and metadata space for delalloc
5329 * @inode: inode we're writing to 5329 * @inode: inode we're writing to
5330 * @num_bytes: the number of bytes we want to allocate 5330 * @num_bytes: the number of bytes we want to allocate
5331 * 5331 *
5332 * This will do the following things 5332 * This will do the following things
5333 * 5333 *
5334 * o reserve space in the data space info for num_bytes 5334 * o reserve space in the data space info for num_bytes
5335 * o reserve space in the metadata space info based on number of outstanding 5335 * o reserve space in the metadata space info based on number of outstanding
5336 * extents and how much csums will be needed 5336 * extents and how much csums will be needed
5337 * o add to the inodes ->delalloc_bytes 5337 * o add to the inodes ->delalloc_bytes
5338 * o add it to the fs_info's delalloc inodes list. 5338 * o add it to the fs_info's delalloc inodes list.
5339 * 5339 *
5340 * This will return 0 for success and -ENOSPC if there is no space left. 5340 * This will return 0 for success and -ENOSPC if there is no space left.
5341 */ 5341 */
5342 int btrfs_delalloc_reserve_space(struct inode *inode, u64 num_bytes) 5342 int btrfs_delalloc_reserve_space(struct inode *inode, u64 num_bytes)
5343 { 5343 {
5344 int ret; 5344 int ret;
5345 5345
5346 ret = btrfs_check_data_free_space(inode, num_bytes); 5346 ret = btrfs_check_data_free_space(inode, num_bytes);
5347 if (ret) 5347 if (ret)
5348 return ret; 5348 return ret;
5349 5349
5350 ret = btrfs_delalloc_reserve_metadata(inode, num_bytes); 5350 ret = btrfs_delalloc_reserve_metadata(inode, num_bytes);
5351 if (ret) { 5351 if (ret) {
5352 btrfs_free_reserved_data_space(inode, num_bytes); 5352 btrfs_free_reserved_data_space(inode, num_bytes);
5353 return ret; 5353 return ret;
5354 } 5354 }
5355 5355
5356 return 0; 5356 return 0;
5357 } 5357 }
5358 5358
5359 /** 5359 /**
5360 * btrfs_delalloc_release_space - release data and metadata space for delalloc 5360 * btrfs_delalloc_release_space - release data and metadata space for delalloc
5361 * @inode: inode we're releasing space for 5361 * @inode: inode we're releasing space for
5362 * @num_bytes: the number of bytes we want to free up 5362 * @num_bytes: the number of bytes we want to free up
5363 * 5363 *
5364 * This must be matched with a call to btrfs_delalloc_reserve_space. This is 5364 * This must be matched with a call to btrfs_delalloc_reserve_space. This is
5365 * called in the case that we don't need the metadata AND data reservations 5365 * called in the case that we don't need the metadata AND data reservations
5366 * anymore. So if there is an error or we insert an inline extent. 5366 * anymore. So if there is an error or we insert an inline extent.
5367 * 5367 *
5368 * This function will release the metadata space that was not used and will 5368 * This function will release the metadata space that was not used and will
5369 * decrement ->delalloc_bytes and remove it from the fs_info delalloc_inodes 5369 * decrement ->delalloc_bytes and remove it from the fs_info delalloc_inodes
5370 * list if there are no delalloc bytes left. 5370 * list if there are no delalloc bytes left.
5371 */ 5371 */
5372 void btrfs_delalloc_release_space(struct inode *inode, u64 num_bytes) 5372 void btrfs_delalloc_release_space(struct inode *inode, u64 num_bytes)
5373 { 5373 {
5374 btrfs_delalloc_release_metadata(inode, num_bytes); 5374 btrfs_delalloc_release_metadata(inode, num_bytes);
5375 btrfs_free_reserved_data_space(inode, num_bytes); 5375 btrfs_free_reserved_data_space(inode, num_bytes);
5376 } 5376 }
5377 5377
5378 static int update_block_group(struct btrfs_root *root, 5378 static int update_block_group(struct btrfs_root *root,
5379 u64 bytenr, u64 num_bytes, int alloc) 5379 u64 bytenr, u64 num_bytes, int alloc)
5380 { 5380 {
5381 struct btrfs_block_group_cache *cache = NULL; 5381 struct btrfs_block_group_cache *cache = NULL;
5382 struct btrfs_fs_info *info = root->fs_info; 5382 struct btrfs_fs_info *info = root->fs_info;
5383 u64 total = num_bytes; 5383 u64 total = num_bytes;
5384 u64 old_val; 5384 u64 old_val;
5385 u64 byte_in_group; 5385 u64 byte_in_group;
5386 int factor; 5386 int factor;
5387 5387
5388 /* block accounting for super block */ 5388 /* block accounting for super block */
5389 spin_lock(&info->delalloc_root_lock); 5389 spin_lock(&info->delalloc_root_lock);
5390 old_val = btrfs_super_bytes_used(info->super_copy); 5390 old_val = btrfs_super_bytes_used(info->super_copy);
5391 if (alloc) 5391 if (alloc)
5392 old_val += num_bytes; 5392 old_val += num_bytes;
5393 else 5393 else
5394 old_val -= num_bytes; 5394 old_val -= num_bytes;
5395 btrfs_set_super_bytes_used(info->super_copy, old_val); 5395 btrfs_set_super_bytes_used(info->super_copy, old_val);
5396 spin_unlock(&info->delalloc_root_lock); 5396 spin_unlock(&info->delalloc_root_lock);
5397 5397
5398 while (total) { 5398 while (total) {
5399 cache = btrfs_lookup_block_group(info, bytenr); 5399 cache = btrfs_lookup_block_group(info, bytenr);
5400 if (!cache) 5400 if (!cache)
5401 return -ENOENT; 5401 return -ENOENT;
5402 if (cache->flags & (BTRFS_BLOCK_GROUP_DUP | 5402 if (cache->flags & (BTRFS_BLOCK_GROUP_DUP |
5403 BTRFS_BLOCK_GROUP_RAID1 | 5403 BTRFS_BLOCK_GROUP_RAID1 |
5404 BTRFS_BLOCK_GROUP_RAID10)) 5404 BTRFS_BLOCK_GROUP_RAID10))
5405 factor = 2; 5405 factor = 2;
5406 else 5406 else
5407 factor = 1; 5407 factor = 1;
5408 /* 5408 /*
5409 * If this block group has free space cache written out, we 5409 * If this block group has free space cache written out, we
5410 * need to make sure to load it if we are removing space. This 5410 * need to make sure to load it if we are removing space. This
5411 * is because we need the unpinning stage to actually add the 5411 * is because we need the unpinning stage to actually add the
5412 * space back to the block group, otherwise we will leak space. 5412 * space back to the block group, otherwise we will leak space.
5413 */ 5413 */
5414 if (!alloc && cache->cached == BTRFS_CACHE_NO) 5414 if (!alloc && cache->cached == BTRFS_CACHE_NO)
5415 cache_block_group(cache, 1); 5415 cache_block_group(cache, 1);
5416 5416
5417 byte_in_group = bytenr - cache->key.objectid; 5417 byte_in_group = bytenr - cache->key.objectid;
5418 WARN_ON(byte_in_group > cache->key.offset); 5418 WARN_ON(byte_in_group > cache->key.offset);
5419 5419
5420 spin_lock(&cache->space_info->lock); 5420 spin_lock(&cache->space_info->lock);
5421 spin_lock(&cache->lock); 5421 spin_lock(&cache->lock);
5422 5422
5423 if (btrfs_test_opt(root, SPACE_CACHE) && 5423 if (btrfs_test_opt(root, SPACE_CACHE) &&
5424 cache->disk_cache_state < BTRFS_DC_CLEAR) 5424 cache->disk_cache_state < BTRFS_DC_CLEAR)
5425 cache->disk_cache_state = BTRFS_DC_CLEAR; 5425 cache->disk_cache_state = BTRFS_DC_CLEAR;
5426 5426
5427 cache->dirty = 1; 5427 cache->dirty = 1;
5428 old_val = btrfs_block_group_used(&cache->item); 5428 old_val = btrfs_block_group_used(&cache->item);
5429 num_bytes = min(total, cache->key.offset - byte_in_group); 5429 num_bytes = min(total, cache->key.offset - byte_in_group);
5430 if (alloc) { 5430 if (alloc) {
5431 old_val += num_bytes; 5431 old_val += num_bytes;
5432 btrfs_set_block_group_used(&cache->item, old_val); 5432 btrfs_set_block_group_used(&cache->item, old_val);
5433 cache->reserved -= num_bytes; 5433 cache->reserved -= num_bytes;
5434 cache->space_info->bytes_reserved -= num_bytes; 5434 cache->space_info->bytes_reserved -= num_bytes;
5435 cache->space_info->bytes_used += num_bytes; 5435 cache->space_info->bytes_used += num_bytes;
5436 cache->space_info->disk_used += num_bytes * factor; 5436 cache->space_info->disk_used += num_bytes * factor;
5437 spin_unlock(&cache->lock); 5437 spin_unlock(&cache->lock);
5438 spin_unlock(&cache->space_info->lock); 5438 spin_unlock(&cache->space_info->lock);
5439 } else { 5439 } else {
5440 old_val -= num_bytes; 5440 old_val -= num_bytes;
5441 btrfs_set_block_group_used(&cache->item, old_val); 5441 btrfs_set_block_group_used(&cache->item, old_val);
5442 cache->pinned += num_bytes; 5442 cache->pinned += num_bytes;
5443 cache->space_info->bytes_pinned += num_bytes; 5443 cache->space_info->bytes_pinned += num_bytes;
5444 cache->space_info->bytes_used -= num_bytes; 5444 cache->space_info->bytes_used -= num_bytes;
5445 cache->space_info->disk_used -= num_bytes * factor; 5445 cache->space_info->disk_used -= num_bytes * factor;
5446 spin_unlock(&cache->lock); 5446 spin_unlock(&cache->lock);
5447 spin_unlock(&cache->space_info->lock); 5447 spin_unlock(&cache->space_info->lock);
5448 5448
5449 set_extent_dirty(info->pinned_extents, 5449 set_extent_dirty(info->pinned_extents,
5450 bytenr, bytenr + num_bytes - 1, 5450 bytenr, bytenr + num_bytes - 1,
5451 GFP_NOFS | __GFP_NOFAIL); 5451 GFP_NOFS | __GFP_NOFAIL);
5452 /* 5452 /*
5453 * No longer have used bytes in this block group, queue 5453 * No longer have used bytes in this block group, queue
5454 * it for deletion. 5454 * it for deletion.
5455 */ 5455 */
5456 if (old_val == 0) { 5456 if (old_val == 0) {
5457 spin_lock(&info->unused_bgs_lock); 5457 spin_lock(&info->unused_bgs_lock);
5458 if (list_empty(&cache->bg_list)) { 5458 if (list_empty(&cache->bg_list)) {
5459 btrfs_get_block_group(cache); 5459 btrfs_get_block_group(cache);
5460 list_add_tail(&cache->bg_list, 5460 list_add_tail(&cache->bg_list,
5461 &info->unused_bgs); 5461 &info->unused_bgs);
5462 } 5462 }
5463 spin_unlock(&info->unused_bgs_lock); 5463 spin_unlock(&info->unused_bgs_lock);
5464 } 5464 }
5465 } 5465 }
5466 btrfs_put_block_group(cache); 5466 btrfs_put_block_group(cache);
5467 total -= num_bytes; 5467 total -= num_bytes;
5468 bytenr += num_bytes; 5468 bytenr += num_bytes;
5469 } 5469 }
5470 return 0; 5470 return 0;
5471 } 5471 }
5472 5472
5473 static u64 first_logical_byte(struct btrfs_root *root, u64 search_start) 5473 static u64 first_logical_byte(struct btrfs_root *root, u64 search_start)
5474 { 5474 {
5475 struct btrfs_block_group_cache *cache; 5475 struct btrfs_block_group_cache *cache;
5476 u64 bytenr; 5476 u64 bytenr;
5477 5477
5478 spin_lock(&root->fs_info->block_group_cache_lock); 5478 spin_lock(&root->fs_info->block_group_cache_lock);
5479 bytenr = root->fs_info->first_logical_byte; 5479 bytenr = root->fs_info->first_logical_byte;
5480 spin_unlock(&root->fs_info->block_group_cache_lock); 5480 spin_unlock(&root->fs_info->block_group_cache_lock);
5481 5481
5482 if (bytenr < (u64)-1) 5482 if (bytenr < (u64)-1)
5483 return bytenr; 5483 return bytenr;
5484 5484
5485 cache = btrfs_lookup_first_block_group(root->fs_info, search_start); 5485 cache = btrfs_lookup_first_block_group(root->fs_info, search_start);
5486 if (!cache) 5486 if (!cache)
5487 return 0; 5487 return 0;
5488 5488
5489 bytenr = cache->key.objectid; 5489 bytenr = cache->key.objectid;
5490 btrfs_put_block_group(cache); 5490 btrfs_put_block_group(cache);
5491 5491
5492 return bytenr; 5492 return bytenr;
5493 } 5493 }
5494 5494
5495 static int pin_down_extent(struct btrfs_root *root, 5495 static int pin_down_extent(struct btrfs_root *root,
5496 struct btrfs_block_group_cache *cache, 5496 struct btrfs_block_group_cache *cache,
5497 u64 bytenr, u64 num_bytes, int reserved) 5497 u64 bytenr, u64 num_bytes, int reserved)
5498 { 5498 {
5499 spin_lock(&cache->space_info->lock); 5499 spin_lock(&cache->space_info->lock);
5500 spin_lock(&cache->lock); 5500 spin_lock(&cache->lock);
5501 cache->pinned += num_bytes; 5501 cache->pinned += num_bytes;
5502 cache->space_info->bytes_pinned += num_bytes; 5502 cache->space_info->bytes_pinned += num_bytes;
5503 if (reserved) { 5503 if (reserved) {
5504 cache->reserved -= num_bytes; 5504 cache->reserved -= num_bytes;
5505 cache->space_info->bytes_reserved -= num_bytes; 5505 cache->space_info->bytes_reserved -= num_bytes;
5506 } 5506 }
5507 spin_unlock(&cache->lock); 5507 spin_unlock(&cache->lock);
5508 spin_unlock(&cache->space_info->lock); 5508 spin_unlock(&cache->space_info->lock);
5509 5509
5510 set_extent_dirty(root->fs_info->pinned_extents, bytenr, 5510 set_extent_dirty(root->fs_info->pinned_extents, bytenr,
5511 bytenr + num_bytes - 1, GFP_NOFS | __GFP_NOFAIL); 5511 bytenr + num_bytes - 1, GFP_NOFS | __GFP_NOFAIL);
5512 if (reserved) 5512 if (reserved)
5513 trace_btrfs_reserved_extent_free(root, bytenr, num_bytes); 5513 trace_btrfs_reserved_extent_free(root, bytenr, num_bytes);
5514 return 0; 5514 return 0;
5515 } 5515 }
5516 5516
5517 /* 5517 /*
5518 * this function must be called within transaction 5518 * this function must be called within transaction
5519 */ 5519 */
5520 int btrfs_pin_extent(struct btrfs_root *root, 5520 int btrfs_pin_extent(struct btrfs_root *root,
5521 u64 bytenr, u64 num_bytes, int reserved) 5521 u64 bytenr, u64 num_bytes, int reserved)
5522 { 5522 {
5523 struct btrfs_block_group_cache *cache; 5523 struct btrfs_block_group_cache *cache;
5524 5524
5525 cache = btrfs_lookup_block_group(root->fs_info, bytenr); 5525 cache = btrfs_lookup_block_group(root->fs_info, bytenr);
5526 BUG_ON(!cache); /* Logic error */ 5526 BUG_ON(!cache); /* Logic error */
5527 5527
5528 pin_down_extent(root, cache, bytenr, num_bytes, reserved); 5528 pin_down_extent(root, cache, bytenr, num_bytes, reserved);
5529 5529
5530 btrfs_put_block_group(cache); 5530 btrfs_put_block_group(cache);
5531 return 0; 5531 return 0;
5532 } 5532 }
5533 5533
5534 /* 5534 /*
5535 * this function must be called within transaction 5535 * this function must be called within transaction
5536 */ 5536 */
5537 int btrfs_pin_extent_for_log_replay(struct btrfs_root *root, 5537 int btrfs_pin_extent_for_log_replay(struct btrfs_root *root,
5538 u64 bytenr, u64 num_bytes) 5538 u64 bytenr, u64 num_bytes)
5539 { 5539 {
5540 struct btrfs_block_group_cache *cache; 5540 struct btrfs_block_group_cache *cache;
5541 int ret; 5541 int ret;
5542 5542
5543 cache = btrfs_lookup_block_group(root->fs_info, bytenr); 5543 cache = btrfs_lookup_block_group(root->fs_info, bytenr);
5544 if (!cache) 5544 if (!cache)
5545 return -EINVAL; 5545 return -EINVAL;
5546 5546
5547 /* 5547 /*
5548 * pull in the free space cache (if any) so that our pin 5548 * pull in the free space cache (if any) so that our pin
5549 * removes the free space from the cache. We have load_only set 5549 * removes the free space from the cache. We have load_only set
5550 * to one because the slow code to read in the free extents does check 5550 * to one because the slow code to read in the free extents does check
5551 * the pinned extents. 5551 * the pinned extents.
5552 */ 5552 */
5553 cache_block_group(cache, 1); 5553 cache_block_group(cache, 1);
5554 5554
5555 pin_down_extent(root, cache, bytenr, num_bytes, 0); 5555 pin_down_extent(root, cache, bytenr, num_bytes, 0);
5556 5556
5557 /* remove us from the free space cache (if we're there at all) */ 5557 /* remove us from the free space cache (if we're there at all) */
5558 ret = btrfs_remove_free_space(cache, bytenr, num_bytes); 5558 ret = btrfs_remove_free_space(cache, bytenr, num_bytes);
5559 btrfs_put_block_group(cache); 5559 btrfs_put_block_group(cache);
5560 return ret; 5560 return ret;
5561 } 5561 }
5562 5562
5563 static int __exclude_logged_extent(struct btrfs_root *root, u64 start, u64 num_bytes) 5563 static int __exclude_logged_extent(struct btrfs_root *root, u64 start, u64 num_bytes)
5564 { 5564 {
5565 int ret; 5565 int ret;
5566 struct btrfs_block_group_cache *block_group; 5566 struct btrfs_block_group_cache *block_group;
5567 struct btrfs_caching_control *caching_ctl; 5567 struct btrfs_caching_control *caching_ctl;
5568 5568
5569 block_group = btrfs_lookup_block_group(root->fs_info, start); 5569 block_group = btrfs_lookup_block_group(root->fs_info, start);
5570 if (!block_group) 5570 if (!block_group)
5571 return -EINVAL; 5571 return -EINVAL;
5572 5572
5573 cache_block_group(block_group, 0); 5573 cache_block_group(block_group, 0);
5574 caching_ctl = get_caching_control(block_group); 5574 caching_ctl = get_caching_control(block_group);
5575 5575
5576 if (!caching_ctl) { 5576 if (!caching_ctl) {
5577 /* Logic error */ 5577 /* Logic error */
5578 BUG_ON(!block_group_cache_done(block_group)); 5578 BUG_ON(!block_group_cache_done(block_group));
5579 ret = btrfs_remove_free_space(block_group, start, num_bytes); 5579 ret = btrfs_remove_free_space(block_group, start, num_bytes);
5580 } else { 5580 } else {
5581 mutex_lock(&caching_ctl->mutex); 5581 mutex_lock(&caching_ctl->mutex);
5582 5582
5583 if (start >= caching_ctl->progress) { 5583 if (start >= caching_ctl->progress) {
5584 ret = add_excluded_extent(root, start, num_bytes); 5584 ret = add_excluded_extent(root, start, num_bytes);
5585 } else if (start + num_bytes <= caching_ctl->progress) { 5585 } else if (start + num_bytes <= caching_ctl->progress) {
5586 ret = btrfs_remove_free_space(block_group, 5586 ret = btrfs_remove_free_space(block_group,
5587 start, num_bytes); 5587 start, num_bytes);
5588 } else { 5588 } else {
5589 num_bytes = caching_ctl->progress - start; 5589 num_bytes = caching_ctl->progress - start;
5590 ret = btrfs_remove_free_space(block_group, 5590 ret = btrfs_remove_free_space(block_group,
5591 start, num_bytes); 5591 start, num_bytes);
5592 if (ret) 5592 if (ret)
5593 goto out_lock; 5593 goto out_lock;
5594 5594
5595 num_bytes = (start + num_bytes) - 5595 num_bytes = (start + num_bytes) -
5596 caching_ctl->progress; 5596 caching_ctl->progress;
5597 start = caching_ctl->progress; 5597 start = caching_ctl->progress;
5598 ret = add_excluded_extent(root, start, num_bytes); 5598 ret = add_excluded_extent(root, start, num_bytes);
5599 } 5599 }
5600 out_lock: 5600 out_lock:
5601 mutex_unlock(&caching_ctl->mutex); 5601 mutex_unlock(&caching_ctl->mutex);
5602 put_caching_control(caching_ctl); 5602 put_caching_control(caching_ctl);
5603 } 5603 }
5604 btrfs_put_block_group(block_group); 5604 btrfs_put_block_group(block_group);
5605 return ret; 5605 return ret;
5606 } 5606 }
5607 5607
5608 int btrfs_exclude_logged_extents(struct btrfs_root *log, 5608 int btrfs_exclude_logged_extents(struct btrfs_root *log,
5609 struct extent_buffer *eb) 5609 struct extent_buffer *eb)
5610 { 5610 {
5611 struct btrfs_file_extent_item *item; 5611 struct btrfs_file_extent_item *item;
5612 struct btrfs_key key; 5612 struct btrfs_key key;
5613 int found_type; 5613 int found_type;
5614 int i; 5614 int i;
5615 5615
5616 if (!btrfs_fs_incompat(log->fs_info, MIXED_GROUPS)) 5616 if (!btrfs_fs_incompat(log->fs_info, MIXED_GROUPS))
5617 return 0; 5617 return 0;
5618 5618
5619 for (i = 0; i < btrfs_header_nritems(eb); i++) { 5619 for (i = 0; i < btrfs_header_nritems(eb); i++) {
5620 btrfs_item_key_to_cpu(eb, &key, i); 5620 btrfs_item_key_to_cpu(eb, &key, i);
5621 if (key.type != BTRFS_EXTENT_DATA_KEY) 5621 if (key.type != BTRFS_EXTENT_DATA_KEY)
5622 continue; 5622 continue;
5623 item = btrfs_item_ptr(eb, i, struct btrfs_file_extent_item); 5623 item = btrfs_item_ptr(eb, i, struct btrfs_file_extent_item);
5624 found_type = btrfs_file_extent_type(eb, item); 5624 found_type = btrfs_file_extent_type(eb, item);
5625 if (found_type == BTRFS_FILE_EXTENT_INLINE) 5625 if (found_type == BTRFS_FILE_EXTENT_INLINE)
5626 continue; 5626 continue;
5627 if (btrfs_file_extent_disk_bytenr(eb, item) == 0) 5627 if (btrfs_file_extent_disk_bytenr(eb, item) == 0)
5628 continue; 5628 continue;
5629 key.objectid = btrfs_file_extent_disk_bytenr(eb, item); 5629 key.objectid = btrfs_file_extent_disk_bytenr(eb, item);
5630 key.offset = btrfs_file_extent_disk_num_bytes(eb, item); 5630 key.offset = btrfs_file_extent_disk_num_bytes(eb, item);
5631 __exclude_logged_extent(log, key.objectid, key.offset); 5631 __exclude_logged_extent(log, key.objectid, key.offset);
5632 } 5632 }
5633 5633
5634 return 0; 5634 return 0;
5635 } 5635 }
5636 5636
5637 /** 5637 /**
5638 * btrfs_update_reserved_bytes - update the block_group and space info counters 5638 * btrfs_update_reserved_bytes - update the block_group and space info counters
5639 * @cache: The cache we are manipulating 5639 * @cache: The cache we are manipulating
5640 * @num_bytes: The number of bytes in question 5640 * @num_bytes: The number of bytes in question
5641 * @reserve: One of the reservation enums 5641 * @reserve: One of the reservation enums
5642 * @delalloc: The blocks are allocated for the delalloc write 5642 * @delalloc: The blocks are allocated for the delalloc write
5643 * 5643 *
5644 * This is called by the allocator when it reserves space, or by somebody who is 5644 * This is called by the allocator when it reserves space, or by somebody who is
5645 * freeing space that was never actually used on disk. For example if you 5645 * freeing space that was never actually used on disk. For example if you
5646 * reserve some space for a new leaf in transaction A and before transaction A 5646 * reserve some space for a new leaf in transaction A and before transaction A
5647 * commits you free that leaf, you call this with reserve set to 0 in order to 5647 * commits you free that leaf, you call this with reserve set to 0 in order to
5648 * clear the reservation. 5648 * clear the reservation.
5649 * 5649 *
5650 * Metadata reservations should be called with RESERVE_ALLOC so we do the proper 5650 * Metadata reservations should be called with RESERVE_ALLOC so we do the proper
5651 * ENOSPC accounting. For data we handle the reservation through clearing the 5651 * ENOSPC accounting. For data we handle the reservation through clearing the
5652 * delalloc bits in the io_tree. We have to do this since we could end up 5652 * delalloc bits in the io_tree. We have to do this since we could end up
5653 * allocating less disk space for the amount of data we have reserved in the 5653 * allocating less disk space for the amount of data we have reserved in the
5654 * case of compression. 5654 * case of compression.
5655 * 5655 *
5656 * If this is a reservation and the block group has become read only we cannot 5656 * If this is a reservation and the block group has become read only we cannot
5657 * make the reservation and return -EAGAIN, otherwise this function always 5657 * make the reservation and return -EAGAIN, otherwise this function always
5658 * succeeds. 5658 * succeeds.
5659 */ 5659 */
5660 static int btrfs_update_reserved_bytes(struct btrfs_block_group_cache *cache, 5660 static int btrfs_update_reserved_bytes(struct btrfs_block_group_cache *cache,
5661 u64 num_bytes, int reserve, int delalloc) 5661 u64 num_bytes, int reserve, int delalloc)
5662 { 5662 {
5663 struct btrfs_space_info *space_info = cache->space_info; 5663 struct btrfs_space_info *space_info = cache->space_info;
5664 int ret = 0; 5664 int ret = 0;
5665 5665
5666 spin_lock(&space_info->lock); 5666 spin_lock(&space_info->lock);
5667 spin_lock(&cache->lock); 5667 spin_lock(&cache->lock);
5668 if (reserve != RESERVE_FREE) { 5668 if (reserve != RESERVE_FREE) {
5669 if (cache->ro) { 5669 if (cache->ro) {
5670 ret = -EAGAIN; 5670 ret = -EAGAIN;
5671 } else { 5671 } else {
5672 cache->reserved += num_bytes; 5672 cache->reserved += num_bytes;
5673 space_info->bytes_reserved += num_bytes; 5673 space_info->bytes_reserved += num_bytes;
5674 if (reserve == RESERVE_ALLOC) { 5674 if (reserve == RESERVE_ALLOC) {
5675 trace_btrfs_space_reservation(cache->fs_info, 5675 trace_btrfs_space_reservation(cache->fs_info,
5676 "space_info", space_info->flags, 5676 "space_info", space_info->flags,
5677 num_bytes, 0); 5677 num_bytes, 0);
5678 space_info->bytes_may_use -= num_bytes; 5678 space_info->bytes_may_use -= num_bytes;
5679 } 5679 }
5680 5680
5681 if (delalloc) 5681 if (delalloc)
5682 cache->delalloc_bytes += num_bytes; 5682 cache->delalloc_bytes += num_bytes;
5683 } 5683 }
5684 } else { 5684 } else {
5685 if (cache->ro) 5685 if (cache->ro)
5686 space_info->bytes_readonly += num_bytes; 5686 space_info->bytes_readonly += num_bytes;
5687 cache->reserved -= num_bytes; 5687 cache->reserved -= num_bytes;
5688 space_info->bytes_reserved -= num_bytes; 5688 space_info->bytes_reserved -= num_bytes;
5689 5689
5690 if (delalloc) 5690 if (delalloc)
5691 cache->delalloc_bytes -= num_bytes; 5691 cache->delalloc_bytes -= num_bytes;
5692 } 5692 }
5693 spin_unlock(&cache->lock); 5693 spin_unlock(&cache->lock);
5694 spin_unlock(&space_info->lock); 5694 spin_unlock(&space_info->lock);
5695 return ret; 5695 return ret;
5696 } 5696 }
5697 5697
5698 void btrfs_prepare_extent_commit(struct btrfs_trans_handle *trans, 5698 void btrfs_prepare_extent_commit(struct btrfs_trans_handle *trans,
5699 struct btrfs_root *root) 5699 struct btrfs_root *root)
5700 { 5700 {
5701 struct btrfs_fs_info *fs_info = root->fs_info; 5701 struct btrfs_fs_info *fs_info = root->fs_info;
5702 struct btrfs_caching_control *next; 5702 struct btrfs_caching_control *next;
5703 struct btrfs_caching_control *caching_ctl; 5703 struct btrfs_caching_control *caching_ctl;
5704 struct btrfs_block_group_cache *cache; 5704 struct btrfs_block_group_cache *cache;
5705 5705
5706 down_write(&fs_info->commit_root_sem); 5706 down_write(&fs_info->commit_root_sem);
5707 5707
5708 list_for_each_entry_safe(caching_ctl, next, 5708 list_for_each_entry_safe(caching_ctl, next,
5709 &fs_info->caching_block_groups, list) { 5709 &fs_info->caching_block_groups, list) {
5710 cache = caching_ctl->block_group; 5710 cache = caching_ctl->block_group;
5711 if (block_group_cache_done(cache)) { 5711 if (block_group_cache_done(cache)) {
5712 cache->last_byte_to_unpin = (u64)-1; 5712 cache->last_byte_to_unpin = (u64)-1;
5713 list_del_init(&caching_ctl->list); 5713 list_del_init(&caching_ctl->list);
5714 put_caching_control(caching_ctl); 5714 put_caching_control(caching_ctl);
5715 } else { 5715 } else {
5716 cache->last_byte_to_unpin = caching_ctl->progress; 5716 cache->last_byte_to_unpin = caching_ctl->progress;
5717 } 5717 }
5718 } 5718 }
5719 5719
5720 if (fs_info->pinned_extents == &fs_info->freed_extents[0]) 5720 if (fs_info->pinned_extents == &fs_info->freed_extents[0])
5721 fs_info->pinned_extents = &fs_info->freed_extents[1]; 5721 fs_info->pinned_extents = &fs_info->freed_extents[1];
5722 else 5722 else
5723 fs_info->pinned_extents = &fs_info->freed_extents[0]; 5723 fs_info->pinned_extents = &fs_info->freed_extents[0];
5724 5724
5725 up_write(&fs_info->commit_root_sem); 5725 up_write(&fs_info->commit_root_sem);
5726 5726
5727 update_global_block_rsv(fs_info); 5727 update_global_block_rsv(fs_info);
5728 } 5728 }
5729 5729
5730 static int unpin_extent_range(struct btrfs_root *root, u64 start, u64 end, 5730 static int unpin_extent_range(struct btrfs_root *root, u64 start, u64 end,
5731 const bool return_free_space) 5731 const bool return_free_space)
5732 { 5732 {
5733 struct btrfs_fs_info *fs_info = root->fs_info; 5733 struct btrfs_fs_info *fs_info = root->fs_info;
5734 struct btrfs_block_group_cache *cache = NULL; 5734 struct btrfs_block_group_cache *cache = NULL;
5735 struct btrfs_space_info *space_info; 5735 struct btrfs_space_info *space_info;
5736 struct btrfs_block_rsv *global_rsv = &fs_info->global_block_rsv; 5736 struct btrfs_block_rsv *global_rsv = &fs_info->global_block_rsv;
5737 u64 len; 5737 u64 len;
5738 bool readonly; 5738 bool readonly;
5739 5739
5740 while (start <= end) { 5740 while (start <= end) {
5741 readonly = false; 5741 readonly = false;
5742 if (!cache || 5742 if (!cache ||
5743 start >= cache->key.objectid + cache->key.offset) { 5743 start >= cache->key.objectid + cache->key.offset) {
5744 if (cache) 5744 if (cache)
5745 btrfs_put_block_group(cache); 5745 btrfs_put_block_group(cache);
5746 cache = btrfs_lookup_block_group(fs_info, start); 5746 cache = btrfs_lookup_block_group(fs_info, start);
5747 BUG_ON(!cache); /* Logic error */ 5747 BUG_ON(!cache); /* Logic error */
5748 } 5748 }
5749 5749
5750 len = cache->key.objectid + cache->key.offset - start; 5750 len = cache->key.objectid + cache->key.offset - start;
5751 len = min(len, end + 1 - start); 5751 len = min(len, end + 1 - start);
5752 5752
5753 if (start < cache->last_byte_to_unpin) { 5753 if (start < cache->last_byte_to_unpin) {
5754 len = min(len, cache->last_byte_to_unpin - start); 5754 len = min(len, cache->last_byte_to_unpin - start);
5755 if (return_free_space) 5755 if (return_free_space)
5756 btrfs_add_free_space(cache, start, len); 5756 btrfs_add_free_space(cache, start, len);
5757 } 5757 }
5758 5758
5759 start += len; 5759 start += len;
5760 space_info = cache->space_info; 5760 space_info = cache->space_info;
5761 5761
5762 spin_lock(&space_info->lock); 5762 spin_lock(&space_info->lock);
5763 spin_lock(&cache->lock); 5763 spin_lock(&cache->lock);
5764 cache->pinned -= len; 5764 cache->pinned -= len;
5765 space_info->bytes_pinned -= len; 5765 space_info->bytes_pinned -= len;
5766 percpu_counter_add(&space_info->total_bytes_pinned, -len); 5766 percpu_counter_add(&space_info->total_bytes_pinned, -len);
5767 if (cache->ro) { 5767 if (cache->ro) {
5768 space_info->bytes_readonly += len; 5768 space_info->bytes_readonly += len;
5769 readonly = true; 5769 readonly = true;
5770 } 5770 }
5771 spin_unlock(&cache->lock); 5771 spin_unlock(&cache->lock);
5772 if (!readonly && global_rsv->space_info == space_info) { 5772 if (!readonly && global_rsv->space_info == space_info) {
5773 spin_lock(&global_rsv->lock); 5773 spin_lock(&global_rsv->lock);
5774 if (!global_rsv->full) { 5774 if (!global_rsv->full) {
5775 len = min(len, global_rsv->size - 5775 len = min(len, global_rsv->size -
5776 global_rsv->reserved); 5776 global_rsv->reserved);
5777 global_rsv->reserved += len; 5777 global_rsv->reserved += len;
5778 space_info->bytes_may_use += len; 5778 space_info->bytes_may_use += len;
5779 if (global_rsv->reserved >= global_rsv->size) 5779 if (global_rsv->reserved >= global_rsv->size)
5780 global_rsv->full = 1; 5780 global_rsv->full = 1;
5781 } 5781 }
5782 spin_unlock(&global_rsv->lock); 5782 spin_unlock(&global_rsv->lock);
5783 } 5783 }
5784 spin_unlock(&space_info->lock); 5784 spin_unlock(&space_info->lock);
5785 } 5785 }
5786 5786
5787 if (cache) 5787 if (cache)
5788 btrfs_put_block_group(cache); 5788 btrfs_put_block_group(cache);
5789 return 0; 5789 return 0;
5790 } 5790 }
5791 5791
5792 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, 5792 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
5793 struct btrfs_root *root) 5793 struct btrfs_root *root)
5794 { 5794 {
5795 struct btrfs_fs_info *fs_info = root->fs_info; 5795 struct btrfs_fs_info *fs_info = root->fs_info;
5796 struct extent_io_tree *unpin; 5796 struct extent_io_tree *unpin;
5797 u64 start; 5797 u64 start;
5798 u64 end; 5798 u64 end;
5799 int ret; 5799 int ret;
5800 5800
5801 if (trans->aborted) 5801 if (trans->aborted)
5802 return 0; 5802 return 0;
5803 5803
5804 if (fs_info->pinned_extents == &fs_info->freed_extents[0]) 5804 if (fs_info->pinned_extents == &fs_info->freed_extents[0])
5805 unpin = &fs_info->freed_extents[1]; 5805 unpin = &fs_info->freed_extents[1];
5806 else 5806 else
5807 unpin = &fs_info->freed_extents[0]; 5807 unpin = &fs_info->freed_extents[0];
5808 5808
5809 while (1) { 5809 while (1) {
5810 ret = find_first_extent_bit(unpin, 0, &start, &end, 5810 ret = find_first_extent_bit(unpin, 0, &start, &end,
5811 EXTENT_DIRTY, NULL); 5811 EXTENT_DIRTY, NULL);
5812 if (ret) 5812 if (ret)
5813 break; 5813 break;
5814 5814
5815 if (btrfs_test_opt(root, DISCARD)) 5815 if (btrfs_test_opt(root, DISCARD))
5816 ret = btrfs_discard_extent(root, start, 5816 ret = btrfs_discard_extent(root, start,
5817 end + 1 - start, NULL); 5817 end + 1 - start, NULL);
5818 5818
5819 clear_extent_dirty(unpin, start, end, GFP_NOFS); 5819 clear_extent_dirty(unpin, start, end, GFP_NOFS);
5820 unpin_extent_range(root, start, end, true); 5820 unpin_extent_range(root, start, end, true);
5821 cond_resched(); 5821 cond_resched();
5822 } 5822 }
5823 5823
5824 return 0; 5824 return 0;
5825 } 5825 }
5826 5826
5827 static void add_pinned_bytes(struct btrfs_fs_info *fs_info, u64 num_bytes, 5827 static void add_pinned_bytes(struct btrfs_fs_info *fs_info, u64 num_bytes,
5828 u64 owner, u64 root_objectid) 5828 u64 owner, u64 root_objectid)
5829 { 5829 {
5830 struct btrfs_space_info *space_info; 5830 struct btrfs_space_info *space_info;
5831 u64 flags; 5831 u64 flags;
5832 5832
5833 if (owner < BTRFS_FIRST_FREE_OBJECTID) { 5833 if (owner < BTRFS_FIRST_FREE_OBJECTID) {
5834 if (root_objectid == BTRFS_CHUNK_TREE_OBJECTID) 5834 if (root_objectid == BTRFS_CHUNK_TREE_OBJECTID)
5835 flags = BTRFS_BLOCK_GROUP_SYSTEM; 5835 flags = BTRFS_BLOCK_GROUP_SYSTEM;
5836 else 5836 else
5837 flags = BTRFS_BLOCK_GROUP_METADATA; 5837 flags = BTRFS_BLOCK_GROUP_METADATA;
5838 } else { 5838 } else {
5839 flags = BTRFS_BLOCK_GROUP_DATA; 5839 flags = BTRFS_BLOCK_GROUP_DATA;
5840 } 5840 }
5841 5841
5842 space_info = __find_space_info(fs_info, flags); 5842 space_info = __find_space_info(fs_info, flags);
5843 BUG_ON(!space_info); /* Logic bug */ 5843 BUG_ON(!space_info); /* Logic bug */
5844 percpu_counter_add(&space_info->total_bytes_pinned, num_bytes); 5844 percpu_counter_add(&space_info->total_bytes_pinned, num_bytes);
5845 } 5845 }
5846 5846
5847 5847
5848 static int __btrfs_free_extent(struct btrfs_trans_handle *trans, 5848 static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
5849 struct btrfs_root *root, 5849 struct btrfs_root *root,
5850 u64 bytenr, u64 num_bytes, u64 parent, 5850 u64 bytenr, u64 num_bytes, u64 parent,
5851 u64 root_objectid, u64 owner_objectid, 5851 u64 root_objectid, u64 owner_objectid,
5852 u64 owner_offset, int refs_to_drop, 5852 u64 owner_offset, int refs_to_drop,
5853 struct btrfs_delayed_extent_op *extent_op, 5853 struct btrfs_delayed_extent_op *extent_op,
5854 int no_quota) 5854 int no_quota)
5855 { 5855 {
5856 struct btrfs_key key; 5856 struct btrfs_key key;
5857 struct btrfs_path *path; 5857 struct btrfs_path *path;
5858 struct btrfs_fs_info *info = root->fs_info; 5858 struct btrfs_fs_info *info = root->fs_info;
5859 struct btrfs_root *extent_root = info->extent_root; 5859 struct btrfs_root *extent_root = info->extent_root;
5860 struct extent_buffer *leaf; 5860 struct extent_buffer *leaf;
5861 struct btrfs_extent_item *ei; 5861 struct btrfs_extent_item *ei;
5862 struct btrfs_extent_inline_ref *iref; 5862 struct btrfs_extent_inline_ref *iref;
5863 int ret; 5863 int ret;
5864 int is_data; 5864 int is_data;
5865 int extent_slot = 0; 5865 int extent_slot = 0;
5866 int found_extent = 0; 5866 int found_extent = 0;
5867 int num_to_del = 1; 5867 int num_to_del = 1;
5868 u32 item_size; 5868 u32 item_size;
5869 u64 refs; 5869 u64 refs;
5870 int last_ref = 0; 5870 int last_ref = 0;
5871 enum btrfs_qgroup_operation_type type = BTRFS_QGROUP_OPER_SUB_EXCL; 5871 enum btrfs_qgroup_operation_type type = BTRFS_QGROUP_OPER_SUB_EXCL;
5872 bool skinny_metadata = btrfs_fs_incompat(root->fs_info, 5872 bool skinny_metadata = btrfs_fs_incompat(root->fs_info,
5873 SKINNY_METADATA); 5873 SKINNY_METADATA);
5874 5874
5875 if (!info->quota_enabled || !is_fstree(root_objectid)) 5875 if (!info->quota_enabled || !is_fstree(root_objectid))
5876 no_quota = 1; 5876 no_quota = 1;
5877 5877
5878 path = btrfs_alloc_path(); 5878 path = btrfs_alloc_path();
5879 if (!path) 5879 if (!path)
5880 return -ENOMEM; 5880 return -ENOMEM;
5881 5881
5882 path->reada = 1; 5882 path->reada = 1;
5883 path->leave_spinning = 1; 5883 path->leave_spinning = 1;
5884 5884
5885 is_data = owner_objectid >= BTRFS_FIRST_FREE_OBJECTID; 5885 is_data = owner_objectid >= BTRFS_FIRST_FREE_OBJECTID;
5886 BUG_ON(!is_data && refs_to_drop != 1); 5886 BUG_ON(!is_data && refs_to_drop != 1);
5887 5887
5888 if (is_data) 5888 if (is_data)
5889 skinny_metadata = 0; 5889 skinny_metadata = 0;
5890 5890
5891 ret = lookup_extent_backref(trans, extent_root, path, &iref, 5891 ret = lookup_extent_backref(trans, extent_root, path, &iref,
5892 bytenr, num_bytes, parent, 5892 bytenr, num_bytes, parent,
5893 root_objectid, owner_objectid, 5893 root_objectid, owner_objectid,
5894 owner_offset); 5894 owner_offset);
5895 if (ret == 0) { 5895 if (ret == 0) {
5896 extent_slot = path->slots[0]; 5896 extent_slot = path->slots[0];
5897 while (extent_slot >= 0) { 5897 while (extent_slot >= 0) {
5898 btrfs_item_key_to_cpu(path->nodes[0], &key, 5898 btrfs_item_key_to_cpu(path->nodes[0], &key,
5899 extent_slot); 5899 extent_slot);
5900 if (key.objectid != bytenr) 5900 if (key.objectid != bytenr)
5901 break; 5901 break;
5902 if (key.type == BTRFS_EXTENT_ITEM_KEY && 5902 if (key.type == BTRFS_EXTENT_ITEM_KEY &&
5903 key.offset == num_bytes) { 5903 key.offset == num_bytes) {
5904 found_extent = 1; 5904 found_extent = 1;
5905 break; 5905 break;
5906 } 5906 }
5907 if (key.type == BTRFS_METADATA_ITEM_KEY && 5907 if (key.type == BTRFS_METADATA_ITEM_KEY &&
5908 key.offset == owner_objectid) { 5908 key.offset == owner_objectid) {
5909 found_extent = 1; 5909 found_extent = 1;
5910 break; 5910 break;
5911 } 5911 }
5912 if (path->slots[0] - extent_slot > 5) 5912 if (path->slots[0] - extent_slot > 5)
5913 break; 5913 break;
5914 extent_slot--; 5914 extent_slot--;
5915 } 5915 }
5916 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0 5916 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
5917 item_size = btrfs_item_size_nr(path->nodes[0], extent_slot); 5917 item_size = btrfs_item_size_nr(path->nodes[0], extent_slot);
5918 if (found_extent && item_size < sizeof(*ei)) 5918 if (found_extent && item_size < sizeof(*ei))
5919 found_extent = 0; 5919 found_extent = 0;
5920 #endif 5920 #endif
5921 if (!found_extent) { 5921 if (!found_extent) {
5922 BUG_ON(iref); 5922 BUG_ON(iref);
5923 ret = remove_extent_backref(trans, extent_root, path, 5923 ret = remove_extent_backref(trans, extent_root, path,
5924 NULL, refs_to_drop, 5924 NULL, refs_to_drop,
5925 is_data, &last_ref); 5925 is_data, &last_ref);
5926 if (ret) { 5926 if (ret) {
5927 btrfs_abort_transaction(trans, extent_root, ret); 5927 btrfs_abort_transaction(trans, extent_root, ret);
5928 goto out; 5928 goto out;
5929 } 5929 }
5930 btrfs_release_path(path); 5930 btrfs_release_path(path);
5931 path->leave_spinning = 1; 5931 path->leave_spinning = 1;
5932 5932
5933 key.objectid = bytenr; 5933 key.objectid = bytenr;
5934 key.type = BTRFS_EXTENT_ITEM_KEY; 5934 key.type = BTRFS_EXTENT_ITEM_KEY;
5935 key.offset = num_bytes; 5935 key.offset = num_bytes;
5936 5936
5937 if (!is_data && skinny_metadata) { 5937 if (!is_data && skinny_metadata) {
5938 key.type = BTRFS_METADATA_ITEM_KEY; 5938 key.type = BTRFS_METADATA_ITEM_KEY;
5939 key.offset = owner_objectid; 5939 key.offset = owner_objectid;
5940 } 5940 }
5941 5941
5942 ret = btrfs_search_slot(trans, extent_root, 5942 ret = btrfs_search_slot(trans, extent_root,
5943 &key, path, -1, 1); 5943 &key, path, -1, 1);
5944 if (ret > 0 && skinny_metadata && path->slots[0]) { 5944 if (ret > 0 && skinny_metadata && path->slots[0]) {
5945 /* 5945 /*
5946 * Couldn't find our skinny metadata item, 5946 * Couldn't find our skinny metadata item,
5947 * see if we have ye olde extent item. 5947 * see if we have ye olde extent item.
5948 */ 5948 */
5949 path->slots[0]--; 5949 path->slots[0]--;
5950 btrfs_item_key_to_cpu(path->nodes[0], &key, 5950 btrfs_item_key_to_cpu(path->nodes[0], &key,
5951 path->slots[0]); 5951 path->slots[0]);
5952 if (key.objectid == bytenr && 5952 if (key.objectid == bytenr &&
5953 key.type == BTRFS_EXTENT_ITEM_KEY && 5953 key.type == BTRFS_EXTENT_ITEM_KEY &&
5954 key.offset == num_bytes) 5954 key.offset == num_bytes)
5955 ret = 0; 5955 ret = 0;
5956 } 5956 }
5957 5957
5958 if (ret > 0 && skinny_metadata) { 5958 if (ret > 0 && skinny_metadata) {
5959 skinny_metadata = false; 5959 skinny_metadata = false;
5960 key.objectid = bytenr; 5960 key.objectid = bytenr;
5961 key.type = BTRFS_EXTENT_ITEM_KEY; 5961 key.type = BTRFS_EXTENT_ITEM_KEY;
5962 key.offset = num_bytes; 5962 key.offset = num_bytes;
5963 btrfs_release_path(path); 5963 btrfs_release_path(path);
5964 ret = btrfs_search_slot(trans, extent_root, 5964 ret = btrfs_search_slot(trans, extent_root,
5965 &key, path, -1, 1); 5965 &key, path, -1, 1);
5966 } 5966 }
5967 5967
5968 if (ret) { 5968 if (ret) {
5969 btrfs_err(info, "umm, got %d back from search, was looking for %llu", 5969 btrfs_err(info, "umm, got %d back from search, was looking for %llu",
5970 ret, bytenr); 5970 ret, bytenr);
5971 if (ret > 0) 5971 if (ret > 0)
5972 btrfs_print_leaf(extent_root, 5972 btrfs_print_leaf(extent_root,
5973 path->nodes[0]); 5973 path->nodes[0]);
5974 } 5974 }
5975 if (ret < 0) { 5975 if (ret < 0) {
5976 btrfs_abort_transaction(trans, extent_root, ret); 5976 btrfs_abort_transaction(trans, extent_root, ret);
5977 goto out; 5977 goto out;
5978 } 5978 }
5979 extent_slot = path->slots[0]; 5979 extent_slot = path->slots[0];
5980 } 5980 }
5981 } else if (WARN_ON(ret == -ENOENT)) { 5981 } else if (WARN_ON(ret == -ENOENT)) {
5982 btrfs_print_leaf(extent_root, path->nodes[0]); 5982 btrfs_print_leaf(extent_root, path->nodes[0]);
5983 btrfs_err(info, 5983 btrfs_err(info,
5984 "unable to find ref byte nr %llu parent %llu root %llu owner %llu offset %llu", 5984 "unable to find ref byte nr %llu parent %llu root %llu owner %llu offset %llu",
5985 bytenr, parent, root_objectid, owner_objectid, 5985 bytenr, parent, root_objectid, owner_objectid,
5986 owner_offset); 5986 owner_offset);
5987 btrfs_abort_transaction(trans, extent_root, ret); 5987 btrfs_abort_transaction(trans, extent_root, ret);
5988 goto out; 5988 goto out;
5989 } else { 5989 } else {
5990 btrfs_abort_transaction(trans, extent_root, ret); 5990 btrfs_abort_transaction(trans, extent_root, ret);
5991 goto out; 5991 goto out;
5992 } 5992 }
5993 5993
5994 leaf = path->nodes[0]; 5994 leaf = path->nodes[0];
5995 item_size = btrfs_item_size_nr(leaf, extent_slot); 5995 item_size = btrfs_item_size_nr(leaf, extent_slot);
5996 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0 5996 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
5997 if (item_size < sizeof(*ei)) { 5997 if (item_size < sizeof(*ei)) {
5998 BUG_ON(found_extent || extent_slot != path->slots[0]); 5998 BUG_ON(found_extent || extent_slot != path->slots[0]);
5999 ret = convert_extent_item_v0(trans, extent_root, path, 5999 ret = convert_extent_item_v0(trans, extent_root, path,
6000 owner_objectid, 0); 6000 owner_objectid, 0);
6001 if (ret < 0) { 6001 if (ret < 0) {
6002 btrfs_abort_transaction(trans, extent_root, ret); 6002 btrfs_abort_transaction(trans, extent_root, ret);
6003 goto out; 6003 goto out;
6004 } 6004 }
6005 6005
6006 btrfs_release_path(path); 6006 btrfs_release_path(path);
6007 path->leave_spinning = 1; 6007 path->leave_spinning = 1;
6008 6008
6009 key.objectid = bytenr; 6009 key.objectid = bytenr;
6010 key.type = BTRFS_EXTENT_ITEM_KEY; 6010 key.type = BTRFS_EXTENT_ITEM_KEY;
6011 key.offset = num_bytes; 6011 key.offset = num_bytes;
6012 6012
6013 ret = btrfs_search_slot(trans, extent_root, &key, path, 6013 ret = btrfs_search_slot(trans, extent_root, &key, path,
6014 -1, 1); 6014 -1, 1);
6015 if (ret) { 6015 if (ret) {
6016 btrfs_err(info, "umm, got %d back from search, was looking for %llu", 6016 btrfs_err(info, "umm, got %d back from search, was looking for %llu",
6017 ret, bytenr); 6017 ret, bytenr);
6018 btrfs_print_leaf(extent_root, path->nodes[0]); 6018 btrfs_print_leaf(extent_root, path->nodes[0]);
6019 } 6019 }
6020 if (ret < 0) { 6020 if (ret < 0) {
6021 btrfs_abort_transaction(trans, extent_root, ret); 6021 btrfs_abort_transaction(trans, extent_root, ret);
6022 goto out; 6022 goto out;
6023 } 6023 }
6024 6024
6025 extent_slot = path->slots[0]; 6025 extent_slot = path->slots[0];
6026 leaf = path->nodes[0]; 6026 leaf = path->nodes[0];
6027 item_size = btrfs_item_size_nr(leaf, extent_slot); 6027 item_size = btrfs_item_size_nr(leaf, extent_slot);
6028 } 6028 }
6029 #endif 6029 #endif
6030 BUG_ON(item_size < sizeof(*ei)); 6030 BUG_ON(item_size < sizeof(*ei));
6031 ei = btrfs_item_ptr(leaf, extent_slot, 6031 ei = btrfs_item_ptr(leaf, extent_slot,
6032 struct btrfs_extent_item); 6032 struct btrfs_extent_item);
6033 if (owner_objectid < BTRFS_FIRST_FREE_OBJECTID && 6033 if (owner_objectid < BTRFS_FIRST_FREE_OBJECTID &&
6034 key.type == BTRFS_EXTENT_ITEM_KEY) { 6034 key.type == BTRFS_EXTENT_ITEM_KEY) {
6035 struct btrfs_tree_block_info *bi; 6035 struct btrfs_tree_block_info *bi;
6036 BUG_ON(item_size < sizeof(*ei) + sizeof(*bi)); 6036 BUG_ON(item_size < sizeof(*ei) + sizeof(*bi));
6037 bi = (struct btrfs_tree_block_info *)(ei + 1); 6037 bi = (struct btrfs_tree_block_info *)(ei + 1);
6038 WARN_ON(owner_objectid != btrfs_tree_block_level(leaf, bi)); 6038 WARN_ON(owner_objectid != btrfs_tree_block_level(leaf, bi));
6039 } 6039 }
6040 6040
6041 refs = btrfs_extent_refs(leaf, ei); 6041 refs = btrfs_extent_refs(leaf, ei);
6042 if (refs < refs_to_drop) { 6042 if (refs < refs_to_drop) {
6043 btrfs_err(info, "trying to drop %d refs but we only have %Lu " 6043 btrfs_err(info, "trying to drop %d refs but we only have %Lu "
6044 "for bytenr %Lu", refs_to_drop, refs, bytenr); 6044 "for bytenr %Lu", refs_to_drop, refs, bytenr);
6045 ret = -EINVAL; 6045 ret = -EINVAL;
6046 btrfs_abort_transaction(trans, extent_root, ret); 6046 btrfs_abort_transaction(trans, extent_root, ret);
6047 goto out; 6047 goto out;
6048 } 6048 }
6049 refs -= refs_to_drop; 6049 refs -= refs_to_drop;
6050 6050
6051 if (refs > 0) { 6051 if (refs > 0) {
6052 type = BTRFS_QGROUP_OPER_SUB_SHARED; 6052 type = BTRFS_QGROUP_OPER_SUB_SHARED;
6053 if (extent_op) 6053 if (extent_op)
6054 __run_delayed_extent_op(extent_op, leaf, ei); 6054 __run_delayed_extent_op(extent_op, leaf, ei);
6055 /* 6055 /*
6056 * In the case of inline back ref, reference count will 6056 * In the case of inline back ref, reference count will
6057 * be updated by remove_extent_backref 6057 * be updated by remove_extent_backref
6058 */ 6058 */
6059 if (iref) { 6059 if (iref) {
6060 BUG_ON(!found_extent); 6060 BUG_ON(!found_extent);
6061 } else { 6061 } else {
6062 btrfs_set_extent_refs(leaf, ei, refs); 6062 btrfs_set_extent_refs(leaf, ei, refs);
6063 btrfs_mark_buffer_dirty(leaf); 6063 btrfs_mark_buffer_dirty(leaf);
6064 } 6064 }
6065 if (found_extent) { 6065 if (found_extent) {
6066 ret = remove_extent_backref(trans, extent_root, path, 6066 ret = remove_extent_backref(trans, extent_root, path,
6067 iref, refs_to_drop, 6067 iref, refs_to_drop,
6068 is_data, &last_ref); 6068 is_data, &last_ref);
6069 if (ret) { 6069 if (ret) {
6070 btrfs_abort_transaction(trans, extent_root, ret); 6070 btrfs_abort_transaction(trans, extent_root, ret);
6071 goto out; 6071 goto out;
6072 } 6072 }
6073 } 6073 }
6074 add_pinned_bytes(root->fs_info, -num_bytes, owner_objectid, 6074 add_pinned_bytes(root->fs_info, -num_bytes, owner_objectid,
6075 root_objectid); 6075 root_objectid);
6076 } else { 6076 } else {
6077 if (found_extent) { 6077 if (found_extent) {
6078 BUG_ON(is_data && refs_to_drop != 6078 BUG_ON(is_data && refs_to_drop !=
6079 extent_data_ref_count(root, path, iref)); 6079 extent_data_ref_count(root, path, iref));
6080 if (iref) { 6080 if (iref) {
6081 BUG_ON(path->slots[0] != extent_slot); 6081 BUG_ON(path->slots[0] != extent_slot);
6082 } else { 6082 } else {
6083 BUG_ON(path->slots[0] != extent_slot + 1); 6083 BUG_ON(path->slots[0] != extent_slot + 1);
6084 path->slots[0] = extent_slot; 6084 path->slots[0] = extent_slot;
6085 num_to_del = 2; 6085 num_to_del = 2;
6086 } 6086 }
6087 } 6087 }
6088 6088
6089 last_ref = 1; 6089 last_ref = 1;
6090 ret = btrfs_del_items(trans, extent_root, path, path->slots[0], 6090 ret = btrfs_del_items(trans, extent_root, path, path->slots[0],
6091 num_to_del); 6091 num_to_del);
6092 if (ret) { 6092 if (ret) {
6093 btrfs_abort_transaction(trans, extent_root, ret); 6093 btrfs_abort_transaction(trans, extent_root, ret);
6094 goto out; 6094 goto out;
6095 } 6095 }
6096 btrfs_release_path(path); 6096 btrfs_release_path(path);
6097 6097
6098 if (is_data) { 6098 if (is_data) {
6099 ret = btrfs_del_csums(trans, root, bytenr, num_bytes); 6099 ret = btrfs_del_csums(trans, root, bytenr, num_bytes);
6100 if (ret) { 6100 if (ret) {
6101 btrfs_abort_transaction(trans, extent_root, ret); 6101 btrfs_abort_transaction(trans, extent_root, ret);
6102 goto out; 6102 goto out;
6103 } 6103 }
6104 } 6104 }
6105 6105
6106 ret = update_block_group(root, bytenr, num_bytes, 0); 6106 ret = update_block_group(root, bytenr, num_bytes, 0);
6107 if (ret) { 6107 if (ret) {
6108 btrfs_abort_transaction(trans, extent_root, ret); 6108 btrfs_abort_transaction(trans, extent_root, ret);
6109 goto out; 6109 goto out;
6110 } 6110 }
6111 } 6111 }
6112 btrfs_release_path(path); 6112 btrfs_release_path(path);
6113 6113
6114 /* Deal with the quota accounting */ 6114 /* Deal with the quota accounting */
6115 if (!ret && last_ref && !no_quota) { 6115 if (!ret && last_ref && !no_quota) {
6116 int mod_seq = 0; 6116 int mod_seq = 0;
6117 6117
6118 if (owner_objectid >= BTRFS_FIRST_FREE_OBJECTID && 6118 if (owner_objectid >= BTRFS_FIRST_FREE_OBJECTID &&
6119 type == BTRFS_QGROUP_OPER_SUB_SHARED) 6119 type == BTRFS_QGROUP_OPER_SUB_SHARED)
6120 mod_seq = 1; 6120 mod_seq = 1;
6121 6121
6122 ret = btrfs_qgroup_record_ref(trans, info, root_objectid, 6122 ret = btrfs_qgroup_record_ref(trans, info, root_objectid,
6123 bytenr, num_bytes, type, 6123 bytenr, num_bytes, type,
6124 mod_seq); 6124 mod_seq);
6125 } 6125 }
6126 out: 6126 out:
6127 btrfs_free_path(path); 6127 btrfs_free_path(path);
6128 return ret; 6128 return ret;
6129 } 6129 }
6130 6130
6131 /* 6131 /*
6132 * when we free an block, it is possible (and likely) that we free the last 6132 * when we free an block, it is possible (and likely) that we free the last
6133 * delayed ref for that extent as well. This searches the delayed ref tree for 6133 * delayed ref for that extent as well. This searches the delayed ref tree for
6134 * a given extent, and if there are no other delayed refs to be processed, it 6134 * a given extent, and if there are no other delayed refs to be processed, it
6135 * removes it from the tree. 6135 * removes it from the tree.
6136 */ 6136 */
6137 static noinline int check_ref_cleanup(struct btrfs_trans_handle *trans, 6137 static noinline int check_ref_cleanup(struct btrfs_trans_handle *trans,
6138 struct btrfs_root *root, u64 bytenr) 6138 struct btrfs_root *root, u64 bytenr)
6139 { 6139 {
6140 struct btrfs_delayed_ref_head *head; 6140 struct btrfs_delayed_ref_head *head;
6141 struct btrfs_delayed_ref_root *delayed_refs; 6141 struct btrfs_delayed_ref_root *delayed_refs;
6142 int ret = 0; 6142 int ret = 0;
6143 6143
6144 delayed_refs = &trans->transaction->delayed_refs; 6144 delayed_refs = &trans->transaction->delayed_refs;
6145 spin_lock(&delayed_refs->lock); 6145 spin_lock(&delayed_refs->lock);
6146 head = btrfs_find_delayed_ref_head(trans, bytenr); 6146 head = btrfs_find_delayed_ref_head(trans, bytenr);
6147 if (!head) 6147 if (!head)
6148 goto out_delayed_unlock; 6148 goto out_delayed_unlock;
6149 6149
6150 spin_lock(&head->lock); 6150 spin_lock(&head->lock);
6151 if (rb_first(&head->ref_root)) 6151 if (rb_first(&head->ref_root))
6152 goto out; 6152 goto out;
6153 6153
6154 if (head->extent_op) { 6154 if (head->extent_op) {
6155 if (!head->must_insert_reserved) 6155 if (!head->must_insert_reserved)
6156 goto out; 6156 goto out;
6157 btrfs_free_delayed_extent_op(head->extent_op); 6157 btrfs_free_delayed_extent_op(head->extent_op);
6158 head->extent_op = NULL; 6158 head->extent_op = NULL;
6159 } 6159 }
6160 6160
6161 /* 6161 /*
6162 * waiting for the lock here would deadlock. If someone else has it 6162 * waiting for the lock here would deadlock. If someone else has it
6163 * locked they are already in the process of dropping it anyway 6163 * locked they are already in the process of dropping it anyway
6164 */ 6164 */
6165 if (!mutex_trylock(&head->mutex)) 6165 if (!mutex_trylock(&head->mutex))
6166 goto out; 6166 goto out;
6167 6167
6168 /* 6168 /*
6169 * at this point we have a head with no other entries. Go 6169 * at this point we have a head with no other entries. Go
6170 * ahead and process it. 6170 * ahead and process it.
6171 */ 6171 */
6172 head->node.in_tree = 0; 6172 head->node.in_tree = 0;
6173 rb_erase(&head->href_node, &delayed_refs->href_root); 6173 rb_erase(&head->href_node, &delayed_refs->href_root);
6174 6174
6175 atomic_dec(&delayed_refs->num_entries); 6175 atomic_dec(&delayed_refs->num_entries);
6176 6176
6177 /* 6177 /*
6178 * we don't take a ref on the node because we're removing it from the 6178 * we don't take a ref on the node because we're removing it from the
6179 * tree, so we just steal the ref the tree was holding. 6179 * tree, so we just steal the ref the tree was holding.
6180 */ 6180 */
6181 delayed_refs->num_heads--; 6181 delayed_refs->num_heads--;
6182 if (head->processing == 0) 6182 if (head->processing == 0)
6183 delayed_refs->num_heads_ready--; 6183 delayed_refs->num_heads_ready--;
6184 head->processing = 0; 6184 head->processing = 0;
6185 spin_unlock(&head->lock); 6185 spin_unlock(&head->lock);
6186 spin_unlock(&delayed_refs->lock); 6186 spin_unlock(&delayed_refs->lock);
6187 6187
6188 BUG_ON(head->extent_op); 6188 BUG_ON(head->extent_op);
6189 if (head->must_insert_reserved) 6189 if (head->must_insert_reserved)
6190 ret = 1; 6190 ret = 1;
6191 6191
6192 mutex_unlock(&head->mutex); 6192 mutex_unlock(&head->mutex);
6193 btrfs_put_delayed_ref(&head->node); 6193 btrfs_put_delayed_ref(&head->node);
6194 return ret; 6194 return ret;
6195 out: 6195 out:
6196 spin_unlock(&head->lock); 6196 spin_unlock(&head->lock);
6197 6197
6198 out_delayed_unlock: 6198 out_delayed_unlock:
6199 spin_unlock(&delayed_refs->lock); 6199 spin_unlock(&delayed_refs->lock);
6200 return 0; 6200 return 0;
6201 } 6201 }
6202 6202
6203 void btrfs_free_tree_block(struct btrfs_trans_handle *trans, 6203 void btrfs_free_tree_block(struct btrfs_trans_handle *trans,
6204 struct btrfs_root *root, 6204 struct btrfs_root *root,
6205 struct extent_buffer *buf, 6205 struct extent_buffer *buf,
6206 u64 parent, int last_ref) 6206 u64 parent, int last_ref)
6207 { 6207 {
6208 struct btrfs_block_group_cache *cache = NULL; 6208 struct btrfs_block_group_cache *cache = NULL;
6209 int pin = 1; 6209 int pin = 1;
6210 int ret; 6210 int ret;
6211 6211
6212 if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) { 6212 if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) {
6213 ret = btrfs_add_delayed_tree_ref(root->fs_info, trans, 6213 ret = btrfs_add_delayed_tree_ref(root->fs_info, trans,
6214 buf->start, buf->len, 6214 buf->start, buf->len,
6215 parent, root->root_key.objectid, 6215 parent, root->root_key.objectid,
6216 btrfs_header_level(buf), 6216 btrfs_header_level(buf),
6217 BTRFS_DROP_DELAYED_REF, NULL, 0); 6217 BTRFS_DROP_DELAYED_REF, NULL, 0);
6218 BUG_ON(ret); /* -ENOMEM */ 6218 BUG_ON(ret); /* -ENOMEM */
6219 } 6219 }
6220 6220
6221 if (!last_ref) 6221 if (!last_ref)
6222 return; 6222 return;
6223 6223
6224 cache = btrfs_lookup_block_group(root->fs_info, buf->start); 6224 cache = btrfs_lookup_block_group(root->fs_info, buf->start);
6225 6225
6226 if (btrfs_header_generation(buf) == trans->transid) { 6226 if (btrfs_header_generation(buf) == trans->transid) {
6227 if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) { 6227 if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) {
6228 ret = check_ref_cleanup(trans, root, buf->start); 6228 ret = check_ref_cleanup(trans, root, buf->start);
6229 if (!ret) 6229 if (!ret)
6230 goto out; 6230 goto out;
6231 } 6231 }
6232 6232
6233 if (btrfs_header_flag(buf, BTRFS_HEADER_FLAG_WRITTEN)) { 6233 if (btrfs_header_flag(buf, BTRFS_HEADER_FLAG_WRITTEN)) {
6234 pin_down_extent(root, cache, buf->start, buf->len, 1); 6234 pin_down_extent(root, cache, buf->start, buf->len, 1);
6235 goto out; 6235 goto out;
6236 } 6236 }
6237 6237
6238 WARN_ON(test_bit(EXTENT_BUFFER_DIRTY, &buf->bflags)); 6238 WARN_ON(test_bit(EXTENT_BUFFER_DIRTY, &buf->bflags));
6239 6239
6240 btrfs_add_free_space(cache, buf->start, buf->len); 6240 btrfs_add_free_space(cache, buf->start, buf->len);
6241 btrfs_update_reserved_bytes(cache, buf->len, RESERVE_FREE, 0); 6241 btrfs_update_reserved_bytes(cache, buf->len, RESERVE_FREE, 0);
6242 trace_btrfs_reserved_extent_free(root, buf->start, buf->len); 6242 trace_btrfs_reserved_extent_free(root, buf->start, buf->len);
6243 pin = 0; 6243 pin = 0;
6244 } 6244 }
6245 out: 6245 out:
6246 if (pin) 6246 if (pin)
6247 add_pinned_bytes(root->fs_info, buf->len, 6247 add_pinned_bytes(root->fs_info, buf->len,
6248 btrfs_header_level(buf), 6248 btrfs_header_level(buf),
6249 root->root_key.objectid); 6249 root->root_key.objectid);
6250 6250
6251 /* 6251 /*
6252 * Deleting the buffer, clear the corrupt flag since it doesn't matter 6252 * Deleting the buffer, clear the corrupt flag since it doesn't matter
6253 * anymore. 6253 * anymore.
6254 */ 6254 */
6255 clear_bit(EXTENT_BUFFER_CORRUPT, &buf->bflags); 6255 clear_bit(EXTENT_BUFFER_CORRUPT, &buf->bflags);
6256 btrfs_put_block_group(cache); 6256 btrfs_put_block_group(cache);
6257 } 6257 }
6258 6258
6259 /* Can return -ENOMEM */ 6259 /* Can return -ENOMEM */
6260 int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root *root, 6260 int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root *root,
6261 u64 bytenr, u64 num_bytes, u64 parent, u64 root_objectid, 6261 u64 bytenr, u64 num_bytes, u64 parent, u64 root_objectid,
6262 u64 owner, u64 offset, int no_quota) 6262 u64 owner, u64 offset, int no_quota)
6263 { 6263 {
6264 int ret; 6264 int ret;
6265 struct btrfs_fs_info *fs_info = root->fs_info; 6265 struct btrfs_fs_info *fs_info = root->fs_info;
6266 6266
6267 if (btrfs_test_is_dummy_root(root)) 6267 if (btrfs_test_is_dummy_root(root))
6268 return 0; 6268 return 0;
6269 6269
6270 add_pinned_bytes(root->fs_info, num_bytes, owner, root_objectid); 6270 add_pinned_bytes(root->fs_info, num_bytes, owner, root_objectid);
6271 6271
6272 /* 6272 /*
6273 * tree log blocks never actually go into the extent allocation 6273 * tree log blocks never actually go into the extent allocation
6274 * tree, just update pinning info and exit early. 6274 * tree, just update pinning info and exit early.
6275 */ 6275 */
6276 if (root_objectid == BTRFS_TREE_LOG_OBJECTID) { 6276 if (root_objectid == BTRFS_TREE_LOG_OBJECTID) {
6277 WARN_ON(owner >= BTRFS_FIRST_FREE_OBJECTID); 6277 WARN_ON(owner >= BTRFS_FIRST_FREE_OBJECTID);
6278 /* unlocks the pinned mutex */ 6278 /* unlocks the pinned mutex */
6279 btrfs_pin_extent(root, bytenr, num_bytes, 1); 6279 btrfs_pin_extent(root, bytenr, num_bytes, 1);
6280 ret = 0; 6280 ret = 0;
6281 } else if (owner < BTRFS_FIRST_FREE_OBJECTID) { 6281 } else if (owner < BTRFS_FIRST_FREE_OBJECTID) {
6282 ret = btrfs_add_delayed_tree_ref(fs_info, trans, bytenr, 6282 ret = btrfs_add_delayed_tree_ref(fs_info, trans, bytenr,
6283 num_bytes, 6283 num_bytes,
6284 parent, root_objectid, (int)owner, 6284 parent, root_objectid, (int)owner,
6285 BTRFS_DROP_DELAYED_REF, NULL, no_quota); 6285 BTRFS_DROP_DELAYED_REF, NULL, no_quota);
6286 } else { 6286 } else {
6287 ret = btrfs_add_delayed_data_ref(fs_info, trans, bytenr, 6287 ret = btrfs_add_delayed_data_ref(fs_info, trans, bytenr,
6288 num_bytes, 6288 num_bytes,
6289 parent, root_objectid, owner, 6289 parent, root_objectid, owner,
6290 offset, BTRFS_DROP_DELAYED_REF, 6290 offset, BTRFS_DROP_DELAYED_REF,
6291 NULL, no_quota); 6291 NULL, no_quota);
6292 } 6292 }
6293 return ret; 6293 return ret;
6294 } 6294 }
6295 6295
6296 /* 6296 /*
6297 * when we wait for progress in the block group caching, its because 6297 * when we wait for progress in the block group caching, its because
6298 * our allocation attempt failed at least once. So, we must sleep 6298 * our allocation attempt failed at least once. So, we must sleep
6299 * and let some progress happen before we try again. 6299 * and let some progress happen before we try again.
6300 * 6300 *
6301 * This function will sleep at least once waiting for new free space to 6301 * This function will sleep at least once waiting for new free space to
6302 * show up, and then it will check the block group free space numbers 6302 * show up, and then it will check the block group free space numbers
6303 * for our min num_bytes. Another option is to have it go ahead 6303 * for our min num_bytes. Another option is to have it go ahead
6304 * and look in the rbtree for a free extent of a given size, but this 6304 * and look in the rbtree for a free extent of a given size, but this
6305 * is a good start. 6305 * is a good start.
6306 * 6306 *
6307 * Callers of this must check if cache->cached == BTRFS_CACHE_ERROR before using 6307 * Callers of this must check if cache->cached == BTRFS_CACHE_ERROR before using
6308 * any of the information in this block group. 6308 * any of the information in this block group.
6309 */ 6309 */
6310 static noinline void 6310 static noinline void
6311 wait_block_group_cache_progress(struct btrfs_block_group_cache *cache, 6311 wait_block_group_cache_progress(struct btrfs_block_group_cache *cache,
6312 u64 num_bytes) 6312 u64 num_bytes)
6313 { 6313 {
6314 struct btrfs_caching_control *caching_ctl; 6314 struct btrfs_caching_control *caching_ctl;
6315 6315
6316 caching_ctl = get_caching_control(cache); 6316 caching_ctl = get_caching_control(cache);
6317 if (!caching_ctl) 6317 if (!caching_ctl)
6318 return; 6318 return;
6319 6319
6320 wait_event(caching_ctl->wait, block_group_cache_done(cache) || 6320 wait_event(caching_ctl->wait, block_group_cache_done(cache) ||
6321 (cache->free_space_ctl->free_space >= num_bytes)); 6321 (cache->free_space_ctl->free_space >= num_bytes));
6322 6322
6323 put_caching_control(caching_ctl); 6323 put_caching_control(caching_ctl);
6324 } 6324 }
6325 6325
6326 static noinline int 6326 static noinline int
6327 wait_block_group_cache_done(struct btrfs_block_group_cache *cache) 6327 wait_block_group_cache_done(struct btrfs_block_group_cache *cache)
6328 { 6328 {
6329 struct btrfs_caching_control *caching_ctl; 6329 struct btrfs_caching_control *caching_ctl;
6330 int ret = 0; 6330 int ret = 0;
6331 6331
6332 caching_ctl = get_caching_control(cache); 6332 caching_ctl = get_caching_control(cache);
6333 if (!caching_ctl) 6333 if (!caching_ctl)
6334 return (cache->cached == BTRFS_CACHE_ERROR) ? -EIO : 0; 6334 return (cache->cached == BTRFS_CACHE_ERROR) ? -EIO : 0;
6335 6335
6336 wait_event(caching_ctl->wait, block_group_cache_done(cache)); 6336 wait_event(caching_ctl->wait, block_group_cache_done(cache));
6337 if (cache->cached == BTRFS_CACHE_ERROR) 6337 if (cache->cached == BTRFS_CACHE_ERROR)
6338 ret = -EIO; 6338 ret = -EIO;
6339 put_caching_control(caching_ctl); 6339 put_caching_control(caching_ctl);
6340 return ret; 6340 return ret;
6341 } 6341 }
6342 6342
6343 int __get_raid_index(u64 flags) 6343 int __get_raid_index(u64 flags)
6344 { 6344 {
6345 if (flags & BTRFS_BLOCK_GROUP_RAID10) 6345 if (flags & BTRFS_BLOCK_GROUP_RAID10)
6346 return BTRFS_RAID_RAID10; 6346 return BTRFS_RAID_RAID10;
6347 else if (flags & BTRFS_BLOCK_GROUP_RAID1) 6347 else if (flags & BTRFS_BLOCK_GROUP_RAID1)
6348 return BTRFS_RAID_RAID1; 6348 return BTRFS_RAID_RAID1;
6349 else if (flags & BTRFS_BLOCK_GROUP_DUP) 6349 else if (flags & BTRFS_BLOCK_GROUP_DUP)
6350 return BTRFS_RAID_DUP; 6350 return BTRFS_RAID_DUP;
6351 else if (flags & BTRFS_BLOCK_GROUP_RAID0) 6351 else if (flags & BTRFS_BLOCK_GROUP_RAID0)
6352 return BTRFS_RAID_RAID0; 6352 return BTRFS_RAID_RAID0;
6353 else if (flags & BTRFS_BLOCK_GROUP_RAID5) 6353 else if (flags & BTRFS_BLOCK_GROUP_RAID5)
6354 return BTRFS_RAID_RAID5; 6354 return BTRFS_RAID_RAID5;
6355 else if (flags & BTRFS_BLOCK_GROUP_RAID6) 6355 else if (flags & BTRFS_BLOCK_GROUP_RAID6)
6356 return BTRFS_RAID_RAID6; 6356 return BTRFS_RAID_RAID6;
6357 6357
6358 return BTRFS_RAID_SINGLE; /* BTRFS_BLOCK_GROUP_SINGLE */ 6358 return BTRFS_RAID_SINGLE; /* BTRFS_BLOCK_GROUP_SINGLE */
6359 } 6359 }
6360 6360
6361 int get_block_group_index(struct btrfs_block_group_cache *cache) 6361 int get_block_group_index(struct btrfs_block_group_cache *cache)
6362 { 6362 {
6363 return __get_raid_index(cache->flags); 6363 return __get_raid_index(cache->flags);
6364 } 6364 }
6365 6365
6366 static const char *btrfs_raid_type_names[BTRFS_NR_RAID_TYPES] = { 6366 static const char *btrfs_raid_type_names[BTRFS_NR_RAID_TYPES] = {
6367 [BTRFS_RAID_RAID10] = "raid10", 6367 [BTRFS_RAID_RAID10] = "raid10",
6368 [BTRFS_RAID_RAID1] = "raid1", 6368 [BTRFS_RAID_RAID1] = "raid1",
6369 [BTRFS_RAID_DUP] = "dup", 6369 [BTRFS_RAID_DUP] = "dup",
6370 [BTRFS_RAID_RAID0] = "raid0", 6370 [BTRFS_RAID_RAID0] = "raid0",
6371 [BTRFS_RAID_SINGLE] = "single", 6371 [BTRFS_RAID_SINGLE] = "single",
6372 [BTRFS_RAID_RAID5] = "raid5", 6372 [BTRFS_RAID_RAID5] = "raid5",
6373 [BTRFS_RAID_RAID6] = "raid6", 6373 [BTRFS_RAID_RAID6] = "raid6",
6374 }; 6374 };
6375 6375
6376 static const char *get_raid_name(enum btrfs_raid_types type) 6376 static const char *get_raid_name(enum btrfs_raid_types type)
6377 { 6377 {
6378 if (type >= BTRFS_NR_RAID_TYPES) 6378 if (type >= BTRFS_NR_RAID_TYPES)
6379 return NULL; 6379 return NULL;
6380 6380
6381 return btrfs_raid_type_names[type]; 6381 return btrfs_raid_type_names[type];
6382 } 6382 }
6383 6383
6384 enum btrfs_loop_type { 6384 enum btrfs_loop_type {
6385 LOOP_CACHING_NOWAIT = 0, 6385 LOOP_CACHING_NOWAIT = 0,
6386 LOOP_CACHING_WAIT = 1, 6386 LOOP_CACHING_WAIT = 1,
6387 LOOP_ALLOC_CHUNK = 2, 6387 LOOP_ALLOC_CHUNK = 2,
6388 LOOP_NO_EMPTY_SIZE = 3, 6388 LOOP_NO_EMPTY_SIZE = 3,
6389 }; 6389 };
6390 6390
6391 static inline void 6391 static inline void
6392 btrfs_lock_block_group(struct btrfs_block_group_cache *cache, 6392 btrfs_lock_block_group(struct btrfs_block_group_cache *cache,
6393 int delalloc) 6393 int delalloc)
6394 { 6394 {
6395 if (delalloc) 6395 if (delalloc)
6396 down_read(&cache->data_rwsem); 6396 down_read(&cache->data_rwsem);
6397 } 6397 }
6398 6398
6399 static inline void 6399 static inline void
6400 btrfs_grab_block_group(struct btrfs_block_group_cache *cache, 6400 btrfs_grab_block_group(struct btrfs_block_group_cache *cache,
6401 int delalloc) 6401 int delalloc)
6402 { 6402 {
6403 btrfs_get_block_group(cache); 6403 btrfs_get_block_group(cache);
6404 if (delalloc) 6404 if (delalloc)
6405 down_read(&cache->data_rwsem); 6405 down_read(&cache->data_rwsem);
6406 } 6406 }
6407 6407
6408 static struct btrfs_block_group_cache * 6408 static struct btrfs_block_group_cache *
6409 btrfs_lock_cluster(struct btrfs_block_group_cache *block_group, 6409 btrfs_lock_cluster(struct btrfs_block_group_cache *block_group,
6410 struct btrfs_free_cluster *cluster, 6410 struct btrfs_free_cluster *cluster,
6411 int delalloc) 6411 int delalloc)
6412 { 6412 {
6413 struct btrfs_block_group_cache *used_bg; 6413 struct btrfs_block_group_cache *used_bg;
6414 bool locked = false; 6414 bool locked = false;
6415 again: 6415 again:
6416 spin_lock(&cluster->refill_lock); 6416 spin_lock(&cluster->refill_lock);
6417 if (locked) { 6417 if (locked) {
6418 if (used_bg == cluster->block_group) 6418 if (used_bg == cluster->block_group)
6419 return used_bg; 6419 return used_bg;
6420 6420
6421 up_read(&used_bg->data_rwsem); 6421 up_read(&used_bg->data_rwsem);
6422 btrfs_put_block_group(used_bg); 6422 btrfs_put_block_group(used_bg);
6423 } 6423 }
6424 6424
6425 used_bg = cluster->block_group; 6425 used_bg = cluster->block_group;
6426 if (!used_bg) 6426 if (!used_bg)
6427 return NULL; 6427 return NULL;
6428 6428
6429 if (used_bg == block_group) 6429 if (used_bg == block_group)
6430 return used_bg; 6430 return used_bg;
6431 6431
6432 btrfs_get_block_group(used_bg); 6432 btrfs_get_block_group(used_bg);
6433 6433
6434 if (!delalloc) 6434 if (!delalloc)
6435 return used_bg; 6435 return used_bg;
6436 6436
6437 if (down_read_trylock(&used_bg->data_rwsem)) 6437 if (down_read_trylock(&used_bg->data_rwsem))
6438 return used_bg; 6438 return used_bg;
6439 6439
6440 spin_unlock(&cluster->refill_lock); 6440 spin_unlock(&cluster->refill_lock);
6441 down_read(&used_bg->data_rwsem); 6441 down_read(&used_bg->data_rwsem);
6442 locked = true; 6442 locked = true;
6443 goto again; 6443 goto again;
6444 } 6444 }
6445 6445
6446 static inline void 6446 static inline void
6447 btrfs_release_block_group(struct btrfs_block_group_cache *cache, 6447 btrfs_release_block_group(struct btrfs_block_group_cache *cache,
6448 int delalloc) 6448 int delalloc)
6449 { 6449 {
6450 if (delalloc) 6450 if (delalloc)
6451 up_read(&cache->data_rwsem); 6451 up_read(&cache->data_rwsem);
6452 btrfs_put_block_group(cache); 6452 btrfs_put_block_group(cache);
6453 } 6453 }
6454 6454
6455 /* 6455 /*
6456 * walks the btree of allocated extents and find a hole of a given size. 6456 * walks the btree of allocated extents and find a hole of a given size.
6457 * The key ins is changed to record the hole: 6457 * The key ins is changed to record the hole:
6458 * ins->objectid == start position 6458 * ins->objectid == start position
6459 * ins->flags = BTRFS_EXTENT_ITEM_KEY 6459 * ins->flags = BTRFS_EXTENT_ITEM_KEY
6460 * ins->offset == the size of the hole. 6460 * ins->offset == the size of the hole.
6461 * Any available blocks before search_start are skipped. 6461 * Any available blocks before search_start are skipped.
6462 * 6462 *
6463 * If there is no suitable free space, we will record the max size of 6463 * If there is no suitable free space, we will record the max size of
6464 * the free space extent currently. 6464 * the free space extent currently.
6465 */ 6465 */
6466 static noinline int find_free_extent(struct btrfs_root *orig_root, 6466 static noinline int find_free_extent(struct btrfs_root *orig_root,
6467 u64 num_bytes, u64 empty_size, 6467 u64 num_bytes, u64 empty_size,
6468 u64 hint_byte, struct btrfs_key *ins, 6468 u64 hint_byte, struct btrfs_key *ins,
6469 u64 flags, int delalloc) 6469 u64 flags, int delalloc)
6470 { 6470 {
6471 int ret = 0; 6471 int ret = 0;
6472 struct btrfs_root *root = orig_root->fs_info->extent_root; 6472 struct btrfs_root *root = orig_root->fs_info->extent_root;
6473 struct btrfs_free_cluster *last_ptr = NULL; 6473 struct btrfs_free_cluster *last_ptr = NULL;
6474 struct btrfs_block_group_cache *block_group = NULL; 6474 struct btrfs_block_group_cache *block_group = NULL;
6475 u64 search_start = 0; 6475 u64 search_start = 0;
6476 u64 max_extent_size = 0; 6476 u64 max_extent_size = 0;
6477 int empty_cluster = 2 * 1024 * 1024; 6477 int empty_cluster = 2 * 1024 * 1024;
6478 struct btrfs_space_info *space_info; 6478 struct btrfs_space_info *space_info;
6479 int loop = 0; 6479 int loop = 0;
6480 int index = __get_raid_index(flags); 6480 int index = __get_raid_index(flags);
6481 int alloc_type = (flags & BTRFS_BLOCK_GROUP_DATA) ? 6481 int alloc_type = (flags & BTRFS_BLOCK_GROUP_DATA) ?
6482 RESERVE_ALLOC_NO_ACCOUNT : RESERVE_ALLOC; 6482 RESERVE_ALLOC_NO_ACCOUNT : RESERVE_ALLOC;
6483 bool failed_cluster_refill = false; 6483 bool failed_cluster_refill = false;
6484 bool failed_alloc = false; 6484 bool failed_alloc = false;
6485 bool use_cluster = true; 6485 bool use_cluster = true;
6486 bool have_caching_bg = false; 6486 bool have_caching_bg = false;
6487 6487
6488 WARN_ON(num_bytes < root->sectorsize); 6488 WARN_ON(num_bytes < root->sectorsize);
6489 ins->type = BTRFS_EXTENT_ITEM_KEY; 6489 ins->type = BTRFS_EXTENT_ITEM_KEY;
6490 ins->objectid = 0; 6490 ins->objectid = 0;
6491 ins->offset = 0; 6491 ins->offset = 0;
6492 6492
6493 trace_find_free_extent(orig_root, num_bytes, empty_size, flags); 6493 trace_find_free_extent(orig_root, num_bytes, empty_size, flags);
6494 6494
6495 space_info = __find_space_info(root->fs_info, flags); 6495 space_info = __find_space_info(root->fs_info, flags);
6496 if (!space_info) { 6496 if (!space_info) {
6497 btrfs_err(root->fs_info, "No space info for %llu", flags); 6497 btrfs_err(root->fs_info, "No space info for %llu", flags);
6498 return -ENOSPC; 6498 return -ENOSPC;
6499 } 6499 }
6500 6500
6501 /* 6501 /*
6502 * If the space info is for both data and metadata it means we have a 6502 * If the space info is for both data and metadata it means we have a
6503 * small filesystem and we can't use the clustering stuff. 6503 * small filesystem and we can't use the clustering stuff.
6504 */ 6504 */
6505 if (btrfs_mixed_space_info(space_info)) 6505 if (btrfs_mixed_space_info(space_info))
6506 use_cluster = false; 6506 use_cluster = false;
6507 6507
6508 if (flags & BTRFS_BLOCK_GROUP_METADATA && use_cluster) { 6508 if (flags & BTRFS_BLOCK_GROUP_METADATA && use_cluster) {
6509 last_ptr = &root->fs_info->meta_alloc_cluster; 6509 last_ptr = &root->fs_info->meta_alloc_cluster;
6510 if (!btrfs_test_opt(root, SSD)) 6510 if (!btrfs_test_opt(root, SSD))
6511 empty_cluster = 64 * 1024; 6511 empty_cluster = 64 * 1024;
6512 } 6512 }
6513 6513
6514 if ((flags & BTRFS_BLOCK_GROUP_DATA) && use_cluster && 6514 if ((flags & BTRFS_BLOCK_GROUP_DATA) && use_cluster &&
6515 btrfs_test_opt(root, SSD)) { 6515 btrfs_test_opt(root, SSD)) {
6516 last_ptr = &root->fs_info->data_alloc_cluster; 6516 last_ptr = &root->fs_info->data_alloc_cluster;
6517 } 6517 }
6518 6518
6519 if (last_ptr) { 6519 if (last_ptr) {
6520 spin_lock(&last_ptr->lock); 6520 spin_lock(&last_ptr->lock);
6521 if (last_ptr->block_group) 6521 if (last_ptr->block_group)
6522 hint_byte = last_ptr->window_start; 6522 hint_byte = last_ptr->window_start;
6523 spin_unlock(&last_ptr->lock); 6523 spin_unlock(&last_ptr->lock);
6524 } 6524 }
6525 6525
6526 search_start = max(search_start, first_logical_byte(root, 0)); 6526 search_start = max(search_start, first_logical_byte(root, 0));
6527 search_start = max(search_start, hint_byte); 6527 search_start = max(search_start, hint_byte);
6528 6528
6529 if (!last_ptr) 6529 if (!last_ptr)
6530 empty_cluster = 0; 6530 empty_cluster = 0;
6531 6531
6532 if (search_start == hint_byte) { 6532 if (search_start == hint_byte) {
6533 block_group = btrfs_lookup_block_group(root->fs_info, 6533 block_group = btrfs_lookup_block_group(root->fs_info,
6534 search_start); 6534 search_start);
6535 /* 6535 /*
6536 * we don't want to use the block group if it doesn't match our 6536 * we don't want to use the block group if it doesn't match our
6537 * allocation bits, or if its not cached. 6537 * allocation bits, or if its not cached.
6538 * 6538 *
6539 * However if we are re-searching with an ideal block group 6539 * However if we are re-searching with an ideal block group
6540 * picked out then we don't care that the block group is cached. 6540 * picked out then we don't care that the block group is cached.
6541 */ 6541 */
6542 if (block_group && block_group_bits(block_group, flags) && 6542 if (block_group && block_group_bits(block_group, flags) &&
6543 block_group->cached != BTRFS_CACHE_NO) { 6543 block_group->cached != BTRFS_CACHE_NO) {
6544 down_read(&space_info->groups_sem); 6544 down_read(&space_info->groups_sem);
6545 if (list_empty(&block_group->list) || 6545 if (list_empty(&block_group->list) ||
6546 block_group->ro) { 6546 block_group->ro) {
6547 /* 6547 /*
6548 * someone is removing this block group, 6548 * someone is removing this block group,
6549 * we can't jump into the have_block_group 6549 * we can't jump into the have_block_group
6550 * target because our list pointers are not 6550 * target because our list pointers are not
6551 * valid 6551 * valid
6552 */ 6552 */
6553 btrfs_put_block_group(block_group); 6553 btrfs_put_block_group(block_group);
6554 up_read(&space_info->groups_sem); 6554 up_read(&space_info->groups_sem);
6555 } else { 6555 } else {
6556 index = get_block_group_index(block_group); 6556 index = get_block_group_index(block_group);
6557 btrfs_lock_block_group(block_group, delalloc); 6557 btrfs_lock_block_group(block_group, delalloc);
6558 goto have_block_group; 6558 goto have_block_group;
6559 } 6559 }
6560 } else if (block_group) { 6560 } else if (block_group) {
6561 btrfs_put_block_group(block_group); 6561 btrfs_put_block_group(block_group);
6562 } 6562 }
6563 } 6563 }
6564 search: 6564 search:
6565 have_caching_bg = false; 6565 have_caching_bg = false;
6566 down_read(&space_info->groups_sem); 6566 down_read(&space_info->groups_sem);
6567 list_for_each_entry(block_group, &space_info->block_groups[index], 6567 list_for_each_entry(block_group, &space_info->block_groups[index],
6568 list) { 6568 list) {
6569 u64 offset; 6569 u64 offset;
6570 int cached; 6570 int cached;
6571 6571
6572 btrfs_grab_block_group(block_group, delalloc); 6572 btrfs_grab_block_group(block_group, delalloc);
6573 search_start = block_group->key.objectid; 6573 search_start = block_group->key.objectid;
6574 6574
6575 /* 6575 /*
6576 * this can happen if we end up cycling through all the 6576 * this can happen if we end up cycling through all the
6577 * raid types, but we want to make sure we only allocate 6577 * raid types, but we want to make sure we only allocate
6578 * for the proper type. 6578 * for the proper type.
6579 */ 6579 */
6580 if (!block_group_bits(block_group, flags)) { 6580 if (!block_group_bits(block_group, flags)) {
6581 u64 extra = BTRFS_BLOCK_GROUP_DUP | 6581 u64 extra = BTRFS_BLOCK_GROUP_DUP |
6582 BTRFS_BLOCK_GROUP_RAID1 | 6582 BTRFS_BLOCK_GROUP_RAID1 |
6583 BTRFS_BLOCK_GROUP_RAID5 | 6583 BTRFS_BLOCK_GROUP_RAID5 |
6584 BTRFS_BLOCK_GROUP_RAID6 | 6584 BTRFS_BLOCK_GROUP_RAID6 |
6585 BTRFS_BLOCK_GROUP_RAID10; 6585 BTRFS_BLOCK_GROUP_RAID10;
6586 6586
6587 /* 6587 /*
6588 * if they asked for extra copies and this block group 6588 * if they asked for extra copies and this block group
6589 * doesn't provide them, bail. This does allow us to 6589 * doesn't provide them, bail. This does allow us to
6590 * fill raid0 from raid1. 6590 * fill raid0 from raid1.
6591 */ 6591 */
6592 if ((flags & extra) && !(block_group->flags & extra)) 6592 if ((flags & extra) && !(block_group->flags & extra))
6593 goto loop; 6593 goto loop;
6594 } 6594 }
6595 6595
6596 have_block_group: 6596 have_block_group:
6597 cached = block_group_cache_done(block_group); 6597 cached = block_group_cache_done(block_group);
6598 if (unlikely(!cached)) { 6598 if (unlikely(!cached)) {
6599 ret = cache_block_group(block_group, 0); 6599 ret = cache_block_group(block_group, 0);
6600 BUG_ON(ret < 0); 6600 BUG_ON(ret < 0);
6601 ret = 0; 6601 ret = 0;
6602 } 6602 }
6603 6603
6604 if (unlikely(block_group->cached == BTRFS_CACHE_ERROR)) 6604 if (unlikely(block_group->cached == BTRFS_CACHE_ERROR))
6605 goto loop; 6605 goto loop;
6606 if (unlikely(block_group->ro)) 6606 if (unlikely(block_group->ro))
6607 goto loop; 6607 goto loop;
6608 6608
6609 /* 6609 /*
6610 * Ok we want to try and use the cluster allocator, so 6610 * Ok we want to try and use the cluster allocator, so
6611 * lets look there 6611 * lets look there
6612 */ 6612 */
6613 if (last_ptr) { 6613 if (last_ptr) {
6614 struct btrfs_block_group_cache *used_block_group; 6614 struct btrfs_block_group_cache *used_block_group;
6615 unsigned long aligned_cluster; 6615 unsigned long aligned_cluster;
6616 /* 6616 /*
6617 * the refill lock keeps out other 6617 * the refill lock keeps out other
6618 * people trying to start a new cluster 6618 * people trying to start a new cluster
6619 */ 6619 */
6620 used_block_group = btrfs_lock_cluster(block_group, 6620 used_block_group = btrfs_lock_cluster(block_group,
6621 last_ptr, 6621 last_ptr,
6622 delalloc); 6622 delalloc);
6623 if (!used_block_group) 6623 if (!used_block_group)
6624 goto refill_cluster; 6624 goto refill_cluster;
6625 6625
6626 if (used_block_group != block_group && 6626 if (used_block_group != block_group &&
6627 (used_block_group->ro || 6627 (used_block_group->ro ||
6628 !block_group_bits(used_block_group, flags))) 6628 !block_group_bits(used_block_group, flags)))
6629 goto release_cluster; 6629 goto release_cluster;
6630 6630
6631 offset = btrfs_alloc_from_cluster(used_block_group, 6631 offset = btrfs_alloc_from_cluster(used_block_group,
6632 last_ptr, 6632 last_ptr,
6633 num_bytes, 6633 num_bytes,
6634 used_block_group->key.objectid, 6634 used_block_group->key.objectid,
6635 &max_extent_size); 6635 &max_extent_size);
6636 if (offset) { 6636 if (offset) {
6637 /* we have a block, we're done */ 6637 /* we have a block, we're done */
6638 spin_unlock(&last_ptr->refill_lock); 6638 spin_unlock(&last_ptr->refill_lock);
6639 trace_btrfs_reserve_extent_cluster(root, 6639 trace_btrfs_reserve_extent_cluster(root,
6640 used_block_group, 6640 used_block_group,
6641 search_start, num_bytes); 6641 search_start, num_bytes);
6642 if (used_block_group != block_group) { 6642 if (used_block_group != block_group) {
6643 btrfs_release_block_group(block_group, 6643 btrfs_release_block_group(block_group,
6644 delalloc); 6644 delalloc);
6645 block_group = used_block_group; 6645 block_group = used_block_group;
6646 } 6646 }
6647 goto checks; 6647 goto checks;
6648 } 6648 }
6649 6649
6650 WARN_ON(last_ptr->block_group != used_block_group); 6650 WARN_ON(last_ptr->block_group != used_block_group);
6651 release_cluster: 6651 release_cluster:
6652 /* If we are on LOOP_NO_EMPTY_SIZE, we can't 6652 /* If we are on LOOP_NO_EMPTY_SIZE, we can't
6653 * set up a new clusters, so lets just skip it 6653 * set up a new clusters, so lets just skip it
6654 * and let the allocator find whatever block 6654 * and let the allocator find whatever block
6655 * it can find. If we reach this point, we 6655 * it can find. If we reach this point, we
6656 * will have tried the cluster allocator 6656 * will have tried the cluster allocator
6657 * plenty of times and not have found 6657 * plenty of times and not have found
6658 * anything, so we are likely way too 6658 * anything, so we are likely way too
6659 * fragmented for the clustering stuff to find 6659 * fragmented for the clustering stuff to find
6660 * anything. 6660 * anything.
6661 * 6661 *
6662 * However, if the cluster is taken from the 6662 * However, if the cluster is taken from the
6663 * current block group, release the cluster 6663 * current block group, release the cluster
6664 * first, so that we stand a better chance of 6664 * first, so that we stand a better chance of
6665 * succeeding in the unclustered 6665 * succeeding in the unclustered
6666 * allocation. */ 6666 * allocation. */
6667 if (loop >= LOOP_NO_EMPTY_SIZE && 6667 if (loop >= LOOP_NO_EMPTY_SIZE &&
6668 used_block_group != block_group) { 6668 used_block_group != block_group) {
6669 spin_unlock(&last_ptr->refill_lock); 6669 spin_unlock(&last_ptr->refill_lock);
6670 btrfs_release_block_group(used_block_group, 6670 btrfs_release_block_group(used_block_group,
6671 delalloc); 6671 delalloc);
6672 goto unclustered_alloc; 6672 goto unclustered_alloc;
6673 } 6673 }
6674 6674
6675 /* 6675 /*
6676 * this cluster didn't work out, free it and 6676 * this cluster didn't work out, free it and
6677 * start over 6677 * start over
6678 */ 6678 */
6679 btrfs_return_cluster_to_free_space(NULL, last_ptr); 6679 btrfs_return_cluster_to_free_space(NULL, last_ptr);
6680 6680
6681 if (used_block_group != block_group) 6681 if (used_block_group != block_group)
6682 btrfs_release_block_group(used_block_group, 6682 btrfs_release_block_group(used_block_group,
6683 delalloc); 6683 delalloc);
6684 refill_cluster: 6684 refill_cluster:
6685 if (loop >= LOOP_NO_EMPTY_SIZE) { 6685 if (loop >= LOOP_NO_EMPTY_SIZE) {
6686 spin_unlock(&last_ptr->refill_lock); 6686 spin_unlock(&last_ptr->refill_lock);
6687 goto unclustered_alloc; 6687 goto unclustered_alloc;
6688 } 6688 }
6689 6689
6690 aligned_cluster = max_t(unsigned long, 6690 aligned_cluster = max_t(unsigned long,
6691 empty_cluster + empty_size, 6691 empty_cluster + empty_size,
6692 block_group->full_stripe_len); 6692 block_group->full_stripe_len);
6693 6693
6694 /* allocate a cluster in this block group */ 6694 /* allocate a cluster in this block group */
6695 ret = btrfs_find_space_cluster(root, block_group, 6695 ret = btrfs_find_space_cluster(root, block_group,
6696 last_ptr, search_start, 6696 last_ptr, search_start,
6697 num_bytes, 6697 num_bytes,
6698 aligned_cluster); 6698 aligned_cluster);
6699 if (ret == 0) { 6699 if (ret == 0) {
6700 /* 6700 /*
6701 * now pull our allocation out of this 6701 * now pull our allocation out of this
6702 * cluster 6702 * cluster
6703 */ 6703 */
6704 offset = btrfs_alloc_from_cluster(block_group, 6704 offset = btrfs_alloc_from_cluster(block_group,
6705 last_ptr, 6705 last_ptr,
6706 num_bytes, 6706 num_bytes,
6707 search_start, 6707 search_start,
6708 &max_extent_size); 6708 &max_extent_size);
6709 if (offset) { 6709 if (offset) {
6710 /* we found one, proceed */ 6710 /* we found one, proceed */
6711 spin_unlock(&last_ptr->refill_lock); 6711 spin_unlock(&last_ptr->refill_lock);
6712 trace_btrfs_reserve_extent_cluster(root, 6712 trace_btrfs_reserve_extent_cluster(root,
6713 block_group, search_start, 6713 block_group, search_start,
6714 num_bytes); 6714 num_bytes);
6715 goto checks; 6715 goto checks;
6716 } 6716 }
6717 } else if (!cached && loop > LOOP_CACHING_NOWAIT 6717 } else if (!cached && loop > LOOP_CACHING_NOWAIT
6718 && !failed_cluster_refill) { 6718 && !failed_cluster_refill) {
6719 spin_unlock(&last_ptr->refill_lock); 6719 spin_unlock(&last_ptr->refill_lock);
6720 6720
6721 failed_cluster_refill = true; 6721 failed_cluster_refill = true;
6722 wait_block_group_cache_progress(block_group, 6722 wait_block_group_cache_progress(block_group,
6723 num_bytes + empty_cluster + empty_size); 6723 num_bytes + empty_cluster + empty_size);
6724 goto have_block_group; 6724 goto have_block_group;
6725 } 6725 }
6726 6726
6727 /* 6727 /*
6728 * at this point we either didn't find a cluster 6728 * at this point we either didn't find a cluster
6729 * or we weren't able to allocate a block from our 6729 * or we weren't able to allocate a block from our
6730 * cluster. Free the cluster we've been trying 6730 * cluster. Free the cluster we've been trying
6731 * to use, and go to the next block group 6731 * to use, and go to the next block group
6732 */ 6732 */
6733 btrfs_return_cluster_to_free_space(NULL, last_ptr); 6733 btrfs_return_cluster_to_free_space(NULL, last_ptr);
6734 spin_unlock(&last_ptr->refill_lock); 6734 spin_unlock(&last_ptr->refill_lock);
6735 goto loop; 6735 goto loop;
6736 } 6736 }
6737 6737
6738 unclustered_alloc: 6738 unclustered_alloc:
6739 spin_lock(&block_group->free_space_ctl->tree_lock); 6739 spin_lock(&block_group->free_space_ctl->tree_lock);
6740 if (cached && 6740 if (cached &&
6741 block_group->free_space_ctl->free_space < 6741 block_group->free_space_ctl->free_space <
6742 num_bytes + empty_cluster + empty_size) { 6742 num_bytes + empty_cluster + empty_size) {
6743 if (block_group->free_space_ctl->free_space > 6743 if (block_group->free_space_ctl->free_space >
6744 max_extent_size) 6744 max_extent_size)
6745 max_extent_size = 6745 max_extent_size =
6746 block_group->free_space_ctl->free_space; 6746 block_group->free_space_ctl->free_space;
6747 spin_unlock(&block_group->free_space_ctl->tree_lock); 6747 spin_unlock(&block_group->free_space_ctl->tree_lock);
6748 goto loop; 6748 goto loop;
6749 } 6749 }
6750 spin_unlock(&block_group->free_space_ctl->tree_lock); 6750 spin_unlock(&block_group->free_space_ctl->tree_lock);
6751 6751
6752 offset = btrfs_find_space_for_alloc(block_group, search_start, 6752 offset = btrfs_find_space_for_alloc(block_group, search_start,
6753 num_bytes, empty_size, 6753 num_bytes, empty_size,
6754 &max_extent_size); 6754 &max_extent_size);
6755 /* 6755 /*
6756 * If we didn't find a chunk, and we haven't failed on this 6756 * If we didn't find a chunk, and we haven't failed on this
6757 * block group before, and this block group is in the middle of 6757 * block group before, and this block group is in the middle of
6758 * caching and we are ok with waiting, then go ahead and wait 6758 * caching and we are ok with waiting, then go ahead and wait
6759 * for progress to be made, and set failed_alloc to true. 6759 * for progress to be made, and set failed_alloc to true.
6760 * 6760 *
6761 * If failed_alloc is true then we've already waited on this 6761 * If failed_alloc is true then we've already waited on this
6762 * block group once and should move on to the next block group. 6762 * block group once and should move on to the next block group.
6763 */ 6763 */
6764 if (!offset && !failed_alloc && !cached && 6764 if (!offset && !failed_alloc && !cached &&
6765 loop > LOOP_CACHING_NOWAIT) { 6765 loop > LOOP_CACHING_NOWAIT) {
6766 wait_block_group_cache_progress(block_group, 6766 wait_block_group_cache_progress(block_group,
6767 num_bytes + empty_size); 6767 num_bytes + empty_size);
6768 failed_alloc = true; 6768 failed_alloc = true;
6769 goto have_block_group; 6769 goto have_block_group;
6770 } else if (!offset) { 6770 } else if (!offset) {
6771 if (!cached) 6771 if (!cached)
6772 have_caching_bg = true; 6772 have_caching_bg = true;
6773 goto loop; 6773 goto loop;
6774 } 6774 }
6775 checks: 6775 checks:
6776 search_start = ALIGN(offset, root->stripesize); 6776 search_start = ALIGN(offset, root->stripesize);
6777 6777
6778 /* move on to the next group */ 6778 /* move on to the next group */
6779 if (search_start + num_bytes > 6779 if (search_start + num_bytes >
6780 block_group->key.objectid + block_group->key.offset) { 6780 block_group->key.objectid + block_group->key.offset) {
6781 btrfs_add_free_space(block_group, offset, num_bytes); 6781 btrfs_add_free_space(block_group, offset, num_bytes);
6782 goto loop; 6782 goto loop;
6783 } 6783 }
6784 6784
6785 if (offset < search_start) 6785 if (offset < search_start)
6786 btrfs_add_free_space(block_group, offset, 6786 btrfs_add_free_space(block_group, offset,
6787 search_start - offset); 6787 search_start - offset);
6788 BUG_ON(offset > search_start); 6788 BUG_ON(offset > search_start);
6789 6789
6790 ret = btrfs_update_reserved_bytes(block_group, num_bytes, 6790 ret = btrfs_update_reserved_bytes(block_group, num_bytes,
6791 alloc_type, delalloc); 6791 alloc_type, delalloc);
6792 if (ret == -EAGAIN) { 6792 if (ret == -EAGAIN) {
6793 btrfs_add_free_space(block_group, offset, num_bytes); 6793 btrfs_add_free_space(block_group, offset, num_bytes);
6794 goto loop; 6794 goto loop;
6795 } 6795 }
6796 6796
6797 /* we are all good, lets return */ 6797 /* we are all good, lets return */
6798 ins->objectid = search_start; 6798 ins->objectid = search_start;
6799 ins->offset = num_bytes; 6799 ins->offset = num_bytes;
6800 6800
6801 trace_btrfs_reserve_extent(orig_root, block_group, 6801 trace_btrfs_reserve_extent(orig_root, block_group,
6802 search_start, num_bytes); 6802 search_start, num_bytes);
6803 btrfs_release_block_group(block_group, delalloc); 6803 btrfs_release_block_group(block_group, delalloc);
6804 break; 6804 break;
6805 loop: 6805 loop:
6806 failed_cluster_refill = false; 6806 failed_cluster_refill = false;
6807 failed_alloc = false; 6807 failed_alloc = false;
6808 BUG_ON(index != get_block_group_index(block_group)); 6808 BUG_ON(index != get_block_group_index(block_group));
6809 btrfs_release_block_group(block_group, delalloc); 6809 btrfs_release_block_group(block_group, delalloc);
6810 } 6810 }
6811 up_read(&space_info->groups_sem); 6811 up_read(&space_info->groups_sem);
6812 6812
6813 if (!ins->objectid && loop >= LOOP_CACHING_WAIT && have_caching_bg) 6813 if (!ins->objectid && loop >= LOOP_CACHING_WAIT && have_caching_bg)
6814 goto search; 6814 goto search;
6815 6815
6816 if (!ins->objectid && ++index < BTRFS_NR_RAID_TYPES) 6816 if (!ins->objectid && ++index < BTRFS_NR_RAID_TYPES)
6817 goto search; 6817 goto search;
6818 6818
6819 /* 6819 /*
6820 * LOOP_CACHING_NOWAIT, search partially cached block groups, kicking 6820 * LOOP_CACHING_NOWAIT, search partially cached block groups, kicking
6821 * caching kthreads as we move along 6821 * caching kthreads as we move along
6822 * LOOP_CACHING_WAIT, search everything, and wait if our bg is caching 6822 * LOOP_CACHING_WAIT, search everything, and wait if our bg is caching
6823 * LOOP_ALLOC_CHUNK, force a chunk allocation and try again 6823 * LOOP_ALLOC_CHUNK, force a chunk allocation and try again
6824 * LOOP_NO_EMPTY_SIZE, set empty_size and empty_cluster to 0 and try 6824 * LOOP_NO_EMPTY_SIZE, set empty_size and empty_cluster to 0 and try
6825 * again 6825 * again
6826 */ 6826 */
6827 if (!ins->objectid && loop < LOOP_NO_EMPTY_SIZE) { 6827 if (!ins->objectid && loop < LOOP_NO_EMPTY_SIZE) {
6828 index = 0; 6828 index = 0;
6829 loop++; 6829 loop++;
6830 if (loop == LOOP_ALLOC_CHUNK) { 6830 if (loop == LOOP_ALLOC_CHUNK) {
6831 struct btrfs_trans_handle *trans; 6831 struct btrfs_trans_handle *trans;
6832 int exist = 0; 6832 int exist = 0;
6833 6833
6834 trans = current->journal_info; 6834 trans = current->journal_info;
6835 if (trans) 6835 if (trans)
6836 exist = 1; 6836 exist = 1;
6837 else 6837 else
6838 trans = btrfs_join_transaction(root); 6838 trans = btrfs_join_transaction(root);
6839 6839
6840 if (IS_ERR(trans)) { 6840 if (IS_ERR(trans)) {
6841 ret = PTR_ERR(trans); 6841 ret = PTR_ERR(trans);
6842 goto out; 6842 goto out;
6843 } 6843 }
6844 6844
6845 ret = do_chunk_alloc(trans, root, flags, 6845 ret = do_chunk_alloc(trans, root, flags,
6846 CHUNK_ALLOC_FORCE); 6846 CHUNK_ALLOC_FORCE);
6847 /* 6847 /*
6848 * Do not bail out on ENOSPC since we 6848 * Do not bail out on ENOSPC since we
6849 * can do more things. 6849 * can do more things.
6850 */ 6850 */
6851 if (ret < 0 && ret != -ENOSPC) 6851 if (ret < 0 && ret != -ENOSPC)
6852 btrfs_abort_transaction(trans, 6852 btrfs_abort_transaction(trans,
6853 root, ret); 6853 root, ret);
6854 else 6854 else
6855 ret = 0; 6855 ret = 0;
6856 if (!exist) 6856 if (!exist)
6857 btrfs_end_transaction(trans, root); 6857 btrfs_end_transaction(trans, root);
6858 if (ret) 6858 if (ret)
6859 goto out; 6859 goto out;
6860 } 6860 }
6861 6861
6862 if (loop == LOOP_NO_EMPTY_SIZE) { 6862 if (loop == LOOP_NO_EMPTY_SIZE) {
6863 empty_size = 0; 6863 empty_size = 0;
6864 empty_cluster = 0; 6864 empty_cluster = 0;
6865 } 6865 }
6866 6866
6867 goto search; 6867 goto search;
6868 } else if (!ins->objectid) { 6868 } else if (!ins->objectid) {
6869 ret = -ENOSPC; 6869 ret = -ENOSPC;
6870 } else if (ins->objectid) { 6870 } else if (ins->objectid) {
6871 ret = 0; 6871 ret = 0;
6872 } 6872 }
6873 out: 6873 out:
6874 if (ret == -ENOSPC) 6874 if (ret == -ENOSPC)
6875 ins->offset = max_extent_size; 6875 ins->offset = max_extent_size;
6876 return ret; 6876 return ret;
6877 } 6877 }
6878 6878
6879 static void dump_space_info(struct btrfs_space_info *info, u64 bytes, 6879 static void dump_space_info(struct btrfs_space_info *info, u64 bytes,
6880 int dump_block_groups) 6880 int dump_block_groups)
6881 { 6881 {
6882 struct btrfs_block_group_cache *cache; 6882 struct btrfs_block_group_cache *cache;
6883 int index = 0; 6883 int index = 0;
6884 6884
6885 spin_lock(&info->lock); 6885 spin_lock(&info->lock);
6886 printk(KERN_INFO "BTRFS: space_info %llu has %llu free, is %sfull\n", 6886 printk(KERN_INFO "BTRFS: space_info %llu has %llu free, is %sfull\n",
6887 info->flags, 6887 info->flags,
6888 info->total_bytes - info->bytes_used - info->bytes_pinned - 6888 info->total_bytes - info->bytes_used - info->bytes_pinned -
6889 info->bytes_reserved - info->bytes_readonly, 6889 info->bytes_reserved - info->bytes_readonly,
6890 (info->full) ? "" : "not "); 6890 (info->full) ? "" : "not ");
6891 printk(KERN_INFO "BTRFS: space_info total=%llu, used=%llu, pinned=%llu, " 6891 printk(KERN_INFO "BTRFS: space_info total=%llu, used=%llu, pinned=%llu, "
6892 "reserved=%llu, may_use=%llu, readonly=%llu\n", 6892 "reserved=%llu, may_use=%llu, readonly=%llu\n",
6893 info->total_bytes, info->bytes_used, info->bytes_pinned, 6893 info->total_bytes, info->bytes_used, info->bytes_pinned,
6894 info->bytes_reserved, info->bytes_may_use, 6894 info->bytes_reserved, info->bytes_may_use,
6895 info->bytes_readonly); 6895 info->bytes_readonly);
6896 spin_unlock(&info->lock); 6896 spin_unlock(&info->lock);
6897 6897
6898 if (!dump_block_groups) 6898 if (!dump_block_groups)
6899 return; 6899 return;
6900 6900
6901 down_read(&info->groups_sem); 6901 down_read(&info->groups_sem);
6902 again: 6902 again:
6903 list_for_each_entry(cache, &info->block_groups[index], list) { 6903 list_for_each_entry(cache, &info->block_groups[index], list) {
6904 spin_lock(&cache->lock); 6904 spin_lock(&cache->lock);
6905 printk(KERN_INFO "BTRFS: " 6905 printk(KERN_INFO "BTRFS: "
6906 "block group %llu has %llu bytes, " 6906 "block group %llu has %llu bytes, "
6907 "%llu used %llu pinned %llu reserved %s\n", 6907 "%llu used %llu pinned %llu reserved %s\n",
6908 cache->key.objectid, cache->key.offset, 6908 cache->key.objectid, cache->key.offset,
6909 btrfs_block_group_used(&cache->item), cache->pinned, 6909 btrfs_block_group_used(&cache->item), cache->pinned,
6910 cache->reserved, cache->ro ? "[readonly]" : ""); 6910 cache->reserved, cache->ro ? "[readonly]" : "");
6911 btrfs_dump_free_space(cache, bytes); 6911 btrfs_dump_free_space(cache, bytes);
6912 spin_unlock(&cache->lock); 6912 spin_unlock(&cache->lock);
6913 } 6913 }
6914 if (++index < BTRFS_NR_RAID_TYPES) 6914 if (++index < BTRFS_NR_RAID_TYPES)
6915 goto again; 6915 goto again;
6916 up_read(&info->groups_sem); 6916 up_read(&info->groups_sem);
6917 } 6917 }
6918 6918
6919 int btrfs_reserve_extent(struct btrfs_root *root, 6919 int btrfs_reserve_extent(struct btrfs_root *root,
6920 u64 num_bytes, u64 min_alloc_size, 6920 u64 num_bytes, u64 min_alloc_size,
6921 u64 empty_size, u64 hint_byte, 6921 u64 empty_size, u64 hint_byte,
6922 struct btrfs_key *ins, int is_data, int delalloc) 6922 struct btrfs_key *ins, int is_data, int delalloc)
6923 { 6923 {
6924 bool final_tried = false; 6924 bool final_tried = false;
6925 u64 flags; 6925 u64 flags;
6926 int ret; 6926 int ret;
6927 6927
6928 flags = btrfs_get_alloc_profile(root, is_data); 6928 flags = btrfs_get_alloc_profile(root, is_data);
6929 again: 6929 again:
6930 WARN_ON(num_bytes < root->sectorsize); 6930 WARN_ON(num_bytes < root->sectorsize);
6931 ret = find_free_extent(root, num_bytes, empty_size, hint_byte, ins, 6931 ret = find_free_extent(root, num_bytes, empty_size, hint_byte, ins,
6932 flags, delalloc); 6932 flags, delalloc);
6933 6933
6934 if (ret == -ENOSPC) { 6934 if (ret == -ENOSPC) {
6935 if (!final_tried && ins->offset) { 6935 if (!final_tried && ins->offset) {
6936 num_bytes = min(num_bytes >> 1, ins->offset); 6936 num_bytes = min(num_bytes >> 1, ins->offset);
6937 num_bytes = round_down(num_bytes, root->sectorsize); 6937 num_bytes = round_down(num_bytes, root->sectorsize);
6938 num_bytes = max(num_bytes, min_alloc_size); 6938 num_bytes = max(num_bytes, min_alloc_size);
6939 if (num_bytes == min_alloc_size) 6939 if (num_bytes == min_alloc_size)
6940 final_tried = true; 6940 final_tried = true;
6941 goto again; 6941 goto again;
6942 } else if (btrfs_test_opt(root, ENOSPC_DEBUG)) { 6942 } else if (btrfs_test_opt(root, ENOSPC_DEBUG)) {
6943 struct btrfs_space_info *sinfo; 6943 struct btrfs_space_info *sinfo;
6944 6944
6945 sinfo = __find_space_info(root->fs_info, flags); 6945 sinfo = __find_space_info(root->fs_info, flags);
6946 btrfs_err(root->fs_info, "allocation failed flags %llu, wanted %llu", 6946 btrfs_err(root->fs_info, "allocation failed flags %llu, wanted %llu",
6947 flags, num_bytes); 6947 flags, num_bytes);
6948 if (sinfo) 6948 if (sinfo)
6949 dump_space_info(sinfo, num_bytes, 1); 6949 dump_space_info(sinfo, num_bytes, 1);
6950 } 6950 }
6951 } 6951 }
6952 6952
6953 return ret; 6953 return ret;
6954 } 6954 }
6955 6955
6956 static int __btrfs_free_reserved_extent(struct btrfs_root *root, 6956 static int __btrfs_free_reserved_extent(struct btrfs_root *root,
6957 u64 start, u64 len, 6957 u64 start, u64 len,
6958 int pin, int delalloc) 6958 int pin, int delalloc)
6959 { 6959 {
6960 struct btrfs_block_group_cache *cache; 6960 struct btrfs_block_group_cache *cache;
6961 int ret = 0; 6961 int ret = 0;
6962 6962
6963 cache = btrfs_lookup_block_group(root->fs_info, start); 6963 cache = btrfs_lookup_block_group(root->fs_info, start);
6964 if (!cache) { 6964 if (!cache) {
6965 btrfs_err(root->fs_info, "Unable to find block group for %llu", 6965 btrfs_err(root->fs_info, "Unable to find block group for %llu",
6966 start); 6966 start);
6967 return -ENOSPC; 6967 return -ENOSPC;
6968 } 6968 }
6969 6969
6970 if (btrfs_test_opt(root, DISCARD)) 6970 if (btrfs_test_opt(root, DISCARD))
6971 ret = btrfs_discard_extent(root, start, len, NULL); 6971 ret = btrfs_discard_extent(root, start, len, NULL);
6972 6972
6973 if (pin) 6973 if (pin)
6974 pin_down_extent(root, cache, start, len, 1); 6974 pin_down_extent(root, cache, start, len, 1);
6975 else { 6975 else {
6976 btrfs_add_free_space(cache, start, len); 6976 btrfs_add_free_space(cache, start, len);
6977 btrfs_update_reserved_bytes(cache, len, RESERVE_FREE, delalloc); 6977 btrfs_update_reserved_bytes(cache, len, RESERVE_FREE, delalloc);
6978 } 6978 }
6979 btrfs_put_block_group(cache); 6979 btrfs_put_block_group(cache);
6980 6980
6981 trace_btrfs_reserved_extent_free(root, start, len); 6981 trace_btrfs_reserved_extent_free(root, start, len);
6982 6982
6983 return ret; 6983 return ret;
6984 } 6984 }
6985 6985
6986 int btrfs_free_reserved_extent(struct btrfs_root *root, 6986 int btrfs_free_reserved_extent(struct btrfs_root *root,
6987 u64 start, u64 len, int delalloc) 6987 u64 start, u64 len, int delalloc)
6988 { 6988 {
6989 return __btrfs_free_reserved_extent(root, start, len, 0, delalloc); 6989 return __btrfs_free_reserved_extent(root, start, len, 0, delalloc);
6990 } 6990 }
6991 6991
6992 int btrfs_free_and_pin_reserved_extent(struct btrfs_root *root, 6992 int btrfs_free_and_pin_reserved_extent(struct btrfs_root *root,
6993 u64 start, u64 len) 6993 u64 start, u64 len)
6994 { 6994 {
6995 return __btrfs_free_reserved_extent(root, start, len, 1, 0); 6995 return __btrfs_free_reserved_extent(root, start, len, 1, 0);
6996 } 6996 }
6997 6997
6998 static int alloc_reserved_file_extent(struct btrfs_trans_handle *trans, 6998 static int alloc_reserved_file_extent(struct btrfs_trans_handle *trans,
6999 struct btrfs_root *root, 6999 struct btrfs_root *root,
7000 u64 parent, u64 root_objectid, 7000 u64 parent, u64 root_objectid,
7001 u64 flags, u64 owner, u64 offset, 7001 u64 flags, u64 owner, u64 offset,
7002 struct btrfs_key *ins, int ref_mod) 7002 struct btrfs_key *ins, int ref_mod)
7003 { 7003 {
7004 int ret; 7004 int ret;
7005 struct btrfs_fs_info *fs_info = root->fs_info; 7005 struct btrfs_fs_info *fs_info = root->fs_info;
7006 struct btrfs_extent_item *extent_item; 7006 struct btrfs_extent_item *extent_item;
7007 struct btrfs_extent_inline_ref *iref; 7007 struct btrfs_extent_inline_ref *iref;
7008 struct btrfs_path *path; 7008 struct btrfs_path *path;
7009 struct extent_buffer *leaf; 7009 struct extent_buffer *leaf;
7010 int type; 7010 int type;
7011 u32 size; 7011 u32 size;
7012 7012
7013 if (parent > 0) 7013 if (parent > 0)
7014 type = BTRFS_SHARED_DATA_REF_KEY; 7014 type = BTRFS_SHARED_DATA_REF_KEY;
7015 else 7015 else
7016 type = BTRFS_EXTENT_DATA_REF_KEY; 7016 type = BTRFS_EXTENT_DATA_REF_KEY;
7017 7017
7018 size = sizeof(*extent_item) + btrfs_extent_inline_ref_size(type); 7018 size = sizeof(*extent_item) + btrfs_extent_inline_ref_size(type);
7019 7019
7020 path = btrfs_alloc_path(); 7020 path = btrfs_alloc_path();
7021 if (!path) 7021 if (!path)
7022 return -ENOMEM; 7022 return -ENOMEM;
7023 7023
7024 path->leave_spinning = 1; 7024 path->leave_spinning = 1;
7025 ret = btrfs_insert_empty_item(trans, fs_info->extent_root, path, 7025 ret = btrfs_insert_empty_item(trans, fs_info->extent_root, path,
7026 ins, size); 7026 ins, size);
7027 if (ret) { 7027 if (ret) {
7028 btrfs_free_path(path); 7028 btrfs_free_path(path);
7029 return ret; 7029 return ret;
7030 } 7030 }
7031 7031
7032 leaf = path->nodes[0]; 7032 leaf = path->nodes[0];
7033 extent_item = btrfs_item_ptr(leaf, path->slots[0], 7033 extent_item = btrfs_item_ptr(leaf, path->slots[0],
7034 struct btrfs_extent_item); 7034 struct btrfs_extent_item);
7035 btrfs_set_extent_refs(leaf, extent_item, ref_mod); 7035 btrfs_set_extent_refs(leaf, extent_item, ref_mod);
7036 btrfs_set_extent_generation(leaf, extent_item, trans->transid); 7036 btrfs_set_extent_generation(leaf, extent_item, trans->transid);
7037 btrfs_set_extent_flags(leaf, extent_item, 7037 btrfs_set_extent_flags(leaf, extent_item,
7038 flags | BTRFS_EXTENT_FLAG_DATA); 7038 flags | BTRFS_EXTENT_FLAG_DATA);
7039 7039
7040 iref = (struct btrfs_extent_inline_ref *)(extent_item + 1); 7040 iref = (struct btrfs_extent_inline_ref *)(extent_item + 1);
7041 btrfs_set_extent_inline_ref_type(leaf, iref, type); 7041 btrfs_set_extent_inline_ref_type(leaf, iref, type);
7042 if (parent > 0) { 7042 if (parent > 0) {
7043 struct btrfs_shared_data_ref *ref; 7043 struct btrfs_shared_data_ref *ref;
7044 ref = (struct btrfs_shared_data_ref *)(iref + 1); 7044 ref = (struct btrfs_shared_data_ref *)(iref + 1);
7045 btrfs_set_extent_inline_ref_offset(leaf, iref, parent); 7045 btrfs_set_extent_inline_ref_offset(leaf, iref, parent);
7046 btrfs_set_shared_data_ref_count(leaf, ref, ref_mod); 7046 btrfs_set_shared_data_ref_count(leaf, ref, ref_mod);
7047 } else { 7047 } else {
7048 struct btrfs_extent_data_ref *ref; 7048 struct btrfs_extent_data_ref *ref;
7049 ref = (struct btrfs_extent_data_ref *)(&iref->offset); 7049 ref = (struct btrfs_extent_data_ref *)(&iref->offset);
7050 btrfs_set_extent_data_ref_root(leaf, ref, root_objectid); 7050 btrfs_set_extent_data_ref_root(leaf, ref, root_objectid);
7051 btrfs_set_extent_data_ref_objectid(leaf, ref, owner); 7051 btrfs_set_extent_data_ref_objectid(leaf, ref, owner);
7052 btrfs_set_extent_data_ref_offset(leaf, ref, offset); 7052 btrfs_set_extent_data_ref_offset(leaf, ref, offset);
7053 btrfs_set_extent_data_ref_count(leaf, ref, ref_mod); 7053 btrfs_set_extent_data_ref_count(leaf, ref, ref_mod);
7054 } 7054 }
7055 7055
7056 btrfs_mark_buffer_dirty(path->nodes[0]); 7056 btrfs_mark_buffer_dirty(path->nodes[0]);
7057 btrfs_free_path(path); 7057 btrfs_free_path(path);
7058 7058
7059 /* Always set parent to 0 here since its exclusive anyway. */ 7059 /* Always set parent to 0 here since its exclusive anyway. */
7060 ret = btrfs_qgroup_record_ref(trans, fs_info, root_objectid, 7060 ret = btrfs_qgroup_record_ref(trans, fs_info, root_objectid,
7061 ins->objectid, ins->offset, 7061 ins->objectid, ins->offset,
7062 BTRFS_QGROUP_OPER_ADD_EXCL, 0); 7062 BTRFS_QGROUP_OPER_ADD_EXCL, 0);
7063 if (ret) 7063 if (ret)
7064 return ret; 7064 return ret;
7065 7065
7066 ret = update_block_group(root, ins->objectid, ins->offset, 1); 7066 ret = update_block_group(root, ins->objectid, ins->offset, 1);
7067 if (ret) { /* -ENOENT, logic error */ 7067 if (ret) { /* -ENOENT, logic error */
7068 btrfs_err(fs_info, "update block group failed for %llu %llu", 7068 btrfs_err(fs_info, "update block group failed for %llu %llu",
7069 ins->objectid, ins->offset); 7069 ins->objectid, ins->offset);
7070 BUG(); 7070 BUG();
7071 } 7071 }
7072 trace_btrfs_reserved_extent_alloc(root, ins->objectid, ins->offset); 7072 trace_btrfs_reserved_extent_alloc(root, ins->objectid, ins->offset);
7073 return ret; 7073 return ret;
7074 } 7074 }
7075 7075
7076 static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans, 7076 static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans,
7077 struct btrfs_root *root, 7077 struct btrfs_root *root,
7078 u64 parent, u64 root_objectid, 7078 u64 parent, u64 root_objectid,
7079 u64 flags, struct btrfs_disk_key *key, 7079 u64 flags, struct btrfs_disk_key *key,
7080 int level, struct btrfs_key *ins, 7080 int level, struct btrfs_key *ins,
7081 int no_quota) 7081 int no_quota)
7082 { 7082 {
7083 int ret; 7083 int ret;
7084 struct btrfs_fs_info *fs_info = root->fs_info; 7084 struct btrfs_fs_info *fs_info = root->fs_info;
7085 struct btrfs_extent_item *extent_item; 7085 struct btrfs_extent_item *extent_item;
7086 struct btrfs_tree_block_info *block_info; 7086 struct btrfs_tree_block_info *block_info;
7087 struct btrfs_extent_inline_ref *iref; 7087 struct btrfs_extent_inline_ref *iref;
7088 struct btrfs_path *path; 7088 struct btrfs_path *path;
7089 struct extent_buffer *leaf; 7089 struct extent_buffer *leaf;
7090 u32 size = sizeof(*extent_item) + sizeof(*iref); 7090 u32 size = sizeof(*extent_item) + sizeof(*iref);
7091 u64 num_bytes = ins->offset; 7091 u64 num_bytes = ins->offset;
7092 bool skinny_metadata = btrfs_fs_incompat(root->fs_info, 7092 bool skinny_metadata = btrfs_fs_incompat(root->fs_info,
7093 SKINNY_METADATA); 7093 SKINNY_METADATA);
7094 7094
7095 if (!skinny_metadata) 7095 if (!skinny_metadata)
7096 size += sizeof(*block_info); 7096 size += sizeof(*block_info);
7097 7097
7098 path = btrfs_alloc_path(); 7098 path = btrfs_alloc_path();
7099 if (!path) { 7099 if (!path) {
7100 btrfs_free_and_pin_reserved_extent(root, ins->objectid, 7100 btrfs_free_and_pin_reserved_extent(root, ins->objectid,
7101 root->nodesize); 7101 root->nodesize);
7102 return -ENOMEM; 7102 return -ENOMEM;
7103 } 7103 }
7104 7104
7105 path->leave_spinning = 1; 7105 path->leave_spinning = 1;
7106 ret = btrfs_insert_empty_item(trans, fs_info->extent_root, path, 7106 ret = btrfs_insert_empty_item(trans, fs_info->extent_root, path,
7107 ins, size); 7107 ins, size);
7108 if (ret) { 7108 if (ret) {
7109 btrfs_free_and_pin_reserved_extent(root, ins->objectid, 7109 btrfs_free_and_pin_reserved_extent(root, ins->objectid,
7110 root->nodesize); 7110 root->nodesize);
7111 btrfs_free_path(path); 7111 btrfs_free_path(path);
7112 return ret; 7112 return ret;
7113 } 7113 }
7114 7114
7115 leaf = path->nodes[0]; 7115 leaf = path->nodes[0];
7116 extent_item = btrfs_item_ptr(leaf, path->slots[0], 7116 extent_item = btrfs_item_ptr(leaf, path->slots[0],
7117 struct btrfs_extent_item); 7117 struct btrfs_extent_item);
7118 btrfs_set_extent_refs(leaf, extent_item, 1); 7118 btrfs_set_extent_refs(leaf, extent_item, 1);
7119 btrfs_set_extent_generation(leaf, extent_item, trans->transid); 7119 btrfs_set_extent_generation(leaf, extent_item, trans->transid);
7120 btrfs_set_extent_flags(leaf, extent_item, 7120 btrfs_set_extent_flags(leaf, extent_item,
7121 flags | BTRFS_EXTENT_FLAG_TREE_BLOCK); 7121 flags | BTRFS_EXTENT_FLAG_TREE_BLOCK);
7122 7122
7123 if (skinny_metadata) { 7123 if (skinny_metadata) {
7124 iref = (struct btrfs_extent_inline_ref *)(extent_item + 1); 7124 iref = (struct btrfs_extent_inline_ref *)(extent_item + 1);
7125 num_bytes = root->nodesize; 7125 num_bytes = root->nodesize;
7126 } else { 7126 } else {
7127 block_info = (struct btrfs_tree_block_info *)(extent_item + 1); 7127 block_info = (struct btrfs_tree_block_info *)(extent_item + 1);
7128 btrfs_set_tree_block_key(leaf, block_info, key); 7128 btrfs_set_tree_block_key(leaf, block_info, key);
7129 btrfs_set_tree_block_level(leaf, block_info, level); 7129 btrfs_set_tree_block_level(leaf, block_info, level);
7130 iref = (struct btrfs_extent_inline_ref *)(block_info + 1); 7130 iref = (struct btrfs_extent_inline_ref *)(block_info + 1);
7131 } 7131 }
7132 7132
7133 if (parent > 0) { 7133 if (parent > 0) {
7134 BUG_ON(!(flags & BTRFS_BLOCK_FLAG_FULL_BACKREF)); 7134 BUG_ON(!(flags & BTRFS_BLOCK_FLAG_FULL_BACKREF));
7135 btrfs_set_extent_inline_ref_type(leaf, iref, 7135 btrfs_set_extent_inline_ref_type(leaf, iref,
7136 BTRFS_SHARED_BLOCK_REF_KEY); 7136 BTRFS_SHARED_BLOCK_REF_KEY);
7137 btrfs_set_extent_inline_ref_offset(leaf, iref, parent); 7137 btrfs_set_extent_inline_ref_offset(leaf, iref, parent);
7138 } else { 7138 } else {
7139 btrfs_set_extent_inline_ref_type(leaf, iref, 7139 btrfs_set_extent_inline_ref_type(leaf, iref,
7140 BTRFS_TREE_BLOCK_REF_KEY); 7140 BTRFS_TREE_BLOCK_REF_KEY);
7141 btrfs_set_extent_inline_ref_offset(leaf, iref, root_objectid); 7141 btrfs_set_extent_inline_ref_offset(leaf, iref, root_objectid);
7142 } 7142 }
7143 7143
7144 btrfs_mark_buffer_dirty(leaf); 7144 btrfs_mark_buffer_dirty(leaf);
7145 btrfs_free_path(path); 7145 btrfs_free_path(path);
7146 7146
7147 if (!no_quota) { 7147 if (!no_quota) {
7148 ret = btrfs_qgroup_record_ref(trans, fs_info, root_objectid, 7148 ret = btrfs_qgroup_record_ref(trans, fs_info, root_objectid,
7149 ins->objectid, num_bytes, 7149 ins->objectid, num_bytes,
7150 BTRFS_QGROUP_OPER_ADD_EXCL, 0); 7150 BTRFS_QGROUP_OPER_ADD_EXCL, 0);
7151 if (ret) 7151 if (ret)
7152 return ret; 7152 return ret;
7153 } 7153 }
7154 7154
7155 ret = update_block_group(root, ins->objectid, root->nodesize, 1); 7155 ret = update_block_group(root, ins->objectid, root->nodesize, 1);
7156 if (ret) { /* -ENOENT, logic error */ 7156 if (ret) { /* -ENOENT, logic error */
7157 btrfs_err(fs_info, "update block group failed for %llu %llu", 7157 btrfs_err(fs_info, "update block group failed for %llu %llu",
7158 ins->objectid, ins->offset); 7158 ins->objectid, ins->offset);
7159 BUG(); 7159 BUG();
7160 } 7160 }
7161 7161
7162 trace_btrfs_reserved_extent_alloc(root, ins->objectid, root->nodesize); 7162 trace_btrfs_reserved_extent_alloc(root, ins->objectid, root->nodesize);
7163 return ret; 7163 return ret;
7164 } 7164 }
7165 7165
7166 int btrfs_alloc_reserved_file_extent(struct btrfs_trans_handle *trans, 7166 int btrfs_alloc_reserved_file_extent(struct btrfs_trans_handle *trans,
7167 struct btrfs_root *root, 7167 struct btrfs_root *root,
7168 u64 root_objectid, u64 owner, 7168 u64 root_objectid, u64 owner,
7169 u64 offset, struct btrfs_key *ins) 7169 u64 offset, struct btrfs_key *ins)
7170 { 7170 {
7171 int ret; 7171 int ret;
7172 7172
7173 BUG_ON(root_objectid == BTRFS_TREE_LOG_OBJECTID); 7173 BUG_ON(root_objectid == BTRFS_TREE_LOG_OBJECTID);
7174 7174
7175 ret = btrfs_add_delayed_data_ref(root->fs_info, trans, ins->objectid, 7175 ret = btrfs_add_delayed_data_ref(root->fs_info, trans, ins->objectid,
7176 ins->offset, 0, 7176 ins->offset, 0,
7177 root_objectid, owner, offset, 7177 root_objectid, owner, offset,
7178 BTRFS_ADD_DELAYED_EXTENT, NULL, 0); 7178 BTRFS_ADD_DELAYED_EXTENT, NULL, 0);
7179 return ret; 7179 return ret;
7180 } 7180 }
7181 7181
7182 /* 7182 /*
7183 * this is used by the tree logging recovery code. It records that 7183 * this is used by the tree logging recovery code. It records that
7184 * an extent has been allocated and makes sure to clear the free 7184 * an extent has been allocated and makes sure to clear the free
7185 * space cache bits as well 7185 * space cache bits as well
7186 */ 7186 */
7187 int btrfs_alloc_logged_file_extent(struct btrfs_trans_handle *trans, 7187 int btrfs_alloc_logged_file_extent(struct btrfs_trans_handle *trans,
7188 struct btrfs_root *root, 7188 struct btrfs_root *root,
7189 u64 root_objectid, u64 owner, u64 offset, 7189 u64 root_objectid, u64 owner, u64 offset,
7190 struct btrfs_key *ins) 7190 struct btrfs_key *ins)
7191 { 7191 {
7192 int ret; 7192 int ret;
7193 struct btrfs_block_group_cache *block_group; 7193 struct btrfs_block_group_cache *block_group;
7194 7194
7195 /* 7195 /*
7196 * Mixed block groups will exclude before processing the log so we only 7196 * Mixed block groups will exclude before processing the log so we only
7197 * need to do the exlude dance if this fs isn't mixed. 7197 * need to do the exlude dance if this fs isn't mixed.
7198 */ 7198 */
7199 if (!btrfs_fs_incompat(root->fs_info, MIXED_GROUPS)) { 7199 if (!btrfs_fs_incompat(root->fs_info, MIXED_GROUPS)) {
7200 ret = __exclude_logged_extent(root, ins->objectid, ins->offset); 7200 ret = __exclude_logged_extent(root, ins->objectid, ins->offset);
7201 if (ret) 7201 if (ret)
7202 return ret; 7202 return ret;
7203 } 7203 }
7204 7204
7205 block_group = btrfs_lookup_block_group(root->fs_info, ins->objectid); 7205 block_group = btrfs_lookup_block_group(root->fs_info, ins->objectid);
7206 if (!block_group) 7206 if (!block_group)
7207 return -EINVAL; 7207 return -EINVAL;
7208 7208
7209 ret = btrfs_update_reserved_bytes(block_group, ins->offset, 7209 ret = btrfs_update_reserved_bytes(block_group, ins->offset,
7210 RESERVE_ALLOC_NO_ACCOUNT, 0); 7210 RESERVE_ALLOC_NO_ACCOUNT, 0);
7211 BUG_ON(ret); /* logic error */ 7211 BUG_ON(ret); /* logic error */
7212 ret = alloc_reserved_file_extent(trans, root, 0, root_objectid, 7212 ret = alloc_reserved_file_extent(trans, root, 0, root_objectid,
7213 0, owner, offset, ins, 1); 7213 0, owner, offset, ins, 1);
7214 btrfs_put_block_group(block_group); 7214 btrfs_put_block_group(block_group);
7215 return ret; 7215 return ret;
7216 } 7216 }
7217 7217
7218 static struct extent_buffer * 7218 static struct extent_buffer *
7219 btrfs_init_new_buffer(struct btrfs_trans_handle *trans, struct btrfs_root *root, 7219 btrfs_init_new_buffer(struct btrfs_trans_handle *trans, struct btrfs_root *root,
7220 u64 bytenr, u32 blocksize, int level) 7220 u64 bytenr, u32 blocksize, int level)
7221 { 7221 {
7222 struct extent_buffer *buf; 7222 struct extent_buffer *buf;
7223 7223
7224 buf = btrfs_find_create_tree_block(root, bytenr, blocksize); 7224 buf = btrfs_find_create_tree_block(root, bytenr, blocksize);
7225 if (!buf) 7225 if (!buf)
7226 return ERR_PTR(-ENOMEM); 7226 return ERR_PTR(-ENOMEM);
7227 btrfs_set_header_generation(buf, trans->transid); 7227 btrfs_set_header_generation(buf, trans->transid);
7228 btrfs_set_buffer_lockdep_class(root->root_key.objectid, buf, level); 7228 btrfs_set_buffer_lockdep_class(root->root_key.objectid, buf, level);
7229 btrfs_tree_lock(buf); 7229 btrfs_tree_lock(buf);
7230 clean_tree_block(trans, root, buf); 7230 clean_tree_block(trans, root, buf);
7231 clear_bit(EXTENT_BUFFER_STALE, &buf->bflags); 7231 clear_bit(EXTENT_BUFFER_STALE, &buf->bflags);
7232 7232
7233 btrfs_set_lock_blocking(buf); 7233 btrfs_set_lock_blocking(buf);
7234 btrfs_set_buffer_uptodate(buf); 7234 btrfs_set_buffer_uptodate(buf);
7235 7235
7236 if (root->root_key.objectid == BTRFS_TREE_LOG_OBJECTID) { 7236 if (root->root_key.objectid == BTRFS_TREE_LOG_OBJECTID) {
7237 buf->log_index = root->log_transid % 2; 7237 buf->log_index = root->log_transid % 2;
7238 /* 7238 /*
7239 * we allow two log transactions at a time, use different 7239 * we allow two log transactions at a time, use different
7240 * EXENT bit to differentiate dirty pages. 7240 * EXENT bit to differentiate dirty pages.
7241 */ 7241 */
7242 if (buf->log_index == 0) 7242 if (buf->log_index == 0)
7243 set_extent_dirty(&root->dirty_log_pages, buf->start, 7243 set_extent_dirty(&root->dirty_log_pages, buf->start,
7244 buf->start + buf->len - 1, GFP_NOFS); 7244 buf->start + buf->len - 1, GFP_NOFS);
7245 else 7245 else
7246 set_extent_new(&root->dirty_log_pages, buf->start, 7246 set_extent_new(&root->dirty_log_pages, buf->start,
7247 buf->start + buf->len - 1, GFP_NOFS); 7247 buf->start + buf->len - 1, GFP_NOFS);
7248 } else { 7248 } else {
7249 buf->log_index = -1; 7249 buf->log_index = -1;
7250 set_extent_dirty(&trans->transaction->dirty_pages, buf->start, 7250 set_extent_dirty(&trans->transaction->dirty_pages, buf->start,
7251 buf->start + buf->len - 1, GFP_NOFS); 7251 buf->start + buf->len - 1, GFP_NOFS);
7252 } 7252 }
7253 trans->blocks_used++; 7253 trans->blocks_used++;
7254 /* this returns a buffer locked for blocking */ 7254 /* this returns a buffer locked for blocking */
7255 return buf; 7255 return buf;
7256 } 7256 }
7257 7257
7258 static struct btrfs_block_rsv * 7258 static struct btrfs_block_rsv *
7259 use_block_rsv(struct btrfs_trans_handle *trans, 7259 use_block_rsv(struct btrfs_trans_handle *trans,
7260 struct btrfs_root *root, u32 blocksize) 7260 struct btrfs_root *root, u32 blocksize)
7261 { 7261 {
7262 struct btrfs_block_rsv *block_rsv; 7262 struct btrfs_block_rsv *block_rsv;
7263 struct btrfs_block_rsv *global_rsv = &root->fs_info->global_block_rsv; 7263 struct btrfs_block_rsv *global_rsv = &root->fs_info->global_block_rsv;
7264 int ret; 7264 int ret;
7265 bool global_updated = false; 7265 bool global_updated = false;
7266 7266
7267 block_rsv = get_block_rsv(trans, root); 7267 block_rsv = get_block_rsv(trans, root);
7268 7268
7269 if (unlikely(block_rsv->size == 0)) 7269 if (unlikely(block_rsv->size == 0))
7270 goto try_reserve; 7270 goto try_reserve;
7271 again: 7271 again:
7272 ret = block_rsv_use_bytes(block_rsv, blocksize); 7272 ret = block_rsv_use_bytes(block_rsv, blocksize);
7273 if (!ret) 7273 if (!ret)
7274 return block_rsv; 7274 return block_rsv;
7275 7275
7276 if (block_rsv->failfast) 7276 if (block_rsv->failfast)
7277 return ERR_PTR(ret); 7277 return ERR_PTR(ret);
7278 7278
7279 if (block_rsv->type == BTRFS_BLOCK_RSV_GLOBAL && !global_updated) { 7279 if (block_rsv->type == BTRFS_BLOCK_RSV_GLOBAL && !global_updated) {
7280 global_updated = true; 7280 global_updated = true;
7281 update_global_block_rsv(root->fs_info); 7281 update_global_block_rsv(root->fs_info);
7282 goto again; 7282 goto again;
7283 } 7283 }
7284 7284
7285 if (btrfs_test_opt(root, ENOSPC_DEBUG)) { 7285 if (btrfs_test_opt(root, ENOSPC_DEBUG)) {
7286 static DEFINE_RATELIMIT_STATE(_rs, 7286 static DEFINE_RATELIMIT_STATE(_rs,
7287 DEFAULT_RATELIMIT_INTERVAL * 10, 7287 DEFAULT_RATELIMIT_INTERVAL * 10,
7288 /*DEFAULT_RATELIMIT_BURST*/ 1); 7288 /*DEFAULT_RATELIMIT_BURST*/ 1);
7289 if (__ratelimit(&_rs)) 7289 if (__ratelimit(&_rs))
7290 WARN(1, KERN_DEBUG 7290 WARN(1, KERN_DEBUG
7291 "BTRFS: block rsv returned %d\n", ret); 7291 "BTRFS: block rsv returned %d\n", ret);
7292 } 7292 }
7293 try_reserve: 7293 try_reserve:
7294 ret = reserve_metadata_bytes(root, block_rsv, blocksize, 7294 ret = reserve_metadata_bytes(root, block_rsv, blocksize,
7295 BTRFS_RESERVE_NO_FLUSH); 7295 BTRFS_RESERVE_NO_FLUSH);
7296 if (!ret) 7296 if (!ret)
7297 return block_rsv; 7297 return block_rsv;
7298 /* 7298 /*
7299 * If we couldn't reserve metadata bytes try and use some from 7299 * If we couldn't reserve metadata bytes try and use some from
7300 * the global reserve if its space type is the same as the global 7300 * the global reserve if its space type is the same as the global
7301 * reservation. 7301 * reservation.
7302 */ 7302 */
7303 if (block_rsv->type != BTRFS_BLOCK_RSV_GLOBAL && 7303 if (block_rsv->type != BTRFS_BLOCK_RSV_GLOBAL &&
7304 block_rsv->space_info == global_rsv->space_info) { 7304 block_rsv->space_info == global_rsv->space_info) {
7305 ret = block_rsv_use_bytes(global_rsv, blocksize); 7305 ret = block_rsv_use_bytes(global_rsv, blocksize);
7306 if (!ret) 7306 if (!ret)
7307 return global_rsv; 7307 return global_rsv;
7308 } 7308 }
7309 return ERR_PTR(ret); 7309 return ERR_PTR(ret);
7310 } 7310 }
7311 7311
7312 static void unuse_block_rsv(struct btrfs_fs_info *fs_info, 7312 static void unuse_block_rsv(struct btrfs_fs_info *fs_info,
7313 struct btrfs_block_rsv *block_rsv, u32 blocksize) 7313 struct btrfs_block_rsv *block_rsv, u32 blocksize)
7314 { 7314 {
7315 block_rsv_add_bytes(block_rsv, blocksize, 0); 7315 block_rsv_add_bytes(block_rsv, blocksize, 0);
7316 block_rsv_release_bytes(fs_info, block_rsv, NULL, 0); 7316 block_rsv_release_bytes(fs_info, block_rsv, NULL, 0);
7317 } 7317 }
7318 7318
7319 /* 7319 /*
7320 * finds a free extent and does all the dirty work required for allocation 7320 * finds a free extent and does all the dirty work required for allocation
7321 * returns the key for the extent through ins, and a tree buffer for 7321 * returns the key for the extent through ins, and a tree buffer for
7322 * the first block of the extent through buf. 7322 * the first block of the extent through buf.
7323 * 7323 *
7324 * returns the tree buffer or NULL. 7324 * returns the tree buffer or NULL.
7325 */ 7325 */
7326 struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans, 7326 struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
7327 struct btrfs_root *root, 7327 struct btrfs_root *root,
7328 u64 parent, u64 root_objectid, 7328 u64 parent, u64 root_objectid,
7329 struct btrfs_disk_key *key, int level, 7329 struct btrfs_disk_key *key, int level,
7330 u64 hint, u64 empty_size) 7330 u64 hint, u64 empty_size)
7331 { 7331 {
7332 struct btrfs_key ins; 7332 struct btrfs_key ins;
7333 struct btrfs_block_rsv *block_rsv; 7333 struct btrfs_block_rsv *block_rsv;
7334 struct extent_buffer *buf; 7334 struct extent_buffer *buf;
7335 u64 flags = 0; 7335 u64 flags = 0;
7336 int ret; 7336 int ret;
7337 u32 blocksize = root->nodesize; 7337 u32 blocksize = root->nodesize;
7338 bool skinny_metadata = btrfs_fs_incompat(root->fs_info, 7338 bool skinny_metadata = btrfs_fs_incompat(root->fs_info,
7339 SKINNY_METADATA); 7339 SKINNY_METADATA);
7340 7340
7341 if (btrfs_test_is_dummy_root(root)) { 7341 if (btrfs_test_is_dummy_root(root)) {
7342 buf = btrfs_init_new_buffer(trans, root, root->alloc_bytenr, 7342 buf = btrfs_init_new_buffer(trans, root, root->alloc_bytenr,
7343 blocksize, level); 7343 blocksize, level);
7344 if (!IS_ERR(buf)) 7344 if (!IS_ERR(buf))
7345 root->alloc_bytenr += blocksize; 7345 root->alloc_bytenr += blocksize;
7346 return buf; 7346 return buf;
7347 } 7347 }
7348 7348
7349 block_rsv = use_block_rsv(trans, root, blocksize); 7349 block_rsv = use_block_rsv(trans, root, blocksize);
7350 if (IS_ERR(block_rsv)) 7350 if (IS_ERR(block_rsv))
7351 return ERR_CAST(block_rsv); 7351 return ERR_CAST(block_rsv);
7352 7352
7353 ret = btrfs_reserve_extent(root, blocksize, blocksize, 7353 ret = btrfs_reserve_extent(root, blocksize, blocksize,
7354 empty_size, hint, &ins, 0, 0); 7354 empty_size, hint, &ins, 0, 0);
7355 if (ret) { 7355 if (ret) {
7356 unuse_block_rsv(root->fs_info, block_rsv, blocksize); 7356 unuse_block_rsv(root->fs_info, block_rsv, blocksize);
7357 return ERR_PTR(ret); 7357 return ERR_PTR(ret);
7358 } 7358 }
7359 7359
7360 buf = btrfs_init_new_buffer(trans, root, ins.objectid, 7360 buf = btrfs_init_new_buffer(trans, root, ins.objectid,
7361 blocksize, level); 7361 blocksize, level);
7362 BUG_ON(IS_ERR(buf)); /* -ENOMEM */ 7362 BUG_ON(IS_ERR(buf)); /* -ENOMEM */
7363 7363
7364 if (root_objectid == BTRFS_TREE_RELOC_OBJECTID) { 7364 if (root_objectid == BTRFS_TREE_RELOC_OBJECTID) {
7365 if (parent == 0) 7365 if (parent == 0)
7366 parent = ins.objectid; 7366 parent = ins.objectid;
7367 flags |= BTRFS_BLOCK_FLAG_FULL_BACKREF; 7367 flags |= BTRFS_BLOCK_FLAG_FULL_BACKREF;
7368 } else 7368 } else
7369 BUG_ON(parent > 0); 7369 BUG_ON(parent > 0);
7370 7370
7371 if (root_objectid != BTRFS_TREE_LOG_OBJECTID) { 7371 if (root_objectid != BTRFS_TREE_LOG_OBJECTID) {
7372 struct btrfs_delayed_extent_op *extent_op; 7372 struct btrfs_delayed_extent_op *extent_op;
7373 extent_op = btrfs_alloc_delayed_extent_op(); 7373 extent_op = btrfs_alloc_delayed_extent_op();
7374 BUG_ON(!extent_op); /* -ENOMEM */ 7374 BUG_ON(!extent_op); /* -ENOMEM */
7375 if (key) 7375 if (key)
7376 memcpy(&extent_op->key, key, sizeof(extent_op->key)); 7376 memcpy(&extent_op->key, key, sizeof(extent_op->key));
7377 else 7377 else
7378 memset(&extent_op->key, 0, sizeof(extent_op->key)); 7378 memset(&extent_op->key, 0, sizeof(extent_op->key));
7379 extent_op->flags_to_set = flags; 7379 extent_op->flags_to_set = flags;
7380 if (skinny_metadata) 7380 if (skinny_metadata)
7381 extent_op->update_key = 0; 7381 extent_op->update_key = 0;
7382 else 7382 else
7383 extent_op->update_key = 1; 7383 extent_op->update_key = 1;
7384 extent_op->update_flags = 1; 7384 extent_op->update_flags = 1;
7385 extent_op->is_data = 0; 7385 extent_op->is_data = 0;
7386 extent_op->level = level; 7386 extent_op->level = level;
7387 7387
7388 ret = btrfs_add_delayed_tree_ref(root->fs_info, trans, 7388 ret = btrfs_add_delayed_tree_ref(root->fs_info, trans,
7389 ins.objectid, 7389 ins.objectid,
7390 ins.offset, parent, root_objectid, 7390 ins.offset, parent, root_objectid,
7391 level, BTRFS_ADD_DELAYED_EXTENT, 7391 level, BTRFS_ADD_DELAYED_EXTENT,
7392 extent_op, 0); 7392 extent_op, 0);
7393 BUG_ON(ret); /* -ENOMEM */ 7393 BUG_ON(ret); /* -ENOMEM */
7394 } 7394 }
7395 return buf; 7395 return buf;
7396 } 7396 }
7397 7397
7398 struct walk_control { 7398 struct walk_control {
7399 u64 refs[BTRFS_MAX_LEVEL]; 7399 u64 refs[BTRFS_MAX_LEVEL];
7400 u64 flags[BTRFS_MAX_LEVEL]; 7400 u64 flags[BTRFS_MAX_LEVEL];
7401 struct btrfs_key update_progress; 7401 struct btrfs_key update_progress;
7402 int stage; 7402 int stage;
7403 int level; 7403 int level;
7404 int shared_level; 7404 int shared_level;
7405 int update_ref; 7405 int update_ref;
7406 int keep_locks; 7406 int keep_locks;
7407 int reada_slot; 7407 int reada_slot;
7408 int reada_count; 7408 int reada_count;
7409 int for_reloc; 7409 int for_reloc;
7410 }; 7410 };
7411 7411
7412 #define DROP_REFERENCE 1 7412 #define DROP_REFERENCE 1
7413 #define UPDATE_BACKREF 2 7413 #define UPDATE_BACKREF 2
7414 7414
7415 static noinline void reada_walk_down(struct btrfs_trans_handle *trans, 7415 static noinline void reada_walk_down(struct btrfs_trans_handle *trans,
7416 struct btrfs_root *root, 7416 struct btrfs_root *root,
7417 struct walk_control *wc, 7417 struct walk_control *wc,
7418 struct btrfs_path *path) 7418 struct btrfs_path *path)
7419 { 7419 {
7420 u64 bytenr; 7420 u64 bytenr;
7421 u64 generation; 7421 u64 generation;
7422 u64 refs; 7422 u64 refs;
7423 u64 flags; 7423 u64 flags;
7424 u32 nritems; 7424 u32 nritems;
7425 u32 blocksize; 7425 u32 blocksize;
7426 struct btrfs_key key; 7426 struct btrfs_key key;
7427 struct extent_buffer *eb; 7427 struct extent_buffer *eb;
7428 int ret; 7428 int ret;
7429 int slot; 7429 int slot;
7430 int nread = 0; 7430 int nread = 0;
7431 7431
7432 if (path->slots[wc->level] < wc->reada_slot) { 7432 if (path->slots[wc->level] < wc->reada_slot) {
7433 wc->reada_count = wc->reada_count * 2 / 3; 7433 wc->reada_count = wc->reada_count * 2 / 3;
7434 wc->reada_count = max(wc->reada_count, 2); 7434 wc->reada_count = max(wc->reada_count, 2);
7435 } else { 7435 } else {
7436 wc->reada_count = wc->reada_count * 3 / 2; 7436 wc->reada_count = wc->reada_count * 3 / 2;
7437 wc->reada_count = min_t(int, wc->reada_count, 7437 wc->reada_count = min_t(int, wc->reada_count,
7438 BTRFS_NODEPTRS_PER_BLOCK(root)); 7438 BTRFS_NODEPTRS_PER_BLOCK(root));
7439 } 7439 }
7440 7440
7441 eb = path->nodes[wc->level]; 7441 eb = path->nodes[wc->level];
7442 nritems = btrfs_header_nritems(eb); 7442 nritems = btrfs_header_nritems(eb);
7443 blocksize = root->nodesize; 7443 blocksize = root->nodesize;
7444 7444
7445 for (slot = path->slots[wc->level]; slot < nritems; slot++) { 7445 for (slot = path->slots[wc->level]; slot < nritems; slot++) {
7446 if (nread >= wc->reada_count) 7446 if (nread >= wc->reada_count)
7447 break; 7447 break;
7448 7448
7449 cond_resched(); 7449 cond_resched();
7450 bytenr = btrfs_node_blockptr(eb, slot); 7450 bytenr = btrfs_node_blockptr(eb, slot);
7451 generation = btrfs_node_ptr_generation(eb, slot); 7451 generation = btrfs_node_ptr_generation(eb, slot);
7452 7452
7453 if (slot == path->slots[wc->level]) 7453 if (slot == path->slots[wc->level])
7454 goto reada; 7454 goto reada;
7455 7455
7456 if (wc->stage == UPDATE_BACKREF && 7456 if (wc->stage == UPDATE_BACKREF &&
7457 generation <= root->root_key.offset) 7457 generation <= root->root_key.offset)
7458 continue; 7458 continue;
7459 7459
7460 /* We don't lock the tree block, it's OK to be racy here */ 7460 /* We don't lock the tree block, it's OK to be racy here */
7461 ret = btrfs_lookup_extent_info(trans, root, bytenr, 7461 ret = btrfs_lookup_extent_info(trans, root, bytenr,
7462 wc->level - 1, 1, &refs, 7462 wc->level - 1, 1, &refs,
7463 &flags); 7463 &flags);
7464 /* We don't care about errors in readahead. */ 7464 /* We don't care about errors in readahead. */
7465 if (ret < 0) 7465 if (ret < 0)
7466 continue; 7466 continue;
7467 BUG_ON(refs == 0); 7467 BUG_ON(refs == 0);
7468 7468
7469 if (wc->stage == DROP_REFERENCE) { 7469 if (wc->stage == DROP_REFERENCE) {
7470 if (refs == 1) 7470 if (refs == 1)
7471 goto reada; 7471 goto reada;
7472 7472
7473 if (wc->level == 1 && 7473 if (wc->level == 1 &&
7474 (flags & BTRFS_BLOCK_FLAG_FULL_BACKREF)) 7474 (flags & BTRFS_BLOCK_FLAG_FULL_BACKREF))
7475 continue; 7475 continue;
7476 if (!wc->update_ref || 7476 if (!wc->update_ref ||
7477 generation <= root->root_key.offset) 7477 generation <= root->root_key.offset)
7478 continue; 7478 continue;
7479 btrfs_node_key_to_cpu(eb, &key, slot); 7479 btrfs_node_key_to_cpu(eb, &key, slot);
7480 ret = btrfs_comp_cpu_keys(&key, 7480 ret = btrfs_comp_cpu_keys(&key,
7481 &wc->update_progress); 7481 &wc->update_progress);
7482 if (ret < 0) 7482 if (ret < 0)
7483 continue; 7483 continue;
7484 } else { 7484 } else {
7485 if (wc->level == 1 && 7485 if (wc->level == 1 &&
7486 (flags & BTRFS_BLOCK_FLAG_FULL_BACKREF)) 7486 (flags & BTRFS_BLOCK_FLAG_FULL_BACKREF))
7487 continue; 7487 continue;
7488 } 7488 }
7489 reada: 7489 reada:
7490 readahead_tree_block(root, bytenr, blocksize); 7490 readahead_tree_block(root, bytenr, blocksize);
7491 nread++; 7491 nread++;
7492 } 7492 }
7493 wc->reada_slot = slot; 7493 wc->reada_slot = slot;
7494 } 7494 }
7495 7495
7496 static int account_leaf_items(struct btrfs_trans_handle *trans, 7496 static int account_leaf_items(struct btrfs_trans_handle *trans,
7497 struct btrfs_root *root, 7497 struct btrfs_root *root,
7498 struct extent_buffer *eb) 7498 struct extent_buffer *eb)
7499 { 7499 {
7500 int nr = btrfs_header_nritems(eb); 7500 int nr = btrfs_header_nritems(eb);
7501 int i, extent_type, ret; 7501 int i, extent_type, ret;
7502 struct btrfs_key key; 7502 struct btrfs_key key;
7503 struct btrfs_file_extent_item *fi; 7503 struct btrfs_file_extent_item *fi;
7504 u64 bytenr, num_bytes; 7504 u64 bytenr, num_bytes;
7505 7505
7506 for (i = 0; i < nr; i++) { 7506 for (i = 0; i < nr; i++) {
7507 btrfs_item_key_to_cpu(eb, &key, i); 7507 btrfs_item_key_to_cpu(eb, &key, i);
7508 7508
7509 if (key.type != BTRFS_EXTENT_DATA_KEY) 7509 if (key.type != BTRFS_EXTENT_DATA_KEY)
7510 continue; 7510 continue;
7511 7511
7512 fi = btrfs_item_ptr(eb, i, struct btrfs_file_extent_item); 7512 fi = btrfs_item_ptr(eb, i, struct btrfs_file_extent_item);
7513 /* filter out non qgroup-accountable extents */ 7513 /* filter out non qgroup-accountable extents */
7514 extent_type = btrfs_file_extent_type(eb, fi); 7514 extent_type = btrfs_file_extent_type(eb, fi);
7515 7515
7516 if (extent_type == BTRFS_FILE_EXTENT_INLINE) 7516 if (extent_type == BTRFS_FILE_EXTENT_INLINE)
7517 continue; 7517 continue;
7518 7518
7519 bytenr = btrfs_file_extent_disk_bytenr(eb, fi); 7519 bytenr = btrfs_file_extent_disk_bytenr(eb, fi);
7520 if (!bytenr) 7520 if (!bytenr)
7521 continue; 7521 continue;
7522 7522
7523 num_bytes = btrfs_file_extent_disk_num_bytes(eb, fi); 7523 num_bytes = btrfs_file_extent_disk_num_bytes(eb, fi);
7524 7524
7525 ret = btrfs_qgroup_record_ref(trans, root->fs_info, 7525 ret = btrfs_qgroup_record_ref(trans, root->fs_info,
7526 root->objectid, 7526 root->objectid,
7527 bytenr, num_bytes, 7527 bytenr, num_bytes,
7528 BTRFS_QGROUP_OPER_SUB_SUBTREE, 0); 7528 BTRFS_QGROUP_OPER_SUB_SUBTREE, 0);
7529 if (ret) 7529 if (ret)
7530 return ret; 7530 return ret;
7531 } 7531 }
7532 return 0; 7532 return 0;
7533 } 7533 }
7534 7534
7535 /* 7535 /*
7536 * Walk up the tree from the bottom, freeing leaves and any interior 7536 * Walk up the tree from the bottom, freeing leaves and any interior
7537 * nodes which have had all slots visited. If a node (leaf or 7537 * nodes which have had all slots visited. If a node (leaf or
7538 * interior) is freed, the node above it will have it's slot 7538 * interior) is freed, the node above it will have it's slot
7539 * incremented. The root node will never be freed. 7539 * incremented. The root node will never be freed.
7540 * 7540 *
7541 * At the end of this function, we should have a path which has all 7541 * At the end of this function, we should have a path which has all
7542 * slots incremented to the next position for a search. If we need to 7542 * slots incremented to the next position for a search. If we need to
7543 * read a new node it will be NULL and the node above it will have the 7543 * read a new node it will be NULL and the node above it will have the
7544 * correct slot selected for a later read. 7544 * correct slot selected for a later read.
7545 * 7545 *
7546 * If we increment the root nodes slot counter past the number of 7546 * If we increment the root nodes slot counter past the number of
7547 * elements, 1 is returned to signal completion of the search. 7547 * elements, 1 is returned to signal completion of the search.
7548 */ 7548 */
7549 static int adjust_slots_upwards(struct btrfs_root *root, 7549 static int adjust_slots_upwards(struct btrfs_root *root,
7550 struct btrfs_path *path, int root_level) 7550 struct btrfs_path *path, int root_level)
7551 { 7551 {
7552 int level = 0; 7552 int level = 0;
7553 int nr, slot; 7553 int nr, slot;
7554 struct extent_buffer *eb; 7554 struct extent_buffer *eb;
7555 7555
7556 if (root_level == 0) 7556 if (root_level == 0)
7557 return 1; 7557 return 1;
7558 7558
7559 while (level <= root_level) { 7559 while (level <= root_level) {
7560 eb = path->nodes[level]; 7560 eb = path->nodes[level];
7561 nr = btrfs_header_nritems(eb); 7561 nr = btrfs_header_nritems(eb);
7562 path->slots[level]++; 7562 path->slots[level]++;
7563 slot = path->slots[level]; 7563 slot = path->slots[level];
7564 if (slot >= nr || level == 0) { 7564 if (slot >= nr || level == 0) {
7565 /* 7565 /*
7566 * Don't free the root - we will detect this 7566 * Don't free the root - we will detect this
7567 * condition after our loop and return a 7567 * condition after our loop and return a
7568 * positive value for caller to stop walking the tree. 7568 * positive value for caller to stop walking the tree.
7569 */ 7569 */
7570 if (level != root_level) { 7570 if (level != root_level) {
7571 btrfs_tree_unlock_rw(eb, path->locks[level]); 7571 btrfs_tree_unlock_rw(eb, path->locks[level]);
7572 path->locks[level] = 0; 7572 path->locks[level] = 0;
7573 7573
7574 free_extent_buffer(eb); 7574 free_extent_buffer(eb);
7575 path->nodes[level] = NULL; 7575 path->nodes[level] = NULL;
7576 path->slots[level] = 0; 7576 path->slots[level] = 0;
7577 } 7577 }
7578 } else { 7578 } else {
7579 /* 7579 /*
7580 * We have a valid slot to walk back down 7580 * We have a valid slot to walk back down
7581 * from. Stop here so caller can process these 7581 * from. Stop here so caller can process these
7582 * new nodes. 7582 * new nodes.
7583 */ 7583 */
7584 break; 7584 break;
7585 } 7585 }
7586 7586
7587 level++; 7587 level++;
7588 } 7588 }
7589 7589
7590 eb = path->nodes[root_level]; 7590 eb = path->nodes[root_level];
7591 if (path->slots[root_level] >= btrfs_header_nritems(eb)) 7591 if (path->slots[root_level] >= btrfs_header_nritems(eb))
7592 return 1; 7592 return 1;
7593 7593
7594 return 0; 7594 return 0;
7595 } 7595 }
7596 7596
7597 /* 7597 /*
7598 * root_eb is the subtree root and is locked before this function is called. 7598 * root_eb is the subtree root and is locked before this function is called.
7599 */ 7599 */
7600 static int account_shared_subtree(struct btrfs_trans_handle *trans, 7600 static int account_shared_subtree(struct btrfs_trans_handle *trans,
7601 struct btrfs_root *root, 7601 struct btrfs_root *root,
7602 struct extent_buffer *root_eb, 7602 struct extent_buffer *root_eb,
7603 u64 root_gen, 7603 u64 root_gen,
7604 int root_level) 7604 int root_level)
7605 { 7605 {
7606 int ret = 0; 7606 int ret = 0;
7607 int level; 7607 int level;
7608 struct extent_buffer *eb = root_eb; 7608 struct extent_buffer *eb = root_eb;
7609 struct btrfs_path *path = NULL; 7609 struct btrfs_path *path = NULL;
7610 7610
7611 BUG_ON(root_level < 0 || root_level > BTRFS_MAX_LEVEL); 7611 BUG_ON(root_level < 0 || root_level > BTRFS_MAX_LEVEL);
7612 BUG_ON(root_eb == NULL); 7612 BUG_ON(root_eb == NULL);
7613 7613
7614 if (!root->fs_info->quota_enabled) 7614 if (!root->fs_info->quota_enabled)
7615 return 0; 7615 return 0;
7616 7616
7617 if (!extent_buffer_uptodate(root_eb)) { 7617 if (!extent_buffer_uptodate(root_eb)) {
7618 ret = btrfs_read_buffer(root_eb, root_gen); 7618 ret = btrfs_read_buffer(root_eb, root_gen);
7619 if (ret) 7619 if (ret)
7620 goto out; 7620 goto out;
7621 } 7621 }
7622 7622
7623 if (root_level == 0) { 7623 if (root_level == 0) {
7624 ret = account_leaf_items(trans, root, root_eb); 7624 ret = account_leaf_items(trans, root, root_eb);
7625 goto out; 7625 goto out;
7626 } 7626 }
7627 7627
7628 path = btrfs_alloc_path(); 7628 path = btrfs_alloc_path();
7629 if (!path) 7629 if (!path)
7630 return -ENOMEM; 7630 return -ENOMEM;
7631 7631
7632 /* 7632 /*
7633 * Walk down the tree. Missing extent blocks are filled in as 7633 * Walk down the tree. Missing extent blocks are filled in as
7634 * we go. Metadata is accounted every time we read a new 7634 * we go. Metadata is accounted every time we read a new
7635 * extent block. 7635 * extent block.
7636 * 7636 *
7637 * When we reach a leaf, we account for file extent items in it, 7637 * When we reach a leaf, we account for file extent items in it,
7638 * walk back up the tree (adjusting slot pointers as we go) 7638 * walk back up the tree (adjusting slot pointers as we go)
7639 * and restart the search process. 7639 * and restart the search process.
7640 */ 7640 */
7641 extent_buffer_get(root_eb); /* For path */ 7641 extent_buffer_get(root_eb); /* For path */
7642 path->nodes[root_level] = root_eb; 7642 path->nodes[root_level] = root_eb;
7643 path->slots[root_level] = 0; 7643 path->slots[root_level] = 0;
7644 path->locks[root_level] = 0; /* so release_path doesn't try to unlock */ 7644 path->locks[root_level] = 0; /* so release_path doesn't try to unlock */
7645 walk_down: 7645 walk_down:
7646 level = root_level; 7646 level = root_level;
7647 while (level >= 0) { 7647 while (level >= 0) {
7648 if (path->nodes[level] == NULL) { 7648 if (path->nodes[level] == NULL) {
7649 int parent_slot; 7649 int parent_slot;
7650 u64 child_gen; 7650 u64 child_gen;
7651 u64 child_bytenr; 7651 u64 child_bytenr;
7652 7652
7653 /* We need to get child blockptr/gen from 7653 /* We need to get child blockptr/gen from
7654 * parent before we can read it. */ 7654 * parent before we can read it. */
7655 eb = path->nodes[level + 1]; 7655 eb = path->nodes[level + 1];
7656 parent_slot = path->slots[level + 1]; 7656 parent_slot = path->slots[level + 1];
7657 child_bytenr = btrfs_node_blockptr(eb, parent_slot); 7657 child_bytenr = btrfs_node_blockptr(eb, parent_slot);
7658 child_gen = btrfs_node_ptr_generation(eb, parent_slot); 7658 child_gen = btrfs_node_ptr_generation(eb, parent_slot);
7659 7659
7660 eb = read_tree_block(root, child_bytenr, child_gen); 7660 eb = read_tree_block(root, child_bytenr, child_gen);
7661 if (!eb || !extent_buffer_uptodate(eb)) { 7661 if (!eb || !extent_buffer_uptodate(eb)) {
7662 ret = -EIO; 7662 ret = -EIO;
7663 goto out; 7663 goto out;
7664 } 7664 }
7665 7665
7666 path->nodes[level] = eb; 7666 path->nodes[level] = eb;
7667 path->slots[level] = 0; 7667 path->slots[level] = 0;
7668 7668
7669 btrfs_tree_read_lock(eb); 7669 btrfs_tree_read_lock(eb);
7670 btrfs_set_lock_blocking_rw(eb, BTRFS_READ_LOCK); 7670 btrfs_set_lock_blocking_rw(eb, BTRFS_READ_LOCK);
7671 path->locks[level] = BTRFS_READ_LOCK_BLOCKING; 7671 path->locks[level] = BTRFS_READ_LOCK_BLOCKING;
7672 7672
7673 ret = btrfs_qgroup_record_ref(trans, root->fs_info, 7673 ret = btrfs_qgroup_record_ref(trans, root->fs_info,
7674 root->objectid, 7674 root->objectid,
7675 child_bytenr, 7675 child_bytenr,
7676 root->nodesize, 7676 root->nodesize,
7677 BTRFS_QGROUP_OPER_SUB_SUBTREE, 7677 BTRFS_QGROUP_OPER_SUB_SUBTREE,
7678 0); 7678 0);
7679 if (ret) 7679 if (ret)
7680 goto out; 7680 goto out;
7681 7681
7682 } 7682 }
7683 7683
7684 if (level == 0) { 7684 if (level == 0) {
7685 ret = account_leaf_items(trans, root, path->nodes[level]); 7685 ret = account_leaf_items(trans, root, path->nodes[level]);
7686 if (ret) 7686 if (ret)
7687 goto out; 7687 goto out;
7688 7688
7689 /* Nonzero return here means we completed our search */ 7689 /* Nonzero return here means we completed our search */
7690 ret = adjust_slots_upwards(root, path, root_level); 7690 ret = adjust_slots_upwards(root, path, root_level);
7691 if (ret) 7691 if (ret)
7692 break; 7692 break;
7693 7693
7694 /* Restart search with new slots */ 7694 /* Restart search with new slots */
7695 goto walk_down; 7695 goto walk_down;
7696 } 7696 }
7697 7697
7698 level--; 7698 level--;
7699 } 7699 }
7700 7700
7701 ret = 0; 7701 ret = 0;
7702 out: 7702 out:
7703 btrfs_free_path(path); 7703 btrfs_free_path(path);
7704 7704
7705 return ret; 7705 return ret;
7706 } 7706 }
7707 7707
7708 /* 7708 /*
7709 * helper to process tree block while walking down the tree. 7709 * helper to process tree block while walking down the tree.
7710 * 7710 *
7711 * when wc->stage == UPDATE_BACKREF, this function updates 7711 * when wc->stage == UPDATE_BACKREF, this function updates
7712 * back refs for pointers in the block. 7712 * back refs for pointers in the block.
7713 * 7713 *
7714 * NOTE: return value 1 means we should stop walking down. 7714 * NOTE: return value 1 means we should stop walking down.
7715 */ 7715 */
7716 static noinline int walk_down_proc(struct btrfs_trans_handle *trans, 7716 static noinline int walk_down_proc(struct btrfs_trans_handle *trans,
7717 struct btrfs_root *root, 7717 struct btrfs_root *root,
7718 struct btrfs_path *path, 7718 struct btrfs_path *path,
7719 struct walk_control *wc, int lookup_info) 7719 struct walk_control *wc, int lookup_info)
7720 { 7720 {
7721 int level = wc->level; 7721 int level = wc->level;
7722 struct extent_buffer *eb = path->nodes[level]; 7722 struct extent_buffer *eb = path->nodes[level];
7723 u64 flag = BTRFS_BLOCK_FLAG_FULL_BACKREF; 7723 u64 flag = BTRFS_BLOCK_FLAG_FULL_BACKREF;
7724 int ret; 7724 int ret;
7725 7725
7726 if (wc->stage == UPDATE_BACKREF && 7726 if (wc->stage == UPDATE_BACKREF &&
7727 btrfs_header_owner(eb) != root->root_key.objectid) 7727 btrfs_header_owner(eb) != root->root_key.objectid)
7728 return 1; 7728 return 1;
7729 7729
7730 /* 7730 /*
7731 * when reference count of tree block is 1, it won't increase 7731 * when reference count of tree block is 1, it won't increase
7732 * again. once full backref flag is set, we never clear it. 7732 * again. once full backref flag is set, we never clear it.
7733 */ 7733 */
7734 if (lookup_info && 7734 if (lookup_info &&
7735 ((wc->stage == DROP_REFERENCE && wc->refs[level] != 1) || 7735 ((wc->stage == DROP_REFERENCE && wc->refs[level] != 1) ||
7736 (wc->stage == UPDATE_BACKREF && !(wc->flags[level] & flag)))) { 7736 (wc->stage == UPDATE_BACKREF && !(wc->flags[level] & flag)))) {
7737 BUG_ON(!path->locks[level]); 7737 BUG_ON(!path->locks[level]);
7738 ret = btrfs_lookup_extent_info(trans, root, 7738 ret = btrfs_lookup_extent_info(trans, root,
7739 eb->start, level, 1, 7739 eb->start, level, 1,
7740 &wc->refs[level], 7740 &wc->refs[level],
7741 &wc->flags[level]); 7741 &wc->flags[level]);
7742 BUG_ON(ret == -ENOMEM); 7742 BUG_ON(ret == -ENOMEM);
7743 if (ret) 7743 if (ret)
7744 return ret; 7744 return ret;
7745 BUG_ON(wc->refs[level] == 0); 7745 BUG_ON(wc->refs[level] == 0);
7746 } 7746 }
7747 7747
7748 if (wc->stage == DROP_REFERENCE) { 7748 if (wc->stage == DROP_REFERENCE) {
7749 if (wc->refs[level] > 1) 7749 if (wc->refs[level] > 1)
7750 return 1; 7750 return 1;
7751 7751
7752 if (path->locks[level] && !wc->keep_locks) { 7752 if (path->locks[level] && !wc->keep_locks) {
7753 btrfs_tree_unlock_rw(eb, path->locks[level]); 7753 btrfs_tree_unlock_rw(eb, path->locks[level]);
7754 path->locks[level] = 0; 7754 path->locks[level] = 0;
7755 } 7755 }
7756 return 0; 7756 return 0;
7757 } 7757 }
7758 7758
7759 /* wc->stage == UPDATE_BACKREF */ 7759 /* wc->stage == UPDATE_BACKREF */
7760 if (!(wc->flags[level] & flag)) { 7760 if (!(wc->flags[level] & flag)) {
7761 BUG_ON(!path->locks[level]); 7761 BUG_ON(!path->locks[level]);
7762 ret = btrfs_inc_ref(trans, root, eb, 1); 7762 ret = btrfs_inc_ref(trans, root, eb, 1);
7763 BUG_ON(ret); /* -ENOMEM */ 7763 BUG_ON(ret); /* -ENOMEM */
7764 ret = btrfs_dec_ref(trans, root, eb, 0); 7764 ret = btrfs_dec_ref(trans, root, eb, 0);
7765 BUG_ON(ret); /* -ENOMEM */ 7765 BUG_ON(ret); /* -ENOMEM */
7766 ret = btrfs_set_disk_extent_flags(trans, root, eb->start, 7766 ret = btrfs_set_disk_extent_flags(trans, root, eb->start,
7767 eb->len, flag, 7767 eb->len, flag,
7768 btrfs_header_level(eb), 0); 7768 btrfs_header_level(eb), 0);
7769 BUG_ON(ret); /* -ENOMEM */ 7769 BUG_ON(ret); /* -ENOMEM */
7770 wc->flags[level] |= flag; 7770 wc->flags[level] |= flag;
7771 } 7771 }
7772 7772
7773 /* 7773 /*
7774 * the block is shared by multiple trees, so it's not good to 7774 * the block is shared by multiple trees, so it's not good to
7775 * keep the tree lock 7775 * keep the tree lock
7776 */ 7776 */
7777 if (path->locks[level] && level > 0) { 7777 if (path->locks[level] && level > 0) {
7778 btrfs_tree_unlock_rw(eb, path->locks[level]); 7778 btrfs_tree_unlock_rw(eb, path->locks[level]);
7779 path->locks[level] = 0; 7779 path->locks[level] = 0;
7780 } 7780 }
7781 return 0; 7781 return 0;
7782 } 7782 }
7783 7783
7784 /* 7784 /*
7785 * helper to process tree block pointer. 7785 * helper to process tree block pointer.
7786 * 7786 *
7787 * when wc->stage == DROP_REFERENCE, this function checks 7787 * when wc->stage == DROP_REFERENCE, this function checks
7788 * reference count of the block pointed to. if the block 7788 * reference count of the block pointed to. if the block
7789 * is shared and we need update back refs for the subtree 7789 * is shared and we need update back refs for the subtree
7790 * rooted at the block, this function changes wc->stage to 7790 * rooted at the block, this function changes wc->stage to
7791 * UPDATE_BACKREF. if the block is shared and there is no 7791 * UPDATE_BACKREF. if the block is shared and there is no
7792 * need to update back, this function drops the reference 7792 * need to update back, this function drops the reference
7793 * to the block. 7793 * to the block.
7794 * 7794 *
7795 * NOTE: return value 1 means we should stop walking down. 7795 * NOTE: return value 1 means we should stop walking down.
7796 */ 7796 */
7797 static noinline int do_walk_down(struct btrfs_trans_handle *trans, 7797 static noinline int do_walk_down(struct btrfs_trans_handle *trans,
7798 struct btrfs_root *root, 7798 struct btrfs_root *root,
7799 struct btrfs_path *path, 7799 struct btrfs_path *path,
7800 struct walk_control *wc, int *lookup_info) 7800 struct walk_control *wc, int *lookup_info)
7801 { 7801 {
7802 u64 bytenr; 7802 u64 bytenr;
7803 u64 generation; 7803 u64 generation;
7804 u64 parent; 7804 u64 parent;
7805 u32 blocksize; 7805 u32 blocksize;
7806 struct btrfs_key key; 7806 struct btrfs_key key;
7807 struct extent_buffer *next; 7807 struct extent_buffer *next;
7808 int level = wc->level; 7808 int level = wc->level;
7809 int reada = 0; 7809 int reada = 0;
7810 int ret = 0; 7810 int ret = 0;
7811 bool need_account = false; 7811 bool need_account = false;
7812 7812
7813 generation = btrfs_node_ptr_generation(path->nodes[level], 7813 generation = btrfs_node_ptr_generation(path->nodes[level],
7814 path->slots[level]); 7814 path->slots[level]);
7815 /* 7815 /*
7816 * if the lower level block was created before the snapshot 7816 * if the lower level block was created before the snapshot
7817 * was created, we know there is no need to update back refs 7817 * was created, we know there is no need to update back refs
7818 * for the subtree 7818 * for the subtree
7819 */ 7819 */
7820 if (wc->stage == UPDATE_BACKREF && 7820 if (wc->stage == UPDATE_BACKREF &&
7821 generation <= root->root_key.offset) { 7821 generation <= root->root_key.offset) {
7822 *lookup_info = 1; 7822 *lookup_info = 1;
7823 return 1; 7823 return 1;
7824 } 7824 }
7825 7825
7826 bytenr = btrfs_node_blockptr(path->nodes[level], path->slots[level]); 7826 bytenr = btrfs_node_blockptr(path->nodes[level], path->slots[level]);
7827 blocksize = root->nodesize; 7827 blocksize = root->nodesize;
7828 7828
7829 next = btrfs_find_tree_block(root, bytenr); 7829 next = btrfs_find_tree_block(root, bytenr);
7830 if (!next) { 7830 if (!next) {
7831 next = btrfs_find_create_tree_block(root, bytenr, blocksize); 7831 next = btrfs_find_create_tree_block(root, bytenr, blocksize);
7832 if (!next) 7832 if (!next)
7833 return -ENOMEM; 7833 return -ENOMEM;
7834 btrfs_set_buffer_lockdep_class(root->root_key.objectid, next, 7834 btrfs_set_buffer_lockdep_class(root->root_key.objectid, next,
7835 level - 1); 7835 level - 1);
7836 reada = 1; 7836 reada = 1;
7837 } 7837 }
7838 btrfs_tree_lock(next); 7838 btrfs_tree_lock(next);
7839 btrfs_set_lock_blocking(next); 7839 btrfs_set_lock_blocking(next);
7840 7840
7841 ret = btrfs_lookup_extent_info(trans, root, bytenr, level - 1, 1, 7841 ret = btrfs_lookup_extent_info(trans, root, bytenr, level - 1, 1,
7842 &wc->refs[level - 1], 7842 &wc->refs[level - 1],
7843 &wc->flags[level - 1]); 7843 &wc->flags[level - 1]);
7844 if (ret < 0) { 7844 if (ret < 0) {
7845 btrfs_tree_unlock(next); 7845 btrfs_tree_unlock(next);
7846 return ret; 7846 return ret;
7847 } 7847 }
7848 7848
7849 if (unlikely(wc->refs[level - 1] == 0)) { 7849 if (unlikely(wc->refs[level - 1] == 0)) {
7850 btrfs_err(root->fs_info, "Missing references."); 7850 btrfs_err(root->fs_info, "Missing references.");
7851 BUG(); 7851 BUG();
7852 } 7852 }
7853 *lookup_info = 0; 7853 *lookup_info = 0;
7854 7854
7855 if (wc->stage == DROP_REFERENCE) { 7855 if (wc->stage == DROP_REFERENCE) {
7856 if (wc->refs[level - 1] > 1) { 7856 if (wc->refs[level - 1] > 1) {
7857 need_account = true; 7857 need_account = true;
7858 if (level == 1 && 7858 if (level == 1 &&
7859 (wc->flags[0] & BTRFS_BLOCK_FLAG_FULL_BACKREF)) 7859 (wc->flags[0] & BTRFS_BLOCK_FLAG_FULL_BACKREF))
7860 goto skip; 7860 goto skip;
7861 7861
7862 if (!wc->update_ref || 7862 if (!wc->update_ref ||
7863 generation <= root->root_key.offset) 7863 generation <= root->root_key.offset)
7864 goto skip; 7864 goto skip;
7865 7865
7866 btrfs_node_key_to_cpu(path->nodes[level], &key, 7866 btrfs_node_key_to_cpu(path->nodes[level], &key,
7867 path->slots[level]); 7867 path->slots[level]);
7868 ret = btrfs_comp_cpu_keys(&key, &wc->update_progress); 7868 ret = btrfs_comp_cpu_keys(&key, &wc->update_progress);
7869 if (ret < 0) 7869 if (ret < 0)
7870 goto skip; 7870 goto skip;
7871 7871
7872 wc->stage = UPDATE_BACKREF; 7872 wc->stage = UPDATE_BACKREF;
7873 wc->shared_level = level - 1; 7873 wc->shared_level = level - 1;
7874 } 7874 }
7875 } else { 7875 } else {
7876 if (level == 1 && 7876 if (level == 1 &&
7877 (wc->flags[0] & BTRFS_BLOCK_FLAG_FULL_BACKREF)) 7877 (wc->flags[0] & BTRFS_BLOCK_FLAG_FULL_BACKREF))
7878 goto skip; 7878 goto skip;
7879 } 7879 }
7880 7880
7881 if (!btrfs_buffer_uptodate(next, generation, 0)) { 7881 if (!btrfs_buffer_uptodate(next, generation, 0)) {
7882 btrfs_tree_unlock(next); 7882 btrfs_tree_unlock(next);
7883 free_extent_buffer(next); 7883 free_extent_buffer(next);
7884 next = NULL; 7884 next = NULL;
7885 *lookup_info = 1; 7885 *lookup_info = 1;
7886 } 7886 }
7887 7887
7888 if (!next) { 7888 if (!next) {
7889 if (reada && level == 1) 7889 if (reada && level == 1)
7890 reada_walk_down(trans, root, wc, path); 7890 reada_walk_down(trans, root, wc, path);
7891 next = read_tree_block(root, bytenr, generation); 7891 next = read_tree_block(root, bytenr, generation);
7892 if (!next || !extent_buffer_uptodate(next)) { 7892 if (!next || !extent_buffer_uptodate(next)) {
7893 free_extent_buffer(next); 7893 free_extent_buffer(next);
7894 return -EIO; 7894 return -EIO;
7895 } 7895 }
7896 btrfs_tree_lock(next); 7896 btrfs_tree_lock(next);
7897 btrfs_set_lock_blocking(next); 7897 btrfs_set_lock_blocking(next);
7898 } 7898 }
7899 7899
7900 level--; 7900 level--;
7901 BUG_ON(level != btrfs_header_level(next)); 7901 BUG_ON(level != btrfs_header_level(next));
7902 path->nodes[level] = next; 7902 path->nodes[level] = next;
7903 path->slots[level] = 0; 7903 path->slots[level] = 0;
7904 path->locks[level] = BTRFS_WRITE_LOCK_BLOCKING; 7904 path->locks[level] = BTRFS_WRITE_LOCK_BLOCKING;
7905 wc->level = level; 7905 wc->level = level;
7906 if (wc->level == 1) 7906 if (wc->level == 1)
7907 wc->reada_slot = 0; 7907 wc->reada_slot = 0;
7908 return 0; 7908 return 0;
7909 skip: 7909 skip:
7910 wc->refs[level - 1] = 0; 7910 wc->refs[level - 1] = 0;
7911 wc->flags[level - 1] = 0; 7911 wc->flags[level - 1] = 0;
7912 if (wc->stage == DROP_REFERENCE) { 7912 if (wc->stage == DROP_REFERENCE) {
7913 if (wc->flags[level] & BTRFS_BLOCK_FLAG_FULL_BACKREF) { 7913 if (wc->flags[level] & BTRFS_BLOCK_FLAG_FULL_BACKREF) {
7914 parent = path->nodes[level]->start; 7914 parent = path->nodes[level]->start;
7915 } else { 7915 } else {
7916 BUG_ON(root->root_key.objectid != 7916 BUG_ON(root->root_key.objectid !=
7917 btrfs_header_owner(path->nodes[level])); 7917 btrfs_header_owner(path->nodes[level]));
7918 parent = 0; 7918 parent = 0;
7919 } 7919 }
7920 7920
7921 if (need_account) { 7921 if (need_account) {
7922 ret = account_shared_subtree(trans, root, next, 7922 ret = account_shared_subtree(trans, root, next,
7923 generation, level - 1); 7923 generation, level - 1);
7924 if (ret) { 7924 if (ret) {
7925 printk_ratelimited(KERN_ERR "BTRFS: %s Error " 7925 printk_ratelimited(KERN_ERR "BTRFS: %s Error "
7926 "%d accounting shared subtree. Quota " 7926 "%d accounting shared subtree. Quota "
7927 "is out of sync, rescan required.\n", 7927 "is out of sync, rescan required.\n",
7928 root->fs_info->sb->s_id, ret); 7928 root->fs_info->sb->s_id, ret);
7929 } 7929 }
7930 } 7930 }
7931 ret = btrfs_free_extent(trans, root, bytenr, blocksize, parent, 7931 ret = btrfs_free_extent(trans, root, bytenr, blocksize, parent,
7932 root->root_key.objectid, level - 1, 0, 0); 7932 root->root_key.objectid, level - 1, 0, 0);
7933 BUG_ON(ret); /* -ENOMEM */ 7933 BUG_ON(ret); /* -ENOMEM */
7934 } 7934 }
7935 btrfs_tree_unlock(next); 7935 btrfs_tree_unlock(next);
7936 free_extent_buffer(next); 7936 free_extent_buffer(next);
7937 *lookup_info = 1; 7937 *lookup_info = 1;
7938 return 1; 7938 return 1;
7939 } 7939 }
7940 7940
7941 /* 7941 /*
7942 * helper to process tree block while walking up the tree. 7942 * helper to process tree block while walking up the tree.
7943 * 7943 *
7944 * when wc->stage == DROP_REFERENCE, this function drops 7944 * when wc->stage == DROP_REFERENCE, this function drops
7945 * reference count on the block. 7945 * reference count on the block.
7946 * 7946 *
7947 * when wc->stage == UPDATE_BACKREF, this function changes 7947 * when wc->stage == UPDATE_BACKREF, this function changes
7948 * wc->stage back to DROP_REFERENCE if we changed wc->stage 7948 * wc->stage back to DROP_REFERENCE if we changed wc->stage
7949 * to UPDATE_BACKREF previously while processing the block. 7949 * to UPDATE_BACKREF previously while processing the block.
7950 * 7950 *
7951 * NOTE: return value 1 means we should stop walking up. 7951 * NOTE: return value 1 means we should stop walking up.
7952 */ 7952 */
7953 static noinline int walk_up_proc(struct btrfs_trans_handle *trans, 7953 static noinline int walk_up_proc(struct btrfs_trans_handle *trans,
7954 struct btrfs_root *root, 7954 struct btrfs_root *root,
7955 struct btrfs_path *path, 7955 struct btrfs_path *path,
7956 struct walk_control *wc) 7956 struct walk_control *wc)
7957 { 7957 {
7958 int ret; 7958 int ret;
7959 int level = wc->level; 7959 int level = wc->level;
7960 struct extent_buffer *eb = path->nodes[level]; 7960 struct extent_buffer *eb = path->nodes[level];
7961 u64 parent = 0; 7961 u64 parent = 0;
7962 7962
7963 if (wc->stage == UPDATE_BACKREF) { 7963 if (wc->stage == UPDATE_BACKREF) {
7964 BUG_ON(wc->shared_level < level); 7964 BUG_ON(wc->shared_level < level);
7965 if (level < wc->shared_level) 7965 if (level < wc->shared_level)
7966 goto out; 7966 goto out;
7967 7967
7968 ret = find_next_key(path, level + 1, &wc->update_progress); 7968 ret = find_next_key(path, level + 1, &wc->update_progress);
7969 if (ret > 0) 7969 if (ret > 0)
7970 wc->update_ref = 0; 7970 wc->update_ref = 0;
7971 7971
7972 wc->stage = DROP_REFERENCE; 7972 wc->stage = DROP_REFERENCE;
7973 wc->shared_level = -1; 7973 wc->shared_level = -1;
7974 path->slots[level] = 0; 7974 path->slots[level] = 0;
7975 7975
7976 /* 7976 /*
7977 * check reference count again if the block isn't locked. 7977 * check reference count again if the block isn't locked.
7978 * we should start walking down the tree again if reference 7978 * we should start walking down the tree again if reference
7979 * count is one. 7979 * count is one.
7980 */ 7980 */
7981 if (!path->locks[level]) { 7981 if (!path->locks[level]) {
7982 BUG_ON(level == 0); 7982 BUG_ON(level == 0);
7983 btrfs_tree_lock(eb); 7983 btrfs_tree_lock(eb);
7984 btrfs_set_lock_blocking(eb); 7984 btrfs_set_lock_blocking(eb);
7985 path->locks[level] = BTRFS_WRITE_LOCK_BLOCKING; 7985 path->locks[level] = BTRFS_WRITE_LOCK_BLOCKING;
7986 7986
7987 ret = btrfs_lookup_extent_info(trans, root, 7987 ret = btrfs_lookup_extent_info(trans, root,
7988 eb->start, level, 1, 7988 eb->start, level, 1,
7989 &wc->refs[level], 7989 &wc->refs[level],
7990 &wc->flags[level]); 7990 &wc->flags[level]);
7991 if (ret < 0) { 7991 if (ret < 0) {
7992 btrfs_tree_unlock_rw(eb, path->locks[level]); 7992 btrfs_tree_unlock_rw(eb, path->locks[level]);
7993 path->locks[level] = 0; 7993 path->locks[level] = 0;
7994 return ret; 7994 return ret;
7995 } 7995 }
7996 BUG_ON(wc->refs[level] == 0); 7996 BUG_ON(wc->refs[level] == 0);
7997 if (wc->refs[level] == 1) { 7997 if (wc->refs[level] == 1) {
7998 btrfs_tree_unlock_rw(eb, path->locks[level]); 7998 btrfs_tree_unlock_rw(eb, path->locks[level]);
7999 path->locks[level] = 0; 7999 path->locks[level] = 0;
8000 return 1; 8000 return 1;
8001 } 8001 }
8002 } 8002 }
8003 } 8003 }
8004 8004
8005 /* wc->stage == DROP_REFERENCE */ 8005 /* wc->stage == DROP_REFERENCE */
8006 BUG_ON(wc->refs[level] > 1 && !path->locks[level]); 8006 BUG_ON(wc->refs[level] > 1 && !path->locks[level]);
8007 8007
8008 if (wc->refs[level] == 1) { 8008 if (wc->refs[level] == 1) {
8009 if (level == 0) { 8009 if (level == 0) {
8010 if (wc->flags[level] & BTRFS_BLOCK_FLAG_FULL_BACKREF) 8010 if (wc->flags[level] & BTRFS_BLOCK_FLAG_FULL_BACKREF)
8011 ret = btrfs_dec_ref(trans, root, eb, 1); 8011 ret = btrfs_dec_ref(trans, root, eb, 1);
8012 else 8012 else
8013 ret = btrfs_dec_ref(trans, root, eb, 0); 8013 ret = btrfs_dec_ref(trans, root, eb, 0);
8014 BUG_ON(ret); /* -ENOMEM */ 8014 BUG_ON(ret); /* -ENOMEM */
8015 ret = account_leaf_items(trans, root, eb); 8015 ret = account_leaf_items(trans, root, eb);
8016 if (ret) { 8016 if (ret) {
8017 printk_ratelimited(KERN_ERR "BTRFS: %s Error " 8017 printk_ratelimited(KERN_ERR "BTRFS: %s Error "
8018 "%d accounting leaf items. Quota " 8018 "%d accounting leaf items. Quota "
8019 "is out of sync, rescan required.\n", 8019 "is out of sync, rescan required.\n",
8020 root->fs_info->sb->s_id, ret); 8020 root->fs_info->sb->s_id, ret);
8021 } 8021 }
8022 } 8022 }
8023 /* make block locked assertion in clean_tree_block happy */ 8023 /* make block locked assertion in clean_tree_block happy */
8024 if (!path->locks[level] && 8024 if (!path->locks[level] &&
8025 btrfs_header_generation(eb) == trans->transid) { 8025 btrfs_header_generation(eb) == trans->transid) {
8026 btrfs_tree_lock(eb); 8026 btrfs_tree_lock(eb);
8027 btrfs_set_lock_blocking(eb); 8027 btrfs_set_lock_blocking(eb);
8028 path->locks[level] = BTRFS_WRITE_LOCK_BLOCKING; 8028 path->locks[level] = BTRFS_WRITE_LOCK_BLOCKING;
8029 } 8029 }
8030 clean_tree_block(trans, root, eb); 8030 clean_tree_block(trans, root, eb);
8031 } 8031 }
8032 8032
8033 if (eb == root->node) { 8033 if (eb == root->node) {
8034 if (wc->flags[level] & BTRFS_BLOCK_FLAG_FULL_BACKREF) 8034 if (wc->flags[level] & BTRFS_BLOCK_FLAG_FULL_BACKREF)
8035 parent = eb->start; 8035 parent = eb->start;
8036 else 8036 else
8037 BUG_ON(root->root_key.objectid != 8037 BUG_ON(root->root_key.objectid !=
8038 btrfs_header_owner(eb)); 8038 btrfs_header_owner(eb));
8039 } else { 8039 } else {
8040 if (wc->flags[level + 1] & BTRFS_BLOCK_FLAG_FULL_BACKREF) 8040 if (wc->flags[level + 1] & BTRFS_BLOCK_FLAG_FULL_BACKREF)
8041 parent = path->nodes[level + 1]->start; 8041 parent = path->nodes[level + 1]->start;
8042 else 8042 else
8043 BUG_ON(root->root_key.objectid != 8043 BUG_ON(root->root_key.objectid !=
8044 btrfs_header_owner(path->nodes[level + 1])); 8044 btrfs_header_owner(path->nodes[level + 1]));
8045 } 8045 }
8046 8046
8047 btrfs_free_tree_block(trans, root, eb, parent, wc->refs[level] == 1); 8047 btrfs_free_tree_block(trans, root, eb, parent, wc->refs[level] == 1);
8048 out: 8048 out:
8049 wc->refs[level] = 0; 8049 wc->refs[level] = 0;
8050 wc->flags[level] = 0; 8050 wc->flags[level] = 0;
8051 return 0; 8051 return 0;
8052 } 8052 }
8053 8053
8054 static noinline int walk_down_tree(struct btrfs_trans_handle *trans, 8054 static noinline int walk_down_tree(struct btrfs_trans_handle *trans,
8055 struct btrfs_root *root, 8055 struct btrfs_root *root,
8056 struct btrfs_path *path, 8056 struct btrfs_path *path,
8057 struct walk_control *wc) 8057 struct walk_control *wc)
8058 { 8058 {
8059 int level = wc->level; 8059 int level = wc->level;
8060 int lookup_info = 1; 8060 int lookup_info = 1;
8061 int ret; 8061 int ret;
8062 8062
8063 while (level >= 0) { 8063 while (level >= 0) {
8064 ret = walk_down_proc(trans, root, path, wc, lookup_info); 8064 ret = walk_down_proc(trans, root, path, wc, lookup_info);
8065 if (ret > 0) 8065 if (ret > 0)
8066 break; 8066 break;
8067 8067
8068 if (level == 0) 8068 if (level == 0)
8069 break; 8069 break;
8070 8070
8071 if (path->slots[level] >= 8071 if (path->slots[level] >=
8072 btrfs_header_nritems(path->nodes[level])) 8072 btrfs_header_nritems(path->nodes[level]))
8073 break; 8073 break;
8074 8074
8075 ret = do_walk_down(trans, root, path, wc, &lookup_info); 8075 ret = do_walk_down(trans, root, path, wc, &lookup_info);
8076 if (ret > 0) { 8076 if (ret > 0) {
8077 path->slots[level]++; 8077 path->slots[level]++;
8078 continue; 8078 continue;
8079 } else if (ret < 0) 8079 } else if (ret < 0)
8080 return ret; 8080 return ret;
8081 level = wc->level; 8081 level = wc->level;
8082 } 8082 }
8083 return 0; 8083 return 0;
8084 } 8084 }
8085 8085
8086 static noinline int walk_up_tree(struct btrfs_trans_handle *trans, 8086 static noinline int walk_up_tree(struct btrfs_trans_handle *trans,
8087 struct btrfs_root *root, 8087 struct btrfs_root *root,
8088 struct btrfs_path *path, 8088 struct btrfs_path *path,
8089 struct walk_control *wc, int max_level) 8089 struct walk_control *wc, int max_level)
8090 { 8090 {
8091 int level = wc->level; 8091 int level = wc->level;
8092 int ret; 8092 int ret;
8093 8093
8094 path->slots[level] = btrfs_header_nritems(path->nodes[level]); 8094 path->slots[level] = btrfs_header_nritems(path->nodes[level]);
8095 while (level < max_level && path->nodes[level]) { 8095 while (level < max_level && path->nodes[level]) {
8096 wc->level = level; 8096 wc->level = level;
8097 if (path->slots[level] + 1 < 8097 if (path->slots[level] + 1 <
8098 btrfs_header_nritems(path->nodes[level])) { 8098 btrfs_header_nritems(path->nodes[level])) {
8099 path->slots[level]++; 8099 path->slots[level]++;
8100 return 0; 8100 return 0;
8101 } else { 8101 } else {
8102 ret = walk_up_proc(trans, root, path, wc); 8102 ret = walk_up_proc(trans, root, path, wc);
8103 if (ret > 0) 8103 if (ret > 0)
8104 return 0; 8104 return 0;
8105 8105
8106 if (path->locks[level]) { 8106 if (path->locks[level]) {
8107 btrfs_tree_unlock_rw(path->nodes[level], 8107 btrfs_tree_unlock_rw(path->nodes[level],
8108 path->locks[level]); 8108 path->locks[level]);
8109 path->locks[level] = 0; 8109 path->locks[level] = 0;
8110 } 8110 }
8111 free_extent_buffer(path->nodes[level]); 8111 free_extent_buffer(path->nodes[level]);
8112 path->nodes[level] = NULL; 8112 path->nodes[level] = NULL;
8113 level++; 8113 level++;
8114 } 8114 }
8115 } 8115 }
8116 return 1; 8116 return 1;
8117 } 8117 }
8118 8118
8119 /* 8119 /*
8120 * drop a subvolume tree. 8120 * drop a subvolume tree.
8121 * 8121 *
8122 * this function traverses the tree freeing any blocks that only 8122 * this function traverses the tree freeing any blocks that only
8123 * referenced by the tree. 8123 * referenced by the tree.
8124 * 8124 *
8125 * when a shared tree block is found. this function decreases its 8125 * when a shared tree block is found. this function decreases its
8126 * reference count by one. if update_ref is true, this function 8126 * reference count by one. if update_ref is true, this function
8127 * also make sure backrefs for the shared block and all lower level 8127 * also make sure backrefs for the shared block and all lower level
8128 * blocks are properly updated. 8128 * blocks are properly updated.
8129 * 8129 *
8130 * If called with for_reloc == 0, may exit early with -EAGAIN 8130 * If called with for_reloc == 0, may exit early with -EAGAIN
8131 */ 8131 */
8132 int btrfs_drop_snapshot(struct btrfs_root *root, 8132 int btrfs_drop_snapshot(struct btrfs_root *root,
8133 struct btrfs_block_rsv *block_rsv, int update_ref, 8133 struct btrfs_block_rsv *block_rsv, int update_ref,
8134 int for_reloc) 8134 int for_reloc)
8135 { 8135 {
8136 struct btrfs_path *path; 8136 struct btrfs_path *path;
8137 struct btrfs_trans_handle *trans; 8137 struct btrfs_trans_handle *trans;
8138 struct btrfs_root *tree_root = root->fs_info->tree_root; 8138 struct btrfs_root *tree_root = root->fs_info->tree_root;
8139 struct btrfs_root_item *root_item = &root->root_item; 8139 struct btrfs_root_item *root_item = &root->root_item;
8140 struct walk_control *wc; 8140 struct walk_control *wc;
8141 struct btrfs_key key; 8141 struct btrfs_key key;
8142 int err = 0; 8142 int err = 0;
8143 int ret; 8143 int ret;
8144 int level; 8144 int level;
8145 bool root_dropped = false; 8145 bool root_dropped = false;
8146 8146
8147 btrfs_debug(root->fs_info, "Drop subvolume %llu", root->objectid); 8147 btrfs_debug(root->fs_info, "Drop subvolume %llu", root->objectid);
8148 8148
8149 path = btrfs_alloc_path(); 8149 path = btrfs_alloc_path();
8150 if (!path) { 8150 if (!path) {
8151 err = -ENOMEM; 8151 err = -ENOMEM;
8152 goto out; 8152 goto out;
8153 } 8153 }
8154 8154
8155 wc = kzalloc(sizeof(*wc), GFP_NOFS); 8155 wc = kzalloc(sizeof(*wc), GFP_NOFS);
8156 if (!wc) { 8156 if (!wc) {
8157 btrfs_free_path(path); 8157 btrfs_free_path(path);
8158 err = -ENOMEM; 8158 err = -ENOMEM;
8159 goto out; 8159 goto out;
8160 } 8160 }
8161 8161
8162 trans = btrfs_start_transaction(tree_root, 0); 8162 trans = btrfs_start_transaction(tree_root, 0);
8163 if (IS_ERR(trans)) { 8163 if (IS_ERR(trans)) {
8164 err = PTR_ERR(trans); 8164 err = PTR_ERR(trans);
8165 goto out_free; 8165 goto out_free;
8166 } 8166 }
8167 8167
8168 if (block_rsv) 8168 if (block_rsv)
8169 trans->block_rsv = block_rsv; 8169 trans->block_rsv = block_rsv;
8170 8170
8171 if (btrfs_disk_key_objectid(&root_item->drop_progress) == 0) { 8171 if (btrfs_disk_key_objectid(&root_item->drop_progress) == 0) {
8172 level = btrfs_header_level(root->node); 8172 level = btrfs_header_level(root->node);
8173 path->nodes[level] = btrfs_lock_root_node(root); 8173 path->nodes[level] = btrfs_lock_root_node(root);
8174 btrfs_set_lock_blocking(path->nodes[level]); 8174 btrfs_set_lock_blocking(path->nodes[level]);
8175 path->slots[level] = 0; 8175 path->slots[level] = 0;
8176 path->locks[level] = BTRFS_WRITE_LOCK_BLOCKING; 8176 path->locks[level] = BTRFS_WRITE_LOCK_BLOCKING;
8177 memset(&wc->update_progress, 0, 8177 memset(&wc->update_progress, 0,
8178 sizeof(wc->update_progress)); 8178 sizeof(wc->update_progress));
8179 } else { 8179 } else {
8180 btrfs_disk_key_to_cpu(&key, &root_item->drop_progress); 8180 btrfs_disk_key_to_cpu(&key, &root_item->drop_progress);
8181 memcpy(&wc->update_progress, &key, 8181 memcpy(&wc->update_progress, &key,
8182 sizeof(wc->update_progress)); 8182 sizeof(wc->update_progress));
8183 8183
8184 level = root_item->drop_level; 8184 level = root_item->drop_level;
8185 BUG_ON(level == 0); 8185 BUG_ON(level == 0);
8186 path->lowest_level = level; 8186 path->lowest_level = level;
8187 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); 8187 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
8188 path->lowest_level = 0; 8188 path->lowest_level = 0;
8189 if (ret < 0) { 8189 if (ret < 0) {
8190 err = ret; 8190 err = ret;
8191 goto out_end_trans; 8191 goto out_end_trans;
8192 } 8192 }
8193 WARN_ON(ret > 0); 8193 WARN_ON(ret > 0);
8194 8194
8195 /* 8195 /*
8196 * unlock our path, this is safe because only this 8196 * unlock our path, this is safe because only this
8197 * function is allowed to delete this snapshot 8197 * function is allowed to delete this snapshot
8198 */ 8198 */
8199 btrfs_unlock_up_safe(path, 0); 8199 btrfs_unlock_up_safe(path, 0);
8200 8200
8201 level = btrfs_header_level(root->node); 8201 level = btrfs_header_level(root->node);
8202 while (1) { 8202 while (1) {
8203 btrfs_tree_lock(path->nodes[level]); 8203 btrfs_tree_lock(path->nodes[level]);
8204 btrfs_set_lock_blocking(path->nodes[level]); 8204 btrfs_set_lock_blocking(path->nodes[level]);
8205 path->locks[level] = BTRFS_WRITE_LOCK_BLOCKING; 8205 path->locks[level] = BTRFS_WRITE_LOCK_BLOCKING;
8206 8206
8207 ret = btrfs_lookup_extent_info(trans, root, 8207 ret = btrfs_lookup_extent_info(trans, root,
8208 path->nodes[level]->start, 8208 path->nodes[level]->start,
8209 level, 1, &wc->refs[level], 8209 level, 1, &wc->refs[level],
8210 &wc->flags[level]); 8210 &wc->flags[level]);
8211 if (ret < 0) { 8211 if (ret < 0) {
8212 err = ret; 8212 err = ret;
8213 goto out_end_trans; 8213 goto out_end_trans;
8214 } 8214 }
8215 BUG_ON(wc->refs[level] == 0); 8215 BUG_ON(wc->refs[level] == 0);
8216 8216
8217 if (level == root_item->drop_level) 8217 if (level == root_item->drop_level)
8218 break; 8218 break;
8219 8219
8220 btrfs_tree_unlock(path->nodes[level]); 8220 btrfs_tree_unlock(path->nodes[level]);
8221 path->locks[level] = 0; 8221 path->locks[level] = 0;
8222 WARN_ON(wc->refs[level] != 1); 8222 WARN_ON(wc->refs[level] != 1);
8223 level--; 8223 level--;
8224 } 8224 }
8225 } 8225 }
8226 8226
8227 wc->level = level; 8227 wc->level = level;
8228 wc->shared_level = -1; 8228 wc->shared_level = -1;
8229 wc->stage = DROP_REFERENCE; 8229 wc->stage = DROP_REFERENCE;
8230 wc->update_ref = update_ref; 8230 wc->update_ref = update_ref;
8231 wc->keep_locks = 0; 8231 wc->keep_locks = 0;
8232 wc->for_reloc = for_reloc; 8232 wc->for_reloc = for_reloc;
8233 wc->reada_count = BTRFS_NODEPTRS_PER_BLOCK(root); 8233 wc->reada_count = BTRFS_NODEPTRS_PER_BLOCK(root);
8234 8234
8235 while (1) { 8235 while (1) {
8236 8236
8237 ret = walk_down_tree(trans, root, path, wc); 8237 ret = walk_down_tree(trans, root, path, wc);
8238 if (ret < 0) { 8238 if (ret < 0) {
8239 err = ret; 8239 err = ret;
8240 break; 8240 break;
8241 } 8241 }
8242 8242
8243 ret = walk_up_tree(trans, root, path, wc, BTRFS_MAX_LEVEL); 8243 ret = walk_up_tree(trans, root, path, wc, BTRFS_MAX_LEVEL);
8244 if (ret < 0) { 8244 if (ret < 0) {
8245 err = ret; 8245 err = ret;
8246 break; 8246 break;
8247 } 8247 }
8248 8248
8249 if (ret > 0) { 8249 if (ret > 0) {
8250 BUG_ON(wc->stage != DROP_REFERENCE); 8250 BUG_ON(wc->stage != DROP_REFERENCE);
8251 break; 8251 break;
8252 } 8252 }
8253 8253
8254 if (wc->stage == DROP_REFERENCE) { 8254 if (wc->stage == DROP_REFERENCE) {
8255 level = wc->level; 8255 level = wc->level;
8256 btrfs_node_key(path->nodes[level], 8256 btrfs_node_key(path->nodes[level],
8257 &root_item->drop_progress, 8257 &root_item->drop_progress,
8258 path->slots[level]); 8258 path->slots[level]);
8259 root_item->drop_level = level; 8259 root_item->drop_level = level;
8260 } 8260 }
8261 8261
8262 BUG_ON(wc->level == 0); 8262 BUG_ON(wc->level == 0);
8263 if (btrfs_should_end_transaction(trans, tree_root) || 8263 if (btrfs_should_end_transaction(trans, tree_root) ||
8264 (!for_reloc && btrfs_need_cleaner_sleep(root))) { 8264 (!for_reloc && btrfs_need_cleaner_sleep(root))) {
8265 ret = btrfs_update_root(trans, tree_root, 8265 ret = btrfs_update_root(trans, tree_root,
8266 &root->root_key, 8266 &root->root_key,
8267 root_item); 8267 root_item);
8268 if (ret) { 8268 if (ret) {
8269 btrfs_abort_transaction(trans, tree_root, ret); 8269 btrfs_abort_transaction(trans, tree_root, ret);
8270 err = ret; 8270 err = ret;
8271 goto out_end_trans; 8271 goto out_end_trans;
8272 } 8272 }
8273 8273
8274 /* 8274 /*
8275 * Qgroup update accounting is run from 8275 * Qgroup update accounting is run from
8276 * delayed ref handling. This usually works 8276 * delayed ref handling. This usually works
8277 * out because delayed refs are normally the 8277 * out because delayed refs are normally the
8278 * only way qgroup updates are added. However, 8278 * only way qgroup updates are added. However,
8279 * we may have added updates during our tree 8279 * we may have added updates during our tree
8280 * walk so run qgroups here to make sure we 8280 * walk so run qgroups here to make sure we
8281 * don't lose any updates. 8281 * don't lose any updates.
8282 */ 8282 */
8283 ret = btrfs_delayed_qgroup_accounting(trans, 8283 ret = btrfs_delayed_qgroup_accounting(trans,
8284 root->fs_info); 8284 root->fs_info);
8285 if (ret) 8285 if (ret)
8286 printk_ratelimited(KERN_ERR "BTRFS: Failure %d " 8286 printk_ratelimited(KERN_ERR "BTRFS: Failure %d "
8287 "running qgroup updates " 8287 "running qgroup updates "
8288 "during snapshot delete. " 8288 "during snapshot delete. "
8289 "Quota is out of sync, " 8289 "Quota is out of sync, "
8290 "rescan required.\n", ret); 8290 "rescan required.\n", ret);
8291 8291
8292 btrfs_end_transaction_throttle(trans, tree_root); 8292 btrfs_end_transaction_throttle(trans, tree_root);
8293 if (!for_reloc && btrfs_need_cleaner_sleep(root)) { 8293 if (!for_reloc && btrfs_need_cleaner_sleep(root)) {
8294 pr_debug("BTRFS: drop snapshot early exit\n"); 8294 pr_debug("BTRFS: drop snapshot early exit\n");
8295 err = -EAGAIN; 8295 err = -EAGAIN;
8296 goto out_free; 8296 goto out_free;
8297 } 8297 }
8298 8298
8299 trans = btrfs_start_transaction(tree_root, 0); 8299 trans = btrfs_start_transaction(tree_root, 0);
8300 if (IS_ERR(trans)) { 8300 if (IS_ERR(trans)) {
8301 err = PTR_ERR(trans); 8301 err = PTR_ERR(trans);
8302 goto out_free; 8302 goto out_free;
8303 } 8303 }
8304 if (block_rsv) 8304 if (block_rsv)
8305 trans->block_rsv = block_rsv; 8305 trans->block_rsv = block_rsv;
8306 } 8306 }
8307 } 8307 }
8308 btrfs_release_path(path); 8308 btrfs_release_path(path);
8309 if (err) 8309 if (err)
8310 goto out_end_trans; 8310 goto out_end_trans;
8311 8311
8312 ret = btrfs_del_root(trans, tree_root, &root->root_key); 8312 ret = btrfs_del_root(trans, tree_root, &root->root_key);
8313 if (ret) { 8313 if (ret) {
8314 btrfs_abort_transaction(trans, tree_root, ret); 8314 btrfs_abort_transaction(trans, tree_root, ret);
8315 goto out_end_trans; 8315 goto out_end_trans;
8316 } 8316 }
8317 8317
8318 if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID) { 8318 if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID) {
8319 ret = btrfs_find_root(tree_root, &root->root_key, path, 8319 ret = btrfs_find_root(tree_root, &root->root_key, path,
8320 NULL, NULL); 8320 NULL, NULL);
8321 if (ret < 0) { 8321 if (ret < 0) {
8322 btrfs_abort_transaction(trans, tree_root, ret); 8322 btrfs_abort_transaction(trans, tree_root, ret);
8323 err = ret; 8323 err = ret;
8324 goto out_end_trans; 8324 goto out_end_trans;
8325 } else if (ret > 0) { 8325 } else if (ret > 0) {
8326 /* if we fail to delete the orphan item this time 8326 /* if we fail to delete the orphan item this time
8327 * around, it'll get picked up the next time. 8327 * around, it'll get picked up the next time.
8328 * 8328 *
8329 * The most common failure here is just -ENOENT. 8329 * The most common failure here is just -ENOENT.
8330 */ 8330 */
8331 btrfs_del_orphan_item(trans, tree_root, 8331 btrfs_del_orphan_item(trans, tree_root,
8332 root->root_key.objectid); 8332 root->root_key.objectid);
8333 } 8333 }
8334 } 8334 }
8335 8335
8336 if (test_bit(BTRFS_ROOT_IN_RADIX, &root->state)) { 8336 if (test_bit(BTRFS_ROOT_IN_RADIX, &root->state)) {
8337 btrfs_drop_and_free_fs_root(tree_root->fs_info, root); 8337 btrfs_drop_and_free_fs_root(tree_root->fs_info, root);
8338 } else { 8338 } else {
8339 free_extent_buffer(root->node); 8339 free_extent_buffer(root->node);
8340 free_extent_buffer(root->commit_root); 8340 free_extent_buffer(root->commit_root);
8341 btrfs_put_fs_root(root); 8341 btrfs_put_fs_root(root);
8342 } 8342 }
8343 root_dropped = true; 8343 root_dropped = true;
8344 out_end_trans: 8344 out_end_trans:
8345 ret = btrfs_delayed_qgroup_accounting(trans, tree_root->fs_info); 8345 ret = btrfs_delayed_qgroup_accounting(trans, tree_root->fs_info);
8346 if (ret) 8346 if (ret)
8347 printk_ratelimited(KERN_ERR "BTRFS: Failure %d " 8347 printk_ratelimited(KERN_ERR "BTRFS: Failure %d "
8348 "running qgroup updates " 8348 "running qgroup updates "
8349 "during snapshot delete. " 8349 "during snapshot delete. "
8350 "Quota is out of sync, " 8350 "Quota is out of sync, "
8351 "rescan required.\n", ret); 8351 "rescan required.\n", ret);
8352 8352
8353 btrfs_end_transaction_throttle(trans, tree_root); 8353 btrfs_end_transaction_throttle(trans, tree_root);
8354 out_free: 8354 out_free:
8355 kfree(wc); 8355 kfree(wc);
8356 btrfs_free_path(path); 8356 btrfs_free_path(path);
8357 out: 8357 out:
8358 /* 8358 /*
8359 * So if we need to stop dropping the snapshot for whatever reason we 8359 * So if we need to stop dropping the snapshot for whatever reason we
8360 * need to make sure to add it back to the dead root list so that we 8360 * need to make sure to add it back to the dead root list so that we
8361 * keep trying to do the work later. This also cleans up roots if we 8361 * keep trying to do the work later. This also cleans up roots if we
8362 * don't have it in the radix (like when we recover after a power fail 8362 * don't have it in the radix (like when we recover after a power fail
8363 * or unmount) so we don't leak memory. 8363 * or unmount) so we don't leak memory.
8364 */ 8364 */
8365 if (!for_reloc && root_dropped == false) 8365 if (!for_reloc && root_dropped == false)
8366 btrfs_add_dead_root(root); 8366 btrfs_add_dead_root(root);
8367 if (err && err != -EAGAIN) 8367 if (err && err != -EAGAIN)
8368 btrfs_std_error(root->fs_info, err); 8368 btrfs_std_error(root->fs_info, err);
8369 return err; 8369 return err;
8370 } 8370 }
8371 8371
8372 /* 8372 /*
8373 * drop subtree rooted at tree block 'node'. 8373 * drop subtree rooted at tree block 'node'.
8374 * 8374 *
8375 * NOTE: this function will unlock and release tree block 'node' 8375 * NOTE: this function will unlock and release tree block 'node'
8376 * only used by relocation code 8376 * only used by relocation code
8377 */ 8377 */
8378 int btrfs_drop_subtree(struct btrfs_trans_handle *trans, 8378 int btrfs_drop_subtree(struct btrfs_trans_handle *trans,
8379 struct btrfs_root *root, 8379 struct btrfs_root *root,
8380 struct extent_buffer *node, 8380 struct extent_buffer *node,
8381 struct extent_buffer *parent) 8381 struct extent_buffer *parent)
8382 { 8382 {
8383 struct btrfs_path *path; 8383 struct btrfs_path *path;
8384 struct walk_control *wc; 8384 struct walk_control *wc;
8385 int level; 8385 int level;
8386 int parent_level; 8386 int parent_level;
8387 int ret = 0; 8387 int ret = 0;
8388 int wret; 8388 int wret;
8389 8389
8390 BUG_ON(root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID); 8390 BUG_ON(root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID);
8391 8391
8392 path = btrfs_alloc_path(); 8392 path = btrfs_alloc_path();
8393 if (!path) 8393 if (!path)
8394 return -ENOMEM; 8394 return -ENOMEM;
8395 8395
8396 wc = kzalloc(sizeof(*wc), GFP_NOFS); 8396 wc = kzalloc(sizeof(*wc), GFP_NOFS);
8397 if (!wc) { 8397 if (!wc) {
8398 btrfs_free_path(path); 8398 btrfs_free_path(path);
8399 return -ENOMEM; 8399 return -ENOMEM;
8400 } 8400 }
8401 8401
8402 btrfs_assert_tree_locked(parent); 8402 btrfs_assert_tree_locked(parent);
8403 parent_level = btrfs_header_level(parent); 8403 parent_level = btrfs_header_level(parent);
8404 extent_buffer_get(parent); 8404 extent_buffer_get(parent);
8405 path->nodes[parent_level] = parent; 8405 path->nodes[parent_level] = parent;
8406 path->slots[parent_level] = btrfs_header_nritems(parent); 8406 path->slots[parent_level] = btrfs_header_nritems(parent);
8407 8407
8408 btrfs_assert_tree_locked(node); 8408 btrfs_assert_tree_locked(node);
8409 level = btrfs_header_level(node); 8409 level = btrfs_header_level(node);
8410 path->nodes[level] = node; 8410 path->nodes[level] = node;
8411 path->slots[level] = 0; 8411 path->slots[level] = 0;
8412 path->locks[level] = BTRFS_WRITE_LOCK_BLOCKING; 8412 path->locks[level] = BTRFS_WRITE_LOCK_BLOCKING;
8413 8413
8414 wc->refs[parent_level] = 1; 8414 wc->refs[parent_level] = 1;
8415 wc->flags[parent_level] = BTRFS_BLOCK_FLAG_FULL_BACKREF; 8415 wc->flags[parent_level] = BTRFS_BLOCK_FLAG_FULL_BACKREF;
8416 wc->level = level; 8416 wc->level = level;
8417 wc->shared_level = -1; 8417 wc->shared_level = -1;
8418 wc->stage = DROP_REFERENCE; 8418 wc->stage = DROP_REFERENCE;
8419 wc->update_ref = 0; 8419 wc->update_ref = 0;
8420 wc->keep_locks = 1; 8420 wc->keep_locks = 1;
8421 wc->for_reloc = 1; 8421 wc->for_reloc = 1;
8422 wc->reada_count = BTRFS_NODEPTRS_PER_BLOCK(root); 8422 wc->reada_count = BTRFS_NODEPTRS_PER_BLOCK(root);
8423 8423
8424 while (1) { 8424 while (1) {
8425 wret = walk_down_tree(trans, root, path, wc); 8425 wret = walk_down_tree(trans, root, path, wc);
8426 if (wret < 0) { 8426 if (wret < 0) {
8427 ret = wret; 8427 ret = wret;
8428 break; 8428 break;
8429 } 8429 }
8430 8430
8431 wret = walk_up_tree(trans, root, path, wc, parent_level); 8431 wret = walk_up_tree(trans, root, path, wc, parent_level);
8432 if (wret < 0) 8432 if (wret < 0)
8433 ret = wret; 8433 ret = wret;
8434 if (wret != 0) 8434 if (wret != 0)
8435 break; 8435 break;
8436 } 8436 }
8437 8437
8438 kfree(wc); 8438 kfree(wc);
8439 btrfs_free_path(path); 8439 btrfs_free_path(path);
8440 return ret; 8440 return ret;
8441 } 8441 }
8442 8442
8443 static u64 update_block_group_flags(struct btrfs_root *root, u64 flags) 8443 static u64 update_block_group_flags(struct btrfs_root *root, u64 flags)
8444 { 8444 {
8445 u64 num_devices; 8445 u64 num_devices;
8446 u64 stripped; 8446 u64 stripped;
8447 8447
8448 /* 8448 /*
8449 * if restripe for this chunk_type is on pick target profile and 8449 * if restripe for this chunk_type is on pick target profile and
8450 * return, otherwise do the usual balance 8450 * return, otherwise do the usual balance
8451 */ 8451 */
8452 stripped = get_restripe_target(root->fs_info, flags); 8452 stripped = get_restripe_target(root->fs_info, flags);
8453 if (stripped) 8453 if (stripped)
8454 return extended_to_chunk(stripped); 8454 return extended_to_chunk(stripped);
8455 8455
8456 num_devices = root->fs_info->fs_devices->rw_devices; 8456 num_devices = root->fs_info->fs_devices->rw_devices;
8457 8457
8458 stripped = BTRFS_BLOCK_GROUP_RAID0 | 8458 stripped = BTRFS_BLOCK_GROUP_RAID0 |
8459 BTRFS_BLOCK_GROUP_RAID5 | BTRFS_BLOCK_GROUP_RAID6 | 8459 BTRFS_BLOCK_GROUP_RAID5 | BTRFS_BLOCK_GROUP_RAID6 |
8460 BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_RAID10; 8460 BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_RAID10;
8461 8461
8462 if (num_devices == 1) { 8462 if (num_devices == 1) {
8463 stripped |= BTRFS_BLOCK_GROUP_DUP; 8463 stripped |= BTRFS_BLOCK_GROUP_DUP;
8464 stripped = flags & ~stripped; 8464 stripped = flags & ~stripped;
8465 8465
8466 /* turn raid0 into single device chunks */ 8466 /* turn raid0 into single device chunks */
8467 if (flags & BTRFS_BLOCK_GROUP_RAID0) 8467 if (flags & BTRFS_BLOCK_GROUP_RAID0)
8468 return stripped; 8468 return stripped;
8469 8469
8470 /* turn mirroring into duplication */ 8470 /* turn mirroring into duplication */
8471 if (flags & (BTRFS_BLOCK_GROUP_RAID1 | 8471 if (flags & (BTRFS_BLOCK_GROUP_RAID1 |
8472 BTRFS_BLOCK_GROUP_RAID10)) 8472 BTRFS_BLOCK_GROUP_RAID10))
8473 return stripped | BTRFS_BLOCK_GROUP_DUP; 8473 return stripped | BTRFS_BLOCK_GROUP_DUP;
8474 } else { 8474 } else {
8475 /* they already had raid on here, just return */ 8475 /* they already had raid on here, just return */
8476 if (flags & stripped) 8476 if (flags & stripped)
8477 return flags; 8477 return flags;
8478 8478
8479 stripped |= BTRFS_BLOCK_GROUP_DUP; 8479 stripped |= BTRFS_BLOCK_GROUP_DUP;
8480 stripped = flags & ~stripped; 8480 stripped = flags & ~stripped;
8481 8481
8482 /* switch duplicated blocks with raid1 */ 8482 /* switch duplicated blocks with raid1 */
8483 if (flags & BTRFS_BLOCK_GROUP_DUP) 8483 if (flags & BTRFS_BLOCK_GROUP_DUP)
8484 return stripped | BTRFS_BLOCK_GROUP_RAID1; 8484 return stripped | BTRFS_BLOCK_GROUP_RAID1;
8485 8485
8486 /* this is drive concat, leave it alone */ 8486 /* this is drive concat, leave it alone */
8487 } 8487 }
8488 8488
8489 return flags; 8489 return flags;
8490 } 8490 }
8491 8491
8492 static int set_block_group_ro(struct btrfs_block_group_cache *cache, int force) 8492 static int set_block_group_ro(struct btrfs_block_group_cache *cache, int force)
8493 { 8493 {
8494 struct btrfs_space_info *sinfo = cache->space_info; 8494 struct btrfs_space_info *sinfo = cache->space_info;
8495 u64 num_bytes; 8495 u64 num_bytes;
8496 u64 min_allocable_bytes; 8496 u64 min_allocable_bytes;
8497 int ret = -ENOSPC; 8497 int ret = -ENOSPC;
8498 8498
8499 8499
8500 /* 8500 /*
8501 * We need some metadata space and system metadata space for 8501 * We need some metadata space and system metadata space for
8502 * allocating chunks in some corner cases until we force to set 8502 * allocating chunks in some corner cases until we force to set
8503 * it to be readonly. 8503 * it to be readonly.
8504 */ 8504 */
8505 if ((sinfo->flags & 8505 if ((sinfo->flags &
8506 (BTRFS_BLOCK_GROUP_SYSTEM | BTRFS_BLOCK_GROUP_METADATA)) && 8506 (BTRFS_BLOCK_GROUP_SYSTEM | BTRFS_BLOCK_GROUP_METADATA)) &&
8507 !force) 8507 !force)
8508 min_allocable_bytes = 1 * 1024 * 1024; 8508 min_allocable_bytes = 1 * 1024 * 1024;
8509 else 8509 else
8510 min_allocable_bytes = 0; 8510 min_allocable_bytes = 0;
8511 8511
8512 spin_lock(&sinfo->lock); 8512 spin_lock(&sinfo->lock);
8513 spin_lock(&cache->lock); 8513 spin_lock(&cache->lock);
8514 8514
8515 if (cache->ro) { 8515 if (cache->ro) {
8516 ret = 0; 8516 ret = 0;
8517 goto out; 8517 goto out;
8518 } 8518 }
8519 8519
8520 num_bytes = cache->key.offset - cache->reserved - cache->pinned - 8520 num_bytes = cache->key.offset - cache->reserved - cache->pinned -
8521 cache->bytes_super - btrfs_block_group_used(&cache->item); 8521 cache->bytes_super - btrfs_block_group_used(&cache->item);
8522 8522
8523 if (sinfo->bytes_used + sinfo->bytes_reserved + sinfo->bytes_pinned + 8523 if (sinfo->bytes_used + sinfo->bytes_reserved + sinfo->bytes_pinned +
8524 sinfo->bytes_may_use + sinfo->bytes_readonly + num_bytes + 8524 sinfo->bytes_may_use + sinfo->bytes_readonly + num_bytes +
8525 min_allocable_bytes <= sinfo->total_bytes) { 8525 min_allocable_bytes <= sinfo->total_bytes) {
8526 sinfo->bytes_readonly += num_bytes; 8526 sinfo->bytes_readonly += num_bytes;
8527 cache->ro = 1; 8527 cache->ro = 1;
8528 list_add_tail(&cache->ro_list, &sinfo->ro_bgs); 8528 list_add_tail(&cache->ro_list, &sinfo->ro_bgs);
8529 ret = 0; 8529 ret = 0;
8530 } 8530 }
8531 out: 8531 out:
8532 spin_unlock(&cache->lock); 8532 spin_unlock(&cache->lock);
8533 spin_unlock(&sinfo->lock); 8533 spin_unlock(&sinfo->lock);
8534 return ret; 8534 return ret;
8535 } 8535 }
8536 8536
8537 int btrfs_set_block_group_ro(struct btrfs_root *root, 8537 int btrfs_set_block_group_ro(struct btrfs_root *root,
8538 struct btrfs_block_group_cache *cache) 8538 struct btrfs_block_group_cache *cache)
8539 8539
8540 { 8540 {
8541 struct btrfs_trans_handle *trans; 8541 struct btrfs_trans_handle *trans;
8542 u64 alloc_flags; 8542 u64 alloc_flags;
8543 int ret; 8543 int ret;
8544 8544
8545 BUG_ON(cache->ro); 8545 BUG_ON(cache->ro);
8546 8546
8547 trans = btrfs_join_transaction(root); 8547 trans = btrfs_join_transaction(root);
8548 if (IS_ERR(trans)) 8548 if (IS_ERR(trans))
8549 return PTR_ERR(trans); 8549 return PTR_ERR(trans);
8550 8550
8551 alloc_flags = update_block_group_flags(root, cache->flags); 8551 alloc_flags = update_block_group_flags(root, cache->flags);
8552 if (alloc_flags != cache->flags) { 8552 if (alloc_flags != cache->flags) {
8553 ret = do_chunk_alloc(trans, root, alloc_flags, 8553 ret = do_chunk_alloc(trans, root, alloc_flags,
8554 CHUNK_ALLOC_FORCE); 8554 CHUNK_ALLOC_FORCE);
8555 if (ret < 0) 8555 if (ret < 0)
8556 goto out; 8556 goto out;
8557 } 8557 }
8558 8558
8559 ret = set_block_group_ro(cache, 0); 8559 ret = set_block_group_ro(cache, 0);
8560 if (!ret) 8560 if (!ret)
8561 goto out; 8561 goto out;
8562 alloc_flags = get_alloc_profile(root, cache->space_info->flags); 8562 alloc_flags = get_alloc_profile(root, cache->space_info->flags);
8563 ret = do_chunk_alloc(trans, root, alloc_flags, 8563 ret = do_chunk_alloc(trans, root, alloc_flags,
8564 CHUNK_ALLOC_FORCE); 8564 CHUNK_ALLOC_FORCE);
8565 if (ret < 0) 8565 if (ret < 0)
8566 goto out; 8566 goto out;
8567 ret = set_block_group_ro(cache, 0); 8567 ret = set_block_group_ro(cache, 0);
8568 out: 8568 out:
8569 btrfs_end_transaction(trans, root); 8569 btrfs_end_transaction(trans, root);
8570 return ret; 8570 return ret;
8571 } 8571 }
8572 8572
8573 int btrfs_force_chunk_alloc(struct btrfs_trans_handle *trans, 8573 int btrfs_force_chunk_alloc(struct btrfs_trans_handle *trans,
8574 struct btrfs_root *root, u64 type) 8574 struct btrfs_root *root, u64 type)
8575 { 8575 {
8576 u64 alloc_flags = get_alloc_profile(root, type); 8576 u64 alloc_flags = get_alloc_profile(root, type);
8577 return do_chunk_alloc(trans, root, alloc_flags, 8577 return do_chunk_alloc(trans, root, alloc_flags,
8578 CHUNK_ALLOC_FORCE); 8578 CHUNK_ALLOC_FORCE);
8579 } 8579 }
8580 8580
8581 /* 8581 /*
8582 * helper to account the unused space of all the readonly block group in the 8582 * helper to account the unused space of all the readonly block group in the
8583 * space_info. takes mirrors into account. 8583 * space_info. takes mirrors into account.
8584 */ 8584 */
8585 u64 btrfs_account_ro_block_groups_free_space(struct btrfs_space_info *sinfo) 8585 u64 btrfs_account_ro_block_groups_free_space(struct btrfs_space_info *sinfo)
8586 { 8586 {
8587 struct btrfs_block_group_cache *block_group; 8587 struct btrfs_block_group_cache *block_group;
8588 u64 free_bytes = 0; 8588 u64 free_bytes = 0;
8589 int factor; 8589 int factor;
8590 8590
8591 /* It's df, we don't care if it's racey */ 8591 /* It's df, we don't care if it's racey */
8592 if (list_empty(&sinfo->ro_bgs)) 8592 if (list_empty(&sinfo->ro_bgs))
8593 return 0; 8593 return 0;
8594 8594
8595 spin_lock(&sinfo->lock); 8595 spin_lock(&sinfo->lock);
8596 list_for_each_entry(block_group, &sinfo->ro_bgs, ro_list) { 8596 list_for_each_entry(block_group, &sinfo->ro_bgs, ro_list) {
8597 spin_lock(&block_group->lock); 8597 spin_lock(&block_group->lock);
8598 8598
8599 if (!block_group->ro) { 8599 if (!block_group->ro) {
8600 spin_unlock(&block_group->lock); 8600 spin_unlock(&block_group->lock);
8601 continue; 8601 continue;
8602 } 8602 }
8603 8603
8604 if (block_group->flags & (BTRFS_BLOCK_GROUP_RAID1 | 8604 if (block_group->flags & (BTRFS_BLOCK_GROUP_RAID1 |
8605 BTRFS_BLOCK_GROUP_RAID10 | 8605 BTRFS_BLOCK_GROUP_RAID10 |
8606 BTRFS_BLOCK_GROUP_DUP)) 8606 BTRFS_BLOCK_GROUP_DUP))
8607 factor = 2; 8607 factor = 2;
8608 else 8608 else
8609 factor = 1; 8609 factor = 1;
8610 8610
8611 free_bytes += (block_group->key.offset - 8611 free_bytes += (block_group->key.offset -
8612 btrfs_block_group_used(&block_group->item)) * 8612 btrfs_block_group_used(&block_group->item)) *
8613 factor; 8613 factor;
8614 8614
8615 spin_unlock(&block_group->lock); 8615 spin_unlock(&block_group->lock);
8616 } 8616 }
8617 spin_unlock(&sinfo->lock); 8617 spin_unlock(&sinfo->lock);
8618 8618
8619 return free_bytes; 8619 return free_bytes;
8620 } 8620 }
8621 8621
8622 void btrfs_set_block_group_rw(struct btrfs_root *root, 8622 void btrfs_set_block_group_rw(struct btrfs_root *root,
8623 struct btrfs_block_group_cache *cache) 8623 struct btrfs_block_group_cache *cache)
8624 { 8624 {
8625 struct btrfs_space_info *sinfo = cache->space_info; 8625 struct btrfs_space_info *sinfo = cache->space_info;
8626 u64 num_bytes; 8626 u64 num_bytes;
8627 8627
8628 BUG_ON(!cache->ro); 8628 BUG_ON(!cache->ro);
8629 8629
8630 spin_lock(&sinfo->lock); 8630 spin_lock(&sinfo->lock);
8631 spin_lock(&cache->lock); 8631 spin_lock(&cache->lock);
8632 num_bytes = cache->key.offset - cache->reserved - cache->pinned - 8632 num_bytes = cache->key.offset - cache->reserved - cache->pinned -
8633 cache->bytes_super - btrfs_block_group_used(&cache->item); 8633 cache->bytes_super - btrfs_block_group_used(&cache->item);
8634 sinfo->bytes_readonly -= num_bytes; 8634 sinfo->bytes_readonly -= num_bytes;
8635 cache->ro = 0; 8635 cache->ro = 0;
8636 list_del_init(&cache->ro_list); 8636 list_del_init(&cache->ro_list);
8637 spin_unlock(&cache->lock); 8637 spin_unlock(&cache->lock);
8638 spin_unlock(&sinfo->lock); 8638 spin_unlock(&sinfo->lock);
8639 } 8639 }
8640 8640
8641 /* 8641 /*
8642 * checks to see if its even possible to relocate this block group. 8642 * checks to see if its even possible to relocate this block group.
8643 * 8643 *
8644 * @return - -1 if it's not a good idea to relocate this block group, 0 if its 8644 * @return - -1 if it's not a good idea to relocate this block group, 0 if its
8645 * ok to go ahead and try. 8645 * ok to go ahead and try.
8646 */ 8646 */
8647 int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr) 8647 int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr)
8648 { 8648 {
8649 struct btrfs_block_group_cache *block_group; 8649 struct btrfs_block_group_cache *block_group;
8650 struct btrfs_space_info *space_info; 8650 struct btrfs_space_info *space_info;
8651 struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices; 8651 struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices;
8652 struct btrfs_device *device; 8652 struct btrfs_device *device;
8653 struct btrfs_trans_handle *trans; 8653 struct btrfs_trans_handle *trans;
8654 u64 min_free; 8654 u64 min_free;
8655 u64 dev_min = 1; 8655 u64 dev_min = 1;
8656 u64 dev_nr = 0; 8656 u64 dev_nr = 0;
8657 u64 target; 8657 u64 target;
8658 int index; 8658 int index;
8659 int full = 0; 8659 int full = 0;
8660 int ret = 0; 8660 int ret = 0;
8661 8661
8662 block_group = btrfs_lookup_block_group(root->fs_info, bytenr); 8662 block_group = btrfs_lookup_block_group(root->fs_info, bytenr);
8663 8663
8664 /* odd, couldn't find the block group, leave it alone */ 8664 /* odd, couldn't find the block group, leave it alone */
8665 if (!block_group) 8665 if (!block_group)
8666 return -1; 8666 return -1;
8667 8667
8668 min_free = btrfs_block_group_used(&block_group->item); 8668 min_free = btrfs_block_group_used(&block_group->item);
8669 8669
8670 /* no bytes used, we're good */ 8670 /* no bytes used, we're good */
8671 if (!min_free) 8671 if (!min_free)
8672 goto out; 8672 goto out;
8673 8673
8674 space_info = block_group->space_info; 8674 space_info = block_group->space_info;
8675 spin_lock(&space_info->lock); 8675 spin_lock(&space_info->lock);
8676 8676
8677 full = space_info->full; 8677 full = space_info->full;
8678 8678
8679 /* 8679 /*
8680 * if this is the last block group we have in this space, we can't 8680 * if this is the last block group we have in this space, we can't
8681 * relocate it unless we're able to allocate a new chunk below. 8681 * relocate it unless we're able to allocate a new chunk below.
8682 * 8682 *
8683 * Otherwise, we need to make sure we have room in the space to handle 8683 * Otherwise, we need to make sure we have room in the space to handle
8684 * all of the extents from this block group. If we can, we're good 8684 * all of the extents from this block group. If we can, we're good
8685 */ 8685 */
8686 if ((space_info->total_bytes != block_group->key.offset) && 8686 if ((space_info->total_bytes != block_group->key.offset) &&
8687 (space_info->bytes_used + space_info->bytes_reserved + 8687 (space_info->bytes_used + space_info->bytes_reserved +
8688 space_info->bytes_pinned + space_info->bytes_readonly + 8688 space_info->bytes_pinned + space_info->bytes_readonly +
8689 min_free < space_info->total_bytes)) { 8689 min_free < space_info->total_bytes)) {
8690 spin_unlock(&space_info->lock); 8690 spin_unlock(&space_info->lock);
8691 goto out; 8691 goto out;
8692 } 8692 }
8693 spin_unlock(&space_info->lock); 8693 spin_unlock(&space_info->lock);
8694 8694
8695 /* 8695 /*
8696 * ok we don't have enough space, but maybe we have free space on our 8696 * ok we don't have enough space, but maybe we have free space on our
8697 * devices to allocate new chunks for relocation, so loop through our 8697 * devices to allocate new chunks for relocation, so loop through our
8698 * alloc devices and guess if we have enough space. if this block 8698 * alloc devices and guess if we have enough space. if this block
8699 * group is going to be restriped, run checks against the target 8699 * group is going to be restriped, run checks against the target
8700 * profile instead of the current one. 8700 * profile instead of the current one.
8701 */ 8701 */
8702 ret = -1; 8702 ret = -1;
8703 8703
8704 /* 8704 /*
8705 * index: 8705 * index:
8706 * 0: raid10 8706 * 0: raid10
8707 * 1: raid1 8707 * 1: raid1
8708 * 2: dup 8708 * 2: dup
8709 * 3: raid0 8709 * 3: raid0
8710 * 4: single 8710 * 4: single
8711 */ 8711 */
8712 target = get_restripe_target(root->fs_info, block_group->flags); 8712 target = get_restripe_target(root->fs_info, block_group->flags);
8713 if (target) { 8713 if (target) {
8714 index = __get_raid_index(extended_to_chunk(target)); 8714 index = __get_raid_index(extended_to_chunk(target));
8715 } else { 8715 } else {
8716 /* 8716 /*
8717 * this is just a balance, so if we were marked as full 8717 * this is just a balance, so if we were marked as full
8718 * we know there is no space for a new chunk 8718 * we know there is no space for a new chunk
8719 */ 8719 */
8720 if (full) 8720 if (full)
8721 goto out; 8721 goto out;
8722 8722
8723 index = get_block_group_index(block_group); 8723 index = get_block_group_index(block_group);
8724 } 8724 }
8725 8725
8726 if (index == BTRFS_RAID_RAID10) { 8726 if (index == BTRFS_RAID_RAID10) {
8727 dev_min = 4; 8727 dev_min = 4;
8728 /* Divide by 2 */ 8728 /* Divide by 2 */
8729 min_free >>= 1; 8729 min_free >>= 1;
8730 } else if (index == BTRFS_RAID_RAID1) { 8730 } else if (index == BTRFS_RAID_RAID1) {
8731 dev_min = 2; 8731 dev_min = 2;
8732 } else if (index == BTRFS_RAID_DUP) { 8732 } else if (index == BTRFS_RAID_DUP) {
8733 /* Multiply by 2 */ 8733 /* Multiply by 2 */
8734 min_free <<= 1; 8734 min_free <<= 1;
8735 } else if (index == BTRFS_RAID_RAID0) { 8735 } else if (index == BTRFS_RAID_RAID0) {
8736 dev_min = fs_devices->rw_devices; 8736 dev_min = fs_devices->rw_devices;
8737 do_div(min_free, dev_min); 8737 do_div(min_free, dev_min);
8738 } 8738 }
8739 8739
8740 /* We need to do this so that we can look at pending chunks */ 8740 /* We need to do this so that we can look at pending chunks */
8741 trans = btrfs_join_transaction(root); 8741 trans = btrfs_join_transaction(root);
8742 if (IS_ERR(trans)) { 8742 if (IS_ERR(trans)) {
8743 ret = PTR_ERR(trans); 8743 ret = PTR_ERR(trans);
8744 goto out; 8744 goto out;
8745 } 8745 }
8746 8746
8747 mutex_lock(&root->fs_info->chunk_mutex); 8747 mutex_lock(&root->fs_info->chunk_mutex);
8748 list_for_each_entry(device, &fs_devices->alloc_list, dev_alloc_list) { 8748 list_for_each_entry(device, &fs_devices->alloc_list, dev_alloc_list) {
8749 u64 dev_offset; 8749 u64 dev_offset;
8750 8750
8751 /* 8751 /*
8752 * check to make sure we can actually find a chunk with enough 8752 * check to make sure we can actually find a chunk with enough
8753 * space to fit our block group in. 8753 * space to fit our block group in.
8754 */ 8754 */
8755 if (device->total_bytes > device->bytes_used + min_free && 8755 if (device->total_bytes > device->bytes_used + min_free &&
8756 !device->is_tgtdev_for_dev_replace) { 8756 !device->is_tgtdev_for_dev_replace) {
8757 ret = find_free_dev_extent(trans, device, min_free, 8757 ret = find_free_dev_extent(trans, device, min_free,
8758 &dev_offset, NULL); 8758 &dev_offset, NULL);
8759 if (!ret) 8759 if (!ret)
8760 dev_nr++; 8760 dev_nr++;
8761 8761
8762 if (dev_nr >= dev_min) 8762 if (dev_nr >= dev_min)
8763 break; 8763 break;
8764 8764
8765 ret = -1; 8765 ret = -1;
8766 } 8766 }
8767 } 8767 }
8768 mutex_unlock(&root->fs_info->chunk_mutex); 8768 mutex_unlock(&root->fs_info->chunk_mutex);
8769 btrfs_end_transaction(trans, root); 8769 btrfs_end_transaction(trans, root);
8770 out: 8770 out:
8771 btrfs_put_block_group(block_group); 8771 btrfs_put_block_group(block_group);
8772 return ret; 8772 return ret;
8773 } 8773 }
8774 8774
8775 static int find_first_block_group(struct btrfs_root *root, 8775 static int find_first_block_group(struct btrfs_root *root,
8776 struct btrfs_path *path, struct btrfs_key *key) 8776 struct btrfs_path *path, struct btrfs_key *key)
8777 { 8777 {
8778 int ret = 0; 8778 int ret = 0;
8779 struct btrfs_key found_key; 8779 struct btrfs_key found_key;
8780 struct extent_buffer *leaf; 8780 struct extent_buffer *leaf;
8781 int slot; 8781 int slot;
8782 8782
8783 ret = btrfs_search_slot(NULL, root, key, path, 0, 0); 8783 ret = btrfs_search_slot(NULL, root, key, path, 0, 0);
8784 if (ret < 0) 8784 if (ret < 0)
8785 goto out; 8785 goto out;
8786 8786
8787 while (1) { 8787 while (1) {
8788 slot = path->slots[0]; 8788 slot = path->slots[0];
8789 leaf = path->nodes[0]; 8789 leaf = path->nodes[0];
8790 if (slot >= btrfs_header_nritems(leaf)) { 8790 if (slot >= btrfs_header_nritems(leaf)) {
8791 ret = btrfs_next_leaf(root, path); 8791 ret = btrfs_next_leaf(root, path);
8792 if (ret == 0) 8792 if (ret == 0)
8793 continue; 8793 continue;
8794 if (ret < 0) 8794 if (ret < 0)
8795 goto out; 8795 goto out;
8796 break; 8796 break;
8797 } 8797 }
8798 btrfs_item_key_to_cpu(leaf, &found_key, slot); 8798 btrfs_item_key_to_cpu(leaf, &found_key, slot);
8799 8799
8800 if (found_key.objectid >= key->objectid && 8800 if (found_key.objectid >= key->objectid &&
8801 found_key.type == BTRFS_BLOCK_GROUP_ITEM_KEY) { 8801 found_key.type == BTRFS_BLOCK_GROUP_ITEM_KEY) {
8802 ret = 0; 8802 ret = 0;
8803 goto out; 8803 goto out;
8804 } 8804 }
8805 path->slots[0]++; 8805 path->slots[0]++;
8806 } 8806 }
8807 out: 8807 out:
8808 return ret; 8808 return ret;
8809 } 8809 }
8810 8810
8811 void btrfs_put_block_group_cache(struct btrfs_fs_info *info) 8811 void btrfs_put_block_group_cache(struct btrfs_fs_info *info)
8812 { 8812 {
8813 struct btrfs_block_group_cache *block_group; 8813 struct btrfs_block_group_cache *block_group;
8814 u64 last = 0; 8814 u64 last = 0;
8815 8815
8816 while (1) { 8816 while (1) {
8817 struct inode *inode; 8817 struct inode *inode;
8818 8818
8819 block_group = btrfs_lookup_first_block_group(info, last); 8819 block_group = btrfs_lookup_first_block_group(info, last);
8820 while (block_group) { 8820 while (block_group) {
8821 spin_lock(&block_group->lock); 8821 spin_lock(&block_group->lock);
8822 if (block_group->iref) 8822 if (block_group->iref)
8823 break; 8823 break;
8824 spin_unlock(&block_group->lock); 8824 spin_unlock(&block_group->lock);
8825 block_group = next_block_group(info->tree_root, 8825 block_group = next_block_group(info->tree_root,
8826 block_group); 8826 block_group);
8827 } 8827 }
8828 if (!block_group) { 8828 if (!block_group) {
8829 if (last == 0) 8829 if (last == 0)
8830 break; 8830 break;
8831 last = 0; 8831 last = 0;
8832 continue; 8832 continue;
8833 } 8833 }
8834 8834
8835 inode = block_group->inode; 8835 inode = block_group->inode;
8836 block_group->iref = 0; 8836 block_group->iref = 0;
8837 block_group->inode = NULL; 8837 block_group->inode = NULL;
8838 spin_unlock(&block_group->lock); 8838 spin_unlock(&block_group->lock);
8839 iput(inode); 8839 iput(inode);
8840 last = block_group->key.objectid + block_group->key.offset; 8840 last = block_group->key.objectid + block_group->key.offset;
8841 btrfs_put_block_group(block_group); 8841 btrfs_put_block_group(block_group);
8842 } 8842 }
8843 } 8843 }
8844 8844
8845 int btrfs_free_block_groups(struct btrfs_fs_info *info) 8845 int btrfs_free_block_groups(struct btrfs_fs_info *info)
8846 { 8846 {
8847 struct btrfs_block_group_cache *block_group; 8847 struct btrfs_block_group_cache *block_group;
8848 struct btrfs_space_info *space_info; 8848 struct btrfs_space_info *space_info;
8849 struct btrfs_caching_control *caching_ctl; 8849 struct btrfs_caching_control *caching_ctl;
8850 struct rb_node *n; 8850 struct rb_node *n;
8851 8851
8852 down_write(&info->commit_root_sem); 8852 down_write(&info->commit_root_sem);
8853 while (!list_empty(&info->caching_block_groups)) { 8853 while (!list_empty(&info->caching_block_groups)) {
8854 caching_ctl = list_entry(info->caching_block_groups.next, 8854 caching_ctl = list_entry(info->caching_block_groups.next,
8855 struct btrfs_caching_control, list); 8855 struct btrfs_caching_control, list);
8856 list_del(&caching_ctl->list); 8856 list_del(&caching_ctl->list);
8857 put_caching_control(caching_ctl); 8857 put_caching_control(caching_ctl);
8858 } 8858 }
8859 up_write(&info->commit_root_sem); 8859 up_write(&info->commit_root_sem);
8860 8860
8861 spin_lock(&info->unused_bgs_lock); 8861 spin_lock(&info->unused_bgs_lock);
8862 while (!list_empty(&info->unused_bgs)) { 8862 while (!list_empty(&info->unused_bgs)) {
8863 block_group = list_first_entry(&info->unused_bgs, 8863 block_group = list_first_entry(&info->unused_bgs,
8864 struct btrfs_block_group_cache, 8864 struct btrfs_block_group_cache,
8865 bg_list); 8865 bg_list);
8866 list_del_init(&block_group->bg_list); 8866 list_del_init(&block_group->bg_list);
8867 btrfs_put_block_group(block_group); 8867 btrfs_put_block_group(block_group);
8868 } 8868 }
8869 spin_unlock(&info->unused_bgs_lock); 8869 spin_unlock(&info->unused_bgs_lock);
8870 8870
8871 spin_lock(&info->block_group_cache_lock); 8871 spin_lock(&info->block_group_cache_lock);
8872 while ((n = rb_last(&info->block_group_cache_tree)) != NULL) { 8872 while ((n = rb_last(&info->block_group_cache_tree)) != NULL) {
8873 block_group = rb_entry(n, struct btrfs_block_group_cache, 8873 block_group = rb_entry(n, struct btrfs_block_group_cache,
8874 cache_node); 8874 cache_node);
8875 rb_erase(&block_group->cache_node, 8875 rb_erase(&block_group->cache_node,
8876 &info->block_group_cache_tree); 8876 &info->block_group_cache_tree);
8877 RB_CLEAR_NODE(&block_group->cache_node); 8877 RB_CLEAR_NODE(&block_group->cache_node);
8878 spin_unlock(&info->block_group_cache_lock); 8878 spin_unlock(&info->block_group_cache_lock);
8879 8879
8880 down_write(&block_group->space_info->groups_sem); 8880 down_write(&block_group->space_info->groups_sem);
8881 list_del(&block_group->list); 8881 list_del(&block_group->list);
8882 up_write(&block_group->space_info->groups_sem); 8882 up_write(&block_group->space_info->groups_sem);
8883 8883
8884 if (block_group->cached == BTRFS_CACHE_STARTED) 8884 if (block_group->cached == BTRFS_CACHE_STARTED)
8885 wait_block_group_cache_done(block_group); 8885 wait_block_group_cache_done(block_group);
8886 8886
8887 /* 8887 /*
8888 * We haven't cached this block group, which means we could 8888 * We haven't cached this block group, which means we could
8889 * possibly have excluded extents on this block group. 8889 * possibly have excluded extents on this block group.
8890 */ 8890 */
8891 if (block_group->cached == BTRFS_CACHE_NO || 8891 if (block_group->cached == BTRFS_CACHE_NO ||
8892 block_group->cached == BTRFS_CACHE_ERROR) 8892 block_group->cached == BTRFS_CACHE_ERROR)
8893 free_excluded_extents(info->extent_root, block_group); 8893 free_excluded_extents(info->extent_root, block_group);
8894 8894
8895 btrfs_remove_free_space_cache(block_group); 8895 btrfs_remove_free_space_cache(block_group);
8896 btrfs_put_block_group(block_group); 8896 btrfs_put_block_group(block_group);
8897 8897
8898 spin_lock(&info->block_group_cache_lock); 8898 spin_lock(&info->block_group_cache_lock);
8899 } 8899 }
8900 spin_unlock(&info->block_group_cache_lock); 8900 spin_unlock(&info->block_group_cache_lock);
8901 8901
8902 /* now that all the block groups are freed, go through and 8902 /* now that all the block groups are freed, go through and
8903 * free all the space_info structs. This is only called during 8903 * free all the space_info structs. This is only called during
8904 * the final stages of unmount, and so we know nobody is 8904 * the final stages of unmount, and so we know nobody is
8905 * using them. We call synchronize_rcu() once before we start, 8905 * using them. We call synchronize_rcu() once before we start,
8906 * just to be on the safe side. 8906 * just to be on the safe side.
8907 */ 8907 */
8908 synchronize_rcu(); 8908 synchronize_rcu();
8909 8909
8910 release_global_block_rsv(info); 8910 release_global_block_rsv(info);
8911 8911
8912 while (!list_empty(&info->space_info)) { 8912 while (!list_empty(&info->space_info)) {
8913 int i; 8913 int i;
8914 8914
8915 space_info = list_entry(info->space_info.next, 8915 space_info = list_entry(info->space_info.next,
8916 struct btrfs_space_info, 8916 struct btrfs_space_info,
8917 list); 8917 list);
8918 if (btrfs_test_opt(info->tree_root, ENOSPC_DEBUG)) { 8918 if (btrfs_test_opt(info->tree_root, ENOSPC_DEBUG)) {
8919 if (WARN_ON(space_info->bytes_pinned > 0 || 8919 if (WARN_ON(space_info->bytes_pinned > 0 ||
8920 space_info->bytes_reserved > 0 || 8920 space_info->bytes_reserved > 0 ||
8921 space_info->bytes_may_use > 0)) { 8921 space_info->bytes_may_use > 0)) {
8922 dump_space_info(space_info, 0, 0); 8922 dump_space_info(space_info, 0, 0);
8923 } 8923 }
8924 } 8924 }
8925 list_del(&space_info->list); 8925 list_del(&space_info->list);
8926 for (i = 0; i < BTRFS_NR_RAID_TYPES; i++) { 8926 for (i = 0; i < BTRFS_NR_RAID_TYPES; i++) {
8927 struct kobject *kobj; 8927 struct kobject *kobj;
8928 kobj = space_info->block_group_kobjs[i]; 8928 kobj = space_info->block_group_kobjs[i];
8929 space_info->block_group_kobjs[i] = NULL; 8929 space_info->block_group_kobjs[i] = NULL;
8930 if (kobj) { 8930 if (kobj) {
8931 kobject_del(kobj); 8931 kobject_del(kobj);
8932 kobject_put(kobj); 8932 kobject_put(kobj);
8933 } 8933 }
8934 } 8934 }
8935 kobject_del(&space_info->kobj); 8935 kobject_del(&space_info->kobj);
8936 kobject_put(&space_info->kobj); 8936 kobject_put(&space_info->kobj);
8937 } 8937 }
8938 return 0; 8938 return 0;
8939 } 8939 }
8940 8940
8941 static void __link_block_group(struct btrfs_space_info *space_info, 8941 static void __link_block_group(struct btrfs_space_info *space_info,
8942 struct btrfs_block_group_cache *cache) 8942 struct btrfs_block_group_cache *cache)
8943 { 8943 {
8944 int index = get_block_group_index(cache); 8944 int index = get_block_group_index(cache);
8945 bool first = false; 8945 bool first = false;
8946 8946
8947 down_write(&space_info->groups_sem); 8947 down_write(&space_info->groups_sem);
8948 if (list_empty(&space_info->block_groups[index])) 8948 if (list_empty(&space_info->block_groups[index]))
8949 first = true; 8949 first = true;
8950 list_add_tail(&cache->list, &space_info->block_groups[index]); 8950 list_add_tail(&cache->list, &space_info->block_groups[index]);
8951 up_write(&space_info->groups_sem); 8951 up_write(&space_info->groups_sem);
8952 8952
8953 if (first) { 8953 if (first) {
8954 struct raid_kobject *rkobj; 8954 struct raid_kobject *rkobj;
8955 int ret; 8955 int ret;
8956 8956
8957 rkobj = kzalloc(sizeof(*rkobj), GFP_NOFS); 8957 rkobj = kzalloc(sizeof(*rkobj), GFP_NOFS);
8958 if (!rkobj) 8958 if (!rkobj)
8959 goto out_err; 8959 goto out_err;
8960 rkobj->raid_type = index; 8960 rkobj->raid_type = index;
8961 kobject_init(&rkobj->kobj, &btrfs_raid_ktype); 8961 kobject_init(&rkobj->kobj, &btrfs_raid_ktype);
8962 ret = kobject_add(&rkobj->kobj, &space_info->kobj, 8962 ret = kobject_add(&rkobj->kobj, &space_info->kobj,
8963 "%s", get_raid_name(index)); 8963 "%s", get_raid_name(index));
8964 if (ret) { 8964 if (ret) {
8965 kobject_put(&rkobj->kobj); 8965 kobject_put(&rkobj->kobj);
8966 goto out_err; 8966 goto out_err;
8967 } 8967 }
8968 space_info->block_group_kobjs[index] = &rkobj->kobj; 8968 space_info->block_group_kobjs[index] = &rkobj->kobj;
8969 } 8969 }
8970 8970
8971 return; 8971 return;
8972 out_err: 8972 out_err:
8973 pr_warn("BTRFS: failed to add kobject for block cache. ignoring.\n"); 8973 pr_warn("BTRFS: failed to add kobject for block cache. ignoring.\n");
8974 } 8974 }
8975 8975
8976 static struct btrfs_block_group_cache * 8976 static struct btrfs_block_group_cache *
8977 btrfs_create_block_group_cache(struct btrfs_root *root, u64 start, u64 size) 8977 btrfs_create_block_group_cache(struct btrfs_root *root, u64 start, u64 size)
8978 { 8978 {
8979 struct btrfs_block_group_cache *cache; 8979 struct btrfs_block_group_cache *cache;
8980 8980
8981 cache = kzalloc(sizeof(*cache), GFP_NOFS); 8981 cache = kzalloc(sizeof(*cache), GFP_NOFS);
8982 if (!cache) 8982 if (!cache)
8983 return NULL; 8983 return NULL;
8984 8984
8985 cache->free_space_ctl = kzalloc(sizeof(*cache->free_space_ctl), 8985 cache->free_space_ctl = kzalloc(sizeof(*cache->free_space_ctl),
8986 GFP_NOFS); 8986 GFP_NOFS);
8987 if (!cache->free_space_ctl) { 8987 if (!cache->free_space_ctl) {
8988 kfree(cache); 8988 kfree(cache);
8989 return NULL; 8989 return NULL;
8990 } 8990 }
8991 8991
8992 cache->key.objectid = start; 8992 cache->key.objectid = start;
8993 cache->key.offset = size; 8993 cache->key.offset = size;
8994 cache->key.type = BTRFS_BLOCK_GROUP_ITEM_KEY; 8994 cache->key.type = BTRFS_BLOCK_GROUP_ITEM_KEY;
8995 8995
8996 cache->sectorsize = root->sectorsize; 8996 cache->sectorsize = root->sectorsize;
8997 cache->fs_info = root->fs_info; 8997 cache->fs_info = root->fs_info;
8998 cache->full_stripe_len = btrfs_full_stripe_len(root, 8998 cache->full_stripe_len = btrfs_full_stripe_len(root,
8999 &root->fs_info->mapping_tree, 8999 &root->fs_info->mapping_tree,
9000 start); 9000 start);
9001 atomic_set(&cache->count, 1); 9001 atomic_set(&cache->count, 1);
9002 spin_lock_init(&cache->lock); 9002 spin_lock_init(&cache->lock);
9003 init_rwsem(&cache->data_rwsem); 9003 init_rwsem(&cache->data_rwsem);
9004 INIT_LIST_HEAD(&cache->list); 9004 INIT_LIST_HEAD(&cache->list);
9005 INIT_LIST_HEAD(&cache->cluster_list); 9005 INIT_LIST_HEAD(&cache->cluster_list);
9006 INIT_LIST_HEAD(&cache->bg_list); 9006 INIT_LIST_HEAD(&cache->bg_list);
9007 INIT_LIST_HEAD(&cache->ro_list); 9007 INIT_LIST_HEAD(&cache->ro_list);
9008 btrfs_init_free_space_ctl(cache); 9008 btrfs_init_free_space_ctl(cache);
9009 atomic_set(&cache->trimming, 0); 9009 atomic_set(&cache->trimming, 0);
9010 9010
9011 return cache; 9011 return cache;
9012 } 9012 }
9013 9013
9014 int btrfs_read_block_groups(struct btrfs_root *root) 9014 int btrfs_read_block_groups(struct btrfs_root *root)
9015 { 9015 {
9016 struct btrfs_path *path; 9016 struct btrfs_path *path;
9017 int ret; 9017 int ret;
9018 struct btrfs_block_group_cache *cache; 9018 struct btrfs_block_group_cache *cache;
9019 struct btrfs_fs_info *info = root->fs_info; 9019 struct btrfs_fs_info *info = root->fs_info;
9020 struct btrfs_space_info *space_info; 9020 struct btrfs_space_info *space_info;
9021 struct btrfs_key key; 9021 struct btrfs_key key;
9022 struct btrfs_key found_key; 9022 struct btrfs_key found_key;
9023 struct extent_buffer *leaf; 9023 struct extent_buffer *leaf;
9024 int need_clear = 0; 9024 int need_clear = 0;
9025 u64 cache_gen; 9025 u64 cache_gen;
9026 9026
9027 root = info->extent_root; 9027 root = info->extent_root;
9028 key.objectid = 0; 9028 key.objectid = 0;
9029 key.offset = 0; 9029 key.offset = 0;
9030 key.type = BTRFS_BLOCK_GROUP_ITEM_KEY; 9030 key.type = BTRFS_BLOCK_GROUP_ITEM_KEY;
9031 path = btrfs_alloc_path(); 9031 path = btrfs_alloc_path();
9032 if (!path) 9032 if (!path)
9033 return -ENOMEM; 9033 return -ENOMEM;
9034 path->reada = 1; 9034 path->reada = 1;
9035 9035
9036 cache_gen = btrfs_super_cache_generation(root->fs_info->super_copy); 9036 cache_gen = btrfs_super_cache_generation(root->fs_info->super_copy);
9037 if (btrfs_test_opt(root, SPACE_CACHE) && 9037 if (btrfs_test_opt(root, SPACE_CACHE) &&
9038 btrfs_super_generation(root->fs_info->super_copy) != cache_gen) 9038 btrfs_super_generation(root->fs_info->super_copy) != cache_gen)
9039 need_clear = 1; 9039 need_clear = 1;
9040 if (btrfs_test_opt(root, CLEAR_CACHE)) 9040 if (btrfs_test_opt(root, CLEAR_CACHE))
9041 need_clear = 1; 9041 need_clear = 1;
9042 9042
9043 while (1) { 9043 while (1) {
9044 ret = find_first_block_group(root, path, &key); 9044 ret = find_first_block_group(root, path, &key);
9045 if (ret > 0) 9045 if (ret > 0)
9046 break; 9046 break;
9047 if (ret != 0) 9047 if (ret != 0)
9048 goto error; 9048 goto error;
9049 9049
9050 leaf = path->nodes[0]; 9050 leaf = path->nodes[0];
9051 btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]); 9051 btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]);
9052 9052
9053 cache = btrfs_create_block_group_cache(root, found_key.objectid, 9053 cache = btrfs_create_block_group_cache(root, found_key.objectid,
9054 found_key.offset); 9054 found_key.offset);
9055 if (!cache) { 9055 if (!cache) {
9056 ret = -ENOMEM; 9056 ret = -ENOMEM;
9057 goto error; 9057 goto error;
9058 } 9058 }
9059 9059
9060 if (need_clear) { 9060 if (need_clear) {
9061 /* 9061 /*
9062 * When we mount with old space cache, we need to 9062 * When we mount with old space cache, we need to
9063 * set BTRFS_DC_CLEAR and set dirty flag. 9063 * set BTRFS_DC_CLEAR and set dirty flag.
9064 * 9064 *
9065 * a) Setting 'BTRFS_DC_CLEAR' makes sure that we 9065 * a) Setting 'BTRFS_DC_CLEAR' makes sure that we
9066 * truncate the old free space cache inode and 9066 * truncate the old free space cache inode and
9067 * setup a new one. 9067 * setup a new one.
9068 * b) Setting 'dirty flag' makes sure that we flush 9068 * b) Setting 'dirty flag' makes sure that we flush
9069 * the new space cache info onto disk. 9069 * the new space cache info onto disk.
9070 */ 9070 */
9071 cache->disk_cache_state = BTRFS_DC_CLEAR; 9071 cache->disk_cache_state = BTRFS_DC_CLEAR;
9072 if (btrfs_test_opt(root, SPACE_CACHE)) 9072 if (btrfs_test_opt(root, SPACE_CACHE))
9073 cache->dirty = 1; 9073 cache->dirty = 1;
9074 } 9074 }
9075 9075
9076 read_extent_buffer(leaf, &cache->item, 9076 read_extent_buffer(leaf, &cache->item,
9077 btrfs_item_ptr_offset(leaf, path->slots[0]), 9077 btrfs_item_ptr_offset(leaf, path->slots[0]),
9078 sizeof(cache->item)); 9078 sizeof(cache->item));
9079 cache->flags = btrfs_block_group_flags(&cache->item); 9079 cache->flags = btrfs_block_group_flags(&cache->item);
9080 9080
9081 key.objectid = found_key.objectid + found_key.offset; 9081 key.objectid = found_key.objectid + found_key.offset;
9082 btrfs_release_path(path); 9082 btrfs_release_path(path);
9083 9083
9084 /* 9084 /*
9085 * We need to exclude the super stripes now so that the space 9085 * We need to exclude the super stripes now so that the space
9086 * info has super bytes accounted for, otherwise we'll think 9086 * info has super bytes accounted for, otherwise we'll think
9087 * we have more space than we actually do. 9087 * we have more space than we actually do.
9088 */ 9088 */
9089 ret = exclude_super_stripes(root, cache); 9089 ret = exclude_super_stripes(root, cache);
9090 if (ret) { 9090 if (ret) {
9091 /* 9091 /*
9092 * We may have excluded something, so call this just in 9092 * We may have excluded something, so call this just in
9093 * case. 9093 * case.
9094 */ 9094 */
9095 free_excluded_extents(root, cache); 9095 free_excluded_extents(root, cache);
9096 btrfs_put_block_group(cache); 9096 btrfs_put_block_group(cache);
9097 goto error; 9097 goto error;
9098 } 9098 }
9099 9099
9100 /* 9100 /*
9101 * check for two cases, either we are full, and therefore 9101 * check for two cases, either we are full, and therefore
9102 * don't need to bother with the caching work since we won't 9102 * don't need to bother with the caching work since we won't
9103 * find any space, or we are empty, and we can just add all 9103 * find any space, or we are empty, and we can just add all
9104 * the space in and be done with it. This saves us _alot_ of 9104 * the space in and be done with it. This saves us _alot_ of
9105 * time, particularly in the full case. 9105 * time, particularly in the full case.
9106 */ 9106 */
9107 if (found_key.offset == btrfs_block_group_used(&cache->item)) { 9107 if (found_key.offset == btrfs_block_group_used(&cache->item)) {
9108 cache->last_byte_to_unpin = (u64)-1; 9108 cache->last_byte_to_unpin = (u64)-1;
9109 cache->cached = BTRFS_CACHE_FINISHED; 9109 cache->cached = BTRFS_CACHE_FINISHED;
9110 free_excluded_extents(root, cache); 9110 free_excluded_extents(root, cache);
9111 } else if (btrfs_block_group_used(&cache->item) == 0) { 9111 } else if (btrfs_block_group_used(&cache->item) == 0) {
9112 cache->last_byte_to_unpin = (u64)-1; 9112 cache->last_byte_to_unpin = (u64)-1;
9113 cache->cached = BTRFS_CACHE_FINISHED; 9113 cache->cached = BTRFS_CACHE_FINISHED;
9114 add_new_free_space(cache, root->fs_info, 9114 add_new_free_space(cache, root->fs_info,
9115 found_key.objectid, 9115 found_key.objectid,
9116 found_key.objectid + 9116 found_key.objectid +
9117 found_key.offset); 9117 found_key.offset);
9118 free_excluded_extents(root, cache); 9118 free_excluded_extents(root, cache);
9119 } 9119 }
9120 9120
9121 ret = btrfs_add_block_group_cache(root->fs_info, cache); 9121 ret = btrfs_add_block_group_cache(root->fs_info, cache);
9122 if (ret) { 9122 if (ret) {
9123 btrfs_remove_free_space_cache(cache); 9123 btrfs_remove_free_space_cache(cache);
9124 btrfs_put_block_group(cache); 9124 btrfs_put_block_group(cache);
9125 goto error; 9125 goto error;
9126 } 9126 }
9127 9127
9128 ret = update_space_info(info, cache->flags, found_key.offset, 9128 ret = update_space_info(info, cache->flags, found_key.offset,
9129 btrfs_block_group_used(&cache->item), 9129 btrfs_block_group_used(&cache->item),
9130 &space_info); 9130 &space_info);
9131 if (ret) { 9131 if (ret) {
9132 btrfs_remove_free_space_cache(cache); 9132 btrfs_remove_free_space_cache(cache);
9133 spin_lock(&info->block_group_cache_lock); 9133 spin_lock(&info->block_group_cache_lock);
9134 rb_erase(&cache->cache_node, 9134 rb_erase(&cache->cache_node,
9135 &info->block_group_cache_tree); 9135 &info->block_group_cache_tree);
9136 RB_CLEAR_NODE(&cache->cache_node); 9136 RB_CLEAR_NODE(&cache->cache_node);
9137 spin_unlock(&info->block_group_cache_lock); 9137 spin_unlock(&info->block_group_cache_lock);
9138 btrfs_put_block_group(cache); 9138 btrfs_put_block_group(cache);
9139 goto error; 9139 goto error;
9140 } 9140 }
9141 9141
9142 cache->space_info = space_info; 9142 cache->space_info = space_info;
9143 spin_lock(&cache->space_info->lock); 9143 spin_lock(&cache->space_info->lock);
9144 cache->space_info->bytes_readonly += cache->bytes_super; 9144 cache->space_info->bytes_readonly += cache->bytes_super;
9145 spin_unlock(&cache->space_info->lock); 9145 spin_unlock(&cache->space_info->lock);
9146 9146
9147 __link_block_group(space_info, cache); 9147 __link_block_group(space_info, cache);
9148 9148
9149 set_avail_alloc_bits(root->fs_info, cache->flags); 9149 set_avail_alloc_bits(root->fs_info, cache->flags);
9150 if (btrfs_chunk_readonly(root, cache->key.objectid)) { 9150 if (btrfs_chunk_readonly(root, cache->key.objectid)) {
9151 set_block_group_ro(cache, 1); 9151 set_block_group_ro(cache, 1);
9152 } else if (btrfs_block_group_used(&cache->item) == 0) { 9152 } else if (btrfs_block_group_used(&cache->item) == 0) {
9153 spin_lock(&info->unused_bgs_lock); 9153 spin_lock(&info->unused_bgs_lock);
9154 /* Should always be true but just in case. */ 9154 /* Should always be true but just in case. */
9155 if (list_empty(&cache->bg_list)) { 9155 if (list_empty(&cache->bg_list)) {
9156 btrfs_get_block_group(cache); 9156 btrfs_get_block_group(cache);
9157 list_add_tail(&cache->bg_list, 9157 list_add_tail(&cache->bg_list,
9158 &info->unused_bgs); 9158 &info->unused_bgs);
9159 } 9159 }
9160 spin_unlock(&info->unused_bgs_lock); 9160 spin_unlock(&info->unused_bgs_lock);
9161 } 9161 }
9162 } 9162 }
9163 9163
9164 list_for_each_entry_rcu(space_info, &root->fs_info->space_info, list) { 9164 list_for_each_entry_rcu(space_info, &root->fs_info->space_info, list) {
9165 if (!(get_alloc_profile(root, space_info->flags) & 9165 if (!(get_alloc_profile(root, space_info->flags) &
9166 (BTRFS_BLOCK_GROUP_RAID10 | 9166 (BTRFS_BLOCK_GROUP_RAID10 |
9167 BTRFS_BLOCK_GROUP_RAID1 | 9167 BTRFS_BLOCK_GROUP_RAID1 |
9168 BTRFS_BLOCK_GROUP_RAID5 | 9168 BTRFS_BLOCK_GROUP_RAID5 |
9169 BTRFS_BLOCK_GROUP_RAID6 | 9169 BTRFS_BLOCK_GROUP_RAID6 |
9170 BTRFS_BLOCK_GROUP_DUP))) 9170 BTRFS_BLOCK_GROUP_DUP)))
9171 continue; 9171 continue;
9172 /* 9172 /*
9173 * avoid allocating from un-mirrored block group if there are 9173 * avoid allocating from un-mirrored block group if there are
9174 * mirrored block groups. 9174 * mirrored block groups.
9175 */ 9175 */
9176 list_for_each_entry(cache, 9176 list_for_each_entry(cache,
9177 &space_info->block_groups[BTRFS_RAID_RAID0], 9177 &space_info->block_groups[BTRFS_RAID_RAID0],
9178 list) 9178 list)
9179 set_block_group_ro(cache, 1); 9179 set_block_group_ro(cache, 1);
9180 list_for_each_entry(cache, 9180 list_for_each_entry(cache,
9181 &space_info->block_groups[BTRFS_RAID_SINGLE], 9181 &space_info->block_groups[BTRFS_RAID_SINGLE],
9182 list) 9182 list)
9183 set_block_group_ro(cache, 1); 9183 set_block_group_ro(cache, 1);
9184 } 9184 }
9185 9185
9186 init_global_block_rsv(info); 9186 init_global_block_rsv(info);
9187 ret = 0; 9187 ret = 0;
9188 error: 9188 error:
9189 btrfs_free_path(path); 9189 btrfs_free_path(path);
9190 return ret; 9190 return ret;
9191 } 9191 }
9192 9192
9193 void btrfs_create_pending_block_groups(struct btrfs_trans_handle *trans, 9193 void btrfs_create_pending_block_groups(struct btrfs_trans_handle *trans,
9194 struct btrfs_root *root) 9194 struct btrfs_root *root)
9195 { 9195 {
9196 struct btrfs_block_group_cache *block_group, *tmp; 9196 struct btrfs_block_group_cache *block_group, *tmp;
9197 struct btrfs_root *extent_root = root->fs_info->extent_root; 9197 struct btrfs_root *extent_root = root->fs_info->extent_root;
9198 struct btrfs_block_group_item item; 9198 struct btrfs_block_group_item item;
9199 struct btrfs_key key; 9199 struct btrfs_key key;
9200 int ret = 0; 9200 int ret = 0;
9201 9201
9202 list_for_each_entry_safe(block_group, tmp, &trans->new_bgs, bg_list) { 9202 list_for_each_entry_safe(block_group, tmp, &trans->new_bgs, bg_list) {
9203 if (ret) 9203 if (ret)
9204 goto next; 9204 goto next;
9205 9205
9206 spin_lock(&block_group->lock); 9206 spin_lock(&block_group->lock);
9207 memcpy(&item, &block_group->item, sizeof(item)); 9207 memcpy(&item, &block_group->item, sizeof(item));
9208 memcpy(&key, &block_group->key, sizeof(key)); 9208 memcpy(&key, &block_group->key, sizeof(key));
9209 spin_unlock(&block_group->lock); 9209 spin_unlock(&block_group->lock);
9210 9210
9211 ret = btrfs_insert_item(trans, extent_root, &key, &item, 9211 ret = btrfs_insert_item(trans, extent_root, &key, &item,
9212 sizeof(item)); 9212 sizeof(item));
9213 if (ret) 9213 if (ret)
9214 btrfs_abort_transaction(trans, extent_root, ret); 9214 btrfs_abort_transaction(trans, extent_root, ret);
9215 ret = btrfs_finish_chunk_alloc(trans, extent_root, 9215 ret = btrfs_finish_chunk_alloc(trans, extent_root,
9216 key.objectid, key.offset); 9216 key.objectid, key.offset);
9217 if (ret) 9217 if (ret)
9218 btrfs_abort_transaction(trans, extent_root, ret); 9218 btrfs_abort_transaction(trans, extent_root, ret);
9219 next: 9219 next:
9220 list_del_init(&block_group->bg_list); 9220 list_del_init(&block_group->bg_list);
9221 } 9221 }
9222 } 9222 }
9223 9223
9224 int btrfs_make_block_group(struct btrfs_trans_handle *trans, 9224 int btrfs_make_block_group(struct btrfs_trans_handle *trans,
9225 struct btrfs_root *root, u64 bytes_used, 9225 struct btrfs_root *root, u64 bytes_used,
9226 u64 type, u64 chunk_objectid, u64 chunk_offset, 9226 u64 type, u64 chunk_objectid, u64 chunk_offset,
9227 u64 size) 9227 u64 size)
9228 { 9228 {
9229 int ret; 9229 int ret;
9230 struct btrfs_root *extent_root; 9230 struct btrfs_root *extent_root;
9231 struct btrfs_block_group_cache *cache; 9231 struct btrfs_block_group_cache *cache;
9232 9232
9233 extent_root = root->fs_info->extent_root; 9233 extent_root = root->fs_info->extent_root;
9234 9234
9235 btrfs_set_log_full_commit(root->fs_info, trans); 9235 btrfs_set_log_full_commit(root->fs_info, trans);
9236 9236
9237 cache = btrfs_create_block_group_cache(root, chunk_offset, size); 9237 cache = btrfs_create_block_group_cache(root, chunk_offset, size);
9238 if (!cache) 9238 if (!cache)
9239 return -ENOMEM; 9239 return -ENOMEM;
9240 9240
9241 btrfs_set_block_group_used(&cache->item, bytes_used); 9241 btrfs_set_block_group_used(&cache->item, bytes_used);
9242 btrfs_set_block_group_chunk_objectid(&cache->item, chunk_objectid); 9242 btrfs_set_block_group_chunk_objectid(&cache->item, chunk_objectid);
9243 btrfs_set_block_group_flags(&cache->item, type); 9243 btrfs_set_block_group_flags(&cache->item, type);
9244 9244
9245 cache->flags = type; 9245 cache->flags = type;
9246 cache->last_byte_to_unpin = (u64)-1; 9246 cache->last_byte_to_unpin = (u64)-1;
9247 cache->cached = BTRFS_CACHE_FINISHED; 9247 cache->cached = BTRFS_CACHE_FINISHED;
9248 ret = exclude_super_stripes(root, cache); 9248 ret = exclude_super_stripes(root, cache);
9249 if (ret) { 9249 if (ret) {
9250 /* 9250 /*
9251 * We may have excluded something, so call this just in 9251 * We may have excluded something, so call this just in
9252 * case. 9252 * case.
9253 */ 9253 */
9254 free_excluded_extents(root, cache); 9254 free_excluded_extents(root, cache);
9255 btrfs_put_block_group(cache); 9255 btrfs_put_block_group(cache);
9256 return ret; 9256 return ret;
9257 } 9257 }
9258 9258
9259 add_new_free_space(cache, root->fs_info, chunk_offset, 9259 add_new_free_space(cache, root->fs_info, chunk_offset,
9260 chunk_offset + size); 9260 chunk_offset + size);
9261 9261
9262 free_excluded_extents(root, cache); 9262 free_excluded_extents(root, cache);
9263 9263
9264 ret = btrfs_add_block_group_cache(root->fs_info, cache); 9264 ret = btrfs_add_block_group_cache(root->fs_info, cache);
9265 if (ret) { 9265 if (ret) {
9266 btrfs_remove_free_space_cache(cache); 9266 btrfs_remove_free_space_cache(cache);
9267 btrfs_put_block_group(cache); 9267 btrfs_put_block_group(cache);
9268 return ret; 9268 return ret;
9269 } 9269 }
9270 9270
9271 ret = update_space_info(root->fs_info, cache->flags, size, bytes_used, 9271 ret = update_space_info(root->fs_info, cache->flags, size, bytes_used,
9272 &cache->space_info); 9272 &cache->space_info);
9273 if (ret) { 9273 if (ret) {
9274 btrfs_remove_free_space_cache(cache); 9274 btrfs_remove_free_space_cache(cache);
9275 spin_lock(&root->fs_info->block_group_cache_lock); 9275 spin_lock(&root->fs_info->block_group_cache_lock);
9276 rb_erase(&cache->cache_node, 9276 rb_erase(&cache->cache_node,
9277 &root->fs_info->block_group_cache_tree); 9277 &root->fs_info->block_group_cache_tree);
9278 RB_CLEAR_NODE(&cache->cache_node); 9278 RB_CLEAR_NODE(&cache->cache_node);
9279 spin_unlock(&root->fs_info->block_group_cache_lock); 9279 spin_unlock(&root->fs_info->block_group_cache_lock);
9280 btrfs_put_block_group(cache); 9280 btrfs_put_block_group(cache);
9281 return ret; 9281 return ret;
9282 } 9282 }
9283 update_global_block_rsv(root->fs_info); 9283 update_global_block_rsv(root->fs_info);
9284 9284
9285 spin_lock(&cache->space_info->lock); 9285 spin_lock(&cache->space_info->lock);
9286 cache->space_info->bytes_readonly += cache->bytes_super; 9286 cache->space_info->bytes_readonly += cache->bytes_super;
9287 spin_unlock(&cache->space_info->lock); 9287 spin_unlock(&cache->space_info->lock);
9288 9288
9289 __link_block_group(cache->space_info, cache); 9289 __link_block_group(cache->space_info, cache);
9290 9290
9291 list_add_tail(&cache->bg_list, &trans->new_bgs); 9291 list_add_tail(&cache->bg_list, &trans->new_bgs);
9292 9292
9293 set_avail_alloc_bits(extent_root->fs_info, type); 9293 set_avail_alloc_bits(extent_root->fs_info, type);
9294 9294
9295 return 0; 9295 return 0;
9296 } 9296 }
9297 9297
9298 static void clear_avail_alloc_bits(struct btrfs_fs_info *fs_info, u64 flags) 9298 static void clear_avail_alloc_bits(struct btrfs_fs_info *fs_info, u64 flags)
9299 { 9299 {
9300 u64 extra_flags = chunk_to_extended(flags) & 9300 u64 extra_flags = chunk_to_extended(flags) &
9301 BTRFS_EXTENDED_PROFILE_MASK; 9301 BTRFS_EXTENDED_PROFILE_MASK;
9302 9302
9303 write_seqlock(&fs_info->profiles_lock); 9303 write_seqlock(&fs_info->profiles_lock);
9304 if (flags & BTRFS_BLOCK_GROUP_DATA) 9304 if (flags & BTRFS_BLOCK_GROUP_DATA)
9305 fs_info->avail_data_alloc_bits &= ~extra_flags; 9305 fs_info->avail_data_alloc_bits &= ~extra_flags;
9306 if (flags & BTRFS_BLOCK_GROUP_METADATA) 9306 if (flags & BTRFS_BLOCK_GROUP_METADATA)
9307 fs_info->avail_metadata_alloc_bits &= ~extra_flags; 9307 fs_info->avail_metadata_alloc_bits &= ~extra_flags;
9308 if (flags & BTRFS_BLOCK_GROUP_SYSTEM) 9308 if (flags & BTRFS_BLOCK_GROUP_SYSTEM)
9309 fs_info->avail_system_alloc_bits &= ~extra_flags; 9309 fs_info->avail_system_alloc_bits &= ~extra_flags;
9310 write_sequnlock(&fs_info->profiles_lock); 9310 write_sequnlock(&fs_info->profiles_lock);
9311 } 9311 }
9312 9312
9313 int btrfs_remove_block_group(struct btrfs_trans_handle *trans, 9313 int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
9314 struct btrfs_root *root, u64 group_start, 9314 struct btrfs_root *root, u64 group_start,
9315 struct extent_map *em) 9315 struct extent_map *em)
9316 { 9316 {
9317 struct btrfs_path *path; 9317 struct btrfs_path *path;
9318 struct btrfs_block_group_cache *block_group; 9318 struct btrfs_block_group_cache *block_group;
9319 struct btrfs_free_cluster *cluster; 9319 struct btrfs_free_cluster *cluster;
9320 struct btrfs_root *tree_root = root->fs_info->tree_root; 9320 struct btrfs_root *tree_root = root->fs_info->tree_root;
9321 struct btrfs_key key; 9321 struct btrfs_key key;
9322 struct inode *inode; 9322 struct inode *inode;
9323 struct kobject *kobj = NULL; 9323 struct kobject *kobj = NULL;
9324 int ret; 9324 int ret;
9325 int index; 9325 int index;
9326 int factor; 9326 int factor;
9327 struct btrfs_caching_control *caching_ctl = NULL; 9327 struct btrfs_caching_control *caching_ctl = NULL;
9328 bool remove_em; 9328 bool remove_em;
9329 9329
9330 root = root->fs_info->extent_root; 9330 root = root->fs_info->extent_root;
9331 9331
9332 block_group = btrfs_lookup_block_group(root->fs_info, group_start); 9332 block_group = btrfs_lookup_block_group(root->fs_info, group_start);
9333 BUG_ON(!block_group); 9333 BUG_ON(!block_group);
9334 BUG_ON(!block_group->ro); 9334 BUG_ON(!block_group->ro);
9335 9335
9336 /* 9336 /*
9337 * Free the reserved super bytes from this block group before 9337 * Free the reserved super bytes from this block group before
9338 * remove it. 9338 * remove it.
9339 */ 9339 */
9340 free_excluded_extents(root, block_group); 9340 free_excluded_extents(root, block_group);
9341 9341
9342 memcpy(&key, &block_group->key, sizeof(key)); 9342 memcpy(&key, &block_group->key, sizeof(key));
9343 index = get_block_group_index(block_group); 9343 index = get_block_group_index(block_group);
9344 if (block_group->flags & (BTRFS_BLOCK_GROUP_DUP | 9344 if (block_group->flags & (BTRFS_BLOCK_GROUP_DUP |
9345 BTRFS_BLOCK_GROUP_RAID1 | 9345 BTRFS_BLOCK_GROUP_RAID1 |
9346 BTRFS_BLOCK_GROUP_RAID10)) 9346 BTRFS_BLOCK_GROUP_RAID10))
9347 factor = 2; 9347 factor = 2;
9348 else 9348 else
9349 factor = 1; 9349 factor = 1;
9350 9350
9351 /* make sure this block group isn't part of an allocation cluster */ 9351 /* make sure this block group isn't part of an allocation cluster */
9352 cluster = &root->fs_info->data_alloc_cluster; 9352 cluster = &root->fs_info->data_alloc_cluster;
9353 spin_lock(&cluster->refill_lock); 9353 spin_lock(&cluster->refill_lock);
9354 btrfs_return_cluster_to_free_space(block_group, cluster); 9354 btrfs_return_cluster_to_free_space(block_group, cluster);
9355 spin_unlock(&cluster->refill_lock); 9355 spin_unlock(&cluster->refill_lock);
9356 9356
9357 /* 9357 /*
9358 * make sure this block group isn't part of a metadata 9358 * make sure this block group isn't part of a metadata
9359 * allocation cluster 9359 * allocation cluster
9360 */ 9360 */
9361 cluster = &root->fs_info->meta_alloc_cluster; 9361 cluster = &root->fs_info->meta_alloc_cluster;
9362 spin_lock(&cluster->refill_lock); 9362 spin_lock(&cluster->refill_lock);
9363 btrfs_return_cluster_to_free_space(block_group, cluster); 9363 btrfs_return_cluster_to_free_space(block_group, cluster);
9364 spin_unlock(&cluster->refill_lock); 9364 spin_unlock(&cluster->refill_lock);
9365 9365
9366 path = btrfs_alloc_path(); 9366 path = btrfs_alloc_path();
9367 if (!path) { 9367 if (!path) {
9368 ret = -ENOMEM; 9368 ret = -ENOMEM;
9369 goto out; 9369 goto out;
9370 } 9370 }
9371 9371
9372 inode = lookup_free_space_inode(tree_root, block_group, path); 9372 inode = lookup_free_space_inode(tree_root, block_group, path);
9373 if (!IS_ERR(inode)) { 9373 if (!IS_ERR(inode)) {
9374 ret = btrfs_orphan_add(trans, inode); 9374 ret = btrfs_orphan_add(trans, inode);
9375 if (ret) { 9375 if (ret) {
9376 btrfs_add_delayed_iput(inode); 9376 btrfs_add_delayed_iput(inode);
9377 goto out; 9377 goto out;
9378 } 9378 }
9379 clear_nlink(inode); 9379 clear_nlink(inode);
9380 /* One for the block groups ref */ 9380 /* One for the block groups ref */
9381 spin_lock(&block_group->lock); 9381 spin_lock(&block_group->lock);
9382 if (block_group->iref) { 9382 if (block_group->iref) {
9383 block_group->iref = 0; 9383 block_group->iref = 0;
9384 block_group->inode = NULL; 9384 block_group->inode = NULL;
9385 spin_unlock(&block_group->lock); 9385 spin_unlock(&block_group->lock);
9386 iput(inode); 9386 iput(inode);
9387 } else { 9387 } else {
9388 spin_unlock(&block_group->lock); 9388 spin_unlock(&block_group->lock);
9389 } 9389 }
9390 /* One for our lookup ref */ 9390 /* One for our lookup ref */
9391 btrfs_add_delayed_iput(inode); 9391 btrfs_add_delayed_iput(inode);
9392 } 9392 }
9393 9393
9394 key.objectid = BTRFS_FREE_SPACE_OBJECTID; 9394 key.objectid = BTRFS_FREE_SPACE_OBJECTID;
9395 key.offset = block_group->key.objectid; 9395 key.offset = block_group->key.objectid;
9396 key.type = 0; 9396 key.type = 0;
9397 9397
9398 ret = btrfs_search_slot(trans, tree_root, &key, path, -1, 1); 9398 ret = btrfs_search_slot(trans, tree_root, &key, path, -1, 1);
9399 if (ret < 0) 9399 if (ret < 0)
9400 goto out; 9400 goto out;
9401 if (ret > 0) 9401 if (ret > 0)
9402 btrfs_release_path(path); 9402 btrfs_release_path(path);
9403 if (ret == 0) { 9403 if (ret == 0) {
9404 ret = btrfs_del_item(trans, tree_root, path); 9404 ret = btrfs_del_item(trans, tree_root, path);
9405 if (ret) 9405 if (ret)
9406 goto out; 9406 goto out;
9407 btrfs_release_path(path); 9407 btrfs_release_path(path);
9408 } 9408 }
9409 9409
9410 spin_lock(&root->fs_info->block_group_cache_lock); 9410 spin_lock(&root->fs_info->block_group_cache_lock);
9411 rb_erase(&block_group->cache_node, 9411 rb_erase(&block_group->cache_node,
9412 &root->fs_info->block_group_cache_tree); 9412 &root->fs_info->block_group_cache_tree);
9413 RB_CLEAR_NODE(&block_group->cache_node); 9413 RB_CLEAR_NODE(&block_group->cache_node);
9414 9414
9415 if (root->fs_info->first_logical_byte == block_group->key.objectid) 9415 if (root->fs_info->first_logical_byte == block_group->key.objectid)
9416 root->fs_info->first_logical_byte = (u64)-1; 9416 root->fs_info->first_logical_byte = (u64)-1;
9417 spin_unlock(&root->fs_info->block_group_cache_lock); 9417 spin_unlock(&root->fs_info->block_group_cache_lock);
9418 9418
9419 down_write(&block_group->space_info->groups_sem); 9419 down_write(&block_group->space_info->groups_sem);
9420 /* 9420 /*
9421 * we must use list_del_init so people can check to see if they 9421 * we must use list_del_init so people can check to see if they
9422 * are still on the list after taking the semaphore 9422 * are still on the list after taking the semaphore
9423 */ 9423 */
9424 list_del_init(&block_group->list); 9424 list_del_init(&block_group->list);
9425 list_del_init(&block_group->ro_list); 9425 list_del_init(&block_group->ro_list);
9426 if (list_empty(&block_group->space_info->block_groups[index])) { 9426 if (list_empty(&block_group->space_info->block_groups[index])) {
9427 kobj = block_group->space_info->block_group_kobjs[index]; 9427 kobj = block_group->space_info->block_group_kobjs[index];
9428 block_group->space_info->block_group_kobjs[index] = NULL; 9428 block_group->space_info->block_group_kobjs[index] = NULL;
9429 clear_avail_alloc_bits(root->fs_info, block_group->flags); 9429 clear_avail_alloc_bits(root->fs_info, block_group->flags);
9430 } 9430 }
9431 up_write(&block_group->space_info->groups_sem); 9431 up_write(&block_group->space_info->groups_sem);
9432 if (kobj) { 9432 if (kobj) {
9433 kobject_del(kobj); 9433 kobject_del(kobj);
9434 kobject_put(kobj); 9434 kobject_put(kobj);
9435 } 9435 }
9436 9436
9437 if (block_group->has_caching_ctl) 9437 if (block_group->has_caching_ctl)
9438 caching_ctl = get_caching_control(block_group); 9438 caching_ctl = get_caching_control(block_group);
9439 if (block_group->cached == BTRFS_CACHE_STARTED) 9439 if (block_group->cached == BTRFS_CACHE_STARTED)
9440 wait_block_group_cache_done(block_group); 9440 wait_block_group_cache_done(block_group);
9441 if (block_group->has_caching_ctl) { 9441 if (block_group->has_caching_ctl) {
9442 down_write(&root->fs_info->commit_root_sem); 9442 down_write(&root->fs_info->commit_root_sem);
9443 if (!caching_ctl) { 9443 if (!caching_ctl) {
9444 struct btrfs_caching_control *ctl; 9444 struct btrfs_caching_control *ctl;
9445 9445
9446 list_for_each_entry(ctl, 9446 list_for_each_entry(ctl,
9447 &root->fs_info->caching_block_groups, list) 9447 &root->fs_info->caching_block_groups, list)
9448 if (ctl->block_group == block_group) { 9448 if (ctl->block_group == block_group) {
9449 caching_ctl = ctl; 9449 caching_ctl = ctl;
9450 atomic_inc(&caching_ctl->count); 9450 atomic_inc(&caching_ctl->count);
9451 break; 9451 break;
9452 } 9452 }
9453 } 9453 }
9454 if (caching_ctl) 9454 if (caching_ctl)
9455 list_del_init(&caching_ctl->list); 9455 list_del_init(&caching_ctl->list);
9456 up_write(&root->fs_info->commit_root_sem); 9456 up_write(&root->fs_info->commit_root_sem);
9457 if (caching_ctl) { 9457 if (caching_ctl) {
9458 /* Once for the caching bgs list and once for us. */ 9458 /* Once for the caching bgs list and once for us. */
9459 put_caching_control(caching_ctl); 9459 put_caching_control(caching_ctl);
9460 put_caching_control(caching_ctl); 9460 put_caching_control(caching_ctl);
9461 } 9461 }
9462 } 9462 }
9463 9463
9464 btrfs_remove_free_space_cache(block_group); 9464 btrfs_remove_free_space_cache(block_group);
9465 9465
9466 spin_lock(&block_group->space_info->lock); 9466 spin_lock(&block_group->space_info->lock);
9467 block_group->space_info->total_bytes -= block_group->key.offset; 9467 block_group->space_info->total_bytes -= block_group->key.offset;
9468 block_group->space_info->bytes_readonly -= block_group->key.offset; 9468 block_group->space_info->bytes_readonly -= block_group->key.offset;
9469 block_group->space_info->disk_total -= block_group->key.offset * factor; 9469 block_group->space_info->disk_total -= block_group->key.offset * factor;
9470 spin_unlock(&block_group->space_info->lock); 9470 spin_unlock(&block_group->space_info->lock);
9471 9471
9472 memcpy(&key, &block_group->key, sizeof(key)); 9472 memcpy(&key, &block_group->key, sizeof(key));
9473 9473
9474 lock_chunks(root); 9474 lock_chunks(root);
9475 if (!list_empty(&em->list)) { 9475 if (!list_empty(&em->list)) {
9476 /* We're in the transaction->pending_chunks list. */ 9476 /* We're in the transaction->pending_chunks list. */
9477 free_extent_map(em); 9477 free_extent_map(em);
9478 } 9478 }
9479 spin_lock(&block_group->lock); 9479 spin_lock(&block_group->lock);
9480 block_group->removed = 1; 9480 block_group->removed = 1;
9481 /* 9481 /*
9482 * At this point trimming can't start on this block group, because we 9482 * At this point trimming can't start on this block group, because we
9483 * removed the block group from the tree fs_info->block_group_cache_tree 9483 * removed the block group from the tree fs_info->block_group_cache_tree
9484 * so no one can't find it anymore and even if someone already got this 9484 * so no one can't find it anymore and even if someone already got this
9485 * block group before we removed it from the rbtree, they have already 9485 * block group before we removed it from the rbtree, they have already
9486 * incremented block_group->trimming - if they didn't, they won't find 9486 * incremented block_group->trimming - if they didn't, they won't find
9487 * any free space entries because we already removed them all when we 9487 * any free space entries because we already removed them all when we
9488 * called btrfs_remove_free_space_cache(). 9488 * called btrfs_remove_free_space_cache().
9489 * 9489 *
9490 * And we must not remove the extent map from the fs_info->mapping_tree 9490 * And we must not remove the extent map from the fs_info->mapping_tree
9491 * to prevent the same logical address range and physical device space 9491 * to prevent the same logical address range and physical device space
9492 * ranges from being reused for a new block group. This is because our 9492 * ranges from being reused for a new block group. This is because our
9493 * fs trim operation (btrfs_trim_fs() / btrfs_ioctl_fitrim()) is 9493 * fs trim operation (btrfs_trim_fs() / btrfs_ioctl_fitrim()) is
9494 * completely transactionless, so while it is trimming a range the 9494 * completely transactionless, so while it is trimming a range the
9495 * currently running transaction might finish and a new one start, 9495 * currently running transaction might finish and a new one start,
9496 * allowing for new block groups to be created that can reuse the same 9496 * allowing for new block groups to be created that can reuse the same
9497 * physical device locations unless we take this special care. 9497 * physical device locations unless we take this special care.
9498 */ 9498 */
9499 remove_em = (atomic_read(&block_group->trimming) == 0); 9499 remove_em = (atomic_read(&block_group->trimming) == 0);
9500 /* 9500 /*
9501 * Make sure a trimmer task always sees the em in the pinned_chunks list 9501 * Make sure a trimmer task always sees the em in the pinned_chunks list
9502 * if it sees block_group->removed == 1 (needs to lock block_group->lock 9502 * if it sees block_group->removed == 1 (needs to lock block_group->lock
9503 * before checking block_group->removed). 9503 * before checking block_group->removed).
9504 */ 9504 */
9505 if (!remove_em) { 9505 if (!remove_em) {
9506 /* 9506 /*
9507 * Our em might be in trans->transaction->pending_chunks which 9507 * Our em might be in trans->transaction->pending_chunks which
9508 * is protected by fs_info->chunk_mutex ([lock|unlock]_chunks), 9508 * is protected by fs_info->chunk_mutex ([lock|unlock]_chunks),
9509 * and so is the fs_info->pinned_chunks list. 9509 * and so is the fs_info->pinned_chunks list.
9510 * 9510 *
9511 * So at this point we must be holding the chunk_mutex to avoid 9511 * So at this point we must be holding the chunk_mutex to avoid
9512 * any races with chunk allocation (more specifically at 9512 * any races with chunk allocation (more specifically at
9513 * volumes.c:contains_pending_extent()), to ensure it always 9513 * volumes.c:contains_pending_extent()), to ensure it always
9514 * sees the em, either in the pending_chunks list or in the 9514 * sees the em, either in the pending_chunks list or in the
9515 * pinned_chunks list. 9515 * pinned_chunks list.
9516 */ 9516 */
9517 list_move_tail(&em->list, &root->fs_info->pinned_chunks); 9517 list_move_tail(&em->list, &root->fs_info->pinned_chunks);
9518 } 9518 }
9519 spin_unlock(&block_group->lock); 9519 spin_unlock(&block_group->lock);
9520 9520
9521 if (remove_em) { 9521 if (remove_em) {
9522 struct extent_map_tree *em_tree; 9522 struct extent_map_tree *em_tree;
9523 9523
9524 em_tree = &root->fs_info->mapping_tree.map_tree; 9524 em_tree = &root->fs_info->mapping_tree.map_tree;
9525 write_lock(&em_tree->lock); 9525 write_lock(&em_tree->lock);
9526 /* 9526 /*
9527 * The em might be in the pending_chunks list, so make sure the 9527 * The em might be in the pending_chunks list, so make sure the
9528 * chunk mutex is locked, since remove_extent_mapping() will 9528 * chunk mutex is locked, since remove_extent_mapping() will
9529 * delete us from that list. 9529 * delete us from that list.
9530 */ 9530 */
9531 remove_extent_mapping(em_tree, em); 9531 remove_extent_mapping(em_tree, em);
9532 write_unlock(&em_tree->lock); 9532 write_unlock(&em_tree->lock);
9533 /* once for the tree */ 9533 /* once for the tree */
9534 free_extent_map(em); 9534 free_extent_map(em);
9535 } 9535 }
9536 9536
9537 unlock_chunks(root); 9537 unlock_chunks(root);
9538 9538
9539 btrfs_put_block_group(block_group); 9539 btrfs_put_block_group(block_group);
9540 btrfs_put_block_group(block_group); 9540 btrfs_put_block_group(block_group);
9541 9541
9542 ret = btrfs_search_slot(trans, root, &key, path, -1, 1); 9542 ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
9543 if (ret > 0) 9543 if (ret > 0)
9544 ret = -EIO; 9544 ret = -EIO;
9545 if (ret < 0) 9545 if (ret < 0)
9546 goto out; 9546 goto out;
9547 9547
9548 ret = btrfs_del_item(trans, root, path); 9548 ret = btrfs_del_item(trans, root, path);
9549 out: 9549 out:
9550 btrfs_free_path(path); 9550 btrfs_free_path(path);
9551 return ret; 9551 return ret;
9552 } 9552 }
9553 9553
9554 /* 9554 /*
9555 * Process the unused_bgs list and remove any that don't have any allocated 9555 * Process the unused_bgs list and remove any that don't have any allocated
9556 * space inside of them. 9556 * space inside of them.
9557 */ 9557 */
9558 void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info) 9558 void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info)
9559 { 9559 {
9560 struct btrfs_block_group_cache *block_group; 9560 struct btrfs_block_group_cache *block_group;
9561 struct btrfs_space_info *space_info; 9561 struct btrfs_space_info *space_info;
9562 struct btrfs_root *root = fs_info->extent_root; 9562 struct btrfs_root *root = fs_info->extent_root;
9563 struct btrfs_trans_handle *trans; 9563 struct btrfs_trans_handle *trans;
9564 int ret = 0; 9564 int ret = 0;
9565 9565
9566 if (!fs_info->open) 9566 if (!fs_info->open)
9567 return; 9567 return;
9568 9568
9569 spin_lock(&fs_info->unused_bgs_lock); 9569 spin_lock(&fs_info->unused_bgs_lock);
9570 while (!list_empty(&fs_info->unused_bgs)) { 9570 while (!list_empty(&fs_info->unused_bgs)) {
9571 u64 start, end; 9571 u64 start, end;
9572 9572
9573 block_group = list_first_entry(&fs_info->unused_bgs, 9573 block_group = list_first_entry(&fs_info->unused_bgs,
9574 struct btrfs_block_group_cache, 9574 struct btrfs_block_group_cache,
9575 bg_list); 9575 bg_list);
9576 space_info = block_group->space_info; 9576 space_info = block_group->space_info;
9577 list_del_init(&block_group->bg_list); 9577 list_del_init(&block_group->bg_list);
9578 if (ret || btrfs_mixed_space_info(space_info)) { 9578 if (ret || btrfs_mixed_space_info(space_info)) {
9579 btrfs_put_block_group(block_group); 9579 btrfs_put_block_group(block_group);
9580 continue; 9580 continue;
9581 } 9581 }
9582 spin_unlock(&fs_info->unused_bgs_lock); 9582 spin_unlock(&fs_info->unused_bgs_lock);
9583 9583
9584 /* Don't want to race with allocators so take the groups_sem */ 9584 /* Don't want to race with allocators so take the groups_sem */
9585 down_write(&space_info->groups_sem); 9585 down_write(&space_info->groups_sem);
9586 spin_lock(&block_group->lock); 9586 spin_lock(&block_group->lock);
9587 if (block_group->reserved || 9587 if (block_group->reserved ||
9588 btrfs_block_group_used(&block_group->item) || 9588 btrfs_block_group_used(&block_group->item) ||
9589 block_group->ro) { 9589 block_group->ro) {
9590 /* 9590 /*
9591 * We want to bail if we made new allocations or have 9591 * We want to bail if we made new allocations or have
9592 * outstanding allocations in this block group. We do 9592 * outstanding allocations in this block group. We do
9593 * the ro check in case balance is currently acting on 9593 * the ro check in case balance is currently acting on
9594 * this block group. 9594 * this block group.
9595 */ 9595 */
9596 spin_unlock(&block_group->lock); 9596 spin_unlock(&block_group->lock);
9597 up_write(&space_info->groups_sem); 9597 up_write(&space_info->groups_sem);
9598 goto next; 9598 goto next;
9599 } 9599 }
9600 spin_unlock(&block_group->lock); 9600 spin_unlock(&block_group->lock);
9601 9601
9602 /* We don't want to force the issue, only flip if it's ok. */ 9602 /* We don't want to force the issue, only flip if it's ok. */
9603 ret = set_block_group_ro(block_group, 0); 9603 ret = set_block_group_ro(block_group, 0);
9604 up_write(&space_info->groups_sem); 9604 up_write(&space_info->groups_sem);
9605 if (ret < 0) { 9605 if (ret < 0) {
9606 ret = 0; 9606 ret = 0;
9607 goto next; 9607 goto next;
9608 } 9608 }
9609 9609
9610 /* 9610 /*
9611 * Want to do this before we do anything else so we can recover 9611 * Want to do this before we do anything else so we can recover
9612 * properly if we fail to join the transaction. 9612 * properly if we fail to join the transaction.
9613 */ 9613 */
9614 trans = btrfs_join_transaction(root); 9614 trans = btrfs_join_transaction(root);
9615 if (IS_ERR(trans)) { 9615 if (IS_ERR(trans)) {
9616 btrfs_set_block_group_rw(root, block_group); 9616 btrfs_set_block_group_rw(root, block_group);
9617 ret = PTR_ERR(trans); 9617 ret = PTR_ERR(trans);
9618 goto next; 9618 goto next;
9619 } 9619 }
9620 9620
9621 /* 9621 /*
9622 * We could have pending pinned extents for this block group, 9622 * We could have pending pinned extents for this block group,
9623 * just delete them, we don't care about them anymore. 9623 * just delete them, we don't care about them anymore.
9624 */ 9624 */
9625 start = block_group->key.objectid; 9625 start = block_group->key.objectid;
9626 end = start + block_group->key.offset - 1; 9626 end = start + block_group->key.offset - 1;
9627 ret = clear_extent_bits(&fs_info->freed_extents[0], start, end, 9627 ret = clear_extent_bits(&fs_info->freed_extents[0], start, end,
9628 EXTENT_DIRTY, GFP_NOFS); 9628 EXTENT_DIRTY, GFP_NOFS);
9629 if (ret) { 9629 if (ret) {
9630 btrfs_set_block_group_rw(root, block_group); 9630 btrfs_set_block_group_rw(root, block_group);
9631 goto end_trans; 9631 goto end_trans;
9632 } 9632 }
9633 ret = clear_extent_bits(&fs_info->freed_extents[1], start, end, 9633 ret = clear_extent_bits(&fs_info->freed_extents[1], start, end,
9634 EXTENT_DIRTY, GFP_NOFS); 9634 EXTENT_DIRTY, GFP_NOFS);
9635 if (ret) { 9635 if (ret) {
9636 btrfs_set_block_group_rw(root, block_group); 9636 btrfs_set_block_group_rw(root, block_group);
9637 goto end_trans; 9637 goto end_trans;
9638 } 9638 }
9639 9639
9640 /* Reset pinned so btrfs_put_block_group doesn't complain */ 9640 /* Reset pinned so btrfs_put_block_group doesn't complain */
9641 block_group->pinned = 0; 9641 block_group->pinned = 0;
9642 9642
9643 /* 9643 /*
9644 * Btrfs_remove_chunk will abort the transaction if things go 9644 * Btrfs_remove_chunk will abort the transaction if things go
9645 * horribly wrong. 9645 * horribly wrong.
9646 */ 9646 */
9647 ret = btrfs_remove_chunk(trans, root, 9647 ret = btrfs_remove_chunk(trans, root,
9648 block_group->key.objectid); 9648 block_group->key.objectid);
9649 end_trans: 9649 end_trans:
9650 btrfs_end_transaction(trans, root); 9650 btrfs_end_transaction(trans, root);
9651 next: 9651 next:
9652 btrfs_put_block_group(block_group); 9652 btrfs_put_block_group(block_group);
9653 spin_lock(&fs_info->unused_bgs_lock); 9653 spin_lock(&fs_info->unused_bgs_lock);
9654 } 9654 }
9655 spin_unlock(&fs_info->unused_bgs_lock); 9655 spin_unlock(&fs_info->unused_bgs_lock);
9656 } 9656 }
9657 9657
9658 int btrfs_init_space_info(struct btrfs_fs_info *fs_info) 9658 int btrfs_init_space_info(struct btrfs_fs_info *fs_info)
9659 { 9659 {
9660 struct btrfs_space_info *space_info; 9660 struct btrfs_space_info *space_info;
9661 struct btrfs_super_block *disk_super; 9661 struct btrfs_super_block *disk_super;
9662 u64 features; 9662 u64 features;
9663 u64 flags; 9663 u64 flags;
9664 int mixed = 0; 9664 int mixed = 0;
9665 int ret; 9665 int ret;
9666 9666
9667 disk_super = fs_info->super_copy; 9667 disk_super = fs_info->super_copy;
9668 if (!btrfs_super_root(disk_super)) 9668 if (!btrfs_super_root(disk_super))
9669 return 1; 9669 return 1;
9670 9670
9671 features = btrfs_super_incompat_flags(disk_super); 9671 features = btrfs_super_incompat_flags(disk_super);
9672 if (features & BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS) 9672 if (features & BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS)
9673 mixed = 1; 9673 mixed = 1;
9674 9674
9675 flags = BTRFS_BLOCK_GROUP_SYSTEM; 9675 flags = BTRFS_BLOCK_GROUP_SYSTEM;
9676 ret = update_space_info(fs_info, flags, 0, 0, &space_info); 9676 ret = update_space_info(fs_info, flags, 0, 0, &space_info);
9677 if (ret) 9677 if (ret)
9678 goto out; 9678 goto out;
9679 9679
9680 if (mixed) { 9680 if (mixed) {
9681 flags = BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_DATA; 9681 flags = BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_DATA;
9682 ret = update_space_info(fs_info, flags, 0, 0, &space_info); 9682 ret = update_space_info(fs_info, flags, 0, 0, &space_info);
9683 } else { 9683 } else {
9684 flags = BTRFS_BLOCK_GROUP_METADATA; 9684 flags = BTRFS_BLOCK_GROUP_METADATA;
9685 ret = update_space_info(fs_info, flags, 0, 0, &space_info); 9685 ret = update_space_info(fs_info, flags, 0, 0, &space_info);
9686 if (ret) 9686 if (ret)
9687 goto out; 9687 goto out;
9688 9688
9689 flags = BTRFS_BLOCK_GROUP_DATA; 9689 flags = BTRFS_BLOCK_GROUP_DATA;
9690 ret = update_space_info(fs_info, flags, 0, 0, &space_info); 9690 ret = update_space_info(fs_info, flags, 0, 0, &space_info);
9691 } 9691 }
9692 out: 9692 out:
9693 return ret; 9693 return ret;
9694 } 9694 }
9695 9695
9696 int btrfs_error_unpin_extent_range(struct btrfs_root *root, u64 start, u64 end) 9696 int btrfs_error_unpin_extent_range(struct btrfs_root *root, u64 start, u64 end)
9697 { 9697 {
9698 return unpin_extent_range(root, start, end, false); 9698 return unpin_extent_range(root, start, end, false);
9699 } 9699 }
9700 9700
9701 int btrfs_trim_fs(struct btrfs_root *root, struct fstrim_range *range) 9701 int btrfs_trim_fs(struct btrfs_root *root, struct fstrim_range *range)
9702 { 9702 {
9703 struct btrfs_fs_info *fs_info = root->fs_info; 9703 struct btrfs_fs_info *fs_info = root->fs_info;
9704 struct btrfs_block_group_cache *cache = NULL; 9704 struct btrfs_block_group_cache *cache = NULL;
9705 u64 group_trimmed; 9705 u64 group_trimmed;
9706 u64 start; 9706 u64 start;
9707 u64 end; 9707 u64 end;
9708 u64 trimmed = 0; 9708 u64 trimmed = 0;
9709 u64 total_bytes = btrfs_super_total_bytes(fs_info->super_copy); 9709 u64 total_bytes = btrfs_super_total_bytes(fs_info->super_copy);
9710 int ret = 0; 9710 int ret = 0;
9711 9711
9712 /* 9712 /*
9713 * try to trim all FS space, our block group may start from non-zero. 9713 * try to trim all FS space, our block group may start from non-zero.
9714 */ 9714 */
9715 if (range->len == total_bytes) 9715 if (range->len == total_bytes)
9716 cache = btrfs_lookup_first_block_group(fs_info, range->start); 9716 cache = btrfs_lookup_first_block_group(fs_info, range->start);
9717 else 9717 else
9718 cache = btrfs_lookup_block_group(fs_info, range->start); 9718 cache = btrfs_lookup_block_group(fs_info, range->start);
9719 9719
9720 while (cache) { 9720 while (cache) {
9721 if (cache->key.objectid >= (range->start + range->len)) { 9721 if (cache->key.objectid >= (range->start + range->len)) {
9722 btrfs_put_block_group(cache); 9722 btrfs_put_block_group(cache);
9723 break; 9723 break;
9724 } 9724 }
9725 9725
9726 start = max(range->start, cache->key.objectid); 9726 start = max(range->start, cache->key.objectid);
9727 end = min(range->start + range->len, 9727 end = min(range->start + range->len,
9728 cache->key.objectid + cache->key.offset); 9728 cache->key.objectid + cache->key.offset);
9729 9729
9730 if (end - start >= range->minlen) { 9730 if (end - start >= range->minlen) {
9731 if (!block_group_cache_done(cache)) { 9731 if (!block_group_cache_done(cache)) {
9732 ret = cache_block_group(cache, 0); 9732 ret = cache_block_group(cache, 0);
9733 if (ret) { 9733 if (ret) {
9734 btrfs_put_block_group(cache); 9734 btrfs_put_block_group(cache);
9735 break; 9735 break;
9736 } 9736 }
9737 ret = wait_block_group_cache_done(cache); 9737 ret = wait_block_group_cache_done(cache);
9738 if (ret) { 9738 if (ret) {
9739 btrfs_put_block_group(cache); 9739 btrfs_put_block_group(cache);
9740 break; 9740 break;
9741 } 9741 }
9742 } 9742 }
9743 ret = btrfs_trim_block_group(cache, 9743 ret = btrfs_trim_block_group(cache,
9744 &group_trimmed, 9744 &group_trimmed,
9745 start, 9745 start,
9746 end, 9746 end,
9747 range->minlen); 9747 range->minlen);
9748 9748
9749 trimmed += group_trimmed; 9749 trimmed += group_trimmed;
9750 if (ret) { 9750 if (ret) {
9751 btrfs_put_block_group(cache); 9751 btrfs_put_block_group(cache);
9752 break; 9752 break;
9753 } 9753 }
9754 } 9754 }
9755 9755
9756 cache = next_block_group(fs_info->tree_root, cache); 9756 cache = next_block_group(fs_info->tree_root, cache);
9757 } 9757 }
9758 9758
9759 range->len = trimmed; 9759 range->len = trimmed;
9760 return ret; 9760 return ret;
9761 } 9761 }
9762 9762
9763 /* 9763 /*
9764 * btrfs_{start,end}_write_no_snapshoting() are similar to 9764 * btrfs_{start,end}_write_no_snapshoting() are similar to
9765 * mnt_{want,drop}_write(), they are used to prevent some tasks from writing 9765 * mnt_{want,drop}_write(), they are used to prevent some tasks from writing
9766 * data into the page cache through nocow before the subvolume is snapshoted, 9766 * data into the page cache through nocow before the subvolume is snapshoted,
9767 * but flush the data into disk after the snapshot creation, or to prevent 9767 * but flush the data into disk after the snapshot creation, or to prevent
9768 * operations while snapshoting is ongoing and that cause the snapshot to be 9768 * operations while snapshoting is ongoing and that cause the snapshot to be
9769 * inconsistent (writes followed by expanding truncates for example). 9769 * inconsistent (writes followed by expanding truncates for example).
9770 */ 9770 */
9771 void btrfs_end_write_no_snapshoting(struct btrfs_root *root) 9771 void btrfs_end_write_no_snapshoting(struct btrfs_root *root)
9772 { 9772 {
9773 percpu_counter_dec(&root->subv_writers->counter); 9773 percpu_counter_dec(&root->subv_writers->counter);
9774 /* 9774 /*
9775 * Make sure counter is updated before we wake up 9775 * Make sure counter is updated before we wake up
9776 * waiters. 9776 * waiters.
9777 */ 9777 */
9778 smp_mb(); 9778 smp_mb();
9779 if (waitqueue_active(&root->subv_writers->wait)) 9779 if (waitqueue_active(&root->subv_writers->wait))
9780 wake_up(&root->subv_writers->wait); 9780 wake_up(&root->subv_writers->wait);
9781 } 9781 }
9782 9782
9783 int btrfs_start_write_no_snapshoting(struct btrfs_root *root) 9783 int btrfs_start_write_no_snapshoting(struct btrfs_root *root)
9784 { 9784 {
9785 if (atomic_read(&root->will_be_snapshoted)) 9785 if (atomic_read(&root->will_be_snapshoted))
9786 return 0; 9786 return 0;
9787 9787
9788 percpu_counter_inc(&root->subv_writers->counter); 9788 percpu_counter_inc(&root->subv_writers->counter);
9789 /* 9789 /*
9790 * Make sure counter is updated before we check for snapshot creation. 9790 * Make sure counter is updated before we check for snapshot creation.
9791 */ 9791 */
9792 smp_mb(); 9792 smp_mb();
9793 if (atomic_read(&root->will_be_snapshoted)) { 9793 if (atomic_read(&root->will_be_snapshoted)) {
9794 btrfs_end_write_no_snapshoting(root); 9794 btrfs_end_write_no_snapshoting(root);
9795 return 0; 9795 return 0;
9796 } 9796 }
9797 return 1; 9797 return 1;
1 /* 1 /*
2 * Copyright (C) 2007 Oracle. All rights reserved. 2 * Copyright (C) 2007 Oracle. All rights reserved.
3 * 3 *
4 * This program is free software; you can redistribute it and/or 4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public 5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation. 6 * License v2 as published by the Free Software Foundation.
7 * 7 *
8 * This program is distributed in the hope that it will be useful, 8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details. 11 * General Public License for more details.
12 * 12 *
13 * You should have received a copy of the GNU General Public 13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the 14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 * Boston, MA 021110-1307, USA. 16 * Boston, MA 021110-1307, USA.
17 */ 17 */
18 18
19 #include <linux/kernel.h> 19 #include <linux/kernel.h>
20 #include <linux/bio.h> 20 #include <linux/bio.h>
21 #include <linux/buffer_head.h> 21 #include <linux/buffer_head.h>
22 #include <linux/file.h> 22 #include <linux/file.h>
23 #include <linux/fs.h> 23 #include <linux/fs.h>
24 #include <linux/pagemap.h> 24 #include <linux/pagemap.h>
25 #include <linux/highmem.h> 25 #include <linux/highmem.h>
26 #include <linux/time.h> 26 #include <linux/time.h>
27 #include <linux/init.h> 27 #include <linux/init.h>
28 #include <linux/string.h> 28 #include <linux/string.h>
29 #include <linux/backing-dev.h> 29 #include <linux/backing-dev.h>
30 #include <linux/mpage.h> 30 #include <linux/mpage.h>
31 #include <linux/swap.h> 31 #include <linux/swap.h>
32 #include <linux/writeback.h> 32 #include <linux/writeback.h>
33 #include <linux/statfs.h> 33 #include <linux/statfs.h>
34 #include <linux/compat.h> 34 #include <linux/compat.h>
35 #include <linux/aio.h> 35 #include <linux/aio.h>
36 #include <linux/bit_spinlock.h> 36 #include <linux/bit_spinlock.h>
37 #include <linux/xattr.h> 37 #include <linux/xattr.h>
38 #include <linux/posix_acl.h> 38 #include <linux/posix_acl.h>
39 #include <linux/falloc.h> 39 #include <linux/falloc.h>
40 #include <linux/slab.h> 40 #include <linux/slab.h>
41 #include <linux/ratelimit.h> 41 #include <linux/ratelimit.h>
42 #include <linux/mount.h> 42 #include <linux/mount.h>
43 #include <linux/btrfs.h> 43 #include <linux/btrfs.h>
44 #include <linux/blkdev.h> 44 #include <linux/blkdev.h>
45 #include <linux/posix_acl_xattr.h> 45 #include <linux/posix_acl_xattr.h>
46 #include "ctree.h" 46 #include "ctree.h"
47 #include "disk-io.h" 47 #include "disk-io.h"
48 #include "transaction.h" 48 #include "transaction.h"
49 #include "btrfs_inode.h" 49 #include "btrfs_inode.h"
50 #include "print-tree.h" 50 #include "print-tree.h"
51 #include "ordered-data.h" 51 #include "ordered-data.h"
52 #include "xattr.h" 52 #include "xattr.h"
53 #include "tree-log.h" 53 #include "tree-log.h"
54 #include "volumes.h" 54 #include "volumes.h"
55 #include "compression.h" 55 #include "compression.h"
56 #include "locking.h" 56 #include "locking.h"
57 #include "free-space-cache.h" 57 #include "free-space-cache.h"
58 #include "inode-map.h" 58 #include "inode-map.h"
59 #include "backref.h" 59 #include "backref.h"
60 #include "hash.h" 60 #include "hash.h"
61 #include "props.h" 61 #include "props.h"
62 62
63 struct btrfs_iget_args { 63 struct btrfs_iget_args {
64 struct btrfs_key *location; 64 struct btrfs_key *location;
65 struct btrfs_root *root; 65 struct btrfs_root *root;
66 }; 66 };
67 67
68 static const struct inode_operations btrfs_dir_inode_operations; 68 static const struct inode_operations btrfs_dir_inode_operations;
69 static const struct inode_operations btrfs_symlink_inode_operations; 69 static const struct inode_operations btrfs_symlink_inode_operations;
70 static const struct inode_operations btrfs_dir_ro_inode_operations; 70 static const struct inode_operations btrfs_dir_ro_inode_operations;
71 static const struct inode_operations btrfs_special_inode_operations; 71 static const struct inode_operations btrfs_special_inode_operations;
72 static const struct inode_operations btrfs_file_inode_operations; 72 static const struct inode_operations btrfs_file_inode_operations;
73 static const struct address_space_operations btrfs_aops; 73 static const struct address_space_operations btrfs_aops;
74 static const struct address_space_operations btrfs_symlink_aops; 74 static const struct address_space_operations btrfs_symlink_aops;
75 static const struct file_operations btrfs_dir_file_operations; 75 static const struct file_operations btrfs_dir_file_operations;
76 static struct extent_io_ops btrfs_extent_io_ops; 76 static struct extent_io_ops btrfs_extent_io_ops;
77 77
78 static struct kmem_cache *btrfs_inode_cachep; 78 static struct kmem_cache *btrfs_inode_cachep;
79 static struct kmem_cache *btrfs_delalloc_work_cachep; 79 static struct kmem_cache *btrfs_delalloc_work_cachep;
80 struct kmem_cache *btrfs_trans_handle_cachep; 80 struct kmem_cache *btrfs_trans_handle_cachep;
81 struct kmem_cache *btrfs_transaction_cachep; 81 struct kmem_cache *btrfs_transaction_cachep;
82 struct kmem_cache *btrfs_path_cachep; 82 struct kmem_cache *btrfs_path_cachep;
83 struct kmem_cache *btrfs_free_space_cachep; 83 struct kmem_cache *btrfs_free_space_cachep;
84 84
85 #define S_SHIFT 12 85 #define S_SHIFT 12
86 static unsigned char btrfs_type_by_mode[S_IFMT >> S_SHIFT] = { 86 static unsigned char btrfs_type_by_mode[S_IFMT >> S_SHIFT] = {
87 [S_IFREG >> S_SHIFT] = BTRFS_FT_REG_FILE, 87 [S_IFREG >> S_SHIFT] = BTRFS_FT_REG_FILE,
88 [S_IFDIR >> S_SHIFT] = BTRFS_FT_DIR, 88 [S_IFDIR >> S_SHIFT] = BTRFS_FT_DIR,
89 [S_IFCHR >> S_SHIFT] = BTRFS_FT_CHRDEV, 89 [S_IFCHR >> S_SHIFT] = BTRFS_FT_CHRDEV,
90 [S_IFBLK >> S_SHIFT] = BTRFS_FT_BLKDEV, 90 [S_IFBLK >> S_SHIFT] = BTRFS_FT_BLKDEV,
91 [S_IFIFO >> S_SHIFT] = BTRFS_FT_FIFO, 91 [S_IFIFO >> S_SHIFT] = BTRFS_FT_FIFO,
92 [S_IFSOCK >> S_SHIFT] = BTRFS_FT_SOCK, 92 [S_IFSOCK >> S_SHIFT] = BTRFS_FT_SOCK,
93 [S_IFLNK >> S_SHIFT] = BTRFS_FT_SYMLINK, 93 [S_IFLNK >> S_SHIFT] = BTRFS_FT_SYMLINK,
94 }; 94 };
95 95
96 static int btrfs_setsize(struct inode *inode, struct iattr *attr); 96 static int btrfs_setsize(struct inode *inode, struct iattr *attr);
97 static int btrfs_truncate(struct inode *inode); 97 static int btrfs_truncate(struct inode *inode);
98 static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent); 98 static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent);
99 static noinline int cow_file_range(struct inode *inode, 99 static noinline int cow_file_range(struct inode *inode,
100 struct page *locked_page, 100 struct page *locked_page,
101 u64 start, u64 end, int *page_started, 101 u64 start, u64 end, int *page_started,
102 unsigned long *nr_written, int unlock); 102 unsigned long *nr_written, int unlock);
103 static struct extent_map *create_pinned_em(struct inode *inode, u64 start, 103 static struct extent_map *create_pinned_em(struct inode *inode, u64 start,
104 u64 len, u64 orig_start, 104 u64 len, u64 orig_start,
105 u64 block_start, u64 block_len, 105 u64 block_start, u64 block_len,
106 u64 orig_block_len, u64 ram_bytes, 106 u64 orig_block_len, u64 ram_bytes,
107 int type); 107 int type);
108 108
109 static int btrfs_dirty_inode(struct inode *inode); 109 static int btrfs_dirty_inode(struct inode *inode);
110 110
111 static int btrfs_init_inode_security(struct btrfs_trans_handle *trans, 111 static int btrfs_init_inode_security(struct btrfs_trans_handle *trans,
112 struct inode *inode, struct inode *dir, 112 struct inode *inode, struct inode *dir,
113 const struct qstr *qstr) 113 const struct qstr *qstr)
114 { 114 {
115 int err; 115 int err;
116 116
117 err = btrfs_init_acl(trans, inode, dir); 117 err = btrfs_init_acl(trans, inode, dir);
118 if (!err) 118 if (!err)
119 err = btrfs_xattr_security_init(trans, inode, dir, qstr); 119 err = btrfs_xattr_security_init(trans, inode, dir, qstr);
120 return err; 120 return err;
121 } 121 }
122 122
123 /* 123 /*
124 * this does all the hard work for inserting an inline extent into 124 * this does all the hard work for inserting an inline extent into
125 * the btree. The caller should have done a btrfs_drop_extents so that 125 * the btree. The caller should have done a btrfs_drop_extents so that
126 * no overlapping inline items exist in the btree 126 * no overlapping inline items exist in the btree
127 */ 127 */
128 static int insert_inline_extent(struct btrfs_trans_handle *trans, 128 static int insert_inline_extent(struct btrfs_trans_handle *trans,
129 struct btrfs_path *path, int extent_inserted, 129 struct btrfs_path *path, int extent_inserted,
130 struct btrfs_root *root, struct inode *inode, 130 struct btrfs_root *root, struct inode *inode,
131 u64 start, size_t size, size_t compressed_size, 131 u64 start, size_t size, size_t compressed_size,
132 int compress_type, 132 int compress_type,
133 struct page **compressed_pages) 133 struct page **compressed_pages)
134 { 134 {
135 struct extent_buffer *leaf; 135 struct extent_buffer *leaf;
136 struct page *page = NULL; 136 struct page *page = NULL;
137 char *kaddr; 137 char *kaddr;
138 unsigned long ptr; 138 unsigned long ptr;
139 struct btrfs_file_extent_item *ei; 139 struct btrfs_file_extent_item *ei;
140 int err = 0; 140 int err = 0;
141 int ret; 141 int ret;
142 size_t cur_size = size; 142 size_t cur_size = size;
143 unsigned long offset; 143 unsigned long offset;
144 144
145 if (compressed_size && compressed_pages) 145 if (compressed_size && compressed_pages)
146 cur_size = compressed_size; 146 cur_size = compressed_size;
147 147
148 inode_add_bytes(inode, size); 148 inode_add_bytes(inode, size);
149 149
150 if (!extent_inserted) { 150 if (!extent_inserted) {
151 struct btrfs_key key; 151 struct btrfs_key key;
152 size_t datasize; 152 size_t datasize;
153 153
154 key.objectid = btrfs_ino(inode); 154 key.objectid = btrfs_ino(inode);
155 key.offset = start; 155 key.offset = start;
156 key.type = BTRFS_EXTENT_DATA_KEY; 156 key.type = BTRFS_EXTENT_DATA_KEY;
157 157
158 datasize = btrfs_file_extent_calc_inline_size(cur_size); 158 datasize = btrfs_file_extent_calc_inline_size(cur_size);
159 path->leave_spinning = 1; 159 path->leave_spinning = 1;
160 ret = btrfs_insert_empty_item(trans, root, path, &key, 160 ret = btrfs_insert_empty_item(trans, root, path, &key,
161 datasize); 161 datasize);
162 if (ret) { 162 if (ret) {
163 err = ret; 163 err = ret;
164 goto fail; 164 goto fail;
165 } 165 }
166 } 166 }
167 leaf = path->nodes[0]; 167 leaf = path->nodes[0];
168 ei = btrfs_item_ptr(leaf, path->slots[0], 168 ei = btrfs_item_ptr(leaf, path->slots[0],
169 struct btrfs_file_extent_item); 169 struct btrfs_file_extent_item);
170 btrfs_set_file_extent_generation(leaf, ei, trans->transid); 170 btrfs_set_file_extent_generation(leaf, ei, trans->transid);
171 btrfs_set_file_extent_type(leaf, ei, BTRFS_FILE_EXTENT_INLINE); 171 btrfs_set_file_extent_type(leaf, ei, BTRFS_FILE_EXTENT_INLINE);
172 btrfs_set_file_extent_encryption(leaf, ei, 0); 172 btrfs_set_file_extent_encryption(leaf, ei, 0);
173 btrfs_set_file_extent_other_encoding(leaf, ei, 0); 173 btrfs_set_file_extent_other_encoding(leaf, ei, 0);
174 btrfs_set_file_extent_ram_bytes(leaf, ei, size); 174 btrfs_set_file_extent_ram_bytes(leaf, ei, size);
175 ptr = btrfs_file_extent_inline_start(ei); 175 ptr = btrfs_file_extent_inline_start(ei);
176 176
177 if (compress_type != BTRFS_COMPRESS_NONE) { 177 if (compress_type != BTRFS_COMPRESS_NONE) {
178 struct page *cpage; 178 struct page *cpage;
179 int i = 0; 179 int i = 0;
180 while (compressed_size > 0) { 180 while (compressed_size > 0) {
181 cpage = compressed_pages[i]; 181 cpage = compressed_pages[i];
182 cur_size = min_t(unsigned long, compressed_size, 182 cur_size = min_t(unsigned long, compressed_size,
183 PAGE_CACHE_SIZE); 183 PAGE_CACHE_SIZE);
184 184
185 kaddr = kmap_atomic(cpage); 185 kaddr = kmap_atomic(cpage);
186 write_extent_buffer(leaf, kaddr, ptr, cur_size); 186 write_extent_buffer(leaf, kaddr, ptr, cur_size);
187 kunmap_atomic(kaddr); 187 kunmap_atomic(kaddr);
188 188
189 i++; 189 i++;
190 ptr += cur_size; 190 ptr += cur_size;
191 compressed_size -= cur_size; 191 compressed_size -= cur_size;
192 } 192 }
193 btrfs_set_file_extent_compression(leaf, ei, 193 btrfs_set_file_extent_compression(leaf, ei,
194 compress_type); 194 compress_type);
195 } else { 195 } else {
196 page = find_get_page(inode->i_mapping, 196 page = find_get_page(inode->i_mapping,
197 start >> PAGE_CACHE_SHIFT); 197 start >> PAGE_CACHE_SHIFT);
198 btrfs_set_file_extent_compression(leaf, ei, 0); 198 btrfs_set_file_extent_compression(leaf, ei, 0);
199 kaddr = kmap_atomic(page); 199 kaddr = kmap_atomic(page);
200 offset = start & (PAGE_CACHE_SIZE - 1); 200 offset = start & (PAGE_CACHE_SIZE - 1);
201 write_extent_buffer(leaf, kaddr + offset, ptr, size); 201 write_extent_buffer(leaf, kaddr + offset, ptr, size);
202 kunmap_atomic(kaddr); 202 kunmap_atomic(kaddr);
203 page_cache_release(page); 203 page_cache_release(page);
204 } 204 }
205 btrfs_mark_buffer_dirty(leaf); 205 btrfs_mark_buffer_dirty(leaf);
206 btrfs_release_path(path); 206 btrfs_release_path(path);
207 207
208 /* 208 /*
209 * we're an inline extent, so nobody can 209 * we're an inline extent, so nobody can
210 * extend the file past i_size without locking 210 * extend the file past i_size without locking
211 * a page we already have locked. 211 * a page we already have locked.
212 * 212 *
213 * We must do any isize and inode updates 213 * We must do any isize and inode updates
214 * before we unlock the pages. Otherwise we 214 * before we unlock the pages. Otherwise we
215 * could end up racing with unlink. 215 * could end up racing with unlink.
216 */ 216 */
217 BTRFS_I(inode)->disk_i_size = inode->i_size; 217 BTRFS_I(inode)->disk_i_size = inode->i_size;
218 ret = btrfs_update_inode(trans, root, inode); 218 ret = btrfs_update_inode(trans, root, inode);
219 219
220 return ret; 220 return ret;
221 fail: 221 fail:
222 return err; 222 return err;
223 } 223 }
224 224
225 225
226 /* 226 /*
227 * conditionally insert an inline extent into the file. This 227 * conditionally insert an inline extent into the file. This
228 * does the checks required to make sure the data is small enough 228 * does the checks required to make sure the data is small enough
229 * to fit as an inline extent. 229 * to fit as an inline extent.
230 */ 230 */
231 static noinline int cow_file_range_inline(struct btrfs_root *root, 231 static noinline int cow_file_range_inline(struct btrfs_root *root,
232 struct inode *inode, u64 start, 232 struct inode *inode, u64 start,
233 u64 end, size_t compressed_size, 233 u64 end, size_t compressed_size,
234 int compress_type, 234 int compress_type,
235 struct page **compressed_pages) 235 struct page **compressed_pages)
236 { 236 {
237 struct btrfs_trans_handle *trans; 237 struct btrfs_trans_handle *trans;
238 u64 isize = i_size_read(inode); 238 u64 isize = i_size_read(inode);
239 u64 actual_end = min(end + 1, isize); 239 u64 actual_end = min(end + 1, isize);
240 u64 inline_len = actual_end - start; 240 u64 inline_len = actual_end - start;
241 u64 aligned_end = ALIGN(end, root->sectorsize); 241 u64 aligned_end = ALIGN(end, root->sectorsize);
242 u64 data_len = inline_len; 242 u64 data_len = inline_len;
243 int ret; 243 int ret;
244 struct btrfs_path *path; 244 struct btrfs_path *path;
245 int extent_inserted = 0; 245 int extent_inserted = 0;
246 u32 extent_item_size; 246 u32 extent_item_size;
247 247
248 if (compressed_size) 248 if (compressed_size)
249 data_len = compressed_size; 249 data_len = compressed_size;
250 250
251 if (start > 0 || 251 if (start > 0 ||
252 actual_end > PAGE_CACHE_SIZE || 252 actual_end > PAGE_CACHE_SIZE ||
253 data_len > BTRFS_MAX_INLINE_DATA_SIZE(root) || 253 data_len > BTRFS_MAX_INLINE_DATA_SIZE(root) ||
254 (!compressed_size && 254 (!compressed_size &&
255 (actual_end & (root->sectorsize - 1)) == 0) || 255 (actual_end & (root->sectorsize - 1)) == 0) ||
256 end + 1 < isize || 256 end + 1 < isize ||
257 data_len > root->fs_info->max_inline) { 257 data_len > root->fs_info->max_inline) {
258 return 1; 258 return 1;
259 } 259 }
260 260
261 path = btrfs_alloc_path(); 261 path = btrfs_alloc_path();
262 if (!path) 262 if (!path)
263 return -ENOMEM; 263 return -ENOMEM;
264 264
265 trans = btrfs_join_transaction(root); 265 trans = btrfs_join_transaction(root);
266 if (IS_ERR(trans)) { 266 if (IS_ERR(trans)) {
267 btrfs_free_path(path); 267 btrfs_free_path(path);
268 return PTR_ERR(trans); 268 return PTR_ERR(trans);
269 } 269 }
270 trans->block_rsv = &root->fs_info->delalloc_block_rsv; 270 trans->block_rsv = &root->fs_info->delalloc_block_rsv;
271 271
272 if (compressed_size && compressed_pages) 272 if (compressed_size && compressed_pages)
273 extent_item_size = btrfs_file_extent_calc_inline_size( 273 extent_item_size = btrfs_file_extent_calc_inline_size(
274 compressed_size); 274 compressed_size);
275 else 275 else
276 extent_item_size = btrfs_file_extent_calc_inline_size( 276 extent_item_size = btrfs_file_extent_calc_inline_size(
277 inline_len); 277 inline_len);
278 278
279 ret = __btrfs_drop_extents(trans, root, inode, path, 279 ret = __btrfs_drop_extents(trans, root, inode, path,
280 start, aligned_end, NULL, 280 start, aligned_end, NULL,
281 1, 1, extent_item_size, &extent_inserted); 281 1, 1, extent_item_size, &extent_inserted);
282 if (ret) { 282 if (ret) {
283 btrfs_abort_transaction(trans, root, ret); 283 btrfs_abort_transaction(trans, root, ret);
284 goto out; 284 goto out;
285 } 285 }
286 286
287 if (isize > actual_end) 287 if (isize > actual_end)
288 inline_len = min_t(u64, isize, actual_end); 288 inline_len = min_t(u64, isize, actual_end);
289 ret = insert_inline_extent(trans, path, extent_inserted, 289 ret = insert_inline_extent(trans, path, extent_inserted,
290 root, inode, start, 290 root, inode, start,
291 inline_len, compressed_size, 291 inline_len, compressed_size,
292 compress_type, compressed_pages); 292 compress_type, compressed_pages);
293 if (ret && ret != -ENOSPC) { 293 if (ret && ret != -ENOSPC) {
294 btrfs_abort_transaction(trans, root, ret); 294 btrfs_abort_transaction(trans, root, ret);
295 goto out; 295 goto out;
296 } else if (ret == -ENOSPC) { 296 } else if (ret == -ENOSPC) {
297 ret = 1; 297 ret = 1;
298 goto out; 298 goto out;
299 } 299 }
300 300
301 set_bit(BTRFS_INODE_NEEDS_FULL_SYNC, &BTRFS_I(inode)->runtime_flags); 301 set_bit(BTRFS_INODE_NEEDS_FULL_SYNC, &BTRFS_I(inode)->runtime_flags);
302 btrfs_delalloc_release_metadata(inode, end + 1 - start); 302 btrfs_delalloc_release_metadata(inode, end + 1 - start);
303 btrfs_drop_extent_cache(inode, start, aligned_end - 1, 0); 303 btrfs_drop_extent_cache(inode, start, aligned_end - 1, 0);
304 out: 304 out:
305 btrfs_free_path(path); 305 btrfs_free_path(path);
306 btrfs_end_transaction(trans, root); 306 btrfs_end_transaction(trans, root);
307 return ret; 307 return ret;
308 } 308 }
309 309
310 struct async_extent { 310 struct async_extent {
311 u64 start; 311 u64 start;
312 u64 ram_size; 312 u64 ram_size;
313 u64 compressed_size; 313 u64 compressed_size;
314 struct page **pages; 314 struct page **pages;
315 unsigned long nr_pages; 315 unsigned long nr_pages;
316 int compress_type; 316 int compress_type;
317 struct list_head list; 317 struct list_head list;
318 }; 318 };
319 319
320 struct async_cow { 320 struct async_cow {
321 struct inode *inode; 321 struct inode *inode;
322 struct btrfs_root *root; 322 struct btrfs_root *root;
323 struct page *locked_page; 323 struct page *locked_page;
324 u64 start; 324 u64 start;
325 u64 end; 325 u64 end;
326 struct list_head extents; 326 struct list_head extents;
327 struct btrfs_work work; 327 struct btrfs_work work;
328 }; 328 };
329 329
330 static noinline int add_async_extent(struct async_cow *cow, 330 static noinline int add_async_extent(struct async_cow *cow,
331 u64 start, u64 ram_size, 331 u64 start, u64 ram_size,
332 u64 compressed_size, 332 u64 compressed_size,
333 struct page **pages, 333 struct page **pages,
334 unsigned long nr_pages, 334 unsigned long nr_pages,
335 int compress_type) 335 int compress_type)
336 { 336 {
337 struct async_extent *async_extent; 337 struct async_extent *async_extent;
338 338
339 async_extent = kmalloc(sizeof(*async_extent), GFP_NOFS); 339 async_extent = kmalloc(sizeof(*async_extent), GFP_NOFS);
340 BUG_ON(!async_extent); /* -ENOMEM */ 340 BUG_ON(!async_extent); /* -ENOMEM */
341 async_extent->start = start; 341 async_extent->start = start;
342 async_extent->ram_size = ram_size; 342 async_extent->ram_size = ram_size;
343 async_extent->compressed_size = compressed_size; 343 async_extent->compressed_size = compressed_size;
344 async_extent->pages = pages; 344 async_extent->pages = pages;
345 async_extent->nr_pages = nr_pages; 345 async_extent->nr_pages = nr_pages;
346 async_extent->compress_type = compress_type; 346 async_extent->compress_type = compress_type;
347 list_add_tail(&async_extent->list, &cow->extents); 347 list_add_tail(&async_extent->list, &cow->extents);
348 return 0; 348 return 0;
349 } 349 }
350 350
351 static inline int inode_need_compress(struct inode *inode) 351 static inline int inode_need_compress(struct inode *inode)
352 { 352 {
353 struct btrfs_root *root = BTRFS_I(inode)->root; 353 struct btrfs_root *root = BTRFS_I(inode)->root;
354 354
355 /* force compress */ 355 /* force compress */
356 if (btrfs_test_opt(root, FORCE_COMPRESS)) 356 if (btrfs_test_opt(root, FORCE_COMPRESS))
357 return 1; 357 return 1;
358 /* bad compression ratios */ 358 /* bad compression ratios */
359 if (BTRFS_I(inode)->flags & BTRFS_INODE_NOCOMPRESS) 359 if (BTRFS_I(inode)->flags & BTRFS_INODE_NOCOMPRESS)
360 return 0; 360 return 0;
361 if (btrfs_test_opt(root, COMPRESS) || 361 if (btrfs_test_opt(root, COMPRESS) ||
362 BTRFS_I(inode)->flags & BTRFS_INODE_COMPRESS || 362 BTRFS_I(inode)->flags & BTRFS_INODE_COMPRESS ||
363 BTRFS_I(inode)->force_compress) 363 BTRFS_I(inode)->force_compress)
364 return 1; 364 return 1;
365 return 0; 365 return 0;
366 } 366 }
367 367
368 /* 368 /*
369 * we create compressed extents in two phases. The first 369 * we create compressed extents in two phases. The first
370 * phase compresses a range of pages that have already been 370 * phase compresses a range of pages that have already been
371 * locked (both pages and state bits are locked). 371 * locked (both pages and state bits are locked).
372 * 372 *
373 * This is done inside an ordered work queue, and the compression 373 * This is done inside an ordered work queue, and the compression
374 * is spread across many cpus. The actual IO submission is step 374 * is spread across many cpus. The actual IO submission is step
375 * two, and the ordered work queue takes care of making sure that 375 * two, and the ordered work queue takes care of making sure that
376 * happens in the same order things were put onto the queue by 376 * happens in the same order things were put onto the queue by
377 * writepages and friends. 377 * writepages and friends.
378 * 378 *
379 * If this code finds it can't get good compression, it puts an 379 * If this code finds it can't get good compression, it puts an
380 * entry onto the work queue to write the uncompressed bytes. This 380 * entry onto the work queue to write the uncompressed bytes. This
381 * makes sure that both compressed inodes and uncompressed inodes 381 * makes sure that both compressed inodes and uncompressed inodes
382 * are written in the same order that the flusher thread sent them 382 * are written in the same order that the flusher thread sent them
383 * down. 383 * down.
384 */ 384 */
385 static noinline void compress_file_range(struct inode *inode, 385 static noinline void compress_file_range(struct inode *inode,
386 struct page *locked_page, 386 struct page *locked_page,
387 u64 start, u64 end, 387 u64 start, u64 end,
388 struct async_cow *async_cow, 388 struct async_cow *async_cow,
389 int *num_added) 389 int *num_added)
390 { 390 {
391 struct btrfs_root *root = BTRFS_I(inode)->root; 391 struct btrfs_root *root = BTRFS_I(inode)->root;
392 u64 num_bytes; 392 u64 num_bytes;
393 u64 blocksize = root->sectorsize; 393 u64 blocksize = root->sectorsize;
394 u64 actual_end; 394 u64 actual_end;
395 u64 isize = i_size_read(inode); 395 u64 isize = i_size_read(inode);
396 int ret = 0; 396 int ret = 0;
397 struct page **pages = NULL; 397 struct page **pages = NULL;
398 unsigned long nr_pages; 398 unsigned long nr_pages;
399 unsigned long nr_pages_ret = 0; 399 unsigned long nr_pages_ret = 0;
400 unsigned long total_compressed = 0; 400 unsigned long total_compressed = 0;
401 unsigned long total_in = 0; 401 unsigned long total_in = 0;
402 unsigned long max_compressed = 128 * 1024; 402 unsigned long max_compressed = 128 * 1024;
403 unsigned long max_uncompressed = 128 * 1024; 403 unsigned long max_uncompressed = 128 * 1024;
404 int i; 404 int i;
405 int will_compress; 405 int will_compress;
406 int compress_type = root->fs_info->compress_type; 406 int compress_type = root->fs_info->compress_type;
407 int redirty = 0; 407 int redirty = 0;
408 408
409 /* if this is a small write inside eof, kick off a defrag */ 409 /* if this is a small write inside eof, kick off a defrag */
410 if ((end - start + 1) < 16 * 1024 && 410 if ((end - start + 1) < 16 * 1024 &&
411 (start > 0 || end + 1 < BTRFS_I(inode)->disk_i_size)) 411 (start > 0 || end + 1 < BTRFS_I(inode)->disk_i_size))
412 btrfs_add_inode_defrag(NULL, inode); 412 btrfs_add_inode_defrag(NULL, inode);
413 413
414 actual_end = min_t(u64, isize, end + 1); 414 actual_end = min_t(u64, isize, end + 1);
415 again: 415 again:
416 will_compress = 0; 416 will_compress = 0;
417 nr_pages = (end >> PAGE_CACHE_SHIFT) - (start >> PAGE_CACHE_SHIFT) + 1; 417 nr_pages = (end >> PAGE_CACHE_SHIFT) - (start >> PAGE_CACHE_SHIFT) + 1;
418 nr_pages = min(nr_pages, (128 * 1024UL) / PAGE_CACHE_SIZE); 418 nr_pages = min(nr_pages, (128 * 1024UL) / PAGE_CACHE_SIZE);
419 419
420 /* 420 /*
421 * we don't want to send crud past the end of i_size through 421 * we don't want to send crud past the end of i_size through
422 * compression, that's just a waste of CPU time. So, if the 422 * compression, that's just a waste of CPU time. So, if the
423 * end of the file is before the start of our current 423 * end of the file is before the start of our current
424 * requested range of bytes, we bail out to the uncompressed 424 * requested range of bytes, we bail out to the uncompressed
425 * cleanup code that can deal with all of this. 425 * cleanup code that can deal with all of this.
426 * 426 *
427 * It isn't really the fastest way to fix things, but this is a 427 * It isn't really the fastest way to fix things, but this is a
428 * very uncommon corner. 428 * very uncommon corner.
429 */ 429 */
430 if (actual_end <= start) 430 if (actual_end <= start)
431 goto cleanup_and_bail_uncompressed; 431 goto cleanup_and_bail_uncompressed;
432 432
433 total_compressed = actual_end - start; 433 total_compressed = actual_end - start;
434 434
435 /* 435 /*
436 * skip compression for a small file range(<=blocksize) that 436 * skip compression for a small file range(<=blocksize) that
437 * isn't an inline extent, since it dosen't save disk space at all. 437 * isn't an inline extent, since it dosen't save disk space at all.
438 */ 438 */
439 if (total_compressed <= blocksize && 439 if (total_compressed <= blocksize &&
440 (start > 0 || end + 1 < BTRFS_I(inode)->disk_i_size)) 440 (start > 0 || end + 1 < BTRFS_I(inode)->disk_i_size))
441 goto cleanup_and_bail_uncompressed; 441 goto cleanup_and_bail_uncompressed;
442 442
443 /* we want to make sure that amount of ram required to uncompress 443 /* we want to make sure that amount of ram required to uncompress
444 * an extent is reasonable, so we limit the total size in ram 444 * an extent is reasonable, so we limit the total size in ram
445 * of a compressed extent to 128k. This is a crucial number 445 * of a compressed extent to 128k. This is a crucial number
446 * because it also controls how easily we can spread reads across 446 * because it also controls how easily we can spread reads across
447 * cpus for decompression. 447 * cpus for decompression.
448 * 448 *
449 * We also want to make sure the amount of IO required to do 449 * We also want to make sure the amount of IO required to do
450 * a random read is reasonably small, so we limit the size of 450 * a random read is reasonably small, so we limit the size of
451 * a compressed extent to 128k. 451 * a compressed extent to 128k.
452 */ 452 */
453 total_compressed = min(total_compressed, max_uncompressed); 453 total_compressed = min(total_compressed, max_uncompressed);
454 num_bytes = ALIGN(end - start + 1, blocksize); 454 num_bytes = ALIGN(end - start + 1, blocksize);
455 num_bytes = max(blocksize, num_bytes); 455 num_bytes = max(blocksize, num_bytes);
456 total_in = 0; 456 total_in = 0;
457 ret = 0; 457 ret = 0;
458 458
459 /* 459 /*
460 * we do compression for mount -o compress and when the 460 * we do compression for mount -o compress and when the
461 * inode has not been flagged as nocompress. This flag can 461 * inode has not been flagged as nocompress. This flag can
462 * change at any time if we discover bad compression ratios. 462 * change at any time if we discover bad compression ratios.
463 */ 463 */
464 if (inode_need_compress(inode)) { 464 if (inode_need_compress(inode)) {
465 WARN_ON(pages); 465 WARN_ON(pages);
466 pages = kzalloc(sizeof(struct page *) * nr_pages, GFP_NOFS); 466 pages = kzalloc(sizeof(struct page *) * nr_pages, GFP_NOFS);
467 if (!pages) { 467 if (!pages) {
468 /* just bail out to the uncompressed code */ 468 /* just bail out to the uncompressed code */
469 goto cont; 469 goto cont;
470 } 470 }
471 471
472 if (BTRFS_I(inode)->force_compress) 472 if (BTRFS_I(inode)->force_compress)
473 compress_type = BTRFS_I(inode)->force_compress; 473 compress_type = BTRFS_I(inode)->force_compress;
474 474
475 /* 475 /*
476 * we need to call clear_page_dirty_for_io on each 476 * we need to call clear_page_dirty_for_io on each
477 * page in the range. Otherwise applications with the file 477 * page in the range. Otherwise applications with the file
478 * mmap'd can wander in and change the page contents while 478 * mmap'd can wander in and change the page contents while
479 * we are compressing them. 479 * we are compressing them.
480 * 480 *
481 * If the compression fails for any reason, we set the pages 481 * If the compression fails for any reason, we set the pages
482 * dirty again later on. 482 * dirty again later on.
483 */ 483 */
484 extent_range_clear_dirty_for_io(inode, start, end); 484 extent_range_clear_dirty_for_io(inode, start, end);
485 redirty = 1; 485 redirty = 1;
486 ret = btrfs_compress_pages(compress_type, 486 ret = btrfs_compress_pages(compress_type,
487 inode->i_mapping, start, 487 inode->i_mapping, start,
488 total_compressed, pages, 488 total_compressed, pages,
489 nr_pages, &nr_pages_ret, 489 nr_pages, &nr_pages_ret,
490 &total_in, 490 &total_in,
491 &total_compressed, 491 &total_compressed,
492 max_compressed); 492 max_compressed);
493 493
494 if (!ret) { 494 if (!ret) {
495 unsigned long offset = total_compressed & 495 unsigned long offset = total_compressed &
496 (PAGE_CACHE_SIZE - 1); 496 (PAGE_CACHE_SIZE - 1);
497 struct page *page = pages[nr_pages_ret - 1]; 497 struct page *page = pages[nr_pages_ret - 1];
498 char *kaddr; 498 char *kaddr;
499 499
500 /* zero the tail end of the last page, we might be 500 /* zero the tail end of the last page, we might be
501 * sending it down to disk 501 * sending it down to disk
502 */ 502 */
503 if (offset) { 503 if (offset) {
504 kaddr = kmap_atomic(page); 504 kaddr = kmap_atomic(page);
505 memset(kaddr + offset, 0, 505 memset(kaddr + offset, 0,
506 PAGE_CACHE_SIZE - offset); 506 PAGE_CACHE_SIZE - offset);
507 kunmap_atomic(kaddr); 507 kunmap_atomic(kaddr);
508 } 508 }
509 will_compress = 1; 509 will_compress = 1;
510 } 510 }
511 } 511 }
512 cont: 512 cont:
513 if (start == 0) { 513 if (start == 0) {
514 /* lets try to make an inline extent */ 514 /* lets try to make an inline extent */
515 if (ret || total_in < (actual_end - start)) { 515 if (ret || total_in < (actual_end - start)) {
516 /* we didn't compress the entire range, try 516 /* we didn't compress the entire range, try
517 * to make an uncompressed inline extent. 517 * to make an uncompressed inline extent.
518 */ 518 */
519 ret = cow_file_range_inline(root, inode, start, end, 519 ret = cow_file_range_inline(root, inode, start, end,
520 0, 0, NULL); 520 0, 0, NULL);
521 } else { 521 } else {
522 /* try making a compressed inline extent */ 522 /* try making a compressed inline extent */
523 ret = cow_file_range_inline(root, inode, start, end, 523 ret = cow_file_range_inline(root, inode, start, end,
524 total_compressed, 524 total_compressed,
525 compress_type, pages); 525 compress_type, pages);
526 } 526 }
527 if (ret <= 0) { 527 if (ret <= 0) {
528 unsigned long clear_flags = EXTENT_DELALLOC | 528 unsigned long clear_flags = EXTENT_DELALLOC |
529 EXTENT_DEFRAG; 529 EXTENT_DEFRAG;
530 unsigned long page_error_op; 530 unsigned long page_error_op;
531 531
532 clear_flags |= (ret < 0) ? EXTENT_DO_ACCOUNTING : 0; 532 clear_flags |= (ret < 0) ? EXTENT_DO_ACCOUNTING : 0;
533 page_error_op = ret < 0 ? PAGE_SET_ERROR : 0; 533 page_error_op = ret < 0 ? PAGE_SET_ERROR : 0;
534 534
535 /* 535 /*
536 * inline extent creation worked or returned error, 536 * inline extent creation worked or returned error,
537 * we don't need to create any more async work items. 537 * we don't need to create any more async work items.
538 * Unlock and free up our temp pages. 538 * Unlock and free up our temp pages.
539 */ 539 */
540 extent_clear_unlock_delalloc(inode, start, end, NULL, 540 extent_clear_unlock_delalloc(inode, start, end, NULL,
541 clear_flags, PAGE_UNLOCK | 541 clear_flags, PAGE_UNLOCK |
542 PAGE_CLEAR_DIRTY | 542 PAGE_CLEAR_DIRTY |
543 PAGE_SET_WRITEBACK | 543 PAGE_SET_WRITEBACK |
544 page_error_op | 544 page_error_op |
545 PAGE_END_WRITEBACK); 545 PAGE_END_WRITEBACK);
546 goto free_pages_out; 546 goto free_pages_out;
547 } 547 }
548 } 548 }
549 549
550 if (will_compress) { 550 if (will_compress) {
551 /* 551 /*
552 * we aren't doing an inline extent round the compressed size 552 * we aren't doing an inline extent round the compressed size
553 * up to a block size boundary so the allocator does sane 553 * up to a block size boundary so the allocator does sane
554 * things 554 * things
555 */ 555 */
556 total_compressed = ALIGN(total_compressed, blocksize); 556 total_compressed = ALIGN(total_compressed, blocksize);
557 557
558 /* 558 /*
559 * one last check to make sure the compression is really a 559 * one last check to make sure the compression is really a
560 * win, compare the page count read with the blocks on disk 560 * win, compare the page count read with the blocks on disk
561 */ 561 */
562 total_in = ALIGN(total_in, PAGE_CACHE_SIZE); 562 total_in = ALIGN(total_in, PAGE_CACHE_SIZE);
563 if (total_compressed >= total_in) { 563 if (total_compressed >= total_in) {
564 will_compress = 0; 564 will_compress = 0;
565 } else { 565 } else {
566 num_bytes = total_in; 566 num_bytes = total_in;
567 } 567 }
568 } 568 }
569 if (!will_compress && pages) { 569 if (!will_compress && pages) {
570 /* 570 /*
571 * the compression code ran but failed to make things smaller, 571 * the compression code ran but failed to make things smaller,
572 * free any pages it allocated and our page pointer array 572 * free any pages it allocated and our page pointer array
573 */ 573 */
574 for (i = 0; i < nr_pages_ret; i++) { 574 for (i = 0; i < nr_pages_ret; i++) {
575 WARN_ON(pages[i]->mapping); 575 WARN_ON(pages[i]->mapping);
576 page_cache_release(pages[i]); 576 page_cache_release(pages[i]);
577 } 577 }
578 kfree(pages); 578 kfree(pages);
579 pages = NULL; 579 pages = NULL;
580 total_compressed = 0; 580 total_compressed = 0;
581 nr_pages_ret = 0; 581 nr_pages_ret = 0;
582 582
583 /* flag the file so we don't compress in the future */ 583 /* flag the file so we don't compress in the future */
584 if (!btrfs_test_opt(root, FORCE_COMPRESS) && 584 if (!btrfs_test_opt(root, FORCE_COMPRESS) &&
585 !(BTRFS_I(inode)->force_compress)) { 585 !(BTRFS_I(inode)->force_compress)) {
586 BTRFS_I(inode)->flags |= BTRFS_INODE_NOCOMPRESS; 586 BTRFS_I(inode)->flags |= BTRFS_INODE_NOCOMPRESS;
587 } 587 }
588 } 588 }
589 if (will_compress) { 589 if (will_compress) {
590 *num_added += 1; 590 *num_added += 1;
591 591
592 /* the async work queues will take care of doing actual 592 /* the async work queues will take care of doing actual
593 * allocation on disk for these compressed pages, 593 * allocation on disk for these compressed pages,
594 * and will submit them to the elevator. 594 * and will submit them to the elevator.
595 */ 595 */
596 add_async_extent(async_cow, start, num_bytes, 596 add_async_extent(async_cow, start, num_bytes,
597 total_compressed, pages, nr_pages_ret, 597 total_compressed, pages, nr_pages_ret,
598 compress_type); 598 compress_type);
599 599
600 if (start + num_bytes < end) { 600 if (start + num_bytes < end) {
601 start += num_bytes; 601 start += num_bytes;
602 pages = NULL; 602 pages = NULL;
603 cond_resched(); 603 cond_resched();
604 goto again; 604 goto again;
605 } 605 }
606 } else { 606 } else {
607 cleanup_and_bail_uncompressed: 607 cleanup_and_bail_uncompressed:
608 /* 608 /*
609 * No compression, but we still need to write the pages in 609 * No compression, but we still need to write the pages in
610 * the file we've been given so far. redirty the locked 610 * the file we've been given so far. redirty the locked
611 * page if it corresponds to our extent and set things up 611 * page if it corresponds to our extent and set things up
612 * for the async work queue to run cow_file_range to do 612 * for the async work queue to run cow_file_range to do
613 * the normal delalloc dance 613 * the normal delalloc dance
614 */ 614 */
615 if (page_offset(locked_page) >= start && 615 if (page_offset(locked_page) >= start &&
616 page_offset(locked_page) <= end) { 616 page_offset(locked_page) <= end) {
617 __set_page_dirty_nobuffers(locked_page); 617 __set_page_dirty_nobuffers(locked_page);
618 /* unlocked later on in the async handlers */ 618 /* unlocked later on in the async handlers */
619 } 619 }
620 if (redirty) 620 if (redirty)
621 extent_range_redirty_for_io(inode, start, end); 621 extent_range_redirty_for_io(inode, start, end);
622 add_async_extent(async_cow, start, end - start + 1, 622 add_async_extent(async_cow, start, end - start + 1,
623 0, NULL, 0, BTRFS_COMPRESS_NONE); 623 0, NULL, 0, BTRFS_COMPRESS_NONE);
624 *num_added += 1; 624 *num_added += 1;
625 } 625 }
626 626
627 return; 627 return;
628 628
629 free_pages_out: 629 free_pages_out:
630 for (i = 0; i < nr_pages_ret; i++) { 630 for (i = 0; i < nr_pages_ret; i++) {
631 WARN_ON(pages[i]->mapping); 631 WARN_ON(pages[i]->mapping);
632 page_cache_release(pages[i]); 632 page_cache_release(pages[i]);
633 } 633 }
634 kfree(pages); 634 kfree(pages);
635 } 635 }
636 636
637 static void free_async_extent_pages(struct async_extent *async_extent) 637 static void free_async_extent_pages(struct async_extent *async_extent)
638 { 638 {
639 int i; 639 int i;
640 640
641 if (!async_extent->pages) 641 if (!async_extent->pages)
642 return; 642 return;
643 643
644 for (i = 0; i < async_extent->nr_pages; i++) { 644 for (i = 0; i < async_extent->nr_pages; i++) {
645 WARN_ON(async_extent->pages[i]->mapping); 645 WARN_ON(async_extent->pages[i]->mapping);
646 page_cache_release(async_extent->pages[i]); 646 page_cache_release(async_extent->pages[i]);
647 } 647 }
648 kfree(async_extent->pages); 648 kfree(async_extent->pages);
649 async_extent->nr_pages = 0; 649 async_extent->nr_pages = 0;
650 async_extent->pages = NULL; 650 async_extent->pages = NULL;
651 } 651 }
652 652
653 /* 653 /*
654 * phase two of compressed writeback. This is the ordered portion 654 * phase two of compressed writeback. This is the ordered portion
655 * of the code, which only gets called in the order the work was 655 * of the code, which only gets called in the order the work was
656 * queued. We walk all the async extents created by compress_file_range 656 * queued. We walk all the async extents created by compress_file_range
657 * and send them down to the disk. 657 * and send them down to the disk.
658 */ 658 */
659 static noinline void submit_compressed_extents(struct inode *inode, 659 static noinline void submit_compressed_extents(struct inode *inode,
660 struct async_cow *async_cow) 660 struct async_cow *async_cow)
661 { 661 {
662 struct async_extent *async_extent; 662 struct async_extent *async_extent;
663 u64 alloc_hint = 0; 663 u64 alloc_hint = 0;
664 struct btrfs_key ins; 664 struct btrfs_key ins;
665 struct extent_map *em; 665 struct extent_map *em;
666 struct btrfs_root *root = BTRFS_I(inode)->root; 666 struct btrfs_root *root = BTRFS_I(inode)->root;
667 struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; 667 struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree;
668 struct extent_io_tree *io_tree; 668 struct extent_io_tree *io_tree;
669 int ret = 0; 669 int ret = 0;
670 670
671 again: 671 again:
672 while (!list_empty(&async_cow->extents)) { 672 while (!list_empty(&async_cow->extents)) {
673 async_extent = list_entry(async_cow->extents.next, 673 async_extent = list_entry(async_cow->extents.next,
674 struct async_extent, list); 674 struct async_extent, list);
675 list_del(&async_extent->list); 675 list_del(&async_extent->list);
676 676
677 io_tree = &BTRFS_I(inode)->io_tree; 677 io_tree = &BTRFS_I(inode)->io_tree;
678 678
679 retry: 679 retry:
680 /* did the compression code fall back to uncompressed IO? */ 680 /* did the compression code fall back to uncompressed IO? */
681 if (!async_extent->pages) { 681 if (!async_extent->pages) {
682 int page_started = 0; 682 int page_started = 0;
683 unsigned long nr_written = 0; 683 unsigned long nr_written = 0;
684 684
685 lock_extent(io_tree, async_extent->start, 685 lock_extent(io_tree, async_extent->start,
686 async_extent->start + 686 async_extent->start +
687 async_extent->ram_size - 1); 687 async_extent->ram_size - 1);
688 688
689 /* allocate blocks */ 689 /* allocate blocks */
690 ret = cow_file_range(inode, async_cow->locked_page, 690 ret = cow_file_range(inode, async_cow->locked_page,
691 async_extent->start, 691 async_extent->start,
692 async_extent->start + 692 async_extent->start +
693 async_extent->ram_size - 1, 693 async_extent->ram_size - 1,
694 &page_started, &nr_written, 0); 694 &page_started, &nr_written, 0);
695 695
696 /* JDM XXX */ 696 /* JDM XXX */
697 697
698 /* 698 /*
699 * if page_started, cow_file_range inserted an 699 * if page_started, cow_file_range inserted an
700 * inline extent and took care of all the unlocking 700 * inline extent and took care of all the unlocking
701 * and IO for us. Otherwise, we need to submit 701 * and IO for us. Otherwise, we need to submit
702 * all those pages down to the drive. 702 * all those pages down to the drive.
703 */ 703 */
704 if (!page_started && !ret) 704 if (!page_started && !ret)
705 extent_write_locked_range(io_tree, 705 extent_write_locked_range(io_tree,
706 inode, async_extent->start, 706 inode, async_extent->start,
707 async_extent->start + 707 async_extent->start +
708 async_extent->ram_size - 1, 708 async_extent->ram_size - 1,
709 btrfs_get_extent, 709 btrfs_get_extent,
710 WB_SYNC_ALL); 710 WB_SYNC_ALL);
711 else if (ret) 711 else if (ret)
712 unlock_page(async_cow->locked_page); 712 unlock_page(async_cow->locked_page);
713 kfree(async_extent); 713 kfree(async_extent);
714 cond_resched(); 714 cond_resched();
715 continue; 715 continue;
716 } 716 }
717 717
718 lock_extent(io_tree, async_extent->start, 718 lock_extent(io_tree, async_extent->start,
719 async_extent->start + async_extent->ram_size - 1); 719 async_extent->start + async_extent->ram_size - 1);
720 720
721 ret = btrfs_reserve_extent(root, 721 ret = btrfs_reserve_extent(root,
722 async_extent->compressed_size, 722 async_extent->compressed_size,
723 async_extent->compressed_size, 723 async_extent->compressed_size,
724 0, alloc_hint, &ins, 1, 1); 724 0, alloc_hint, &ins, 1, 1);
725 if (ret) { 725 if (ret) {
726 free_async_extent_pages(async_extent); 726 free_async_extent_pages(async_extent);
727 727
728 if (ret == -ENOSPC) { 728 if (ret == -ENOSPC) {
729 unlock_extent(io_tree, async_extent->start, 729 unlock_extent(io_tree, async_extent->start,
730 async_extent->start + 730 async_extent->start +
731 async_extent->ram_size - 1); 731 async_extent->ram_size - 1);
732 732
733 /* 733 /*
734 * we need to redirty the pages if we decide to 734 * we need to redirty the pages if we decide to
735 * fallback to uncompressed IO, otherwise we 735 * fallback to uncompressed IO, otherwise we
736 * will not submit these pages down to lower 736 * will not submit these pages down to lower
737 * layers. 737 * layers.
738 */ 738 */
739 extent_range_redirty_for_io(inode, 739 extent_range_redirty_for_io(inode,
740 async_extent->start, 740 async_extent->start,
741 async_extent->start + 741 async_extent->start +
742 async_extent->ram_size - 1); 742 async_extent->ram_size - 1);
743 743
744 goto retry; 744 goto retry;
745 } 745 }
746 goto out_free; 746 goto out_free;
747 } 747 }
748 748
749 /* 749 /*
750 * here we're doing allocation and writeback of the 750 * here we're doing allocation and writeback of the
751 * compressed pages 751 * compressed pages
752 */ 752 */
753 btrfs_drop_extent_cache(inode, async_extent->start, 753 btrfs_drop_extent_cache(inode, async_extent->start,
754 async_extent->start + 754 async_extent->start +
755 async_extent->ram_size - 1, 0); 755 async_extent->ram_size - 1, 0);
756 756
757 em = alloc_extent_map(); 757 em = alloc_extent_map();
758 if (!em) { 758 if (!em) {
759 ret = -ENOMEM; 759 ret = -ENOMEM;
760 goto out_free_reserve; 760 goto out_free_reserve;
761 } 761 }
762 em->start = async_extent->start; 762 em->start = async_extent->start;
763 em->len = async_extent->ram_size; 763 em->len = async_extent->ram_size;
764 em->orig_start = em->start; 764 em->orig_start = em->start;
765 em->mod_start = em->start; 765 em->mod_start = em->start;
766 em->mod_len = em->len; 766 em->mod_len = em->len;
767 767
768 em->block_start = ins.objectid; 768 em->block_start = ins.objectid;
769 em->block_len = ins.offset; 769 em->block_len = ins.offset;
770 em->orig_block_len = ins.offset; 770 em->orig_block_len = ins.offset;
771 em->ram_bytes = async_extent->ram_size; 771 em->ram_bytes = async_extent->ram_size;
772 em->bdev = root->fs_info->fs_devices->latest_bdev; 772 em->bdev = root->fs_info->fs_devices->latest_bdev;
773 em->compress_type = async_extent->compress_type; 773 em->compress_type = async_extent->compress_type;
774 set_bit(EXTENT_FLAG_PINNED, &em->flags); 774 set_bit(EXTENT_FLAG_PINNED, &em->flags);
775 set_bit(EXTENT_FLAG_COMPRESSED, &em->flags); 775 set_bit(EXTENT_FLAG_COMPRESSED, &em->flags);
776 em->generation = -1; 776 em->generation = -1;
777 777
778 while (1) { 778 while (1) {
779 write_lock(&em_tree->lock); 779 write_lock(&em_tree->lock);
780 ret = add_extent_mapping(em_tree, em, 1); 780 ret = add_extent_mapping(em_tree, em, 1);
781 write_unlock(&em_tree->lock); 781 write_unlock(&em_tree->lock);
782 if (ret != -EEXIST) { 782 if (ret != -EEXIST) {
783 free_extent_map(em); 783 free_extent_map(em);
784 break; 784 break;
785 } 785 }
786 btrfs_drop_extent_cache(inode, async_extent->start, 786 btrfs_drop_extent_cache(inode, async_extent->start,
787 async_extent->start + 787 async_extent->start +
788 async_extent->ram_size - 1, 0); 788 async_extent->ram_size - 1, 0);
789 } 789 }
790 790
791 if (ret) 791 if (ret)
792 goto out_free_reserve; 792 goto out_free_reserve;
793 793
794 ret = btrfs_add_ordered_extent_compress(inode, 794 ret = btrfs_add_ordered_extent_compress(inode,
795 async_extent->start, 795 async_extent->start,
796 ins.objectid, 796 ins.objectid,
797 async_extent->ram_size, 797 async_extent->ram_size,
798 ins.offset, 798 ins.offset,
799 BTRFS_ORDERED_COMPRESSED, 799 BTRFS_ORDERED_COMPRESSED,
800 async_extent->compress_type); 800 async_extent->compress_type);
801 if (ret) { 801 if (ret) {
802 btrfs_drop_extent_cache(inode, async_extent->start, 802 btrfs_drop_extent_cache(inode, async_extent->start,
803 async_extent->start + 803 async_extent->start +
804 async_extent->ram_size - 1, 0); 804 async_extent->ram_size - 1, 0);
805 goto out_free_reserve; 805 goto out_free_reserve;
806 } 806 }
807 807
808 /* 808 /*
809 * clear dirty, set writeback and unlock the pages. 809 * clear dirty, set writeback and unlock the pages.
810 */ 810 */
811 extent_clear_unlock_delalloc(inode, async_extent->start, 811 extent_clear_unlock_delalloc(inode, async_extent->start,
812 async_extent->start + 812 async_extent->start +
813 async_extent->ram_size - 1, 813 async_extent->ram_size - 1,
814 NULL, EXTENT_LOCKED | EXTENT_DELALLOC, 814 NULL, EXTENT_LOCKED | EXTENT_DELALLOC,
815 PAGE_UNLOCK | PAGE_CLEAR_DIRTY | 815 PAGE_UNLOCK | PAGE_CLEAR_DIRTY |
816 PAGE_SET_WRITEBACK); 816 PAGE_SET_WRITEBACK);
817 ret = btrfs_submit_compressed_write(inode, 817 ret = btrfs_submit_compressed_write(inode,
818 async_extent->start, 818 async_extent->start,
819 async_extent->ram_size, 819 async_extent->ram_size,
820 ins.objectid, 820 ins.objectid,
821 ins.offset, async_extent->pages, 821 ins.offset, async_extent->pages,
822 async_extent->nr_pages); 822 async_extent->nr_pages);
823 if (ret) { 823 if (ret) {
824 struct extent_io_tree *tree = &BTRFS_I(inode)->io_tree; 824 struct extent_io_tree *tree = &BTRFS_I(inode)->io_tree;
825 struct page *p = async_extent->pages[0]; 825 struct page *p = async_extent->pages[0];
826 const u64 start = async_extent->start; 826 const u64 start = async_extent->start;
827 const u64 end = start + async_extent->ram_size - 1; 827 const u64 end = start + async_extent->ram_size - 1;
828 828
829 p->mapping = inode->i_mapping; 829 p->mapping = inode->i_mapping;
830 tree->ops->writepage_end_io_hook(p, start, end, 830 tree->ops->writepage_end_io_hook(p, start, end,
831 NULL, 0); 831 NULL, 0);
832 p->mapping = NULL; 832 p->mapping = NULL;
833 extent_clear_unlock_delalloc(inode, start, end, NULL, 0, 833 extent_clear_unlock_delalloc(inode, start, end, NULL, 0,
834 PAGE_END_WRITEBACK | 834 PAGE_END_WRITEBACK |
835 PAGE_SET_ERROR); 835 PAGE_SET_ERROR);
836 free_async_extent_pages(async_extent); 836 free_async_extent_pages(async_extent);
837 } 837 }
838 alloc_hint = ins.objectid + ins.offset; 838 alloc_hint = ins.objectid + ins.offset;
839 kfree(async_extent); 839 kfree(async_extent);
840 cond_resched(); 840 cond_resched();
841 } 841 }
842 return; 842 return;
843 out_free_reserve: 843 out_free_reserve:
844 btrfs_free_reserved_extent(root, ins.objectid, ins.offset, 1); 844 btrfs_free_reserved_extent(root, ins.objectid, ins.offset, 1);
845 out_free: 845 out_free:
846 extent_clear_unlock_delalloc(inode, async_extent->start, 846 extent_clear_unlock_delalloc(inode, async_extent->start,
847 async_extent->start + 847 async_extent->start +
848 async_extent->ram_size - 1, 848 async_extent->ram_size - 1,
849 NULL, EXTENT_LOCKED | EXTENT_DELALLOC | 849 NULL, EXTENT_LOCKED | EXTENT_DELALLOC |
850 EXTENT_DEFRAG | EXTENT_DO_ACCOUNTING, 850 EXTENT_DEFRAG | EXTENT_DO_ACCOUNTING,
851 PAGE_UNLOCK | PAGE_CLEAR_DIRTY | 851 PAGE_UNLOCK | PAGE_CLEAR_DIRTY |
852 PAGE_SET_WRITEBACK | PAGE_END_WRITEBACK | 852 PAGE_SET_WRITEBACK | PAGE_END_WRITEBACK |
853 PAGE_SET_ERROR); 853 PAGE_SET_ERROR);
854 free_async_extent_pages(async_extent); 854 free_async_extent_pages(async_extent);
855 kfree(async_extent); 855 kfree(async_extent);
856 goto again; 856 goto again;
857 } 857 }
858 858
859 static u64 get_extent_allocation_hint(struct inode *inode, u64 start, 859 static u64 get_extent_allocation_hint(struct inode *inode, u64 start,
860 u64 num_bytes) 860 u64 num_bytes)
861 { 861 {
862 struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; 862 struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree;
863 struct extent_map *em; 863 struct extent_map *em;
864 u64 alloc_hint = 0; 864 u64 alloc_hint = 0;
865 865
866 read_lock(&em_tree->lock); 866 read_lock(&em_tree->lock);
867 em = search_extent_mapping(em_tree, start, num_bytes); 867 em = search_extent_mapping(em_tree, start, num_bytes);
868 if (em) { 868 if (em) {
869 /* 869 /*
870 * if block start isn't an actual block number then find the 870 * if block start isn't an actual block number then find the
871 * first block in this inode and use that as a hint. If that 871 * first block in this inode and use that as a hint. If that
872 * block is also bogus then just don't worry about it. 872 * block is also bogus then just don't worry about it.
873 */ 873 */
874 if (em->block_start >= EXTENT_MAP_LAST_BYTE) { 874 if (em->block_start >= EXTENT_MAP_LAST_BYTE) {
875 free_extent_map(em); 875 free_extent_map(em);
876 em = search_extent_mapping(em_tree, 0, 0); 876 em = search_extent_mapping(em_tree, 0, 0);
877 if (em && em->block_start < EXTENT_MAP_LAST_BYTE) 877 if (em && em->block_start < EXTENT_MAP_LAST_BYTE)
878 alloc_hint = em->block_start; 878 alloc_hint = em->block_start;
879 if (em) 879 if (em)
880 free_extent_map(em); 880 free_extent_map(em);
881 } else { 881 } else {
882 alloc_hint = em->block_start; 882 alloc_hint = em->block_start;
883 free_extent_map(em); 883 free_extent_map(em);
884 } 884 }
885 } 885 }
886 read_unlock(&em_tree->lock); 886 read_unlock(&em_tree->lock);
887 887
888 return alloc_hint; 888 return alloc_hint;
889 } 889 }
890 890
891 /* 891 /*
892 * when extent_io.c finds a delayed allocation range in the file, 892 * when extent_io.c finds a delayed allocation range in the file,
893 * the call backs end up in this code. The basic idea is to 893 * the call backs end up in this code. The basic idea is to
894 * allocate extents on disk for the range, and create ordered data structs 894 * allocate extents on disk for the range, and create ordered data structs
895 * in ram to track those extents. 895 * in ram to track those extents.
896 * 896 *
897 * locked_page is the page that writepage had locked already. We use 897 * locked_page is the page that writepage had locked already. We use
898 * it to make sure we don't do extra locks or unlocks. 898 * it to make sure we don't do extra locks or unlocks.
899 * 899 *
900 * *page_started is set to one if we unlock locked_page and do everything 900 * *page_started is set to one if we unlock locked_page and do everything
901 * required to start IO on it. It may be clean and already done with 901 * required to start IO on it. It may be clean and already done with
902 * IO when we return. 902 * IO when we return.
903 */ 903 */
904 static noinline int cow_file_range(struct inode *inode, 904 static noinline int cow_file_range(struct inode *inode,
905 struct page *locked_page, 905 struct page *locked_page,
906 u64 start, u64 end, int *page_started, 906 u64 start, u64 end, int *page_started,
907 unsigned long *nr_written, 907 unsigned long *nr_written,
908 int unlock) 908 int unlock)
909 { 909 {
910 struct btrfs_root *root = BTRFS_I(inode)->root; 910 struct btrfs_root *root = BTRFS_I(inode)->root;
911 u64 alloc_hint = 0; 911 u64 alloc_hint = 0;
912 u64 num_bytes; 912 u64 num_bytes;
913 unsigned long ram_size; 913 unsigned long ram_size;
914 u64 disk_num_bytes; 914 u64 disk_num_bytes;
915 u64 cur_alloc_size; 915 u64 cur_alloc_size;
916 u64 blocksize = root->sectorsize; 916 u64 blocksize = root->sectorsize;
917 struct btrfs_key ins; 917 struct btrfs_key ins;
918 struct extent_map *em; 918 struct extent_map *em;
919 struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; 919 struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree;
920 int ret = 0; 920 int ret = 0;
921 921
922 if (btrfs_is_free_space_inode(inode)) { 922 if (btrfs_is_free_space_inode(inode)) {
923 WARN_ON_ONCE(1); 923 WARN_ON_ONCE(1);
924 ret = -EINVAL; 924 ret = -EINVAL;
925 goto out_unlock; 925 goto out_unlock;
926 } 926 }
927 927
928 num_bytes = ALIGN(end - start + 1, blocksize); 928 num_bytes = ALIGN(end - start + 1, blocksize);
929 num_bytes = max(blocksize, num_bytes); 929 num_bytes = max(blocksize, num_bytes);
930 disk_num_bytes = num_bytes; 930 disk_num_bytes = num_bytes;
931 931
932 /* if this is a small write inside eof, kick off defrag */ 932 /* if this is a small write inside eof, kick off defrag */
933 if (num_bytes < 64 * 1024 && 933 if (num_bytes < 64 * 1024 &&
934 (start > 0 || end + 1 < BTRFS_I(inode)->disk_i_size)) 934 (start > 0 || end + 1 < BTRFS_I(inode)->disk_i_size))
935 btrfs_add_inode_defrag(NULL, inode); 935 btrfs_add_inode_defrag(NULL, inode);
936 936
937 if (start == 0) { 937 if (start == 0) {
938 /* lets try to make an inline extent */ 938 /* lets try to make an inline extent */
939 ret = cow_file_range_inline(root, inode, start, end, 0, 0, 939 ret = cow_file_range_inline(root, inode, start, end, 0, 0,
940 NULL); 940 NULL);
941 if (ret == 0) { 941 if (ret == 0) {
942 extent_clear_unlock_delalloc(inode, start, end, NULL, 942 extent_clear_unlock_delalloc(inode, start, end, NULL,
943 EXTENT_LOCKED | EXTENT_DELALLOC | 943 EXTENT_LOCKED | EXTENT_DELALLOC |
944 EXTENT_DEFRAG, PAGE_UNLOCK | 944 EXTENT_DEFRAG, PAGE_UNLOCK |
945 PAGE_CLEAR_DIRTY | PAGE_SET_WRITEBACK | 945 PAGE_CLEAR_DIRTY | PAGE_SET_WRITEBACK |
946 PAGE_END_WRITEBACK); 946 PAGE_END_WRITEBACK);
947 947
948 *nr_written = *nr_written + 948 *nr_written = *nr_written +
949 (end - start + PAGE_CACHE_SIZE) / PAGE_CACHE_SIZE; 949 (end - start + PAGE_CACHE_SIZE) / PAGE_CACHE_SIZE;
950 *page_started = 1; 950 *page_started = 1;
951 goto out; 951 goto out;
952 } else if (ret < 0) { 952 } else if (ret < 0) {
953 goto out_unlock; 953 goto out_unlock;
954 } 954 }
955 } 955 }
956 956
957 BUG_ON(disk_num_bytes > 957 BUG_ON(disk_num_bytes >
958 btrfs_super_total_bytes(root->fs_info->super_copy)); 958 btrfs_super_total_bytes(root->fs_info->super_copy));
959 959
960 alloc_hint = get_extent_allocation_hint(inode, start, num_bytes); 960 alloc_hint = get_extent_allocation_hint(inode, start, num_bytes);
961 btrfs_drop_extent_cache(inode, start, start + num_bytes - 1, 0); 961 btrfs_drop_extent_cache(inode, start, start + num_bytes - 1, 0);
962 962
963 while (disk_num_bytes > 0) { 963 while (disk_num_bytes > 0) {
964 unsigned long op; 964 unsigned long op;
965 965
966 cur_alloc_size = disk_num_bytes; 966 cur_alloc_size = disk_num_bytes;
967 ret = btrfs_reserve_extent(root, cur_alloc_size, 967 ret = btrfs_reserve_extent(root, cur_alloc_size,
968 root->sectorsize, 0, alloc_hint, 968 root->sectorsize, 0, alloc_hint,
969 &ins, 1, 1); 969 &ins, 1, 1);
970 if (ret < 0) 970 if (ret < 0)
971 goto out_unlock; 971 goto out_unlock;
972 972
973 em = alloc_extent_map(); 973 em = alloc_extent_map();
974 if (!em) { 974 if (!em) {
975 ret = -ENOMEM; 975 ret = -ENOMEM;
976 goto out_reserve; 976 goto out_reserve;
977 } 977 }
978 em->start = start; 978 em->start = start;
979 em->orig_start = em->start; 979 em->orig_start = em->start;
980 ram_size = ins.offset; 980 ram_size = ins.offset;
981 em->len = ins.offset; 981 em->len = ins.offset;
982 em->mod_start = em->start; 982 em->mod_start = em->start;
983 em->mod_len = em->len; 983 em->mod_len = em->len;
984 984
985 em->block_start = ins.objectid; 985 em->block_start = ins.objectid;
986 em->block_len = ins.offset; 986 em->block_len = ins.offset;
987 em->orig_block_len = ins.offset; 987 em->orig_block_len = ins.offset;
988 em->ram_bytes = ram_size; 988 em->ram_bytes = ram_size;
989 em->bdev = root->fs_info->fs_devices->latest_bdev; 989 em->bdev = root->fs_info->fs_devices->latest_bdev;
990 set_bit(EXTENT_FLAG_PINNED, &em->flags); 990 set_bit(EXTENT_FLAG_PINNED, &em->flags);
991 em->generation = -1; 991 em->generation = -1;
992 992
993 while (1) { 993 while (1) {
994 write_lock(&em_tree->lock); 994 write_lock(&em_tree->lock);
995 ret = add_extent_mapping(em_tree, em, 1); 995 ret = add_extent_mapping(em_tree, em, 1);
996 write_unlock(&em_tree->lock); 996 write_unlock(&em_tree->lock);
997 if (ret != -EEXIST) { 997 if (ret != -EEXIST) {
998 free_extent_map(em); 998 free_extent_map(em);
999 break; 999 break;
1000 } 1000 }
1001 btrfs_drop_extent_cache(inode, start, 1001 btrfs_drop_extent_cache(inode, start,
1002 start + ram_size - 1, 0); 1002 start + ram_size - 1, 0);
1003 } 1003 }
1004 if (ret) 1004 if (ret)
1005 goto out_reserve; 1005 goto out_reserve;
1006 1006
1007 cur_alloc_size = ins.offset; 1007 cur_alloc_size = ins.offset;
1008 ret = btrfs_add_ordered_extent(inode, start, ins.objectid, 1008 ret = btrfs_add_ordered_extent(inode, start, ins.objectid,
1009 ram_size, cur_alloc_size, 0); 1009 ram_size, cur_alloc_size, 0);
1010 if (ret) 1010 if (ret)
1011 goto out_drop_extent_cache; 1011 goto out_drop_extent_cache;
1012 1012
1013 if (root->root_key.objectid == 1013 if (root->root_key.objectid ==
1014 BTRFS_DATA_RELOC_TREE_OBJECTID) { 1014 BTRFS_DATA_RELOC_TREE_OBJECTID) {
1015 ret = btrfs_reloc_clone_csums(inode, start, 1015 ret = btrfs_reloc_clone_csums(inode, start,
1016 cur_alloc_size); 1016 cur_alloc_size);
1017 if (ret) 1017 if (ret)
1018 goto out_drop_extent_cache; 1018 goto out_drop_extent_cache;
1019 } 1019 }
1020 1020
1021 if (disk_num_bytes < cur_alloc_size) 1021 if (disk_num_bytes < cur_alloc_size)
1022 break; 1022 break;
1023 1023
1024 /* we're not doing compressed IO, don't unlock the first 1024 /* we're not doing compressed IO, don't unlock the first
1025 * page (which the caller expects to stay locked), don't 1025 * page (which the caller expects to stay locked), don't
1026 * clear any dirty bits and don't set any writeback bits 1026 * clear any dirty bits and don't set any writeback bits
1027 * 1027 *
1028 * Do set the Private2 bit so we know this page was properly 1028 * Do set the Private2 bit so we know this page was properly
1029 * setup for writepage 1029 * setup for writepage
1030 */ 1030 */
1031 op = unlock ? PAGE_UNLOCK : 0; 1031 op = unlock ? PAGE_UNLOCK : 0;
1032 op |= PAGE_SET_PRIVATE2; 1032 op |= PAGE_SET_PRIVATE2;
1033 1033
1034 extent_clear_unlock_delalloc(inode, start, 1034 extent_clear_unlock_delalloc(inode, start,
1035 start + ram_size - 1, locked_page, 1035 start + ram_size - 1, locked_page,
1036 EXTENT_LOCKED | EXTENT_DELALLOC, 1036 EXTENT_LOCKED | EXTENT_DELALLOC,
1037 op); 1037 op);
1038 disk_num_bytes -= cur_alloc_size; 1038 disk_num_bytes -= cur_alloc_size;
1039 num_bytes -= cur_alloc_size; 1039 num_bytes -= cur_alloc_size;
1040 alloc_hint = ins.objectid + ins.offset; 1040 alloc_hint = ins.objectid + ins.offset;
1041 start += cur_alloc_size; 1041 start += cur_alloc_size;
1042 } 1042 }
1043 out: 1043 out:
1044 return ret; 1044 return ret;
1045 1045
1046 out_drop_extent_cache: 1046 out_drop_extent_cache:
1047 btrfs_drop_extent_cache(inode, start, start + ram_size - 1, 0); 1047 btrfs_drop_extent_cache(inode, start, start + ram_size - 1, 0);
1048 out_reserve: 1048 out_reserve:
1049 btrfs_free_reserved_extent(root, ins.objectid, ins.offset, 1); 1049 btrfs_free_reserved_extent(root, ins.objectid, ins.offset, 1);
1050 out_unlock: 1050 out_unlock:
1051 extent_clear_unlock_delalloc(inode, start, end, locked_page, 1051 extent_clear_unlock_delalloc(inode, start, end, locked_page,
1052 EXTENT_LOCKED | EXTENT_DO_ACCOUNTING | 1052 EXTENT_LOCKED | EXTENT_DO_ACCOUNTING |
1053 EXTENT_DELALLOC | EXTENT_DEFRAG, 1053 EXTENT_DELALLOC | EXTENT_DEFRAG,
1054 PAGE_UNLOCK | PAGE_CLEAR_DIRTY | 1054 PAGE_UNLOCK | PAGE_CLEAR_DIRTY |
1055 PAGE_SET_WRITEBACK | PAGE_END_WRITEBACK); 1055 PAGE_SET_WRITEBACK | PAGE_END_WRITEBACK);
1056 goto out; 1056 goto out;
1057 } 1057 }
1058 1058
1059 /* 1059 /*
1060 * work queue call back to started compression on a file and pages 1060 * work queue call back to started compression on a file and pages
1061 */ 1061 */
1062 static noinline void async_cow_start(struct btrfs_work *work) 1062 static noinline void async_cow_start(struct btrfs_work *work)
1063 { 1063 {
1064 struct async_cow *async_cow; 1064 struct async_cow *async_cow;
1065 int num_added = 0; 1065 int num_added = 0;
1066 async_cow = container_of(work, struct async_cow, work); 1066 async_cow = container_of(work, struct async_cow, work);
1067 1067
1068 compress_file_range(async_cow->inode, async_cow->locked_page, 1068 compress_file_range(async_cow->inode, async_cow->locked_page,
1069 async_cow->start, async_cow->end, async_cow, 1069 async_cow->start, async_cow->end, async_cow,
1070 &num_added); 1070 &num_added);
1071 if (num_added == 0) { 1071 if (num_added == 0) {
1072 btrfs_add_delayed_iput(async_cow->inode); 1072 btrfs_add_delayed_iput(async_cow->inode);
1073 async_cow->inode = NULL; 1073 async_cow->inode = NULL;
1074 } 1074 }
1075 } 1075 }
1076 1076
1077 /* 1077 /*
1078 * work queue call back to submit previously compressed pages 1078 * work queue call back to submit previously compressed pages
1079 */ 1079 */
1080 static noinline void async_cow_submit(struct btrfs_work *work) 1080 static noinline void async_cow_submit(struct btrfs_work *work)
1081 { 1081 {
1082 struct async_cow *async_cow; 1082 struct async_cow *async_cow;
1083 struct btrfs_root *root; 1083 struct btrfs_root *root;
1084 unsigned long nr_pages; 1084 unsigned long nr_pages;
1085 1085
1086 async_cow = container_of(work, struct async_cow, work); 1086 async_cow = container_of(work, struct async_cow, work);
1087 1087
1088 root = async_cow->root; 1088 root = async_cow->root;
1089 nr_pages = (async_cow->end - async_cow->start + PAGE_CACHE_SIZE) >> 1089 nr_pages = (async_cow->end - async_cow->start + PAGE_CACHE_SIZE) >>
1090 PAGE_CACHE_SHIFT; 1090 PAGE_CACHE_SHIFT;
1091 1091
1092 if (atomic_sub_return(nr_pages, &root->fs_info->async_delalloc_pages) < 1092 if (atomic_sub_return(nr_pages, &root->fs_info->async_delalloc_pages) <
1093 5 * 1024 * 1024 && 1093 5 * 1024 * 1024 &&
1094 waitqueue_active(&root->fs_info->async_submit_wait)) 1094 waitqueue_active(&root->fs_info->async_submit_wait))
1095 wake_up(&root->fs_info->async_submit_wait); 1095 wake_up(&root->fs_info->async_submit_wait);
1096 1096
1097 if (async_cow->inode) 1097 if (async_cow->inode)
1098 submit_compressed_extents(async_cow->inode, async_cow); 1098 submit_compressed_extents(async_cow->inode, async_cow);
1099 } 1099 }
1100 1100
1101 static noinline void async_cow_free(struct btrfs_work *work) 1101 static noinline void async_cow_free(struct btrfs_work *work)
1102 { 1102 {
1103 struct async_cow *async_cow; 1103 struct async_cow *async_cow;
1104 async_cow = container_of(work, struct async_cow, work); 1104 async_cow = container_of(work, struct async_cow, work);
1105 if (async_cow->inode) 1105 if (async_cow->inode)
1106 btrfs_add_delayed_iput(async_cow->inode); 1106 btrfs_add_delayed_iput(async_cow->inode);
1107 kfree(async_cow); 1107 kfree(async_cow);
1108 } 1108 }
1109 1109
1110 static int cow_file_range_async(struct inode *inode, struct page *locked_page, 1110 static int cow_file_range_async(struct inode *inode, struct page *locked_page,
1111 u64 start, u64 end, int *page_started, 1111 u64 start, u64 end, int *page_started,
1112 unsigned long *nr_written) 1112 unsigned long *nr_written)
1113 { 1113 {
1114 struct async_cow *async_cow; 1114 struct async_cow *async_cow;
1115 struct btrfs_root *root = BTRFS_I(inode)->root; 1115 struct btrfs_root *root = BTRFS_I(inode)->root;
1116 unsigned long nr_pages; 1116 unsigned long nr_pages;
1117 u64 cur_end; 1117 u64 cur_end;
1118 int limit = 10 * 1024 * 1024; 1118 int limit = 10 * 1024 * 1024;
1119 1119
1120 clear_extent_bit(&BTRFS_I(inode)->io_tree, start, end, EXTENT_LOCKED, 1120 clear_extent_bit(&BTRFS_I(inode)->io_tree, start, end, EXTENT_LOCKED,
1121 1, 0, NULL, GFP_NOFS); 1121 1, 0, NULL, GFP_NOFS);
1122 while (start < end) { 1122 while (start < end) {
1123 async_cow = kmalloc(sizeof(*async_cow), GFP_NOFS); 1123 async_cow = kmalloc(sizeof(*async_cow), GFP_NOFS);
1124 BUG_ON(!async_cow); /* -ENOMEM */ 1124 BUG_ON(!async_cow); /* -ENOMEM */
1125 async_cow->inode = igrab(inode); 1125 async_cow->inode = igrab(inode);
1126 async_cow->root = root; 1126 async_cow->root = root;
1127 async_cow->locked_page = locked_page; 1127 async_cow->locked_page = locked_page;
1128 async_cow->start = start; 1128 async_cow->start = start;
1129 1129
1130 if (BTRFS_I(inode)->flags & BTRFS_INODE_NOCOMPRESS && 1130 if (BTRFS_I(inode)->flags & BTRFS_INODE_NOCOMPRESS &&
1131 !btrfs_test_opt(root, FORCE_COMPRESS)) 1131 !btrfs_test_opt(root, FORCE_COMPRESS))
1132 cur_end = end; 1132 cur_end = end;
1133 else 1133 else
1134 cur_end = min(end, start + 512 * 1024 - 1); 1134 cur_end = min(end, start + 512 * 1024 - 1);
1135 1135
1136 async_cow->end = cur_end; 1136 async_cow->end = cur_end;
1137 INIT_LIST_HEAD(&async_cow->extents); 1137 INIT_LIST_HEAD(&async_cow->extents);
1138 1138
1139 btrfs_init_work(&async_cow->work, 1139 btrfs_init_work(&async_cow->work,
1140 btrfs_delalloc_helper, 1140 btrfs_delalloc_helper,
1141 async_cow_start, async_cow_submit, 1141 async_cow_start, async_cow_submit,
1142 async_cow_free); 1142 async_cow_free);
1143 1143
1144 nr_pages = (cur_end - start + PAGE_CACHE_SIZE) >> 1144 nr_pages = (cur_end - start + PAGE_CACHE_SIZE) >>
1145 PAGE_CACHE_SHIFT; 1145 PAGE_CACHE_SHIFT;
1146 atomic_add(nr_pages, &root->fs_info->async_delalloc_pages); 1146 atomic_add(nr_pages, &root->fs_info->async_delalloc_pages);
1147 1147
1148 btrfs_queue_work(root->fs_info->delalloc_workers, 1148 btrfs_queue_work(root->fs_info->delalloc_workers,
1149 &async_cow->work); 1149 &async_cow->work);
1150 1150
1151 if (atomic_read(&root->fs_info->async_delalloc_pages) > limit) { 1151 if (atomic_read(&root->fs_info->async_delalloc_pages) > limit) {
1152 wait_event(root->fs_info->async_submit_wait, 1152 wait_event(root->fs_info->async_submit_wait,
1153 (atomic_read(&root->fs_info->async_delalloc_pages) < 1153 (atomic_read(&root->fs_info->async_delalloc_pages) <
1154 limit)); 1154 limit));
1155 } 1155 }
1156 1156
1157 while (atomic_read(&root->fs_info->async_submit_draining) && 1157 while (atomic_read(&root->fs_info->async_submit_draining) &&
1158 atomic_read(&root->fs_info->async_delalloc_pages)) { 1158 atomic_read(&root->fs_info->async_delalloc_pages)) {
1159 wait_event(root->fs_info->async_submit_wait, 1159 wait_event(root->fs_info->async_submit_wait,
1160 (atomic_read(&root->fs_info->async_delalloc_pages) == 1160 (atomic_read(&root->fs_info->async_delalloc_pages) ==
1161 0)); 1161 0));
1162 } 1162 }
1163 1163
1164 *nr_written += nr_pages; 1164 *nr_written += nr_pages;
1165 start = cur_end + 1; 1165 start = cur_end + 1;
1166 } 1166 }
1167 *page_started = 1; 1167 *page_started = 1;
1168 return 0; 1168 return 0;
1169 } 1169 }
1170 1170
1171 static noinline int csum_exist_in_range(struct btrfs_root *root, 1171 static noinline int csum_exist_in_range(struct btrfs_root *root,
1172 u64 bytenr, u64 num_bytes) 1172 u64 bytenr, u64 num_bytes)
1173 { 1173 {
1174 int ret; 1174 int ret;
1175 struct btrfs_ordered_sum *sums; 1175 struct btrfs_ordered_sum *sums;
1176 LIST_HEAD(list); 1176 LIST_HEAD(list);
1177 1177
1178 ret = btrfs_lookup_csums_range(root->fs_info->csum_root, bytenr, 1178 ret = btrfs_lookup_csums_range(root->fs_info->csum_root, bytenr,
1179 bytenr + num_bytes - 1, &list, 0); 1179 bytenr + num_bytes - 1, &list, 0);
1180 if (ret == 0 && list_empty(&list)) 1180 if (ret == 0 && list_empty(&list))
1181 return 0; 1181 return 0;
1182 1182
1183 while (!list_empty(&list)) { 1183 while (!list_empty(&list)) {
1184 sums = list_entry(list.next, struct btrfs_ordered_sum, list); 1184 sums = list_entry(list.next, struct btrfs_ordered_sum, list);
1185 list_del(&sums->list); 1185 list_del(&sums->list);
1186 kfree(sums); 1186 kfree(sums);
1187 } 1187 }
1188 return 1; 1188 return 1;
1189 } 1189 }
1190 1190
1191 /* 1191 /*
1192 * when nowcow writeback call back. This checks for snapshots or COW copies 1192 * when nowcow writeback call back. This checks for snapshots or COW copies
1193 * of the extents that exist in the file, and COWs the file as required. 1193 * of the extents that exist in the file, and COWs the file as required.
1194 * 1194 *
1195 * If no cow copies or snapshots exist, we write directly to the existing 1195 * If no cow copies or snapshots exist, we write directly to the existing
1196 * blocks on disk 1196 * blocks on disk
1197 */ 1197 */
1198 static noinline int run_delalloc_nocow(struct inode *inode, 1198 static noinline int run_delalloc_nocow(struct inode *inode,
1199 struct page *locked_page, 1199 struct page *locked_page,
1200 u64 start, u64 end, int *page_started, int force, 1200 u64 start, u64 end, int *page_started, int force,
1201 unsigned long *nr_written) 1201 unsigned long *nr_written)
1202 { 1202 {
1203 struct btrfs_root *root = BTRFS_I(inode)->root; 1203 struct btrfs_root *root = BTRFS_I(inode)->root;
1204 struct btrfs_trans_handle *trans; 1204 struct btrfs_trans_handle *trans;
1205 struct extent_buffer *leaf; 1205 struct extent_buffer *leaf;
1206 struct btrfs_path *path; 1206 struct btrfs_path *path;
1207 struct btrfs_file_extent_item *fi; 1207 struct btrfs_file_extent_item *fi;
1208 struct btrfs_key found_key; 1208 struct btrfs_key found_key;
1209 u64 cow_start; 1209 u64 cow_start;
1210 u64 cur_offset; 1210 u64 cur_offset;
1211 u64 extent_end; 1211 u64 extent_end;
1212 u64 extent_offset; 1212 u64 extent_offset;
1213 u64 disk_bytenr; 1213 u64 disk_bytenr;
1214 u64 num_bytes; 1214 u64 num_bytes;
1215 u64 disk_num_bytes; 1215 u64 disk_num_bytes;
1216 u64 ram_bytes; 1216 u64 ram_bytes;
1217 int extent_type; 1217 int extent_type;
1218 int ret, err; 1218 int ret, err;
1219 int type; 1219 int type;
1220 int nocow; 1220 int nocow;
1221 int check_prev = 1; 1221 int check_prev = 1;
1222 bool nolock; 1222 bool nolock;
1223 u64 ino = btrfs_ino(inode); 1223 u64 ino = btrfs_ino(inode);
1224 1224
1225 path = btrfs_alloc_path(); 1225 path = btrfs_alloc_path();
1226 if (!path) { 1226 if (!path) {
1227 extent_clear_unlock_delalloc(inode, start, end, locked_page, 1227 extent_clear_unlock_delalloc(inode, start, end, locked_page,
1228 EXTENT_LOCKED | EXTENT_DELALLOC | 1228 EXTENT_LOCKED | EXTENT_DELALLOC |
1229 EXTENT_DO_ACCOUNTING | 1229 EXTENT_DO_ACCOUNTING |
1230 EXTENT_DEFRAG, PAGE_UNLOCK | 1230 EXTENT_DEFRAG, PAGE_UNLOCK |
1231 PAGE_CLEAR_DIRTY | 1231 PAGE_CLEAR_DIRTY |
1232 PAGE_SET_WRITEBACK | 1232 PAGE_SET_WRITEBACK |
1233 PAGE_END_WRITEBACK); 1233 PAGE_END_WRITEBACK);
1234 return -ENOMEM; 1234 return -ENOMEM;
1235 } 1235 }
1236 1236
1237 nolock = btrfs_is_free_space_inode(inode); 1237 nolock = btrfs_is_free_space_inode(inode);
1238 1238
1239 if (nolock) 1239 if (nolock)
1240 trans = btrfs_join_transaction_nolock(root); 1240 trans = btrfs_join_transaction_nolock(root);
1241 else 1241 else
1242 trans = btrfs_join_transaction(root); 1242 trans = btrfs_join_transaction(root);
1243 1243
1244 if (IS_ERR(trans)) { 1244 if (IS_ERR(trans)) {
1245 extent_clear_unlock_delalloc(inode, start, end, locked_page, 1245 extent_clear_unlock_delalloc(inode, start, end, locked_page,
1246 EXTENT_LOCKED | EXTENT_DELALLOC | 1246 EXTENT_LOCKED | EXTENT_DELALLOC |
1247 EXTENT_DO_ACCOUNTING | 1247 EXTENT_DO_ACCOUNTING |
1248 EXTENT_DEFRAG, PAGE_UNLOCK | 1248 EXTENT_DEFRAG, PAGE_UNLOCK |
1249 PAGE_CLEAR_DIRTY | 1249 PAGE_CLEAR_DIRTY |
1250 PAGE_SET_WRITEBACK | 1250 PAGE_SET_WRITEBACK |
1251 PAGE_END_WRITEBACK); 1251 PAGE_END_WRITEBACK);
1252 btrfs_free_path(path); 1252 btrfs_free_path(path);
1253 return PTR_ERR(trans); 1253 return PTR_ERR(trans);
1254 } 1254 }
1255 1255
1256 trans->block_rsv = &root->fs_info->delalloc_block_rsv; 1256 trans->block_rsv = &root->fs_info->delalloc_block_rsv;
1257 1257
1258 cow_start = (u64)-1; 1258 cow_start = (u64)-1;
1259 cur_offset = start; 1259 cur_offset = start;
1260 while (1) { 1260 while (1) {
1261 ret = btrfs_lookup_file_extent(trans, root, path, ino, 1261 ret = btrfs_lookup_file_extent(trans, root, path, ino,
1262 cur_offset, 0); 1262 cur_offset, 0);
1263 if (ret < 0) 1263 if (ret < 0)
1264 goto error; 1264 goto error;
1265 if (ret > 0 && path->slots[0] > 0 && check_prev) { 1265 if (ret > 0 && path->slots[0] > 0 && check_prev) {
1266 leaf = path->nodes[0]; 1266 leaf = path->nodes[0];
1267 btrfs_item_key_to_cpu(leaf, &found_key, 1267 btrfs_item_key_to_cpu(leaf, &found_key,
1268 path->slots[0] - 1); 1268 path->slots[0] - 1);
1269 if (found_key.objectid == ino && 1269 if (found_key.objectid == ino &&
1270 found_key.type == BTRFS_EXTENT_DATA_KEY) 1270 found_key.type == BTRFS_EXTENT_DATA_KEY)
1271 path->slots[0]--; 1271 path->slots[0]--;
1272 } 1272 }
1273 check_prev = 0; 1273 check_prev = 0;
1274 next_slot: 1274 next_slot:
1275 leaf = path->nodes[0]; 1275 leaf = path->nodes[0];
1276 if (path->slots[0] >= btrfs_header_nritems(leaf)) { 1276 if (path->slots[0] >= btrfs_header_nritems(leaf)) {
1277 ret = btrfs_next_leaf(root, path); 1277 ret = btrfs_next_leaf(root, path);
1278 if (ret < 0) 1278 if (ret < 0)
1279 goto error; 1279 goto error;
1280 if (ret > 0) 1280 if (ret > 0)
1281 break; 1281 break;
1282 leaf = path->nodes[0]; 1282 leaf = path->nodes[0];
1283 } 1283 }
1284 1284
1285 nocow = 0; 1285 nocow = 0;
1286 disk_bytenr = 0; 1286 disk_bytenr = 0;
1287 num_bytes = 0; 1287 num_bytes = 0;
1288 btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]); 1288 btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]);
1289 1289
1290 if (found_key.objectid > ino || 1290 if (found_key.objectid > ino ||
1291 found_key.type > BTRFS_EXTENT_DATA_KEY || 1291 found_key.type > BTRFS_EXTENT_DATA_KEY ||
1292 found_key.offset > end) 1292 found_key.offset > end)
1293 break; 1293 break;
1294 1294
1295 if (found_key.offset > cur_offset) { 1295 if (found_key.offset > cur_offset) {
1296 extent_end = found_key.offset; 1296 extent_end = found_key.offset;
1297 extent_type = 0; 1297 extent_type = 0;
1298 goto out_check; 1298 goto out_check;
1299 } 1299 }
1300 1300
1301 fi = btrfs_item_ptr(leaf, path->slots[0], 1301 fi = btrfs_item_ptr(leaf, path->slots[0],
1302 struct btrfs_file_extent_item); 1302 struct btrfs_file_extent_item);
1303 extent_type = btrfs_file_extent_type(leaf, fi); 1303 extent_type = btrfs_file_extent_type(leaf, fi);
1304 1304
1305 ram_bytes = btrfs_file_extent_ram_bytes(leaf, fi); 1305 ram_bytes = btrfs_file_extent_ram_bytes(leaf, fi);
1306 if (extent_type == BTRFS_FILE_EXTENT_REG || 1306 if (extent_type == BTRFS_FILE_EXTENT_REG ||
1307 extent_type == BTRFS_FILE_EXTENT_PREALLOC) { 1307 extent_type == BTRFS_FILE_EXTENT_PREALLOC) {
1308 disk_bytenr = btrfs_file_extent_disk_bytenr(leaf, fi); 1308 disk_bytenr = btrfs_file_extent_disk_bytenr(leaf, fi);
1309 extent_offset = btrfs_file_extent_offset(leaf, fi); 1309 extent_offset = btrfs_file_extent_offset(leaf, fi);
1310 extent_end = found_key.offset + 1310 extent_end = found_key.offset +
1311 btrfs_file_extent_num_bytes(leaf, fi); 1311 btrfs_file_extent_num_bytes(leaf, fi);
1312 disk_num_bytes = 1312 disk_num_bytes =
1313 btrfs_file_extent_disk_num_bytes(leaf, fi); 1313 btrfs_file_extent_disk_num_bytes(leaf, fi);
1314 if (extent_end <= start) { 1314 if (extent_end <= start) {
1315 path->slots[0]++; 1315 path->slots[0]++;
1316 goto next_slot; 1316 goto next_slot;
1317 } 1317 }
1318 if (disk_bytenr == 0) 1318 if (disk_bytenr == 0)
1319 goto out_check; 1319 goto out_check;
1320 if (btrfs_file_extent_compression(leaf, fi) || 1320 if (btrfs_file_extent_compression(leaf, fi) ||
1321 btrfs_file_extent_encryption(leaf, fi) || 1321 btrfs_file_extent_encryption(leaf, fi) ||
1322 btrfs_file_extent_other_encoding(leaf, fi)) 1322 btrfs_file_extent_other_encoding(leaf, fi))
1323 goto out_check; 1323 goto out_check;
1324 if (extent_type == BTRFS_FILE_EXTENT_REG && !force) 1324 if (extent_type == BTRFS_FILE_EXTENT_REG && !force)
1325 goto out_check; 1325 goto out_check;
1326 if (btrfs_extent_readonly(root, disk_bytenr)) 1326 if (btrfs_extent_readonly(root, disk_bytenr))
1327 goto out_check; 1327 goto out_check;
1328 if (btrfs_cross_ref_exist(trans, root, ino, 1328 if (btrfs_cross_ref_exist(trans, root, ino,
1329 found_key.offset - 1329 found_key.offset -
1330 extent_offset, disk_bytenr)) 1330 extent_offset, disk_bytenr))
1331 goto out_check; 1331 goto out_check;
1332 disk_bytenr += extent_offset; 1332 disk_bytenr += extent_offset;
1333 disk_bytenr += cur_offset - found_key.offset; 1333 disk_bytenr += cur_offset - found_key.offset;
1334 num_bytes = min(end + 1, extent_end) - cur_offset; 1334 num_bytes = min(end + 1, extent_end) - cur_offset;
1335 /* 1335 /*
1336 * if there are pending snapshots for this root, 1336 * if there are pending snapshots for this root,
1337 * we fall into common COW way. 1337 * we fall into common COW way.
1338 */ 1338 */
1339 if (!nolock) { 1339 if (!nolock) {
1340 err = btrfs_start_write_no_snapshoting(root); 1340 err = btrfs_start_write_no_snapshoting(root);
1341 if (!err) 1341 if (!err)
1342 goto out_check; 1342 goto out_check;
1343 } 1343 }
1344 /* 1344 /*
1345 * force cow if csum exists in the range. 1345 * force cow if csum exists in the range.
1346 * this ensure that csum for a given extent are 1346 * this ensure that csum for a given extent are
1347 * either valid or do not exist. 1347 * either valid or do not exist.
1348 */ 1348 */
1349 if (csum_exist_in_range(root, disk_bytenr, num_bytes)) 1349 if (csum_exist_in_range(root, disk_bytenr, num_bytes))
1350 goto out_check; 1350 goto out_check;
1351 nocow = 1; 1351 nocow = 1;
1352 } else if (extent_type == BTRFS_FILE_EXTENT_INLINE) { 1352 } else if (extent_type == BTRFS_FILE_EXTENT_INLINE) {
1353 extent_end = found_key.offset + 1353 extent_end = found_key.offset +
1354 btrfs_file_extent_inline_len(leaf, 1354 btrfs_file_extent_inline_len(leaf,
1355 path->slots[0], fi); 1355 path->slots[0], fi);
1356 extent_end = ALIGN(extent_end, root->sectorsize); 1356 extent_end = ALIGN(extent_end, root->sectorsize);
1357 } else { 1357 } else {
1358 BUG_ON(1); 1358 BUG_ON(1);
1359 } 1359 }
1360 out_check: 1360 out_check:
1361 if (extent_end <= start) { 1361 if (extent_end <= start) {
1362 path->slots[0]++; 1362 path->slots[0]++;
1363 if (!nolock && nocow) 1363 if (!nolock && nocow)
1364 btrfs_end_write_no_snapshoting(root); 1364 btrfs_end_write_no_snapshoting(root);
1365 goto next_slot; 1365 goto next_slot;
1366 } 1366 }
1367 if (!nocow) { 1367 if (!nocow) {
1368 if (cow_start == (u64)-1) 1368 if (cow_start == (u64)-1)
1369 cow_start = cur_offset; 1369 cow_start = cur_offset;
1370 cur_offset = extent_end; 1370 cur_offset = extent_end;
1371 if (cur_offset > end) 1371 if (cur_offset > end)
1372 break; 1372 break;
1373 path->slots[0]++; 1373 path->slots[0]++;
1374 goto next_slot; 1374 goto next_slot;
1375 } 1375 }
1376 1376
1377 btrfs_release_path(path); 1377 btrfs_release_path(path);
1378 if (cow_start != (u64)-1) { 1378 if (cow_start != (u64)-1) {
1379 ret = cow_file_range(inode, locked_page, 1379 ret = cow_file_range(inode, locked_page,
1380 cow_start, found_key.offset - 1, 1380 cow_start, found_key.offset - 1,
1381 page_started, nr_written, 1); 1381 page_started, nr_written, 1);
1382 if (ret) { 1382 if (ret) {
1383 if (!nolock && nocow) 1383 if (!nolock && nocow)
1384 btrfs_end_write_no_snapshoting(root); 1384 btrfs_end_write_no_snapshoting(root);
1385 goto error; 1385 goto error;
1386 } 1386 }
1387 cow_start = (u64)-1; 1387 cow_start = (u64)-1;
1388 } 1388 }
1389 1389
1390 if (extent_type == BTRFS_FILE_EXTENT_PREALLOC) { 1390 if (extent_type == BTRFS_FILE_EXTENT_PREALLOC) {
1391 struct extent_map *em; 1391 struct extent_map *em;
1392 struct extent_map_tree *em_tree; 1392 struct extent_map_tree *em_tree;
1393 em_tree = &BTRFS_I(inode)->extent_tree; 1393 em_tree = &BTRFS_I(inode)->extent_tree;
1394 em = alloc_extent_map(); 1394 em = alloc_extent_map();
1395 BUG_ON(!em); /* -ENOMEM */ 1395 BUG_ON(!em); /* -ENOMEM */
1396 em->start = cur_offset; 1396 em->start = cur_offset;
1397 em->orig_start = found_key.offset - extent_offset; 1397 em->orig_start = found_key.offset - extent_offset;
1398 em->len = num_bytes; 1398 em->len = num_bytes;
1399 em->block_len = num_bytes; 1399 em->block_len = num_bytes;
1400 em->block_start = disk_bytenr; 1400 em->block_start = disk_bytenr;
1401 em->orig_block_len = disk_num_bytes; 1401 em->orig_block_len = disk_num_bytes;
1402 em->ram_bytes = ram_bytes; 1402 em->ram_bytes = ram_bytes;
1403 em->bdev = root->fs_info->fs_devices->latest_bdev; 1403 em->bdev = root->fs_info->fs_devices->latest_bdev;
1404 em->mod_start = em->start; 1404 em->mod_start = em->start;
1405 em->mod_len = em->len; 1405 em->mod_len = em->len;
1406 set_bit(EXTENT_FLAG_PINNED, &em->flags); 1406 set_bit(EXTENT_FLAG_PINNED, &em->flags);
1407 set_bit(EXTENT_FLAG_FILLING, &em->flags); 1407 set_bit(EXTENT_FLAG_FILLING, &em->flags);
1408 em->generation = -1; 1408 em->generation = -1;
1409 while (1) { 1409 while (1) {
1410 write_lock(&em_tree->lock); 1410 write_lock(&em_tree->lock);
1411 ret = add_extent_mapping(em_tree, em, 1); 1411 ret = add_extent_mapping(em_tree, em, 1);
1412 write_unlock(&em_tree->lock); 1412 write_unlock(&em_tree->lock);
1413 if (ret != -EEXIST) { 1413 if (ret != -EEXIST) {
1414 free_extent_map(em); 1414 free_extent_map(em);
1415 break; 1415 break;
1416 } 1416 }
1417 btrfs_drop_extent_cache(inode, em->start, 1417 btrfs_drop_extent_cache(inode, em->start,
1418 em->start + em->len - 1, 0); 1418 em->start + em->len - 1, 0);
1419 } 1419 }
1420 type = BTRFS_ORDERED_PREALLOC; 1420 type = BTRFS_ORDERED_PREALLOC;
1421 } else { 1421 } else {
1422 type = BTRFS_ORDERED_NOCOW; 1422 type = BTRFS_ORDERED_NOCOW;
1423 } 1423 }
1424 1424
1425 ret = btrfs_add_ordered_extent(inode, cur_offset, disk_bytenr, 1425 ret = btrfs_add_ordered_extent(inode, cur_offset, disk_bytenr,
1426 num_bytes, num_bytes, type); 1426 num_bytes, num_bytes, type);
1427 BUG_ON(ret); /* -ENOMEM */ 1427 BUG_ON(ret); /* -ENOMEM */
1428 1428
1429 if (root->root_key.objectid == 1429 if (root->root_key.objectid ==
1430 BTRFS_DATA_RELOC_TREE_OBJECTID) { 1430 BTRFS_DATA_RELOC_TREE_OBJECTID) {
1431 ret = btrfs_reloc_clone_csums(inode, cur_offset, 1431 ret = btrfs_reloc_clone_csums(inode, cur_offset,
1432 num_bytes); 1432 num_bytes);
1433 if (ret) { 1433 if (ret) {
1434 if (!nolock && nocow) 1434 if (!nolock && nocow)
1435 btrfs_end_write_no_snapshoting(root); 1435 btrfs_end_write_no_snapshoting(root);
1436 goto error; 1436 goto error;
1437 } 1437 }
1438 } 1438 }
1439 1439
1440 extent_clear_unlock_delalloc(inode, cur_offset, 1440 extent_clear_unlock_delalloc(inode, cur_offset,
1441 cur_offset + num_bytes - 1, 1441 cur_offset + num_bytes - 1,
1442 locked_page, EXTENT_LOCKED | 1442 locked_page, EXTENT_LOCKED |
1443 EXTENT_DELALLOC, PAGE_UNLOCK | 1443 EXTENT_DELALLOC, PAGE_UNLOCK |
1444 PAGE_SET_PRIVATE2); 1444 PAGE_SET_PRIVATE2);
1445 if (!nolock && nocow) 1445 if (!nolock && nocow)
1446 btrfs_end_write_no_snapshoting(root); 1446 btrfs_end_write_no_snapshoting(root);
1447 cur_offset = extent_end; 1447 cur_offset = extent_end;
1448 if (cur_offset > end) 1448 if (cur_offset > end)
1449 break; 1449 break;
1450 } 1450 }
1451 btrfs_release_path(path); 1451 btrfs_release_path(path);
1452 1452
1453 if (cur_offset <= end && cow_start == (u64)-1) { 1453 if (cur_offset <= end && cow_start == (u64)-1) {
1454 cow_start = cur_offset; 1454 cow_start = cur_offset;
1455 cur_offset = end; 1455 cur_offset = end;
1456 } 1456 }
1457 1457
1458 if (cow_start != (u64)-1) { 1458 if (cow_start != (u64)-1) {
1459 ret = cow_file_range(inode, locked_page, cow_start, end, 1459 ret = cow_file_range(inode, locked_page, cow_start, end,
1460 page_started, nr_written, 1); 1460 page_started, nr_written, 1);
1461 if (ret) 1461 if (ret)
1462 goto error; 1462 goto error;
1463 } 1463 }
1464 1464
1465 error: 1465 error:
1466 err = btrfs_end_transaction(trans, root); 1466 err = btrfs_end_transaction(trans, root);
1467 if (!ret) 1467 if (!ret)
1468 ret = err; 1468 ret = err;
1469 1469
1470 if (ret && cur_offset < end) 1470 if (ret && cur_offset < end)
1471 extent_clear_unlock_delalloc(inode, cur_offset, end, 1471 extent_clear_unlock_delalloc(inode, cur_offset, end,
1472 locked_page, EXTENT_LOCKED | 1472 locked_page, EXTENT_LOCKED |
1473 EXTENT_DELALLOC | EXTENT_DEFRAG | 1473 EXTENT_DELALLOC | EXTENT_DEFRAG |
1474 EXTENT_DO_ACCOUNTING, PAGE_UNLOCK | 1474 EXTENT_DO_ACCOUNTING, PAGE_UNLOCK |
1475 PAGE_CLEAR_DIRTY | 1475 PAGE_CLEAR_DIRTY |
1476 PAGE_SET_WRITEBACK | 1476 PAGE_SET_WRITEBACK |
1477 PAGE_END_WRITEBACK); 1477 PAGE_END_WRITEBACK);
1478 btrfs_free_path(path); 1478 btrfs_free_path(path);
1479 return ret; 1479 return ret;
1480 } 1480 }
1481 1481
1482 static inline int need_force_cow(struct inode *inode, u64 start, u64 end) 1482 static inline int need_force_cow(struct inode *inode, u64 start, u64 end)
1483 { 1483 {
1484 1484
1485 if (!(BTRFS_I(inode)->flags & BTRFS_INODE_NODATACOW) && 1485 if (!(BTRFS_I(inode)->flags & BTRFS_INODE_NODATACOW) &&
1486 !(BTRFS_I(inode)->flags & BTRFS_INODE_PREALLOC)) 1486 !(BTRFS_I(inode)->flags & BTRFS_INODE_PREALLOC))
1487 return 0; 1487 return 0;
1488 1488
1489 /* 1489 /*
1490 * @defrag_bytes is a hint value, no spinlock held here, 1490 * @defrag_bytes is a hint value, no spinlock held here,
1491 * if is not zero, it means the file is defragging. 1491 * if is not zero, it means the file is defragging.
1492 * Force cow if given extent needs to be defragged. 1492 * Force cow if given extent needs to be defragged.
1493 */ 1493 */
1494 if (BTRFS_I(inode)->defrag_bytes && 1494 if (BTRFS_I(inode)->defrag_bytes &&
1495 test_range_bit(&BTRFS_I(inode)->io_tree, start, end, 1495 test_range_bit(&BTRFS_I(inode)->io_tree, start, end,
1496 EXTENT_DEFRAG, 0, NULL)) 1496 EXTENT_DEFRAG, 0, NULL))
1497 return 1; 1497 return 1;
1498 1498
1499 return 0; 1499 return 0;
1500 } 1500 }
1501 1501
1502 /* 1502 /*
1503 * extent_io.c call back to do delayed allocation processing 1503 * extent_io.c call back to do delayed allocation processing
1504 */ 1504 */
1505 static int run_delalloc_range(struct inode *inode, struct page *locked_page, 1505 static int run_delalloc_range(struct inode *inode, struct page *locked_page,
1506 u64 start, u64 end, int *page_started, 1506 u64 start, u64 end, int *page_started,
1507 unsigned long *nr_written) 1507 unsigned long *nr_written)
1508 { 1508 {
1509 int ret; 1509 int ret;
1510 int force_cow = need_force_cow(inode, start, end); 1510 int force_cow = need_force_cow(inode, start, end);
1511 1511
1512 if (BTRFS_I(inode)->flags & BTRFS_INODE_NODATACOW && !force_cow) { 1512 if (BTRFS_I(inode)->flags & BTRFS_INODE_NODATACOW && !force_cow) {
1513 ret = run_delalloc_nocow(inode, locked_page, start, end, 1513 ret = run_delalloc_nocow(inode, locked_page, start, end,
1514 page_started, 1, nr_written); 1514 page_started, 1, nr_written);
1515 } else if (BTRFS_I(inode)->flags & BTRFS_INODE_PREALLOC && !force_cow) { 1515 } else if (BTRFS_I(inode)->flags & BTRFS_INODE_PREALLOC && !force_cow) {
1516 ret = run_delalloc_nocow(inode, locked_page, start, end, 1516 ret = run_delalloc_nocow(inode, locked_page, start, end,
1517 page_started, 0, nr_written); 1517 page_started, 0, nr_written);
1518 } else if (!inode_need_compress(inode)) { 1518 } else if (!inode_need_compress(inode)) {
1519 ret = cow_file_range(inode, locked_page, start, end, 1519 ret = cow_file_range(inode, locked_page, start, end,
1520 page_started, nr_written, 1); 1520 page_started, nr_written, 1);
1521 } else { 1521 } else {
1522 set_bit(BTRFS_INODE_HAS_ASYNC_EXTENT, 1522 set_bit(BTRFS_INODE_HAS_ASYNC_EXTENT,
1523 &BTRFS_I(inode)->runtime_flags); 1523 &BTRFS_I(inode)->runtime_flags);
1524 ret = cow_file_range_async(inode, locked_page, start, end, 1524 ret = cow_file_range_async(inode, locked_page, start, end,
1525 page_started, nr_written); 1525 page_started, nr_written);
1526 } 1526 }
1527 return ret; 1527 return ret;
1528 } 1528 }
1529 1529
1530 static void btrfs_split_extent_hook(struct inode *inode, 1530 static void btrfs_split_extent_hook(struct inode *inode,
1531 struct extent_state *orig, u64 split) 1531 struct extent_state *orig, u64 split)
1532 { 1532 {
1533 /* not delalloc, ignore it */ 1533 /* not delalloc, ignore it */
1534 if (!(orig->state & EXTENT_DELALLOC)) 1534 if (!(orig->state & EXTENT_DELALLOC))
1535 return; 1535 return;
1536 1536
1537 spin_lock(&BTRFS_I(inode)->lock); 1537 spin_lock(&BTRFS_I(inode)->lock);
1538 BTRFS_I(inode)->outstanding_extents++; 1538 BTRFS_I(inode)->outstanding_extents++;
1539 spin_unlock(&BTRFS_I(inode)->lock); 1539 spin_unlock(&BTRFS_I(inode)->lock);
1540 } 1540 }
1541 1541
1542 /* 1542 /*
1543 * extent_io.c merge_extent_hook, used to track merged delayed allocation 1543 * extent_io.c merge_extent_hook, used to track merged delayed allocation
1544 * extents so we can keep track of new extents that are just merged onto old 1544 * extents so we can keep track of new extents that are just merged onto old
1545 * extents, such as when we are doing sequential writes, so we can properly 1545 * extents, such as when we are doing sequential writes, so we can properly
1546 * account for the metadata space we'll need. 1546 * account for the metadata space we'll need.
1547 */ 1547 */
1548 static void btrfs_merge_extent_hook(struct inode *inode, 1548 static void btrfs_merge_extent_hook(struct inode *inode,
1549 struct extent_state *new, 1549 struct extent_state *new,
1550 struct extent_state *other) 1550 struct extent_state *other)
1551 { 1551 {
1552 /* not delalloc, ignore it */ 1552 /* not delalloc, ignore it */
1553 if (!(other->state & EXTENT_DELALLOC)) 1553 if (!(other->state & EXTENT_DELALLOC))
1554 return; 1554 return;
1555 1555
1556 spin_lock(&BTRFS_I(inode)->lock); 1556 spin_lock(&BTRFS_I(inode)->lock);
1557 BTRFS_I(inode)->outstanding_extents--; 1557 BTRFS_I(inode)->outstanding_extents--;
1558 spin_unlock(&BTRFS_I(inode)->lock); 1558 spin_unlock(&BTRFS_I(inode)->lock);
1559 } 1559 }
1560 1560
1561 static void btrfs_add_delalloc_inodes(struct btrfs_root *root, 1561 static void btrfs_add_delalloc_inodes(struct btrfs_root *root,
1562 struct inode *inode) 1562 struct inode *inode)
1563 { 1563 {
1564 spin_lock(&root->delalloc_lock); 1564 spin_lock(&root->delalloc_lock);
1565 if (list_empty(&BTRFS_I(inode)->delalloc_inodes)) { 1565 if (list_empty(&BTRFS_I(inode)->delalloc_inodes)) {
1566 list_add_tail(&BTRFS_I(inode)->delalloc_inodes, 1566 list_add_tail(&BTRFS_I(inode)->delalloc_inodes,
1567 &root->delalloc_inodes); 1567 &root->delalloc_inodes);
1568 set_bit(BTRFS_INODE_IN_DELALLOC_LIST, 1568 set_bit(BTRFS_INODE_IN_DELALLOC_LIST,
1569 &BTRFS_I(inode)->runtime_flags); 1569 &BTRFS_I(inode)->runtime_flags);
1570 root->nr_delalloc_inodes++; 1570 root->nr_delalloc_inodes++;
1571 if (root->nr_delalloc_inodes == 1) { 1571 if (root->nr_delalloc_inodes == 1) {
1572 spin_lock(&root->fs_info->delalloc_root_lock); 1572 spin_lock(&root->fs_info->delalloc_root_lock);
1573 BUG_ON(!list_empty(&root->delalloc_root)); 1573 BUG_ON(!list_empty(&root->delalloc_root));
1574 list_add_tail(&root->delalloc_root, 1574 list_add_tail(&root->delalloc_root,
1575 &root->fs_info->delalloc_roots); 1575 &root->fs_info->delalloc_roots);
1576 spin_unlock(&root->fs_info->delalloc_root_lock); 1576 spin_unlock(&root->fs_info->delalloc_root_lock);
1577 } 1577 }
1578 } 1578 }
1579 spin_unlock(&root->delalloc_lock); 1579 spin_unlock(&root->delalloc_lock);
1580 } 1580 }
1581 1581
1582 static void btrfs_del_delalloc_inode(struct btrfs_root *root, 1582 static void btrfs_del_delalloc_inode(struct btrfs_root *root,
1583 struct inode *inode) 1583 struct inode *inode)
1584 { 1584 {
1585 spin_lock(&root->delalloc_lock); 1585 spin_lock(&root->delalloc_lock);
1586 if (!list_empty(&BTRFS_I(inode)->delalloc_inodes)) { 1586 if (!list_empty(&BTRFS_I(inode)->delalloc_inodes)) {
1587 list_del_init(&BTRFS_I(inode)->delalloc_inodes); 1587 list_del_init(&BTRFS_I(inode)->delalloc_inodes);
1588 clear_bit(BTRFS_INODE_IN_DELALLOC_LIST, 1588 clear_bit(BTRFS_INODE_IN_DELALLOC_LIST,
1589 &BTRFS_I(inode)->runtime_flags); 1589 &BTRFS_I(inode)->runtime_flags);
1590 root->nr_delalloc_inodes--; 1590 root->nr_delalloc_inodes--;
1591 if (!root->nr_delalloc_inodes) { 1591 if (!root->nr_delalloc_inodes) {
1592 spin_lock(&root->fs_info->delalloc_root_lock); 1592 spin_lock(&root->fs_info->delalloc_root_lock);
1593 BUG_ON(list_empty(&root->delalloc_root)); 1593 BUG_ON(list_empty(&root->delalloc_root));
1594 list_del_init(&root->delalloc_root); 1594 list_del_init(&root->delalloc_root);
1595 spin_unlock(&root->fs_info->delalloc_root_lock); 1595 spin_unlock(&root->fs_info->delalloc_root_lock);
1596 } 1596 }
1597 } 1597 }
1598 spin_unlock(&root->delalloc_lock); 1598 spin_unlock(&root->delalloc_lock);
1599 } 1599 }
1600 1600
1601 /* 1601 /*
1602 * extent_io.c set_bit_hook, used to track delayed allocation 1602 * extent_io.c set_bit_hook, used to track delayed allocation
1603 * bytes in this file, and to maintain the list of inodes that 1603 * bytes in this file, and to maintain the list of inodes that
1604 * have pending delalloc work to be done. 1604 * have pending delalloc work to be done.
1605 */ 1605 */
1606 static void btrfs_set_bit_hook(struct inode *inode, 1606 static void btrfs_set_bit_hook(struct inode *inode,
1607 struct extent_state *state, unsigned long *bits) 1607 struct extent_state *state, unsigned long *bits)
1608 { 1608 {
1609 1609
1610 if ((*bits & EXTENT_DEFRAG) && !(*bits & EXTENT_DELALLOC)) 1610 if ((*bits & EXTENT_DEFRAG) && !(*bits & EXTENT_DELALLOC))
1611 WARN_ON(1); 1611 WARN_ON(1);
1612 /* 1612 /*
1613 * set_bit and clear bit hooks normally require _irqsave/restore 1613 * set_bit and clear bit hooks normally require _irqsave/restore
1614 * but in this case, we are only testing for the DELALLOC 1614 * but in this case, we are only testing for the DELALLOC
1615 * bit, which is only set or cleared with irqs on 1615 * bit, which is only set or cleared with irqs on
1616 */ 1616 */
1617 if (!(state->state & EXTENT_DELALLOC) && (*bits & EXTENT_DELALLOC)) { 1617 if (!(state->state & EXTENT_DELALLOC) && (*bits & EXTENT_DELALLOC)) {
1618 struct btrfs_root *root = BTRFS_I(inode)->root; 1618 struct btrfs_root *root = BTRFS_I(inode)->root;
1619 u64 len = state->end + 1 - state->start; 1619 u64 len = state->end + 1 - state->start;
1620 bool do_list = !btrfs_is_free_space_inode(inode); 1620 bool do_list = !btrfs_is_free_space_inode(inode);
1621 1621
1622 if (*bits & EXTENT_FIRST_DELALLOC) { 1622 if (*bits & EXTENT_FIRST_DELALLOC) {
1623 *bits &= ~EXTENT_FIRST_DELALLOC; 1623 *bits &= ~EXTENT_FIRST_DELALLOC;
1624 } else { 1624 } else {
1625 spin_lock(&BTRFS_I(inode)->lock); 1625 spin_lock(&BTRFS_I(inode)->lock);
1626 BTRFS_I(inode)->outstanding_extents++; 1626 BTRFS_I(inode)->outstanding_extents++;
1627 spin_unlock(&BTRFS_I(inode)->lock); 1627 spin_unlock(&BTRFS_I(inode)->lock);
1628 } 1628 }
1629 1629
1630 __percpu_counter_add(&root->fs_info->delalloc_bytes, len, 1630 __percpu_counter_add(&root->fs_info->delalloc_bytes, len,
1631 root->fs_info->delalloc_batch); 1631 root->fs_info->delalloc_batch);
1632 spin_lock(&BTRFS_I(inode)->lock); 1632 spin_lock(&BTRFS_I(inode)->lock);
1633 BTRFS_I(inode)->delalloc_bytes += len; 1633 BTRFS_I(inode)->delalloc_bytes += len;
1634 if (*bits & EXTENT_DEFRAG) 1634 if (*bits & EXTENT_DEFRAG)
1635 BTRFS_I(inode)->defrag_bytes += len; 1635 BTRFS_I(inode)->defrag_bytes += len;
1636 if (do_list && !test_bit(BTRFS_INODE_IN_DELALLOC_LIST, 1636 if (do_list && !test_bit(BTRFS_INODE_IN_DELALLOC_LIST,
1637 &BTRFS_I(inode)->runtime_flags)) 1637 &BTRFS_I(inode)->runtime_flags))
1638 btrfs_add_delalloc_inodes(root, inode); 1638 btrfs_add_delalloc_inodes(root, inode);
1639 spin_unlock(&BTRFS_I(inode)->lock); 1639 spin_unlock(&BTRFS_I(inode)->lock);
1640 } 1640 }
1641 } 1641 }
1642 1642
1643 /* 1643 /*
1644 * extent_io.c clear_bit_hook, see set_bit_hook for why 1644 * extent_io.c clear_bit_hook, see set_bit_hook for why
1645 */ 1645 */
1646 static void btrfs_clear_bit_hook(struct inode *inode, 1646 static void btrfs_clear_bit_hook(struct inode *inode,
1647 struct extent_state *state, 1647 struct extent_state *state,
1648 unsigned long *bits) 1648 unsigned long *bits)
1649 { 1649 {
1650 u64 len = state->end + 1 - state->start; 1650 u64 len = state->end + 1 - state->start;
1651 1651
1652 spin_lock(&BTRFS_I(inode)->lock); 1652 spin_lock(&BTRFS_I(inode)->lock);
1653 if ((state->state & EXTENT_DEFRAG) && (*bits & EXTENT_DEFRAG)) 1653 if ((state->state & EXTENT_DEFRAG) && (*bits & EXTENT_DEFRAG))
1654 BTRFS_I(inode)->defrag_bytes -= len; 1654 BTRFS_I(inode)->defrag_bytes -= len;
1655 spin_unlock(&BTRFS_I(inode)->lock); 1655 spin_unlock(&BTRFS_I(inode)->lock);
1656 1656
1657 /* 1657 /*
1658 * set_bit and clear bit hooks normally require _irqsave/restore 1658 * set_bit and clear bit hooks normally require _irqsave/restore
1659 * but in this case, we are only testing for the DELALLOC 1659 * but in this case, we are only testing for the DELALLOC
1660 * bit, which is only set or cleared with irqs on 1660 * bit, which is only set or cleared with irqs on
1661 */ 1661 */
1662 if ((state->state & EXTENT_DELALLOC) && (*bits & EXTENT_DELALLOC)) { 1662 if ((state->state & EXTENT_DELALLOC) && (*bits & EXTENT_DELALLOC)) {
1663 struct btrfs_root *root = BTRFS_I(inode)->root; 1663 struct btrfs_root *root = BTRFS_I(inode)->root;
1664 bool do_list = !btrfs_is_free_space_inode(inode); 1664 bool do_list = !btrfs_is_free_space_inode(inode);
1665 1665
1666 if (*bits & EXTENT_FIRST_DELALLOC) { 1666 if (*bits & EXTENT_FIRST_DELALLOC) {
1667 *bits &= ~EXTENT_FIRST_DELALLOC; 1667 *bits &= ~EXTENT_FIRST_DELALLOC;
1668 } else if (!(*bits & EXTENT_DO_ACCOUNTING)) { 1668 } else if (!(*bits & EXTENT_DO_ACCOUNTING)) {
1669 spin_lock(&BTRFS_I(inode)->lock); 1669 spin_lock(&BTRFS_I(inode)->lock);
1670 BTRFS_I(inode)->outstanding_extents--; 1670 BTRFS_I(inode)->outstanding_extents--;
1671 spin_unlock(&BTRFS_I(inode)->lock); 1671 spin_unlock(&BTRFS_I(inode)->lock);
1672 } 1672 }
1673 1673
1674 /* 1674 /*
1675 * We don't reserve metadata space for space cache inodes so we 1675 * We don't reserve metadata space for space cache inodes so we
1676 * don't need to call dellalloc_release_metadata if there is an 1676 * don't need to call dellalloc_release_metadata if there is an
1677 * error. 1677 * error.
1678 */ 1678 */
1679 if (*bits & EXTENT_DO_ACCOUNTING && 1679 if (*bits & EXTENT_DO_ACCOUNTING &&
1680 root != root->fs_info->tree_root) 1680 root != root->fs_info->tree_root)
1681 btrfs_delalloc_release_metadata(inode, len); 1681 btrfs_delalloc_release_metadata(inode, len);
1682 1682
1683 if (root->root_key.objectid != BTRFS_DATA_RELOC_TREE_OBJECTID 1683 if (root->root_key.objectid != BTRFS_DATA_RELOC_TREE_OBJECTID
1684 && do_list && !(state->state & EXTENT_NORESERVE)) 1684 && do_list && !(state->state & EXTENT_NORESERVE))
1685 btrfs_free_reserved_data_space(inode, len); 1685 btrfs_free_reserved_data_space(inode, len);
1686 1686
1687 __percpu_counter_add(&root->fs_info->delalloc_bytes, -len, 1687 __percpu_counter_add(&root->fs_info->delalloc_bytes, -len,
1688 root->fs_info->delalloc_batch); 1688 root->fs_info->delalloc_batch);
1689 spin_lock(&BTRFS_I(inode)->lock); 1689 spin_lock(&BTRFS_I(inode)->lock);
1690 BTRFS_I(inode)->delalloc_bytes -= len; 1690 BTRFS_I(inode)->delalloc_bytes -= len;
1691 if (do_list && BTRFS_I(inode)->delalloc_bytes == 0 && 1691 if (do_list && BTRFS_I(inode)->delalloc_bytes == 0 &&
1692 test_bit(BTRFS_INODE_IN_DELALLOC_LIST, 1692 test_bit(BTRFS_INODE_IN_DELALLOC_LIST,
1693 &BTRFS_I(inode)->runtime_flags)) 1693 &BTRFS_I(inode)->runtime_flags))
1694 btrfs_del_delalloc_inode(root, inode); 1694 btrfs_del_delalloc_inode(root, inode);
1695 spin_unlock(&BTRFS_I(inode)->lock); 1695 spin_unlock(&BTRFS_I(inode)->lock);
1696 } 1696 }
1697 } 1697 }
1698 1698
1699 /* 1699 /*
1700 * extent_io.c merge_bio_hook, this must check the chunk tree to make sure 1700 * extent_io.c merge_bio_hook, this must check the chunk tree to make sure
1701 * we don't create bios that span stripes or chunks 1701 * we don't create bios that span stripes or chunks
1702 */ 1702 */
1703 int btrfs_merge_bio_hook(int rw, struct page *page, unsigned long offset, 1703 int btrfs_merge_bio_hook(int rw, struct page *page, unsigned long offset,
1704 size_t size, struct bio *bio, 1704 size_t size, struct bio *bio,
1705 unsigned long bio_flags) 1705 unsigned long bio_flags)
1706 { 1706 {
1707 struct btrfs_root *root = BTRFS_I(page->mapping->host)->root; 1707 struct btrfs_root *root = BTRFS_I(page->mapping->host)->root;
1708 u64 logical = (u64)bio->bi_iter.bi_sector << 9; 1708 u64 logical = (u64)bio->bi_iter.bi_sector << 9;
1709 u64 length = 0; 1709 u64 length = 0;
1710 u64 map_length; 1710 u64 map_length;
1711 int ret; 1711 int ret;
1712 1712
1713 if (bio_flags & EXTENT_BIO_COMPRESSED) 1713 if (bio_flags & EXTENT_BIO_COMPRESSED)
1714 return 0; 1714 return 0;
1715 1715
1716 length = bio->bi_iter.bi_size; 1716 length = bio->bi_iter.bi_size;
1717 map_length = length; 1717 map_length = length;
1718 ret = btrfs_map_block(root->fs_info, rw, logical, 1718 ret = btrfs_map_block(root->fs_info, rw, logical,
1719 &map_length, NULL, 0); 1719 &map_length, NULL, 0);
1720 /* Will always return 0 with map_multi == NULL */ 1720 /* Will always return 0 with map_multi == NULL */
1721 BUG_ON(ret < 0); 1721 BUG_ON(ret < 0);
1722 if (map_length < length + size) 1722 if (map_length < length + size)
1723 return 1; 1723 return 1;
1724 return 0; 1724 return 0;
1725 } 1725 }
1726 1726
1727 /* 1727 /*
1728 * in order to insert checksums into the metadata in large chunks, 1728 * in order to insert checksums into the metadata in large chunks,
1729 * we wait until bio submission time. All the pages in the bio are 1729 * we wait until bio submission time. All the pages in the bio are
1730 * checksummed and sums are attached onto the ordered extent record. 1730 * checksummed and sums are attached onto the ordered extent record.
1731 * 1731 *
1732 * At IO completion time the cums attached on the ordered extent record 1732 * At IO completion time the cums attached on the ordered extent record
1733 * are inserted into the btree 1733 * are inserted into the btree
1734 */ 1734 */
1735 static int __btrfs_submit_bio_start(struct inode *inode, int rw, 1735 static int __btrfs_submit_bio_start(struct inode *inode, int rw,
1736 struct bio *bio, int mirror_num, 1736 struct bio *bio, int mirror_num,
1737 unsigned long bio_flags, 1737 unsigned long bio_flags,
1738 u64 bio_offset) 1738 u64 bio_offset)
1739 { 1739 {
1740 struct btrfs_root *root = BTRFS_I(inode)->root; 1740 struct btrfs_root *root = BTRFS_I(inode)->root;
1741 int ret = 0; 1741 int ret = 0;
1742 1742
1743 ret = btrfs_csum_one_bio(root, inode, bio, 0, 0); 1743 ret = btrfs_csum_one_bio(root, inode, bio, 0, 0);
1744 BUG_ON(ret); /* -ENOMEM */ 1744 BUG_ON(ret); /* -ENOMEM */
1745 return 0; 1745 return 0;
1746 } 1746 }
1747 1747
1748 /* 1748 /*
1749 * in order to insert checksums into the metadata in large chunks, 1749 * in order to insert checksums into the metadata in large chunks,
1750 * we wait until bio submission time. All the pages in the bio are 1750 * we wait until bio submission time. All the pages in the bio are
1751 * checksummed and sums are attached onto the ordered extent record. 1751 * checksummed and sums are attached onto the ordered extent record.
1752 * 1752 *
1753 * At IO completion time the cums attached on the ordered extent record 1753 * At IO completion time the cums attached on the ordered extent record
1754 * are inserted into the btree 1754 * are inserted into the btree
1755 */ 1755 */
1756 static int __btrfs_submit_bio_done(struct inode *inode, int rw, struct bio *bio, 1756 static int __btrfs_submit_bio_done(struct inode *inode, int rw, struct bio *bio,
1757 int mirror_num, unsigned long bio_flags, 1757 int mirror_num, unsigned long bio_flags,
1758 u64 bio_offset) 1758 u64 bio_offset)
1759 { 1759 {
1760 struct btrfs_root *root = BTRFS_I(inode)->root; 1760 struct btrfs_root *root = BTRFS_I(inode)->root;
1761 int ret; 1761 int ret;
1762 1762
1763 ret = btrfs_map_bio(root, rw, bio, mirror_num, 1); 1763 ret = btrfs_map_bio(root, rw, bio, mirror_num, 1);
1764 if (ret) 1764 if (ret)
1765 bio_endio(bio, ret); 1765 bio_endio(bio, ret);
1766 return ret; 1766 return ret;
1767 } 1767 }
1768 1768
1769 /* 1769 /*
1770 * extent_io.c submission hook. This does the right thing for csum calculation 1770 * extent_io.c submission hook. This does the right thing for csum calculation
1771 * on write, or reading the csums from the tree before a read 1771 * on write, or reading the csums from the tree before a read
1772 */ 1772 */
1773 static int btrfs_submit_bio_hook(struct inode *inode, int rw, struct bio *bio, 1773 static int btrfs_submit_bio_hook(struct inode *inode, int rw, struct bio *bio,
1774 int mirror_num, unsigned long bio_flags, 1774 int mirror_num, unsigned long bio_flags,
1775 u64 bio_offset) 1775 u64 bio_offset)
1776 { 1776 {
1777 struct btrfs_root *root = BTRFS_I(inode)->root; 1777 struct btrfs_root *root = BTRFS_I(inode)->root;
1778 int ret = 0; 1778 int ret = 0;
1779 int skip_sum; 1779 int skip_sum;
1780 int metadata = 0; 1780 int metadata = 0;
1781 int async = !atomic_read(&BTRFS_I(inode)->sync_writers); 1781 int async = !atomic_read(&BTRFS_I(inode)->sync_writers);
1782 1782
1783 skip_sum = BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM; 1783 skip_sum = BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM;
1784 1784
1785 if (btrfs_is_free_space_inode(inode)) 1785 if (btrfs_is_free_space_inode(inode))
1786 metadata = 2; 1786 metadata = 2;
1787 1787
1788 if (!(rw & REQ_WRITE)) { 1788 if (!(rw & REQ_WRITE)) {
1789 ret = btrfs_bio_wq_end_io(root->fs_info, bio, metadata); 1789 ret = btrfs_bio_wq_end_io(root->fs_info, bio, metadata);
1790 if (ret) 1790 if (ret)
1791 goto out; 1791 goto out;
1792 1792
1793 if (bio_flags & EXTENT_BIO_COMPRESSED) { 1793 if (bio_flags & EXTENT_BIO_COMPRESSED) {
1794 ret = btrfs_submit_compressed_read(inode, bio, 1794 ret = btrfs_submit_compressed_read(inode, bio,
1795 mirror_num, 1795 mirror_num,
1796 bio_flags); 1796 bio_flags);
1797 goto out; 1797 goto out;
1798 } else if (!skip_sum) { 1798 } else if (!skip_sum) {
1799 ret = btrfs_lookup_bio_sums(root, inode, bio, NULL); 1799 ret = btrfs_lookup_bio_sums(root, inode, bio, NULL);
1800 if (ret) 1800 if (ret)
1801 goto out; 1801 goto out;
1802 } 1802 }
1803 goto mapit; 1803 goto mapit;
1804 } else if (async && !skip_sum) { 1804 } else if (async && !skip_sum) {
1805 /* csum items have already been cloned */ 1805 /* csum items have already been cloned */
1806 if (root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID) 1806 if (root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID)
1807 goto mapit; 1807 goto mapit;
1808 /* we're doing a write, do the async checksumming */ 1808 /* we're doing a write, do the async checksumming */
1809 ret = btrfs_wq_submit_bio(BTRFS_I(inode)->root->fs_info, 1809 ret = btrfs_wq_submit_bio(BTRFS_I(inode)->root->fs_info,
1810 inode, rw, bio, mirror_num, 1810 inode, rw, bio, mirror_num,
1811 bio_flags, bio_offset, 1811 bio_flags, bio_offset,
1812 __btrfs_submit_bio_start, 1812 __btrfs_submit_bio_start,
1813 __btrfs_submit_bio_done); 1813 __btrfs_submit_bio_done);
1814 goto out; 1814 goto out;
1815 } else if (!skip_sum) { 1815 } else if (!skip_sum) {
1816 ret = btrfs_csum_one_bio(root, inode, bio, 0, 0); 1816 ret = btrfs_csum_one_bio(root, inode, bio, 0, 0);
1817 if (ret) 1817 if (ret)
1818 goto out; 1818 goto out;
1819 } 1819 }
1820 1820
1821 mapit: 1821 mapit:
1822 ret = btrfs_map_bio(root, rw, bio, mirror_num, 0); 1822 ret = btrfs_map_bio(root, rw, bio, mirror_num, 0);
1823 1823
1824 out: 1824 out:
1825 if (ret < 0) 1825 if (ret < 0)
1826 bio_endio(bio, ret); 1826 bio_endio(bio, ret);
1827 return ret; 1827 return ret;
1828 } 1828 }
1829 1829
1830 /* 1830 /*
1831 * given a list of ordered sums record them in the inode. This happens 1831 * given a list of ordered sums record them in the inode. This happens
1832 * at IO completion time based on sums calculated at bio submission time. 1832 * at IO completion time based on sums calculated at bio submission time.
1833 */ 1833 */
1834 static noinline int add_pending_csums(struct btrfs_trans_handle *trans, 1834 static noinline int add_pending_csums(struct btrfs_trans_handle *trans,
1835 struct inode *inode, u64 file_offset, 1835 struct inode *inode, u64 file_offset,
1836 struct list_head *list) 1836 struct list_head *list)
1837 { 1837 {
1838 struct btrfs_ordered_sum *sum; 1838 struct btrfs_ordered_sum *sum;
1839 1839
1840 list_for_each_entry(sum, list, list) { 1840 list_for_each_entry(sum, list, list) {
1841 trans->adding_csums = 1; 1841 trans->adding_csums = 1;
1842 btrfs_csum_file_blocks(trans, 1842 btrfs_csum_file_blocks(trans,
1843 BTRFS_I(inode)->root->fs_info->csum_root, sum); 1843 BTRFS_I(inode)->root->fs_info->csum_root, sum);
1844 trans->adding_csums = 0; 1844 trans->adding_csums = 0;
1845 } 1845 }
1846 return 0; 1846 return 0;
1847 } 1847 }
1848 1848
1849 int btrfs_set_extent_delalloc(struct inode *inode, u64 start, u64 end, 1849 int btrfs_set_extent_delalloc(struct inode *inode, u64 start, u64 end,
1850 struct extent_state **cached_state) 1850 struct extent_state **cached_state)
1851 { 1851 {
1852 WARN_ON((end & (PAGE_CACHE_SIZE - 1)) == 0); 1852 WARN_ON((end & (PAGE_CACHE_SIZE - 1)) == 0);
1853 return set_extent_delalloc(&BTRFS_I(inode)->io_tree, start, end, 1853 return set_extent_delalloc(&BTRFS_I(inode)->io_tree, start, end,
1854 cached_state, GFP_NOFS); 1854 cached_state, GFP_NOFS);
1855 } 1855 }
1856 1856
1857 /* see btrfs_writepage_start_hook for details on why this is required */ 1857 /* see btrfs_writepage_start_hook for details on why this is required */
1858 struct btrfs_writepage_fixup { 1858 struct btrfs_writepage_fixup {
1859 struct page *page; 1859 struct page *page;
1860 struct btrfs_work work; 1860 struct btrfs_work work;
1861 }; 1861 };
1862 1862
1863 static void btrfs_writepage_fixup_worker(struct btrfs_work *work) 1863 static void btrfs_writepage_fixup_worker(struct btrfs_work *work)
1864 { 1864 {
1865 struct btrfs_writepage_fixup *fixup; 1865 struct btrfs_writepage_fixup *fixup;
1866 struct btrfs_ordered_extent *ordered; 1866 struct btrfs_ordered_extent *ordered;
1867 struct extent_state *cached_state = NULL; 1867 struct extent_state *cached_state = NULL;
1868 struct page *page; 1868 struct page *page;
1869 struct inode *inode; 1869 struct inode *inode;
1870 u64 page_start; 1870 u64 page_start;
1871 u64 page_end; 1871 u64 page_end;
1872 int ret; 1872 int ret;
1873 1873
1874 fixup = container_of(work, struct btrfs_writepage_fixup, work); 1874 fixup = container_of(work, struct btrfs_writepage_fixup, work);
1875 page = fixup->page; 1875 page = fixup->page;
1876 again: 1876 again:
1877 lock_page(page); 1877 lock_page(page);
1878 if (!page->mapping || !PageDirty(page) || !PageChecked(page)) { 1878 if (!page->mapping || !PageDirty(page) || !PageChecked(page)) {
1879 ClearPageChecked(page); 1879 ClearPageChecked(page);
1880 goto out_page; 1880 goto out_page;
1881 } 1881 }
1882 1882
1883 inode = page->mapping->host; 1883 inode = page->mapping->host;
1884 page_start = page_offset(page); 1884 page_start = page_offset(page);
1885 page_end = page_offset(page) + PAGE_CACHE_SIZE - 1; 1885 page_end = page_offset(page) + PAGE_CACHE_SIZE - 1;
1886 1886
1887 lock_extent_bits(&BTRFS_I(inode)->io_tree, page_start, page_end, 0, 1887 lock_extent_bits(&BTRFS_I(inode)->io_tree, page_start, page_end, 0,
1888 &cached_state); 1888 &cached_state);
1889 1889
1890 /* already ordered? We're done */ 1890 /* already ordered? We're done */
1891 if (PagePrivate2(page)) 1891 if (PagePrivate2(page))
1892 goto out; 1892 goto out;
1893 1893
1894 ordered = btrfs_lookup_ordered_extent(inode, page_start); 1894 ordered = btrfs_lookup_ordered_extent(inode, page_start);
1895 if (ordered) { 1895 if (ordered) {
1896 unlock_extent_cached(&BTRFS_I(inode)->io_tree, page_start, 1896 unlock_extent_cached(&BTRFS_I(inode)->io_tree, page_start,
1897 page_end, &cached_state, GFP_NOFS); 1897 page_end, &cached_state, GFP_NOFS);
1898 unlock_page(page); 1898 unlock_page(page);
1899 btrfs_start_ordered_extent(inode, ordered, 1); 1899 btrfs_start_ordered_extent(inode, ordered, 1);
1900 btrfs_put_ordered_extent(ordered); 1900 btrfs_put_ordered_extent(ordered);
1901 goto again; 1901 goto again;
1902 } 1902 }
1903 1903
1904 ret = btrfs_delalloc_reserve_space(inode, PAGE_CACHE_SIZE); 1904 ret = btrfs_delalloc_reserve_space(inode, PAGE_CACHE_SIZE);
1905 if (ret) { 1905 if (ret) {
1906 mapping_set_error(page->mapping, ret); 1906 mapping_set_error(page->mapping, ret);
1907 end_extent_writepage(page, ret, page_start, page_end); 1907 end_extent_writepage(page, ret, page_start, page_end);
1908 ClearPageChecked(page); 1908 ClearPageChecked(page);
1909 goto out; 1909 goto out;
1910 } 1910 }
1911 1911
1912 btrfs_set_extent_delalloc(inode, page_start, page_end, &cached_state); 1912 btrfs_set_extent_delalloc(inode, page_start, page_end, &cached_state);
1913 ClearPageChecked(page); 1913 ClearPageChecked(page);
1914 set_page_dirty(page); 1914 set_page_dirty(page);
1915 out: 1915 out:
1916 unlock_extent_cached(&BTRFS_I(inode)->io_tree, page_start, page_end, 1916 unlock_extent_cached(&BTRFS_I(inode)->io_tree, page_start, page_end,
1917 &cached_state, GFP_NOFS); 1917 &cached_state, GFP_NOFS);
1918 out_page: 1918 out_page:
1919 unlock_page(page); 1919 unlock_page(page);
1920 page_cache_release(page); 1920 page_cache_release(page);
1921 kfree(fixup); 1921 kfree(fixup);
1922 } 1922 }
1923 1923
1924 /* 1924 /*
1925 * There are a few paths in the higher layers of the kernel that directly 1925 * There are a few paths in the higher layers of the kernel that directly
1926 * set the page dirty bit without asking the filesystem if it is a 1926 * set the page dirty bit without asking the filesystem if it is a
1927 * good idea. This causes problems because we want to make sure COW 1927 * good idea. This causes problems because we want to make sure COW
1928 * properly happens and the data=ordered rules are followed. 1928 * properly happens and the data=ordered rules are followed.
1929 * 1929 *
1930 * In our case any range that doesn't have the ORDERED bit set 1930 * In our case any range that doesn't have the ORDERED bit set
1931 * hasn't been properly setup for IO. We kick off an async process 1931 * hasn't been properly setup for IO. We kick off an async process
1932 * to fix it up. The async helper will wait for ordered extents, set 1932 * to fix it up. The async helper will wait for ordered extents, set
1933 * the delalloc bit and make it safe to write the page. 1933 * the delalloc bit and make it safe to write the page.
1934 */ 1934 */
1935 static int btrfs_writepage_start_hook(struct page *page, u64 start, u64 end) 1935 static int btrfs_writepage_start_hook(struct page *page, u64 start, u64 end)
1936 { 1936 {
1937 struct inode *inode = page->mapping->host; 1937 struct inode *inode = page->mapping->host;
1938 struct btrfs_writepage_fixup *fixup; 1938 struct btrfs_writepage_fixup *fixup;
1939 struct btrfs_root *root = BTRFS_I(inode)->root; 1939 struct btrfs_root *root = BTRFS_I(inode)->root;
1940 1940
1941 /* this page is properly in the ordered list */ 1941 /* this page is properly in the ordered list */
1942 if (TestClearPagePrivate2(page)) 1942 if (TestClearPagePrivate2(page))
1943 return 0; 1943 return 0;
1944 1944
1945 if (PageChecked(page)) 1945 if (PageChecked(page))
1946 return -EAGAIN; 1946 return -EAGAIN;
1947 1947
1948 fixup = kzalloc(sizeof(*fixup), GFP_NOFS); 1948 fixup = kzalloc(sizeof(*fixup), GFP_NOFS);
1949 if (!fixup) 1949 if (!fixup)
1950 return -EAGAIN; 1950 return -EAGAIN;
1951 1951
1952 SetPageChecked(page); 1952 SetPageChecked(page);
1953 page_cache_get(page); 1953 page_cache_get(page);
1954 btrfs_init_work(&fixup->work, btrfs_fixup_helper, 1954 btrfs_init_work(&fixup->work, btrfs_fixup_helper,
1955 btrfs_writepage_fixup_worker, NULL, NULL); 1955 btrfs_writepage_fixup_worker, NULL, NULL);
1956 fixup->page = page; 1956 fixup->page = page;
1957 btrfs_queue_work(root->fs_info->fixup_workers, &fixup->work); 1957 btrfs_queue_work(root->fs_info->fixup_workers, &fixup->work);
1958 return -EBUSY; 1958 return -EBUSY;
1959 } 1959 }
1960 1960
1961 static int insert_reserved_file_extent(struct btrfs_trans_handle *trans, 1961 static int insert_reserved_file_extent(struct btrfs_trans_handle *trans,
1962 struct inode *inode, u64 file_pos, 1962 struct inode *inode, u64 file_pos,
1963 u64 disk_bytenr, u64 disk_num_bytes, 1963 u64 disk_bytenr, u64 disk_num_bytes,
1964 u64 num_bytes, u64 ram_bytes, 1964 u64 num_bytes, u64 ram_bytes,
1965 u8 compression, u8 encryption, 1965 u8 compression, u8 encryption,
1966 u16 other_encoding, int extent_type) 1966 u16 other_encoding, int extent_type)
1967 { 1967 {
1968 struct btrfs_root *root = BTRFS_I(inode)->root; 1968 struct btrfs_root *root = BTRFS_I(inode)->root;
1969 struct btrfs_file_extent_item *fi; 1969 struct btrfs_file_extent_item *fi;
1970 struct btrfs_path *path; 1970 struct btrfs_path *path;
1971 struct extent_buffer *leaf; 1971 struct extent_buffer *leaf;
1972 struct btrfs_key ins; 1972 struct btrfs_key ins;
1973 int extent_inserted = 0; 1973 int extent_inserted = 0;
1974 int ret; 1974 int ret;
1975 1975
1976 path = btrfs_alloc_path(); 1976 path = btrfs_alloc_path();
1977 if (!path) 1977 if (!path)
1978 return -ENOMEM; 1978 return -ENOMEM;
1979 1979
1980 /* 1980 /*
1981 * we may be replacing one extent in the tree with another. 1981 * we may be replacing one extent in the tree with another.
1982 * The new extent is pinned in the extent map, and we don't want 1982 * The new extent is pinned in the extent map, and we don't want
1983 * to drop it from the cache until it is completely in the btree. 1983 * to drop it from the cache until it is completely in the btree.
1984 * 1984 *
1985 * So, tell btrfs_drop_extents to leave this extent in the cache. 1985 * So, tell btrfs_drop_extents to leave this extent in the cache.
1986 * the caller is expected to unpin it and allow it to be merged 1986 * the caller is expected to unpin it and allow it to be merged
1987 * with the others. 1987 * with the others.
1988 */ 1988 */
1989 ret = __btrfs_drop_extents(trans, root, inode, path, file_pos, 1989 ret = __btrfs_drop_extents(trans, root, inode, path, file_pos,
1990 file_pos + num_bytes, NULL, 0, 1990 file_pos + num_bytes, NULL, 0,
1991 1, sizeof(*fi), &extent_inserted); 1991 1, sizeof(*fi), &extent_inserted);
1992 if (ret) 1992 if (ret)
1993 goto out; 1993 goto out;
1994 1994
1995 if (!extent_inserted) { 1995 if (!extent_inserted) {
1996 ins.objectid = btrfs_ino(inode); 1996 ins.objectid = btrfs_ino(inode);
1997 ins.offset = file_pos; 1997 ins.offset = file_pos;
1998 ins.type = BTRFS_EXTENT_DATA_KEY; 1998 ins.type = BTRFS_EXTENT_DATA_KEY;
1999 1999
2000 path->leave_spinning = 1; 2000 path->leave_spinning = 1;
2001 ret = btrfs_insert_empty_item(trans, root, path, &ins, 2001 ret = btrfs_insert_empty_item(trans, root, path, &ins,
2002 sizeof(*fi)); 2002 sizeof(*fi));
2003 if (ret) 2003 if (ret)
2004 goto out; 2004 goto out;
2005 } 2005 }
2006 leaf = path->nodes[0]; 2006 leaf = path->nodes[0];
2007 fi = btrfs_item_ptr(leaf, path->slots[0], 2007 fi = btrfs_item_ptr(leaf, path->slots[0],
2008 struct btrfs_file_extent_item); 2008 struct btrfs_file_extent_item);
2009 btrfs_set_file_extent_generation(leaf, fi, trans->transid); 2009 btrfs_set_file_extent_generation(leaf, fi, trans->transid);
2010 btrfs_set_file_extent_type(leaf, fi, extent_type); 2010 btrfs_set_file_extent_type(leaf, fi, extent_type);
2011 btrfs_set_file_extent_disk_bytenr(leaf, fi, disk_bytenr); 2011 btrfs_set_file_extent_disk_bytenr(leaf, fi, disk_bytenr);
2012 btrfs_set_file_extent_disk_num_bytes(leaf, fi, disk_num_bytes); 2012 btrfs_set_file_extent_disk_num_bytes(leaf, fi, disk_num_bytes);
2013 btrfs_set_file_extent_offset(leaf, fi, 0); 2013 btrfs_set_file_extent_offset(leaf, fi, 0);
2014 btrfs_set_file_extent_num_bytes(leaf, fi, num_bytes); 2014 btrfs_set_file_extent_num_bytes(leaf, fi, num_bytes);
2015 btrfs_set_file_extent_ram_bytes(leaf, fi, ram_bytes); 2015 btrfs_set_file_extent_ram_bytes(leaf, fi, ram_bytes);
2016 btrfs_set_file_extent_compression(leaf, fi, compression); 2016 btrfs_set_file_extent_compression(leaf, fi, compression);
2017 btrfs_set_file_extent_encryption(leaf, fi, encryption); 2017 btrfs_set_file_extent_encryption(leaf, fi, encryption);
2018 btrfs_set_file_extent_other_encoding(leaf, fi, other_encoding); 2018 btrfs_set_file_extent_other_encoding(leaf, fi, other_encoding);
2019 2019
2020 btrfs_mark_buffer_dirty(leaf); 2020 btrfs_mark_buffer_dirty(leaf);
2021 btrfs_release_path(path); 2021 btrfs_release_path(path);
2022 2022
2023 inode_add_bytes(inode, num_bytes); 2023 inode_add_bytes(inode, num_bytes);
2024 2024
2025 ins.objectid = disk_bytenr; 2025 ins.objectid = disk_bytenr;
2026 ins.offset = disk_num_bytes; 2026 ins.offset = disk_num_bytes;
2027 ins.type = BTRFS_EXTENT_ITEM_KEY; 2027 ins.type = BTRFS_EXTENT_ITEM_KEY;
2028 ret = btrfs_alloc_reserved_file_extent(trans, root, 2028 ret = btrfs_alloc_reserved_file_extent(trans, root,
2029 root->root_key.objectid, 2029 root->root_key.objectid,
2030 btrfs_ino(inode), file_pos, &ins); 2030 btrfs_ino(inode), file_pos, &ins);
2031 out: 2031 out:
2032 btrfs_free_path(path); 2032 btrfs_free_path(path);
2033 2033
2034 return ret; 2034 return ret;
2035 } 2035 }
2036 2036
2037 /* snapshot-aware defrag */ 2037 /* snapshot-aware defrag */
2038 struct sa_defrag_extent_backref { 2038 struct sa_defrag_extent_backref {
2039 struct rb_node node; 2039 struct rb_node node;
2040 struct old_sa_defrag_extent *old; 2040 struct old_sa_defrag_extent *old;
2041 u64 root_id; 2041 u64 root_id;
2042 u64 inum; 2042 u64 inum;
2043 u64 file_pos; 2043 u64 file_pos;
2044 u64 extent_offset; 2044 u64 extent_offset;
2045 u64 num_bytes; 2045 u64 num_bytes;
2046 u64 generation; 2046 u64 generation;
2047 }; 2047 };
2048 2048
2049 struct old_sa_defrag_extent { 2049 struct old_sa_defrag_extent {
2050 struct list_head list; 2050 struct list_head list;
2051 struct new_sa_defrag_extent *new; 2051 struct new_sa_defrag_extent *new;
2052 2052
2053 u64 extent_offset; 2053 u64 extent_offset;
2054 u64 bytenr; 2054 u64 bytenr;
2055 u64 offset; 2055 u64 offset;
2056 u64 len; 2056 u64 len;
2057 int count; 2057 int count;
2058 }; 2058 };
2059 2059
2060 struct new_sa_defrag_extent { 2060 struct new_sa_defrag_extent {
2061 struct rb_root root; 2061 struct rb_root root;
2062 struct list_head head; 2062 struct list_head head;
2063 struct btrfs_path *path; 2063 struct btrfs_path *path;
2064 struct inode *inode; 2064 struct inode *inode;
2065 u64 file_pos; 2065 u64 file_pos;
2066 u64 len; 2066 u64 len;
2067 u64 bytenr; 2067 u64 bytenr;
2068 u64 disk_len; 2068 u64 disk_len;
2069 u8 compress_type; 2069 u8 compress_type;
2070 }; 2070 };
2071 2071
2072 static int backref_comp(struct sa_defrag_extent_backref *b1, 2072 static int backref_comp(struct sa_defrag_extent_backref *b1,
2073 struct sa_defrag_extent_backref *b2) 2073 struct sa_defrag_extent_backref *b2)
2074 { 2074 {
2075 if (b1->root_id < b2->root_id) 2075 if (b1->root_id < b2->root_id)
2076 return -1; 2076 return -1;
2077 else if (b1->root_id > b2->root_id) 2077 else if (b1->root_id > b2->root_id)
2078 return 1; 2078 return 1;
2079 2079
2080 if (b1->inum < b2->inum) 2080 if (b1->inum < b2->inum)
2081 return -1; 2081 return -1;
2082 else if (b1->inum > b2->inum) 2082 else if (b1->inum > b2->inum)
2083 return 1; 2083 return 1;
2084 2084
2085 if (b1->file_pos < b2->file_pos) 2085 if (b1->file_pos < b2->file_pos)
2086 return -1; 2086 return -1;
2087 else if (b1->file_pos > b2->file_pos) 2087 else if (b1->file_pos > b2->file_pos)
2088 return 1; 2088 return 1;
2089 2089
2090 /* 2090 /*
2091 * [------------------------------] ===> (a range of space) 2091 * [------------------------------] ===> (a range of space)
2092 * |<--->| |<---->| =============> (fs/file tree A) 2092 * |<--->| |<---->| =============> (fs/file tree A)
2093 * |<---------------------------->| ===> (fs/file tree B) 2093 * |<---------------------------->| ===> (fs/file tree B)
2094 * 2094 *
2095 * A range of space can refer to two file extents in one tree while 2095 * A range of space can refer to two file extents in one tree while
2096 * refer to only one file extent in another tree. 2096 * refer to only one file extent in another tree.
2097 * 2097 *
2098 * So we may process a disk offset more than one time(two extents in A) 2098 * So we may process a disk offset more than one time(two extents in A)
2099 * and locate at the same extent(one extent in B), then insert two same 2099 * and locate at the same extent(one extent in B), then insert two same
2100 * backrefs(both refer to the extent in B). 2100 * backrefs(both refer to the extent in B).
2101 */ 2101 */
2102 return 0; 2102 return 0;
2103 } 2103 }
2104 2104
2105 static void backref_insert(struct rb_root *root, 2105 static void backref_insert(struct rb_root *root,
2106 struct sa_defrag_extent_backref *backref) 2106 struct sa_defrag_extent_backref *backref)
2107 { 2107 {
2108 struct rb_node **p = &root->rb_node; 2108 struct rb_node **p = &root->rb_node;
2109 struct rb_node *parent = NULL; 2109 struct rb_node *parent = NULL;
2110 struct sa_defrag_extent_backref *entry; 2110 struct sa_defrag_extent_backref *entry;
2111 int ret; 2111 int ret;
2112 2112
2113 while (*p) { 2113 while (*p) {
2114 parent = *p; 2114 parent = *p;
2115 entry = rb_entry(parent, struct sa_defrag_extent_backref, node); 2115 entry = rb_entry(parent, struct sa_defrag_extent_backref, node);
2116 2116
2117 ret = backref_comp(backref, entry); 2117 ret = backref_comp(backref, entry);
2118 if (ret < 0) 2118 if (ret < 0)
2119 p = &(*p)->rb_left; 2119 p = &(*p)->rb_left;
2120 else 2120 else
2121 p = &(*p)->rb_right; 2121 p = &(*p)->rb_right;
2122 } 2122 }
2123 2123
2124 rb_link_node(&backref->node, parent, p); 2124 rb_link_node(&backref->node, parent, p);
2125 rb_insert_color(&backref->node, root); 2125 rb_insert_color(&backref->node, root);
2126 } 2126 }
2127 2127
2128 /* 2128 /*
2129 * Note the backref might has changed, and in this case we just return 0. 2129 * Note the backref might has changed, and in this case we just return 0.
2130 */ 2130 */
2131 static noinline int record_one_backref(u64 inum, u64 offset, u64 root_id, 2131 static noinline int record_one_backref(u64 inum, u64 offset, u64 root_id,
2132 void *ctx) 2132 void *ctx)
2133 { 2133 {
2134 struct btrfs_file_extent_item *extent; 2134 struct btrfs_file_extent_item *extent;
2135 struct btrfs_fs_info *fs_info; 2135 struct btrfs_fs_info *fs_info;
2136 struct old_sa_defrag_extent *old = ctx; 2136 struct old_sa_defrag_extent *old = ctx;
2137 struct new_sa_defrag_extent *new = old->new; 2137 struct new_sa_defrag_extent *new = old->new;
2138 struct btrfs_path *path = new->path; 2138 struct btrfs_path *path = new->path;
2139 struct btrfs_key key; 2139 struct btrfs_key key;
2140 struct btrfs_root *root; 2140 struct btrfs_root *root;
2141 struct sa_defrag_extent_backref *backref; 2141 struct sa_defrag_extent_backref *backref;
2142 struct extent_buffer *leaf; 2142 struct extent_buffer *leaf;
2143 struct inode *inode = new->inode; 2143 struct inode *inode = new->inode;
2144 int slot; 2144 int slot;
2145 int ret; 2145 int ret;
2146 u64 extent_offset; 2146 u64 extent_offset;
2147 u64 num_bytes; 2147 u64 num_bytes;
2148 2148
2149 if (BTRFS_I(inode)->root->root_key.objectid == root_id && 2149 if (BTRFS_I(inode)->root->root_key.objectid == root_id &&
2150 inum == btrfs_ino(inode)) 2150 inum == btrfs_ino(inode))
2151 return 0; 2151 return 0;
2152 2152
2153 key.objectid = root_id; 2153 key.objectid = root_id;
2154 key.type = BTRFS_ROOT_ITEM_KEY; 2154 key.type = BTRFS_ROOT_ITEM_KEY;
2155 key.offset = (u64)-1; 2155 key.offset = (u64)-1;
2156 2156
2157 fs_info = BTRFS_I(inode)->root->fs_info; 2157 fs_info = BTRFS_I(inode)->root->fs_info;
2158 root = btrfs_read_fs_root_no_name(fs_info, &key); 2158 root = btrfs_read_fs_root_no_name(fs_info, &key);
2159 if (IS_ERR(root)) { 2159 if (IS_ERR(root)) {
2160 if (PTR_ERR(root) == -ENOENT) 2160 if (PTR_ERR(root) == -ENOENT)
2161 return 0; 2161 return 0;
2162 WARN_ON(1); 2162 WARN_ON(1);
2163 pr_debug("inum=%llu, offset=%llu, root_id=%llu\n", 2163 pr_debug("inum=%llu, offset=%llu, root_id=%llu\n",
2164 inum, offset, root_id); 2164 inum, offset, root_id);
2165 return PTR_ERR(root); 2165 return PTR_ERR(root);
2166 } 2166 }
2167 2167
2168 key.objectid = inum; 2168 key.objectid = inum;
2169 key.type = BTRFS_EXTENT_DATA_KEY; 2169 key.type = BTRFS_EXTENT_DATA_KEY;
2170 if (offset > (u64)-1 << 32) 2170 if (offset > (u64)-1 << 32)
2171 key.offset = 0; 2171 key.offset = 0;
2172 else 2172 else
2173 key.offset = offset; 2173 key.offset = offset;
2174 2174
2175 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); 2175 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
2176 if (WARN_ON(ret < 0)) 2176 if (WARN_ON(ret < 0))
2177 return ret; 2177 return ret;
2178 ret = 0; 2178 ret = 0;
2179 2179
2180 while (1) { 2180 while (1) {
2181 cond_resched(); 2181 cond_resched();
2182 2182
2183 leaf = path->nodes[0]; 2183 leaf = path->nodes[0];
2184 slot = path->slots[0]; 2184 slot = path->slots[0];
2185 2185
2186 if (slot >= btrfs_header_nritems(leaf)) { 2186 if (slot >= btrfs_header_nritems(leaf)) {
2187 ret = btrfs_next_leaf(root, path); 2187 ret = btrfs_next_leaf(root, path);
2188 if (ret < 0) { 2188 if (ret < 0) {
2189 goto out; 2189 goto out;
2190 } else if (ret > 0) { 2190 } else if (ret > 0) {
2191 ret = 0; 2191 ret = 0;
2192 goto out; 2192 goto out;
2193 } 2193 }
2194 continue; 2194 continue;
2195 } 2195 }
2196 2196
2197 path->slots[0]++; 2197 path->slots[0]++;
2198 2198
2199 btrfs_item_key_to_cpu(leaf, &key, slot); 2199 btrfs_item_key_to_cpu(leaf, &key, slot);
2200 2200
2201 if (key.objectid > inum) 2201 if (key.objectid > inum)
2202 goto out; 2202 goto out;
2203 2203
2204 if (key.objectid < inum || key.type != BTRFS_EXTENT_DATA_KEY) 2204 if (key.objectid < inum || key.type != BTRFS_EXTENT_DATA_KEY)
2205 continue; 2205 continue;
2206 2206
2207 extent = btrfs_item_ptr(leaf, slot, 2207 extent = btrfs_item_ptr(leaf, slot,
2208 struct btrfs_file_extent_item); 2208 struct btrfs_file_extent_item);
2209 2209
2210 if (btrfs_file_extent_disk_bytenr(leaf, extent) != old->bytenr) 2210 if (btrfs_file_extent_disk_bytenr(leaf, extent) != old->bytenr)
2211 continue; 2211 continue;
2212 2212
2213 /* 2213 /*
2214 * 'offset' refers to the exact key.offset, 2214 * 'offset' refers to the exact key.offset,
2215 * NOT the 'offset' field in btrfs_extent_data_ref, ie. 2215 * NOT the 'offset' field in btrfs_extent_data_ref, ie.
2216 * (key.offset - extent_offset). 2216 * (key.offset - extent_offset).
2217 */ 2217 */
2218 if (key.offset != offset) 2218 if (key.offset != offset)
2219 continue; 2219 continue;
2220 2220
2221 extent_offset = btrfs_file_extent_offset(leaf, extent); 2221 extent_offset = btrfs_file_extent_offset(leaf, extent);
2222 num_bytes = btrfs_file_extent_num_bytes(leaf, extent); 2222 num_bytes = btrfs_file_extent_num_bytes(leaf, extent);
2223 2223
2224 if (extent_offset >= old->extent_offset + old->offset + 2224 if (extent_offset >= old->extent_offset + old->offset +
2225 old->len || extent_offset + num_bytes <= 2225 old->len || extent_offset + num_bytes <=
2226 old->extent_offset + old->offset) 2226 old->extent_offset + old->offset)
2227 continue; 2227 continue;
2228 break; 2228 break;
2229 } 2229 }
2230 2230
2231 backref = kmalloc(sizeof(*backref), GFP_NOFS); 2231 backref = kmalloc(sizeof(*backref), GFP_NOFS);
2232 if (!backref) { 2232 if (!backref) {
2233 ret = -ENOENT; 2233 ret = -ENOENT;
2234 goto out; 2234 goto out;
2235 } 2235 }
2236 2236
2237 backref->root_id = root_id; 2237 backref->root_id = root_id;
2238 backref->inum = inum; 2238 backref->inum = inum;
2239 backref->file_pos = offset; 2239 backref->file_pos = offset;
2240 backref->num_bytes = num_bytes; 2240 backref->num_bytes = num_bytes;
2241 backref->extent_offset = extent_offset; 2241 backref->extent_offset = extent_offset;
2242 backref->generation = btrfs_file_extent_generation(leaf, extent); 2242 backref->generation = btrfs_file_extent_generation(leaf, extent);
2243 backref->old = old; 2243 backref->old = old;
2244 backref_insert(&new->root, backref); 2244 backref_insert(&new->root, backref);
2245 old->count++; 2245 old->count++;
2246 out: 2246 out:
2247 btrfs_release_path(path); 2247 btrfs_release_path(path);
2248 WARN_ON(ret); 2248 WARN_ON(ret);
2249 return ret; 2249 return ret;
2250 } 2250 }
2251 2251
2252 static noinline bool record_extent_backrefs(struct btrfs_path *path, 2252 static noinline bool record_extent_backrefs(struct btrfs_path *path,
2253 struct new_sa_defrag_extent *new) 2253 struct new_sa_defrag_extent *new)
2254 { 2254 {
2255 struct btrfs_fs_info *fs_info = BTRFS_I(new->inode)->root->fs_info; 2255 struct btrfs_fs_info *fs_info = BTRFS_I(new->inode)->root->fs_info;
2256 struct old_sa_defrag_extent *old, *tmp; 2256 struct old_sa_defrag_extent *old, *tmp;
2257 int ret; 2257 int ret;
2258 2258
2259 new->path = path; 2259 new->path = path;
2260 2260
2261 list_for_each_entry_safe(old, tmp, &new->head, list) { 2261 list_for_each_entry_safe(old, tmp, &new->head, list) {
2262 ret = iterate_inodes_from_logical(old->bytenr + 2262 ret = iterate_inodes_from_logical(old->bytenr +
2263 old->extent_offset, fs_info, 2263 old->extent_offset, fs_info,
2264 path, record_one_backref, 2264 path, record_one_backref,
2265 old); 2265 old);
2266 if (ret < 0 && ret != -ENOENT) 2266 if (ret < 0 && ret != -ENOENT)
2267 return false; 2267 return false;
2268 2268
2269 /* no backref to be processed for this extent */ 2269 /* no backref to be processed for this extent */
2270 if (!old->count) { 2270 if (!old->count) {
2271 list_del(&old->list); 2271 list_del(&old->list);
2272 kfree(old); 2272 kfree(old);
2273 } 2273 }
2274 } 2274 }
2275 2275
2276 if (list_empty(&new->head)) 2276 if (list_empty(&new->head))
2277 return false; 2277 return false;
2278 2278
2279 return true; 2279 return true;
2280 } 2280 }
2281 2281
2282 static int relink_is_mergable(struct extent_buffer *leaf, 2282 static int relink_is_mergable(struct extent_buffer *leaf,
2283 struct btrfs_file_extent_item *fi, 2283 struct btrfs_file_extent_item *fi,
2284 struct new_sa_defrag_extent *new) 2284 struct new_sa_defrag_extent *new)
2285 { 2285 {
2286 if (btrfs_file_extent_disk_bytenr(leaf, fi) != new->bytenr) 2286 if (btrfs_file_extent_disk_bytenr(leaf, fi) != new->bytenr)
2287 return 0; 2287 return 0;
2288 2288
2289 if (btrfs_file_extent_type(leaf, fi) != BTRFS_FILE_EXTENT_REG) 2289 if (btrfs_file_extent_type(leaf, fi) != BTRFS_FILE_EXTENT_REG)
2290 return 0; 2290 return 0;
2291 2291
2292 if (btrfs_file_extent_compression(leaf, fi) != new->compress_type) 2292 if (btrfs_file_extent_compression(leaf, fi) != new->compress_type)
2293 return 0; 2293 return 0;
2294 2294
2295 if (btrfs_file_extent_encryption(leaf, fi) || 2295 if (btrfs_file_extent_encryption(leaf, fi) ||
2296 btrfs_file_extent_other_encoding(leaf, fi)) 2296 btrfs_file_extent_other_encoding(leaf, fi))
2297 return 0; 2297 return 0;
2298 2298
2299 return 1; 2299 return 1;
2300 } 2300 }
2301 2301
2302 /* 2302 /*
2303 * Note the backref might has changed, and in this case we just return 0. 2303 * Note the backref might has changed, and in this case we just return 0.
2304 */ 2304 */
2305 static noinline int relink_extent_backref(struct btrfs_path *path, 2305 static noinline int relink_extent_backref(struct btrfs_path *path,
2306 struct sa_defrag_extent_backref *prev, 2306 struct sa_defrag_extent_backref *prev,
2307 struct sa_defrag_extent_backref *backref) 2307 struct sa_defrag_extent_backref *backref)
2308 { 2308 {
2309 struct btrfs_file_extent_item *extent; 2309 struct btrfs_file_extent_item *extent;
2310 struct btrfs_file_extent_item *item; 2310 struct btrfs_file_extent_item *item;
2311 struct btrfs_ordered_extent *ordered; 2311 struct btrfs_ordered_extent *ordered;
2312 struct btrfs_trans_handle *trans; 2312 struct btrfs_trans_handle *trans;
2313 struct btrfs_fs_info *fs_info; 2313 struct btrfs_fs_info *fs_info;
2314 struct btrfs_root *root; 2314 struct btrfs_root *root;
2315 struct btrfs_key key; 2315 struct btrfs_key key;
2316 struct extent_buffer *leaf; 2316 struct extent_buffer *leaf;
2317 struct old_sa_defrag_extent *old = backref->old; 2317 struct old_sa_defrag_extent *old = backref->old;
2318 struct new_sa_defrag_extent *new = old->new; 2318 struct new_sa_defrag_extent *new = old->new;
2319 struct inode *src_inode = new->inode; 2319 struct inode *src_inode = new->inode;
2320 struct inode *inode; 2320 struct inode *inode;
2321 struct extent_state *cached = NULL; 2321 struct extent_state *cached = NULL;
2322 int ret = 0; 2322 int ret = 0;
2323 u64 start; 2323 u64 start;
2324 u64 len; 2324 u64 len;
2325 u64 lock_start; 2325 u64 lock_start;
2326 u64 lock_end; 2326 u64 lock_end;
2327 bool merge = false; 2327 bool merge = false;
2328 int index; 2328 int index;
2329 2329
2330 if (prev && prev->root_id == backref->root_id && 2330 if (prev && prev->root_id == backref->root_id &&
2331 prev->inum == backref->inum && 2331 prev->inum == backref->inum &&
2332 prev->file_pos + prev->num_bytes == backref->file_pos) 2332 prev->file_pos + prev->num_bytes == backref->file_pos)
2333 merge = true; 2333 merge = true;
2334 2334
2335 /* step 1: get root */ 2335 /* step 1: get root */
2336 key.objectid = backref->root_id; 2336 key.objectid = backref->root_id;
2337 key.type = BTRFS_ROOT_ITEM_KEY; 2337 key.type = BTRFS_ROOT_ITEM_KEY;
2338 key.offset = (u64)-1; 2338 key.offset = (u64)-1;
2339 2339
2340 fs_info = BTRFS_I(src_inode)->root->fs_info; 2340 fs_info = BTRFS_I(src_inode)->root->fs_info;
2341 index = srcu_read_lock(&fs_info->subvol_srcu); 2341 index = srcu_read_lock(&fs_info->subvol_srcu);
2342 2342
2343 root = btrfs_read_fs_root_no_name(fs_info, &key); 2343 root = btrfs_read_fs_root_no_name(fs_info, &key);
2344 if (IS_ERR(root)) { 2344 if (IS_ERR(root)) {
2345 srcu_read_unlock(&fs_info->subvol_srcu, index); 2345 srcu_read_unlock(&fs_info->subvol_srcu, index);
2346 if (PTR_ERR(root) == -ENOENT) 2346 if (PTR_ERR(root) == -ENOENT)
2347 return 0; 2347 return 0;
2348 return PTR_ERR(root); 2348 return PTR_ERR(root);
2349 } 2349 }
2350 2350
2351 if (btrfs_root_readonly(root)) { 2351 if (btrfs_root_readonly(root)) {
2352 srcu_read_unlock(&fs_info->subvol_srcu, index); 2352 srcu_read_unlock(&fs_info->subvol_srcu, index);
2353 return 0; 2353 return 0;
2354 } 2354 }
2355 2355
2356 /* step 2: get inode */ 2356 /* step 2: get inode */
2357 key.objectid = backref->inum; 2357 key.objectid = backref->inum;
2358 key.type = BTRFS_INODE_ITEM_KEY; 2358 key.type = BTRFS_INODE_ITEM_KEY;
2359 key.offset = 0; 2359 key.offset = 0;
2360 2360
2361 inode = btrfs_iget(fs_info->sb, &key, root, NULL); 2361 inode = btrfs_iget(fs_info->sb, &key, root, NULL);
2362 if (IS_ERR(inode)) { 2362 if (IS_ERR(inode)) {
2363 srcu_read_unlock(&fs_info->subvol_srcu, index); 2363 srcu_read_unlock(&fs_info->subvol_srcu, index);
2364 return 0; 2364 return 0;
2365 } 2365 }
2366 2366
2367 srcu_read_unlock(&fs_info->subvol_srcu, index); 2367 srcu_read_unlock(&fs_info->subvol_srcu, index);
2368 2368
2369 /* step 3: relink backref */ 2369 /* step 3: relink backref */
2370 lock_start = backref->file_pos; 2370 lock_start = backref->file_pos;
2371 lock_end = backref->file_pos + backref->num_bytes - 1; 2371 lock_end = backref->file_pos + backref->num_bytes - 1;
2372 lock_extent_bits(&BTRFS_I(inode)->io_tree, lock_start, lock_end, 2372 lock_extent_bits(&BTRFS_I(inode)->io_tree, lock_start, lock_end,
2373 0, &cached); 2373 0, &cached);
2374 2374
2375 ordered = btrfs_lookup_first_ordered_extent(inode, lock_end); 2375 ordered = btrfs_lookup_first_ordered_extent(inode, lock_end);
2376 if (ordered) { 2376 if (ordered) {
2377 btrfs_put_ordered_extent(ordered); 2377 btrfs_put_ordered_extent(ordered);
2378 goto out_unlock; 2378 goto out_unlock;
2379 } 2379 }
2380 2380
2381 trans = btrfs_join_transaction(root); 2381 trans = btrfs_join_transaction(root);
2382 if (IS_ERR(trans)) { 2382 if (IS_ERR(trans)) {
2383 ret = PTR_ERR(trans); 2383 ret = PTR_ERR(trans);
2384 goto out_unlock; 2384 goto out_unlock;
2385 } 2385 }
2386 2386
2387 key.objectid = backref->inum; 2387 key.objectid = backref->inum;
2388 key.type = BTRFS_EXTENT_DATA_KEY; 2388 key.type = BTRFS_EXTENT_DATA_KEY;
2389 key.offset = backref->file_pos; 2389 key.offset = backref->file_pos;
2390 2390
2391 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); 2391 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
2392 if (ret < 0) { 2392 if (ret < 0) {
2393 goto out_free_path; 2393 goto out_free_path;
2394 } else if (ret > 0) { 2394 } else if (ret > 0) {
2395 ret = 0; 2395 ret = 0;
2396 goto out_free_path; 2396 goto out_free_path;
2397 } 2397 }
2398 2398
2399 extent = btrfs_item_ptr(path->nodes[0], path->slots[0], 2399 extent = btrfs_item_ptr(path->nodes[0], path->slots[0],
2400 struct btrfs_file_extent_item); 2400 struct btrfs_file_extent_item);
2401 2401
2402 if (btrfs_file_extent_generation(path->nodes[0], extent) != 2402 if (btrfs_file_extent_generation(path->nodes[0], extent) !=
2403 backref->generation) 2403 backref->generation)
2404 goto out_free_path; 2404 goto out_free_path;
2405 2405
2406 btrfs_release_path(path); 2406 btrfs_release_path(path);
2407 2407
2408 start = backref->file_pos; 2408 start = backref->file_pos;
2409 if (backref->extent_offset < old->extent_offset + old->offset) 2409 if (backref->extent_offset < old->extent_offset + old->offset)
2410 start += old->extent_offset + old->offset - 2410 start += old->extent_offset + old->offset -
2411 backref->extent_offset; 2411 backref->extent_offset;
2412 2412
2413 len = min(backref->extent_offset + backref->num_bytes, 2413 len = min(backref->extent_offset + backref->num_bytes,
2414 old->extent_offset + old->offset + old->len); 2414 old->extent_offset + old->offset + old->len);
2415 len -= max(backref->extent_offset, old->extent_offset + old->offset); 2415 len -= max(backref->extent_offset, old->extent_offset + old->offset);
2416 2416
2417 ret = btrfs_drop_extents(trans, root, inode, start, 2417 ret = btrfs_drop_extents(trans, root, inode, start,
2418 start + len, 1); 2418 start + len, 1);
2419 if (ret) 2419 if (ret)
2420 goto out_free_path; 2420 goto out_free_path;
2421 again: 2421 again:
2422 key.objectid = btrfs_ino(inode); 2422 key.objectid = btrfs_ino(inode);
2423 key.type = BTRFS_EXTENT_DATA_KEY; 2423 key.type = BTRFS_EXTENT_DATA_KEY;
2424 key.offset = start; 2424 key.offset = start;
2425 2425
2426 path->leave_spinning = 1; 2426 path->leave_spinning = 1;
2427 if (merge) { 2427 if (merge) {
2428 struct btrfs_file_extent_item *fi; 2428 struct btrfs_file_extent_item *fi;
2429 u64 extent_len; 2429 u64 extent_len;
2430 struct btrfs_key found_key; 2430 struct btrfs_key found_key;
2431 2431
2432 ret = btrfs_search_slot(trans, root, &key, path, 0, 1); 2432 ret = btrfs_search_slot(trans, root, &key, path, 0, 1);
2433 if (ret < 0) 2433 if (ret < 0)
2434 goto out_free_path; 2434 goto out_free_path;
2435 2435
2436 path->slots[0]--; 2436 path->slots[0]--;
2437 leaf = path->nodes[0]; 2437 leaf = path->nodes[0];
2438 btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]); 2438 btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]);
2439 2439
2440 fi = btrfs_item_ptr(leaf, path->slots[0], 2440 fi = btrfs_item_ptr(leaf, path->slots[0],
2441 struct btrfs_file_extent_item); 2441 struct btrfs_file_extent_item);
2442 extent_len = btrfs_file_extent_num_bytes(leaf, fi); 2442 extent_len = btrfs_file_extent_num_bytes(leaf, fi);
2443 2443
2444 if (extent_len + found_key.offset == start && 2444 if (extent_len + found_key.offset == start &&
2445 relink_is_mergable(leaf, fi, new)) { 2445 relink_is_mergable(leaf, fi, new)) {
2446 btrfs_set_file_extent_num_bytes(leaf, fi, 2446 btrfs_set_file_extent_num_bytes(leaf, fi,
2447 extent_len + len); 2447 extent_len + len);
2448 btrfs_mark_buffer_dirty(leaf); 2448 btrfs_mark_buffer_dirty(leaf);
2449 inode_add_bytes(inode, len); 2449 inode_add_bytes(inode, len);
2450 2450
2451 ret = 1; 2451 ret = 1;
2452 goto out_free_path; 2452 goto out_free_path;
2453 } else { 2453 } else {
2454 merge = false; 2454 merge = false;
2455 btrfs_release_path(path); 2455 btrfs_release_path(path);
2456 goto again; 2456 goto again;
2457 } 2457 }
2458 } 2458 }
2459 2459
2460 ret = btrfs_insert_empty_item(trans, root, path, &key, 2460 ret = btrfs_insert_empty_item(trans, root, path, &key,
2461 sizeof(*extent)); 2461 sizeof(*extent));
2462 if (ret) { 2462 if (ret) {
2463 btrfs_abort_transaction(trans, root, ret); 2463 btrfs_abort_transaction(trans, root, ret);
2464 goto out_free_path; 2464 goto out_free_path;
2465 } 2465 }
2466 2466
2467 leaf = path->nodes[0]; 2467 leaf = path->nodes[0];
2468 item = btrfs_item_ptr(leaf, path->slots[0], 2468 item = btrfs_item_ptr(leaf, path->slots[0],
2469 struct btrfs_file_extent_item); 2469 struct btrfs_file_extent_item);
2470 btrfs_set_file_extent_disk_bytenr(leaf, item, new->bytenr); 2470 btrfs_set_file_extent_disk_bytenr(leaf, item, new->bytenr);
2471 btrfs_set_file_extent_disk_num_bytes(leaf, item, new->disk_len); 2471 btrfs_set_file_extent_disk_num_bytes(leaf, item, new->disk_len);
2472 btrfs_set_file_extent_offset(leaf, item, start - new->file_pos); 2472 btrfs_set_file_extent_offset(leaf, item, start - new->file_pos);
2473 btrfs_set_file_extent_num_bytes(leaf, item, len); 2473 btrfs_set_file_extent_num_bytes(leaf, item, len);
2474 btrfs_set_file_extent_ram_bytes(leaf, item, new->len); 2474 btrfs_set_file_extent_ram_bytes(leaf, item, new->len);
2475 btrfs_set_file_extent_generation(leaf, item, trans->transid); 2475 btrfs_set_file_extent_generation(leaf, item, trans->transid);
2476 btrfs_set_file_extent_type(leaf, item, BTRFS_FILE_EXTENT_REG); 2476 btrfs_set_file_extent_type(leaf, item, BTRFS_FILE_EXTENT_REG);
2477 btrfs_set_file_extent_compression(leaf, item, new->compress_type); 2477 btrfs_set_file_extent_compression(leaf, item, new->compress_type);
2478 btrfs_set_file_extent_encryption(leaf, item, 0); 2478 btrfs_set_file_extent_encryption(leaf, item, 0);
2479 btrfs_set_file_extent_other_encoding(leaf, item, 0); 2479 btrfs_set_file_extent_other_encoding(leaf, item, 0);
2480 2480
2481 btrfs_mark_buffer_dirty(leaf); 2481 btrfs_mark_buffer_dirty(leaf);
2482 inode_add_bytes(inode, len); 2482 inode_add_bytes(inode, len);
2483 btrfs_release_path(path); 2483 btrfs_release_path(path);
2484 2484
2485 ret = btrfs_inc_extent_ref(trans, root, new->bytenr, 2485 ret = btrfs_inc_extent_ref(trans, root, new->bytenr,
2486 new->disk_len, 0, 2486 new->disk_len, 0,
2487 backref->root_id, backref->inum, 2487 backref->root_id, backref->inum,
2488 new->file_pos, 0); /* start - extent_offset */ 2488 new->file_pos, 0); /* start - extent_offset */
2489 if (ret) { 2489 if (ret) {
2490 btrfs_abort_transaction(trans, root, ret); 2490 btrfs_abort_transaction(trans, root, ret);
2491 goto out_free_path; 2491 goto out_free_path;
2492 } 2492 }
2493 2493
2494 ret = 1; 2494 ret = 1;
2495 out_free_path: 2495 out_free_path:
2496 btrfs_release_path(path); 2496 btrfs_release_path(path);
2497 path->leave_spinning = 0; 2497 path->leave_spinning = 0;
2498 btrfs_end_transaction(trans, root); 2498 btrfs_end_transaction(trans, root);
2499 out_unlock: 2499 out_unlock:
2500 unlock_extent_cached(&BTRFS_I(inode)->io_tree, lock_start, lock_end, 2500 unlock_extent_cached(&BTRFS_I(inode)->io_tree, lock_start, lock_end,
2501 &cached, GFP_NOFS); 2501 &cached, GFP_NOFS);
2502 iput(inode); 2502 iput(inode);
2503 return ret; 2503 return ret;
2504 } 2504 }
2505 2505
2506 static void free_sa_defrag_extent(struct new_sa_defrag_extent *new) 2506 static void free_sa_defrag_extent(struct new_sa_defrag_extent *new)
2507 { 2507 {
2508 struct old_sa_defrag_extent *old, *tmp; 2508 struct old_sa_defrag_extent *old, *tmp;
2509 2509
2510 if (!new) 2510 if (!new)
2511 return; 2511 return;
2512 2512
2513 list_for_each_entry_safe(old, tmp, &new->head, list) { 2513 list_for_each_entry_safe(old, tmp, &new->head, list) {
2514 list_del(&old->list); 2514 list_del(&old->list);
2515 kfree(old); 2515 kfree(old);
2516 } 2516 }
2517 kfree(new); 2517 kfree(new);
2518 } 2518 }
2519 2519
2520 static void relink_file_extents(struct new_sa_defrag_extent *new) 2520 static void relink_file_extents(struct new_sa_defrag_extent *new)
2521 { 2521 {
2522 struct btrfs_path *path; 2522 struct btrfs_path *path;
2523 struct sa_defrag_extent_backref *backref; 2523 struct sa_defrag_extent_backref *backref;
2524 struct sa_defrag_extent_backref *prev = NULL; 2524 struct sa_defrag_extent_backref *prev = NULL;
2525 struct inode *inode; 2525 struct inode *inode;
2526 struct btrfs_root *root; 2526 struct btrfs_root *root;
2527 struct rb_node *node; 2527 struct rb_node *node;
2528 int ret; 2528 int ret;
2529 2529
2530 inode = new->inode; 2530 inode = new->inode;
2531 root = BTRFS_I(inode)->root; 2531 root = BTRFS_I(inode)->root;
2532 2532
2533 path = btrfs_alloc_path(); 2533 path = btrfs_alloc_path();
2534 if (!path) 2534 if (!path)
2535 return; 2535 return;
2536 2536
2537 if (!record_extent_backrefs(path, new)) { 2537 if (!record_extent_backrefs(path, new)) {
2538 btrfs_free_path(path); 2538 btrfs_free_path(path);
2539 goto out; 2539 goto out;
2540 } 2540 }
2541 btrfs_release_path(path); 2541 btrfs_release_path(path);
2542 2542
2543 while (1) { 2543 while (1) {
2544 node = rb_first(&new->root); 2544 node = rb_first(&new->root);
2545 if (!node) 2545 if (!node)
2546 break; 2546 break;
2547 rb_erase(node, &new->root); 2547 rb_erase(node, &new->root);
2548 2548
2549 backref = rb_entry(node, struct sa_defrag_extent_backref, node); 2549 backref = rb_entry(node, struct sa_defrag_extent_backref, node);
2550 2550
2551 ret = relink_extent_backref(path, prev, backref); 2551 ret = relink_extent_backref(path, prev, backref);
2552 WARN_ON(ret < 0); 2552 WARN_ON(ret < 0);
2553 2553
2554 kfree(prev); 2554 kfree(prev);
2555 2555
2556 if (ret == 1) 2556 if (ret == 1)
2557 prev = backref; 2557 prev = backref;
2558 else 2558 else
2559 prev = NULL; 2559 prev = NULL;
2560 cond_resched(); 2560 cond_resched();
2561 } 2561 }
2562 kfree(prev); 2562 kfree(prev);
2563 2563
2564 btrfs_free_path(path); 2564 btrfs_free_path(path);
2565 out: 2565 out:
2566 free_sa_defrag_extent(new); 2566 free_sa_defrag_extent(new);
2567 2567
2568 atomic_dec(&root->fs_info->defrag_running); 2568 atomic_dec(&root->fs_info->defrag_running);
2569 wake_up(&root->fs_info->transaction_wait); 2569 wake_up(&root->fs_info->transaction_wait);
2570 } 2570 }
2571 2571
2572 static struct new_sa_defrag_extent * 2572 static struct new_sa_defrag_extent *
2573 record_old_file_extents(struct inode *inode, 2573 record_old_file_extents(struct inode *inode,
2574 struct btrfs_ordered_extent *ordered) 2574 struct btrfs_ordered_extent *ordered)
2575 { 2575 {
2576 struct btrfs_root *root = BTRFS_I(inode)->root; 2576 struct btrfs_root *root = BTRFS_I(inode)->root;
2577 struct btrfs_path *path; 2577 struct btrfs_path *path;
2578 struct btrfs_key key; 2578 struct btrfs_key key;
2579 struct old_sa_defrag_extent *old; 2579 struct old_sa_defrag_extent *old;
2580 struct new_sa_defrag_extent *new; 2580 struct new_sa_defrag_extent *new;
2581 int ret; 2581 int ret;
2582 2582
2583 new = kmalloc(sizeof(*new), GFP_NOFS); 2583 new = kmalloc(sizeof(*new), GFP_NOFS);
2584 if (!new) 2584 if (!new)
2585 return NULL; 2585 return NULL;
2586 2586
2587 new->inode = inode; 2587 new->inode = inode;
2588 new->file_pos = ordered->file_offset; 2588 new->file_pos = ordered->file_offset;
2589 new->len = ordered->len; 2589 new->len = ordered->len;
2590 new->bytenr = ordered->start; 2590 new->bytenr = ordered->start;
2591 new->disk_len = ordered->disk_len; 2591 new->disk_len = ordered->disk_len;
2592 new->compress_type = ordered->compress_type; 2592 new->compress_type = ordered->compress_type;
2593 new->root = RB_ROOT; 2593 new->root = RB_ROOT;
2594 INIT_LIST_HEAD(&new->head); 2594 INIT_LIST_HEAD(&new->head);
2595 2595
2596 path = btrfs_alloc_path(); 2596 path = btrfs_alloc_path();
2597 if (!path) 2597 if (!path)
2598 goto out_kfree; 2598 goto out_kfree;
2599 2599
2600 key.objectid = btrfs_ino(inode); 2600 key.objectid = btrfs_ino(inode);
2601 key.type = BTRFS_EXTENT_DATA_KEY; 2601 key.type = BTRFS_EXTENT_DATA_KEY;
2602 key.offset = new->file_pos; 2602 key.offset = new->file_pos;
2603 2603
2604 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); 2604 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
2605 if (ret < 0) 2605 if (ret < 0)
2606 goto out_free_path; 2606 goto out_free_path;
2607 if (ret > 0 && path->slots[0] > 0) 2607 if (ret > 0 && path->slots[0] > 0)
2608 path->slots[0]--; 2608 path->slots[0]--;
2609 2609
2610 /* find out all the old extents for the file range */ 2610 /* find out all the old extents for the file range */
2611 while (1) { 2611 while (1) {
2612 struct btrfs_file_extent_item *extent; 2612 struct btrfs_file_extent_item *extent;
2613 struct extent_buffer *l; 2613 struct extent_buffer *l;
2614 int slot; 2614 int slot;
2615 u64 num_bytes; 2615 u64 num_bytes;
2616 u64 offset; 2616 u64 offset;
2617 u64 end; 2617 u64 end;
2618 u64 disk_bytenr; 2618 u64 disk_bytenr;
2619 u64 extent_offset; 2619 u64 extent_offset;
2620 2620
2621 l = path->nodes[0]; 2621 l = path->nodes[0];
2622 slot = path->slots[0]; 2622 slot = path->slots[0];
2623 2623
2624 if (slot >= btrfs_header_nritems(l)) { 2624 if (slot >= btrfs_header_nritems(l)) {
2625 ret = btrfs_next_leaf(root, path); 2625 ret = btrfs_next_leaf(root, path);
2626 if (ret < 0) 2626 if (ret < 0)
2627 goto out_free_path; 2627 goto out_free_path;
2628 else if (ret > 0) 2628 else if (ret > 0)
2629 break; 2629 break;
2630 continue; 2630 continue;
2631 } 2631 }
2632 2632
2633 btrfs_item_key_to_cpu(l, &key, slot); 2633 btrfs_item_key_to_cpu(l, &key, slot);
2634 2634
2635 if (key.objectid != btrfs_ino(inode)) 2635 if (key.objectid != btrfs_ino(inode))
2636 break; 2636 break;
2637 if (key.type != BTRFS_EXTENT_DATA_KEY) 2637 if (key.type != BTRFS_EXTENT_DATA_KEY)
2638 break; 2638 break;
2639 if (key.offset >= new->file_pos + new->len) 2639 if (key.offset >= new->file_pos + new->len)
2640 break; 2640 break;
2641 2641
2642 extent = btrfs_item_ptr(l, slot, struct btrfs_file_extent_item); 2642 extent = btrfs_item_ptr(l, slot, struct btrfs_file_extent_item);
2643 2643
2644 num_bytes = btrfs_file_extent_num_bytes(l, extent); 2644 num_bytes = btrfs_file_extent_num_bytes(l, extent);
2645 if (key.offset + num_bytes < new->file_pos) 2645 if (key.offset + num_bytes < new->file_pos)
2646 goto next; 2646 goto next;
2647 2647
2648 disk_bytenr = btrfs_file_extent_disk_bytenr(l, extent); 2648 disk_bytenr = btrfs_file_extent_disk_bytenr(l, extent);
2649 if (!disk_bytenr) 2649 if (!disk_bytenr)
2650 goto next; 2650 goto next;
2651 2651
2652 extent_offset = btrfs_file_extent_offset(l, extent); 2652 extent_offset = btrfs_file_extent_offset(l, extent);
2653 2653
2654 old = kmalloc(sizeof(*old), GFP_NOFS); 2654 old = kmalloc(sizeof(*old), GFP_NOFS);
2655 if (!old) 2655 if (!old)
2656 goto out_free_path; 2656 goto out_free_path;
2657 2657
2658 offset = max(new->file_pos, key.offset); 2658 offset = max(new->file_pos, key.offset);
2659 end = min(new->file_pos + new->len, key.offset + num_bytes); 2659 end = min(new->file_pos + new->len, key.offset + num_bytes);
2660 2660
2661 old->bytenr = disk_bytenr; 2661 old->bytenr = disk_bytenr;
2662 old->extent_offset = extent_offset; 2662 old->extent_offset = extent_offset;
2663 old->offset = offset - key.offset; 2663 old->offset = offset - key.offset;
2664 old->len = end - offset; 2664 old->len = end - offset;
2665 old->new = new; 2665 old->new = new;
2666 old->count = 0; 2666 old->count = 0;
2667 list_add_tail(&old->list, &new->head); 2667 list_add_tail(&old->list, &new->head);
2668 next: 2668 next:
2669 path->slots[0]++; 2669 path->slots[0]++;
2670 cond_resched(); 2670 cond_resched();
2671 } 2671 }
2672 2672
2673 btrfs_free_path(path); 2673 btrfs_free_path(path);
2674 atomic_inc(&root->fs_info->defrag_running); 2674 atomic_inc(&root->fs_info->defrag_running);
2675 2675
2676 return new; 2676 return new;
2677 2677
2678 out_free_path: 2678 out_free_path:
2679 btrfs_free_path(path); 2679 btrfs_free_path(path);
2680 out_kfree: 2680 out_kfree:
2681 free_sa_defrag_extent(new); 2681 free_sa_defrag_extent(new);
2682 return NULL; 2682 return NULL;
2683 } 2683 }
2684 2684
2685 static void btrfs_release_delalloc_bytes(struct btrfs_root *root, 2685 static void btrfs_release_delalloc_bytes(struct btrfs_root *root,
2686 u64 start, u64 len) 2686 u64 start, u64 len)
2687 { 2687 {
2688 struct btrfs_block_group_cache *cache; 2688 struct btrfs_block_group_cache *cache;
2689 2689
2690 cache = btrfs_lookup_block_group(root->fs_info, start); 2690 cache = btrfs_lookup_block_group(root->fs_info, start);
2691 ASSERT(cache); 2691 ASSERT(cache);
2692 2692
2693 spin_lock(&cache->lock); 2693 spin_lock(&cache->lock);
2694 cache->delalloc_bytes -= len; 2694 cache->delalloc_bytes -= len;
2695 spin_unlock(&cache->lock); 2695 spin_unlock(&cache->lock);
2696 2696
2697 btrfs_put_block_group(cache); 2697 btrfs_put_block_group(cache);
2698 } 2698 }
2699 2699
2700 /* as ordered data IO finishes, this gets called so we can finish 2700 /* as ordered data IO finishes, this gets called so we can finish
2701 * an ordered extent if the range of bytes in the file it covers are 2701 * an ordered extent if the range of bytes in the file it covers are
2702 * fully written. 2702 * fully written.
2703 */ 2703 */
2704 static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) 2704 static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
2705 { 2705 {
2706 struct inode *inode = ordered_extent->inode; 2706 struct inode *inode = ordered_extent->inode;
2707 struct btrfs_root *root = BTRFS_I(inode)->root; 2707 struct btrfs_root *root = BTRFS_I(inode)->root;
2708 struct btrfs_trans_handle *trans = NULL; 2708 struct btrfs_trans_handle *trans = NULL;
2709 struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; 2709 struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
2710 struct extent_state *cached_state = NULL; 2710 struct extent_state *cached_state = NULL;
2711 struct new_sa_defrag_extent *new = NULL; 2711 struct new_sa_defrag_extent *new = NULL;
2712 int compress_type = 0; 2712 int compress_type = 0;
2713 int ret = 0; 2713 int ret = 0;
2714 u64 logical_len = ordered_extent->len; 2714 u64 logical_len = ordered_extent->len;
2715 bool nolock; 2715 bool nolock;
2716 bool truncated = false; 2716 bool truncated = false;
2717 2717
2718 nolock = btrfs_is_free_space_inode(inode); 2718 nolock = btrfs_is_free_space_inode(inode);
2719 2719
2720 if (test_bit(BTRFS_ORDERED_IOERR, &ordered_extent->flags)) { 2720 if (test_bit(BTRFS_ORDERED_IOERR, &ordered_extent->flags)) {
2721 ret = -EIO; 2721 ret = -EIO;
2722 goto out; 2722 goto out;
2723 } 2723 }
2724 2724
2725 btrfs_free_io_failure_record(inode, ordered_extent->file_offset, 2725 btrfs_free_io_failure_record(inode, ordered_extent->file_offset,
2726 ordered_extent->file_offset + 2726 ordered_extent->file_offset +
2727 ordered_extent->len - 1); 2727 ordered_extent->len - 1);
2728 2728
2729 if (test_bit(BTRFS_ORDERED_TRUNCATED, &ordered_extent->flags)) { 2729 if (test_bit(BTRFS_ORDERED_TRUNCATED, &ordered_extent->flags)) {
2730 truncated = true; 2730 truncated = true;
2731 logical_len = ordered_extent->truncated_len; 2731 logical_len = ordered_extent->truncated_len;
2732 /* Truncated the entire extent, don't bother adding */ 2732 /* Truncated the entire extent, don't bother adding */
2733 if (!logical_len) 2733 if (!logical_len)
2734 goto out; 2734 goto out;
2735 } 2735 }
2736 2736
2737 if (test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags)) { 2737 if (test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags)) {
2738 BUG_ON(!list_empty(&ordered_extent->list)); /* Logic error */ 2738 BUG_ON(!list_empty(&ordered_extent->list)); /* Logic error */
2739 btrfs_ordered_update_i_size(inode, 0, ordered_extent); 2739 btrfs_ordered_update_i_size(inode, 0, ordered_extent);
2740 if (nolock) 2740 if (nolock)
2741 trans = btrfs_join_transaction_nolock(root); 2741 trans = btrfs_join_transaction_nolock(root);
2742 else 2742 else
2743 trans = btrfs_join_transaction(root); 2743 trans = btrfs_join_transaction(root);
2744 if (IS_ERR(trans)) { 2744 if (IS_ERR(trans)) {
2745 ret = PTR_ERR(trans); 2745 ret = PTR_ERR(trans);
2746 trans = NULL; 2746 trans = NULL;
2747 goto out; 2747 goto out;
2748 } 2748 }
2749 trans->block_rsv = &root->fs_info->delalloc_block_rsv; 2749 trans->block_rsv = &root->fs_info->delalloc_block_rsv;
2750 ret = btrfs_update_inode_fallback(trans, root, inode); 2750 ret = btrfs_update_inode_fallback(trans, root, inode);
2751 if (ret) /* -ENOMEM or corruption */ 2751 if (ret) /* -ENOMEM or corruption */
2752 btrfs_abort_transaction(trans, root, ret); 2752 btrfs_abort_transaction(trans, root, ret);
2753 goto out; 2753 goto out;
2754 } 2754 }
2755 2755
2756 lock_extent_bits(io_tree, ordered_extent->file_offset, 2756 lock_extent_bits(io_tree, ordered_extent->file_offset,
2757 ordered_extent->file_offset + ordered_extent->len - 1, 2757 ordered_extent->file_offset + ordered_extent->len - 1,
2758 0, &cached_state); 2758 0, &cached_state);
2759 2759
2760 ret = test_range_bit(io_tree, ordered_extent->file_offset, 2760 ret = test_range_bit(io_tree, ordered_extent->file_offset,
2761 ordered_extent->file_offset + ordered_extent->len - 1, 2761 ordered_extent->file_offset + ordered_extent->len - 1,
2762 EXTENT_DEFRAG, 1, cached_state); 2762 EXTENT_DEFRAG, 1, cached_state);
2763 if (ret) { 2763 if (ret) {
2764 u64 last_snapshot = btrfs_root_last_snapshot(&root->root_item); 2764 u64 last_snapshot = btrfs_root_last_snapshot(&root->root_item);
2765 if (0 && last_snapshot >= BTRFS_I(inode)->generation) 2765 if (0 && last_snapshot >= BTRFS_I(inode)->generation)
2766 /* the inode is shared */ 2766 /* the inode is shared */
2767 new = record_old_file_extents(inode, ordered_extent); 2767 new = record_old_file_extents(inode, ordered_extent);
2768 2768
2769 clear_extent_bit(io_tree, ordered_extent->file_offset, 2769 clear_extent_bit(io_tree, ordered_extent->file_offset,
2770 ordered_extent->file_offset + ordered_extent->len - 1, 2770 ordered_extent->file_offset + ordered_extent->len - 1,
2771 EXTENT_DEFRAG, 0, 0, &cached_state, GFP_NOFS); 2771 EXTENT_DEFRAG, 0, 0, &cached_state, GFP_NOFS);
2772 } 2772 }
2773 2773
2774 if (nolock) 2774 if (nolock)
2775 trans = btrfs_join_transaction_nolock(root); 2775 trans = btrfs_join_transaction_nolock(root);
2776 else 2776 else
2777 trans = btrfs_join_transaction(root); 2777 trans = btrfs_join_transaction(root);
2778 if (IS_ERR(trans)) { 2778 if (IS_ERR(trans)) {
2779 ret = PTR_ERR(trans); 2779 ret = PTR_ERR(trans);
2780 trans = NULL; 2780 trans = NULL;
2781 goto out_unlock; 2781 goto out_unlock;
2782 } 2782 }
2783 2783
2784 trans->block_rsv = &root->fs_info->delalloc_block_rsv; 2784 trans->block_rsv = &root->fs_info->delalloc_block_rsv;
2785 2785
2786 if (test_bit(BTRFS_ORDERED_COMPRESSED, &ordered_extent->flags)) 2786 if (test_bit(BTRFS_ORDERED_COMPRESSED, &ordered_extent->flags))
2787 compress_type = ordered_extent->compress_type; 2787 compress_type = ordered_extent->compress_type;
2788 if (test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags)) { 2788 if (test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags)) {
2789 BUG_ON(compress_type); 2789 BUG_ON(compress_type);
2790 ret = btrfs_mark_extent_written(trans, inode, 2790 ret = btrfs_mark_extent_written(trans, inode,
2791 ordered_extent->file_offset, 2791 ordered_extent->file_offset,
2792 ordered_extent->file_offset + 2792 ordered_extent->file_offset +
2793 logical_len); 2793 logical_len);
2794 } else { 2794 } else {
2795 BUG_ON(root == root->fs_info->tree_root); 2795 BUG_ON(root == root->fs_info->tree_root);
2796 ret = insert_reserved_file_extent(trans, inode, 2796 ret = insert_reserved_file_extent(trans, inode,
2797 ordered_extent->file_offset, 2797 ordered_extent->file_offset,
2798 ordered_extent->start, 2798 ordered_extent->start,
2799 ordered_extent->disk_len, 2799 ordered_extent->disk_len,
2800 logical_len, logical_len, 2800 logical_len, logical_len,
2801 compress_type, 0, 0, 2801 compress_type, 0, 0,
2802 BTRFS_FILE_EXTENT_REG); 2802 BTRFS_FILE_EXTENT_REG);
2803 if (!ret) 2803 if (!ret)
2804 btrfs_release_delalloc_bytes(root, 2804 btrfs_release_delalloc_bytes(root,
2805 ordered_extent->start, 2805 ordered_extent->start,
2806 ordered_extent->disk_len); 2806 ordered_extent->disk_len);
2807 } 2807 }
2808 unpin_extent_cache(&BTRFS_I(inode)->extent_tree, 2808 unpin_extent_cache(&BTRFS_I(inode)->extent_tree,
2809 ordered_extent->file_offset, ordered_extent->len, 2809 ordered_extent->file_offset, ordered_extent->len,
2810 trans->transid); 2810 trans->transid);
2811 if (ret < 0) { 2811 if (ret < 0) {
2812 btrfs_abort_transaction(trans, root, ret); 2812 btrfs_abort_transaction(trans, root, ret);
2813 goto out_unlock; 2813 goto out_unlock;
2814 } 2814 }
2815 2815
2816 add_pending_csums(trans, inode, ordered_extent->file_offset, 2816 add_pending_csums(trans, inode, ordered_extent->file_offset,
2817 &ordered_extent->list); 2817 &ordered_extent->list);
2818 2818
2819 btrfs_ordered_update_i_size(inode, 0, ordered_extent); 2819 btrfs_ordered_update_i_size(inode, 0, ordered_extent);
2820 ret = btrfs_update_inode_fallback(trans, root, inode); 2820 ret = btrfs_update_inode_fallback(trans, root, inode);
2821 if (ret) { /* -ENOMEM or corruption */ 2821 if (ret) { /* -ENOMEM or corruption */
2822 btrfs_abort_transaction(trans, root, ret); 2822 btrfs_abort_transaction(trans, root, ret);
2823 goto out_unlock; 2823 goto out_unlock;
2824 } 2824 }
2825 ret = 0; 2825 ret = 0;
2826 out_unlock: 2826 out_unlock:
2827 unlock_extent_cached(io_tree, ordered_extent->file_offset, 2827 unlock_extent_cached(io_tree, ordered_extent->file_offset,
2828 ordered_extent->file_offset + 2828 ordered_extent->file_offset +
2829 ordered_extent->len - 1, &cached_state, GFP_NOFS); 2829 ordered_extent->len - 1, &cached_state, GFP_NOFS);
2830 out: 2830 out:
2831 if (root != root->fs_info->tree_root) 2831 if (root != root->fs_info->tree_root)
2832 btrfs_delalloc_release_metadata(inode, ordered_extent->len); 2832 btrfs_delalloc_release_metadata(inode, ordered_extent->len);
2833 if (trans) 2833 if (trans)
2834 btrfs_end_transaction(trans, root); 2834 btrfs_end_transaction(trans, root);
2835 2835
2836 if (ret || truncated) { 2836 if (ret || truncated) {
2837 u64 start, end; 2837 u64 start, end;
2838 2838
2839 if (truncated) 2839 if (truncated)
2840 start = ordered_extent->file_offset + logical_len; 2840 start = ordered_extent->file_offset + logical_len;
2841 else 2841 else
2842 start = ordered_extent->file_offset; 2842 start = ordered_extent->file_offset;
2843 end = ordered_extent->file_offset + ordered_extent->len - 1; 2843 end = ordered_extent->file_offset + ordered_extent->len - 1;
2844 clear_extent_uptodate(io_tree, start, end, NULL, GFP_NOFS); 2844 clear_extent_uptodate(io_tree, start, end, NULL, GFP_NOFS);
2845 2845
2846 /* Drop the cache for the part of the extent we didn't write. */ 2846 /* Drop the cache for the part of the extent we didn't write. */
2847 btrfs_drop_extent_cache(inode, start, end, 0); 2847 btrfs_drop_extent_cache(inode, start, end, 0);
2848 2848
2849 /* 2849 /*
2850 * If the ordered extent had an IOERR or something else went 2850 * If the ordered extent had an IOERR or something else went
2851 * wrong we need to return the space for this ordered extent 2851 * wrong we need to return the space for this ordered extent
2852 * back to the allocator. We only free the extent in the 2852 * back to the allocator. We only free the extent in the
2853 * truncated case if we didn't write out the extent at all. 2853 * truncated case if we didn't write out the extent at all.
2854 */ 2854 */
2855 if ((ret || !logical_len) && 2855 if ((ret || !logical_len) &&
2856 !test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags) && 2856 !test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags) &&
2857 !test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags)) 2857 !test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags))
2858 btrfs_free_reserved_extent(root, ordered_extent->start, 2858 btrfs_free_reserved_extent(root, ordered_extent->start,
2859 ordered_extent->disk_len, 1); 2859 ordered_extent->disk_len, 1);
2860 } 2860 }
2861 2861
2862 2862
2863 /* 2863 /*
2864 * This needs to be done to make sure anybody waiting knows we are done 2864 * This needs to be done to make sure anybody waiting knows we are done
2865 * updating everything for this ordered extent. 2865 * updating everything for this ordered extent.
2866 */ 2866 */
2867 btrfs_remove_ordered_extent(inode, ordered_extent); 2867 btrfs_remove_ordered_extent(inode, ordered_extent);
2868 2868
2869 /* for snapshot-aware defrag */ 2869 /* for snapshot-aware defrag */
2870 if (new) { 2870 if (new) {
2871 if (ret) { 2871 if (ret) {
2872 free_sa_defrag_extent(new); 2872 free_sa_defrag_extent(new);
2873 atomic_dec(&root->fs_info->defrag_running); 2873 atomic_dec(&root->fs_info->defrag_running);
2874 } else { 2874 } else {
2875 relink_file_extents(new); 2875 relink_file_extents(new);
2876 } 2876 }
2877 } 2877 }
2878 2878
2879 /* once for us */ 2879 /* once for us */
2880 btrfs_put_ordered_extent(ordered_extent); 2880 btrfs_put_ordered_extent(ordered_extent);
2881 /* once for the tree */ 2881 /* once for the tree */
2882 btrfs_put_ordered_extent(ordered_extent); 2882 btrfs_put_ordered_extent(ordered_extent);
2883 2883
2884 return ret; 2884 return ret;
2885 } 2885 }
2886 2886
2887 static void finish_ordered_fn(struct btrfs_work *work) 2887 static void finish_ordered_fn(struct btrfs_work *work)
2888 { 2888 {
2889 struct btrfs_ordered_extent *ordered_extent; 2889 struct btrfs_ordered_extent *ordered_extent;
2890 ordered_extent = container_of(work, struct btrfs_ordered_extent, work); 2890 ordered_extent = container_of(work, struct btrfs_ordered_extent, work);
2891 btrfs_finish_ordered_io(ordered_extent); 2891 btrfs_finish_ordered_io(ordered_extent);
2892 } 2892 }
2893 2893
2894 static int btrfs_writepage_end_io_hook(struct page *page, u64 start, u64 end, 2894 static int btrfs_writepage_end_io_hook(struct page *page, u64 start, u64 end,
2895 struct extent_state *state, int uptodate) 2895 struct extent_state *state, int uptodate)
2896 { 2896 {
2897 struct inode *inode = page->mapping->host; 2897 struct inode *inode = page->mapping->host;
2898 struct btrfs_root *root = BTRFS_I(inode)->root; 2898 struct btrfs_root *root = BTRFS_I(inode)->root;
2899 struct btrfs_ordered_extent *ordered_extent = NULL; 2899 struct btrfs_ordered_extent *ordered_extent = NULL;
2900 struct btrfs_workqueue *wq; 2900 struct btrfs_workqueue *wq;
2901 btrfs_work_func_t func; 2901 btrfs_work_func_t func;
2902 2902
2903 trace_btrfs_writepage_end_io_hook(page, start, end, uptodate); 2903 trace_btrfs_writepage_end_io_hook(page, start, end, uptodate);
2904 2904
2905 ClearPagePrivate2(page); 2905 ClearPagePrivate2(page);
2906 if (!btrfs_dec_test_ordered_pending(inode, &ordered_extent, start, 2906 if (!btrfs_dec_test_ordered_pending(inode, &ordered_extent, start,
2907 end - start + 1, uptodate)) 2907 end - start + 1, uptodate))
2908 return 0; 2908 return 0;
2909 2909
2910 if (btrfs_is_free_space_inode(inode)) { 2910 if (btrfs_is_free_space_inode(inode)) {
2911 wq = root->fs_info->endio_freespace_worker; 2911 wq = root->fs_info->endio_freespace_worker;
2912 func = btrfs_freespace_write_helper; 2912 func = btrfs_freespace_write_helper;
2913 } else { 2913 } else {
2914 wq = root->fs_info->endio_write_workers; 2914 wq = root->fs_info->endio_write_workers;
2915 func = btrfs_endio_write_helper; 2915 func = btrfs_endio_write_helper;
2916 } 2916 }
2917 2917
2918 btrfs_init_work(&ordered_extent->work, func, finish_ordered_fn, NULL, 2918 btrfs_init_work(&ordered_extent->work, func, finish_ordered_fn, NULL,
2919 NULL); 2919 NULL);
2920 btrfs_queue_work(wq, &ordered_extent->work); 2920 btrfs_queue_work(wq, &ordered_extent->work);
2921 2921
2922 return 0; 2922 return 0;
2923 } 2923 }
2924 2924
2925 static int __readpage_endio_check(struct inode *inode, 2925 static int __readpage_endio_check(struct inode *inode,
2926 struct btrfs_io_bio *io_bio, 2926 struct btrfs_io_bio *io_bio,
2927 int icsum, struct page *page, 2927 int icsum, struct page *page,
2928 int pgoff, u64 start, size_t len) 2928 int pgoff, u64 start, size_t len)
2929 { 2929 {
2930 char *kaddr; 2930 char *kaddr;
2931 u32 csum_expected; 2931 u32 csum_expected;
2932 u32 csum = ~(u32)0; 2932 u32 csum = ~(u32)0;
2933 static DEFINE_RATELIMIT_STATE(_rs, DEFAULT_RATELIMIT_INTERVAL, 2933 static DEFINE_RATELIMIT_STATE(_rs, DEFAULT_RATELIMIT_INTERVAL,
2934 DEFAULT_RATELIMIT_BURST); 2934 DEFAULT_RATELIMIT_BURST);
2935 2935
2936 csum_expected = *(((u32 *)io_bio->csum) + icsum); 2936 csum_expected = *(((u32 *)io_bio->csum) + icsum);
2937 2937
2938 kaddr = kmap_atomic(page); 2938 kaddr = kmap_atomic(page);
2939 csum = btrfs_csum_data(kaddr + pgoff, csum, len); 2939 csum = btrfs_csum_data(kaddr + pgoff, csum, len);
2940 btrfs_csum_final(csum, (char *)&csum); 2940 btrfs_csum_final(csum, (char *)&csum);
2941 if (csum != csum_expected) 2941 if (csum != csum_expected)
2942 goto zeroit; 2942 goto zeroit;
2943 2943
2944 kunmap_atomic(kaddr); 2944 kunmap_atomic(kaddr);
2945 return 0; 2945 return 0;
2946 zeroit: 2946 zeroit:
2947 if (__ratelimit(&_rs)) 2947 if (__ratelimit(&_rs))
2948 btrfs_info(BTRFS_I(inode)->root->fs_info, 2948 btrfs_info(BTRFS_I(inode)->root->fs_info,
2949 "csum failed ino %llu off %llu csum %u expected csum %u", 2949 "csum failed ino %llu off %llu csum %u expected csum %u",
2950 btrfs_ino(inode), start, csum, csum_expected); 2950 btrfs_ino(inode), start, csum, csum_expected);
2951 memset(kaddr + pgoff, 1, len); 2951 memset(kaddr + pgoff, 1, len);
2952 flush_dcache_page(page); 2952 flush_dcache_page(page);
2953 kunmap_atomic(kaddr); 2953 kunmap_atomic(kaddr);
2954 if (csum_expected == 0) 2954 if (csum_expected == 0)
2955 return 0; 2955 return 0;
2956 return -EIO; 2956 return -EIO;
2957 } 2957 }
2958 2958
2959 /* 2959 /*
2960 * when reads are done, we need to check csums to verify the data is correct 2960 * when reads are done, we need to check csums to verify the data is correct
2961 * if there's a match, we allow the bio to finish. If not, the code in 2961 * if there's a match, we allow the bio to finish. If not, the code in
2962 * extent_io.c will try to find good copies for us. 2962 * extent_io.c will try to find good copies for us.
2963 */ 2963 */
2964 static int btrfs_readpage_end_io_hook(struct btrfs_io_bio *io_bio, 2964 static int btrfs_readpage_end_io_hook(struct btrfs_io_bio *io_bio,
2965 u64 phy_offset, struct page *page, 2965 u64 phy_offset, struct page *page,
2966 u64 start, u64 end, int mirror) 2966 u64 start, u64 end, int mirror)
2967 { 2967 {
2968 size_t offset = start - page_offset(page); 2968 size_t offset = start - page_offset(page);
2969 struct inode *inode = page->mapping->host; 2969 struct inode *inode = page->mapping->host;
2970 struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; 2970 struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
2971 struct btrfs_root *root = BTRFS_I(inode)->root; 2971 struct btrfs_root *root = BTRFS_I(inode)->root;
2972 2972
2973 if (PageChecked(page)) { 2973 if (PageChecked(page)) {
2974 ClearPageChecked(page); 2974 ClearPageChecked(page);
2975 return 0; 2975 return 0;
2976 } 2976 }
2977 2977
2978 if (BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM) 2978 if (BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM)
2979 return 0; 2979 return 0;
2980 2980
2981 if (root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID && 2981 if (root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID &&
2982 test_range_bit(io_tree, start, end, EXTENT_NODATASUM, 1, NULL)) { 2982 test_range_bit(io_tree, start, end, EXTENT_NODATASUM, 1, NULL)) {
2983 clear_extent_bits(io_tree, start, end, EXTENT_NODATASUM, 2983 clear_extent_bits(io_tree, start, end, EXTENT_NODATASUM,
2984 GFP_NOFS); 2984 GFP_NOFS);
2985 return 0; 2985 return 0;
2986 } 2986 }
2987 2987
2988 phy_offset >>= inode->i_sb->s_blocksize_bits; 2988 phy_offset >>= inode->i_sb->s_blocksize_bits;
2989 return __readpage_endio_check(inode, io_bio, phy_offset, page, offset, 2989 return __readpage_endio_check(inode, io_bio, phy_offset, page, offset,
2990 start, (size_t)(end - start + 1)); 2990 start, (size_t)(end - start + 1));
2991 } 2991 }
2992 2992
2993 struct delayed_iput { 2993 struct delayed_iput {
2994 struct list_head list; 2994 struct list_head list;
2995 struct inode *inode; 2995 struct inode *inode;
2996 }; 2996 };
2997 2997
2998 /* JDM: If this is fs-wide, why can't we add a pointer to 2998 /* JDM: If this is fs-wide, why can't we add a pointer to
2999 * btrfs_inode instead and avoid the allocation? */ 2999 * btrfs_inode instead and avoid the allocation? */
3000 void btrfs_add_delayed_iput(struct inode *inode) 3000 void btrfs_add_delayed_iput(struct inode *inode)
3001 { 3001 {
3002 struct btrfs_fs_info *fs_info = BTRFS_I(inode)->root->fs_info; 3002 struct btrfs_fs_info *fs_info = BTRFS_I(inode)->root->fs_info;
3003 struct delayed_iput *delayed; 3003 struct delayed_iput *delayed;
3004 3004
3005 if (atomic_add_unless(&inode->i_count, -1, 1)) 3005 if (atomic_add_unless(&inode->i_count, -1, 1))
3006 return; 3006 return;
3007 3007
3008 delayed = kmalloc(sizeof(*delayed), GFP_NOFS | __GFP_NOFAIL); 3008 delayed = kmalloc(sizeof(*delayed), GFP_NOFS | __GFP_NOFAIL);
3009 delayed->inode = inode; 3009 delayed->inode = inode;
3010 3010
3011 spin_lock(&fs_info->delayed_iput_lock); 3011 spin_lock(&fs_info->delayed_iput_lock);
3012 list_add_tail(&delayed->list, &fs_info->delayed_iputs); 3012 list_add_tail(&delayed->list, &fs_info->delayed_iputs);
3013 spin_unlock(&fs_info->delayed_iput_lock); 3013 spin_unlock(&fs_info->delayed_iput_lock);
3014 } 3014 }
3015 3015
3016 void btrfs_run_delayed_iputs(struct btrfs_root *root) 3016 void btrfs_run_delayed_iputs(struct btrfs_root *root)
3017 { 3017 {
3018 LIST_HEAD(list); 3018 LIST_HEAD(list);
3019 struct btrfs_fs_info *fs_info = root->fs_info; 3019 struct btrfs_fs_info *fs_info = root->fs_info;
3020 struct delayed_iput *delayed; 3020 struct delayed_iput *delayed;
3021 int empty; 3021 int empty;
3022 3022
3023 spin_lock(&fs_info->delayed_iput_lock); 3023 spin_lock(&fs_info->delayed_iput_lock);
3024 empty = list_empty(&fs_info->delayed_iputs); 3024 empty = list_empty(&fs_info->delayed_iputs);
3025 spin_unlock(&fs_info->delayed_iput_lock); 3025 spin_unlock(&fs_info->delayed_iput_lock);
3026 if (empty) 3026 if (empty)
3027 return; 3027 return;
3028 3028
3029 spin_lock(&fs_info->delayed_iput_lock); 3029 spin_lock(&fs_info->delayed_iput_lock);
3030 list_splice_init(&fs_info->delayed_iputs, &list); 3030 list_splice_init(&fs_info->delayed_iputs, &list);
3031 spin_unlock(&fs_info->delayed_iput_lock); 3031 spin_unlock(&fs_info->delayed_iput_lock);
3032 3032
3033 while (!list_empty(&list)) { 3033 while (!list_empty(&list)) {
3034 delayed = list_entry(list.next, struct delayed_iput, list); 3034 delayed = list_entry(list.next, struct delayed_iput, list);
3035 list_del(&delayed->list); 3035 list_del(&delayed->list);
3036 iput(delayed->inode); 3036 iput(delayed->inode);
3037 kfree(delayed); 3037 kfree(delayed);
3038 } 3038 }
3039 } 3039 }
3040 3040
3041 /* 3041 /*
3042 * This is called in transaction commit time. If there are no orphan 3042 * This is called in transaction commit time. If there are no orphan
3043 * files in the subvolume, it removes orphan item and frees block_rsv 3043 * files in the subvolume, it removes orphan item and frees block_rsv
3044 * structure. 3044 * structure.
3045 */ 3045 */
3046 void btrfs_orphan_commit_root(struct btrfs_trans_handle *trans, 3046 void btrfs_orphan_commit_root(struct btrfs_trans_handle *trans,
3047 struct btrfs_root *root) 3047 struct btrfs_root *root)
3048 { 3048 {
3049 struct btrfs_block_rsv *block_rsv; 3049 struct btrfs_block_rsv *block_rsv;
3050 int ret; 3050 int ret;
3051 3051
3052 if (atomic_read(&root->orphan_inodes) || 3052 if (atomic_read(&root->orphan_inodes) ||
3053 root->orphan_cleanup_state != ORPHAN_CLEANUP_DONE) 3053 root->orphan_cleanup_state != ORPHAN_CLEANUP_DONE)
3054 return; 3054 return;
3055 3055
3056 spin_lock(&root->orphan_lock); 3056 spin_lock(&root->orphan_lock);
3057 if (atomic_read(&root->orphan_inodes)) { 3057 if (atomic_read(&root->orphan_inodes)) {
3058 spin_unlock(&root->orphan_lock); 3058 spin_unlock(&root->orphan_lock);
3059 return; 3059 return;
3060 } 3060 }
3061 3061
3062 if (root->orphan_cleanup_state != ORPHAN_CLEANUP_DONE) { 3062 if (root->orphan_cleanup_state != ORPHAN_CLEANUP_DONE) {
3063 spin_unlock(&root->orphan_lock); 3063 spin_unlock(&root->orphan_lock);
3064 return; 3064 return;
3065 } 3065 }
3066 3066
3067 block_rsv = root->orphan_block_rsv; 3067 block_rsv = root->orphan_block_rsv;
3068 root->orphan_block_rsv = NULL; 3068 root->orphan_block_rsv = NULL;
3069 spin_unlock(&root->orphan_lock); 3069 spin_unlock(&root->orphan_lock);
3070 3070
3071 if (test_bit(BTRFS_ROOT_ORPHAN_ITEM_INSERTED, &root->state) && 3071 if (test_bit(BTRFS_ROOT_ORPHAN_ITEM_INSERTED, &root->state) &&
3072 btrfs_root_refs(&root->root_item) > 0) { 3072 btrfs_root_refs(&root->root_item) > 0) {
3073 ret = btrfs_del_orphan_item(trans, root->fs_info->tree_root, 3073 ret = btrfs_del_orphan_item(trans, root->fs_info->tree_root,
3074 root->root_key.objectid); 3074 root->root_key.objectid);
3075 if (ret) 3075 if (ret)
3076 btrfs_abort_transaction(trans, root, ret); 3076 btrfs_abort_transaction(trans, root, ret);
3077 else 3077 else
3078 clear_bit(BTRFS_ROOT_ORPHAN_ITEM_INSERTED, 3078 clear_bit(BTRFS_ROOT_ORPHAN_ITEM_INSERTED,
3079 &root->state); 3079 &root->state);
3080 } 3080 }
3081 3081
3082 if (block_rsv) { 3082 if (block_rsv) {
3083 WARN_ON(block_rsv->size > 0); 3083 WARN_ON(block_rsv->size > 0);
3084 btrfs_free_block_rsv(root, block_rsv); 3084 btrfs_free_block_rsv(root, block_rsv);
3085 } 3085 }
3086 } 3086 }
3087 3087
3088 /* 3088 /*
3089 * This creates an orphan entry for the given inode in case something goes 3089 * This creates an orphan entry for the given inode in case something goes
3090 * wrong in the middle of an unlink/truncate. 3090 * wrong in the middle of an unlink/truncate.
3091 * 3091 *
3092 * NOTE: caller of this function should reserve 5 units of metadata for 3092 * NOTE: caller of this function should reserve 5 units of metadata for
3093 * this function. 3093 * this function.
3094 */ 3094 */
3095 int btrfs_orphan_add(struct btrfs_trans_handle *trans, struct inode *inode) 3095 int btrfs_orphan_add(struct btrfs_trans_handle *trans, struct inode *inode)
3096 { 3096 {
3097 struct btrfs_root *root = BTRFS_I(inode)->root; 3097 struct btrfs_root *root = BTRFS_I(inode)->root;
3098 struct btrfs_block_rsv *block_rsv = NULL; 3098 struct btrfs_block_rsv *block_rsv = NULL;
3099 int reserve = 0; 3099 int reserve = 0;
3100 int insert = 0; 3100 int insert = 0;
3101 int ret; 3101 int ret;
3102 3102
3103 if (!root->orphan_block_rsv) { 3103 if (!root->orphan_block_rsv) {
3104 block_rsv = btrfs_alloc_block_rsv(root, BTRFS_BLOCK_RSV_TEMP); 3104 block_rsv = btrfs_alloc_block_rsv(root, BTRFS_BLOCK_RSV_TEMP);
3105 if (!block_rsv) 3105 if (!block_rsv)
3106 return -ENOMEM; 3106 return -ENOMEM;
3107 } 3107 }
3108 3108
3109 spin_lock(&root->orphan_lock); 3109 spin_lock(&root->orphan_lock);
3110 if (!root->orphan_block_rsv) { 3110 if (!root->orphan_block_rsv) {
3111 root->orphan_block_rsv = block_rsv; 3111 root->orphan_block_rsv = block_rsv;
3112 } else if (block_rsv) { 3112 } else if (block_rsv) {
3113 btrfs_free_block_rsv(root, block_rsv); 3113 btrfs_free_block_rsv(root, block_rsv);
3114 block_rsv = NULL; 3114 block_rsv = NULL;
3115 } 3115 }
3116 3116
3117 if (!test_and_set_bit(BTRFS_INODE_HAS_ORPHAN_ITEM, 3117 if (!test_and_set_bit(BTRFS_INODE_HAS_ORPHAN_ITEM,
3118 &BTRFS_I(inode)->runtime_flags)) { 3118 &BTRFS_I(inode)->runtime_flags)) {
3119 #if 0 3119 #if 0
3120 /* 3120 /*
3121 * For proper ENOSPC handling, we should do orphan 3121 * For proper ENOSPC handling, we should do orphan
3122 * cleanup when mounting. But this introduces backward 3122 * cleanup when mounting. But this introduces backward
3123 * compatibility issue. 3123 * compatibility issue.
3124 */ 3124 */
3125 if (!xchg(&root->orphan_item_inserted, 1)) 3125 if (!xchg(&root->orphan_item_inserted, 1))
3126 insert = 2; 3126 insert = 2;
3127 else 3127 else
3128 insert = 1; 3128 insert = 1;
3129 #endif 3129 #endif
3130 insert = 1; 3130 insert = 1;
3131 atomic_inc(&root->orphan_inodes); 3131 atomic_inc(&root->orphan_inodes);
3132 } 3132 }
3133 3133
3134 if (!test_and_set_bit(BTRFS_INODE_ORPHAN_META_RESERVED, 3134 if (!test_and_set_bit(BTRFS_INODE_ORPHAN_META_RESERVED,
3135 &BTRFS_I(inode)->runtime_flags)) 3135 &BTRFS_I(inode)->runtime_flags))
3136 reserve = 1; 3136 reserve = 1;
3137 spin_unlock(&root->orphan_lock); 3137 spin_unlock(&root->orphan_lock);
3138 3138
3139 /* grab metadata reservation from transaction handle */ 3139 /* grab metadata reservation from transaction handle */
3140 if (reserve) { 3140 if (reserve) {
3141 ret = btrfs_orphan_reserve_metadata(trans, inode); 3141 ret = btrfs_orphan_reserve_metadata(trans, inode);
3142 BUG_ON(ret); /* -ENOSPC in reservation; Logic error? JDM */ 3142 BUG_ON(ret); /* -ENOSPC in reservation; Logic error? JDM */
3143 } 3143 }
3144 3144
3145 /* insert an orphan item to track this unlinked/truncated file */ 3145 /* insert an orphan item to track this unlinked/truncated file */
3146 if (insert >= 1) { 3146 if (insert >= 1) {
3147 ret = btrfs_insert_orphan_item(trans, root, btrfs_ino(inode)); 3147 ret = btrfs_insert_orphan_item(trans, root, btrfs_ino(inode));
3148 if (ret) { 3148 if (ret) {
3149 atomic_dec(&root->orphan_inodes); 3149 atomic_dec(&root->orphan_inodes);
3150 if (reserve) { 3150 if (reserve) {
3151 clear_bit(BTRFS_INODE_ORPHAN_META_RESERVED, 3151 clear_bit(BTRFS_INODE_ORPHAN_META_RESERVED,
3152 &BTRFS_I(inode)->runtime_flags); 3152 &BTRFS_I(inode)->runtime_flags);
3153 btrfs_orphan_release_metadata(inode); 3153 btrfs_orphan_release_metadata(inode);
3154 } 3154 }
3155 if (ret != -EEXIST) { 3155 if (ret != -EEXIST) {
3156 clear_bit(BTRFS_INODE_HAS_ORPHAN_ITEM, 3156 clear_bit(BTRFS_INODE_HAS_ORPHAN_ITEM,
3157 &BTRFS_I(inode)->runtime_flags); 3157 &BTRFS_I(inode)->runtime_flags);
3158 btrfs_abort_transaction(trans, root, ret); 3158 btrfs_abort_transaction(trans, root, ret);
3159 return ret; 3159 return ret;
3160 } 3160 }
3161 } 3161 }
3162 ret = 0; 3162 ret = 0;
3163 } 3163 }
3164 3164
3165 /* insert an orphan item to track subvolume contains orphan files */ 3165 /* insert an orphan item to track subvolume contains orphan files */
3166 if (insert >= 2) { 3166 if (insert >= 2) {
3167 ret = btrfs_insert_orphan_item(trans, root->fs_info->tree_root, 3167 ret = btrfs_insert_orphan_item(trans, root->fs_info->tree_root,
3168 root->root_key.objectid); 3168 root->root_key.objectid);
3169 if (ret && ret != -EEXIST) { 3169 if (ret && ret != -EEXIST) {
3170 btrfs_abort_transaction(trans, root, ret); 3170 btrfs_abort_transaction(trans, root, ret);
3171 return ret; 3171 return ret;
3172 } 3172 }
3173 } 3173 }
3174 return 0; 3174 return 0;
3175 } 3175 }
3176 3176
3177 /* 3177 /*
3178 * We have done the truncate/delete so we can go ahead and remove the orphan 3178 * We have done the truncate/delete so we can go ahead and remove the orphan
3179 * item for this particular inode. 3179 * item for this particular inode.
3180 */ 3180 */
3181 static int btrfs_orphan_del(struct btrfs_trans_handle *trans, 3181 static int btrfs_orphan_del(struct btrfs_trans_handle *trans,
3182 struct inode *inode) 3182 struct inode *inode)
3183 { 3183 {
3184 struct btrfs_root *root = BTRFS_I(inode)->root; 3184 struct btrfs_root *root = BTRFS_I(inode)->root;
3185 int delete_item = 0; 3185 int delete_item = 0;
3186 int release_rsv = 0; 3186 int release_rsv = 0;
3187 int ret = 0; 3187 int ret = 0;
3188 3188
3189 spin_lock(&root->orphan_lock); 3189 spin_lock(&root->orphan_lock);
3190 if (test_and_clear_bit(BTRFS_INODE_HAS_ORPHAN_ITEM, 3190 if (test_and_clear_bit(BTRFS_INODE_HAS_ORPHAN_ITEM,
3191 &BTRFS_I(inode)->runtime_flags)) 3191 &BTRFS_I(inode)->runtime_flags))
3192 delete_item = 1; 3192 delete_item = 1;
3193 3193
3194 if (test_and_clear_bit(BTRFS_INODE_ORPHAN_META_RESERVED, 3194 if (test_and_clear_bit(BTRFS_INODE_ORPHAN_META_RESERVED,
3195 &BTRFS_I(inode)->runtime_flags)) 3195 &BTRFS_I(inode)->runtime_flags))
3196 release_rsv = 1; 3196 release_rsv = 1;
3197 spin_unlock(&root->orphan_lock); 3197 spin_unlock(&root->orphan_lock);
3198 3198
3199 if (delete_item) { 3199 if (delete_item) {
3200 atomic_dec(&root->orphan_inodes); 3200 atomic_dec(&root->orphan_inodes);
3201 if (trans) 3201 if (trans)
3202 ret = btrfs_del_orphan_item(trans, root, 3202 ret = btrfs_del_orphan_item(trans, root,
3203 btrfs_ino(inode)); 3203 btrfs_ino(inode));
3204 } 3204 }
3205 3205
3206 if (release_rsv) 3206 if (release_rsv)
3207 btrfs_orphan_release_metadata(inode); 3207 btrfs_orphan_release_metadata(inode);
3208 3208
3209 return ret; 3209 return ret;
3210 } 3210 }
3211 3211
3212 /* 3212 /*
3213 * this cleans up any orphans that may be left on the list from the last use 3213 * this cleans up any orphans that may be left on the list from the last use
3214 * of this root. 3214 * of this root.
3215 */ 3215 */
3216 int btrfs_orphan_cleanup(struct btrfs_root *root) 3216 int btrfs_orphan_cleanup(struct btrfs_root *root)
3217 { 3217 {
3218 struct btrfs_path *path; 3218 struct btrfs_path *path;
3219 struct extent_buffer *leaf; 3219 struct extent_buffer *leaf;
3220 struct btrfs_key key, found_key; 3220 struct btrfs_key key, found_key;
3221 struct btrfs_trans_handle *trans; 3221 struct btrfs_trans_handle *trans;
3222 struct inode *inode; 3222 struct inode *inode;
3223 u64 last_objectid = 0; 3223 u64 last_objectid = 0;
3224 int ret = 0, nr_unlink = 0, nr_truncate = 0; 3224 int ret = 0, nr_unlink = 0, nr_truncate = 0;
3225 3225
3226 if (cmpxchg(&root->orphan_cleanup_state, 0, ORPHAN_CLEANUP_STARTED)) 3226 if (cmpxchg(&root->orphan_cleanup_state, 0, ORPHAN_CLEANUP_STARTED))
3227 return 0; 3227 return 0;
3228 3228
3229 path = btrfs_alloc_path(); 3229 path = btrfs_alloc_path();
3230 if (!path) { 3230 if (!path) {
3231 ret = -ENOMEM; 3231 ret = -ENOMEM;
3232 goto out; 3232 goto out;
3233 } 3233 }
3234 path->reada = -1; 3234 path->reada = -1;
3235 3235
3236 key.objectid = BTRFS_ORPHAN_OBJECTID; 3236 key.objectid = BTRFS_ORPHAN_OBJECTID;
3237 key.type = BTRFS_ORPHAN_ITEM_KEY; 3237 key.type = BTRFS_ORPHAN_ITEM_KEY;
3238 key.offset = (u64)-1; 3238 key.offset = (u64)-1;
3239 3239
3240 while (1) { 3240 while (1) {
3241 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); 3241 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
3242 if (ret < 0) 3242 if (ret < 0)
3243 goto out; 3243 goto out;
3244 3244
3245 /* 3245 /*
3246 * if ret == 0 means we found what we were searching for, which 3246 * if ret == 0 means we found what we were searching for, which
3247 * is weird, but possible, so only screw with path if we didn't 3247 * is weird, but possible, so only screw with path if we didn't
3248 * find the key and see if we have stuff that matches 3248 * find the key and see if we have stuff that matches
3249 */ 3249 */
3250 if (ret > 0) { 3250 if (ret > 0) {
3251 ret = 0; 3251 ret = 0;
3252 if (path->slots[0] == 0) 3252 if (path->slots[0] == 0)
3253 break; 3253 break;
3254 path->slots[0]--; 3254 path->slots[0]--;
3255 } 3255 }
3256 3256
3257 /* pull out the item */ 3257 /* pull out the item */
3258 leaf = path->nodes[0]; 3258 leaf = path->nodes[0];
3259 btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]); 3259 btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]);
3260 3260
3261 /* make sure the item matches what we want */ 3261 /* make sure the item matches what we want */
3262 if (found_key.objectid != BTRFS_ORPHAN_OBJECTID) 3262 if (found_key.objectid != BTRFS_ORPHAN_OBJECTID)
3263 break; 3263 break;
3264 if (found_key.type != BTRFS_ORPHAN_ITEM_KEY) 3264 if (found_key.type != BTRFS_ORPHAN_ITEM_KEY)
3265 break; 3265 break;
3266 3266
3267 /* release the path since we're done with it */ 3267 /* release the path since we're done with it */
3268 btrfs_release_path(path); 3268 btrfs_release_path(path);
3269 3269
3270 /* 3270 /*
3271 * this is where we are basically btrfs_lookup, without the 3271 * this is where we are basically btrfs_lookup, without the
3272 * crossing root thing. we store the inode number in the 3272 * crossing root thing. we store the inode number in the
3273 * offset of the orphan item. 3273 * offset of the orphan item.
3274 */ 3274 */
3275 3275
3276 if (found_key.offset == last_objectid) { 3276 if (found_key.offset == last_objectid) {
3277 btrfs_err(root->fs_info, 3277 btrfs_err(root->fs_info,
3278 "Error removing orphan entry, stopping orphan cleanup"); 3278 "Error removing orphan entry, stopping orphan cleanup");
3279 ret = -EINVAL; 3279 ret = -EINVAL;
3280 goto out; 3280 goto out;
3281 } 3281 }
3282 3282
3283 last_objectid = found_key.offset; 3283 last_objectid = found_key.offset;
3284 3284
3285 found_key.objectid = found_key.offset; 3285 found_key.objectid = found_key.offset;
3286 found_key.type = BTRFS_INODE_ITEM_KEY; 3286 found_key.type = BTRFS_INODE_ITEM_KEY;
3287 found_key.offset = 0; 3287 found_key.offset = 0;
3288 inode = btrfs_iget(root->fs_info->sb, &found_key, root, NULL); 3288 inode = btrfs_iget(root->fs_info->sb, &found_key, root, NULL);
3289 ret = PTR_ERR_OR_ZERO(inode); 3289 ret = PTR_ERR_OR_ZERO(inode);
3290 if (ret && ret != -ESTALE) 3290 if (ret && ret != -ESTALE)
3291 goto out; 3291 goto out;
3292 3292
3293 if (ret == -ESTALE && root == root->fs_info->tree_root) { 3293 if (ret == -ESTALE && root == root->fs_info->tree_root) {
3294 struct btrfs_root *dead_root; 3294 struct btrfs_root *dead_root;
3295 struct btrfs_fs_info *fs_info = root->fs_info; 3295 struct btrfs_fs_info *fs_info = root->fs_info;
3296 int is_dead_root = 0; 3296 int is_dead_root = 0;
3297 3297
3298 /* 3298 /*
3299 * this is an orphan in the tree root. Currently these 3299 * this is an orphan in the tree root. Currently these
3300 * could come from 2 sources: 3300 * could come from 2 sources:
3301 * a) a snapshot deletion in progress 3301 * a) a snapshot deletion in progress
3302 * b) a free space cache inode 3302 * b) a free space cache inode
3303 * We need to distinguish those two, as the snapshot 3303 * We need to distinguish those two, as the snapshot
3304 * orphan must not get deleted. 3304 * orphan must not get deleted.
3305 * find_dead_roots already ran before us, so if this 3305 * find_dead_roots already ran before us, so if this
3306 * is a snapshot deletion, we should find the root 3306 * is a snapshot deletion, we should find the root
3307 * in the dead_roots list 3307 * in the dead_roots list
3308 */ 3308 */
3309 spin_lock(&fs_info->trans_lock); 3309 spin_lock(&fs_info->trans_lock);
3310 list_for_each_entry(dead_root, &fs_info->dead_roots, 3310 list_for_each_entry(dead_root, &fs_info->dead_roots,
3311 root_list) { 3311 root_list) {
3312 if (dead_root->root_key.objectid == 3312 if (dead_root->root_key.objectid ==
3313 found_key.objectid) { 3313 found_key.objectid) {
3314 is_dead_root = 1; 3314 is_dead_root = 1;
3315 break; 3315 break;
3316 } 3316 }
3317 } 3317 }
3318 spin_unlock(&fs_info->trans_lock); 3318 spin_unlock(&fs_info->trans_lock);
3319 if (is_dead_root) { 3319 if (is_dead_root) {
3320 /* prevent this orphan from being found again */ 3320 /* prevent this orphan from being found again */
3321 key.offset = found_key.objectid - 1; 3321 key.offset = found_key.objectid - 1;
3322 continue; 3322 continue;
3323 } 3323 }
3324 } 3324 }
3325 /* 3325 /*
3326 * Inode is already gone but the orphan item is still there, 3326 * Inode is already gone but the orphan item is still there,
3327 * kill the orphan item. 3327 * kill the orphan item.
3328 */ 3328 */
3329 if (ret == -ESTALE) { 3329 if (ret == -ESTALE) {
3330 trans = btrfs_start_transaction(root, 1); 3330 trans = btrfs_start_transaction(root, 1);
3331 if (IS_ERR(trans)) { 3331 if (IS_ERR(trans)) {
3332 ret = PTR_ERR(trans); 3332 ret = PTR_ERR(trans);
3333 goto out; 3333 goto out;
3334 } 3334 }
3335 btrfs_debug(root->fs_info, "auto deleting %Lu", 3335 btrfs_debug(root->fs_info, "auto deleting %Lu",
3336 found_key.objectid); 3336 found_key.objectid);
3337 ret = btrfs_del_orphan_item(trans, root, 3337 ret = btrfs_del_orphan_item(trans, root,
3338 found_key.objectid); 3338 found_key.objectid);
3339 btrfs_end_transaction(trans, root); 3339 btrfs_end_transaction(trans, root);
3340 if (ret) 3340 if (ret)
3341 goto out; 3341 goto out;
3342 continue; 3342 continue;
3343 } 3343 }
3344 3344
3345 /* 3345 /*
3346 * add this inode to the orphan list so btrfs_orphan_del does 3346 * add this inode to the orphan list so btrfs_orphan_del does
3347 * the proper thing when we hit it 3347 * the proper thing when we hit it
3348 */ 3348 */
3349 set_bit(BTRFS_INODE_HAS_ORPHAN_ITEM, 3349 set_bit(BTRFS_INODE_HAS_ORPHAN_ITEM,
3350 &BTRFS_I(inode)->runtime_flags); 3350 &BTRFS_I(inode)->runtime_flags);
3351 atomic_inc(&root->orphan_inodes); 3351 atomic_inc(&root->orphan_inodes);
3352 3352
3353 /* if we have links, this was a truncate, lets do that */ 3353 /* if we have links, this was a truncate, lets do that */
3354 if (inode->i_nlink) { 3354 if (inode->i_nlink) {
3355 if (WARN_ON(!S_ISREG(inode->i_mode))) { 3355 if (WARN_ON(!S_ISREG(inode->i_mode))) {
3356 iput(inode); 3356 iput(inode);
3357 continue; 3357 continue;
3358 } 3358 }
3359 nr_truncate++; 3359 nr_truncate++;
3360 3360
3361 /* 1 for the orphan item deletion. */ 3361 /* 1 for the orphan item deletion. */
3362 trans = btrfs_start_transaction(root, 1); 3362 trans = btrfs_start_transaction(root, 1);
3363 if (IS_ERR(trans)) { 3363 if (IS_ERR(trans)) {
3364 iput(inode); 3364 iput(inode);
3365 ret = PTR_ERR(trans); 3365 ret = PTR_ERR(trans);
3366 goto out; 3366 goto out;
3367 } 3367 }
3368 ret = btrfs_orphan_add(trans, inode); 3368 ret = btrfs_orphan_add(trans, inode);
3369 btrfs_end_transaction(trans, root); 3369 btrfs_end_transaction(trans, root);
3370 if (ret) { 3370 if (ret) {
3371 iput(inode); 3371 iput(inode);
3372 goto out; 3372 goto out;
3373 } 3373 }
3374 3374
3375 ret = btrfs_truncate(inode); 3375 ret = btrfs_truncate(inode);
3376 if (ret) 3376 if (ret)
3377 btrfs_orphan_del(NULL, inode); 3377 btrfs_orphan_del(NULL, inode);
3378 } else { 3378 } else {
3379 nr_unlink++; 3379 nr_unlink++;
3380 } 3380 }
3381 3381
3382 /* this will do delete_inode and everything for us */ 3382 /* this will do delete_inode and everything for us */
3383 iput(inode); 3383 iput(inode);
3384 if (ret) 3384 if (ret)
3385 goto out; 3385 goto out;
3386 } 3386 }
3387 /* release the path since we're done with it */ 3387 /* release the path since we're done with it */
3388 btrfs_release_path(path); 3388 btrfs_release_path(path);
3389 3389
3390 root->orphan_cleanup_state = ORPHAN_CLEANUP_DONE; 3390 root->orphan_cleanup_state = ORPHAN_CLEANUP_DONE;
3391 3391
3392 if (root->orphan_block_rsv) 3392 if (root->orphan_block_rsv)
3393 btrfs_block_rsv_release(root, root->orphan_block_rsv, 3393 btrfs_block_rsv_release(root, root->orphan_block_rsv,
3394 (u64)-1); 3394 (u64)-1);
3395 3395
3396 if (root->orphan_block_rsv || 3396 if (root->orphan_block_rsv ||
3397 test_bit(BTRFS_ROOT_ORPHAN_ITEM_INSERTED, &root->state)) { 3397 test_bit(BTRFS_ROOT_ORPHAN_ITEM_INSERTED, &root->state)) {
3398 trans = btrfs_join_transaction(root); 3398 trans = btrfs_join_transaction(root);
3399 if (!IS_ERR(trans)) 3399 if (!IS_ERR(trans))
3400 btrfs_end_transaction(trans, root); 3400 btrfs_end_transaction(trans, root);
3401 } 3401 }
3402 3402
3403 if (nr_unlink) 3403 if (nr_unlink)
3404 btrfs_debug(root->fs_info, "unlinked %d orphans", nr_unlink); 3404 btrfs_debug(root->fs_info, "unlinked %d orphans", nr_unlink);
3405 if (nr_truncate) 3405 if (nr_truncate)
3406 btrfs_debug(root->fs_info, "truncated %d orphans", nr_truncate); 3406 btrfs_debug(root->fs_info, "truncated %d orphans", nr_truncate);
3407 3407
3408 out: 3408 out:
3409 if (ret) 3409 if (ret)
3410 btrfs_crit(root->fs_info, 3410 btrfs_crit(root->fs_info,
3411 "could not do orphan cleanup %d", ret); 3411 "could not do orphan cleanup %d", ret);
3412 btrfs_free_path(path); 3412 btrfs_free_path(path);
3413 return ret; 3413 return ret;
3414 } 3414 }
3415 3415
3416 /* 3416 /*
3417 * very simple check to peek ahead in the leaf looking for xattrs. If we 3417 * very simple check to peek ahead in the leaf looking for xattrs. If we
3418 * don't find any xattrs, we know there can't be any acls. 3418 * don't find any xattrs, we know there can't be any acls.
3419 * 3419 *
3420 * slot is the slot the inode is in, objectid is the objectid of the inode 3420 * slot is the slot the inode is in, objectid is the objectid of the inode
3421 */ 3421 */
3422 static noinline int acls_after_inode_item(struct extent_buffer *leaf, 3422 static noinline int acls_after_inode_item(struct extent_buffer *leaf,
3423 int slot, u64 objectid, 3423 int slot, u64 objectid,
3424 int *first_xattr_slot) 3424 int *first_xattr_slot)
3425 { 3425 {
3426 u32 nritems = btrfs_header_nritems(leaf); 3426 u32 nritems = btrfs_header_nritems(leaf);
3427 struct btrfs_key found_key; 3427 struct btrfs_key found_key;
3428 static u64 xattr_access = 0; 3428 static u64 xattr_access = 0;
3429 static u64 xattr_default = 0; 3429 static u64 xattr_default = 0;
3430 int scanned = 0; 3430 int scanned = 0;
3431 3431
3432 if (!xattr_access) { 3432 if (!xattr_access) {
3433 xattr_access = btrfs_name_hash(POSIX_ACL_XATTR_ACCESS, 3433 xattr_access = btrfs_name_hash(POSIX_ACL_XATTR_ACCESS,
3434 strlen(POSIX_ACL_XATTR_ACCESS)); 3434 strlen(POSIX_ACL_XATTR_ACCESS));
3435 xattr_default = btrfs_name_hash(POSIX_ACL_XATTR_DEFAULT, 3435 xattr_default = btrfs_name_hash(POSIX_ACL_XATTR_DEFAULT,
3436 strlen(POSIX_ACL_XATTR_DEFAULT)); 3436 strlen(POSIX_ACL_XATTR_DEFAULT));
3437 } 3437 }
3438 3438
3439 slot++; 3439 slot++;
3440 *first_xattr_slot = -1; 3440 *first_xattr_slot = -1;
3441 while (slot < nritems) { 3441 while (slot < nritems) {
3442 btrfs_item_key_to_cpu(leaf, &found_key, slot); 3442 btrfs_item_key_to_cpu(leaf, &found_key, slot);
3443 3443
3444 /* we found a different objectid, there must not be acls */ 3444 /* we found a different objectid, there must not be acls */
3445 if (found_key.objectid != objectid) 3445 if (found_key.objectid != objectid)
3446 return 0; 3446 return 0;
3447 3447
3448 /* we found an xattr, assume we've got an acl */ 3448 /* we found an xattr, assume we've got an acl */
3449 if (found_key.type == BTRFS_XATTR_ITEM_KEY) { 3449 if (found_key.type == BTRFS_XATTR_ITEM_KEY) {
3450 if (*first_xattr_slot == -1) 3450 if (*first_xattr_slot == -1)
3451 *first_xattr_slot = slot; 3451 *first_xattr_slot = slot;
3452 if (found_key.offset == xattr_access || 3452 if (found_key.offset == xattr_access ||
3453 found_key.offset == xattr_default) 3453 found_key.offset == xattr_default)
3454 return 1; 3454 return 1;
3455 } 3455 }
3456 3456
3457 /* 3457 /*
3458 * we found a key greater than an xattr key, there can't 3458 * we found a key greater than an xattr key, there can't
3459 * be any acls later on 3459 * be any acls later on
3460 */ 3460 */
3461 if (found_key.type > BTRFS_XATTR_ITEM_KEY) 3461 if (found_key.type > BTRFS_XATTR_ITEM_KEY)
3462 return 0; 3462 return 0;
3463 3463
3464 slot++; 3464 slot++;
3465 scanned++; 3465 scanned++;
3466 3466
3467 /* 3467 /*
3468 * it goes inode, inode backrefs, xattrs, extents, 3468 * it goes inode, inode backrefs, xattrs, extents,
3469 * so if there are a ton of hard links to an inode there can 3469 * so if there are a ton of hard links to an inode there can
3470 * be a lot of backrefs. Don't waste time searching too hard, 3470 * be a lot of backrefs. Don't waste time searching too hard,
3471 * this is just an optimization 3471 * this is just an optimization
3472 */ 3472 */
3473 if (scanned >= 8) 3473 if (scanned >= 8)
3474 break; 3474 break;
3475 } 3475 }
3476 /* we hit the end of the leaf before we found an xattr or 3476 /* we hit the end of the leaf before we found an xattr or
3477 * something larger than an xattr. We have to assume the inode 3477 * something larger than an xattr. We have to assume the inode
3478 * has acls 3478 * has acls
3479 */ 3479 */
3480 if (*first_xattr_slot == -1) 3480 if (*first_xattr_slot == -1)
3481 *first_xattr_slot = slot; 3481 *first_xattr_slot = slot;
3482 return 1; 3482 return 1;
3483 } 3483 }
3484 3484
3485 /* 3485 /*
3486 * read an inode from the btree into the in-memory inode 3486 * read an inode from the btree into the in-memory inode
3487 */ 3487 */
3488 static void btrfs_read_locked_inode(struct inode *inode) 3488 static void btrfs_read_locked_inode(struct inode *inode)
3489 { 3489 {
3490 struct btrfs_path *path; 3490 struct btrfs_path *path;
3491 struct extent_buffer *leaf; 3491 struct extent_buffer *leaf;
3492 struct btrfs_inode_item *inode_item; 3492 struct btrfs_inode_item *inode_item;
3493 struct btrfs_timespec *tspec; 3493 struct btrfs_timespec *tspec;
3494 struct btrfs_root *root = BTRFS_I(inode)->root; 3494 struct btrfs_root *root = BTRFS_I(inode)->root;
3495 struct btrfs_key location; 3495 struct btrfs_key location;
3496 unsigned long ptr; 3496 unsigned long ptr;
3497 int maybe_acls; 3497 int maybe_acls;
3498 u32 rdev; 3498 u32 rdev;
3499 int ret; 3499 int ret;
3500 bool filled = false; 3500 bool filled = false;
3501 int first_xattr_slot; 3501 int first_xattr_slot;
3502 3502
3503 ret = btrfs_fill_inode(inode, &rdev); 3503 ret = btrfs_fill_inode(inode, &rdev);
3504 if (!ret) 3504 if (!ret)
3505 filled = true; 3505 filled = true;
3506 3506
3507 path = btrfs_alloc_path(); 3507 path = btrfs_alloc_path();
3508 if (!path) 3508 if (!path)
3509 goto make_bad; 3509 goto make_bad;
3510 3510
3511 memcpy(&location, &BTRFS_I(inode)->location, sizeof(location)); 3511 memcpy(&location, &BTRFS_I(inode)->location, sizeof(location));
3512 3512
3513 ret = btrfs_lookup_inode(NULL, root, path, &location, 0); 3513 ret = btrfs_lookup_inode(NULL, root, path, &location, 0);
3514 if (ret) 3514 if (ret)
3515 goto make_bad; 3515 goto make_bad;
3516 3516
3517 leaf = path->nodes[0]; 3517 leaf = path->nodes[0];
3518 3518
3519 if (filled) 3519 if (filled)
3520 goto cache_index; 3520 goto cache_index;
3521 3521
3522 inode_item = btrfs_item_ptr(leaf, path->slots[0], 3522 inode_item = btrfs_item_ptr(leaf, path->slots[0],
3523 struct btrfs_inode_item); 3523 struct btrfs_inode_item);
3524 inode->i_mode = btrfs_inode_mode(leaf, inode_item); 3524 inode->i_mode = btrfs_inode_mode(leaf, inode_item);
3525 set_nlink(inode, btrfs_inode_nlink(leaf, inode_item)); 3525 set_nlink(inode, btrfs_inode_nlink(leaf, inode_item));
3526 i_uid_write(inode, btrfs_inode_uid(leaf, inode_item)); 3526 i_uid_write(inode, btrfs_inode_uid(leaf, inode_item));
3527 i_gid_write(inode, btrfs_inode_gid(leaf, inode_item)); 3527 i_gid_write(inode, btrfs_inode_gid(leaf, inode_item));
3528 btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item)); 3528 btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
3529 3529
3530 tspec = btrfs_inode_atime(inode_item); 3530 tspec = btrfs_inode_atime(inode_item);
3531 inode->i_atime.tv_sec = btrfs_timespec_sec(leaf, tspec); 3531 inode->i_atime.tv_sec = btrfs_timespec_sec(leaf, tspec);
3532 inode->i_atime.tv_nsec = btrfs_timespec_nsec(leaf, tspec); 3532 inode->i_atime.tv_nsec = btrfs_timespec_nsec(leaf, tspec);
3533 3533
3534 tspec = btrfs_inode_mtime(inode_item); 3534 tspec = btrfs_inode_mtime(inode_item);
3535 inode->i_mtime.tv_sec = btrfs_timespec_sec(leaf, tspec); 3535 inode->i_mtime.tv_sec = btrfs_timespec_sec(leaf, tspec);
3536 inode->i_mtime.tv_nsec = btrfs_timespec_nsec(leaf, tspec); 3536 inode->i_mtime.tv_nsec = btrfs_timespec_nsec(leaf, tspec);
3537 3537
3538 tspec = btrfs_inode_ctime(inode_item); 3538 tspec = btrfs_inode_ctime(inode_item);
3539 inode->i_ctime.tv_sec = btrfs_timespec_sec(leaf, tspec); 3539 inode->i_ctime.tv_sec = btrfs_timespec_sec(leaf, tspec);
3540 inode->i_ctime.tv_nsec = btrfs_timespec_nsec(leaf, tspec); 3540 inode->i_ctime.tv_nsec = btrfs_timespec_nsec(leaf, tspec);
3541 3541
3542 inode_set_bytes(inode, btrfs_inode_nbytes(leaf, inode_item)); 3542 inode_set_bytes(inode, btrfs_inode_nbytes(leaf, inode_item));
3543 BTRFS_I(inode)->generation = btrfs_inode_generation(leaf, inode_item); 3543 BTRFS_I(inode)->generation = btrfs_inode_generation(leaf, inode_item);
3544 BTRFS_I(inode)->last_trans = btrfs_inode_transid(leaf, inode_item); 3544 BTRFS_I(inode)->last_trans = btrfs_inode_transid(leaf, inode_item);
3545 3545
3546 /* 3546 /*
3547 * If we were modified in the current generation and evicted from memory 3547 * If we were modified in the current generation and evicted from memory
3548 * and then re-read we need to do a full sync since we don't have any 3548 * and then re-read we need to do a full sync since we don't have any
3549 * idea about which extents were modified before we were evicted from 3549 * idea about which extents were modified before we were evicted from
3550 * cache. 3550 * cache.
3551 */ 3551 */
3552 if (BTRFS_I(inode)->last_trans == root->fs_info->generation) 3552 if (BTRFS_I(inode)->last_trans == root->fs_info->generation)
3553 set_bit(BTRFS_INODE_NEEDS_FULL_SYNC, 3553 set_bit(BTRFS_INODE_NEEDS_FULL_SYNC,
3554 &BTRFS_I(inode)->runtime_flags); 3554 &BTRFS_I(inode)->runtime_flags);
3555 3555
3556 inode->i_version = btrfs_inode_sequence(leaf, inode_item); 3556 inode->i_version = btrfs_inode_sequence(leaf, inode_item);
3557 inode->i_generation = BTRFS_I(inode)->generation; 3557 inode->i_generation = BTRFS_I(inode)->generation;
3558 inode->i_rdev = 0; 3558 inode->i_rdev = 0;
3559 rdev = btrfs_inode_rdev(leaf, inode_item); 3559 rdev = btrfs_inode_rdev(leaf, inode_item);
3560 3560
3561 BTRFS_I(inode)->index_cnt = (u64)-1; 3561 BTRFS_I(inode)->index_cnt = (u64)-1;
3562 BTRFS_I(inode)->flags = btrfs_inode_flags(leaf, inode_item); 3562 BTRFS_I(inode)->flags = btrfs_inode_flags(leaf, inode_item);
3563 3563
3564 cache_index: 3564 cache_index:
3565 path->slots[0]++; 3565 path->slots[0]++;
3566 if (inode->i_nlink != 1 || 3566 if (inode->i_nlink != 1 ||
3567 path->slots[0] >= btrfs_header_nritems(leaf)) 3567 path->slots[0] >= btrfs_header_nritems(leaf))
3568 goto cache_acl; 3568 goto cache_acl;
3569 3569
3570 btrfs_item_key_to_cpu(leaf, &location, path->slots[0]); 3570 btrfs_item_key_to_cpu(leaf, &location, path->slots[0]);
3571 if (location.objectid != btrfs_ino(inode)) 3571 if (location.objectid != btrfs_ino(inode))
3572 goto cache_acl; 3572 goto cache_acl;
3573 3573
3574 ptr = btrfs_item_ptr_offset(leaf, path->slots[0]); 3574 ptr = btrfs_item_ptr_offset(leaf, path->slots[0]);
3575 if (location.type == BTRFS_INODE_REF_KEY) { 3575 if (location.type == BTRFS_INODE_REF_KEY) {
3576 struct btrfs_inode_ref *ref; 3576 struct btrfs_inode_ref *ref;
3577 3577
3578 ref = (struct btrfs_inode_ref *)ptr; 3578 ref = (struct btrfs_inode_ref *)ptr;
3579 BTRFS_I(inode)->dir_index = btrfs_inode_ref_index(leaf, ref); 3579 BTRFS_I(inode)->dir_index = btrfs_inode_ref_index(leaf, ref);
3580 } else if (location.type == BTRFS_INODE_EXTREF_KEY) { 3580 } else if (location.type == BTRFS_INODE_EXTREF_KEY) {
3581 struct btrfs_inode_extref *extref; 3581 struct btrfs_inode_extref *extref;
3582 3582
3583 extref = (struct btrfs_inode_extref *)ptr; 3583 extref = (struct btrfs_inode_extref *)ptr;
3584 BTRFS_I(inode)->dir_index = btrfs_inode_extref_index(leaf, 3584 BTRFS_I(inode)->dir_index = btrfs_inode_extref_index(leaf,
3585 extref); 3585 extref);
3586 } 3586 }
3587 cache_acl: 3587 cache_acl:
3588 /* 3588 /*
3589 * try to precache a NULL acl entry for files that don't have 3589 * try to precache a NULL acl entry for files that don't have
3590 * any xattrs or acls 3590 * any xattrs or acls
3591 */ 3591 */
3592 maybe_acls = acls_after_inode_item(leaf, path->slots[0], 3592 maybe_acls = acls_after_inode_item(leaf, path->slots[0],
3593 btrfs_ino(inode), &first_xattr_slot); 3593 btrfs_ino(inode), &first_xattr_slot);
3594 if (first_xattr_slot != -1) { 3594 if (first_xattr_slot != -1) {
3595 path->slots[0] = first_xattr_slot; 3595 path->slots[0] = first_xattr_slot;
3596 ret = btrfs_load_inode_props(inode, path); 3596 ret = btrfs_load_inode_props(inode, path);
3597 if (ret) 3597 if (ret)
3598 btrfs_err(root->fs_info, 3598 btrfs_err(root->fs_info,
3599 "error loading props for ino %llu (root %llu): %d", 3599 "error loading props for ino %llu (root %llu): %d",
3600 btrfs_ino(inode), 3600 btrfs_ino(inode),
3601 root->root_key.objectid, ret); 3601 root->root_key.objectid, ret);
3602 } 3602 }
3603 btrfs_free_path(path); 3603 btrfs_free_path(path);
3604 3604
3605 if (!maybe_acls) 3605 if (!maybe_acls)
3606 cache_no_acl(inode); 3606 cache_no_acl(inode);
3607 3607
3608 switch (inode->i_mode & S_IFMT) { 3608 switch (inode->i_mode & S_IFMT) {
3609 case S_IFREG: 3609 case S_IFREG:
3610 inode->i_mapping->a_ops = &btrfs_aops; 3610 inode->i_mapping->a_ops = &btrfs_aops;
3611 inode->i_mapping->backing_dev_info = &root->fs_info->bdi; 3611 inode->i_mapping->backing_dev_info = &root->fs_info->bdi;
3612 BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops; 3612 BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops;
3613 inode->i_fop = &btrfs_file_operations; 3613 inode->i_fop = &btrfs_file_operations;
3614 inode->i_op = &btrfs_file_inode_operations; 3614 inode->i_op = &btrfs_file_inode_operations;
3615 break; 3615 break;
3616 case S_IFDIR: 3616 case S_IFDIR:
3617 inode->i_fop = &btrfs_dir_file_operations; 3617 inode->i_fop = &btrfs_dir_file_operations;
3618 if (root == root->fs_info->tree_root) 3618 if (root == root->fs_info->tree_root)
3619 inode->i_op = &btrfs_dir_ro_inode_operations; 3619 inode->i_op = &btrfs_dir_ro_inode_operations;
3620 else 3620 else
3621 inode->i_op = &btrfs_dir_inode_operations; 3621 inode->i_op = &btrfs_dir_inode_operations;
3622 break; 3622 break;
3623 case S_IFLNK: 3623 case S_IFLNK:
3624 inode->i_op = &btrfs_symlink_inode_operations; 3624 inode->i_op = &btrfs_symlink_inode_operations;
3625 inode->i_mapping->a_ops = &btrfs_symlink_aops; 3625 inode->i_mapping->a_ops = &btrfs_symlink_aops;
3626 inode->i_mapping->backing_dev_info = &root->fs_info->bdi; 3626 inode->i_mapping->backing_dev_info = &root->fs_info->bdi;
3627 break; 3627 break;
3628 default: 3628 default:
3629 inode->i_op = &btrfs_special_inode_operations; 3629 inode->i_op = &btrfs_special_inode_operations;
3630 init_special_inode(inode, inode->i_mode, rdev); 3630 init_special_inode(inode, inode->i_mode, rdev);
3631 break; 3631 break;
3632 } 3632 }
3633 3633
3634 btrfs_update_iflags(inode); 3634 btrfs_update_iflags(inode);
3635 return; 3635 return;
3636 3636
3637 make_bad: 3637 make_bad:
3638 btrfs_free_path(path); 3638 btrfs_free_path(path);
3639 make_bad_inode(inode); 3639 make_bad_inode(inode);
3640 } 3640 }
3641 3641
3642 /* 3642 /*
3643 * given a leaf and an inode, copy the inode fields into the leaf 3643 * given a leaf and an inode, copy the inode fields into the leaf
3644 */ 3644 */
3645 static void fill_inode_item(struct btrfs_trans_handle *trans, 3645 static void fill_inode_item(struct btrfs_trans_handle *trans,
3646 struct extent_buffer *leaf, 3646 struct extent_buffer *leaf,
3647 struct btrfs_inode_item *item, 3647 struct btrfs_inode_item *item,
3648 struct inode *inode) 3648 struct inode *inode)
3649 { 3649 {
3650 struct btrfs_map_token token; 3650 struct btrfs_map_token token;
3651 3651
3652 btrfs_init_map_token(&token); 3652 btrfs_init_map_token(&token);
3653 3653
3654 btrfs_set_token_inode_uid(leaf, item, i_uid_read(inode), &token); 3654 btrfs_set_token_inode_uid(leaf, item, i_uid_read(inode), &token);
3655 btrfs_set_token_inode_gid(leaf, item, i_gid_read(inode), &token); 3655 btrfs_set_token_inode_gid(leaf, item, i_gid_read(inode), &token);
3656 btrfs_set_token_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size, 3656 btrfs_set_token_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size,
3657 &token); 3657 &token);
3658 btrfs_set_token_inode_mode(leaf, item, inode->i_mode, &token); 3658 btrfs_set_token_inode_mode(leaf, item, inode->i_mode, &token);
3659 btrfs_set_token_inode_nlink(leaf, item, inode->i_nlink, &token); 3659 btrfs_set_token_inode_nlink(leaf, item, inode->i_nlink, &token);
3660 3660
3661 btrfs_set_token_timespec_sec(leaf, btrfs_inode_atime(item), 3661 btrfs_set_token_timespec_sec(leaf, btrfs_inode_atime(item),
3662 inode->i_atime.tv_sec, &token); 3662 inode->i_atime.tv_sec, &token);
3663 btrfs_set_token_timespec_nsec(leaf, btrfs_inode_atime(item), 3663 btrfs_set_token_timespec_nsec(leaf, btrfs_inode_atime(item),
3664 inode->i_atime.tv_nsec, &token); 3664 inode->i_atime.tv_nsec, &token);
3665 3665
3666 btrfs_set_token_timespec_sec(leaf, btrfs_inode_mtime(item), 3666 btrfs_set_token_timespec_sec(leaf, btrfs_inode_mtime(item),
3667 inode->i_mtime.tv_sec, &token); 3667 inode->i_mtime.tv_sec, &token);
3668 btrfs_set_token_timespec_nsec(leaf, btrfs_inode_mtime(item), 3668 btrfs_set_token_timespec_nsec(leaf, btrfs_inode_mtime(item),
3669 inode->i_mtime.tv_nsec, &token); 3669 inode->i_mtime.tv_nsec, &token);
3670 3670
3671 btrfs_set_token_timespec_sec(leaf, btrfs_inode_ctime(item), 3671 btrfs_set_token_timespec_sec(leaf, btrfs_inode_ctime(item),
3672 inode->i_ctime.tv_sec, &token); 3672 inode->i_ctime.tv_sec, &token);
3673 btrfs_set_token_timespec_nsec(leaf, btrfs_inode_ctime(item), 3673 btrfs_set_token_timespec_nsec(leaf, btrfs_inode_ctime(item),
3674 inode->i_ctime.tv_nsec, &token); 3674 inode->i_ctime.tv_nsec, &token);
3675 3675
3676 btrfs_set_token_inode_nbytes(leaf, item, inode_get_bytes(inode), 3676 btrfs_set_token_inode_nbytes(leaf, item, inode_get_bytes(inode),
3677 &token); 3677 &token);
3678 btrfs_set_token_inode_generation(leaf, item, BTRFS_I(inode)->generation, 3678 btrfs_set_token_inode_generation(leaf, item, BTRFS_I(inode)->generation,
3679 &token); 3679 &token);
3680 btrfs_set_token_inode_sequence(leaf, item, inode->i_version, &token); 3680 btrfs_set_token_inode_sequence(leaf, item, inode->i_version, &token);
3681 btrfs_set_token_inode_transid(leaf, item, trans->transid, &token); 3681 btrfs_set_token_inode_transid(leaf, item, trans->transid, &token);
3682 btrfs_set_token_inode_rdev(leaf, item, inode->i_rdev, &token); 3682 btrfs_set_token_inode_rdev(leaf, item, inode->i_rdev, &token);
3683 btrfs_set_token_inode_flags(leaf, item, BTRFS_I(inode)->flags, &token); 3683 btrfs_set_token_inode_flags(leaf, item, BTRFS_I(inode)->flags, &token);
3684 btrfs_set_token_inode_block_group(leaf, item, 0, &token); 3684 btrfs_set_token_inode_block_group(leaf, item, 0, &token);
3685 } 3685 }
3686 3686
3687 /* 3687 /*
3688 * copy everything in the in-memory inode into the btree. 3688 * copy everything in the in-memory inode into the btree.
3689 */ 3689 */
3690 static noinline int btrfs_update_inode_item(struct btrfs_trans_handle *trans, 3690 static noinline int btrfs_update_inode_item(struct btrfs_trans_handle *trans,
3691 struct btrfs_root *root, struct inode *inode) 3691 struct btrfs_root *root, struct inode *inode)
3692 { 3692 {
3693 struct btrfs_inode_item *inode_item; 3693 struct btrfs_inode_item *inode_item;
3694 struct btrfs_path *path; 3694 struct btrfs_path *path;
3695 struct extent_buffer *leaf; 3695 struct extent_buffer *leaf;
3696 int ret; 3696 int ret;
3697 3697
3698 path = btrfs_alloc_path(); 3698 path = btrfs_alloc_path();
3699 if (!path) 3699 if (!path)
3700 return -ENOMEM; 3700 return -ENOMEM;
3701 3701
3702 path->leave_spinning = 1; 3702 path->leave_spinning = 1;
3703 ret = btrfs_lookup_inode(trans, root, path, &BTRFS_I(inode)->location, 3703 ret = btrfs_lookup_inode(trans, root, path, &BTRFS_I(inode)->location,
3704 1); 3704 1);
3705 if (ret) { 3705 if (ret) {
3706 if (ret > 0) 3706 if (ret > 0)
3707 ret = -ENOENT; 3707 ret = -ENOENT;
3708 goto failed; 3708 goto failed;
3709 } 3709 }
3710 3710
3711 leaf = path->nodes[0]; 3711 leaf = path->nodes[0];
3712 inode_item = btrfs_item_ptr(leaf, path->slots[0], 3712 inode_item = btrfs_item_ptr(leaf, path->slots[0],
3713 struct btrfs_inode_item); 3713 struct btrfs_inode_item);
3714 3714
3715 fill_inode_item(trans, leaf, inode_item, inode); 3715 fill_inode_item(trans, leaf, inode_item, inode);
3716 btrfs_mark_buffer_dirty(leaf); 3716 btrfs_mark_buffer_dirty(leaf);
3717 btrfs_set_inode_last_trans(trans, inode); 3717 btrfs_set_inode_last_trans(trans, inode);
3718 ret = 0; 3718 ret = 0;
3719 failed: 3719 failed:
3720 btrfs_free_path(path); 3720 btrfs_free_path(path);
3721 return ret; 3721 return ret;
3722 } 3722 }
3723 3723
3724 /* 3724 /*
3725 * copy everything in the in-memory inode into the btree. 3725 * copy everything in the in-memory inode into the btree.
3726 */ 3726 */
3727 noinline int btrfs_update_inode(struct btrfs_trans_handle *trans, 3727 noinline int btrfs_update_inode(struct btrfs_trans_handle *trans,
3728 struct btrfs_root *root, struct inode *inode) 3728 struct btrfs_root *root, struct inode *inode)
3729 { 3729 {
3730 int ret; 3730 int ret;
3731 3731
3732 /* 3732 /*
3733 * If the inode is a free space inode, we can deadlock during commit 3733 * If the inode is a free space inode, we can deadlock during commit
3734 * if we put it into the delayed code. 3734 * if we put it into the delayed code.
3735 * 3735 *
3736 * The data relocation inode should also be directly updated 3736 * The data relocation inode should also be directly updated
3737 * without delay 3737 * without delay
3738 */ 3738 */
3739 if (!btrfs_is_free_space_inode(inode) 3739 if (!btrfs_is_free_space_inode(inode)
3740 && root->root_key.objectid != BTRFS_DATA_RELOC_TREE_OBJECTID 3740 && root->root_key.objectid != BTRFS_DATA_RELOC_TREE_OBJECTID
3741 && !root->fs_info->log_root_recovering) { 3741 && !root->fs_info->log_root_recovering) {
3742 btrfs_update_root_times(trans, root); 3742 btrfs_update_root_times(trans, root);
3743 3743
3744 ret = btrfs_delayed_update_inode(trans, root, inode); 3744 ret = btrfs_delayed_update_inode(trans, root, inode);
3745 if (!ret) 3745 if (!ret)
3746 btrfs_set_inode_last_trans(trans, inode); 3746 btrfs_set_inode_last_trans(trans, inode);
3747 return ret; 3747 return ret;
3748 } 3748 }
3749 3749
3750 return btrfs_update_inode_item(trans, root, inode); 3750 return btrfs_update_inode_item(trans, root, inode);
3751 } 3751 }
3752 3752
3753 noinline int btrfs_update_inode_fallback(struct btrfs_trans_handle *trans, 3753 noinline int btrfs_update_inode_fallback(struct btrfs_trans_handle *trans,
3754 struct btrfs_root *root, 3754 struct btrfs_root *root,
3755 struct inode *inode) 3755 struct inode *inode)
3756 { 3756 {
3757 int ret; 3757 int ret;
3758 3758
3759 ret = btrfs_update_inode(trans, root, inode); 3759 ret = btrfs_update_inode(trans, root, inode);
3760 if (ret == -ENOSPC) 3760 if (ret == -ENOSPC)
3761 return btrfs_update_inode_item(trans, root, inode); 3761 return btrfs_update_inode_item(trans, root, inode);
3762 return ret; 3762 return ret;
3763 } 3763 }
3764 3764
3765 /* 3765 /*
3766 * unlink helper that gets used here in inode.c and in the tree logging 3766 * unlink helper that gets used here in inode.c and in the tree logging
3767 * recovery code. It remove a link in a directory with a given name, and 3767 * recovery code. It remove a link in a directory with a given name, and
3768 * also drops the back refs in the inode to the directory 3768 * also drops the back refs in the inode to the directory
3769 */ 3769 */
3770 static int __btrfs_unlink_inode(struct btrfs_trans_handle *trans, 3770 static int __btrfs_unlink_inode(struct btrfs_trans_handle *trans,
3771 struct btrfs_root *root, 3771 struct btrfs_root *root,
3772 struct inode *dir, struct inode *inode, 3772 struct inode *dir, struct inode *inode,
3773 const char *name, int name_len) 3773 const char *name, int name_len)
3774 { 3774 {
3775 struct btrfs_path *path; 3775 struct btrfs_path *path;
3776 int ret = 0; 3776 int ret = 0;
3777 struct extent_buffer *leaf; 3777 struct extent_buffer *leaf;
3778 struct btrfs_dir_item *di; 3778 struct btrfs_dir_item *di;
3779 struct btrfs_key key; 3779 struct btrfs_key key;
3780 u64 index; 3780 u64 index;
3781 u64 ino = btrfs_ino(inode); 3781 u64 ino = btrfs_ino(inode);
3782 u64 dir_ino = btrfs_ino(dir); 3782 u64 dir_ino = btrfs_ino(dir);
3783 3783
3784 path = btrfs_alloc_path(); 3784 path = btrfs_alloc_path();
3785 if (!path) { 3785 if (!path) {
3786 ret = -ENOMEM; 3786 ret = -ENOMEM;
3787 goto out; 3787 goto out;
3788 } 3788 }
3789 3789
3790 path->leave_spinning = 1; 3790 path->leave_spinning = 1;
3791 di = btrfs_lookup_dir_item(trans, root, path, dir_ino, 3791 di = btrfs_lookup_dir_item(trans, root, path, dir_ino,
3792 name, name_len, -1); 3792 name, name_len, -1);
3793 if (IS_ERR(di)) { 3793 if (IS_ERR(di)) {
3794 ret = PTR_ERR(di); 3794 ret = PTR_ERR(di);
3795 goto err; 3795 goto err;
3796 } 3796 }
3797 if (!di) { 3797 if (!di) {
3798 ret = -ENOENT; 3798 ret = -ENOENT;
3799 goto err; 3799 goto err;
3800 } 3800 }
3801 leaf = path->nodes[0]; 3801 leaf = path->nodes[0];
3802 btrfs_dir_item_key_to_cpu(leaf, di, &key); 3802 btrfs_dir_item_key_to_cpu(leaf, di, &key);
3803 ret = btrfs_delete_one_dir_name(trans, root, path, di); 3803 ret = btrfs_delete_one_dir_name(trans, root, path, di);
3804 if (ret) 3804 if (ret)
3805 goto err; 3805 goto err;
3806 btrfs_release_path(path); 3806 btrfs_release_path(path);
3807 3807
3808 /* 3808 /*
3809 * If we don't have dir index, we have to get it by looking up 3809 * If we don't have dir index, we have to get it by looking up
3810 * the inode ref, since we get the inode ref, remove it directly, 3810 * the inode ref, since we get the inode ref, remove it directly,
3811 * it is unnecessary to do delayed deletion. 3811 * it is unnecessary to do delayed deletion.
3812 * 3812 *
3813 * But if we have dir index, needn't search inode ref to get it. 3813 * But if we have dir index, needn't search inode ref to get it.
3814 * Since the inode ref is close to the inode item, it is better 3814 * Since the inode ref is close to the inode item, it is better
3815 * that we delay to delete it, and just do this deletion when 3815 * that we delay to delete it, and just do this deletion when
3816 * we update the inode item. 3816 * we update the inode item.
3817 */ 3817 */
3818 if (BTRFS_I(inode)->dir_index) { 3818 if (BTRFS_I(inode)->dir_index) {
3819 ret = btrfs_delayed_delete_inode_ref(inode); 3819 ret = btrfs_delayed_delete_inode_ref(inode);
3820 if (!ret) { 3820 if (!ret) {
3821 index = BTRFS_I(inode)->dir_index; 3821 index = BTRFS_I(inode)->dir_index;
3822 goto skip_backref; 3822 goto skip_backref;
3823 } 3823 }
3824 } 3824 }
3825 3825
3826 ret = btrfs_del_inode_ref(trans, root, name, name_len, ino, 3826 ret = btrfs_del_inode_ref(trans, root, name, name_len, ino,
3827 dir_ino, &index); 3827 dir_ino, &index);
3828 if (ret) { 3828 if (ret) {
3829 btrfs_info(root->fs_info, 3829 btrfs_info(root->fs_info,
3830 "failed to delete reference to %.*s, inode %llu parent %llu", 3830 "failed to delete reference to %.*s, inode %llu parent %llu",
3831 name_len, name, ino, dir_ino); 3831 name_len, name, ino, dir_ino);
3832 btrfs_abort_transaction(trans, root, ret); 3832 btrfs_abort_transaction(trans, root, ret);
3833 goto err; 3833 goto err;
3834 } 3834 }
3835 skip_backref: 3835 skip_backref:
3836 ret = btrfs_delete_delayed_dir_index(trans, root, dir, index); 3836 ret = btrfs_delete_delayed_dir_index(trans, root, dir, index);
3837 if (ret) { 3837 if (ret) {
3838 btrfs_abort_transaction(trans, root, ret); 3838 btrfs_abort_transaction(trans, root, ret);
3839 goto err; 3839 goto err;
3840 } 3840 }
3841 3841
3842 ret = btrfs_del_inode_ref_in_log(trans, root, name, name_len, 3842 ret = btrfs_del_inode_ref_in_log(trans, root, name, name_len,
3843 inode, dir_ino); 3843 inode, dir_ino);
3844 if (ret != 0 && ret != -ENOENT) { 3844 if (ret != 0 && ret != -ENOENT) {
3845 btrfs_abort_transaction(trans, root, ret); 3845 btrfs_abort_transaction(trans, root, ret);
3846 goto err; 3846 goto err;
3847 } 3847 }
3848 3848
3849 ret = btrfs_del_dir_entries_in_log(trans, root, name, name_len, 3849 ret = btrfs_del_dir_entries_in_log(trans, root, name, name_len,
3850 dir, index); 3850 dir, index);
3851 if (ret == -ENOENT) 3851 if (ret == -ENOENT)
3852 ret = 0; 3852 ret = 0;
3853 else if (ret) 3853 else if (ret)
3854 btrfs_abort_transaction(trans, root, ret); 3854 btrfs_abort_transaction(trans, root, ret);
3855 err: 3855 err:
3856 btrfs_free_path(path); 3856 btrfs_free_path(path);
3857 if (ret) 3857 if (ret)
3858 goto out; 3858 goto out;
3859 3859
3860 btrfs_i_size_write(dir, dir->i_size - name_len * 2); 3860 btrfs_i_size_write(dir, dir->i_size - name_len * 2);
3861 inode_inc_iversion(inode); 3861 inode_inc_iversion(inode);
3862 inode_inc_iversion(dir); 3862 inode_inc_iversion(dir);
3863 inode->i_ctime = dir->i_mtime = dir->i_ctime = CURRENT_TIME; 3863 inode->i_ctime = dir->i_mtime = dir->i_ctime = CURRENT_TIME;
3864 ret = btrfs_update_inode(trans, root, dir); 3864 ret = btrfs_update_inode(trans, root, dir);
3865 out: 3865 out:
3866 return ret; 3866 return ret;
3867 } 3867 }
3868 3868
3869 int btrfs_unlink_inode(struct btrfs_trans_handle *trans, 3869 int btrfs_unlink_inode(struct btrfs_trans_handle *trans,
3870 struct btrfs_root *root, 3870 struct btrfs_root *root,
3871 struct inode *dir, struct inode *inode, 3871 struct inode *dir, struct inode *inode,
3872 const char *name, int name_len) 3872 const char *name, int name_len)
3873 { 3873 {
3874 int ret; 3874 int ret;
3875 ret = __btrfs_unlink_inode(trans, root, dir, inode, name, name_len); 3875 ret = __btrfs_unlink_inode(trans, root, dir, inode, name, name_len);
3876 if (!ret) { 3876 if (!ret) {
3877 drop_nlink(inode); 3877 drop_nlink(inode);
3878 ret = btrfs_update_inode(trans, root, inode); 3878 ret = btrfs_update_inode(trans, root, inode);
3879 } 3879 }
3880 return ret; 3880 return ret;
3881 } 3881 }
3882 3882
3883 /* 3883 /*
3884 * helper to start transaction for unlink and rmdir. 3884 * helper to start transaction for unlink and rmdir.
3885 * 3885 *
3886 * unlink and rmdir are special in btrfs, they do not always free space, so 3886 * unlink and rmdir are special in btrfs, they do not always free space, so
3887 * if we cannot make our reservations the normal way try and see if there is 3887 * if we cannot make our reservations the normal way try and see if there is
3888 * plenty of slack room in the global reserve to migrate, otherwise we cannot 3888 * plenty of slack room in the global reserve to migrate, otherwise we cannot
3889 * allow the unlink to occur. 3889 * allow the unlink to occur.
3890 */ 3890 */
3891 static struct btrfs_trans_handle *__unlink_start_trans(struct inode *dir) 3891 static struct btrfs_trans_handle *__unlink_start_trans(struct inode *dir)
3892 { 3892 {
3893 struct btrfs_trans_handle *trans; 3893 struct btrfs_trans_handle *trans;
3894 struct btrfs_root *root = BTRFS_I(dir)->root; 3894 struct btrfs_root *root = BTRFS_I(dir)->root;
3895 int ret; 3895 int ret;
3896 3896
3897 /* 3897 /*
3898 * 1 for the possible orphan item 3898 * 1 for the possible orphan item
3899 * 1 for the dir item 3899 * 1 for the dir item
3900 * 1 for the dir index 3900 * 1 for the dir index
3901 * 1 for the inode ref 3901 * 1 for the inode ref
3902 * 1 for the inode 3902 * 1 for the inode
3903 */ 3903 */
3904 trans = btrfs_start_transaction(root, 5); 3904 trans = btrfs_start_transaction(root, 5);
3905 if (!IS_ERR(trans) || PTR_ERR(trans) != -ENOSPC) 3905 if (!IS_ERR(trans) || PTR_ERR(trans) != -ENOSPC)
3906 return trans; 3906 return trans;
3907 3907
3908 if (PTR_ERR(trans) == -ENOSPC) { 3908 if (PTR_ERR(trans) == -ENOSPC) {
3909 u64 num_bytes = btrfs_calc_trans_metadata_size(root, 5); 3909 u64 num_bytes = btrfs_calc_trans_metadata_size(root, 5);
3910 3910
3911 trans = btrfs_start_transaction(root, 0); 3911 trans = btrfs_start_transaction(root, 0);
3912 if (IS_ERR(trans)) 3912 if (IS_ERR(trans))
3913 return trans; 3913 return trans;
3914 ret = btrfs_cond_migrate_bytes(root->fs_info, 3914 ret = btrfs_cond_migrate_bytes(root->fs_info,
3915 &root->fs_info->trans_block_rsv, 3915 &root->fs_info->trans_block_rsv,
3916 num_bytes, 5); 3916 num_bytes, 5);
3917 if (ret) { 3917 if (ret) {
3918 btrfs_end_transaction(trans, root); 3918 btrfs_end_transaction(trans, root);
3919 return ERR_PTR(ret); 3919 return ERR_PTR(ret);
3920 } 3920 }
3921 trans->block_rsv = &root->fs_info->trans_block_rsv; 3921 trans->block_rsv = &root->fs_info->trans_block_rsv;
3922 trans->bytes_reserved = num_bytes; 3922 trans->bytes_reserved = num_bytes;
3923 } 3923 }
3924 return trans; 3924 return trans;
3925 } 3925 }
3926 3926
3927 static int btrfs_unlink(struct inode *dir, struct dentry *dentry) 3927 static int btrfs_unlink(struct inode *dir, struct dentry *dentry)
3928 { 3928 {
3929 struct btrfs_root *root = BTRFS_I(dir)->root; 3929 struct btrfs_root *root = BTRFS_I(dir)->root;
3930 struct btrfs_trans_handle *trans; 3930 struct btrfs_trans_handle *trans;
3931 struct inode *inode = dentry->d_inode; 3931 struct inode *inode = dentry->d_inode;
3932 int ret; 3932 int ret;
3933 3933
3934 trans = __unlink_start_trans(dir); 3934 trans = __unlink_start_trans(dir);
3935 if (IS_ERR(trans)) 3935 if (IS_ERR(trans))
3936 return PTR_ERR(trans); 3936 return PTR_ERR(trans);
3937 3937
3938 btrfs_record_unlink_dir(trans, dir, dentry->d_inode, 0); 3938 btrfs_record_unlink_dir(trans, dir, dentry->d_inode, 0);
3939 3939
3940 ret = btrfs_unlink_inode(trans, root, dir, dentry->d_inode, 3940 ret = btrfs_unlink_inode(trans, root, dir, dentry->d_inode,
3941 dentry->d_name.name, dentry->d_name.len); 3941 dentry->d_name.name, dentry->d_name.len);
3942 if (ret) 3942 if (ret)
3943 goto out; 3943 goto out;
3944 3944
3945 if (inode->i_nlink == 0) { 3945 if (inode->i_nlink == 0) {
3946 ret = btrfs_orphan_add(trans, inode); 3946 ret = btrfs_orphan_add(trans, inode);
3947 if (ret) 3947 if (ret)
3948 goto out; 3948 goto out;
3949 } 3949 }
3950 3950
3951 out: 3951 out:
3952 btrfs_end_transaction(trans, root); 3952 btrfs_end_transaction(trans, root);
3953 btrfs_btree_balance_dirty(root); 3953 btrfs_btree_balance_dirty(root);
3954 return ret; 3954 return ret;
3955 } 3955 }
3956 3956
3957 int btrfs_unlink_subvol(struct btrfs_trans_handle *trans, 3957 int btrfs_unlink_subvol(struct btrfs_trans_handle *trans,
3958 struct btrfs_root *root, 3958 struct btrfs_root *root,
3959 struct inode *dir, u64 objectid, 3959 struct inode *dir, u64 objectid,
3960 const char *name, int name_len) 3960 const char *name, int name_len)
3961 { 3961 {
3962 struct btrfs_path *path; 3962 struct btrfs_path *path;
3963 struct extent_buffer *leaf; 3963 struct extent_buffer *leaf;
3964 struct btrfs_dir_item *di; 3964 struct btrfs_dir_item *di;
3965 struct btrfs_key key; 3965 struct btrfs_key key;
3966 u64 index; 3966 u64 index;
3967 int ret; 3967 int ret;
3968 u64 dir_ino = btrfs_ino(dir); 3968 u64 dir_ino = btrfs_ino(dir);
3969 3969
3970 path = btrfs_alloc_path(); 3970 path = btrfs_alloc_path();
3971 if (!path) 3971 if (!path)
3972 return -ENOMEM; 3972 return -ENOMEM;
3973 3973
3974 di = btrfs_lookup_dir_item(trans, root, path, dir_ino, 3974 di = btrfs_lookup_dir_item(trans, root, path, dir_ino,
3975 name, name_len, -1); 3975 name, name_len, -1);
3976 if (IS_ERR_OR_NULL(di)) { 3976 if (IS_ERR_OR_NULL(di)) {
3977 if (!di) 3977 if (!di)
3978 ret = -ENOENT; 3978 ret = -ENOENT;
3979 else 3979 else
3980 ret = PTR_ERR(di); 3980 ret = PTR_ERR(di);
3981 goto out; 3981 goto out;
3982 } 3982 }
3983 3983
3984 leaf = path->nodes[0]; 3984 leaf = path->nodes[0];
3985 btrfs_dir_item_key_to_cpu(leaf, di, &key); 3985 btrfs_dir_item_key_to_cpu(leaf, di, &key);
3986 WARN_ON(key.type != BTRFS_ROOT_ITEM_KEY || key.objectid != objectid); 3986 WARN_ON(key.type != BTRFS_ROOT_ITEM_KEY || key.objectid != objectid);
3987 ret = btrfs_delete_one_dir_name(trans, root, path, di); 3987 ret = btrfs_delete_one_dir_name(trans, root, path, di);
3988 if (ret) { 3988 if (ret) {
3989 btrfs_abort_transaction(trans, root, ret); 3989 btrfs_abort_transaction(trans, root, ret);
3990 goto out; 3990 goto out;
3991 } 3991 }
3992 btrfs_release_path(path); 3992 btrfs_release_path(path);
3993 3993
3994 ret = btrfs_del_root_ref(trans, root->fs_info->tree_root, 3994 ret = btrfs_del_root_ref(trans, root->fs_info->tree_root,
3995 objectid, root->root_key.objectid, 3995 objectid, root->root_key.objectid,
3996 dir_ino, &index, name, name_len); 3996 dir_ino, &index, name, name_len);
3997 if (ret < 0) { 3997 if (ret < 0) {
3998 if (ret != -ENOENT) { 3998 if (ret != -ENOENT) {
3999 btrfs_abort_transaction(trans, root, ret); 3999 btrfs_abort_transaction(trans, root, ret);
4000 goto out; 4000 goto out;
4001 } 4001 }
4002 di = btrfs_search_dir_index_item(root, path, dir_ino, 4002 di = btrfs_search_dir_index_item(root, path, dir_ino,
4003 name, name_len); 4003 name, name_len);
4004 if (IS_ERR_OR_NULL(di)) { 4004 if (IS_ERR_OR_NULL(di)) {
4005 if (!di) 4005 if (!di)
4006 ret = -ENOENT; 4006 ret = -ENOENT;
4007 else 4007 else
4008 ret = PTR_ERR(di); 4008 ret = PTR_ERR(di);
4009 btrfs_abort_transaction(trans, root, ret); 4009 btrfs_abort_transaction(trans, root, ret);
4010 goto out; 4010 goto out;
4011 } 4011 }
4012 4012
4013 leaf = path->nodes[0]; 4013 leaf = path->nodes[0];
4014 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); 4014 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
4015 btrfs_release_path(path); 4015 btrfs_release_path(path);
4016 index = key.offset; 4016 index = key.offset;
4017 } 4017 }
4018 btrfs_release_path(path); 4018 btrfs_release_path(path);
4019 4019
4020 ret = btrfs_delete_delayed_dir_index(trans, root, dir, index); 4020 ret = btrfs_delete_delayed_dir_index(trans, root, dir, index);
4021 if (ret) { 4021 if (ret) {
4022 btrfs_abort_transaction(trans, root, ret); 4022 btrfs_abort_transaction(trans, root, ret);
4023 goto out; 4023 goto out;
4024 } 4024 }
4025 4025
4026 btrfs_i_size_write(dir, dir->i_size - name_len * 2); 4026 btrfs_i_size_write(dir, dir->i_size - name_len * 2);
4027 inode_inc_iversion(dir); 4027 inode_inc_iversion(dir);
4028 dir->i_mtime = dir->i_ctime = CURRENT_TIME; 4028 dir->i_mtime = dir->i_ctime = CURRENT_TIME;
4029 ret = btrfs_update_inode_fallback(trans, root, dir); 4029 ret = btrfs_update_inode_fallback(trans, root, dir);
4030 if (ret) 4030 if (ret)
4031 btrfs_abort_transaction(trans, root, ret); 4031 btrfs_abort_transaction(trans, root, ret);
4032 out: 4032 out:
4033 btrfs_free_path(path); 4033 btrfs_free_path(path);
4034 return ret; 4034 return ret;
4035 } 4035 }
4036 4036
4037 static int btrfs_rmdir(struct inode *dir, struct dentry *dentry) 4037 static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
4038 { 4038 {
4039 struct inode *inode = dentry->d_inode; 4039 struct inode *inode = dentry->d_inode;
4040 int err = 0; 4040 int err = 0;
4041 struct btrfs_root *root = BTRFS_I(dir)->root; 4041 struct btrfs_root *root = BTRFS_I(dir)->root;
4042 struct btrfs_trans_handle *trans; 4042 struct btrfs_trans_handle *trans;
4043 4043
4044 if (inode->i_size > BTRFS_EMPTY_DIR_SIZE) 4044 if (inode->i_size > BTRFS_EMPTY_DIR_SIZE)
4045 return -ENOTEMPTY; 4045 return -ENOTEMPTY;
4046 if (btrfs_ino(inode) == BTRFS_FIRST_FREE_OBJECTID) 4046 if (btrfs_ino(inode) == BTRFS_FIRST_FREE_OBJECTID)
4047 return -EPERM; 4047 return -EPERM;
4048 4048
4049 trans = __unlink_start_trans(dir); 4049 trans = __unlink_start_trans(dir);
4050 if (IS_ERR(trans)) 4050 if (IS_ERR(trans))
4051 return PTR_ERR(trans); 4051 return PTR_ERR(trans);
4052 4052
4053 if (unlikely(btrfs_ino(inode) == BTRFS_EMPTY_SUBVOL_DIR_OBJECTID)) { 4053 if (unlikely(btrfs_ino(inode) == BTRFS_EMPTY_SUBVOL_DIR_OBJECTID)) {
4054 err = btrfs_unlink_subvol(trans, root, dir, 4054 err = btrfs_unlink_subvol(trans, root, dir,
4055 BTRFS_I(inode)->location.objectid, 4055 BTRFS_I(inode)->location.objectid,
4056 dentry->d_name.name, 4056 dentry->d_name.name,
4057 dentry->d_name.len); 4057 dentry->d_name.len);
4058 goto out; 4058 goto out;
4059 } 4059 }
4060 4060
4061 err = btrfs_orphan_add(trans, inode); 4061 err = btrfs_orphan_add(trans, inode);
4062 if (err) 4062 if (err)
4063 goto out; 4063 goto out;
4064 4064
4065 /* now the directory is empty */ 4065 /* now the directory is empty */
4066 err = btrfs_unlink_inode(trans, root, dir, dentry->d_inode, 4066 err = btrfs_unlink_inode(trans, root, dir, dentry->d_inode,
4067 dentry->d_name.name, dentry->d_name.len); 4067 dentry->d_name.name, dentry->d_name.len);
4068 if (!err) 4068 if (!err)
4069 btrfs_i_size_write(inode, 0); 4069 btrfs_i_size_write(inode, 0);
4070 out: 4070 out:
4071 btrfs_end_transaction(trans, root); 4071 btrfs_end_transaction(trans, root);
4072 btrfs_btree_balance_dirty(root); 4072 btrfs_btree_balance_dirty(root);
4073 4073
4074 return err; 4074 return err;
4075 } 4075 }
4076 4076
4077 /* 4077 /*
4078 * this can truncate away extent items, csum items and directory items. 4078 * this can truncate away extent items, csum items and directory items.
4079 * It starts at a high offset and removes keys until it can't find 4079 * It starts at a high offset and removes keys until it can't find
4080 * any higher than new_size 4080 * any higher than new_size
4081 * 4081 *
4082 * csum items that cross the new i_size are truncated to the new size 4082 * csum items that cross the new i_size are truncated to the new size
4083 * as well. 4083 * as well.
4084 * 4084 *
4085 * min_type is the minimum key type to truncate down to. If set to 0, this 4085 * min_type is the minimum key type to truncate down to. If set to 0, this
4086 * will kill all the items on this inode, including the INODE_ITEM_KEY. 4086 * will kill all the items on this inode, including the INODE_ITEM_KEY.
4087 */ 4087 */
4088 int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, 4088 int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
4089 struct btrfs_root *root, 4089 struct btrfs_root *root,
4090 struct inode *inode, 4090 struct inode *inode,
4091 u64 new_size, u32 min_type) 4091 u64 new_size, u32 min_type)
4092 { 4092 {
4093 struct btrfs_path *path; 4093 struct btrfs_path *path;
4094 struct extent_buffer *leaf; 4094 struct extent_buffer *leaf;
4095 struct btrfs_file_extent_item *fi; 4095 struct btrfs_file_extent_item *fi;
4096 struct btrfs_key key; 4096 struct btrfs_key key;
4097 struct btrfs_key found_key; 4097 struct btrfs_key found_key;
4098 u64 extent_start = 0; 4098 u64 extent_start = 0;
4099 u64 extent_num_bytes = 0; 4099 u64 extent_num_bytes = 0;
4100 u64 extent_offset = 0; 4100 u64 extent_offset = 0;
4101 u64 item_end = 0; 4101 u64 item_end = 0;
4102 u64 last_size = (u64)-1; 4102 u64 last_size = (u64)-1;
4103 u32 found_type = (u8)-1; 4103 u32 found_type = (u8)-1;
4104 int found_extent; 4104 int found_extent;
4105 int del_item; 4105 int del_item;
4106 int pending_del_nr = 0; 4106 int pending_del_nr = 0;
4107 int pending_del_slot = 0; 4107 int pending_del_slot = 0;
4108 int extent_type = -1; 4108 int extent_type = -1;
4109 int ret; 4109 int ret;
4110 int err = 0; 4110 int err = 0;
4111 u64 ino = btrfs_ino(inode); 4111 u64 ino = btrfs_ino(inode);
4112 4112
4113 BUG_ON(new_size > 0 && min_type != BTRFS_EXTENT_DATA_KEY); 4113 BUG_ON(new_size > 0 && min_type != BTRFS_EXTENT_DATA_KEY);
4114 4114
4115 path = btrfs_alloc_path(); 4115 path = btrfs_alloc_path();
4116 if (!path) 4116 if (!path)
4117 return -ENOMEM; 4117 return -ENOMEM;
4118 path->reada = -1; 4118 path->reada = -1;
4119 4119
4120 /* 4120 /*
4121 * We want to drop from the next block forward in case this new size is 4121 * We want to drop from the next block forward in case this new size is
4122 * not block aligned since we will be keeping the last block of the 4122 * not block aligned since we will be keeping the last block of the
4123 * extent just the way it is. 4123 * extent just the way it is.
4124 */ 4124 */
4125 if (test_bit(BTRFS_ROOT_REF_COWS, &root->state) || 4125 if (test_bit(BTRFS_ROOT_REF_COWS, &root->state) ||
4126 root == root->fs_info->tree_root) 4126 root == root->fs_info->tree_root)
4127 btrfs_drop_extent_cache(inode, ALIGN(new_size, 4127 btrfs_drop_extent_cache(inode, ALIGN(new_size,
4128 root->sectorsize), (u64)-1, 0); 4128 root->sectorsize), (u64)-1, 0);
4129 4129
4130 /* 4130 /*
4131 * This function is also used to drop the items in the log tree before 4131 * This function is also used to drop the items in the log tree before
4132 * we relog the inode, so if root != BTRFS_I(inode)->root, it means 4132 * we relog the inode, so if root != BTRFS_I(inode)->root, it means
4133 * it is used to drop the loged items. So we shouldn't kill the delayed 4133 * it is used to drop the loged items. So we shouldn't kill the delayed
4134 * items. 4134 * items.
4135 */ 4135 */
4136 if (min_type == 0 && root == BTRFS_I(inode)->root) 4136 if (min_type == 0 && root == BTRFS_I(inode)->root)
4137 btrfs_kill_delayed_inode_items(inode); 4137 btrfs_kill_delayed_inode_items(inode);
4138 4138
4139 key.objectid = ino; 4139 key.objectid = ino;
4140 key.offset = (u64)-1; 4140 key.offset = (u64)-1;
4141 key.type = (u8)-1; 4141 key.type = (u8)-1;
4142 4142
4143 search_again: 4143 search_again:
4144 path->leave_spinning = 1; 4144 path->leave_spinning = 1;
4145 ret = btrfs_search_slot(trans, root, &key, path, -1, 1); 4145 ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
4146 if (ret < 0) { 4146 if (ret < 0) {
4147 err = ret; 4147 err = ret;
4148 goto out; 4148 goto out;
4149 } 4149 }
4150 4150
4151 if (ret > 0) { 4151 if (ret > 0) {
4152 /* there are no items in the tree for us to truncate, we're 4152 /* there are no items in the tree for us to truncate, we're
4153 * done 4153 * done
4154 */ 4154 */
4155 if (path->slots[0] == 0) 4155 if (path->slots[0] == 0)
4156 goto out; 4156 goto out;
4157 path->slots[0]--; 4157 path->slots[0]--;
4158 } 4158 }
4159 4159
4160 while (1) { 4160 while (1) {
4161 fi = NULL; 4161 fi = NULL;
4162 leaf = path->nodes[0]; 4162 leaf = path->nodes[0];
4163 btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]); 4163 btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]);
4164 found_type = found_key.type; 4164 found_type = found_key.type;
4165 4165
4166 if (found_key.objectid != ino) 4166 if (found_key.objectid != ino)
4167 break; 4167 break;
4168 4168
4169 if (found_type < min_type) 4169 if (found_type < min_type)
4170 break; 4170 break;
4171 4171
4172 item_end = found_key.offset; 4172 item_end = found_key.offset;
4173 if (found_type == BTRFS_EXTENT_DATA_KEY) { 4173 if (found_type == BTRFS_EXTENT_DATA_KEY) {
4174 fi = btrfs_item_ptr(leaf, path->slots[0], 4174 fi = btrfs_item_ptr(leaf, path->slots[0],
4175 struct btrfs_file_extent_item); 4175 struct btrfs_file_extent_item);
4176 extent_type = btrfs_file_extent_type(leaf, fi); 4176 extent_type = btrfs_file_extent_type(leaf, fi);
4177 if (extent_type != BTRFS_FILE_EXTENT_INLINE) { 4177 if (extent_type != BTRFS_FILE_EXTENT_INLINE) {
4178 item_end += 4178 item_end +=
4179 btrfs_file_extent_num_bytes(leaf, fi); 4179 btrfs_file_extent_num_bytes(leaf, fi);
4180 } else if (extent_type == BTRFS_FILE_EXTENT_INLINE) { 4180 } else if (extent_type == BTRFS_FILE_EXTENT_INLINE) {
4181 item_end += btrfs_file_extent_inline_len(leaf, 4181 item_end += btrfs_file_extent_inline_len(leaf,
4182 path->slots[0], fi); 4182 path->slots[0], fi);
4183 } 4183 }
4184 item_end--; 4184 item_end--;
4185 } 4185 }
4186 if (found_type > min_type) { 4186 if (found_type > min_type) {
4187 del_item = 1; 4187 del_item = 1;
4188 } else { 4188 } else {
4189 if (item_end < new_size) 4189 if (item_end < new_size)
4190 break; 4190 break;
4191 if (found_key.offset >= new_size) 4191 if (found_key.offset >= new_size)
4192 del_item = 1; 4192 del_item = 1;
4193 else 4193 else
4194 del_item = 0; 4194 del_item = 0;
4195 } 4195 }
4196 found_extent = 0; 4196 found_extent = 0;
4197 /* FIXME, shrink the extent if the ref count is only 1 */ 4197 /* FIXME, shrink the extent if the ref count is only 1 */
4198 if (found_type != BTRFS_EXTENT_DATA_KEY) 4198 if (found_type != BTRFS_EXTENT_DATA_KEY)
4199 goto delete; 4199 goto delete;
4200 4200
4201 if (del_item) 4201 if (del_item)
4202 last_size = found_key.offset; 4202 last_size = found_key.offset;
4203 else 4203 else
4204 last_size = new_size; 4204 last_size = new_size;
4205 4205
4206 if (extent_type != BTRFS_FILE_EXTENT_INLINE) { 4206 if (extent_type != BTRFS_FILE_EXTENT_INLINE) {
4207 u64 num_dec; 4207 u64 num_dec;
4208 extent_start = btrfs_file_extent_disk_bytenr(leaf, fi); 4208 extent_start = btrfs_file_extent_disk_bytenr(leaf, fi);
4209 if (!del_item) { 4209 if (!del_item) {
4210 u64 orig_num_bytes = 4210 u64 orig_num_bytes =
4211 btrfs_file_extent_num_bytes(leaf, fi); 4211 btrfs_file_extent_num_bytes(leaf, fi);
4212 extent_num_bytes = ALIGN(new_size - 4212 extent_num_bytes = ALIGN(new_size -
4213 found_key.offset, 4213 found_key.offset,
4214 root->sectorsize); 4214 root->sectorsize);
4215 btrfs_set_file_extent_num_bytes(leaf, fi, 4215 btrfs_set_file_extent_num_bytes(leaf, fi,
4216 extent_num_bytes); 4216 extent_num_bytes);
4217 num_dec = (orig_num_bytes - 4217 num_dec = (orig_num_bytes -
4218 extent_num_bytes); 4218 extent_num_bytes);
4219 if (test_bit(BTRFS_ROOT_REF_COWS, 4219 if (test_bit(BTRFS_ROOT_REF_COWS,
4220 &root->state) && 4220 &root->state) &&
4221 extent_start != 0) 4221 extent_start != 0)
4222 inode_sub_bytes(inode, num_dec); 4222 inode_sub_bytes(inode, num_dec);
4223 btrfs_mark_buffer_dirty(leaf); 4223 btrfs_mark_buffer_dirty(leaf);
4224 } else { 4224 } else {
4225 extent_num_bytes = 4225 extent_num_bytes =
4226 btrfs_file_extent_disk_num_bytes(leaf, 4226 btrfs_file_extent_disk_num_bytes(leaf,
4227 fi); 4227 fi);
4228 extent_offset = found_key.offset - 4228 extent_offset = found_key.offset -
4229 btrfs_file_extent_offset(leaf, fi); 4229 btrfs_file_extent_offset(leaf, fi);
4230 4230
4231 /* FIXME blocksize != 4096 */ 4231 /* FIXME blocksize != 4096 */
4232 num_dec = btrfs_file_extent_num_bytes(leaf, fi); 4232 num_dec = btrfs_file_extent_num_bytes(leaf, fi);
4233 if (extent_start != 0) { 4233 if (extent_start != 0) {
4234 found_extent = 1; 4234 found_extent = 1;
4235 if (test_bit(BTRFS_ROOT_REF_COWS, 4235 if (test_bit(BTRFS_ROOT_REF_COWS,
4236 &root->state)) 4236 &root->state))
4237 inode_sub_bytes(inode, num_dec); 4237 inode_sub_bytes(inode, num_dec);
4238 } 4238 }
4239 } 4239 }
4240 } else if (extent_type == BTRFS_FILE_EXTENT_INLINE) { 4240 } else if (extent_type == BTRFS_FILE_EXTENT_INLINE) {
4241 /* 4241 /*
4242 * we can't truncate inline items that have had 4242 * we can't truncate inline items that have had
4243 * special encodings 4243 * special encodings
4244 */ 4244 */
4245 if (!del_item && 4245 if (!del_item &&
4246 btrfs_file_extent_compression(leaf, fi) == 0 && 4246 btrfs_file_extent_compression(leaf, fi) == 0 &&
4247 btrfs_file_extent_encryption(leaf, fi) == 0 && 4247 btrfs_file_extent_encryption(leaf, fi) == 0 &&
4248 btrfs_file_extent_other_encoding(leaf, fi) == 0) { 4248 btrfs_file_extent_other_encoding(leaf, fi) == 0) {
4249 u32 size = new_size - found_key.offset; 4249 u32 size = new_size - found_key.offset;
4250 4250
4251 if (test_bit(BTRFS_ROOT_REF_COWS, &root->state)) 4251 if (test_bit(BTRFS_ROOT_REF_COWS, &root->state))
4252 inode_sub_bytes(inode, item_end + 1 - 4252 inode_sub_bytes(inode, item_end + 1 -
4253 new_size); 4253 new_size);
4254 4254
4255 /* 4255 /*
4256 * update the ram bytes to properly reflect 4256 * update the ram bytes to properly reflect
4257 * the new size of our item 4257 * the new size of our item
4258 */ 4258 */
4259 btrfs_set_file_extent_ram_bytes(leaf, fi, size); 4259 btrfs_set_file_extent_ram_bytes(leaf, fi, size);
4260 size = 4260 size =
4261 btrfs_file_extent_calc_inline_size(size); 4261 btrfs_file_extent_calc_inline_size(size);
4262 btrfs_truncate_item(root, path, size, 1); 4262 btrfs_truncate_item(root, path, size, 1);
4263 } else if (test_bit(BTRFS_ROOT_REF_COWS, 4263 } else if (test_bit(BTRFS_ROOT_REF_COWS,
4264 &root->state)) { 4264 &root->state)) {
4265 inode_sub_bytes(inode, item_end + 1 - 4265 inode_sub_bytes(inode, item_end + 1 -
4266 found_key.offset); 4266 found_key.offset);
4267 } 4267 }
4268 } 4268 }
4269 delete: 4269 delete:
4270 if (del_item) { 4270 if (del_item) {
4271 if (!pending_del_nr) { 4271 if (!pending_del_nr) {
4272 /* no pending yet, add ourselves */ 4272 /* no pending yet, add ourselves */
4273 pending_del_slot = path->slots[0]; 4273 pending_del_slot = path->slots[0];
4274 pending_del_nr = 1; 4274 pending_del_nr = 1;
4275 } else if (pending_del_nr && 4275 } else if (pending_del_nr &&
4276 path->slots[0] + 1 == pending_del_slot) { 4276 path->slots[0] + 1 == pending_del_slot) {
4277 /* hop on the pending chunk */ 4277 /* hop on the pending chunk */
4278 pending_del_nr++; 4278 pending_del_nr++;
4279 pending_del_slot = path->slots[0]; 4279 pending_del_slot = path->slots[0];
4280 } else { 4280 } else {
4281 BUG(); 4281 BUG();
4282 } 4282 }
4283 } else { 4283 } else {
4284 break; 4284 break;
4285 } 4285 }
4286 if (found_extent && 4286 if (found_extent &&
4287 (test_bit(BTRFS_ROOT_REF_COWS, &root->state) || 4287 (test_bit(BTRFS_ROOT_REF_COWS, &root->state) ||
4288 root == root->fs_info->tree_root)) { 4288 root == root->fs_info->tree_root)) {
4289 btrfs_set_path_blocking(path); 4289 btrfs_set_path_blocking(path);
4290 ret = btrfs_free_extent(trans, root, extent_start, 4290 ret = btrfs_free_extent(trans, root, extent_start,
4291 extent_num_bytes, 0, 4291 extent_num_bytes, 0,
4292 btrfs_header_owner(leaf), 4292 btrfs_header_owner(leaf),
4293 ino, extent_offset, 0); 4293 ino, extent_offset, 0);
4294 BUG_ON(ret); 4294 BUG_ON(ret);
4295 } 4295 }
4296 4296
4297 if (found_type == BTRFS_INODE_ITEM_KEY) 4297 if (found_type == BTRFS_INODE_ITEM_KEY)
4298 break; 4298 break;
4299 4299
4300 if (path->slots[0] == 0 || 4300 if (path->slots[0] == 0 ||
4301 path->slots[0] != pending_del_slot) { 4301 path->slots[0] != pending_del_slot) {
4302 if (pending_del_nr) { 4302 if (pending_del_nr) {
4303 ret = btrfs_del_items(trans, root, path, 4303 ret = btrfs_del_items(trans, root, path,
4304 pending_del_slot, 4304 pending_del_slot,
4305 pending_del_nr); 4305 pending_del_nr);
4306 if (ret) { 4306 if (ret) {
4307 btrfs_abort_transaction(trans, 4307 btrfs_abort_transaction(trans,
4308 root, ret); 4308 root, ret);
4309 goto error; 4309 goto error;
4310 } 4310 }
4311 pending_del_nr = 0; 4311 pending_del_nr = 0;
4312 } 4312 }
4313 btrfs_release_path(path); 4313 btrfs_release_path(path);
4314 goto search_again; 4314 goto search_again;
4315 } else { 4315 } else {
4316 path->slots[0]--; 4316 path->slots[0]--;
4317 } 4317 }
4318 } 4318 }
4319 out: 4319 out:
4320 if (pending_del_nr) { 4320 if (pending_del_nr) {
4321 ret = btrfs_del_items(trans, root, path, pending_del_slot, 4321 ret = btrfs_del_items(trans, root, path, pending_del_slot,
4322 pending_del_nr); 4322 pending_del_nr);
4323 if (ret) 4323 if (ret)
4324 btrfs_abort_transaction(trans, root, ret); 4324 btrfs_abort_transaction(trans, root, ret);
4325 } 4325 }
4326 error: 4326 error:
4327 if (last_size != (u64)-1 && 4327 if (last_size != (u64)-1 &&
4328 root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) 4328 root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID)
4329 btrfs_ordered_update_i_size(inode, last_size, NULL); 4329 btrfs_ordered_update_i_size(inode, last_size, NULL);
4330 btrfs_free_path(path); 4330 btrfs_free_path(path);
4331 return err; 4331 return err;
4332 } 4332 }
4333 4333
4334 /* 4334 /*
4335 * btrfs_truncate_page - read, zero a chunk and write a page 4335 * btrfs_truncate_page - read, zero a chunk and write a page
4336 * @inode - inode that we're zeroing 4336 * @inode - inode that we're zeroing
4337 * @from - the offset to start zeroing 4337 * @from - the offset to start zeroing
4338 * @len - the length to zero, 0 to zero the entire range respective to the 4338 * @len - the length to zero, 0 to zero the entire range respective to the
4339 * offset 4339 * offset
4340 * @front - zero up to the offset instead of from the offset on 4340 * @front - zero up to the offset instead of from the offset on
4341 * 4341 *
4342 * This will find the page for the "from" offset and cow the page and zero the 4342 * This will find the page for the "from" offset and cow the page and zero the
4343 * part we want to zero. This is used with truncate and hole punching. 4343 * part we want to zero. This is used with truncate and hole punching.
4344 */ 4344 */
4345 int btrfs_truncate_page(struct inode *inode, loff_t from, loff_t len, 4345 int btrfs_truncate_page(struct inode *inode, loff_t from, loff_t len,
4346 int front) 4346 int front)
4347 { 4347 {
4348 struct address_space *mapping = inode->i_mapping; 4348 struct address_space *mapping = inode->i_mapping;
4349 struct btrfs_root *root = BTRFS_I(inode)->root; 4349 struct btrfs_root *root = BTRFS_I(inode)->root;
4350 struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; 4350 struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
4351 struct btrfs_ordered_extent *ordered; 4351 struct btrfs_ordered_extent *ordered;
4352 struct extent_state *cached_state = NULL; 4352 struct extent_state *cached_state = NULL;
4353 char *kaddr; 4353 char *kaddr;
4354 u32 blocksize = root->sectorsize; 4354 u32 blocksize = root->sectorsize;
4355 pgoff_t index = from >> PAGE_CACHE_SHIFT; 4355 pgoff_t index = from >> PAGE_CACHE_SHIFT;
4356 unsigned offset = from & (PAGE_CACHE_SIZE-1); 4356 unsigned offset = from & (PAGE_CACHE_SIZE-1);
4357 struct page *page; 4357 struct page *page;
4358 gfp_t mask = btrfs_alloc_write_mask(mapping); 4358 gfp_t mask = btrfs_alloc_write_mask(mapping);
4359 int ret = 0; 4359 int ret = 0;
4360 u64 page_start; 4360 u64 page_start;
4361 u64 page_end; 4361 u64 page_end;
4362 4362
4363 if ((offset & (blocksize - 1)) == 0 && 4363 if ((offset & (blocksize - 1)) == 0 &&
4364 (!len || ((len & (blocksize - 1)) == 0))) 4364 (!len || ((len & (blocksize - 1)) == 0)))
4365 goto out; 4365 goto out;
4366 ret = btrfs_delalloc_reserve_space(inode, PAGE_CACHE_SIZE); 4366 ret = btrfs_delalloc_reserve_space(inode, PAGE_CACHE_SIZE);
4367 if (ret) 4367 if (ret)
4368 goto out; 4368 goto out;
4369 4369
4370 again: 4370 again:
4371 page = find_or_create_page(mapping, index, mask); 4371 page = find_or_create_page(mapping, index, mask);
4372 if (!page) { 4372 if (!page) {
4373 btrfs_delalloc_release_space(inode, PAGE_CACHE_SIZE); 4373 btrfs_delalloc_release_space(inode, PAGE_CACHE_SIZE);
4374 ret = -ENOMEM; 4374 ret = -ENOMEM;
4375 goto out; 4375 goto out;
4376 } 4376 }
4377 4377
4378 page_start = page_offset(page); 4378 page_start = page_offset(page);
4379 page_end = page_start + PAGE_CACHE_SIZE - 1; 4379 page_end = page_start + PAGE_CACHE_SIZE - 1;
4380 4380
4381 if (!PageUptodate(page)) { 4381 if (!PageUptodate(page)) {
4382 ret = btrfs_readpage(NULL, page); 4382 ret = btrfs_readpage(NULL, page);
4383 lock_page(page); 4383 lock_page(page);
4384 if (page->mapping != mapping) { 4384 if (page->mapping != mapping) {
4385 unlock_page(page); 4385 unlock_page(page);
4386 page_cache_release(page); 4386 page_cache_release(page);
4387 goto again; 4387 goto again;
4388 } 4388 }
4389 if (!PageUptodate(page)) { 4389 if (!PageUptodate(page)) {
4390 ret = -EIO; 4390 ret = -EIO;
4391 goto out_unlock; 4391 goto out_unlock;
4392 } 4392 }
4393 } 4393 }
4394 wait_on_page_writeback(page); 4394 wait_on_page_writeback(page);
4395 4395
4396 lock_extent_bits(io_tree, page_start, page_end, 0, &cached_state); 4396 lock_extent_bits(io_tree, page_start, page_end, 0, &cached_state);
4397 set_page_extent_mapped(page); 4397 set_page_extent_mapped(page);
4398 4398
4399 ordered = btrfs_lookup_ordered_extent(inode, page_start); 4399 ordered = btrfs_lookup_ordered_extent(inode, page_start);
4400 if (ordered) { 4400 if (ordered) {
4401 unlock_extent_cached(io_tree, page_start, page_end, 4401 unlock_extent_cached(io_tree, page_start, page_end,
4402 &cached_state, GFP_NOFS); 4402 &cached_state, GFP_NOFS);
4403 unlock_page(page); 4403 unlock_page(page);
4404 page_cache_release(page); 4404 page_cache_release(page);
4405 btrfs_start_ordered_extent(inode, ordered, 1); 4405 btrfs_start_ordered_extent(inode, ordered, 1);
4406 btrfs_put_ordered_extent(ordered); 4406 btrfs_put_ordered_extent(ordered);
4407 goto again; 4407 goto again;
4408 } 4408 }
4409 4409
4410 clear_extent_bit(&BTRFS_I(inode)->io_tree, page_start, page_end, 4410 clear_extent_bit(&BTRFS_I(inode)->io_tree, page_start, page_end,
4411 EXTENT_DIRTY | EXTENT_DELALLOC | 4411 EXTENT_DIRTY | EXTENT_DELALLOC |
4412 EXTENT_DO_ACCOUNTING | EXTENT_DEFRAG, 4412 EXTENT_DO_ACCOUNTING | EXTENT_DEFRAG,
4413 0, 0, &cached_state, GFP_NOFS); 4413 0, 0, &cached_state, GFP_NOFS);
4414 4414
4415 ret = btrfs_set_extent_delalloc(inode, page_start, page_end, 4415 ret = btrfs_set_extent_delalloc(inode, page_start, page_end,
4416 &cached_state); 4416 &cached_state);
4417 if (ret) { 4417 if (ret) {
4418 unlock_extent_cached(io_tree, page_start, page_end, 4418 unlock_extent_cached(io_tree, page_start, page_end,
4419 &cached_state, GFP_NOFS); 4419 &cached_state, GFP_NOFS);
4420 goto out_unlock; 4420 goto out_unlock;
4421 } 4421 }
4422 4422
4423 if (offset != PAGE_CACHE_SIZE) { 4423 if (offset != PAGE_CACHE_SIZE) {
4424 if (!len) 4424 if (!len)
4425 len = PAGE_CACHE_SIZE - offset; 4425 len = PAGE_CACHE_SIZE - offset;
4426 kaddr = kmap(page); 4426 kaddr = kmap(page);
4427 if (front) 4427 if (front)
4428 memset(kaddr, 0, offset); 4428 memset(kaddr, 0, offset);
4429 else 4429 else
4430 memset(kaddr + offset, 0, len); 4430 memset(kaddr + offset, 0, len);
4431 flush_dcache_page(page); 4431 flush_dcache_page(page);
4432 kunmap(page); 4432 kunmap(page);
4433 } 4433 }
4434 ClearPageChecked(page); 4434 ClearPageChecked(page);
4435 set_page_dirty(page); 4435 set_page_dirty(page);
4436 unlock_extent_cached(io_tree, page_start, page_end, &cached_state, 4436 unlock_extent_cached(io_tree, page_start, page_end, &cached_state,
4437 GFP_NOFS); 4437 GFP_NOFS);
4438 4438
4439 out_unlock: 4439 out_unlock:
4440 if (ret) 4440 if (ret)
4441 btrfs_delalloc_release_space(inode, PAGE_CACHE_SIZE); 4441 btrfs_delalloc_release_space(inode, PAGE_CACHE_SIZE);
4442 unlock_page(page); 4442 unlock_page(page);
4443 page_cache_release(page); 4443 page_cache_release(page);
4444 out: 4444 out:
4445 return ret; 4445 return ret;
4446 } 4446 }
4447 4447
4448 static int maybe_insert_hole(struct btrfs_root *root, struct inode *inode, 4448 static int maybe_insert_hole(struct btrfs_root *root, struct inode *inode,
4449 u64 offset, u64 len) 4449 u64 offset, u64 len)
4450 { 4450 {
4451 struct btrfs_trans_handle *trans; 4451 struct btrfs_trans_handle *trans;
4452 int ret; 4452 int ret;
4453 4453
4454 /* 4454 /*
4455 * Still need to make sure the inode looks like it's been updated so 4455 * Still need to make sure the inode looks like it's been updated so
4456 * that any holes get logged if we fsync. 4456 * that any holes get logged if we fsync.
4457 */ 4457 */
4458 if (btrfs_fs_incompat(root->fs_info, NO_HOLES)) { 4458 if (btrfs_fs_incompat(root->fs_info, NO_HOLES)) {
4459 BTRFS_I(inode)->last_trans = root->fs_info->generation; 4459 BTRFS_I(inode)->last_trans = root->fs_info->generation;
4460 BTRFS_I(inode)->last_sub_trans = root->log_transid; 4460 BTRFS_I(inode)->last_sub_trans = root->log_transid;
4461 BTRFS_I(inode)->last_log_commit = root->last_log_commit; 4461 BTRFS_I(inode)->last_log_commit = root->last_log_commit;
4462 return 0; 4462 return 0;
4463 } 4463 }
4464 4464
4465 /* 4465 /*
4466 * 1 - for the one we're dropping 4466 * 1 - for the one we're dropping
4467 * 1 - for the one we're adding 4467 * 1 - for the one we're adding
4468 * 1 - for updating the inode. 4468 * 1 - for updating the inode.
4469 */ 4469 */
4470 trans = btrfs_start_transaction(root, 3); 4470 trans = btrfs_start_transaction(root, 3);
4471 if (IS_ERR(trans)) 4471 if (IS_ERR(trans))
4472 return PTR_ERR(trans); 4472 return PTR_ERR(trans);
4473 4473
4474 ret = btrfs_drop_extents(trans, root, inode, offset, offset + len, 1); 4474 ret = btrfs_drop_extents(trans, root, inode, offset, offset + len, 1);
4475 if (ret) { 4475 if (ret) {
4476 btrfs_abort_transaction(trans, root, ret); 4476 btrfs_abort_transaction(trans, root, ret);
4477 btrfs_end_transaction(trans, root); 4477 btrfs_end_transaction(trans, root);
4478 return ret; 4478 return ret;
4479 } 4479 }
4480 4480
4481 ret = btrfs_insert_file_extent(trans, root, btrfs_ino(inode), offset, 4481 ret = btrfs_insert_file_extent(trans, root, btrfs_ino(inode), offset,
4482 0, 0, len, 0, len, 0, 0, 0); 4482 0, 0, len, 0, len, 0, 0, 0);
4483 if (ret) 4483 if (ret)
4484 btrfs_abort_transaction(trans, root, ret); 4484 btrfs_abort_transaction(trans, root, ret);
4485 else 4485 else
4486 btrfs_update_inode(trans, root, inode); 4486 btrfs_update_inode(trans, root, inode);
4487 btrfs_end_transaction(trans, root); 4487 btrfs_end_transaction(trans, root);
4488 return ret; 4488 return ret;
4489 } 4489 }
4490 4490
4491 /* 4491 /*
4492 * This function puts in dummy file extents for the area we're creating a hole 4492 * This function puts in dummy file extents for the area we're creating a hole
4493 * for. So if we are truncating this file to a larger size we need to insert 4493 * for. So if we are truncating this file to a larger size we need to insert
4494 * these file extents so that btrfs_get_extent will return a EXTENT_MAP_HOLE for 4494 * these file extents so that btrfs_get_extent will return a EXTENT_MAP_HOLE for
4495 * the range between oldsize and size 4495 * the range between oldsize and size
4496 */ 4496 */
4497 int btrfs_cont_expand(struct inode *inode, loff_t oldsize, loff_t size) 4497 int btrfs_cont_expand(struct inode *inode, loff_t oldsize, loff_t size)
4498 { 4498 {
4499 struct btrfs_root *root = BTRFS_I(inode)->root; 4499 struct btrfs_root *root = BTRFS_I(inode)->root;
4500 struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; 4500 struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
4501 struct extent_map *em = NULL; 4501 struct extent_map *em = NULL;
4502 struct extent_state *cached_state = NULL; 4502 struct extent_state *cached_state = NULL;
4503 struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; 4503 struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree;
4504 u64 hole_start = ALIGN(oldsize, root->sectorsize); 4504 u64 hole_start = ALIGN(oldsize, root->sectorsize);
4505 u64 block_end = ALIGN(size, root->sectorsize); 4505 u64 block_end = ALIGN(size, root->sectorsize);
4506 u64 last_byte; 4506 u64 last_byte;
4507 u64 cur_offset; 4507 u64 cur_offset;
4508 u64 hole_size; 4508 u64 hole_size;
4509 int err = 0; 4509 int err = 0;
4510 4510
4511 /* 4511 /*
4512 * If our size started in the middle of a page we need to zero out the 4512 * If our size started in the middle of a page we need to zero out the
4513 * rest of the page before we expand the i_size, otherwise we could 4513 * rest of the page before we expand the i_size, otherwise we could
4514 * expose stale data. 4514 * expose stale data.
4515 */ 4515 */
4516 err = btrfs_truncate_page(inode, oldsize, 0, 0); 4516 err = btrfs_truncate_page(inode, oldsize, 0, 0);
4517 if (err) 4517 if (err)
4518 return err; 4518 return err;
4519 4519
4520 if (size <= hole_start) 4520 if (size <= hole_start)
4521 return 0; 4521 return 0;
4522 4522
4523 while (1) { 4523 while (1) {
4524 struct btrfs_ordered_extent *ordered; 4524 struct btrfs_ordered_extent *ordered;
4525 4525
4526 lock_extent_bits(io_tree, hole_start, block_end - 1, 0, 4526 lock_extent_bits(io_tree, hole_start, block_end - 1, 0,
4527 &cached_state); 4527 &cached_state);
4528 ordered = btrfs_lookup_ordered_range(inode, hole_start, 4528 ordered = btrfs_lookup_ordered_range(inode, hole_start,
4529 block_end - hole_start); 4529 block_end - hole_start);
4530 if (!ordered) 4530 if (!ordered)
4531 break; 4531 break;
4532 unlock_extent_cached(io_tree, hole_start, block_end - 1, 4532 unlock_extent_cached(io_tree, hole_start, block_end - 1,
4533 &cached_state, GFP_NOFS); 4533 &cached_state, GFP_NOFS);
4534 btrfs_start_ordered_extent(inode, ordered, 1); 4534 btrfs_start_ordered_extent(inode, ordered, 1);
4535 btrfs_put_ordered_extent(ordered); 4535 btrfs_put_ordered_extent(ordered);
4536 } 4536 }
4537 4537
4538 cur_offset = hole_start; 4538 cur_offset = hole_start;
4539 while (1) { 4539 while (1) {
4540 em = btrfs_get_extent(inode, NULL, 0, cur_offset, 4540 em = btrfs_get_extent(inode, NULL, 0, cur_offset,
4541 block_end - cur_offset, 0); 4541 block_end - cur_offset, 0);
4542 if (IS_ERR(em)) { 4542 if (IS_ERR(em)) {
4543 err = PTR_ERR(em); 4543 err = PTR_ERR(em);
4544 em = NULL; 4544 em = NULL;
4545 break; 4545 break;
4546 } 4546 }
4547 last_byte = min(extent_map_end(em), block_end); 4547 last_byte = min(extent_map_end(em), block_end);
4548 last_byte = ALIGN(last_byte , root->sectorsize); 4548 last_byte = ALIGN(last_byte , root->sectorsize);
4549 if (!test_bit(EXTENT_FLAG_PREALLOC, &em->flags)) { 4549 if (!test_bit(EXTENT_FLAG_PREALLOC, &em->flags)) {
4550 struct extent_map *hole_em; 4550 struct extent_map *hole_em;
4551 hole_size = last_byte - cur_offset; 4551 hole_size = last_byte - cur_offset;
4552 4552
4553 err = maybe_insert_hole(root, inode, cur_offset, 4553 err = maybe_insert_hole(root, inode, cur_offset,
4554 hole_size); 4554 hole_size);
4555 if (err) 4555 if (err)
4556 break; 4556 break;
4557 btrfs_drop_extent_cache(inode, cur_offset, 4557 btrfs_drop_extent_cache(inode, cur_offset,
4558 cur_offset + hole_size - 1, 0); 4558 cur_offset + hole_size - 1, 0);
4559 hole_em = alloc_extent_map(); 4559 hole_em = alloc_extent_map();
4560 if (!hole_em) { 4560 if (!hole_em) {
4561 set_bit(BTRFS_INODE_NEEDS_FULL_SYNC, 4561 set_bit(BTRFS_INODE_NEEDS_FULL_SYNC,
4562 &BTRFS_I(inode)->runtime_flags); 4562 &BTRFS_I(inode)->runtime_flags);
4563 goto next; 4563 goto next;
4564 } 4564 }
4565 hole_em->start = cur_offset; 4565 hole_em->start = cur_offset;
4566 hole_em->len = hole_size; 4566 hole_em->len = hole_size;
4567 hole_em->orig_start = cur_offset; 4567 hole_em->orig_start = cur_offset;
4568 4568
4569 hole_em->block_start = EXTENT_MAP_HOLE; 4569 hole_em->block_start = EXTENT_MAP_HOLE;
4570 hole_em->block_len = 0; 4570 hole_em->block_len = 0;
4571 hole_em->orig_block_len = 0; 4571 hole_em->orig_block_len = 0;
4572 hole_em->ram_bytes = hole_size; 4572 hole_em->ram_bytes = hole_size;
4573 hole_em->bdev = root->fs_info->fs_devices->latest_bdev; 4573 hole_em->bdev = root->fs_info->fs_devices->latest_bdev;
4574 hole_em->compress_type = BTRFS_COMPRESS_NONE; 4574 hole_em->compress_type = BTRFS_COMPRESS_NONE;
4575 hole_em->generation = root->fs_info->generation; 4575 hole_em->generation = root->fs_info->generation;
4576 4576
4577 while (1) { 4577 while (1) {
4578 write_lock(&em_tree->lock); 4578 write_lock(&em_tree->lock);
4579 err = add_extent_mapping(em_tree, hole_em, 1); 4579 err = add_extent_mapping(em_tree, hole_em, 1);
4580 write_unlock(&em_tree->lock); 4580 write_unlock(&em_tree->lock);
4581 if (err != -EEXIST) 4581 if (err != -EEXIST)
4582 break; 4582 break;
4583 btrfs_drop_extent_cache(inode, cur_offset, 4583 btrfs_drop_extent_cache(inode, cur_offset,
4584 cur_offset + 4584 cur_offset +
4585 hole_size - 1, 0); 4585 hole_size - 1, 0);
4586 } 4586 }
4587 free_extent_map(hole_em); 4587 free_extent_map(hole_em);
4588 } 4588 }
4589 next: 4589 next:
4590 free_extent_map(em); 4590 free_extent_map(em);
4591 em = NULL; 4591 em = NULL;
4592 cur_offset = last_byte; 4592 cur_offset = last_byte;
4593 if (cur_offset >= block_end) 4593 if (cur_offset >= block_end)
4594 break; 4594 break;
4595 } 4595 }
4596 free_extent_map(em); 4596 free_extent_map(em);
4597 unlock_extent_cached(io_tree, hole_start, block_end - 1, &cached_state, 4597 unlock_extent_cached(io_tree, hole_start, block_end - 1, &cached_state,
4598 GFP_NOFS); 4598 GFP_NOFS);
4599 return err; 4599 return err;
4600 } 4600 }
4601 4601
4602 static int wait_snapshoting_atomic_t(atomic_t *a) 4602 static int wait_snapshoting_atomic_t(atomic_t *a)
4603 { 4603 {
4604 schedule(); 4604 schedule();
4605 return 0; 4605 return 0;
4606 } 4606 }
4607 4607
4608 static void wait_for_snapshot_creation(struct btrfs_root *root) 4608 static void wait_for_snapshot_creation(struct btrfs_root *root)
4609 { 4609 {
4610 while (true) { 4610 while (true) {
4611 int ret; 4611 int ret;
4612 4612
4613 ret = btrfs_start_write_no_snapshoting(root); 4613 ret = btrfs_start_write_no_snapshoting(root);
4614 if (ret) 4614 if (ret)
4615 break; 4615 break;
4616 wait_on_atomic_t(&root->will_be_snapshoted, 4616 wait_on_atomic_t(&root->will_be_snapshoted,
4617 wait_snapshoting_atomic_t, 4617 wait_snapshoting_atomic_t,
4618 TASK_UNINTERRUPTIBLE); 4618 TASK_UNINTERRUPTIBLE);
4619 } 4619 }
4620 } 4620 }
4621 4621
4622 static int btrfs_setsize(struct inode *inode, struct iattr *attr) 4622 static int btrfs_setsize(struct inode *inode, struct iattr *attr)
4623 { 4623 {
4624 struct btrfs_root *root = BTRFS_I(inode)->root; 4624 struct btrfs_root *root = BTRFS_I(inode)->root;
4625 struct btrfs_trans_handle *trans; 4625 struct btrfs_trans_handle *trans;
4626 loff_t oldsize = i_size_read(inode); 4626 loff_t oldsize = i_size_read(inode);
4627 loff_t newsize = attr->ia_size; 4627 loff_t newsize = attr->ia_size;
4628 int mask = attr->ia_valid; 4628 int mask = attr->ia_valid;
4629 int ret; 4629 int ret;
4630 4630
4631 /* 4631 /*
4632 * The regular truncate() case without ATTR_CTIME and ATTR_MTIME is a 4632 * The regular truncate() case without ATTR_CTIME and ATTR_MTIME is a
4633 * special case where we need to update the times despite not having 4633 * special case where we need to update the times despite not having
4634 * these flags set. For all other operations the VFS set these flags 4634 * these flags set. For all other operations the VFS set these flags
4635 * explicitly if it wants a timestamp update. 4635 * explicitly if it wants a timestamp update.
4636 */ 4636 */
4637 if (newsize != oldsize) { 4637 if (newsize != oldsize) {
4638 inode_inc_iversion(inode); 4638 inode_inc_iversion(inode);
4639 if (!(mask & (ATTR_CTIME | ATTR_MTIME))) 4639 if (!(mask & (ATTR_CTIME | ATTR_MTIME)))
4640 inode->i_ctime = inode->i_mtime = 4640 inode->i_ctime = inode->i_mtime =
4641 current_fs_time(inode->i_sb); 4641 current_fs_time(inode->i_sb);
4642 } 4642 }
4643 4643
4644 if (newsize > oldsize) { 4644 if (newsize > oldsize) {
4645 truncate_pagecache(inode, newsize); 4645 truncate_pagecache(inode, newsize);
4646 /* 4646 /*
4647 * Don't do an expanding truncate while snapshoting is ongoing. 4647 * Don't do an expanding truncate while snapshoting is ongoing.
4648 * This is to ensure the snapshot captures a fully consistent 4648 * This is to ensure the snapshot captures a fully consistent
4649 * state of this file - if the snapshot captures this expanding 4649 * state of this file - if the snapshot captures this expanding
4650 * truncation, it must capture all writes that happened before 4650 * truncation, it must capture all writes that happened before
4651 * this truncation. 4651 * this truncation.
4652 */ 4652 */
4653 wait_for_snapshot_creation(root); 4653 wait_for_snapshot_creation(root);
4654 ret = btrfs_cont_expand(inode, oldsize, newsize); 4654 ret = btrfs_cont_expand(inode, oldsize, newsize);
4655 if (ret) { 4655 if (ret) {
4656 btrfs_end_write_no_snapshoting(root); 4656 btrfs_end_write_no_snapshoting(root);
4657 return ret; 4657 return ret;
4658 } 4658 }
4659 4659
4660 trans = btrfs_start_transaction(root, 1); 4660 trans = btrfs_start_transaction(root, 1);
4661 if (IS_ERR(trans)) { 4661 if (IS_ERR(trans)) {
4662 btrfs_end_write_no_snapshoting(root); 4662 btrfs_end_write_no_snapshoting(root);
4663 return PTR_ERR(trans); 4663 return PTR_ERR(trans);
4664 } 4664 }
4665 4665
4666 i_size_write(inode, newsize); 4666 i_size_write(inode, newsize);
4667 btrfs_ordered_update_i_size(inode, i_size_read(inode), NULL); 4667 btrfs_ordered_update_i_size(inode, i_size_read(inode), NULL);
4668 ret = btrfs_update_inode(trans, root, inode); 4668 ret = btrfs_update_inode(trans, root, inode);
4669 btrfs_end_write_no_snapshoting(root); 4669 btrfs_end_write_no_snapshoting(root);
4670 btrfs_end_transaction(trans, root); 4670 btrfs_end_transaction(trans, root);
4671 } else { 4671 } else {
4672 4672
4673 /* 4673 /*
4674 * We're truncating a file that used to have good data down to 4674 * We're truncating a file that used to have good data down to
4675 * zero. Make sure it gets into the ordered flush list so that 4675 * zero. Make sure it gets into the ordered flush list so that
4676 * any new writes get down to disk quickly. 4676 * any new writes get down to disk quickly.
4677 */ 4677 */
4678 if (newsize == 0) 4678 if (newsize == 0)
4679 set_bit(BTRFS_INODE_ORDERED_DATA_CLOSE, 4679 set_bit(BTRFS_INODE_ORDERED_DATA_CLOSE,
4680 &BTRFS_I(inode)->runtime_flags); 4680 &BTRFS_I(inode)->runtime_flags);
4681 4681
4682 /* 4682 /*
4683 * 1 for the orphan item we're going to add 4683 * 1 for the orphan item we're going to add
4684 * 1 for the orphan item deletion. 4684 * 1 for the orphan item deletion.
4685 */ 4685 */
4686 trans = btrfs_start_transaction(root, 2); 4686 trans = btrfs_start_transaction(root, 2);
4687 if (IS_ERR(trans)) 4687 if (IS_ERR(trans))
4688 return PTR_ERR(trans); 4688 return PTR_ERR(trans);
4689 4689
4690 /* 4690 /*
4691 * We need to do this in case we fail at _any_ point during the 4691 * We need to do this in case we fail at _any_ point during the
4692 * actual truncate. Once we do the truncate_setsize we could 4692 * actual truncate. Once we do the truncate_setsize we could
4693 * invalidate pages which forces any outstanding ordered io to 4693 * invalidate pages which forces any outstanding ordered io to
4694 * be instantly completed which will give us extents that need 4694 * be instantly completed which will give us extents that need
4695 * to be truncated. If we fail to get an orphan inode down we 4695 * to be truncated. If we fail to get an orphan inode down we
4696 * could have left over extents that were never meant to live, 4696 * could have left over extents that were never meant to live,
4697 * so we need to garuntee from this point on that everything 4697 * so we need to garuntee from this point on that everything
4698 * will be consistent. 4698 * will be consistent.
4699 */ 4699 */
4700 ret = btrfs_orphan_add(trans, inode); 4700 ret = btrfs_orphan_add(trans, inode);
4701 btrfs_end_transaction(trans, root); 4701 btrfs_end_transaction(trans, root);
4702 if (ret) 4702 if (ret)
4703 return ret; 4703 return ret;
4704 4704
4705 /* we don't support swapfiles, so vmtruncate shouldn't fail */ 4705 /* we don't support swapfiles, so vmtruncate shouldn't fail */
4706 truncate_setsize(inode, newsize); 4706 truncate_setsize(inode, newsize);
4707 4707
4708 /* Disable nonlocked read DIO to avoid the end less truncate */ 4708 /* Disable nonlocked read DIO to avoid the end less truncate */
4709 btrfs_inode_block_unlocked_dio(inode); 4709 btrfs_inode_block_unlocked_dio(inode);
4710 inode_dio_wait(inode); 4710 inode_dio_wait(inode);
4711 btrfs_inode_resume_unlocked_dio(inode); 4711 btrfs_inode_resume_unlocked_dio(inode);
4712 4712
4713 ret = btrfs_truncate(inode); 4713 ret = btrfs_truncate(inode);
4714 if (ret && inode->i_nlink) { 4714 if (ret && inode->i_nlink) {
4715 int err; 4715 int err;
4716 4716
4717 /* 4717 /*
4718 * failed to truncate, disk_i_size is only adjusted down 4718 * failed to truncate, disk_i_size is only adjusted down
4719 * as we remove extents, so it should represent the true 4719 * as we remove extents, so it should represent the true
4720 * size of the inode, so reset the in memory size and 4720 * size of the inode, so reset the in memory size and
4721 * delete our orphan entry. 4721 * delete our orphan entry.
4722 */ 4722 */
4723 trans = btrfs_join_transaction(root); 4723 trans = btrfs_join_transaction(root);
4724 if (IS_ERR(trans)) { 4724 if (IS_ERR(trans)) {
4725 btrfs_orphan_del(NULL, inode); 4725 btrfs_orphan_del(NULL, inode);
4726 return ret; 4726 return ret;
4727 } 4727 }
4728 i_size_write(inode, BTRFS_I(inode)->disk_i_size); 4728 i_size_write(inode, BTRFS_I(inode)->disk_i_size);
4729 err = btrfs_orphan_del(trans, inode); 4729 err = btrfs_orphan_del(trans, inode);
4730 if (err) 4730 if (err)
4731 btrfs_abort_transaction(trans, root, err); 4731 btrfs_abort_transaction(trans, root, err);
4732 btrfs_end_transaction(trans, root); 4732 btrfs_end_transaction(trans, root);
4733 } 4733 }
4734 } 4734 }
4735 4735
4736 return ret; 4736 return ret;
4737 } 4737 }
4738 4738
4739 static int btrfs_setattr(struct dentry *dentry, struct iattr *attr) 4739 static int btrfs_setattr(struct dentry *dentry, struct iattr *attr)
4740 { 4740 {
4741 struct inode *inode = dentry->d_inode; 4741 struct inode *inode = dentry->d_inode;
4742 struct btrfs_root *root = BTRFS_I(inode)->root; 4742 struct btrfs_root *root = BTRFS_I(inode)->root;
4743 int err; 4743 int err;
4744 4744
4745 if (btrfs_root_readonly(root)) 4745 if (btrfs_root_readonly(root))
4746 return -EROFS; 4746 return -EROFS;
4747 4747
4748 err = inode_change_ok(inode, attr); 4748 err = inode_change_ok(inode, attr);
4749 if (err) 4749 if (err)
4750 return err; 4750 return err;
4751 4751
4752 if (S_ISREG(inode->i_mode) && (attr->ia_valid & ATTR_SIZE)) { 4752 if (S_ISREG(inode->i_mode) && (attr->ia_valid & ATTR_SIZE)) {
4753 err = btrfs_setsize(inode, attr); 4753 err = btrfs_setsize(inode, attr);
4754 if (err) 4754 if (err)
4755 return err; 4755 return err;
4756 } 4756 }
4757 4757
4758 if (attr->ia_valid) { 4758 if (attr->ia_valid) {
4759 setattr_copy(inode, attr); 4759 setattr_copy(inode, attr);
4760 inode_inc_iversion(inode); 4760 inode_inc_iversion(inode);
4761 err = btrfs_dirty_inode(inode); 4761 err = btrfs_dirty_inode(inode);
4762 4762
4763 if (!err && attr->ia_valid & ATTR_MODE) 4763 if (!err && attr->ia_valid & ATTR_MODE)
4764 err = posix_acl_chmod(inode, inode->i_mode); 4764 err = posix_acl_chmod(inode, inode->i_mode);
4765 } 4765 }
4766 4766
4767 return err; 4767 return err;
4768 } 4768 }
4769 4769
4770 /* 4770 /*
4771 * While truncating the inode pages during eviction, we get the VFS calling 4771 * While truncating the inode pages during eviction, we get the VFS calling
4772 * btrfs_invalidatepage() against each page of the inode. This is slow because 4772 * btrfs_invalidatepage() against each page of the inode. This is slow because
4773 * the calls to btrfs_invalidatepage() result in a huge amount of calls to 4773 * the calls to btrfs_invalidatepage() result in a huge amount of calls to
4774 * lock_extent_bits() and clear_extent_bit(), which keep merging and splitting 4774 * lock_extent_bits() and clear_extent_bit(), which keep merging and splitting
4775 * extent_state structures over and over, wasting lots of time. 4775 * extent_state structures over and over, wasting lots of time.
4776 * 4776 *
4777 * Therefore if the inode is being evicted, let btrfs_invalidatepage() skip all 4777 * Therefore if the inode is being evicted, let btrfs_invalidatepage() skip all
4778 * those expensive operations on a per page basis and do only the ordered io 4778 * those expensive operations on a per page basis and do only the ordered io
4779 * finishing, while we release here the extent_map and extent_state structures, 4779 * finishing, while we release here the extent_map and extent_state structures,
4780 * without the excessive merging and splitting. 4780 * without the excessive merging and splitting.
4781 */ 4781 */
4782 static void evict_inode_truncate_pages(struct inode *inode) 4782 static void evict_inode_truncate_pages(struct inode *inode)
4783 { 4783 {
4784 struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; 4784 struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
4785 struct extent_map_tree *map_tree = &BTRFS_I(inode)->extent_tree; 4785 struct extent_map_tree *map_tree = &BTRFS_I(inode)->extent_tree;
4786 struct rb_node *node; 4786 struct rb_node *node;
4787 4787
4788 ASSERT(inode->i_state & I_FREEING); 4788 ASSERT(inode->i_state & I_FREEING);
4789 truncate_inode_pages_final(&inode->i_data); 4789 truncate_inode_pages_final(&inode->i_data);
4790 4790
4791 write_lock(&map_tree->lock); 4791 write_lock(&map_tree->lock);
4792 while (!RB_EMPTY_ROOT(&map_tree->map)) { 4792 while (!RB_EMPTY_ROOT(&map_tree->map)) {
4793 struct extent_map *em; 4793 struct extent_map *em;
4794 4794
4795 node = rb_first(&map_tree->map); 4795 node = rb_first(&map_tree->map);
4796 em = rb_entry(node, struct extent_map, rb_node); 4796 em = rb_entry(node, struct extent_map, rb_node);
4797 clear_bit(EXTENT_FLAG_PINNED, &em->flags); 4797 clear_bit(EXTENT_FLAG_PINNED, &em->flags);
4798 clear_bit(EXTENT_FLAG_LOGGING, &em->flags); 4798 clear_bit(EXTENT_FLAG_LOGGING, &em->flags);
4799 remove_extent_mapping(map_tree, em); 4799 remove_extent_mapping(map_tree, em);
4800 free_extent_map(em); 4800 free_extent_map(em);
4801 if (need_resched()) { 4801 if (need_resched()) {
4802 write_unlock(&map_tree->lock); 4802 write_unlock(&map_tree->lock);
4803 cond_resched(); 4803 cond_resched();
4804 write_lock(&map_tree->lock); 4804 write_lock(&map_tree->lock);
4805 } 4805 }
4806 } 4806 }
4807 write_unlock(&map_tree->lock); 4807 write_unlock(&map_tree->lock);
4808 4808
4809 spin_lock(&io_tree->lock); 4809 spin_lock(&io_tree->lock);
4810 while (!RB_EMPTY_ROOT(&io_tree->state)) { 4810 while (!RB_EMPTY_ROOT(&io_tree->state)) {
4811 struct extent_state *state; 4811 struct extent_state *state;
4812 struct extent_state *cached_state = NULL; 4812 struct extent_state *cached_state = NULL;
4813 4813
4814 node = rb_first(&io_tree->state); 4814 node = rb_first(&io_tree->state);
4815 state = rb_entry(node, struct extent_state, rb_node); 4815 state = rb_entry(node, struct extent_state, rb_node);
4816 atomic_inc(&state->refs); 4816 atomic_inc(&state->refs);
4817 spin_unlock(&io_tree->lock); 4817 spin_unlock(&io_tree->lock);
4818 4818
4819 lock_extent_bits(io_tree, state->start, state->end, 4819 lock_extent_bits(io_tree, state->start, state->end,
4820 0, &cached_state); 4820 0, &cached_state);
4821 clear_extent_bit(io_tree, state->start, state->end, 4821 clear_extent_bit(io_tree, state->start, state->end,
4822 EXTENT_LOCKED | EXTENT_DIRTY | 4822 EXTENT_LOCKED | EXTENT_DIRTY |
4823 EXTENT_DELALLOC | EXTENT_DO_ACCOUNTING | 4823 EXTENT_DELALLOC | EXTENT_DO_ACCOUNTING |
4824 EXTENT_DEFRAG, 1, 1, 4824 EXTENT_DEFRAG, 1, 1,
4825 &cached_state, GFP_NOFS); 4825 &cached_state, GFP_NOFS);
4826 free_extent_state(state); 4826 free_extent_state(state);
4827 4827
4828 cond_resched(); 4828 cond_resched();
4829 spin_lock(&io_tree->lock); 4829 spin_lock(&io_tree->lock);
4830 } 4830 }
4831 spin_unlock(&io_tree->lock); 4831 spin_unlock(&io_tree->lock);
4832 } 4832 }
4833 4833
4834 void btrfs_evict_inode(struct inode *inode) 4834 void btrfs_evict_inode(struct inode *inode)
4835 { 4835 {
4836 struct btrfs_trans_handle *trans; 4836 struct btrfs_trans_handle *trans;
4837 struct btrfs_root *root = BTRFS_I(inode)->root; 4837 struct btrfs_root *root = BTRFS_I(inode)->root;
4838 struct btrfs_block_rsv *rsv, *global_rsv; 4838 struct btrfs_block_rsv *rsv, *global_rsv;
4839 u64 min_size = btrfs_calc_trunc_metadata_size(root, 1); 4839 u64 min_size = btrfs_calc_trunc_metadata_size(root, 1);
4840 int ret; 4840 int ret;
4841 4841
4842 trace_btrfs_inode_evict(inode); 4842 trace_btrfs_inode_evict(inode);
4843 4843
4844 evict_inode_truncate_pages(inode); 4844 evict_inode_truncate_pages(inode);
4845 4845
4846 if (inode->i_nlink && 4846 if (inode->i_nlink &&
4847 ((btrfs_root_refs(&root->root_item) != 0 && 4847 ((btrfs_root_refs(&root->root_item) != 0 &&
4848 root->root_key.objectid != BTRFS_ROOT_TREE_OBJECTID) || 4848 root->root_key.objectid != BTRFS_ROOT_TREE_OBJECTID) ||
4849 btrfs_is_free_space_inode(inode))) 4849 btrfs_is_free_space_inode(inode)))
4850 goto no_delete; 4850 goto no_delete;
4851 4851
4852 if (is_bad_inode(inode)) { 4852 if (is_bad_inode(inode)) {
4853 btrfs_orphan_del(NULL, inode); 4853 btrfs_orphan_del(NULL, inode);
4854 goto no_delete; 4854 goto no_delete;
4855 } 4855 }
4856 /* do we really want it for ->i_nlink > 0 and zero btrfs_root_refs? */ 4856 /* do we really want it for ->i_nlink > 0 and zero btrfs_root_refs? */
4857 btrfs_wait_ordered_range(inode, 0, (u64)-1); 4857 btrfs_wait_ordered_range(inode, 0, (u64)-1);
4858 4858
4859 btrfs_free_io_failure_record(inode, 0, (u64)-1); 4859 btrfs_free_io_failure_record(inode, 0, (u64)-1);
4860 4860
4861 if (root->fs_info->log_root_recovering) { 4861 if (root->fs_info->log_root_recovering) {
4862 BUG_ON(test_bit(BTRFS_INODE_HAS_ORPHAN_ITEM, 4862 BUG_ON(test_bit(BTRFS_INODE_HAS_ORPHAN_ITEM,
4863 &BTRFS_I(inode)->runtime_flags)); 4863 &BTRFS_I(inode)->runtime_flags));
4864 goto no_delete; 4864 goto no_delete;
4865 } 4865 }
4866 4866
4867 if (inode->i_nlink > 0) { 4867 if (inode->i_nlink > 0) {
4868 BUG_ON(btrfs_root_refs(&root->root_item) != 0 && 4868 BUG_ON(btrfs_root_refs(&root->root_item) != 0 &&
4869 root->root_key.objectid != BTRFS_ROOT_TREE_OBJECTID); 4869 root->root_key.objectid != BTRFS_ROOT_TREE_OBJECTID);
4870 goto no_delete; 4870 goto no_delete;
4871 } 4871 }
4872 4872
4873 ret = btrfs_commit_inode_delayed_inode(inode); 4873 ret = btrfs_commit_inode_delayed_inode(inode);
4874 if (ret) { 4874 if (ret) {
4875 btrfs_orphan_del(NULL, inode); 4875 btrfs_orphan_del(NULL, inode);
4876 goto no_delete; 4876 goto no_delete;
4877 } 4877 }
4878 4878
4879 rsv = btrfs_alloc_block_rsv(root, BTRFS_BLOCK_RSV_TEMP); 4879 rsv = btrfs_alloc_block_rsv(root, BTRFS_BLOCK_RSV_TEMP);
4880 if (!rsv) { 4880 if (!rsv) {
4881 btrfs_orphan_del(NULL, inode); 4881 btrfs_orphan_del(NULL, inode);
4882 goto no_delete; 4882 goto no_delete;
4883 } 4883 }
4884 rsv->size = min_size; 4884 rsv->size = min_size;
4885 rsv->failfast = 1; 4885 rsv->failfast = 1;
4886 global_rsv = &root->fs_info->global_block_rsv; 4886 global_rsv = &root->fs_info->global_block_rsv;
4887 4887
4888 btrfs_i_size_write(inode, 0); 4888 btrfs_i_size_write(inode, 0);
4889 4889
4890 /* 4890 /*
4891 * This is a bit simpler than btrfs_truncate since we've already 4891 * This is a bit simpler than btrfs_truncate since we've already
4892 * reserved our space for our orphan item in the unlink, so we just 4892 * reserved our space for our orphan item in the unlink, so we just
4893 * need to reserve some slack space in case we add bytes and update 4893 * need to reserve some slack space in case we add bytes and update
4894 * inode item when doing the truncate. 4894 * inode item when doing the truncate.
4895 */ 4895 */
4896 while (1) { 4896 while (1) {
4897 ret = btrfs_block_rsv_refill(root, rsv, min_size, 4897 ret = btrfs_block_rsv_refill(root, rsv, min_size,
4898 BTRFS_RESERVE_FLUSH_LIMIT); 4898 BTRFS_RESERVE_FLUSH_LIMIT);
4899 4899
4900 /* 4900 /*
4901 * Try and steal from the global reserve since we will 4901 * Try and steal from the global reserve since we will
4902 * likely not use this space anyway, we want to try as 4902 * likely not use this space anyway, we want to try as
4903 * hard as possible to get this to work. 4903 * hard as possible to get this to work.
4904 */ 4904 */
4905 if (ret) 4905 if (ret)
4906 ret = btrfs_block_rsv_migrate(global_rsv, rsv, min_size); 4906 ret = btrfs_block_rsv_migrate(global_rsv, rsv, min_size);
4907 4907
4908 if (ret) { 4908 if (ret) {
4909 btrfs_warn(root->fs_info, 4909 btrfs_warn(root->fs_info,
4910 "Could not get space for a delete, will truncate on mount %d", 4910 "Could not get space for a delete, will truncate on mount %d",
4911 ret); 4911 ret);
4912 btrfs_orphan_del(NULL, inode); 4912 btrfs_orphan_del(NULL, inode);
4913 btrfs_free_block_rsv(root, rsv); 4913 btrfs_free_block_rsv(root, rsv);
4914 goto no_delete; 4914 goto no_delete;
4915 } 4915 }
4916 4916
4917 trans = btrfs_join_transaction(root); 4917 trans = btrfs_join_transaction(root);
4918 if (IS_ERR(trans)) { 4918 if (IS_ERR(trans)) {
4919 btrfs_orphan_del(NULL, inode); 4919 btrfs_orphan_del(NULL, inode);
4920 btrfs_free_block_rsv(root, rsv); 4920 btrfs_free_block_rsv(root, rsv);
4921 goto no_delete; 4921 goto no_delete;
4922 } 4922 }
4923 4923
4924 trans->block_rsv = rsv; 4924 trans->block_rsv = rsv;
4925 4925
4926 ret = btrfs_truncate_inode_items(trans, root, inode, 0, 0); 4926 ret = btrfs_truncate_inode_items(trans, root, inode, 0, 0);
4927 if (ret != -ENOSPC) 4927 if (ret != -ENOSPC)
4928 break; 4928 break;
4929 4929
4930 trans->block_rsv = &root->fs_info->trans_block_rsv; 4930 trans->block_rsv = &root->fs_info->trans_block_rsv;
4931 btrfs_end_transaction(trans, root); 4931 btrfs_end_transaction(trans, root);
4932 trans = NULL; 4932 trans = NULL;
4933 btrfs_btree_balance_dirty(root); 4933 btrfs_btree_balance_dirty(root);
4934 } 4934 }
4935 4935
4936 btrfs_free_block_rsv(root, rsv); 4936 btrfs_free_block_rsv(root, rsv);
4937 4937
4938 /* 4938 /*
4939 * Errors here aren't a big deal, it just means we leave orphan items 4939 * Errors here aren't a big deal, it just means we leave orphan items
4940 * in the tree. They will be cleaned up on the next mount. 4940 * in the tree. They will be cleaned up on the next mount.
4941 */ 4941 */
4942 if (ret == 0) { 4942 if (ret == 0) {
4943 trans->block_rsv = root->orphan_block_rsv; 4943 trans->block_rsv = root->orphan_block_rsv;
4944 btrfs_orphan_del(trans, inode); 4944 btrfs_orphan_del(trans, inode);
4945 } else { 4945 } else {
4946 btrfs_orphan_del(NULL, inode); 4946 btrfs_orphan_del(NULL, inode);
4947 } 4947 }
4948 4948
4949 trans->block_rsv = &root->fs_info->trans_block_rsv; 4949 trans->block_rsv = &root->fs_info->trans_block_rsv;
4950 if (!(root == root->fs_info->tree_root || 4950 if (!(root == root->fs_info->tree_root ||
4951 root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)) 4951 root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID))
4952 btrfs_return_ino(root, btrfs_ino(inode)); 4952 btrfs_return_ino(root, btrfs_ino(inode));
4953 4953
4954 btrfs_end_transaction(trans, root); 4954 btrfs_end_transaction(trans, root);
4955 btrfs_btree_balance_dirty(root); 4955 btrfs_btree_balance_dirty(root);
4956 no_delete: 4956 no_delete:
4957 btrfs_remove_delayed_node(inode); 4957 btrfs_remove_delayed_node(inode);
4958 clear_inode(inode); 4958 clear_inode(inode);
4959 return; 4959 return;
4960 } 4960 }
4961 4961
4962 /* 4962 /*
4963 * this returns the key found in the dir entry in the location pointer. 4963 * this returns the key found in the dir entry in the location pointer.
4964 * If no dir entries were found, location->objectid is 0. 4964 * If no dir entries were found, location->objectid is 0.
4965 */ 4965 */
4966 static int btrfs_inode_by_name(struct inode *dir, struct dentry *dentry, 4966 static int btrfs_inode_by_name(struct inode *dir, struct dentry *dentry,
4967 struct btrfs_key *location) 4967 struct btrfs_key *location)
4968 { 4968 {
4969 const char *name = dentry->d_name.name; 4969 const char *name = dentry->d_name.name;
4970 int namelen = dentry->d_name.len; 4970 int namelen = dentry->d_name.len;
4971 struct btrfs_dir_item *di; 4971 struct btrfs_dir_item *di;
4972 struct btrfs_path *path; 4972 struct btrfs_path *path;
4973 struct btrfs_root *root = BTRFS_I(dir)->root; 4973 struct btrfs_root *root = BTRFS_I(dir)->root;
4974 int ret = 0; 4974 int ret = 0;
4975 4975
4976 path = btrfs_alloc_path(); 4976 path = btrfs_alloc_path();
4977 if (!path) 4977 if (!path)
4978 return -ENOMEM; 4978 return -ENOMEM;
4979 4979
4980 di = btrfs_lookup_dir_item(NULL, root, path, btrfs_ino(dir), name, 4980 di = btrfs_lookup_dir_item(NULL, root, path, btrfs_ino(dir), name,
4981 namelen, 0); 4981 namelen, 0);
4982 if (IS_ERR(di)) 4982 if (IS_ERR(di))
4983 ret = PTR_ERR(di); 4983 ret = PTR_ERR(di);
4984 4984
4985 if (IS_ERR_OR_NULL(di)) 4985 if (IS_ERR_OR_NULL(di))
4986 goto out_err; 4986 goto out_err;
4987 4987
4988 btrfs_dir_item_key_to_cpu(path->nodes[0], di, location); 4988 btrfs_dir_item_key_to_cpu(path->nodes[0], di, location);
4989 out: 4989 out:
4990 btrfs_free_path(path); 4990 btrfs_free_path(path);
4991 return ret; 4991 return ret;
4992 out_err: 4992 out_err:
4993 location->objectid = 0; 4993 location->objectid = 0;
4994 goto out; 4994 goto out;
4995 } 4995 }
4996 4996
4997 /* 4997 /*
4998 * when we hit a tree root in a directory, the btrfs part of the inode 4998 * when we hit a tree root in a directory, the btrfs part of the inode
4999 * needs to be changed to reflect the root directory of the tree root. This 4999 * needs to be changed to reflect the root directory of the tree root. This
5000 * is kind of like crossing a mount point. 5000 * is kind of like crossing a mount point.
5001 */ 5001 */
5002 static int fixup_tree_root_location(struct btrfs_root *root, 5002 static int fixup_tree_root_location(struct btrfs_root *root,
5003 struct inode *dir, 5003 struct inode *dir,
5004 struct dentry *dentry, 5004 struct dentry *dentry,
5005 struct btrfs_key *location, 5005 struct btrfs_key *location,
5006 struct btrfs_root **sub_root) 5006 struct btrfs_root **sub_root)
5007 { 5007 {
5008 struct btrfs_path *path; 5008 struct btrfs_path *path;
5009 struct btrfs_root *new_root; 5009 struct btrfs_root *new_root;
5010 struct btrfs_root_ref *ref; 5010 struct btrfs_root_ref *ref;
5011 struct extent_buffer *leaf; 5011 struct extent_buffer *leaf;
5012 int ret; 5012 int ret;
5013 int err = 0; 5013 int err = 0;
5014 5014
5015 path = btrfs_alloc_path(); 5015 path = btrfs_alloc_path();
5016 if (!path) { 5016 if (!path) {
5017 err = -ENOMEM; 5017 err = -ENOMEM;
5018 goto out; 5018 goto out;
5019 } 5019 }
5020 5020
5021 err = -ENOENT; 5021 err = -ENOENT;
5022 ret = btrfs_find_item(root->fs_info->tree_root, path, 5022 ret = btrfs_find_item(root->fs_info->tree_root, path,
5023 BTRFS_I(dir)->root->root_key.objectid, 5023 BTRFS_I(dir)->root->root_key.objectid,
5024 location->objectid, BTRFS_ROOT_REF_KEY, NULL); 5024 location->objectid, BTRFS_ROOT_REF_KEY, NULL);
5025 if (ret) { 5025 if (ret) {
5026 if (ret < 0) 5026 if (ret < 0)
5027 err = ret; 5027 err = ret;
5028 goto out; 5028 goto out;
5029 } 5029 }
5030 5030
5031 leaf = path->nodes[0]; 5031 leaf = path->nodes[0];
5032 ref = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_root_ref); 5032 ref = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_root_ref);
5033 if (btrfs_root_ref_dirid(leaf, ref) != btrfs_ino(dir) || 5033 if (btrfs_root_ref_dirid(leaf, ref) != btrfs_ino(dir) ||
5034 btrfs_root_ref_name_len(leaf, ref) != dentry->d_name.len) 5034 btrfs_root_ref_name_len(leaf, ref) != dentry->d_name.len)
5035 goto out; 5035 goto out;
5036 5036
5037 ret = memcmp_extent_buffer(leaf, dentry->d_name.name, 5037 ret = memcmp_extent_buffer(leaf, dentry->d_name.name,
5038 (unsigned long)(ref + 1), 5038 (unsigned long)(ref + 1),
5039 dentry->d_name.len); 5039 dentry->d_name.len);
5040 if (ret) 5040 if (ret)
5041 goto out; 5041 goto out;
5042 5042
5043 btrfs_release_path(path); 5043 btrfs_release_path(path);
5044 5044
5045 new_root = btrfs_read_fs_root_no_name(root->fs_info, location); 5045 new_root = btrfs_read_fs_root_no_name(root->fs_info, location);
5046 if (IS_ERR(new_root)) { 5046 if (IS_ERR(new_root)) {
5047 err = PTR_ERR(new_root); 5047 err = PTR_ERR(new_root);
5048 goto out; 5048 goto out;
5049 } 5049 }
5050 5050
5051 *sub_root = new_root; 5051 *sub_root = new_root;
5052 location->objectid = btrfs_root_dirid(&new_root->root_item); 5052 location->objectid = btrfs_root_dirid(&new_root->root_item);
5053 location->type = BTRFS_INODE_ITEM_KEY; 5053 location->type = BTRFS_INODE_ITEM_KEY;
5054 location->offset = 0; 5054 location->offset = 0;
5055 err = 0; 5055 err = 0;
5056 out: 5056 out:
5057 btrfs_free_path(path); 5057 btrfs_free_path(path);
5058 return err; 5058 return err;
5059 } 5059 }
5060 5060
5061 static void inode_tree_add(struct inode *inode) 5061 static void inode_tree_add(struct inode *inode)
5062 { 5062 {
5063 struct btrfs_root *root = BTRFS_I(inode)->root; 5063 struct btrfs_root *root = BTRFS_I(inode)->root;
5064 struct btrfs_inode *entry; 5064 struct btrfs_inode *entry;
5065 struct rb_node **p; 5065 struct rb_node **p;
5066 struct rb_node *parent; 5066 struct rb_node *parent;
5067 struct rb_node *new = &BTRFS_I(inode)->rb_node; 5067 struct rb_node *new = &BTRFS_I(inode)->rb_node;
5068 u64 ino = btrfs_ino(inode); 5068 u64 ino = btrfs_ino(inode);
5069 5069
5070 if (inode_unhashed(inode)) 5070 if (inode_unhashed(inode))
5071 return; 5071 return;
5072 parent = NULL; 5072 parent = NULL;
5073 spin_lock(&root->inode_lock); 5073 spin_lock(&root->inode_lock);
5074 p = &root->inode_tree.rb_node; 5074 p = &root->inode_tree.rb_node;
5075 while (*p) { 5075 while (*p) {
5076 parent = *p; 5076 parent = *p;
5077 entry = rb_entry(parent, struct btrfs_inode, rb_node); 5077 entry = rb_entry(parent, struct btrfs_inode, rb_node);
5078 5078
5079 if (ino < btrfs_ino(&entry->vfs_inode)) 5079 if (ino < btrfs_ino(&entry->vfs_inode))
5080 p = &parent->rb_left; 5080 p = &parent->rb_left;
5081 else if (ino > btrfs_ino(&entry->vfs_inode)) 5081 else if (ino > btrfs_ino(&entry->vfs_inode))
5082 p = &parent->rb_right; 5082 p = &parent->rb_right;
5083 else { 5083 else {
5084 WARN_ON(!(entry->vfs_inode.i_state & 5084 WARN_ON(!(entry->vfs_inode.i_state &
5085 (I_WILL_FREE | I_FREEING))); 5085 (I_WILL_FREE | I_FREEING)));
5086 rb_replace_node(parent, new, &root->inode_tree); 5086 rb_replace_node(parent, new, &root->inode_tree);
5087 RB_CLEAR_NODE(parent); 5087 RB_CLEAR_NODE(parent);
5088 spin_unlock(&root->inode_lock); 5088 spin_unlock(&root->inode_lock);
5089 return; 5089 return;
5090 } 5090 }
5091 } 5091 }
5092 rb_link_node(new, parent, p); 5092 rb_link_node(new, parent, p);
5093 rb_insert_color(new, &root->inode_tree); 5093 rb_insert_color(new, &root->inode_tree);
5094 spin_unlock(&root->inode_lock); 5094 spin_unlock(&root->inode_lock);
5095 } 5095 }
5096 5096
5097 static void inode_tree_del(struct inode *inode) 5097 static void inode_tree_del(struct inode *inode)
5098 { 5098 {
5099 struct btrfs_root *root = BTRFS_I(inode)->root; 5099 struct btrfs_root *root = BTRFS_I(inode)->root;
5100 int empty = 0; 5100 int empty = 0;
5101 5101
5102 spin_lock(&root->inode_lock); 5102 spin_lock(&root->inode_lock);
5103 if (!RB_EMPTY_NODE(&BTRFS_I(inode)->rb_node)) { 5103 if (!RB_EMPTY_NODE(&BTRFS_I(inode)->rb_node)) {
5104 rb_erase(&BTRFS_I(inode)->rb_node, &root->inode_tree); 5104 rb_erase(&BTRFS_I(inode)->rb_node, &root->inode_tree);
5105 RB_CLEAR_NODE(&BTRFS_I(inode)->rb_node); 5105 RB_CLEAR_NODE(&BTRFS_I(inode)->rb_node);
5106 empty = RB_EMPTY_ROOT(&root->inode_tree); 5106 empty = RB_EMPTY_ROOT(&root->inode_tree);
5107 } 5107 }
5108 spin_unlock(&root->inode_lock); 5108 spin_unlock(&root->inode_lock);
5109 5109
5110 if (empty && btrfs_root_refs(&root->root_item) == 0) { 5110 if (empty && btrfs_root_refs(&root->root_item) == 0) {
5111 synchronize_srcu(&root->fs_info->subvol_srcu); 5111 synchronize_srcu(&root->fs_info->subvol_srcu);
5112 spin_lock(&root->inode_lock); 5112 spin_lock(&root->inode_lock);
5113 empty = RB_EMPTY_ROOT(&root->inode_tree); 5113 empty = RB_EMPTY_ROOT(&root->inode_tree);
5114 spin_unlock(&root->inode_lock); 5114 spin_unlock(&root->inode_lock);
5115 if (empty) 5115 if (empty)
5116 btrfs_add_dead_root(root); 5116 btrfs_add_dead_root(root);
5117 } 5117 }
5118 } 5118 }
5119 5119
5120 void btrfs_invalidate_inodes(struct btrfs_root *root) 5120 void btrfs_invalidate_inodes(struct btrfs_root *root)
5121 { 5121 {
5122 struct rb_node *node; 5122 struct rb_node *node;
5123 struct rb_node *prev; 5123 struct rb_node *prev;
5124 struct btrfs_inode *entry; 5124 struct btrfs_inode *entry;
5125 struct inode *inode; 5125 struct inode *inode;
5126 u64 objectid = 0; 5126 u64 objectid = 0;
5127 5127
5128 if (!test_bit(BTRFS_FS_STATE_ERROR, &root->fs_info->fs_state)) 5128 if (!test_bit(BTRFS_FS_STATE_ERROR, &root->fs_info->fs_state))
5129 WARN_ON(btrfs_root_refs(&root->root_item) != 0); 5129 WARN_ON(btrfs_root_refs(&root->root_item) != 0);
5130 5130
5131 spin_lock(&root->inode_lock); 5131 spin_lock(&root->inode_lock);
5132 again: 5132 again:
5133 node = root->inode_tree.rb_node; 5133 node = root->inode_tree.rb_node;
5134 prev = NULL; 5134 prev = NULL;
5135 while (node) { 5135 while (node) {
5136 prev = node; 5136 prev = node;
5137 entry = rb_entry(node, struct btrfs_inode, rb_node); 5137 entry = rb_entry(node, struct btrfs_inode, rb_node);
5138 5138
5139 if (objectid < btrfs_ino(&entry->vfs_inode)) 5139 if (objectid < btrfs_ino(&entry->vfs_inode))
5140 node = node->rb_left; 5140 node = node->rb_left;
5141 else if (objectid > btrfs_ino(&entry->vfs_inode)) 5141 else if (objectid > btrfs_ino(&entry->vfs_inode))
5142 node = node->rb_right; 5142 node = node->rb_right;
5143 else 5143 else
5144 break; 5144 break;
5145 } 5145 }
5146 if (!node) { 5146 if (!node) {
5147 while (prev) { 5147 while (prev) {
5148 entry = rb_entry(prev, struct btrfs_inode, rb_node); 5148 entry = rb_entry(prev, struct btrfs_inode, rb_node);
5149 if (objectid <= btrfs_ino(&entry->vfs_inode)) { 5149 if (objectid <= btrfs_ino(&entry->vfs_inode)) {
5150 node = prev; 5150 node = prev;
5151 break; 5151 break;
5152 } 5152 }
5153 prev = rb_next(prev); 5153 prev = rb_next(prev);
5154 } 5154 }
5155 } 5155 }
5156 while (node) { 5156 while (node) {
5157 entry = rb_entry(node, struct btrfs_inode, rb_node); 5157 entry = rb_entry(node, struct btrfs_inode, rb_node);
5158 objectid = btrfs_ino(&entry->vfs_inode) + 1; 5158 objectid = btrfs_ino(&entry->vfs_inode) + 1;
5159 inode = igrab(&entry->vfs_inode); 5159 inode = igrab(&entry->vfs_inode);
5160 if (inode) { 5160 if (inode) {
5161 spin_unlock(&root->inode_lock); 5161 spin_unlock(&root->inode_lock);
5162 if (atomic_read(&inode->i_count) > 1) 5162 if (atomic_read(&inode->i_count) > 1)
5163 d_prune_aliases(inode); 5163 d_prune_aliases(inode);
5164 /* 5164 /*
5165 * btrfs_drop_inode will have it removed from 5165 * btrfs_drop_inode will have it removed from
5166 * the inode cache when its usage count 5166 * the inode cache when its usage count
5167 * hits zero. 5167 * hits zero.
5168 */ 5168 */
5169 iput(inode); 5169 iput(inode);
5170 cond_resched(); 5170 cond_resched();
5171 spin_lock(&root->inode_lock); 5171 spin_lock(&root->inode_lock);
5172 goto again; 5172 goto again;
5173 } 5173 }
5174 5174
5175 if (cond_resched_lock(&root->inode_lock)) 5175 if (cond_resched_lock(&root->inode_lock))
5176 goto again; 5176 goto again;
5177 5177
5178 node = rb_next(node); 5178 node = rb_next(node);
5179 } 5179 }
5180 spin_unlock(&root->inode_lock); 5180 spin_unlock(&root->inode_lock);
5181 } 5181 }
5182 5182
5183 static int btrfs_init_locked_inode(struct inode *inode, void *p) 5183 static int btrfs_init_locked_inode(struct inode *inode, void *p)
5184 { 5184 {
5185 struct btrfs_iget_args *args = p; 5185 struct btrfs_iget_args *args = p;
5186 inode->i_ino = args->location->objectid; 5186 inode->i_ino = args->location->objectid;
5187 memcpy(&BTRFS_I(inode)->location, args->location, 5187 memcpy(&BTRFS_I(inode)->location, args->location,
5188 sizeof(*args->location)); 5188 sizeof(*args->location));
5189 BTRFS_I(inode)->root = args->root; 5189 BTRFS_I(inode)->root = args->root;
5190 return 0; 5190 return 0;
5191 } 5191 }
5192 5192
5193 static int btrfs_find_actor(struct inode *inode, void *opaque) 5193 static int btrfs_find_actor(struct inode *inode, void *opaque)
5194 { 5194 {
5195 struct btrfs_iget_args *args = opaque; 5195 struct btrfs_iget_args *args = opaque;
5196 return args->location->objectid == BTRFS_I(inode)->location.objectid && 5196 return args->location->objectid == BTRFS_I(inode)->location.objectid &&
5197 args->root == BTRFS_I(inode)->root; 5197 args->root == BTRFS_I(inode)->root;
5198 } 5198 }
5199 5199
5200 static struct inode *btrfs_iget_locked(struct super_block *s, 5200 static struct inode *btrfs_iget_locked(struct super_block *s,
5201 struct btrfs_key *location, 5201 struct btrfs_key *location,
5202 struct btrfs_root *root) 5202 struct btrfs_root *root)
5203 { 5203 {
5204 struct inode *inode; 5204 struct inode *inode;
5205 struct btrfs_iget_args args; 5205 struct btrfs_iget_args args;
5206 unsigned long hashval = btrfs_inode_hash(location->objectid, root); 5206 unsigned long hashval = btrfs_inode_hash(location->objectid, root);
5207 5207
5208 args.location = location; 5208 args.location = location;
5209 args.root = root; 5209 args.root = root;
5210 5210
5211 inode = iget5_locked(s, hashval, btrfs_find_actor, 5211 inode = iget5_locked(s, hashval, btrfs_find_actor,
5212 btrfs_init_locked_inode, 5212 btrfs_init_locked_inode,
5213 (void *)&args); 5213 (void *)&args);
5214 return inode; 5214 return inode;
5215 } 5215 }
5216 5216
5217 /* Get an inode object given its location and corresponding root. 5217 /* Get an inode object given its location and corresponding root.
5218 * Returns in *is_new if the inode was read from disk 5218 * Returns in *is_new if the inode was read from disk
5219 */ 5219 */
5220 struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location, 5220 struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location,
5221 struct btrfs_root *root, int *new) 5221 struct btrfs_root *root, int *new)
5222 { 5222 {
5223 struct inode *inode; 5223 struct inode *inode;
5224 5224
5225 inode = btrfs_iget_locked(s, location, root); 5225 inode = btrfs_iget_locked(s, location, root);
5226 if (!inode) 5226 if (!inode)
5227 return ERR_PTR(-ENOMEM); 5227 return ERR_PTR(-ENOMEM);
5228 5228
5229 if (inode->i_state & I_NEW) { 5229 if (inode->i_state & I_NEW) {
5230 btrfs_read_locked_inode(inode); 5230 btrfs_read_locked_inode(inode);
5231 if (!is_bad_inode(inode)) { 5231 if (!is_bad_inode(inode)) {
5232 inode_tree_add(inode); 5232 inode_tree_add(inode);
5233 unlock_new_inode(inode); 5233 unlock_new_inode(inode);
5234 if (new) 5234 if (new)
5235 *new = 1; 5235 *new = 1;
5236 } else { 5236 } else {
5237 unlock_new_inode(inode); 5237 unlock_new_inode(inode);
5238 iput(inode); 5238 iput(inode);
5239 inode = ERR_PTR(-ESTALE); 5239 inode = ERR_PTR(-ESTALE);
5240 } 5240 }
5241 } 5241 }
5242 5242
5243 return inode; 5243 return inode;
5244 } 5244 }
5245 5245
5246 static struct inode *new_simple_dir(struct super_block *s, 5246 static struct inode *new_simple_dir(struct super_block *s,
5247 struct btrfs_key *key, 5247 struct btrfs_key *key,
5248 struct btrfs_root *root) 5248 struct btrfs_root *root)
5249 { 5249 {
5250 struct inode *inode = new_inode(s); 5250 struct inode *inode = new_inode(s);
5251 5251
5252 if (!inode) 5252 if (!inode)
5253 return ERR_PTR(-ENOMEM); 5253 return ERR_PTR(-ENOMEM);
5254 5254
5255 BTRFS_I(inode)->root = root; 5255 BTRFS_I(inode)->root = root;
5256 memcpy(&BTRFS_I(inode)->location, key, sizeof(*key)); 5256 memcpy(&BTRFS_I(inode)->location, key, sizeof(*key));
5257 set_bit(BTRFS_INODE_DUMMY, &BTRFS_I(inode)->runtime_flags); 5257 set_bit(BTRFS_INODE_DUMMY, &BTRFS_I(inode)->runtime_flags);
5258 5258
5259 inode->i_ino = BTRFS_EMPTY_SUBVOL_DIR_OBJECTID; 5259 inode->i_ino = BTRFS_EMPTY_SUBVOL_DIR_OBJECTID;
5260 inode->i_op = &btrfs_dir_ro_inode_operations; 5260 inode->i_op = &btrfs_dir_ro_inode_operations;
5261 inode->i_fop = &simple_dir_operations; 5261 inode->i_fop = &simple_dir_operations;
5262 inode->i_mode = S_IFDIR | S_IRUGO | S_IWUSR | S_IXUGO; 5262 inode->i_mode = S_IFDIR | S_IRUGO | S_IWUSR | S_IXUGO;
5263 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; 5263 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
5264 5264
5265 return inode; 5265 return inode;
5266 } 5266 }
5267 5267
5268 struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry) 5268 struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry)
5269 { 5269 {
5270 struct inode *inode; 5270 struct inode *inode;
5271 struct btrfs_root *root = BTRFS_I(dir)->root; 5271 struct btrfs_root *root = BTRFS_I(dir)->root;
5272 struct btrfs_root *sub_root = root; 5272 struct btrfs_root *sub_root = root;
5273 struct btrfs_key location; 5273 struct btrfs_key location;
5274 int index; 5274 int index;
5275 int ret = 0; 5275 int ret = 0;
5276 5276
5277 if (dentry->d_name.len > BTRFS_NAME_LEN) 5277 if (dentry->d_name.len > BTRFS_NAME_LEN)
5278 return ERR_PTR(-ENAMETOOLONG); 5278 return ERR_PTR(-ENAMETOOLONG);
5279 5279
5280 ret = btrfs_inode_by_name(dir, dentry, &location); 5280 ret = btrfs_inode_by_name(dir, dentry, &location);
5281 if (ret < 0) 5281 if (ret < 0)
5282 return ERR_PTR(ret); 5282 return ERR_PTR(ret);
5283 5283
5284 if (location.objectid == 0) 5284 if (location.objectid == 0)
5285 return ERR_PTR(-ENOENT); 5285 return ERR_PTR(-ENOENT);
5286 5286
5287 if (location.type == BTRFS_INODE_ITEM_KEY) { 5287 if (location.type == BTRFS_INODE_ITEM_KEY) {
5288 inode = btrfs_iget(dir->i_sb, &location, root, NULL); 5288 inode = btrfs_iget(dir->i_sb, &location, root, NULL);
5289 return inode; 5289 return inode;
5290 } 5290 }
5291 5291
5292 BUG_ON(location.type != BTRFS_ROOT_ITEM_KEY); 5292 BUG_ON(location.type != BTRFS_ROOT_ITEM_KEY);
5293 5293
5294 index = srcu_read_lock(&root->fs_info->subvol_srcu); 5294 index = srcu_read_lock(&root->fs_info->subvol_srcu);
5295 ret = fixup_tree_root_location(root, dir, dentry, 5295 ret = fixup_tree_root_location(root, dir, dentry,
5296 &location, &sub_root); 5296 &location, &sub_root);
5297 if (ret < 0) { 5297 if (ret < 0) {
5298 if (ret != -ENOENT) 5298 if (ret != -ENOENT)
5299 inode = ERR_PTR(ret); 5299 inode = ERR_PTR(ret);
5300 else 5300 else
5301 inode = new_simple_dir(dir->i_sb, &location, sub_root); 5301 inode = new_simple_dir(dir->i_sb, &location, sub_root);
5302 } else { 5302 } else {
5303 inode = btrfs_iget(dir->i_sb, &location, sub_root, NULL); 5303 inode = btrfs_iget(dir->i_sb, &location, sub_root, NULL);
5304 } 5304 }
5305 srcu_read_unlock(&root->fs_info->subvol_srcu, index); 5305 srcu_read_unlock(&root->fs_info->subvol_srcu, index);
5306 5306
5307 if (!IS_ERR(inode) && root != sub_root) { 5307 if (!IS_ERR(inode) && root != sub_root) {
5308 down_read(&root->fs_info->cleanup_work_sem); 5308 down_read(&root->fs_info->cleanup_work_sem);
5309 if (!(inode->i_sb->s_flags & MS_RDONLY)) 5309 if (!(inode->i_sb->s_flags & MS_RDONLY))
5310 ret = btrfs_orphan_cleanup(sub_root); 5310 ret = btrfs_orphan_cleanup(sub_root);
5311 up_read(&root->fs_info->cleanup_work_sem); 5311 up_read(&root->fs_info->cleanup_work_sem);
5312 if (ret) { 5312 if (ret) {
5313 iput(inode); 5313 iput(inode);
5314 inode = ERR_PTR(ret); 5314 inode = ERR_PTR(ret);
5315 } 5315 }
5316 } 5316 }
5317 5317
5318 return inode; 5318 return inode;
5319 } 5319 }
5320 5320
5321 static int btrfs_dentry_delete(const struct dentry *dentry) 5321 static int btrfs_dentry_delete(const struct dentry *dentry)
5322 { 5322 {
5323 struct btrfs_root *root; 5323 struct btrfs_root *root;
5324 struct inode *inode = dentry->d_inode; 5324 struct inode *inode = dentry->d_inode;
5325 5325
5326 if (!inode && !IS_ROOT(dentry)) 5326 if (!inode && !IS_ROOT(dentry))
5327 inode = dentry->d_parent->d_inode; 5327 inode = dentry->d_parent->d_inode;
5328 5328
5329 if (inode) { 5329 if (inode) {
5330 root = BTRFS_I(inode)->root; 5330 root = BTRFS_I(inode)->root;
5331 if (btrfs_root_refs(&root->root_item) == 0) 5331 if (btrfs_root_refs(&root->root_item) == 0)
5332 return 1; 5332 return 1;
5333 5333
5334 if (btrfs_ino(inode) == BTRFS_EMPTY_SUBVOL_DIR_OBJECTID) 5334 if (btrfs_ino(inode) == BTRFS_EMPTY_SUBVOL_DIR_OBJECTID)
5335 return 1; 5335 return 1;
5336 } 5336 }
5337 return 0; 5337 return 0;
5338 } 5338 }
5339 5339
5340 static void btrfs_dentry_release(struct dentry *dentry) 5340 static void btrfs_dentry_release(struct dentry *dentry)
5341 { 5341 {
5342 kfree(dentry->d_fsdata); 5342 kfree(dentry->d_fsdata);
5343 } 5343 }
5344 5344
5345 static struct dentry *btrfs_lookup(struct inode *dir, struct dentry *dentry, 5345 static struct dentry *btrfs_lookup(struct inode *dir, struct dentry *dentry,
5346 unsigned int flags) 5346 unsigned int flags)
5347 { 5347 {
5348 struct inode *inode; 5348 struct inode *inode;
5349 5349
5350 inode = btrfs_lookup_dentry(dir, dentry); 5350 inode = btrfs_lookup_dentry(dir, dentry);
5351 if (IS_ERR(inode)) { 5351 if (IS_ERR(inode)) {
5352 if (PTR_ERR(inode) == -ENOENT) 5352 if (PTR_ERR(inode) == -ENOENT)
5353 inode = NULL; 5353 inode = NULL;
5354 else 5354 else
5355 return ERR_CAST(inode); 5355 return ERR_CAST(inode);
5356 } 5356 }
5357 5357
5358 return d_splice_alias(inode, dentry); 5358 return d_splice_alias(inode, dentry);
5359 } 5359 }
5360 5360
5361 unsigned char btrfs_filetype_table[] = { 5361 unsigned char btrfs_filetype_table[] = {
5362 DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK 5362 DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK
5363 }; 5363 };
5364 5364
5365 static int btrfs_real_readdir(struct file *file, struct dir_context *ctx) 5365 static int btrfs_real_readdir(struct file *file, struct dir_context *ctx)
5366 { 5366 {
5367 struct inode *inode = file_inode(file); 5367 struct inode *inode = file_inode(file);
5368 struct btrfs_root *root = BTRFS_I(inode)->root; 5368 struct btrfs_root *root = BTRFS_I(inode)->root;
5369 struct btrfs_item *item; 5369 struct btrfs_item *item;
5370 struct btrfs_dir_item *di; 5370 struct btrfs_dir_item *di;
5371 struct btrfs_key key; 5371 struct btrfs_key key;
5372 struct btrfs_key found_key; 5372 struct btrfs_key found_key;
5373 struct btrfs_path *path; 5373 struct btrfs_path *path;
5374 struct list_head ins_list; 5374 struct list_head ins_list;
5375 struct list_head del_list; 5375 struct list_head del_list;
5376 int ret; 5376 int ret;
5377 struct extent_buffer *leaf; 5377 struct extent_buffer *leaf;
5378 int slot; 5378 int slot;
5379 unsigned char d_type; 5379 unsigned char d_type;
5380 int over = 0; 5380 int over = 0;
5381 u32 di_cur; 5381 u32 di_cur;
5382 u32 di_total; 5382 u32 di_total;
5383 u32 di_len; 5383 u32 di_len;
5384 int key_type = BTRFS_DIR_INDEX_KEY; 5384 int key_type = BTRFS_DIR_INDEX_KEY;
5385 char tmp_name[32]; 5385 char tmp_name[32];
5386 char *name_ptr; 5386 char *name_ptr;
5387 int name_len; 5387 int name_len;
5388 int is_curr = 0; /* ctx->pos points to the current index? */ 5388 int is_curr = 0; /* ctx->pos points to the current index? */
5389 5389
5390 /* FIXME, use a real flag for deciding about the key type */ 5390 /* FIXME, use a real flag for deciding about the key type */
5391 if (root->fs_info->tree_root == root) 5391 if (root->fs_info->tree_root == root)
5392 key_type = BTRFS_DIR_ITEM_KEY; 5392 key_type = BTRFS_DIR_ITEM_KEY;
5393 5393
5394 if (!dir_emit_dots(file, ctx)) 5394 if (!dir_emit_dots(file, ctx))
5395 return 0; 5395 return 0;
5396 5396
5397 path = btrfs_alloc_path(); 5397 path = btrfs_alloc_path();
5398 if (!path) 5398 if (!path)
5399 return -ENOMEM; 5399 return -ENOMEM;
5400 5400
5401 path->reada = 1; 5401 path->reada = 1;
5402 5402
5403 if (key_type == BTRFS_DIR_INDEX_KEY) { 5403 if (key_type == BTRFS_DIR_INDEX_KEY) {
5404 INIT_LIST_HEAD(&ins_list); 5404 INIT_LIST_HEAD(&ins_list);
5405 INIT_LIST_HEAD(&del_list); 5405 INIT_LIST_HEAD(&del_list);
5406 btrfs_get_delayed_items(inode, &ins_list, &del_list); 5406 btrfs_get_delayed_items(inode, &ins_list, &del_list);
5407 } 5407 }
5408 5408
5409 key.type = key_type; 5409 key.type = key_type;
5410 key.offset = ctx->pos; 5410 key.offset = ctx->pos;
5411 key.objectid = btrfs_ino(inode); 5411 key.objectid = btrfs_ino(inode);
5412 5412
5413 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); 5413 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
5414 if (ret < 0) 5414 if (ret < 0)
5415 goto err; 5415 goto err;
5416 5416
5417 while (1) { 5417 while (1) {
5418 leaf = path->nodes[0]; 5418 leaf = path->nodes[0];
5419 slot = path->slots[0]; 5419 slot = path->slots[0];
5420 if (slot >= btrfs_header_nritems(leaf)) { 5420 if (slot >= btrfs_header_nritems(leaf)) {
5421 ret = btrfs_next_leaf(root, path); 5421 ret = btrfs_next_leaf(root, path);
5422 if (ret < 0) 5422 if (ret < 0)
5423 goto err; 5423 goto err;
5424 else if (ret > 0) 5424 else if (ret > 0)
5425 break; 5425 break;
5426 continue; 5426 continue;
5427 } 5427 }
5428 5428
5429 item = btrfs_item_nr(slot); 5429 item = btrfs_item_nr(slot);
5430 btrfs_item_key_to_cpu(leaf, &found_key, slot); 5430 btrfs_item_key_to_cpu(leaf, &found_key, slot);
5431 5431
5432 if (found_key.objectid != key.objectid) 5432 if (found_key.objectid != key.objectid)
5433 break; 5433 break;
5434 if (found_key.type != key_type) 5434 if (found_key.type != key_type)
5435 break; 5435 break;
5436 if (found_key.offset < ctx->pos) 5436 if (found_key.offset < ctx->pos)
5437 goto next; 5437 goto next;
5438 if (key_type == BTRFS_DIR_INDEX_KEY && 5438 if (key_type == BTRFS_DIR_INDEX_KEY &&
5439 btrfs_should_delete_dir_index(&del_list, 5439 btrfs_should_delete_dir_index(&del_list,
5440 found_key.offset)) 5440 found_key.offset))
5441 goto next; 5441 goto next;
5442 5442
5443 ctx->pos = found_key.offset; 5443 ctx->pos = found_key.offset;
5444 is_curr = 1; 5444 is_curr = 1;
5445 5445
5446 di = btrfs_item_ptr(leaf, slot, struct btrfs_dir_item); 5446 di = btrfs_item_ptr(leaf, slot, struct btrfs_dir_item);
5447 di_cur = 0; 5447 di_cur = 0;
5448 di_total = btrfs_item_size(leaf, item); 5448 di_total = btrfs_item_size(leaf, item);
5449 5449
5450 while (di_cur < di_total) { 5450 while (di_cur < di_total) {
5451 struct btrfs_key location; 5451 struct btrfs_key location;
5452 5452
5453 if (verify_dir_item(root, leaf, di)) 5453 if (verify_dir_item(root, leaf, di))
5454 break; 5454 break;
5455 5455
5456 name_len = btrfs_dir_name_len(leaf, di); 5456 name_len = btrfs_dir_name_len(leaf, di);
5457 if (name_len <= sizeof(tmp_name)) { 5457 if (name_len <= sizeof(tmp_name)) {
5458 name_ptr = tmp_name; 5458 name_ptr = tmp_name;
5459 } else { 5459 } else {
5460 name_ptr = kmalloc(name_len, GFP_NOFS); 5460 name_ptr = kmalloc(name_len, GFP_NOFS);
5461 if (!name_ptr) { 5461 if (!name_ptr) {
5462 ret = -ENOMEM; 5462 ret = -ENOMEM;
5463 goto err; 5463 goto err;
5464 } 5464 }
5465 } 5465 }
5466 read_extent_buffer(leaf, name_ptr, 5466 read_extent_buffer(leaf, name_ptr,
5467 (unsigned long)(di + 1), name_len); 5467 (unsigned long)(di + 1), name_len);
5468 5468
5469 d_type = btrfs_filetype_table[btrfs_dir_type(leaf, di)]; 5469 d_type = btrfs_filetype_table[btrfs_dir_type(leaf, di)];
5470 btrfs_dir_item_key_to_cpu(leaf, di, &location); 5470 btrfs_dir_item_key_to_cpu(leaf, di, &location);
5471 5471
5472 5472
5473 /* is this a reference to our own snapshot? If so 5473 /* is this a reference to our own snapshot? If so
5474 * skip it. 5474 * skip it.
5475 * 5475 *
5476 * In contrast to old kernels, we insert the snapshot's 5476 * In contrast to old kernels, we insert the snapshot's
5477 * dir item and dir index after it has been created, so 5477 * dir item and dir index after it has been created, so
5478 * we won't find a reference to our own snapshot. We 5478 * we won't find a reference to our own snapshot. We
5479 * still keep the following code for backward 5479 * still keep the following code for backward
5480 * compatibility. 5480 * compatibility.
5481 */ 5481 */
5482 if (location.type == BTRFS_ROOT_ITEM_KEY && 5482 if (location.type == BTRFS_ROOT_ITEM_KEY &&
5483 location.objectid == root->root_key.objectid) { 5483 location.objectid == root->root_key.objectid) {
5484 over = 0; 5484 over = 0;
5485 goto skip; 5485 goto skip;
5486 } 5486 }
5487 over = !dir_emit(ctx, name_ptr, name_len, 5487 over = !dir_emit(ctx, name_ptr, name_len,
5488 location.objectid, d_type); 5488 location.objectid, d_type);
5489 5489
5490 skip: 5490 skip:
5491 if (name_ptr != tmp_name) 5491 if (name_ptr != tmp_name)
5492 kfree(name_ptr); 5492 kfree(name_ptr);
5493 5493
5494 if (over) 5494 if (over)
5495 goto nopos; 5495 goto nopos;
5496 di_len = btrfs_dir_name_len(leaf, di) + 5496 di_len = btrfs_dir_name_len(leaf, di) +
5497 btrfs_dir_data_len(leaf, di) + sizeof(*di); 5497 btrfs_dir_data_len(leaf, di) + sizeof(*di);
5498 di_cur += di_len; 5498 di_cur += di_len;
5499 di = (struct btrfs_dir_item *)((char *)di + di_len); 5499 di = (struct btrfs_dir_item *)((char *)di + di_len);
5500 } 5500 }
5501 next: 5501 next:
5502 path->slots[0]++; 5502 path->slots[0]++;
5503 } 5503 }
5504 5504
5505 if (key_type == BTRFS_DIR_INDEX_KEY) { 5505 if (key_type == BTRFS_DIR_INDEX_KEY) {
5506 if (is_curr) 5506 if (is_curr)
5507 ctx->pos++; 5507 ctx->pos++;
5508 ret = btrfs_readdir_delayed_dir_index(ctx, &ins_list); 5508 ret = btrfs_readdir_delayed_dir_index(ctx, &ins_list);
5509 if (ret) 5509 if (ret)
5510 goto nopos; 5510 goto nopos;
5511 } 5511 }
5512 5512
5513 /* Reached end of directory/root. Bump pos past the last item. */ 5513 /* Reached end of directory/root. Bump pos past the last item. */
5514 ctx->pos++; 5514 ctx->pos++;
5515 5515
5516 /* 5516 /*
5517 * Stop new entries from being returned after we return the last 5517 * Stop new entries from being returned after we return the last
5518 * entry. 5518 * entry.
5519 * 5519 *
5520 * New directory entries are assigned a strictly increasing 5520 * New directory entries are assigned a strictly increasing
5521 * offset. This means that new entries created during readdir 5521 * offset. This means that new entries created during readdir
5522 * are *guaranteed* to be seen in the future by that readdir. 5522 * are *guaranteed* to be seen in the future by that readdir.
5523 * This has broken buggy programs which operate on names as 5523 * This has broken buggy programs which operate on names as
5524 * they're returned by readdir. Until we re-use freed offsets 5524 * they're returned by readdir. Until we re-use freed offsets
5525 * we have this hack to stop new entries from being returned 5525 * we have this hack to stop new entries from being returned
5526 * under the assumption that they'll never reach this huge 5526 * under the assumption that they'll never reach this huge
5527 * offset. 5527 * offset.
5528 * 5528 *
5529 * This is being careful not to overflow 32bit loff_t unless the 5529 * This is being careful not to overflow 32bit loff_t unless the
5530 * last entry requires it because doing so has broken 32bit apps 5530 * last entry requires it because doing so has broken 32bit apps
5531 * in the past. 5531 * in the past.
5532 */ 5532 */
5533 if (key_type == BTRFS_DIR_INDEX_KEY) { 5533 if (key_type == BTRFS_DIR_INDEX_KEY) {
5534 if (ctx->pos >= INT_MAX) 5534 if (ctx->pos >= INT_MAX)
5535 ctx->pos = LLONG_MAX; 5535 ctx->pos = LLONG_MAX;
5536 else 5536 else
5537 ctx->pos = INT_MAX; 5537 ctx->pos = INT_MAX;
5538 } 5538 }
5539 nopos: 5539 nopos:
5540 ret = 0; 5540 ret = 0;
5541 err: 5541 err:
5542 if (key_type == BTRFS_DIR_INDEX_KEY) 5542 if (key_type == BTRFS_DIR_INDEX_KEY)
5543 btrfs_put_delayed_items(&ins_list, &del_list); 5543 btrfs_put_delayed_items(&ins_list, &del_list);
5544 btrfs_free_path(path); 5544 btrfs_free_path(path);
5545 return ret; 5545 return ret;
5546 } 5546 }
5547 5547
5548 int btrfs_write_inode(struct inode *inode, struct writeback_control *wbc) 5548 int btrfs_write_inode(struct inode *inode, struct writeback_control *wbc)
5549 { 5549 {
5550 struct btrfs_root *root = BTRFS_I(inode)->root; 5550 struct btrfs_root *root = BTRFS_I(inode)->root;
5551 struct btrfs_trans_handle *trans; 5551 struct btrfs_trans_handle *trans;
5552 int ret = 0; 5552 int ret = 0;
5553 bool nolock = false; 5553 bool nolock = false;
5554 5554
5555 if (test_bit(BTRFS_INODE_DUMMY, &BTRFS_I(inode)->runtime_flags)) 5555 if (test_bit(BTRFS_INODE_DUMMY, &BTRFS_I(inode)->runtime_flags))
5556 return 0; 5556 return 0;
5557 5557
5558 if (btrfs_fs_closing(root->fs_info) && btrfs_is_free_space_inode(inode)) 5558 if (btrfs_fs_closing(root->fs_info) && btrfs_is_free_space_inode(inode))
5559 nolock = true; 5559 nolock = true;
5560 5560
5561 if (wbc->sync_mode == WB_SYNC_ALL) { 5561 if (wbc->sync_mode == WB_SYNC_ALL) {
5562 if (nolock) 5562 if (nolock)
5563 trans = btrfs_join_transaction_nolock(root); 5563 trans = btrfs_join_transaction_nolock(root);
5564 else 5564 else
5565 trans = btrfs_join_transaction(root); 5565 trans = btrfs_join_transaction(root);
5566 if (IS_ERR(trans)) 5566 if (IS_ERR(trans))
5567 return PTR_ERR(trans); 5567 return PTR_ERR(trans);
5568 ret = btrfs_commit_transaction(trans, root); 5568 ret = btrfs_commit_transaction(trans, root);
5569 } 5569 }
5570 return ret; 5570 return ret;
5571 } 5571 }
5572 5572
5573 /* 5573 /*
5574 * This is somewhat expensive, updating the tree every time the 5574 * This is somewhat expensive, updating the tree every time the
5575 * inode changes. But, it is most likely to find the inode in cache. 5575 * inode changes. But, it is most likely to find the inode in cache.
5576 * FIXME, needs more benchmarking...there are no reasons other than performance 5576 * FIXME, needs more benchmarking...there are no reasons other than performance
5577 * to keep or drop this code. 5577 * to keep or drop this code.
5578 */ 5578 */
5579 static int btrfs_dirty_inode(struct inode *inode) 5579 static int btrfs_dirty_inode(struct inode *inode)
5580 { 5580 {
5581 struct btrfs_root *root = BTRFS_I(inode)->root; 5581 struct btrfs_root *root = BTRFS_I(inode)->root;
5582 struct btrfs_trans_handle *trans; 5582 struct btrfs_trans_handle *trans;
5583 int ret; 5583 int ret;
5584 5584
5585 if (test_bit(BTRFS_INODE_DUMMY, &BTRFS_I(inode)->runtime_flags)) 5585 if (test_bit(BTRFS_INODE_DUMMY, &BTRFS_I(inode)->runtime_flags))
5586 return 0; 5586 return 0;
5587 5587
5588 trans = btrfs_join_transaction(root); 5588 trans = btrfs_join_transaction(root);
5589 if (IS_ERR(trans)) 5589 if (IS_ERR(trans))
5590 return PTR_ERR(trans); 5590 return PTR_ERR(trans);
5591 5591
5592 ret = btrfs_update_inode(trans, root, inode); 5592 ret = btrfs_update_inode(trans, root, inode);
5593 if (ret && ret == -ENOSPC) { 5593 if (ret && ret == -ENOSPC) {
5594 /* whoops, lets try again with the full transaction */ 5594 /* whoops, lets try again with the full transaction */
5595 btrfs_end_transaction(trans, root); 5595 btrfs_end_transaction(trans, root);
5596 trans = btrfs_start_transaction(root, 1); 5596 trans = btrfs_start_transaction(root, 1);
5597 if (IS_ERR(trans)) 5597 if (IS_ERR(trans))
5598 return PTR_ERR(trans); 5598 return PTR_ERR(trans);
5599 5599
5600 ret = btrfs_update_inode(trans, root, inode); 5600 ret = btrfs_update_inode(trans, root, inode);
5601 } 5601 }
5602 btrfs_end_transaction(trans, root); 5602 btrfs_end_transaction(trans, root);
5603 if (BTRFS_I(inode)->delayed_node) 5603 if (BTRFS_I(inode)->delayed_node)
5604 btrfs_balance_delayed_items(root); 5604 btrfs_balance_delayed_items(root);
5605 5605
5606 return ret; 5606 return ret;
5607 } 5607 }
5608 5608
5609 /* 5609 /*
5610 * This is a copy of file_update_time. We need this so we can return error on 5610 * This is a copy of file_update_time. We need this so we can return error on
5611 * ENOSPC for updating the inode in the case of file write and mmap writes. 5611 * ENOSPC for updating the inode in the case of file write and mmap writes.
5612 */ 5612 */
5613 static int btrfs_update_time(struct inode *inode, struct timespec *now, 5613 static int btrfs_update_time(struct inode *inode, struct timespec *now,
5614 int flags) 5614 int flags)
5615 { 5615 {
5616 struct btrfs_root *root = BTRFS_I(inode)->root; 5616 struct btrfs_root *root = BTRFS_I(inode)->root;
5617 5617
5618 if (btrfs_root_readonly(root)) 5618 if (btrfs_root_readonly(root))
5619 return -EROFS; 5619 return -EROFS;
5620 5620
5621 if (flags & S_VERSION) 5621 if (flags & S_VERSION)
5622 inode_inc_iversion(inode); 5622 inode_inc_iversion(inode);
5623 if (flags & S_CTIME) 5623 if (flags & S_CTIME)
5624 inode->i_ctime = *now; 5624 inode->i_ctime = *now;
5625 if (flags & S_MTIME) 5625 if (flags & S_MTIME)
5626 inode->i_mtime = *now; 5626 inode->i_mtime = *now;
5627 if (flags & S_ATIME) 5627 if (flags & S_ATIME)
5628 inode->i_atime = *now; 5628 inode->i_atime = *now;
5629 return btrfs_dirty_inode(inode); 5629 return btrfs_dirty_inode(inode);
5630 } 5630 }
5631 5631
5632 /* 5632 /*
5633 * find the highest existing sequence number in a directory 5633 * find the highest existing sequence number in a directory
5634 * and then set the in-memory index_cnt variable to reflect 5634 * and then set the in-memory index_cnt variable to reflect
5635 * free sequence numbers 5635 * free sequence numbers
5636 */ 5636 */
5637 static int btrfs_set_inode_index_count(struct inode *inode) 5637 static int btrfs_set_inode_index_count(struct inode *inode)
5638 { 5638 {
5639 struct btrfs_root *root = BTRFS_I(inode)->root; 5639 struct btrfs_root *root = BTRFS_I(inode)->root;
5640 struct btrfs_key key, found_key; 5640 struct btrfs_key key, found_key;
5641 struct btrfs_path *path; 5641 struct btrfs_path *path;
5642 struct extent_buffer *leaf; 5642 struct extent_buffer *leaf;
5643 int ret; 5643 int ret;
5644 5644
5645 key.objectid = btrfs_ino(inode); 5645 key.objectid = btrfs_ino(inode);
5646 key.type = BTRFS_DIR_INDEX_KEY; 5646 key.type = BTRFS_DIR_INDEX_KEY;
5647 key.offset = (u64)-1; 5647 key.offset = (u64)-1;
5648 5648
5649 path = btrfs_alloc_path(); 5649 path = btrfs_alloc_path();
5650 if (!path) 5650 if (!path)
5651 return -ENOMEM; 5651 return -ENOMEM;
5652 5652
5653 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); 5653 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
5654 if (ret < 0) 5654 if (ret < 0)
5655 goto out; 5655 goto out;
5656 /* FIXME: we should be able to handle this */ 5656 /* FIXME: we should be able to handle this */
5657 if (ret == 0) 5657 if (ret == 0)
5658 goto out; 5658 goto out;
5659 ret = 0; 5659 ret = 0;
5660 5660
5661 /* 5661 /*
5662 * MAGIC NUMBER EXPLANATION: 5662 * MAGIC NUMBER EXPLANATION:
5663 * since we search a directory based on f_pos we have to start at 2 5663 * since we search a directory based on f_pos we have to start at 2
5664 * since '.' and '..' have f_pos of 0 and 1 respectively, so everybody 5664 * since '.' and '..' have f_pos of 0 and 1 respectively, so everybody
5665 * else has to start at 2 5665 * else has to start at 2
5666 */ 5666 */
5667 if (path->slots[0] == 0) { 5667 if (path->slots[0] == 0) {
5668 BTRFS_I(inode)->index_cnt = 2; 5668 BTRFS_I(inode)->index_cnt = 2;
5669 goto out; 5669 goto out;
5670 } 5670 }
5671 5671
5672 path->slots[0]--; 5672 path->slots[0]--;
5673 5673
5674 leaf = path->nodes[0]; 5674 leaf = path->nodes[0];
5675 btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]); 5675 btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]);
5676 5676
5677 if (found_key.objectid != btrfs_ino(inode) || 5677 if (found_key.objectid != btrfs_ino(inode) ||
5678 found_key.type != BTRFS_DIR_INDEX_KEY) { 5678 found_key.type != BTRFS_DIR_INDEX_KEY) {
5679 BTRFS_I(inode)->index_cnt = 2; 5679 BTRFS_I(inode)->index_cnt = 2;
5680 goto out; 5680 goto out;
5681 } 5681 }
5682 5682
5683 BTRFS_I(inode)->index_cnt = found_key.offset + 1; 5683 BTRFS_I(inode)->index_cnt = found_key.offset + 1;
5684 out: 5684 out:
5685 btrfs_free_path(path); 5685 btrfs_free_path(path);
5686 return ret; 5686 return ret;
5687 } 5687 }
5688 5688
5689 /* 5689 /*
5690 * helper to find a free sequence number in a given directory. This current 5690 * helper to find a free sequence number in a given directory. This current
5691 * code is very simple, later versions will do smarter things in the btree 5691 * code is very simple, later versions will do smarter things in the btree
5692 */ 5692 */
5693 int btrfs_set_inode_index(struct inode *dir, u64 *index) 5693 int btrfs_set_inode_index(struct inode *dir, u64 *index)
5694 { 5694 {
5695 int ret = 0; 5695 int ret = 0;
5696 5696
5697 if (BTRFS_I(dir)->index_cnt == (u64)-1) { 5697 if (BTRFS_I(dir)->index_cnt == (u64)-1) {
5698 ret = btrfs_inode_delayed_dir_index_count(dir); 5698 ret = btrfs_inode_delayed_dir_index_count(dir);
5699 if (ret) { 5699 if (ret) {
5700 ret = btrfs_set_inode_index_count(dir); 5700 ret = btrfs_set_inode_index_count(dir);
5701 if (ret) 5701 if (ret)
5702 return ret; 5702 return ret;
5703 } 5703 }
5704 } 5704 }
5705 5705
5706 *index = BTRFS_I(dir)->index_cnt; 5706 *index = BTRFS_I(dir)->index_cnt;
5707 BTRFS_I(dir)->index_cnt++; 5707 BTRFS_I(dir)->index_cnt++;
5708 5708
5709 return ret; 5709 return ret;
5710 } 5710 }
5711 5711
5712 static int btrfs_insert_inode_locked(struct inode *inode) 5712 static int btrfs_insert_inode_locked(struct inode *inode)
5713 { 5713 {
5714 struct btrfs_iget_args args; 5714 struct btrfs_iget_args args;
5715 args.location = &BTRFS_I(inode)->location; 5715 args.location = &BTRFS_I(inode)->location;
5716 args.root = BTRFS_I(inode)->root; 5716 args.root = BTRFS_I(inode)->root;
5717 5717
5718 return insert_inode_locked4(inode, 5718 return insert_inode_locked4(inode,
5719 btrfs_inode_hash(inode->i_ino, BTRFS_I(inode)->root), 5719 btrfs_inode_hash(inode->i_ino, BTRFS_I(inode)->root),
5720 btrfs_find_actor, &args); 5720 btrfs_find_actor, &args);
5721 } 5721 }
5722 5722
5723 static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, 5723 static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,
5724 struct btrfs_root *root, 5724 struct btrfs_root *root,
5725 struct inode *dir, 5725 struct inode *dir,
5726 const char *name, int name_len, 5726 const char *name, int name_len,
5727 u64 ref_objectid, u64 objectid, 5727 u64 ref_objectid, u64 objectid,
5728 umode_t mode, u64 *index) 5728 umode_t mode, u64 *index)
5729 { 5729 {
5730 struct inode *inode; 5730 struct inode *inode;
5731 struct btrfs_inode_item *inode_item; 5731 struct btrfs_inode_item *inode_item;
5732 struct btrfs_key *location; 5732 struct btrfs_key *location;
5733 struct btrfs_path *path; 5733 struct btrfs_path *path;
5734 struct btrfs_inode_ref *ref; 5734 struct btrfs_inode_ref *ref;
5735 struct btrfs_key key[2]; 5735 struct btrfs_key key[2];
5736 u32 sizes[2]; 5736 u32 sizes[2];
5737 int nitems = name ? 2 : 1; 5737 int nitems = name ? 2 : 1;
5738 unsigned long ptr; 5738 unsigned long ptr;
5739 int ret; 5739 int ret;
5740 5740
5741 path = btrfs_alloc_path(); 5741 path = btrfs_alloc_path();
5742 if (!path) 5742 if (!path)
5743 return ERR_PTR(-ENOMEM); 5743 return ERR_PTR(-ENOMEM);
5744 5744
5745 inode = new_inode(root->fs_info->sb); 5745 inode = new_inode(root->fs_info->sb);
5746 if (!inode) { 5746 if (!inode) {
5747 btrfs_free_path(path); 5747 btrfs_free_path(path);
5748 return ERR_PTR(-ENOMEM); 5748 return ERR_PTR(-ENOMEM);
5749 } 5749 }
5750 5750
5751 /* 5751 /*
5752 * O_TMPFILE, set link count to 0, so that after this point, 5752 * O_TMPFILE, set link count to 0, so that after this point,
5753 * we fill in an inode item with the correct link count. 5753 * we fill in an inode item with the correct link count.
5754 */ 5754 */
5755 if (!name) 5755 if (!name)
5756 set_nlink(inode, 0); 5756 set_nlink(inode, 0);
5757 5757
5758 /* 5758 /*
5759 * we have to initialize this early, so we can reclaim the inode 5759 * we have to initialize this early, so we can reclaim the inode
5760 * number if we fail afterwards in this function. 5760 * number if we fail afterwards in this function.
5761 */ 5761 */
5762 inode->i_ino = objectid; 5762 inode->i_ino = objectid;
5763 5763
5764 if (dir && name) { 5764 if (dir && name) {
5765 trace_btrfs_inode_request(dir); 5765 trace_btrfs_inode_request(dir);
5766 5766
5767 ret = btrfs_set_inode_index(dir, index); 5767 ret = btrfs_set_inode_index(dir, index);
5768 if (ret) { 5768 if (ret) {
5769 btrfs_free_path(path); 5769 btrfs_free_path(path);
5770 iput(inode); 5770 iput(inode);
5771 return ERR_PTR(ret); 5771 return ERR_PTR(ret);
5772 } 5772 }
5773 } else if (dir) { 5773 } else if (dir) {
5774 *index = 0; 5774 *index = 0;
5775 } 5775 }
5776 /* 5776 /*
5777 * index_cnt is ignored for everything but a dir, 5777 * index_cnt is ignored for everything but a dir,
5778 * btrfs_get_inode_index_count has an explanation for the magic 5778 * btrfs_get_inode_index_count has an explanation for the magic
5779 * number 5779 * number
5780 */ 5780 */
5781 BTRFS_I(inode)->index_cnt = 2; 5781 BTRFS_I(inode)->index_cnt = 2;
5782 BTRFS_I(inode)->dir_index = *index; 5782 BTRFS_I(inode)->dir_index = *index;
5783 BTRFS_I(inode)->root = root; 5783 BTRFS_I(inode)->root = root;
5784 BTRFS_I(inode)->generation = trans->transid; 5784 BTRFS_I(inode)->generation = trans->transid;
5785 inode->i_generation = BTRFS_I(inode)->generation; 5785 inode->i_generation = BTRFS_I(inode)->generation;
5786 5786
5787 /* 5787 /*
5788 * We could have gotten an inode number from somebody who was fsynced 5788 * We could have gotten an inode number from somebody who was fsynced
5789 * and then removed in this same transaction, so let's just set full 5789 * and then removed in this same transaction, so let's just set full
5790 * sync since it will be a full sync anyway and this will blow away the 5790 * sync since it will be a full sync anyway and this will blow away the
5791 * old info in the log. 5791 * old info in the log.
5792 */ 5792 */
5793 set_bit(BTRFS_INODE_NEEDS_FULL_SYNC, &BTRFS_I(inode)->runtime_flags); 5793 set_bit(BTRFS_INODE_NEEDS_FULL_SYNC, &BTRFS_I(inode)->runtime_flags);
5794 5794
5795 key[0].objectid = objectid; 5795 key[0].objectid = objectid;
5796 key[0].type = BTRFS_INODE_ITEM_KEY; 5796 key[0].type = BTRFS_INODE_ITEM_KEY;
5797 key[0].offset = 0; 5797 key[0].offset = 0;
5798 5798
5799 sizes[0] = sizeof(struct btrfs_inode_item); 5799 sizes[0] = sizeof(struct btrfs_inode_item);
5800 5800
5801 if (name) { 5801 if (name) {
5802 /* 5802 /*
5803 * Start new inodes with an inode_ref. This is slightly more 5803 * Start new inodes with an inode_ref. This is slightly more
5804 * efficient for small numbers of hard links since they will 5804 * efficient for small numbers of hard links since they will
5805 * be packed into one item. Extended refs will kick in if we 5805 * be packed into one item. Extended refs will kick in if we
5806 * add more hard links than can fit in the ref item. 5806 * add more hard links than can fit in the ref item.
5807 */ 5807 */
5808 key[1].objectid = objectid; 5808 key[1].objectid = objectid;
5809 key[1].type = BTRFS_INODE_REF_KEY; 5809 key[1].type = BTRFS_INODE_REF_KEY;
5810 key[1].offset = ref_objectid; 5810 key[1].offset = ref_objectid;
5811 5811
5812 sizes[1] = name_len + sizeof(*ref); 5812 sizes[1] = name_len + sizeof(*ref);
5813 } 5813 }
5814 5814
5815 location = &BTRFS_I(inode)->location; 5815 location = &BTRFS_I(inode)->location;
5816 location->objectid = objectid; 5816 location->objectid = objectid;
5817 location->offset = 0; 5817 location->offset = 0;
5818 location->type = BTRFS_INODE_ITEM_KEY; 5818 location->type = BTRFS_INODE_ITEM_KEY;
5819 5819
5820 ret = btrfs_insert_inode_locked(inode); 5820 ret = btrfs_insert_inode_locked(inode);
5821 if (ret < 0) 5821 if (ret < 0)
5822 goto fail; 5822 goto fail;
5823 5823
5824 path->leave_spinning = 1; 5824 path->leave_spinning = 1;
5825 ret = btrfs_insert_empty_items(trans, root, path, key, sizes, nitems); 5825 ret = btrfs_insert_empty_items(trans, root, path, key, sizes, nitems);
5826 if (ret != 0) 5826 if (ret != 0)
5827 goto fail_unlock; 5827 goto fail_unlock;
5828 5828
5829 inode_init_owner(inode, dir, mode); 5829 inode_init_owner(inode, dir, mode);
5830 inode_set_bytes(inode, 0); 5830 inode_set_bytes(inode, 0);
5831 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; 5831 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
5832 inode_item = btrfs_item_ptr(path->nodes[0], path->slots[0], 5832 inode_item = btrfs_item_ptr(path->nodes[0], path->slots[0],
5833 struct btrfs_inode_item); 5833 struct btrfs_inode_item);
5834 memset_extent_buffer(path->nodes[0], 0, (unsigned long)inode_item, 5834 memset_extent_buffer(path->nodes[0], 0, (unsigned long)inode_item,
5835 sizeof(*inode_item)); 5835 sizeof(*inode_item));
5836 fill_inode_item(trans, path->nodes[0], inode_item, inode); 5836 fill_inode_item(trans, path->nodes[0], inode_item, inode);
5837 5837
5838 if (name) { 5838 if (name) {
5839 ref = btrfs_item_ptr(path->nodes[0], path->slots[0] + 1, 5839 ref = btrfs_item_ptr(path->nodes[0], path->slots[0] + 1,
5840 struct btrfs_inode_ref); 5840 struct btrfs_inode_ref);
5841 btrfs_set_inode_ref_name_len(path->nodes[0], ref, name_len); 5841 btrfs_set_inode_ref_name_len(path->nodes[0], ref, name_len);
5842 btrfs_set_inode_ref_index(path->nodes[0], ref, *index); 5842 btrfs_set_inode_ref_index(path->nodes[0], ref, *index);
5843 ptr = (unsigned long)(ref + 1); 5843 ptr = (unsigned long)(ref + 1);
5844 write_extent_buffer(path->nodes[0], name, ptr, name_len); 5844 write_extent_buffer(path->nodes[0], name, ptr, name_len);
5845 } 5845 }
5846 5846
5847 btrfs_mark_buffer_dirty(path->nodes[0]); 5847 btrfs_mark_buffer_dirty(path->nodes[0]);
5848 btrfs_free_path(path); 5848 btrfs_free_path(path);
5849 5849
5850 btrfs_inherit_iflags(inode, dir); 5850 btrfs_inherit_iflags(inode, dir);
5851 5851
5852 if (S_ISREG(mode)) { 5852 if (S_ISREG(mode)) {
5853 if (btrfs_test_opt(root, NODATASUM)) 5853 if (btrfs_test_opt(root, NODATASUM))
5854 BTRFS_I(inode)->flags |= BTRFS_INODE_NODATASUM; 5854 BTRFS_I(inode)->flags |= BTRFS_INODE_NODATASUM;
5855 if (btrfs_test_opt(root, NODATACOW)) 5855 if (btrfs_test_opt(root, NODATACOW))
5856 BTRFS_I(inode)->flags |= BTRFS_INODE_NODATACOW | 5856 BTRFS_I(inode)->flags |= BTRFS_INODE_NODATACOW |
5857 BTRFS_INODE_NODATASUM; 5857 BTRFS_INODE_NODATASUM;
5858 } 5858 }
5859 5859
5860 inode_tree_add(inode); 5860 inode_tree_add(inode);
5861 5861
5862 trace_btrfs_inode_new(inode); 5862 trace_btrfs_inode_new(inode);
5863 btrfs_set_inode_last_trans(trans, inode); 5863 btrfs_set_inode_last_trans(trans, inode);
5864 5864
5865 btrfs_update_root_times(trans, root); 5865 btrfs_update_root_times(trans, root);
5866 5866
5867 ret = btrfs_inode_inherit_props(trans, inode, dir); 5867 ret = btrfs_inode_inherit_props(trans, inode, dir);
5868 if (ret) 5868 if (ret)
5869 btrfs_err(root->fs_info, 5869 btrfs_err(root->fs_info,
5870 "error inheriting props for ino %llu (root %llu): %d", 5870 "error inheriting props for ino %llu (root %llu): %d",
5871 btrfs_ino(inode), root->root_key.objectid, ret); 5871 btrfs_ino(inode), root->root_key.objectid, ret);
5872 5872
5873 return inode; 5873 return inode;
5874 5874
5875 fail_unlock: 5875 fail_unlock:
5876 unlock_new_inode(inode); 5876 unlock_new_inode(inode);
5877 fail: 5877 fail:
5878 if (dir && name) 5878 if (dir && name)
5879 BTRFS_I(dir)->index_cnt--; 5879 BTRFS_I(dir)->index_cnt--;
5880 btrfs_free_path(path); 5880 btrfs_free_path(path);
5881 iput(inode); 5881 iput(inode);
5882 return ERR_PTR(ret); 5882 return ERR_PTR(ret);
5883 } 5883 }
5884 5884
5885 static inline u8 btrfs_inode_type(struct inode *inode) 5885 static inline u8 btrfs_inode_type(struct inode *inode)
5886 { 5886 {
5887 return btrfs_type_by_mode[(inode->i_mode & S_IFMT) >> S_SHIFT]; 5887 return btrfs_type_by_mode[(inode->i_mode & S_IFMT) >> S_SHIFT];
5888 } 5888 }
5889 5889
5890 /* 5890 /*
5891 * utility function to add 'inode' into 'parent_inode' with 5891 * utility function to add 'inode' into 'parent_inode' with
5892 * a give name and a given sequence number. 5892 * a give name and a given sequence number.
5893 * if 'add_backref' is true, also insert a backref from the 5893 * if 'add_backref' is true, also insert a backref from the
5894 * inode to the parent directory. 5894 * inode to the parent directory.
5895 */ 5895 */
5896 int btrfs_add_link(struct btrfs_trans_handle *trans, 5896 int btrfs_add_link(struct btrfs_trans_handle *trans,
5897 struct inode *parent_inode, struct inode *inode, 5897 struct inode *parent_inode, struct inode *inode,
5898 const char *name, int name_len, int add_backref, u64 index) 5898 const char *name, int name_len, int add_backref, u64 index)
5899 { 5899 {
5900 int ret = 0; 5900 int ret = 0;
5901 struct btrfs_key key; 5901 struct btrfs_key key;
5902 struct btrfs_root *root = BTRFS_I(parent_inode)->root; 5902 struct btrfs_root *root = BTRFS_I(parent_inode)->root;
5903 u64 ino = btrfs_ino(inode); 5903 u64 ino = btrfs_ino(inode);
5904 u64 parent_ino = btrfs_ino(parent_inode); 5904 u64 parent_ino = btrfs_ino(parent_inode);
5905 5905
5906 if (unlikely(ino == BTRFS_FIRST_FREE_OBJECTID)) { 5906 if (unlikely(ino == BTRFS_FIRST_FREE_OBJECTID)) {
5907 memcpy(&key, &BTRFS_I(inode)->root->root_key, sizeof(key)); 5907 memcpy(&key, &BTRFS_I(inode)->root->root_key, sizeof(key));
5908 } else { 5908 } else {
5909 key.objectid = ino; 5909 key.objectid = ino;
5910 key.type = BTRFS_INODE_ITEM_KEY; 5910 key.type = BTRFS_INODE_ITEM_KEY;
5911 key.offset = 0; 5911 key.offset = 0;
5912 } 5912 }
5913 5913
5914 if (unlikely(ino == BTRFS_FIRST_FREE_OBJECTID)) { 5914 if (unlikely(ino == BTRFS_FIRST_FREE_OBJECTID)) {
5915 ret = btrfs_add_root_ref(trans, root->fs_info->tree_root, 5915 ret = btrfs_add_root_ref(trans, root->fs_info->tree_root,
5916 key.objectid, root->root_key.objectid, 5916 key.objectid, root->root_key.objectid,
5917 parent_ino, index, name, name_len); 5917 parent_ino, index, name, name_len);
5918 } else if (add_backref) { 5918 } else if (add_backref) {
5919 ret = btrfs_insert_inode_ref(trans, root, name, name_len, ino, 5919 ret = btrfs_insert_inode_ref(trans, root, name, name_len, ino,
5920 parent_ino, index); 5920 parent_ino, index);
5921 } 5921 }
5922 5922
5923 /* Nothing to clean up yet */ 5923 /* Nothing to clean up yet */
5924 if (ret) 5924 if (ret)
5925 return ret; 5925 return ret;
5926 5926
5927 ret = btrfs_insert_dir_item(trans, root, name, name_len, 5927 ret = btrfs_insert_dir_item(trans, root, name, name_len,
5928 parent_inode, &key, 5928 parent_inode, &key,
5929 btrfs_inode_type(inode), index); 5929 btrfs_inode_type(inode), index);
5930 if (ret == -EEXIST || ret == -EOVERFLOW) 5930 if (ret == -EEXIST || ret == -EOVERFLOW)
5931 goto fail_dir_item; 5931 goto fail_dir_item;
5932 else if (ret) { 5932 else if (ret) {
5933 btrfs_abort_transaction(trans, root, ret); 5933 btrfs_abort_transaction(trans, root, ret);
5934 return ret; 5934 return ret;
5935 } 5935 }
5936 5936
5937 btrfs_i_size_write(parent_inode, parent_inode->i_size + 5937 btrfs_i_size_write(parent_inode, parent_inode->i_size +
5938 name_len * 2); 5938 name_len * 2);
5939 inode_inc_iversion(parent_inode); 5939 inode_inc_iversion(parent_inode);
5940 parent_inode->i_mtime = parent_inode->i_ctime = CURRENT_TIME; 5940 parent_inode->i_mtime = parent_inode->i_ctime = CURRENT_TIME;
5941 ret = btrfs_update_inode(trans, root, parent_inode); 5941 ret = btrfs_update_inode(trans, root, parent_inode);
5942 if (ret) 5942 if (ret)
5943 btrfs_abort_transaction(trans, root, ret); 5943 btrfs_abort_transaction(trans, root, ret);
5944 return ret; 5944 return ret;
5945 5945
5946 fail_dir_item: 5946 fail_dir_item:
5947 if (unlikely(ino == BTRFS_FIRST_FREE_OBJECTID)) { 5947 if (unlikely(ino == BTRFS_FIRST_FREE_OBJECTID)) {
5948 u64 local_index; 5948 u64 local_index;
5949 int err; 5949 int err;
5950 err = btrfs_del_root_ref(trans, root->fs_info->tree_root, 5950 err = btrfs_del_root_ref(trans, root->fs_info->tree_root,
5951 key.objectid, root->root_key.objectid, 5951 key.objectid, root->root_key.objectid,
5952 parent_ino, &local_index, name, name_len); 5952 parent_ino, &local_index, name, name_len);
5953 5953
5954 } else if (add_backref) { 5954 } else if (add_backref) {
5955 u64 local_index; 5955 u64 local_index;
5956 int err; 5956 int err;
5957 5957
5958 err = btrfs_del_inode_ref(trans, root, name, name_len, 5958 err = btrfs_del_inode_ref(trans, root, name, name_len,
5959 ino, parent_ino, &local_index); 5959 ino, parent_ino, &local_index);
5960 } 5960 }
5961 return ret; 5961 return ret;
5962 } 5962 }
5963 5963
5964 static int btrfs_add_nondir(struct btrfs_trans_handle *trans, 5964 static int btrfs_add_nondir(struct btrfs_trans_handle *trans,
5965 struct inode *dir, struct dentry *dentry, 5965 struct inode *dir, struct dentry *dentry,
5966 struct inode *inode, int backref, u64 index) 5966 struct inode *inode, int backref, u64 index)
5967 { 5967 {
5968 int err = btrfs_add_link(trans, dir, inode, 5968 int err = btrfs_add_link(trans, dir, inode,
5969 dentry->d_name.name, dentry->d_name.len, 5969 dentry->d_name.name, dentry->d_name.len,
5970 backref, index); 5970 backref, index);
5971 if (err > 0) 5971 if (err > 0)
5972 err = -EEXIST; 5972 err = -EEXIST;
5973 return err; 5973 return err;
5974 } 5974 }
5975 5975
5976 static int btrfs_mknod(struct inode *dir, struct dentry *dentry, 5976 static int btrfs_mknod(struct inode *dir, struct dentry *dentry,
5977 umode_t mode, dev_t rdev) 5977 umode_t mode, dev_t rdev)
5978 { 5978 {
5979 struct btrfs_trans_handle *trans; 5979 struct btrfs_trans_handle *trans;
5980 struct btrfs_root *root = BTRFS_I(dir)->root; 5980 struct btrfs_root *root = BTRFS_I(dir)->root;
5981 struct inode *inode = NULL; 5981 struct inode *inode = NULL;
5982 int err; 5982 int err;
5983 int drop_inode = 0; 5983 int drop_inode = 0;
5984 u64 objectid; 5984 u64 objectid;
5985 u64 index = 0; 5985 u64 index = 0;
5986 5986
5987 if (!new_valid_dev(rdev)) 5987 if (!new_valid_dev(rdev))
5988 return -EINVAL; 5988 return -EINVAL;
5989 5989
5990 /* 5990 /*
5991 * 2 for inode item and ref 5991 * 2 for inode item and ref
5992 * 2 for dir items 5992 * 2 for dir items
5993 * 1 for xattr if selinux is on 5993 * 1 for xattr if selinux is on
5994 */ 5994 */
5995 trans = btrfs_start_transaction(root, 5); 5995 trans = btrfs_start_transaction(root, 5);
5996 if (IS_ERR(trans)) 5996 if (IS_ERR(trans))
5997 return PTR_ERR(trans); 5997 return PTR_ERR(trans);
5998 5998
5999 err = btrfs_find_free_ino(root, &objectid); 5999 err = btrfs_find_free_ino(root, &objectid);
6000 if (err) 6000 if (err)
6001 goto out_unlock; 6001 goto out_unlock;
6002 6002
6003 inode = btrfs_new_inode(trans, root, dir, dentry->d_name.name, 6003 inode = btrfs_new_inode(trans, root, dir, dentry->d_name.name,
6004 dentry->d_name.len, btrfs_ino(dir), objectid, 6004 dentry->d_name.len, btrfs_ino(dir), objectid,
6005 mode, &index); 6005 mode, &index);
6006 if (IS_ERR(inode)) { 6006 if (IS_ERR(inode)) {
6007 err = PTR_ERR(inode); 6007 err = PTR_ERR(inode);
6008 goto out_unlock; 6008 goto out_unlock;
6009 } 6009 }
6010 6010
6011 /* 6011 /*
6012 * If the active LSM wants to access the inode during 6012 * If the active LSM wants to access the inode during
6013 * d_instantiate it needs these. Smack checks to see 6013 * d_instantiate it needs these. Smack checks to see
6014 * if the filesystem supports xattrs by looking at the 6014 * if the filesystem supports xattrs by looking at the
6015 * ops vector. 6015 * ops vector.
6016 */ 6016 */
6017 inode->i_op = &btrfs_special_inode_operations; 6017 inode->i_op = &btrfs_special_inode_operations;
6018 init_special_inode(inode, inode->i_mode, rdev); 6018 init_special_inode(inode, inode->i_mode, rdev);
6019 6019
6020 err = btrfs_init_inode_security(trans, inode, dir, &dentry->d_name); 6020 err = btrfs_init_inode_security(trans, inode, dir, &dentry->d_name);
6021 if (err) 6021 if (err)
6022 goto out_unlock_inode; 6022 goto out_unlock_inode;
6023 6023
6024 err = btrfs_add_nondir(trans, dir, dentry, inode, 0, index); 6024 err = btrfs_add_nondir(trans, dir, dentry, inode, 0, index);
6025 if (err) { 6025 if (err) {
6026 goto out_unlock_inode; 6026 goto out_unlock_inode;
6027 } else { 6027 } else {
6028 btrfs_update_inode(trans, root, inode); 6028 btrfs_update_inode(trans, root, inode);
6029 unlock_new_inode(inode); 6029 unlock_new_inode(inode);
6030 d_instantiate(dentry, inode); 6030 d_instantiate(dentry, inode);
6031 } 6031 }
6032 6032
6033 out_unlock: 6033 out_unlock:
6034 btrfs_end_transaction(trans, root); 6034 btrfs_end_transaction(trans, root);
6035 btrfs_balance_delayed_items(root); 6035 btrfs_balance_delayed_items(root);
6036 btrfs_btree_balance_dirty(root); 6036 btrfs_btree_balance_dirty(root);
6037 if (drop_inode) { 6037 if (drop_inode) {
6038 inode_dec_link_count(inode); 6038 inode_dec_link_count(inode);
6039 iput(inode); 6039 iput(inode);
6040 } 6040 }
6041 return err; 6041 return err;
6042 6042
6043 out_unlock_inode: 6043 out_unlock_inode:
6044 drop_inode = 1; 6044 drop_inode = 1;
6045 unlock_new_inode(inode); 6045 unlock_new_inode(inode);
6046 goto out_unlock; 6046 goto out_unlock;
6047 6047
6048 } 6048 }
6049 6049
6050 static int btrfs_create(struct inode *dir, struct dentry *dentry, 6050 static int btrfs_create(struct inode *dir, struct dentry *dentry,
6051 umode_t mode, bool excl) 6051 umode_t mode, bool excl)
6052 { 6052 {
6053 struct btrfs_trans_handle *trans; 6053 struct btrfs_trans_handle *trans;
6054 struct btrfs_root *root = BTRFS_I(dir)->root; 6054 struct btrfs_root *root = BTRFS_I(dir)->root;
6055 struct inode *inode = NULL; 6055 struct inode *inode = NULL;
6056 int drop_inode_on_err = 0; 6056 int drop_inode_on_err = 0;
6057 int err; 6057 int err;
6058 u64 objectid; 6058 u64 objectid;
6059 u64 index = 0; 6059 u64 index = 0;
6060 6060
6061 /* 6061 /*
6062 * 2 for inode item and ref 6062 * 2 for inode item and ref
6063 * 2 for dir items 6063 * 2 for dir items
6064 * 1 for xattr if selinux is on 6064 * 1 for xattr if selinux is on
6065 */ 6065 */
6066 trans = btrfs_start_transaction(root, 5); 6066 trans = btrfs_start_transaction(root, 5);
6067 if (IS_ERR(trans)) 6067 if (IS_ERR(trans))
6068 return PTR_ERR(trans); 6068 return PTR_ERR(trans);
6069 6069
6070 err = btrfs_find_free_ino(root, &objectid); 6070 err = btrfs_find_free_ino(root, &objectid);
6071 if (err) 6071 if (err)
6072 goto out_unlock; 6072 goto out_unlock;
6073 6073
6074 inode = btrfs_new_inode(trans, root, dir, dentry->d_name.name, 6074 inode = btrfs_new_inode(trans, root, dir, dentry->d_name.name,
6075 dentry->d_name.len, btrfs_ino(dir), objectid, 6075 dentry->d_name.len, btrfs_ino(dir), objectid,
6076 mode, &index); 6076 mode, &index);
6077 if (IS_ERR(inode)) { 6077 if (IS_ERR(inode)) {
6078 err = PTR_ERR(inode); 6078 err = PTR_ERR(inode);
6079 goto out_unlock; 6079 goto out_unlock;
6080 } 6080 }
6081 drop_inode_on_err = 1; 6081 drop_inode_on_err = 1;
6082 /* 6082 /*
6083 * If the active LSM wants to access the inode during 6083 * If the active LSM wants to access the inode during
6084 * d_instantiate it needs these. Smack checks to see 6084 * d_instantiate it needs these. Smack checks to see
6085 * if the filesystem supports xattrs by looking at the 6085 * if the filesystem supports xattrs by looking at the
6086 * ops vector. 6086 * ops vector.
6087 */ 6087 */
6088 inode->i_fop = &btrfs_file_operations; 6088 inode->i_fop = &btrfs_file_operations;
6089 inode->i_op = &btrfs_file_inode_operations; 6089 inode->i_op = &btrfs_file_inode_operations;
6090 inode->i_mapping->a_ops = &btrfs_aops; 6090 inode->i_mapping->a_ops = &btrfs_aops;
6091 inode->i_mapping->backing_dev_info = &root->fs_info->bdi; 6091 inode->i_mapping->backing_dev_info = &root->fs_info->bdi;
6092 6092
6093 err = btrfs_init_inode_security(trans, inode, dir, &dentry->d_name); 6093 err = btrfs_init_inode_security(trans, inode, dir, &dentry->d_name);
6094 if (err) 6094 if (err)
6095 goto out_unlock_inode; 6095 goto out_unlock_inode;
6096 6096
6097 err = btrfs_update_inode(trans, root, inode); 6097 err = btrfs_update_inode(trans, root, inode);
6098 if (err) 6098 if (err)
6099 goto out_unlock_inode; 6099 goto out_unlock_inode;
6100 6100
6101 err = btrfs_add_nondir(trans, dir, dentry, inode, 0, index); 6101 err = btrfs_add_nondir(trans, dir, dentry, inode, 0, index);
6102 if (err) 6102 if (err)
6103 goto out_unlock_inode; 6103 goto out_unlock_inode;
6104 6104
6105 BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops; 6105 BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops;
6106 unlock_new_inode(inode); 6106 unlock_new_inode(inode);
6107 d_instantiate(dentry, inode); 6107 d_instantiate(dentry, inode);
6108 6108
6109 out_unlock: 6109 out_unlock:
6110 btrfs_end_transaction(trans, root); 6110 btrfs_end_transaction(trans, root);
6111 if (err && drop_inode_on_err) { 6111 if (err && drop_inode_on_err) {
6112 inode_dec_link_count(inode); 6112 inode_dec_link_count(inode);
6113 iput(inode); 6113 iput(inode);
6114 } 6114 }
6115 btrfs_balance_delayed_items(root); 6115 btrfs_balance_delayed_items(root);
6116 btrfs_btree_balance_dirty(root); 6116 btrfs_btree_balance_dirty(root);
6117 return err; 6117 return err;
6118 6118
6119 out_unlock_inode: 6119 out_unlock_inode:
6120 unlock_new_inode(inode); 6120 unlock_new_inode(inode);
6121 goto out_unlock; 6121 goto out_unlock;
6122 6122
6123 } 6123 }
6124 6124
6125 static int btrfs_link(struct dentry *old_dentry, struct inode *dir, 6125 static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
6126 struct dentry *dentry) 6126 struct dentry *dentry)
6127 { 6127 {
6128 struct btrfs_trans_handle *trans; 6128 struct btrfs_trans_handle *trans;
6129 struct btrfs_root *root = BTRFS_I(dir)->root; 6129 struct btrfs_root *root = BTRFS_I(dir)->root;
6130 struct inode *inode = old_dentry->d_inode; 6130 struct inode *inode = old_dentry->d_inode;
6131 u64 index; 6131 u64 index;
6132 int err; 6132 int err;
6133 int drop_inode = 0; 6133 int drop_inode = 0;
6134 6134
6135 /* do not allow sys_link's with other subvols of the same device */ 6135 /* do not allow sys_link's with other subvols of the same device */
6136 if (root->objectid != BTRFS_I(inode)->root->objectid) 6136 if (root->objectid != BTRFS_I(inode)->root->objectid)
6137 return -EXDEV; 6137 return -EXDEV;
6138 6138
6139 if (inode->i_nlink >= BTRFS_LINK_MAX) 6139 if (inode->i_nlink >= BTRFS_LINK_MAX)
6140 return -EMLINK; 6140 return -EMLINK;
6141 6141
6142 err = btrfs_set_inode_index(dir, &index); 6142 err = btrfs_set_inode_index(dir, &index);
6143 if (err) 6143 if (err)
6144 goto fail; 6144 goto fail;
6145 6145
6146 /* 6146 /*
6147 * 2 items for inode and inode ref 6147 * 2 items for inode and inode ref
6148 * 2 items for dir items 6148 * 2 items for dir items
6149 * 1 item for parent inode 6149 * 1 item for parent inode
6150 */ 6150 */
6151 trans = btrfs_start_transaction(root, 5); 6151 trans = btrfs_start_transaction(root, 5);
6152 if (IS_ERR(trans)) { 6152 if (IS_ERR(trans)) {
6153 err = PTR_ERR(trans); 6153 err = PTR_ERR(trans);
6154 goto fail; 6154 goto fail;
6155 } 6155 }
6156 6156
6157 /* There are several dir indexes for this inode, clear the cache. */ 6157 /* There are several dir indexes for this inode, clear the cache. */
6158 BTRFS_I(inode)->dir_index = 0ULL; 6158 BTRFS_I(inode)->dir_index = 0ULL;
6159 inc_nlink(inode); 6159 inc_nlink(inode);
6160 inode_inc_iversion(inode); 6160 inode_inc_iversion(inode);
6161 inode->i_ctime = CURRENT_TIME; 6161 inode->i_ctime = CURRENT_TIME;
6162 ihold(inode); 6162 ihold(inode);
6163 set_bit(BTRFS_INODE_COPY_EVERYTHING, &BTRFS_I(inode)->runtime_flags); 6163 set_bit(BTRFS_INODE_COPY_EVERYTHING, &BTRFS_I(inode)->runtime_flags);
6164 6164
6165 err = btrfs_add_nondir(trans, dir, dentry, inode, 1, index); 6165 err = btrfs_add_nondir(trans, dir, dentry, inode, 1, index);
6166 6166
6167 if (err) { 6167 if (err) {
6168 drop_inode = 1; 6168 drop_inode = 1;
6169 } else { 6169 } else {
6170 struct dentry *parent = dentry->d_parent; 6170 struct dentry *parent = dentry->d_parent;
6171 err = btrfs_update_inode(trans, root, inode); 6171 err = btrfs_update_inode(trans, root, inode);
6172 if (err) 6172 if (err)
6173 goto fail; 6173 goto fail;
6174 if (inode->i_nlink == 1) { 6174 if (inode->i_nlink == 1) {
6175 /* 6175 /*
6176 * If new hard link count is 1, it's a file created 6176 * If new hard link count is 1, it's a file created
6177 * with open(2) O_TMPFILE flag. 6177 * with open(2) O_TMPFILE flag.
6178 */ 6178 */
6179 err = btrfs_orphan_del(trans, inode); 6179 err = btrfs_orphan_del(trans, inode);
6180 if (err) 6180 if (err)
6181 goto fail; 6181 goto fail;
6182 } 6182 }
6183 d_instantiate(dentry, inode); 6183 d_instantiate(dentry, inode);
6184 btrfs_log_new_name(trans, inode, NULL, parent); 6184 btrfs_log_new_name(trans, inode, NULL, parent);
6185 } 6185 }
6186 6186
6187 btrfs_end_transaction(trans, root); 6187 btrfs_end_transaction(trans, root);
6188 btrfs_balance_delayed_items(root); 6188 btrfs_balance_delayed_items(root);
6189 fail: 6189 fail:
6190 if (drop_inode) { 6190 if (drop_inode) {
6191 inode_dec_link_count(inode); 6191 inode_dec_link_count(inode);
6192 iput(inode); 6192 iput(inode);
6193 } 6193 }
6194 btrfs_btree_balance_dirty(root); 6194 btrfs_btree_balance_dirty(root);
6195 return err; 6195 return err;
6196 } 6196 }
6197 6197
6198 static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) 6198 static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
6199 { 6199 {
6200 struct inode *inode = NULL; 6200 struct inode *inode = NULL;
6201 struct btrfs_trans_handle *trans; 6201 struct btrfs_trans_handle *trans;
6202 struct btrfs_root *root = BTRFS_I(dir)->root; 6202 struct btrfs_root *root = BTRFS_I(dir)->root;
6203 int err = 0; 6203 int err = 0;
6204 int drop_on_err = 0; 6204 int drop_on_err = 0;
6205 u64 objectid = 0; 6205 u64 objectid = 0;
6206 u64 index = 0; 6206 u64 index = 0;
6207 6207
6208 /* 6208 /*
6209 * 2 items for inode and ref 6209 * 2 items for inode and ref
6210 * 2 items for dir items 6210 * 2 items for dir items
6211 * 1 for xattr if selinux is on 6211 * 1 for xattr if selinux is on
6212 */ 6212 */
6213 trans = btrfs_start_transaction(root, 5); 6213 trans = btrfs_start_transaction(root, 5);
6214 if (IS_ERR(trans)) 6214 if (IS_ERR(trans))
6215 return PTR_ERR(trans); 6215 return PTR_ERR(trans);
6216 6216
6217 err = btrfs_find_free_ino(root, &objectid); 6217 err = btrfs_find_free_ino(root, &objectid);
6218 if (err) 6218 if (err)
6219 goto out_fail; 6219 goto out_fail;
6220 6220
6221 inode = btrfs_new_inode(trans, root, dir, dentry->d_name.name, 6221 inode = btrfs_new_inode(trans, root, dir, dentry->d_name.name,
6222 dentry->d_name.len, btrfs_ino(dir), objectid, 6222 dentry->d_name.len, btrfs_ino(dir), objectid,
6223 S_IFDIR | mode, &index); 6223 S_IFDIR | mode, &index);
6224 if (IS_ERR(inode)) { 6224 if (IS_ERR(inode)) {
6225 err = PTR_ERR(inode); 6225 err = PTR_ERR(inode);
6226 goto out_fail; 6226 goto out_fail;
6227 } 6227 }
6228 6228
6229 drop_on_err = 1; 6229 drop_on_err = 1;
6230 /* these must be set before we unlock the inode */ 6230 /* these must be set before we unlock the inode */
6231 inode->i_op = &btrfs_dir_inode_operations; 6231 inode->i_op = &btrfs_dir_inode_operations;
6232 inode->i_fop = &btrfs_dir_file_operations; 6232 inode->i_fop = &btrfs_dir_file_operations;
6233 6233
6234 err = btrfs_init_inode_security(trans, inode, dir, &dentry->d_name); 6234 err = btrfs_init_inode_security(trans, inode, dir, &dentry->d_name);
6235 if (err) 6235 if (err)
6236 goto out_fail_inode; 6236 goto out_fail_inode;
6237 6237
6238 btrfs_i_size_write(inode, 0); 6238 btrfs_i_size_write(inode, 0);
6239 err = btrfs_update_inode(trans, root, inode); 6239 err = btrfs_update_inode(trans, root, inode);
6240 if (err) 6240 if (err)
6241 goto out_fail_inode; 6241 goto out_fail_inode;
6242 6242
6243 err = btrfs_add_link(trans, dir, inode, dentry->d_name.name, 6243 err = btrfs_add_link(trans, dir, inode, dentry->d_name.name,
6244 dentry->d_name.len, 0, index); 6244 dentry->d_name.len, 0, index);
6245 if (err) 6245 if (err)
6246 goto out_fail_inode; 6246 goto out_fail_inode;
6247 6247
6248 d_instantiate(dentry, inode); 6248 d_instantiate(dentry, inode);
6249 /* 6249 /*
6250 * mkdir is special. We're unlocking after we call d_instantiate 6250 * mkdir is special. We're unlocking after we call d_instantiate
6251 * to avoid a race with nfsd calling d_instantiate. 6251 * to avoid a race with nfsd calling d_instantiate.
6252 */ 6252 */
6253 unlock_new_inode(inode); 6253 unlock_new_inode(inode);
6254 drop_on_err = 0; 6254 drop_on_err = 0;
6255 6255
6256 out_fail: 6256 out_fail:
6257 btrfs_end_transaction(trans, root); 6257 btrfs_end_transaction(trans, root);
6258 if (drop_on_err) 6258 if (drop_on_err) {
6259 inode_dec_link_count(inode);
6259 iput(inode); 6260 iput(inode);
6261 }
6260 btrfs_balance_delayed_items(root); 6262 btrfs_balance_delayed_items(root);
6261 btrfs_btree_balance_dirty(root); 6263 btrfs_btree_balance_dirty(root);
6262 return err; 6264 return err;
6263 6265
6264 out_fail_inode: 6266 out_fail_inode:
6265 unlock_new_inode(inode); 6267 unlock_new_inode(inode);
6266 goto out_fail; 6268 goto out_fail;
6267 } 6269 }
6268 6270
6269 /* Find next extent map of a given extent map, caller needs to ensure locks */ 6271 /* Find next extent map of a given extent map, caller needs to ensure locks */
6270 static struct extent_map *next_extent_map(struct extent_map *em) 6272 static struct extent_map *next_extent_map(struct extent_map *em)
6271 { 6273 {
6272 struct rb_node *next; 6274 struct rb_node *next;
6273 6275
6274 next = rb_next(&em->rb_node); 6276 next = rb_next(&em->rb_node);
6275 if (!next) 6277 if (!next)
6276 return NULL; 6278 return NULL;
6277 return container_of(next, struct extent_map, rb_node); 6279 return container_of(next, struct extent_map, rb_node);
6278 } 6280 }
6279 6281
6280 static struct extent_map *prev_extent_map(struct extent_map *em) 6282 static struct extent_map *prev_extent_map(struct extent_map *em)
6281 { 6283 {
6282 struct rb_node *prev; 6284 struct rb_node *prev;
6283 6285
6284 prev = rb_prev(&em->rb_node); 6286 prev = rb_prev(&em->rb_node);
6285 if (!prev) 6287 if (!prev)
6286 return NULL; 6288 return NULL;
6287 return container_of(prev, struct extent_map, rb_node); 6289 return container_of(prev, struct extent_map, rb_node);
6288 } 6290 }
6289 6291
6290 /* helper for btfs_get_extent. Given an existing extent in the tree, 6292 /* helper for btfs_get_extent. Given an existing extent in the tree,
6291 * the existing extent is the nearest extent to map_start, 6293 * the existing extent is the nearest extent to map_start,
6292 * and an extent that you want to insert, deal with overlap and insert 6294 * and an extent that you want to insert, deal with overlap and insert
6293 * the best fitted new extent into the tree. 6295 * the best fitted new extent into the tree.
6294 */ 6296 */
6295 static int merge_extent_mapping(struct extent_map_tree *em_tree, 6297 static int merge_extent_mapping(struct extent_map_tree *em_tree,
6296 struct extent_map *existing, 6298 struct extent_map *existing,
6297 struct extent_map *em, 6299 struct extent_map *em,
6298 u64 map_start) 6300 u64 map_start)
6299 { 6301 {
6300 struct extent_map *prev; 6302 struct extent_map *prev;
6301 struct extent_map *next; 6303 struct extent_map *next;
6302 u64 start; 6304 u64 start;
6303 u64 end; 6305 u64 end;
6304 u64 start_diff; 6306 u64 start_diff;
6305 6307
6306 BUG_ON(map_start < em->start || map_start >= extent_map_end(em)); 6308 BUG_ON(map_start < em->start || map_start >= extent_map_end(em));
6307 6309
6308 if (existing->start > map_start) { 6310 if (existing->start > map_start) {
6309 next = existing; 6311 next = existing;
6310 prev = prev_extent_map(next); 6312 prev = prev_extent_map(next);
6311 } else { 6313 } else {
6312 prev = existing; 6314 prev = existing;
6313 next = next_extent_map(prev); 6315 next = next_extent_map(prev);
6314 } 6316 }
6315 6317
6316 start = prev ? extent_map_end(prev) : em->start; 6318 start = prev ? extent_map_end(prev) : em->start;
6317 start = max_t(u64, start, em->start); 6319 start = max_t(u64, start, em->start);
6318 end = next ? next->start : extent_map_end(em); 6320 end = next ? next->start : extent_map_end(em);
6319 end = min_t(u64, end, extent_map_end(em)); 6321 end = min_t(u64, end, extent_map_end(em));
6320 start_diff = start - em->start; 6322 start_diff = start - em->start;
6321 em->start = start; 6323 em->start = start;
6322 em->len = end - start; 6324 em->len = end - start;
6323 if (em->block_start < EXTENT_MAP_LAST_BYTE && 6325 if (em->block_start < EXTENT_MAP_LAST_BYTE &&
6324 !test_bit(EXTENT_FLAG_COMPRESSED, &em->flags)) { 6326 !test_bit(EXTENT_FLAG_COMPRESSED, &em->flags)) {
6325 em->block_start += start_diff; 6327 em->block_start += start_diff;
6326 em->block_len -= start_diff; 6328 em->block_len -= start_diff;
6327 } 6329 }
6328 return add_extent_mapping(em_tree, em, 0); 6330 return add_extent_mapping(em_tree, em, 0);
6329 } 6331 }
6330 6332
6331 static noinline int uncompress_inline(struct btrfs_path *path, 6333 static noinline int uncompress_inline(struct btrfs_path *path,
6332 struct inode *inode, struct page *page, 6334 struct inode *inode, struct page *page,
6333 size_t pg_offset, u64 extent_offset, 6335 size_t pg_offset, u64 extent_offset,
6334 struct btrfs_file_extent_item *item) 6336 struct btrfs_file_extent_item *item)
6335 { 6337 {
6336 int ret; 6338 int ret;
6337 struct extent_buffer *leaf = path->nodes[0]; 6339 struct extent_buffer *leaf = path->nodes[0];
6338 char *tmp; 6340 char *tmp;
6339 size_t max_size; 6341 size_t max_size;
6340 unsigned long inline_size; 6342 unsigned long inline_size;
6341 unsigned long ptr; 6343 unsigned long ptr;
6342 int compress_type; 6344 int compress_type;
6343 6345
6344 WARN_ON(pg_offset != 0); 6346 WARN_ON(pg_offset != 0);
6345 compress_type = btrfs_file_extent_compression(leaf, item); 6347 compress_type = btrfs_file_extent_compression(leaf, item);
6346 max_size = btrfs_file_extent_ram_bytes(leaf, item); 6348 max_size = btrfs_file_extent_ram_bytes(leaf, item);
6347 inline_size = btrfs_file_extent_inline_item_len(leaf, 6349 inline_size = btrfs_file_extent_inline_item_len(leaf,
6348 btrfs_item_nr(path->slots[0])); 6350 btrfs_item_nr(path->slots[0]));
6349 tmp = kmalloc(inline_size, GFP_NOFS); 6351 tmp = kmalloc(inline_size, GFP_NOFS);
6350 if (!tmp) 6352 if (!tmp)
6351 return -ENOMEM; 6353 return -ENOMEM;
6352 ptr = btrfs_file_extent_inline_start(item); 6354 ptr = btrfs_file_extent_inline_start(item);
6353 6355
6354 read_extent_buffer(leaf, tmp, ptr, inline_size); 6356 read_extent_buffer(leaf, tmp, ptr, inline_size);
6355 6357
6356 max_size = min_t(unsigned long, PAGE_CACHE_SIZE, max_size); 6358 max_size = min_t(unsigned long, PAGE_CACHE_SIZE, max_size);
6357 ret = btrfs_decompress(compress_type, tmp, page, 6359 ret = btrfs_decompress(compress_type, tmp, page,
6358 extent_offset, inline_size, max_size); 6360 extent_offset, inline_size, max_size);
6359 kfree(tmp); 6361 kfree(tmp);
6360 return ret; 6362 return ret;
6361 } 6363 }
6362 6364
6363 /* 6365 /*
6364 * a bit scary, this does extent mapping from logical file offset to the disk. 6366 * a bit scary, this does extent mapping from logical file offset to the disk.
6365 * the ugly parts come from merging extents from the disk with the in-ram 6367 * the ugly parts come from merging extents from the disk with the in-ram
6366 * representation. This gets more complex because of the data=ordered code, 6368 * representation. This gets more complex because of the data=ordered code,
6367 * where the in-ram extents might be locked pending data=ordered completion. 6369 * where the in-ram extents might be locked pending data=ordered completion.
6368 * 6370 *
6369 * This also copies inline extents directly into the page. 6371 * This also copies inline extents directly into the page.
6370 */ 6372 */
6371 6373
6372 struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page, 6374 struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page,
6373 size_t pg_offset, u64 start, u64 len, 6375 size_t pg_offset, u64 start, u64 len,
6374 int create) 6376 int create)
6375 { 6377 {
6376 int ret; 6378 int ret;
6377 int err = 0; 6379 int err = 0;
6378 u64 extent_start = 0; 6380 u64 extent_start = 0;
6379 u64 extent_end = 0; 6381 u64 extent_end = 0;
6380 u64 objectid = btrfs_ino(inode); 6382 u64 objectid = btrfs_ino(inode);
6381 u32 found_type; 6383 u32 found_type;
6382 struct btrfs_path *path = NULL; 6384 struct btrfs_path *path = NULL;
6383 struct btrfs_root *root = BTRFS_I(inode)->root; 6385 struct btrfs_root *root = BTRFS_I(inode)->root;
6384 struct btrfs_file_extent_item *item; 6386 struct btrfs_file_extent_item *item;
6385 struct extent_buffer *leaf; 6387 struct extent_buffer *leaf;
6386 struct btrfs_key found_key; 6388 struct btrfs_key found_key;
6387 struct extent_map *em = NULL; 6389 struct extent_map *em = NULL;
6388 struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; 6390 struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree;
6389 struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; 6391 struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
6390 struct btrfs_trans_handle *trans = NULL; 6392 struct btrfs_trans_handle *trans = NULL;
6391 const bool new_inline = !page || create; 6393 const bool new_inline = !page || create;
6392 6394
6393 again: 6395 again:
6394 read_lock(&em_tree->lock); 6396 read_lock(&em_tree->lock);
6395 em = lookup_extent_mapping(em_tree, start, len); 6397 em = lookup_extent_mapping(em_tree, start, len);
6396 if (em) 6398 if (em)
6397 em->bdev = root->fs_info->fs_devices->latest_bdev; 6399 em->bdev = root->fs_info->fs_devices->latest_bdev;
6398 read_unlock(&em_tree->lock); 6400 read_unlock(&em_tree->lock);
6399 6401
6400 if (em) { 6402 if (em) {
6401 if (em->start > start || em->start + em->len <= start) 6403 if (em->start > start || em->start + em->len <= start)
6402 free_extent_map(em); 6404 free_extent_map(em);
6403 else if (em->block_start == EXTENT_MAP_INLINE && page) 6405 else if (em->block_start == EXTENT_MAP_INLINE && page)
6404 free_extent_map(em); 6406 free_extent_map(em);
6405 else 6407 else
6406 goto out; 6408 goto out;
6407 } 6409 }
6408 em = alloc_extent_map(); 6410 em = alloc_extent_map();
6409 if (!em) { 6411 if (!em) {
6410 err = -ENOMEM; 6412 err = -ENOMEM;
6411 goto out; 6413 goto out;
6412 } 6414 }
6413 em->bdev = root->fs_info->fs_devices->latest_bdev; 6415 em->bdev = root->fs_info->fs_devices->latest_bdev;
6414 em->start = EXTENT_MAP_HOLE; 6416 em->start = EXTENT_MAP_HOLE;
6415 em->orig_start = EXTENT_MAP_HOLE; 6417 em->orig_start = EXTENT_MAP_HOLE;
6416 em->len = (u64)-1; 6418 em->len = (u64)-1;
6417 em->block_len = (u64)-1; 6419 em->block_len = (u64)-1;
6418 6420
6419 if (!path) { 6421 if (!path) {
6420 path = btrfs_alloc_path(); 6422 path = btrfs_alloc_path();
6421 if (!path) { 6423 if (!path) {
6422 err = -ENOMEM; 6424 err = -ENOMEM;
6423 goto out; 6425 goto out;
6424 } 6426 }
6425 /* 6427 /*
6426 * Chances are we'll be called again, so go ahead and do 6428 * Chances are we'll be called again, so go ahead and do
6427 * readahead 6429 * readahead
6428 */ 6430 */
6429 path->reada = 1; 6431 path->reada = 1;
6430 } 6432 }
6431 6433
6432 ret = btrfs_lookup_file_extent(trans, root, path, 6434 ret = btrfs_lookup_file_extent(trans, root, path,
6433 objectid, start, trans != NULL); 6435 objectid, start, trans != NULL);
6434 if (ret < 0) { 6436 if (ret < 0) {
6435 err = ret; 6437 err = ret;
6436 goto out; 6438 goto out;
6437 } 6439 }
6438 6440
6439 if (ret != 0) { 6441 if (ret != 0) {
6440 if (path->slots[0] == 0) 6442 if (path->slots[0] == 0)
6441 goto not_found; 6443 goto not_found;
6442 path->slots[0]--; 6444 path->slots[0]--;
6443 } 6445 }
6444 6446
6445 leaf = path->nodes[0]; 6447 leaf = path->nodes[0];
6446 item = btrfs_item_ptr(leaf, path->slots[0], 6448 item = btrfs_item_ptr(leaf, path->slots[0],
6447 struct btrfs_file_extent_item); 6449 struct btrfs_file_extent_item);
6448 /* are we inside the extent that was found? */ 6450 /* are we inside the extent that was found? */
6449 btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]); 6451 btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]);
6450 found_type = found_key.type; 6452 found_type = found_key.type;
6451 if (found_key.objectid != objectid || 6453 if (found_key.objectid != objectid ||
6452 found_type != BTRFS_EXTENT_DATA_KEY) { 6454 found_type != BTRFS_EXTENT_DATA_KEY) {
6453 /* 6455 /*
6454 * If we backup past the first extent we want to move forward 6456 * If we backup past the first extent we want to move forward
6455 * and see if there is an extent in front of us, otherwise we'll 6457 * and see if there is an extent in front of us, otherwise we'll
6456 * say there is a hole for our whole search range which can 6458 * say there is a hole for our whole search range which can
6457 * cause problems. 6459 * cause problems.
6458 */ 6460 */
6459 extent_end = start; 6461 extent_end = start;
6460 goto next; 6462 goto next;
6461 } 6463 }
6462 6464
6463 found_type = btrfs_file_extent_type(leaf, item); 6465 found_type = btrfs_file_extent_type(leaf, item);
6464 extent_start = found_key.offset; 6466 extent_start = found_key.offset;
6465 if (found_type == BTRFS_FILE_EXTENT_REG || 6467 if (found_type == BTRFS_FILE_EXTENT_REG ||
6466 found_type == BTRFS_FILE_EXTENT_PREALLOC) { 6468 found_type == BTRFS_FILE_EXTENT_PREALLOC) {
6467 extent_end = extent_start + 6469 extent_end = extent_start +
6468 btrfs_file_extent_num_bytes(leaf, item); 6470 btrfs_file_extent_num_bytes(leaf, item);
6469 } else if (found_type == BTRFS_FILE_EXTENT_INLINE) { 6471 } else if (found_type == BTRFS_FILE_EXTENT_INLINE) {
6470 size_t size; 6472 size_t size;
6471 size = btrfs_file_extent_inline_len(leaf, path->slots[0], item); 6473 size = btrfs_file_extent_inline_len(leaf, path->slots[0], item);
6472 extent_end = ALIGN(extent_start + size, root->sectorsize); 6474 extent_end = ALIGN(extent_start + size, root->sectorsize);
6473 } 6475 }
6474 next: 6476 next:
6475 if (start >= extent_end) { 6477 if (start >= extent_end) {
6476 path->slots[0]++; 6478 path->slots[0]++;
6477 if (path->slots[0] >= btrfs_header_nritems(leaf)) { 6479 if (path->slots[0] >= btrfs_header_nritems(leaf)) {
6478 ret = btrfs_next_leaf(root, path); 6480 ret = btrfs_next_leaf(root, path);
6479 if (ret < 0) { 6481 if (ret < 0) {
6480 err = ret; 6482 err = ret;
6481 goto out; 6483 goto out;
6482 } 6484 }
6483 if (ret > 0) 6485 if (ret > 0)
6484 goto not_found; 6486 goto not_found;
6485 leaf = path->nodes[0]; 6487 leaf = path->nodes[0];
6486 } 6488 }
6487 btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]); 6489 btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]);
6488 if (found_key.objectid != objectid || 6490 if (found_key.objectid != objectid ||
6489 found_key.type != BTRFS_EXTENT_DATA_KEY) 6491 found_key.type != BTRFS_EXTENT_DATA_KEY)
6490 goto not_found; 6492 goto not_found;
6491 if (start + len <= found_key.offset) 6493 if (start + len <= found_key.offset)
6492 goto not_found; 6494 goto not_found;
6493 if (start > found_key.offset) 6495 if (start > found_key.offset)
6494 goto next; 6496 goto next;
6495 em->start = start; 6497 em->start = start;
6496 em->orig_start = start; 6498 em->orig_start = start;
6497 em->len = found_key.offset - start; 6499 em->len = found_key.offset - start;
6498 goto not_found_em; 6500 goto not_found_em;
6499 } 6501 }
6500 6502
6501 btrfs_extent_item_to_extent_map(inode, path, item, new_inline, em); 6503 btrfs_extent_item_to_extent_map(inode, path, item, new_inline, em);
6502 6504
6503 if (found_type == BTRFS_FILE_EXTENT_REG || 6505 if (found_type == BTRFS_FILE_EXTENT_REG ||
6504 found_type == BTRFS_FILE_EXTENT_PREALLOC) { 6506 found_type == BTRFS_FILE_EXTENT_PREALLOC) {
6505 goto insert; 6507 goto insert;
6506 } else if (found_type == BTRFS_FILE_EXTENT_INLINE) { 6508 } else if (found_type == BTRFS_FILE_EXTENT_INLINE) {
6507 unsigned long ptr; 6509 unsigned long ptr;
6508 char *map; 6510 char *map;
6509 size_t size; 6511 size_t size;
6510 size_t extent_offset; 6512 size_t extent_offset;
6511 size_t copy_size; 6513 size_t copy_size;
6512 6514
6513 if (new_inline) 6515 if (new_inline)
6514 goto out; 6516 goto out;
6515 6517
6516 size = btrfs_file_extent_inline_len(leaf, path->slots[0], item); 6518 size = btrfs_file_extent_inline_len(leaf, path->slots[0], item);
6517 extent_offset = page_offset(page) + pg_offset - extent_start; 6519 extent_offset = page_offset(page) + pg_offset - extent_start;
6518 copy_size = min_t(u64, PAGE_CACHE_SIZE - pg_offset, 6520 copy_size = min_t(u64, PAGE_CACHE_SIZE - pg_offset,
6519 size - extent_offset); 6521 size - extent_offset);
6520 em->start = extent_start + extent_offset; 6522 em->start = extent_start + extent_offset;
6521 em->len = ALIGN(copy_size, root->sectorsize); 6523 em->len = ALIGN(copy_size, root->sectorsize);
6522 em->orig_block_len = em->len; 6524 em->orig_block_len = em->len;
6523 em->orig_start = em->start; 6525 em->orig_start = em->start;
6524 ptr = btrfs_file_extent_inline_start(item) + extent_offset; 6526 ptr = btrfs_file_extent_inline_start(item) + extent_offset;
6525 if (create == 0 && !PageUptodate(page)) { 6527 if (create == 0 && !PageUptodate(page)) {
6526 if (btrfs_file_extent_compression(leaf, item) != 6528 if (btrfs_file_extent_compression(leaf, item) !=
6527 BTRFS_COMPRESS_NONE) { 6529 BTRFS_COMPRESS_NONE) {
6528 ret = uncompress_inline(path, inode, page, 6530 ret = uncompress_inline(path, inode, page,
6529 pg_offset, 6531 pg_offset,
6530 extent_offset, item); 6532 extent_offset, item);
6531 if (ret) { 6533 if (ret) {
6532 err = ret; 6534 err = ret;
6533 goto out; 6535 goto out;
6534 } 6536 }
6535 } else { 6537 } else {
6536 map = kmap(page); 6538 map = kmap(page);
6537 read_extent_buffer(leaf, map + pg_offset, ptr, 6539 read_extent_buffer(leaf, map + pg_offset, ptr,
6538 copy_size); 6540 copy_size);
6539 if (pg_offset + copy_size < PAGE_CACHE_SIZE) { 6541 if (pg_offset + copy_size < PAGE_CACHE_SIZE) {
6540 memset(map + pg_offset + copy_size, 0, 6542 memset(map + pg_offset + copy_size, 0,
6541 PAGE_CACHE_SIZE - pg_offset - 6543 PAGE_CACHE_SIZE - pg_offset -
6542 copy_size); 6544 copy_size);
6543 } 6545 }
6544 kunmap(page); 6546 kunmap(page);
6545 } 6547 }
6546 flush_dcache_page(page); 6548 flush_dcache_page(page);
6547 } else if (create && PageUptodate(page)) { 6549 } else if (create && PageUptodate(page)) {
6548 BUG(); 6550 BUG();
6549 if (!trans) { 6551 if (!trans) {
6550 kunmap(page); 6552 kunmap(page);
6551 free_extent_map(em); 6553 free_extent_map(em);
6552 em = NULL; 6554 em = NULL;
6553 6555
6554 btrfs_release_path(path); 6556 btrfs_release_path(path);
6555 trans = btrfs_join_transaction(root); 6557 trans = btrfs_join_transaction(root);
6556 6558
6557 if (IS_ERR(trans)) 6559 if (IS_ERR(trans))
6558 return ERR_CAST(trans); 6560 return ERR_CAST(trans);
6559 goto again; 6561 goto again;
6560 } 6562 }
6561 map = kmap(page); 6563 map = kmap(page);
6562 write_extent_buffer(leaf, map + pg_offset, ptr, 6564 write_extent_buffer(leaf, map + pg_offset, ptr,
6563 copy_size); 6565 copy_size);
6564 kunmap(page); 6566 kunmap(page);
6565 btrfs_mark_buffer_dirty(leaf); 6567 btrfs_mark_buffer_dirty(leaf);
6566 } 6568 }
6567 set_extent_uptodate(io_tree, em->start, 6569 set_extent_uptodate(io_tree, em->start,
6568 extent_map_end(em) - 1, NULL, GFP_NOFS); 6570 extent_map_end(em) - 1, NULL, GFP_NOFS);
6569 goto insert; 6571 goto insert;
6570 } 6572 }
6571 not_found: 6573 not_found:
6572 em->start = start; 6574 em->start = start;
6573 em->orig_start = start; 6575 em->orig_start = start;
6574 em->len = len; 6576 em->len = len;
6575 not_found_em: 6577 not_found_em:
6576 em->block_start = EXTENT_MAP_HOLE; 6578 em->block_start = EXTENT_MAP_HOLE;
6577 set_bit(EXTENT_FLAG_VACANCY, &em->flags); 6579 set_bit(EXTENT_FLAG_VACANCY, &em->flags);
6578 insert: 6580 insert:
6579 btrfs_release_path(path); 6581 btrfs_release_path(path);
6580 if (em->start > start || extent_map_end(em) <= start) { 6582 if (em->start > start || extent_map_end(em) <= start) {
6581 btrfs_err(root->fs_info, "bad extent! em: [%llu %llu] passed [%llu %llu]", 6583 btrfs_err(root->fs_info, "bad extent! em: [%llu %llu] passed [%llu %llu]",
6582 em->start, em->len, start, len); 6584 em->start, em->len, start, len);
6583 err = -EIO; 6585 err = -EIO;
6584 goto out; 6586 goto out;
6585 } 6587 }
6586 6588
6587 err = 0; 6589 err = 0;
6588 write_lock(&em_tree->lock); 6590 write_lock(&em_tree->lock);
6589 ret = add_extent_mapping(em_tree, em, 0); 6591 ret = add_extent_mapping(em_tree, em, 0);
6590 /* it is possible that someone inserted the extent into the tree 6592 /* it is possible that someone inserted the extent into the tree
6591 * while we had the lock dropped. It is also possible that 6593 * while we had the lock dropped. It is also possible that
6592 * an overlapping map exists in the tree 6594 * an overlapping map exists in the tree
6593 */ 6595 */
6594 if (ret == -EEXIST) { 6596 if (ret == -EEXIST) {
6595 struct extent_map *existing; 6597 struct extent_map *existing;
6596 6598
6597 ret = 0; 6599 ret = 0;
6598 6600
6599 existing = search_extent_mapping(em_tree, start, len); 6601 existing = search_extent_mapping(em_tree, start, len);
6600 /* 6602 /*
6601 * existing will always be non-NULL, since there must be 6603 * existing will always be non-NULL, since there must be
6602 * extent causing the -EEXIST. 6604 * extent causing the -EEXIST.
6603 */ 6605 */
6604 if (start >= extent_map_end(existing) || 6606 if (start >= extent_map_end(existing) ||
6605 start <= existing->start) { 6607 start <= existing->start) {
6606 /* 6608 /*
6607 * The existing extent map is the one nearest to 6609 * The existing extent map is the one nearest to
6608 * the [start, start + len) range which overlaps 6610 * the [start, start + len) range which overlaps
6609 */ 6611 */
6610 err = merge_extent_mapping(em_tree, existing, 6612 err = merge_extent_mapping(em_tree, existing,
6611 em, start); 6613 em, start);
6612 free_extent_map(existing); 6614 free_extent_map(existing);
6613 if (err) { 6615 if (err) {
6614 free_extent_map(em); 6616 free_extent_map(em);
6615 em = NULL; 6617 em = NULL;
6616 } 6618 }
6617 } else { 6619 } else {
6618 free_extent_map(em); 6620 free_extent_map(em);
6619 em = existing; 6621 em = existing;
6620 err = 0; 6622 err = 0;
6621 } 6623 }
6622 } 6624 }
6623 write_unlock(&em_tree->lock); 6625 write_unlock(&em_tree->lock);
6624 out: 6626 out:
6625 6627
6626 trace_btrfs_get_extent(root, em); 6628 trace_btrfs_get_extent(root, em);
6627 6629
6628 if (path) 6630 if (path)
6629 btrfs_free_path(path); 6631 btrfs_free_path(path);
6630 if (trans) { 6632 if (trans) {
6631 ret = btrfs_end_transaction(trans, root); 6633 ret = btrfs_end_transaction(trans, root);
6632 if (!err) 6634 if (!err)
6633 err = ret; 6635 err = ret;
6634 } 6636 }
6635 if (err) { 6637 if (err) {
6636 free_extent_map(em); 6638 free_extent_map(em);
6637 return ERR_PTR(err); 6639 return ERR_PTR(err);
6638 } 6640 }
6639 BUG_ON(!em); /* Error is always set */ 6641 BUG_ON(!em); /* Error is always set */
6640 return em; 6642 return em;
6641 } 6643 }
6642 6644
6643 struct extent_map *btrfs_get_extent_fiemap(struct inode *inode, struct page *page, 6645 struct extent_map *btrfs_get_extent_fiemap(struct inode *inode, struct page *page,
6644 size_t pg_offset, u64 start, u64 len, 6646 size_t pg_offset, u64 start, u64 len,
6645 int create) 6647 int create)
6646 { 6648 {
6647 struct extent_map *em; 6649 struct extent_map *em;
6648 struct extent_map *hole_em = NULL; 6650 struct extent_map *hole_em = NULL;
6649 u64 range_start = start; 6651 u64 range_start = start;
6650 u64 end; 6652 u64 end;
6651 u64 found; 6653 u64 found;
6652 u64 found_end; 6654 u64 found_end;
6653 int err = 0; 6655 int err = 0;
6654 6656
6655 em = btrfs_get_extent(inode, page, pg_offset, start, len, create); 6657 em = btrfs_get_extent(inode, page, pg_offset, start, len, create);
6656 if (IS_ERR(em)) 6658 if (IS_ERR(em))
6657 return em; 6659 return em;
6658 if (em) { 6660 if (em) {
6659 /* 6661 /*
6660 * if our em maps to 6662 * if our em maps to
6661 * - a hole or 6663 * - a hole or
6662 * - a pre-alloc extent, 6664 * - a pre-alloc extent,
6663 * there might actually be delalloc bytes behind it. 6665 * there might actually be delalloc bytes behind it.
6664 */ 6666 */
6665 if (em->block_start != EXTENT_MAP_HOLE && 6667 if (em->block_start != EXTENT_MAP_HOLE &&
6666 !test_bit(EXTENT_FLAG_PREALLOC, &em->flags)) 6668 !test_bit(EXTENT_FLAG_PREALLOC, &em->flags))
6667 return em; 6669 return em;
6668 else 6670 else
6669 hole_em = em; 6671 hole_em = em;
6670 } 6672 }
6671 6673
6672 /* check to see if we've wrapped (len == -1 or similar) */ 6674 /* check to see if we've wrapped (len == -1 or similar) */
6673 end = start + len; 6675 end = start + len;
6674 if (end < start) 6676 if (end < start)
6675 end = (u64)-1; 6677 end = (u64)-1;
6676 else 6678 else
6677 end -= 1; 6679 end -= 1;
6678 6680
6679 em = NULL; 6681 em = NULL;
6680 6682
6681 /* ok, we didn't find anything, lets look for delalloc */ 6683 /* ok, we didn't find anything, lets look for delalloc */
6682 found = count_range_bits(&BTRFS_I(inode)->io_tree, &range_start, 6684 found = count_range_bits(&BTRFS_I(inode)->io_tree, &range_start,
6683 end, len, EXTENT_DELALLOC, 1); 6685 end, len, EXTENT_DELALLOC, 1);
6684 found_end = range_start + found; 6686 found_end = range_start + found;
6685 if (found_end < range_start) 6687 if (found_end < range_start)
6686 found_end = (u64)-1; 6688 found_end = (u64)-1;
6687 6689
6688 /* 6690 /*
6689 * we didn't find anything useful, return 6691 * we didn't find anything useful, return
6690 * the original results from get_extent() 6692 * the original results from get_extent()
6691 */ 6693 */
6692 if (range_start > end || found_end <= start) { 6694 if (range_start > end || found_end <= start) {
6693 em = hole_em; 6695 em = hole_em;
6694 hole_em = NULL; 6696 hole_em = NULL;
6695 goto out; 6697 goto out;
6696 } 6698 }
6697 6699
6698 /* adjust the range_start to make sure it doesn't 6700 /* adjust the range_start to make sure it doesn't
6699 * go backwards from the start they passed in 6701 * go backwards from the start they passed in
6700 */ 6702 */
6701 range_start = max(start, range_start); 6703 range_start = max(start, range_start);
6702 found = found_end - range_start; 6704 found = found_end - range_start;
6703 6705
6704 if (found > 0) { 6706 if (found > 0) {
6705 u64 hole_start = start; 6707 u64 hole_start = start;
6706 u64 hole_len = len; 6708 u64 hole_len = len;
6707 6709
6708 em = alloc_extent_map(); 6710 em = alloc_extent_map();
6709 if (!em) { 6711 if (!em) {
6710 err = -ENOMEM; 6712 err = -ENOMEM;
6711 goto out; 6713 goto out;
6712 } 6714 }
6713 /* 6715 /*
6714 * when btrfs_get_extent can't find anything it 6716 * when btrfs_get_extent can't find anything it
6715 * returns one huge hole 6717 * returns one huge hole
6716 * 6718 *
6717 * make sure what it found really fits our range, and 6719 * make sure what it found really fits our range, and
6718 * adjust to make sure it is based on the start from 6720 * adjust to make sure it is based on the start from
6719 * the caller 6721 * the caller
6720 */ 6722 */
6721 if (hole_em) { 6723 if (hole_em) {
6722 u64 calc_end = extent_map_end(hole_em); 6724 u64 calc_end = extent_map_end(hole_em);
6723 6725
6724 if (calc_end <= start || (hole_em->start > end)) { 6726 if (calc_end <= start || (hole_em->start > end)) {
6725 free_extent_map(hole_em); 6727 free_extent_map(hole_em);
6726 hole_em = NULL; 6728 hole_em = NULL;
6727 } else { 6729 } else {
6728 hole_start = max(hole_em->start, start); 6730 hole_start = max(hole_em->start, start);
6729 hole_len = calc_end - hole_start; 6731 hole_len = calc_end - hole_start;
6730 } 6732 }
6731 } 6733 }
6732 em->bdev = NULL; 6734 em->bdev = NULL;
6733 if (hole_em && range_start > hole_start) { 6735 if (hole_em && range_start > hole_start) {
6734 /* our hole starts before our delalloc, so we 6736 /* our hole starts before our delalloc, so we
6735 * have to return just the parts of the hole 6737 * have to return just the parts of the hole
6736 * that go until the delalloc starts 6738 * that go until the delalloc starts
6737 */ 6739 */
6738 em->len = min(hole_len, 6740 em->len = min(hole_len,
6739 range_start - hole_start); 6741 range_start - hole_start);
6740 em->start = hole_start; 6742 em->start = hole_start;
6741 em->orig_start = hole_start; 6743 em->orig_start = hole_start;
6742 /* 6744 /*
6743 * don't adjust block start at all, 6745 * don't adjust block start at all,
6744 * it is fixed at EXTENT_MAP_HOLE 6746 * it is fixed at EXTENT_MAP_HOLE
6745 */ 6747 */
6746 em->block_start = hole_em->block_start; 6748 em->block_start = hole_em->block_start;
6747 em->block_len = hole_len; 6749 em->block_len = hole_len;
6748 if (test_bit(EXTENT_FLAG_PREALLOC, &hole_em->flags)) 6750 if (test_bit(EXTENT_FLAG_PREALLOC, &hole_em->flags))
6749 set_bit(EXTENT_FLAG_PREALLOC, &em->flags); 6751 set_bit(EXTENT_FLAG_PREALLOC, &em->flags);
6750 } else { 6752 } else {
6751 em->start = range_start; 6753 em->start = range_start;
6752 em->len = found; 6754 em->len = found;
6753 em->orig_start = range_start; 6755 em->orig_start = range_start;
6754 em->block_start = EXTENT_MAP_DELALLOC; 6756 em->block_start = EXTENT_MAP_DELALLOC;
6755 em->block_len = found; 6757 em->block_len = found;
6756 } 6758 }
6757 } else if (hole_em) { 6759 } else if (hole_em) {
6758 return hole_em; 6760 return hole_em;
6759 } 6761 }
6760 out: 6762 out:
6761 6763
6762 free_extent_map(hole_em); 6764 free_extent_map(hole_em);
6763 if (err) { 6765 if (err) {
6764 free_extent_map(em); 6766 free_extent_map(em);
6765 return ERR_PTR(err); 6767 return ERR_PTR(err);
6766 } 6768 }
6767 return em; 6769 return em;
6768 } 6770 }
6769 6771
6770 static struct extent_map *btrfs_new_extent_direct(struct inode *inode, 6772 static struct extent_map *btrfs_new_extent_direct(struct inode *inode,
6771 u64 start, u64 len) 6773 u64 start, u64 len)
6772 { 6774 {
6773 struct btrfs_root *root = BTRFS_I(inode)->root; 6775 struct btrfs_root *root = BTRFS_I(inode)->root;
6774 struct extent_map *em; 6776 struct extent_map *em;
6775 struct btrfs_key ins; 6777 struct btrfs_key ins;
6776 u64 alloc_hint; 6778 u64 alloc_hint;
6777 int ret; 6779 int ret;
6778 6780
6779 alloc_hint = get_extent_allocation_hint(inode, start, len); 6781 alloc_hint = get_extent_allocation_hint(inode, start, len);
6780 ret = btrfs_reserve_extent(root, len, root->sectorsize, 0, 6782 ret = btrfs_reserve_extent(root, len, root->sectorsize, 0,
6781 alloc_hint, &ins, 1, 1); 6783 alloc_hint, &ins, 1, 1);
6782 if (ret) 6784 if (ret)
6783 return ERR_PTR(ret); 6785 return ERR_PTR(ret);
6784 6786
6785 em = create_pinned_em(inode, start, ins.offset, start, ins.objectid, 6787 em = create_pinned_em(inode, start, ins.offset, start, ins.objectid,
6786 ins.offset, ins.offset, ins.offset, 0); 6788 ins.offset, ins.offset, ins.offset, 0);
6787 if (IS_ERR(em)) { 6789 if (IS_ERR(em)) {
6788 btrfs_free_reserved_extent(root, ins.objectid, ins.offset, 1); 6790 btrfs_free_reserved_extent(root, ins.objectid, ins.offset, 1);
6789 return em; 6791 return em;
6790 } 6792 }
6791 6793
6792 ret = btrfs_add_ordered_extent_dio(inode, start, ins.objectid, 6794 ret = btrfs_add_ordered_extent_dio(inode, start, ins.objectid,
6793 ins.offset, ins.offset, 0); 6795 ins.offset, ins.offset, 0);
6794 if (ret) { 6796 if (ret) {
6795 btrfs_free_reserved_extent(root, ins.objectid, ins.offset, 1); 6797 btrfs_free_reserved_extent(root, ins.objectid, ins.offset, 1);
6796 free_extent_map(em); 6798 free_extent_map(em);
6797 return ERR_PTR(ret); 6799 return ERR_PTR(ret);
6798 } 6800 }
6799 6801
6800 return em; 6802 return em;
6801 } 6803 }
6802 6804
6803 /* 6805 /*
6804 * returns 1 when the nocow is safe, < 1 on error, 0 if the 6806 * returns 1 when the nocow is safe, < 1 on error, 0 if the
6805 * block must be cow'd 6807 * block must be cow'd
6806 */ 6808 */
6807 noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len, 6809 noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
6808 u64 *orig_start, u64 *orig_block_len, 6810 u64 *orig_start, u64 *orig_block_len,
6809 u64 *ram_bytes) 6811 u64 *ram_bytes)
6810 { 6812 {
6811 struct btrfs_trans_handle *trans; 6813 struct btrfs_trans_handle *trans;
6812 struct btrfs_path *path; 6814 struct btrfs_path *path;
6813 int ret; 6815 int ret;
6814 struct extent_buffer *leaf; 6816 struct extent_buffer *leaf;
6815 struct btrfs_root *root = BTRFS_I(inode)->root; 6817 struct btrfs_root *root = BTRFS_I(inode)->root;
6816 struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; 6818 struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
6817 struct btrfs_file_extent_item *fi; 6819 struct btrfs_file_extent_item *fi;
6818 struct btrfs_key key; 6820 struct btrfs_key key;
6819 u64 disk_bytenr; 6821 u64 disk_bytenr;
6820 u64 backref_offset; 6822 u64 backref_offset;
6821 u64 extent_end; 6823 u64 extent_end;
6822 u64 num_bytes; 6824 u64 num_bytes;
6823 int slot; 6825 int slot;
6824 int found_type; 6826 int found_type;
6825 bool nocow = (BTRFS_I(inode)->flags & BTRFS_INODE_NODATACOW); 6827 bool nocow = (BTRFS_I(inode)->flags & BTRFS_INODE_NODATACOW);
6826 6828
6827 path = btrfs_alloc_path(); 6829 path = btrfs_alloc_path();
6828 if (!path) 6830 if (!path)
6829 return -ENOMEM; 6831 return -ENOMEM;
6830 6832
6831 ret = btrfs_lookup_file_extent(NULL, root, path, btrfs_ino(inode), 6833 ret = btrfs_lookup_file_extent(NULL, root, path, btrfs_ino(inode),
6832 offset, 0); 6834 offset, 0);
6833 if (ret < 0) 6835 if (ret < 0)
6834 goto out; 6836 goto out;
6835 6837
6836 slot = path->slots[0]; 6838 slot = path->slots[0];
6837 if (ret == 1) { 6839 if (ret == 1) {
6838 if (slot == 0) { 6840 if (slot == 0) {
6839 /* can't find the item, must cow */ 6841 /* can't find the item, must cow */
6840 ret = 0; 6842 ret = 0;
6841 goto out; 6843 goto out;
6842 } 6844 }
6843 slot--; 6845 slot--;
6844 } 6846 }
6845 ret = 0; 6847 ret = 0;
6846 leaf = path->nodes[0]; 6848 leaf = path->nodes[0];
6847 btrfs_item_key_to_cpu(leaf, &key, slot); 6849 btrfs_item_key_to_cpu(leaf, &key, slot);
6848 if (key.objectid != btrfs_ino(inode) || 6850 if (key.objectid != btrfs_ino(inode) ||
6849 key.type != BTRFS_EXTENT_DATA_KEY) { 6851 key.type != BTRFS_EXTENT_DATA_KEY) {
6850 /* not our file or wrong item type, must cow */ 6852 /* not our file or wrong item type, must cow */
6851 goto out; 6853 goto out;
6852 } 6854 }
6853 6855
6854 if (key.offset > offset) { 6856 if (key.offset > offset) {
6855 /* Wrong offset, must cow */ 6857 /* Wrong offset, must cow */
6856 goto out; 6858 goto out;
6857 } 6859 }
6858 6860
6859 fi = btrfs_item_ptr(leaf, slot, struct btrfs_file_extent_item); 6861 fi = btrfs_item_ptr(leaf, slot, struct btrfs_file_extent_item);
6860 found_type = btrfs_file_extent_type(leaf, fi); 6862 found_type = btrfs_file_extent_type(leaf, fi);
6861 if (found_type != BTRFS_FILE_EXTENT_REG && 6863 if (found_type != BTRFS_FILE_EXTENT_REG &&
6862 found_type != BTRFS_FILE_EXTENT_PREALLOC) { 6864 found_type != BTRFS_FILE_EXTENT_PREALLOC) {
6863 /* not a regular extent, must cow */ 6865 /* not a regular extent, must cow */
6864 goto out; 6866 goto out;
6865 } 6867 }
6866 6868
6867 if (!nocow && found_type == BTRFS_FILE_EXTENT_REG) 6869 if (!nocow && found_type == BTRFS_FILE_EXTENT_REG)
6868 goto out; 6870 goto out;
6869 6871
6870 extent_end = key.offset + btrfs_file_extent_num_bytes(leaf, fi); 6872 extent_end = key.offset + btrfs_file_extent_num_bytes(leaf, fi);
6871 if (extent_end <= offset) 6873 if (extent_end <= offset)
6872 goto out; 6874 goto out;
6873 6875
6874 disk_bytenr = btrfs_file_extent_disk_bytenr(leaf, fi); 6876 disk_bytenr = btrfs_file_extent_disk_bytenr(leaf, fi);
6875 if (disk_bytenr == 0) 6877 if (disk_bytenr == 0)
6876 goto out; 6878 goto out;
6877 6879
6878 if (btrfs_file_extent_compression(leaf, fi) || 6880 if (btrfs_file_extent_compression(leaf, fi) ||
6879 btrfs_file_extent_encryption(leaf, fi) || 6881 btrfs_file_extent_encryption(leaf, fi) ||
6880 btrfs_file_extent_other_encoding(leaf, fi)) 6882 btrfs_file_extent_other_encoding(leaf, fi))
6881 goto out; 6883 goto out;
6882 6884
6883 backref_offset = btrfs_file_extent_offset(leaf, fi); 6885 backref_offset = btrfs_file_extent_offset(leaf, fi);
6884 6886
6885 if (orig_start) { 6887 if (orig_start) {
6886 *orig_start = key.offset - backref_offset; 6888 *orig_start = key.offset - backref_offset;
6887 *orig_block_len = btrfs_file_extent_disk_num_bytes(leaf, fi); 6889 *orig_block_len = btrfs_file_extent_disk_num_bytes(leaf, fi);
6888 *ram_bytes = btrfs_file_extent_ram_bytes(leaf, fi); 6890 *ram_bytes = btrfs_file_extent_ram_bytes(leaf, fi);
6889 } 6891 }
6890 6892
6891 if (btrfs_extent_readonly(root, disk_bytenr)) 6893 if (btrfs_extent_readonly(root, disk_bytenr))
6892 goto out; 6894 goto out;
6893 6895
6894 num_bytes = min(offset + *len, extent_end) - offset; 6896 num_bytes = min(offset + *len, extent_end) - offset;
6895 if (!nocow && found_type == BTRFS_FILE_EXTENT_PREALLOC) { 6897 if (!nocow && found_type == BTRFS_FILE_EXTENT_PREALLOC) {
6896 u64 range_end; 6898 u64 range_end;
6897 6899
6898 range_end = round_up(offset + num_bytes, root->sectorsize) - 1; 6900 range_end = round_up(offset + num_bytes, root->sectorsize) - 1;
6899 ret = test_range_bit(io_tree, offset, range_end, 6901 ret = test_range_bit(io_tree, offset, range_end,
6900 EXTENT_DELALLOC, 0, NULL); 6902 EXTENT_DELALLOC, 0, NULL);
6901 if (ret) { 6903 if (ret) {
6902 ret = -EAGAIN; 6904 ret = -EAGAIN;
6903 goto out; 6905 goto out;
6904 } 6906 }
6905 } 6907 }
6906 6908
6907 btrfs_release_path(path); 6909 btrfs_release_path(path);
6908 6910
6909 /* 6911 /*
6910 * look for other files referencing this extent, if we 6912 * look for other files referencing this extent, if we
6911 * find any we must cow 6913 * find any we must cow
6912 */ 6914 */
6913 trans = btrfs_join_transaction(root); 6915 trans = btrfs_join_transaction(root);
6914 if (IS_ERR(trans)) { 6916 if (IS_ERR(trans)) {
6915 ret = 0; 6917 ret = 0;
6916 goto out; 6918 goto out;
6917 } 6919 }
6918 6920
6919 ret = btrfs_cross_ref_exist(trans, root, btrfs_ino(inode), 6921 ret = btrfs_cross_ref_exist(trans, root, btrfs_ino(inode),
6920 key.offset - backref_offset, disk_bytenr); 6922 key.offset - backref_offset, disk_bytenr);
6921 btrfs_end_transaction(trans, root); 6923 btrfs_end_transaction(trans, root);
6922 if (ret) { 6924 if (ret) {
6923 ret = 0; 6925 ret = 0;
6924 goto out; 6926 goto out;
6925 } 6927 }
6926 6928
6927 /* 6929 /*
6928 * adjust disk_bytenr and num_bytes to cover just the bytes 6930 * adjust disk_bytenr and num_bytes to cover just the bytes
6929 * in this extent we are about to write. If there 6931 * in this extent we are about to write. If there
6930 * are any csums in that range we have to cow in order 6932 * are any csums in that range we have to cow in order
6931 * to keep the csums correct 6933 * to keep the csums correct
6932 */ 6934 */
6933 disk_bytenr += backref_offset; 6935 disk_bytenr += backref_offset;
6934 disk_bytenr += offset - key.offset; 6936 disk_bytenr += offset - key.offset;
6935 if (csum_exist_in_range(root, disk_bytenr, num_bytes)) 6937 if (csum_exist_in_range(root, disk_bytenr, num_bytes))
6936 goto out; 6938 goto out;
6937 /* 6939 /*
6938 * all of the above have passed, it is safe to overwrite this extent 6940 * all of the above have passed, it is safe to overwrite this extent
6939 * without cow 6941 * without cow
6940 */ 6942 */
6941 *len = num_bytes; 6943 *len = num_bytes;
6942 ret = 1; 6944 ret = 1;
6943 out: 6945 out:
6944 btrfs_free_path(path); 6946 btrfs_free_path(path);
6945 return ret; 6947 return ret;
6946 } 6948 }
6947 6949
6948 bool btrfs_page_exists_in_range(struct inode *inode, loff_t start, loff_t end) 6950 bool btrfs_page_exists_in_range(struct inode *inode, loff_t start, loff_t end)
6949 { 6951 {
6950 struct radix_tree_root *root = &inode->i_mapping->page_tree; 6952 struct radix_tree_root *root = &inode->i_mapping->page_tree;
6951 int found = false; 6953 int found = false;
6952 void **pagep = NULL; 6954 void **pagep = NULL;
6953 struct page *page = NULL; 6955 struct page *page = NULL;
6954 int start_idx; 6956 int start_idx;
6955 int end_idx; 6957 int end_idx;
6956 6958
6957 start_idx = start >> PAGE_CACHE_SHIFT; 6959 start_idx = start >> PAGE_CACHE_SHIFT;
6958 6960
6959 /* 6961 /*
6960 * end is the last byte in the last page. end == start is legal 6962 * end is the last byte in the last page. end == start is legal
6961 */ 6963 */
6962 end_idx = end >> PAGE_CACHE_SHIFT; 6964 end_idx = end >> PAGE_CACHE_SHIFT;
6963 6965
6964 rcu_read_lock(); 6966 rcu_read_lock();
6965 6967
6966 /* Most of the code in this while loop is lifted from 6968 /* Most of the code in this while loop is lifted from
6967 * find_get_page. It's been modified to begin searching from a 6969 * find_get_page. It's been modified to begin searching from a
6968 * page and return just the first page found in that range. If the 6970 * page and return just the first page found in that range. If the
6969 * found idx is less than or equal to the end idx then we know that 6971 * found idx is less than or equal to the end idx then we know that
6970 * a page exists. If no pages are found or if those pages are 6972 * a page exists. If no pages are found or if those pages are
6971 * outside of the range then we're fine (yay!) */ 6973 * outside of the range then we're fine (yay!) */
6972 while (page == NULL && 6974 while (page == NULL &&
6973 radix_tree_gang_lookup_slot(root, &pagep, NULL, start_idx, 1)) { 6975 radix_tree_gang_lookup_slot(root, &pagep, NULL, start_idx, 1)) {
6974 page = radix_tree_deref_slot(pagep); 6976 page = radix_tree_deref_slot(pagep);
6975 if (unlikely(!page)) 6977 if (unlikely(!page))
6976 break; 6978 break;
6977 6979
6978 if (radix_tree_exception(page)) { 6980 if (radix_tree_exception(page)) {
6979 if (radix_tree_deref_retry(page)) { 6981 if (radix_tree_deref_retry(page)) {
6980 page = NULL; 6982 page = NULL;
6981 continue; 6983 continue;
6982 } 6984 }
6983 /* 6985 /*
6984 * Otherwise, shmem/tmpfs must be storing a swap entry 6986 * Otherwise, shmem/tmpfs must be storing a swap entry
6985 * here as an exceptional entry: so return it without 6987 * here as an exceptional entry: so return it without
6986 * attempting to raise page count. 6988 * attempting to raise page count.
6987 */ 6989 */
6988 page = NULL; 6990 page = NULL;
6989 break; /* TODO: Is this relevant for this use case? */ 6991 break; /* TODO: Is this relevant for this use case? */
6990 } 6992 }
6991 6993
6992 if (!page_cache_get_speculative(page)) { 6994 if (!page_cache_get_speculative(page)) {
6993 page = NULL; 6995 page = NULL;
6994 continue; 6996 continue;
6995 } 6997 }
6996 6998
6997 /* 6999 /*
6998 * Has the page moved? 7000 * Has the page moved?
6999 * This is part of the lockless pagecache protocol. See 7001 * This is part of the lockless pagecache protocol. See
7000 * include/linux/pagemap.h for details. 7002 * include/linux/pagemap.h for details.
7001 */ 7003 */
7002 if (unlikely(page != *pagep)) { 7004 if (unlikely(page != *pagep)) {
7003 page_cache_release(page); 7005 page_cache_release(page);
7004 page = NULL; 7006 page = NULL;
7005 } 7007 }
7006 } 7008 }
7007 7009
7008 if (page) { 7010 if (page) {
7009 if (page->index <= end_idx) 7011 if (page->index <= end_idx)
7010 found = true; 7012 found = true;
7011 page_cache_release(page); 7013 page_cache_release(page);
7012 } 7014 }
7013 7015
7014 rcu_read_unlock(); 7016 rcu_read_unlock();
7015 return found; 7017 return found;
7016 } 7018 }
7017 7019
7018 static int lock_extent_direct(struct inode *inode, u64 lockstart, u64 lockend, 7020 static int lock_extent_direct(struct inode *inode, u64 lockstart, u64 lockend,
7019 struct extent_state **cached_state, int writing) 7021 struct extent_state **cached_state, int writing)
7020 { 7022 {
7021 struct btrfs_ordered_extent *ordered; 7023 struct btrfs_ordered_extent *ordered;
7022 int ret = 0; 7024 int ret = 0;
7023 7025
7024 while (1) { 7026 while (1) {
7025 lock_extent_bits(&BTRFS_I(inode)->io_tree, lockstart, lockend, 7027 lock_extent_bits(&BTRFS_I(inode)->io_tree, lockstart, lockend,
7026 0, cached_state); 7028 0, cached_state);
7027 /* 7029 /*
7028 * We're concerned with the entire range that we're going to be 7030 * We're concerned with the entire range that we're going to be
7029 * doing DIO to, so we need to make sure theres no ordered 7031 * doing DIO to, so we need to make sure theres no ordered
7030 * extents in this range. 7032 * extents in this range.
7031 */ 7033 */
7032 ordered = btrfs_lookup_ordered_range(inode, lockstart, 7034 ordered = btrfs_lookup_ordered_range(inode, lockstart,
7033 lockend - lockstart + 1); 7035 lockend - lockstart + 1);
7034 7036
7035 /* 7037 /*
7036 * We need to make sure there are no buffered pages in this 7038 * We need to make sure there are no buffered pages in this
7037 * range either, we could have raced between the invalidate in 7039 * range either, we could have raced between the invalidate in
7038 * generic_file_direct_write and locking the extent. The 7040 * generic_file_direct_write and locking the extent. The
7039 * invalidate needs to happen so that reads after a write do not 7041 * invalidate needs to happen so that reads after a write do not
7040 * get stale data. 7042 * get stale data.
7041 */ 7043 */
7042 if (!ordered && 7044 if (!ordered &&
7043 (!writing || 7045 (!writing ||
7044 !btrfs_page_exists_in_range(inode, lockstart, lockend))) 7046 !btrfs_page_exists_in_range(inode, lockstart, lockend)))
7045 break; 7047 break;
7046 7048
7047 unlock_extent_cached(&BTRFS_I(inode)->io_tree, lockstart, lockend, 7049 unlock_extent_cached(&BTRFS_I(inode)->io_tree, lockstart, lockend,
7048 cached_state, GFP_NOFS); 7050 cached_state, GFP_NOFS);
7049 7051
7050 if (ordered) { 7052 if (ordered) {
7051 btrfs_start_ordered_extent(inode, ordered, 1); 7053 btrfs_start_ordered_extent(inode, ordered, 1);
7052 btrfs_put_ordered_extent(ordered); 7054 btrfs_put_ordered_extent(ordered);
7053 } else { 7055 } else {
7054 /* Screw you mmap */ 7056 /* Screw you mmap */
7055 ret = btrfs_fdatawrite_range(inode, lockstart, lockend); 7057 ret = btrfs_fdatawrite_range(inode, lockstart, lockend);
7056 if (ret) 7058 if (ret)
7057 break; 7059 break;
7058 ret = filemap_fdatawait_range(inode->i_mapping, 7060 ret = filemap_fdatawait_range(inode->i_mapping,
7059 lockstart, 7061 lockstart,
7060 lockend); 7062 lockend);
7061 if (ret) 7063 if (ret)
7062 break; 7064 break;
7063 7065
7064 /* 7066 /*
7065 * If we found a page that couldn't be invalidated just 7067 * If we found a page that couldn't be invalidated just
7066 * fall back to buffered. 7068 * fall back to buffered.
7067 */ 7069 */
7068 ret = invalidate_inode_pages2_range(inode->i_mapping, 7070 ret = invalidate_inode_pages2_range(inode->i_mapping,
7069 lockstart >> PAGE_CACHE_SHIFT, 7071 lockstart >> PAGE_CACHE_SHIFT,
7070 lockend >> PAGE_CACHE_SHIFT); 7072 lockend >> PAGE_CACHE_SHIFT);
7071 if (ret) 7073 if (ret)
7072 break; 7074 break;
7073 } 7075 }
7074 7076
7075 cond_resched(); 7077 cond_resched();
7076 } 7078 }
7077 7079
7078 return ret; 7080 return ret;
7079 } 7081 }
7080 7082
7081 static struct extent_map *create_pinned_em(struct inode *inode, u64 start, 7083 static struct extent_map *create_pinned_em(struct inode *inode, u64 start,
7082 u64 len, u64 orig_start, 7084 u64 len, u64 orig_start,
7083 u64 block_start, u64 block_len, 7085 u64 block_start, u64 block_len,
7084 u64 orig_block_len, u64 ram_bytes, 7086 u64 orig_block_len, u64 ram_bytes,
7085 int type) 7087 int type)
7086 { 7088 {
7087 struct extent_map_tree *em_tree; 7089 struct extent_map_tree *em_tree;
7088 struct extent_map *em; 7090 struct extent_map *em;
7089 struct btrfs_root *root = BTRFS_I(inode)->root; 7091 struct btrfs_root *root = BTRFS_I(inode)->root;
7090 int ret; 7092 int ret;
7091 7093
7092 em_tree = &BTRFS_I(inode)->extent_tree; 7094 em_tree = &BTRFS_I(inode)->extent_tree;
7093 em = alloc_extent_map(); 7095 em = alloc_extent_map();
7094 if (!em) 7096 if (!em)
7095 return ERR_PTR(-ENOMEM); 7097 return ERR_PTR(-ENOMEM);
7096 7098
7097 em->start = start; 7099 em->start = start;
7098 em->orig_start = orig_start; 7100 em->orig_start = orig_start;
7099 em->mod_start = start; 7101 em->mod_start = start;
7100 em->mod_len = len; 7102 em->mod_len = len;
7101 em->len = len; 7103 em->len = len;
7102 em->block_len = block_len; 7104 em->block_len = block_len;
7103 em->block_start = block_start; 7105 em->block_start = block_start;
7104 em->bdev = root->fs_info->fs_devices->latest_bdev; 7106 em->bdev = root->fs_info->fs_devices->latest_bdev;
7105 em->orig_block_len = orig_block_len; 7107 em->orig_block_len = orig_block_len;
7106 em->ram_bytes = ram_bytes; 7108 em->ram_bytes = ram_bytes;
7107 em->generation = -1; 7109 em->generation = -1;
7108 set_bit(EXTENT_FLAG_PINNED, &em->flags); 7110 set_bit(EXTENT_FLAG_PINNED, &em->flags);
7109 if (type == BTRFS_ORDERED_PREALLOC) 7111 if (type == BTRFS_ORDERED_PREALLOC)
7110 set_bit(EXTENT_FLAG_FILLING, &em->flags); 7112 set_bit(EXTENT_FLAG_FILLING, &em->flags);
7111 7113
7112 do { 7114 do {
7113 btrfs_drop_extent_cache(inode, em->start, 7115 btrfs_drop_extent_cache(inode, em->start,
7114 em->start + em->len - 1, 0); 7116 em->start + em->len - 1, 0);
7115 write_lock(&em_tree->lock); 7117 write_lock(&em_tree->lock);
7116 ret = add_extent_mapping(em_tree, em, 1); 7118 ret = add_extent_mapping(em_tree, em, 1);
7117 write_unlock(&em_tree->lock); 7119 write_unlock(&em_tree->lock);
7118 } while (ret == -EEXIST); 7120 } while (ret == -EEXIST);
7119 7121
7120 if (ret) { 7122 if (ret) {
7121 free_extent_map(em); 7123 free_extent_map(em);
7122 return ERR_PTR(ret); 7124 return ERR_PTR(ret);
7123 } 7125 }
7124 7126
7125 return em; 7127 return em;
7126 } 7128 }
7127 7129
7128 7130
7129 static int btrfs_get_blocks_direct(struct inode *inode, sector_t iblock, 7131 static int btrfs_get_blocks_direct(struct inode *inode, sector_t iblock,
7130 struct buffer_head *bh_result, int create) 7132 struct buffer_head *bh_result, int create)
7131 { 7133 {
7132 struct extent_map *em; 7134 struct extent_map *em;
7133 struct btrfs_root *root = BTRFS_I(inode)->root; 7135 struct btrfs_root *root = BTRFS_I(inode)->root;
7134 struct extent_state *cached_state = NULL; 7136 struct extent_state *cached_state = NULL;
7135 u64 start = iblock << inode->i_blkbits; 7137 u64 start = iblock << inode->i_blkbits;
7136 u64 lockstart, lockend; 7138 u64 lockstart, lockend;
7137 u64 len = bh_result->b_size; 7139 u64 len = bh_result->b_size;
7138 int unlock_bits = EXTENT_LOCKED; 7140 int unlock_bits = EXTENT_LOCKED;
7139 int ret = 0; 7141 int ret = 0;
7140 7142
7141 if (create) 7143 if (create)
7142 unlock_bits |= EXTENT_DELALLOC | EXTENT_DIRTY; 7144 unlock_bits |= EXTENT_DELALLOC | EXTENT_DIRTY;
7143 else 7145 else
7144 len = min_t(u64, len, root->sectorsize); 7146 len = min_t(u64, len, root->sectorsize);
7145 7147
7146 lockstart = start; 7148 lockstart = start;
7147 lockend = start + len - 1; 7149 lockend = start + len - 1;
7148 7150
7149 /* 7151 /*
7150 * If this errors out it's because we couldn't invalidate pagecache for 7152 * If this errors out it's because we couldn't invalidate pagecache for
7151 * this range and we need to fallback to buffered. 7153 * this range and we need to fallback to buffered.
7152 */ 7154 */
7153 if (lock_extent_direct(inode, lockstart, lockend, &cached_state, create)) 7155 if (lock_extent_direct(inode, lockstart, lockend, &cached_state, create))
7154 return -ENOTBLK; 7156 return -ENOTBLK;
7155 7157
7156 em = btrfs_get_extent(inode, NULL, 0, start, len, 0); 7158 em = btrfs_get_extent(inode, NULL, 0, start, len, 0);
7157 if (IS_ERR(em)) { 7159 if (IS_ERR(em)) {
7158 ret = PTR_ERR(em); 7160 ret = PTR_ERR(em);
7159 goto unlock_err; 7161 goto unlock_err;
7160 } 7162 }
7161 7163
7162 /* 7164 /*
7163 * Ok for INLINE and COMPRESSED extents we need to fallback on buffered 7165 * Ok for INLINE and COMPRESSED extents we need to fallback on buffered
7164 * io. INLINE is special, and we could probably kludge it in here, but 7166 * io. INLINE is special, and we could probably kludge it in here, but
7165 * it's still buffered so for safety lets just fall back to the generic 7167 * it's still buffered so for safety lets just fall back to the generic
7166 * buffered path. 7168 * buffered path.
7167 * 7169 *
7168 * For COMPRESSED we _have_ to read the entire extent in so we can 7170 * For COMPRESSED we _have_ to read the entire extent in so we can
7169 * decompress it, so there will be buffering required no matter what we 7171 * decompress it, so there will be buffering required no matter what we
7170 * do, so go ahead and fallback to buffered. 7172 * do, so go ahead and fallback to buffered.
7171 * 7173 *
7172 * We return -ENOTBLK because thats what makes DIO go ahead and go back 7174 * We return -ENOTBLK because thats what makes DIO go ahead and go back
7173 * to buffered IO. Don't blame me, this is the price we pay for using 7175 * to buffered IO. Don't blame me, this is the price we pay for using
7174 * the generic code. 7176 * the generic code.
7175 */ 7177 */
7176 if (test_bit(EXTENT_FLAG_COMPRESSED, &em->flags) || 7178 if (test_bit(EXTENT_FLAG_COMPRESSED, &em->flags) ||
7177 em->block_start == EXTENT_MAP_INLINE) { 7179 em->block_start == EXTENT_MAP_INLINE) {
7178 free_extent_map(em); 7180 free_extent_map(em);
7179 ret = -ENOTBLK; 7181 ret = -ENOTBLK;
7180 goto unlock_err; 7182 goto unlock_err;
7181 } 7183 }
7182 7184
7183 /* Just a good old fashioned hole, return */ 7185 /* Just a good old fashioned hole, return */
7184 if (!create && (em->block_start == EXTENT_MAP_HOLE || 7186 if (!create && (em->block_start == EXTENT_MAP_HOLE ||
7185 test_bit(EXTENT_FLAG_PREALLOC, &em->flags))) { 7187 test_bit(EXTENT_FLAG_PREALLOC, &em->flags))) {
7186 free_extent_map(em); 7188 free_extent_map(em);
7187 goto unlock_err; 7189 goto unlock_err;
7188 } 7190 }
7189 7191
7190 /* 7192 /*
7191 * We don't allocate a new extent in the following cases 7193 * We don't allocate a new extent in the following cases
7192 * 7194 *
7193 * 1) The inode is marked as NODATACOW. In this case we'll just use the 7195 * 1) The inode is marked as NODATACOW. In this case we'll just use the
7194 * existing extent. 7196 * existing extent.
7195 * 2) The extent is marked as PREALLOC. We're good to go here and can 7197 * 2) The extent is marked as PREALLOC. We're good to go here and can
7196 * just use the extent. 7198 * just use the extent.
7197 * 7199 *
7198 */ 7200 */
7199 if (!create) { 7201 if (!create) {
7200 len = min(len, em->len - (start - em->start)); 7202 len = min(len, em->len - (start - em->start));
7201 lockstart = start + len; 7203 lockstart = start + len;
7202 goto unlock; 7204 goto unlock;
7203 } 7205 }
7204 7206
7205 if (test_bit(EXTENT_FLAG_PREALLOC, &em->flags) || 7207 if (test_bit(EXTENT_FLAG_PREALLOC, &em->flags) ||
7206 ((BTRFS_I(inode)->flags & BTRFS_INODE_NODATACOW) && 7208 ((BTRFS_I(inode)->flags & BTRFS_INODE_NODATACOW) &&
7207 em->block_start != EXTENT_MAP_HOLE)) { 7209 em->block_start != EXTENT_MAP_HOLE)) {
7208 int type; 7210 int type;
7209 int ret; 7211 int ret;
7210 u64 block_start, orig_start, orig_block_len, ram_bytes; 7212 u64 block_start, orig_start, orig_block_len, ram_bytes;
7211 7213
7212 if (test_bit(EXTENT_FLAG_PREALLOC, &em->flags)) 7214 if (test_bit(EXTENT_FLAG_PREALLOC, &em->flags))
7213 type = BTRFS_ORDERED_PREALLOC; 7215 type = BTRFS_ORDERED_PREALLOC;
7214 else 7216 else
7215 type = BTRFS_ORDERED_NOCOW; 7217 type = BTRFS_ORDERED_NOCOW;
7216 len = min(len, em->len - (start - em->start)); 7218 len = min(len, em->len - (start - em->start));
7217 block_start = em->block_start + (start - em->start); 7219 block_start = em->block_start + (start - em->start);
7218 7220
7219 if (can_nocow_extent(inode, start, &len, &orig_start, 7221 if (can_nocow_extent(inode, start, &len, &orig_start,
7220 &orig_block_len, &ram_bytes) == 1) { 7222 &orig_block_len, &ram_bytes) == 1) {
7221 if (type == BTRFS_ORDERED_PREALLOC) { 7223 if (type == BTRFS_ORDERED_PREALLOC) {
7222 free_extent_map(em); 7224 free_extent_map(em);
7223 em = create_pinned_em(inode, start, len, 7225 em = create_pinned_em(inode, start, len,
7224 orig_start, 7226 orig_start,
7225 block_start, len, 7227 block_start, len,
7226 orig_block_len, 7228 orig_block_len,
7227 ram_bytes, type); 7229 ram_bytes, type);
7228 if (IS_ERR(em)) { 7230 if (IS_ERR(em)) {
7229 ret = PTR_ERR(em); 7231 ret = PTR_ERR(em);
7230 goto unlock_err; 7232 goto unlock_err;
7231 } 7233 }
7232 } 7234 }
7233 7235
7234 ret = btrfs_add_ordered_extent_dio(inode, start, 7236 ret = btrfs_add_ordered_extent_dio(inode, start,
7235 block_start, len, len, type); 7237 block_start, len, len, type);
7236 if (ret) { 7238 if (ret) {
7237 free_extent_map(em); 7239 free_extent_map(em);
7238 goto unlock_err; 7240 goto unlock_err;
7239 } 7241 }
7240 goto unlock; 7242 goto unlock;
7241 } 7243 }
7242 } 7244 }
7243 7245
7244 /* 7246 /*
7245 * this will cow the extent, reset the len in case we changed 7247 * this will cow the extent, reset the len in case we changed
7246 * it above 7248 * it above
7247 */ 7249 */
7248 len = bh_result->b_size; 7250 len = bh_result->b_size;
7249 free_extent_map(em); 7251 free_extent_map(em);
7250 em = btrfs_new_extent_direct(inode, start, len); 7252 em = btrfs_new_extent_direct(inode, start, len);
7251 if (IS_ERR(em)) { 7253 if (IS_ERR(em)) {
7252 ret = PTR_ERR(em); 7254 ret = PTR_ERR(em);
7253 goto unlock_err; 7255 goto unlock_err;
7254 } 7256 }
7255 len = min(len, em->len - (start - em->start)); 7257 len = min(len, em->len - (start - em->start));
7256 unlock: 7258 unlock:
7257 bh_result->b_blocknr = (em->block_start + (start - em->start)) >> 7259 bh_result->b_blocknr = (em->block_start + (start - em->start)) >>
7258 inode->i_blkbits; 7260 inode->i_blkbits;
7259 bh_result->b_size = len; 7261 bh_result->b_size = len;
7260 bh_result->b_bdev = em->bdev; 7262 bh_result->b_bdev = em->bdev;
7261 set_buffer_mapped(bh_result); 7263 set_buffer_mapped(bh_result);
7262 if (create) { 7264 if (create) {
7263 if (!test_bit(EXTENT_FLAG_PREALLOC, &em->flags)) 7265 if (!test_bit(EXTENT_FLAG_PREALLOC, &em->flags))
7264 set_buffer_new(bh_result); 7266 set_buffer_new(bh_result);
7265 7267
7266 /* 7268 /*
7267 * Need to update the i_size under the extent lock so buffered 7269 * Need to update the i_size under the extent lock so buffered
7268 * readers will get the updated i_size when we unlock. 7270 * readers will get the updated i_size when we unlock.
7269 */ 7271 */
7270 if (start + len > i_size_read(inode)) 7272 if (start + len > i_size_read(inode))
7271 i_size_write(inode, start + len); 7273 i_size_write(inode, start + len);
7272 7274
7273 spin_lock(&BTRFS_I(inode)->lock); 7275 spin_lock(&BTRFS_I(inode)->lock);
7274 BTRFS_I(inode)->outstanding_extents++; 7276 BTRFS_I(inode)->outstanding_extents++;
7275 spin_unlock(&BTRFS_I(inode)->lock); 7277 spin_unlock(&BTRFS_I(inode)->lock);
7276 7278
7277 ret = set_extent_bit(&BTRFS_I(inode)->io_tree, lockstart, 7279 ret = set_extent_bit(&BTRFS_I(inode)->io_tree, lockstart,
7278 lockstart + len - 1, EXTENT_DELALLOC, NULL, 7280 lockstart + len - 1, EXTENT_DELALLOC, NULL,
7279 &cached_state, GFP_NOFS); 7281 &cached_state, GFP_NOFS);
7280 BUG_ON(ret); 7282 BUG_ON(ret);
7281 } 7283 }
7282 7284
7283 /* 7285 /*
7284 * In the case of write we need to clear and unlock the entire range, 7286 * In the case of write we need to clear and unlock the entire range,
7285 * in the case of read we need to unlock only the end area that we 7287 * in the case of read we need to unlock only the end area that we
7286 * aren't using if there is any left over space. 7288 * aren't using if there is any left over space.
7287 */ 7289 */
7288 if (lockstart < lockend) { 7290 if (lockstart < lockend) {
7289 clear_extent_bit(&BTRFS_I(inode)->io_tree, lockstart, 7291 clear_extent_bit(&BTRFS_I(inode)->io_tree, lockstart,
7290 lockend, unlock_bits, 1, 0, 7292 lockend, unlock_bits, 1, 0,
7291 &cached_state, GFP_NOFS); 7293 &cached_state, GFP_NOFS);
7292 } else { 7294 } else {
7293 free_extent_state(cached_state); 7295 free_extent_state(cached_state);
7294 } 7296 }
7295 7297
7296 free_extent_map(em); 7298 free_extent_map(em);
7297 7299
7298 return 0; 7300 return 0;
7299 7301
7300 unlock_err: 7302 unlock_err:
7301 clear_extent_bit(&BTRFS_I(inode)->io_tree, lockstart, lockend, 7303 clear_extent_bit(&BTRFS_I(inode)->io_tree, lockstart, lockend,
7302 unlock_bits, 1, 0, &cached_state, GFP_NOFS); 7304 unlock_bits, 1, 0, &cached_state, GFP_NOFS);
7303 return ret; 7305 return ret;
7304 } 7306 }
7305 7307
7306 static inline int submit_dio_repair_bio(struct inode *inode, struct bio *bio, 7308 static inline int submit_dio_repair_bio(struct inode *inode, struct bio *bio,
7307 int rw, int mirror_num) 7309 int rw, int mirror_num)
7308 { 7310 {
7309 struct btrfs_root *root = BTRFS_I(inode)->root; 7311 struct btrfs_root *root = BTRFS_I(inode)->root;
7310 int ret; 7312 int ret;
7311 7313
7312 BUG_ON(rw & REQ_WRITE); 7314 BUG_ON(rw & REQ_WRITE);
7313 7315
7314 bio_get(bio); 7316 bio_get(bio);
7315 7317
7316 ret = btrfs_bio_wq_end_io(root->fs_info, bio, 7318 ret = btrfs_bio_wq_end_io(root->fs_info, bio,
7317 BTRFS_WQ_ENDIO_DIO_REPAIR); 7319 BTRFS_WQ_ENDIO_DIO_REPAIR);
7318 if (ret) 7320 if (ret)
7319 goto err; 7321 goto err;
7320 7322
7321 ret = btrfs_map_bio(root, rw, bio, mirror_num, 0); 7323 ret = btrfs_map_bio(root, rw, bio, mirror_num, 0);
7322 err: 7324 err:
7323 bio_put(bio); 7325 bio_put(bio);
7324 return ret; 7326 return ret;
7325 } 7327 }
7326 7328
7327 static int btrfs_check_dio_repairable(struct inode *inode, 7329 static int btrfs_check_dio_repairable(struct inode *inode,
7328 struct bio *failed_bio, 7330 struct bio *failed_bio,
7329 struct io_failure_record *failrec, 7331 struct io_failure_record *failrec,
7330 int failed_mirror) 7332 int failed_mirror)
7331 { 7333 {
7332 int num_copies; 7334 int num_copies;
7333 7335
7334 num_copies = btrfs_num_copies(BTRFS_I(inode)->root->fs_info, 7336 num_copies = btrfs_num_copies(BTRFS_I(inode)->root->fs_info,
7335 failrec->logical, failrec->len); 7337 failrec->logical, failrec->len);
7336 if (num_copies == 1) { 7338 if (num_copies == 1) {
7337 /* 7339 /*
7338 * we only have a single copy of the data, so don't bother with 7340 * we only have a single copy of the data, so don't bother with
7339 * all the retry and error correction code that follows. no 7341 * all the retry and error correction code that follows. no
7340 * matter what the error is, it is very likely to persist. 7342 * matter what the error is, it is very likely to persist.
7341 */ 7343 */
7342 pr_debug("Check DIO Repairable: cannot repair, num_copies=%d, next_mirror %d, failed_mirror %d\n", 7344 pr_debug("Check DIO Repairable: cannot repair, num_copies=%d, next_mirror %d, failed_mirror %d\n",
7343 num_copies, failrec->this_mirror, failed_mirror); 7345 num_copies, failrec->this_mirror, failed_mirror);
7344 return 0; 7346 return 0;
7345 } 7347 }
7346 7348
7347 failrec->failed_mirror = failed_mirror; 7349 failrec->failed_mirror = failed_mirror;
7348 failrec->this_mirror++; 7350 failrec->this_mirror++;
7349 if (failrec->this_mirror == failed_mirror) 7351 if (failrec->this_mirror == failed_mirror)
7350 failrec->this_mirror++; 7352 failrec->this_mirror++;
7351 7353
7352 if (failrec->this_mirror > num_copies) { 7354 if (failrec->this_mirror > num_copies) {
7353 pr_debug("Check DIO Repairable: (fail) num_copies=%d, next_mirror %d, failed_mirror %d\n", 7355 pr_debug("Check DIO Repairable: (fail) num_copies=%d, next_mirror %d, failed_mirror %d\n",
7354 num_copies, failrec->this_mirror, failed_mirror); 7356 num_copies, failrec->this_mirror, failed_mirror);
7355 return 0; 7357 return 0;
7356 } 7358 }
7357 7359
7358 return 1; 7360 return 1;
7359 } 7361 }
7360 7362
7361 static int dio_read_error(struct inode *inode, struct bio *failed_bio, 7363 static int dio_read_error(struct inode *inode, struct bio *failed_bio,
7362 struct page *page, u64 start, u64 end, 7364 struct page *page, u64 start, u64 end,
7363 int failed_mirror, bio_end_io_t *repair_endio, 7365 int failed_mirror, bio_end_io_t *repair_endio,
7364 void *repair_arg) 7366 void *repair_arg)
7365 { 7367 {
7366 struct io_failure_record *failrec; 7368 struct io_failure_record *failrec;
7367 struct bio *bio; 7369 struct bio *bio;
7368 int isector; 7370 int isector;
7369 int read_mode; 7371 int read_mode;
7370 int ret; 7372 int ret;
7371 7373
7372 BUG_ON(failed_bio->bi_rw & REQ_WRITE); 7374 BUG_ON(failed_bio->bi_rw & REQ_WRITE);
7373 7375
7374 ret = btrfs_get_io_failure_record(inode, start, end, &failrec); 7376 ret = btrfs_get_io_failure_record(inode, start, end, &failrec);
7375 if (ret) 7377 if (ret)
7376 return ret; 7378 return ret;
7377 7379
7378 ret = btrfs_check_dio_repairable(inode, failed_bio, failrec, 7380 ret = btrfs_check_dio_repairable(inode, failed_bio, failrec,
7379 failed_mirror); 7381 failed_mirror);
7380 if (!ret) { 7382 if (!ret) {
7381 free_io_failure(inode, failrec); 7383 free_io_failure(inode, failrec);
7382 return -EIO; 7384 return -EIO;
7383 } 7385 }
7384 7386
7385 if (failed_bio->bi_vcnt > 1) 7387 if (failed_bio->bi_vcnt > 1)
7386 read_mode = READ_SYNC | REQ_FAILFAST_DEV; 7388 read_mode = READ_SYNC | REQ_FAILFAST_DEV;
7387 else 7389 else
7388 read_mode = READ_SYNC; 7390 read_mode = READ_SYNC;
7389 7391
7390 isector = start - btrfs_io_bio(failed_bio)->logical; 7392 isector = start - btrfs_io_bio(failed_bio)->logical;
7391 isector >>= inode->i_sb->s_blocksize_bits; 7393 isector >>= inode->i_sb->s_blocksize_bits;
7392 bio = btrfs_create_repair_bio(inode, failed_bio, failrec, page, 7394 bio = btrfs_create_repair_bio(inode, failed_bio, failrec, page,
7393 0, isector, repair_endio, repair_arg); 7395 0, isector, repair_endio, repair_arg);
7394 if (!bio) { 7396 if (!bio) {
7395 free_io_failure(inode, failrec); 7397 free_io_failure(inode, failrec);
7396 return -EIO; 7398 return -EIO;
7397 } 7399 }
7398 7400
7399 btrfs_debug(BTRFS_I(inode)->root->fs_info, 7401 btrfs_debug(BTRFS_I(inode)->root->fs_info,
7400 "Repair DIO Read Error: submitting new dio read[%#x] to this_mirror=%d, in_validation=%d\n", 7402 "Repair DIO Read Error: submitting new dio read[%#x] to this_mirror=%d, in_validation=%d\n",
7401 read_mode, failrec->this_mirror, failrec->in_validation); 7403 read_mode, failrec->this_mirror, failrec->in_validation);
7402 7404
7403 ret = submit_dio_repair_bio(inode, bio, read_mode, 7405 ret = submit_dio_repair_bio(inode, bio, read_mode,
7404 failrec->this_mirror); 7406 failrec->this_mirror);
7405 if (ret) { 7407 if (ret) {
7406 free_io_failure(inode, failrec); 7408 free_io_failure(inode, failrec);
7407 bio_put(bio); 7409 bio_put(bio);
7408 } 7410 }
7409 7411
7410 return ret; 7412 return ret;
7411 } 7413 }
7412 7414
7413 struct btrfs_retry_complete { 7415 struct btrfs_retry_complete {
7414 struct completion done; 7416 struct completion done;
7415 struct inode *inode; 7417 struct inode *inode;
7416 u64 start; 7418 u64 start;
7417 int uptodate; 7419 int uptodate;
7418 }; 7420 };
7419 7421
7420 static void btrfs_retry_endio_nocsum(struct bio *bio, int err) 7422 static void btrfs_retry_endio_nocsum(struct bio *bio, int err)
7421 { 7423 {
7422 struct btrfs_retry_complete *done = bio->bi_private; 7424 struct btrfs_retry_complete *done = bio->bi_private;
7423 struct bio_vec *bvec; 7425 struct bio_vec *bvec;
7424 int i; 7426 int i;
7425 7427
7426 if (err) 7428 if (err)
7427 goto end; 7429 goto end;
7428 7430
7429 done->uptodate = 1; 7431 done->uptodate = 1;
7430 bio_for_each_segment_all(bvec, bio, i) 7432 bio_for_each_segment_all(bvec, bio, i)
7431 clean_io_failure(done->inode, done->start, bvec->bv_page, 0); 7433 clean_io_failure(done->inode, done->start, bvec->bv_page, 0);
7432 end: 7434 end:
7433 complete(&done->done); 7435 complete(&done->done);
7434 bio_put(bio); 7436 bio_put(bio);
7435 } 7437 }
7436 7438
7437 static int __btrfs_correct_data_nocsum(struct inode *inode, 7439 static int __btrfs_correct_data_nocsum(struct inode *inode,
7438 struct btrfs_io_bio *io_bio) 7440 struct btrfs_io_bio *io_bio)
7439 { 7441 {
7440 struct bio_vec *bvec; 7442 struct bio_vec *bvec;
7441 struct btrfs_retry_complete done; 7443 struct btrfs_retry_complete done;
7442 u64 start; 7444 u64 start;
7443 int i; 7445 int i;
7444 int ret; 7446 int ret;
7445 7447
7446 start = io_bio->logical; 7448 start = io_bio->logical;
7447 done.inode = inode; 7449 done.inode = inode;
7448 7450
7449 bio_for_each_segment_all(bvec, &io_bio->bio, i) { 7451 bio_for_each_segment_all(bvec, &io_bio->bio, i) {
7450 try_again: 7452 try_again:
7451 done.uptodate = 0; 7453 done.uptodate = 0;
7452 done.start = start; 7454 done.start = start;
7453 init_completion(&done.done); 7455 init_completion(&done.done);
7454 7456
7455 ret = dio_read_error(inode, &io_bio->bio, bvec->bv_page, start, 7457 ret = dio_read_error(inode, &io_bio->bio, bvec->bv_page, start,
7456 start + bvec->bv_len - 1, 7458 start + bvec->bv_len - 1,
7457 io_bio->mirror_num, 7459 io_bio->mirror_num,
7458 btrfs_retry_endio_nocsum, &done); 7460 btrfs_retry_endio_nocsum, &done);
7459 if (ret) 7461 if (ret)
7460 return ret; 7462 return ret;
7461 7463
7462 wait_for_completion(&done.done); 7464 wait_for_completion(&done.done);
7463 7465
7464 if (!done.uptodate) { 7466 if (!done.uptodate) {
7465 /* We might have another mirror, so try again */ 7467 /* We might have another mirror, so try again */
7466 goto try_again; 7468 goto try_again;
7467 } 7469 }
7468 7470
7469 start += bvec->bv_len; 7471 start += bvec->bv_len;
7470 } 7472 }
7471 7473
7472 return 0; 7474 return 0;
7473 } 7475 }
7474 7476
7475 static void btrfs_retry_endio(struct bio *bio, int err) 7477 static void btrfs_retry_endio(struct bio *bio, int err)
7476 { 7478 {
7477 struct btrfs_retry_complete *done = bio->bi_private; 7479 struct btrfs_retry_complete *done = bio->bi_private;
7478 struct btrfs_io_bio *io_bio = btrfs_io_bio(bio); 7480 struct btrfs_io_bio *io_bio = btrfs_io_bio(bio);
7479 struct bio_vec *bvec; 7481 struct bio_vec *bvec;
7480 int uptodate; 7482 int uptodate;
7481 int ret; 7483 int ret;
7482 int i; 7484 int i;
7483 7485
7484 if (err) 7486 if (err)
7485 goto end; 7487 goto end;
7486 7488
7487 uptodate = 1; 7489 uptodate = 1;
7488 bio_for_each_segment_all(bvec, bio, i) { 7490 bio_for_each_segment_all(bvec, bio, i) {
7489 ret = __readpage_endio_check(done->inode, io_bio, i, 7491 ret = __readpage_endio_check(done->inode, io_bio, i,
7490 bvec->bv_page, 0, 7492 bvec->bv_page, 0,
7491 done->start, bvec->bv_len); 7493 done->start, bvec->bv_len);
7492 if (!ret) 7494 if (!ret)
7493 clean_io_failure(done->inode, done->start, 7495 clean_io_failure(done->inode, done->start,
7494 bvec->bv_page, 0); 7496 bvec->bv_page, 0);
7495 else 7497 else
7496 uptodate = 0; 7498 uptodate = 0;
7497 } 7499 }
7498 7500
7499 done->uptodate = uptodate; 7501 done->uptodate = uptodate;
7500 end: 7502 end:
7501 complete(&done->done); 7503 complete(&done->done);
7502 bio_put(bio); 7504 bio_put(bio);
7503 } 7505 }
7504 7506
7505 static int __btrfs_subio_endio_read(struct inode *inode, 7507 static int __btrfs_subio_endio_read(struct inode *inode,
7506 struct btrfs_io_bio *io_bio, int err) 7508 struct btrfs_io_bio *io_bio, int err)
7507 { 7509 {
7508 struct bio_vec *bvec; 7510 struct bio_vec *bvec;
7509 struct btrfs_retry_complete done; 7511 struct btrfs_retry_complete done;
7510 u64 start; 7512 u64 start;
7511 u64 offset = 0; 7513 u64 offset = 0;
7512 int i; 7514 int i;
7513 int ret; 7515 int ret;
7514 7516
7515 err = 0; 7517 err = 0;
7516 start = io_bio->logical; 7518 start = io_bio->logical;
7517 done.inode = inode; 7519 done.inode = inode;
7518 7520
7519 bio_for_each_segment_all(bvec, &io_bio->bio, i) { 7521 bio_for_each_segment_all(bvec, &io_bio->bio, i) {
7520 ret = __readpage_endio_check(inode, io_bio, i, bvec->bv_page, 7522 ret = __readpage_endio_check(inode, io_bio, i, bvec->bv_page,
7521 0, start, bvec->bv_len); 7523 0, start, bvec->bv_len);
7522 if (likely(!ret)) 7524 if (likely(!ret))
7523 goto next; 7525 goto next;
7524 try_again: 7526 try_again:
7525 done.uptodate = 0; 7527 done.uptodate = 0;
7526 done.start = start; 7528 done.start = start;
7527 init_completion(&done.done); 7529 init_completion(&done.done);
7528 7530
7529 ret = dio_read_error(inode, &io_bio->bio, bvec->bv_page, start, 7531 ret = dio_read_error(inode, &io_bio->bio, bvec->bv_page, start,
7530 start + bvec->bv_len - 1, 7532 start + bvec->bv_len - 1,
7531 io_bio->mirror_num, 7533 io_bio->mirror_num,
7532 btrfs_retry_endio, &done); 7534 btrfs_retry_endio, &done);
7533 if (ret) { 7535 if (ret) {
7534 err = ret; 7536 err = ret;
7535 goto next; 7537 goto next;
7536 } 7538 }
7537 7539
7538 wait_for_completion(&done.done); 7540 wait_for_completion(&done.done);
7539 7541
7540 if (!done.uptodate) { 7542 if (!done.uptodate) {
7541 /* We might have another mirror, so try again */ 7543 /* We might have another mirror, so try again */
7542 goto try_again; 7544 goto try_again;
7543 } 7545 }
7544 next: 7546 next:
7545 offset += bvec->bv_len; 7547 offset += bvec->bv_len;
7546 start += bvec->bv_len; 7548 start += bvec->bv_len;
7547 } 7549 }
7548 7550
7549 return err; 7551 return err;
7550 } 7552 }
7551 7553
7552 static int btrfs_subio_endio_read(struct inode *inode, 7554 static int btrfs_subio_endio_read(struct inode *inode,
7553 struct btrfs_io_bio *io_bio, int err) 7555 struct btrfs_io_bio *io_bio, int err)
7554 { 7556 {
7555 bool skip_csum = BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM; 7557 bool skip_csum = BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM;
7556 7558
7557 if (skip_csum) { 7559 if (skip_csum) {
7558 if (unlikely(err)) 7560 if (unlikely(err))
7559 return __btrfs_correct_data_nocsum(inode, io_bio); 7561 return __btrfs_correct_data_nocsum(inode, io_bio);
7560 else 7562 else
7561 return 0; 7563 return 0;
7562 } else { 7564 } else {
7563 return __btrfs_subio_endio_read(inode, io_bio, err); 7565 return __btrfs_subio_endio_read(inode, io_bio, err);
7564 } 7566 }
7565 } 7567 }
7566 7568
7567 static void btrfs_endio_direct_read(struct bio *bio, int err) 7569 static void btrfs_endio_direct_read(struct bio *bio, int err)
7568 { 7570 {
7569 struct btrfs_dio_private *dip = bio->bi_private; 7571 struct btrfs_dio_private *dip = bio->bi_private;
7570 struct inode *inode = dip->inode; 7572 struct inode *inode = dip->inode;
7571 struct bio *dio_bio; 7573 struct bio *dio_bio;
7572 struct btrfs_io_bio *io_bio = btrfs_io_bio(bio); 7574 struct btrfs_io_bio *io_bio = btrfs_io_bio(bio);
7573 7575
7574 if (dip->flags & BTRFS_DIO_ORIG_BIO_SUBMITTED) 7576 if (dip->flags & BTRFS_DIO_ORIG_BIO_SUBMITTED)
7575 err = btrfs_subio_endio_read(inode, io_bio, err); 7577 err = btrfs_subio_endio_read(inode, io_bio, err);
7576 7578
7577 unlock_extent(&BTRFS_I(inode)->io_tree, dip->logical_offset, 7579 unlock_extent(&BTRFS_I(inode)->io_tree, dip->logical_offset,
7578 dip->logical_offset + dip->bytes - 1); 7580 dip->logical_offset + dip->bytes - 1);
7579 dio_bio = dip->dio_bio; 7581 dio_bio = dip->dio_bio;
7580 7582
7581 kfree(dip); 7583 kfree(dip);
7582 7584
7583 /* If we had a csum failure make sure to clear the uptodate flag */ 7585 /* If we had a csum failure make sure to clear the uptodate flag */
7584 if (err) 7586 if (err)
7585 clear_bit(BIO_UPTODATE, &dio_bio->bi_flags); 7587 clear_bit(BIO_UPTODATE, &dio_bio->bi_flags);
7586 dio_end_io(dio_bio, err); 7588 dio_end_io(dio_bio, err);
7587 7589
7588 if (io_bio->end_io) 7590 if (io_bio->end_io)
7589 io_bio->end_io(io_bio, err); 7591 io_bio->end_io(io_bio, err);
7590 bio_put(bio); 7592 bio_put(bio);
7591 } 7593 }
7592 7594
7593 static void btrfs_endio_direct_write(struct bio *bio, int err) 7595 static void btrfs_endio_direct_write(struct bio *bio, int err)
7594 { 7596 {
7595 struct btrfs_dio_private *dip = bio->bi_private; 7597 struct btrfs_dio_private *dip = bio->bi_private;
7596 struct inode *inode = dip->inode; 7598 struct inode *inode = dip->inode;
7597 struct btrfs_root *root = BTRFS_I(inode)->root; 7599 struct btrfs_root *root = BTRFS_I(inode)->root;
7598 struct btrfs_ordered_extent *ordered = NULL; 7600 struct btrfs_ordered_extent *ordered = NULL;
7599 u64 ordered_offset = dip->logical_offset; 7601 u64 ordered_offset = dip->logical_offset;
7600 u64 ordered_bytes = dip->bytes; 7602 u64 ordered_bytes = dip->bytes;
7601 struct bio *dio_bio; 7603 struct bio *dio_bio;
7602 int ret; 7604 int ret;
7603 7605
7604 if (err) 7606 if (err)
7605 goto out_done; 7607 goto out_done;
7606 again: 7608 again:
7607 ret = btrfs_dec_test_first_ordered_pending(inode, &ordered, 7609 ret = btrfs_dec_test_first_ordered_pending(inode, &ordered,
7608 &ordered_offset, 7610 &ordered_offset,
7609 ordered_bytes, !err); 7611 ordered_bytes, !err);
7610 if (!ret) 7612 if (!ret)
7611 goto out_test; 7613 goto out_test;
7612 7614
7613 btrfs_init_work(&ordered->work, btrfs_endio_write_helper, 7615 btrfs_init_work(&ordered->work, btrfs_endio_write_helper,
7614 finish_ordered_fn, NULL, NULL); 7616 finish_ordered_fn, NULL, NULL);
7615 btrfs_queue_work(root->fs_info->endio_write_workers, 7617 btrfs_queue_work(root->fs_info->endio_write_workers,
7616 &ordered->work); 7618 &ordered->work);
7617 out_test: 7619 out_test:
7618 /* 7620 /*
7619 * our bio might span multiple ordered extents. If we haven't 7621 * our bio might span multiple ordered extents. If we haven't
7620 * completed the accounting for the whole dio, go back and try again 7622 * completed the accounting for the whole dio, go back and try again
7621 */ 7623 */
7622 if (ordered_offset < dip->logical_offset + dip->bytes) { 7624 if (ordered_offset < dip->logical_offset + dip->bytes) {
7623 ordered_bytes = dip->logical_offset + dip->bytes - 7625 ordered_bytes = dip->logical_offset + dip->bytes -
7624 ordered_offset; 7626 ordered_offset;
7625 ordered = NULL; 7627 ordered = NULL;
7626 goto again; 7628 goto again;
7627 } 7629 }
7628 out_done: 7630 out_done:
7629 dio_bio = dip->dio_bio; 7631 dio_bio = dip->dio_bio;
7630 7632
7631 kfree(dip); 7633 kfree(dip);
7632 7634
7633 /* If we had an error make sure to clear the uptodate flag */ 7635 /* If we had an error make sure to clear the uptodate flag */
7634 if (err) 7636 if (err)
7635 clear_bit(BIO_UPTODATE, &dio_bio->bi_flags); 7637 clear_bit(BIO_UPTODATE, &dio_bio->bi_flags);
7636 dio_end_io(dio_bio, err); 7638 dio_end_io(dio_bio, err);
7637 bio_put(bio); 7639 bio_put(bio);
7638 } 7640 }
7639 7641
7640 static int __btrfs_submit_bio_start_direct_io(struct inode *inode, int rw, 7642 static int __btrfs_submit_bio_start_direct_io(struct inode *inode, int rw,
7641 struct bio *bio, int mirror_num, 7643 struct bio *bio, int mirror_num,
7642 unsigned long bio_flags, u64 offset) 7644 unsigned long bio_flags, u64 offset)
7643 { 7645 {
7644 int ret; 7646 int ret;
7645 struct btrfs_root *root = BTRFS_I(inode)->root; 7647 struct btrfs_root *root = BTRFS_I(inode)->root;
7646 ret = btrfs_csum_one_bio(root, inode, bio, offset, 1); 7648 ret = btrfs_csum_one_bio(root, inode, bio, offset, 1);
7647 BUG_ON(ret); /* -ENOMEM */ 7649 BUG_ON(ret); /* -ENOMEM */
7648 return 0; 7650 return 0;
7649 } 7651 }
7650 7652
7651 static void btrfs_end_dio_bio(struct bio *bio, int err) 7653 static void btrfs_end_dio_bio(struct bio *bio, int err)
7652 { 7654 {
7653 struct btrfs_dio_private *dip = bio->bi_private; 7655 struct btrfs_dio_private *dip = bio->bi_private;
7654 7656
7655 if (err) 7657 if (err)
7656 btrfs_warn(BTRFS_I(dip->inode)->root->fs_info, 7658 btrfs_warn(BTRFS_I(dip->inode)->root->fs_info,
7657 "direct IO failed ino %llu rw %lu sector %#Lx len %u err no %d", 7659 "direct IO failed ino %llu rw %lu sector %#Lx len %u err no %d",
7658 btrfs_ino(dip->inode), bio->bi_rw, 7660 btrfs_ino(dip->inode), bio->bi_rw,
7659 (unsigned long long)bio->bi_iter.bi_sector, 7661 (unsigned long long)bio->bi_iter.bi_sector,
7660 bio->bi_iter.bi_size, err); 7662 bio->bi_iter.bi_size, err);
7661 7663
7662 if (dip->subio_endio) 7664 if (dip->subio_endio)
7663 err = dip->subio_endio(dip->inode, btrfs_io_bio(bio), err); 7665 err = dip->subio_endio(dip->inode, btrfs_io_bio(bio), err);
7664 7666
7665 if (err) { 7667 if (err) {
7666 dip->errors = 1; 7668 dip->errors = 1;
7667 7669
7668 /* 7670 /*
7669 * before atomic variable goto zero, we must make sure 7671 * before atomic variable goto zero, we must make sure
7670 * dip->errors is perceived to be set. 7672 * dip->errors is perceived to be set.
7671 */ 7673 */
7672 smp_mb__before_atomic(); 7674 smp_mb__before_atomic();
7673 } 7675 }
7674 7676
7675 /* if there are more bios still pending for this dio, just exit */ 7677 /* if there are more bios still pending for this dio, just exit */
7676 if (!atomic_dec_and_test(&dip->pending_bios)) 7678 if (!atomic_dec_and_test(&dip->pending_bios))
7677 goto out; 7679 goto out;
7678 7680
7679 if (dip->errors) { 7681 if (dip->errors) {
7680 bio_io_error(dip->orig_bio); 7682 bio_io_error(dip->orig_bio);
7681 } else { 7683 } else {
7682 set_bit(BIO_UPTODATE, &dip->dio_bio->bi_flags); 7684 set_bit(BIO_UPTODATE, &dip->dio_bio->bi_flags);
7683 bio_endio(dip->orig_bio, 0); 7685 bio_endio(dip->orig_bio, 0);
7684 } 7686 }
7685 out: 7687 out:
7686 bio_put(bio); 7688 bio_put(bio);
7687 } 7689 }
7688 7690
7689 static struct bio *btrfs_dio_bio_alloc(struct block_device *bdev, 7691 static struct bio *btrfs_dio_bio_alloc(struct block_device *bdev,
7690 u64 first_sector, gfp_t gfp_flags) 7692 u64 first_sector, gfp_t gfp_flags)
7691 { 7693 {
7692 int nr_vecs = bio_get_nr_vecs(bdev); 7694 int nr_vecs = bio_get_nr_vecs(bdev);
7693 return btrfs_bio_alloc(bdev, first_sector, nr_vecs, gfp_flags); 7695 return btrfs_bio_alloc(bdev, first_sector, nr_vecs, gfp_flags);
7694 } 7696 }
7695 7697
7696 static inline int btrfs_lookup_and_bind_dio_csum(struct btrfs_root *root, 7698 static inline int btrfs_lookup_and_bind_dio_csum(struct btrfs_root *root,
7697 struct inode *inode, 7699 struct inode *inode,
7698 struct btrfs_dio_private *dip, 7700 struct btrfs_dio_private *dip,
7699 struct bio *bio, 7701 struct bio *bio,
7700 u64 file_offset) 7702 u64 file_offset)
7701 { 7703 {
7702 struct btrfs_io_bio *io_bio = btrfs_io_bio(bio); 7704 struct btrfs_io_bio *io_bio = btrfs_io_bio(bio);
7703 struct btrfs_io_bio *orig_io_bio = btrfs_io_bio(dip->orig_bio); 7705 struct btrfs_io_bio *orig_io_bio = btrfs_io_bio(dip->orig_bio);
7704 int ret; 7706 int ret;
7705 7707
7706 /* 7708 /*
7707 * We load all the csum data we need when we submit 7709 * We load all the csum data we need when we submit
7708 * the first bio to reduce the csum tree search and 7710 * the first bio to reduce the csum tree search and
7709 * contention. 7711 * contention.
7710 */ 7712 */
7711 if (dip->logical_offset == file_offset) { 7713 if (dip->logical_offset == file_offset) {
7712 ret = btrfs_lookup_bio_sums_dio(root, inode, dip->orig_bio, 7714 ret = btrfs_lookup_bio_sums_dio(root, inode, dip->orig_bio,
7713 file_offset); 7715 file_offset);
7714 if (ret) 7716 if (ret)
7715 return ret; 7717 return ret;
7716 } 7718 }
7717 7719
7718 if (bio == dip->orig_bio) 7720 if (bio == dip->orig_bio)
7719 return 0; 7721 return 0;
7720 7722
7721 file_offset -= dip->logical_offset; 7723 file_offset -= dip->logical_offset;
7722 file_offset >>= inode->i_sb->s_blocksize_bits; 7724 file_offset >>= inode->i_sb->s_blocksize_bits;
7723 io_bio->csum = (u8 *)(((u32 *)orig_io_bio->csum) + file_offset); 7725 io_bio->csum = (u8 *)(((u32 *)orig_io_bio->csum) + file_offset);
7724 7726
7725 return 0; 7727 return 0;
7726 } 7728 }
7727 7729
7728 static inline int __btrfs_submit_dio_bio(struct bio *bio, struct inode *inode, 7730 static inline int __btrfs_submit_dio_bio(struct bio *bio, struct inode *inode,
7729 int rw, u64 file_offset, int skip_sum, 7731 int rw, u64 file_offset, int skip_sum,
7730 int async_submit) 7732 int async_submit)
7731 { 7733 {
7732 struct btrfs_dio_private *dip = bio->bi_private; 7734 struct btrfs_dio_private *dip = bio->bi_private;
7733 int write = rw & REQ_WRITE; 7735 int write = rw & REQ_WRITE;
7734 struct btrfs_root *root = BTRFS_I(inode)->root; 7736 struct btrfs_root *root = BTRFS_I(inode)->root;
7735 int ret; 7737 int ret;
7736 7738
7737 if (async_submit) 7739 if (async_submit)
7738 async_submit = !atomic_read(&BTRFS_I(inode)->sync_writers); 7740 async_submit = !atomic_read(&BTRFS_I(inode)->sync_writers);
7739 7741
7740 bio_get(bio); 7742 bio_get(bio);
7741 7743
7742 if (!write) { 7744 if (!write) {
7743 ret = btrfs_bio_wq_end_io(root->fs_info, bio, 7745 ret = btrfs_bio_wq_end_io(root->fs_info, bio,
7744 BTRFS_WQ_ENDIO_DATA); 7746 BTRFS_WQ_ENDIO_DATA);
7745 if (ret) 7747 if (ret)
7746 goto err; 7748 goto err;
7747 } 7749 }
7748 7750
7749 if (skip_sum) 7751 if (skip_sum)
7750 goto map; 7752 goto map;
7751 7753
7752 if (write && async_submit) { 7754 if (write && async_submit) {
7753 ret = btrfs_wq_submit_bio(root->fs_info, 7755 ret = btrfs_wq_submit_bio(root->fs_info,
7754 inode, rw, bio, 0, 0, 7756 inode, rw, bio, 0, 0,
7755 file_offset, 7757 file_offset,
7756 __btrfs_submit_bio_start_direct_io, 7758 __btrfs_submit_bio_start_direct_io,
7757 __btrfs_submit_bio_done); 7759 __btrfs_submit_bio_done);
7758 goto err; 7760 goto err;
7759 } else if (write) { 7761 } else if (write) {
7760 /* 7762 /*
7761 * If we aren't doing async submit, calculate the csum of the 7763 * If we aren't doing async submit, calculate the csum of the
7762 * bio now. 7764 * bio now.
7763 */ 7765 */
7764 ret = btrfs_csum_one_bio(root, inode, bio, file_offset, 1); 7766 ret = btrfs_csum_one_bio(root, inode, bio, file_offset, 1);
7765 if (ret) 7767 if (ret)
7766 goto err; 7768 goto err;
7767 } else { 7769 } else {
7768 ret = btrfs_lookup_and_bind_dio_csum(root, inode, dip, bio, 7770 ret = btrfs_lookup_and_bind_dio_csum(root, inode, dip, bio,
7769 file_offset); 7771 file_offset);
7770 if (ret) 7772 if (ret)
7771 goto err; 7773 goto err;
7772 } 7774 }
7773 map: 7775 map:
7774 ret = btrfs_map_bio(root, rw, bio, 0, async_submit); 7776 ret = btrfs_map_bio(root, rw, bio, 0, async_submit);
7775 err: 7777 err:
7776 bio_put(bio); 7778 bio_put(bio);
7777 return ret; 7779 return ret;
7778 } 7780 }
7779 7781
7780 static int btrfs_submit_direct_hook(int rw, struct btrfs_dio_private *dip, 7782 static int btrfs_submit_direct_hook(int rw, struct btrfs_dio_private *dip,
7781 int skip_sum) 7783 int skip_sum)
7782 { 7784 {
7783 struct inode *inode = dip->inode; 7785 struct inode *inode = dip->inode;
7784 struct btrfs_root *root = BTRFS_I(inode)->root; 7786 struct btrfs_root *root = BTRFS_I(inode)->root;
7785 struct bio *bio; 7787 struct bio *bio;
7786 struct bio *orig_bio = dip->orig_bio; 7788 struct bio *orig_bio = dip->orig_bio;
7787 struct bio_vec *bvec = orig_bio->bi_io_vec; 7789 struct bio_vec *bvec = orig_bio->bi_io_vec;
7788 u64 start_sector = orig_bio->bi_iter.bi_sector; 7790 u64 start_sector = orig_bio->bi_iter.bi_sector;
7789 u64 file_offset = dip->logical_offset; 7791 u64 file_offset = dip->logical_offset;
7790 u64 submit_len = 0; 7792 u64 submit_len = 0;
7791 u64 map_length; 7793 u64 map_length;
7792 int nr_pages = 0; 7794 int nr_pages = 0;
7793 int ret; 7795 int ret;
7794 int async_submit = 0; 7796 int async_submit = 0;
7795 7797
7796 map_length = orig_bio->bi_iter.bi_size; 7798 map_length = orig_bio->bi_iter.bi_size;
7797 ret = btrfs_map_block(root->fs_info, rw, start_sector << 9, 7799 ret = btrfs_map_block(root->fs_info, rw, start_sector << 9,
7798 &map_length, NULL, 0); 7800 &map_length, NULL, 0);
7799 if (ret) 7801 if (ret)
7800 return -EIO; 7802 return -EIO;
7801 7803
7802 if (map_length >= orig_bio->bi_iter.bi_size) { 7804 if (map_length >= orig_bio->bi_iter.bi_size) {
7803 bio = orig_bio; 7805 bio = orig_bio;
7804 dip->flags |= BTRFS_DIO_ORIG_BIO_SUBMITTED; 7806 dip->flags |= BTRFS_DIO_ORIG_BIO_SUBMITTED;
7805 goto submit; 7807 goto submit;
7806 } 7808 }
7807 7809
7808 /* async crcs make it difficult to collect full stripe writes. */ 7810 /* async crcs make it difficult to collect full stripe writes. */
7809 if (btrfs_get_alloc_profile(root, 1) & 7811 if (btrfs_get_alloc_profile(root, 1) &
7810 (BTRFS_BLOCK_GROUP_RAID5 | BTRFS_BLOCK_GROUP_RAID6)) 7812 (BTRFS_BLOCK_GROUP_RAID5 | BTRFS_BLOCK_GROUP_RAID6))
7811 async_submit = 0; 7813 async_submit = 0;
7812 else 7814 else
7813 async_submit = 1; 7815 async_submit = 1;
7814 7816
7815 bio = btrfs_dio_bio_alloc(orig_bio->bi_bdev, start_sector, GFP_NOFS); 7817 bio = btrfs_dio_bio_alloc(orig_bio->bi_bdev, start_sector, GFP_NOFS);
7816 if (!bio) 7818 if (!bio)
7817 return -ENOMEM; 7819 return -ENOMEM;
7818 7820
7819 bio->bi_private = dip; 7821 bio->bi_private = dip;
7820 bio->bi_end_io = btrfs_end_dio_bio; 7822 bio->bi_end_io = btrfs_end_dio_bio;
7821 btrfs_io_bio(bio)->logical = file_offset; 7823 btrfs_io_bio(bio)->logical = file_offset;
7822 atomic_inc(&dip->pending_bios); 7824 atomic_inc(&dip->pending_bios);
7823 7825
7824 while (bvec <= (orig_bio->bi_io_vec + orig_bio->bi_vcnt - 1)) { 7826 while (bvec <= (orig_bio->bi_io_vec + orig_bio->bi_vcnt - 1)) {
7825 if (map_length < submit_len + bvec->bv_len || 7827 if (map_length < submit_len + bvec->bv_len ||
7826 bio_add_page(bio, bvec->bv_page, bvec->bv_len, 7828 bio_add_page(bio, bvec->bv_page, bvec->bv_len,
7827 bvec->bv_offset) < bvec->bv_len) { 7829 bvec->bv_offset) < bvec->bv_len) {
7828 /* 7830 /*
7829 * inc the count before we submit the bio so 7831 * inc the count before we submit the bio so
7830 * we know the end IO handler won't happen before 7832 * we know the end IO handler won't happen before
7831 * we inc the count. Otherwise, the dip might get freed 7833 * we inc the count. Otherwise, the dip might get freed
7832 * before we're done setting it up 7834 * before we're done setting it up
7833 */ 7835 */
7834 atomic_inc(&dip->pending_bios); 7836 atomic_inc(&dip->pending_bios);
7835 ret = __btrfs_submit_dio_bio(bio, inode, rw, 7837 ret = __btrfs_submit_dio_bio(bio, inode, rw,
7836 file_offset, skip_sum, 7838 file_offset, skip_sum,
7837 async_submit); 7839 async_submit);
7838 if (ret) { 7840 if (ret) {
7839 bio_put(bio); 7841 bio_put(bio);
7840 atomic_dec(&dip->pending_bios); 7842 atomic_dec(&dip->pending_bios);
7841 goto out_err; 7843 goto out_err;
7842 } 7844 }
7843 7845
7844 start_sector += submit_len >> 9; 7846 start_sector += submit_len >> 9;
7845 file_offset += submit_len; 7847 file_offset += submit_len;
7846 7848
7847 submit_len = 0; 7849 submit_len = 0;
7848 nr_pages = 0; 7850 nr_pages = 0;
7849 7851
7850 bio = btrfs_dio_bio_alloc(orig_bio->bi_bdev, 7852 bio = btrfs_dio_bio_alloc(orig_bio->bi_bdev,
7851 start_sector, GFP_NOFS); 7853 start_sector, GFP_NOFS);
7852 if (!bio) 7854 if (!bio)
7853 goto out_err; 7855 goto out_err;
7854 bio->bi_private = dip; 7856 bio->bi_private = dip;
7855 bio->bi_end_io = btrfs_end_dio_bio; 7857 bio->bi_end_io = btrfs_end_dio_bio;
7856 btrfs_io_bio(bio)->logical = file_offset; 7858 btrfs_io_bio(bio)->logical = file_offset;
7857 7859
7858 map_length = orig_bio->bi_iter.bi_size; 7860 map_length = orig_bio->bi_iter.bi_size;
7859 ret = btrfs_map_block(root->fs_info, rw, 7861 ret = btrfs_map_block(root->fs_info, rw,
7860 start_sector << 9, 7862 start_sector << 9,
7861 &map_length, NULL, 0); 7863 &map_length, NULL, 0);
7862 if (ret) { 7864 if (ret) {
7863 bio_put(bio); 7865 bio_put(bio);
7864 goto out_err; 7866 goto out_err;
7865 } 7867 }
7866 } else { 7868 } else {
7867 submit_len += bvec->bv_len; 7869 submit_len += bvec->bv_len;
7868 nr_pages++; 7870 nr_pages++;
7869 bvec++; 7871 bvec++;
7870 } 7872 }
7871 } 7873 }
7872 7874
7873 submit: 7875 submit:
7874 ret = __btrfs_submit_dio_bio(bio, inode, rw, file_offset, skip_sum, 7876 ret = __btrfs_submit_dio_bio(bio, inode, rw, file_offset, skip_sum,
7875 async_submit); 7877 async_submit);
7876 if (!ret) 7878 if (!ret)
7877 return 0; 7879 return 0;
7878 7880
7879 bio_put(bio); 7881 bio_put(bio);
7880 out_err: 7882 out_err:
7881 dip->errors = 1; 7883 dip->errors = 1;
7882 /* 7884 /*
7883 * before atomic variable goto zero, we must 7885 * before atomic variable goto zero, we must
7884 * make sure dip->errors is perceived to be set. 7886 * make sure dip->errors is perceived to be set.
7885 */ 7887 */
7886 smp_mb__before_atomic(); 7888 smp_mb__before_atomic();
7887 if (atomic_dec_and_test(&dip->pending_bios)) 7889 if (atomic_dec_and_test(&dip->pending_bios))
7888 bio_io_error(dip->orig_bio); 7890 bio_io_error(dip->orig_bio);
7889 7891
7890 /* bio_end_io() will handle error, so we needn't return it */ 7892 /* bio_end_io() will handle error, so we needn't return it */
7891 return 0; 7893 return 0;
7892 } 7894 }
7893 7895
7894 static void btrfs_submit_direct(int rw, struct bio *dio_bio, 7896 static void btrfs_submit_direct(int rw, struct bio *dio_bio,
7895 struct inode *inode, loff_t file_offset) 7897 struct inode *inode, loff_t file_offset)
7896 { 7898 {
7897 struct btrfs_root *root = BTRFS_I(inode)->root; 7899 struct btrfs_root *root = BTRFS_I(inode)->root;
7898 struct btrfs_dio_private *dip; 7900 struct btrfs_dio_private *dip;
7899 struct bio *io_bio; 7901 struct bio *io_bio;
7900 struct btrfs_io_bio *btrfs_bio; 7902 struct btrfs_io_bio *btrfs_bio;
7901 int skip_sum; 7903 int skip_sum;
7902 int write = rw & REQ_WRITE; 7904 int write = rw & REQ_WRITE;
7903 int ret = 0; 7905 int ret = 0;
7904 7906
7905 skip_sum = BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM; 7907 skip_sum = BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM;
7906 7908
7907 io_bio = btrfs_bio_clone(dio_bio, GFP_NOFS); 7909 io_bio = btrfs_bio_clone(dio_bio, GFP_NOFS);
7908 if (!io_bio) { 7910 if (!io_bio) {
7909 ret = -ENOMEM; 7911 ret = -ENOMEM;
7910 goto free_ordered; 7912 goto free_ordered;
7911 } 7913 }
7912 7914
7913 dip = kzalloc(sizeof(*dip), GFP_NOFS); 7915 dip = kzalloc(sizeof(*dip), GFP_NOFS);
7914 if (!dip) { 7916 if (!dip) {
7915 ret = -ENOMEM; 7917 ret = -ENOMEM;
7916 goto free_io_bio; 7918 goto free_io_bio;
7917 } 7919 }
7918 7920
7919 dip->private = dio_bio->bi_private; 7921 dip->private = dio_bio->bi_private;
7920 dip->inode = inode; 7922 dip->inode = inode;
7921 dip->logical_offset = file_offset; 7923 dip->logical_offset = file_offset;
7922 dip->bytes = dio_bio->bi_iter.bi_size; 7924 dip->bytes = dio_bio->bi_iter.bi_size;
7923 dip->disk_bytenr = (u64)dio_bio->bi_iter.bi_sector << 9; 7925 dip->disk_bytenr = (u64)dio_bio->bi_iter.bi_sector << 9;
7924 io_bio->bi_private = dip; 7926 io_bio->bi_private = dip;
7925 dip->orig_bio = io_bio; 7927 dip->orig_bio = io_bio;
7926 dip->dio_bio = dio_bio; 7928 dip->dio_bio = dio_bio;
7927 atomic_set(&dip->pending_bios, 0); 7929 atomic_set(&dip->pending_bios, 0);
7928 btrfs_bio = btrfs_io_bio(io_bio); 7930 btrfs_bio = btrfs_io_bio(io_bio);
7929 btrfs_bio->logical = file_offset; 7931 btrfs_bio->logical = file_offset;
7930 7932
7931 if (write) { 7933 if (write) {
7932 io_bio->bi_end_io = btrfs_endio_direct_write; 7934 io_bio->bi_end_io = btrfs_endio_direct_write;
7933 } else { 7935 } else {
7934 io_bio->bi_end_io = btrfs_endio_direct_read; 7936 io_bio->bi_end_io = btrfs_endio_direct_read;
7935 dip->subio_endio = btrfs_subio_endio_read; 7937 dip->subio_endio = btrfs_subio_endio_read;
7936 } 7938 }
7937 7939
7938 ret = btrfs_submit_direct_hook(rw, dip, skip_sum); 7940 ret = btrfs_submit_direct_hook(rw, dip, skip_sum);
7939 if (!ret) 7941 if (!ret)
7940 return; 7942 return;
7941 7943
7942 if (btrfs_bio->end_io) 7944 if (btrfs_bio->end_io)
7943 btrfs_bio->end_io(btrfs_bio, ret); 7945 btrfs_bio->end_io(btrfs_bio, ret);
7944 free_io_bio: 7946 free_io_bio:
7945 bio_put(io_bio); 7947 bio_put(io_bio);
7946 7948
7947 free_ordered: 7949 free_ordered:
7948 /* 7950 /*
7949 * If this is a write, we need to clean up the reserved space and kill 7951 * If this is a write, we need to clean up the reserved space and kill
7950 * the ordered extent. 7952 * the ordered extent.
7951 */ 7953 */
7952 if (write) { 7954 if (write) {
7953 struct btrfs_ordered_extent *ordered; 7955 struct btrfs_ordered_extent *ordered;
7954 ordered = btrfs_lookup_ordered_extent(inode, file_offset); 7956 ordered = btrfs_lookup_ordered_extent(inode, file_offset);
7955 if (!test_bit(BTRFS_ORDERED_PREALLOC, &ordered->flags) && 7957 if (!test_bit(BTRFS_ORDERED_PREALLOC, &ordered->flags) &&
7956 !test_bit(BTRFS_ORDERED_NOCOW, &ordered->flags)) 7958 !test_bit(BTRFS_ORDERED_NOCOW, &ordered->flags))
7957 btrfs_free_reserved_extent(root, ordered->start, 7959 btrfs_free_reserved_extent(root, ordered->start,
7958 ordered->disk_len, 1); 7960 ordered->disk_len, 1);
7959 btrfs_put_ordered_extent(ordered); 7961 btrfs_put_ordered_extent(ordered);
7960 btrfs_put_ordered_extent(ordered); 7962 btrfs_put_ordered_extent(ordered);
7961 } 7963 }
7962 bio_endio(dio_bio, ret); 7964 bio_endio(dio_bio, ret);
7963 } 7965 }
7964 7966
7965 static ssize_t check_direct_IO(struct btrfs_root *root, int rw, struct kiocb *iocb, 7967 static ssize_t check_direct_IO(struct btrfs_root *root, int rw, struct kiocb *iocb,
7966 const struct iov_iter *iter, loff_t offset) 7968 const struct iov_iter *iter, loff_t offset)
7967 { 7969 {
7968 int seg; 7970 int seg;
7969 int i; 7971 int i;
7970 unsigned blocksize_mask = root->sectorsize - 1; 7972 unsigned blocksize_mask = root->sectorsize - 1;
7971 ssize_t retval = -EINVAL; 7973 ssize_t retval = -EINVAL;
7972 7974
7973 if (offset & blocksize_mask) 7975 if (offset & blocksize_mask)
7974 goto out; 7976 goto out;
7975 7977
7976 if (iov_iter_alignment(iter) & blocksize_mask) 7978 if (iov_iter_alignment(iter) & blocksize_mask)
7977 goto out; 7979 goto out;
7978 7980
7979 /* If this is a write we don't need to check anymore */ 7981 /* If this is a write we don't need to check anymore */
7980 if (rw & WRITE) 7982 if (rw & WRITE)
7981 return 0; 7983 return 0;
7982 /* 7984 /*
7983 * Check to make sure we don't have duplicate iov_base's in this 7985 * Check to make sure we don't have duplicate iov_base's in this
7984 * iovec, if so return EINVAL, otherwise we'll get csum errors 7986 * iovec, if so return EINVAL, otherwise we'll get csum errors
7985 * when reading back. 7987 * when reading back.
7986 */ 7988 */
7987 for (seg = 0; seg < iter->nr_segs; seg++) { 7989 for (seg = 0; seg < iter->nr_segs; seg++) {
7988 for (i = seg + 1; i < iter->nr_segs; i++) { 7990 for (i = seg + 1; i < iter->nr_segs; i++) {
7989 if (iter->iov[seg].iov_base == iter->iov[i].iov_base) 7991 if (iter->iov[seg].iov_base == iter->iov[i].iov_base)
7990 goto out; 7992 goto out;
7991 } 7993 }
7992 } 7994 }
7993 retval = 0; 7995 retval = 0;
7994 out: 7996 out:
7995 return retval; 7997 return retval;
7996 } 7998 }
7997 7999
7998 static ssize_t btrfs_direct_IO(int rw, struct kiocb *iocb, 8000 static ssize_t btrfs_direct_IO(int rw, struct kiocb *iocb,
7999 struct iov_iter *iter, loff_t offset) 8001 struct iov_iter *iter, loff_t offset)
8000 { 8002 {
8001 struct file *file = iocb->ki_filp; 8003 struct file *file = iocb->ki_filp;
8002 struct inode *inode = file->f_mapping->host; 8004 struct inode *inode = file->f_mapping->host;
8003 size_t count = 0; 8005 size_t count = 0;
8004 int flags = 0; 8006 int flags = 0;
8005 bool wakeup = true; 8007 bool wakeup = true;
8006 bool relock = false; 8008 bool relock = false;
8007 ssize_t ret; 8009 ssize_t ret;
8008 8010
8009 if (check_direct_IO(BTRFS_I(inode)->root, rw, iocb, iter, offset)) 8011 if (check_direct_IO(BTRFS_I(inode)->root, rw, iocb, iter, offset))
8010 return 0; 8012 return 0;
8011 8013
8012 atomic_inc(&inode->i_dio_count); 8014 atomic_inc(&inode->i_dio_count);
8013 smp_mb__after_atomic(); 8015 smp_mb__after_atomic();
8014 8016
8015 /* 8017 /*
8016 * The generic stuff only does filemap_write_and_wait_range, which 8018 * The generic stuff only does filemap_write_and_wait_range, which
8017 * isn't enough if we've written compressed pages to this area, so 8019 * isn't enough if we've written compressed pages to this area, so
8018 * we need to flush the dirty pages again to make absolutely sure 8020 * we need to flush the dirty pages again to make absolutely sure
8019 * that any outstanding dirty pages are on disk. 8021 * that any outstanding dirty pages are on disk.
8020 */ 8022 */
8021 count = iov_iter_count(iter); 8023 count = iov_iter_count(iter);
8022 if (test_bit(BTRFS_INODE_HAS_ASYNC_EXTENT, 8024 if (test_bit(BTRFS_INODE_HAS_ASYNC_EXTENT,
8023 &BTRFS_I(inode)->runtime_flags)) 8025 &BTRFS_I(inode)->runtime_flags))
8024 filemap_fdatawrite_range(inode->i_mapping, offset, 8026 filemap_fdatawrite_range(inode->i_mapping, offset,
8025 offset + count - 1); 8027 offset + count - 1);
8026 8028
8027 if (rw & WRITE) { 8029 if (rw & WRITE) {
8028 /* 8030 /*
8029 * If the write DIO is beyond the EOF, we need update 8031 * If the write DIO is beyond the EOF, we need update
8030 * the isize, but it is protected by i_mutex. So we can 8032 * the isize, but it is protected by i_mutex. So we can
8031 * not unlock the i_mutex at this case. 8033 * not unlock the i_mutex at this case.
8032 */ 8034 */
8033 if (offset + count <= inode->i_size) { 8035 if (offset + count <= inode->i_size) {
8034 mutex_unlock(&inode->i_mutex); 8036 mutex_unlock(&inode->i_mutex);
8035 relock = true; 8037 relock = true;
8036 } 8038 }
8037 ret = btrfs_delalloc_reserve_space(inode, count); 8039 ret = btrfs_delalloc_reserve_space(inode, count);
8038 if (ret) 8040 if (ret)
8039 goto out; 8041 goto out;
8040 } else if (test_bit(BTRFS_INODE_READDIO_NEED_LOCK, 8042 } else if (test_bit(BTRFS_INODE_READDIO_NEED_LOCK,
8041 &BTRFS_I(inode)->runtime_flags)) { 8043 &BTRFS_I(inode)->runtime_flags)) {
8042 inode_dio_done(inode); 8044 inode_dio_done(inode);
8043 flags = DIO_LOCKING | DIO_SKIP_HOLES; 8045 flags = DIO_LOCKING | DIO_SKIP_HOLES;
8044 wakeup = false; 8046 wakeup = false;
8045 } 8047 }
8046 8048
8047 ret = __blockdev_direct_IO(rw, iocb, inode, 8049 ret = __blockdev_direct_IO(rw, iocb, inode,
8048 BTRFS_I(inode)->root->fs_info->fs_devices->latest_bdev, 8050 BTRFS_I(inode)->root->fs_info->fs_devices->latest_bdev,
8049 iter, offset, btrfs_get_blocks_direct, NULL, 8051 iter, offset, btrfs_get_blocks_direct, NULL,
8050 btrfs_submit_direct, flags); 8052 btrfs_submit_direct, flags);
8051 if (rw & WRITE) { 8053 if (rw & WRITE) {
8052 if (ret < 0 && ret != -EIOCBQUEUED) 8054 if (ret < 0 && ret != -EIOCBQUEUED)
8053 btrfs_delalloc_release_space(inode, count); 8055 btrfs_delalloc_release_space(inode, count);
8054 else if (ret >= 0 && (size_t)ret < count) 8056 else if (ret >= 0 && (size_t)ret < count)
8055 btrfs_delalloc_release_space(inode, 8057 btrfs_delalloc_release_space(inode,
8056 count - (size_t)ret); 8058 count - (size_t)ret);
8057 else 8059 else
8058 btrfs_delalloc_release_metadata(inode, 0); 8060 btrfs_delalloc_release_metadata(inode, 0);
8059 } 8061 }
8060 out: 8062 out:
8061 if (wakeup) 8063 if (wakeup)
8062 inode_dio_done(inode); 8064 inode_dio_done(inode);
8063 if (relock) 8065 if (relock)
8064 mutex_lock(&inode->i_mutex); 8066 mutex_lock(&inode->i_mutex);
8065 8067
8066 return ret; 8068 return ret;
8067 } 8069 }
8068 8070
8069 #define BTRFS_FIEMAP_FLAGS (FIEMAP_FLAG_SYNC) 8071 #define BTRFS_FIEMAP_FLAGS (FIEMAP_FLAG_SYNC)
8070 8072
8071 static int btrfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 8073 static int btrfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
8072 __u64 start, __u64 len) 8074 __u64 start, __u64 len)
8073 { 8075 {
8074 int ret; 8076 int ret;
8075 8077
8076 ret = fiemap_check_flags(fieinfo, BTRFS_FIEMAP_FLAGS); 8078 ret = fiemap_check_flags(fieinfo, BTRFS_FIEMAP_FLAGS);
8077 if (ret) 8079 if (ret)
8078 return ret; 8080 return ret;
8079 8081
8080 return extent_fiemap(inode, fieinfo, start, len, btrfs_get_extent_fiemap); 8082 return extent_fiemap(inode, fieinfo, start, len, btrfs_get_extent_fiemap);
8081 } 8083 }
8082 8084
8083 int btrfs_readpage(struct file *file, struct page *page) 8085 int btrfs_readpage(struct file *file, struct page *page)
8084 { 8086 {
8085 struct extent_io_tree *tree; 8087 struct extent_io_tree *tree;
8086 tree = &BTRFS_I(page->mapping->host)->io_tree; 8088 tree = &BTRFS_I(page->mapping->host)->io_tree;
8087 return extent_read_full_page(tree, page, btrfs_get_extent, 0); 8089 return extent_read_full_page(tree, page, btrfs_get_extent, 0);
8088 } 8090 }
8089 8091
8090 static int btrfs_writepage(struct page *page, struct writeback_control *wbc) 8092 static int btrfs_writepage(struct page *page, struct writeback_control *wbc)
8091 { 8093 {
8092 struct extent_io_tree *tree; 8094 struct extent_io_tree *tree;
8093 8095
8094 8096
8095 if (current->flags & PF_MEMALLOC) { 8097 if (current->flags & PF_MEMALLOC) {
8096 redirty_page_for_writepage(wbc, page); 8098 redirty_page_for_writepage(wbc, page);
8097 unlock_page(page); 8099 unlock_page(page);
8098 return 0; 8100 return 0;
8099 } 8101 }
8100 tree = &BTRFS_I(page->mapping->host)->io_tree; 8102 tree = &BTRFS_I(page->mapping->host)->io_tree;
8101 return extent_write_full_page(tree, page, btrfs_get_extent, wbc); 8103 return extent_write_full_page(tree, page, btrfs_get_extent, wbc);
8102 } 8104 }
8103 8105
8104 static int btrfs_writepages(struct address_space *mapping, 8106 static int btrfs_writepages(struct address_space *mapping,
8105 struct writeback_control *wbc) 8107 struct writeback_control *wbc)
8106 { 8108 {
8107 struct extent_io_tree *tree; 8109 struct extent_io_tree *tree;
8108 8110
8109 tree = &BTRFS_I(mapping->host)->io_tree; 8111 tree = &BTRFS_I(mapping->host)->io_tree;
8110 return extent_writepages(tree, mapping, btrfs_get_extent, wbc); 8112 return extent_writepages(tree, mapping, btrfs_get_extent, wbc);
8111 } 8113 }
8112 8114
8113 static int 8115 static int
8114 btrfs_readpages(struct file *file, struct address_space *mapping, 8116 btrfs_readpages(struct file *file, struct address_space *mapping,
8115 struct list_head *pages, unsigned nr_pages) 8117 struct list_head *pages, unsigned nr_pages)
8116 { 8118 {
8117 struct extent_io_tree *tree; 8119 struct extent_io_tree *tree;
8118 tree = &BTRFS_I(mapping->host)->io_tree; 8120 tree = &BTRFS_I(mapping->host)->io_tree;
8119 return extent_readpages(tree, mapping, pages, nr_pages, 8121 return extent_readpages(tree, mapping, pages, nr_pages,
8120 btrfs_get_extent); 8122 btrfs_get_extent);
8121 } 8123 }
8122 static int __btrfs_releasepage(struct page *page, gfp_t gfp_flags) 8124 static int __btrfs_releasepage(struct page *page, gfp_t gfp_flags)
8123 { 8125 {
8124 struct extent_io_tree *tree; 8126 struct extent_io_tree *tree;
8125 struct extent_map_tree *map; 8127 struct extent_map_tree *map;
8126 int ret; 8128 int ret;
8127 8129
8128 tree = &BTRFS_I(page->mapping->host)->io_tree; 8130 tree = &BTRFS_I(page->mapping->host)->io_tree;
8129 map = &BTRFS_I(page->mapping->host)->extent_tree; 8131 map = &BTRFS_I(page->mapping->host)->extent_tree;
8130 ret = try_release_extent_mapping(map, tree, page, gfp_flags); 8132 ret = try_release_extent_mapping(map, tree, page, gfp_flags);
8131 if (ret == 1) { 8133 if (ret == 1) {
8132 ClearPagePrivate(page); 8134 ClearPagePrivate(page);
8133 set_page_private(page, 0); 8135 set_page_private(page, 0);
8134 page_cache_release(page); 8136 page_cache_release(page);
8135 } 8137 }
8136 return ret; 8138 return ret;
8137 } 8139 }
8138 8140
8139 static int btrfs_releasepage(struct page *page, gfp_t gfp_flags) 8141 static int btrfs_releasepage(struct page *page, gfp_t gfp_flags)
8140 { 8142 {
8141 if (PageWriteback(page) || PageDirty(page)) 8143 if (PageWriteback(page) || PageDirty(page))
8142 return 0; 8144 return 0;
8143 return __btrfs_releasepage(page, gfp_flags & GFP_NOFS); 8145 return __btrfs_releasepage(page, gfp_flags & GFP_NOFS);
8144 } 8146 }
8145 8147
8146 static void btrfs_invalidatepage(struct page *page, unsigned int offset, 8148 static void btrfs_invalidatepage(struct page *page, unsigned int offset,
8147 unsigned int length) 8149 unsigned int length)
8148 { 8150 {
8149 struct inode *inode = page->mapping->host; 8151 struct inode *inode = page->mapping->host;
8150 struct extent_io_tree *tree; 8152 struct extent_io_tree *tree;
8151 struct btrfs_ordered_extent *ordered; 8153 struct btrfs_ordered_extent *ordered;
8152 struct extent_state *cached_state = NULL; 8154 struct extent_state *cached_state = NULL;
8153 u64 page_start = page_offset(page); 8155 u64 page_start = page_offset(page);
8154 u64 page_end = page_start + PAGE_CACHE_SIZE - 1; 8156 u64 page_end = page_start + PAGE_CACHE_SIZE - 1;
8155 int inode_evicting = inode->i_state & I_FREEING; 8157 int inode_evicting = inode->i_state & I_FREEING;
8156 8158
8157 /* 8159 /*
8158 * we have the page locked, so new writeback can't start, 8160 * we have the page locked, so new writeback can't start,
8159 * and the dirty bit won't be cleared while we are here. 8161 * and the dirty bit won't be cleared while we are here.
8160 * 8162 *
8161 * Wait for IO on this page so that we can safely clear 8163 * Wait for IO on this page so that we can safely clear
8162 * the PagePrivate2 bit and do ordered accounting 8164 * the PagePrivate2 bit and do ordered accounting
8163 */ 8165 */
8164 wait_on_page_writeback(page); 8166 wait_on_page_writeback(page);
8165 8167
8166 tree = &BTRFS_I(inode)->io_tree; 8168 tree = &BTRFS_I(inode)->io_tree;
8167 if (offset) { 8169 if (offset) {
8168 btrfs_releasepage(page, GFP_NOFS); 8170 btrfs_releasepage(page, GFP_NOFS);
8169 return; 8171 return;
8170 } 8172 }
8171 8173
8172 if (!inode_evicting) 8174 if (!inode_evicting)
8173 lock_extent_bits(tree, page_start, page_end, 0, &cached_state); 8175 lock_extent_bits(tree, page_start, page_end, 0, &cached_state);
8174 ordered = btrfs_lookup_ordered_extent(inode, page_start); 8176 ordered = btrfs_lookup_ordered_extent(inode, page_start);
8175 if (ordered) { 8177 if (ordered) {
8176 /* 8178 /*
8177 * IO on this page will never be started, so we need 8179 * IO on this page will never be started, so we need
8178 * to account for any ordered extents now 8180 * to account for any ordered extents now
8179 */ 8181 */
8180 if (!inode_evicting) 8182 if (!inode_evicting)
8181 clear_extent_bit(tree, page_start, page_end, 8183 clear_extent_bit(tree, page_start, page_end,
8182 EXTENT_DIRTY | EXTENT_DELALLOC | 8184 EXTENT_DIRTY | EXTENT_DELALLOC |
8183 EXTENT_LOCKED | EXTENT_DO_ACCOUNTING | 8185 EXTENT_LOCKED | EXTENT_DO_ACCOUNTING |
8184 EXTENT_DEFRAG, 1, 0, &cached_state, 8186 EXTENT_DEFRAG, 1, 0, &cached_state,
8185 GFP_NOFS); 8187 GFP_NOFS);
8186 /* 8188 /*
8187 * whoever cleared the private bit is responsible 8189 * whoever cleared the private bit is responsible
8188 * for the finish_ordered_io 8190 * for the finish_ordered_io
8189 */ 8191 */
8190 if (TestClearPagePrivate2(page)) { 8192 if (TestClearPagePrivate2(page)) {
8191 struct btrfs_ordered_inode_tree *tree; 8193 struct btrfs_ordered_inode_tree *tree;
8192 u64 new_len; 8194 u64 new_len;
8193 8195
8194 tree = &BTRFS_I(inode)->ordered_tree; 8196 tree = &BTRFS_I(inode)->ordered_tree;
8195 8197
8196 spin_lock_irq(&tree->lock); 8198 spin_lock_irq(&tree->lock);
8197 set_bit(BTRFS_ORDERED_TRUNCATED, &ordered->flags); 8199 set_bit(BTRFS_ORDERED_TRUNCATED, &ordered->flags);
8198 new_len = page_start - ordered->file_offset; 8200 new_len = page_start - ordered->file_offset;
8199 if (new_len < ordered->truncated_len) 8201 if (new_len < ordered->truncated_len)
8200 ordered->truncated_len = new_len; 8202 ordered->truncated_len = new_len;
8201 spin_unlock_irq(&tree->lock); 8203 spin_unlock_irq(&tree->lock);
8202 8204
8203 if (btrfs_dec_test_ordered_pending(inode, &ordered, 8205 if (btrfs_dec_test_ordered_pending(inode, &ordered,
8204 page_start, 8206 page_start,
8205 PAGE_CACHE_SIZE, 1)) 8207 PAGE_CACHE_SIZE, 1))
8206 btrfs_finish_ordered_io(ordered); 8208 btrfs_finish_ordered_io(ordered);
8207 } 8209 }
8208 btrfs_put_ordered_extent(ordered); 8210 btrfs_put_ordered_extent(ordered);
8209 if (!inode_evicting) { 8211 if (!inode_evicting) {
8210 cached_state = NULL; 8212 cached_state = NULL;
8211 lock_extent_bits(tree, page_start, page_end, 0, 8213 lock_extent_bits(tree, page_start, page_end, 0,
8212 &cached_state); 8214 &cached_state);
8213 } 8215 }
8214 } 8216 }
8215 8217
8216 if (!inode_evicting) { 8218 if (!inode_evicting) {
8217 clear_extent_bit(tree, page_start, page_end, 8219 clear_extent_bit(tree, page_start, page_end,
8218 EXTENT_LOCKED | EXTENT_DIRTY | 8220 EXTENT_LOCKED | EXTENT_DIRTY |
8219 EXTENT_DELALLOC | EXTENT_DO_ACCOUNTING | 8221 EXTENT_DELALLOC | EXTENT_DO_ACCOUNTING |
8220 EXTENT_DEFRAG, 1, 1, 8222 EXTENT_DEFRAG, 1, 1,
8221 &cached_state, GFP_NOFS); 8223 &cached_state, GFP_NOFS);
8222 8224
8223 __btrfs_releasepage(page, GFP_NOFS); 8225 __btrfs_releasepage(page, GFP_NOFS);
8224 } 8226 }
8225 8227
8226 ClearPageChecked(page); 8228 ClearPageChecked(page);
8227 if (PagePrivate(page)) { 8229 if (PagePrivate(page)) {
8228 ClearPagePrivate(page); 8230 ClearPagePrivate(page);
8229 set_page_private(page, 0); 8231 set_page_private(page, 0);
8230 page_cache_release(page); 8232 page_cache_release(page);
8231 } 8233 }
8232 } 8234 }
8233 8235
8234 /* 8236 /*
8235 * btrfs_page_mkwrite() is not allowed to change the file size as it gets 8237 * btrfs_page_mkwrite() is not allowed to change the file size as it gets
8236 * called from a page fault handler when a page is first dirtied. Hence we must 8238 * called from a page fault handler when a page is first dirtied. Hence we must
8237 * be careful to check for EOF conditions here. We set the page up correctly 8239 * be careful to check for EOF conditions here. We set the page up correctly
8238 * for a written page which means we get ENOSPC checking when writing into 8240 * for a written page which means we get ENOSPC checking when writing into
8239 * holes and correct delalloc and unwritten extent mapping on filesystems that 8241 * holes and correct delalloc and unwritten extent mapping on filesystems that
8240 * support these features. 8242 * support these features.
8241 * 8243 *
8242 * We are not allowed to take the i_mutex here so we have to play games to 8244 * We are not allowed to take the i_mutex here so we have to play games to
8243 * protect against truncate races as the page could now be beyond EOF. Because 8245 * protect against truncate races as the page could now be beyond EOF. Because
8244 * vmtruncate() writes the inode size before removing pages, once we have the 8246 * vmtruncate() writes the inode size before removing pages, once we have the
8245 * page lock we can determine safely if the page is beyond EOF. If it is not 8247 * page lock we can determine safely if the page is beyond EOF. If it is not
8246 * beyond EOF, then the page is guaranteed safe against truncation until we 8248 * beyond EOF, then the page is guaranteed safe against truncation until we
8247 * unlock the page. 8249 * unlock the page.
8248 */ 8250 */
8249 int btrfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) 8251 int btrfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
8250 { 8252 {
8251 struct page *page = vmf->page; 8253 struct page *page = vmf->page;
8252 struct inode *inode = file_inode(vma->vm_file); 8254 struct inode *inode = file_inode(vma->vm_file);
8253 struct btrfs_root *root = BTRFS_I(inode)->root; 8255 struct btrfs_root *root = BTRFS_I(inode)->root;
8254 struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; 8256 struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
8255 struct btrfs_ordered_extent *ordered; 8257 struct btrfs_ordered_extent *ordered;
8256 struct extent_state *cached_state = NULL; 8258 struct extent_state *cached_state = NULL;
8257 char *kaddr; 8259 char *kaddr;
8258 unsigned long zero_start; 8260 unsigned long zero_start;
8259 loff_t size; 8261 loff_t size;
8260 int ret; 8262 int ret;
8261 int reserved = 0; 8263 int reserved = 0;
8262 u64 page_start; 8264 u64 page_start;
8263 u64 page_end; 8265 u64 page_end;
8264 8266
8265 sb_start_pagefault(inode->i_sb); 8267 sb_start_pagefault(inode->i_sb);
8266 ret = btrfs_delalloc_reserve_space(inode, PAGE_CACHE_SIZE); 8268 ret = btrfs_delalloc_reserve_space(inode, PAGE_CACHE_SIZE);
8267 if (!ret) { 8269 if (!ret) {
8268 ret = file_update_time(vma->vm_file); 8270 ret = file_update_time(vma->vm_file);
8269 reserved = 1; 8271 reserved = 1;
8270 } 8272 }
8271 if (ret) { 8273 if (ret) {
8272 if (ret == -ENOMEM) 8274 if (ret == -ENOMEM)
8273 ret = VM_FAULT_OOM; 8275 ret = VM_FAULT_OOM;
8274 else /* -ENOSPC, -EIO, etc */ 8276 else /* -ENOSPC, -EIO, etc */
8275 ret = VM_FAULT_SIGBUS; 8277 ret = VM_FAULT_SIGBUS;
8276 if (reserved) 8278 if (reserved)
8277 goto out; 8279 goto out;
8278 goto out_noreserve; 8280 goto out_noreserve;
8279 } 8281 }
8280 8282
8281 ret = VM_FAULT_NOPAGE; /* make the VM retry the fault */ 8283 ret = VM_FAULT_NOPAGE; /* make the VM retry the fault */
8282 again: 8284 again:
8283 lock_page(page); 8285 lock_page(page);
8284 size = i_size_read(inode); 8286 size = i_size_read(inode);
8285 page_start = page_offset(page); 8287 page_start = page_offset(page);
8286 page_end = page_start + PAGE_CACHE_SIZE - 1; 8288 page_end = page_start + PAGE_CACHE_SIZE - 1;
8287 8289
8288 if ((page->mapping != inode->i_mapping) || 8290 if ((page->mapping != inode->i_mapping) ||
8289 (page_start >= size)) { 8291 (page_start >= size)) {
8290 /* page got truncated out from underneath us */ 8292 /* page got truncated out from underneath us */
8291 goto out_unlock; 8293 goto out_unlock;
8292 } 8294 }
8293 wait_on_page_writeback(page); 8295 wait_on_page_writeback(page);
8294 8296
8295 lock_extent_bits(io_tree, page_start, page_end, 0, &cached_state); 8297 lock_extent_bits(io_tree, page_start, page_end, 0, &cached_state);
8296 set_page_extent_mapped(page); 8298 set_page_extent_mapped(page);
8297 8299
8298 /* 8300 /*
8299 * we can't set the delalloc bits if there are pending ordered 8301 * we can't set the delalloc bits if there are pending ordered
8300 * extents. Drop our locks and wait for them to finish 8302 * extents. Drop our locks and wait for them to finish
8301 */ 8303 */
8302 ordered = btrfs_lookup_ordered_extent(inode, page_start); 8304 ordered = btrfs_lookup_ordered_extent(inode, page_start);
8303 if (ordered) { 8305 if (ordered) {
8304 unlock_extent_cached(io_tree, page_start, page_end, 8306 unlock_extent_cached(io_tree, page_start, page_end,
8305 &cached_state, GFP_NOFS); 8307 &cached_state, GFP_NOFS);
8306 unlock_page(page); 8308 unlock_page(page);
8307 btrfs_start_ordered_extent(inode, ordered, 1); 8309 btrfs_start_ordered_extent(inode, ordered, 1);
8308 btrfs_put_ordered_extent(ordered); 8310 btrfs_put_ordered_extent(ordered);
8309 goto again; 8311 goto again;
8310 } 8312 }
8311 8313
8312 /* 8314 /*
8313 * XXX - page_mkwrite gets called every time the page is dirtied, even 8315 * XXX - page_mkwrite gets called every time the page is dirtied, even
8314 * if it was already dirty, so for space accounting reasons we need to 8316 * if it was already dirty, so for space accounting reasons we need to
8315 * clear any delalloc bits for the range we are fixing to save. There 8317 * clear any delalloc bits for the range we are fixing to save. There
8316 * is probably a better way to do this, but for now keep consistent with 8318 * is probably a better way to do this, but for now keep consistent with
8317 * prepare_pages in the normal write path. 8319 * prepare_pages in the normal write path.
8318 */ 8320 */
8319 clear_extent_bit(&BTRFS_I(inode)->io_tree, page_start, page_end, 8321 clear_extent_bit(&BTRFS_I(inode)->io_tree, page_start, page_end,
8320 EXTENT_DIRTY | EXTENT_DELALLOC | 8322 EXTENT_DIRTY | EXTENT_DELALLOC |
8321 EXTENT_DO_ACCOUNTING | EXTENT_DEFRAG, 8323 EXTENT_DO_ACCOUNTING | EXTENT_DEFRAG,
8322 0, 0, &cached_state, GFP_NOFS); 8324 0, 0, &cached_state, GFP_NOFS);
8323 8325
8324 ret = btrfs_set_extent_delalloc(inode, page_start, page_end, 8326 ret = btrfs_set_extent_delalloc(inode, page_start, page_end,
8325 &cached_state); 8327 &cached_state);
8326 if (ret) { 8328 if (ret) {
8327 unlock_extent_cached(io_tree, page_start, page_end, 8329 unlock_extent_cached(io_tree, page_start, page_end,
8328 &cached_state, GFP_NOFS); 8330 &cached_state, GFP_NOFS);
8329 ret = VM_FAULT_SIGBUS; 8331 ret = VM_FAULT_SIGBUS;
8330 goto out_unlock; 8332 goto out_unlock;
8331 } 8333 }
8332 ret = 0; 8334 ret = 0;
8333 8335
8334 /* page is wholly or partially inside EOF */ 8336 /* page is wholly or partially inside EOF */
8335 if (page_start + PAGE_CACHE_SIZE > size) 8337 if (page_start + PAGE_CACHE_SIZE > size)
8336 zero_start = size & ~PAGE_CACHE_MASK; 8338 zero_start = size & ~PAGE_CACHE_MASK;
8337 else 8339 else
8338 zero_start = PAGE_CACHE_SIZE; 8340 zero_start = PAGE_CACHE_SIZE;
8339 8341
8340 if (zero_start != PAGE_CACHE_SIZE) { 8342 if (zero_start != PAGE_CACHE_SIZE) {
8341 kaddr = kmap(page); 8343 kaddr = kmap(page);
8342 memset(kaddr + zero_start, 0, PAGE_CACHE_SIZE - zero_start); 8344 memset(kaddr + zero_start, 0, PAGE_CACHE_SIZE - zero_start);
8343 flush_dcache_page(page); 8345 flush_dcache_page(page);
8344 kunmap(page); 8346 kunmap(page);
8345 } 8347 }
8346 ClearPageChecked(page); 8348 ClearPageChecked(page);
8347 set_page_dirty(page); 8349 set_page_dirty(page);
8348 SetPageUptodate(page); 8350 SetPageUptodate(page);
8349 8351
8350 BTRFS_I(inode)->last_trans = root->fs_info->generation; 8352 BTRFS_I(inode)->last_trans = root->fs_info->generation;
8351 BTRFS_I(inode)->last_sub_trans = BTRFS_I(inode)->root->log_transid; 8353 BTRFS_I(inode)->last_sub_trans = BTRFS_I(inode)->root->log_transid;
8352 BTRFS_I(inode)->last_log_commit = BTRFS_I(inode)->root->last_log_commit; 8354 BTRFS_I(inode)->last_log_commit = BTRFS_I(inode)->root->last_log_commit;
8353 8355
8354 unlock_extent_cached(io_tree, page_start, page_end, &cached_state, GFP_NOFS); 8356 unlock_extent_cached(io_tree, page_start, page_end, &cached_state, GFP_NOFS);
8355 8357
8356 out_unlock: 8358 out_unlock:
8357 if (!ret) { 8359 if (!ret) {
8358 sb_end_pagefault(inode->i_sb); 8360 sb_end_pagefault(inode->i_sb);
8359 return VM_FAULT_LOCKED; 8361 return VM_FAULT_LOCKED;
8360 } 8362 }
8361 unlock_page(page); 8363 unlock_page(page);
8362 out: 8364 out:
8363 btrfs_delalloc_release_space(inode, PAGE_CACHE_SIZE); 8365 btrfs_delalloc_release_space(inode, PAGE_CACHE_SIZE);
8364 out_noreserve: 8366 out_noreserve:
8365 sb_end_pagefault(inode->i_sb); 8367 sb_end_pagefault(inode->i_sb);
8366 return ret; 8368 return ret;
8367 } 8369 }
8368 8370
8369 static int btrfs_truncate(struct inode *inode) 8371 static int btrfs_truncate(struct inode *inode)
8370 { 8372 {
8371 struct btrfs_root *root = BTRFS_I(inode)->root; 8373 struct btrfs_root *root = BTRFS_I(inode)->root;
8372 struct btrfs_block_rsv *rsv; 8374 struct btrfs_block_rsv *rsv;
8373 int ret = 0; 8375 int ret = 0;
8374 int err = 0; 8376 int err = 0;
8375 struct btrfs_trans_handle *trans; 8377 struct btrfs_trans_handle *trans;
8376 u64 mask = root->sectorsize - 1; 8378 u64 mask = root->sectorsize - 1;
8377 u64 min_size = btrfs_calc_trunc_metadata_size(root, 1); 8379 u64 min_size = btrfs_calc_trunc_metadata_size(root, 1);
8378 8380
8379 ret = btrfs_wait_ordered_range(inode, inode->i_size & (~mask), 8381 ret = btrfs_wait_ordered_range(inode, inode->i_size & (~mask),
8380 (u64)-1); 8382 (u64)-1);
8381 if (ret) 8383 if (ret)
8382 return ret; 8384 return ret;
8383 8385
8384 /* 8386 /*
8385 * Yes ladies and gentelment, this is indeed ugly. The fact is we have 8387 * Yes ladies and gentelment, this is indeed ugly. The fact is we have
8386 * 3 things going on here 8388 * 3 things going on here
8387 * 8389 *
8388 * 1) We need to reserve space for our orphan item and the space to 8390 * 1) We need to reserve space for our orphan item and the space to
8389 * delete our orphan item. Lord knows we don't want to have a dangling 8391 * delete our orphan item. Lord knows we don't want to have a dangling
8390 * orphan item because we didn't reserve space to remove it. 8392 * orphan item because we didn't reserve space to remove it.
8391 * 8393 *
8392 * 2) We need to reserve space to update our inode. 8394 * 2) We need to reserve space to update our inode.
8393 * 8395 *
8394 * 3) We need to have something to cache all the space that is going to 8396 * 3) We need to have something to cache all the space that is going to
8395 * be free'd up by the truncate operation, but also have some slack 8397 * be free'd up by the truncate operation, but also have some slack
8396 * space reserved in case it uses space during the truncate (thank you 8398 * space reserved in case it uses space during the truncate (thank you
8397 * very much snapshotting). 8399 * very much snapshotting).
8398 * 8400 *
8399 * And we need these to all be seperate. The fact is we can use alot of 8401 * And we need these to all be seperate. The fact is we can use alot of
8400 * space doing the truncate, and we have no earthly idea how much space 8402 * space doing the truncate, and we have no earthly idea how much space
8401 * we will use, so we need the truncate reservation to be seperate so it 8403 * we will use, so we need the truncate reservation to be seperate so it
8402 * doesn't end up using space reserved for updating the inode or 8404 * doesn't end up using space reserved for updating the inode or
8403 * removing the orphan item. We also need to be able to stop the 8405 * removing the orphan item. We also need to be able to stop the
8404 * transaction and start a new one, which means we need to be able to 8406 * transaction and start a new one, which means we need to be able to
8405 * update the inode several times, and we have no idea of knowing how 8407 * update the inode several times, and we have no idea of knowing how
8406 * many times that will be, so we can't just reserve 1 item for the 8408 * many times that will be, so we can't just reserve 1 item for the
8407 * entirety of the opration, so that has to be done seperately as well. 8409 * entirety of the opration, so that has to be done seperately as well.
8408 * Then there is the orphan item, which does indeed need to be held on 8410 * Then there is the orphan item, which does indeed need to be held on
8409 * to for the whole operation, and we need nobody to touch this reserved 8411 * to for the whole operation, and we need nobody to touch this reserved
8410 * space except the orphan code. 8412 * space except the orphan code.
8411 * 8413 *
8412 * So that leaves us with 8414 * So that leaves us with
8413 * 8415 *
8414 * 1) root->orphan_block_rsv - for the orphan deletion. 8416 * 1) root->orphan_block_rsv - for the orphan deletion.
8415 * 2) rsv - for the truncate reservation, which we will steal from the 8417 * 2) rsv - for the truncate reservation, which we will steal from the
8416 * transaction reservation. 8418 * transaction reservation.
8417 * 3) fs_info->trans_block_rsv - this will have 1 items worth left for 8419 * 3) fs_info->trans_block_rsv - this will have 1 items worth left for
8418 * updating the inode. 8420 * updating the inode.
8419 */ 8421 */
8420 rsv = btrfs_alloc_block_rsv(root, BTRFS_BLOCK_RSV_TEMP); 8422 rsv = btrfs_alloc_block_rsv(root, BTRFS_BLOCK_RSV_TEMP);
8421 if (!rsv) 8423 if (!rsv)
8422 return -ENOMEM; 8424 return -ENOMEM;
8423 rsv->size = min_size; 8425 rsv->size = min_size;
8424 rsv->failfast = 1; 8426 rsv->failfast = 1;
8425 8427
8426 /* 8428 /*
8427 * 1 for the truncate slack space 8429 * 1 for the truncate slack space
8428 * 1 for updating the inode. 8430 * 1 for updating the inode.
8429 */ 8431 */
8430 trans = btrfs_start_transaction(root, 2); 8432 trans = btrfs_start_transaction(root, 2);
8431 if (IS_ERR(trans)) { 8433 if (IS_ERR(trans)) {
8432 err = PTR_ERR(trans); 8434 err = PTR_ERR(trans);
8433 goto out; 8435 goto out;
8434 } 8436 }
8435 8437
8436 /* Migrate the slack space for the truncate to our reserve */ 8438 /* Migrate the slack space for the truncate to our reserve */
8437 ret = btrfs_block_rsv_migrate(&root->fs_info->trans_block_rsv, rsv, 8439 ret = btrfs_block_rsv_migrate(&root->fs_info->trans_block_rsv, rsv,
8438 min_size); 8440 min_size);
8439 BUG_ON(ret); 8441 BUG_ON(ret);
8440 8442
8441 /* 8443 /*
8442 * So if we truncate and then write and fsync we normally would just 8444 * So if we truncate and then write and fsync we normally would just
8443 * write the extents that changed, which is a problem if we need to 8445 * write the extents that changed, which is a problem if we need to
8444 * first truncate that entire inode. So set this flag so we write out 8446 * first truncate that entire inode. So set this flag so we write out
8445 * all of the extents in the inode to the sync log so we're completely 8447 * all of the extents in the inode to the sync log so we're completely
8446 * safe. 8448 * safe.
8447 */ 8449 */
8448 set_bit(BTRFS_INODE_NEEDS_FULL_SYNC, &BTRFS_I(inode)->runtime_flags); 8450 set_bit(BTRFS_INODE_NEEDS_FULL_SYNC, &BTRFS_I(inode)->runtime_flags);
8449 trans->block_rsv = rsv; 8451 trans->block_rsv = rsv;
8450 8452
8451 while (1) { 8453 while (1) {
8452 ret = btrfs_truncate_inode_items(trans, root, inode, 8454 ret = btrfs_truncate_inode_items(trans, root, inode,
8453 inode->i_size, 8455 inode->i_size,
8454 BTRFS_EXTENT_DATA_KEY); 8456 BTRFS_EXTENT_DATA_KEY);
8455 if (ret != -ENOSPC) { 8457 if (ret != -ENOSPC) {
8456 err = ret; 8458 err = ret;
8457 break; 8459 break;
8458 } 8460 }
8459 8461
8460 trans->block_rsv = &root->fs_info->trans_block_rsv; 8462 trans->block_rsv = &root->fs_info->trans_block_rsv;
8461 ret = btrfs_update_inode(trans, root, inode); 8463 ret = btrfs_update_inode(trans, root, inode);
8462 if (ret) { 8464 if (ret) {
8463 err = ret; 8465 err = ret;
8464 break; 8466 break;
8465 } 8467 }
8466 8468
8467 btrfs_end_transaction(trans, root); 8469 btrfs_end_transaction(trans, root);
8468 btrfs_btree_balance_dirty(root); 8470 btrfs_btree_balance_dirty(root);
8469 8471
8470 trans = btrfs_start_transaction(root, 2); 8472 trans = btrfs_start_transaction(root, 2);
8471 if (IS_ERR(trans)) { 8473 if (IS_ERR(trans)) {
8472 ret = err = PTR_ERR(trans); 8474 ret = err = PTR_ERR(trans);
8473 trans = NULL; 8475 trans = NULL;
8474 break; 8476 break;
8475 } 8477 }
8476 8478
8477 ret = btrfs_block_rsv_migrate(&root->fs_info->trans_block_rsv, 8479 ret = btrfs_block_rsv_migrate(&root->fs_info->trans_block_rsv,
8478 rsv, min_size); 8480 rsv, min_size);
8479 BUG_ON(ret); /* shouldn't happen */ 8481 BUG_ON(ret); /* shouldn't happen */
8480 trans->block_rsv = rsv; 8482 trans->block_rsv = rsv;
8481 } 8483 }
8482 8484
8483 if (ret == 0 && inode->i_nlink > 0) { 8485 if (ret == 0 && inode->i_nlink > 0) {
8484 trans->block_rsv = root->orphan_block_rsv; 8486 trans->block_rsv = root->orphan_block_rsv;
8485 ret = btrfs_orphan_del(trans, inode); 8487 ret = btrfs_orphan_del(trans, inode);
8486 if (ret) 8488 if (ret)
8487 err = ret; 8489 err = ret;
8488 } 8490 }
8489 8491
8490 if (trans) { 8492 if (trans) {
8491 trans->block_rsv = &root->fs_info->trans_block_rsv; 8493 trans->block_rsv = &root->fs_info->trans_block_rsv;
8492 ret = btrfs_update_inode(trans, root, inode); 8494 ret = btrfs_update_inode(trans, root, inode);
8493 if (ret && !err) 8495 if (ret && !err)
8494 err = ret; 8496 err = ret;
8495 8497
8496 ret = btrfs_end_transaction(trans, root); 8498 ret = btrfs_end_transaction(trans, root);
8497 btrfs_btree_balance_dirty(root); 8499 btrfs_btree_balance_dirty(root);
8498 } 8500 }
8499 8501
8500 out: 8502 out:
8501 btrfs_free_block_rsv(root, rsv); 8503 btrfs_free_block_rsv(root, rsv);
8502 8504
8503 if (ret && !err) 8505 if (ret && !err)
8504 err = ret; 8506 err = ret;
8505 8507
8506 return err; 8508 return err;
8507 } 8509 }
8508 8510
8509 /* 8511 /*
8510 * create a new subvolume directory/inode (helper for the ioctl). 8512 * create a new subvolume directory/inode (helper for the ioctl).
8511 */ 8513 */
8512 int btrfs_create_subvol_root(struct btrfs_trans_handle *trans, 8514 int btrfs_create_subvol_root(struct btrfs_trans_handle *trans,
8513 struct btrfs_root *new_root, 8515 struct btrfs_root *new_root,
8514 struct btrfs_root *parent_root, 8516 struct btrfs_root *parent_root,
8515 u64 new_dirid) 8517 u64 new_dirid)
8516 { 8518 {
8517 struct inode *inode; 8519 struct inode *inode;
8518 int err; 8520 int err;
8519 u64 index = 0; 8521 u64 index = 0;
8520 8522
8521 inode = btrfs_new_inode(trans, new_root, NULL, "..", 2, 8523 inode = btrfs_new_inode(trans, new_root, NULL, "..", 2,
8522 new_dirid, new_dirid, 8524 new_dirid, new_dirid,
8523 S_IFDIR | (~current_umask() & S_IRWXUGO), 8525 S_IFDIR | (~current_umask() & S_IRWXUGO),
8524 &index); 8526 &index);
8525 if (IS_ERR(inode)) 8527 if (IS_ERR(inode))
8526 return PTR_ERR(inode); 8528 return PTR_ERR(inode);
8527 inode->i_op = &btrfs_dir_inode_operations; 8529 inode->i_op = &btrfs_dir_inode_operations;
8528 inode->i_fop = &btrfs_dir_file_operations; 8530 inode->i_fop = &btrfs_dir_file_operations;
8529 8531
8530 set_nlink(inode, 1); 8532 set_nlink(inode, 1);
8531 btrfs_i_size_write(inode, 0); 8533 btrfs_i_size_write(inode, 0);
8532 unlock_new_inode(inode); 8534 unlock_new_inode(inode);
8533 8535
8534 err = btrfs_subvol_inherit_props(trans, new_root, parent_root); 8536 err = btrfs_subvol_inherit_props(trans, new_root, parent_root);
8535 if (err) 8537 if (err)
8536 btrfs_err(new_root->fs_info, 8538 btrfs_err(new_root->fs_info,
8537 "error inheriting subvolume %llu properties: %d", 8539 "error inheriting subvolume %llu properties: %d",
8538 new_root->root_key.objectid, err); 8540 new_root->root_key.objectid, err);
8539 8541
8540 err = btrfs_update_inode(trans, new_root, inode); 8542 err = btrfs_update_inode(trans, new_root, inode);
8541 8543
8542 iput(inode); 8544 iput(inode);
8543 return err; 8545 return err;
8544 } 8546 }
8545 8547
8546 struct inode *btrfs_alloc_inode(struct super_block *sb) 8548 struct inode *btrfs_alloc_inode(struct super_block *sb)
8547 { 8549 {
8548 struct btrfs_inode *ei; 8550 struct btrfs_inode *ei;
8549 struct inode *inode; 8551 struct inode *inode;
8550 8552
8551 ei = kmem_cache_alloc(btrfs_inode_cachep, GFP_NOFS); 8553 ei = kmem_cache_alloc(btrfs_inode_cachep, GFP_NOFS);
8552 if (!ei) 8554 if (!ei)
8553 return NULL; 8555 return NULL;
8554 8556
8555 ei->root = NULL; 8557 ei->root = NULL;
8556 ei->generation = 0; 8558 ei->generation = 0;
8557 ei->last_trans = 0; 8559 ei->last_trans = 0;
8558 ei->last_sub_trans = 0; 8560 ei->last_sub_trans = 0;
8559 ei->logged_trans = 0; 8561 ei->logged_trans = 0;
8560 ei->delalloc_bytes = 0; 8562 ei->delalloc_bytes = 0;
8561 ei->defrag_bytes = 0; 8563 ei->defrag_bytes = 0;
8562 ei->disk_i_size = 0; 8564 ei->disk_i_size = 0;
8563 ei->flags = 0; 8565 ei->flags = 0;
8564 ei->csum_bytes = 0; 8566 ei->csum_bytes = 0;
8565 ei->index_cnt = (u64)-1; 8567 ei->index_cnt = (u64)-1;
8566 ei->dir_index = 0; 8568 ei->dir_index = 0;
8567 ei->last_unlink_trans = 0; 8569 ei->last_unlink_trans = 0;
8568 ei->last_log_commit = 0; 8570 ei->last_log_commit = 0;
8569 8571
8570 spin_lock_init(&ei->lock); 8572 spin_lock_init(&ei->lock);
8571 ei->outstanding_extents = 0; 8573 ei->outstanding_extents = 0;
8572 ei->reserved_extents = 0; 8574 ei->reserved_extents = 0;
8573 8575
8574 ei->runtime_flags = 0; 8576 ei->runtime_flags = 0;
8575 ei->force_compress = BTRFS_COMPRESS_NONE; 8577 ei->force_compress = BTRFS_COMPRESS_NONE;
8576 8578
8577 ei->delayed_node = NULL; 8579 ei->delayed_node = NULL;
8578 8580
8579 inode = &ei->vfs_inode; 8581 inode = &ei->vfs_inode;
8580 extent_map_tree_init(&ei->extent_tree); 8582 extent_map_tree_init(&ei->extent_tree);
8581 extent_io_tree_init(&ei->io_tree, &inode->i_data); 8583 extent_io_tree_init(&ei->io_tree, &inode->i_data);
8582 extent_io_tree_init(&ei->io_failure_tree, &inode->i_data); 8584 extent_io_tree_init(&ei->io_failure_tree, &inode->i_data);
8583 ei->io_tree.track_uptodate = 1; 8585 ei->io_tree.track_uptodate = 1;
8584 ei->io_failure_tree.track_uptodate = 1; 8586 ei->io_failure_tree.track_uptodate = 1;
8585 atomic_set(&ei->sync_writers, 0); 8587 atomic_set(&ei->sync_writers, 0);
8586 mutex_init(&ei->log_mutex); 8588 mutex_init(&ei->log_mutex);
8587 mutex_init(&ei->delalloc_mutex); 8589 mutex_init(&ei->delalloc_mutex);
8588 btrfs_ordered_inode_tree_init(&ei->ordered_tree); 8590 btrfs_ordered_inode_tree_init(&ei->ordered_tree);
8589 INIT_LIST_HEAD(&ei->delalloc_inodes); 8591 INIT_LIST_HEAD(&ei->delalloc_inodes);
8590 RB_CLEAR_NODE(&ei->rb_node); 8592 RB_CLEAR_NODE(&ei->rb_node);
8591 8593
8592 return inode; 8594 return inode;
8593 } 8595 }
8594 8596
8595 #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS 8597 #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
8596 void btrfs_test_destroy_inode(struct inode *inode) 8598 void btrfs_test_destroy_inode(struct inode *inode)
8597 { 8599 {
8598 btrfs_drop_extent_cache(inode, 0, (u64)-1, 0); 8600 btrfs_drop_extent_cache(inode, 0, (u64)-1, 0);
8599 kmem_cache_free(btrfs_inode_cachep, BTRFS_I(inode)); 8601 kmem_cache_free(btrfs_inode_cachep, BTRFS_I(inode));
8600 } 8602 }
8601 #endif 8603 #endif
8602 8604
8603 static void btrfs_i_callback(struct rcu_head *head) 8605 static void btrfs_i_callback(struct rcu_head *head)
8604 { 8606 {
8605 struct inode *inode = container_of(head, struct inode, i_rcu); 8607 struct inode *inode = container_of(head, struct inode, i_rcu);
8606 kmem_cache_free(btrfs_inode_cachep, BTRFS_I(inode)); 8608 kmem_cache_free(btrfs_inode_cachep, BTRFS_I(inode));
8607 } 8609 }
8608 8610
8609 void btrfs_destroy_inode(struct inode *inode) 8611 void btrfs_destroy_inode(struct inode *inode)
8610 { 8612 {
8611 struct btrfs_ordered_extent *ordered; 8613 struct btrfs_ordered_extent *ordered;
8612 struct btrfs_root *root = BTRFS_I(inode)->root; 8614 struct btrfs_root *root = BTRFS_I(inode)->root;
8613 8615
8614 WARN_ON(!hlist_empty(&inode->i_dentry)); 8616 WARN_ON(!hlist_empty(&inode->i_dentry));
8615 WARN_ON(inode->i_data.nrpages); 8617 WARN_ON(inode->i_data.nrpages);
8616 WARN_ON(BTRFS_I(inode)->outstanding_extents); 8618 WARN_ON(BTRFS_I(inode)->outstanding_extents);
8617 WARN_ON(BTRFS_I(inode)->reserved_extents); 8619 WARN_ON(BTRFS_I(inode)->reserved_extents);
8618 WARN_ON(BTRFS_I(inode)->delalloc_bytes); 8620 WARN_ON(BTRFS_I(inode)->delalloc_bytes);
8619 WARN_ON(BTRFS_I(inode)->csum_bytes); 8621 WARN_ON(BTRFS_I(inode)->csum_bytes);
8620 WARN_ON(BTRFS_I(inode)->defrag_bytes); 8622 WARN_ON(BTRFS_I(inode)->defrag_bytes);
8621 8623
8622 /* 8624 /*
8623 * This can happen where we create an inode, but somebody else also 8625 * This can happen where we create an inode, but somebody else also
8624 * created the same inode and we need to destroy the one we already 8626 * created the same inode and we need to destroy the one we already
8625 * created. 8627 * created.
8626 */ 8628 */
8627 if (!root) 8629 if (!root)
8628 goto free; 8630 goto free;
8629 8631
8630 if (test_bit(BTRFS_INODE_HAS_ORPHAN_ITEM, 8632 if (test_bit(BTRFS_INODE_HAS_ORPHAN_ITEM,
8631 &BTRFS_I(inode)->runtime_flags)) { 8633 &BTRFS_I(inode)->runtime_flags)) {
8632 btrfs_info(root->fs_info, "inode %llu still on the orphan list", 8634 btrfs_info(root->fs_info, "inode %llu still on the orphan list",
8633 btrfs_ino(inode)); 8635 btrfs_ino(inode));
8634 atomic_dec(&root->orphan_inodes); 8636 atomic_dec(&root->orphan_inodes);
8635 } 8637 }
8636 8638
8637 while (1) { 8639 while (1) {
8638 ordered = btrfs_lookup_first_ordered_extent(inode, (u64)-1); 8640 ordered = btrfs_lookup_first_ordered_extent(inode, (u64)-1);
8639 if (!ordered) 8641 if (!ordered)
8640 break; 8642 break;
8641 else { 8643 else {
8642 btrfs_err(root->fs_info, "found ordered extent %llu %llu on inode cleanup", 8644 btrfs_err(root->fs_info, "found ordered extent %llu %llu on inode cleanup",
8643 ordered->file_offset, ordered->len); 8645 ordered->file_offset, ordered->len);
8644 btrfs_remove_ordered_extent(inode, ordered); 8646 btrfs_remove_ordered_extent(inode, ordered);
8645 btrfs_put_ordered_extent(ordered); 8647 btrfs_put_ordered_extent(ordered);
8646 btrfs_put_ordered_extent(ordered); 8648 btrfs_put_ordered_extent(ordered);
8647 } 8649 }
8648 } 8650 }
8649 inode_tree_del(inode); 8651 inode_tree_del(inode);
8650 btrfs_drop_extent_cache(inode, 0, (u64)-1, 0); 8652 btrfs_drop_extent_cache(inode, 0, (u64)-1, 0);
8651 free: 8653 free:
8652 call_rcu(&inode->i_rcu, btrfs_i_callback); 8654 call_rcu(&inode->i_rcu, btrfs_i_callback);
8653 } 8655 }
8654 8656
8655 int btrfs_drop_inode(struct inode *inode) 8657 int btrfs_drop_inode(struct inode *inode)
8656 { 8658 {
8657 struct btrfs_root *root = BTRFS_I(inode)->root; 8659 struct btrfs_root *root = BTRFS_I(inode)->root;
8658 8660
8659 if (root == NULL) 8661 if (root == NULL)
8660 return 1; 8662 return 1;
8661 8663
8662 /* the snap/subvol tree is on deleting */ 8664 /* the snap/subvol tree is on deleting */
8663 if (btrfs_root_refs(&root->root_item) == 0) 8665 if (btrfs_root_refs(&root->root_item) == 0)
8664 return 1; 8666 return 1;
8665 else 8667 else
8666 return generic_drop_inode(inode); 8668 return generic_drop_inode(inode);
8667 } 8669 }
8668 8670
8669 static void init_once(void *foo) 8671 static void init_once(void *foo)
8670 { 8672 {
8671 struct btrfs_inode *ei = (struct btrfs_inode *) foo; 8673 struct btrfs_inode *ei = (struct btrfs_inode *) foo;
8672 8674
8673 inode_init_once(&ei->vfs_inode); 8675 inode_init_once(&ei->vfs_inode);
8674 } 8676 }
8675 8677
8676 void btrfs_destroy_cachep(void) 8678 void btrfs_destroy_cachep(void)
8677 { 8679 {
8678 /* 8680 /*
8679 * Make sure all delayed rcu free inodes are flushed before we 8681 * Make sure all delayed rcu free inodes are flushed before we
8680 * destroy cache. 8682 * destroy cache.
8681 */ 8683 */
8682 rcu_barrier(); 8684 rcu_barrier();
8683 if (btrfs_inode_cachep) 8685 if (btrfs_inode_cachep)
8684 kmem_cache_destroy(btrfs_inode_cachep); 8686 kmem_cache_destroy(btrfs_inode_cachep);
8685 if (btrfs_trans_handle_cachep) 8687 if (btrfs_trans_handle_cachep)
8686 kmem_cache_destroy(btrfs_trans_handle_cachep); 8688 kmem_cache_destroy(btrfs_trans_handle_cachep);
8687 if (btrfs_transaction_cachep) 8689 if (btrfs_transaction_cachep)
8688 kmem_cache_destroy(btrfs_transaction_cachep); 8690 kmem_cache_destroy(btrfs_transaction_cachep);
8689 if (btrfs_path_cachep) 8691 if (btrfs_path_cachep)
8690 kmem_cache_destroy(btrfs_path_cachep); 8692 kmem_cache_destroy(btrfs_path_cachep);
8691 if (btrfs_free_space_cachep) 8693 if (btrfs_free_space_cachep)
8692 kmem_cache_destroy(btrfs_free_space_cachep); 8694 kmem_cache_destroy(btrfs_free_space_cachep);
8693 if (btrfs_delalloc_work_cachep) 8695 if (btrfs_delalloc_work_cachep)
8694 kmem_cache_destroy(btrfs_delalloc_work_cachep); 8696 kmem_cache_destroy(btrfs_delalloc_work_cachep);
8695 } 8697 }
8696 8698
8697 int btrfs_init_cachep(void) 8699 int btrfs_init_cachep(void)
8698 { 8700 {
8699 btrfs_inode_cachep = kmem_cache_create("btrfs_inode", 8701 btrfs_inode_cachep = kmem_cache_create("btrfs_inode",
8700 sizeof(struct btrfs_inode), 0, 8702 sizeof(struct btrfs_inode), 0,
8701 SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, init_once); 8703 SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, init_once);
8702 if (!btrfs_inode_cachep) 8704 if (!btrfs_inode_cachep)
8703 goto fail; 8705 goto fail;
8704 8706
8705 btrfs_trans_handle_cachep = kmem_cache_create("btrfs_trans_handle", 8707 btrfs_trans_handle_cachep = kmem_cache_create("btrfs_trans_handle",
8706 sizeof(struct btrfs_trans_handle), 0, 8708 sizeof(struct btrfs_trans_handle), 0,
8707 SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL); 8709 SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL);
8708 if (!btrfs_trans_handle_cachep) 8710 if (!btrfs_trans_handle_cachep)
8709 goto fail; 8711 goto fail;
8710 8712
8711 btrfs_transaction_cachep = kmem_cache_create("btrfs_transaction", 8713 btrfs_transaction_cachep = kmem_cache_create("btrfs_transaction",
8712 sizeof(struct btrfs_transaction), 0, 8714 sizeof(struct btrfs_transaction), 0,
8713 SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL); 8715 SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL);
8714 if (!btrfs_transaction_cachep) 8716 if (!btrfs_transaction_cachep)
8715 goto fail; 8717 goto fail;
8716 8718
8717 btrfs_path_cachep = kmem_cache_create("btrfs_path", 8719 btrfs_path_cachep = kmem_cache_create("btrfs_path",
8718 sizeof(struct btrfs_path), 0, 8720 sizeof(struct btrfs_path), 0,
8719 SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL); 8721 SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL);
8720 if (!btrfs_path_cachep) 8722 if (!btrfs_path_cachep)
8721 goto fail; 8723 goto fail;
8722 8724
8723 btrfs_free_space_cachep = kmem_cache_create("btrfs_free_space", 8725 btrfs_free_space_cachep = kmem_cache_create("btrfs_free_space",
8724 sizeof(struct btrfs_free_space), 0, 8726 sizeof(struct btrfs_free_space), 0,
8725 SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL); 8727 SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, NULL);
8726 if (!btrfs_free_space_cachep) 8728 if (!btrfs_free_space_cachep)
8727 goto fail; 8729 goto fail;
8728 8730
8729 btrfs_delalloc_work_cachep = kmem_cache_create("btrfs_delalloc_work", 8731 btrfs_delalloc_work_cachep = kmem_cache_create("btrfs_delalloc_work",
8730 sizeof(struct btrfs_delalloc_work), 0, 8732 sizeof(struct btrfs_delalloc_work), 0,
8731 SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, 8733 SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD,
8732 NULL); 8734 NULL);
8733 if (!btrfs_delalloc_work_cachep) 8735 if (!btrfs_delalloc_work_cachep)
8734 goto fail; 8736 goto fail;
8735 8737
8736 return 0; 8738 return 0;
8737 fail: 8739 fail:
8738 btrfs_destroy_cachep(); 8740 btrfs_destroy_cachep();
8739 return -ENOMEM; 8741 return -ENOMEM;
8740 } 8742 }
8741 8743
8742 static int btrfs_getattr(struct vfsmount *mnt, 8744 static int btrfs_getattr(struct vfsmount *mnt,
8743 struct dentry *dentry, struct kstat *stat) 8745 struct dentry *dentry, struct kstat *stat)
8744 { 8746 {
8745 u64 delalloc_bytes; 8747 u64 delalloc_bytes;
8746 struct inode *inode = dentry->d_inode; 8748 struct inode *inode = dentry->d_inode;
8747 u32 blocksize = inode->i_sb->s_blocksize; 8749 u32 blocksize = inode->i_sb->s_blocksize;
8748 8750
8749 generic_fillattr(inode, stat); 8751 generic_fillattr(inode, stat);
8750 stat->dev = BTRFS_I(inode)->root->anon_dev; 8752 stat->dev = BTRFS_I(inode)->root->anon_dev;
8751 stat->blksize = PAGE_CACHE_SIZE; 8753 stat->blksize = PAGE_CACHE_SIZE;
8752 8754
8753 spin_lock(&BTRFS_I(inode)->lock); 8755 spin_lock(&BTRFS_I(inode)->lock);
8754 delalloc_bytes = BTRFS_I(inode)->delalloc_bytes; 8756 delalloc_bytes = BTRFS_I(inode)->delalloc_bytes;
8755 spin_unlock(&BTRFS_I(inode)->lock); 8757 spin_unlock(&BTRFS_I(inode)->lock);
8756 stat->blocks = (ALIGN(inode_get_bytes(inode), blocksize) + 8758 stat->blocks = (ALIGN(inode_get_bytes(inode), blocksize) +
8757 ALIGN(delalloc_bytes, blocksize)) >> 9; 8759 ALIGN(delalloc_bytes, blocksize)) >> 9;
8758 return 0; 8760 return 0;
8759 } 8761 }
8760 8762
8761 static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry, 8763 static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
8762 struct inode *new_dir, struct dentry *new_dentry) 8764 struct inode *new_dir, struct dentry *new_dentry)
8763 { 8765 {
8764 struct btrfs_trans_handle *trans; 8766 struct btrfs_trans_handle *trans;
8765 struct btrfs_root *root = BTRFS_I(old_dir)->root; 8767 struct btrfs_root *root = BTRFS_I(old_dir)->root;
8766 struct btrfs_root *dest = BTRFS_I(new_dir)->root; 8768 struct btrfs_root *dest = BTRFS_I(new_dir)->root;
8767 struct inode *new_inode = new_dentry->d_inode; 8769 struct inode *new_inode = new_dentry->d_inode;
8768 struct inode *old_inode = old_dentry->d_inode; 8770 struct inode *old_inode = old_dentry->d_inode;
8769 struct timespec ctime = CURRENT_TIME; 8771 struct timespec ctime = CURRENT_TIME;
8770 u64 index = 0; 8772 u64 index = 0;
8771 u64 root_objectid; 8773 u64 root_objectid;
8772 int ret; 8774 int ret;
8773 u64 old_ino = btrfs_ino(old_inode); 8775 u64 old_ino = btrfs_ino(old_inode);
8774 8776
8775 if (btrfs_ino(new_dir) == BTRFS_EMPTY_SUBVOL_DIR_OBJECTID) 8777 if (btrfs_ino(new_dir) == BTRFS_EMPTY_SUBVOL_DIR_OBJECTID)
8776 return -EPERM; 8778 return -EPERM;
8777 8779
8778 /* we only allow rename subvolume link between subvolumes */ 8780 /* we only allow rename subvolume link between subvolumes */
8779 if (old_ino != BTRFS_FIRST_FREE_OBJECTID && root != dest) 8781 if (old_ino != BTRFS_FIRST_FREE_OBJECTID && root != dest)
8780 return -EXDEV; 8782 return -EXDEV;
8781 8783
8782 if (old_ino == BTRFS_EMPTY_SUBVOL_DIR_OBJECTID || 8784 if (old_ino == BTRFS_EMPTY_SUBVOL_DIR_OBJECTID ||
8783 (new_inode && btrfs_ino(new_inode) == BTRFS_FIRST_FREE_OBJECTID)) 8785 (new_inode && btrfs_ino(new_inode) == BTRFS_FIRST_FREE_OBJECTID))
8784 return -ENOTEMPTY; 8786 return -ENOTEMPTY;
8785 8787
8786 if (S_ISDIR(old_inode->i_mode) && new_inode && 8788 if (S_ISDIR(old_inode->i_mode) && new_inode &&
8787 new_inode->i_size > BTRFS_EMPTY_DIR_SIZE) 8789 new_inode->i_size > BTRFS_EMPTY_DIR_SIZE)
8788 return -ENOTEMPTY; 8790 return -ENOTEMPTY;
8789 8791
8790 8792
8791 /* check for collisions, even if the name isn't there */ 8793 /* check for collisions, even if the name isn't there */
8792 ret = btrfs_check_dir_item_collision(dest, new_dir->i_ino, 8794 ret = btrfs_check_dir_item_collision(dest, new_dir->i_ino,
8793 new_dentry->d_name.name, 8795 new_dentry->d_name.name,
8794 new_dentry->d_name.len); 8796 new_dentry->d_name.len);
8795 8797
8796 if (ret) { 8798 if (ret) {
8797 if (ret == -EEXIST) { 8799 if (ret == -EEXIST) {
8798 /* we shouldn't get 8800 /* we shouldn't get
8799 * eexist without a new_inode */ 8801 * eexist without a new_inode */
8800 if (WARN_ON(!new_inode)) { 8802 if (WARN_ON(!new_inode)) {
8801 return ret; 8803 return ret;
8802 } 8804 }
8803 } else { 8805 } else {
8804 /* maybe -EOVERFLOW */ 8806 /* maybe -EOVERFLOW */
8805 return ret; 8807 return ret;
8806 } 8808 }
8807 } 8809 }
8808 ret = 0; 8810 ret = 0;
8809 8811
8810 /* 8812 /*
8811 * we're using rename to replace one file with another. Start IO on it 8813 * we're using rename to replace one file with another. Start IO on it
8812 * now so we don't add too much work to the end of the transaction 8814 * now so we don't add too much work to the end of the transaction
8813 */ 8815 */
8814 if (new_inode && S_ISREG(old_inode->i_mode) && new_inode->i_size) 8816 if (new_inode && S_ISREG(old_inode->i_mode) && new_inode->i_size)
8815 filemap_flush(old_inode->i_mapping); 8817 filemap_flush(old_inode->i_mapping);
8816 8818
8817 /* close the racy window with snapshot create/destroy ioctl */ 8819 /* close the racy window with snapshot create/destroy ioctl */
8818 if (old_ino == BTRFS_FIRST_FREE_OBJECTID) 8820 if (old_ino == BTRFS_FIRST_FREE_OBJECTID)
8819 down_read(&root->fs_info->subvol_sem); 8821 down_read(&root->fs_info->subvol_sem);
8820 /* 8822 /*
8821 * We want to reserve the absolute worst case amount of items. So if 8823 * We want to reserve the absolute worst case amount of items. So if
8822 * both inodes are subvols and we need to unlink them then that would 8824 * both inodes are subvols and we need to unlink them then that would
8823 * require 4 item modifications, but if they are both normal inodes it 8825 * require 4 item modifications, but if they are both normal inodes it
8824 * would require 5 item modifications, so we'll assume their normal 8826 * would require 5 item modifications, so we'll assume their normal
8825 * inodes. So 5 * 2 is 10, plus 1 for the new link, so 11 total items 8827 * inodes. So 5 * 2 is 10, plus 1 for the new link, so 11 total items
8826 * should cover the worst case number of items we'll modify. 8828 * should cover the worst case number of items we'll modify.
8827 */ 8829 */
8828 trans = btrfs_start_transaction(root, 11); 8830 trans = btrfs_start_transaction(root, 11);
8829 if (IS_ERR(trans)) { 8831 if (IS_ERR(trans)) {
8830 ret = PTR_ERR(trans); 8832 ret = PTR_ERR(trans);
8831 goto out_notrans; 8833 goto out_notrans;
8832 } 8834 }
8833 8835
8834 if (dest != root) 8836 if (dest != root)
8835 btrfs_record_root_in_trans(trans, dest); 8837 btrfs_record_root_in_trans(trans, dest);
8836 8838
8837 ret = btrfs_set_inode_index(new_dir, &index); 8839 ret = btrfs_set_inode_index(new_dir, &index);
8838 if (ret) 8840 if (ret)
8839 goto out_fail; 8841 goto out_fail;
8840 8842
8841 BTRFS_I(old_inode)->dir_index = 0ULL; 8843 BTRFS_I(old_inode)->dir_index = 0ULL;
8842 if (unlikely(old_ino == BTRFS_FIRST_FREE_OBJECTID)) { 8844 if (unlikely(old_ino == BTRFS_FIRST_FREE_OBJECTID)) {
8843 /* force full log commit if subvolume involved. */ 8845 /* force full log commit if subvolume involved. */
8844 btrfs_set_log_full_commit(root->fs_info, trans); 8846 btrfs_set_log_full_commit(root->fs_info, trans);
8845 } else { 8847 } else {
8846 ret = btrfs_insert_inode_ref(trans, dest, 8848 ret = btrfs_insert_inode_ref(trans, dest,
8847 new_dentry->d_name.name, 8849 new_dentry->d_name.name,
8848 new_dentry->d_name.len, 8850 new_dentry->d_name.len,
8849 old_ino, 8851 old_ino,
8850 btrfs_ino(new_dir), index); 8852 btrfs_ino(new_dir), index);
8851 if (ret) 8853 if (ret)
8852 goto out_fail; 8854 goto out_fail;
8853 /* 8855 /*
8854 * this is an ugly little race, but the rename is required 8856 * this is an ugly little race, but the rename is required
8855 * to make sure that if we crash, the inode is either at the 8857 * to make sure that if we crash, the inode is either at the
8856 * old name or the new one. pinning the log transaction lets 8858 * old name or the new one. pinning the log transaction lets
8857 * us make sure we don't allow a log commit to come in after 8859 * us make sure we don't allow a log commit to come in after
8858 * we unlink the name but before we add the new name back in. 8860 * we unlink the name but before we add the new name back in.
8859 */ 8861 */
8860 btrfs_pin_log_trans(root); 8862 btrfs_pin_log_trans(root);
8861 } 8863 }
8862 8864
8863 inode_inc_iversion(old_dir); 8865 inode_inc_iversion(old_dir);
8864 inode_inc_iversion(new_dir); 8866 inode_inc_iversion(new_dir);
8865 inode_inc_iversion(old_inode); 8867 inode_inc_iversion(old_inode);
8866 old_dir->i_ctime = old_dir->i_mtime = ctime; 8868 old_dir->i_ctime = old_dir->i_mtime = ctime;
8867 new_dir->i_ctime = new_dir->i_mtime = ctime; 8869 new_dir->i_ctime = new_dir->i_mtime = ctime;
8868 old_inode->i_ctime = ctime; 8870 old_inode->i_ctime = ctime;
8869 8871
8870 if (old_dentry->d_parent != new_dentry->d_parent) 8872 if (old_dentry->d_parent != new_dentry->d_parent)
8871 btrfs_record_unlink_dir(trans, old_dir, old_inode, 1); 8873 btrfs_record_unlink_dir(trans, old_dir, old_inode, 1);
8872 8874
8873 if (unlikely(old_ino == BTRFS_FIRST_FREE_OBJECTID)) { 8875 if (unlikely(old_ino == BTRFS_FIRST_FREE_OBJECTID)) {
8874 root_objectid = BTRFS_I(old_inode)->root->root_key.objectid; 8876 root_objectid = BTRFS_I(old_inode)->root->root_key.objectid;
8875 ret = btrfs_unlink_subvol(trans, root, old_dir, root_objectid, 8877 ret = btrfs_unlink_subvol(trans, root, old_dir, root_objectid,
8876 old_dentry->d_name.name, 8878 old_dentry->d_name.name,
8877 old_dentry->d_name.len); 8879 old_dentry->d_name.len);
8878 } else { 8880 } else {
8879 ret = __btrfs_unlink_inode(trans, root, old_dir, 8881 ret = __btrfs_unlink_inode(trans, root, old_dir,
8880 old_dentry->d_inode, 8882 old_dentry->d_inode,
8881 old_dentry->d_name.name, 8883 old_dentry->d_name.name,
8882 old_dentry->d_name.len); 8884 old_dentry->d_name.len);
8883 if (!ret) 8885 if (!ret)
8884 ret = btrfs_update_inode(trans, root, old_inode); 8886 ret = btrfs_update_inode(trans, root, old_inode);
8885 } 8887 }
8886 if (ret) { 8888 if (ret) {
8887 btrfs_abort_transaction(trans, root, ret); 8889 btrfs_abort_transaction(trans, root, ret);
8888 goto out_fail; 8890 goto out_fail;
8889 } 8891 }
8890 8892
8891 if (new_inode) { 8893 if (new_inode) {
8892 inode_inc_iversion(new_inode); 8894 inode_inc_iversion(new_inode);
8893 new_inode->i_ctime = CURRENT_TIME; 8895 new_inode->i_ctime = CURRENT_TIME;
8894 if (unlikely(btrfs_ino(new_inode) == 8896 if (unlikely(btrfs_ino(new_inode) ==
8895 BTRFS_EMPTY_SUBVOL_DIR_OBJECTID)) { 8897 BTRFS_EMPTY_SUBVOL_DIR_OBJECTID)) {
8896 root_objectid = BTRFS_I(new_inode)->location.objectid; 8898 root_objectid = BTRFS_I(new_inode)->location.objectid;
8897 ret = btrfs_unlink_subvol(trans, dest, new_dir, 8899 ret = btrfs_unlink_subvol(trans, dest, new_dir,
8898 root_objectid, 8900 root_objectid,
8899 new_dentry->d_name.name, 8901 new_dentry->d_name.name,
8900 new_dentry->d_name.len); 8902 new_dentry->d_name.len);
8901 BUG_ON(new_inode->i_nlink == 0); 8903 BUG_ON(new_inode->i_nlink == 0);
8902 } else { 8904 } else {
8903 ret = btrfs_unlink_inode(trans, dest, new_dir, 8905 ret = btrfs_unlink_inode(trans, dest, new_dir,
8904 new_dentry->d_inode, 8906 new_dentry->d_inode,
8905 new_dentry->d_name.name, 8907 new_dentry->d_name.name,
8906 new_dentry->d_name.len); 8908 new_dentry->d_name.len);
8907 } 8909 }
8908 if (!ret && new_inode->i_nlink == 0) 8910 if (!ret && new_inode->i_nlink == 0)
8909 ret = btrfs_orphan_add(trans, new_dentry->d_inode); 8911 ret = btrfs_orphan_add(trans, new_dentry->d_inode);
8910 if (ret) { 8912 if (ret) {
8911 btrfs_abort_transaction(trans, root, ret); 8913 btrfs_abort_transaction(trans, root, ret);
8912 goto out_fail; 8914 goto out_fail;
8913 } 8915 }
8914 } 8916 }
8915 8917
8916 ret = btrfs_add_link(trans, new_dir, old_inode, 8918 ret = btrfs_add_link(trans, new_dir, old_inode,
8917 new_dentry->d_name.name, 8919 new_dentry->d_name.name,
8918 new_dentry->d_name.len, 0, index); 8920 new_dentry->d_name.len, 0, index);
8919 if (ret) { 8921 if (ret) {
8920 btrfs_abort_transaction(trans, root, ret); 8922 btrfs_abort_transaction(trans, root, ret);
8921 goto out_fail; 8923 goto out_fail;
8922 } 8924 }
8923 8925
8924 if (old_inode->i_nlink == 1) 8926 if (old_inode->i_nlink == 1)
8925 BTRFS_I(old_inode)->dir_index = index; 8927 BTRFS_I(old_inode)->dir_index = index;
8926 8928
8927 if (old_ino != BTRFS_FIRST_FREE_OBJECTID) { 8929 if (old_ino != BTRFS_FIRST_FREE_OBJECTID) {
8928 struct dentry *parent = new_dentry->d_parent; 8930 struct dentry *parent = new_dentry->d_parent;
8929 btrfs_log_new_name(trans, old_inode, old_dir, parent); 8931 btrfs_log_new_name(trans, old_inode, old_dir, parent);
8930 btrfs_end_log_trans(root); 8932 btrfs_end_log_trans(root);
8931 } 8933 }
8932 out_fail: 8934 out_fail:
8933 btrfs_end_transaction(trans, root); 8935 btrfs_end_transaction(trans, root);
8934 out_notrans: 8936 out_notrans:
8935 if (old_ino == BTRFS_FIRST_FREE_OBJECTID) 8937 if (old_ino == BTRFS_FIRST_FREE_OBJECTID)
8936 up_read(&root->fs_info->subvol_sem); 8938 up_read(&root->fs_info->subvol_sem);
8937 8939
8938 return ret; 8940 return ret;
8939 } 8941 }
8940 8942
8941 static int btrfs_rename2(struct inode *old_dir, struct dentry *old_dentry, 8943 static int btrfs_rename2(struct inode *old_dir, struct dentry *old_dentry,
8942 struct inode *new_dir, struct dentry *new_dentry, 8944 struct inode *new_dir, struct dentry *new_dentry,
8943 unsigned int flags) 8945 unsigned int flags)
8944 { 8946 {
8945 if (flags & ~RENAME_NOREPLACE) 8947 if (flags & ~RENAME_NOREPLACE)
8946 return -EINVAL; 8948 return -EINVAL;
8947 8949
8948 return btrfs_rename(old_dir, old_dentry, new_dir, new_dentry); 8950 return btrfs_rename(old_dir, old_dentry, new_dir, new_dentry);
8949 } 8951 }
8950 8952
8951 static void btrfs_run_delalloc_work(struct btrfs_work *work) 8953 static void btrfs_run_delalloc_work(struct btrfs_work *work)
8952 { 8954 {
8953 struct btrfs_delalloc_work *delalloc_work; 8955 struct btrfs_delalloc_work *delalloc_work;
8954 struct inode *inode; 8956 struct inode *inode;
8955 8957
8956 delalloc_work = container_of(work, struct btrfs_delalloc_work, 8958 delalloc_work = container_of(work, struct btrfs_delalloc_work,
8957 work); 8959 work);
8958 inode = delalloc_work->inode; 8960 inode = delalloc_work->inode;
8959 if (delalloc_work->wait) { 8961 if (delalloc_work->wait) {
8960 btrfs_wait_ordered_range(inode, 0, (u64)-1); 8962 btrfs_wait_ordered_range(inode, 0, (u64)-1);
8961 } else { 8963 } else {
8962 filemap_flush(inode->i_mapping); 8964 filemap_flush(inode->i_mapping);
8963 if (test_bit(BTRFS_INODE_HAS_ASYNC_EXTENT, 8965 if (test_bit(BTRFS_INODE_HAS_ASYNC_EXTENT,
8964 &BTRFS_I(inode)->runtime_flags)) 8966 &BTRFS_I(inode)->runtime_flags))
8965 filemap_flush(inode->i_mapping); 8967 filemap_flush(inode->i_mapping);
8966 } 8968 }
8967 8969
8968 if (delalloc_work->delay_iput) 8970 if (delalloc_work->delay_iput)
8969 btrfs_add_delayed_iput(inode); 8971 btrfs_add_delayed_iput(inode);
8970 else 8972 else
8971 iput(inode); 8973 iput(inode);
8972 complete(&delalloc_work->completion); 8974 complete(&delalloc_work->completion);
8973 } 8975 }
8974 8976
8975 struct btrfs_delalloc_work *btrfs_alloc_delalloc_work(struct inode *inode, 8977 struct btrfs_delalloc_work *btrfs_alloc_delalloc_work(struct inode *inode,
8976 int wait, int delay_iput) 8978 int wait, int delay_iput)
8977 { 8979 {
8978 struct btrfs_delalloc_work *work; 8980 struct btrfs_delalloc_work *work;
8979 8981
8980 work = kmem_cache_zalloc(btrfs_delalloc_work_cachep, GFP_NOFS); 8982 work = kmem_cache_zalloc(btrfs_delalloc_work_cachep, GFP_NOFS);
8981 if (!work) 8983 if (!work)
8982 return NULL; 8984 return NULL;
8983 8985
8984 init_completion(&work->completion); 8986 init_completion(&work->completion);
8985 INIT_LIST_HEAD(&work->list); 8987 INIT_LIST_HEAD(&work->list);
8986 work->inode = inode; 8988 work->inode = inode;
8987 work->wait = wait; 8989 work->wait = wait;
8988 work->delay_iput = delay_iput; 8990 work->delay_iput = delay_iput;
8989 WARN_ON_ONCE(!inode); 8991 WARN_ON_ONCE(!inode);
8990 btrfs_init_work(&work->work, btrfs_flush_delalloc_helper, 8992 btrfs_init_work(&work->work, btrfs_flush_delalloc_helper,
8991 btrfs_run_delalloc_work, NULL, NULL); 8993 btrfs_run_delalloc_work, NULL, NULL);
8992 8994
8993 return work; 8995 return work;
8994 } 8996 }
8995 8997
8996 void btrfs_wait_and_free_delalloc_work(struct btrfs_delalloc_work *work) 8998 void btrfs_wait_and_free_delalloc_work(struct btrfs_delalloc_work *work)
8997 { 8999 {
8998 wait_for_completion(&work->completion); 9000 wait_for_completion(&work->completion);
8999 kmem_cache_free(btrfs_delalloc_work_cachep, work); 9001 kmem_cache_free(btrfs_delalloc_work_cachep, work);
9000 } 9002 }
9001 9003
9002 /* 9004 /*
9003 * some fairly slow code that needs optimization. This walks the list 9005 * some fairly slow code that needs optimization. This walks the list
9004 * of all the inodes with pending delalloc and forces them to disk. 9006 * of all the inodes with pending delalloc and forces them to disk.
9005 */ 9007 */
9006 static int __start_delalloc_inodes(struct btrfs_root *root, int delay_iput, 9008 static int __start_delalloc_inodes(struct btrfs_root *root, int delay_iput,
9007 int nr) 9009 int nr)
9008 { 9010 {
9009 struct btrfs_inode *binode; 9011 struct btrfs_inode *binode;
9010 struct inode *inode; 9012 struct inode *inode;
9011 struct btrfs_delalloc_work *work, *next; 9013 struct btrfs_delalloc_work *work, *next;
9012 struct list_head works; 9014 struct list_head works;
9013 struct list_head splice; 9015 struct list_head splice;
9014 int ret = 0; 9016 int ret = 0;
9015 9017
9016 INIT_LIST_HEAD(&works); 9018 INIT_LIST_HEAD(&works);
9017 INIT_LIST_HEAD(&splice); 9019 INIT_LIST_HEAD(&splice);
9018 9020
9019 mutex_lock(&root->delalloc_mutex); 9021 mutex_lock(&root->delalloc_mutex);
9020 spin_lock(&root->delalloc_lock); 9022 spin_lock(&root->delalloc_lock);
9021 list_splice_init(&root->delalloc_inodes, &splice); 9023 list_splice_init(&root->delalloc_inodes, &splice);
9022 while (!list_empty(&splice)) { 9024 while (!list_empty(&splice)) {
9023 binode = list_entry(splice.next, struct btrfs_inode, 9025 binode = list_entry(splice.next, struct btrfs_inode,
9024 delalloc_inodes); 9026 delalloc_inodes);
9025 9027
9026 list_move_tail(&binode->delalloc_inodes, 9028 list_move_tail(&binode->delalloc_inodes,
9027 &root->delalloc_inodes); 9029 &root->delalloc_inodes);
9028 inode = igrab(&binode->vfs_inode); 9030 inode = igrab(&binode->vfs_inode);
9029 if (!inode) { 9031 if (!inode) {
9030 cond_resched_lock(&root->delalloc_lock); 9032 cond_resched_lock(&root->delalloc_lock);
9031 continue; 9033 continue;
9032 } 9034 }
9033 spin_unlock(&root->delalloc_lock); 9035 spin_unlock(&root->delalloc_lock);
9034 9036
9035 work = btrfs_alloc_delalloc_work(inode, 0, delay_iput); 9037 work = btrfs_alloc_delalloc_work(inode, 0, delay_iput);
9036 if (!work) { 9038 if (!work) {
9037 if (delay_iput) 9039 if (delay_iput)
9038 btrfs_add_delayed_iput(inode); 9040 btrfs_add_delayed_iput(inode);
9039 else 9041 else
9040 iput(inode); 9042 iput(inode);
9041 ret = -ENOMEM; 9043 ret = -ENOMEM;
9042 goto out; 9044 goto out;
9043 } 9045 }
9044 list_add_tail(&work->list, &works); 9046 list_add_tail(&work->list, &works);
9045 btrfs_queue_work(root->fs_info->flush_workers, 9047 btrfs_queue_work(root->fs_info->flush_workers,
9046 &work->work); 9048 &work->work);
9047 ret++; 9049 ret++;
9048 if (nr != -1 && ret >= nr) 9050 if (nr != -1 && ret >= nr)
9049 goto out; 9051 goto out;
9050 cond_resched(); 9052 cond_resched();
9051 spin_lock(&root->delalloc_lock); 9053 spin_lock(&root->delalloc_lock);
9052 } 9054 }
9053 spin_unlock(&root->delalloc_lock); 9055 spin_unlock(&root->delalloc_lock);
9054 9056
9055 out: 9057 out:
9056 list_for_each_entry_safe(work, next, &works, list) { 9058 list_for_each_entry_safe(work, next, &works, list) {
9057 list_del_init(&work->list); 9059 list_del_init(&work->list);
9058 btrfs_wait_and_free_delalloc_work(work); 9060 btrfs_wait_and_free_delalloc_work(work);
9059 } 9061 }
9060 9062
9061 if (!list_empty_careful(&splice)) { 9063 if (!list_empty_careful(&splice)) {
9062 spin_lock(&root->delalloc_lock); 9064 spin_lock(&root->delalloc_lock);
9063 list_splice_tail(&splice, &root->delalloc_inodes); 9065 list_splice_tail(&splice, &root->delalloc_inodes);
9064 spin_unlock(&root->delalloc_lock); 9066 spin_unlock(&root->delalloc_lock);
9065 } 9067 }
9066 mutex_unlock(&root->delalloc_mutex); 9068 mutex_unlock(&root->delalloc_mutex);
9067 return ret; 9069 return ret;
9068 } 9070 }
9069 9071
9070 int btrfs_start_delalloc_inodes(struct btrfs_root *root, int delay_iput) 9072 int btrfs_start_delalloc_inodes(struct btrfs_root *root, int delay_iput)
9071 { 9073 {
9072 int ret; 9074 int ret;
9073 9075
9074 if (test_bit(BTRFS_FS_STATE_ERROR, &root->fs_info->fs_state)) 9076 if (test_bit(BTRFS_FS_STATE_ERROR, &root->fs_info->fs_state))
9075 return -EROFS; 9077 return -EROFS;
9076 9078
9077 ret = __start_delalloc_inodes(root, delay_iput, -1); 9079 ret = __start_delalloc_inodes(root, delay_iput, -1);
9078 if (ret > 0) 9080 if (ret > 0)
9079 ret = 0; 9081 ret = 0;
9080 /* 9082 /*
9081 * the filemap_flush will queue IO into the worker threads, but 9083 * the filemap_flush will queue IO into the worker threads, but
9082 * we have to make sure the IO is actually started and that 9084 * we have to make sure the IO is actually started and that
9083 * ordered extents get created before we return 9085 * ordered extents get created before we return
9084 */ 9086 */
9085 atomic_inc(&root->fs_info->async_submit_draining); 9087 atomic_inc(&root->fs_info->async_submit_draining);
9086 while (atomic_read(&root->fs_info->nr_async_submits) || 9088 while (atomic_read(&root->fs_info->nr_async_submits) ||
9087 atomic_read(&root->fs_info->async_delalloc_pages)) { 9089 atomic_read(&root->fs_info->async_delalloc_pages)) {
9088 wait_event(root->fs_info->async_submit_wait, 9090 wait_event(root->fs_info->async_submit_wait,
9089 (atomic_read(&root->fs_info->nr_async_submits) == 0 && 9091 (atomic_read(&root->fs_info->nr_async_submits) == 0 &&
9090 atomic_read(&root->fs_info->async_delalloc_pages) == 0)); 9092 atomic_read(&root->fs_info->async_delalloc_pages) == 0));
9091 } 9093 }
9092 atomic_dec(&root->fs_info->async_submit_draining); 9094 atomic_dec(&root->fs_info->async_submit_draining);
9093 return ret; 9095 return ret;
9094 } 9096 }
9095 9097
9096 int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, int delay_iput, 9098 int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, int delay_iput,
9097 int nr) 9099 int nr)
9098 { 9100 {
9099 struct btrfs_root *root; 9101 struct btrfs_root *root;
9100 struct list_head splice; 9102 struct list_head splice;
9101 int ret; 9103 int ret;
9102 9104
9103 if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) 9105 if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state))
9104 return -EROFS; 9106 return -EROFS;
9105 9107
9106 INIT_LIST_HEAD(&splice); 9108 INIT_LIST_HEAD(&splice);
9107 9109
9108 mutex_lock(&fs_info->delalloc_root_mutex); 9110 mutex_lock(&fs_info->delalloc_root_mutex);
9109 spin_lock(&fs_info->delalloc_root_lock); 9111 spin_lock(&fs_info->delalloc_root_lock);
9110 list_splice_init(&fs_info->delalloc_roots, &splice); 9112 list_splice_init(&fs_info->delalloc_roots, &splice);
9111 while (!list_empty(&splice) && nr) { 9113 while (!list_empty(&splice) && nr) {
9112 root = list_first_entry(&splice, struct btrfs_root, 9114 root = list_first_entry(&splice, struct btrfs_root,
9113 delalloc_root); 9115 delalloc_root);
9114 root = btrfs_grab_fs_root(root); 9116 root = btrfs_grab_fs_root(root);
9115 BUG_ON(!root); 9117 BUG_ON(!root);
9116 list_move_tail(&root->delalloc_root, 9118 list_move_tail(&root->delalloc_root,
9117 &fs_info->delalloc_roots); 9119 &fs_info->delalloc_roots);
9118 spin_unlock(&fs_info->delalloc_root_lock); 9120 spin_unlock(&fs_info->delalloc_root_lock);
9119 9121
9120 ret = __start_delalloc_inodes(root, delay_iput, nr); 9122 ret = __start_delalloc_inodes(root, delay_iput, nr);
9121 btrfs_put_fs_root(root); 9123 btrfs_put_fs_root(root);
9122 if (ret < 0) 9124 if (ret < 0)
9123 goto out; 9125 goto out;
9124 9126
9125 if (nr != -1) { 9127 if (nr != -1) {
9126 nr -= ret; 9128 nr -= ret;
9127 WARN_ON(nr < 0); 9129 WARN_ON(nr < 0);
9128 } 9130 }
9129 spin_lock(&fs_info->delalloc_root_lock); 9131 spin_lock(&fs_info->delalloc_root_lock);
9130 } 9132 }
9131 spin_unlock(&fs_info->delalloc_root_lock); 9133 spin_unlock(&fs_info->delalloc_root_lock);
9132 9134
9133 ret = 0; 9135 ret = 0;
9134 atomic_inc(&fs_info->async_submit_draining); 9136 atomic_inc(&fs_info->async_submit_draining);
9135 while (atomic_read(&fs_info->nr_async_submits) || 9137 while (atomic_read(&fs_info->nr_async_submits) ||
9136 atomic_read(&fs_info->async_delalloc_pages)) { 9138 atomic_read(&fs_info->async_delalloc_pages)) {
9137 wait_event(fs_info->async_submit_wait, 9139 wait_event(fs_info->async_submit_wait,
9138 (atomic_read(&fs_info->nr_async_submits) == 0 && 9140 (atomic_read(&fs_info->nr_async_submits) == 0 &&
9139 atomic_read(&fs_info->async_delalloc_pages) == 0)); 9141 atomic_read(&fs_info->async_delalloc_pages) == 0));
9140 } 9142 }
9141 atomic_dec(&fs_info->async_submit_draining); 9143 atomic_dec(&fs_info->async_submit_draining);
9142 out: 9144 out:
9143 if (!list_empty_careful(&splice)) { 9145 if (!list_empty_careful(&splice)) {
9144 spin_lock(&fs_info->delalloc_root_lock); 9146 spin_lock(&fs_info->delalloc_root_lock);
9145 list_splice_tail(&splice, &fs_info->delalloc_roots); 9147 list_splice_tail(&splice, &fs_info->delalloc_roots);
9146 spin_unlock(&fs_info->delalloc_root_lock); 9148 spin_unlock(&fs_info->delalloc_root_lock);
9147 } 9149 }
9148 mutex_unlock(&fs_info->delalloc_root_mutex); 9150 mutex_unlock(&fs_info->delalloc_root_mutex);
9149 return ret; 9151 return ret;
9150 } 9152 }
9151 9153
9152 static int btrfs_symlink(struct inode *dir, struct dentry *dentry, 9154 static int btrfs_symlink(struct inode *dir, struct dentry *dentry,
9153 const char *symname) 9155 const char *symname)
9154 { 9156 {
9155 struct btrfs_trans_handle *trans; 9157 struct btrfs_trans_handle *trans;
9156 struct btrfs_root *root = BTRFS_I(dir)->root; 9158 struct btrfs_root *root = BTRFS_I(dir)->root;
9157 struct btrfs_path *path; 9159 struct btrfs_path *path;
9158 struct btrfs_key key; 9160 struct btrfs_key key;
9159 struct inode *inode = NULL; 9161 struct inode *inode = NULL;
9160 int err; 9162 int err;
9161 int drop_inode = 0; 9163 int drop_inode = 0;
9162 u64 objectid; 9164 u64 objectid;
9163 u64 index = 0; 9165 u64 index = 0;
9164 int name_len; 9166 int name_len;
9165 int datasize; 9167 int datasize;
9166 unsigned long ptr; 9168 unsigned long ptr;
9167 struct btrfs_file_extent_item *ei; 9169 struct btrfs_file_extent_item *ei;
9168 struct extent_buffer *leaf; 9170 struct extent_buffer *leaf;
9169 9171
9170 name_len = strlen(symname); 9172 name_len = strlen(symname);
9171 if (name_len > BTRFS_MAX_INLINE_DATA_SIZE(root)) 9173 if (name_len > BTRFS_MAX_INLINE_DATA_SIZE(root))
9172 return -ENAMETOOLONG; 9174 return -ENAMETOOLONG;
9173 9175
9174 /* 9176 /*
9175 * 2 items for inode item and ref 9177 * 2 items for inode item and ref
9176 * 2 items for dir items 9178 * 2 items for dir items
9177 * 1 item for xattr if selinux is on 9179 * 1 item for xattr if selinux is on
9178 */ 9180 */
9179 trans = btrfs_start_transaction(root, 5); 9181 trans = btrfs_start_transaction(root, 5);
9180 if (IS_ERR(trans)) 9182 if (IS_ERR(trans))
9181 return PTR_ERR(trans); 9183 return PTR_ERR(trans);
9182 9184
9183 err = btrfs_find_free_ino(root, &objectid); 9185 err = btrfs_find_free_ino(root, &objectid);
9184 if (err) 9186 if (err)
9185 goto out_unlock; 9187 goto out_unlock;
9186 9188
9187 inode = btrfs_new_inode(trans, root, dir, dentry->d_name.name, 9189 inode = btrfs_new_inode(trans, root, dir, dentry->d_name.name,
9188 dentry->d_name.len, btrfs_ino(dir), objectid, 9190 dentry->d_name.len, btrfs_ino(dir), objectid,
9189 S_IFLNK|S_IRWXUGO, &index); 9191 S_IFLNK|S_IRWXUGO, &index);
9190 if (IS_ERR(inode)) { 9192 if (IS_ERR(inode)) {
9191 err = PTR_ERR(inode); 9193 err = PTR_ERR(inode);
9192 goto out_unlock; 9194 goto out_unlock;
9193 } 9195 }
9194 9196
9195 /* 9197 /*
9196 * If the active LSM wants to access the inode during 9198 * If the active LSM wants to access the inode during
9197 * d_instantiate it needs these. Smack checks to see 9199 * d_instantiate it needs these. Smack checks to see
9198 * if the filesystem supports xattrs by looking at the 9200 * if the filesystem supports xattrs by looking at the
9199 * ops vector. 9201 * ops vector.
9200 */ 9202 */
9201 inode->i_fop = &btrfs_file_operations; 9203 inode->i_fop = &btrfs_file_operations;
9202 inode->i_op = &btrfs_file_inode_operations; 9204 inode->i_op = &btrfs_file_inode_operations;
9203 inode->i_mapping->a_ops = &btrfs_aops; 9205 inode->i_mapping->a_ops = &btrfs_aops;
9204 inode->i_mapping->backing_dev_info = &root->fs_info->bdi; 9206 inode->i_mapping->backing_dev_info = &root->fs_info->bdi;
9205 BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops; 9207 BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops;
9206 9208
9207 err = btrfs_init_inode_security(trans, inode, dir, &dentry->d_name); 9209 err = btrfs_init_inode_security(trans, inode, dir, &dentry->d_name);
9208 if (err) 9210 if (err)
9209 goto out_unlock_inode; 9211 goto out_unlock_inode;
9210 9212
9211 err = btrfs_add_nondir(trans, dir, dentry, inode, 0, index); 9213 err = btrfs_add_nondir(trans, dir, dentry, inode, 0, index);
9212 if (err) 9214 if (err)
9213 goto out_unlock_inode; 9215 goto out_unlock_inode;
9214 9216
9215 path = btrfs_alloc_path(); 9217 path = btrfs_alloc_path();
9216 if (!path) { 9218 if (!path) {
9217 err = -ENOMEM; 9219 err = -ENOMEM;
9218 goto out_unlock_inode; 9220 goto out_unlock_inode;
9219 } 9221 }
9220 key.objectid = btrfs_ino(inode); 9222 key.objectid = btrfs_ino(inode);
9221 key.offset = 0; 9223 key.offset = 0;
9222 key.type = BTRFS_EXTENT_DATA_KEY; 9224 key.type = BTRFS_EXTENT_DATA_KEY;
9223 datasize = btrfs_file_extent_calc_inline_size(name_len); 9225 datasize = btrfs_file_extent_calc_inline_size(name_len);
9224 err = btrfs_insert_empty_item(trans, root, path, &key, 9226 err = btrfs_insert_empty_item(trans, root, path, &key,
9225 datasize); 9227 datasize);
9226 if (err) { 9228 if (err) {
9227 btrfs_free_path(path); 9229 btrfs_free_path(path);
9228 goto out_unlock_inode; 9230 goto out_unlock_inode;
9229 } 9231 }
9230 leaf = path->nodes[0]; 9232 leaf = path->nodes[0];
9231 ei = btrfs_item_ptr(leaf, path->slots[0], 9233 ei = btrfs_item_ptr(leaf, path->slots[0],
9232 struct btrfs_file_extent_item); 9234 struct btrfs_file_extent_item);
9233 btrfs_set_file_extent_generation(leaf, ei, trans->transid); 9235 btrfs_set_file_extent_generation(leaf, ei, trans->transid);
9234 btrfs_set_file_extent_type(leaf, ei, 9236 btrfs_set_file_extent_type(leaf, ei,
9235 BTRFS_FILE_EXTENT_INLINE); 9237 BTRFS_FILE_EXTENT_INLINE);
9236 btrfs_set_file_extent_encryption(leaf, ei, 0); 9238 btrfs_set_file_extent_encryption(leaf, ei, 0);
9237 btrfs_set_file_extent_compression(leaf, ei, 0); 9239 btrfs_set_file_extent_compression(leaf, ei, 0);
9238 btrfs_set_file_extent_other_encoding(leaf, ei, 0); 9240 btrfs_set_file_extent_other_encoding(leaf, ei, 0);
9239 btrfs_set_file_extent_ram_bytes(leaf, ei, name_len); 9241 btrfs_set_file_extent_ram_bytes(leaf, ei, name_len);
9240 9242
9241 ptr = btrfs_file_extent_inline_start(ei); 9243 ptr = btrfs_file_extent_inline_start(ei);
9242 write_extent_buffer(leaf, symname, ptr, name_len); 9244 write_extent_buffer(leaf, symname, ptr, name_len);
9243 btrfs_mark_buffer_dirty(leaf); 9245 btrfs_mark_buffer_dirty(leaf);
9244 btrfs_free_path(path); 9246 btrfs_free_path(path);
9245 9247
9246 inode->i_op = &btrfs_symlink_inode_operations; 9248 inode->i_op = &btrfs_symlink_inode_operations;
9247 inode->i_mapping->a_ops = &btrfs_symlink_aops; 9249 inode->i_mapping->a_ops = &btrfs_symlink_aops;
9248 inode->i_mapping->backing_dev_info = &root->fs_info->bdi; 9250 inode->i_mapping->backing_dev_info = &root->fs_info->bdi;
9249 inode_set_bytes(inode, name_len); 9251 inode_set_bytes(inode, name_len);
9250 btrfs_i_size_write(inode, name_len); 9252 btrfs_i_size_write(inode, name_len);
9251 err = btrfs_update_inode(trans, root, inode); 9253 err = btrfs_update_inode(trans, root, inode);
9252 if (err) { 9254 if (err) {
9253 drop_inode = 1; 9255 drop_inode = 1;
9254 goto out_unlock_inode; 9256 goto out_unlock_inode;
9255 } 9257 }
9256 9258
9257 unlock_new_inode(inode); 9259 unlock_new_inode(inode);
9258 d_instantiate(dentry, inode); 9260 d_instantiate(dentry, inode);
9259 9261
9260 out_unlock: 9262 out_unlock:
9261 btrfs_end_transaction(trans, root); 9263 btrfs_end_transaction(trans, root);
9262 if (drop_inode) { 9264 if (drop_inode) {
9263 inode_dec_link_count(inode); 9265 inode_dec_link_count(inode);
9264 iput(inode); 9266 iput(inode);
9265 } 9267 }
9266 btrfs_btree_balance_dirty(root); 9268 btrfs_btree_balance_dirty(root);
9267 return err; 9269 return err;
9268 9270
9269 out_unlock_inode: 9271 out_unlock_inode:
9270 drop_inode = 1; 9272 drop_inode = 1;
9271 unlock_new_inode(inode); 9273 unlock_new_inode(inode);
9272 goto out_unlock; 9274 goto out_unlock;
9273 } 9275 }
9274 9276
9275 static int __btrfs_prealloc_file_range(struct inode *inode, int mode, 9277 static int __btrfs_prealloc_file_range(struct inode *inode, int mode,
9276 u64 start, u64 num_bytes, u64 min_size, 9278 u64 start, u64 num_bytes, u64 min_size,
9277 loff_t actual_len, u64 *alloc_hint, 9279 loff_t actual_len, u64 *alloc_hint,
9278 struct btrfs_trans_handle *trans) 9280 struct btrfs_trans_handle *trans)
9279 { 9281 {
9280 struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; 9282 struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree;
9281 struct extent_map *em; 9283 struct extent_map *em;
9282 struct btrfs_root *root = BTRFS_I(inode)->root; 9284 struct btrfs_root *root = BTRFS_I(inode)->root;
9283 struct btrfs_key ins; 9285 struct btrfs_key ins;
9284 u64 cur_offset = start; 9286 u64 cur_offset = start;
9285 u64 i_size; 9287 u64 i_size;
9286 u64 cur_bytes; 9288 u64 cur_bytes;
9287 int ret = 0; 9289 int ret = 0;
9288 bool own_trans = true; 9290 bool own_trans = true;
9289 9291
9290 if (trans) 9292 if (trans)
9291 own_trans = false; 9293 own_trans = false;
9292 while (num_bytes > 0) { 9294 while (num_bytes > 0) {
9293 if (own_trans) { 9295 if (own_trans) {
9294 trans = btrfs_start_transaction(root, 3); 9296 trans = btrfs_start_transaction(root, 3);
9295 if (IS_ERR(trans)) { 9297 if (IS_ERR(trans)) {
9296 ret = PTR_ERR(trans); 9298 ret = PTR_ERR(trans);
9297 break; 9299 break;
9298 } 9300 }
9299 } 9301 }
9300 9302
9301 cur_bytes = min(num_bytes, 256ULL * 1024 * 1024); 9303 cur_bytes = min(num_bytes, 256ULL * 1024 * 1024);
9302 cur_bytes = max(cur_bytes, min_size); 9304 cur_bytes = max(cur_bytes, min_size);
9303 ret = btrfs_reserve_extent(root, cur_bytes, min_size, 0, 9305 ret = btrfs_reserve_extent(root, cur_bytes, min_size, 0,
9304 *alloc_hint, &ins, 1, 0); 9306 *alloc_hint, &ins, 1, 0);
9305 if (ret) { 9307 if (ret) {
9306 if (own_trans) 9308 if (own_trans)
9307 btrfs_end_transaction(trans, root); 9309 btrfs_end_transaction(trans, root);
9308 break; 9310 break;
9309 } 9311 }
9310 9312
9311 ret = insert_reserved_file_extent(trans, inode, 9313 ret = insert_reserved_file_extent(trans, inode,
9312 cur_offset, ins.objectid, 9314 cur_offset, ins.objectid,
9313 ins.offset, ins.offset, 9315 ins.offset, ins.offset,
9314 ins.offset, 0, 0, 0, 9316 ins.offset, 0, 0, 0,
9315 BTRFS_FILE_EXTENT_PREALLOC); 9317 BTRFS_FILE_EXTENT_PREALLOC);
9316 if (ret) { 9318 if (ret) {
9317 btrfs_free_reserved_extent(root, ins.objectid, 9319 btrfs_free_reserved_extent(root, ins.objectid,
9318 ins.offset, 0); 9320 ins.offset, 0);
9319 btrfs_abort_transaction(trans, root, ret); 9321 btrfs_abort_transaction(trans, root, ret);
9320 if (own_trans) 9322 if (own_trans)
9321 btrfs_end_transaction(trans, root); 9323 btrfs_end_transaction(trans, root);
9322 break; 9324 break;
9323 } 9325 }
9324 btrfs_drop_extent_cache(inode, cur_offset, 9326 btrfs_drop_extent_cache(inode, cur_offset,
9325 cur_offset + ins.offset -1, 0); 9327 cur_offset + ins.offset -1, 0);
9326 9328
9327 em = alloc_extent_map(); 9329 em = alloc_extent_map();
9328 if (!em) { 9330 if (!em) {
9329 set_bit(BTRFS_INODE_NEEDS_FULL_SYNC, 9331 set_bit(BTRFS_INODE_NEEDS_FULL_SYNC,
9330 &BTRFS_I(inode)->runtime_flags); 9332 &BTRFS_I(inode)->runtime_flags);
9331 goto next; 9333 goto next;
9332 } 9334 }
9333 9335
9334 em->start = cur_offset; 9336 em->start = cur_offset;
9335 em->orig_start = cur_offset; 9337 em->orig_start = cur_offset;
9336 em->len = ins.offset; 9338 em->len = ins.offset;
9337 em->block_start = ins.objectid; 9339 em->block_start = ins.objectid;
9338 em->block_len = ins.offset; 9340 em->block_len = ins.offset;
9339 em->orig_block_len = ins.offset; 9341 em->orig_block_len = ins.offset;
9340 em->ram_bytes = ins.offset; 9342 em->ram_bytes = ins.offset;
9341 em->bdev = root->fs_info->fs_devices->latest_bdev; 9343 em->bdev = root->fs_info->fs_devices->latest_bdev;
9342 set_bit(EXTENT_FLAG_PREALLOC, &em->flags); 9344 set_bit(EXTENT_FLAG_PREALLOC, &em->flags);
9343 em->generation = trans->transid; 9345 em->generation = trans->transid;
9344 9346
9345 while (1) { 9347 while (1) {
9346 write_lock(&em_tree->lock); 9348 write_lock(&em_tree->lock);
9347 ret = add_extent_mapping(em_tree, em, 1); 9349 ret = add_extent_mapping(em_tree, em, 1);
9348 write_unlock(&em_tree->lock); 9350 write_unlock(&em_tree->lock);
9349 if (ret != -EEXIST) 9351 if (ret != -EEXIST)
9350 break; 9352 break;
9351 btrfs_drop_extent_cache(inode, cur_offset, 9353 btrfs_drop_extent_cache(inode, cur_offset,
9352 cur_offset + ins.offset - 1, 9354 cur_offset + ins.offset - 1,
9353 0); 9355 0);
9354 } 9356 }
9355 free_extent_map(em); 9357 free_extent_map(em);
9356 next: 9358 next:
9357 num_bytes -= ins.offset; 9359 num_bytes -= ins.offset;
9358 cur_offset += ins.offset; 9360 cur_offset += ins.offset;
9359 *alloc_hint = ins.objectid + ins.offset; 9361 *alloc_hint = ins.objectid + ins.offset;
9360 9362
9361 inode_inc_iversion(inode); 9363 inode_inc_iversion(inode);
9362 inode->i_ctime = CURRENT_TIME; 9364 inode->i_ctime = CURRENT_TIME;
9363 BTRFS_I(inode)->flags |= BTRFS_INODE_PREALLOC; 9365 BTRFS_I(inode)->flags |= BTRFS_INODE_PREALLOC;
9364 if (!(mode & FALLOC_FL_KEEP_SIZE) && 9366 if (!(mode & FALLOC_FL_KEEP_SIZE) &&
9365 (actual_len > inode->i_size) && 9367 (actual_len > inode->i_size) &&
9366 (cur_offset > inode->i_size)) { 9368 (cur_offset > inode->i_size)) {
9367 if (cur_offset > actual_len) 9369 if (cur_offset > actual_len)
9368 i_size = actual_len; 9370 i_size = actual_len;
9369 else 9371 else
9370 i_size = cur_offset; 9372 i_size = cur_offset;
9371 i_size_write(inode, i_size); 9373 i_size_write(inode, i_size);
9372 btrfs_ordered_update_i_size(inode, i_size, NULL); 9374 btrfs_ordered_update_i_size(inode, i_size, NULL);
9373 } 9375 }
9374 9376
9375 ret = btrfs_update_inode(trans, root, inode); 9377 ret = btrfs_update_inode(trans, root, inode);
9376 9378
9377 if (ret) { 9379 if (ret) {
9378 btrfs_abort_transaction(trans, root, ret); 9380 btrfs_abort_transaction(trans, root, ret);
9379 if (own_trans) 9381 if (own_trans)
9380 btrfs_end_transaction(trans, root); 9382 btrfs_end_transaction(trans, root);
9381 break; 9383 break;
9382 } 9384 }
9383 9385
9384 if (own_trans) 9386 if (own_trans)
9385 btrfs_end_transaction(trans, root); 9387 btrfs_end_transaction(trans, root);
9386 } 9388 }
9387 return ret; 9389 return ret;
9388 } 9390 }
9389 9391
9390 int btrfs_prealloc_file_range(struct inode *inode, int mode, 9392 int btrfs_prealloc_file_range(struct inode *inode, int mode,
9391 u64 start, u64 num_bytes, u64 min_size, 9393 u64 start, u64 num_bytes, u64 min_size,
9392 loff_t actual_len, u64 *alloc_hint) 9394 loff_t actual_len, u64 *alloc_hint)
9393 { 9395 {
9394 return __btrfs_prealloc_file_range(inode, mode, start, num_bytes, 9396 return __btrfs_prealloc_file_range(inode, mode, start, num_bytes,
9395 min_size, actual_len, alloc_hint, 9397 min_size, actual_len, alloc_hint,
9396 NULL); 9398 NULL);
9397 } 9399 }
9398 9400
9399 int btrfs_prealloc_file_range_trans(struct inode *inode, 9401 int btrfs_prealloc_file_range_trans(struct inode *inode,
9400 struct btrfs_trans_handle *trans, int mode, 9402 struct btrfs_trans_handle *trans, int mode,
9401 u64 start, u64 num_bytes, u64 min_size, 9403 u64 start, u64 num_bytes, u64 min_size,
9402 loff_t actual_len, u64 *alloc_hint) 9404 loff_t actual_len, u64 *alloc_hint)
9403 { 9405 {
9404 return __btrfs_prealloc_file_range(inode, mode, start, num_bytes, 9406 return __btrfs_prealloc_file_range(inode, mode, start, num_bytes,
9405 min_size, actual_len, alloc_hint, trans); 9407 min_size, actual_len, alloc_hint, trans);
9406 } 9408 }
9407 9409
9408 static int btrfs_set_page_dirty(struct page *page) 9410 static int btrfs_set_page_dirty(struct page *page)
9409 { 9411 {
9410 return __set_page_dirty_nobuffers(page); 9412 return __set_page_dirty_nobuffers(page);
9411 } 9413 }
9412 9414
9413 static int btrfs_permission(struct inode *inode, int mask) 9415 static int btrfs_permission(struct inode *inode, int mask)
9414 { 9416 {
9415 struct btrfs_root *root = BTRFS_I(inode)->root; 9417 struct btrfs_root *root = BTRFS_I(inode)->root;
9416 umode_t mode = inode->i_mode; 9418 umode_t mode = inode->i_mode;
9417 9419
9418 if (mask & MAY_WRITE && 9420 if (mask & MAY_WRITE &&
9419 (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))) { 9421 (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))) {
9420 if (btrfs_root_readonly(root)) 9422 if (btrfs_root_readonly(root))
9421 return -EROFS; 9423 return -EROFS;
9422 if (BTRFS_I(inode)->flags & BTRFS_INODE_READONLY) 9424 if (BTRFS_I(inode)->flags & BTRFS_INODE_READONLY)
9423 return -EACCES; 9425 return -EACCES;
9424 } 9426 }
9425 return generic_permission(inode, mask); 9427 return generic_permission(inode, mask);
9426 } 9428 }
9427 9429
9428 static int btrfs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode) 9430 static int btrfs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
9429 { 9431 {
9430 struct btrfs_trans_handle *trans; 9432 struct btrfs_trans_handle *trans;
9431 struct btrfs_root *root = BTRFS_I(dir)->root; 9433 struct btrfs_root *root = BTRFS_I(dir)->root;
9432 struct inode *inode = NULL; 9434 struct inode *inode = NULL;
9433 u64 objectid; 9435 u64 objectid;
9434 u64 index; 9436 u64 index;
9435 int ret = 0; 9437 int ret = 0;
9436 9438
9437 /* 9439 /*
9438 * 5 units required for adding orphan entry 9440 * 5 units required for adding orphan entry
9439 */ 9441 */
9440 trans = btrfs_start_transaction(root, 5); 9442 trans = btrfs_start_transaction(root, 5);
9441 if (IS_ERR(trans)) 9443 if (IS_ERR(trans))
9442 return PTR_ERR(trans); 9444 return PTR_ERR(trans);
9443 9445
9444 ret = btrfs_find_free_ino(root, &objectid); 9446 ret = btrfs_find_free_ino(root, &objectid);
9445 if (ret) 9447 if (ret)
9446 goto out; 9448 goto out;
9447 9449
9448 inode = btrfs_new_inode(trans, root, dir, NULL, 0, 9450 inode = btrfs_new_inode(trans, root, dir, NULL, 0,
9449 btrfs_ino(dir), objectid, mode, &index); 9451 btrfs_ino(dir), objectid, mode, &index);
9450 if (IS_ERR(inode)) { 9452 if (IS_ERR(inode)) {
9451 ret = PTR_ERR(inode); 9453 ret = PTR_ERR(inode);
9452 inode = NULL; 9454 inode = NULL;
9453 goto out; 9455 goto out;
9454 } 9456 }
9455 9457
9456 inode->i_fop = &btrfs_file_operations; 9458 inode->i_fop = &btrfs_file_operations;
9457 inode->i_op = &btrfs_file_inode_operations; 9459 inode->i_op = &btrfs_file_inode_operations;
9458 9460
9459 inode->i_mapping->a_ops = &btrfs_aops; 9461 inode->i_mapping->a_ops = &btrfs_aops;
9460 inode->i_mapping->backing_dev_info = &root->fs_info->bdi; 9462 inode->i_mapping->backing_dev_info = &root->fs_info->bdi;
9461 BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops; 9463 BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops;
9462 9464
9463 ret = btrfs_init_inode_security(trans, inode, dir, NULL); 9465 ret = btrfs_init_inode_security(trans, inode, dir, NULL);
9464 if (ret) 9466 if (ret)
9465 goto out_inode; 9467 goto out_inode;
9466 9468
9467 ret = btrfs_update_inode(trans, root, inode); 9469 ret = btrfs_update_inode(trans, root, inode);
9468 if (ret) 9470 if (ret)
9469 goto out_inode; 9471 goto out_inode;
9470 ret = btrfs_orphan_add(trans, inode); 9472 ret = btrfs_orphan_add(trans, inode);
9471 if (ret) 9473 if (ret)
9472 goto out_inode; 9474 goto out_inode;
9473 9475
9474 /* 9476 /*
9475 * We set number of links to 0 in btrfs_new_inode(), and here we set 9477 * We set number of links to 0 in btrfs_new_inode(), and here we set
9476 * it to 1 because d_tmpfile() will issue a warning if the count is 0, 9478 * it to 1 because d_tmpfile() will issue a warning if the count is 0,
9477 * through: 9479 * through:
9478 * 9480 *
9479 * d_tmpfile() -> inode_dec_link_count() -> drop_nlink() 9481 * d_tmpfile() -> inode_dec_link_count() -> drop_nlink()
9480 */ 9482 */
9481 set_nlink(inode, 1); 9483 set_nlink(inode, 1);
9482 unlock_new_inode(inode); 9484 unlock_new_inode(inode);
9483 d_tmpfile(dentry, inode); 9485 d_tmpfile(dentry, inode);
9484 mark_inode_dirty(inode); 9486 mark_inode_dirty(inode);
9485 9487
9486 out: 9488 out:
9487 btrfs_end_transaction(trans, root); 9489 btrfs_end_transaction(trans, root);
9488 if (ret) 9490 if (ret)
9489 iput(inode); 9491 iput(inode);
9490 btrfs_balance_delayed_items(root); 9492 btrfs_balance_delayed_items(root);
9491 btrfs_btree_balance_dirty(root); 9493 btrfs_btree_balance_dirty(root);
9492 return ret; 9494 return ret;
9493 9495
9494 out_inode: 9496 out_inode:
9495 unlock_new_inode(inode); 9497 unlock_new_inode(inode);
9496 goto out; 9498 goto out;
9497 9499
9498 } 9500 }
9499 9501
9500 /* Inspired by filemap_check_errors() */ 9502 /* Inspired by filemap_check_errors() */
9501 int btrfs_inode_check_errors(struct inode *inode) 9503 int btrfs_inode_check_errors(struct inode *inode)
9502 { 9504 {
9503 int ret = 0; 9505 int ret = 0;
9504 9506
9505 if (test_bit(AS_ENOSPC, &inode->i_mapping->flags) && 9507 if (test_bit(AS_ENOSPC, &inode->i_mapping->flags) &&
9506 test_and_clear_bit(AS_ENOSPC, &inode->i_mapping->flags)) 9508 test_and_clear_bit(AS_ENOSPC, &inode->i_mapping->flags))
9507 ret = -ENOSPC; 9509 ret = -ENOSPC;
9508 if (test_bit(AS_EIO, &inode->i_mapping->flags) && 9510 if (test_bit(AS_EIO, &inode->i_mapping->flags) &&
9509 test_and_clear_bit(AS_EIO, &inode->i_mapping->flags)) 9511 test_and_clear_bit(AS_EIO, &inode->i_mapping->flags))
9510 ret = -EIO; 9512 ret = -EIO;
9511 9513
9512 return ret; 9514 return ret;
9513 } 9515 }
9514 9516
9515 static const struct inode_operations btrfs_dir_inode_operations = { 9517 static const struct inode_operations btrfs_dir_inode_operations = {
9516 .getattr = btrfs_getattr, 9518 .getattr = btrfs_getattr,
9517 .lookup = btrfs_lookup, 9519 .lookup = btrfs_lookup,
9518 .create = btrfs_create, 9520 .create = btrfs_create,
9519 .unlink = btrfs_unlink, 9521 .unlink = btrfs_unlink,
9520 .link = btrfs_link, 9522 .link = btrfs_link,
9521 .mkdir = btrfs_mkdir, 9523 .mkdir = btrfs_mkdir,
9522 .rmdir = btrfs_rmdir, 9524 .rmdir = btrfs_rmdir,
9523 .rename2 = btrfs_rename2, 9525 .rename2 = btrfs_rename2,
9524 .symlink = btrfs_symlink, 9526 .symlink = btrfs_symlink,
9525 .setattr = btrfs_setattr, 9527 .setattr = btrfs_setattr,
9526 .mknod = btrfs_mknod, 9528 .mknod = btrfs_mknod,
9527 .setxattr = btrfs_setxattr, 9529 .setxattr = btrfs_setxattr,
9528 .getxattr = btrfs_getxattr, 9530 .getxattr = btrfs_getxattr,
9529 .listxattr = btrfs_listxattr, 9531 .listxattr = btrfs_listxattr,
9530 .removexattr = btrfs_removexattr, 9532 .removexattr = btrfs_removexattr,
9531 .permission = btrfs_permission, 9533 .permission = btrfs_permission,
9532 .get_acl = btrfs_get_acl, 9534 .get_acl = btrfs_get_acl,
9533 .set_acl = btrfs_set_acl, 9535 .set_acl = btrfs_set_acl,
9534 .update_time = btrfs_update_time, 9536 .update_time = btrfs_update_time,
9535 .tmpfile = btrfs_tmpfile, 9537 .tmpfile = btrfs_tmpfile,
9536 }; 9538 };
9537 static const struct inode_operations btrfs_dir_ro_inode_operations = { 9539 static const struct inode_operations btrfs_dir_ro_inode_operations = {
9538 .lookup = btrfs_lookup, 9540 .lookup = btrfs_lookup,
9539 .permission = btrfs_permission, 9541 .permission = btrfs_permission,
9540 .get_acl = btrfs_get_acl, 9542 .get_acl = btrfs_get_acl,
9541 .set_acl = btrfs_set_acl, 9543 .set_acl = btrfs_set_acl,
9542 .update_time = btrfs_update_time, 9544 .update_time = btrfs_update_time,
9543 }; 9545 };
9544 9546
9545 static const struct file_operations btrfs_dir_file_operations = { 9547 static const struct file_operations btrfs_dir_file_operations = {
9546 .llseek = generic_file_llseek, 9548 .llseek = generic_file_llseek,
9547 .read = generic_read_dir, 9549 .read = generic_read_dir,
9548 .iterate = btrfs_real_readdir, 9550 .iterate = btrfs_real_readdir,
9549 .unlocked_ioctl = btrfs_ioctl, 9551 .unlocked_ioctl = btrfs_ioctl,
9550 #ifdef CONFIG_COMPAT 9552 #ifdef CONFIG_COMPAT
9551 .compat_ioctl = btrfs_ioctl, 9553 .compat_ioctl = btrfs_ioctl,
9552 #endif 9554 #endif
9553 .release = btrfs_release_file, 9555 .release = btrfs_release_file,
9554 .fsync = btrfs_sync_file, 9556 .fsync = btrfs_sync_file,
9555 }; 9557 };
9556 9558
9557 static struct extent_io_ops btrfs_extent_io_ops = { 9559 static struct extent_io_ops btrfs_extent_io_ops = {
9558 .fill_delalloc = run_delalloc_range, 9560 .fill_delalloc = run_delalloc_range,
9559 .submit_bio_hook = btrfs_submit_bio_hook, 9561 .submit_bio_hook = btrfs_submit_bio_hook,
9560 .merge_bio_hook = btrfs_merge_bio_hook, 9562 .merge_bio_hook = btrfs_merge_bio_hook,
9561 .readpage_end_io_hook = btrfs_readpage_end_io_hook, 9563 .readpage_end_io_hook = btrfs_readpage_end_io_hook,
9562 .writepage_end_io_hook = btrfs_writepage_end_io_hook, 9564 .writepage_end_io_hook = btrfs_writepage_end_io_hook,
9563 .writepage_start_hook = btrfs_writepage_start_hook, 9565 .writepage_start_hook = btrfs_writepage_start_hook,
9564 .set_bit_hook = btrfs_set_bit_hook, 9566 .set_bit_hook = btrfs_set_bit_hook,
9565 .clear_bit_hook = btrfs_clear_bit_hook, 9567 .clear_bit_hook = btrfs_clear_bit_hook,
9566 .merge_extent_hook = btrfs_merge_extent_hook, 9568 .merge_extent_hook = btrfs_merge_extent_hook,
9567 .split_extent_hook = btrfs_split_extent_hook, 9569 .split_extent_hook = btrfs_split_extent_hook,
9568 }; 9570 };
9569 9571
9570 /* 9572 /*
9571 * btrfs doesn't support the bmap operation because swapfiles 9573 * btrfs doesn't support the bmap operation because swapfiles
9572 * use bmap to make a mapping of extents in the file. They assume 9574 * use bmap to make a mapping of extents in the file. They assume
9573 * these extents won't change over the life of the file and they 9575 * these extents won't change over the life of the file and they
9574 * use the bmap result to do IO directly to the drive. 9576 * use the bmap result to do IO directly to the drive.
9575 * 9577 *
9576 * the btrfs bmap call would return logical addresses that aren't 9578 * the btrfs bmap call would return logical addresses that aren't
9577 * suitable for IO and they also will change frequently as COW 9579 * suitable for IO and they also will change frequently as COW
9578 * operations happen. So, swapfile + btrfs == corruption. 9580 * operations happen. So, swapfile + btrfs == corruption.
9579 * 9581 *
9580 * For now we're avoiding this by dropping bmap. 9582 * For now we're avoiding this by dropping bmap.
9581 */ 9583 */
9582 static const struct address_space_operations btrfs_aops = { 9584 static const struct address_space_operations btrfs_aops = {
9583 .readpage = btrfs_readpage, 9585 .readpage = btrfs_readpage,
9584 .writepage = btrfs_writepage, 9586 .writepage = btrfs_writepage,
9585 .writepages = btrfs_writepages, 9587 .writepages = btrfs_writepages,
9586 .readpages = btrfs_readpages, 9588 .readpages = btrfs_readpages,
9587 .direct_IO = btrfs_direct_IO, 9589 .direct_IO = btrfs_direct_IO,
9588 .invalidatepage = btrfs_invalidatepage, 9590 .invalidatepage = btrfs_invalidatepage,
9589 .releasepage = btrfs_releasepage, 9591 .releasepage = btrfs_releasepage,
9590 .set_page_dirty = btrfs_set_page_dirty, 9592 .set_page_dirty = btrfs_set_page_dirty,
9591 .error_remove_page = generic_error_remove_page, 9593 .error_remove_page = generic_error_remove_page,
9592 }; 9594 };
9593 9595
9594 static const struct address_space_operations btrfs_symlink_aops = { 9596 static const struct address_space_operations btrfs_symlink_aops = {
9595 .readpage = btrfs_readpage, 9597 .readpage = btrfs_readpage,
9596 .writepage = btrfs_writepage, 9598 .writepage = btrfs_writepage,
9597 .invalidatepage = btrfs_invalidatepage, 9599 .invalidatepage = btrfs_invalidatepage,
9598 .releasepage = btrfs_releasepage, 9600 .releasepage = btrfs_releasepage,
9599 }; 9601 };
9600 9602
9601 static const struct inode_operations btrfs_file_inode_operations = { 9603 static const struct inode_operations btrfs_file_inode_operations = {
9602 .getattr = btrfs_getattr, 9604 .getattr = btrfs_getattr,
9603 .setattr = btrfs_setattr, 9605 .setattr = btrfs_setattr,
9604 .setxattr = btrfs_setxattr, 9606 .setxattr = btrfs_setxattr,
9605 .getxattr = btrfs_getxattr, 9607 .getxattr = btrfs_getxattr,
9606 .listxattr = btrfs_listxattr, 9608 .listxattr = btrfs_listxattr,
9607 .removexattr = btrfs_removexattr, 9609 .removexattr = btrfs_removexattr,
9608 .permission = btrfs_permission, 9610 .permission = btrfs_permission,
9609 .fiemap = btrfs_fiemap, 9611 .fiemap = btrfs_fiemap,
9610 .get_acl = btrfs_get_acl, 9612 .get_acl = btrfs_get_acl,
9611 .set_acl = btrfs_set_acl, 9613 .set_acl = btrfs_set_acl,
9612 .update_time = btrfs_update_time, 9614 .update_time = btrfs_update_time,
9613 }; 9615 };
9614 static const struct inode_operations btrfs_special_inode_operations = { 9616 static const struct inode_operations btrfs_special_inode_operations = {
9615 .getattr = btrfs_getattr, 9617 .getattr = btrfs_getattr,
9616 .setattr = btrfs_setattr, 9618 .setattr = btrfs_setattr,
9617 .permission = btrfs_permission, 9619 .permission = btrfs_permission,
9618 .setxattr = btrfs_setxattr, 9620 .setxattr = btrfs_setxattr,
9619 .getxattr = btrfs_getxattr, 9621 .getxattr = btrfs_getxattr,
9620 .listxattr = btrfs_listxattr, 9622 .listxattr = btrfs_listxattr,
9621 .removexattr = btrfs_removexattr, 9623 .removexattr = btrfs_removexattr,
9622 .get_acl = btrfs_get_acl, 9624 .get_acl = btrfs_get_acl,
9623 .set_acl = btrfs_set_acl, 9625 .set_acl = btrfs_set_acl,
9624 .update_time = btrfs_update_time, 9626 .update_time = btrfs_update_time,
9625 }; 9627 };
9626 static const struct inode_operations btrfs_symlink_inode_operations = { 9628 static const struct inode_operations btrfs_symlink_inode_operations = {
9627 .readlink = generic_readlink, 9629 .readlink = generic_readlink,
9628 .follow_link = page_follow_link_light, 9630 .follow_link = page_follow_link_light,
9629 .put_link = page_put_link, 9631 .put_link = page_put_link,
9630 .getattr = btrfs_getattr, 9632 .getattr = btrfs_getattr,
9631 .setattr = btrfs_setattr, 9633 .setattr = btrfs_setattr,
9632 .permission = btrfs_permission, 9634 .permission = btrfs_permission,
9633 .setxattr = btrfs_setxattr, 9635 .setxattr = btrfs_setxattr,
9634 .getxattr = btrfs_getxattr, 9636 .getxattr = btrfs_getxattr,
9635 .listxattr = btrfs_listxattr, 9637 .listxattr = btrfs_listxattr,
9636 .removexattr = btrfs_removexattr, 9638 .removexattr = btrfs_removexattr,
9637 .update_time = btrfs_update_time, 9639 .update_time = btrfs_update_time,
9638 }; 9640 };
9639 9641
9640 const struct dentry_operations btrfs_dentry_operations = { 9642 const struct dentry_operations btrfs_dentry_operations = {
9641 .d_delete = btrfs_dentry_delete, 9643 .d_delete = btrfs_dentry_delete,
9642 .d_release = btrfs_dentry_release, 9644 .d_release = btrfs_dentry_release,
9643 }; 9645 };
9644 9646
1 /* 1 /*
2 * Copyright (C) 2011, 2012 STRATO. All rights reserved. 2 * Copyright (C) 2011, 2012 STRATO. All rights reserved.
3 * 3 *
4 * This program is free software; you can redistribute it and/or 4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public 5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation. 6 * License v2 as published by the Free Software Foundation.
7 * 7 *
8 * This program is distributed in the hope that it will be useful, 8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details. 11 * General Public License for more details.
12 * 12 *
13 * You should have received a copy of the GNU General Public 13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the 14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 * Boston, MA 021110-1307, USA. 16 * Boston, MA 021110-1307, USA.
17 */ 17 */
18 18
19 #include <linux/blkdev.h> 19 #include <linux/blkdev.h>
20 #include <linux/ratelimit.h> 20 #include <linux/ratelimit.h>
21 #include "ctree.h" 21 #include "ctree.h"
22 #include "volumes.h" 22 #include "volumes.h"
23 #include "disk-io.h" 23 #include "disk-io.h"
24 #include "ordered-data.h" 24 #include "ordered-data.h"
25 #include "transaction.h" 25 #include "transaction.h"
26 #include "backref.h" 26 #include "backref.h"
27 #include "extent_io.h" 27 #include "extent_io.h"
28 #include "dev-replace.h" 28 #include "dev-replace.h"
29 #include "check-integrity.h" 29 #include "check-integrity.h"
30 #include "rcu-string.h" 30 #include "rcu-string.h"
31 #include "raid56.h" 31 #include "raid56.h"
32 32
33 /* 33 /*
34 * This is only the first step towards a full-features scrub. It reads all 34 * This is only the first step towards a full-features scrub. It reads all
35 * extent and super block and verifies the checksums. In case a bad checksum 35 * extent and super block and verifies the checksums. In case a bad checksum
36 * is found or the extent cannot be read, good data will be written back if 36 * is found or the extent cannot be read, good data will be written back if
37 * any can be found. 37 * any can be found.
38 * 38 *
39 * Future enhancements: 39 * Future enhancements:
40 * - In case an unrepairable extent is encountered, track which files are 40 * - In case an unrepairable extent is encountered, track which files are
41 * affected and report them 41 * affected and report them
42 * - track and record media errors, throw out bad devices 42 * - track and record media errors, throw out bad devices
43 * - add a mode to also read unallocated space 43 * - add a mode to also read unallocated space
44 */ 44 */
45 45
46 struct scrub_block; 46 struct scrub_block;
47 struct scrub_ctx; 47 struct scrub_ctx;
48 48
49 /* 49 /*
50 * the following three values only influence the performance. 50 * the following three values only influence the performance.
51 * The last one configures the number of parallel and outstanding I/O 51 * The last one configures the number of parallel and outstanding I/O
52 * operations. The first two values configure an upper limit for the number 52 * operations. The first two values configure an upper limit for the number
53 * of (dynamically allocated) pages that are added to a bio. 53 * of (dynamically allocated) pages that are added to a bio.
54 */ 54 */
55 #define SCRUB_PAGES_PER_RD_BIO 32 /* 128k per bio */ 55 #define SCRUB_PAGES_PER_RD_BIO 32 /* 128k per bio */
56 #define SCRUB_PAGES_PER_WR_BIO 32 /* 128k per bio */ 56 #define SCRUB_PAGES_PER_WR_BIO 32 /* 128k per bio */
57 #define SCRUB_BIOS_PER_SCTX 64 /* 8MB per device in flight */ 57 #define SCRUB_BIOS_PER_SCTX 64 /* 8MB per device in flight */
58 58
59 /* 59 /*
60 * the following value times PAGE_SIZE needs to be large enough to match the 60 * the following value times PAGE_SIZE needs to be large enough to match the
61 * largest node/leaf/sector size that shall be supported. 61 * largest node/leaf/sector size that shall be supported.
62 * Values larger than BTRFS_STRIPE_LEN are not supported. 62 * Values larger than BTRFS_STRIPE_LEN are not supported.
63 */ 63 */
64 #define SCRUB_MAX_PAGES_PER_BLOCK 16 /* 64k per node/leaf/sector */ 64 #define SCRUB_MAX_PAGES_PER_BLOCK 16 /* 64k per node/leaf/sector */
65 65
66 struct scrub_recover { 66 struct scrub_recover {
67 atomic_t refs; 67 atomic_t refs;
68 struct btrfs_bio *bbio; 68 struct btrfs_bio *bbio;
69 u64 *raid_map; 69 u64 *raid_map;
70 u64 map_length; 70 u64 map_length;
71 }; 71 };
72 72
73 struct scrub_page { 73 struct scrub_page {
74 struct scrub_block *sblock; 74 struct scrub_block *sblock;
75 struct page *page; 75 struct page *page;
76 struct btrfs_device *dev; 76 struct btrfs_device *dev;
77 struct list_head list; 77 struct list_head list;
78 u64 flags; /* extent flags */ 78 u64 flags; /* extent flags */
79 u64 generation; 79 u64 generation;
80 u64 logical; 80 u64 logical;
81 u64 physical; 81 u64 physical;
82 u64 physical_for_dev_replace; 82 u64 physical_for_dev_replace;
83 atomic_t ref_count; 83 atomic_t ref_count;
84 struct { 84 struct {
85 unsigned int mirror_num:8; 85 unsigned int mirror_num:8;
86 unsigned int have_csum:1; 86 unsigned int have_csum:1;
87 unsigned int io_error:1; 87 unsigned int io_error:1;
88 }; 88 };
89 u8 csum[BTRFS_CSUM_SIZE]; 89 u8 csum[BTRFS_CSUM_SIZE];
90 90
91 struct scrub_recover *recover; 91 struct scrub_recover *recover;
92 }; 92 };
93 93
94 struct scrub_bio { 94 struct scrub_bio {
95 int index; 95 int index;
96 struct scrub_ctx *sctx; 96 struct scrub_ctx *sctx;
97 struct btrfs_device *dev; 97 struct btrfs_device *dev;
98 struct bio *bio; 98 struct bio *bio;
99 int err; 99 int err;
100 u64 logical; 100 u64 logical;
101 u64 physical; 101 u64 physical;
102 #if SCRUB_PAGES_PER_WR_BIO >= SCRUB_PAGES_PER_RD_BIO 102 #if SCRUB_PAGES_PER_WR_BIO >= SCRUB_PAGES_PER_RD_BIO
103 struct scrub_page *pagev[SCRUB_PAGES_PER_WR_BIO]; 103 struct scrub_page *pagev[SCRUB_PAGES_PER_WR_BIO];
104 #else 104 #else
105 struct scrub_page *pagev[SCRUB_PAGES_PER_RD_BIO]; 105 struct scrub_page *pagev[SCRUB_PAGES_PER_RD_BIO];
106 #endif 106 #endif
107 int page_count; 107 int page_count;
108 int next_free; 108 int next_free;
109 struct btrfs_work work; 109 struct btrfs_work work;
110 }; 110 };
111 111
112 struct scrub_block { 112 struct scrub_block {
113 struct scrub_page *pagev[SCRUB_MAX_PAGES_PER_BLOCK]; 113 struct scrub_page *pagev[SCRUB_MAX_PAGES_PER_BLOCK];
114 int page_count; 114 int page_count;
115 atomic_t outstanding_pages; 115 atomic_t outstanding_pages;
116 atomic_t ref_count; /* free mem on transition to zero */ 116 atomic_t ref_count; /* free mem on transition to zero */
117 struct scrub_ctx *sctx; 117 struct scrub_ctx *sctx;
118 struct scrub_parity *sparity; 118 struct scrub_parity *sparity;
119 struct { 119 struct {
120 unsigned int header_error:1; 120 unsigned int header_error:1;
121 unsigned int checksum_error:1; 121 unsigned int checksum_error:1;
122 unsigned int no_io_error_seen:1; 122 unsigned int no_io_error_seen:1;
123 unsigned int generation_error:1; /* also sets header_error */ 123 unsigned int generation_error:1; /* also sets header_error */
124 124
125 /* The following is for the data used to check parity */ 125 /* The following is for the data used to check parity */
126 /* It is for the data with checksum */ 126 /* It is for the data with checksum */
127 unsigned int data_corrected:1; 127 unsigned int data_corrected:1;
128 }; 128 };
129 }; 129 };
130 130
131 /* Used for the chunks with parity stripe such RAID5/6 */ 131 /* Used for the chunks with parity stripe such RAID5/6 */
132 struct scrub_parity { 132 struct scrub_parity {
133 struct scrub_ctx *sctx; 133 struct scrub_ctx *sctx;
134 134
135 struct btrfs_device *scrub_dev; 135 struct btrfs_device *scrub_dev;
136 136
137 u64 logic_start; 137 u64 logic_start;
138 138
139 u64 logic_end; 139 u64 logic_end;
140 140
141 int nsectors; 141 int nsectors;
142 142
143 int stripe_len; 143 int stripe_len;
144 144
145 atomic_t ref_count; 145 atomic_t ref_count;
146 146
147 struct list_head spages; 147 struct list_head spages;
148 148
149 /* Work of parity check and repair */ 149 /* Work of parity check and repair */
150 struct btrfs_work work; 150 struct btrfs_work work;
151 151
152 /* Mark the parity blocks which have data */ 152 /* Mark the parity blocks which have data */
153 unsigned long *dbitmap; 153 unsigned long *dbitmap;
154 154
155 /* 155 /*
156 * Mark the parity blocks which have data, but errors happen when 156 * Mark the parity blocks which have data, but errors happen when
157 * read data or check data 157 * read data or check data
158 */ 158 */
159 unsigned long *ebitmap; 159 unsigned long *ebitmap;
160 160
161 unsigned long bitmap[0]; 161 unsigned long bitmap[0];
162 }; 162 };
163 163
164 struct scrub_wr_ctx { 164 struct scrub_wr_ctx {
165 struct scrub_bio *wr_curr_bio; 165 struct scrub_bio *wr_curr_bio;
166 struct btrfs_device *tgtdev; 166 struct btrfs_device *tgtdev;
167 int pages_per_wr_bio; /* <= SCRUB_PAGES_PER_WR_BIO */ 167 int pages_per_wr_bio; /* <= SCRUB_PAGES_PER_WR_BIO */
168 atomic_t flush_all_writes; 168 atomic_t flush_all_writes;
169 struct mutex wr_lock; 169 struct mutex wr_lock;
170 }; 170 };
171 171
172 struct scrub_ctx { 172 struct scrub_ctx {
173 struct scrub_bio *bios[SCRUB_BIOS_PER_SCTX]; 173 struct scrub_bio *bios[SCRUB_BIOS_PER_SCTX];
174 struct btrfs_root *dev_root; 174 struct btrfs_root *dev_root;
175 int first_free; 175 int first_free;
176 int curr; 176 int curr;
177 atomic_t bios_in_flight; 177 atomic_t bios_in_flight;
178 atomic_t workers_pending; 178 atomic_t workers_pending;
179 spinlock_t list_lock; 179 spinlock_t list_lock;
180 wait_queue_head_t list_wait; 180 wait_queue_head_t list_wait;
181 u16 csum_size; 181 u16 csum_size;
182 struct list_head csum_list; 182 struct list_head csum_list;
183 atomic_t cancel_req; 183 atomic_t cancel_req;
184 int readonly; 184 int readonly;
185 int pages_per_rd_bio; 185 int pages_per_rd_bio;
186 u32 sectorsize; 186 u32 sectorsize;
187 u32 nodesize; 187 u32 nodesize;
188 188
189 int is_dev_replace; 189 int is_dev_replace;
190 struct scrub_wr_ctx wr_ctx; 190 struct scrub_wr_ctx wr_ctx;
191 191
192 /* 192 /*
193 * statistics 193 * statistics
194 */ 194 */
195 struct btrfs_scrub_progress stat; 195 struct btrfs_scrub_progress stat;
196 spinlock_t stat_lock; 196 spinlock_t stat_lock;
197 }; 197 };
198 198
199 struct scrub_fixup_nodatasum { 199 struct scrub_fixup_nodatasum {
200 struct scrub_ctx *sctx; 200 struct scrub_ctx *sctx;
201 struct btrfs_device *dev; 201 struct btrfs_device *dev;
202 u64 logical; 202 u64 logical;
203 struct btrfs_root *root; 203 struct btrfs_root *root;
204 struct btrfs_work work; 204 struct btrfs_work work;
205 int mirror_num; 205 int mirror_num;
206 }; 206 };
207 207
208 struct scrub_nocow_inode { 208 struct scrub_nocow_inode {
209 u64 inum; 209 u64 inum;
210 u64 offset; 210 u64 offset;
211 u64 root; 211 u64 root;
212 struct list_head list; 212 struct list_head list;
213 }; 213 };
214 214
215 struct scrub_copy_nocow_ctx { 215 struct scrub_copy_nocow_ctx {
216 struct scrub_ctx *sctx; 216 struct scrub_ctx *sctx;
217 u64 logical; 217 u64 logical;
218 u64 len; 218 u64 len;
219 int mirror_num; 219 int mirror_num;
220 u64 physical_for_dev_replace; 220 u64 physical_for_dev_replace;
221 struct list_head inodes; 221 struct list_head inodes;
222 struct btrfs_work work; 222 struct btrfs_work work;
223 }; 223 };
224 224
225 struct scrub_warning { 225 struct scrub_warning {
226 struct btrfs_path *path; 226 struct btrfs_path *path;
227 u64 extent_item_size; 227 u64 extent_item_size;
228 const char *errstr; 228 const char *errstr;
229 sector_t sector; 229 sector_t sector;
230 u64 logical; 230 u64 logical;
231 struct btrfs_device *dev; 231 struct btrfs_device *dev;
232 }; 232 };
233 233
234 static void scrub_pending_bio_inc(struct scrub_ctx *sctx); 234 static void scrub_pending_bio_inc(struct scrub_ctx *sctx);
235 static void scrub_pending_bio_dec(struct scrub_ctx *sctx); 235 static void scrub_pending_bio_dec(struct scrub_ctx *sctx);
236 static void scrub_pending_trans_workers_inc(struct scrub_ctx *sctx); 236 static void scrub_pending_trans_workers_inc(struct scrub_ctx *sctx);
237 static void scrub_pending_trans_workers_dec(struct scrub_ctx *sctx); 237 static void scrub_pending_trans_workers_dec(struct scrub_ctx *sctx);
238 static int scrub_handle_errored_block(struct scrub_block *sblock_to_check); 238 static int scrub_handle_errored_block(struct scrub_block *sblock_to_check);
239 static int scrub_setup_recheck_block(struct scrub_ctx *sctx, 239 static int scrub_setup_recheck_block(struct scrub_ctx *sctx,
240 struct btrfs_fs_info *fs_info, 240 struct btrfs_fs_info *fs_info,
241 struct scrub_block *original_sblock, 241 struct scrub_block *original_sblock,
242 u64 length, u64 logical, 242 u64 length, u64 logical,
243 struct scrub_block *sblocks_for_recheck); 243 struct scrub_block *sblocks_for_recheck);
244 static void scrub_recheck_block(struct btrfs_fs_info *fs_info, 244 static void scrub_recheck_block(struct btrfs_fs_info *fs_info,
245 struct scrub_block *sblock, int is_metadata, 245 struct scrub_block *sblock, int is_metadata,
246 int have_csum, u8 *csum, u64 generation, 246 int have_csum, u8 *csum, u64 generation,
247 u16 csum_size, int retry_failed_mirror); 247 u16 csum_size, int retry_failed_mirror);
248 static void scrub_recheck_block_checksum(struct btrfs_fs_info *fs_info, 248 static void scrub_recheck_block_checksum(struct btrfs_fs_info *fs_info,
249 struct scrub_block *sblock, 249 struct scrub_block *sblock,
250 int is_metadata, int have_csum, 250 int is_metadata, int have_csum,
251 const u8 *csum, u64 generation, 251 const u8 *csum, u64 generation,
252 u16 csum_size); 252 u16 csum_size);
253 static int scrub_repair_block_from_good_copy(struct scrub_block *sblock_bad, 253 static int scrub_repair_block_from_good_copy(struct scrub_block *sblock_bad,
254 struct scrub_block *sblock_good, 254 struct scrub_block *sblock_good,
255 int force_write); 255 int force_write);
256 static int scrub_repair_page_from_good_copy(struct scrub_block *sblock_bad, 256 static int scrub_repair_page_from_good_copy(struct scrub_block *sblock_bad,
257 struct scrub_block *sblock_good, 257 struct scrub_block *sblock_good,
258 int page_num, int force_write); 258 int page_num, int force_write);
259 static void scrub_write_block_to_dev_replace(struct scrub_block *sblock); 259 static void scrub_write_block_to_dev_replace(struct scrub_block *sblock);
260 static int scrub_write_page_to_dev_replace(struct scrub_block *sblock, 260 static int scrub_write_page_to_dev_replace(struct scrub_block *sblock,
261 int page_num); 261 int page_num);
262 static int scrub_checksum_data(struct scrub_block *sblock); 262 static int scrub_checksum_data(struct scrub_block *sblock);
263 static int scrub_checksum_tree_block(struct scrub_block *sblock); 263 static int scrub_checksum_tree_block(struct scrub_block *sblock);
264 static int scrub_checksum_super(struct scrub_block *sblock); 264 static int scrub_checksum_super(struct scrub_block *sblock);
265 static void scrub_block_get(struct scrub_block *sblock); 265 static void scrub_block_get(struct scrub_block *sblock);
266 static void scrub_block_put(struct scrub_block *sblock); 266 static void scrub_block_put(struct scrub_block *sblock);
267 static void scrub_page_get(struct scrub_page *spage); 267 static void scrub_page_get(struct scrub_page *spage);
268 static void scrub_page_put(struct scrub_page *spage); 268 static void scrub_page_put(struct scrub_page *spage);
269 static void scrub_parity_get(struct scrub_parity *sparity); 269 static void scrub_parity_get(struct scrub_parity *sparity);
270 static void scrub_parity_put(struct scrub_parity *sparity); 270 static void scrub_parity_put(struct scrub_parity *sparity);
271 static int scrub_add_page_to_rd_bio(struct scrub_ctx *sctx, 271 static int scrub_add_page_to_rd_bio(struct scrub_ctx *sctx,
272 struct scrub_page *spage); 272 struct scrub_page *spage);
273 static int scrub_pages(struct scrub_ctx *sctx, u64 logical, u64 len, 273 static int scrub_pages(struct scrub_ctx *sctx, u64 logical, u64 len,
274 u64 physical, struct btrfs_device *dev, u64 flags, 274 u64 physical, struct btrfs_device *dev, u64 flags,
275 u64 gen, int mirror_num, u8 *csum, int force, 275 u64 gen, int mirror_num, u8 *csum, int force,
276 u64 physical_for_dev_replace); 276 u64 physical_for_dev_replace);
277 static void scrub_bio_end_io(struct bio *bio, int err); 277 static void scrub_bio_end_io(struct bio *bio, int err);
278 static void scrub_bio_end_io_worker(struct btrfs_work *work); 278 static void scrub_bio_end_io_worker(struct btrfs_work *work);
279 static void scrub_block_complete(struct scrub_block *sblock); 279 static void scrub_block_complete(struct scrub_block *sblock);
280 static void scrub_remap_extent(struct btrfs_fs_info *fs_info, 280 static void scrub_remap_extent(struct btrfs_fs_info *fs_info,
281 u64 extent_logical, u64 extent_len, 281 u64 extent_logical, u64 extent_len,
282 u64 *extent_physical, 282 u64 *extent_physical,
283 struct btrfs_device **extent_dev, 283 struct btrfs_device **extent_dev,
284 int *extent_mirror_num); 284 int *extent_mirror_num);
285 static int scrub_setup_wr_ctx(struct scrub_ctx *sctx, 285 static int scrub_setup_wr_ctx(struct scrub_ctx *sctx,
286 struct scrub_wr_ctx *wr_ctx, 286 struct scrub_wr_ctx *wr_ctx,
287 struct btrfs_fs_info *fs_info, 287 struct btrfs_fs_info *fs_info,
288 struct btrfs_device *dev, 288 struct btrfs_device *dev,
289 int is_dev_replace); 289 int is_dev_replace);
290 static void scrub_free_wr_ctx(struct scrub_wr_ctx *wr_ctx); 290 static void scrub_free_wr_ctx(struct scrub_wr_ctx *wr_ctx);
291 static int scrub_add_page_to_wr_bio(struct scrub_ctx *sctx, 291 static int scrub_add_page_to_wr_bio(struct scrub_ctx *sctx,
292 struct scrub_page *spage); 292 struct scrub_page *spage);
293 static void scrub_wr_submit(struct scrub_ctx *sctx); 293 static void scrub_wr_submit(struct scrub_ctx *sctx);
294 static void scrub_wr_bio_end_io(struct bio *bio, int err); 294 static void scrub_wr_bio_end_io(struct bio *bio, int err);
295 static void scrub_wr_bio_end_io_worker(struct btrfs_work *work); 295 static void scrub_wr_bio_end_io_worker(struct btrfs_work *work);
296 static int write_page_nocow(struct scrub_ctx *sctx, 296 static int write_page_nocow(struct scrub_ctx *sctx,
297 u64 physical_for_dev_replace, struct page *page); 297 u64 physical_for_dev_replace, struct page *page);
298 static int copy_nocow_pages_for_inode(u64 inum, u64 offset, u64 root, 298 static int copy_nocow_pages_for_inode(u64 inum, u64 offset, u64 root,
299 struct scrub_copy_nocow_ctx *ctx); 299 struct scrub_copy_nocow_ctx *ctx);
300 static int copy_nocow_pages(struct scrub_ctx *sctx, u64 logical, u64 len, 300 static int copy_nocow_pages(struct scrub_ctx *sctx, u64 logical, u64 len,
301 int mirror_num, u64 physical_for_dev_replace); 301 int mirror_num, u64 physical_for_dev_replace);
302 static void copy_nocow_pages_worker(struct btrfs_work *work); 302 static void copy_nocow_pages_worker(struct btrfs_work *work);
303 static void __scrub_blocked_if_needed(struct btrfs_fs_info *fs_info); 303 static void __scrub_blocked_if_needed(struct btrfs_fs_info *fs_info);
304 static void scrub_blocked_if_needed(struct btrfs_fs_info *fs_info); 304 static void scrub_blocked_if_needed(struct btrfs_fs_info *fs_info);
305 305
306 306
307 static void scrub_pending_bio_inc(struct scrub_ctx *sctx) 307 static void scrub_pending_bio_inc(struct scrub_ctx *sctx)
308 { 308 {
309 atomic_inc(&sctx->bios_in_flight); 309 atomic_inc(&sctx->bios_in_flight);
310 } 310 }
311 311
312 static void scrub_pending_bio_dec(struct scrub_ctx *sctx) 312 static void scrub_pending_bio_dec(struct scrub_ctx *sctx)
313 { 313 {
314 atomic_dec(&sctx->bios_in_flight); 314 atomic_dec(&sctx->bios_in_flight);
315 wake_up(&sctx->list_wait); 315 wake_up(&sctx->list_wait);
316 } 316 }
317 317
318 static void __scrub_blocked_if_needed(struct btrfs_fs_info *fs_info) 318 static void __scrub_blocked_if_needed(struct btrfs_fs_info *fs_info)
319 { 319 {
320 while (atomic_read(&fs_info->scrub_pause_req)) { 320 while (atomic_read(&fs_info->scrub_pause_req)) {
321 mutex_unlock(&fs_info->scrub_lock); 321 mutex_unlock(&fs_info->scrub_lock);
322 wait_event(fs_info->scrub_pause_wait, 322 wait_event(fs_info->scrub_pause_wait,
323 atomic_read(&fs_info->scrub_pause_req) == 0); 323 atomic_read(&fs_info->scrub_pause_req) == 0);
324 mutex_lock(&fs_info->scrub_lock); 324 mutex_lock(&fs_info->scrub_lock);
325 } 325 }
326 } 326 }
327 327
328 static void scrub_blocked_if_needed(struct btrfs_fs_info *fs_info) 328 static void scrub_blocked_if_needed(struct btrfs_fs_info *fs_info)
329 { 329 {
330 atomic_inc(&fs_info->scrubs_paused); 330 atomic_inc(&fs_info->scrubs_paused);
331 wake_up(&fs_info->scrub_pause_wait); 331 wake_up(&fs_info->scrub_pause_wait);
332 332
333 mutex_lock(&fs_info->scrub_lock); 333 mutex_lock(&fs_info->scrub_lock);
334 __scrub_blocked_if_needed(fs_info); 334 __scrub_blocked_if_needed(fs_info);
335 atomic_dec(&fs_info->scrubs_paused); 335 atomic_dec(&fs_info->scrubs_paused);
336 mutex_unlock(&fs_info->scrub_lock); 336 mutex_unlock(&fs_info->scrub_lock);
337 337
338 wake_up(&fs_info->scrub_pause_wait); 338 wake_up(&fs_info->scrub_pause_wait);
339 } 339 }
340 340
341 /* 341 /*
342 * used for workers that require transaction commits (i.e., for the 342 * used for workers that require transaction commits (i.e., for the
343 * NOCOW case) 343 * NOCOW case)
344 */ 344 */
345 static void scrub_pending_trans_workers_inc(struct scrub_ctx *sctx) 345 static void scrub_pending_trans_workers_inc(struct scrub_ctx *sctx)
346 { 346 {
347 struct btrfs_fs_info *fs_info = sctx->dev_root->fs_info; 347 struct btrfs_fs_info *fs_info = sctx->dev_root->fs_info;
348 348
349 /* 349 /*
350 * increment scrubs_running to prevent cancel requests from 350 * increment scrubs_running to prevent cancel requests from
351 * completing as long as a worker is running. we must also 351 * completing as long as a worker is running. we must also
352 * increment scrubs_paused to prevent deadlocking on pause 352 * increment scrubs_paused to prevent deadlocking on pause
353 * requests used for transactions commits (as the worker uses a 353 * requests used for transactions commits (as the worker uses a
354 * transaction context). it is safe to regard the worker 354 * transaction context). it is safe to regard the worker
355 * as paused for all matters practical. effectively, we only 355 * as paused for all matters practical. effectively, we only
356 * avoid cancellation requests from completing. 356 * avoid cancellation requests from completing.
357 */ 357 */
358 mutex_lock(&fs_info->scrub_lock); 358 mutex_lock(&fs_info->scrub_lock);
359 atomic_inc(&fs_info->scrubs_running); 359 atomic_inc(&fs_info->scrubs_running);
360 atomic_inc(&fs_info->scrubs_paused); 360 atomic_inc(&fs_info->scrubs_paused);
361 mutex_unlock(&fs_info->scrub_lock); 361 mutex_unlock(&fs_info->scrub_lock);
362 362
363 /* 363 /*
364 * check if @scrubs_running=@scrubs_paused condition 364 * check if @scrubs_running=@scrubs_paused condition
365 * inside wait_event() is not an atomic operation. 365 * inside wait_event() is not an atomic operation.
366 * which means we may inc/dec @scrub_running/paused 366 * which means we may inc/dec @scrub_running/paused
367 * at any time. Let's wake up @scrub_pause_wait as 367 * at any time. Let's wake up @scrub_pause_wait as
368 * much as we can to let commit transaction blocked less. 368 * much as we can to let commit transaction blocked less.
369 */ 369 */
370 wake_up(&fs_info->scrub_pause_wait); 370 wake_up(&fs_info->scrub_pause_wait);
371 371
372 atomic_inc(&sctx->workers_pending); 372 atomic_inc(&sctx->workers_pending);
373 } 373 }
374 374
375 /* used for workers that require transaction commits */ 375 /* used for workers that require transaction commits */
376 static void scrub_pending_trans_workers_dec(struct scrub_ctx *sctx) 376 static void scrub_pending_trans_workers_dec(struct scrub_ctx *sctx)
377 { 377 {
378 struct btrfs_fs_info *fs_info = sctx->dev_root->fs_info; 378 struct btrfs_fs_info *fs_info = sctx->dev_root->fs_info;
379 379
380 /* 380 /*
381 * see scrub_pending_trans_workers_inc() why we're pretending 381 * see scrub_pending_trans_workers_inc() why we're pretending
382 * to be paused in the scrub counters 382 * to be paused in the scrub counters
383 */ 383 */
384 mutex_lock(&fs_info->scrub_lock); 384 mutex_lock(&fs_info->scrub_lock);
385 atomic_dec(&fs_info->scrubs_running); 385 atomic_dec(&fs_info->scrubs_running);
386 atomic_dec(&fs_info->scrubs_paused); 386 atomic_dec(&fs_info->scrubs_paused);
387 mutex_unlock(&fs_info->scrub_lock); 387 mutex_unlock(&fs_info->scrub_lock);
388 atomic_dec(&sctx->workers_pending); 388 atomic_dec(&sctx->workers_pending);
389 wake_up(&fs_info->scrub_pause_wait); 389 wake_up(&fs_info->scrub_pause_wait);
390 wake_up(&sctx->list_wait); 390 wake_up(&sctx->list_wait);
391 } 391 }
392 392
393 static void scrub_free_csums(struct scrub_ctx *sctx) 393 static void scrub_free_csums(struct scrub_ctx *sctx)
394 { 394 {
395 while (!list_empty(&sctx->csum_list)) { 395 while (!list_empty(&sctx->csum_list)) {
396 struct btrfs_ordered_sum *sum; 396 struct btrfs_ordered_sum *sum;
397 sum = list_first_entry(&sctx->csum_list, 397 sum = list_first_entry(&sctx->csum_list,
398 struct btrfs_ordered_sum, list); 398 struct btrfs_ordered_sum, list);
399 list_del(&sum->list); 399 list_del(&sum->list);
400 kfree(sum); 400 kfree(sum);
401 } 401 }
402 } 402 }
403 403
404 static noinline_for_stack void scrub_free_ctx(struct scrub_ctx *sctx) 404 static noinline_for_stack void scrub_free_ctx(struct scrub_ctx *sctx)
405 { 405 {
406 int i; 406 int i;
407 407
408 if (!sctx) 408 if (!sctx)
409 return; 409 return;
410 410
411 scrub_free_wr_ctx(&sctx->wr_ctx); 411 scrub_free_wr_ctx(&sctx->wr_ctx);
412 412
413 /* this can happen when scrub is cancelled */ 413 /* this can happen when scrub is cancelled */
414 if (sctx->curr != -1) { 414 if (sctx->curr != -1) {
415 struct scrub_bio *sbio = sctx->bios[sctx->curr]; 415 struct scrub_bio *sbio = sctx->bios[sctx->curr];
416 416
417 for (i = 0; i < sbio->page_count; i++) { 417 for (i = 0; i < sbio->page_count; i++) {
418 WARN_ON(!sbio->pagev[i]->page); 418 WARN_ON(!sbio->pagev[i]->page);
419 scrub_block_put(sbio->pagev[i]->sblock); 419 scrub_block_put(sbio->pagev[i]->sblock);
420 } 420 }
421 bio_put(sbio->bio); 421 bio_put(sbio->bio);
422 } 422 }
423 423
424 for (i = 0; i < SCRUB_BIOS_PER_SCTX; ++i) { 424 for (i = 0; i < SCRUB_BIOS_PER_SCTX; ++i) {
425 struct scrub_bio *sbio = sctx->bios[i]; 425 struct scrub_bio *sbio = sctx->bios[i];
426 426
427 if (!sbio) 427 if (!sbio)
428 break; 428 break;
429 kfree(sbio); 429 kfree(sbio);
430 } 430 }
431 431
432 scrub_free_csums(sctx); 432 scrub_free_csums(sctx);
433 kfree(sctx); 433 kfree(sctx);
434 } 434 }
435 435
436 static noinline_for_stack 436 static noinline_for_stack
437 struct scrub_ctx *scrub_setup_ctx(struct btrfs_device *dev, int is_dev_replace) 437 struct scrub_ctx *scrub_setup_ctx(struct btrfs_device *dev, int is_dev_replace)
438 { 438 {
439 struct scrub_ctx *sctx; 439 struct scrub_ctx *sctx;
440 int i; 440 int i;
441 struct btrfs_fs_info *fs_info = dev->dev_root->fs_info; 441 struct btrfs_fs_info *fs_info = dev->dev_root->fs_info;
442 int pages_per_rd_bio; 442 int pages_per_rd_bio;
443 int ret; 443 int ret;
444 444
445 /* 445 /*
446 * the setting of pages_per_rd_bio is correct for scrub but might 446 * the setting of pages_per_rd_bio is correct for scrub but might
447 * be wrong for the dev_replace code where we might read from 447 * be wrong for the dev_replace code where we might read from
448 * different devices in the initial huge bios. However, that 448 * different devices in the initial huge bios. However, that
449 * code is able to correctly handle the case when adding a page 449 * code is able to correctly handle the case when adding a page
450 * to a bio fails. 450 * to a bio fails.
451 */ 451 */
452 if (dev->bdev) 452 if (dev->bdev)
453 pages_per_rd_bio = min_t(int, SCRUB_PAGES_PER_RD_BIO, 453 pages_per_rd_bio = min_t(int, SCRUB_PAGES_PER_RD_BIO,
454 bio_get_nr_vecs(dev->bdev)); 454 bio_get_nr_vecs(dev->bdev));
455 else 455 else
456 pages_per_rd_bio = SCRUB_PAGES_PER_RD_BIO; 456 pages_per_rd_bio = SCRUB_PAGES_PER_RD_BIO;
457 sctx = kzalloc(sizeof(*sctx), GFP_NOFS); 457 sctx = kzalloc(sizeof(*sctx), GFP_NOFS);
458 if (!sctx) 458 if (!sctx)
459 goto nomem; 459 goto nomem;
460 sctx->is_dev_replace = is_dev_replace; 460 sctx->is_dev_replace = is_dev_replace;
461 sctx->pages_per_rd_bio = pages_per_rd_bio; 461 sctx->pages_per_rd_bio = pages_per_rd_bio;
462 sctx->curr = -1; 462 sctx->curr = -1;
463 sctx->dev_root = dev->dev_root; 463 sctx->dev_root = dev->dev_root;
464 for (i = 0; i < SCRUB_BIOS_PER_SCTX; ++i) { 464 for (i = 0; i < SCRUB_BIOS_PER_SCTX; ++i) {
465 struct scrub_bio *sbio; 465 struct scrub_bio *sbio;
466 466
467 sbio = kzalloc(sizeof(*sbio), GFP_NOFS); 467 sbio = kzalloc(sizeof(*sbio), GFP_NOFS);
468 if (!sbio) 468 if (!sbio)
469 goto nomem; 469 goto nomem;
470 sctx->bios[i] = sbio; 470 sctx->bios[i] = sbio;
471 471
472 sbio->index = i; 472 sbio->index = i;
473 sbio->sctx = sctx; 473 sbio->sctx = sctx;
474 sbio->page_count = 0; 474 sbio->page_count = 0;
475 btrfs_init_work(&sbio->work, btrfs_scrub_helper, 475 btrfs_init_work(&sbio->work, btrfs_scrub_helper,
476 scrub_bio_end_io_worker, NULL, NULL); 476 scrub_bio_end_io_worker, NULL, NULL);
477 477
478 if (i != SCRUB_BIOS_PER_SCTX - 1) 478 if (i != SCRUB_BIOS_PER_SCTX - 1)
479 sctx->bios[i]->next_free = i + 1; 479 sctx->bios[i]->next_free = i + 1;
480 else 480 else
481 sctx->bios[i]->next_free = -1; 481 sctx->bios[i]->next_free = -1;
482 } 482 }
483 sctx->first_free = 0; 483 sctx->first_free = 0;
484 sctx->nodesize = dev->dev_root->nodesize; 484 sctx->nodesize = dev->dev_root->nodesize;
485 sctx->sectorsize = dev->dev_root->sectorsize; 485 sctx->sectorsize = dev->dev_root->sectorsize;
486 atomic_set(&sctx->bios_in_flight, 0); 486 atomic_set(&sctx->bios_in_flight, 0);
487 atomic_set(&sctx->workers_pending, 0); 487 atomic_set(&sctx->workers_pending, 0);
488 atomic_set(&sctx->cancel_req, 0); 488 atomic_set(&sctx->cancel_req, 0);
489 sctx->csum_size = btrfs_super_csum_size(fs_info->super_copy); 489 sctx->csum_size = btrfs_super_csum_size(fs_info->super_copy);
490 INIT_LIST_HEAD(&sctx->csum_list); 490 INIT_LIST_HEAD(&sctx->csum_list);
491 491
492 spin_lock_init(&sctx->list_lock); 492 spin_lock_init(&sctx->list_lock);
493 spin_lock_init(&sctx->stat_lock); 493 spin_lock_init(&sctx->stat_lock);
494 init_waitqueue_head(&sctx->list_wait); 494 init_waitqueue_head(&sctx->list_wait);
495 495
496 ret = scrub_setup_wr_ctx(sctx, &sctx->wr_ctx, fs_info, 496 ret = scrub_setup_wr_ctx(sctx, &sctx->wr_ctx, fs_info,
497 fs_info->dev_replace.tgtdev, is_dev_replace); 497 fs_info->dev_replace.tgtdev, is_dev_replace);
498 if (ret) { 498 if (ret) {
499 scrub_free_ctx(sctx); 499 scrub_free_ctx(sctx);
500 return ERR_PTR(ret); 500 return ERR_PTR(ret);
501 } 501 }
502 return sctx; 502 return sctx;
503 503
504 nomem: 504 nomem:
505 scrub_free_ctx(sctx); 505 scrub_free_ctx(sctx);
506 return ERR_PTR(-ENOMEM); 506 return ERR_PTR(-ENOMEM);
507 } 507 }
508 508
509 static int scrub_print_warning_inode(u64 inum, u64 offset, u64 root, 509 static int scrub_print_warning_inode(u64 inum, u64 offset, u64 root,
510 void *warn_ctx) 510 void *warn_ctx)
511 { 511 {
512 u64 isize; 512 u64 isize;
513 u32 nlink; 513 u32 nlink;
514 int ret; 514 int ret;
515 int i; 515 int i;
516 struct extent_buffer *eb; 516 struct extent_buffer *eb;
517 struct btrfs_inode_item *inode_item; 517 struct btrfs_inode_item *inode_item;
518 struct scrub_warning *swarn = warn_ctx; 518 struct scrub_warning *swarn = warn_ctx;
519 struct btrfs_fs_info *fs_info = swarn->dev->dev_root->fs_info; 519 struct btrfs_fs_info *fs_info = swarn->dev->dev_root->fs_info;
520 struct inode_fs_paths *ipath = NULL; 520 struct inode_fs_paths *ipath = NULL;
521 struct btrfs_root *local_root; 521 struct btrfs_root *local_root;
522 struct btrfs_key root_key; 522 struct btrfs_key root_key;
523 523
524 root_key.objectid = root; 524 root_key.objectid = root;
525 root_key.type = BTRFS_ROOT_ITEM_KEY; 525 root_key.type = BTRFS_ROOT_ITEM_KEY;
526 root_key.offset = (u64)-1; 526 root_key.offset = (u64)-1;
527 local_root = btrfs_read_fs_root_no_name(fs_info, &root_key); 527 local_root = btrfs_read_fs_root_no_name(fs_info, &root_key);
528 if (IS_ERR(local_root)) { 528 if (IS_ERR(local_root)) {
529 ret = PTR_ERR(local_root); 529 ret = PTR_ERR(local_root);
530 goto err; 530 goto err;
531 } 531 }
532 532
533 ret = inode_item_info(inum, 0, local_root, swarn->path); 533 ret = inode_item_info(inum, 0, local_root, swarn->path);
534 if (ret) { 534 if (ret) {
535 btrfs_release_path(swarn->path); 535 btrfs_release_path(swarn->path);
536 goto err; 536 goto err;
537 } 537 }
538 538
539 eb = swarn->path->nodes[0]; 539 eb = swarn->path->nodes[0];
540 inode_item = btrfs_item_ptr(eb, swarn->path->slots[0], 540 inode_item = btrfs_item_ptr(eb, swarn->path->slots[0],
541 struct btrfs_inode_item); 541 struct btrfs_inode_item);
542 isize = btrfs_inode_size(eb, inode_item); 542 isize = btrfs_inode_size(eb, inode_item);
543 nlink = btrfs_inode_nlink(eb, inode_item); 543 nlink = btrfs_inode_nlink(eb, inode_item);
544 btrfs_release_path(swarn->path); 544 btrfs_release_path(swarn->path);
545 545
546 ipath = init_ipath(4096, local_root, swarn->path); 546 ipath = init_ipath(4096, local_root, swarn->path);
547 if (IS_ERR(ipath)) { 547 if (IS_ERR(ipath)) {
548 ret = PTR_ERR(ipath); 548 ret = PTR_ERR(ipath);
549 ipath = NULL; 549 ipath = NULL;
550 goto err; 550 goto err;
551 } 551 }
552 ret = paths_from_inode(inum, ipath); 552 ret = paths_from_inode(inum, ipath);
553 553
554 if (ret < 0) 554 if (ret < 0)
555 goto err; 555 goto err;
556 556
557 /* 557 /*
558 * we deliberately ignore the bit ipath might have been too small to 558 * we deliberately ignore the bit ipath might have been too small to
559 * hold all of the paths here 559 * hold all of the paths here
560 */ 560 */
561 for (i = 0; i < ipath->fspath->elem_cnt; ++i) 561 for (i = 0; i < ipath->fspath->elem_cnt; ++i)
562 printk_in_rcu(KERN_WARNING "BTRFS: %s at logical %llu on dev " 562 printk_in_rcu(KERN_WARNING "BTRFS: %s at logical %llu on dev "
563 "%s, sector %llu, root %llu, inode %llu, offset %llu, " 563 "%s, sector %llu, root %llu, inode %llu, offset %llu, "
564 "length %llu, links %u (path: %s)\n", swarn->errstr, 564 "length %llu, links %u (path: %s)\n", swarn->errstr,
565 swarn->logical, rcu_str_deref(swarn->dev->name), 565 swarn->logical, rcu_str_deref(swarn->dev->name),
566 (unsigned long long)swarn->sector, root, inum, offset, 566 (unsigned long long)swarn->sector, root, inum, offset,
567 min(isize - offset, (u64)PAGE_SIZE), nlink, 567 min(isize - offset, (u64)PAGE_SIZE), nlink,
568 (char *)(unsigned long)ipath->fspath->val[i]); 568 (char *)(unsigned long)ipath->fspath->val[i]);
569 569
570 free_ipath(ipath); 570 free_ipath(ipath);
571 return 0; 571 return 0;
572 572
573 err: 573 err:
574 printk_in_rcu(KERN_WARNING "BTRFS: %s at logical %llu on dev " 574 printk_in_rcu(KERN_WARNING "BTRFS: %s at logical %llu on dev "
575 "%s, sector %llu, root %llu, inode %llu, offset %llu: path " 575 "%s, sector %llu, root %llu, inode %llu, offset %llu: path "
576 "resolving failed with ret=%d\n", swarn->errstr, 576 "resolving failed with ret=%d\n", swarn->errstr,
577 swarn->logical, rcu_str_deref(swarn->dev->name), 577 swarn->logical, rcu_str_deref(swarn->dev->name),
578 (unsigned long long)swarn->sector, root, inum, offset, ret); 578 (unsigned long long)swarn->sector, root, inum, offset, ret);
579 579
580 free_ipath(ipath); 580 free_ipath(ipath);
581 return 0; 581 return 0;
582 } 582 }
583 583
584 static void scrub_print_warning(const char *errstr, struct scrub_block *sblock) 584 static void scrub_print_warning(const char *errstr, struct scrub_block *sblock)
585 { 585 {
586 struct btrfs_device *dev; 586 struct btrfs_device *dev;
587 struct btrfs_fs_info *fs_info; 587 struct btrfs_fs_info *fs_info;
588 struct btrfs_path *path; 588 struct btrfs_path *path;
589 struct btrfs_key found_key; 589 struct btrfs_key found_key;
590 struct extent_buffer *eb; 590 struct extent_buffer *eb;
591 struct btrfs_extent_item *ei; 591 struct btrfs_extent_item *ei;
592 struct scrub_warning swarn; 592 struct scrub_warning swarn;
593 unsigned long ptr = 0; 593 unsigned long ptr = 0;
594 u64 extent_item_pos; 594 u64 extent_item_pos;
595 u64 flags = 0; 595 u64 flags = 0;
596 u64 ref_root; 596 u64 ref_root;
597 u32 item_size; 597 u32 item_size;
598 u8 ref_level; 598 u8 ref_level;
599 int ret; 599 int ret;
600 600
601 WARN_ON(sblock->page_count < 1); 601 WARN_ON(sblock->page_count < 1);
602 dev = sblock->pagev[0]->dev; 602 dev = sblock->pagev[0]->dev;
603 fs_info = sblock->sctx->dev_root->fs_info; 603 fs_info = sblock->sctx->dev_root->fs_info;
604 604
605 path = btrfs_alloc_path(); 605 path = btrfs_alloc_path();
606 if (!path) 606 if (!path)
607 return; 607 return;
608 608
609 swarn.sector = (sblock->pagev[0]->physical) >> 9; 609 swarn.sector = (sblock->pagev[0]->physical) >> 9;
610 swarn.logical = sblock->pagev[0]->logical; 610 swarn.logical = sblock->pagev[0]->logical;
611 swarn.errstr = errstr; 611 swarn.errstr = errstr;
612 swarn.dev = NULL; 612 swarn.dev = NULL;
613 613
614 ret = extent_from_logical(fs_info, swarn.logical, path, &found_key, 614 ret = extent_from_logical(fs_info, swarn.logical, path, &found_key,
615 &flags); 615 &flags);
616 if (ret < 0) 616 if (ret < 0)
617 goto out; 617 goto out;
618 618
619 extent_item_pos = swarn.logical - found_key.objectid; 619 extent_item_pos = swarn.logical - found_key.objectid;
620 swarn.extent_item_size = found_key.offset; 620 swarn.extent_item_size = found_key.offset;
621 621
622 eb = path->nodes[0]; 622 eb = path->nodes[0];
623 ei = btrfs_item_ptr(eb, path->slots[0], struct btrfs_extent_item); 623 ei = btrfs_item_ptr(eb, path->slots[0], struct btrfs_extent_item);
624 item_size = btrfs_item_size_nr(eb, path->slots[0]); 624 item_size = btrfs_item_size_nr(eb, path->slots[0]);
625 625
626 if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) { 626 if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) {
627 do { 627 do {
628 ret = tree_backref_for_extent(&ptr, eb, &found_key, ei, 628 ret = tree_backref_for_extent(&ptr, eb, &found_key, ei,
629 item_size, &ref_root, 629 item_size, &ref_root,
630 &ref_level); 630 &ref_level);
631 printk_in_rcu(KERN_WARNING 631 printk_in_rcu(KERN_WARNING
632 "BTRFS: %s at logical %llu on dev %s, " 632 "BTRFS: %s at logical %llu on dev %s, "
633 "sector %llu: metadata %s (level %d) in tree " 633 "sector %llu: metadata %s (level %d) in tree "
634 "%llu\n", errstr, swarn.logical, 634 "%llu\n", errstr, swarn.logical,
635 rcu_str_deref(dev->name), 635 rcu_str_deref(dev->name),
636 (unsigned long long)swarn.sector, 636 (unsigned long long)swarn.sector,
637 ref_level ? "node" : "leaf", 637 ref_level ? "node" : "leaf",
638 ret < 0 ? -1 : ref_level, 638 ret < 0 ? -1 : ref_level,
639 ret < 0 ? -1 : ref_root); 639 ret < 0 ? -1 : ref_root);
640 } while (ret != 1); 640 } while (ret != 1);
641 btrfs_release_path(path); 641 btrfs_release_path(path);
642 } else { 642 } else {
643 btrfs_release_path(path); 643 btrfs_release_path(path);
644 swarn.path = path; 644 swarn.path = path;
645 swarn.dev = dev; 645 swarn.dev = dev;
646 iterate_extent_inodes(fs_info, found_key.objectid, 646 iterate_extent_inodes(fs_info, found_key.objectid,
647 extent_item_pos, 1, 647 extent_item_pos, 1,
648 scrub_print_warning_inode, &swarn); 648 scrub_print_warning_inode, &swarn);
649 } 649 }
650 650
651 out: 651 out:
652 btrfs_free_path(path); 652 btrfs_free_path(path);
653 } 653 }
654 654
655 static int scrub_fixup_readpage(u64 inum, u64 offset, u64 root, void *fixup_ctx) 655 static int scrub_fixup_readpage(u64 inum, u64 offset, u64 root, void *fixup_ctx)
656 { 656 {
657 struct page *page = NULL; 657 struct page *page = NULL;
658 unsigned long index; 658 unsigned long index;
659 struct scrub_fixup_nodatasum *fixup = fixup_ctx; 659 struct scrub_fixup_nodatasum *fixup = fixup_ctx;
660 int ret; 660 int ret;
661 int corrected = 0; 661 int corrected = 0;
662 struct btrfs_key key; 662 struct btrfs_key key;
663 struct inode *inode = NULL; 663 struct inode *inode = NULL;
664 struct btrfs_fs_info *fs_info; 664 struct btrfs_fs_info *fs_info;
665 u64 end = offset + PAGE_SIZE - 1; 665 u64 end = offset + PAGE_SIZE - 1;
666 struct btrfs_root *local_root; 666 struct btrfs_root *local_root;
667 int srcu_index; 667 int srcu_index;
668 668
669 key.objectid = root; 669 key.objectid = root;
670 key.type = BTRFS_ROOT_ITEM_KEY; 670 key.type = BTRFS_ROOT_ITEM_KEY;
671 key.offset = (u64)-1; 671 key.offset = (u64)-1;
672 672
673 fs_info = fixup->root->fs_info; 673 fs_info = fixup->root->fs_info;
674 srcu_index = srcu_read_lock(&fs_info->subvol_srcu); 674 srcu_index = srcu_read_lock(&fs_info->subvol_srcu);
675 675
676 local_root = btrfs_read_fs_root_no_name(fs_info, &key); 676 local_root = btrfs_read_fs_root_no_name(fs_info, &key);
677 if (IS_ERR(local_root)) { 677 if (IS_ERR(local_root)) {
678 srcu_read_unlock(&fs_info->subvol_srcu, srcu_index); 678 srcu_read_unlock(&fs_info->subvol_srcu, srcu_index);
679 return PTR_ERR(local_root); 679 return PTR_ERR(local_root);
680 } 680 }
681 681
682 key.type = BTRFS_INODE_ITEM_KEY; 682 key.type = BTRFS_INODE_ITEM_KEY;
683 key.objectid = inum; 683 key.objectid = inum;
684 key.offset = 0; 684 key.offset = 0;
685 inode = btrfs_iget(fs_info->sb, &key, local_root, NULL); 685 inode = btrfs_iget(fs_info->sb, &key, local_root, NULL);
686 srcu_read_unlock(&fs_info->subvol_srcu, srcu_index); 686 srcu_read_unlock(&fs_info->subvol_srcu, srcu_index);
687 if (IS_ERR(inode)) 687 if (IS_ERR(inode))
688 return PTR_ERR(inode); 688 return PTR_ERR(inode);
689 689
690 index = offset >> PAGE_CACHE_SHIFT; 690 index = offset >> PAGE_CACHE_SHIFT;
691 691
692 page = find_or_create_page(inode->i_mapping, index, GFP_NOFS); 692 page = find_or_create_page(inode->i_mapping, index, GFP_NOFS);
693 if (!page) { 693 if (!page) {
694 ret = -ENOMEM; 694 ret = -ENOMEM;
695 goto out; 695 goto out;
696 } 696 }
697 697
698 if (PageUptodate(page)) { 698 if (PageUptodate(page)) {
699 if (PageDirty(page)) { 699 if (PageDirty(page)) {
700 /* 700 /*
701 * we need to write the data to the defect sector. the 701 * we need to write the data to the defect sector. the
702 * data that was in that sector is not in memory, 702 * data that was in that sector is not in memory,
703 * because the page was modified. we must not write the 703 * because the page was modified. we must not write the
704 * modified page to that sector. 704 * modified page to that sector.
705 * 705 *
706 * TODO: what could be done here: wait for the delalloc 706 * TODO: what could be done here: wait for the delalloc
707 * runner to write out that page (might involve 707 * runner to write out that page (might involve
708 * COW) and see whether the sector is still 708 * COW) and see whether the sector is still
709 * referenced afterwards. 709 * referenced afterwards.
710 * 710 *
711 * For the meantime, we'll treat this error 711 * For the meantime, we'll treat this error
712 * incorrectable, although there is a chance that a 712 * incorrectable, although there is a chance that a
713 * later scrub will find the bad sector again and that 713 * later scrub will find the bad sector again and that
714 * there's no dirty page in memory, then. 714 * there's no dirty page in memory, then.
715 */ 715 */
716 ret = -EIO; 716 ret = -EIO;
717 goto out; 717 goto out;
718 } 718 }
719 ret = repair_io_failure(inode, offset, PAGE_SIZE, 719 ret = repair_io_failure(inode, offset, PAGE_SIZE,
720 fixup->logical, page, 720 fixup->logical, page,
721 offset - page_offset(page), 721 offset - page_offset(page),
722 fixup->mirror_num); 722 fixup->mirror_num);
723 unlock_page(page); 723 unlock_page(page);
724 corrected = !ret; 724 corrected = !ret;
725 } else { 725 } else {
726 /* 726 /*
727 * we need to get good data first. the general readpage path 727 * we need to get good data first. the general readpage path
728 * will call repair_io_failure for us, we just have to make 728 * will call repair_io_failure for us, we just have to make
729 * sure we read the bad mirror. 729 * sure we read the bad mirror.
730 */ 730 */
731 ret = set_extent_bits(&BTRFS_I(inode)->io_tree, offset, end, 731 ret = set_extent_bits(&BTRFS_I(inode)->io_tree, offset, end,
732 EXTENT_DAMAGED, GFP_NOFS); 732 EXTENT_DAMAGED, GFP_NOFS);
733 if (ret) { 733 if (ret) {
734 /* set_extent_bits should give proper error */ 734 /* set_extent_bits should give proper error */
735 WARN_ON(ret > 0); 735 WARN_ON(ret > 0);
736 if (ret > 0) 736 if (ret > 0)
737 ret = -EFAULT; 737 ret = -EFAULT;
738 goto out; 738 goto out;
739 } 739 }
740 740
741 ret = extent_read_full_page(&BTRFS_I(inode)->io_tree, page, 741 ret = extent_read_full_page(&BTRFS_I(inode)->io_tree, page,
742 btrfs_get_extent, 742 btrfs_get_extent,
743 fixup->mirror_num); 743 fixup->mirror_num);
744 wait_on_page_locked(page); 744 wait_on_page_locked(page);
745 745
746 corrected = !test_range_bit(&BTRFS_I(inode)->io_tree, offset, 746 corrected = !test_range_bit(&BTRFS_I(inode)->io_tree, offset,
747 end, EXTENT_DAMAGED, 0, NULL); 747 end, EXTENT_DAMAGED, 0, NULL);
748 if (!corrected) 748 if (!corrected)
749 clear_extent_bits(&BTRFS_I(inode)->io_tree, offset, end, 749 clear_extent_bits(&BTRFS_I(inode)->io_tree, offset, end,
750 EXTENT_DAMAGED, GFP_NOFS); 750 EXTENT_DAMAGED, GFP_NOFS);
751 } 751 }
752 752
753 out: 753 out:
754 if (page) 754 if (page)
755 put_page(page); 755 put_page(page);
756 756
757 iput(inode); 757 iput(inode);
758 758
759 if (ret < 0) 759 if (ret < 0)
760 return ret; 760 return ret;
761 761
762 if (ret == 0 && corrected) { 762 if (ret == 0 && corrected) {
763 /* 763 /*
764 * we only need to call readpage for one of the inodes belonging 764 * we only need to call readpage for one of the inodes belonging
765 * to this extent. so make iterate_extent_inodes stop 765 * to this extent. so make iterate_extent_inodes stop
766 */ 766 */
767 return 1; 767 return 1;
768 } 768 }
769 769
770 return -EIO; 770 return -EIO;
771 } 771 }
772 772
773 static void scrub_fixup_nodatasum(struct btrfs_work *work) 773 static void scrub_fixup_nodatasum(struct btrfs_work *work)
774 { 774 {
775 int ret; 775 int ret;
776 struct scrub_fixup_nodatasum *fixup; 776 struct scrub_fixup_nodatasum *fixup;
777 struct scrub_ctx *sctx; 777 struct scrub_ctx *sctx;
778 struct btrfs_trans_handle *trans = NULL; 778 struct btrfs_trans_handle *trans = NULL;
779 struct btrfs_path *path; 779 struct btrfs_path *path;
780 int uncorrectable = 0; 780 int uncorrectable = 0;
781 781
782 fixup = container_of(work, struct scrub_fixup_nodatasum, work); 782 fixup = container_of(work, struct scrub_fixup_nodatasum, work);
783 sctx = fixup->sctx; 783 sctx = fixup->sctx;
784 784
785 path = btrfs_alloc_path(); 785 path = btrfs_alloc_path();
786 if (!path) { 786 if (!path) {
787 spin_lock(&sctx->stat_lock); 787 spin_lock(&sctx->stat_lock);
788 ++sctx->stat.malloc_errors; 788 ++sctx->stat.malloc_errors;
789 spin_unlock(&sctx->stat_lock); 789 spin_unlock(&sctx->stat_lock);
790 uncorrectable = 1; 790 uncorrectable = 1;
791 goto out; 791 goto out;
792 } 792 }
793 793
794 trans = btrfs_join_transaction(fixup->root); 794 trans = btrfs_join_transaction(fixup->root);
795 if (IS_ERR(trans)) { 795 if (IS_ERR(trans)) {
796 uncorrectable = 1; 796 uncorrectable = 1;
797 goto out; 797 goto out;
798 } 798 }
799 799
800 /* 800 /*
801 * the idea is to trigger a regular read through the standard path. we 801 * the idea is to trigger a regular read through the standard path. we
802 * read a page from the (failed) logical address by specifying the 802 * read a page from the (failed) logical address by specifying the
803 * corresponding copynum of the failed sector. thus, that readpage is 803 * corresponding copynum of the failed sector. thus, that readpage is
804 * expected to fail. 804 * expected to fail.
805 * that is the point where on-the-fly error correction will kick in 805 * that is the point where on-the-fly error correction will kick in
806 * (once it's finished) and rewrite the failed sector if a good copy 806 * (once it's finished) and rewrite the failed sector if a good copy
807 * can be found. 807 * can be found.
808 */ 808 */
809 ret = iterate_inodes_from_logical(fixup->logical, fixup->root->fs_info, 809 ret = iterate_inodes_from_logical(fixup->logical, fixup->root->fs_info,
810 path, scrub_fixup_readpage, 810 path, scrub_fixup_readpage,
811 fixup); 811 fixup);
812 if (ret < 0) { 812 if (ret < 0) {
813 uncorrectable = 1; 813 uncorrectable = 1;
814 goto out; 814 goto out;
815 } 815 }
816 WARN_ON(ret != 1); 816 WARN_ON(ret != 1);
817 817
818 spin_lock(&sctx->stat_lock); 818 spin_lock(&sctx->stat_lock);
819 ++sctx->stat.corrected_errors; 819 ++sctx->stat.corrected_errors;
820 spin_unlock(&sctx->stat_lock); 820 spin_unlock(&sctx->stat_lock);
821 821
822 out: 822 out:
823 if (trans && !IS_ERR(trans)) 823 if (trans && !IS_ERR(trans))
824 btrfs_end_transaction(trans, fixup->root); 824 btrfs_end_transaction(trans, fixup->root);
825 if (uncorrectable) { 825 if (uncorrectable) {
826 spin_lock(&sctx->stat_lock); 826 spin_lock(&sctx->stat_lock);
827 ++sctx->stat.uncorrectable_errors; 827 ++sctx->stat.uncorrectable_errors;
828 spin_unlock(&sctx->stat_lock); 828 spin_unlock(&sctx->stat_lock);
829 btrfs_dev_replace_stats_inc( 829 btrfs_dev_replace_stats_inc(
830 &sctx->dev_root->fs_info->dev_replace. 830 &sctx->dev_root->fs_info->dev_replace.
831 num_uncorrectable_read_errors); 831 num_uncorrectable_read_errors);
832 printk_ratelimited_in_rcu(KERN_ERR "BTRFS: " 832 printk_ratelimited_in_rcu(KERN_ERR "BTRFS: "
833 "unable to fixup (nodatasum) error at logical %llu on dev %s\n", 833 "unable to fixup (nodatasum) error at logical %llu on dev %s\n",
834 fixup->logical, rcu_str_deref(fixup->dev->name)); 834 fixup->logical, rcu_str_deref(fixup->dev->name));
835 } 835 }
836 836
837 btrfs_free_path(path); 837 btrfs_free_path(path);
838 kfree(fixup); 838 kfree(fixup);
839 839
840 scrub_pending_trans_workers_dec(sctx); 840 scrub_pending_trans_workers_dec(sctx);
841 } 841 }
842 842
843 static inline void scrub_get_recover(struct scrub_recover *recover) 843 static inline void scrub_get_recover(struct scrub_recover *recover)
844 { 844 {
845 atomic_inc(&recover->refs); 845 atomic_inc(&recover->refs);
846 } 846 }
847 847
848 static inline void scrub_put_recover(struct scrub_recover *recover) 848 static inline void scrub_put_recover(struct scrub_recover *recover)
849 { 849 {
850 if (atomic_dec_and_test(&recover->refs)) { 850 if (atomic_dec_and_test(&recover->refs)) {
851 kfree(recover->bbio); 851 kfree(recover->bbio);
852 kfree(recover->raid_map); 852 kfree(recover->raid_map);
853 kfree(recover); 853 kfree(recover);
854 } 854 }
855 } 855 }
856 856
857 /* 857 /*
858 * scrub_handle_errored_block gets called when either verification of the 858 * scrub_handle_errored_block gets called when either verification of the
859 * pages failed or the bio failed to read, e.g. with EIO. In the latter 859 * pages failed or the bio failed to read, e.g. with EIO. In the latter
860 * case, this function handles all pages in the bio, even though only one 860 * case, this function handles all pages in the bio, even though only one
861 * may be bad. 861 * may be bad.
862 * The goal of this function is to repair the errored block by using the 862 * The goal of this function is to repair the errored block by using the
863 * contents of one of the mirrors. 863 * contents of one of the mirrors.
864 */ 864 */
865 static int scrub_handle_errored_block(struct scrub_block *sblock_to_check) 865 static int scrub_handle_errored_block(struct scrub_block *sblock_to_check)
866 { 866 {
867 struct scrub_ctx *sctx = sblock_to_check->sctx; 867 struct scrub_ctx *sctx = sblock_to_check->sctx;
868 struct btrfs_device *dev; 868 struct btrfs_device *dev;
869 struct btrfs_fs_info *fs_info; 869 struct btrfs_fs_info *fs_info;
870 u64 length; 870 u64 length;
871 u64 logical; 871 u64 logical;
872 u64 generation; 872 u64 generation;
873 unsigned int failed_mirror_index; 873 unsigned int failed_mirror_index;
874 unsigned int is_metadata; 874 unsigned int is_metadata;
875 unsigned int have_csum; 875 unsigned int have_csum;
876 u8 *csum; 876 u8 *csum;
877 struct scrub_block *sblocks_for_recheck; /* holds one for each mirror */ 877 struct scrub_block *sblocks_for_recheck; /* holds one for each mirror */
878 struct scrub_block *sblock_bad; 878 struct scrub_block *sblock_bad;
879 int ret; 879 int ret;
880 int mirror_index; 880 int mirror_index;
881 int page_num; 881 int page_num;
882 int success; 882 int success;
883 static DEFINE_RATELIMIT_STATE(_rs, DEFAULT_RATELIMIT_INTERVAL, 883 static DEFINE_RATELIMIT_STATE(_rs, DEFAULT_RATELIMIT_INTERVAL,
884 DEFAULT_RATELIMIT_BURST); 884 DEFAULT_RATELIMIT_BURST);
885 885
886 BUG_ON(sblock_to_check->page_count < 1); 886 BUG_ON(sblock_to_check->page_count < 1);
887 fs_info = sctx->dev_root->fs_info; 887 fs_info = sctx->dev_root->fs_info;
888 if (sblock_to_check->pagev[0]->flags & BTRFS_EXTENT_FLAG_SUPER) { 888 if (sblock_to_check->pagev[0]->flags & BTRFS_EXTENT_FLAG_SUPER) {
889 /* 889 /*
890 * if we find an error in a super block, we just report it. 890 * if we find an error in a super block, we just report it.
891 * They will get written with the next transaction commit 891 * They will get written with the next transaction commit
892 * anyway 892 * anyway
893 */ 893 */
894 spin_lock(&sctx->stat_lock); 894 spin_lock(&sctx->stat_lock);
895 ++sctx->stat.super_errors; 895 ++sctx->stat.super_errors;
896 spin_unlock(&sctx->stat_lock); 896 spin_unlock(&sctx->stat_lock);
897 return 0; 897 return 0;
898 } 898 }
899 length = sblock_to_check->page_count * PAGE_SIZE; 899 length = sblock_to_check->page_count * PAGE_SIZE;
900 logical = sblock_to_check->pagev[0]->logical; 900 logical = sblock_to_check->pagev[0]->logical;
901 generation = sblock_to_check->pagev[0]->generation; 901 generation = sblock_to_check->pagev[0]->generation;
902 BUG_ON(sblock_to_check->pagev[0]->mirror_num < 1); 902 BUG_ON(sblock_to_check->pagev[0]->mirror_num < 1);
903 failed_mirror_index = sblock_to_check->pagev[0]->mirror_num - 1; 903 failed_mirror_index = sblock_to_check->pagev[0]->mirror_num - 1;
904 is_metadata = !(sblock_to_check->pagev[0]->flags & 904 is_metadata = !(sblock_to_check->pagev[0]->flags &
905 BTRFS_EXTENT_FLAG_DATA); 905 BTRFS_EXTENT_FLAG_DATA);
906 have_csum = sblock_to_check->pagev[0]->have_csum; 906 have_csum = sblock_to_check->pagev[0]->have_csum;
907 csum = sblock_to_check->pagev[0]->csum; 907 csum = sblock_to_check->pagev[0]->csum;
908 dev = sblock_to_check->pagev[0]->dev; 908 dev = sblock_to_check->pagev[0]->dev;
909 909
910 if (sctx->is_dev_replace && !is_metadata && !have_csum) { 910 if (sctx->is_dev_replace && !is_metadata && !have_csum) {
911 sblocks_for_recheck = NULL; 911 sblocks_for_recheck = NULL;
912 goto nodatasum_case; 912 goto nodatasum_case;
913 } 913 }
914 914
915 /* 915 /*
916 * read all mirrors one after the other. This includes to 916 * read all mirrors one after the other. This includes to
917 * re-read the extent or metadata block that failed (that was 917 * re-read the extent or metadata block that failed (that was
918 * the cause that this fixup code is called) another time, 918 * the cause that this fixup code is called) another time,
919 * page by page this time in order to know which pages 919 * page by page this time in order to know which pages
920 * caused I/O errors and which ones are good (for all mirrors). 920 * caused I/O errors and which ones are good (for all mirrors).
921 * It is the goal to handle the situation when more than one 921 * It is the goal to handle the situation when more than one
922 * mirror contains I/O errors, but the errors do not 922 * mirror contains I/O errors, but the errors do not
923 * overlap, i.e. the data can be repaired by selecting the 923 * overlap, i.e. the data can be repaired by selecting the
924 * pages from those mirrors without I/O error on the 924 * pages from those mirrors without I/O error on the
925 * particular pages. One example (with blocks >= 2 * PAGE_SIZE) 925 * particular pages. One example (with blocks >= 2 * PAGE_SIZE)
926 * would be that mirror #1 has an I/O error on the first page, 926 * would be that mirror #1 has an I/O error on the first page,
927 * the second page is good, and mirror #2 has an I/O error on 927 * the second page is good, and mirror #2 has an I/O error on
928 * the second page, but the first page is good. 928 * the second page, but the first page is good.
929 * Then the first page of the first mirror can be repaired by 929 * Then the first page of the first mirror can be repaired by
930 * taking the first page of the second mirror, and the 930 * taking the first page of the second mirror, and the
931 * second page of the second mirror can be repaired by 931 * second page of the second mirror can be repaired by
932 * copying the contents of the 2nd page of the 1st mirror. 932 * copying the contents of the 2nd page of the 1st mirror.
933 * One more note: if the pages of one mirror contain I/O 933 * One more note: if the pages of one mirror contain I/O
934 * errors, the checksum cannot be verified. In order to get 934 * errors, the checksum cannot be verified. In order to get
935 * the best data for repairing, the first attempt is to find 935 * the best data for repairing, the first attempt is to find
936 * a mirror without I/O errors and with a validated checksum. 936 * a mirror without I/O errors and with a validated checksum.
937 * Only if this is not possible, the pages are picked from 937 * Only if this is not possible, the pages are picked from
938 * mirrors with I/O errors without considering the checksum. 938 * mirrors with I/O errors without considering the checksum.
939 * If the latter is the case, at the end, the checksum of the 939 * If the latter is the case, at the end, the checksum of the
940 * repaired area is verified in order to correctly maintain 940 * repaired area is verified in order to correctly maintain
941 * the statistics. 941 * the statistics.
942 */ 942 */
943 943
944 sblocks_for_recheck = kzalloc(BTRFS_MAX_MIRRORS * 944 sblocks_for_recheck = kzalloc(BTRFS_MAX_MIRRORS *
945 sizeof(*sblocks_for_recheck), 945 sizeof(*sblocks_for_recheck),
946 GFP_NOFS); 946 GFP_NOFS);
947 if (!sblocks_for_recheck) { 947 if (!sblocks_for_recheck) {
948 spin_lock(&sctx->stat_lock); 948 spin_lock(&sctx->stat_lock);
949 sctx->stat.malloc_errors++; 949 sctx->stat.malloc_errors++;
950 sctx->stat.read_errors++; 950 sctx->stat.read_errors++;
951 sctx->stat.uncorrectable_errors++; 951 sctx->stat.uncorrectable_errors++;
952 spin_unlock(&sctx->stat_lock); 952 spin_unlock(&sctx->stat_lock);
953 btrfs_dev_stat_inc_and_print(dev, BTRFS_DEV_STAT_READ_ERRS); 953 btrfs_dev_stat_inc_and_print(dev, BTRFS_DEV_STAT_READ_ERRS);
954 goto out; 954 goto out;
955 } 955 }
956 956
957 /* setup the context, map the logical blocks and alloc the pages */ 957 /* setup the context, map the logical blocks and alloc the pages */
958 ret = scrub_setup_recheck_block(sctx, fs_info, sblock_to_check, length, 958 ret = scrub_setup_recheck_block(sctx, fs_info, sblock_to_check, length,
959 logical, sblocks_for_recheck); 959 logical, sblocks_for_recheck);
960 if (ret) { 960 if (ret) {
961 spin_lock(&sctx->stat_lock); 961 spin_lock(&sctx->stat_lock);
962 sctx->stat.read_errors++; 962 sctx->stat.read_errors++;
963 sctx->stat.uncorrectable_errors++; 963 sctx->stat.uncorrectable_errors++;
964 spin_unlock(&sctx->stat_lock); 964 spin_unlock(&sctx->stat_lock);
965 btrfs_dev_stat_inc_and_print(dev, BTRFS_DEV_STAT_READ_ERRS); 965 btrfs_dev_stat_inc_and_print(dev, BTRFS_DEV_STAT_READ_ERRS);
966 goto out; 966 goto out;
967 } 967 }
968 BUG_ON(failed_mirror_index >= BTRFS_MAX_MIRRORS); 968 BUG_ON(failed_mirror_index >= BTRFS_MAX_MIRRORS);
969 sblock_bad = sblocks_for_recheck + failed_mirror_index; 969 sblock_bad = sblocks_for_recheck + failed_mirror_index;
970 970
971 /* build and submit the bios for the failed mirror, check checksums */ 971 /* build and submit the bios for the failed mirror, check checksums */
972 scrub_recheck_block(fs_info, sblock_bad, is_metadata, have_csum, 972 scrub_recheck_block(fs_info, sblock_bad, is_metadata, have_csum,
973 csum, generation, sctx->csum_size, 1); 973 csum, generation, sctx->csum_size, 1);
974 974
975 if (!sblock_bad->header_error && !sblock_bad->checksum_error && 975 if (!sblock_bad->header_error && !sblock_bad->checksum_error &&
976 sblock_bad->no_io_error_seen) { 976 sblock_bad->no_io_error_seen) {
977 /* 977 /*
978 * the error disappeared after reading page by page, or 978 * the error disappeared after reading page by page, or
979 * the area was part of a huge bio and other parts of the 979 * the area was part of a huge bio and other parts of the
980 * bio caused I/O errors, or the block layer merged several 980 * bio caused I/O errors, or the block layer merged several
981 * read requests into one and the error is caused by a 981 * read requests into one and the error is caused by a
982 * different bio (usually one of the two latter cases is 982 * different bio (usually one of the two latter cases is
983 * the cause) 983 * the cause)
984 */ 984 */
985 spin_lock(&sctx->stat_lock); 985 spin_lock(&sctx->stat_lock);
986 sctx->stat.unverified_errors++; 986 sctx->stat.unverified_errors++;
987 sblock_to_check->data_corrected = 1; 987 sblock_to_check->data_corrected = 1;
988 spin_unlock(&sctx->stat_lock); 988 spin_unlock(&sctx->stat_lock);
989 989
990 if (sctx->is_dev_replace) 990 if (sctx->is_dev_replace)
991 scrub_write_block_to_dev_replace(sblock_bad); 991 scrub_write_block_to_dev_replace(sblock_bad);
992 goto out; 992 goto out;
993 } 993 }
994 994
995 if (!sblock_bad->no_io_error_seen) { 995 if (!sblock_bad->no_io_error_seen) {
996 spin_lock(&sctx->stat_lock); 996 spin_lock(&sctx->stat_lock);
997 sctx->stat.read_errors++; 997 sctx->stat.read_errors++;
998 spin_unlock(&sctx->stat_lock); 998 spin_unlock(&sctx->stat_lock);
999 if (__ratelimit(&_rs)) 999 if (__ratelimit(&_rs))
1000 scrub_print_warning("i/o error", sblock_to_check); 1000 scrub_print_warning("i/o error", sblock_to_check);
1001 btrfs_dev_stat_inc_and_print(dev, BTRFS_DEV_STAT_READ_ERRS); 1001 btrfs_dev_stat_inc_and_print(dev, BTRFS_DEV_STAT_READ_ERRS);
1002 } else if (sblock_bad->checksum_error) { 1002 } else if (sblock_bad->checksum_error) {
1003 spin_lock(&sctx->stat_lock); 1003 spin_lock(&sctx->stat_lock);
1004 sctx->stat.csum_errors++; 1004 sctx->stat.csum_errors++;
1005 spin_unlock(&sctx->stat_lock); 1005 spin_unlock(&sctx->stat_lock);
1006 if (__ratelimit(&_rs)) 1006 if (__ratelimit(&_rs))
1007 scrub_print_warning("checksum error", sblock_to_check); 1007 scrub_print_warning("checksum error", sblock_to_check);
1008 btrfs_dev_stat_inc_and_print(dev, 1008 btrfs_dev_stat_inc_and_print(dev,
1009 BTRFS_DEV_STAT_CORRUPTION_ERRS); 1009 BTRFS_DEV_STAT_CORRUPTION_ERRS);
1010 } else if (sblock_bad->header_error) { 1010 } else if (sblock_bad->header_error) {
1011 spin_lock(&sctx->stat_lock); 1011 spin_lock(&sctx->stat_lock);
1012 sctx->stat.verify_errors++; 1012 sctx->stat.verify_errors++;
1013 spin_unlock(&sctx->stat_lock); 1013 spin_unlock(&sctx->stat_lock);
1014 if (__ratelimit(&_rs)) 1014 if (__ratelimit(&_rs))
1015 scrub_print_warning("checksum/header error", 1015 scrub_print_warning("checksum/header error",
1016 sblock_to_check); 1016 sblock_to_check);
1017 if (sblock_bad->generation_error) 1017 if (sblock_bad->generation_error)
1018 btrfs_dev_stat_inc_and_print(dev, 1018 btrfs_dev_stat_inc_and_print(dev,
1019 BTRFS_DEV_STAT_GENERATION_ERRS); 1019 BTRFS_DEV_STAT_GENERATION_ERRS);
1020 else 1020 else
1021 btrfs_dev_stat_inc_and_print(dev, 1021 btrfs_dev_stat_inc_and_print(dev,
1022 BTRFS_DEV_STAT_CORRUPTION_ERRS); 1022 BTRFS_DEV_STAT_CORRUPTION_ERRS);
1023 } 1023 }
1024 1024
1025 if (sctx->readonly) { 1025 if (sctx->readonly) {
1026 ASSERT(!sctx->is_dev_replace); 1026 ASSERT(!sctx->is_dev_replace);
1027 goto out; 1027 goto out;
1028 } 1028 }
1029 1029
1030 if (!is_metadata && !have_csum) { 1030 if (!is_metadata && !have_csum) {
1031 struct scrub_fixup_nodatasum *fixup_nodatasum; 1031 struct scrub_fixup_nodatasum *fixup_nodatasum;
1032 1032
1033 nodatasum_case: 1033 nodatasum_case:
1034 WARN_ON(sctx->is_dev_replace); 1034 WARN_ON(sctx->is_dev_replace);
1035 1035
1036 /* 1036 /*
1037 * !is_metadata and !have_csum, this means that the data 1037 * !is_metadata and !have_csum, this means that the data
1038 * might not be COW'ed, that it might be modified 1038 * might not be COW'ed, that it might be modified
1039 * concurrently. The general strategy to work on the 1039 * concurrently. The general strategy to work on the
1040 * commit root does not help in the case when COW is not 1040 * commit root does not help in the case when COW is not
1041 * used. 1041 * used.
1042 */ 1042 */
1043 fixup_nodatasum = kzalloc(sizeof(*fixup_nodatasum), GFP_NOFS); 1043 fixup_nodatasum = kzalloc(sizeof(*fixup_nodatasum), GFP_NOFS);
1044 if (!fixup_nodatasum) 1044 if (!fixup_nodatasum)
1045 goto did_not_correct_error; 1045 goto did_not_correct_error;
1046 fixup_nodatasum->sctx = sctx; 1046 fixup_nodatasum->sctx = sctx;
1047 fixup_nodatasum->dev = dev; 1047 fixup_nodatasum->dev = dev;
1048 fixup_nodatasum->logical = logical; 1048 fixup_nodatasum->logical = logical;
1049 fixup_nodatasum->root = fs_info->extent_root; 1049 fixup_nodatasum->root = fs_info->extent_root;
1050 fixup_nodatasum->mirror_num = failed_mirror_index + 1; 1050 fixup_nodatasum->mirror_num = failed_mirror_index + 1;
1051 scrub_pending_trans_workers_inc(sctx); 1051 scrub_pending_trans_workers_inc(sctx);
1052 btrfs_init_work(&fixup_nodatasum->work, btrfs_scrub_helper, 1052 btrfs_init_work(&fixup_nodatasum->work, btrfs_scrub_helper,
1053 scrub_fixup_nodatasum, NULL, NULL); 1053 scrub_fixup_nodatasum, NULL, NULL);
1054 btrfs_queue_work(fs_info->scrub_workers, 1054 btrfs_queue_work(fs_info->scrub_workers,
1055 &fixup_nodatasum->work); 1055 &fixup_nodatasum->work);
1056 goto out; 1056 goto out;
1057 } 1057 }
1058 1058
1059 /* 1059 /*
1060 * now build and submit the bios for the other mirrors, check 1060 * now build and submit the bios for the other mirrors, check
1061 * checksums. 1061 * checksums.
1062 * First try to pick the mirror which is completely without I/O 1062 * First try to pick the mirror which is completely without I/O
1063 * errors and also does not have a checksum error. 1063 * errors and also does not have a checksum error.
1064 * If one is found, and if a checksum is present, the full block 1064 * If one is found, and if a checksum is present, the full block
1065 * that is known to contain an error is rewritten. Afterwards 1065 * that is known to contain an error is rewritten. Afterwards
1066 * the block is known to be corrected. 1066 * the block is known to be corrected.
1067 * If a mirror is found which is completely correct, and no 1067 * If a mirror is found which is completely correct, and no
1068 * checksum is present, only those pages are rewritten that had 1068 * checksum is present, only those pages are rewritten that had
1069 * an I/O error in the block to be repaired, since it cannot be 1069 * an I/O error in the block to be repaired, since it cannot be
1070 * determined, which copy of the other pages is better (and it 1070 * determined, which copy of the other pages is better (and it
1071 * could happen otherwise that a correct page would be 1071 * could happen otherwise that a correct page would be
1072 * overwritten by a bad one). 1072 * overwritten by a bad one).
1073 */ 1073 */
1074 for (mirror_index = 0; 1074 for (mirror_index = 0;
1075 mirror_index < BTRFS_MAX_MIRRORS && 1075 mirror_index < BTRFS_MAX_MIRRORS &&
1076 sblocks_for_recheck[mirror_index].page_count > 0; 1076 sblocks_for_recheck[mirror_index].page_count > 0;
1077 mirror_index++) { 1077 mirror_index++) {
1078 struct scrub_block *sblock_other; 1078 struct scrub_block *sblock_other;
1079 1079
1080 if (mirror_index == failed_mirror_index) 1080 if (mirror_index == failed_mirror_index)
1081 continue; 1081 continue;
1082 sblock_other = sblocks_for_recheck + mirror_index; 1082 sblock_other = sblocks_for_recheck + mirror_index;
1083 1083
1084 /* build and submit the bios, check checksums */ 1084 /* build and submit the bios, check checksums */
1085 scrub_recheck_block(fs_info, sblock_other, is_metadata, 1085 scrub_recheck_block(fs_info, sblock_other, is_metadata,
1086 have_csum, csum, generation, 1086 have_csum, csum, generation,
1087 sctx->csum_size, 0); 1087 sctx->csum_size, 0);
1088 1088
1089 if (!sblock_other->header_error && 1089 if (!sblock_other->header_error &&
1090 !sblock_other->checksum_error && 1090 !sblock_other->checksum_error &&
1091 sblock_other->no_io_error_seen) { 1091 sblock_other->no_io_error_seen) {
1092 if (sctx->is_dev_replace) { 1092 if (sctx->is_dev_replace) {
1093 scrub_write_block_to_dev_replace(sblock_other); 1093 scrub_write_block_to_dev_replace(sblock_other);
1094 } else { 1094 } else {
1095 int force_write = is_metadata || have_csum; 1095 int force_write = is_metadata || have_csum;
1096 1096
1097 ret = scrub_repair_block_from_good_copy( 1097 ret = scrub_repair_block_from_good_copy(
1098 sblock_bad, sblock_other, 1098 sblock_bad, sblock_other,
1099 force_write); 1099 force_write);
1100 } 1100 }
1101 if (0 == ret) 1101 if (0 == ret)
1102 goto corrected_error; 1102 goto corrected_error;
1103 } 1103 }
1104 } 1104 }
1105 1105
1106 /* 1106 /*
1107 * for dev_replace, pick good pages and write to the target device. 1107 * for dev_replace, pick good pages and write to the target device.
1108 */ 1108 */
1109 if (sctx->is_dev_replace) { 1109 if (sctx->is_dev_replace) {
1110 success = 1; 1110 success = 1;
1111 for (page_num = 0; page_num < sblock_bad->page_count; 1111 for (page_num = 0; page_num < sblock_bad->page_count;
1112 page_num++) { 1112 page_num++) {
1113 int sub_success; 1113 int sub_success;
1114 1114
1115 sub_success = 0; 1115 sub_success = 0;
1116 for (mirror_index = 0; 1116 for (mirror_index = 0;
1117 mirror_index < BTRFS_MAX_MIRRORS && 1117 mirror_index < BTRFS_MAX_MIRRORS &&
1118 sblocks_for_recheck[mirror_index].page_count > 0; 1118 sblocks_for_recheck[mirror_index].page_count > 0;
1119 mirror_index++) { 1119 mirror_index++) {
1120 struct scrub_block *sblock_other = 1120 struct scrub_block *sblock_other =
1121 sblocks_for_recheck + mirror_index; 1121 sblocks_for_recheck + mirror_index;
1122 struct scrub_page *page_other = 1122 struct scrub_page *page_other =
1123 sblock_other->pagev[page_num]; 1123 sblock_other->pagev[page_num];
1124 1124
1125 if (!page_other->io_error) { 1125 if (!page_other->io_error) {
1126 ret = scrub_write_page_to_dev_replace( 1126 ret = scrub_write_page_to_dev_replace(
1127 sblock_other, page_num); 1127 sblock_other, page_num);
1128 if (ret == 0) { 1128 if (ret == 0) {
1129 /* succeeded for this page */ 1129 /* succeeded for this page */
1130 sub_success = 1; 1130 sub_success = 1;
1131 break; 1131 break;
1132 } else { 1132 } else {
1133 btrfs_dev_replace_stats_inc( 1133 btrfs_dev_replace_stats_inc(
1134 &sctx->dev_root-> 1134 &sctx->dev_root->
1135 fs_info->dev_replace. 1135 fs_info->dev_replace.
1136 num_write_errors); 1136 num_write_errors);
1137 } 1137 }
1138 } 1138 }
1139 } 1139 }
1140 1140
1141 if (!sub_success) { 1141 if (!sub_success) {
1142 /* 1142 /*
1143 * did not find a mirror to fetch the page 1143 * did not find a mirror to fetch the page
1144 * from. scrub_write_page_to_dev_replace() 1144 * from. scrub_write_page_to_dev_replace()
1145 * handles this case (page->io_error), by 1145 * handles this case (page->io_error), by
1146 * filling the block with zeros before 1146 * filling the block with zeros before
1147 * submitting the write request 1147 * submitting the write request
1148 */ 1148 */
1149 success = 0; 1149 success = 0;
1150 ret = scrub_write_page_to_dev_replace( 1150 ret = scrub_write_page_to_dev_replace(
1151 sblock_bad, page_num); 1151 sblock_bad, page_num);
1152 if (ret) 1152 if (ret)
1153 btrfs_dev_replace_stats_inc( 1153 btrfs_dev_replace_stats_inc(
1154 &sctx->dev_root->fs_info-> 1154 &sctx->dev_root->fs_info->
1155 dev_replace.num_write_errors); 1155 dev_replace.num_write_errors);
1156 } 1156 }
1157 } 1157 }
1158 1158
1159 goto out; 1159 goto out;
1160 } 1160 }
1161 1161
1162 /* 1162 /*
1163 * for regular scrub, repair those pages that are errored. 1163 * for regular scrub, repair those pages that are errored.
1164 * In case of I/O errors in the area that is supposed to be 1164 * In case of I/O errors in the area that is supposed to be
1165 * repaired, continue by picking good copies of those pages. 1165 * repaired, continue by picking good copies of those pages.
1166 * Select the good pages from mirrors to rewrite bad pages from 1166 * Select the good pages from mirrors to rewrite bad pages from
1167 * the area to fix. Afterwards verify the checksum of the block 1167 * the area to fix. Afterwards verify the checksum of the block
1168 * that is supposed to be repaired. This verification step is 1168 * that is supposed to be repaired. This verification step is
1169 * only done for the purpose of statistic counting and for the 1169 * only done for the purpose of statistic counting and for the
1170 * final scrub report, whether errors remain. 1170 * final scrub report, whether errors remain.
1171 * A perfect algorithm could make use of the checksum and try 1171 * A perfect algorithm could make use of the checksum and try
1172 * all possible combinations of pages from the different mirrors 1172 * all possible combinations of pages from the different mirrors
1173 * until the checksum verification succeeds. For example, when 1173 * until the checksum verification succeeds. For example, when
1174 * the 2nd page of mirror #1 faces I/O errors, and the 2nd page 1174 * the 2nd page of mirror #1 faces I/O errors, and the 2nd page
1175 * of mirror #2 is readable but the final checksum test fails, 1175 * of mirror #2 is readable but the final checksum test fails,
1176 * then the 2nd page of mirror #3 could be tried, whether now 1176 * then the 2nd page of mirror #3 could be tried, whether now
1177 * the final checksum succeedes. But this would be a rare 1177 * the final checksum succeedes. But this would be a rare
1178 * exception and is therefore not implemented. At least it is 1178 * exception and is therefore not implemented. At least it is
1179 * avoided that the good copy is overwritten. 1179 * avoided that the good copy is overwritten.
1180 * A more useful improvement would be to pick the sectors 1180 * A more useful improvement would be to pick the sectors
1181 * without I/O error based on sector sizes (512 bytes on legacy 1181 * without I/O error based on sector sizes (512 bytes on legacy
1182 * disks) instead of on PAGE_SIZE. Then maybe 512 byte of one 1182 * disks) instead of on PAGE_SIZE. Then maybe 512 byte of one
1183 * mirror could be repaired by taking 512 byte of a different 1183 * mirror could be repaired by taking 512 byte of a different
1184 * mirror, even if other 512 byte sectors in the same PAGE_SIZE 1184 * mirror, even if other 512 byte sectors in the same PAGE_SIZE
1185 * area are unreadable. 1185 * area are unreadable.
1186 */ 1186 */
1187 1187
1188 /* can only fix I/O errors from here on */ 1188 /* can only fix I/O errors from here on */
1189 if (sblock_bad->no_io_error_seen) 1189 if (sblock_bad->no_io_error_seen)
1190 goto did_not_correct_error; 1190 goto did_not_correct_error;
1191 1191
1192 success = 1; 1192 success = 1;
1193 for (page_num = 0; page_num < sblock_bad->page_count; page_num++) { 1193 for (page_num = 0; page_num < sblock_bad->page_count; page_num++) {
1194 struct scrub_page *page_bad = sblock_bad->pagev[page_num]; 1194 struct scrub_page *page_bad = sblock_bad->pagev[page_num];
1195 1195
1196 if (!page_bad->io_error) 1196 if (!page_bad->io_error)
1197 continue; 1197 continue;
1198 1198
1199 for (mirror_index = 0; 1199 for (mirror_index = 0;
1200 mirror_index < BTRFS_MAX_MIRRORS && 1200 mirror_index < BTRFS_MAX_MIRRORS &&
1201 sblocks_for_recheck[mirror_index].page_count > 0; 1201 sblocks_for_recheck[mirror_index].page_count > 0;
1202 mirror_index++) { 1202 mirror_index++) {
1203 struct scrub_block *sblock_other = sblocks_for_recheck + 1203 struct scrub_block *sblock_other = sblocks_for_recheck +
1204 mirror_index; 1204 mirror_index;
1205 struct scrub_page *page_other = sblock_other->pagev[ 1205 struct scrub_page *page_other = sblock_other->pagev[
1206 page_num]; 1206 page_num];
1207 1207
1208 if (!page_other->io_error) { 1208 if (!page_other->io_error) {
1209 ret = scrub_repair_page_from_good_copy( 1209 ret = scrub_repair_page_from_good_copy(
1210 sblock_bad, sblock_other, page_num, 0); 1210 sblock_bad, sblock_other, page_num, 0);
1211 if (0 == ret) { 1211 if (0 == ret) {
1212 page_bad->io_error = 0; 1212 page_bad->io_error = 0;
1213 break; /* succeeded for this page */ 1213 break; /* succeeded for this page */
1214 } 1214 }
1215 } 1215 }
1216 } 1216 }
1217 1217
1218 if (page_bad->io_error) { 1218 if (page_bad->io_error) {
1219 /* did not find a mirror to copy the page from */ 1219 /* did not find a mirror to copy the page from */
1220 success = 0; 1220 success = 0;
1221 } 1221 }
1222 } 1222 }
1223 1223
1224 if (success) { 1224 if (success) {
1225 if (is_metadata || have_csum) { 1225 if (is_metadata || have_csum) {
1226 /* 1226 /*
1227 * need to verify the checksum now that all 1227 * need to verify the checksum now that all
1228 * sectors on disk are repaired (the write 1228 * sectors on disk are repaired (the write
1229 * request for data to be repaired is on its way). 1229 * request for data to be repaired is on its way).
1230 * Just be lazy and use scrub_recheck_block() 1230 * Just be lazy and use scrub_recheck_block()
1231 * which re-reads the data before the checksum 1231 * which re-reads the data before the checksum
1232 * is verified, but most likely the data comes out 1232 * is verified, but most likely the data comes out
1233 * of the page cache. 1233 * of the page cache.
1234 */ 1234 */
1235 scrub_recheck_block(fs_info, sblock_bad, 1235 scrub_recheck_block(fs_info, sblock_bad,
1236 is_metadata, have_csum, csum, 1236 is_metadata, have_csum, csum,
1237 generation, sctx->csum_size, 1); 1237 generation, sctx->csum_size, 1);
1238 if (!sblock_bad->header_error && 1238 if (!sblock_bad->header_error &&
1239 !sblock_bad->checksum_error && 1239 !sblock_bad->checksum_error &&
1240 sblock_bad->no_io_error_seen) 1240 sblock_bad->no_io_error_seen)
1241 goto corrected_error; 1241 goto corrected_error;
1242 else 1242 else
1243 goto did_not_correct_error; 1243 goto did_not_correct_error;
1244 } else { 1244 } else {
1245 corrected_error: 1245 corrected_error:
1246 spin_lock(&sctx->stat_lock); 1246 spin_lock(&sctx->stat_lock);
1247 sctx->stat.corrected_errors++; 1247 sctx->stat.corrected_errors++;
1248 sblock_to_check->data_corrected = 1; 1248 sblock_to_check->data_corrected = 1;
1249 spin_unlock(&sctx->stat_lock); 1249 spin_unlock(&sctx->stat_lock);
1250 printk_ratelimited_in_rcu(KERN_ERR 1250 printk_ratelimited_in_rcu(KERN_ERR
1251 "BTRFS: fixed up error at logical %llu on dev %s\n", 1251 "BTRFS: fixed up error at logical %llu on dev %s\n",
1252 logical, rcu_str_deref(dev->name)); 1252 logical, rcu_str_deref(dev->name));
1253 } 1253 }
1254 } else { 1254 } else {
1255 did_not_correct_error: 1255 did_not_correct_error:
1256 spin_lock(&sctx->stat_lock); 1256 spin_lock(&sctx->stat_lock);
1257 sctx->stat.uncorrectable_errors++; 1257 sctx->stat.uncorrectable_errors++;
1258 spin_unlock(&sctx->stat_lock); 1258 spin_unlock(&sctx->stat_lock);
1259 printk_ratelimited_in_rcu(KERN_ERR 1259 printk_ratelimited_in_rcu(KERN_ERR
1260 "BTRFS: unable to fixup (regular) error at logical %llu on dev %s\n", 1260 "BTRFS: unable to fixup (regular) error at logical %llu on dev %s\n",
1261 logical, rcu_str_deref(dev->name)); 1261 logical, rcu_str_deref(dev->name));
1262 } 1262 }
1263 1263
1264 out: 1264 out:
1265 if (sblocks_for_recheck) { 1265 if (sblocks_for_recheck) {
1266 for (mirror_index = 0; mirror_index < BTRFS_MAX_MIRRORS; 1266 for (mirror_index = 0; mirror_index < BTRFS_MAX_MIRRORS;
1267 mirror_index++) { 1267 mirror_index++) {
1268 struct scrub_block *sblock = sblocks_for_recheck + 1268 struct scrub_block *sblock = sblocks_for_recheck +
1269 mirror_index; 1269 mirror_index;
1270 struct scrub_recover *recover; 1270 struct scrub_recover *recover;
1271 int page_index; 1271 int page_index;
1272 1272
1273 for (page_index = 0; page_index < sblock->page_count; 1273 for (page_index = 0; page_index < sblock->page_count;
1274 page_index++) { 1274 page_index++) {
1275 sblock->pagev[page_index]->sblock = NULL; 1275 sblock->pagev[page_index]->sblock = NULL;
1276 recover = sblock->pagev[page_index]->recover; 1276 recover = sblock->pagev[page_index]->recover;
1277 if (recover) { 1277 if (recover) {
1278 scrub_put_recover(recover); 1278 scrub_put_recover(recover);
1279 sblock->pagev[page_index]->recover = 1279 sblock->pagev[page_index]->recover =
1280 NULL; 1280 NULL;
1281 } 1281 }
1282 scrub_page_put(sblock->pagev[page_index]); 1282 scrub_page_put(sblock->pagev[page_index]);
1283 } 1283 }
1284 } 1284 }
1285 kfree(sblocks_for_recheck); 1285 kfree(sblocks_for_recheck);
1286 } 1286 }
1287 1287
1288 return 0; 1288 return 0;
1289 } 1289 }
1290 1290
1291 static inline int scrub_nr_raid_mirrors(struct btrfs_bio *bbio, u64 *raid_map) 1291 static inline int scrub_nr_raid_mirrors(struct btrfs_bio *bbio, u64 *raid_map)
1292 { 1292 {
1293 if (raid_map) { 1293 if (raid_map) {
1294 if (raid_map[bbio->num_stripes - 1] == RAID6_Q_STRIPE) 1294 if (raid_map[bbio->num_stripes - 1] == RAID6_Q_STRIPE)
1295 return 3; 1295 return 3;
1296 else 1296 else
1297 return 2; 1297 return 2;
1298 } else { 1298 } else {
1299 return (int)bbio->num_stripes; 1299 return (int)bbio->num_stripes;
1300 } 1300 }
1301 } 1301 }
1302 1302
1303 static inline void scrub_stripe_index_and_offset(u64 logical, u64 *raid_map, 1303 static inline void scrub_stripe_index_and_offset(u64 logical, u64 *raid_map,
1304 u64 mapped_length, 1304 u64 mapped_length,
1305 int nstripes, int mirror, 1305 int nstripes, int mirror,
1306 int *stripe_index, 1306 int *stripe_index,
1307 u64 *stripe_offset) 1307 u64 *stripe_offset)
1308 { 1308 {
1309 int i; 1309 int i;
1310 1310
1311 if (raid_map) { 1311 if (raid_map) {
1312 /* RAID5/6 */ 1312 /* RAID5/6 */
1313 for (i = 0; i < nstripes; i++) { 1313 for (i = 0; i < nstripes; i++) {
1314 if (raid_map[i] == RAID6_Q_STRIPE || 1314 if (raid_map[i] == RAID6_Q_STRIPE ||
1315 raid_map[i] == RAID5_P_STRIPE) 1315 raid_map[i] == RAID5_P_STRIPE)
1316 continue; 1316 continue;
1317 1317
1318 if (logical >= raid_map[i] && 1318 if (logical >= raid_map[i] &&
1319 logical < raid_map[i] + mapped_length) 1319 logical < raid_map[i] + mapped_length)
1320 break; 1320 break;
1321 } 1321 }
1322 1322
1323 *stripe_index = i; 1323 *stripe_index = i;
1324 *stripe_offset = logical - raid_map[i]; 1324 *stripe_offset = logical - raid_map[i];
1325 } else { 1325 } else {
1326 /* The other RAID type */ 1326 /* The other RAID type */
1327 *stripe_index = mirror; 1327 *stripe_index = mirror;
1328 *stripe_offset = 0; 1328 *stripe_offset = 0;
1329 } 1329 }
1330 } 1330 }
1331 1331
1332 static int scrub_setup_recheck_block(struct scrub_ctx *sctx, 1332 static int scrub_setup_recheck_block(struct scrub_ctx *sctx,
1333 struct btrfs_fs_info *fs_info, 1333 struct btrfs_fs_info *fs_info,
1334 struct scrub_block *original_sblock, 1334 struct scrub_block *original_sblock,
1335 u64 length, u64 logical, 1335 u64 length, u64 logical,
1336 struct scrub_block *sblocks_for_recheck) 1336 struct scrub_block *sblocks_for_recheck)
1337 { 1337 {
1338 struct scrub_recover *recover; 1338 struct scrub_recover *recover;
1339 struct btrfs_bio *bbio; 1339 struct btrfs_bio *bbio;
1340 u64 *raid_map; 1340 u64 *raid_map;
1341 u64 sublen; 1341 u64 sublen;
1342 u64 mapped_length; 1342 u64 mapped_length;
1343 u64 stripe_offset; 1343 u64 stripe_offset;
1344 int stripe_index; 1344 int stripe_index;
1345 int page_index; 1345 int page_index;
1346 int mirror_index; 1346 int mirror_index;
1347 int nmirrors; 1347 int nmirrors;
1348 int ret; 1348 int ret;
1349 1349
1350 /* 1350 /*
1351 * note: the two members ref_count and outstanding_pages 1351 * note: the two members ref_count and outstanding_pages
1352 * are not used (and not set) in the blocks that are used for 1352 * are not used (and not set) in the blocks that are used for
1353 * the recheck procedure 1353 * the recheck procedure
1354 */ 1354 */
1355 1355
1356 page_index = 0; 1356 page_index = 0;
1357 while (length > 0) { 1357 while (length > 0) {
1358 sublen = min_t(u64, length, PAGE_SIZE); 1358 sublen = min_t(u64, length, PAGE_SIZE);
1359 mapped_length = sublen; 1359 mapped_length = sublen;
1360 bbio = NULL; 1360 bbio = NULL;
1361 raid_map = NULL; 1361 raid_map = NULL;
1362 1362
1363 /* 1363 /*
1364 * with a length of PAGE_SIZE, each returned stripe 1364 * with a length of PAGE_SIZE, each returned stripe
1365 * represents one mirror 1365 * represents one mirror
1366 */ 1366 */
1367 ret = btrfs_map_sblock(fs_info, REQ_GET_READ_MIRRORS, logical, 1367 ret = btrfs_map_sblock(fs_info, REQ_GET_READ_MIRRORS, logical,
1368 &mapped_length, &bbio, 0, &raid_map); 1368 &mapped_length, &bbio, 0, &raid_map);
1369 if (ret || !bbio || mapped_length < sublen) { 1369 if (ret || !bbio || mapped_length < sublen) {
1370 kfree(bbio); 1370 kfree(bbio);
1371 kfree(raid_map); 1371 kfree(raid_map);
1372 return -EIO; 1372 return -EIO;
1373 } 1373 }
1374 1374
1375 recover = kzalloc(sizeof(struct scrub_recover), GFP_NOFS); 1375 recover = kzalloc(sizeof(struct scrub_recover), GFP_NOFS);
1376 if (!recover) { 1376 if (!recover) {
1377 kfree(bbio); 1377 kfree(bbio);
1378 kfree(raid_map); 1378 kfree(raid_map);
1379 return -ENOMEM; 1379 return -ENOMEM;
1380 } 1380 }
1381 1381
1382 atomic_set(&recover->refs, 1); 1382 atomic_set(&recover->refs, 1);
1383 recover->bbio = bbio; 1383 recover->bbio = bbio;
1384 recover->raid_map = raid_map; 1384 recover->raid_map = raid_map;
1385 recover->map_length = mapped_length; 1385 recover->map_length = mapped_length;
1386 1386
1387 BUG_ON(page_index >= SCRUB_PAGES_PER_RD_BIO); 1387 BUG_ON(page_index >= SCRUB_PAGES_PER_RD_BIO);
1388 1388
1389 nmirrors = scrub_nr_raid_mirrors(bbio, raid_map); 1389 nmirrors = scrub_nr_raid_mirrors(bbio, raid_map);
1390 for (mirror_index = 0; mirror_index < nmirrors; 1390 for (mirror_index = 0; mirror_index < nmirrors;
1391 mirror_index++) { 1391 mirror_index++) {
1392 struct scrub_block *sblock; 1392 struct scrub_block *sblock;
1393 struct scrub_page *page; 1393 struct scrub_page *page;
1394 1394
1395 if (mirror_index >= BTRFS_MAX_MIRRORS) 1395 if (mirror_index >= BTRFS_MAX_MIRRORS)
1396 continue; 1396 continue;
1397 1397
1398 sblock = sblocks_for_recheck + mirror_index; 1398 sblock = sblocks_for_recheck + mirror_index;
1399 sblock->sctx = sctx; 1399 sblock->sctx = sctx;
1400 page = kzalloc(sizeof(*page), GFP_NOFS); 1400 page = kzalloc(sizeof(*page), GFP_NOFS);
1401 if (!page) { 1401 if (!page) {
1402 leave_nomem: 1402 leave_nomem:
1403 spin_lock(&sctx->stat_lock); 1403 spin_lock(&sctx->stat_lock);
1404 sctx->stat.malloc_errors++; 1404 sctx->stat.malloc_errors++;
1405 spin_unlock(&sctx->stat_lock); 1405 spin_unlock(&sctx->stat_lock);
1406 scrub_put_recover(recover); 1406 scrub_put_recover(recover);
1407 return -ENOMEM; 1407 return -ENOMEM;
1408 } 1408 }
1409 scrub_page_get(page); 1409 scrub_page_get(page);
1410 sblock->pagev[page_index] = page; 1410 sblock->pagev[page_index] = page;
1411 page->logical = logical; 1411 page->logical = logical;
1412 1412
1413 scrub_stripe_index_and_offset(logical, raid_map, 1413 scrub_stripe_index_and_offset(logical, raid_map,
1414 mapped_length, 1414 mapped_length,
1415 bbio->num_stripes, 1415 bbio->num_stripes,
1416 mirror_index, 1416 mirror_index,
1417 &stripe_index, 1417 &stripe_index,
1418 &stripe_offset); 1418 &stripe_offset);
1419 page->physical = bbio->stripes[stripe_index].physical + 1419 page->physical = bbio->stripes[stripe_index].physical +
1420 stripe_offset; 1420 stripe_offset;
1421 page->dev = bbio->stripes[stripe_index].dev; 1421 page->dev = bbio->stripes[stripe_index].dev;
1422 1422
1423 BUG_ON(page_index >= original_sblock->page_count); 1423 BUG_ON(page_index >= original_sblock->page_count);
1424 page->physical_for_dev_replace = 1424 page->physical_for_dev_replace =
1425 original_sblock->pagev[page_index]-> 1425 original_sblock->pagev[page_index]->
1426 physical_for_dev_replace; 1426 physical_for_dev_replace;
1427 /* for missing devices, dev->bdev is NULL */ 1427 /* for missing devices, dev->bdev is NULL */
1428 page->mirror_num = mirror_index + 1; 1428 page->mirror_num = mirror_index + 1;
1429 sblock->page_count++; 1429 sblock->page_count++;
1430 page->page = alloc_page(GFP_NOFS); 1430 page->page = alloc_page(GFP_NOFS);
1431 if (!page->page) 1431 if (!page->page)
1432 goto leave_nomem; 1432 goto leave_nomem;
1433 1433
1434 scrub_get_recover(recover); 1434 scrub_get_recover(recover);
1435 page->recover = recover; 1435 page->recover = recover;
1436 } 1436 }
1437 scrub_put_recover(recover); 1437 scrub_put_recover(recover);
1438 length -= sublen; 1438 length -= sublen;
1439 logical += sublen; 1439 logical += sublen;
1440 page_index++; 1440 page_index++;
1441 } 1441 }
1442 1442
1443 return 0; 1443 return 0;
1444 } 1444 }
1445 1445
1446 struct scrub_bio_ret { 1446 struct scrub_bio_ret {
1447 struct completion event; 1447 struct completion event;
1448 int error; 1448 int error;
1449 }; 1449 };
1450 1450
1451 static void scrub_bio_wait_endio(struct bio *bio, int error) 1451 static void scrub_bio_wait_endio(struct bio *bio, int error)
1452 { 1452 {
1453 struct scrub_bio_ret *ret = bio->bi_private; 1453 struct scrub_bio_ret *ret = bio->bi_private;
1454 1454
1455 ret->error = error; 1455 ret->error = error;
1456 complete(&ret->event); 1456 complete(&ret->event);
1457 } 1457 }
1458 1458
1459 static inline int scrub_is_page_on_raid56(struct scrub_page *page) 1459 static inline int scrub_is_page_on_raid56(struct scrub_page *page)
1460 { 1460 {
1461 return page->recover && page->recover->raid_map; 1461 return page->recover && page->recover->raid_map;
1462 } 1462 }
1463 1463
1464 static int scrub_submit_raid56_bio_wait(struct btrfs_fs_info *fs_info, 1464 static int scrub_submit_raid56_bio_wait(struct btrfs_fs_info *fs_info,
1465 struct bio *bio, 1465 struct bio *bio,
1466 struct scrub_page *page) 1466 struct scrub_page *page)
1467 { 1467 {
1468 struct scrub_bio_ret done; 1468 struct scrub_bio_ret done;
1469 int ret; 1469 int ret;
1470 1470
1471 init_completion(&done.event); 1471 init_completion(&done.event);
1472 done.error = 0; 1472 done.error = 0;
1473 bio->bi_iter.bi_sector = page->logical >> 9; 1473 bio->bi_iter.bi_sector = page->logical >> 9;
1474 bio->bi_private = &done; 1474 bio->bi_private = &done;
1475 bio->bi_end_io = scrub_bio_wait_endio; 1475 bio->bi_end_io = scrub_bio_wait_endio;
1476 1476
1477 ret = raid56_parity_recover(fs_info->fs_root, bio, page->recover->bbio, 1477 ret = raid56_parity_recover(fs_info->fs_root, bio, page->recover->bbio,
1478 page->recover->raid_map, 1478 page->recover->raid_map,
1479 page->recover->map_length, 1479 page->recover->map_length,
1480 page->mirror_num, 0); 1480 page->mirror_num, 0);
1481 if (ret) 1481 if (ret)
1482 return ret; 1482 return ret;
1483 1483
1484 wait_for_completion(&done.event); 1484 wait_for_completion(&done.event);
1485 if (done.error) 1485 if (done.error)
1486 return -EIO; 1486 return -EIO;
1487 1487
1488 return 0; 1488 return 0;
1489 } 1489 }
1490 1490
1491 /* 1491 /*
1492 * this function will check the on disk data for checksum errors, header 1492 * this function will check the on disk data for checksum errors, header
1493 * errors and read I/O errors. If any I/O errors happen, the exact pages 1493 * errors and read I/O errors. If any I/O errors happen, the exact pages
1494 * which are errored are marked as being bad. The goal is to enable scrub 1494 * which are errored are marked as being bad. The goal is to enable scrub
1495 * to take those pages that are not errored from all the mirrors so that 1495 * to take those pages that are not errored from all the mirrors so that
1496 * the pages that are errored in the just handled mirror can be repaired. 1496 * the pages that are errored in the just handled mirror can be repaired.
1497 */ 1497 */
1498 static void scrub_recheck_block(struct btrfs_fs_info *fs_info, 1498 static void scrub_recheck_block(struct btrfs_fs_info *fs_info,
1499 struct scrub_block *sblock, int is_metadata, 1499 struct scrub_block *sblock, int is_metadata,
1500 int have_csum, u8 *csum, u64 generation, 1500 int have_csum, u8 *csum, u64 generation,
1501 u16 csum_size, int retry_failed_mirror) 1501 u16 csum_size, int retry_failed_mirror)
1502 { 1502 {
1503 int page_num; 1503 int page_num;
1504 1504
1505 sblock->no_io_error_seen = 1; 1505 sblock->no_io_error_seen = 1;
1506 sblock->header_error = 0; 1506 sblock->header_error = 0;
1507 sblock->checksum_error = 0; 1507 sblock->checksum_error = 0;
1508 1508
1509 for (page_num = 0; page_num < sblock->page_count; page_num++) { 1509 for (page_num = 0; page_num < sblock->page_count; page_num++) {
1510 struct bio *bio; 1510 struct bio *bio;
1511 struct scrub_page *page = sblock->pagev[page_num]; 1511 struct scrub_page *page = sblock->pagev[page_num];
1512 1512
1513 if (page->dev->bdev == NULL) { 1513 if (page->dev->bdev == NULL) {
1514 page->io_error = 1; 1514 page->io_error = 1;
1515 sblock->no_io_error_seen = 0; 1515 sblock->no_io_error_seen = 0;
1516 continue; 1516 continue;
1517 } 1517 }
1518 1518
1519 WARN_ON(!page->page); 1519 WARN_ON(!page->page);
1520 bio = btrfs_io_bio_alloc(GFP_NOFS, 1); 1520 bio = btrfs_io_bio_alloc(GFP_NOFS, 1);
1521 if (!bio) { 1521 if (!bio) {
1522 page->io_error = 1; 1522 page->io_error = 1;
1523 sblock->no_io_error_seen = 0; 1523 sblock->no_io_error_seen = 0;
1524 continue; 1524 continue;
1525 } 1525 }
1526 bio->bi_bdev = page->dev->bdev; 1526 bio->bi_bdev = page->dev->bdev;
1527 1527
1528 bio_add_page(bio, page->page, PAGE_SIZE, 0); 1528 bio_add_page(bio, page->page, PAGE_SIZE, 0);
1529 if (!retry_failed_mirror && scrub_is_page_on_raid56(page)) { 1529 if (!retry_failed_mirror && scrub_is_page_on_raid56(page)) {
1530 if (scrub_submit_raid56_bio_wait(fs_info, bio, page)) 1530 if (scrub_submit_raid56_bio_wait(fs_info, bio, page))
1531 sblock->no_io_error_seen = 0; 1531 sblock->no_io_error_seen = 0;
1532 } else { 1532 } else {
1533 bio->bi_iter.bi_sector = page->physical >> 9; 1533 bio->bi_iter.bi_sector = page->physical >> 9;
1534 1534
1535 if (btrfsic_submit_bio_wait(READ, bio)) 1535 if (btrfsic_submit_bio_wait(READ, bio))
1536 sblock->no_io_error_seen = 0; 1536 sblock->no_io_error_seen = 0;
1537 } 1537 }
1538 1538
1539 bio_put(bio); 1539 bio_put(bio);
1540 } 1540 }
1541 1541
1542 if (sblock->no_io_error_seen) 1542 if (sblock->no_io_error_seen)
1543 scrub_recheck_block_checksum(fs_info, sblock, is_metadata, 1543 scrub_recheck_block_checksum(fs_info, sblock, is_metadata,
1544 have_csum, csum, generation, 1544 have_csum, csum, generation,
1545 csum_size); 1545 csum_size);
1546 1546
1547 return; 1547 return;
1548 } 1548 }
1549 1549
1550 static inline int scrub_check_fsid(u8 fsid[], 1550 static inline int scrub_check_fsid(u8 fsid[],
1551 struct scrub_page *spage) 1551 struct scrub_page *spage)
1552 { 1552 {
1553 struct btrfs_fs_devices *fs_devices = spage->dev->fs_devices; 1553 struct btrfs_fs_devices *fs_devices = spage->dev->fs_devices;
1554 int ret; 1554 int ret;
1555 1555
1556 ret = memcmp(fsid, fs_devices->fsid, BTRFS_UUID_SIZE); 1556 ret = memcmp(fsid, fs_devices->fsid, BTRFS_UUID_SIZE);
1557 return !ret; 1557 return !ret;
1558 } 1558 }
1559 1559
1560 static void scrub_recheck_block_checksum(struct btrfs_fs_info *fs_info, 1560 static void scrub_recheck_block_checksum(struct btrfs_fs_info *fs_info,
1561 struct scrub_block *sblock, 1561 struct scrub_block *sblock,
1562 int is_metadata, int have_csum, 1562 int is_metadata, int have_csum,
1563 const u8 *csum, u64 generation, 1563 const u8 *csum, u64 generation,
1564 u16 csum_size) 1564 u16 csum_size)
1565 { 1565 {
1566 int page_num; 1566 int page_num;
1567 u8 calculated_csum[BTRFS_CSUM_SIZE]; 1567 u8 calculated_csum[BTRFS_CSUM_SIZE];
1568 u32 crc = ~(u32)0; 1568 u32 crc = ~(u32)0;
1569 void *mapped_buffer; 1569 void *mapped_buffer;
1570 1570
1571 WARN_ON(!sblock->pagev[0]->page); 1571 WARN_ON(!sblock->pagev[0]->page);
1572 if (is_metadata) { 1572 if (is_metadata) {
1573 struct btrfs_header *h; 1573 struct btrfs_header *h;
1574 1574
1575 mapped_buffer = kmap_atomic(sblock->pagev[0]->page); 1575 mapped_buffer = kmap_atomic(sblock->pagev[0]->page);
1576 h = (struct btrfs_header *)mapped_buffer; 1576 h = (struct btrfs_header *)mapped_buffer;
1577 1577
1578 if (sblock->pagev[0]->logical != btrfs_stack_header_bytenr(h) || 1578 if (sblock->pagev[0]->logical != btrfs_stack_header_bytenr(h) ||
1579 !scrub_check_fsid(h->fsid, sblock->pagev[0]) || 1579 !scrub_check_fsid(h->fsid, sblock->pagev[0]) ||
1580 memcmp(h->chunk_tree_uuid, fs_info->chunk_tree_uuid, 1580 memcmp(h->chunk_tree_uuid, fs_info->chunk_tree_uuid,
1581 BTRFS_UUID_SIZE)) { 1581 BTRFS_UUID_SIZE)) {
1582 sblock->header_error = 1; 1582 sblock->header_error = 1;
1583 } else if (generation != btrfs_stack_header_generation(h)) { 1583 } else if (generation != btrfs_stack_header_generation(h)) {
1584 sblock->header_error = 1; 1584 sblock->header_error = 1;
1585 sblock->generation_error = 1; 1585 sblock->generation_error = 1;
1586 } 1586 }
1587 csum = h->csum; 1587 csum = h->csum;
1588 } else { 1588 } else {
1589 if (!have_csum) 1589 if (!have_csum)
1590 return; 1590 return;
1591 1591
1592 mapped_buffer = kmap_atomic(sblock->pagev[0]->page); 1592 mapped_buffer = kmap_atomic(sblock->pagev[0]->page);
1593 } 1593 }
1594 1594
1595 for (page_num = 0;;) { 1595 for (page_num = 0;;) {
1596 if (page_num == 0 && is_metadata) 1596 if (page_num == 0 && is_metadata)
1597 crc = btrfs_csum_data( 1597 crc = btrfs_csum_data(
1598 ((u8 *)mapped_buffer) + BTRFS_CSUM_SIZE, 1598 ((u8 *)mapped_buffer) + BTRFS_CSUM_SIZE,
1599 crc, PAGE_SIZE - BTRFS_CSUM_SIZE); 1599 crc, PAGE_SIZE - BTRFS_CSUM_SIZE);
1600 else 1600 else
1601 crc = btrfs_csum_data(mapped_buffer, crc, PAGE_SIZE); 1601 crc = btrfs_csum_data(mapped_buffer, crc, PAGE_SIZE);
1602 1602
1603 kunmap_atomic(mapped_buffer); 1603 kunmap_atomic(mapped_buffer);
1604 page_num++; 1604 page_num++;
1605 if (page_num >= sblock->page_count) 1605 if (page_num >= sblock->page_count)
1606 break; 1606 break;
1607 WARN_ON(!sblock->pagev[page_num]->page); 1607 WARN_ON(!sblock->pagev[page_num]->page);
1608 1608
1609 mapped_buffer = kmap_atomic(sblock->pagev[page_num]->page); 1609 mapped_buffer = kmap_atomic(sblock->pagev[page_num]->page);
1610 } 1610 }
1611 1611
1612 btrfs_csum_final(crc, calculated_csum); 1612 btrfs_csum_final(crc, calculated_csum);
1613 if (memcmp(calculated_csum, csum, csum_size)) 1613 if (memcmp(calculated_csum, csum, csum_size))
1614 sblock->checksum_error = 1; 1614 sblock->checksum_error = 1;
1615 } 1615 }
1616 1616
1617 static int scrub_repair_block_from_good_copy(struct scrub_block *sblock_bad, 1617 static int scrub_repair_block_from_good_copy(struct scrub_block *sblock_bad,
1618 struct scrub_block *sblock_good, 1618 struct scrub_block *sblock_good,
1619 int force_write) 1619 int force_write)
1620 { 1620 {
1621 int page_num; 1621 int page_num;
1622 int ret = 0; 1622 int ret = 0;
1623 1623
1624 for (page_num = 0; page_num < sblock_bad->page_count; page_num++) { 1624 for (page_num = 0; page_num < sblock_bad->page_count; page_num++) {
1625 int ret_sub; 1625 int ret_sub;
1626 1626
1627 ret_sub = scrub_repair_page_from_good_copy(sblock_bad, 1627 ret_sub = scrub_repair_page_from_good_copy(sblock_bad,
1628 sblock_good, 1628 sblock_good,
1629 page_num, 1629 page_num,
1630 force_write); 1630 force_write);
1631 if (ret_sub) 1631 if (ret_sub)
1632 ret = ret_sub; 1632 ret = ret_sub;
1633 } 1633 }
1634 1634
1635 return ret; 1635 return ret;
1636 } 1636 }
1637 1637
1638 static int scrub_repair_page_from_good_copy(struct scrub_block *sblock_bad, 1638 static int scrub_repair_page_from_good_copy(struct scrub_block *sblock_bad,
1639 struct scrub_block *sblock_good, 1639 struct scrub_block *sblock_good,
1640 int page_num, int force_write) 1640 int page_num, int force_write)
1641 { 1641 {
1642 struct scrub_page *page_bad = sblock_bad->pagev[page_num]; 1642 struct scrub_page *page_bad = sblock_bad->pagev[page_num];
1643 struct scrub_page *page_good = sblock_good->pagev[page_num]; 1643 struct scrub_page *page_good = sblock_good->pagev[page_num];
1644 1644
1645 BUG_ON(page_bad->page == NULL); 1645 BUG_ON(page_bad->page == NULL);
1646 BUG_ON(page_good->page == NULL); 1646 BUG_ON(page_good->page == NULL);
1647 if (force_write || sblock_bad->header_error || 1647 if (force_write || sblock_bad->header_error ||
1648 sblock_bad->checksum_error || page_bad->io_error) { 1648 sblock_bad->checksum_error || page_bad->io_error) {
1649 struct bio *bio; 1649 struct bio *bio;
1650 int ret; 1650 int ret;
1651 1651
1652 if (!page_bad->dev->bdev) { 1652 if (!page_bad->dev->bdev) {
1653 printk_ratelimited(KERN_WARNING "BTRFS: " 1653 printk_ratelimited(KERN_WARNING "BTRFS: "
1654 "scrub_repair_page_from_good_copy(bdev == NULL) " 1654 "scrub_repair_page_from_good_copy(bdev == NULL) "
1655 "is unexpected!\n"); 1655 "is unexpected!\n");
1656 return -EIO; 1656 return -EIO;
1657 } 1657 }
1658 1658
1659 bio = btrfs_io_bio_alloc(GFP_NOFS, 1); 1659 bio = btrfs_io_bio_alloc(GFP_NOFS, 1);
1660 if (!bio) 1660 if (!bio)
1661 return -EIO; 1661 return -EIO;
1662 bio->bi_bdev = page_bad->dev->bdev; 1662 bio->bi_bdev = page_bad->dev->bdev;
1663 bio->bi_iter.bi_sector = page_bad->physical >> 9; 1663 bio->bi_iter.bi_sector = page_bad->physical >> 9;
1664 1664
1665 ret = bio_add_page(bio, page_good->page, PAGE_SIZE, 0); 1665 ret = bio_add_page(bio, page_good->page, PAGE_SIZE, 0);
1666 if (PAGE_SIZE != ret) { 1666 if (PAGE_SIZE != ret) {
1667 bio_put(bio); 1667 bio_put(bio);
1668 return -EIO; 1668 return -EIO;
1669 } 1669 }
1670 1670
1671 if (btrfsic_submit_bio_wait(WRITE, bio)) { 1671 if (btrfsic_submit_bio_wait(WRITE, bio)) {
1672 btrfs_dev_stat_inc_and_print(page_bad->dev, 1672 btrfs_dev_stat_inc_and_print(page_bad->dev,
1673 BTRFS_DEV_STAT_WRITE_ERRS); 1673 BTRFS_DEV_STAT_WRITE_ERRS);
1674 btrfs_dev_replace_stats_inc( 1674 btrfs_dev_replace_stats_inc(
1675 &sblock_bad->sctx->dev_root->fs_info-> 1675 &sblock_bad->sctx->dev_root->fs_info->
1676 dev_replace.num_write_errors); 1676 dev_replace.num_write_errors);
1677 bio_put(bio); 1677 bio_put(bio);
1678 return -EIO; 1678 return -EIO;
1679 } 1679 }
1680 bio_put(bio); 1680 bio_put(bio);
1681 } 1681 }
1682 1682
1683 return 0; 1683 return 0;
1684 } 1684 }
1685 1685
1686 static void scrub_write_block_to_dev_replace(struct scrub_block *sblock) 1686 static void scrub_write_block_to_dev_replace(struct scrub_block *sblock)
1687 { 1687 {
1688 int page_num; 1688 int page_num;
1689 1689
1690 /* 1690 /*
1691 * This block is used for the check of the parity on the source device, 1691 * This block is used for the check of the parity on the source device,
1692 * so the data needn't be written into the destination device. 1692 * so the data needn't be written into the destination device.
1693 */ 1693 */
1694 if (sblock->sparity) 1694 if (sblock->sparity)
1695 return; 1695 return;
1696 1696
1697 for (page_num = 0; page_num < sblock->page_count; page_num++) { 1697 for (page_num = 0; page_num < sblock->page_count; page_num++) {
1698 int ret; 1698 int ret;
1699 1699
1700 ret = scrub_write_page_to_dev_replace(sblock, page_num); 1700 ret = scrub_write_page_to_dev_replace(sblock, page_num);
1701 if (ret) 1701 if (ret)
1702 btrfs_dev_replace_stats_inc( 1702 btrfs_dev_replace_stats_inc(
1703 &sblock->sctx->dev_root->fs_info->dev_replace. 1703 &sblock->sctx->dev_root->fs_info->dev_replace.
1704 num_write_errors); 1704 num_write_errors);
1705 } 1705 }
1706 } 1706 }
1707 1707
1708 static int scrub_write_page_to_dev_replace(struct scrub_block *sblock, 1708 static int scrub_write_page_to_dev_replace(struct scrub_block *sblock,
1709 int page_num) 1709 int page_num)
1710 { 1710 {
1711 struct scrub_page *spage = sblock->pagev[page_num]; 1711 struct scrub_page *spage = sblock->pagev[page_num];
1712 1712
1713 BUG_ON(spage->page == NULL); 1713 BUG_ON(spage->page == NULL);
1714 if (spage->io_error) { 1714 if (spage->io_error) {
1715 void *mapped_buffer = kmap_atomic(spage->page); 1715 void *mapped_buffer = kmap_atomic(spage->page);
1716 1716
1717 memset(mapped_buffer, 0, PAGE_CACHE_SIZE); 1717 memset(mapped_buffer, 0, PAGE_CACHE_SIZE);
1718 flush_dcache_page(spage->page); 1718 flush_dcache_page(spage->page);
1719 kunmap_atomic(mapped_buffer); 1719 kunmap_atomic(mapped_buffer);
1720 } 1720 }
1721 return scrub_add_page_to_wr_bio(sblock->sctx, spage); 1721 return scrub_add_page_to_wr_bio(sblock->sctx, spage);
1722 } 1722 }
1723 1723
1724 static int scrub_add_page_to_wr_bio(struct scrub_ctx *sctx, 1724 static int scrub_add_page_to_wr_bio(struct scrub_ctx *sctx,
1725 struct scrub_page *spage) 1725 struct scrub_page *spage)
1726 { 1726 {
1727 struct scrub_wr_ctx *wr_ctx = &sctx->wr_ctx; 1727 struct scrub_wr_ctx *wr_ctx = &sctx->wr_ctx;
1728 struct scrub_bio *sbio; 1728 struct scrub_bio *sbio;
1729 int ret; 1729 int ret;
1730 1730
1731 mutex_lock(&wr_ctx->wr_lock); 1731 mutex_lock(&wr_ctx->wr_lock);
1732 again: 1732 again:
1733 if (!wr_ctx->wr_curr_bio) { 1733 if (!wr_ctx->wr_curr_bio) {
1734 wr_ctx->wr_curr_bio = kzalloc(sizeof(*wr_ctx->wr_curr_bio), 1734 wr_ctx->wr_curr_bio = kzalloc(sizeof(*wr_ctx->wr_curr_bio),
1735 GFP_NOFS); 1735 GFP_NOFS);
1736 if (!wr_ctx->wr_curr_bio) { 1736 if (!wr_ctx->wr_curr_bio) {
1737 mutex_unlock(&wr_ctx->wr_lock); 1737 mutex_unlock(&wr_ctx->wr_lock);
1738 return -ENOMEM; 1738 return -ENOMEM;
1739 } 1739 }
1740 wr_ctx->wr_curr_bio->sctx = sctx; 1740 wr_ctx->wr_curr_bio->sctx = sctx;
1741 wr_ctx->wr_curr_bio->page_count = 0; 1741 wr_ctx->wr_curr_bio->page_count = 0;
1742 } 1742 }
1743 sbio = wr_ctx->wr_curr_bio; 1743 sbio = wr_ctx->wr_curr_bio;
1744 if (sbio->page_count == 0) { 1744 if (sbio->page_count == 0) {
1745 struct bio *bio; 1745 struct bio *bio;
1746 1746
1747 sbio->physical = spage->physical_for_dev_replace; 1747 sbio->physical = spage->physical_for_dev_replace;
1748 sbio->logical = spage->logical; 1748 sbio->logical = spage->logical;
1749 sbio->dev = wr_ctx->tgtdev; 1749 sbio->dev = wr_ctx->tgtdev;
1750 bio = sbio->bio; 1750 bio = sbio->bio;
1751 if (!bio) { 1751 if (!bio) {
1752 bio = btrfs_io_bio_alloc(GFP_NOFS, wr_ctx->pages_per_wr_bio); 1752 bio = btrfs_io_bio_alloc(GFP_NOFS, wr_ctx->pages_per_wr_bio);
1753 if (!bio) { 1753 if (!bio) {
1754 mutex_unlock(&wr_ctx->wr_lock); 1754 mutex_unlock(&wr_ctx->wr_lock);
1755 return -ENOMEM; 1755 return -ENOMEM;
1756 } 1756 }
1757 sbio->bio = bio; 1757 sbio->bio = bio;
1758 } 1758 }
1759 1759
1760 bio->bi_private = sbio; 1760 bio->bi_private = sbio;
1761 bio->bi_end_io = scrub_wr_bio_end_io; 1761 bio->bi_end_io = scrub_wr_bio_end_io;
1762 bio->bi_bdev = sbio->dev->bdev; 1762 bio->bi_bdev = sbio->dev->bdev;
1763 bio->bi_iter.bi_sector = sbio->physical >> 9; 1763 bio->bi_iter.bi_sector = sbio->physical >> 9;
1764 sbio->err = 0; 1764 sbio->err = 0;
1765 } else if (sbio->physical + sbio->page_count * PAGE_SIZE != 1765 } else if (sbio->physical + sbio->page_count * PAGE_SIZE !=
1766 spage->physical_for_dev_replace || 1766 spage->physical_for_dev_replace ||
1767 sbio->logical + sbio->page_count * PAGE_SIZE != 1767 sbio->logical + sbio->page_count * PAGE_SIZE !=
1768 spage->logical) { 1768 spage->logical) {
1769 scrub_wr_submit(sctx); 1769 scrub_wr_submit(sctx);
1770 goto again; 1770 goto again;
1771 } 1771 }
1772 1772
1773 ret = bio_add_page(sbio->bio, spage->page, PAGE_SIZE, 0); 1773 ret = bio_add_page(sbio->bio, spage->page, PAGE_SIZE, 0);
1774 if (ret != PAGE_SIZE) { 1774 if (ret != PAGE_SIZE) {
1775 if (sbio->page_count < 1) { 1775 if (sbio->page_count < 1) {
1776 bio_put(sbio->bio); 1776 bio_put(sbio->bio);
1777 sbio->bio = NULL; 1777 sbio->bio = NULL;
1778 mutex_unlock(&wr_ctx->wr_lock); 1778 mutex_unlock(&wr_ctx->wr_lock);
1779 return -EIO; 1779 return -EIO;
1780 } 1780 }
1781 scrub_wr_submit(sctx); 1781 scrub_wr_submit(sctx);
1782 goto again; 1782 goto again;
1783 } 1783 }
1784 1784
1785 sbio->pagev[sbio->page_count] = spage; 1785 sbio->pagev[sbio->page_count] = spage;
1786 scrub_page_get(spage); 1786 scrub_page_get(spage);
1787 sbio->page_count++; 1787 sbio->page_count++;
1788 if (sbio->page_count == wr_ctx->pages_per_wr_bio) 1788 if (sbio->page_count == wr_ctx->pages_per_wr_bio)
1789 scrub_wr_submit(sctx); 1789 scrub_wr_submit(sctx);
1790 mutex_unlock(&wr_ctx->wr_lock); 1790 mutex_unlock(&wr_ctx->wr_lock);
1791 1791
1792 return 0; 1792 return 0;
1793 } 1793 }
1794 1794
1795 static void scrub_wr_submit(struct scrub_ctx *sctx) 1795 static void scrub_wr_submit(struct scrub_ctx *sctx)
1796 { 1796 {
1797 struct scrub_wr_ctx *wr_ctx = &sctx->wr_ctx; 1797 struct scrub_wr_ctx *wr_ctx = &sctx->wr_ctx;
1798 struct scrub_bio *sbio; 1798 struct scrub_bio *sbio;
1799 1799
1800 if (!wr_ctx->wr_curr_bio) 1800 if (!wr_ctx->wr_curr_bio)
1801 return; 1801 return;
1802 1802
1803 sbio = wr_ctx->wr_curr_bio; 1803 sbio = wr_ctx->wr_curr_bio;
1804 wr_ctx->wr_curr_bio = NULL; 1804 wr_ctx->wr_curr_bio = NULL;
1805 WARN_ON(!sbio->bio->bi_bdev); 1805 WARN_ON(!sbio->bio->bi_bdev);
1806 scrub_pending_bio_inc(sctx); 1806 scrub_pending_bio_inc(sctx);
1807 /* process all writes in a single worker thread. Then the block layer 1807 /* process all writes in a single worker thread. Then the block layer
1808 * orders the requests before sending them to the driver which 1808 * orders the requests before sending them to the driver which
1809 * doubled the write performance on spinning disks when measured 1809 * doubled the write performance on spinning disks when measured
1810 * with Linux 3.5 */ 1810 * with Linux 3.5 */
1811 btrfsic_submit_bio(WRITE, sbio->bio); 1811 btrfsic_submit_bio(WRITE, sbio->bio);
1812 } 1812 }
1813 1813
1814 static void scrub_wr_bio_end_io(struct bio *bio, int err) 1814 static void scrub_wr_bio_end_io(struct bio *bio, int err)
1815 { 1815 {
1816 struct scrub_bio *sbio = bio->bi_private; 1816 struct scrub_bio *sbio = bio->bi_private;
1817 struct btrfs_fs_info *fs_info = sbio->dev->dev_root->fs_info; 1817 struct btrfs_fs_info *fs_info = sbio->dev->dev_root->fs_info;
1818 1818
1819 sbio->err = err; 1819 sbio->err = err;
1820 sbio->bio = bio; 1820 sbio->bio = bio;
1821 1821
1822 btrfs_init_work(&sbio->work, btrfs_scrubwrc_helper, 1822 btrfs_init_work(&sbio->work, btrfs_scrubwrc_helper,
1823 scrub_wr_bio_end_io_worker, NULL, NULL); 1823 scrub_wr_bio_end_io_worker, NULL, NULL);
1824 btrfs_queue_work(fs_info->scrub_wr_completion_workers, &sbio->work); 1824 btrfs_queue_work(fs_info->scrub_wr_completion_workers, &sbio->work);
1825 } 1825 }
1826 1826
1827 static void scrub_wr_bio_end_io_worker(struct btrfs_work *work) 1827 static void scrub_wr_bio_end_io_worker(struct btrfs_work *work)
1828 { 1828 {
1829 struct scrub_bio *sbio = container_of(work, struct scrub_bio, work); 1829 struct scrub_bio *sbio = container_of(work, struct scrub_bio, work);
1830 struct scrub_ctx *sctx = sbio->sctx; 1830 struct scrub_ctx *sctx = sbio->sctx;
1831 int i; 1831 int i;
1832 1832
1833 WARN_ON(sbio->page_count > SCRUB_PAGES_PER_WR_BIO); 1833 WARN_ON(sbio->page_count > SCRUB_PAGES_PER_WR_BIO);
1834 if (sbio->err) { 1834 if (sbio->err) {
1835 struct btrfs_dev_replace *dev_replace = 1835 struct btrfs_dev_replace *dev_replace =
1836 &sbio->sctx->dev_root->fs_info->dev_replace; 1836 &sbio->sctx->dev_root->fs_info->dev_replace;
1837 1837
1838 for (i = 0; i < sbio->page_count; i++) { 1838 for (i = 0; i < sbio->page_count; i++) {
1839 struct scrub_page *spage = sbio->pagev[i]; 1839 struct scrub_page *spage = sbio->pagev[i];
1840 1840
1841 spage->io_error = 1; 1841 spage->io_error = 1;
1842 btrfs_dev_replace_stats_inc(&dev_replace-> 1842 btrfs_dev_replace_stats_inc(&dev_replace->
1843 num_write_errors); 1843 num_write_errors);
1844 } 1844 }
1845 } 1845 }
1846 1846
1847 for (i = 0; i < sbio->page_count; i++) 1847 for (i = 0; i < sbio->page_count; i++)
1848 scrub_page_put(sbio->pagev[i]); 1848 scrub_page_put(sbio->pagev[i]);
1849 1849
1850 bio_put(sbio->bio); 1850 bio_put(sbio->bio);
1851 kfree(sbio); 1851 kfree(sbio);
1852 scrub_pending_bio_dec(sctx); 1852 scrub_pending_bio_dec(sctx);
1853 } 1853 }
1854 1854
1855 static int scrub_checksum(struct scrub_block *sblock) 1855 static int scrub_checksum(struct scrub_block *sblock)
1856 { 1856 {
1857 u64 flags; 1857 u64 flags;
1858 int ret; 1858 int ret;
1859 1859
1860 WARN_ON(sblock->page_count < 1); 1860 WARN_ON(sblock->page_count < 1);
1861 flags = sblock->pagev[0]->flags; 1861 flags = sblock->pagev[0]->flags;
1862 ret = 0; 1862 ret = 0;
1863 if (flags & BTRFS_EXTENT_FLAG_DATA) 1863 if (flags & BTRFS_EXTENT_FLAG_DATA)
1864 ret = scrub_checksum_data(sblock); 1864 ret = scrub_checksum_data(sblock);
1865 else if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) 1865 else if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK)
1866 ret = scrub_checksum_tree_block(sblock); 1866 ret = scrub_checksum_tree_block(sblock);
1867 else if (flags & BTRFS_EXTENT_FLAG_SUPER) 1867 else if (flags & BTRFS_EXTENT_FLAG_SUPER)
1868 (void)scrub_checksum_super(sblock); 1868 (void)scrub_checksum_super(sblock);
1869 else 1869 else
1870 WARN_ON(1); 1870 WARN_ON(1);
1871 if (ret) 1871 if (ret)
1872 scrub_handle_errored_block(sblock); 1872 scrub_handle_errored_block(sblock);
1873 1873
1874 return ret; 1874 return ret;
1875 } 1875 }
1876 1876
1877 static int scrub_checksum_data(struct scrub_block *sblock) 1877 static int scrub_checksum_data(struct scrub_block *sblock)
1878 { 1878 {
1879 struct scrub_ctx *sctx = sblock->sctx; 1879 struct scrub_ctx *sctx = sblock->sctx;
1880 u8 csum[BTRFS_CSUM_SIZE]; 1880 u8 csum[BTRFS_CSUM_SIZE];
1881 u8 *on_disk_csum; 1881 u8 *on_disk_csum;
1882 struct page *page; 1882 struct page *page;
1883 void *buffer; 1883 void *buffer;
1884 u32 crc = ~(u32)0; 1884 u32 crc = ~(u32)0;
1885 int fail = 0; 1885 int fail = 0;
1886 u64 len; 1886 u64 len;
1887 int index; 1887 int index;
1888 1888
1889 BUG_ON(sblock->page_count < 1); 1889 BUG_ON(sblock->page_count < 1);
1890 if (!sblock->pagev[0]->have_csum) 1890 if (!sblock->pagev[0]->have_csum)
1891 return 0; 1891 return 0;
1892 1892
1893 on_disk_csum = sblock->pagev[0]->csum; 1893 on_disk_csum = sblock->pagev[0]->csum;
1894 page = sblock->pagev[0]->page; 1894 page = sblock->pagev[0]->page;
1895 buffer = kmap_atomic(page); 1895 buffer = kmap_atomic(page);
1896 1896
1897 len = sctx->sectorsize; 1897 len = sctx->sectorsize;
1898 index = 0; 1898 index = 0;
1899 for (;;) { 1899 for (;;) {
1900 u64 l = min_t(u64, len, PAGE_SIZE); 1900 u64 l = min_t(u64, len, PAGE_SIZE);
1901 1901
1902 crc = btrfs_csum_data(buffer, crc, l); 1902 crc = btrfs_csum_data(buffer, crc, l);
1903 kunmap_atomic(buffer); 1903 kunmap_atomic(buffer);
1904 len -= l; 1904 len -= l;
1905 if (len == 0) 1905 if (len == 0)
1906 break; 1906 break;
1907 index++; 1907 index++;
1908 BUG_ON(index >= sblock->page_count); 1908 BUG_ON(index >= sblock->page_count);
1909 BUG_ON(!sblock->pagev[index]->page); 1909 BUG_ON(!sblock->pagev[index]->page);
1910 page = sblock->pagev[index]->page; 1910 page = sblock->pagev[index]->page;
1911 buffer = kmap_atomic(page); 1911 buffer = kmap_atomic(page);
1912 } 1912 }
1913 1913
1914 btrfs_csum_final(crc, csum); 1914 btrfs_csum_final(crc, csum);
1915 if (memcmp(csum, on_disk_csum, sctx->csum_size)) 1915 if (memcmp(csum, on_disk_csum, sctx->csum_size))
1916 fail = 1; 1916 fail = 1;
1917 1917
1918 return fail; 1918 return fail;
1919 } 1919 }
1920 1920
1921 static int scrub_checksum_tree_block(struct scrub_block *sblock) 1921 static int scrub_checksum_tree_block(struct scrub_block *sblock)
1922 { 1922 {
1923 struct scrub_ctx *sctx = sblock->sctx; 1923 struct scrub_ctx *sctx = sblock->sctx;
1924 struct btrfs_header *h; 1924 struct btrfs_header *h;
1925 struct btrfs_root *root = sctx->dev_root; 1925 struct btrfs_root *root = sctx->dev_root;
1926 struct btrfs_fs_info *fs_info = root->fs_info; 1926 struct btrfs_fs_info *fs_info = root->fs_info;
1927 u8 calculated_csum[BTRFS_CSUM_SIZE]; 1927 u8 calculated_csum[BTRFS_CSUM_SIZE];
1928 u8 on_disk_csum[BTRFS_CSUM_SIZE]; 1928 u8 on_disk_csum[BTRFS_CSUM_SIZE];
1929 struct page *page; 1929 struct page *page;
1930 void *mapped_buffer; 1930 void *mapped_buffer;
1931 u64 mapped_size; 1931 u64 mapped_size;
1932 void *p; 1932 void *p;
1933 u32 crc = ~(u32)0; 1933 u32 crc = ~(u32)0;
1934 int fail = 0; 1934 int fail = 0;
1935 int crc_fail = 0; 1935 int crc_fail = 0;
1936 u64 len; 1936 u64 len;
1937 int index; 1937 int index;
1938 1938
1939 BUG_ON(sblock->page_count < 1); 1939 BUG_ON(sblock->page_count < 1);
1940 page = sblock->pagev[0]->page; 1940 page = sblock->pagev[0]->page;
1941 mapped_buffer = kmap_atomic(page); 1941 mapped_buffer = kmap_atomic(page);
1942 h = (struct btrfs_header *)mapped_buffer; 1942 h = (struct btrfs_header *)mapped_buffer;
1943 memcpy(on_disk_csum, h->csum, sctx->csum_size); 1943 memcpy(on_disk_csum, h->csum, sctx->csum_size);
1944 1944
1945 /* 1945 /*
1946 * we don't use the getter functions here, as we 1946 * we don't use the getter functions here, as we
1947 * a) don't have an extent buffer and 1947 * a) don't have an extent buffer and
1948 * b) the page is already kmapped 1948 * b) the page is already kmapped
1949 */ 1949 */
1950 1950
1951 if (sblock->pagev[0]->logical != btrfs_stack_header_bytenr(h)) 1951 if (sblock->pagev[0]->logical != btrfs_stack_header_bytenr(h))
1952 ++fail; 1952 ++fail;
1953 1953
1954 if (sblock->pagev[0]->generation != btrfs_stack_header_generation(h)) 1954 if (sblock->pagev[0]->generation != btrfs_stack_header_generation(h))
1955 ++fail; 1955 ++fail;
1956 1956
1957 if (!scrub_check_fsid(h->fsid, sblock->pagev[0])) 1957 if (!scrub_check_fsid(h->fsid, sblock->pagev[0]))
1958 ++fail; 1958 ++fail;
1959 1959
1960 if (memcmp(h->chunk_tree_uuid, fs_info->chunk_tree_uuid, 1960 if (memcmp(h->chunk_tree_uuid, fs_info->chunk_tree_uuid,
1961 BTRFS_UUID_SIZE)) 1961 BTRFS_UUID_SIZE))
1962 ++fail; 1962 ++fail;
1963 1963
1964 len = sctx->nodesize - BTRFS_CSUM_SIZE; 1964 len = sctx->nodesize - BTRFS_CSUM_SIZE;
1965 mapped_size = PAGE_SIZE - BTRFS_CSUM_SIZE; 1965 mapped_size = PAGE_SIZE - BTRFS_CSUM_SIZE;
1966 p = ((u8 *)mapped_buffer) + BTRFS_CSUM_SIZE; 1966 p = ((u8 *)mapped_buffer) + BTRFS_CSUM_SIZE;
1967 index = 0; 1967 index = 0;
1968 for (;;) { 1968 for (;;) {
1969 u64 l = min_t(u64, len, mapped_size); 1969 u64 l = min_t(u64, len, mapped_size);
1970 1970
1971 crc = btrfs_csum_data(p, crc, l); 1971 crc = btrfs_csum_data(p, crc, l);
1972 kunmap_atomic(mapped_buffer); 1972 kunmap_atomic(mapped_buffer);
1973 len -= l; 1973 len -= l;
1974 if (len == 0) 1974 if (len == 0)
1975 break; 1975 break;
1976 index++; 1976 index++;
1977 BUG_ON(index >= sblock->page_count); 1977 BUG_ON(index >= sblock->page_count);
1978 BUG_ON(!sblock->pagev[index]->page); 1978 BUG_ON(!sblock->pagev[index]->page);
1979 page = sblock->pagev[index]->page; 1979 page = sblock->pagev[index]->page;
1980 mapped_buffer = kmap_atomic(page); 1980 mapped_buffer = kmap_atomic(page);
1981 mapped_size = PAGE_SIZE; 1981 mapped_size = PAGE_SIZE;
1982 p = mapped_buffer; 1982 p = mapped_buffer;
1983 } 1983 }
1984 1984
1985 btrfs_csum_final(crc, calculated_csum); 1985 btrfs_csum_final(crc, calculated_csum);
1986 if (memcmp(calculated_csum, on_disk_csum, sctx->csum_size)) 1986 if (memcmp(calculated_csum, on_disk_csum, sctx->csum_size))
1987 ++crc_fail; 1987 ++crc_fail;
1988 1988
1989 return fail || crc_fail; 1989 return fail || crc_fail;
1990 } 1990 }
1991 1991
1992 static int scrub_checksum_super(struct scrub_block *sblock) 1992 static int scrub_checksum_super(struct scrub_block *sblock)
1993 { 1993 {
1994 struct btrfs_super_block *s; 1994 struct btrfs_super_block *s;
1995 struct scrub_ctx *sctx = sblock->sctx; 1995 struct scrub_ctx *sctx = sblock->sctx;
1996 u8 calculated_csum[BTRFS_CSUM_SIZE]; 1996 u8 calculated_csum[BTRFS_CSUM_SIZE];
1997 u8 on_disk_csum[BTRFS_CSUM_SIZE]; 1997 u8 on_disk_csum[BTRFS_CSUM_SIZE];
1998 struct page *page; 1998 struct page *page;
1999 void *mapped_buffer; 1999 void *mapped_buffer;
2000 u64 mapped_size; 2000 u64 mapped_size;
2001 void *p; 2001 void *p;
2002 u32 crc = ~(u32)0; 2002 u32 crc = ~(u32)0;
2003 int fail_gen = 0; 2003 int fail_gen = 0;
2004 int fail_cor = 0; 2004 int fail_cor = 0;
2005 u64 len; 2005 u64 len;
2006 int index; 2006 int index;
2007 2007
2008 BUG_ON(sblock->page_count < 1); 2008 BUG_ON(sblock->page_count < 1);
2009 page = sblock->pagev[0]->page; 2009 page = sblock->pagev[0]->page;
2010 mapped_buffer = kmap_atomic(page); 2010 mapped_buffer = kmap_atomic(page);
2011 s = (struct btrfs_super_block *)mapped_buffer; 2011 s = (struct btrfs_super_block *)mapped_buffer;
2012 memcpy(on_disk_csum, s->csum, sctx->csum_size); 2012 memcpy(on_disk_csum, s->csum, sctx->csum_size);
2013 2013
2014 if (sblock->pagev[0]->logical != btrfs_super_bytenr(s)) 2014 if (sblock->pagev[0]->logical != btrfs_super_bytenr(s))
2015 ++fail_cor; 2015 ++fail_cor;
2016 2016
2017 if (sblock->pagev[0]->generation != btrfs_super_generation(s)) 2017 if (sblock->pagev[0]->generation != btrfs_super_generation(s))
2018 ++fail_gen; 2018 ++fail_gen;
2019 2019
2020 if (!scrub_check_fsid(s->fsid, sblock->pagev[0])) 2020 if (!scrub_check_fsid(s->fsid, sblock->pagev[0]))
2021 ++fail_cor; 2021 ++fail_cor;
2022 2022
2023 len = BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE; 2023 len = BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE;
2024 mapped_size = PAGE_SIZE - BTRFS_CSUM_SIZE; 2024 mapped_size = PAGE_SIZE - BTRFS_CSUM_SIZE;
2025 p = ((u8 *)mapped_buffer) + BTRFS_CSUM_SIZE; 2025 p = ((u8 *)mapped_buffer) + BTRFS_CSUM_SIZE;
2026 index = 0; 2026 index = 0;
2027 for (;;) { 2027 for (;;) {
2028 u64 l = min_t(u64, len, mapped_size); 2028 u64 l = min_t(u64, len, mapped_size);
2029 2029
2030 crc = btrfs_csum_data(p, crc, l); 2030 crc = btrfs_csum_data(p, crc, l);
2031 kunmap_atomic(mapped_buffer); 2031 kunmap_atomic(mapped_buffer);
2032 len -= l; 2032 len -= l;
2033 if (len == 0) 2033 if (len == 0)
2034 break; 2034 break;
2035 index++; 2035 index++;
2036 BUG_ON(index >= sblock->page_count); 2036 BUG_ON(index >= sblock->page_count);
2037 BUG_ON(!sblock->pagev[index]->page); 2037 BUG_ON(!sblock->pagev[index]->page);
2038 page = sblock->pagev[index]->page; 2038 page = sblock->pagev[index]->page;
2039 mapped_buffer = kmap_atomic(page); 2039 mapped_buffer = kmap_atomic(page);
2040 mapped_size = PAGE_SIZE; 2040 mapped_size = PAGE_SIZE;
2041 p = mapped_buffer; 2041 p = mapped_buffer;
2042 } 2042 }
2043 2043
2044 btrfs_csum_final(crc, calculated_csum); 2044 btrfs_csum_final(crc, calculated_csum);
2045 if (memcmp(calculated_csum, on_disk_csum, sctx->csum_size)) 2045 if (memcmp(calculated_csum, on_disk_csum, sctx->csum_size))
2046 ++fail_cor; 2046 ++fail_cor;
2047 2047
2048 if (fail_cor + fail_gen) { 2048 if (fail_cor + fail_gen) {
2049 /* 2049 /*
2050 * if we find an error in a super block, we just report it. 2050 * if we find an error in a super block, we just report it.
2051 * They will get written with the next transaction commit 2051 * They will get written with the next transaction commit
2052 * anyway 2052 * anyway
2053 */ 2053 */
2054 spin_lock(&sctx->stat_lock); 2054 spin_lock(&sctx->stat_lock);
2055 ++sctx->stat.super_errors; 2055 ++sctx->stat.super_errors;
2056 spin_unlock(&sctx->stat_lock); 2056 spin_unlock(&sctx->stat_lock);
2057 if (fail_cor) 2057 if (fail_cor)
2058 btrfs_dev_stat_inc_and_print(sblock->pagev[0]->dev, 2058 btrfs_dev_stat_inc_and_print(sblock->pagev[0]->dev,
2059 BTRFS_DEV_STAT_CORRUPTION_ERRS); 2059 BTRFS_DEV_STAT_CORRUPTION_ERRS);
2060 else 2060 else
2061 btrfs_dev_stat_inc_and_print(sblock->pagev[0]->dev, 2061 btrfs_dev_stat_inc_and_print(sblock->pagev[0]->dev,
2062 BTRFS_DEV_STAT_GENERATION_ERRS); 2062 BTRFS_DEV_STAT_GENERATION_ERRS);
2063 } 2063 }
2064 2064
2065 return fail_cor + fail_gen; 2065 return fail_cor + fail_gen;
2066 } 2066 }
2067 2067
2068 static void scrub_block_get(struct scrub_block *sblock) 2068 static void scrub_block_get(struct scrub_block *sblock)
2069 { 2069 {
2070 atomic_inc(&sblock->ref_count); 2070 atomic_inc(&sblock->ref_count);
2071 } 2071 }
2072 2072
2073 static void scrub_block_put(struct scrub_block *sblock) 2073 static void scrub_block_put(struct scrub_block *sblock)
2074 { 2074 {
2075 if (atomic_dec_and_test(&sblock->ref_count)) { 2075 if (atomic_dec_and_test(&sblock->ref_count)) {
2076 int i; 2076 int i;
2077 2077
2078 if (sblock->sparity) 2078 if (sblock->sparity)
2079 scrub_parity_put(sblock->sparity); 2079 scrub_parity_put(sblock->sparity);
2080 2080
2081 for (i = 0; i < sblock->page_count; i++) 2081 for (i = 0; i < sblock->page_count; i++)
2082 scrub_page_put(sblock->pagev[i]); 2082 scrub_page_put(sblock->pagev[i]);
2083 kfree(sblock); 2083 kfree(sblock);
2084 } 2084 }
2085 } 2085 }
2086 2086
2087 static void scrub_page_get(struct scrub_page *spage) 2087 static void scrub_page_get(struct scrub_page *spage)
2088 { 2088 {
2089 atomic_inc(&spage->ref_count); 2089 atomic_inc(&spage->ref_count);
2090 } 2090 }
2091 2091
2092 static void scrub_page_put(struct scrub_page *spage) 2092 static void scrub_page_put(struct scrub_page *spage)
2093 { 2093 {
2094 if (atomic_dec_and_test(&spage->ref_count)) { 2094 if (atomic_dec_and_test(&spage->ref_count)) {
2095 if (spage->page) 2095 if (spage->page)
2096 __free_page(spage->page); 2096 __free_page(spage->page);
2097 kfree(spage); 2097 kfree(spage);
2098 } 2098 }
2099 } 2099 }
2100 2100
2101 static void scrub_submit(struct scrub_ctx *sctx) 2101 static void scrub_submit(struct scrub_ctx *sctx)
2102 { 2102 {
2103 struct scrub_bio *sbio; 2103 struct scrub_bio *sbio;
2104 2104
2105 if (sctx->curr == -1) 2105 if (sctx->curr == -1)
2106 return; 2106 return;
2107 2107
2108 sbio = sctx->bios[sctx->curr]; 2108 sbio = sctx->bios[sctx->curr];
2109 sctx->curr = -1; 2109 sctx->curr = -1;
2110 scrub_pending_bio_inc(sctx); 2110 scrub_pending_bio_inc(sctx);
2111 2111
2112 if (!sbio->bio->bi_bdev) { 2112 if (!sbio->bio->bi_bdev) {
2113 /* 2113 /*
2114 * this case should not happen. If btrfs_map_block() is 2114 * this case should not happen. If btrfs_map_block() is
2115 * wrong, it could happen for dev-replace operations on 2115 * wrong, it could happen for dev-replace operations on
2116 * missing devices when no mirrors are available, but in 2116 * missing devices when no mirrors are available, but in
2117 * this case it should already fail the mount. 2117 * this case it should already fail the mount.
2118 * This case is handled correctly (but _very_ slowly). 2118 * This case is handled correctly (but _very_ slowly).
2119 */ 2119 */
2120 printk_ratelimited(KERN_WARNING 2120 printk_ratelimited(KERN_WARNING
2121 "BTRFS: scrub_submit(bio bdev == NULL) is unexpected!\n"); 2121 "BTRFS: scrub_submit(bio bdev == NULL) is unexpected!\n");
2122 bio_endio(sbio->bio, -EIO); 2122 bio_endio(sbio->bio, -EIO);
2123 } else { 2123 } else {
2124 btrfsic_submit_bio(READ, sbio->bio); 2124 btrfsic_submit_bio(READ, sbio->bio);
2125 } 2125 }
2126 } 2126 }
2127 2127
2128 static int scrub_add_page_to_rd_bio(struct scrub_ctx *sctx, 2128 static int scrub_add_page_to_rd_bio(struct scrub_ctx *sctx,
2129 struct scrub_page *spage) 2129 struct scrub_page *spage)
2130 { 2130 {
2131 struct scrub_block *sblock = spage->sblock; 2131 struct scrub_block *sblock = spage->sblock;
2132 struct scrub_bio *sbio; 2132 struct scrub_bio *sbio;
2133 int ret; 2133 int ret;
2134 2134
2135 again: 2135 again:
2136 /* 2136 /*
2137 * grab a fresh bio or wait for one to become available 2137 * grab a fresh bio or wait for one to become available
2138 */ 2138 */
2139 while (sctx->curr == -1) { 2139 while (sctx->curr == -1) {
2140 spin_lock(&sctx->list_lock); 2140 spin_lock(&sctx->list_lock);
2141 sctx->curr = sctx->first_free; 2141 sctx->curr = sctx->first_free;
2142 if (sctx->curr != -1) { 2142 if (sctx->curr != -1) {
2143 sctx->first_free = sctx->bios[sctx->curr]->next_free; 2143 sctx->first_free = sctx->bios[sctx->curr]->next_free;
2144 sctx->bios[sctx->curr]->next_free = -1; 2144 sctx->bios[sctx->curr]->next_free = -1;
2145 sctx->bios[sctx->curr]->page_count = 0; 2145 sctx->bios[sctx->curr]->page_count = 0;
2146 spin_unlock(&sctx->list_lock); 2146 spin_unlock(&sctx->list_lock);
2147 } else { 2147 } else {
2148 spin_unlock(&sctx->list_lock); 2148 spin_unlock(&sctx->list_lock);
2149 wait_event(sctx->list_wait, sctx->first_free != -1); 2149 wait_event(sctx->list_wait, sctx->first_free != -1);
2150 } 2150 }
2151 } 2151 }
2152 sbio = sctx->bios[sctx->curr]; 2152 sbio = sctx->bios[sctx->curr];
2153 if (sbio->page_count == 0) { 2153 if (sbio->page_count == 0) {
2154 struct bio *bio; 2154 struct bio *bio;
2155 2155
2156 sbio->physical = spage->physical; 2156 sbio->physical = spage->physical;
2157 sbio->logical = spage->logical; 2157 sbio->logical = spage->logical;
2158 sbio->dev = spage->dev; 2158 sbio->dev = spage->dev;
2159 bio = sbio->bio; 2159 bio = sbio->bio;
2160 if (!bio) { 2160 if (!bio) {
2161 bio = btrfs_io_bio_alloc(GFP_NOFS, sctx->pages_per_rd_bio); 2161 bio = btrfs_io_bio_alloc(GFP_NOFS, sctx->pages_per_rd_bio);
2162 if (!bio) 2162 if (!bio)
2163 return -ENOMEM; 2163 return -ENOMEM;
2164 sbio->bio = bio; 2164 sbio->bio = bio;
2165 } 2165 }
2166 2166
2167 bio->bi_private = sbio; 2167 bio->bi_private = sbio;
2168 bio->bi_end_io = scrub_bio_end_io; 2168 bio->bi_end_io = scrub_bio_end_io;
2169 bio->bi_bdev = sbio->dev->bdev; 2169 bio->bi_bdev = sbio->dev->bdev;
2170 bio->bi_iter.bi_sector = sbio->physical >> 9; 2170 bio->bi_iter.bi_sector = sbio->physical >> 9;
2171 sbio->err = 0; 2171 sbio->err = 0;
2172 } else if (sbio->physical + sbio->page_count * PAGE_SIZE != 2172 } else if (sbio->physical + sbio->page_count * PAGE_SIZE !=
2173 spage->physical || 2173 spage->physical ||
2174 sbio->logical + sbio->page_count * PAGE_SIZE != 2174 sbio->logical + sbio->page_count * PAGE_SIZE !=
2175 spage->logical || 2175 spage->logical ||
2176 sbio->dev != spage->dev) { 2176 sbio->dev != spage->dev) {
2177 scrub_submit(sctx); 2177 scrub_submit(sctx);
2178 goto again; 2178 goto again;
2179 } 2179 }
2180 2180
2181 sbio->pagev[sbio->page_count] = spage; 2181 sbio->pagev[sbio->page_count] = spage;
2182 ret = bio_add_page(sbio->bio, spage->page, PAGE_SIZE, 0); 2182 ret = bio_add_page(sbio->bio, spage->page, PAGE_SIZE, 0);
2183 if (ret != PAGE_SIZE) { 2183 if (ret != PAGE_SIZE) {
2184 if (sbio->page_count < 1) { 2184 if (sbio->page_count < 1) {
2185 bio_put(sbio->bio); 2185 bio_put(sbio->bio);
2186 sbio->bio = NULL; 2186 sbio->bio = NULL;
2187 return -EIO; 2187 return -EIO;
2188 } 2188 }
2189 scrub_submit(sctx); 2189 scrub_submit(sctx);
2190 goto again; 2190 goto again;
2191 } 2191 }
2192 2192
2193 scrub_block_get(sblock); /* one for the page added to the bio */ 2193 scrub_block_get(sblock); /* one for the page added to the bio */
2194 atomic_inc(&sblock->outstanding_pages); 2194 atomic_inc(&sblock->outstanding_pages);
2195 sbio->page_count++; 2195 sbio->page_count++;
2196 if (sbio->page_count == sctx->pages_per_rd_bio) 2196 if (sbio->page_count == sctx->pages_per_rd_bio)
2197 scrub_submit(sctx); 2197 scrub_submit(sctx);
2198 2198
2199 return 0; 2199 return 0;
2200 } 2200 }
2201 2201
2202 static int scrub_pages(struct scrub_ctx *sctx, u64 logical, u64 len, 2202 static int scrub_pages(struct scrub_ctx *sctx, u64 logical, u64 len,
2203 u64 physical, struct btrfs_device *dev, u64 flags, 2203 u64 physical, struct btrfs_device *dev, u64 flags,
2204 u64 gen, int mirror_num, u8 *csum, int force, 2204 u64 gen, int mirror_num, u8 *csum, int force,
2205 u64 physical_for_dev_replace) 2205 u64 physical_for_dev_replace)
2206 { 2206 {
2207 struct scrub_block *sblock; 2207 struct scrub_block *sblock;
2208 int index; 2208 int index;
2209 2209
2210 sblock = kzalloc(sizeof(*sblock), GFP_NOFS); 2210 sblock = kzalloc(sizeof(*sblock), GFP_NOFS);
2211 if (!sblock) { 2211 if (!sblock) {
2212 spin_lock(&sctx->stat_lock); 2212 spin_lock(&sctx->stat_lock);
2213 sctx->stat.malloc_errors++; 2213 sctx->stat.malloc_errors++;
2214 spin_unlock(&sctx->stat_lock); 2214 spin_unlock(&sctx->stat_lock);
2215 return -ENOMEM; 2215 return -ENOMEM;
2216 } 2216 }
2217 2217
2218 /* one ref inside this function, plus one for each page added to 2218 /* one ref inside this function, plus one for each page added to
2219 * a bio later on */ 2219 * a bio later on */
2220 atomic_set(&sblock->ref_count, 1); 2220 atomic_set(&sblock->ref_count, 1);
2221 sblock->sctx = sctx; 2221 sblock->sctx = sctx;
2222 sblock->no_io_error_seen = 1; 2222 sblock->no_io_error_seen = 1;
2223 2223
2224 for (index = 0; len > 0; index++) { 2224 for (index = 0; len > 0; index++) {
2225 struct scrub_page *spage; 2225 struct scrub_page *spage;
2226 u64 l = min_t(u64, len, PAGE_SIZE); 2226 u64 l = min_t(u64, len, PAGE_SIZE);
2227 2227
2228 spage = kzalloc(sizeof(*spage), GFP_NOFS); 2228 spage = kzalloc(sizeof(*spage), GFP_NOFS);
2229 if (!spage) { 2229 if (!spage) {
2230 leave_nomem: 2230 leave_nomem:
2231 spin_lock(&sctx->stat_lock); 2231 spin_lock(&sctx->stat_lock);
2232 sctx->stat.malloc_errors++; 2232 sctx->stat.malloc_errors++;
2233 spin_unlock(&sctx->stat_lock); 2233 spin_unlock(&sctx->stat_lock);
2234 scrub_block_put(sblock); 2234 scrub_block_put(sblock);
2235 return -ENOMEM; 2235 return -ENOMEM;
2236 } 2236 }
2237 BUG_ON(index >= SCRUB_MAX_PAGES_PER_BLOCK); 2237 BUG_ON(index >= SCRUB_MAX_PAGES_PER_BLOCK);
2238 scrub_page_get(spage); 2238 scrub_page_get(spage);
2239 sblock->pagev[index] = spage; 2239 sblock->pagev[index] = spage;
2240 spage->sblock = sblock; 2240 spage->sblock = sblock;
2241 spage->dev = dev; 2241 spage->dev = dev;
2242 spage->flags = flags; 2242 spage->flags = flags;
2243 spage->generation = gen; 2243 spage->generation = gen;
2244 spage->logical = logical; 2244 spage->logical = logical;
2245 spage->physical = physical; 2245 spage->physical = physical;
2246 spage->physical_for_dev_replace = physical_for_dev_replace; 2246 spage->physical_for_dev_replace = physical_for_dev_replace;
2247 spage->mirror_num = mirror_num; 2247 spage->mirror_num = mirror_num;
2248 if (csum) { 2248 if (csum) {
2249 spage->have_csum = 1; 2249 spage->have_csum = 1;
2250 memcpy(spage->csum, csum, sctx->csum_size); 2250 memcpy(spage->csum, csum, sctx->csum_size);
2251 } else { 2251 } else {
2252 spage->have_csum = 0; 2252 spage->have_csum = 0;
2253 } 2253 }
2254 sblock->page_count++; 2254 sblock->page_count++;
2255 spage->page = alloc_page(GFP_NOFS); 2255 spage->page = alloc_page(GFP_NOFS);
2256 if (!spage->page) 2256 if (!spage->page)
2257 goto leave_nomem; 2257 goto leave_nomem;
2258 len -= l; 2258 len -= l;
2259 logical += l; 2259 logical += l;
2260 physical += l; 2260 physical += l;
2261 physical_for_dev_replace += l; 2261 physical_for_dev_replace += l;
2262 } 2262 }
2263 2263
2264 WARN_ON(sblock->page_count == 0); 2264 WARN_ON(sblock->page_count == 0);
2265 for (index = 0; index < sblock->page_count; index++) { 2265 for (index = 0; index < sblock->page_count; index++) {
2266 struct scrub_page *spage = sblock->pagev[index]; 2266 struct scrub_page *spage = sblock->pagev[index];
2267 int ret; 2267 int ret;
2268 2268
2269 ret = scrub_add_page_to_rd_bio(sctx, spage); 2269 ret = scrub_add_page_to_rd_bio(sctx, spage);
2270 if (ret) { 2270 if (ret) {
2271 scrub_block_put(sblock); 2271 scrub_block_put(sblock);
2272 return ret; 2272 return ret;
2273 } 2273 }
2274 } 2274 }
2275 2275
2276 if (force) 2276 if (force)
2277 scrub_submit(sctx); 2277 scrub_submit(sctx);
2278 2278
2279 /* last one frees, either here or in bio completion for last page */ 2279 /* last one frees, either here or in bio completion for last page */
2280 scrub_block_put(sblock); 2280 scrub_block_put(sblock);
2281 return 0; 2281 return 0;
2282 } 2282 }
2283 2283
2284 static void scrub_bio_end_io(struct bio *bio, int err) 2284 static void scrub_bio_end_io(struct bio *bio, int err)
2285 { 2285 {
2286 struct scrub_bio *sbio = bio->bi_private; 2286 struct scrub_bio *sbio = bio->bi_private;
2287 struct btrfs_fs_info *fs_info = sbio->dev->dev_root->fs_info; 2287 struct btrfs_fs_info *fs_info = sbio->dev->dev_root->fs_info;
2288 2288
2289 sbio->err = err; 2289 sbio->err = err;
2290 sbio->bio = bio; 2290 sbio->bio = bio;
2291 2291
2292 btrfs_queue_work(fs_info->scrub_workers, &sbio->work); 2292 btrfs_queue_work(fs_info->scrub_workers, &sbio->work);
2293 } 2293 }
2294 2294
2295 static void scrub_bio_end_io_worker(struct btrfs_work *work) 2295 static void scrub_bio_end_io_worker(struct btrfs_work *work)
2296 { 2296 {
2297 struct scrub_bio *sbio = container_of(work, struct scrub_bio, work); 2297 struct scrub_bio *sbio = container_of(work, struct scrub_bio, work);
2298 struct scrub_ctx *sctx = sbio->sctx; 2298 struct scrub_ctx *sctx = sbio->sctx;
2299 int i; 2299 int i;
2300 2300
2301 BUG_ON(sbio->page_count > SCRUB_PAGES_PER_RD_BIO); 2301 BUG_ON(sbio->page_count > SCRUB_PAGES_PER_RD_BIO);
2302 if (sbio->err) { 2302 if (sbio->err) {
2303 for (i = 0; i < sbio->page_count; i++) { 2303 for (i = 0; i < sbio->page_count; i++) {
2304 struct scrub_page *spage = sbio->pagev[i]; 2304 struct scrub_page *spage = sbio->pagev[i];
2305 2305
2306 spage->io_error = 1; 2306 spage->io_error = 1;
2307 spage->sblock->no_io_error_seen = 0; 2307 spage->sblock->no_io_error_seen = 0;
2308 } 2308 }
2309 } 2309 }
2310 2310
2311 /* now complete the scrub_block items that have all pages completed */ 2311 /* now complete the scrub_block items that have all pages completed */
2312 for (i = 0; i < sbio->page_count; i++) { 2312 for (i = 0; i < sbio->page_count; i++) {
2313 struct scrub_page *spage = sbio->pagev[i]; 2313 struct scrub_page *spage = sbio->pagev[i];
2314 struct scrub_block *sblock = spage->sblock; 2314 struct scrub_block *sblock = spage->sblock;
2315 2315
2316 if (atomic_dec_and_test(&sblock->outstanding_pages)) 2316 if (atomic_dec_and_test(&sblock->outstanding_pages))
2317 scrub_block_complete(sblock); 2317 scrub_block_complete(sblock);
2318 scrub_block_put(sblock); 2318 scrub_block_put(sblock);
2319 } 2319 }
2320 2320
2321 bio_put(sbio->bio); 2321 bio_put(sbio->bio);
2322 sbio->bio = NULL; 2322 sbio->bio = NULL;
2323 spin_lock(&sctx->list_lock); 2323 spin_lock(&sctx->list_lock);
2324 sbio->next_free = sctx->first_free; 2324 sbio->next_free = sctx->first_free;
2325 sctx->first_free = sbio->index; 2325 sctx->first_free = sbio->index;
2326 spin_unlock(&sctx->list_lock); 2326 spin_unlock(&sctx->list_lock);
2327 2327
2328 if (sctx->is_dev_replace && 2328 if (sctx->is_dev_replace &&
2329 atomic_read(&sctx->wr_ctx.flush_all_writes)) { 2329 atomic_read(&sctx->wr_ctx.flush_all_writes)) {
2330 mutex_lock(&sctx->wr_ctx.wr_lock); 2330 mutex_lock(&sctx->wr_ctx.wr_lock);
2331 scrub_wr_submit(sctx); 2331 scrub_wr_submit(sctx);
2332 mutex_unlock(&sctx->wr_ctx.wr_lock); 2332 mutex_unlock(&sctx->wr_ctx.wr_lock);
2333 } 2333 }
2334 2334
2335 scrub_pending_bio_dec(sctx); 2335 scrub_pending_bio_dec(sctx);
2336 } 2336 }
2337 2337
2338 static inline void __scrub_mark_bitmap(struct scrub_parity *sparity, 2338 static inline void __scrub_mark_bitmap(struct scrub_parity *sparity,
2339 unsigned long *bitmap, 2339 unsigned long *bitmap,
2340 u64 start, u64 len) 2340 u64 start, u64 len)
2341 { 2341 {
2342 int offset; 2342 int offset;
2343 int nsectors; 2343 int nsectors;
2344 int sectorsize = sparity->sctx->dev_root->sectorsize; 2344 int sectorsize = sparity->sctx->dev_root->sectorsize;
2345 2345
2346 if (len >= sparity->stripe_len) { 2346 if (len >= sparity->stripe_len) {
2347 bitmap_set(bitmap, 0, sparity->nsectors); 2347 bitmap_set(bitmap, 0, sparity->nsectors);
2348 return; 2348 return;
2349 } 2349 }
2350 2350
2351 start -= sparity->logic_start; 2351 start -= sparity->logic_start;
2352 offset = (int)do_div(start, sparity->stripe_len); 2352 offset = (int)do_div(start, sparity->stripe_len);
2353 offset /= sectorsize; 2353 offset /= sectorsize;
2354 nsectors = (int)len / sectorsize; 2354 nsectors = (int)len / sectorsize;
2355 2355
2356 if (offset + nsectors <= sparity->nsectors) { 2356 if (offset + nsectors <= sparity->nsectors) {
2357 bitmap_set(bitmap, offset, nsectors); 2357 bitmap_set(bitmap, offset, nsectors);
2358 return; 2358 return;
2359 } 2359 }
2360 2360
2361 bitmap_set(bitmap, offset, sparity->nsectors - offset); 2361 bitmap_set(bitmap, offset, sparity->nsectors - offset);
2362 bitmap_set(bitmap, 0, nsectors - (sparity->nsectors - offset)); 2362 bitmap_set(bitmap, 0, nsectors - (sparity->nsectors - offset));
2363 } 2363 }
2364 2364
2365 static inline void scrub_parity_mark_sectors_error(struct scrub_parity *sparity, 2365 static inline void scrub_parity_mark_sectors_error(struct scrub_parity *sparity,
2366 u64 start, u64 len) 2366 u64 start, u64 len)
2367 { 2367 {
2368 __scrub_mark_bitmap(sparity, sparity->ebitmap, start, len); 2368 __scrub_mark_bitmap(sparity, sparity->ebitmap, start, len);
2369 } 2369 }
2370 2370
2371 static inline void scrub_parity_mark_sectors_data(struct scrub_parity *sparity, 2371 static inline void scrub_parity_mark_sectors_data(struct scrub_parity *sparity,
2372 u64 start, u64 len) 2372 u64 start, u64 len)
2373 { 2373 {
2374 __scrub_mark_bitmap(sparity, sparity->dbitmap, start, len); 2374 __scrub_mark_bitmap(sparity, sparity->dbitmap, start, len);
2375 } 2375 }
2376 2376
2377 static void scrub_block_complete(struct scrub_block *sblock) 2377 static void scrub_block_complete(struct scrub_block *sblock)
2378 { 2378 {
2379 int corrupted = 0; 2379 int corrupted = 0;
2380 2380
2381 if (!sblock->no_io_error_seen) { 2381 if (!sblock->no_io_error_seen) {
2382 corrupted = 1; 2382 corrupted = 1;
2383 scrub_handle_errored_block(sblock); 2383 scrub_handle_errored_block(sblock);
2384 } else { 2384 } else {
2385 /* 2385 /*
2386 * if has checksum error, write via repair mechanism in 2386 * if has checksum error, write via repair mechanism in
2387 * dev replace case, otherwise write here in dev replace 2387 * dev replace case, otherwise write here in dev replace
2388 * case. 2388 * case.
2389 */ 2389 */
2390 corrupted = scrub_checksum(sblock); 2390 corrupted = scrub_checksum(sblock);
2391 if (!corrupted && sblock->sctx->is_dev_replace) 2391 if (!corrupted && sblock->sctx->is_dev_replace)
2392 scrub_write_block_to_dev_replace(sblock); 2392 scrub_write_block_to_dev_replace(sblock);
2393 } 2393 }
2394 2394
2395 if (sblock->sparity && corrupted && !sblock->data_corrected) { 2395 if (sblock->sparity && corrupted && !sblock->data_corrected) {
2396 u64 start = sblock->pagev[0]->logical; 2396 u64 start = sblock->pagev[0]->logical;
2397 u64 end = sblock->pagev[sblock->page_count - 1]->logical + 2397 u64 end = sblock->pagev[sblock->page_count - 1]->logical +
2398 PAGE_SIZE; 2398 PAGE_SIZE;
2399 2399
2400 scrub_parity_mark_sectors_error(sblock->sparity, 2400 scrub_parity_mark_sectors_error(sblock->sparity,
2401 start, end - start); 2401 start, end - start);
2402 } 2402 }
2403 } 2403 }
2404 2404
2405 static int scrub_find_csum(struct scrub_ctx *sctx, u64 logical, u64 len, 2405 static int scrub_find_csum(struct scrub_ctx *sctx, u64 logical, u64 len,
2406 u8 *csum) 2406 u8 *csum)
2407 { 2407 {
2408 struct btrfs_ordered_sum *sum = NULL; 2408 struct btrfs_ordered_sum *sum = NULL;
2409 unsigned long index; 2409 unsigned long index;
2410 unsigned long num_sectors; 2410 unsigned long num_sectors;
2411 2411
2412 while (!list_empty(&sctx->csum_list)) { 2412 while (!list_empty(&sctx->csum_list)) {
2413 sum = list_first_entry(&sctx->csum_list, 2413 sum = list_first_entry(&sctx->csum_list,
2414 struct btrfs_ordered_sum, list); 2414 struct btrfs_ordered_sum, list);
2415 if (sum->bytenr > logical) 2415 if (sum->bytenr > logical)
2416 return 0; 2416 return 0;
2417 if (sum->bytenr + sum->len > logical) 2417 if (sum->bytenr + sum->len > logical)
2418 break; 2418 break;
2419 2419
2420 ++sctx->stat.csum_discards; 2420 ++sctx->stat.csum_discards;
2421 list_del(&sum->list); 2421 list_del(&sum->list);
2422 kfree(sum); 2422 kfree(sum);
2423 sum = NULL; 2423 sum = NULL;
2424 } 2424 }
2425 if (!sum) 2425 if (!sum)
2426 return 0; 2426 return 0;
2427 2427
2428 index = ((u32)(logical - sum->bytenr)) / sctx->sectorsize; 2428 index = ((u32)(logical - sum->bytenr)) / sctx->sectorsize;
2429 num_sectors = sum->len / sctx->sectorsize; 2429 num_sectors = sum->len / sctx->sectorsize;
2430 memcpy(csum, sum->sums + index, sctx->csum_size); 2430 memcpy(csum, sum->sums + index, sctx->csum_size);
2431 if (index == num_sectors - 1) { 2431 if (index == num_sectors - 1) {
2432 list_del(&sum->list); 2432 list_del(&sum->list);
2433 kfree(sum); 2433 kfree(sum);
2434 } 2434 }
2435 return 1; 2435 return 1;
2436 } 2436 }
2437 2437
2438 /* scrub extent tries to collect up to 64 kB for each bio */ 2438 /* scrub extent tries to collect up to 64 kB for each bio */
2439 static int scrub_extent(struct scrub_ctx *sctx, u64 logical, u64 len, 2439 static int scrub_extent(struct scrub_ctx *sctx, u64 logical, u64 len,
2440 u64 physical, struct btrfs_device *dev, u64 flags, 2440 u64 physical, struct btrfs_device *dev, u64 flags,
2441 u64 gen, int mirror_num, u64 physical_for_dev_replace) 2441 u64 gen, int mirror_num, u64 physical_for_dev_replace)
2442 { 2442 {
2443 int ret; 2443 int ret;
2444 u8 csum[BTRFS_CSUM_SIZE]; 2444 u8 csum[BTRFS_CSUM_SIZE];
2445 u32 blocksize; 2445 u32 blocksize;
2446 2446
2447 if (flags & BTRFS_EXTENT_FLAG_DATA) { 2447 if (flags & BTRFS_EXTENT_FLAG_DATA) {
2448 blocksize = sctx->sectorsize; 2448 blocksize = sctx->sectorsize;
2449 spin_lock(&sctx->stat_lock); 2449 spin_lock(&sctx->stat_lock);
2450 sctx->stat.data_extents_scrubbed++; 2450 sctx->stat.data_extents_scrubbed++;
2451 sctx->stat.data_bytes_scrubbed += len; 2451 sctx->stat.data_bytes_scrubbed += len;
2452 spin_unlock(&sctx->stat_lock); 2452 spin_unlock(&sctx->stat_lock);
2453 } else if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) { 2453 } else if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) {
2454 blocksize = sctx->nodesize; 2454 blocksize = sctx->nodesize;
2455 spin_lock(&sctx->stat_lock); 2455 spin_lock(&sctx->stat_lock);
2456 sctx->stat.tree_extents_scrubbed++; 2456 sctx->stat.tree_extents_scrubbed++;
2457 sctx->stat.tree_bytes_scrubbed += len; 2457 sctx->stat.tree_bytes_scrubbed += len;
2458 spin_unlock(&sctx->stat_lock); 2458 spin_unlock(&sctx->stat_lock);
2459 } else { 2459 } else {
2460 blocksize = sctx->sectorsize; 2460 blocksize = sctx->sectorsize;
2461 WARN_ON(1); 2461 WARN_ON(1);
2462 } 2462 }
2463 2463
2464 while (len) { 2464 while (len) {
2465 u64 l = min_t(u64, len, blocksize); 2465 u64 l = min_t(u64, len, blocksize);
2466 int have_csum = 0; 2466 int have_csum = 0;
2467 2467
2468 if (flags & BTRFS_EXTENT_FLAG_DATA) { 2468 if (flags & BTRFS_EXTENT_FLAG_DATA) {
2469 /* push csums to sbio */ 2469 /* push csums to sbio */
2470 have_csum = scrub_find_csum(sctx, logical, l, csum); 2470 have_csum = scrub_find_csum(sctx, logical, l, csum);
2471 if (have_csum == 0) 2471 if (have_csum == 0)
2472 ++sctx->stat.no_csum; 2472 ++sctx->stat.no_csum;
2473 if (sctx->is_dev_replace && !have_csum) { 2473 if (sctx->is_dev_replace && !have_csum) {
2474 ret = copy_nocow_pages(sctx, logical, l, 2474 ret = copy_nocow_pages(sctx, logical, l,
2475 mirror_num, 2475 mirror_num,
2476 physical_for_dev_replace); 2476 physical_for_dev_replace);
2477 goto behind_scrub_pages; 2477 goto behind_scrub_pages;
2478 } 2478 }
2479 } 2479 }
2480 ret = scrub_pages(sctx, logical, l, physical, dev, flags, gen, 2480 ret = scrub_pages(sctx, logical, l, physical, dev, flags, gen,
2481 mirror_num, have_csum ? csum : NULL, 0, 2481 mirror_num, have_csum ? csum : NULL, 0,
2482 physical_for_dev_replace); 2482 physical_for_dev_replace);
2483 behind_scrub_pages: 2483 behind_scrub_pages:
2484 if (ret) 2484 if (ret)
2485 return ret; 2485 return ret;
2486 len -= l; 2486 len -= l;
2487 logical += l; 2487 logical += l;
2488 physical += l; 2488 physical += l;
2489 physical_for_dev_replace += l; 2489 physical_for_dev_replace += l;
2490 } 2490 }
2491 return 0; 2491 return 0;
2492 } 2492 }
2493 2493
2494 static int scrub_pages_for_parity(struct scrub_parity *sparity, 2494 static int scrub_pages_for_parity(struct scrub_parity *sparity,
2495 u64 logical, u64 len, 2495 u64 logical, u64 len,
2496 u64 physical, struct btrfs_device *dev, 2496 u64 physical, struct btrfs_device *dev,
2497 u64 flags, u64 gen, int mirror_num, u8 *csum) 2497 u64 flags, u64 gen, int mirror_num, u8 *csum)
2498 { 2498 {
2499 struct scrub_ctx *sctx = sparity->sctx; 2499 struct scrub_ctx *sctx = sparity->sctx;
2500 struct scrub_block *sblock; 2500 struct scrub_block *sblock;
2501 int index; 2501 int index;
2502 2502
2503 sblock = kzalloc(sizeof(*sblock), GFP_NOFS); 2503 sblock = kzalloc(sizeof(*sblock), GFP_NOFS);
2504 if (!sblock) { 2504 if (!sblock) {
2505 spin_lock(&sctx->stat_lock); 2505 spin_lock(&sctx->stat_lock);
2506 sctx->stat.malloc_errors++; 2506 sctx->stat.malloc_errors++;
2507 spin_unlock(&sctx->stat_lock); 2507 spin_unlock(&sctx->stat_lock);
2508 return -ENOMEM; 2508 return -ENOMEM;
2509 } 2509 }
2510 2510
2511 /* one ref inside this function, plus one for each page added to 2511 /* one ref inside this function, plus one for each page added to
2512 * a bio later on */ 2512 * a bio later on */
2513 atomic_set(&sblock->ref_count, 1); 2513 atomic_set(&sblock->ref_count, 1);
2514 sblock->sctx = sctx; 2514 sblock->sctx = sctx;
2515 sblock->no_io_error_seen = 1; 2515 sblock->no_io_error_seen = 1;
2516 sblock->sparity = sparity; 2516 sblock->sparity = sparity;
2517 scrub_parity_get(sparity); 2517 scrub_parity_get(sparity);
2518 2518
2519 for (index = 0; len > 0; index++) { 2519 for (index = 0; len > 0; index++) {
2520 struct scrub_page *spage; 2520 struct scrub_page *spage;
2521 u64 l = min_t(u64, len, PAGE_SIZE); 2521 u64 l = min_t(u64, len, PAGE_SIZE);
2522 2522
2523 spage = kzalloc(sizeof(*spage), GFP_NOFS); 2523 spage = kzalloc(sizeof(*spage), GFP_NOFS);
2524 if (!spage) { 2524 if (!spage) {
2525 leave_nomem: 2525 leave_nomem:
2526 spin_lock(&sctx->stat_lock); 2526 spin_lock(&sctx->stat_lock);
2527 sctx->stat.malloc_errors++; 2527 sctx->stat.malloc_errors++;
2528 spin_unlock(&sctx->stat_lock); 2528 spin_unlock(&sctx->stat_lock);
2529 scrub_block_put(sblock); 2529 scrub_block_put(sblock);
2530 return -ENOMEM; 2530 return -ENOMEM;
2531 } 2531 }
2532 BUG_ON(index >= SCRUB_MAX_PAGES_PER_BLOCK); 2532 BUG_ON(index >= SCRUB_MAX_PAGES_PER_BLOCK);
2533 /* For scrub block */ 2533 /* For scrub block */
2534 scrub_page_get(spage); 2534 scrub_page_get(spage);
2535 sblock->pagev[index] = spage; 2535 sblock->pagev[index] = spage;
2536 /* For scrub parity */ 2536 /* For scrub parity */
2537 scrub_page_get(spage); 2537 scrub_page_get(spage);
2538 list_add_tail(&spage->list, &sparity->spages); 2538 list_add_tail(&spage->list, &sparity->spages);
2539 spage->sblock = sblock; 2539 spage->sblock = sblock;
2540 spage->dev = dev; 2540 spage->dev = dev;
2541 spage->flags = flags; 2541 spage->flags = flags;
2542 spage->generation = gen; 2542 spage->generation = gen;
2543 spage->logical = logical; 2543 spage->logical = logical;
2544 spage->physical = physical; 2544 spage->physical = physical;
2545 spage->mirror_num = mirror_num; 2545 spage->mirror_num = mirror_num;
2546 if (csum) { 2546 if (csum) {
2547 spage->have_csum = 1; 2547 spage->have_csum = 1;
2548 memcpy(spage->csum, csum, sctx->csum_size); 2548 memcpy(spage->csum, csum, sctx->csum_size);
2549 } else { 2549 } else {
2550 spage->have_csum = 0; 2550 spage->have_csum = 0;
2551 } 2551 }
2552 sblock->page_count++; 2552 sblock->page_count++;
2553 spage->page = alloc_page(GFP_NOFS); 2553 spage->page = alloc_page(GFP_NOFS);
2554 if (!spage->page) 2554 if (!spage->page)
2555 goto leave_nomem; 2555 goto leave_nomem;
2556 len -= l; 2556 len -= l;
2557 logical += l; 2557 logical += l;
2558 physical += l; 2558 physical += l;
2559 } 2559 }
2560 2560
2561 WARN_ON(sblock->page_count == 0); 2561 WARN_ON(sblock->page_count == 0);
2562 for (index = 0; index < sblock->page_count; index++) { 2562 for (index = 0; index < sblock->page_count; index++) {
2563 struct scrub_page *spage = sblock->pagev[index]; 2563 struct scrub_page *spage = sblock->pagev[index];
2564 int ret; 2564 int ret;
2565 2565
2566 ret = scrub_add_page_to_rd_bio(sctx, spage); 2566 ret = scrub_add_page_to_rd_bio(sctx, spage);
2567 if (ret) { 2567 if (ret) {
2568 scrub_block_put(sblock); 2568 scrub_block_put(sblock);
2569 return ret; 2569 return ret;
2570 } 2570 }
2571 } 2571 }
2572 2572
2573 /* last one frees, either here or in bio completion for last page */ 2573 /* last one frees, either here or in bio completion for last page */
2574 scrub_block_put(sblock); 2574 scrub_block_put(sblock);
2575 return 0; 2575 return 0;
2576 } 2576 }
2577 2577
2578 static int scrub_extent_for_parity(struct scrub_parity *sparity, 2578 static int scrub_extent_for_parity(struct scrub_parity *sparity,
2579 u64 logical, u64 len, 2579 u64 logical, u64 len,
2580 u64 physical, struct btrfs_device *dev, 2580 u64 physical, struct btrfs_device *dev,
2581 u64 flags, u64 gen, int mirror_num) 2581 u64 flags, u64 gen, int mirror_num)
2582 { 2582 {
2583 struct scrub_ctx *sctx = sparity->sctx; 2583 struct scrub_ctx *sctx = sparity->sctx;
2584 int ret; 2584 int ret;
2585 u8 csum[BTRFS_CSUM_SIZE]; 2585 u8 csum[BTRFS_CSUM_SIZE];
2586 u32 blocksize; 2586 u32 blocksize;
2587 2587
2588 if (flags & BTRFS_EXTENT_FLAG_DATA) { 2588 if (flags & BTRFS_EXTENT_FLAG_DATA) {
2589 blocksize = sctx->sectorsize; 2589 blocksize = sctx->sectorsize;
2590 } else if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) { 2590 } else if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) {
2591 blocksize = sctx->nodesize; 2591 blocksize = sctx->nodesize;
2592 } else { 2592 } else {
2593 blocksize = sctx->sectorsize; 2593 blocksize = sctx->sectorsize;
2594 WARN_ON(1); 2594 WARN_ON(1);
2595 } 2595 }
2596 2596
2597 while (len) { 2597 while (len) {
2598 u64 l = min_t(u64, len, blocksize); 2598 u64 l = min_t(u64, len, blocksize);
2599 int have_csum = 0; 2599 int have_csum = 0;
2600 2600
2601 if (flags & BTRFS_EXTENT_FLAG_DATA) { 2601 if (flags & BTRFS_EXTENT_FLAG_DATA) {
2602 /* push csums to sbio */ 2602 /* push csums to sbio */
2603 have_csum = scrub_find_csum(sctx, logical, l, csum); 2603 have_csum = scrub_find_csum(sctx, logical, l, csum);
2604 if (have_csum == 0) 2604 if (have_csum == 0)
2605 goto skip; 2605 goto skip;
2606 } 2606 }
2607 ret = scrub_pages_for_parity(sparity, logical, l, physical, dev, 2607 ret = scrub_pages_for_parity(sparity, logical, l, physical, dev,
2608 flags, gen, mirror_num, 2608 flags, gen, mirror_num,
2609 have_csum ? csum : NULL); 2609 have_csum ? csum : NULL);
2610 skip:
2611 if (ret) 2610 if (ret)
2612 return ret; 2611 return ret;
2612 skip:
2613 len -= l; 2613 len -= l;
2614 logical += l; 2614 logical += l;
2615 physical += l; 2615 physical += l;
2616 } 2616 }
2617 return 0; 2617 return 0;
2618 } 2618 }
2619 2619
2620 /* 2620 /*
2621 * Given a physical address, this will calculate it's 2621 * Given a physical address, this will calculate it's
2622 * logical offset. if this is a parity stripe, it will return 2622 * logical offset. if this is a parity stripe, it will return
2623 * the most left data stripe's logical offset. 2623 * the most left data stripe's logical offset.
2624 * 2624 *
2625 * return 0 if it is a data stripe, 1 means parity stripe. 2625 * return 0 if it is a data stripe, 1 means parity stripe.
2626 */ 2626 */
2627 static int get_raid56_logic_offset(u64 physical, int num, 2627 static int get_raid56_logic_offset(u64 physical, int num,
2628 struct map_lookup *map, u64 *offset, 2628 struct map_lookup *map, u64 *offset,
2629 u64 *stripe_start) 2629 u64 *stripe_start)
2630 { 2630 {
2631 int i; 2631 int i;
2632 int j = 0; 2632 int j = 0;
2633 u64 stripe_nr; 2633 u64 stripe_nr;
2634 u64 last_offset; 2634 u64 last_offset;
2635 int stripe_index; 2635 int stripe_index;
2636 int rot; 2636 int rot;
2637 2637
2638 last_offset = (physical - map->stripes[num].physical) * 2638 last_offset = (physical - map->stripes[num].physical) *
2639 nr_data_stripes(map); 2639 nr_data_stripes(map);
2640 if (stripe_start) 2640 if (stripe_start)
2641 *stripe_start = last_offset; 2641 *stripe_start = last_offset;
2642 2642
2643 *offset = last_offset; 2643 *offset = last_offset;
2644 for (i = 0; i < nr_data_stripes(map); i++) { 2644 for (i = 0; i < nr_data_stripes(map); i++) {
2645 *offset = last_offset + i * map->stripe_len; 2645 *offset = last_offset + i * map->stripe_len;
2646 2646
2647 stripe_nr = *offset; 2647 stripe_nr = *offset;
2648 do_div(stripe_nr, map->stripe_len); 2648 do_div(stripe_nr, map->stripe_len);
2649 do_div(stripe_nr, nr_data_stripes(map)); 2649 do_div(stripe_nr, nr_data_stripes(map));
2650 2650
2651 /* Work out the disk rotation on this stripe-set */ 2651 /* Work out the disk rotation on this stripe-set */
2652 rot = do_div(stripe_nr, map->num_stripes); 2652 rot = do_div(stripe_nr, map->num_stripes);
2653 /* calculate which stripe this data locates */ 2653 /* calculate which stripe this data locates */
2654 rot += i; 2654 rot += i;
2655 stripe_index = rot % map->num_stripes; 2655 stripe_index = rot % map->num_stripes;
2656 if (stripe_index == num) 2656 if (stripe_index == num)
2657 return 0; 2657 return 0;
2658 if (stripe_index < num) 2658 if (stripe_index < num)
2659 j++; 2659 j++;
2660 } 2660 }
2661 *offset = last_offset + j * map->stripe_len; 2661 *offset = last_offset + j * map->stripe_len;
2662 return 1; 2662 return 1;
2663 } 2663 }
2664 2664
2665 static void scrub_free_parity(struct scrub_parity *sparity) 2665 static void scrub_free_parity(struct scrub_parity *sparity)
2666 { 2666 {
2667 struct scrub_ctx *sctx = sparity->sctx; 2667 struct scrub_ctx *sctx = sparity->sctx;
2668 struct scrub_page *curr, *next; 2668 struct scrub_page *curr, *next;
2669 int nbits; 2669 int nbits;
2670 2670
2671 nbits = bitmap_weight(sparity->ebitmap, sparity->nsectors); 2671 nbits = bitmap_weight(sparity->ebitmap, sparity->nsectors);
2672 if (nbits) { 2672 if (nbits) {
2673 spin_lock(&sctx->stat_lock); 2673 spin_lock(&sctx->stat_lock);
2674 sctx->stat.read_errors += nbits; 2674 sctx->stat.read_errors += nbits;
2675 sctx->stat.uncorrectable_errors += nbits; 2675 sctx->stat.uncorrectable_errors += nbits;
2676 spin_unlock(&sctx->stat_lock); 2676 spin_unlock(&sctx->stat_lock);
2677 } 2677 }
2678 2678
2679 list_for_each_entry_safe(curr, next, &sparity->spages, list) { 2679 list_for_each_entry_safe(curr, next, &sparity->spages, list) {
2680 list_del_init(&curr->list); 2680 list_del_init(&curr->list);
2681 scrub_page_put(curr); 2681 scrub_page_put(curr);
2682 } 2682 }
2683 2683
2684 kfree(sparity); 2684 kfree(sparity);
2685 } 2685 }
2686 2686
2687 static void scrub_parity_bio_endio(struct bio *bio, int error) 2687 static void scrub_parity_bio_endio(struct bio *bio, int error)
2688 { 2688 {
2689 struct scrub_parity *sparity = (struct scrub_parity *)bio->bi_private; 2689 struct scrub_parity *sparity = (struct scrub_parity *)bio->bi_private;
2690 struct scrub_ctx *sctx = sparity->sctx; 2690 struct scrub_ctx *sctx = sparity->sctx;
2691 2691
2692 if (error) 2692 if (error)
2693 bitmap_or(sparity->ebitmap, sparity->ebitmap, sparity->dbitmap, 2693 bitmap_or(sparity->ebitmap, sparity->ebitmap, sparity->dbitmap,
2694 sparity->nsectors); 2694 sparity->nsectors);
2695 2695
2696 scrub_free_parity(sparity); 2696 scrub_free_parity(sparity);
2697 scrub_pending_bio_dec(sctx); 2697 scrub_pending_bio_dec(sctx);
2698 bio_put(bio); 2698 bio_put(bio);
2699 } 2699 }
2700 2700
2701 static void scrub_parity_check_and_repair(struct scrub_parity *sparity) 2701 static void scrub_parity_check_and_repair(struct scrub_parity *sparity)
2702 { 2702 {
2703 struct scrub_ctx *sctx = sparity->sctx; 2703 struct scrub_ctx *sctx = sparity->sctx;
2704 struct bio *bio; 2704 struct bio *bio;
2705 struct btrfs_raid_bio *rbio; 2705 struct btrfs_raid_bio *rbio;
2706 struct scrub_page *spage; 2706 struct scrub_page *spage;
2707 struct btrfs_bio *bbio = NULL; 2707 struct btrfs_bio *bbio = NULL;
2708 u64 *raid_map = NULL; 2708 u64 *raid_map = NULL;
2709 u64 length; 2709 u64 length;
2710 int ret; 2710 int ret;
2711 2711
2712 if (!bitmap_andnot(sparity->dbitmap, sparity->dbitmap, sparity->ebitmap, 2712 if (!bitmap_andnot(sparity->dbitmap, sparity->dbitmap, sparity->ebitmap,
2713 sparity->nsectors)) 2713 sparity->nsectors))
2714 goto out; 2714 goto out;
2715 2715
2716 length = sparity->logic_end - sparity->logic_start + 1; 2716 length = sparity->logic_end - sparity->logic_start + 1;
2717 ret = btrfs_map_sblock(sctx->dev_root->fs_info, WRITE, 2717 ret = btrfs_map_sblock(sctx->dev_root->fs_info, WRITE,
2718 sparity->logic_start, 2718 sparity->logic_start,
2719 &length, &bbio, 0, &raid_map); 2719 &length, &bbio, 0, &raid_map);
2720 if (ret || !bbio || !raid_map) 2720 if (ret || !bbio || !raid_map)
2721 goto bbio_out; 2721 goto bbio_out;
2722 2722
2723 bio = btrfs_io_bio_alloc(GFP_NOFS, 0); 2723 bio = btrfs_io_bio_alloc(GFP_NOFS, 0);
2724 if (!bio) 2724 if (!bio)
2725 goto bbio_out; 2725 goto bbio_out;
2726 2726
2727 bio->bi_iter.bi_sector = sparity->logic_start >> 9; 2727 bio->bi_iter.bi_sector = sparity->logic_start >> 9;
2728 bio->bi_private = sparity; 2728 bio->bi_private = sparity;
2729 bio->bi_end_io = scrub_parity_bio_endio; 2729 bio->bi_end_io = scrub_parity_bio_endio;
2730 2730
2731 rbio = raid56_parity_alloc_scrub_rbio(sctx->dev_root, bio, bbio, 2731 rbio = raid56_parity_alloc_scrub_rbio(sctx->dev_root, bio, bbio,
2732 raid_map, length, 2732 raid_map, length,
2733 sparity->scrub_dev, 2733 sparity->scrub_dev,
2734 sparity->dbitmap, 2734 sparity->dbitmap,
2735 sparity->nsectors); 2735 sparity->nsectors);
2736 if (!rbio) 2736 if (!rbio)
2737 goto rbio_out; 2737 goto rbio_out;
2738 2738
2739 list_for_each_entry(spage, &sparity->spages, list) 2739 list_for_each_entry(spage, &sparity->spages, list)
2740 raid56_parity_add_scrub_pages(rbio, spage->page, 2740 raid56_parity_add_scrub_pages(rbio, spage->page,
2741 spage->logical); 2741 spage->logical);
2742 2742
2743 scrub_pending_bio_inc(sctx); 2743 scrub_pending_bio_inc(sctx);
2744 raid56_parity_submit_scrub_rbio(rbio); 2744 raid56_parity_submit_scrub_rbio(rbio);
2745 return; 2745 return;
2746 2746
2747 rbio_out: 2747 rbio_out:
2748 bio_put(bio); 2748 bio_put(bio);
2749 bbio_out: 2749 bbio_out:
2750 kfree(bbio); 2750 kfree(bbio);
2751 kfree(raid_map); 2751 kfree(raid_map);
2752 bitmap_or(sparity->ebitmap, sparity->ebitmap, sparity->dbitmap, 2752 bitmap_or(sparity->ebitmap, sparity->ebitmap, sparity->dbitmap,
2753 sparity->nsectors); 2753 sparity->nsectors);
2754 spin_lock(&sctx->stat_lock); 2754 spin_lock(&sctx->stat_lock);
2755 sctx->stat.malloc_errors++; 2755 sctx->stat.malloc_errors++;
2756 spin_unlock(&sctx->stat_lock); 2756 spin_unlock(&sctx->stat_lock);
2757 out: 2757 out:
2758 scrub_free_parity(sparity); 2758 scrub_free_parity(sparity);
2759 } 2759 }
2760 2760
2761 static inline int scrub_calc_parity_bitmap_len(int nsectors) 2761 static inline int scrub_calc_parity_bitmap_len(int nsectors)
2762 { 2762 {
2763 return DIV_ROUND_UP(nsectors, BITS_PER_LONG) * (BITS_PER_LONG / 8); 2763 return DIV_ROUND_UP(nsectors, BITS_PER_LONG) * (BITS_PER_LONG / 8);
2764 } 2764 }
2765 2765
2766 static void scrub_parity_get(struct scrub_parity *sparity) 2766 static void scrub_parity_get(struct scrub_parity *sparity)
2767 { 2767 {
2768 atomic_inc(&sparity->ref_count); 2768 atomic_inc(&sparity->ref_count);
2769 } 2769 }
2770 2770
2771 static void scrub_parity_put(struct scrub_parity *sparity) 2771 static void scrub_parity_put(struct scrub_parity *sparity)
2772 { 2772 {
2773 if (!atomic_dec_and_test(&sparity->ref_count)) 2773 if (!atomic_dec_and_test(&sparity->ref_count))
2774 return; 2774 return;
2775 2775
2776 scrub_parity_check_and_repair(sparity); 2776 scrub_parity_check_and_repair(sparity);
2777 } 2777 }
2778 2778
2779 static noinline_for_stack int scrub_raid56_parity(struct scrub_ctx *sctx, 2779 static noinline_for_stack int scrub_raid56_parity(struct scrub_ctx *sctx,
2780 struct map_lookup *map, 2780 struct map_lookup *map,
2781 struct btrfs_device *sdev, 2781 struct btrfs_device *sdev,
2782 struct btrfs_path *path, 2782 struct btrfs_path *path,
2783 u64 logic_start, 2783 u64 logic_start,
2784 u64 logic_end) 2784 u64 logic_end)
2785 { 2785 {
2786 struct btrfs_fs_info *fs_info = sctx->dev_root->fs_info; 2786 struct btrfs_fs_info *fs_info = sctx->dev_root->fs_info;
2787 struct btrfs_root *root = fs_info->extent_root; 2787 struct btrfs_root *root = fs_info->extent_root;
2788 struct btrfs_root *csum_root = fs_info->csum_root; 2788 struct btrfs_root *csum_root = fs_info->csum_root;
2789 struct btrfs_extent_item *extent; 2789 struct btrfs_extent_item *extent;
2790 u64 flags; 2790 u64 flags;
2791 int ret; 2791 int ret;
2792 int slot; 2792 int slot;
2793 struct extent_buffer *l; 2793 struct extent_buffer *l;
2794 struct btrfs_key key; 2794 struct btrfs_key key;
2795 u64 generation; 2795 u64 generation;
2796 u64 extent_logical; 2796 u64 extent_logical;
2797 u64 extent_physical; 2797 u64 extent_physical;
2798 u64 extent_len; 2798 u64 extent_len;
2799 struct btrfs_device *extent_dev; 2799 struct btrfs_device *extent_dev;
2800 struct scrub_parity *sparity; 2800 struct scrub_parity *sparity;
2801 int nsectors; 2801 int nsectors;
2802 int bitmap_len; 2802 int bitmap_len;
2803 int extent_mirror_num; 2803 int extent_mirror_num;
2804 int stop_loop = 0; 2804 int stop_loop = 0;
2805 2805
2806 nsectors = map->stripe_len / root->sectorsize; 2806 nsectors = map->stripe_len / root->sectorsize;
2807 bitmap_len = scrub_calc_parity_bitmap_len(nsectors); 2807 bitmap_len = scrub_calc_parity_bitmap_len(nsectors);
2808 sparity = kzalloc(sizeof(struct scrub_parity) + 2 * bitmap_len, 2808 sparity = kzalloc(sizeof(struct scrub_parity) + 2 * bitmap_len,
2809 GFP_NOFS); 2809 GFP_NOFS);
2810 if (!sparity) { 2810 if (!sparity) {
2811 spin_lock(&sctx->stat_lock); 2811 spin_lock(&sctx->stat_lock);
2812 sctx->stat.malloc_errors++; 2812 sctx->stat.malloc_errors++;
2813 spin_unlock(&sctx->stat_lock); 2813 spin_unlock(&sctx->stat_lock);
2814 return -ENOMEM; 2814 return -ENOMEM;
2815 } 2815 }
2816 2816
2817 sparity->stripe_len = map->stripe_len; 2817 sparity->stripe_len = map->stripe_len;
2818 sparity->nsectors = nsectors; 2818 sparity->nsectors = nsectors;
2819 sparity->sctx = sctx; 2819 sparity->sctx = sctx;
2820 sparity->scrub_dev = sdev; 2820 sparity->scrub_dev = sdev;
2821 sparity->logic_start = logic_start; 2821 sparity->logic_start = logic_start;
2822 sparity->logic_end = logic_end; 2822 sparity->logic_end = logic_end;
2823 atomic_set(&sparity->ref_count, 1); 2823 atomic_set(&sparity->ref_count, 1);
2824 INIT_LIST_HEAD(&sparity->spages); 2824 INIT_LIST_HEAD(&sparity->spages);
2825 sparity->dbitmap = sparity->bitmap; 2825 sparity->dbitmap = sparity->bitmap;
2826 sparity->ebitmap = (void *)sparity->bitmap + bitmap_len; 2826 sparity->ebitmap = (void *)sparity->bitmap + bitmap_len;
2827 2827
2828 ret = 0; 2828 ret = 0;
2829 while (logic_start < logic_end) { 2829 while (logic_start < logic_end) {
2830 if (btrfs_fs_incompat(fs_info, SKINNY_METADATA)) 2830 if (btrfs_fs_incompat(fs_info, SKINNY_METADATA))
2831 key.type = BTRFS_METADATA_ITEM_KEY; 2831 key.type = BTRFS_METADATA_ITEM_KEY;
2832 else 2832 else
2833 key.type = BTRFS_EXTENT_ITEM_KEY; 2833 key.type = BTRFS_EXTENT_ITEM_KEY;
2834 key.objectid = logic_start; 2834 key.objectid = logic_start;
2835 key.offset = (u64)-1; 2835 key.offset = (u64)-1;
2836 2836
2837 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); 2837 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
2838 if (ret < 0) 2838 if (ret < 0)
2839 goto out; 2839 goto out;
2840 2840
2841 if (ret > 0) { 2841 if (ret > 0) {
2842 ret = btrfs_previous_extent_item(root, path, 0); 2842 ret = btrfs_previous_extent_item(root, path, 0);
2843 if (ret < 0) 2843 if (ret < 0)
2844 goto out; 2844 goto out;
2845 if (ret > 0) { 2845 if (ret > 0) {
2846 btrfs_release_path(path); 2846 btrfs_release_path(path);
2847 ret = btrfs_search_slot(NULL, root, &key, 2847 ret = btrfs_search_slot(NULL, root, &key,
2848 path, 0, 0); 2848 path, 0, 0);
2849 if (ret < 0) 2849 if (ret < 0)
2850 goto out; 2850 goto out;
2851 } 2851 }
2852 } 2852 }
2853 2853
2854 stop_loop = 0; 2854 stop_loop = 0;
2855 while (1) { 2855 while (1) {
2856 u64 bytes; 2856 u64 bytes;
2857 2857
2858 l = path->nodes[0]; 2858 l = path->nodes[0];
2859 slot = path->slots[0]; 2859 slot = path->slots[0];
2860 if (slot >= btrfs_header_nritems(l)) { 2860 if (slot >= btrfs_header_nritems(l)) {
2861 ret = btrfs_next_leaf(root, path); 2861 ret = btrfs_next_leaf(root, path);
2862 if (ret == 0) 2862 if (ret == 0)
2863 continue; 2863 continue;
2864 if (ret < 0) 2864 if (ret < 0)
2865 goto out; 2865 goto out;
2866 2866
2867 stop_loop = 1; 2867 stop_loop = 1;
2868 break; 2868 break;
2869 } 2869 }
2870 btrfs_item_key_to_cpu(l, &key, slot); 2870 btrfs_item_key_to_cpu(l, &key, slot);
2871 2871
2872 if (key.type == BTRFS_METADATA_ITEM_KEY) 2872 if (key.type == BTRFS_METADATA_ITEM_KEY)
2873 bytes = root->nodesize; 2873 bytes = root->nodesize;
2874 else 2874 else
2875 bytes = key.offset; 2875 bytes = key.offset;
2876 2876
2877 if (key.objectid + bytes <= logic_start) 2877 if (key.objectid + bytes <= logic_start)
2878 goto next; 2878 goto next;
2879 2879
2880 if (key.type != BTRFS_EXTENT_ITEM_KEY && 2880 if (key.type != BTRFS_EXTENT_ITEM_KEY &&
2881 key.type != BTRFS_METADATA_ITEM_KEY) 2881 key.type != BTRFS_METADATA_ITEM_KEY)
2882 goto next; 2882 goto next;
2883 2883
2884 if (key.objectid > logic_end) { 2884 if (key.objectid > logic_end) {
2885 stop_loop = 1; 2885 stop_loop = 1;
2886 break; 2886 break;
2887 } 2887 }
2888 2888
2889 while (key.objectid >= logic_start + map->stripe_len) 2889 while (key.objectid >= logic_start + map->stripe_len)
2890 logic_start += map->stripe_len; 2890 logic_start += map->stripe_len;
2891 2891
2892 extent = btrfs_item_ptr(l, slot, 2892 extent = btrfs_item_ptr(l, slot,
2893 struct btrfs_extent_item); 2893 struct btrfs_extent_item);
2894 flags = btrfs_extent_flags(l, extent); 2894 flags = btrfs_extent_flags(l, extent);
2895 generation = btrfs_extent_generation(l, extent); 2895 generation = btrfs_extent_generation(l, extent);
2896 2896
2897 if (key.objectid < logic_start && 2897 if (key.objectid < logic_start &&
2898 (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK)) { 2898 (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK)) {
2899 btrfs_err(fs_info, 2899 btrfs_err(fs_info,
2900 "scrub: tree block %llu spanning stripes, ignored. logical=%llu", 2900 "scrub: tree block %llu spanning stripes, ignored. logical=%llu",
2901 key.objectid, logic_start); 2901 key.objectid, logic_start);
2902 goto next; 2902 goto next;
2903 } 2903 }
2904 again: 2904 again:
2905 extent_logical = key.objectid; 2905 extent_logical = key.objectid;
2906 extent_len = bytes; 2906 extent_len = bytes;
2907 2907
2908 if (extent_logical < logic_start) { 2908 if (extent_logical < logic_start) {
2909 extent_len -= logic_start - extent_logical; 2909 extent_len -= logic_start - extent_logical;
2910 extent_logical = logic_start; 2910 extent_logical = logic_start;
2911 } 2911 }
2912 2912
2913 if (extent_logical + extent_len > 2913 if (extent_logical + extent_len >
2914 logic_start + map->stripe_len) 2914 logic_start + map->stripe_len)
2915 extent_len = logic_start + map->stripe_len - 2915 extent_len = logic_start + map->stripe_len -
2916 extent_logical; 2916 extent_logical;
2917 2917
2918 scrub_parity_mark_sectors_data(sparity, extent_logical, 2918 scrub_parity_mark_sectors_data(sparity, extent_logical,
2919 extent_len); 2919 extent_len);
2920 2920
2921 scrub_remap_extent(fs_info, extent_logical, 2921 scrub_remap_extent(fs_info, extent_logical,
2922 extent_len, &extent_physical, 2922 extent_len, &extent_physical,
2923 &extent_dev, 2923 &extent_dev,
2924 &extent_mirror_num); 2924 &extent_mirror_num);
2925 2925
2926 ret = btrfs_lookup_csums_range(csum_root, 2926 ret = btrfs_lookup_csums_range(csum_root,
2927 extent_logical, 2927 extent_logical,
2928 extent_logical + extent_len - 1, 2928 extent_logical + extent_len - 1,
2929 &sctx->csum_list, 1); 2929 &sctx->csum_list, 1);
2930 if (ret) 2930 if (ret)
2931 goto out; 2931 goto out;
2932 2932
2933 ret = scrub_extent_for_parity(sparity, extent_logical, 2933 ret = scrub_extent_for_parity(sparity, extent_logical,
2934 extent_len, 2934 extent_len,
2935 extent_physical, 2935 extent_physical,
2936 extent_dev, flags, 2936 extent_dev, flags,
2937 generation, 2937 generation,
2938 extent_mirror_num); 2938 extent_mirror_num);
2939 if (ret) 2939 if (ret)
2940 goto out; 2940 goto out;
2941 2941
2942 scrub_free_csums(sctx); 2942 scrub_free_csums(sctx);
2943 if (extent_logical + extent_len < 2943 if (extent_logical + extent_len <
2944 key.objectid + bytes) { 2944 key.objectid + bytes) {
2945 logic_start += map->stripe_len; 2945 logic_start += map->stripe_len;
2946 2946
2947 if (logic_start >= logic_end) { 2947 if (logic_start >= logic_end) {
2948 stop_loop = 1; 2948 stop_loop = 1;
2949 break; 2949 break;
2950 } 2950 }
2951 2951
2952 if (logic_start < key.objectid + bytes) { 2952 if (logic_start < key.objectid + bytes) {
2953 cond_resched(); 2953 cond_resched();
2954 goto again; 2954 goto again;
2955 } 2955 }
2956 } 2956 }
2957 next: 2957 next:
2958 path->slots[0]++; 2958 path->slots[0]++;
2959 } 2959 }
2960 2960
2961 btrfs_release_path(path); 2961 btrfs_release_path(path);
2962 2962
2963 if (stop_loop) 2963 if (stop_loop)
2964 break; 2964 break;
2965 2965
2966 logic_start += map->stripe_len; 2966 logic_start += map->stripe_len;
2967 } 2967 }
2968 out: 2968 out:
2969 if (ret < 0) 2969 if (ret < 0)
2970 scrub_parity_mark_sectors_error(sparity, logic_start, 2970 scrub_parity_mark_sectors_error(sparity, logic_start,
2971 logic_end - logic_start + 1); 2971 logic_end - logic_start + 1);
2972 scrub_parity_put(sparity); 2972 scrub_parity_put(sparity);
2973 scrub_submit(sctx); 2973 scrub_submit(sctx);
2974 mutex_lock(&sctx->wr_ctx.wr_lock); 2974 mutex_lock(&sctx->wr_ctx.wr_lock);
2975 scrub_wr_submit(sctx); 2975 scrub_wr_submit(sctx);
2976 mutex_unlock(&sctx->wr_ctx.wr_lock); 2976 mutex_unlock(&sctx->wr_ctx.wr_lock);
2977 2977
2978 btrfs_release_path(path); 2978 btrfs_release_path(path);
2979 return ret < 0 ? ret : 0; 2979 return ret < 0 ? ret : 0;
2980 } 2980 }
2981 2981
2982 static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx, 2982 static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
2983 struct map_lookup *map, 2983 struct map_lookup *map,
2984 struct btrfs_device *scrub_dev, 2984 struct btrfs_device *scrub_dev,
2985 int num, u64 base, u64 length, 2985 int num, u64 base, u64 length,
2986 int is_dev_replace) 2986 int is_dev_replace)
2987 { 2987 {
2988 struct btrfs_path *path, *ppath; 2988 struct btrfs_path *path, *ppath;
2989 struct btrfs_fs_info *fs_info = sctx->dev_root->fs_info; 2989 struct btrfs_fs_info *fs_info = sctx->dev_root->fs_info;
2990 struct btrfs_root *root = fs_info->extent_root; 2990 struct btrfs_root *root = fs_info->extent_root;
2991 struct btrfs_root *csum_root = fs_info->csum_root; 2991 struct btrfs_root *csum_root = fs_info->csum_root;
2992 struct btrfs_extent_item *extent; 2992 struct btrfs_extent_item *extent;
2993 struct blk_plug plug; 2993 struct blk_plug plug;
2994 u64 flags; 2994 u64 flags;
2995 int ret; 2995 int ret;
2996 int slot; 2996 int slot;
2997 u64 nstripes; 2997 u64 nstripes;
2998 struct extent_buffer *l; 2998 struct extent_buffer *l;
2999 struct btrfs_key key; 2999 struct btrfs_key key;
3000 u64 physical; 3000 u64 physical;
3001 u64 logical; 3001 u64 logical;
3002 u64 logic_end; 3002 u64 logic_end;
3003 u64 physical_end; 3003 u64 physical_end;
3004 u64 generation; 3004 u64 generation;
3005 int mirror_num; 3005 int mirror_num;
3006 struct reada_control *reada1; 3006 struct reada_control *reada1;
3007 struct reada_control *reada2; 3007 struct reada_control *reada2;
3008 struct btrfs_key key_start; 3008 struct btrfs_key key_start;
3009 struct btrfs_key key_end; 3009 struct btrfs_key key_end;
3010 u64 increment = map->stripe_len; 3010 u64 increment = map->stripe_len;
3011 u64 offset; 3011 u64 offset;
3012 u64 extent_logical; 3012 u64 extent_logical;
3013 u64 extent_physical; 3013 u64 extent_physical;
3014 u64 extent_len; 3014 u64 extent_len;
3015 u64 stripe_logical; 3015 u64 stripe_logical;
3016 u64 stripe_end; 3016 u64 stripe_end;
3017 struct btrfs_device *extent_dev; 3017 struct btrfs_device *extent_dev;
3018 int extent_mirror_num; 3018 int extent_mirror_num;
3019 int stop_loop = 0; 3019 int stop_loop = 0;
3020 3020
3021 nstripes = length; 3021 nstripes = length;
3022 physical = map->stripes[num].physical; 3022 physical = map->stripes[num].physical;
3023 offset = 0; 3023 offset = 0;
3024 do_div(nstripes, map->stripe_len); 3024 do_div(nstripes, map->stripe_len);
3025 if (map->type & BTRFS_BLOCK_GROUP_RAID0) { 3025 if (map->type & BTRFS_BLOCK_GROUP_RAID0) {
3026 offset = map->stripe_len * num; 3026 offset = map->stripe_len * num;
3027 increment = map->stripe_len * map->num_stripes; 3027 increment = map->stripe_len * map->num_stripes;
3028 mirror_num = 1; 3028 mirror_num = 1;
3029 } else if (map->type & BTRFS_BLOCK_GROUP_RAID10) { 3029 } else if (map->type & BTRFS_BLOCK_GROUP_RAID10) {
3030 int factor = map->num_stripes / map->sub_stripes; 3030 int factor = map->num_stripes / map->sub_stripes;
3031 offset = map->stripe_len * (num / map->sub_stripes); 3031 offset = map->stripe_len * (num / map->sub_stripes);
3032 increment = map->stripe_len * factor; 3032 increment = map->stripe_len * factor;
3033 mirror_num = num % map->sub_stripes + 1; 3033 mirror_num = num % map->sub_stripes + 1;
3034 } else if (map->type & BTRFS_BLOCK_GROUP_RAID1) { 3034 } else if (map->type & BTRFS_BLOCK_GROUP_RAID1) {
3035 increment = map->stripe_len; 3035 increment = map->stripe_len;
3036 mirror_num = num % map->num_stripes + 1; 3036 mirror_num = num % map->num_stripes + 1;
3037 } else if (map->type & BTRFS_BLOCK_GROUP_DUP) { 3037 } else if (map->type & BTRFS_BLOCK_GROUP_DUP) {
3038 increment = map->stripe_len; 3038 increment = map->stripe_len;
3039 mirror_num = num % map->num_stripes + 1; 3039 mirror_num = num % map->num_stripes + 1;
3040 } else if (map->type & (BTRFS_BLOCK_GROUP_RAID5 | 3040 } else if (map->type & (BTRFS_BLOCK_GROUP_RAID5 |
3041 BTRFS_BLOCK_GROUP_RAID6)) { 3041 BTRFS_BLOCK_GROUP_RAID6)) {
3042 get_raid56_logic_offset(physical, num, map, &offset, NULL); 3042 get_raid56_logic_offset(physical, num, map, &offset, NULL);
3043 increment = map->stripe_len * nr_data_stripes(map); 3043 increment = map->stripe_len * nr_data_stripes(map);
3044 mirror_num = 1; 3044 mirror_num = 1;
3045 } else { 3045 } else {
3046 increment = map->stripe_len; 3046 increment = map->stripe_len;
3047 mirror_num = 1; 3047 mirror_num = 1;
3048 } 3048 }
3049 3049
3050 path = btrfs_alloc_path(); 3050 path = btrfs_alloc_path();
3051 if (!path) 3051 if (!path)
3052 return -ENOMEM; 3052 return -ENOMEM;
3053 3053
3054 ppath = btrfs_alloc_path(); 3054 ppath = btrfs_alloc_path();
3055 if (!ppath) { 3055 if (!ppath) {
3056 btrfs_free_path(ppath); 3056 btrfs_free_path(ppath);
3057 return -ENOMEM; 3057 return -ENOMEM;
3058 } 3058 }
3059 3059
3060 /* 3060 /*
3061 * work on commit root. The related disk blocks are static as 3061 * work on commit root. The related disk blocks are static as
3062 * long as COW is applied. This means, it is save to rewrite 3062 * long as COW is applied. This means, it is save to rewrite
3063 * them to repair disk errors without any race conditions 3063 * them to repair disk errors without any race conditions
3064 */ 3064 */
3065 path->search_commit_root = 1; 3065 path->search_commit_root = 1;
3066 path->skip_locking = 1; 3066 path->skip_locking = 1;
3067 3067
3068 /* 3068 /*
3069 * trigger the readahead for extent tree csum tree and wait for 3069 * trigger the readahead for extent tree csum tree and wait for
3070 * completion. During readahead, the scrub is officially paused 3070 * completion. During readahead, the scrub is officially paused
3071 * to not hold off transaction commits 3071 * to not hold off transaction commits
3072 */ 3072 */
3073 logical = base + offset; 3073 logical = base + offset;
3074 physical_end = physical + nstripes * map->stripe_len; 3074 physical_end = physical + nstripes * map->stripe_len;
3075 if (map->type & (BTRFS_BLOCK_GROUP_RAID5 | 3075 if (map->type & (BTRFS_BLOCK_GROUP_RAID5 |
3076 BTRFS_BLOCK_GROUP_RAID6)) { 3076 BTRFS_BLOCK_GROUP_RAID6)) {
3077 get_raid56_logic_offset(physical_end, num, 3077 get_raid56_logic_offset(physical_end, num,
3078 map, &logic_end, NULL); 3078 map, &logic_end, NULL);
3079 logic_end += base; 3079 logic_end += base;
3080 } else { 3080 } else {
3081 logic_end = logical + increment * nstripes; 3081 logic_end = logical + increment * nstripes;
3082 } 3082 }
3083 wait_event(sctx->list_wait, 3083 wait_event(sctx->list_wait,
3084 atomic_read(&sctx->bios_in_flight) == 0); 3084 atomic_read(&sctx->bios_in_flight) == 0);
3085 scrub_blocked_if_needed(fs_info); 3085 scrub_blocked_if_needed(fs_info);
3086 3086
3087 /* FIXME it might be better to start readahead at commit root */ 3087 /* FIXME it might be better to start readahead at commit root */
3088 key_start.objectid = logical; 3088 key_start.objectid = logical;
3089 key_start.type = BTRFS_EXTENT_ITEM_KEY; 3089 key_start.type = BTRFS_EXTENT_ITEM_KEY;
3090 key_start.offset = (u64)0; 3090 key_start.offset = (u64)0;
3091 key_end.objectid = logic_end; 3091 key_end.objectid = logic_end;
3092 key_end.type = BTRFS_METADATA_ITEM_KEY; 3092 key_end.type = BTRFS_METADATA_ITEM_KEY;
3093 key_end.offset = (u64)-1; 3093 key_end.offset = (u64)-1;
3094 reada1 = btrfs_reada_add(root, &key_start, &key_end); 3094 reada1 = btrfs_reada_add(root, &key_start, &key_end);
3095 3095
3096 key_start.objectid = BTRFS_EXTENT_CSUM_OBJECTID; 3096 key_start.objectid = BTRFS_EXTENT_CSUM_OBJECTID;
3097 key_start.type = BTRFS_EXTENT_CSUM_KEY; 3097 key_start.type = BTRFS_EXTENT_CSUM_KEY;
3098 key_start.offset = logical; 3098 key_start.offset = logical;
3099 key_end.objectid = BTRFS_EXTENT_CSUM_OBJECTID; 3099 key_end.objectid = BTRFS_EXTENT_CSUM_OBJECTID;
3100 key_end.type = BTRFS_EXTENT_CSUM_KEY; 3100 key_end.type = BTRFS_EXTENT_CSUM_KEY;
3101 key_end.offset = logic_end; 3101 key_end.offset = logic_end;
3102 reada2 = btrfs_reada_add(csum_root, &key_start, &key_end); 3102 reada2 = btrfs_reada_add(csum_root, &key_start, &key_end);
3103 3103
3104 if (!IS_ERR(reada1)) 3104 if (!IS_ERR(reada1))
3105 btrfs_reada_wait(reada1); 3105 btrfs_reada_wait(reada1);
3106 if (!IS_ERR(reada2)) 3106 if (!IS_ERR(reada2))
3107 btrfs_reada_wait(reada2); 3107 btrfs_reada_wait(reada2);
3108 3108
3109 3109
3110 /* 3110 /*
3111 * collect all data csums for the stripe to avoid seeking during 3111 * collect all data csums for the stripe to avoid seeking during
3112 * the scrub. This might currently (crc32) end up to be about 1MB 3112 * the scrub. This might currently (crc32) end up to be about 1MB
3113 */ 3113 */
3114 blk_start_plug(&plug); 3114 blk_start_plug(&plug);
3115 3115
3116 /* 3116 /*
3117 * now find all extents for each stripe and scrub them 3117 * now find all extents for each stripe and scrub them
3118 */ 3118 */
3119 ret = 0; 3119 ret = 0;
3120 while (physical < physical_end) { 3120 while (physical < physical_end) {
3121 /* for raid56, we skip parity stripe */ 3121 /* for raid56, we skip parity stripe */
3122 if (map->type & (BTRFS_BLOCK_GROUP_RAID5 | 3122 if (map->type & (BTRFS_BLOCK_GROUP_RAID5 |
3123 BTRFS_BLOCK_GROUP_RAID6)) { 3123 BTRFS_BLOCK_GROUP_RAID6)) {
3124 ret = get_raid56_logic_offset(physical, num, 3124 ret = get_raid56_logic_offset(physical, num,
3125 map, &logical, &stripe_logical); 3125 map, &logical, &stripe_logical);
3126 logical += base; 3126 logical += base;
3127 if (ret) { 3127 if (ret) {
3128 stripe_logical += base; 3128 stripe_logical += base;
3129 stripe_end = stripe_logical + increment - 1; 3129 stripe_end = stripe_logical + increment - 1;
3130 ret = scrub_raid56_parity(sctx, map, scrub_dev, 3130 ret = scrub_raid56_parity(sctx, map, scrub_dev,
3131 ppath, stripe_logical, 3131 ppath, stripe_logical,
3132 stripe_end); 3132 stripe_end);
3133 if (ret) 3133 if (ret)
3134 goto out; 3134 goto out;
3135 goto skip; 3135 goto skip;
3136 } 3136 }
3137 } 3137 }
3138 /* 3138 /*
3139 * canceled? 3139 * canceled?
3140 */ 3140 */
3141 if (atomic_read(&fs_info->scrub_cancel_req) || 3141 if (atomic_read(&fs_info->scrub_cancel_req) ||
3142 atomic_read(&sctx->cancel_req)) { 3142 atomic_read(&sctx->cancel_req)) {
3143 ret = -ECANCELED; 3143 ret = -ECANCELED;
3144 goto out; 3144 goto out;
3145 } 3145 }
3146 /* 3146 /*
3147 * check to see if we have to pause 3147 * check to see if we have to pause
3148 */ 3148 */
3149 if (atomic_read(&fs_info->scrub_pause_req)) { 3149 if (atomic_read(&fs_info->scrub_pause_req)) {
3150 /* push queued extents */ 3150 /* push queued extents */
3151 atomic_set(&sctx->wr_ctx.flush_all_writes, 1); 3151 atomic_set(&sctx->wr_ctx.flush_all_writes, 1);
3152 scrub_submit(sctx); 3152 scrub_submit(sctx);
3153 mutex_lock(&sctx->wr_ctx.wr_lock); 3153 mutex_lock(&sctx->wr_ctx.wr_lock);
3154 scrub_wr_submit(sctx); 3154 scrub_wr_submit(sctx);
3155 mutex_unlock(&sctx->wr_ctx.wr_lock); 3155 mutex_unlock(&sctx->wr_ctx.wr_lock);
3156 wait_event(sctx->list_wait, 3156 wait_event(sctx->list_wait,
3157 atomic_read(&sctx->bios_in_flight) == 0); 3157 atomic_read(&sctx->bios_in_flight) == 0);
3158 atomic_set(&sctx->wr_ctx.flush_all_writes, 0); 3158 atomic_set(&sctx->wr_ctx.flush_all_writes, 0);
3159 scrub_blocked_if_needed(fs_info); 3159 scrub_blocked_if_needed(fs_info);
3160 } 3160 }
3161 3161
3162 if (btrfs_fs_incompat(fs_info, SKINNY_METADATA)) 3162 if (btrfs_fs_incompat(fs_info, SKINNY_METADATA))
3163 key.type = BTRFS_METADATA_ITEM_KEY; 3163 key.type = BTRFS_METADATA_ITEM_KEY;
3164 else 3164 else
3165 key.type = BTRFS_EXTENT_ITEM_KEY; 3165 key.type = BTRFS_EXTENT_ITEM_KEY;
3166 key.objectid = logical; 3166 key.objectid = logical;
3167 key.offset = (u64)-1; 3167 key.offset = (u64)-1;
3168 3168
3169 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); 3169 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
3170 if (ret < 0) 3170 if (ret < 0)
3171 goto out; 3171 goto out;
3172 3172
3173 if (ret > 0) { 3173 if (ret > 0) {
3174 ret = btrfs_previous_extent_item(root, path, 0); 3174 ret = btrfs_previous_extent_item(root, path, 0);
3175 if (ret < 0) 3175 if (ret < 0)
3176 goto out; 3176 goto out;
3177 if (ret > 0) { 3177 if (ret > 0) {
3178 /* there's no smaller item, so stick with the 3178 /* there's no smaller item, so stick with the
3179 * larger one */ 3179 * larger one */
3180 btrfs_release_path(path); 3180 btrfs_release_path(path);
3181 ret = btrfs_search_slot(NULL, root, &key, 3181 ret = btrfs_search_slot(NULL, root, &key,
3182 path, 0, 0); 3182 path, 0, 0);
3183 if (ret < 0) 3183 if (ret < 0)
3184 goto out; 3184 goto out;
3185 } 3185 }
3186 } 3186 }
3187 3187
3188 stop_loop = 0; 3188 stop_loop = 0;
3189 while (1) { 3189 while (1) {
3190 u64 bytes; 3190 u64 bytes;
3191 3191
3192 l = path->nodes[0]; 3192 l = path->nodes[0];
3193 slot = path->slots[0]; 3193 slot = path->slots[0];
3194 if (slot >= btrfs_header_nritems(l)) { 3194 if (slot >= btrfs_header_nritems(l)) {
3195 ret = btrfs_next_leaf(root, path); 3195 ret = btrfs_next_leaf(root, path);
3196 if (ret == 0) 3196 if (ret == 0)
3197 continue; 3197 continue;
3198 if (ret < 0) 3198 if (ret < 0)
3199 goto out; 3199 goto out;
3200 3200
3201 stop_loop = 1; 3201 stop_loop = 1;
3202 break; 3202 break;
3203 } 3203 }
3204 btrfs_item_key_to_cpu(l, &key, slot); 3204 btrfs_item_key_to_cpu(l, &key, slot);
3205 3205
3206 if (key.type == BTRFS_METADATA_ITEM_KEY) 3206 if (key.type == BTRFS_METADATA_ITEM_KEY)
3207 bytes = root->nodesize; 3207 bytes = root->nodesize;
3208 else 3208 else
3209 bytes = key.offset; 3209 bytes = key.offset;
3210 3210
3211 if (key.objectid + bytes <= logical) 3211 if (key.objectid + bytes <= logical)
3212 goto next; 3212 goto next;
3213 3213
3214 if (key.type != BTRFS_EXTENT_ITEM_KEY && 3214 if (key.type != BTRFS_EXTENT_ITEM_KEY &&
3215 key.type != BTRFS_METADATA_ITEM_KEY) 3215 key.type != BTRFS_METADATA_ITEM_KEY)
3216 goto next; 3216 goto next;
3217 3217
3218 if (key.objectid >= logical + map->stripe_len) { 3218 if (key.objectid >= logical + map->stripe_len) {
3219 /* out of this device extent */ 3219 /* out of this device extent */
3220 if (key.objectid >= logic_end) 3220 if (key.objectid >= logic_end)
3221 stop_loop = 1; 3221 stop_loop = 1;
3222 break; 3222 break;
3223 } 3223 }
3224 3224
3225 extent = btrfs_item_ptr(l, slot, 3225 extent = btrfs_item_ptr(l, slot,
3226 struct btrfs_extent_item); 3226 struct btrfs_extent_item);
3227 flags = btrfs_extent_flags(l, extent); 3227 flags = btrfs_extent_flags(l, extent);
3228 generation = btrfs_extent_generation(l, extent); 3228 generation = btrfs_extent_generation(l, extent);
3229 3229
3230 if (key.objectid < logical && 3230 if (key.objectid < logical &&
3231 (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK)) { 3231 (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK)) {
3232 btrfs_err(fs_info, 3232 btrfs_err(fs_info,
3233 "scrub: tree block %llu spanning " 3233 "scrub: tree block %llu spanning "
3234 "stripes, ignored. logical=%llu", 3234 "stripes, ignored. logical=%llu",
3235 key.objectid, logical); 3235 key.objectid, logical);
3236 goto next; 3236 goto next;
3237 } 3237 }
3238 3238
3239 again: 3239 again:
3240 extent_logical = key.objectid; 3240 extent_logical = key.objectid;
3241 extent_len = bytes; 3241 extent_len = bytes;
3242 3242
3243 /* 3243 /*
3244 * trim extent to this stripe 3244 * trim extent to this stripe
3245 */ 3245 */
3246 if (extent_logical < logical) { 3246 if (extent_logical < logical) {
3247 extent_len -= logical - extent_logical; 3247 extent_len -= logical - extent_logical;
3248 extent_logical = logical; 3248 extent_logical = logical;
3249 } 3249 }
3250 if (extent_logical + extent_len > 3250 if (extent_logical + extent_len >
3251 logical + map->stripe_len) { 3251 logical + map->stripe_len) {
3252 extent_len = logical + map->stripe_len - 3252 extent_len = logical + map->stripe_len -
3253 extent_logical; 3253 extent_logical;
3254 } 3254 }
3255 3255
3256 extent_physical = extent_logical - logical + physical; 3256 extent_physical = extent_logical - logical + physical;
3257 extent_dev = scrub_dev; 3257 extent_dev = scrub_dev;
3258 extent_mirror_num = mirror_num; 3258 extent_mirror_num = mirror_num;
3259 if (is_dev_replace) 3259 if (is_dev_replace)
3260 scrub_remap_extent(fs_info, extent_logical, 3260 scrub_remap_extent(fs_info, extent_logical,
3261 extent_len, &extent_physical, 3261 extent_len, &extent_physical,
3262 &extent_dev, 3262 &extent_dev,
3263 &extent_mirror_num); 3263 &extent_mirror_num);
3264 3264
3265 ret = btrfs_lookup_csums_range(csum_root, logical, 3265 ret = btrfs_lookup_csums_range(csum_root, logical,
3266 logical + map->stripe_len - 1, 3266 logical + map->stripe_len - 1,
3267 &sctx->csum_list, 1); 3267 &sctx->csum_list, 1);
3268 if (ret) 3268 if (ret)
3269 goto out; 3269 goto out;
3270 3270
3271 ret = scrub_extent(sctx, extent_logical, extent_len, 3271 ret = scrub_extent(sctx, extent_logical, extent_len,
3272 extent_physical, extent_dev, flags, 3272 extent_physical, extent_dev, flags,
3273 generation, extent_mirror_num, 3273 generation, extent_mirror_num,
3274 extent_logical - logical + physical); 3274 extent_logical - logical + physical);
3275 if (ret) 3275 if (ret)
3276 goto out; 3276 goto out;
3277 3277
3278 scrub_free_csums(sctx); 3278 scrub_free_csums(sctx);
3279 if (extent_logical + extent_len < 3279 if (extent_logical + extent_len <
3280 key.objectid + bytes) { 3280 key.objectid + bytes) {
3281 if (map->type & (BTRFS_BLOCK_GROUP_RAID5 | 3281 if (map->type & (BTRFS_BLOCK_GROUP_RAID5 |
3282 BTRFS_BLOCK_GROUP_RAID6)) { 3282 BTRFS_BLOCK_GROUP_RAID6)) {
3283 /* 3283 /*
3284 * loop until we find next data stripe 3284 * loop until we find next data stripe
3285 * or we have finished all stripes. 3285 * or we have finished all stripes.
3286 */ 3286 */
3287 loop: 3287 loop:
3288 physical += map->stripe_len; 3288 physical += map->stripe_len;
3289 ret = get_raid56_logic_offset(physical, 3289 ret = get_raid56_logic_offset(physical,
3290 num, map, &logical, 3290 num, map, &logical,
3291 &stripe_logical); 3291 &stripe_logical);
3292 logical += base; 3292 logical += base;
3293 3293
3294 if (ret && physical < physical_end) { 3294 if (ret && physical < physical_end) {
3295 stripe_logical += base; 3295 stripe_logical += base;
3296 stripe_end = stripe_logical + 3296 stripe_end = stripe_logical +
3297 increment - 1; 3297 increment - 1;
3298 ret = scrub_raid56_parity(sctx, 3298 ret = scrub_raid56_parity(sctx,
3299 map, scrub_dev, ppath, 3299 map, scrub_dev, ppath,
3300 stripe_logical, 3300 stripe_logical,
3301 stripe_end); 3301 stripe_end);
3302 if (ret) 3302 if (ret)
3303 goto out; 3303 goto out;
3304 goto loop; 3304 goto loop;
3305 } 3305 }
3306 } else { 3306 } else {
3307 physical += map->stripe_len; 3307 physical += map->stripe_len;
3308 logical += increment; 3308 logical += increment;
3309 } 3309 }
3310 if (logical < key.objectid + bytes) { 3310 if (logical < key.objectid + bytes) {
3311 cond_resched(); 3311 cond_resched();
3312 goto again; 3312 goto again;
3313 } 3313 }
3314 3314
3315 if (physical >= physical_end) { 3315 if (physical >= physical_end) {
3316 stop_loop = 1; 3316 stop_loop = 1;
3317 break; 3317 break;
3318 } 3318 }
3319 } 3319 }
3320 next: 3320 next:
3321 path->slots[0]++; 3321 path->slots[0]++;
3322 } 3322 }
3323 btrfs_release_path(path); 3323 btrfs_release_path(path);
3324 skip: 3324 skip:
3325 logical += increment; 3325 logical += increment;
3326 physical += map->stripe_len; 3326 physical += map->stripe_len;
3327 spin_lock(&sctx->stat_lock); 3327 spin_lock(&sctx->stat_lock);
3328 if (stop_loop) 3328 if (stop_loop)
3329 sctx->stat.last_physical = map->stripes[num].physical + 3329 sctx->stat.last_physical = map->stripes[num].physical +
3330 length; 3330 length;
3331 else 3331 else
3332 sctx->stat.last_physical = physical; 3332 sctx->stat.last_physical = physical;
3333 spin_unlock(&sctx->stat_lock); 3333 spin_unlock(&sctx->stat_lock);
3334 if (stop_loop) 3334 if (stop_loop)
3335 break; 3335 break;
3336 } 3336 }
3337 out: 3337 out:
3338 /* push queued extents */ 3338 /* push queued extents */
3339 scrub_submit(sctx); 3339 scrub_submit(sctx);
3340 mutex_lock(&sctx->wr_ctx.wr_lock); 3340 mutex_lock(&sctx->wr_ctx.wr_lock);
3341 scrub_wr_submit(sctx); 3341 scrub_wr_submit(sctx);
3342 mutex_unlock(&sctx->wr_ctx.wr_lock); 3342 mutex_unlock(&sctx->wr_ctx.wr_lock);
3343 3343
3344 blk_finish_plug(&plug); 3344 blk_finish_plug(&plug);
3345 btrfs_free_path(path); 3345 btrfs_free_path(path);
3346 btrfs_free_path(ppath); 3346 btrfs_free_path(ppath);
3347 return ret < 0 ? ret : 0; 3347 return ret < 0 ? ret : 0;
3348 } 3348 }
3349 3349
3350 static noinline_for_stack int scrub_chunk(struct scrub_ctx *sctx, 3350 static noinline_for_stack int scrub_chunk(struct scrub_ctx *sctx,
3351 struct btrfs_device *scrub_dev, 3351 struct btrfs_device *scrub_dev,
3352 u64 chunk_tree, u64 chunk_objectid, 3352 u64 chunk_tree, u64 chunk_objectid,
3353 u64 chunk_offset, u64 length, 3353 u64 chunk_offset, u64 length,
3354 u64 dev_offset, int is_dev_replace) 3354 u64 dev_offset, int is_dev_replace)
3355 { 3355 {
3356 struct btrfs_mapping_tree *map_tree = 3356 struct btrfs_mapping_tree *map_tree =
3357 &sctx->dev_root->fs_info->mapping_tree; 3357 &sctx->dev_root->fs_info->mapping_tree;
3358 struct map_lookup *map; 3358 struct map_lookup *map;
3359 struct extent_map *em; 3359 struct extent_map *em;
3360 int i; 3360 int i;
3361 int ret = 0; 3361 int ret = 0;
3362 3362
3363 read_lock(&map_tree->map_tree.lock); 3363 read_lock(&map_tree->map_tree.lock);
3364 em = lookup_extent_mapping(&map_tree->map_tree, chunk_offset, 1); 3364 em = lookup_extent_mapping(&map_tree->map_tree, chunk_offset, 1);
3365 read_unlock(&map_tree->map_tree.lock); 3365 read_unlock(&map_tree->map_tree.lock);
3366 3366
3367 if (!em) 3367 if (!em)
3368 return -EINVAL; 3368 return -EINVAL;
3369 3369
3370 map = (struct map_lookup *)em->bdev; 3370 map = (struct map_lookup *)em->bdev;
3371 if (em->start != chunk_offset) 3371 if (em->start != chunk_offset)
3372 goto out; 3372 goto out;
3373 3373
3374 if (em->len < length) 3374 if (em->len < length)
3375 goto out; 3375 goto out;
3376 3376
3377 for (i = 0; i < map->num_stripes; ++i) { 3377 for (i = 0; i < map->num_stripes; ++i) {
3378 if (map->stripes[i].dev->bdev == scrub_dev->bdev && 3378 if (map->stripes[i].dev->bdev == scrub_dev->bdev &&
3379 map->stripes[i].physical == dev_offset) { 3379 map->stripes[i].physical == dev_offset) {
3380 ret = scrub_stripe(sctx, map, scrub_dev, i, 3380 ret = scrub_stripe(sctx, map, scrub_dev, i,
3381 chunk_offset, length, 3381 chunk_offset, length,
3382 is_dev_replace); 3382 is_dev_replace);
3383 if (ret) 3383 if (ret)
3384 goto out; 3384 goto out;
3385 } 3385 }
3386 } 3386 }
3387 out: 3387 out:
3388 free_extent_map(em); 3388 free_extent_map(em);
3389 3389
3390 return ret; 3390 return ret;
3391 } 3391 }
3392 3392
3393 static noinline_for_stack 3393 static noinline_for_stack
3394 int scrub_enumerate_chunks(struct scrub_ctx *sctx, 3394 int scrub_enumerate_chunks(struct scrub_ctx *sctx,
3395 struct btrfs_device *scrub_dev, u64 start, u64 end, 3395 struct btrfs_device *scrub_dev, u64 start, u64 end,
3396 int is_dev_replace) 3396 int is_dev_replace)
3397 { 3397 {
3398 struct btrfs_dev_extent *dev_extent = NULL; 3398 struct btrfs_dev_extent *dev_extent = NULL;
3399 struct btrfs_path *path; 3399 struct btrfs_path *path;
3400 struct btrfs_root *root = sctx->dev_root; 3400 struct btrfs_root *root = sctx->dev_root;
3401 struct btrfs_fs_info *fs_info = root->fs_info; 3401 struct btrfs_fs_info *fs_info = root->fs_info;
3402 u64 length; 3402 u64 length;
3403 u64 chunk_tree; 3403 u64 chunk_tree;
3404 u64 chunk_objectid; 3404 u64 chunk_objectid;
3405 u64 chunk_offset; 3405 u64 chunk_offset;
3406 int ret; 3406 int ret;
3407 int slot; 3407 int slot;
3408 struct extent_buffer *l; 3408 struct extent_buffer *l;
3409 struct btrfs_key key; 3409 struct btrfs_key key;
3410 struct btrfs_key found_key; 3410 struct btrfs_key found_key;
3411 struct btrfs_block_group_cache *cache; 3411 struct btrfs_block_group_cache *cache;
3412 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; 3412 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace;
3413 3413
3414 path = btrfs_alloc_path(); 3414 path = btrfs_alloc_path();
3415 if (!path) 3415 if (!path)
3416 return -ENOMEM; 3416 return -ENOMEM;
3417 3417
3418 path->reada = 2; 3418 path->reada = 2;
3419 path->search_commit_root = 1; 3419 path->search_commit_root = 1;
3420 path->skip_locking = 1; 3420 path->skip_locking = 1;
3421 3421
3422 key.objectid = scrub_dev->devid; 3422 key.objectid = scrub_dev->devid;
3423 key.offset = 0ull; 3423 key.offset = 0ull;
3424 key.type = BTRFS_DEV_EXTENT_KEY; 3424 key.type = BTRFS_DEV_EXTENT_KEY;
3425 3425
3426 while (1) { 3426 while (1) {
3427 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); 3427 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
3428 if (ret < 0) 3428 if (ret < 0)
3429 break; 3429 break;
3430 if (ret > 0) { 3430 if (ret > 0) {
3431 if (path->slots[0] >= 3431 if (path->slots[0] >=
3432 btrfs_header_nritems(path->nodes[0])) { 3432 btrfs_header_nritems(path->nodes[0])) {
3433 ret = btrfs_next_leaf(root, path); 3433 ret = btrfs_next_leaf(root, path);
3434 if (ret) 3434 if (ret)
3435 break; 3435 break;
3436 } 3436 }
3437 } 3437 }
3438 3438
3439 l = path->nodes[0]; 3439 l = path->nodes[0];
3440 slot = path->slots[0]; 3440 slot = path->slots[0];
3441 3441
3442 btrfs_item_key_to_cpu(l, &found_key, slot); 3442 btrfs_item_key_to_cpu(l, &found_key, slot);
3443 3443
3444 if (found_key.objectid != scrub_dev->devid) 3444 if (found_key.objectid != scrub_dev->devid)
3445 break; 3445 break;
3446 3446
3447 if (found_key.type != BTRFS_DEV_EXTENT_KEY) 3447 if (found_key.type != BTRFS_DEV_EXTENT_KEY)
3448 break; 3448 break;
3449 3449
3450 if (found_key.offset >= end) 3450 if (found_key.offset >= end)
3451 break; 3451 break;
3452 3452
3453 if (found_key.offset < key.offset) 3453 if (found_key.offset < key.offset)
3454 break; 3454 break;
3455 3455
3456 dev_extent = btrfs_item_ptr(l, slot, struct btrfs_dev_extent); 3456 dev_extent = btrfs_item_ptr(l, slot, struct btrfs_dev_extent);
3457 length = btrfs_dev_extent_length(l, dev_extent); 3457 length = btrfs_dev_extent_length(l, dev_extent);
3458 3458
3459 if (found_key.offset + length <= start) 3459 if (found_key.offset + length <= start)
3460 goto skip; 3460 goto skip;
3461 3461
3462 chunk_tree = btrfs_dev_extent_chunk_tree(l, dev_extent); 3462 chunk_tree = btrfs_dev_extent_chunk_tree(l, dev_extent);
3463 chunk_objectid = btrfs_dev_extent_chunk_objectid(l, dev_extent); 3463 chunk_objectid = btrfs_dev_extent_chunk_objectid(l, dev_extent);
3464 chunk_offset = btrfs_dev_extent_chunk_offset(l, dev_extent); 3464 chunk_offset = btrfs_dev_extent_chunk_offset(l, dev_extent);
3465 3465
3466 /* 3466 /*
3467 * get a reference on the corresponding block group to prevent 3467 * get a reference on the corresponding block group to prevent
3468 * the chunk from going away while we scrub it 3468 * the chunk from going away while we scrub it
3469 */ 3469 */
3470 cache = btrfs_lookup_block_group(fs_info, chunk_offset); 3470 cache = btrfs_lookup_block_group(fs_info, chunk_offset);
3471 3471
3472 /* some chunks are removed but not committed to disk yet, 3472 /* some chunks are removed but not committed to disk yet,
3473 * continue scrubbing */ 3473 * continue scrubbing */
3474 if (!cache) 3474 if (!cache)
3475 goto skip; 3475 goto skip;
3476 3476
3477 dev_replace->cursor_right = found_key.offset + length; 3477 dev_replace->cursor_right = found_key.offset + length;
3478 dev_replace->cursor_left = found_key.offset; 3478 dev_replace->cursor_left = found_key.offset;
3479 dev_replace->item_needs_writeback = 1; 3479 dev_replace->item_needs_writeback = 1;
3480 ret = scrub_chunk(sctx, scrub_dev, chunk_tree, chunk_objectid, 3480 ret = scrub_chunk(sctx, scrub_dev, chunk_tree, chunk_objectid,
3481 chunk_offset, length, found_key.offset, 3481 chunk_offset, length, found_key.offset,
3482 is_dev_replace); 3482 is_dev_replace);
3483 3483
3484 /* 3484 /*
3485 * flush, submit all pending read and write bios, afterwards 3485 * flush, submit all pending read and write bios, afterwards
3486 * wait for them. 3486 * wait for them.
3487 * Note that in the dev replace case, a read request causes 3487 * Note that in the dev replace case, a read request causes
3488 * write requests that are submitted in the read completion 3488 * write requests that are submitted in the read completion
3489 * worker. Therefore in the current situation, it is required 3489 * worker. Therefore in the current situation, it is required
3490 * that all write requests are flushed, so that all read and 3490 * that all write requests are flushed, so that all read and
3491 * write requests are really completed when bios_in_flight 3491 * write requests are really completed when bios_in_flight
3492 * changes to 0. 3492 * changes to 0.
3493 */ 3493 */
3494 atomic_set(&sctx->wr_ctx.flush_all_writes, 1); 3494 atomic_set(&sctx->wr_ctx.flush_all_writes, 1);
3495 scrub_submit(sctx); 3495 scrub_submit(sctx);
3496 mutex_lock(&sctx->wr_ctx.wr_lock); 3496 mutex_lock(&sctx->wr_ctx.wr_lock);
3497 scrub_wr_submit(sctx); 3497 scrub_wr_submit(sctx);
3498 mutex_unlock(&sctx->wr_ctx.wr_lock); 3498 mutex_unlock(&sctx->wr_ctx.wr_lock);
3499 3499
3500 wait_event(sctx->list_wait, 3500 wait_event(sctx->list_wait,
3501 atomic_read(&sctx->bios_in_flight) == 0); 3501 atomic_read(&sctx->bios_in_flight) == 0);
3502 atomic_inc(&fs_info->scrubs_paused); 3502 atomic_inc(&fs_info->scrubs_paused);
3503 wake_up(&fs_info->scrub_pause_wait); 3503 wake_up(&fs_info->scrub_pause_wait);
3504 3504
3505 /* 3505 /*
3506 * must be called before we decrease @scrub_paused. 3506 * must be called before we decrease @scrub_paused.
3507 * make sure we don't block transaction commit while 3507 * make sure we don't block transaction commit while
3508 * we are waiting pending workers finished. 3508 * we are waiting pending workers finished.
3509 */ 3509 */
3510 wait_event(sctx->list_wait, 3510 wait_event(sctx->list_wait,
3511 atomic_read(&sctx->workers_pending) == 0); 3511 atomic_read(&sctx->workers_pending) == 0);
3512 atomic_set(&sctx->wr_ctx.flush_all_writes, 0); 3512 atomic_set(&sctx->wr_ctx.flush_all_writes, 0);
3513 3513
3514 mutex_lock(&fs_info->scrub_lock); 3514 mutex_lock(&fs_info->scrub_lock);
3515 __scrub_blocked_if_needed(fs_info); 3515 __scrub_blocked_if_needed(fs_info);
3516 atomic_dec(&fs_info->scrubs_paused); 3516 atomic_dec(&fs_info->scrubs_paused);
3517 mutex_unlock(&fs_info->scrub_lock); 3517 mutex_unlock(&fs_info->scrub_lock);
3518 wake_up(&fs_info->scrub_pause_wait); 3518 wake_up(&fs_info->scrub_pause_wait);
3519 3519
3520 btrfs_put_block_group(cache); 3520 btrfs_put_block_group(cache);
3521 if (ret) 3521 if (ret)
3522 break; 3522 break;
3523 if (is_dev_replace && 3523 if (is_dev_replace &&
3524 atomic64_read(&dev_replace->num_write_errors) > 0) { 3524 atomic64_read(&dev_replace->num_write_errors) > 0) {
3525 ret = -EIO; 3525 ret = -EIO;
3526 break; 3526 break;
3527 } 3527 }
3528 if (sctx->stat.malloc_errors > 0) { 3528 if (sctx->stat.malloc_errors > 0) {
3529 ret = -ENOMEM; 3529 ret = -ENOMEM;
3530 break; 3530 break;
3531 } 3531 }
3532 3532
3533 dev_replace->cursor_left = dev_replace->cursor_right; 3533 dev_replace->cursor_left = dev_replace->cursor_right;
3534 dev_replace->item_needs_writeback = 1; 3534 dev_replace->item_needs_writeback = 1;
3535 skip: 3535 skip:
3536 key.offset = found_key.offset + length; 3536 key.offset = found_key.offset + length;
3537 btrfs_release_path(path); 3537 btrfs_release_path(path);
3538 } 3538 }
3539 3539
3540 btrfs_free_path(path); 3540 btrfs_free_path(path);
3541 3541
3542 /* 3542 /*
3543 * ret can still be 1 from search_slot or next_leaf, 3543 * ret can still be 1 from search_slot or next_leaf,
3544 * that's not an error 3544 * that's not an error
3545 */ 3545 */
3546 return ret < 0 ? ret : 0; 3546 return ret < 0 ? ret : 0;
3547 } 3547 }
3548 3548
3549 static noinline_for_stack int scrub_supers(struct scrub_ctx *sctx, 3549 static noinline_for_stack int scrub_supers(struct scrub_ctx *sctx,
3550 struct btrfs_device *scrub_dev) 3550 struct btrfs_device *scrub_dev)
3551 { 3551 {
3552 int i; 3552 int i;
3553 u64 bytenr; 3553 u64 bytenr;
3554 u64 gen; 3554 u64 gen;
3555 int ret; 3555 int ret;
3556 struct btrfs_root *root = sctx->dev_root; 3556 struct btrfs_root *root = sctx->dev_root;
3557 3557
3558 if (test_bit(BTRFS_FS_STATE_ERROR, &root->fs_info->fs_state)) 3558 if (test_bit(BTRFS_FS_STATE_ERROR, &root->fs_info->fs_state))
3559 return -EIO; 3559 return -EIO;
3560 3560
3561 /* Seed devices of a new filesystem has their own generation. */ 3561 /* Seed devices of a new filesystem has their own generation. */
3562 if (scrub_dev->fs_devices != root->fs_info->fs_devices) 3562 if (scrub_dev->fs_devices != root->fs_info->fs_devices)
3563 gen = scrub_dev->generation; 3563 gen = scrub_dev->generation;
3564 else 3564 else
3565 gen = root->fs_info->last_trans_committed; 3565 gen = root->fs_info->last_trans_committed;
3566 3566
3567 for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) { 3567 for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) {
3568 bytenr = btrfs_sb_offset(i); 3568 bytenr = btrfs_sb_offset(i);
3569 if (bytenr + BTRFS_SUPER_INFO_SIZE > 3569 if (bytenr + BTRFS_SUPER_INFO_SIZE >
3570 scrub_dev->commit_total_bytes) 3570 scrub_dev->commit_total_bytes)
3571 break; 3571 break;
3572 3572
3573 ret = scrub_pages(sctx, bytenr, BTRFS_SUPER_INFO_SIZE, bytenr, 3573 ret = scrub_pages(sctx, bytenr, BTRFS_SUPER_INFO_SIZE, bytenr,
3574 scrub_dev, BTRFS_EXTENT_FLAG_SUPER, gen, i, 3574 scrub_dev, BTRFS_EXTENT_FLAG_SUPER, gen, i,
3575 NULL, 1, bytenr); 3575 NULL, 1, bytenr);
3576 if (ret) 3576 if (ret)
3577 return ret; 3577 return ret;
3578 } 3578 }
3579 wait_event(sctx->list_wait, atomic_read(&sctx->bios_in_flight) == 0); 3579 wait_event(sctx->list_wait, atomic_read(&sctx->bios_in_flight) == 0);
3580 3580
3581 return 0; 3581 return 0;
3582 } 3582 }
3583 3583
3584 /* 3584 /*
3585 * get a reference count on fs_info->scrub_workers. start worker if necessary 3585 * get a reference count on fs_info->scrub_workers. start worker if necessary
3586 */ 3586 */
3587 static noinline_for_stack int scrub_workers_get(struct btrfs_fs_info *fs_info, 3587 static noinline_for_stack int scrub_workers_get(struct btrfs_fs_info *fs_info,
3588 int is_dev_replace) 3588 int is_dev_replace)
3589 { 3589 {
3590 int ret = 0; 3590 int ret = 0;
3591 int flags = WQ_FREEZABLE | WQ_UNBOUND; 3591 int flags = WQ_FREEZABLE | WQ_UNBOUND;
3592 int max_active = fs_info->thread_pool_size; 3592 int max_active = fs_info->thread_pool_size;
3593 3593
3594 if (fs_info->scrub_workers_refcnt == 0) { 3594 if (fs_info->scrub_workers_refcnt == 0) {
3595 if (is_dev_replace) 3595 if (is_dev_replace)
3596 fs_info->scrub_workers = 3596 fs_info->scrub_workers =
3597 btrfs_alloc_workqueue("btrfs-scrub", flags, 3597 btrfs_alloc_workqueue("btrfs-scrub", flags,
3598 1, 4); 3598 1, 4);
3599 else 3599 else
3600 fs_info->scrub_workers = 3600 fs_info->scrub_workers =
3601 btrfs_alloc_workqueue("btrfs-scrub", flags, 3601 btrfs_alloc_workqueue("btrfs-scrub", flags,
3602 max_active, 4); 3602 max_active, 4);
3603 if (!fs_info->scrub_workers) { 3603 if (!fs_info->scrub_workers) {
3604 ret = -ENOMEM; 3604 ret = -ENOMEM;
3605 goto out; 3605 goto out;
3606 } 3606 }
3607 fs_info->scrub_wr_completion_workers = 3607 fs_info->scrub_wr_completion_workers =
3608 btrfs_alloc_workqueue("btrfs-scrubwrc", flags, 3608 btrfs_alloc_workqueue("btrfs-scrubwrc", flags,
3609 max_active, 2); 3609 max_active, 2);
3610 if (!fs_info->scrub_wr_completion_workers) { 3610 if (!fs_info->scrub_wr_completion_workers) {
3611 ret = -ENOMEM; 3611 ret = -ENOMEM;
3612 goto out; 3612 goto out;
3613 } 3613 }
3614 fs_info->scrub_nocow_workers = 3614 fs_info->scrub_nocow_workers =
3615 btrfs_alloc_workqueue("btrfs-scrubnc", flags, 1, 0); 3615 btrfs_alloc_workqueue("btrfs-scrubnc", flags, 1, 0);
3616 if (!fs_info->scrub_nocow_workers) { 3616 if (!fs_info->scrub_nocow_workers) {
3617 ret = -ENOMEM; 3617 ret = -ENOMEM;
3618 goto out; 3618 goto out;
3619 } 3619 }
3620 } 3620 }
3621 ++fs_info->scrub_workers_refcnt; 3621 ++fs_info->scrub_workers_refcnt;
3622 out: 3622 out:
3623 return ret; 3623 return ret;
3624 } 3624 }
3625 3625
3626 static noinline_for_stack void scrub_workers_put(struct btrfs_fs_info *fs_info) 3626 static noinline_for_stack void scrub_workers_put(struct btrfs_fs_info *fs_info)
3627 { 3627 {
3628 if (--fs_info->scrub_workers_refcnt == 0) { 3628 if (--fs_info->scrub_workers_refcnt == 0) {
3629 btrfs_destroy_workqueue(fs_info->scrub_workers); 3629 btrfs_destroy_workqueue(fs_info->scrub_workers);
3630 btrfs_destroy_workqueue(fs_info->scrub_wr_completion_workers); 3630 btrfs_destroy_workqueue(fs_info->scrub_wr_completion_workers);
3631 btrfs_destroy_workqueue(fs_info->scrub_nocow_workers); 3631 btrfs_destroy_workqueue(fs_info->scrub_nocow_workers);
3632 } 3632 }
3633 WARN_ON(fs_info->scrub_workers_refcnt < 0); 3633 WARN_ON(fs_info->scrub_workers_refcnt < 0);
3634 } 3634 }
3635 3635
3636 int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start, 3636 int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
3637 u64 end, struct btrfs_scrub_progress *progress, 3637 u64 end, struct btrfs_scrub_progress *progress,
3638 int readonly, int is_dev_replace) 3638 int readonly, int is_dev_replace)
3639 { 3639 {
3640 struct scrub_ctx *sctx; 3640 struct scrub_ctx *sctx;
3641 int ret; 3641 int ret;
3642 struct btrfs_device *dev; 3642 struct btrfs_device *dev;
3643 struct rcu_string *name; 3643 struct rcu_string *name;
3644 3644
3645 if (btrfs_fs_closing(fs_info)) 3645 if (btrfs_fs_closing(fs_info))
3646 return -EINVAL; 3646 return -EINVAL;
3647 3647
3648 if (fs_info->chunk_root->nodesize > BTRFS_STRIPE_LEN) { 3648 if (fs_info->chunk_root->nodesize > BTRFS_STRIPE_LEN) {
3649 /* 3649 /*
3650 * in this case scrub is unable to calculate the checksum 3650 * in this case scrub is unable to calculate the checksum
3651 * the way scrub is implemented. Do not handle this 3651 * the way scrub is implemented. Do not handle this
3652 * situation at all because it won't ever happen. 3652 * situation at all because it won't ever happen.
3653 */ 3653 */
3654 btrfs_err(fs_info, 3654 btrfs_err(fs_info,
3655 "scrub: size assumption nodesize <= BTRFS_STRIPE_LEN (%d <= %d) fails", 3655 "scrub: size assumption nodesize <= BTRFS_STRIPE_LEN (%d <= %d) fails",
3656 fs_info->chunk_root->nodesize, BTRFS_STRIPE_LEN); 3656 fs_info->chunk_root->nodesize, BTRFS_STRIPE_LEN);
3657 return -EINVAL; 3657 return -EINVAL;
3658 } 3658 }
3659 3659
3660 if (fs_info->chunk_root->sectorsize != PAGE_SIZE) { 3660 if (fs_info->chunk_root->sectorsize != PAGE_SIZE) {
3661 /* not supported for data w/o checksums */ 3661 /* not supported for data w/o checksums */
3662 btrfs_err(fs_info, 3662 btrfs_err(fs_info,
3663 "scrub: size assumption sectorsize != PAGE_SIZE " 3663 "scrub: size assumption sectorsize != PAGE_SIZE "
3664 "(%d != %lu) fails", 3664 "(%d != %lu) fails",
3665 fs_info->chunk_root->sectorsize, PAGE_SIZE); 3665 fs_info->chunk_root->sectorsize, PAGE_SIZE);
3666 return -EINVAL; 3666 return -EINVAL;
3667 } 3667 }
3668 3668
3669 if (fs_info->chunk_root->nodesize > 3669 if (fs_info->chunk_root->nodesize >
3670 PAGE_SIZE * SCRUB_MAX_PAGES_PER_BLOCK || 3670 PAGE_SIZE * SCRUB_MAX_PAGES_PER_BLOCK ||
3671 fs_info->chunk_root->sectorsize > 3671 fs_info->chunk_root->sectorsize >
3672 PAGE_SIZE * SCRUB_MAX_PAGES_PER_BLOCK) { 3672 PAGE_SIZE * SCRUB_MAX_PAGES_PER_BLOCK) {
3673 /* 3673 /*
3674 * would exhaust the array bounds of pagev member in 3674 * would exhaust the array bounds of pagev member in
3675 * struct scrub_block 3675 * struct scrub_block
3676 */ 3676 */
3677 btrfs_err(fs_info, "scrub: size assumption nodesize and sectorsize " 3677 btrfs_err(fs_info, "scrub: size assumption nodesize and sectorsize "
3678 "<= SCRUB_MAX_PAGES_PER_BLOCK (%d <= %d && %d <= %d) fails", 3678 "<= SCRUB_MAX_PAGES_PER_BLOCK (%d <= %d && %d <= %d) fails",
3679 fs_info->chunk_root->nodesize, 3679 fs_info->chunk_root->nodesize,
3680 SCRUB_MAX_PAGES_PER_BLOCK, 3680 SCRUB_MAX_PAGES_PER_BLOCK,
3681 fs_info->chunk_root->sectorsize, 3681 fs_info->chunk_root->sectorsize,
3682 SCRUB_MAX_PAGES_PER_BLOCK); 3682 SCRUB_MAX_PAGES_PER_BLOCK);
3683 return -EINVAL; 3683 return -EINVAL;
3684 } 3684 }
3685 3685
3686 3686
3687 mutex_lock(&fs_info->fs_devices->device_list_mutex); 3687 mutex_lock(&fs_info->fs_devices->device_list_mutex);
3688 dev = btrfs_find_device(fs_info, devid, NULL, NULL); 3688 dev = btrfs_find_device(fs_info, devid, NULL, NULL);
3689 if (!dev || (dev->missing && !is_dev_replace)) { 3689 if (!dev || (dev->missing && !is_dev_replace)) {
3690 mutex_unlock(&fs_info->fs_devices->device_list_mutex); 3690 mutex_unlock(&fs_info->fs_devices->device_list_mutex);
3691 return -ENODEV; 3691 return -ENODEV;
3692 } 3692 }
3693 3693
3694 if (!is_dev_replace && !readonly && !dev->writeable) { 3694 if (!is_dev_replace && !readonly && !dev->writeable) {
3695 mutex_unlock(&fs_info->fs_devices->device_list_mutex); 3695 mutex_unlock(&fs_info->fs_devices->device_list_mutex);
3696 rcu_read_lock(); 3696 rcu_read_lock();
3697 name = rcu_dereference(dev->name); 3697 name = rcu_dereference(dev->name);
3698 btrfs_err(fs_info, "scrub: device %s is not writable", 3698 btrfs_err(fs_info, "scrub: device %s is not writable",
3699 name->str); 3699 name->str);
3700 rcu_read_unlock(); 3700 rcu_read_unlock();
3701 return -EROFS; 3701 return -EROFS;
3702 } 3702 }
3703 3703
3704 mutex_lock(&fs_info->scrub_lock); 3704 mutex_lock(&fs_info->scrub_lock);
3705 if (!dev->in_fs_metadata || dev->is_tgtdev_for_dev_replace) { 3705 if (!dev->in_fs_metadata || dev->is_tgtdev_for_dev_replace) {
3706 mutex_unlock(&fs_info->scrub_lock); 3706 mutex_unlock(&fs_info->scrub_lock);
3707 mutex_unlock(&fs_info->fs_devices->device_list_mutex); 3707 mutex_unlock(&fs_info->fs_devices->device_list_mutex);
3708 return -EIO; 3708 return -EIO;
3709 } 3709 }
3710 3710
3711 btrfs_dev_replace_lock(&fs_info->dev_replace); 3711 btrfs_dev_replace_lock(&fs_info->dev_replace);
3712 if (dev->scrub_device || 3712 if (dev->scrub_device ||
3713 (!is_dev_replace && 3713 (!is_dev_replace &&
3714 btrfs_dev_replace_is_ongoing(&fs_info->dev_replace))) { 3714 btrfs_dev_replace_is_ongoing(&fs_info->dev_replace))) {
3715 btrfs_dev_replace_unlock(&fs_info->dev_replace); 3715 btrfs_dev_replace_unlock(&fs_info->dev_replace);
3716 mutex_unlock(&fs_info->scrub_lock); 3716 mutex_unlock(&fs_info->scrub_lock);
3717 mutex_unlock(&fs_info->fs_devices->device_list_mutex); 3717 mutex_unlock(&fs_info->fs_devices->device_list_mutex);
3718 return -EINPROGRESS; 3718 return -EINPROGRESS;
3719 } 3719 }
3720 btrfs_dev_replace_unlock(&fs_info->dev_replace); 3720 btrfs_dev_replace_unlock(&fs_info->dev_replace);
3721 3721
3722 ret = scrub_workers_get(fs_info, is_dev_replace); 3722 ret = scrub_workers_get(fs_info, is_dev_replace);
3723 if (ret) { 3723 if (ret) {
3724 mutex_unlock(&fs_info->scrub_lock); 3724 mutex_unlock(&fs_info->scrub_lock);
3725 mutex_unlock(&fs_info->fs_devices->device_list_mutex); 3725 mutex_unlock(&fs_info->fs_devices->device_list_mutex);
3726 return ret; 3726 return ret;
3727 } 3727 }
3728 3728
3729 sctx = scrub_setup_ctx(dev, is_dev_replace); 3729 sctx = scrub_setup_ctx(dev, is_dev_replace);
3730 if (IS_ERR(sctx)) { 3730 if (IS_ERR(sctx)) {
3731 mutex_unlock(&fs_info->scrub_lock); 3731 mutex_unlock(&fs_info->scrub_lock);
3732 mutex_unlock(&fs_info->fs_devices->device_list_mutex); 3732 mutex_unlock(&fs_info->fs_devices->device_list_mutex);
3733 scrub_workers_put(fs_info); 3733 scrub_workers_put(fs_info);
3734 return PTR_ERR(sctx); 3734 return PTR_ERR(sctx);
3735 } 3735 }
3736 sctx->readonly = readonly; 3736 sctx->readonly = readonly;
3737 dev->scrub_device = sctx; 3737 dev->scrub_device = sctx;
3738 mutex_unlock(&fs_info->fs_devices->device_list_mutex); 3738 mutex_unlock(&fs_info->fs_devices->device_list_mutex);
3739 3739
3740 /* 3740 /*
3741 * checking @scrub_pause_req here, we can avoid 3741 * checking @scrub_pause_req here, we can avoid
3742 * race between committing transaction and scrubbing. 3742 * race between committing transaction and scrubbing.
3743 */ 3743 */
3744 __scrub_blocked_if_needed(fs_info); 3744 __scrub_blocked_if_needed(fs_info);
3745 atomic_inc(&fs_info->scrubs_running); 3745 atomic_inc(&fs_info->scrubs_running);
3746 mutex_unlock(&fs_info->scrub_lock); 3746 mutex_unlock(&fs_info->scrub_lock);
3747 3747
3748 if (!is_dev_replace) { 3748 if (!is_dev_replace) {
3749 /* 3749 /*
3750 * by holding device list mutex, we can 3750 * by holding device list mutex, we can
3751 * kick off writing super in log tree sync. 3751 * kick off writing super in log tree sync.
3752 */ 3752 */
3753 mutex_lock(&fs_info->fs_devices->device_list_mutex); 3753 mutex_lock(&fs_info->fs_devices->device_list_mutex);
3754 ret = scrub_supers(sctx, dev); 3754 ret = scrub_supers(sctx, dev);
3755 mutex_unlock(&fs_info->fs_devices->device_list_mutex); 3755 mutex_unlock(&fs_info->fs_devices->device_list_mutex);
3756 } 3756 }
3757 3757
3758 if (!ret) 3758 if (!ret)
3759 ret = scrub_enumerate_chunks(sctx, dev, start, end, 3759 ret = scrub_enumerate_chunks(sctx, dev, start, end,
3760 is_dev_replace); 3760 is_dev_replace);
3761 3761
3762 wait_event(sctx->list_wait, atomic_read(&sctx->bios_in_flight) == 0); 3762 wait_event(sctx->list_wait, atomic_read(&sctx->bios_in_flight) == 0);
3763 atomic_dec(&fs_info->scrubs_running); 3763 atomic_dec(&fs_info->scrubs_running);
3764 wake_up(&fs_info->scrub_pause_wait); 3764 wake_up(&fs_info->scrub_pause_wait);
3765 3765
3766 wait_event(sctx->list_wait, atomic_read(&sctx->workers_pending) == 0); 3766 wait_event(sctx->list_wait, atomic_read(&sctx->workers_pending) == 0);
3767 3767
3768 if (progress) 3768 if (progress)
3769 memcpy(progress, &sctx->stat, sizeof(*progress)); 3769 memcpy(progress, &sctx->stat, sizeof(*progress));
3770 3770
3771 mutex_lock(&fs_info->scrub_lock); 3771 mutex_lock(&fs_info->scrub_lock);
3772 dev->scrub_device = NULL; 3772 dev->scrub_device = NULL;
3773 scrub_workers_put(fs_info); 3773 scrub_workers_put(fs_info);
3774 mutex_unlock(&fs_info->scrub_lock); 3774 mutex_unlock(&fs_info->scrub_lock);
3775 3775
3776 scrub_free_ctx(sctx); 3776 scrub_free_ctx(sctx);
3777 3777
3778 return ret; 3778 return ret;
3779 } 3779 }
3780 3780
3781 void btrfs_scrub_pause(struct btrfs_root *root) 3781 void btrfs_scrub_pause(struct btrfs_root *root)
3782 { 3782 {
3783 struct btrfs_fs_info *fs_info = root->fs_info; 3783 struct btrfs_fs_info *fs_info = root->fs_info;
3784 3784
3785 mutex_lock(&fs_info->scrub_lock); 3785 mutex_lock(&fs_info->scrub_lock);
3786 atomic_inc(&fs_info->scrub_pause_req); 3786 atomic_inc(&fs_info->scrub_pause_req);
3787 while (atomic_read(&fs_info->scrubs_paused) != 3787 while (atomic_read(&fs_info->scrubs_paused) !=
3788 atomic_read(&fs_info->scrubs_running)) { 3788 atomic_read(&fs_info->scrubs_running)) {
3789 mutex_unlock(&fs_info->scrub_lock); 3789 mutex_unlock(&fs_info->scrub_lock);
3790 wait_event(fs_info->scrub_pause_wait, 3790 wait_event(fs_info->scrub_pause_wait,
3791 atomic_read(&fs_info->scrubs_paused) == 3791 atomic_read(&fs_info->scrubs_paused) ==
3792 atomic_read(&fs_info->scrubs_running)); 3792 atomic_read(&fs_info->scrubs_running));
3793 mutex_lock(&fs_info->scrub_lock); 3793 mutex_lock(&fs_info->scrub_lock);
3794 } 3794 }
3795 mutex_unlock(&fs_info->scrub_lock); 3795 mutex_unlock(&fs_info->scrub_lock);
3796 } 3796 }
3797 3797
3798 void btrfs_scrub_continue(struct btrfs_root *root) 3798 void btrfs_scrub_continue(struct btrfs_root *root)
3799 { 3799 {
3800 struct btrfs_fs_info *fs_info = root->fs_info; 3800 struct btrfs_fs_info *fs_info = root->fs_info;
3801 3801
3802 atomic_dec(&fs_info->scrub_pause_req); 3802 atomic_dec(&fs_info->scrub_pause_req);
3803 wake_up(&fs_info->scrub_pause_wait); 3803 wake_up(&fs_info->scrub_pause_wait);
3804 } 3804 }
3805 3805
3806 int btrfs_scrub_cancel(struct btrfs_fs_info *fs_info) 3806 int btrfs_scrub_cancel(struct btrfs_fs_info *fs_info)
3807 { 3807 {
3808 mutex_lock(&fs_info->scrub_lock); 3808 mutex_lock(&fs_info->scrub_lock);
3809 if (!atomic_read(&fs_info->scrubs_running)) { 3809 if (!atomic_read(&fs_info->scrubs_running)) {
3810 mutex_unlock(&fs_info->scrub_lock); 3810 mutex_unlock(&fs_info->scrub_lock);
3811 return -ENOTCONN; 3811 return -ENOTCONN;
3812 } 3812 }
3813 3813
3814 atomic_inc(&fs_info->scrub_cancel_req); 3814 atomic_inc(&fs_info->scrub_cancel_req);
3815 while (atomic_read(&fs_info->scrubs_running)) { 3815 while (atomic_read(&fs_info->scrubs_running)) {
3816 mutex_unlock(&fs_info->scrub_lock); 3816 mutex_unlock(&fs_info->scrub_lock);
3817 wait_event(fs_info->scrub_pause_wait, 3817 wait_event(fs_info->scrub_pause_wait,
3818 atomic_read(&fs_info->scrubs_running) == 0); 3818 atomic_read(&fs_info->scrubs_running) == 0);
3819 mutex_lock(&fs_info->scrub_lock); 3819 mutex_lock(&fs_info->scrub_lock);
3820 } 3820 }
3821 atomic_dec(&fs_info->scrub_cancel_req); 3821 atomic_dec(&fs_info->scrub_cancel_req);
3822 mutex_unlock(&fs_info->scrub_lock); 3822 mutex_unlock(&fs_info->scrub_lock);
3823 3823
3824 return 0; 3824 return 0;
3825 } 3825 }
3826 3826
3827 int btrfs_scrub_cancel_dev(struct btrfs_fs_info *fs_info, 3827 int btrfs_scrub_cancel_dev(struct btrfs_fs_info *fs_info,
3828 struct btrfs_device *dev) 3828 struct btrfs_device *dev)
3829 { 3829 {
3830 struct scrub_ctx *sctx; 3830 struct scrub_ctx *sctx;
3831 3831
3832 mutex_lock(&fs_info->scrub_lock); 3832 mutex_lock(&fs_info->scrub_lock);
3833 sctx = dev->scrub_device; 3833 sctx = dev->scrub_device;
3834 if (!sctx) { 3834 if (!sctx) {
3835 mutex_unlock(&fs_info->scrub_lock); 3835 mutex_unlock(&fs_info->scrub_lock);
3836 return -ENOTCONN; 3836 return -ENOTCONN;
3837 } 3837 }
3838 atomic_inc(&sctx->cancel_req); 3838 atomic_inc(&sctx->cancel_req);
3839 while (dev->scrub_device) { 3839 while (dev->scrub_device) {
3840 mutex_unlock(&fs_info->scrub_lock); 3840 mutex_unlock(&fs_info->scrub_lock);
3841 wait_event(fs_info->scrub_pause_wait, 3841 wait_event(fs_info->scrub_pause_wait,
3842 dev->scrub_device == NULL); 3842 dev->scrub_device == NULL);
3843 mutex_lock(&fs_info->scrub_lock); 3843 mutex_lock(&fs_info->scrub_lock);
3844 } 3844 }
3845 mutex_unlock(&fs_info->scrub_lock); 3845 mutex_unlock(&fs_info->scrub_lock);
3846 3846
3847 return 0; 3847 return 0;
3848 } 3848 }
3849 3849
3850 int btrfs_scrub_progress(struct btrfs_root *root, u64 devid, 3850 int btrfs_scrub_progress(struct btrfs_root *root, u64 devid,
3851 struct btrfs_scrub_progress *progress) 3851 struct btrfs_scrub_progress *progress)
3852 { 3852 {
3853 struct btrfs_device *dev; 3853 struct btrfs_device *dev;
3854 struct scrub_ctx *sctx = NULL; 3854 struct scrub_ctx *sctx = NULL;
3855 3855
3856 mutex_lock(&root->fs_info->fs_devices->device_list_mutex); 3856 mutex_lock(&root->fs_info->fs_devices->device_list_mutex);
3857 dev = btrfs_find_device(root->fs_info, devid, NULL, NULL); 3857 dev = btrfs_find_device(root->fs_info, devid, NULL, NULL);
3858 if (dev) 3858 if (dev)
3859 sctx = dev->scrub_device; 3859 sctx = dev->scrub_device;
3860 if (sctx) 3860 if (sctx)
3861 memcpy(progress, &sctx->stat, sizeof(*progress)); 3861 memcpy(progress, &sctx->stat, sizeof(*progress));
3862 mutex_unlock(&root->fs_info->fs_devices->device_list_mutex); 3862 mutex_unlock(&root->fs_info->fs_devices->device_list_mutex);
3863 3863
3864 return dev ? (sctx ? 0 : -ENOTCONN) : -ENODEV; 3864 return dev ? (sctx ? 0 : -ENOTCONN) : -ENODEV;
3865 } 3865 }
3866 3866
3867 static void scrub_remap_extent(struct btrfs_fs_info *fs_info, 3867 static void scrub_remap_extent(struct btrfs_fs_info *fs_info,
3868 u64 extent_logical, u64 extent_len, 3868 u64 extent_logical, u64 extent_len,
3869 u64 *extent_physical, 3869 u64 *extent_physical,
3870 struct btrfs_device **extent_dev, 3870 struct btrfs_device **extent_dev,
3871 int *extent_mirror_num) 3871 int *extent_mirror_num)
3872 { 3872 {
3873 u64 mapped_length; 3873 u64 mapped_length;
3874 struct btrfs_bio *bbio = NULL; 3874 struct btrfs_bio *bbio = NULL;
3875 int ret; 3875 int ret;
3876 3876
3877 mapped_length = extent_len; 3877 mapped_length = extent_len;
3878 ret = btrfs_map_block(fs_info, READ, extent_logical, 3878 ret = btrfs_map_block(fs_info, READ, extent_logical,
3879 &mapped_length, &bbio, 0); 3879 &mapped_length, &bbio, 0);
3880 if (ret || !bbio || mapped_length < extent_len || 3880 if (ret || !bbio || mapped_length < extent_len ||
3881 !bbio->stripes[0].dev->bdev) { 3881 !bbio->stripes[0].dev->bdev) {
3882 kfree(bbio); 3882 kfree(bbio);
3883 return; 3883 return;
3884 } 3884 }
3885 3885
3886 *extent_physical = bbio->stripes[0].physical; 3886 *extent_physical = bbio->stripes[0].physical;
3887 *extent_mirror_num = bbio->mirror_num; 3887 *extent_mirror_num = bbio->mirror_num;
3888 *extent_dev = bbio->stripes[0].dev; 3888 *extent_dev = bbio->stripes[0].dev;
3889 kfree(bbio); 3889 kfree(bbio);
3890 } 3890 }
3891 3891
3892 static int scrub_setup_wr_ctx(struct scrub_ctx *sctx, 3892 static int scrub_setup_wr_ctx(struct scrub_ctx *sctx,
3893 struct scrub_wr_ctx *wr_ctx, 3893 struct scrub_wr_ctx *wr_ctx,
3894 struct btrfs_fs_info *fs_info, 3894 struct btrfs_fs_info *fs_info,
3895 struct btrfs_device *dev, 3895 struct btrfs_device *dev,
3896 int is_dev_replace) 3896 int is_dev_replace)
3897 { 3897 {
3898 WARN_ON(wr_ctx->wr_curr_bio != NULL); 3898 WARN_ON(wr_ctx->wr_curr_bio != NULL);
3899 3899
3900 mutex_init(&wr_ctx->wr_lock); 3900 mutex_init(&wr_ctx->wr_lock);
3901 wr_ctx->wr_curr_bio = NULL; 3901 wr_ctx->wr_curr_bio = NULL;
3902 if (!is_dev_replace) 3902 if (!is_dev_replace)
3903 return 0; 3903 return 0;
3904 3904
3905 WARN_ON(!dev->bdev); 3905 WARN_ON(!dev->bdev);
3906 wr_ctx->pages_per_wr_bio = min_t(int, SCRUB_PAGES_PER_WR_BIO, 3906 wr_ctx->pages_per_wr_bio = min_t(int, SCRUB_PAGES_PER_WR_BIO,
3907 bio_get_nr_vecs(dev->bdev)); 3907 bio_get_nr_vecs(dev->bdev));
3908 wr_ctx->tgtdev = dev; 3908 wr_ctx->tgtdev = dev;
3909 atomic_set(&wr_ctx->flush_all_writes, 0); 3909 atomic_set(&wr_ctx->flush_all_writes, 0);
3910 return 0; 3910 return 0;
3911 } 3911 }
3912 3912
3913 static void scrub_free_wr_ctx(struct scrub_wr_ctx *wr_ctx) 3913 static void scrub_free_wr_ctx(struct scrub_wr_ctx *wr_ctx)
3914 { 3914 {
3915 mutex_lock(&wr_ctx->wr_lock); 3915 mutex_lock(&wr_ctx->wr_lock);
3916 kfree(wr_ctx->wr_curr_bio); 3916 kfree(wr_ctx->wr_curr_bio);
3917 wr_ctx->wr_curr_bio = NULL; 3917 wr_ctx->wr_curr_bio = NULL;
3918 mutex_unlock(&wr_ctx->wr_lock); 3918 mutex_unlock(&wr_ctx->wr_lock);
3919 } 3919 }
3920 3920
3921 static int copy_nocow_pages(struct scrub_ctx *sctx, u64 logical, u64 len, 3921 static int copy_nocow_pages(struct scrub_ctx *sctx, u64 logical, u64 len,
3922 int mirror_num, u64 physical_for_dev_replace) 3922 int mirror_num, u64 physical_for_dev_replace)
3923 { 3923 {
3924 struct scrub_copy_nocow_ctx *nocow_ctx; 3924 struct scrub_copy_nocow_ctx *nocow_ctx;
3925 struct btrfs_fs_info *fs_info = sctx->dev_root->fs_info; 3925 struct btrfs_fs_info *fs_info = sctx->dev_root->fs_info;
3926 3926
3927 nocow_ctx = kzalloc(sizeof(*nocow_ctx), GFP_NOFS); 3927 nocow_ctx = kzalloc(sizeof(*nocow_ctx), GFP_NOFS);
3928 if (!nocow_ctx) { 3928 if (!nocow_ctx) {
3929 spin_lock(&sctx->stat_lock); 3929 spin_lock(&sctx->stat_lock);
3930 sctx->stat.malloc_errors++; 3930 sctx->stat.malloc_errors++;
3931 spin_unlock(&sctx->stat_lock); 3931 spin_unlock(&sctx->stat_lock);
3932 return -ENOMEM; 3932 return -ENOMEM;
3933 } 3933 }
3934 3934
3935 scrub_pending_trans_workers_inc(sctx); 3935 scrub_pending_trans_workers_inc(sctx);
3936 3936
3937 nocow_ctx->sctx = sctx; 3937 nocow_ctx->sctx = sctx;
3938 nocow_ctx->logical = logical; 3938 nocow_ctx->logical = logical;
3939 nocow_ctx->len = len; 3939 nocow_ctx->len = len;
3940 nocow_ctx->mirror_num = mirror_num; 3940 nocow_ctx->mirror_num = mirror_num;
3941 nocow_ctx->physical_for_dev_replace = physical_for_dev_replace; 3941 nocow_ctx->physical_for_dev_replace = physical_for_dev_replace;
3942 btrfs_init_work(&nocow_ctx->work, btrfs_scrubnc_helper, 3942 btrfs_init_work(&nocow_ctx->work, btrfs_scrubnc_helper,
3943 copy_nocow_pages_worker, NULL, NULL); 3943 copy_nocow_pages_worker, NULL, NULL);
3944 INIT_LIST_HEAD(&nocow_ctx->inodes); 3944 INIT_LIST_HEAD(&nocow_ctx->inodes);
3945 btrfs_queue_work(fs_info->scrub_nocow_workers, 3945 btrfs_queue_work(fs_info->scrub_nocow_workers,
3946 &nocow_ctx->work); 3946 &nocow_ctx->work);
3947 3947
3948 return 0; 3948 return 0;
3949 } 3949 }
3950 3950
3951 static int record_inode_for_nocow(u64 inum, u64 offset, u64 root, void *ctx) 3951 static int record_inode_for_nocow(u64 inum, u64 offset, u64 root, void *ctx)
3952 { 3952 {
3953 struct scrub_copy_nocow_ctx *nocow_ctx = ctx; 3953 struct scrub_copy_nocow_ctx *nocow_ctx = ctx;
3954 struct scrub_nocow_inode *nocow_inode; 3954 struct scrub_nocow_inode *nocow_inode;
3955 3955
3956 nocow_inode = kzalloc(sizeof(*nocow_inode), GFP_NOFS); 3956 nocow_inode = kzalloc(sizeof(*nocow_inode), GFP_NOFS);
3957 if (!nocow_inode) 3957 if (!nocow_inode)
3958 return -ENOMEM; 3958 return -ENOMEM;
3959 nocow_inode->inum = inum; 3959 nocow_inode->inum = inum;
3960 nocow_inode->offset = offset; 3960 nocow_inode->offset = offset;
3961 nocow_inode->root = root; 3961 nocow_inode->root = root;
3962 list_add_tail(&nocow_inode->list, &nocow_ctx->inodes); 3962 list_add_tail(&nocow_inode->list, &nocow_ctx->inodes);
3963 return 0; 3963 return 0;
3964 } 3964 }
3965 3965
3966 #define COPY_COMPLETE 1 3966 #define COPY_COMPLETE 1
3967 3967
3968 static void copy_nocow_pages_worker(struct btrfs_work *work) 3968 static void copy_nocow_pages_worker(struct btrfs_work *work)
3969 { 3969 {
3970 struct scrub_copy_nocow_ctx *nocow_ctx = 3970 struct scrub_copy_nocow_ctx *nocow_ctx =
3971 container_of(work, struct scrub_copy_nocow_ctx, work); 3971 container_of(work, struct scrub_copy_nocow_ctx, work);
3972 struct scrub_ctx *sctx = nocow_ctx->sctx; 3972 struct scrub_ctx *sctx = nocow_ctx->sctx;
3973 u64 logical = nocow_ctx->logical; 3973 u64 logical = nocow_ctx->logical;
3974 u64 len = nocow_ctx->len; 3974 u64 len = nocow_ctx->len;
3975 int mirror_num = nocow_ctx->mirror_num; 3975 int mirror_num = nocow_ctx->mirror_num;
3976 u64 physical_for_dev_replace = nocow_ctx->physical_for_dev_replace; 3976 u64 physical_for_dev_replace = nocow_ctx->physical_for_dev_replace;
3977 int ret; 3977 int ret;
3978 struct btrfs_trans_handle *trans = NULL; 3978 struct btrfs_trans_handle *trans = NULL;
3979 struct btrfs_fs_info *fs_info; 3979 struct btrfs_fs_info *fs_info;
3980 struct btrfs_path *path; 3980 struct btrfs_path *path;
3981 struct btrfs_root *root; 3981 struct btrfs_root *root;
3982 int not_written = 0; 3982 int not_written = 0;
3983 3983
3984 fs_info = sctx->dev_root->fs_info; 3984 fs_info = sctx->dev_root->fs_info;
3985 root = fs_info->extent_root; 3985 root = fs_info->extent_root;
3986 3986
3987 path = btrfs_alloc_path(); 3987 path = btrfs_alloc_path();
3988 if (!path) { 3988 if (!path) {
3989 spin_lock(&sctx->stat_lock); 3989 spin_lock(&sctx->stat_lock);
3990 sctx->stat.malloc_errors++; 3990 sctx->stat.malloc_errors++;
3991 spin_unlock(&sctx->stat_lock); 3991 spin_unlock(&sctx->stat_lock);
3992 not_written = 1; 3992 not_written = 1;
3993 goto out; 3993 goto out;
3994 } 3994 }
3995 3995
3996 trans = btrfs_join_transaction(root); 3996 trans = btrfs_join_transaction(root);
3997 if (IS_ERR(trans)) { 3997 if (IS_ERR(trans)) {
3998 not_written = 1; 3998 not_written = 1;
3999 goto out; 3999 goto out;
4000 } 4000 }
4001 4001
4002 ret = iterate_inodes_from_logical(logical, fs_info, path, 4002 ret = iterate_inodes_from_logical(logical, fs_info, path,
4003 record_inode_for_nocow, nocow_ctx); 4003 record_inode_for_nocow, nocow_ctx);
4004 if (ret != 0 && ret != -ENOENT) { 4004 if (ret != 0 && ret != -ENOENT) {
4005 btrfs_warn(fs_info, "iterate_inodes_from_logical() failed: log %llu, " 4005 btrfs_warn(fs_info, "iterate_inodes_from_logical() failed: log %llu, "
4006 "phys %llu, len %llu, mir %u, ret %d", 4006 "phys %llu, len %llu, mir %u, ret %d",
4007 logical, physical_for_dev_replace, len, mirror_num, 4007 logical, physical_for_dev_replace, len, mirror_num,
4008 ret); 4008 ret);
4009 not_written = 1; 4009 not_written = 1;
4010 goto out; 4010 goto out;
4011 } 4011 }
4012 4012
4013 btrfs_end_transaction(trans, root); 4013 btrfs_end_transaction(trans, root);
4014 trans = NULL; 4014 trans = NULL;
4015 while (!list_empty(&nocow_ctx->inodes)) { 4015 while (!list_empty(&nocow_ctx->inodes)) {
4016 struct scrub_nocow_inode *entry; 4016 struct scrub_nocow_inode *entry;
4017 entry = list_first_entry(&nocow_ctx->inodes, 4017 entry = list_first_entry(&nocow_ctx->inodes,
4018 struct scrub_nocow_inode, 4018 struct scrub_nocow_inode,
4019 list); 4019 list);
4020 list_del_init(&entry->list); 4020 list_del_init(&entry->list);
4021 ret = copy_nocow_pages_for_inode(entry->inum, entry->offset, 4021 ret = copy_nocow_pages_for_inode(entry->inum, entry->offset,
4022 entry->root, nocow_ctx); 4022 entry->root, nocow_ctx);
4023 kfree(entry); 4023 kfree(entry);
4024 if (ret == COPY_COMPLETE) { 4024 if (ret == COPY_COMPLETE) {
4025 ret = 0; 4025 ret = 0;
4026 break; 4026 break;
4027 } else if (ret) { 4027 } else if (ret) {
4028 break; 4028 break;
4029 } 4029 }
4030 } 4030 }
4031 out: 4031 out:
4032 while (!list_empty(&nocow_ctx->inodes)) { 4032 while (!list_empty(&nocow_ctx->inodes)) {
4033 struct scrub_nocow_inode *entry; 4033 struct scrub_nocow_inode *entry;
4034 entry = list_first_entry(&nocow_ctx->inodes, 4034 entry = list_first_entry(&nocow_ctx->inodes,
4035 struct scrub_nocow_inode, 4035 struct scrub_nocow_inode,
4036 list); 4036 list);
4037 list_del_init(&entry->list); 4037 list_del_init(&entry->list);
4038 kfree(entry); 4038 kfree(entry);
4039 } 4039 }
4040 if (trans && !IS_ERR(trans)) 4040 if (trans && !IS_ERR(trans))
4041 btrfs_end_transaction(trans, root); 4041 btrfs_end_transaction(trans, root);
4042 if (not_written) 4042 if (not_written)
4043 btrfs_dev_replace_stats_inc(&fs_info->dev_replace. 4043 btrfs_dev_replace_stats_inc(&fs_info->dev_replace.
4044 num_uncorrectable_read_errors); 4044 num_uncorrectable_read_errors);
4045 4045
4046 btrfs_free_path(path); 4046 btrfs_free_path(path);
4047 kfree(nocow_ctx); 4047 kfree(nocow_ctx);
4048 4048
4049 scrub_pending_trans_workers_dec(sctx); 4049 scrub_pending_trans_workers_dec(sctx);
4050 } 4050 }
4051 4051
4052 static int check_extent_to_block(struct inode *inode, u64 start, u64 len, 4052 static int check_extent_to_block(struct inode *inode, u64 start, u64 len,
4053 u64 logical) 4053 u64 logical)
4054 { 4054 {
4055 struct extent_state *cached_state = NULL; 4055 struct extent_state *cached_state = NULL;
4056 struct btrfs_ordered_extent *ordered; 4056 struct btrfs_ordered_extent *ordered;
4057 struct extent_io_tree *io_tree; 4057 struct extent_io_tree *io_tree;
4058 struct extent_map *em; 4058 struct extent_map *em;
4059 u64 lockstart = start, lockend = start + len - 1; 4059 u64 lockstart = start, lockend = start + len - 1;
4060 int ret = 0; 4060 int ret = 0;
4061 4061
4062 io_tree = &BTRFS_I(inode)->io_tree; 4062 io_tree = &BTRFS_I(inode)->io_tree;
4063 4063
4064 lock_extent_bits(io_tree, lockstart, lockend, 0, &cached_state); 4064 lock_extent_bits(io_tree, lockstart, lockend, 0, &cached_state);
4065 ordered = btrfs_lookup_ordered_range(inode, lockstart, len); 4065 ordered = btrfs_lookup_ordered_range(inode, lockstart, len);
4066 if (ordered) { 4066 if (ordered) {
4067 btrfs_put_ordered_extent(ordered); 4067 btrfs_put_ordered_extent(ordered);
4068 ret = 1; 4068 ret = 1;
4069 goto out_unlock; 4069 goto out_unlock;
4070 } 4070 }
4071 4071
4072 em = btrfs_get_extent(inode, NULL, 0, start, len, 0); 4072 em = btrfs_get_extent(inode, NULL, 0, start, len, 0);
4073 if (IS_ERR(em)) { 4073 if (IS_ERR(em)) {
4074 ret = PTR_ERR(em); 4074 ret = PTR_ERR(em);
4075 goto out_unlock; 4075 goto out_unlock;
4076 } 4076 }
4077 4077
4078 /* 4078 /*
4079 * This extent does not actually cover the logical extent anymore, 4079 * This extent does not actually cover the logical extent anymore,
4080 * move on to the next inode. 4080 * move on to the next inode.
4081 */ 4081 */
4082 if (em->block_start > logical || 4082 if (em->block_start > logical ||
4083 em->block_start + em->block_len < logical + len) { 4083 em->block_start + em->block_len < logical + len) {
4084 free_extent_map(em); 4084 free_extent_map(em);
4085 ret = 1; 4085 ret = 1;
4086 goto out_unlock; 4086 goto out_unlock;
4087 } 4087 }
4088 free_extent_map(em); 4088 free_extent_map(em);
4089 4089
4090 out_unlock: 4090 out_unlock:
4091 unlock_extent_cached(io_tree, lockstart, lockend, &cached_state, 4091 unlock_extent_cached(io_tree, lockstart, lockend, &cached_state,
4092 GFP_NOFS); 4092 GFP_NOFS);
4093 return ret; 4093 return ret;
4094 } 4094 }
4095 4095
4096 static int copy_nocow_pages_for_inode(u64 inum, u64 offset, u64 root, 4096 static int copy_nocow_pages_for_inode(u64 inum, u64 offset, u64 root,
4097 struct scrub_copy_nocow_ctx *nocow_ctx) 4097 struct scrub_copy_nocow_ctx *nocow_ctx)
4098 { 4098 {
4099 struct btrfs_fs_info *fs_info = nocow_ctx->sctx->dev_root->fs_info; 4099 struct btrfs_fs_info *fs_info = nocow_ctx->sctx->dev_root->fs_info;
4100 struct btrfs_key key; 4100 struct btrfs_key key;
4101 struct inode *inode; 4101 struct inode *inode;
4102 struct page *page; 4102 struct page *page;
4103 struct btrfs_root *local_root; 4103 struct btrfs_root *local_root;
4104 struct extent_io_tree *io_tree; 4104 struct extent_io_tree *io_tree;
4105 u64 physical_for_dev_replace; 4105 u64 physical_for_dev_replace;
4106 u64 nocow_ctx_logical; 4106 u64 nocow_ctx_logical;
4107 u64 len = nocow_ctx->len; 4107 u64 len = nocow_ctx->len;
4108 unsigned long index; 4108 unsigned long index;
4109 int srcu_index; 4109 int srcu_index;
4110 int ret = 0; 4110 int ret = 0;
4111 int err = 0; 4111 int err = 0;
4112 4112
4113 key.objectid = root; 4113 key.objectid = root;
4114 key.type = BTRFS_ROOT_ITEM_KEY; 4114 key.type = BTRFS_ROOT_ITEM_KEY;
4115 key.offset = (u64)-1; 4115 key.offset = (u64)-1;
4116 4116
4117 srcu_index = srcu_read_lock(&fs_info->subvol_srcu); 4117 srcu_index = srcu_read_lock(&fs_info->subvol_srcu);
4118 4118
4119 local_root = btrfs_read_fs_root_no_name(fs_info, &key); 4119 local_root = btrfs_read_fs_root_no_name(fs_info, &key);
4120 if (IS_ERR(local_root)) { 4120 if (IS_ERR(local_root)) {
4121 srcu_read_unlock(&fs_info->subvol_srcu, srcu_index); 4121 srcu_read_unlock(&fs_info->subvol_srcu, srcu_index);
4122 return PTR_ERR(local_root); 4122 return PTR_ERR(local_root);
4123 } 4123 }
4124 4124
4125 key.type = BTRFS_INODE_ITEM_KEY; 4125 key.type = BTRFS_INODE_ITEM_KEY;
4126 key.objectid = inum; 4126 key.objectid = inum;
4127 key.offset = 0; 4127 key.offset = 0;
4128 inode = btrfs_iget(fs_info->sb, &key, local_root, NULL); 4128 inode = btrfs_iget(fs_info->sb, &key, local_root, NULL);
4129 srcu_read_unlock(&fs_info->subvol_srcu, srcu_index); 4129 srcu_read_unlock(&fs_info->subvol_srcu, srcu_index);
4130 if (IS_ERR(inode)) 4130 if (IS_ERR(inode))
4131 return PTR_ERR(inode); 4131 return PTR_ERR(inode);
4132 4132
4133 /* Avoid truncate/dio/punch hole.. */ 4133 /* Avoid truncate/dio/punch hole.. */
4134 mutex_lock(&inode->i_mutex); 4134 mutex_lock(&inode->i_mutex);
4135 inode_dio_wait(inode); 4135 inode_dio_wait(inode);
4136 4136
4137 physical_for_dev_replace = nocow_ctx->physical_for_dev_replace; 4137 physical_for_dev_replace = nocow_ctx->physical_for_dev_replace;
4138 io_tree = &BTRFS_I(inode)->io_tree; 4138 io_tree = &BTRFS_I(inode)->io_tree;
4139 nocow_ctx_logical = nocow_ctx->logical; 4139 nocow_ctx_logical = nocow_ctx->logical;
4140 4140
4141 ret = check_extent_to_block(inode, offset, len, nocow_ctx_logical); 4141 ret = check_extent_to_block(inode, offset, len, nocow_ctx_logical);
4142 if (ret) { 4142 if (ret) {
4143 ret = ret > 0 ? 0 : ret; 4143 ret = ret > 0 ? 0 : ret;
4144 goto out; 4144 goto out;
4145 } 4145 }
4146 4146
4147 while (len >= PAGE_CACHE_SIZE) { 4147 while (len >= PAGE_CACHE_SIZE) {
4148 index = offset >> PAGE_CACHE_SHIFT; 4148 index = offset >> PAGE_CACHE_SHIFT;
4149 again: 4149 again:
4150 page = find_or_create_page(inode->i_mapping, index, GFP_NOFS); 4150 page = find_or_create_page(inode->i_mapping, index, GFP_NOFS);
4151 if (!page) { 4151 if (!page) {
4152 btrfs_err(fs_info, "find_or_create_page() failed"); 4152 btrfs_err(fs_info, "find_or_create_page() failed");
4153 ret = -ENOMEM; 4153 ret = -ENOMEM;
4154 goto out; 4154 goto out;
4155 } 4155 }
4156 4156
4157 if (PageUptodate(page)) { 4157 if (PageUptodate(page)) {
4158 if (PageDirty(page)) 4158 if (PageDirty(page))
4159 goto next_page; 4159 goto next_page;
4160 } else { 4160 } else {
4161 ClearPageError(page); 4161 ClearPageError(page);
4162 err = extent_read_full_page(io_tree, page, 4162 err = extent_read_full_page(io_tree, page,
4163 btrfs_get_extent, 4163 btrfs_get_extent,
4164 nocow_ctx->mirror_num); 4164 nocow_ctx->mirror_num);
4165 if (err) { 4165 if (err) {
4166 ret = err; 4166 ret = err;
4167 goto next_page; 4167 goto next_page;
4168 } 4168 }
4169 4169
4170 lock_page(page); 4170 lock_page(page);
4171 /* 4171 /*
4172 * If the page has been remove from the page cache, 4172 * If the page has been remove from the page cache,
4173 * the data on it is meaningless, because it may be 4173 * the data on it is meaningless, because it may be
4174 * old one, the new data may be written into the new 4174 * old one, the new data may be written into the new
4175 * page in the page cache. 4175 * page in the page cache.
4176 */ 4176 */
4177 if (page->mapping != inode->i_mapping) { 4177 if (page->mapping != inode->i_mapping) {
4178 unlock_page(page); 4178 unlock_page(page);
4179 page_cache_release(page); 4179 page_cache_release(page);
4180 goto again; 4180 goto again;
4181 } 4181 }
4182 if (!PageUptodate(page)) { 4182 if (!PageUptodate(page)) {
4183 ret = -EIO; 4183 ret = -EIO;
4184 goto next_page; 4184 goto next_page;
4185 } 4185 }
4186 } 4186 }
4187 4187
4188 ret = check_extent_to_block(inode, offset, len, 4188 ret = check_extent_to_block(inode, offset, len,
4189 nocow_ctx_logical); 4189 nocow_ctx_logical);
4190 if (ret) { 4190 if (ret) {
4191 ret = ret > 0 ? 0 : ret; 4191 ret = ret > 0 ? 0 : ret;
4192 goto next_page; 4192 goto next_page;
4193 } 4193 }
4194 4194
4195 err = write_page_nocow(nocow_ctx->sctx, 4195 err = write_page_nocow(nocow_ctx->sctx,
4196 physical_for_dev_replace, page); 4196 physical_for_dev_replace, page);
4197 if (err) 4197 if (err)
4198 ret = err; 4198 ret = err;
4199 next_page: 4199 next_page:
4200 unlock_page(page); 4200 unlock_page(page);
4201 page_cache_release(page); 4201 page_cache_release(page);
4202 4202
4203 if (ret) 4203 if (ret)
4204 break; 4204 break;
4205 4205
4206 offset += PAGE_CACHE_SIZE; 4206 offset += PAGE_CACHE_SIZE;
4207 physical_for_dev_replace += PAGE_CACHE_SIZE; 4207 physical_for_dev_replace += PAGE_CACHE_SIZE;
4208 nocow_ctx_logical += PAGE_CACHE_SIZE; 4208 nocow_ctx_logical += PAGE_CACHE_SIZE;
4209 len -= PAGE_CACHE_SIZE; 4209 len -= PAGE_CACHE_SIZE;
4210 } 4210 }
4211 ret = COPY_COMPLETE; 4211 ret = COPY_COMPLETE;
4212 out: 4212 out:
4213 mutex_unlock(&inode->i_mutex); 4213 mutex_unlock(&inode->i_mutex);
4214 iput(inode); 4214 iput(inode);
4215 return ret; 4215 return ret;
4216 } 4216 }
4217 4217
4218 static int write_page_nocow(struct scrub_ctx *sctx, 4218 static int write_page_nocow(struct scrub_ctx *sctx,
4219 u64 physical_for_dev_replace, struct page *page) 4219 u64 physical_for_dev_replace, struct page *page)
4220 { 4220 {
4221 struct bio *bio; 4221 struct bio *bio;
4222 struct btrfs_device *dev; 4222 struct btrfs_device *dev;
4223 int ret; 4223 int ret;
4224 4224
4225 dev = sctx->wr_ctx.tgtdev; 4225 dev = sctx->wr_ctx.tgtdev;
4226 if (!dev) 4226 if (!dev)
4227 return -EIO; 4227 return -EIO;
4228 if (!dev->bdev) { 4228 if (!dev->bdev) {
4229 printk_ratelimited(KERN_WARNING 4229 printk_ratelimited(KERN_WARNING
4230 "BTRFS: scrub write_page_nocow(bdev == NULL) is unexpected!\n"); 4230 "BTRFS: scrub write_page_nocow(bdev == NULL) is unexpected!\n");
4231 return -EIO; 4231 return -EIO;
4232 } 4232 }
4233 bio = btrfs_io_bio_alloc(GFP_NOFS, 1); 4233 bio = btrfs_io_bio_alloc(GFP_NOFS, 1);
4234 if (!bio) { 4234 if (!bio) {
4235 spin_lock(&sctx->stat_lock); 4235 spin_lock(&sctx->stat_lock);
4236 sctx->stat.malloc_errors++; 4236 sctx->stat.malloc_errors++;
4237 spin_unlock(&sctx->stat_lock); 4237 spin_unlock(&sctx->stat_lock);
4238 return -ENOMEM; 4238 return -ENOMEM;
4239 } 4239 }
4240 bio->bi_iter.bi_size = 0; 4240 bio->bi_iter.bi_size = 0;
4241 bio->bi_iter.bi_sector = physical_for_dev_replace >> 9; 4241 bio->bi_iter.bi_sector = physical_for_dev_replace >> 9;
4242 bio->bi_bdev = dev->bdev; 4242 bio->bi_bdev = dev->bdev;
4243 ret = bio_add_page(bio, page, PAGE_CACHE_SIZE, 0); 4243 ret = bio_add_page(bio, page, PAGE_CACHE_SIZE, 0);
4244 if (ret != PAGE_CACHE_SIZE) { 4244 if (ret != PAGE_CACHE_SIZE) {
4245 leave_with_eio: 4245 leave_with_eio:
4246 bio_put(bio); 4246 bio_put(bio);
4247 btrfs_dev_stat_inc_and_print(dev, BTRFS_DEV_STAT_WRITE_ERRS); 4247 btrfs_dev_stat_inc_and_print(dev, BTRFS_DEV_STAT_WRITE_ERRS);
4248 return -EIO; 4248 return -EIO;
4249 } 4249 }
4250 4250
4251 if (btrfsic_submit_bio_wait(WRITE_SYNC, bio)) 4251 if (btrfsic_submit_bio_wait(WRITE_SYNC, bio))
4252 goto leave_with_eio; 4252 goto leave_with_eio;
4253 4253
4254 bio_put(bio); 4254 bio_put(bio);
4255 return 0; 4255 return 0;
4256 } 4256 }