2 * Copyright (C) 2007 Oracle. All rights reserved.
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.
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.
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.
19 #include <linux/buffer_head.h>
21 #include <linux/pagemap.h>
22 #include <linux/highmem.h>
23 #include <linux/time.h>
24 #include <linux/init.h>
25 #include <linux/string.h>
26 #include <linux/smp_lock.h>
27 #include <linux/backing-dev.h>
28 #include <linux/mpage.h>
29 #include <linux/swap.h>
30 #include <linux/writeback.h>
31 #include <linux/statfs.h>
32 #include <linux/compat.h>
33 #include <linux/bit_spinlock.h>
34 #include <linux/version.h>
37 #include "transaction.h"
38 #include "btrfs_inode.h"
40 #include "print-tree.h"
42 struct btrfs_iget_args {
44 struct btrfs_root *root;
47 static struct inode_operations btrfs_dir_inode_operations;
48 static struct inode_operations btrfs_symlink_inode_operations;
49 static struct inode_operations btrfs_dir_ro_inode_operations;
50 static struct inode_operations btrfs_special_inode_operations;
51 static struct inode_operations btrfs_file_inode_operations;
52 static struct address_space_operations btrfs_aops;
53 static struct address_space_operations btrfs_symlink_aops;
54 static struct file_operations btrfs_dir_file_operations;
55 static struct extent_map_ops btrfs_extent_map_ops;
57 static struct kmem_cache *btrfs_inode_cachep;
58 struct kmem_cache *btrfs_trans_handle_cachep;
59 struct kmem_cache *btrfs_transaction_cachep;
60 struct kmem_cache *btrfs_bit_radix_cachep;
61 struct kmem_cache *btrfs_path_cachep;
64 static unsigned char btrfs_type_by_mode[S_IFMT >> S_SHIFT] = {
65 [S_IFREG >> S_SHIFT] = BTRFS_FT_REG_FILE,
66 [S_IFDIR >> S_SHIFT] = BTRFS_FT_DIR,
67 [S_IFCHR >> S_SHIFT] = BTRFS_FT_CHRDEV,
68 [S_IFBLK >> S_SHIFT] = BTRFS_FT_BLKDEV,
69 [S_IFIFO >> S_SHIFT] = BTRFS_FT_FIFO,
70 [S_IFSOCK >> S_SHIFT] = BTRFS_FT_SOCK,
71 [S_IFLNK >> S_SHIFT] = BTRFS_FT_SYMLINK,
74 static int run_delalloc_range(struct inode *inode, u64 start, u64 end)
76 struct btrfs_root *root = BTRFS_I(inode)->root;
77 struct btrfs_trans_handle *trans;
82 u64 blocksize = root->sectorsize;
84 mutex_lock(&root->fs_info->fs_mutex);
85 trans = btrfs_start_transaction(root, 1);
86 btrfs_set_trans_block_group(trans, inode);
88 num_bytes = (end - start + blocksize) & ~(blocksize - 1);
89 ret = btrfs_drop_extents(trans, root, inode,
90 start, start + num_bytes, start, &alloc_hint);
92 if (alloc_hint == EXTENT_MAP_INLINE)
95 ret = btrfs_alloc_extent(trans, root, inode->i_ino, num_bytes, 0,
96 alloc_hint, (u64)-1, &ins, 1);
101 ret = btrfs_insert_file_extent(trans, root, inode->i_ino,
102 start, ins.objectid, ins.offset,
105 btrfs_end_transaction(trans, root);
106 mutex_unlock(&root->fs_info->fs_mutex);
110 int btrfs_writepage_io_hook(struct page *page, u64 start, u64 end)
112 struct inode *inode = page->mapping->host;
113 struct btrfs_root *root = BTRFS_I(inode)->root;
114 struct btrfs_trans_handle *trans;
117 u64 page_start = (u64)page->index << PAGE_CACHE_SHIFT;
118 size_t offset = start - page_start;
120 mutex_lock(&root->fs_info->fs_mutex);
121 trans = btrfs_start_transaction(root, 1);
122 btrfs_set_trans_block_group(trans, inode);
124 btrfs_csum_file_block(trans, root, inode, inode->i_ino,
125 start, kaddr + offset, end - start + 1);
127 ret = btrfs_end_transaction(trans, root);
129 mutex_unlock(&root->fs_info->fs_mutex);
133 int btrfs_readpage_io_hook(struct page *page, u64 start, u64 end)
136 struct inode *inode = page->mapping->host;
137 struct btrfs_root *root = BTRFS_I(inode)->root;
138 struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree;
139 struct btrfs_csum_item *item;
140 struct btrfs_path *path = NULL;
143 mutex_lock(&root->fs_info->fs_mutex);
144 path = btrfs_alloc_path();
145 item = btrfs_lookup_csum(NULL, root, path, inode->i_ino, start, 0);
148 /* a csum that isn't present is a preallocated region. */
149 if (ret == -ENOENT || ret == -EFBIG)
154 read_extent_buffer(path->nodes[0], &csum, (unsigned long)item,
156 set_state_private(em_tree, start, csum);
159 btrfs_free_path(path);
160 mutex_unlock(&root->fs_info->fs_mutex);
164 int btrfs_readpage_end_io_hook(struct page *page, u64 start, u64 end)
166 size_t offset = start - ((u64)page->index << PAGE_CACHE_SHIFT);
167 struct inode *inode = page->mapping->host;
168 struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree;
172 struct btrfs_root *root = BTRFS_I(inode)->root;
176 ret = get_state_private(em_tree, start, &private);
177 local_irq_save(flags);
178 kaddr = kmap_atomic(page, KM_IRQ0);
182 csum = btrfs_csum_data(root, kaddr + offset, csum, end - start + 1);
183 btrfs_csum_final(csum, (char *)&csum);
184 if (csum != private) {
187 kunmap_atomic(kaddr, KM_IRQ0);
188 local_irq_restore(flags);
192 printk("btrfs csum failed ino %lu off %llu\n",
193 page->mapping->host->i_ino, (unsigned long long)start);
194 memset(kaddr + offset, 1, end - start + 1);
195 flush_dcache_page(page);
196 kunmap_atomic(kaddr, KM_IRQ0);
197 local_irq_restore(flags);
201 void btrfs_read_locked_inode(struct inode *inode)
203 struct btrfs_path *path;
204 struct extent_buffer *leaf;
205 struct btrfs_inode_item *inode_item;
206 struct btrfs_inode_timespec *tspec;
207 struct btrfs_root *root = BTRFS_I(inode)->root;
208 struct btrfs_key location;
209 u64 alloc_group_block;
213 path = btrfs_alloc_path();
215 mutex_lock(&root->fs_info->fs_mutex);
217 memcpy(&location, &BTRFS_I(inode)->location, sizeof(location));
218 ret = btrfs_lookup_inode(NULL, root, path, &location, 0);
222 leaf = path->nodes[0];
223 inode_item = btrfs_item_ptr(leaf, path->slots[0],
224 struct btrfs_inode_item);
226 inode->i_mode = btrfs_inode_mode(leaf, inode_item);
227 inode->i_nlink = btrfs_inode_nlink(leaf, inode_item);
228 inode->i_uid = btrfs_inode_uid(leaf, inode_item);
229 inode->i_gid = btrfs_inode_gid(leaf, inode_item);
230 inode->i_size = btrfs_inode_size(leaf, inode_item);
232 tspec = btrfs_inode_atime(inode_item);
233 inode->i_atime.tv_sec = btrfs_timespec_sec(leaf, tspec);
234 inode->i_atime.tv_nsec = btrfs_timespec_nsec(leaf, tspec);
236 tspec = btrfs_inode_mtime(inode_item);
237 inode->i_mtime.tv_sec = btrfs_timespec_sec(leaf, tspec);
238 inode->i_mtime.tv_nsec = btrfs_timespec_nsec(leaf, tspec);
240 tspec = btrfs_inode_ctime(inode_item);
241 inode->i_ctime.tv_sec = btrfs_timespec_sec(leaf, tspec);
242 inode->i_ctime.tv_nsec = btrfs_timespec_nsec(leaf, tspec);
244 inode->i_blocks = btrfs_inode_nblocks(leaf, inode_item);
245 inode->i_generation = btrfs_inode_generation(leaf, inode_item);
247 rdev = btrfs_inode_rdev(leaf, inode_item);
249 alloc_group_block = btrfs_inode_block_group(leaf, inode_item);
250 BTRFS_I(inode)->block_group = btrfs_lookup_block_group(root->fs_info,
253 btrfs_free_path(path);
256 mutex_unlock(&root->fs_info->fs_mutex);
258 switch (inode->i_mode & S_IFMT) {
260 inode->i_mapping->a_ops = &btrfs_aops;
261 BTRFS_I(inode)->extent_tree.ops = &btrfs_extent_map_ops;
262 inode->i_fop = &btrfs_file_operations;
263 inode->i_op = &btrfs_file_inode_operations;
266 inode->i_fop = &btrfs_dir_file_operations;
267 if (root == root->fs_info->tree_root)
268 inode->i_op = &btrfs_dir_ro_inode_operations;
270 inode->i_op = &btrfs_dir_inode_operations;
273 inode->i_op = &btrfs_symlink_inode_operations;
274 inode->i_mapping->a_ops = &btrfs_symlink_aops;
277 init_special_inode(inode, inode->i_mode, rdev);
283 btrfs_release_path(root, path);
284 btrfs_free_path(path);
285 mutex_unlock(&root->fs_info->fs_mutex);
286 make_bad_inode(inode);
289 static void fill_inode_item(struct extent_buffer *leaf,
290 struct btrfs_inode_item *item,
293 btrfs_set_inode_uid(leaf, item, inode->i_uid);
294 btrfs_set_inode_gid(leaf, item, inode->i_gid);
295 btrfs_set_inode_size(leaf, item, inode->i_size);
296 btrfs_set_inode_mode(leaf, item, inode->i_mode);
297 btrfs_set_inode_nlink(leaf, item, inode->i_nlink);
299 btrfs_set_timespec_sec(leaf, btrfs_inode_atime(item),
300 inode->i_atime.tv_sec);
301 btrfs_set_timespec_nsec(leaf, btrfs_inode_atime(item),
302 inode->i_atime.tv_nsec);
304 btrfs_set_timespec_sec(leaf, btrfs_inode_mtime(item),
305 inode->i_mtime.tv_sec);
306 btrfs_set_timespec_nsec(leaf, btrfs_inode_mtime(item),
307 inode->i_mtime.tv_nsec);
309 btrfs_set_timespec_sec(leaf, btrfs_inode_ctime(item),
310 inode->i_ctime.tv_sec);
311 btrfs_set_timespec_nsec(leaf, btrfs_inode_ctime(item),
312 inode->i_ctime.tv_nsec);
314 btrfs_set_inode_nblocks(leaf, item, inode->i_blocks);
315 btrfs_set_inode_generation(leaf, item, inode->i_generation);
316 btrfs_set_inode_rdev(leaf, item, inode->i_rdev);
317 btrfs_set_inode_block_group(leaf, item,
318 BTRFS_I(inode)->block_group->key.objectid);
321 int btrfs_update_inode(struct btrfs_trans_handle *trans,
322 struct btrfs_root *root,
325 struct btrfs_inode_item *inode_item;
326 struct btrfs_path *path;
327 struct extent_buffer *leaf;
330 path = btrfs_alloc_path();
332 ret = btrfs_lookup_inode(trans, root, path,
333 &BTRFS_I(inode)->location, 1);
340 leaf = path->nodes[0];
341 inode_item = btrfs_item_ptr(leaf, path->slots[0],
342 struct btrfs_inode_item);
344 fill_inode_item(leaf, inode_item, inode);
345 btrfs_mark_buffer_dirty(leaf);
346 btrfs_set_inode_last_trans(trans, inode);
349 btrfs_release_path(root, path);
350 btrfs_free_path(path);
355 static int btrfs_unlink_trans(struct btrfs_trans_handle *trans,
356 struct btrfs_root *root,
358 struct dentry *dentry)
360 struct btrfs_path *path;
361 const char *name = dentry->d_name.name;
362 int name_len = dentry->d_name.len;
364 struct extent_buffer *leaf;
365 struct btrfs_dir_item *di;
366 struct btrfs_key key;
368 path = btrfs_alloc_path();
374 di = btrfs_lookup_dir_item(trans, root, path, dir->i_ino,
384 leaf = path->nodes[0];
385 btrfs_dir_item_key_to_cpu(leaf, di, &key);
386 ret = btrfs_delete_one_dir_name(trans, root, path, di);
389 btrfs_release_path(root, path);
391 di = btrfs_lookup_dir_index_item(trans, root, path, dir->i_ino,
392 key.objectid, name, name_len, -1);
401 ret = btrfs_delete_one_dir_name(trans, root, path, di);
403 dentry->d_inode->i_ctime = dir->i_ctime;
405 btrfs_free_path(path);
407 dir->i_size -= name_len * 2;
408 dir->i_mtime = dir->i_ctime = CURRENT_TIME;
409 btrfs_update_inode(trans, root, dir);
410 drop_nlink(dentry->d_inode);
411 ret = btrfs_update_inode(trans, root, dentry->d_inode);
412 dir->i_sb->s_dirt = 1;
417 static int btrfs_unlink(struct inode *dir, struct dentry *dentry)
419 struct btrfs_root *root;
420 struct btrfs_trans_handle *trans;
424 root = BTRFS_I(dir)->root;
425 mutex_lock(&root->fs_info->fs_mutex);
426 trans = btrfs_start_transaction(root, 1);
428 btrfs_set_trans_block_group(trans, dir);
429 ret = btrfs_unlink_trans(trans, root, dir, dentry);
430 nr = trans->blocks_used;
432 btrfs_end_transaction(trans, root);
433 mutex_unlock(&root->fs_info->fs_mutex);
434 btrfs_btree_balance_dirty(root, nr);
439 static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
441 struct inode *inode = dentry->d_inode;
444 struct btrfs_root *root = BTRFS_I(dir)->root;
445 struct btrfs_path *path;
446 struct btrfs_key key;
447 struct btrfs_trans_handle *trans;
448 struct btrfs_key found_key;
450 struct extent_buffer *leaf;
451 char *goodnames = "..";
454 if (inode->i_size > BTRFS_EMPTY_DIR_SIZE)
457 path = btrfs_alloc_path();
459 mutex_lock(&root->fs_info->fs_mutex);
460 trans = btrfs_start_transaction(root, 1);
462 btrfs_set_trans_block_group(trans, dir);
463 key.objectid = inode->i_ino;
464 key.offset = (u64)-1;
467 ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
473 if (path->slots[0] == 0) {
478 leaf = path->nodes[0];
479 btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]);
480 found_type = btrfs_key_type(&found_key);
481 if (found_key.objectid != inode->i_ino) {
485 if ((found_type != BTRFS_DIR_ITEM_KEY &&
486 found_type != BTRFS_DIR_INDEX_KEY) ||
487 (!btrfs_match_dir_item_name(root, path, goodnames, 2) &&
488 !btrfs_match_dir_item_name(root, path, goodnames, 1))) {
492 ret = btrfs_del_item(trans, root, path);
495 if (found_type == BTRFS_DIR_ITEM_KEY && found_key.offset == 1)
497 btrfs_release_path(root, path);
500 btrfs_release_path(root, path);
502 /* now the directory is empty */
503 err = btrfs_unlink_trans(trans, root, dir, dentry);
508 btrfs_release_path(root, path);
509 btrfs_free_path(path);
510 nr = trans->blocks_used;
511 ret = btrfs_end_transaction(trans, root);
512 mutex_unlock(&root->fs_info->fs_mutex);
513 btrfs_btree_balance_dirty(root, nr);
519 static int btrfs_free_inode(struct btrfs_trans_handle *trans,
520 struct btrfs_root *root,
523 struct btrfs_path *path;
528 path = btrfs_alloc_path();
530 ret = btrfs_lookup_inode(trans, root, path,
531 &BTRFS_I(inode)->location, -1);
535 ret = btrfs_del_item(trans, root, path);
536 btrfs_free_path(path);
541 * this can truncate away extent items, csum items and directory items.
542 * It starts at a high offset and removes keys until it can't find
543 * any higher than i_size.
545 * csum items that cross the new i_size are truncated to the new size
548 static int btrfs_truncate_in_trans(struct btrfs_trans_handle *trans,
549 struct btrfs_root *root,
553 struct btrfs_path *path;
554 struct btrfs_key key;
555 struct btrfs_key found_key;
557 struct extent_buffer *leaf;
558 struct btrfs_file_extent_item *fi;
559 u64 extent_start = 0;
560 u64 extent_num_bytes = 0;
564 int extent_type = -1;
566 btrfs_drop_extent_cache(inode, inode->i_size, (u64)-1);
567 path = btrfs_alloc_path();
571 /* FIXME, add redo link to tree so we don't leak on crash */
572 key.objectid = inode->i_ino;
573 key.offset = (u64)-1;
577 btrfs_init_path(path);
579 ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
584 BUG_ON(path->slots[0] == 0);
587 leaf = path->nodes[0];
588 btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]);
589 found_type = btrfs_key_type(&found_key);
591 if (found_key.objectid != inode->i_ino)
594 if (found_type != BTRFS_CSUM_ITEM_KEY &&
595 found_type != BTRFS_DIR_ITEM_KEY &&
596 found_type != BTRFS_DIR_INDEX_KEY &&
597 found_type != BTRFS_EXTENT_DATA_KEY)
600 item_end = found_key.offset;
601 if (found_type == BTRFS_EXTENT_DATA_KEY) {
602 fi = btrfs_item_ptr(leaf, path->slots[0],
603 struct btrfs_file_extent_item);
604 extent_type = btrfs_file_extent_type(leaf, fi);
605 if (extent_type != BTRFS_FILE_EXTENT_INLINE) {
607 btrfs_file_extent_num_bytes(leaf, fi);
608 } else if (extent_type == BTRFS_FILE_EXTENT_INLINE) {
609 struct btrfs_item *item = btrfs_item_nr(leaf,
611 item_end += btrfs_file_extent_inline_len(leaf,
616 if (found_type == BTRFS_CSUM_ITEM_KEY) {
617 ret = btrfs_csum_truncate(trans, root, path,
621 if (item_end < inode->i_size) {
622 if (found_type == BTRFS_DIR_ITEM_KEY) {
623 found_type = BTRFS_INODE_ITEM_KEY;
624 } else if (found_type == BTRFS_EXTENT_ITEM_KEY) {
625 found_type = BTRFS_CSUM_ITEM_KEY;
626 } else if (found_type) {
631 btrfs_set_key_type(&key, found_type);
632 btrfs_release_path(root, path);
635 if (found_key.offset >= inode->i_size)
641 /* FIXME, shrink the extent if the ref count is only 1 */
642 if (found_type != BTRFS_EXTENT_DATA_KEY)
645 if (extent_type != BTRFS_FILE_EXTENT_INLINE) {
647 extent_start = btrfs_file_extent_disk_bytenr(leaf, fi);
650 btrfs_file_extent_num_bytes(leaf, fi);
651 extent_num_bytes = inode->i_size -
652 found_key.offset + root->sectorsize - 1;
653 btrfs_set_file_extent_num_bytes(leaf, fi,
655 num_dec = (orig_num_bytes -
656 extent_num_bytes) >> 9;
657 if (extent_start != 0) {
658 inode->i_blocks -= num_dec;
660 btrfs_mark_buffer_dirty(leaf);
663 btrfs_file_extent_disk_num_bytes(leaf,
665 /* FIXME blocksize != 4096 */
666 num_dec = btrfs_file_extent_num_bytes(leaf,
668 if (extent_start != 0) {
670 inode->i_blocks -= num_dec;
673 } else if (extent_type == BTRFS_FILE_EXTENT_INLINE &&
675 u32 newsize = inode->i_size - found_key.offset;
676 newsize = btrfs_file_extent_calc_inline_size(newsize);
677 ret = btrfs_truncate_item(trans, root, path,
683 ret = btrfs_del_item(trans, root, path);
689 btrfs_release_path(root, path);
691 ret = btrfs_free_extent(trans, root, extent_start,
692 extent_num_bytes, 0);
698 btrfs_release_path(root, path);
699 btrfs_free_path(path);
700 inode->i_sb->s_dirt = 1;
704 static int btrfs_cow_one_page(struct inode *inode, struct page *page,
709 struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree;
710 u64 page_start = (u64)page->index << PAGE_CACHE_SHIFT;
711 u64 page_end = page_start + PAGE_CACHE_SIZE - 1;
713 set_page_extent_mapped(page);
715 lock_extent(em_tree, page_start, page_end, GFP_NOFS);
716 set_extent_delalloc(&BTRFS_I(inode)->extent_tree, page_start,
718 if (zero_start != PAGE_CACHE_SIZE) {
720 memset(kaddr + zero_start, 0, PAGE_CACHE_SIZE - zero_start);
721 flush_dcache_page(page);
724 set_page_dirty(page);
725 unlock_extent(em_tree, page_start, page_end, GFP_NOFS);
731 * taken from block_truncate_page, but does cow as it zeros out
732 * any bytes left in the last page in the file.
734 static int btrfs_truncate_page(struct address_space *mapping, loff_t from)
736 struct inode *inode = mapping->host;
737 struct btrfs_root *root = BTRFS_I(inode)->root;
738 u32 blocksize = root->sectorsize;
739 pgoff_t index = from >> PAGE_CACHE_SHIFT;
740 unsigned offset = from & (PAGE_CACHE_SIZE-1);
745 if ((offset & (blocksize - 1)) == 0)
748 down_read(&root->snap_sem);
750 page = grab_cache_page(mapping, index);
753 if (!PageUptodate(page)) {
754 ret = btrfs_readpage(NULL, page);
756 if (!PageUptodate(page)) {
761 page_start = (u64)page->index << PAGE_CACHE_SHIFT;
763 ret = btrfs_cow_one_page(inode, page, offset);
766 page_cache_release(page);
767 up_read(&BTRFS_I(inode)->root->snap_sem);
772 static int btrfs_setattr(struct dentry *dentry, struct iattr *attr)
774 struct inode *inode = dentry->d_inode;
777 err = inode_change_ok(inode, attr);
781 if (S_ISREG(inode->i_mode) &&
782 attr->ia_valid & ATTR_SIZE && attr->ia_size > inode->i_size) {
783 struct btrfs_trans_handle *trans;
784 struct btrfs_root *root = BTRFS_I(inode)->root;
785 struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree;
787 u64 mask = root->sectorsize - 1;
788 u64 pos = (inode->i_size + mask) & ~mask;
789 u64 block_end = attr->ia_size | mask;
793 if (attr->ia_size <= pos)
796 btrfs_truncate_page(inode->i_mapping, inode->i_size);
798 lock_extent(em_tree, pos, block_end, GFP_NOFS);
799 hole_size = (attr->ia_size - pos + mask) & ~mask;
801 mutex_lock(&root->fs_info->fs_mutex);
802 trans = btrfs_start_transaction(root, 1);
803 btrfs_set_trans_block_group(trans, inode);
804 err = btrfs_drop_extents(trans, root, inode,
805 pos, pos + hole_size, pos,
808 if (alloc_hint != EXTENT_MAP_INLINE) {
809 err = btrfs_insert_file_extent(trans, root,
811 pos, 0, 0, hole_size);
813 btrfs_end_transaction(trans, root);
814 mutex_unlock(&root->fs_info->fs_mutex);
815 unlock_extent(em_tree, pos, block_end, GFP_NOFS);
820 err = inode_setattr(inode, attr);
824 void btrfs_delete_inode(struct inode *inode)
826 struct btrfs_trans_handle *trans;
827 struct btrfs_root *root = BTRFS_I(inode)->root;
831 truncate_inode_pages(&inode->i_data, 0);
832 if (is_bad_inode(inode)) {
837 mutex_lock(&root->fs_info->fs_mutex);
838 trans = btrfs_start_transaction(root, 1);
840 btrfs_set_trans_block_group(trans, inode);
841 ret = btrfs_truncate_in_trans(trans, root, inode);
844 ret = btrfs_free_inode(trans, root, inode);
847 nr = trans->blocks_used;
849 btrfs_end_transaction(trans, root);
850 mutex_unlock(&root->fs_info->fs_mutex);
851 btrfs_btree_balance_dirty(root, nr);
855 nr = trans->blocks_used;
856 btrfs_end_transaction(trans, root);
857 mutex_unlock(&root->fs_info->fs_mutex);
858 btrfs_btree_balance_dirty(root, nr);
864 * this returns the key found in the dir entry in the location pointer.
865 * If no dir entries were found, location->objectid is 0.
867 static int btrfs_inode_by_name(struct inode *dir, struct dentry *dentry,
868 struct btrfs_key *location)
870 const char *name = dentry->d_name.name;
871 int namelen = dentry->d_name.len;
872 struct btrfs_dir_item *di;
873 struct btrfs_path *path;
874 struct btrfs_root *root = BTRFS_I(dir)->root;
877 path = btrfs_alloc_path();
879 di = btrfs_lookup_dir_item(NULL, root, path, dir->i_ino, name,
883 if (!di || IS_ERR(di)) {
884 location->objectid = 0;
887 btrfs_dir_item_key_to_cpu(path->nodes[0], di, location);
889 btrfs_release_path(root, path);
890 btrfs_free_path(path);
895 * when we hit a tree root in a directory, the btrfs part of the inode
896 * needs to be changed to reflect the root directory of the tree root. This
897 * is kind of like crossing a mount point.
899 static int fixup_tree_root_location(struct btrfs_root *root,
900 struct btrfs_key *location,
901 struct btrfs_root **sub_root,
902 struct dentry *dentry)
904 struct btrfs_path *path;
905 struct btrfs_root_item *ri;
907 if (btrfs_key_type(location) != BTRFS_ROOT_ITEM_KEY)
909 if (location->objectid == BTRFS_ROOT_TREE_OBJECTID)
912 path = btrfs_alloc_path();
914 mutex_lock(&root->fs_info->fs_mutex);
916 *sub_root = btrfs_read_fs_root(root->fs_info, location,
919 if (IS_ERR(*sub_root))
920 return PTR_ERR(*sub_root);
922 ri = &(*sub_root)->root_item;
923 location->objectid = btrfs_root_dirid(ri);
924 btrfs_set_key_type(location, BTRFS_INODE_ITEM_KEY);
925 location->offset = 0;
927 btrfs_free_path(path);
928 mutex_unlock(&root->fs_info->fs_mutex);
932 static int btrfs_init_locked_inode(struct inode *inode, void *p)
934 struct btrfs_iget_args *args = p;
935 inode->i_ino = args->ino;
936 BTRFS_I(inode)->root = args->root;
937 extent_map_tree_init(&BTRFS_I(inode)->extent_tree,
938 inode->i_mapping, GFP_NOFS);
942 static int btrfs_find_actor(struct inode *inode, void *opaque)
944 struct btrfs_iget_args *args = opaque;
945 return (args->ino == inode->i_ino &&
946 args->root == BTRFS_I(inode)->root);
949 struct inode *btrfs_iget_locked(struct super_block *s, u64 objectid,
950 struct btrfs_root *root)
953 struct btrfs_iget_args args;
957 inode = iget5_locked(s, objectid, btrfs_find_actor,
958 btrfs_init_locked_inode,
963 static struct dentry *btrfs_lookup(struct inode *dir, struct dentry *dentry,
964 struct nameidata *nd)
966 struct inode * inode;
967 struct btrfs_inode *bi = BTRFS_I(dir);
968 struct btrfs_root *root = bi->root;
969 struct btrfs_root *sub_root = root;
970 struct btrfs_key location;
973 if (dentry->d_name.len > BTRFS_NAME_LEN)
974 return ERR_PTR(-ENAMETOOLONG);
976 mutex_lock(&root->fs_info->fs_mutex);
977 ret = btrfs_inode_by_name(dir, dentry, &location);
978 mutex_unlock(&root->fs_info->fs_mutex);
984 if (location.objectid) {
985 ret = fixup_tree_root_location(root, &location, &sub_root,
990 return ERR_PTR(-ENOENT);
991 inode = btrfs_iget_locked(dir->i_sb, location.objectid,
994 return ERR_PTR(-EACCES);
995 if (inode->i_state & I_NEW) {
996 /* the inode and parent dir are two different roots */
997 if (sub_root != root) {
999 sub_root->inode = inode;
1001 BTRFS_I(inode)->root = sub_root;
1002 memcpy(&BTRFS_I(inode)->location, &location,
1004 btrfs_read_locked_inode(inode);
1005 unlock_new_inode(inode);
1008 return d_splice_alias(inode, dentry);
1011 static unsigned char btrfs_filetype_table[] = {
1012 DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK
1015 static int btrfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
1017 struct inode *inode = filp->f_path.dentry->d_inode;
1018 struct btrfs_root *root = BTRFS_I(inode)->root;
1019 struct btrfs_item *item;
1020 struct btrfs_dir_item *di;
1021 struct btrfs_key key;
1022 struct btrfs_key found_key;
1023 struct btrfs_path *path;
1026 struct extent_buffer *leaf;
1029 unsigned char d_type;
1034 int key_type = BTRFS_DIR_INDEX_KEY;
1039 /* FIXME, use a real flag for deciding about the key type */
1040 if (root->fs_info->tree_root == root)
1041 key_type = BTRFS_DIR_ITEM_KEY;
1043 mutex_lock(&root->fs_info->fs_mutex);
1044 key.objectid = inode->i_ino;
1045 btrfs_set_key_type(&key, key_type);
1046 key.offset = filp->f_pos;
1048 path = btrfs_alloc_path();
1050 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
1055 leaf = path->nodes[0];
1056 nritems = btrfs_header_nritems(leaf);
1057 slot = path->slots[0];
1058 if (advance || slot >= nritems) {
1059 if (slot >= nritems -1) {
1060 ret = btrfs_next_leaf(root, path);
1063 leaf = path->nodes[0];
1064 nritems = btrfs_header_nritems(leaf);
1065 slot = path->slots[0];
1072 item = btrfs_item_nr(leaf, slot);
1073 btrfs_item_key_to_cpu(leaf, &found_key, slot);
1075 if (found_key.objectid != key.objectid)
1077 if (btrfs_key_type(&found_key) != key_type)
1079 if (found_key.offset < filp->f_pos)
1082 filp->f_pos = found_key.offset;
1084 di = btrfs_item_ptr(leaf, slot, struct btrfs_dir_item);
1086 di_total = btrfs_item_size(leaf, item);
1087 while(di_cur < di_total) {
1088 struct btrfs_key location;
1090 name_len = btrfs_dir_name_len(leaf, di);
1091 if (name_len < 32) {
1092 name_ptr = tmp_name;
1094 name_ptr = kmalloc(name_len, GFP_NOFS);
1097 read_extent_buffer(leaf, name_ptr,
1098 (unsigned long)(di + 1), name_len);
1100 d_type = btrfs_filetype_table[btrfs_dir_type(leaf, di)];
1101 btrfs_dir_item_key_to_cpu(leaf, di, &location);
1103 over = filldir(dirent, name_ptr, name_len,
1108 if (name_ptr != tmp_name)
1113 di_len = btrfs_dir_name_len(leaf, di) + sizeof(*di);
1115 di = (struct btrfs_dir_item *)((char *)di + di_len);
1122 btrfs_release_path(root, path);
1123 btrfs_free_path(path);
1124 mutex_unlock(&root->fs_info->fs_mutex);
1128 int btrfs_write_inode(struct inode *inode, int wait)
1130 struct btrfs_root *root = BTRFS_I(inode)->root;
1131 struct btrfs_trans_handle *trans;
1135 mutex_lock(&root->fs_info->fs_mutex);
1136 trans = btrfs_start_transaction(root, 1);
1137 btrfs_set_trans_block_group(trans, inode);
1138 ret = btrfs_commit_transaction(trans, root);
1139 mutex_unlock(&root->fs_info->fs_mutex);
1145 * This is somewhat expensive, updating the tree every time the
1146 * inode changes. But, it is most likely to find the inode in cache.
1147 * FIXME, needs more benchmarking...there are no reasons other than performance
1148 * to keep or drop this code.
1150 void btrfs_dirty_inode(struct inode *inode)
1152 struct btrfs_root *root = BTRFS_I(inode)->root;
1153 struct btrfs_trans_handle *trans;
1155 mutex_lock(&root->fs_info->fs_mutex);
1156 trans = btrfs_start_transaction(root, 1);
1157 btrfs_set_trans_block_group(trans, inode);
1158 btrfs_update_inode(trans, root, inode);
1159 btrfs_end_transaction(trans, root);
1160 mutex_unlock(&root->fs_info->fs_mutex);
1163 static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,
1164 struct btrfs_root *root,
1166 struct btrfs_block_group_cache *group,
1169 struct inode *inode;
1170 struct btrfs_inode_item *inode_item;
1171 struct btrfs_key *location;
1172 struct btrfs_path *path;
1176 path = btrfs_alloc_path();
1179 inode = new_inode(root->fs_info->sb);
1181 return ERR_PTR(-ENOMEM);
1183 extent_map_tree_init(&BTRFS_I(inode)->extent_tree,
1184 inode->i_mapping, GFP_NOFS);
1185 BTRFS_I(inode)->root = root;
1191 group = btrfs_find_block_group(root, group, 0, 0, owner);
1192 BTRFS_I(inode)->block_group = group;
1194 ret = btrfs_insert_empty_inode(trans, root, path, objectid);
1198 inode->i_uid = current->fsuid;
1199 inode->i_gid = current->fsgid;
1200 inode->i_mode = mode;
1201 inode->i_ino = objectid;
1202 inode->i_blocks = 0;
1203 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
1204 inode_item = btrfs_item_ptr(path->nodes[0], path->slots[0],
1205 struct btrfs_inode_item);
1206 fill_inode_item(path->nodes[0], inode_item, inode);
1207 btrfs_mark_buffer_dirty(path->nodes[0]);
1208 btrfs_free_path(path);
1210 location = &BTRFS_I(inode)->location;
1211 location->objectid = objectid;
1212 location->offset = 0;
1213 btrfs_set_key_type(location, BTRFS_INODE_ITEM_KEY);
1215 insert_inode_hash(inode);
1218 btrfs_free_path(path);
1219 return ERR_PTR(ret);
1222 static inline u8 btrfs_inode_type(struct inode *inode)
1224 return btrfs_type_by_mode[(inode->i_mode & S_IFMT) >> S_SHIFT];
1227 static int btrfs_add_link(struct btrfs_trans_handle *trans,
1228 struct dentry *dentry, struct inode *inode)
1231 struct btrfs_key key;
1232 struct btrfs_root *root = BTRFS_I(dentry->d_parent->d_inode)->root;
1233 struct inode *parent_inode;
1235 key.objectid = inode->i_ino;
1236 btrfs_set_key_type(&key, BTRFS_INODE_ITEM_KEY);
1239 ret = btrfs_insert_dir_item(trans, root,
1240 dentry->d_name.name, dentry->d_name.len,
1241 dentry->d_parent->d_inode->i_ino,
1242 &key, btrfs_inode_type(inode));
1244 parent_inode = dentry->d_parent->d_inode;
1245 parent_inode->i_size += dentry->d_name.len * 2;
1246 parent_inode->i_mtime = parent_inode->i_ctime = CURRENT_TIME;
1247 ret = btrfs_update_inode(trans, root,
1248 dentry->d_parent->d_inode);
1253 static int btrfs_add_nondir(struct btrfs_trans_handle *trans,
1254 struct dentry *dentry, struct inode *inode)
1256 int err = btrfs_add_link(trans, dentry, inode);
1258 d_instantiate(dentry, inode);
1266 static int btrfs_mknod(struct inode *dir, struct dentry *dentry,
1267 int mode, dev_t rdev)
1269 struct btrfs_trans_handle *trans;
1270 struct btrfs_root *root = BTRFS_I(dir)->root;
1271 struct inode *inode;
1277 if (!new_valid_dev(rdev))
1280 mutex_lock(&root->fs_info->fs_mutex);
1281 trans = btrfs_start_transaction(root, 1);
1282 btrfs_set_trans_block_group(trans, dir);
1284 err = btrfs_find_free_objectid(trans, root, dir->i_ino, &objectid);
1290 inode = btrfs_new_inode(trans, root, objectid,
1291 BTRFS_I(dir)->block_group, mode);
1292 err = PTR_ERR(inode);
1296 btrfs_set_trans_block_group(trans, inode);
1297 err = btrfs_add_nondir(trans, dentry, inode);
1301 inode->i_op = &btrfs_special_inode_operations;
1302 init_special_inode(inode, inode->i_mode, rdev);
1303 btrfs_update_inode(trans, root, inode);
1305 dir->i_sb->s_dirt = 1;
1306 btrfs_update_inode_block_group(trans, inode);
1307 btrfs_update_inode_block_group(trans, dir);
1309 nr = trans->blocks_used;
1310 btrfs_end_transaction(trans, root);
1311 mutex_unlock(&root->fs_info->fs_mutex);
1314 inode_dec_link_count(inode);
1317 btrfs_btree_balance_dirty(root, nr);
1321 static int btrfs_create(struct inode *dir, struct dentry *dentry,
1322 int mode, struct nameidata *nd)
1324 struct btrfs_trans_handle *trans;
1325 struct btrfs_root *root = BTRFS_I(dir)->root;
1326 struct inode *inode;
1332 mutex_lock(&root->fs_info->fs_mutex);
1333 trans = btrfs_start_transaction(root, 1);
1334 btrfs_set_trans_block_group(trans, dir);
1336 err = btrfs_find_free_objectid(trans, root, dir->i_ino, &objectid);
1342 inode = btrfs_new_inode(trans, root, objectid,
1343 BTRFS_I(dir)->block_group, mode);
1344 err = PTR_ERR(inode);
1348 btrfs_set_trans_block_group(trans, inode);
1349 err = btrfs_add_nondir(trans, dentry, inode);
1353 inode->i_mapping->a_ops = &btrfs_aops;
1354 inode->i_fop = &btrfs_file_operations;
1355 inode->i_op = &btrfs_file_inode_operations;
1356 extent_map_tree_init(&BTRFS_I(inode)->extent_tree,
1357 inode->i_mapping, GFP_NOFS);
1358 BTRFS_I(inode)->extent_tree.ops = &btrfs_extent_map_ops;
1360 dir->i_sb->s_dirt = 1;
1361 btrfs_update_inode_block_group(trans, inode);
1362 btrfs_update_inode_block_group(trans, dir);
1364 nr = trans->blocks_used;
1365 btrfs_end_transaction(trans, root);
1366 mutex_unlock(&root->fs_info->fs_mutex);
1369 inode_dec_link_count(inode);
1372 btrfs_btree_balance_dirty(root, nr);
1376 static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
1377 struct dentry *dentry)
1379 struct btrfs_trans_handle *trans;
1380 struct btrfs_root *root = BTRFS_I(dir)->root;
1381 struct inode *inode = old_dentry->d_inode;
1386 if (inode->i_nlink == 0)
1390 mutex_lock(&root->fs_info->fs_mutex);
1391 trans = btrfs_start_transaction(root, 1);
1393 btrfs_set_trans_block_group(trans, dir);
1394 atomic_inc(&inode->i_count);
1395 err = btrfs_add_nondir(trans, dentry, inode);
1400 dir->i_sb->s_dirt = 1;
1401 btrfs_update_inode_block_group(trans, dir);
1402 err = btrfs_update_inode(trans, root, inode);
1407 nr = trans->blocks_used;
1408 btrfs_end_transaction(trans, root);
1409 mutex_unlock(&root->fs_info->fs_mutex);
1412 inode_dec_link_count(inode);
1415 btrfs_btree_balance_dirty(root, nr);
1419 static int btrfs_make_empty_dir(struct btrfs_trans_handle *trans,
1420 struct btrfs_root *root,
1421 u64 objectid, u64 dirid)
1425 struct btrfs_key key;
1430 key.objectid = objectid;
1432 btrfs_set_key_type(&key, BTRFS_INODE_ITEM_KEY);
1434 ret = btrfs_insert_dir_item(trans, root, buf, 1, objectid,
1435 &key, BTRFS_FT_DIR);
1439 key.objectid = dirid;
1440 ret = btrfs_insert_dir_item(trans, root, buf, 2, objectid,
1441 &key, BTRFS_FT_DIR);
1448 static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
1450 struct inode *inode;
1451 struct btrfs_trans_handle *trans;
1452 struct btrfs_root *root = BTRFS_I(dir)->root;
1454 int drop_on_err = 0;
1456 unsigned long nr = 1;
1458 mutex_lock(&root->fs_info->fs_mutex);
1459 trans = btrfs_start_transaction(root, 1);
1460 btrfs_set_trans_block_group(trans, dir);
1462 if (IS_ERR(trans)) {
1463 err = PTR_ERR(trans);
1467 err = btrfs_find_free_objectid(trans, root, dir->i_ino, &objectid);
1473 inode = btrfs_new_inode(trans, root, objectid,
1474 BTRFS_I(dir)->block_group, S_IFDIR | mode);
1475 if (IS_ERR(inode)) {
1476 err = PTR_ERR(inode);
1481 inode->i_op = &btrfs_dir_inode_operations;
1482 inode->i_fop = &btrfs_dir_file_operations;
1483 btrfs_set_trans_block_group(trans, inode);
1485 err = btrfs_make_empty_dir(trans, root, inode->i_ino, dir->i_ino);
1490 err = btrfs_update_inode(trans, root, inode);
1494 err = btrfs_add_link(trans, dentry, inode);
1498 d_instantiate(dentry, inode);
1500 dir->i_sb->s_dirt = 1;
1501 btrfs_update_inode_block_group(trans, inode);
1502 btrfs_update_inode_block_group(trans, dir);
1505 nr = trans->blocks_used;
1506 btrfs_end_transaction(trans, root);
1509 mutex_unlock(&root->fs_info->fs_mutex);
1512 btrfs_btree_balance_dirty(root, nr);
1516 struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page,
1517 size_t page_offset, u64 start, u64 end,
1523 u64 extent_start = 0;
1525 u64 objectid = inode->i_ino;
1527 int failed_insert = 0;
1528 struct btrfs_path *path;
1529 struct btrfs_root *root = BTRFS_I(inode)->root;
1530 struct btrfs_file_extent_item *item;
1531 struct extent_buffer *leaf;
1532 struct btrfs_key found_key;
1533 struct extent_map *em = NULL;
1534 struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree;
1535 struct btrfs_trans_handle *trans = NULL;
1537 path = btrfs_alloc_path();
1539 mutex_lock(&root->fs_info->fs_mutex);
1542 em = lookup_extent_mapping(em_tree, start, end);
1547 em = alloc_extent_map(GFP_NOFS);
1552 em->start = EXTENT_MAP_HOLE;
1553 em->end = EXTENT_MAP_HOLE;
1555 em->bdev = inode->i_sb->s_bdev;
1556 ret = btrfs_lookup_file_extent(trans, root, path,
1557 objectid, start, trans != NULL);
1564 if (path->slots[0] == 0)
1569 leaf = path->nodes[0];
1570 item = btrfs_item_ptr(leaf, path->slots[0],
1571 struct btrfs_file_extent_item);
1572 /* are we inside the extent that was found? */
1573 btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]);
1574 found_type = btrfs_key_type(&found_key);
1575 if (found_key.objectid != objectid ||
1576 found_type != BTRFS_EXTENT_DATA_KEY) {
1580 found_type = btrfs_file_extent_type(leaf, item);
1581 extent_start = found_key.offset;
1582 if (found_type == BTRFS_FILE_EXTENT_REG) {
1583 extent_end = extent_start +
1584 btrfs_file_extent_num_bytes(leaf, item);
1586 if (start < extent_start || start >= extent_end) {
1588 if (start < extent_start) {
1589 if (end < extent_start)
1591 em->end = extent_end - 1;
1597 bytenr = btrfs_file_extent_disk_bytenr(leaf, item);
1599 em->start = extent_start;
1600 em->end = extent_end - 1;
1601 em->block_start = EXTENT_MAP_HOLE;
1602 em->block_end = EXTENT_MAP_HOLE;
1605 bytenr += btrfs_file_extent_offset(leaf, item);
1606 em->block_start = bytenr;
1607 em->block_end = em->block_start +
1608 btrfs_file_extent_num_bytes(leaf, item) - 1;
1609 em->start = extent_start;
1610 em->end = extent_end - 1;
1612 } else if (found_type == BTRFS_FILE_EXTENT_INLINE) {
1616 size_t extent_offset;
1619 size = btrfs_file_extent_inline_len(leaf, btrfs_item_nr(leaf,
1621 extent_end = (extent_start + size - 1) |
1622 ((u64)root->sectorsize - 1);
1623 if (start < extent_start || start >= extent_end) {
1625 if (start < extent_start) {
1626 if (end < extent_start)
1628 em->end = extent_end;
1634 em->block_start = EXTENT_MAP_INLINE;
1635 em->block_end = EXTENT_MAP_INLINE;
1638 em->start = extent_start;
1639 em->end = extent_start + size - 1;
1643 extent_offset = ((u64)page->index << PAGE_CACHE_SHIFT) -
1644 extent_start + page_offset;
1645 copy_size = min_t(u64, PAGE_CACHE_SIZE - page_offset,
1646 size - extent_offset);
1647 em->start = extent_start + extent_offset;
1648 em->end = (em->start + copy_size -1) |
1649 ((u64)root->sectorsize -1);
1651 ptr = btrfs_file_extent_inline_start(item) + extent_offset;
1652 if (create == 0 && !PageUptodate(page)) {
1653 read_extent_buffer(leaf, map + page_offset, ptr,
1655 flush_dcache_page(page);
1656 } else if (create && PageUptodate(page)) {
1659 free_extent_map(em);
1661 btrfs_release_path(root, path);
1662 trans = btrfs_start_transaction(root, 1);
1665 write_extent_buffer(leaf, map + page_offset, ptr,
1667 btrfs_mark_buffer_dirty(leaf);
1670 set_extent_uptodate(em_tree, em->start, em->end, GFP_NOFS);
1673 printk("unkknown found_type %d\n", found_type);
1680 em->block_start = EXTENT_MAP_HOLE;
1681 em->block_end = EXTENT_MAP_HOLE;
1683 btrfs_release_path(root, path);
1684 if (em->start > start || em->end < start) {
1685 printk("bad extent! em: [%Lu %Lu] passed [%Lu %Lu]\n", em->start, em->end, start, end);
1689 ret = add_extent_mapping(em_tree, em);
1690 if (ret == -EEXIST) {
1691 free_extent_map(em);
1694 if (failed_insert > 5) {
1695 printk("failing to insert %Lu %Lu\n", start, end);
1703 btrfs_free_path(path);
1705 ret = btrfs_end_transaction(trans, root);
1709 mutex_unlock(&root->fs_info->fs_mutex);
1711 free_extent_map(em);
1713 return ERR_PTR(err);
1718 static sector_t btrfs_bmap(struct address_space *mapping, sector_t iblock)
1720 return extent_bmap(mapping, iblock, btrfs_get_extent);
1723 static int btrfs_prepare_write(struct file *file, struct page *page,
1724 unsigned from, unsigned to)
1726 return extent_prepare_write(&BTRFS_I(page->mapping->host)->extent_tree,
1727 page->mapping->host, page, from, to,
1731 int btrfs_readpage(struct file *file, struct page *page)
1733 struct extent_map_tree *tree;
1734 tree = &BTRFS_I(page->mapping->host)->extent_tree;
1735 return extent_read_full_page(tree, page, btrfs_get_extent);
1737 static int btrfs_writepage(struct page *page, struct writeback_control *wbc)
1739 struct extent_map_tree *tree;
1742 if (current->flags & PF_MEMALLOC) {
1743 redirty_page_for_writepage(wbc, page);
1747 tree = &BTRFS_I(page->mapping->host)->extent_tree;
1748 return extent_write_full_page(tree, page, btrfs_get_extent, wbc);
1752 static int btrfs_writepages(struct address_space *mapping,
1753 struct writeback_control *wbc)
1755 struct extent_map_tree *tree;
1756 tree = &BTRFS_I(mapping->host)->extent_tree;
1757 return extent_writepages(tree, mapping, btrfs_get_extent, wbc);
1760 static int btrfs_releasepage(struct page *page, gfp_t unused_gfp_flags)
1762 struct extent_map_tree *tree;
1765 tree = &BTRFS_I(page->mapping->host)->extent_tree;
1766 ret = try_release_extent_mapping(tree, page);
1768 ClearPagePrivate(page);
1769 set_page_private(page, 0);
1770 page_cache_release(page);
1775 static void btrfs_invalidatepage(struct page *page, unsigned long offset)
1777 struct extent_map_tree *tree;
1779 tree = &BTRFS_I(page->mapping->host)->extent_tree;
1780 extent_invalidatepage(tree, page, offset);
1781 btrfs_releasepage(page, GFP_NOFS);
1785 * btrfs_page_mkwrite() is not allowed to change the file size as it gets
1786 * called from a page fault handler when a page is first dirtied. Hence we must
1787 * be careful to check for EOF conditions here. We set the page up correctly
1788 * for a written page which means we get ENOSPC checking when writing into
1789 * holes and correct delalloc and unwritten extent mapping on filesystems that
1790 * support these features.
1792 * We are not allowed to take the i_mutex here so we have to play games to
1793 * protect against truncate races as the page could now be beyond EOF. Because
1794 * vmtruncate() writes the inode size before removing pages, once we have the
1795 * page lock we can determine safely if the page is beyond EOF. If it is not
1796 * beyond EOF, then the page is guaranteed safe against truncation until we
1799 int btrfs_page_mkwrite(struct vm_area_struct *vma, struct page *page)
1801 struct inode *inode = vma->vm_file->f_path.dentry->d_inode;
1807 down_read(&BTRFS_I(inode)->root->snap_sem);
1809 wait_on_page_writeback(page);
1810 size = i_size_read(inode);
1811 page_start = (u64)page->index << PAGE_CACHE_SHIFT;
1813 if ((page->mapping != inode->i_mapping) ||
1814 (page_start > size)) {
1815 /* page got truncated out from underneath us */
1819 /* page is wholly or partially inside EOF */
1820 if (page_start + PAGE_CACHE_SIZE > size)
1821 end = size & ~PAGE_CACHE_MASK;
1823 end = PAGE_CACHE_SIZE;
1825 ret = btrfs_cow_one_page(inode, page, end);
1828 up_read(&BTRFS_I(inode)->root->snap_sem);
1833 static void btrfs_truncate(struct inode *inode)
1835 struct btrfs_root *root = BTRFS_I(inode)->root;
1837 struct btrfs_trans_handle *trans;
1840 if (!S_ISREG(inode->i_mode))
1842 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
1845 btrfs_truncate_page(inode->i_mapping, inode->i_size);
1847 mutex_lock(&root->fs_info->fs_mutex);
1848 trans = btrfs_start_transaction(root, 1);
1849 btrfs_set_trans_block_group(trans, inode);
1851 /* FIXME, add redo link to tree so we don't leak on crash */
1852 ret = btrfs_truncate_in_trans(trans, root, inode);
1853 btrfs_update_inode(trans, root, inode);
1854 nr = trans->blocks_used;
1856 ret = btrfs_end_transaction(trans, root);
1858 mutex_unlock(&root->fs_info->fs_mutex);
1859 btrfs_btree_balance_dirty(root, nr);
1862 int btrfs_commit_write(struct file *file, struct page *page,
1863 unsigned from, unsigned to)
1865 return extent_commit_write(&BTRFS_I(page->mapping->host)->extent_tree,
1866 page->mapping->host, page, from, to);
1869 static int create_subvol(struct btrfs_root *root, char *name, int namelen)
1871 struct btrfs_trans_handle *trans;
1872 struct btrfs_key key;
1873 struct btrfs_root_item root_item;
1874 struct btrfs_inode_item *inode_item;
1875 struct extent_buffer *leaf;
1876 struct btrfs_root *new_root;
1877 struct inode *inode;
1882 u64 new_dirid = BTRFS_FIRST_FREE_OBJECTID;
1883 unsigned long nr = 1;
1885 mutex_lock(&root->fs_info->fs_mutex);
1886 trans = btrfs_start_transaction(root, 1);
1889 leaf = btrfs_alloc_free_block(trans, root, root->leafsize, 0, 0);
1891 return PTR_ERR(leaf);
1893 btrfs_set_header_nritems(leaf, 0);
1894 btrfs_set_header_level(leaf, 0);
1895 btrfs_set_header_bytenr(leaf, leaf->start);
1896 btrfs_set_header_generation(leaf, trans->transid);
1897 btrfs_set_header_owner(leaf, root->root_key.objectid);
1898 write_extent_buffer(leaf, root->fs_info->fsid,
1899 (unsigned long)btrfs_header_fsid(leaf),
1901 btrfs_mark_buffer_dirty(leaf);
1903 inode_item = &root_item.inode;
1904 memset(inode_item, 0, sizeof(*inode_item));
1905 inode_item->generation = cpu_to_le64(1);
1906 inode_item->size = cpu_to_le64(3);
1907 inode_item->nlink = cpu_to_le32(1);
1908 inode_item->nblocks = cpu_to_le64(1);
1909 inode_item->mode = cpu_to_le32(S_IFDIR | 0755);
1911 btrfs_set_root_bytenr(&root_item, leaf->start);
1912 btrfs_set_root_level(&root_item, 0);
1913 btrfs_set_root_refs(&root_item, 1);
1914 btrfs_set_root_used(&root_item, 0);
1916 memset(&root_item.drop_progress, 0, sizeof(root_item.drop_progress));
1917 root_item.drop_level = 0;
1919 free_extent_buffer(leaf);
1922 ret = btrfs_find_free_objectid(trans, root->fs_info->tree_root,
1927 btrfs_set_root_dirid(&root_item, new_dirid);
1929 key.objectid = objectid;
1931 btrfs_set_key_type(&key, BTRFS_ROOT_ITEM_KEY);
1932 ret = btrfs_insert_root(trans, root->fs_info->tree_root, &key,
1938 * insert the directory item
1940 key.offset = (u64)-1;
1941 dir = root->fs_info->sb->s_root->d_inode;
1942 ret = btrfs_insert_dir_item(trans, root->fs_info->tree_root,
1943 name, namelen, dir->i_ino, &key,
1948 ret = btrfs_commit_transaction(trans, root);
1952 new_root = btrfs_read_fs_root(root->fs_info, &key, name, namelen);
1955 trans = btrfs_start_transaction(new_root, 1);
1958 inode = btrfs_new_inode(trans, new_root, new_dirid,
1959 BTRFS_I(dir)->block_group, S_IFDIR | 0700);
1962 inode->i_op = &btrfs_dir_inode_operations;
1963 inode->i_fop = &btrfs_dir_file_operations;
1964 new_root->inode = inode;
1966 ret = btrfs_make_empty_dir(trans, new_root, new_dirid, new_dirid);
1972 ret = btrfs_update_inode(trans, new_root, inode);
1976 nr = trans->blocks_used;
1977 err = btrfs_commit_transaction(trans, root);
1981 mutex_unlock(&root->fs_info->fs_mutex);
1982 btrfs_btree_balance_dirty(root, nr);
1986 static int create_snapshot(struct btrfs_root *root, char *name, int namelen)
1988 struct btrfs_trans_handle *trans;
1989 struct btrfs_key key;
1990 struct btrfs_root_item new_root_item;
1991 struct extent_buffer *tmp;
1997 if (!root->ref_cows)
2000 down_write(&root->snap_sem);
2001 freeze_bdev(root->fs_info->sb->s_bdev);
2002 thaw_bdev(root->fs_info->sb->s_bdev, root->fs_info->sb);
2004 mutex_lock(&root->fs_info->fs_mutex);
2005 trans = btrfs_start_transaction(root, 1);
2008 ret = btrfs_update_inode(trans, root, root->inode);
2012 ret = btrfs_find_free_objectid(trans, root->fs_info->tree_root,
2017 memcpy(&new_root_item, &root->root_item,
2018 sizeof(new_root_item));
2020 key.objectid = objectid;
2022 btrfs_set_key_type(&key, BTRFS_ROOT_ITEM_KEY);
2024 btrfs_cow_block(trans, root, root->node, NULL, 0, &tmp);
2025 btrfs_set_root_bytenr(&new_root_item, root->node->start);
2026 btrfs_set_root_level(&new_root_item, btrfs_header_level(root->node));
2028 ret = btrfs_insert_root(trans, root->fs_info->tree_root, &key,
2034 * insert the directory item
2036 key.offset = (u64)-1;
2037 ret = btrfs_insert_dir_item(trans, root->fs_info->tree_root,
2039 root->fs_info->sb->s_root->d_inode->i_ino,
2040 &key, BTRFS_FT_DIR);
2045 ret = btrfs_inc_root_ref(trans, root);
2049 nr = trans->blocks_used;
2050 err = btrfs_commit_transaction(trans, root);
2055 mutex_unlock(&root->fs_info->fs_mutex);
2056 up_write(&root->snap_sem);
2057 btrfs_btree_balance_dirty(root, nr);
2061 static unsigned long force_ra(struct address_space *mapping,
2062 struct file_ra_state *ra, struct file *file,
2063 pgoff_t offset, pgoff_t last_index)
2067 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
2068 req_size = last_index - offset + 1;
2069 offset = page_cache_readahead(mapping, ra, file, offset, req_size);
2072 req_size = min(last_index - offset + 1, (pgoff_t)128);
2073 page_cache_sync_readahead(mapping, ra, file, offset, req_size);
2074 return offset + req_size;
2078 int btrfs_defrag_file(struct file *file) {
2079 struct inode *inode = file->f_path.dentry->d_inode;
2080 struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree;
2082 unsigned long last_index;
2083 unsigned long ra_index = 0;
2088 mutex_lock(&inode->i_mutex);
2089 last_index = inode->i_size >> PAGE_CACHE_SHIFT;
2090 for (i = 0; i <= last_index; i++) {
2091 if (i == ra_index) {
2092 ra_index = force_ra(inode->i_mapping, &file->f_ra,
2093 file, ra_index, last_index);
2095 page = grab_cache_page(inode->i_mapping, i);
2098 if (!PageUptodate(page)) {
2099 btrfs_readpage(NULL, page);
2101 if (!PageUptodate(page)) {
2103 page_cache_release(page);
2107 page_start = (u64)page->index << PAGE_CACHE_SHIFT;
2108 page_end = page_start + PAGE_CACHE_SIZE - 1;
2110 lock_extent(em_tree, page_start, page_end, GFP_NOFS);
2111 set_extent_delalloc(em_tree, page_start,
2112 page_end, GFP_NOFS);
2113 unlock_extent(em_tree, page_start, page_end, GFP_NOFS);
2114 set_page_dirty(page);
2116 page_cache_release(page);
2117 balance_dirty_pages_ratelimited_nr(inode->i_mapping, 1);
2121 mutex_unlock(&inode->i_mutex);
2125 static int btrfs_ioctl_snap_create(struct btrfs_root *root, void __user *arg)
2127 struct btrfs_ioctl_vol_args vol_args;
2128 struct btrfs_dir_item *di;
2129 struct btrfs_path *path;
2133 if (copy_from_user(&vol_args, arg, sizeof(vol_args)))
2136 namelen = strlen(vol_args.name);
2137 if (namelen > BTRFS_VOL_NAME_MAX)
2139 if (strchr(vol_args.name, '/'))
2142 path = btrfs_alloc_path();
2146 root_dirid = root->fs_info->sb->s_root->d_inode->i_ino,
2147 mutex_lock(&root->fs_info->fs_mutex);
2148 di = btrfs_lookup_dir_item(NULL, root->fs_info->tree_root,
2150 vol_args.name, namelen, 0);
2151 mutex_unlock(&root->fs_info->fs_mutex);
2152 btrfs_free_path(path);
2153 if (di && !IS_ERR(di))
2158 if (root == root->fs_info->tree_root)
2159 return create_subvol(root, vol_args.name, namelen);
2160 return create_snapshot(root, vol_args.name, namelen);
2163 static int btrfs_ioctl_defrag(struct file *file)
2165 struct inode *inode = file->f_path.dentry->d_inode;
2166 struct btrfs_root *root = BTRFS_I(inode)->root;
2168 switch (inode->i_mode & S_IFMT) {
2170 mutex_lock(&root->fs_info->fs_mutex);
2171 btrfs_defrag_root(root, 0);
2172 btrfs_defrag_root(root->fs_info->extent_root, 0);
2173 mutex_unlock(&root->fs_info->fs_mutex);
2176 btrfs_defrag_file(file);
2183 long btrfs_ioctl(struct file *file, unsigned int
2184 cmd, unsigned long arg)
2186 struct btrfs_root *root = BTRFS_I(file->f_path.dentry->d_inode)->root;
2189 case BTRFS_IOC_SNAP_CREATE:
2190 return btrfs_ioctl_snap_create(root, (void __user *)arg);
2191 case BTRFS_IOC_DEFRAG:
2192 return btrfs_ioctl_defrag(file);
2199 * Called inside transaction, so use GFP_NOFS
2201 struct inode *btrfs_alloc_inode(struct super_block *sb)
2203 struct btrfs_inode *ei;
2205 ei = kmem_cache_alloc(btrfs_inode_cachep, GFP_NOFS);
2209 return &ei->vfs_inode;
2212 void btrfs_destroy_inode(struct inode *inode)
2214 WARN_ON(!list_empty(&inode->i_dentry));
2215 WARN_ON(inode->i_data.nrpages);
2217 kmem_cache_free(btrfs_inode_cachep, BTRFS_I(inode));
2220 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,23)
2221 static void init_once(struct kmem_cache * cachep, void *foo)
2223 static void init_once(void * foo, struct kmem_cache * cachep,
2224 unsigned long flags)
2227 struct btrfs_inode *ei = (struct btrfs_inode *) foo;
2229 inode_init_once(&ei->vfs_inode);
2232 void btrfs_destroy_cachep(void)
2234 if (btrfs_inode_cachep)
2235 kmem_cache_destroy(btrfs_inode_cachep);
2236 if (btrfs_trans_handle_cachep)
2237 kmem_cache_destroy(btrfs_trans_handle_cachep);
2238 if (btrfs_transaction_cachep)
2239 kmem_cache_destroy(btrfs_transaction_cachep);
2240 if (btrfs_bit_radix_cachep)
2241 kmem_cache_destroy(btrfs_bit_radix_cachep);
2242 if (btrfs_path_cachep)
2243 kmem_cache_destroy(btrfs_path_cachep);
2246 struct kmem_cache *btrfs_cache_create(const char *name, size_t size,
2247 unsigned long extra_flags,
2248 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,23)
2249 void (*ctor)(struct kmem_cache *, void *)
2251 void (*ctor)(void *, struct kmem_cache *,
2256 return kmem_cache_create(name, size, 0, (SLAB_RECLAIM_ACCOUNT |
2257 SLAB_MEM_SPREAD | extra_flags), ctor
2258 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
2264 int btrfs_init_cachep(void)
2266 btrfs_inode_cachep = btrfs_cache_create("btrfs_inode_cache",
2267 sizeof(struct btrfs_inode),
2269 if (!btrfs_inode_cachep)
2271 btrfs_trans_handle_cachep =
2272 btrfs_cache_create("btrfs_trans_handle_cache",
2273 sizeof(struct btrfs_trans_handle),
2275 if (!btrfs_trans_handle_cachep)
2277 btrfs_transaction_cachep = btrfs_cache_create("btrfs_transaction_cache",
2278 sizeof(struct btrfs_transaction),
2280 if (!btrfs_transaction_cachep)
2282 btrfs_path_cachep = btrfs_cache_create("btrfs_path_cache",
2283 sizeof(struct btrfs_path),
2285 if (!btrfs_path_cachep)
2287 btrfs_bit_radix_cachep = btrfs_cache_create("btrfs_radix", 256,
2288 SLAB_DESTROY_BY_RCU, NULL);
2289 if (!btrfs_bit_radix_cachep)
2293 btrfs_destroy_cachep();
2297 static int btrfs_getattr(struct vfsmount *mnt,
2298 struct dentry *dentry, struct kstat *stat)
2300 struct inode *inode = dentry->d_inode;
2301 generic_fillattr(inode, stat);
2302 stat->blksize = 256 * 1024;
2306 static int btrfs_rename(struct inode * old_dir, struct dentry *old_dentry,
2307 struct inode * new_dir,struct dentry *new_dentry)
2309 struct btrfs_trans_handle *trans;
2310 struct btrfs_root *root = BTRFS_I(old_dir)->root;
2311 struct inode *new_inode = new_dentry->d_inode;
2312 struct inode *old_inode = old_dentry->d_inode;
2313 struct timespec ctime = CURRENT_TIME;
2314 struct btrfs_path *path;
2315 struct btrfs_dir_item *di;
2318 if (S_ISDIR(old_inode->i_mode) && new_inode &&
2319 new_inode->i_size > BTRFS_EMPTY_DIR_SIZE) {
2323 mutex_lock(&root->fs_info->fs_mutex);
2324 trans = btrfs_start_transaction(root, 1);
2326 btrfs_set_trans_block_group(trans, new_dir);
2327 path = btrfs_alloc_path();
2333 old_dentry->d_inode->i_nlink++;
2334 old_dir->i_ctime = old_dir->i_mtime = ctime;
2335 new_dir->i_ctime = new_dir->i_mtime = ctime;
2336 old_inode->i_ctime = ctime;
2338 if (S_ISDIR(old_inode->i_mode) && old_dir != new_dir) {
2339 struct btrfs_key *location = &BTRFS_I(new_dir)->location;
2340 struct btrfs_key old_parent_key;
2341 di = btrfs_lookup_dir_item(trans, root, path, old_inode->i_ino,
2351 btrfs_dir_item_key_to_cpu(path->nodes[0], di, &old_parent_key);
2352 ret = btrfs_del_item(trans, root, path);
2356 btrfs_release_path(root, path);
2358 di = btrfs_lookup_dir_index_item(trans, root, path,
2360 old_parent_key.objectid,
2370 ret = btrfs_del_item(trans, root, path);
2374 btrfs_release_path(root, path);
2376 ret = btrfs_insert_dir_item(trans, root, "..", 2,
2377 old_inode->i_ino, location,
2384 ret = btrfs_unlink_trans(trans, root, old_dir, old_dentry);
2389 new_inode->i_ctime = CURRENT_TIME;
2390 ret = btrfs_unlink_trans(trans, root, new_dir, new_dentry);
2394 ret = btrfs_add_link(trans, new_dentry, old_inode);
2399 btrfs_free_path(path);
2400 btrfs_end_transaction(trans, root);
2401 mutex_unlock(&root->fs_info->fs_mutex);
2405 static int btrfs_symlink(struct inode *dir, struct dentry *dentry,
2406 const char *symname)
2408 struct btrfs_trans_handle *trans;
2409 struct btrfs_root *root = BTRFS_I(dir)->root;
2410 struct btrfs_path *path;
2411 struct btrfs_key key;
2412 struct inode *inode;
2419 struct btrfs_file_extent_item *ei;
2420 struct extent_buffer *leaf;
2423 name_len = strlen(symname) + 1;
2424 if (name_len > BTRFS_MAX_INLINE_DATA_SIZE(root))
2425 return -ENAMETOOLONG;
2426 mutex_lock(&root->fs_info->fs_mutex);
2427 trans = btrfs_start_transaction(root, 1);
2428 btrfs_set_trans_block_group(trans, dir);
2430 err = btrfs_find_free_objectid(trans, root, dir->i_ino, &objectid);
2436 inode = btrfs_new_inode(trans, root, objectid,
2437 BTRFS_I(dir)->block_group, S_IFLNK|S_IRWXUGO);
2438 err = PTR_ERR(inode);
2442 btrfs_set_trans_block_group(trans, inode);
2443 err = btrfs_add_nondir(trans, dentry, inode);
2447 inode->i_mapping->a_ops = &btrfs_aops;
2448 inode->i_fop = &btrfs_file_operations;
2449 inode->i_op = &btrfs_file_inode_operations;
2450 extent_map_tree_init(&BTRFS_I(inode)->extent_tree,
2451 inode->i_mapping, GFP_NOFS);
2452 BTRFS_I(inode)->extent_tree.ops = &btrfs_extent_map_ops;
2454 dir->i_sb->s_dirt = 1;
2455 btrfs_update_inode_block_group(trans, inode);
2456 btrfs_update_inode_block_group(trans, dir);
2460 path = btrfs_alloc_path();
2462 key.objectid = inode->i_ino;
2464 btrfs_set_key_type(&key, BTRFS_EXTENT_DATA_KEY);
2465 datasize = btrfs_file_extent_calc_inline_size(name_len);
2466 err = btrfs_insert_empty_item(trans, root, path, &key,
2472 leaf = path->nodes[0];
2473 ei = btrfs_item_ptr(leaf, path->slots[0],
2474 struct btrfs_file_extent_item);
2475 btrfs_set_file_extent_generation(leaf, ei, trans->transid);
2476 btrfs_set_file_extent_type(leaf, ei,
2477 BTRFS_FILE_EXTENT_INLINE);
2478 ptr = btrfs_file_extent_inline_start(ei);
2479 write_extent_buffer(leaf, symname, ptr, name_len);
2480 btrfs_mark_buffer_dirty(leaf);
2481 btrfs_free_path(path);
2483 inode->i_op = &btrfs_symlink_inode_operations;
2484 inode->i_mapping->a_ops = &btrfs_symlink_aops;
2485 inode->i_size = name_len - 1;
2486 err = btrfs_update_inode(trans, root, inode);
2491 nr = trans->blocks_used;
2492 btrfs_end_transaction(trans, root);
2493 mutex_unlock(&root->fs_info->fs_mutex);
2495 inode_dec_link_count(inode);
2498 btrfs_btree_balance_dirty(root, nr);
2502 static struct inode_operations btrfs_dir_inode_operations = {
2503 .lookup = btrfs_lookup,
2504 .create = btrfs_create,
2505 .unlink = btrfs_unlink,
2507 .mkdir = btrfs_mkdir,
2508 .rmdir = btrfs_rmdir,
2509 .rename = btrfs_rename,
2510 .symlink = btrfs_symlink,
2511 .setattr = btrfs_setattr,
2512 .mknod = btrfs_mknod,
2515 static struct inode_operations btrfs_dir_ro_inode_operations = {
2516 .lookup = btrfs_lookup,
2519 static struct file_operations btrfs_dir_file_operations = {
2520 .llseek = generic_file_llseek,
2521 .read = generic_read_dir,
2522 .readdir = btrfs_readdir,
2523 .unlocked_ioctl = btrfs_ioctl,
2524 #ifdef CONFIG_COMPAT
2525 .compat_ioctl = btrfs_ioctl,
2529 static struct extent_map_ops btrfs_extent_map_ops = {
2530 .fill_delalloc = run_delalloc_range,
2531 .writepage_io_hook = btrfs_writepage_io_hook,
2532 .readpage_io_hook = btrfs_readpage_io_hook,
2533 .readpage_end_io_hook = btrfs_readpage_end_io_hook,
2536 static struct address_space_operations btrfs_aops = {
2537 .readpage = btrfs_readpage,
2538 .writepage = btrfs_writepage,
2539 .writepages = btrfs_writepages,
2540 .sync_page = block_sync_page,
2541 .prepare_write = btrfs_prepare_write,
2542 .commit_write = btrfs_commit_write,
2544 .invalidatepage = btrfs_invalidatepage,
2545 .releasepage = btrfs_releasepage,
2546 .set_page_dirty = __set_page_dirty_nobuffers,
2549 static struct address_space_operations btrfs_symlink_aops = {
2550 .readpage = btrfs_readpage,
2551 .writepage = btrfs_writepage,
2552 .invalidatepage = btrfs_invalidatepage,
2553 .releasepage = btrfs_releasepage,
2556 static struct inode_operations btrfs_file_inode_operations = {
2557 .truncate = btrfs_truncate,
2558 .getattr = btrfs_getattr,
2559 .setattr = btrfs_setattr,
2562 static struct inode_operations btrfs_special_inode_operations = {
2563 .getattr = btrfs_getattr,
2564 .setattr = btrfs_setattr,
2567 static struct inode_operations btrfs_symlink_inode_operations = {
2568 .readlink = generic_readlink,
2569 .follow_link = page_follow_link_light,
2570 .put_link = page_put_link,