Btrfs: don't read leaf blocks containing only checksums during truncate
[linux-2.6-block.git] / fs / btrfs / file.c
CommitLineData
6cbd5570
CM
1/*
2 * Copyright (C) 2007 Oracle. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 * Boston, MA 021110-1307, USA.
17 */
18
39279cc3
CM
19#include <linux/fs.h>
20#include <linux/pagemap.h>
21#include <linux/highmem.h>
22#include <linux/time.h>
23#include <linux/init.h>
24#include <linux/string.h>
25#include <linux/smp_lock.h>
26#include <linux/backing-dev.h>
27#include <linux/mpage.h>
28#include <linux/swap.h>
29#include <linux/writeback.h>
30#include <linux/statfs.h>
31#include <linux/compat.h>
92fee66d 32#include <linux/version.h>
39279cc3
CM
33#include "ctree.h"
34#include "disk-io.h"
35#include "transaction.h"
36#include "btrfs_inode.h"
37#include "ioctl.h"
38#include "print-tree.h"
e02119d5
CM
39#include "tree-log.h"
40#include "locking.h"
12fa8ec6 41#include "compat.h"
39279cc3
CM
42
43
d352ac68
CM
44/* simple helper to fault in pages and copy. This should go away
45 * and be replaced with calls into generic code.
46 */
a1b32a59
CM
47static int noinline btrfs_copy_from_user(loff_t pos, int num_pages,
48 int write_bytes,
49 struct page **prepared_pages,
50 const char __user * buf)
39279cc3
CM
51{
52 long page_fault = 0;
53 int i;
54 int offset = pos & (PAGE_CACHE_SIZE - 1);
55
56 for (i = 0; i < num_pages && write_bytes > 0; i++, offset = 0) {
57 size_t count = min_t(size_t,
58 PAGE_CACHE_SIZE - offset, write_bytes);
59 struct page *page = prepared_pages[i];
60 fault_in_pages_readable(buf, count);
61
62 /* Copy data from userspace to the current page */
63 kmap(page);
64 page_fault = __copy_from_user(page_address(page) + offset,
65 buf, count);
66 /* Flush processor's dcache for this page */
67 flush_dcache_page(page);
68 kunmap(page);
69 buf += count;
70 write_bytes -= count;
71
72 if (page_fault)
73 break;
74 }
75 return page_fault ? -EFAULT : 0;
76}
77
d352ac68
CM
78/*
79 * unlocks pages after btrfs_file_write is done with them
80 */
a1b32a59 81static void noinline btrfs_drop_pages(struct page **pages, size_t num_pages)
39279cc3
CM
82{
83 size_t i;
84 for (i = 0; i < num_pages; i++) {
85 if (!pages[i])
86 break;
d352ac68
CM
87 /* page checked is some magic around finding pages that
88 * have been modified without going through btrfs_set_page_dirty
89 * clear it here
90 */
4a096752 91 ClearPageChecked(pages[i]);
39279cc3
CM
92 unlock_page(pages[i]);
93 mark_page_accessed(pages[i]);
94 page_cache_release(pages[i]);
95 }
96}
97
d352ac68
CM
98/* this does all the hard work for inserting an inline extent into
99 * the btree. Any existing inline extent is extended as required to make room,
100 * otherwise things are inserted as required into the btree
101 */
98ed5174 102static int noinline insert_inline_extent(struct btrfs_trans_handle *trans,
a52d9a80 103 struct btrfs_root *root, struct inode *inode,
3326d1b0
CM
104 u64 offset, size_t size,
105 struct page **pages, size_t page_offset,
106 int num_pages)
54aa1f4d
CM
107{
108 struct btrfs_key key;
109 struct btrfs_path *path;
5f39d397
CM
110 struct extent_buffer *leaf;
111 char *kaddr;
112 unsigned long ptr;
54aa1f4d 113 struct btrfs_file_extent_item *ei;
3326d1b0 114 struct page *page;
54aa1f4d
CM
115 u32 datasize;
116 int err = 0;
117 int ret;
3326d1b0
CM
118 int i;
119 ssize_t cur_size;
54aa1f4d
CM
120
121 path = btrfs_alloc_path();
122 if (!path)
123 return -ENOMEM;
124
54aa1f4d
CM
125 btrfs_set_trans_block_group(trans, inode);
126
127 key.objectid = inode->i_ino;
128 key.offset = offset;
54aa1f4d 129 btrfs_set_key_type(&key, BTRFS_EXTENT_DATA_KEY);
54aa1f4d 130
3326d1b0
CM
131 ret = btrfs_search_slot(trans, root, &key, path, 0, 1);
132 if (ret < 0) {
54aa1f4d
CM
133 err = ret;
134 goto fail;
135 }
3326d1b0 136 if (ret == 1) {
179e29e4
CM
137 struct btrfs_key found_key;
138
139 if (path->slots[0] == 0)
140 goto insert;
141
3326d1b0
CM
142 path->slots[0]--;
143 leaf = path->nodes[0];
179e29e4
CM
144 btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]);
145
146 if (found_key.objectid != inode->i_ino)
147 goto insert;
148
149 if (found_key.type != BTRFS_EXTENT_DATA_KEY)
150 goto insert;
3326d1b0
CM
151 ei = btrfs_item_ptr(leaf, path->slots[0],
152 struct btrfs_file_extent_item);
153
154 if (btrfs_file_extent_type(leaf, ei) !=
155 BTRFS_FILE_EXTENT_INLINE) {
156 goto insert;
157 }
158 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
159 ret = 0;
160 }
161 if (ret == 0) {
162 u32 found_size;
18f16f7b 163 u64 found_end;
3326d1b0
CM
164
165 leaf = path->nodes[0];
166 ei = btrfs_item_ptr(leaf, path->slots[0],
167 struct btrfs_file_extent_item);
168
169 if (btrfs_file_extent_type(leaf, ei) !=
170 BTRFS_FILE_EXTENT_INLINE) {
171 err = ret;
172 btrfs_print_leaf(root, leaf);
173 printk("found wasn't inline offset %Lu inode %lu\n",
174 offset, inode->i_ino);
175 goto fail;
176 }
3326d1b0
CM
177 found_size = btrfs_file_extent_inline_len(leaf,
178 btrfs_item_nr(leaf, path->slots[0]));
18f16f7b 179 found_end = key.offset + found_size;
3326d1b0 180
18f16f7b 181 if (found_end < offset + size) {
3326d1b0
CM
182 btrfs_release_path(root, path);
183 ret = btrfs_search_slot(trans, root, &key, path,
18f16f7b 184 offset + size - found_end, 1);
3326d1b0 185 BUG_ON(ret != 0);
179e29e4 186
3326d1b0 187 ret = btrfs_extend_item(trans, root, path,
18f16f7b 188 offset + size - found_end);
3326d1b0
CM
189 if (ret) {
190 err = ret;
191 goto fail;
192 }
193 leaf = path->nodes[0];
194 ei = btrfs_item_ptr(leaf, path->slots[0],
195 struct btrfs_file_extent_item);
9069218d 196 inode->i_blocks += (offset + size - found_end) >> 9;
3326d1b0 197 }
18f16f7b
Y
198 if (found_end < offset) {
199 ptr = btrfs_file_extent_inline_start(ei) + found_size;
200 memset_extent_buffer(leaf, 0, ptr, offset - found_end);
201 }
3326d1b0
CM
202 } else {
203insert:
204 btrfs_release_path(root, path);
18f16f7b 205 datasize = offset + size - key.offset;
9069218d 206 inode->i_blocks += datasize >> 9;
18f16f7b 207 datasize = btrfs_file_extent_calc_inline_size(datasize);
3326d1b0
CM
208 ret = btrfs_insert_empty_item(trans, root, path, &key,
209 datasize);
210 if (ret) {
211 err = ret;
212 printk("got bad ret %d\n", ret);
213 goto fail;
214 }
215 leaf = path->nodes[0];
216 ei = btrfs_item_ptr(leaf, path->slots[0],
217 struct btrfs_file_extent_item);
218 btrfs_set_file_extent_generation(leaf, ei, trans->transid);
219 btrfs_set_file_extent_type(leaf, ei, BTRFS_FILE_EXTENT_INLINE);
220 }
18f16f7b 221 ptr = btrfs_file_extent_inline_start(ei) + offset - key.offset;
3326d1b0
CM
222
223 cur_size = size;
224 i = 0;
225 while (size > 0) {
226 page = pages[i];
227 kaddr = kmap_atomic(page, KM_USER0);
ae2f5411 228 cur_size = min_t(size_t, PAGE_CACHE_SIZE - page_offset, size);
3326d1b0
CM
229 write_extent_buffer(leaf, kaddr + page_offset, ptr, cur_size);
230 kunmap_atomic(kaddr, KM_USER0);
231 page_offset = 0;
232 ptr += cur_size;
233 size -= cur_size;
234 if (i >= num_pages) {
235 printk("i %d num_pages %d\n", i, num_pages);
236 }
237 i++;
238 }
5f39d397 239 btrfs_mark_buffer_dirty(leaf);
54aa1f4d
CM
240fail:
241 btrfs_free_path(path);
54aa1f4d
CM
242 return err;
243}
244
d352ac68
CM
245/*
246 * after copy_from_user, pages need to be dirtied and we need to make
247 * sure holes are created between the current EOF and the start of
248 * any next extents (if required).
249 *
250 * this also makes the decision about creating an inline extent vs
251 * doing real data extents, marking pages dirty and delalloc as required.
252 */
98ed5174 253static int noinline dirty_and_release_pages(struct btrfs_trans_handle *trans,
39279cc3
CM
254 struct btrfs_root *root,
255 struct file *file,
256 struct page **pages,
257 size_t num_pages,
258 loff_t pos,
259 size_t write_bytes)
260{
39279cc3 261 int err = 0;
a52d9a80 262 int i;
6da6abae 263 struct inode *inode = fdentry(file)->d_inode;
d1310b2e 264 struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
db94535d
CM
265 u64 hint_byte;
266 u64 num_bytes;
a52d9a80
CM
267 u64 start_pos;
268 u64 end_of_last_block;
269 u64 end_pos = pos + write_bytes;
dcfec0dc 270 u64 inline_size;
ee6e6504 271 int did_inline = 0;
a52d9a80 272 loff_t isize = i_size_read(inode);
39279cc3 273
5f39d397 274 start_pos = pos & ~((u64)root->sectorsize - 1);
db94535d
CM
275 num_bytes = (write_bytes + pos - start_pos +
276 root->sectorsize - 1) & ~((u64)root->sectorsize - 1);
39279cc3 277
db94535d
CM
278 end_of_last_block = start_pos + num_bytes - 1;
279
d1310b2e 280 lock_extent(io_tree, start_pos, end_of_last_block, GFP_NOFS);
37d1aeee 281 trans = btrfs_join_transaction(root, 1);
a52d9a80
CM
282 if (!trans) {
283 err = -ENOMEM;
284 goto out_unlock;
285 }
286 btrfs_set_trans_block_group(trans, inode);
db94535d 287 hint_byte = 0;
a52d9a80
CM
288
289 if ((end_of_last_block & 4095) == 0) {
9433063b 290 printk("strange end of last %Lu %zu %Lu\n", start_pos, write_bytes, end_of_last_block);
a52d9a80 291 }
d1310b2e 292 set_extent_uptodate(io_tree, start_pos, end_of_last_block, GFP_NOFS);
a52d9a80
CM
293
294 /* FIXME...EIEIO, ENOSPC and more */
a52d9a80 295 /* insert any holes we need to create */
1b1e2135 296 if (isize < start_pos) {
a52d9a80
CM
297 u64 last_pos_in_file;
298 u64 hole_size;
5f39d397 299 u64 mask = root->sectorsize - 1;
a52d9a80 300 last_pos_in_file = (isize + mask) & ~mask;
1b1e2135 301 hole_size = (start_pos - last_pos_in_file + mask) & ~mask;
e6dcd2dc
CM
302 if (hole_size > 0) {
303 btrfs_wait_ordered_range(inode, last_pos_in_file,
304 last_pos_in_file + hole_size);
ee6e6504 305 mutex_lock(&BTRFS_I(inode)->extent_mutex);
2bf5a725
CM
306 err = btrfs_drop_extents(trans, root, inode,
307 last_pos_in_file,
308 last_pos_in_file + hole_size,
3326d1b0 309 last_pos_in_file,
db94535d 310 &hint_byte);
2bf5a725
CM
311 if (err)
312 goto failed;
313
a52d9a80
CM
314 err = btrfs_insert_file_extent(trans, root,
315 inode->i_ino,
316 last_pos_in_file,
f2eb0a24 317 0, 0, hole_size, 0);
d1310b2e 318 btrfs_drop_extent_cache(inode, last_pos_in_file,
5b21f2ed 319 last_pos_in_file + hole_size - 1, 0);
ee6e6504 320 mutex_unlock(&BTRFS_I(inode)->extent_mutex);
5f56406a 321 btrfs_check_file(root, inode);
a52d9a80
CM
322 }
323 if (err)
39279cc3 324 goto failed;
a52d9a80
CM
325 }
326
327 /*
328 * either allocate an extent for the new bytes or setup the key
329 * to show we are doing inline data in the extent
330 */
3326d1b0
CM
331 inline_size = end_pos;
332 if (isize >= BTRFS_MAX_INLINE_DATA_SIZE(root) ||
6f568d35
CM
333 inline_size > root->fs_info->max_inline ||
334 (inline_size & (root->sectorsize -1)) == 0 ||
3326d1b0 335 inline_size >= BTRFS_MAX_INLINE_DATA_SIZE(root)) {
e6dcd2dc
CM
336 /* check for reserved extents on each page, we don't want
337 * to reset the delalloc bit on things that already have
338 * extents reserved.
339 */
ea8c2819 340 btrfs_set_extent_delalloc(inode, start_pos, end_of_last_block);
a52d9a80
CM
341 for (i = 0; i < num_pages; i++) {
342 struct page *p = pages[i];
343 SetPageUptodate(p);
247e743c 344 ClearPageChecked(p);
b888db2b 345 set_page_dirty(p);
39279cc3 346 }
a52d9a80 347 } else {
3326d1b0 348 u64 aligned_end;
b888db2b 349 /* step one, delete the existing extents in this range */
3326d1b0
CM
350 aligned_end = (pos + write_bytes + root->sectorsize - 1) &
351 ~((u64)root->sectorsize - 1);
ee6e6504 352 mutex_lock(&BTRFS_I(inode)->extent_mutex);
2bf5a725 353 err = btrfs_drop_extents(trans, root, inode, start_pos,
179e29e4 354 aligned_end, aligned_end, &hint_byte);
2bf5a725
CM
355 if (err)
356 goto failed;
dcfec0dc
Y
357 if (isize > inline_size)
358 inline_size = min_t(u64, isize, aligned_end);
359 inline_size -= start_pos;
a52d9a80 360 err = insert_inline_extent(trans, root, inode, start_pos,
dcfec0dc 361 inline_size, pages, 0, num_pages);
5b21f2ed 362 btrfs_drop_extent_cache(inode, start_pos, aligned_end - 1, 0);
a52d9a80 363 BUG_ON(err);
ee6e6504 364 mutex_unlock(&BTRFS_I(inode)->extent_mutex);
f87f057b
CM
365
366 /*
367 * an ugly way to do all the prop accounting around
368 * the page bits and mapping tags
369 */
370 set_page_writeback(pages[0]);
371 end_page_writeback(pages[0]);
ee6e6504 372 did_inline = 1;
a52d9a80
CM
373 }
374 if (end_pos > isize) {
375 i_size_write(inode, end_pos);
ee6e6504
CM
376 if (did_inline)
377 BTRFS_I(inode)->disk_i_size = end_pos;
a52d9a80 378 btrfs_update_inode(trans, root, inode);
39279cc3
CM
379 }
380failed:
017e5369 381 err = btrfs_end_transaction(trans, root);
a52d9a80 382out_unlock:
d1310b2e 383 unlock_extent(io_tree, start_pos, end_of_last_block, GFP_NOFS);
39279cc3
CM
384 return err;
385}
386
d352ac68
CM
387/*
388 * this drops all the extents in the cache that intersect the range
389 * [start, end]. Existing extents are split as required.
390 */
5b21f2ed
ZY
391int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end,
392 int skip_pinned)
a52d9a80
CM
393{
394 struct extent_map *em;
3b951516
CM
395 struct extent_map *split = NULL;
396 struct extent_map *split2 = NULL;
a52d9a80 397 struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree;
39b5637f 398 u64 len = end - start + 1;
3b951516
CM
399 int ret;
400 int testend = 1;
5b21f2ed 401 unsigned long flags;
a52d9a80 402
e6dcd2dc 403 WARN_ON(end < start);
3b951516 404 if (end == (u64)-1) {
39b5637f 405 len = (u64)-1;
3b951516
CM
406 testend = 0;
407 }
a52d9a80 408 while(1) {
3b951516
CM
409 if (!split)
410 split = alloc_extent_map(GFP_NOFS);
411 if (!split2)
412 split2 = alloc_extent_map(GFP_NOFS);
413
d1310b2e 414 spin_lock(&em_tree->lock);
39b5637f 415 em = lookup_extent_mapping(em_tree, start, len);
d1310b2e
CM
416 if (!em) {
417 spin_unlock(&em_tree->lock);
a52d9a80 418 break;
d1310b2e 419 }
5b21f2ed
ZY
420 flags = em->flags;
421 if (skip_pinned && test_bit(EXTENT_FLAG_PINNED, &em->flags)) {
422 spin_unlock(&em_tree->lock);
423 if (em->start <= start &&
424 (!testend || em->start + em->len >= start + len)) {
425 free_extent_map(em);
426 break;
427 }
428 if (start < em->start) {
429 len = em->start - start;
430 } else {
431 len = start + len - (em->start + em->len);
432 start = em->start + em->len;
433 }
434 free_extent_map(em);
435 continue;
436 }
3ce7e67a 437 clear_bit(EXTENT_FLAG_PINNED, &em->flags);
a52d9a80 438 remove_extent_mapping(em_tree, em);
3b951516
CM
439
440 if (em->block_start < EXTENT_MAP_LAST_BYTE &&
441 em->start < start) {
442 split->start = em->start;
443 split->len = start - em->start;
444 split->block_start = em->block_start;
445 split->bdev = em->bdev;
5b21f2ed 446 split->flags = flags;
3b951516
CM
447 ret = add_extent_mapping(em_tree, split);
448 BUG_ON(ret);
449 free_extent_map(split);
450 split = split2;
451 split2 = NULL;
452 }
453 if (em->block_start < EXTENT_MAP_LAST_BYTE &&
454 testend && em->start + em->len > start + len) {
455 u64 diff = start + len - em->start;
456
457 split->start = start + len;
458 split->len = em->start + em->len - (start + len);
459 split->bdev = em->bdev;
5b21f2ed 460 split->flags = flags;
3b951516
CM
461
462 split->block_start = em->block_start + diff;
463
464 ret = add_extent_mapping(em_tree, split);
465 BUG_ON(ret);
466 free_extent_map(split);
467 split = NULL;
468 }
d1310b2e
CM
469 spin_unlock(&em_tree->lock);
470
a52d9a80
CM
471 /* once for us */
472 free_extent_map(em);
473 /* once for the tree*/
474 free_extent_map(em);
475 }
3b951516
CM
476 if (split)
477 free_extent_map(split);
478 if (split2)
479 free_extent_map(split2);
a52d9a80
CM
480 return 0;
481}
482
5f56406a
CM
483int btrfs_check_file(struct btrfs_root *root, struct inode *inode)
484{
485 return 0;
486#if 0
487 struct btrfs_path *path;
488 struct btrfs_key found_key;
489 struct extent_buffer *leaf;
490 struct btrfs_file_extent_item *extent;
491 u64 last_offset = 0;
492 int nritems;
493 int slot;
494 int found_type;
495 int ret;
496 int err = 0;
497 u64 extent_end = 0;
498
499 path = btrfs_alloc_path();
500 ret = btrfs_lookup_file_extent(NULL, root, path, inode->i_ino,
501 last_offset, 0);
502 while(1) {
503 nritems = btrfs_header_nritems(path->nodes[0]);
504 if (path->slots[0] >= nritems) {
505 ret = btrfs_next_leaf(root, path);
506 if (ret)
507 goto out;
508 nritems = btrfs_header_nritems(path->nodes[0]);
509 }
510 slot = path->slots[0];
511 leaf = path->nodes[0];
512 btrfs_item_key_to_cpu(leaf, &found_key, slot);
513 if (found_key.objectid != inode->i_ino)
514 break;
515 if (found_key.type != BTRFS_EXTENT_DATA_KEY)
516 goto out;
517
9069218d 518 if (found_key.offset < last_offset) {
5f56406a
CM
519 WARN_ON(1);
520 btrfs_print_leaf(root, leaf);
521 printk("inode %lu found offset %Lu expected %Lu\n",
522 inode->i_ino, found_key.offset, last_offset);
523 err = 1;
524 goto out;
525 }
526 extent = btrfs_item_ptr(leaf, slot,
527 struct btrfs_file_extent_item);
528 found_type = btrfs_file_extent_type(leaf, extent);
529 if (found_type == BTRFS_FILE_EXTENT_REG) {
530 extent_end = found_key.offset +
531 btrfs_file_extent_num_bytes(leaf, extent);
532 } else if (found_type == BTRFS_FILE_EXTENT_INLINE) {
533 struct btrfs_item *item;
534 item = btrfs_item_nr(leaf, slot);
535 extent_end = found_key.offset +
536 btrfs_file_extent_inline_len(leaf, item);
537 extent_end = (extent_end + root->sectorsize - 1) &
538 ~((u64)root->sectorsize -1 );
539 }
540 last_offset = extent_end;
541 path->slots[0]++;
542 }
9069218d 543 if (0 && last_offset < inode->i_size) {
5f56406a
CM
544 WARN_ON(1);
545 btrfs_print_leaf(root, leaf);
546 printk("inode %lu found offset %Lu size %Lu\n", inode->i_ino,
547 last_offset, inode->i_size);
548 err = 1;
549
550 }
551out:
552 btrfs_free_path(path);
553 return err;
554#endif
555}
556
39279cc3
CM
557/*
558 * this is very complex, but the basic idea is to drop all extents
559 * in the range start - end. hint_block is filled in with a block number
560 * that would be a good hint to the block allocator for this file.
561 *
562 * If an extent intersects the range but is not entirely inside the range
563 * it is either truncated or split. Anything entirely inside the range
564 * is deleted from the tree.
d352ac68
CM
565 *
566 * inline_limit is used to tell this code which offsets in the file to keep
567 * if they contain inline extents.
39279cc3 568 */
a1b32a59 569int noinline btrfs_drop_extents(struct btrfs_trans_handle *trans,
39279cc3 570 struct btrfs_root *root, struct inode *inode,
00f5c795 571 u64 start, u64 end, u64 inline_limit, u64 *hint_byte)
39279cc3 572{
00f5c795
CM
573 u64 extent_end = 0;
574 u64 search_start = start;
31840ae1
ZY
575 u64 leaf_start;
576 u64 root_gen;
577 u64 root_owner;
5f39d397 578 struct extent_buffer *leaf;
39279cc3 579 struct btrfs_file_extent_item *extent;
39279cc3 580 struct btrfs_path *path;
00f5c795
CM
581 struct btrfs_key key;
582 struct btrfs_file_extent_item old;
583 int keep;
584 int slot;
39279cc3
CM
585 int bookend;
586 int found_type;
587 int found_extent;
588 int found_inline;
ccd467d6 589 int recow;
00f5c795 590 int ret;
39279cc3 591
5b21f2ed 592 btrfs_drop_extent_cache(inode, start, end - 1, 0);
a52d9a80 593
39279cc3
CM
594 path = btrfs_alloc_path();
595 if (!path)
596 return -ENOMEM;
597 while(1) {
ccd467d6 598 recow = 0;
39279cc3
CM
599 btrfs_release_path(root, path);
600 ret = btrfs_lookup_file_extent(trans, root, path, inode->i_ino,
601 search_start, -1);
602 if (ret < 0)
603 goto out;
604 if (ret > 0) {
605 if (path->slots[0] == 0) {
606 ret = 0;
607 goto out;
608 }
609 path->slots[0]--;
610 }
8c2383c3 611next_slot:
39279cc3
CM
612 keep = 0;
613 bookend = 0;
614 found_extent = 0;
615 found_inline = 0;
31840ae1
ZY
616 leaf_start = 0;
617 root_gen = 0;
618 root_owner = 0;
39279cc3 619 extent = NULL;
5f39d397 620 leaf = path->nodes[0];
39279cc3 621 slot = path->slots[0];
8c2383c3 622 ret = 0;
5f39d397 623 btrfs_item_key_to_cpu(leaf, &key, slot);
7261009c
Y
624 if (btrfs_key_type(&key) == BTRFS_EXTENT_DATA_KEY &&
625 key.offset >= end) {
39279cc3
CM
626 goto out;
627 }
7261009c
Y
628 if (btrfs_key_type(&key) > BTRFS_EXTENT_DATA_KEY ||
629 key.objectid != inode->i_ino) {
39279cc3
CM
630 goto out;
631 }
ccd467d6
CM
632 if (recow) {
633 search_start = key.offset;
634 continue;
635 }
8c2383c3
CM
636 if (btrfs_key_type(&key) == BTRFS_EXTENT_DATA_KEY) {
637 extent = btrfs_item_ptr(leaf, slot,
638 struct btrfs_file_extent_item);
5f39d397 639 found_type = btrfs_file_extent_type(leaf, extent);
8c2383c3 640 if (found_type == BTRFS_FILE_EXTENT_REG) {
257d0ce3
CM
641 extent_end =
642 btrfs_file_extent_disk_bytenr(leaf,
643 extent);
644 if (extent_end)
645 *hint_byte = extent_end;
646
8c2383c3 647 extent_end = key.offset +
db94535d 648 btrfs_file_extent_num_bytes(leaf, extent);
8c2383c3
CM
649 found_extent = 1;
650 } else if (found_type == BTRFS_FILE_EXTENT_INLINE) {
5f39d397
CM
651 struct btrfs_item *item;
652 item = btrfs_item_nr(leaf, slot);
8c2383c3
CM
653 found_inline = 1;
654 extent_end = key.offset +
5f39d397 655 btrfs_file_extent_inline_len(leaf, item);
8c2383c3
CM
656 }
657 } else {
658 extent_end = search_start;
39279cc3
CM
659 }
660
661 /* we found nothing we can drop */
8c2383c3
CM
662 if ((!found_extent && !found_inline) ||
663 search_start >= extent_end) {
664 int nextret;
665 u32 nritems;
5f39d397 666 nritems = btrfs_header_nritems(leaf);
8c2383c3
CM
667 if (slot >= nritems - 1) {
668 nextret = btrfs_next_leaf(root, path);
669 if (nextret)
670 goto out;
ccd467d6 671 recow = 1;
8c2383c3
CM
672 } else {
673 path->slots[0]++;
674 }
675 goto next_slot;
39279cc3
CM
676 }
677
39279cc3 678 if (found_inline) {
5f39d397 679 u64 mask = root->sectorsize - 1;
39279cc3
CM
680 search_start = (extent_end + mask) & ~mask;
681 } else
682 search_start = extent_end;
6e3b9666 683 if (end <= extent_end && start >= key.offset && found_inline) {
179e29e4 684 *hint_byte = EXTENT_MAP_INLINE;
31840ae1
ZY
685 goto out;
686 }
687
688 if (found_extent) {
689 read_extent_buffer(leaf, &old, (unsigned long)extent,
690 sizeof(old));
691 root_gen = btrfs_header_generation(leaf);
692 root_owner = btrfs_header_owner(leaf);
693 leaf_start = leaf->start;
179e29e4 694 }
31840ae1 695
39279cc3 696 if (end < extent_end && end >= key.offset) {
179e29e4 697 bookend = 1;
0181e58f 698 if (found_inline && start <= key.offset)
179e29e4 699 keep = 1;
39279cc3 700 }
39279cc3
CM
701 /* truncate existing extent */
702 if (start > key.offset) {
703 u64 new_num;
704 u64 old_num;
705 keep = 1;
5f39d397 706 WARN_ON(start & (root->sectorsize - 1));
39279cc3 707 if (found_extent) {
db94535d
CM
708 new_num = start - key.offset;
709 old_num = btrfs_file_extent_num_bytes(leaf,
710 extent);
711 *hint_byte =
712 btrfs_file_extent_disk_bytenr(leaf,
713 extent);
714 if (btrfs_file_extent_disk_bytenr(leaf,
715 extent)) {
9069218d 716 dec_i_blocks(inode, old_num - new_num);
39279cc3 717 }
db94535d
CM
718 btrfs_set_file_extent_num_bytes(leaf, extent,
719 new_num);
5f39d397 720 btrfs_mark_buffer_dirty(leaf);
00f5c795
CM
721 } else if (key.offset < inline_limit &&
722 (end > extent_end) &&
723 (inline_limit < extent_end)) {
3326d1b0
CM
724 u32 new_size;
725 new_size = btrfs_file_extent_calc_inline_size(
00f5c795 726 inline_limit - key.offset);
9069218d
CM
727 dec_i_blocks(inode, (extent_end - key.offset) -
728 (inline_limit - key.offset));
3326d1b0 729 btrfs_truncate_item(trans, root, path,
179e29e4 730 new_size, 1);
39279cc3
CM
731 }
732 }
733 /* delete the entire extent */
734 if (!keep) {
39279cc3 735 ret = btrfs_del_item(trans, root, path);
54aa1f4d 736 /* TODO update progress marker and return */
39279cc3 737 BUG_ON(ret);
39279cc3 738 extent = NULL;
31840ae1
ZY
739 btrfs_release_path(root, path);
740 /* the extent will be freed later */
39279cc3 741 }
0181e58f 742 if (bookend && found_inline && start <= key.offset) {
179e29e4
CM
743 u32 new_size;
744 new_size = btrfs_file_extent_calc_inline_size(
0181e58f 745 extent_end - end);
9069218d
CM
746 dec_i_blocks(inode, (extent_end - key.offset) -
747 (extent_end - end));
31840ae1
ZY
748 ret = btrfs_truncate_item(trans, root, path,
749 new_size, 0);
750 BUG_ON(ret);
179e29e4 751 }
39279cc3
CM
752 /* create bookend, splitting the extent in two */
753 if (bookend && found_extent) {
31840ae1 754 u64 disk_bytenr;
39279cc3
CM
755 struct btrfs_key ins;
756 ins.objectid = inode->i_ino;
757 ins.offset = end;
39279cc3 758 btrfs_set_key_type(&ins, BTRFS_EXTENT_DATA_KEY);
39279cc3
CM
759 btrfs_release_path(root, path);
760 ret = btrfs_insert_empty_item(trans, root, path, &ins,
761 sizeof(*extent));
31840ae1 762 BUG_ON(ret);
8c2383c3 763
5f39d397 764 leaf = path->nodes[0];
5f39d397
CM
765 extent = btrfs_item_ptr(leaf, path->slots[0],
766 struct btrfs_file_extent_item);
767 write_extent_buffer(leaf, &old,
768 (unsigned long)extent, sizeof(old));
769
770 btrfs_set_file_extent_offset(leaf, extent,
db94535d
CM
771 le64_to_cpu(old.offset) + end - key.offset);
772 WARN_ON(le64_to_cpu(old.num_bytes) <
773 (extent_end - end));
774 btrfs_set_file_extent_num_bytes(leaf, extent,
775 extent_end - end);
5f39d397 776 btrfs_set_file_extent_type(leaf, extent,
39279cc3 777 BTRFS_FILE_EXTENT_REG);
db94535d 778
39279cc3 779 btrfs_mark_buffer_dirty(path->nodes[0]);
31840ae1
ZY
780
781 disk_bytenr = le64_to_cpu(old.disk_bytenr);
782 if (disk_bytenr != 0) {
783 ret = btrfs_inc_extent_ref(trans, root,
784 disk_bytenr,
785 le64_to_cpu(old.disk_num_bytes),
786 leaf->start,
787 root->root_key.objectid,
788 trans->transid,
789 ins.objectid, ins.offset);
790 BUG_ON(ret);
791 }
792 btrfs_release_path(root, path);
793 if (disk_bytenr != 0) {
39279cc3 794 inode->i_blocks +=
db94535d
CM
795 btrfs_file_extent_num_bytes(leaf,
796 extent) >> 9;
39279cc3 797 }
31840ae1
ZY
798 }
799
800 if (found_extent && !keep) {
801 u64 disk_bytenr = le64_to_cpu(old.disk_bytenr);
802
803 if (disk_bytenr != 0) {
804 dec_i_blocks(inode, le64_to_cpu(old.num_bytes));
805 ret = btrfs_free_extent(trans, root,
806 disk_bytenr,
807 le64_to_cpu(old.disk_num_bytes),
808 leaf_start, root_owner,
809 root_gen, key.objectid,
810 key.offset, 0);
811 BUG_ON(ret);
812 *hint_byte = disk_bytenr;
813 }
814 }
815
816 if (search_start >= end) {
39279cc3
CM
817 ret = 0;
818 goto out;
819 }
820 }
821out:
822 btrfs_free_path(path);
9069218d 823 btrfs_check_file(root, inode);
39279cc3
CM
824 return ret;
825}
826
827/*
d352ac68
CM
828 * this gets pages into the page cache and locks them down, it also properly
829 * waits for data=ordered extents to finish before allowing the pages to be
830 * modified.
39279cc3 831 */
a1b32a59 832static int noinline prepare_pages(struct btrfs_root *root, struct file *file,
98ed5174
CM
833 struct page **pages, size_t num_pages,
834 loff_t pos, unsigned long first_index,
835 unsigned long last_index, size_t write_bytes)
39279cc3
CM
836{
837 int i;
838 unsigned long index = pos >> PAGE_CACHE_SHIFT;
6da6abae 839 struct inode *inode = fdentry(file)->d_inode;
39279cc3 840 int err = 0;
8c2383c3 841 u64 start_pos;
e6dcd2dc 842 u64 last_pos;
8c2383c3 843
5f39d397 844 start_pos = pos & ~((u64)root->sectorsize - 1);
e6dcd2dc 845 last_pos = ((u64)index + num_pages) << PAGE_CACHE_SHIFT;
39279cc3
CM
846
847 memset(pages, 0, num_pages * sizeof(struct page *));
e6dcd2dc 848again:
39279cc3
CM
849 for (i = 0; i < num_pages; i++) {
850 pages[i] = grab_cache_page(inode->i_mapping, index + i);
851 if (!pages[i]) {
852 err = -ENOMEM;
a52d9a80 853 BUG_ON(1);
39279cc3 854 }
ccd467d6 855 wait_on_page_writeback(pages[i]);
39279cc3 856 }
0762704b 857 if (start_pos < inode->i_size) {
e6dcd2dc 858 struct btrfs_ordered_extent *ordered;
d99cb30a
CM
859 lock_extent(&BTRFS_I(inode)->io_tree,
860 start_pos, last_pos - 1, GFP_NOFS);
e6dcd2dc
CM
861 ordered = btrfs_lookup_first_ordered_extent(inode, last_pos -1);
862 if (ordered &&
863 ordered->file_offset + ordered->len > start_pos &&
864 ordered->file_offset < last_pos) {
865 btrfs_put_ordered_extent(ordered);
866 unlock_extent(&BTRFS_I(inode)->io_tree,
867 start_pos, last_pos - 1, GFP_NOFS);
868 for (i = 0; i < num_pages; i++) {
869 unlock_page(pages[i]);
870 page_cache_release(pages[i]);
871 }
872 btrfs_wait_ordered_range(inode, start_pos,
873 last_pos - start_pos);
874 goto again;
875 }
876 if (ordered)
877 btrfs_put_ordered_extent(ordered);
878
0762704b
CM
879 clear_extent_bits(&BTRFS_I(inode)->io_tree, start_pos,
880 last_pos - 1, EXTENT_DIRTY | EXTENT_DELALLOC,
881 GFP_NOFS);
d99cb30a
CM
882 unlock_extent(&BTRFS_I(inode)->io_tree,
883 start_pos, last_pos - 1, GFP_NOFS);
0762704b 884 }
e6dcd2dc 885 for (i = 0; i < num_pages; i++) {
f87f057b 886 clear_page_dirty_for_io(pages[i]);
e6dcd2dc
CM
887 set_page_extent_mapped(pages[i]);
888 WARN_ON(!PageLocked(pages[i]));
889 }
39279cc3 890 return 0;
39279cc3
CM
891}
892
893static ssize_t btrfs_file_write(struct file *file, const char __user *buf,
894 size_t count, loff_t *ppos)
895{
896 loff_t pos;
2ff3e9b6
CM
897 loff_t start_pos;
898 ssize_t num_written = 0;
899 ssize_t err = 0;
39279cc3 900 int ret = 0;
6da6abae 901 struct inode *inode = fdentry(file)->d_inode;
39279cc3 902 struct btrfs_root *root = BTRFS_I(inode)->root;
8c2383c3
CM
903 struct page **pages = NULL;
904 int nrptrs;
39279cc3
CM
905 struct page *pinned[2];
906 unsigned long first_index;
907 unsigned long last_index;
8c2383c3
CM
908
909 nrptrs = min((count + PAGE_CACHE_SIZE - 1) / PAGE_CACHE_SIZE,
910 PAGE_CACHE_SIZE / (sizeof(struct page *)));
39279cc3
CM
911 pinned[0] = NULL;
912 pinned[1] = NULL;
2ff3e9b6 913
39279cc3 914 pos = *ppos;
2ff3e9b6
CM
915 start_pos = pos;
916
39279cc3
CM
917 vfs_check_frozen(inode->i_sb, SB_FREEZE_WRITE);
918 current->backing_dev_info = inode->i_mapping->backing_dev_info;
919 err = generic_write_checks(file, &pos, &count, S_ISBLK(inode->i_mode));
920 if (err)
1832a6d5 921 goto out_nolock;
39279cc3 922 if (count == 0)
1832a6d5 923 goto out_nolock;
2b1f55b0 924
0ee0fda0 925 err = file_remove_suid(file);
39279cc3 926 if (err)
1832a6d5 927 goto out_nolock;
39279cc3
CM
928 file_update_time(file);
929
8c2383c3 930 pages = kmalloc(nrptrs * sizeof(struct page *), GFP_KERNEL);
39279cc3
CM
931
932 mutex_lock(&inode->i_mutex);
933 first_index = pos >> PAGE_CACHE_SHIFT;
934 last_index = (pos + count) >> PAGE_CACHE_SHIFT;
935
409c6118
CM
936 /*
937 * if this is a nodatasum mount, force summing off for the inode
938 * all the time. That way a later mount with summing on won't
939 * get confused
940 */
941 if (btrfs_test_opt(root, NODATASUM))
942 btrfs_set_flag(inode, NODATASUM);
943
39279cc3
CM
944 /*
945 * there are lots of better ways to do this, but this code
946 * makes sure the first and last page in the file range are
947 * up to date and ready for cow
948 */
949 if ((pos & (PAGE_CACHE_SIZE - 1))) {
950 pinned[0] = grab_cache_page(inode->i_mapping, first_index);
951 if (!PageUptodate(pinned[0])) {
9ebefb18 952 ret = btrfs_readpage(NULL, pinned[0]);
39279cc3
CM
953 BUG_ON(ret);
954 wait_on_page_locked(pinned[0]);
955 } else {
956 unlock_page(pinned[0]);
957 }
958 }
959 if ((pos + count) & (PAGE_CACHE_SIZE - 1)) {
960 pinned[1] = grab_cache_page(inode->i_mapping, last_index);
961 if (!PageUptodate(pinned[1])) {
9ebefb18 962 ret = btrfs_readpage(NULL, pinned[1]);
39279cc3
CM
963 BUG_ON(ret);
964 wait_on_page_locked(pinned[1]);
965 } else {
966 unlock_page(pinned[1]);
967 }
968 }
969
39279cc3
CM
970 while(count > 0) {
971 size_t offset = pos & (PAGE_CACHE_SIZE - 1);
11bd143f
CM
972 size_t write_bytes = min(count, nrptrs *
973 (size_t)PAGE_CACHE_SIZE -
8c2383c3 974 offset);
39279cc3
CM
975 size_t num_pages = (write_bytes + PAGE_CACHE_SIZE - 1) >>
976 PAGE_CACHE_SHIFT;
977
8c2383c3 978 WARN_ON(num_pages > nrptrs);
39279cc3 979 memset(pages, 0, sizeof(pages));
1832a6d5 980
1832a6d5 981 ret = btrfs_check_free_space(root, write_bytes, 0);
1832a6d5
CM
982 if (ret)
983 goto out;
984
39279cc3
CM
985 ret = prepare_pages(root, file, pages, num_pages,
986 pos, first_index, last_index,
8c2383c3 987 write_bytes);
54aa1f4d
CM
988 if (ret)
989 goto out;
39279cc3 990
39279cc3
CM
991 ret = btrfs_copy_from_user(pos, num_pages,
992 write_bytes, pages, buf);
54aa1f4d
CM
993 if (ret) {
994 btrfs_drop_pages(pages, num_pages);
995 goto out;
996 }
39279cc3
CM
997
998 ret = dirty_and_release_pages(NULL, root, file, pages,
999 num_pages, pos, write_bytes);
39279cc3 1000 btrfs_drop_pages(pages, num_pages);
54aa1f4d
CM
1001 if (ret)
1002 goto out;
39279cc3
CM
1003
1004 buf += write_bytes;
1005 count -= write_bytes;
1006 pos += write_bytes;
1007 num_written += write_bytes;
1008
8c2383c3 1009 balance_dirty_pages_ratelimited_nr(inode->i_mapping, num_pages);
448d640b
CM
1010 if (num_pages < (root->leafsize >> PAGE_CACHE_SHIFT) + 1)
1011 btrfs_btree_balance_dirty(root, 1);
ab78c84d 1012 btrfs_throttle(root);
39279cc3
CM
1013 cond_resched();
1014 }
39279cc3 1015out:
1832a6d5 1016 mutex_unlock(&inode->i_mutex);
5b92ee72 1017
1832a6d5 1018out_nolock:
8c2383c3 1019 kfree(pages);
39279cc3
CM
1020 if (pinned[0])
1021 page_cache_release(pinned[0]);
1022 if (pinned[1])
1023 page_cache_release(pinned[1]);
1024 *ppos = pos;
2ff3e9b6
CM
1025
1026 if (num_written > 0 && ((file->f_flags & O_SYNC) || IS_SYNC(inode))) {
e02119d5
CM
1027 struct btrfs_trans_handle *trans;
1028
1029 err = btrfs_fdatawrite_range(inode->i_mapping, start_pos,
1030 start_pos + num_written -1,
1031 WB_SYNC_NONE);
1032 if (err < 0)
1033 num_written = err;
1034
1035 err = btrfs_wait_on_page_writeback_range(inode->i_mapping,
1036 start_pos, start_pos + num_written - 1);
2ff3e9b6
CM
1037 if (err < 0)
1038 num_written = err;
e02119d5
CM
1039
1040 trans = btrfs_start_transaction(root, 1);
1041 ret = btrfs_log_dentry_safe(trans, root, file->f_dentry);
1042 if (ret == 0) {
1043 btrfs_sync_log(trans, root);
1044 btrfs_end_transaction(trans, root);
1045 } else {
1046 btrfs_commit_transaction(trans, root);
1047 }
16432985
CM
1048 } else if (num_written > 0 && (file->f_flags & O_DIRECT)) {
1049 do_sync_mapping_range(inode->i_mapping, start_pos,
1050 start_pos + num_written - 1,
1051 SYNC_FILE_RANGE_WRITE |
1052 SYNC_FILE_RANGE_WAIT_AFTER);
16432985
CM
1053 invalidate_mapping_pages(inode->i_mapping,
1054 start_pos >> PAGE_CACHE_SHIFT,
1055 (start_pos + num_written - 1) >> PAGE_CACHE_SHIFT);
2ff3e9b6 1056 }
39279cc3 1057 current->backing_dev_info = NULL;
39279cc3
CM
1058 return num_written ? num_written : err;
1059}
1060
6bf13c0c 1061int btrfs_release_file(struct inode * inode, struct file * filp)
e1b81e67 1062{
6bf13c0c
SW
1063 if (filp->private_data)
1064 btrfs_ioctl_trans_end(filp);
e1b81e67
M
1065 return 0;
1066}
1067
d352ac68
CM
1068/*
1069 * fsync call for both files and directories. This logs the inode into
1070 * the tree log instead of forcing full commits whenever possible.
1071 *
1072 * It needs to call filemap_fdatawait so that all ordered extent updates are
1073 * in the metadata btree are up to date for copying to the log.
1074 *
1075 * It drops the inode mutex before doing the tree log commit. This is an
1076 * important optimization for directories because holding the mutex prevents
1077 * new operations on the dir while we write to disk.
1078 */
e02119d5 1079int btrfs_sync_file(struct file *file, struct dentry *dentry, int datasync)
39279cc3
CM
1080{
1081 struct inode *inode = dentry->d_inode;
1082 struct btrfs_root *root = BTRFS_I(inode)->root;
15ee9bc7 1083 int ret = 0;
39279cc3
CM
1084 struct btrfs_trans_handle *trans;
1085
1086 /*
15ee9bc7
JB
1087 * check the transaction that last modified this inode
1088 * and see if its already been committed
39279cc3 1089 */
15ee9bc7
JB
1090 if (!BTRFS_I(inode)->last_trans)
1091 goto out;
a2135011 1092
15ee9bc7
JB
1093 mutex_lock(&root->fs_info->trans_mutex);
1094 if (BTRFS_I(inode)->last_trans <=
1095 root->fs_info->last_trans_committed) {
1096 BTRFS_I(inode)->last_trans = 0;
1097 mutex_unlock(&root->fs_info->trans_mutex);
1098 goto out;
1099 }
1100 mutex_unlock(&root->fs_info->trans_mutex);
1101
49eb7e46 1102 root->fs_info->tree_log_batch++;
e02119d5 1103 filemap_fdatawait(inode->i_mapping);
49eb7e46 1104 root->fs_info->tree_log_batch++;
e02119d5 1105
15ee9bc7 1106 /*
a52d9a80
CM
1107 * ok we haven't committed the transaction yet, lets do a commit
1108 */
6bf13c0c
SW
1109 if (file->private_data)
1110 btrfs_ioctl_trans_end(file);
1111
39279cc3
CM
1112 trans = btrfs_start_transaction(root, 1);
1113 if (!trans) {
1114 ret = -ENOMEM;
1115 goto out;
1116 }
e02119d5
CM
1117
1118 ret = btrfs_log_dentry_safe(trans, root, file->f_dentry);
49eb7e46 1119 if (ret < 0) {
e02119d5 1120 goto out;
49eb7e46
CM
1121 }
1122
1123 /* we've logged all the items and now have a consistent
1124 * version of the file in the log. It is possible that
1125 * someone will come in and modify the file, but that's
1126 * fine because the log is consistent on disk, and we
1127 * have references to all of the file's extents
1128 *
1129 * It is possible that someone will come in and log the
1130 * file again, but that will end up using the synchronization
1131 * inside btrfs_sync_log to keep things safe.
1132 */
1133 mutex_unlock(&file->f_dentry->d_inode->i_mutex);
1134
e02119d5
CM
1135 if (ret > 0) {
1136 ret = btrfs_commit_transaction(trans, root);
1137 } else {
1138 btrfs_sync_log(trans, root);
1139 ret = btrfs_end_transaction(trans, root);
1140 }
49eb7e46 1141 mutex_lock(&file->f_dentry->d_inode->i_mutex);
39279cc3
CM
1142out:
1143 return ret > 0 ? EIO : ret;
1144}
1145
9ebefb18 1146static struct vm_operations_struct btrfs_file_vm_ops = {
92fee66d 1147 .fault = filemap_fault,
9ebefb18
CM
1148 .page_mkwrite = btrfs_page_mkwrite,
1149};
1150
1151static int btrfs_file_mmap(struct file *filp, struct vm_area_struct *vma)
1152{
1153 vma->vm_ops = &btrfs_file_vm_ops;
1154 file_accessed(filp);
1155 return 0;
1156}
1157
39279cc3
CM
1158struct file_operations btrfs_file_operations = {
1159 .llseek = generic_file_llseek,
1160 .read = do_sync_read,
9ebefb18 1161 .aio_read = generic_file_aio_read,
e9906a98 1162 .splice_read = generic_file_splice_read,
39279cc3 1163 .write = btrfs_file_write,
9ebefb18 1164 .mmap = btrfs_file_mmap,
39279cc3 1165 .open = generic_file_open,
e1b81e67 1166 .release = btrfs_release_file,
39279cc3 1167 .fsync = btrfs_sync_file,
34287aa3 1168 .unlocked_ioctl = btrfs_ioctl,
39279cc3 1169#ifdef CONFIG_COMPAT
34287aa3 1170 .compat_ioctl = btrfs_ioctl,
39279cc3
CM
1171#endif
1172};