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;
56 static struct kmem_cache *btrfs_inode_cachep;
57 struct kmem_cache *btrfs_trans_handle_cachep;
58 struct kmem_cache *btrfs_transaction_cachep;
59 struct kmem_cache *btrfs_bit_radix_cachep;
60 struct kmem_cache *btrfs_path_cachep;
63 static unsigned char btrfs_type_by_mode[S_IFMT >> S_SHIFT] = {
64 [S_IFREG >> S_SHIFT] = BTRFS_FT_REG_FILE,
65 [S_IFDIR >> S_SHIFT] = BTRFS_FT_DIR,
66 [S_IFCHR >> S_SHIFT] = BTRFS_FT_CHRDEV,
67 [S_IFBLK >> S_SHIFT] = BTRFS_FT_BLKDEV,
68 [S_IFIFO >> S_SHIFT] = BTRFS_FT_FIFO,
69 [S_IFSOCK >> S_SHIFT] = BTRFS_FT_SOCK,
70 [S_IFLNK >> S_SHIFT] = BTRFS_FT_SYMLINK,
73 void btrfs_read_locked_inode(struct inode *inode)
75 struct btrfs_path *path;
76 struct btrfs_inode_item *inode_item;
77 struct btrfs_root *root = BTRFS_I(inode)->root;
78 struct btrfs_key location;
79 u64 alloc_group_block;
83 path = btrfs_alloc_path();
85 mutex_lock(&root->fs_info->fs_mutex);
87 memcpy(&location, &BTRFS_I(inode)->location, sizeof(location));
88 ret = btrfs_lookup_inode(NULL, root, path, &location, 0);
90 btrfs_free_path(path);
93 inode_item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]),
95 struct btrfs_inode_item);
97 inode->i_mode = btrfs_inode_mode(inode_item);
98 inode->i_nlink = btrfs_inode_nlink(inode_item);
99 inode->i_uid = btrfs_inode_uid(inode_item);
100 inode->i_gid = btrfs_inode_gid(inode_item);
101 inode->i_size = btrfs_inode_size(inode_item);
102 inode->i_atime.tv_sec = btrfs_timespec_sec(&inode_item->atime);
103 inode->i_atime.tv_nsec = btrfs_timespec_nsec(&inode_item->atime);
104 inode->i_mtime.tv_sec = btrfs_timespec_sec(&inode_item->mtime);
105 inode->i_mtime.tv_nsec = btrfs_timespec_nsec(&inode_item->mtime);
106 inode->i_ctime.tv_sec = btrfs_timespec_sec(&inode_item->ctime);
107 inode->i_ctime.tv_nsec = btrfs_timespec_nsec(&inode_item->ctime);
108 inode->i_blocks = btrfs_inode_nblocks(inode_item);
109 inode->i_generation = btrfs_inode_generation(inode_item);
111 rdev = btrfs_inode_rdev(inode_item);
112 alloc_group_block = btrfs_inode_block_group(inode_item);
113 BTRFS_I(inode)->block_group = btrfs_lookup_block_group(root->fs_info,
116 btrfs_free_path(path);
119 mutex_unlock(&root->fs_info->fs_mutex);
121 switch (inode->i_mode & S_IFMT) {
123 inode->i_mapping->a_ops = &btrfs_aops;
124 inode->i_fop = &btrfs_file_operations;
125 inode->i_op = &btrfs_file_inode_operations;
128 inode->i_fop = &btrfs_dir_file_operations;
129 if (root == root->fs_info->tree_root)
130 inode->i_op = &btrfs_dir_ro_inode_operations;
132 inode->i_op = &btrfs_dir_inode_operations;
135 inode->i_op = &btrfs_symlink_inode_operations;
136 inode->i_mapping->a_ops = &btrfs_symlink_aops;
139 init_special_inode(inode, inode->i_mode, rdev);
145 btrfs_release_path(root, path);
146 btrfs_free_path(path);
147 mutex_unlock(&root->fs_info->fs_mutex);
148 make_bad_inode(inode);
151 static void fill_inode_item(struct btrfs_inode_item *item,
154 btrfs_set_inode_uid(item, inode->i_uid);
155 btrfs_set_inode_gid(item, inode->i_gid);
156 btrfs_set_inode_size(item, inode->i_size);
157 btrfs_set_inode_mode(item, inode->i_mode);
158 btrfs_set_inode_nlink(item, inode->i_nlink);
159 btrfs_set_timespec_sec(&item->atime, inode->i_atime.tv_sec);
160 btrfs_set_timespec_nsec(&item->atime, inode->i_atime.tv_nsec);
161 btrfs_set_timespec_sec(&item->mtime, inode->i_mtime.tv_sec);
162 btrfs_set_timespec_nsec(&item->mtime, inode->i_mtime.tv_nsec);
163 btrfs_set_timespec_sec(&item->ctime, inode->i_ctime.tv_sec);
164 btrfs_set_timespec_nsec(&item->ctime, inode->i_ctime.tv_nsec);
165 btrfs_set_inode_nblocks(item, inode->i_blocks);
166 btrfs_set_inode_generation(item, inode->i_generation);
167 btrfs_set_inode_rdev(item, inode->i_rdev);
168 btrfs_set_inode_block_group(item,
169 BTRFS_I(inode)->block_group->key.objectid);
172 static int btrfs_update_inode(struct btrfs_trans_handle *trans,
173 struct btrfs_root *root,
176 struct btrfs_inode_item *inode_item;
177 struct btrfs_path *path;
180 path = btrfs_alloc_path();
182 ret = btrfs_lookup_inode(trans, root, path,
183 &BTRFS_I(inode)->location, 1);
190 inode_item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]),
192 struct btrfs_inode_item);
194 fill_inode_item(inode_item, inode);
195 btrfs_mark_buffer_dirty(path->nodes[0]);
198 btrfs_release_path(root, path);
199 btrfs_free_path(path);
204 static int btrfs_unlink_trans(struct btrfs_trans_handle *trans,
205 struct btrfs_root *root,
207 struct dentry *dentry)
209 struct btrfs_path *path;
210 const char *name = dentry->d_name.name;
211 int name_len = dentry->d_name.len;
214 struct btrfs_dir_item *di;
216 path = btrfs_alloc_path();
222 di = btrfs_lookup_dir_item(trans, root, path, dir->i_ino,
232 objectid = btrfs_disk_key_objectid(&di->location);
233 ret = btrfs_delete_one_dir_name(trans, root, path, di);
236 btrfs_release_path(root, path);
238 di = btrfs_lookup_dir_index_item(trans, root, path, dir->i_ino,
239 objectid, name, name_len, -1);
248 ret = btrfs_delete_one_dir_name(trans, root, path, di);
250 dentry->d_inode->i_ctime = dir->i_ctime;
252 btrfs_free_path(path);
254 dir->i_size -= name_len * 2;
255 dir->i_mtime = dir->i_ctime = CURRENT_TIME;
256 btrfs_update_inode(trans, root, dir);
257 drop_nlink(dentry->d_inode);
258 ret = btrfs_update_inode(trans, root, dentry->d_inode);
259 dir->i_sb->s_dirt = 1;
264 static int btrfs_unlink(struct inode *dir, struct dentry *dentry)
266 struct btrfs_root *root;
267 struct btrfs_trans_handle *trans;
270 root = BTRFS_I(dir)->root;
271 mutex_lock(&root->fs_info->fs_mutex);
272 trans = btrfs_start_transaction(root, 1);
273 btrfs_set_trans_block_group(trans, dir);
274 ret = btrfs_unlink_trans(trans, root, dir, dentry);
275 btrfs_end_transaction(trans, root);
276 mutex_unlock(&root->fs_info->fs_mutex);
277 btrfs_btree_balance_dirty(root);
281 static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
283 struct inode *inode = dentry->d_inode;
286 struct btrfs_root *root = BTRFS_I(dir)->root;
287 struct btrfs_path *path;
288 struct btrfs_key key;
289 struct btrfs_trans_handle *trans;
290 struct btrfs_key found_key;
292 struct btrfs_leaf *leaf;
293 char *goodnames = "..";
295 path = btrfs_alloc_path();
297 mutex_lock(&root->fs_info->fs_mutex);
298 trans = btrfs_start_transaction(root, 1);
299 btrfs_set_trans_block_group(trans, dir);
300 key.objectid = inode->i_ino;
301 key.offset = (u64)-1;
304 ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
310 if (path->slots[0] == 0) {
315 leaf = btrfs_buffer_leaf(path->nodes[0]);
316 btrfs_disk_key_to_cpu(&found_key,
317 &leaf->items[path->slots[0]].key);
318 found_type = btrfs_key_type(&found_key);
319 if (found_key.objectid != inode->i_ino) {
323 if ((found_type != BTRFS_DIR_ITEM_KEY &&
324 found_type != BTRFS_DIR_INDEX_KEY) ||
325 (!btrfs_match_dir_item_name(root, path, goodnames, 2) &&
326 !btrfs_match_dir_item_name(root, path, goodnames, 1))) {
330 ret = btrfs_del_item(trans, root, path);
333 if (found_type == BTRFS_DIR_ITEM_KEY && found_key.offset == 1)
335 btrfs_release_path(root, path);
338 btrfs_release_path(root, path);
340 /* now the directory is empty */
341 err = btrfs_unlink_trans(trans, root, dir, dentry);
346 btrfs_release_path(root, path);
347 btrfs_free_path(path);
348 mutex_unlock(&root->fs_info->fs_mutex);
349 ret = btrfs_end_transaction(trans, root);
350 btrfs_btree_balance_dirty(root);
356 static int btrfs_free_inode(struct btrfs_trans_handle *trans,
357 struct btrfs_root *root,
360 struct btrfs_path *path;
365 path = btrfs_alloc_path();
367 ret = btrfs_lookup_inode(trans, root, path,
368 &BTRFS_I(inode)->location, -1);
372 ret = btrfs_del_item(trans, root, path);
373 btrfs_free_path(path);
378 * this can truncate away extent items, csum items and directory items.
379 * It starts at a high offset and removes keys until it can't find
380 * any higher than i_size.
382 * csum items that cross the new i_size are truncated to the new size
385 static int btrfs_truncate_in_trans(struct btrfs_trans_handle *trans,
386 struct btrfs_root *root,
390 struct btrfs_path *path;
391 struct btrfs_key key;
392 struct btrfs_disk_key *found_key;
394 struct btrfs_leaf *leaf;
395 struct btrfs_file_extent_item *fi;
396 u64 extent_start = 0;
397 u64 extent_num_blocks = 0;
402 path = btrfs_alloc_path();
405 /* FIXME, add redo link to tree so we don't leak on crash */
406 key.objectid = inode->i_ino;
407 key.offset = (u64)-1;
410 btrfs_init_path(path);
412 ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
417 BUG_ON(path->slots[0] == 0);
420 leaf = btrfs_buffer_leaf(path->nodes[0]);
421 found_key = &leaf->items[path->slots[0]].key;
422 found_type = btrfs_disk_key_type(found_key);
424 if (btrfs_disk_key_objectid(found_key) != inode->i_ino)
426 if (found_type != BTRFS_CSUM_ITEM_KEY &&
427 found_type != BTRFS_DIR_ITEM_KEY &&
428 found_type != BTRFS_DIR_INDEX_KEY &&
429 found_type != BTRFS_EXTENT_DATA_KEY)
432 item_end = btrfs_disk_key_offset(found_key);
433 if (found_type == BTRFS_EXTENT_DATA_KEY) {
434 fi = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]),
436 struct btrfs_file_extent_item);
437 if (btrfs_file_extent_type(fi) !=
438 BTRFS_FILE_EXTENT_INLINE) {
439 item_end += btrfs_file_extent_num_blocks(fi) <<
443 if (found_type == BTRFS_CSUM_ITEM_KEY) {
444 ret = btrfs_csum_truncate(trans, root, path,
448 if (item_end < inode->i_size) {
450 btrfs_set_key_type(&key, found_type - 1);
455 if (btrfs_disk_key_offset(found_key) >= inode->i_size)
461 /* FIXME, shrink the extent if the ref count is only 1 */
462 if (found_type == BTRFS_EXTENT_DATA_KEY &&
463 btrfs_file_extent_type(fi) !=
464 BTRFS_FILE_EXTENT_INLINE) {
467 u64 orig_num_blocks =
468 btrfs_file_extent_num_blocks(fi);
469 extent_num_blocks = inode->i_size -
470 btrfs_disk_key_offset(found_key) +
472 extent_num_blocks >>= inode->i_blkbits;
473 btrfs_set_file_extent_num_blocks(fi,
475 inode->i_blocks -= (orig_num_blocks -
476 extent_num_blocks) << 3;
477 btrfs_mark_buffer_dirty(path->nodes[0]);
480 btrfs_file_extent_disk_blocknr(fi);
482 btrfs_file_extent_disk_num_blocks(fi);
483 /* FIXME blocksize != 4096 */
484 num_dec = btrfs_file_extent_num_blocks(fi) << 3;
485 if (extent_start != 0) {
487 inode->i_blocks -= num_dec;
492 ret = btrfs_del_item(trans, root, path);
498 btrfs_release_path(root, path);
500 ret = btrfs_free_extent(trans, root, extent_start,
501 extent_num_blocks, 0);
507 btrfs_release_path(root, path);
508 btrfs_free_path(path);
509 inode->i_sb->s_dirt = 1;
514 * taken from block_truncate_page, but does cow as it zeros out
515 * any bytes left in the last page in the file.
517 static int btrfs_truncate_page(struct address_space *mapping, loff_t from)
519 struct inode *inode = mapping->host;
520 unsigned blocksize = 1 << inode->i_blkbits;
521 pgoff_t index = from >> PAGE_CACHE_SHIFT;
522 unsigned offset = from & (PAGE_CACHE_SIZE-1);
526 struct btrfs_root *root = BTRFS_I(inode)->root;
528 struct btrfs_key ins;
529 struct btrfs_trans_handle *trans;
531 if ((offset & (blocksize - 1)) == 0)
535 page = grab_cache_page(mapping, index);
539 if (!PageUptodate(page)) {
540 ret = btrfs_readpage(NULL, page);
542 if (!PageUptodate(page)) {
547 mutex_lock(&root->fs_info->fs_mutex);
548 trans = btrfs_start_transaction(root, 1);
549 btrfs_set_trans_block_group(trans, inode);
551 ret = btrfs_drop_extents(trans, root, inode,
552 page->index << PAGE_CACHE_SHIFT,
553 (page->index + 1) << PAGE_CACHE_SHIFT,
557 ret = btrfs_alloc_extent(trans, root, inode->i_ino, 1, 0,
558 alloc_hint, (u64)-1, &ins, 1);
561 ret = btrfs_insert_file_extent(trans, root, inode->i_ino,
562 page->index << PAGE_CACHE_SHIFT,
566 SetPageChecked(page);
568 memset(kaddr + offset, 0, PAGE_CACHE_SIZE - offset);
569 flush_dcache_page(page);
570 ret = btrfs_csum_file_block(trans, root, inode->i_ino,
571 page->index << PAGE_CACHE_SHIFT,
572 kaddr, PAGE_CACHE_SIZE);
574 btrfs_end_transaction(trans, root);
575 mutex_unlock(&root->fs_info->fs_mutex);
577 set_page_dirty(page);
579 page_cache_release(page);
584 static int btrfs_setattr(struct dentry *dentry, struct iattr *attr)
586 struct inode *inode = dentry->d_inode;
589 err = inode_change_ok(inode, attr);
593 if (S_ISREG(inode->i_mode) &&
594 attr->ia_valid & ATTR_SIZE && attr->ia_size > inode->i_size) {
595 struct btrfs_trans_handle *trans;
596 struct btrfs_root *root = BTRFS_I(inode)->root;
597 u64 mask = root->blocksize - 1;
598 u64 pos = (inode->i_size + mask) & ~mask;
601 if (attr->ia_size <= pos)
604 btrfs_truncate_page(inode->i_mapping, inode->i_size);
606 hole_size = (attr->ia_size - pos + mask) & ~mask;
607 hole_size >>= inode->i_blkbits;
609 mutex_lock(&root->fs_info->fs_mutex);
610 trans = btrfs_start_transaction(root, 1);
611 btrfs_set_trans_block_group(trans, inode);
612 err = btrfs_insert_file_extent(trans, root, inode->i_ino,
613 pos, 0, 0, hole_size);
614 btrfs_end_transaction(trans, root);
615 mutex_unlock(&root->fs_info->fs_mutex);
620 err = inode_setattr(inode, attr);
624 void btrfs_delete_inode(struct inode *inode)
626 struct btrfs_trans_handle *trans;
627 struct btrfs_root *root = BTRFS_I(inode)->root;
630 truncate_inode_pages(&inode->i_data, 0);
631 if (is_bad_inode(inode)) {
635 mutex_lock(&root->fs_info->fs_mutex);
636 trans = btrfs_start_transaction(root, 1);
637 btrfs_set_trans_block_group(trans, inode);
638 ret = btrfs_truncate_in_trans(trans, root, inode);
641 ret = btrfs_free_inode(trans, root, inode);
644 btrfs_end_transaction(trans, root);
645 mutex_unlock(&root->fs_info->fs_mutex);
646 btrfs_btree_balance_dirty(root);
650 btrfs_end_transaction(trans, root);
651 mutex_unlock(&root->fs_info->fs_mutex);
652 btrfs_btree_balance_dirty(root);
658 * this returns the key found in the dir entry in the location pointer.
659 * If no dir entries were found, location->objectid is 0.
661 static int btrfs_inode_by_name(struct inode *dir, struct dentry *dentry,
662 struct btrfs_key *location)
664 const char *name = dentry->d_name.name;
665 int namelen = dentry->d_name.len;
666 struct btrfs_dir_item *di;
667 struct btrfs_path *path;
668 struct btrfs_root *root = BTRFS_I(dir)->root;
671 path = btrfs_alloc_path();
673 di = btrfs_lookup_dir_item(NULL, root, path, dir->i_ino, name,
675 if (!di || IS_ERR(di)) {
676 location->objectid = 0;
680 btrfs_disk_key_to_cpu(location, &di->location);
682 btrfs_release_path(root, path);
683 btrfs_free_path(path);
688 * when we hit a tree root in a directory, the btrfs part of the inode
689 * needs to be changed to reflect the root directory of the tree root. This
690 * is kind of like crossing a mount point.
692 static int fixup_tree_root_location(struct btrfs_root *root,
693 struct btrfs_key *location,
694 struct btrfs_root **sub_root)
696 struct btrfs_path *path;
697 struct btrfs_root_item *ri;
699 if (btrfs_key_type(location) != BTRFS_ROOT_ITEM_KEY)
701 if (location->objectid == BTRFS_ROOT_TREE_OBJECTID)
704 path = btrfs_alloc_path();
706 mutex_lock(&root->fs_info->fs_mutex);
708 *sub_root = btrfs_read_fs_root(root->fs_info, location);
709 if (IS_ERR(*sub_root))
710 return PTR_ERR(*sub_root);
712 ri = &(*sub_root)->root_item;
713 location->objectid = btrfs_root_dirid(ri);
715 btrfs_set_key_type(location, BTRFS_INODE_ITEM_KEY);
716 location->offset = 0;
718 btrfs_free_path(path);
719 mutex_unlock(&root->fs_info->fs_mutex);
723 static int btrfs_init_locked_inode(struct inode *inode, void *p)
725 struct btrfs_iget_args *args = p;
726 inode->i_ino = args->ino;
727 BTRFS_I(inode)->root = args->root;
731 static int btrfs_find_actor(struct inode *inode, void *opaque)
733 struct btrfs_iget_args *args = opaque;
734 return (args->ino == inode->i_ino &&
735 args->root == BTRFS_I(inode)->root);
738 struct inode *btrfs_iget_locked(struct super_block *s, u64 objectid,
739 struct btrfs_root *root)
742 struct btrfs_iget_args args;
746 inode = iget5_locked(s, objectid, btrfs_find_actor,
747 btrfs_init_locked_inode,
752 static struct dentry *btrfs_lookup(struct inode *dir, struct dentry *dentry,
753 struct nameidata *nd)
755 struct inode * inode;
756 struct btrfs_inode *bi = BTRFS_I(dir);
757 struct btrfs_root *root = bi->root;
758 struct btrfs_root *sub_root = root;
759 struct btrfs_key location;
762 if (dentry->d_name.len > BTRFS_NAME_LEN)
763 return ERR_PTR(-ENAMETOOLONG);
764 mutex_lock(&root->fs_info->fs_mutex);
765 ret = btrfs_inode_by_name(dir, dentry, &location);
766 mutex_unlock(&root->fs_info->fs_mutex);
770 if (location.objectid) {
771 ret = fixup_tree_root_location(root, &location, &sub_root);
775 return ERR_PTR(-ENOENT);
776 inode = btrfs_iget_locked(dir->i_sb, location.objectid,
779 return ERR_PTR(-EACCES);
780 if (inode->i_state & I_NEW) {
781 /* the inode and parent dir are two different roots */
782 if (sub_root != root) {
784 sub_root->inode = inode;
786 BTRFS_I(inode)->root = sub_root;
787 memcpy(&BTRFS_I(inode)->location, &location,
789 btrfs_read_locked_inode(inode);
790 unlock_new_inode(inode);
793 return d_splice_alias(inode, dentry);
796 static unsigned char btrfs_filetype_table[] = {
797 DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK
800 static int btrfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
802 struct inode *inode = filp->f_path.dentry->d_inode;
803 struct btrfs_root *root = BTRFS_I(inode)->root;
804 struct btrfs_item *item;
805 struct btrfs_dir_item *di;
806 struct btrfs_key key;
807 struct btrfs_path *path;
810 struct btrfs_leaf *leaf;
813 unsigned char d_type;
818 int key_type = BTRFS_DIR_INDEX_KEY;
820 /* FIXME, use a real flag for deciding about the key type */
821 if (root->fs_info->tree_root == root)
822 key_type = BTRFS_DIR_ITEM_KEY;
823 mutex_lock(&root->fs_info->fs_mutex);
824 key.objectid = inode->i_ino;
826 btrfs_set_key_type(&key, key_type);
827 key.offset = filp->f_pos;
828 path = btrfs_alloc_path();
830 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
835 leaf = btrfs_buffer_leaf(path->nodes[0]);
836 nritems = btrfs_header_nritems(&leaf->header);
837 slot = path->slots[0];
838 if (advance || slot >= nritems) {
839 if (slot >= nritems -1) {
840 ret = btrfs_next_leaf(root, path);
843 leaf = btrfs_buffer_leaf(path->nodes[0]);
844 nritems = btrfs_header_nritems(&leaf->header);
845 slot = path->slots[0];
852 item = leaf->items + slot;
853 if (btrfs_disk_key_objectid(&item->key) != key.objectid)
855 if (btrfs_disk_key_type(&item->key) != key_type)
857 if (btrfs_disk_key_offset(&item->key) < filp->f_pos)
859 filp->f_pos = btrfs_disk_key_offset(&item->key);
861 di = btrfs_item_ptr(leaf, slot, struct btrfs_dir_item);
863 di_total = btrfs_item_size(leaf->items + slot);
864 while(di_cur < di_total) {
865 d_type = btrfs_filetype_table[btrfs_dir_type(di)];
866 over = filldir(dirent, (const char *)(di + 1),
867 btrfs_dir_name_len(di),
868 btrfs_disk_key_offset(&item->key),
869 btrfs_disk_key_objectid(&di->location),
873 di_len = btrfs_dir_name_len(di) + sizeof(*di);
875 di = (struct btrfs_dir_item *)((char *)di + di_len);
882 btrfs_release_path(root, path);
883 btrfs_free_path(path);
884 mutex_unlock(&root->fs_info->fs_mutex);
888 int btrfs_write_inode(struct inode *inode, int wait)
890 struct btrfs_root *root = BTRFS_I(inode)->root;
891 struct btrfs_trans_handle *trans;
895 mutex_lock(&root->fs_info->fs_mutex);
896 trans = btrfs_start_transaction(root, 1);
897 btrfs_set_trans_block_group(trans, inode);
898 ret = btrfs_commit_transaction(trans, root);
899 mutex_unlock(&root->fs_info->fs_mutex);
905 * This is somewhat expensive, updating the tree every time the
906 * inode changes. But, it is most likely to find the inode in cache.
907 * FIXME, needs more benchmarking...there are no reasons other than performance
908 * to keep or drop this code.
910 void btrfs_dirty_inode(struct inode *inode)
912 struct btrfs_root *root = BTRFS_I(inode)->root;
913 struct btrfs_trans_handle *trans;
915 mutex_lock(&root->fs_info->fs_mutex);
916 trans = btrfs_start_transaction(root, 1);
917 btrfs_set_trans_block_group(trans, inode);
918 btrfs_update_inode(trans, root, inode);
919 btrfs_end_transaction(trans, root);
920 mutex_unlock(&root->fs_info->fs_mutex);
923 static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,
924 struct btrfs_root *root,
926 struct btrfs_block_group_cache *group,
930 struct btrfs_inode_item inode_item;
931 struct btrfs_key *location;
935 inode = new_inode(root->fs_info->sb);
937 return ERR_PTR(-ENOMEM);
939 BTRFS_I(inode)->root = root;
944 group = btrfs_find_block_group(root, group, 0, 0, owner);
945 BTRFS_I(inode)->block_group = group;
947 inode->i_uid = current->fsuid;
948 inode->i_gid = current->fsgid;
949 inode->i_mode = mode;
950 inode->i_ino = objectid;
952 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
953 fill_inode_item(&inode_item, inode);
954 location = &BTRFS_I(inode)->location;
955 location->objectid = objectid;
957 location->offset = 0;
958 btrfs_set_key_type(location, BTRFS_INODE_ITEM_KEY);
960 ret = btrfs_insert_inode(trans, root, objectid, &inode_item);
963 insert_inode_hash(inode);
967 static inline u8 btrfs_inode_type(struct inode *inode)
969 return btrfs_type_by_mode[(inode->i_mode & S_IFMT) >> S_SHIFT];
972 static int btrfs_add_link(struct btrfs_trans_handle *trans,
973 struct dentry *dentry, struct inode *inode)
976 struct btrfs_key key;
977 struct btrfs_root *root = BTRFS_I(dentry->d_parent->d_inode)->root;
978 struct inode *parent_inode;
979 key.objectid = inode->i_ino;
981 btrfs_set_key_type(&key, BTRFS_INODE_ITEM_KEY);
984 ret = btrfs_insert_dir_item(trans, root,
985 dentry->d_name.name, dentry->d_name.len,
986 dentry->d_parent->d_inode->i_ino,
987 &key, btrfs_inode_type(inode));
989 parent_inode = dentry->d_parent->d_inode;
990 parent_inode->i_size += dentry->d_name.len * 2;
991 parent_inode->i_mtime = parent_inode->i_ctime = CURRENT_TIME;
992 ret = btrfs_update_inode(trans, root,
993 dentry->d_parent->d_inode);
998 static int btrfs_add_nondir(struct btrfs_trans_handle *trans,
999 struct dentry *dentry, struct inode *inode)
1001 int err = btrfs_add_link(trans, dentry, inode);
1003 d_instantiate(dentry, inode);
1011 static int btrfs_mknod(struct inode *dir, struct dentry *dentry,
1012 int mode, dev_t rdev)
1014 struct btrfs_trans_handle *trans;
1015 struct btrfs_root *root = BTRFS_I(dir)->root;
1016 struct inode *inode;
1021 if (!new_valid_dev(rdev))
1024 mutex_lock(&root->fs_info->fs_mutex);
1025 trans = btrfs_start_transaction(root, 1);
1026 btrfs_set_trans_block_group(trans, dir);
1028 err = btrfs_find_free_objectid(trans, root, dir->i_ino, &objectid);
1034 inode = btrfs_new_inode(trans, root, objectid,
1035 BTRFS_I(dir)->block_group, mode);
1036 err = PTR_ERR(inode);
1040 btrfs_set_trans_block_group(trans, inode);
1041 err = btrfs_add_nondir(trans, dentry, inode);
1045 inode->i_op = &btrfs_special_inode_operations;
1046 init_special_inode(inode, inode->i_mode, rdev);
1048 dir->i_sb->s_dirt = 1;
1049 btrfs_update_inode_block_group(trans, inode);
1050 btrfs_update_inode_block_group(trans, dir);
1052 btrfs_end_transaction(trans, root);
1053 mutex_unlock(&root->fs_info->fs_mutex);
1056 inode_dec_link_count(inode);
1059 btrfs_btree_balance_dirty(root);
1063 static int btrfs_create(struct inode *dir, struct dentry *dentry,
1064 int mode, struct nameidata *nd)
1066 struct btrfs_trans_handle *trans;
1067 struct btrfs_root *root = BTRFS_I(dir)->root;
1068 struct inode *inode;
1073 mutex_lock(&root->fs_info->fs_mutex);
1074 trans = btrfs_start_transaction(root, 1);
1075 btrfs_set_trans_block_group(trans, dir);
1077 err = btrfs_find_free_objectid(trans, root, dir->i_ino, &objectid);
1083 inode = btrfs_new_inode(trans, root, objectid,
1084 BTRFS_I(dir)->block_group, mode);
1085 err = PTR_ERR(inode);
1089 btrfs_set_trans_block_group(trans, inode);
1090 err = btrfs_add_nondir(trans, dentry, inode);
1094 inode->i_mapping->a_ops = &btrfs_aops;
1095 inode->i_fop = &btrfs_file_operations;
1096 inode->i_op = &btrfs_file_inode_operations;
1098 dir->i_sb->s_dirt = 1;
1099 btrfs_update_inode_block_group(trans, inode);
1100 btrfs_update_inode_block_group(trans, dir);
1102 btrfs_end_transaction(trans, root);
1103 mutex_unlock(&root->fs_info->fs_mutex);
1106 inode_dec_link_count(inode);
1109 btrfs_btree_balance_dirty(root);
1113 static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
1114 struct dentry *dentry)
1116 struct btrfs_trans_handle *trans;
1117 struct btrfs_root *root = BTRFS_I(dir)->root;
1118 struct inode *inode = old_dentry->d_inode;
1122 if (inode->i_nlink == 0)
1126 mutex_lock(&root->fs_info->fs_mutex);
1127 trans = btrfs_start_transaction(root, 1);
1128 btrfs_set_trans_block_group(trans, dir);
1129 atomic_inc(&inode->i_count);
1130 err = btrfs_add_nondir(trans, dentry, inode);
1133 dir->i_sb->s_dirt = 1;
1134 btrfs_update_inode_block_group(trans, dir);
1135 err = btrfs_update_inode(trans, root, inode);
1139 btrfs_end_transaction(trans, root);
1140 mutex_unlock(&root->fs_info->fs_mutex);
1143 inode_dec_link_count(inode);
1146 btrfs_btree_balance_dirty(root);
1150 static int btrfs_make_empty_dir(struct btrfs_trans_handle *trans,
1151 struct btrfs_root *root,
1152 u64 objectid, u64 dirid)
1156 struct btrfs_key key;
1161 key.objectid = objectid;
1164 btrfs_set_key_type(&key, BTRFS_INODE_ITEM_KEY);
1166 ret = btrfs_insert_dir_item(trans, root, buf, 1, objectid,
1167 &key, BTRFS_FT_DIR);
1170 key.objectid = dirid;
1171 ret = btrfs_insert_dir_item(trans, root, buf, 2, objectid,
1172 &key, BTRFS_FT_DIR);
1179 static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
1181 struct inode *inode;
1182 struct btrfs_trans_handle *trans;
1183 struct btrfs_root *root = BTRFS_I(dir)->root;
1185 int drop_on_err = 0;
1188 mutex_lock(&root->fs_info->fs_mutex);
1189 trans = btrfs_start_transaction(root, 1);
1190 btrfs_set_trans_block_group(trans, dir);
1191 if (IS_ERR(trans)) {
1192 err = PTR_ERR(trans);
1196 err = btrfs_find_free_objectid(trans, root, dir->i_ino, &objectid);
1202 inode = btrfs_new_inode(trans, root, objectid,
1203 BTRFS_I(dir)->block_group, S_IFDIR | mode);
1204 if (IS_ERR(inode)) {
1205 err = PTR_ERR(inode);
1209 inode->i_op = &btrfs_dir_inode_operations;
1210 inode->i_fop = &btrfs_dir_file_operations;
1211 btrfs_set_trans_block_group(trans, inode);
1213 err = btrfs_make_empty_dir(trans, root, inode->i_ino, dir->i_ino);
1218 err = btrfs_update_inode(trans, root, inode);
1221 err = btrfs_add_link(trans, dentry, inode);
1224 d_instantiate(dentry, inode);
1226 dir->i_sb->s_dirt = 1;
1227 btrfs_update_inode_block_group(trans, inode);
1228 btrfs_update_inode_block_group(trans, dir);
1231 btrfs_end_transaction(trans, root);
1233 mutex_unlock(&root->fs_info->fs_mutex);
1236 btrfs_btree_balance_dirty(root);
1241 * FIBMAP and others want to pass in a fake buffer head. They need to
1242 * use BTRFS_GET_BLOCK_NO_DIRECT to make sure we don't try to memcpy
1243 * any packed file data into the fake bh
1245 #define BTRFS_GET_BLOCK_NO_CREATE 0
1246 #define BTRFS_GET_BLOCK_CREATE 1
1247 #define BTRFS_GET_BLOCK_NO_DIRECT 2
1250 * FIXME create==1 doe not work.
1252 static int btrfs_get_block_lock(struct inode *inode, sector_t iblock,
1253 struct buffer_head *result, int create)
1258 u64 extent_start = 0;
1260 u64 objectid = inode->i_ino;
1263 struct btrfs_path *path;
1264 struct btrfs_root *root = BTRFS_I(inode)->root;
1265 struct btrfs_file_extent_item *item;
1266 struct btrfs_leaf *leaf;
1267 struct btrfs_disk_key *found_key;
1268 struct btrfs_trans_handle *trans = NULL;
1270 path = btrfs_alloc_path();
1272 if (create & BTRFS_GET_BLOCK_CREATE) {
1274 * danger!, this only works if the page is properly up
1277 trans = btrfs_start_transaction(root, 1);
1282 ret = btrfs_drop_extents(trans, root, inode,
1283 iblock << inode->i_blkbits,
1284 (iblock + 1) << inode->i_blkbits,
1289 ret = btrfs_lookup_file_extent(NULL, root, path,
1291 iblock << inode->i_blkbits, 0);
1298 if (path->slots[0] == 0) {
1299 btrfs_release_path(root, path);
1305 item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]), path->slots[0],
1306 struct btrfs_file_extent_item);
1307 leaf = btrfs_buffer_leaf(path->nodes[0]);
1308 blocknr = btrfs_file_extent_disk_blocknr(item);
1309 blocknr += btrfs_file_extent_offset(item);
1311 /* are we inside the extent that was found? */
1312 found_key = &leaf->items[path->slots[0]].key;
1313 found_type = btrfs_disk_key_type(found_key);
1314 if (btrfs_disk_key_objectid(found_key) != objectid ||
1315 found_type != BTRFS_EXTENT_DATA_KEY) {
1320 found_type = btrfs_file_extent_type(item);
1321 extent_start = btrfs_disk_key_offset(&leaf->items[path->slots[0]].key);
1322 if (found_type == BTRFS_FILE_EXTENT_REG) {
1323 extent_start = extent_start >> inode->i_blkbits;
1324 extent_end = extent_start + btrfs_file_extent_num_blocks(item);
1326 if (btrfs_file_extent_disk_blocknr(item) == 0)
1328 if (iblock >= extent_start && iblock < extent_end) {
1329 btrfs_map_bh_to_logical(root, result, blocknr +
1330 iblock - extent_start);
1333 } else if (found_type == BTRFS_FILE_EXTENT_INLINE) {
1338 if (create & BTRFS_GET_BLOCK_NO_DIRECT) {
1342 size = btrfs_file_extent_inline_len(leaf->items +
1344 extent_end = (extent_start + size) >> inode->i_blkbits;
1345 extent_start >>= inode->i_blkbits;
1346 if (iblock < extent_start || iblock > extent_end) {
1349 ptr = btrfs_file_extent_inline_start(item);
1350 map = kmap(result->b_page);
1351 memcpy(map, ptr, size);
1352 memset(map + size, 0, PAGE_CACHE_SIZE - size);
1353 flush_dcache_page(result->b_page);
1354 kunmap(result->b_page);
1355 set_buffer_uptodate(result);
1356 SetPageChecked(result->b_page);
1357 btrfs_map_bh_to_logical(root, result, 0);
1360 if (create & BTRFS_GET_BLOCK_CREATE) {
1361 struct btrfs_key ins;
1362 ret = btrfs_alloc_extent(trans, root, inode->i_ino,
1363 1, 0, alloc_hint, (u64)-1,
1369 ret = btrfs_insert_file_extent(trans, root, inode->i_ino,
1370 iblock << inode->i_blkbits,
1371 ins.objectid, ins.offset,
1377 btrfs_map_bh_to_logical(root, result, ins.objectid);
1381 ret = btrfs_end_transaction(trans, root);
1385 btrfs_free_path(path);
1389 int btrfs_get_block(struct inode *inode, sector_t iblock,
1390 struct buffer_head *result, int create)
1393 struct btrfs_root *root = BTRFS_I(inode)->root;
1394 mutex_lock(&root->fs_info->fs_mutex);
1395 err = btrfs_get_block_lock(inode, iblock, result, create);
1396 mutex_unlock(&root->fs_info->fs_mutex);
1400 static int btrfs_get_block_csum(struct inode *inode, sector_t iblock,
1401 struct buffer_head *result, int create)
1404 struct btrfs_root *root = BTRFS_I(inode)->root;
1405 struct page *page = result->b_page;
1406 u64 offset = (page->index << PAGE_CACHE_SHIFT) + bh_offset(result);
1407 struct btrfs_csum_item *item;
1408 struct btrfs_path *path = NULL;
1410 mutex_lock(&root->fs_info->fs_mutex);
1411 ret = btrfs_get_block_lock(inode, iblock, result, create);
1415 path = btrfs_alloc_path();
1416 item = btrfs_lookup_csum(NULL, root, path, inode->i_ino, offset, 0);
1418 ret = PTR_ERR(item);
1419 /* a csum that isn't present is a preallocated region. */
1420 if (ret == -ENOENT || ret == -EFBIG)
1422 result->b_private = NULL;
1425 memcpy((char *)&result->b_private, &item->csum, BTRFS_CRC32_SIZE);
1428 btrfs_free_path(path);
1429 mutex_unlock(&root->fs_info->fs_mutex);
1433 static int btrfs_get_block_bmap(struct inode *inode, sector_t iblock,
1434 struct buffer_head *result, int create)
1436 struct btrfs_root *root = BTRFS_I(inode)->root;
1437 mutex_lock(&root->fs_info->fs_mutex);
1438 btrfs_get_block_lock(inode, iblock, result, BTRFS_GET_BLOCK_NO_DIRECT);
1439 mutex_unlock(&root->fs_info->fs_mutex);
1443 static sector_t btrfs_bmap(struct address_space *as, sector_t block)
1445 return generic_block_bmap(as, block, btrfs_get_block_bmap);
1448 static int btrfs_prepare_write(struct file *file, struct page *page,
1449 unsigned from, unsigned to)
1451 return block_prepare_write(page, from, to, btrfs_get_block);
1454 static void buffer_io_error(struct buffer_head *bh)
1456 char b[BDEVNAME_SIZE];
1458 printk(KERN_ERR "Buffer I/O error on device %s, logical block %Lu\n",
1459 bdevname(bh->b_bdev, b),
1460 (unsigned long long)bh->b_blocknr);
1464 * I/O completion handler for block_read_full_page() - pages
1465 * which come unlocked at the end of I/O.
1467 static void btrfs_end_buffer_async_read(struct buffer_head *bh, int uptodate)
1469 unsigned long flags;
1470 struct buffer_head *first;
1471 struct buffer_head *tmp;
1473 int page_uptodate = 1;
1474 struct inode *inode;
1477 BUG_ON(!buffer_async_read(bh));
1480 inode = page->mapping->host;
1483 struct btrfs_root *root = BTRFS_I(page->mapping->host)->root;
1484 if (bh->b_private) {
1485 char csum[BTRFS_CRC32_SIZE];
1486 kaddr = kmap_atomic(page, KM_IRQ0);
1487 ret = btrfs_csum_data(root, kaddr + bh_offset(bh),
1490 if (memcmp(csum, &bh->b_private, BTRFS_CRC32_SIZE)) {
1492 offset = (page->index << PAGE_CACHE_SHIFT) +
1494 printk("btrfs csum failed ino %lu off %llu\n",
1495 page->mapping->host->i_ino,
1496 (unsigned long long)offset);
1497 memset(kaddr + bh_offset(bh), 1, bh->b_size);
1498 flush_dcache_page(page);
1500 kunmap_atomic(kaddr, KM_IRQ0);
1502 set_buffer_uptodate(bh);
1504 clear_buffer_uptodate(bh);
1505 if (printk_ratelimit())
1506 buffer_io_error(bh);
1511 * Be _very_ careful from here on. Bad things can happen if
1512 * two buffer heads end IO at almost the same time and both
1513 * decide that the page is now completely done.
1515 first = page_buffers(page);
1516 local_irq_save(flags);
1517 bit_spin_lock(BH_Uptodate_Lock, &first->b_state);
1518 clear_buffer_async_read(bh);
1522 if (!buffer_uptodate(tmp))
1524 if (buffer_async_read(tmp)) {
1525 BUG_ON(!buffer_locked(tmp));
1528 tmp = tmp->b_this_page;
1529 } while (tmp != bh);
1530 bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
1531 local_irq_restore(flags);
1534 * If none of the buffers had errors and they are all
1535 * uptodate then we can set the page uptodate.
1537 if (page_uptodate && !PageError(page))
1538 SetPageUptodate(page);
1543 bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
1544 local_irq_restore(flags);
1549 * Generic "read page" function for block devices that have the normal
1550 * get_block functionality. This is most of the block device filesystems.
1551 * Reads the page asynchronously --- the unlock_buffer() and
1552 * set/clear_buffer_uptodate() functions propagate buffer state into the
1553 * page struct once IO has completed.
1555 int btrfs_readpage(struct file *file, struct page *page)
1557 struct inode *inode = page->mapping->host;
1558 sector_t iblock, lblock;
1559 struct buffer_head *bh, *head, *arr[MAX_BUF_PER_PAGE];
1560 unsigned int blocksize;
1562 int fully_mapped = 1;
1564 BUG_ON(!PageLocked(page));
1565 blocksize = 1 << inode->i_blkbits;
1566 if (!page_has_buffers(page))
1567 create_empty_buffers(page, blocksize, 0);
1568 head = page_buffers(page);
1570 iblock = (sector_t)page->index << (PAGE_CACHE_SHIFT - inode->i_blkbits);
1571 lblock = (i_size_read(inode)+blocksize-1) >> inode->i_blkbits;
1577 if (buffer_uptodate(bh))
1580 if (!buffer_mapped(bh)) {
1584 if (iblock < lblock) {
1585 WARN_ON(bh->b_size != blocksize);
1586 err = btrfs_get_block_csum(inode, iblock,
1591 if (!buffer_mapped(bh)) {
1592 void *kaddr = kmap_atomic(page, KM_USER0);
1593 memset(kaddr + i * blocksize, 0, blocksize);
1594 flush_dcache_page(page);
1595 kunmap_atomic(kaddr, KM_USER0);
1597 set_buffer_uptodate(bh);
1601 * get_block() might have updated the buffer
1604 if (buffer_uptodate(bh))
1608 } while (i++, iblock++, (bh = bh->b_this_page) != head);
1611 SetPageMappedToDisk(page);
1615 * All buffers are uptodate - we can set the page uptodate
1616 * as well. But not if get_block() returned an error.
1618 if (!PageError(page))
1619 SetPageUptodate(page);
1624 /* Stage two: lock the buffers */
1625 for (i = 0; i < nr; i++) {
1628 bh->b_end_io = btrfs_end_buffer_async_read;
1629 set_buffer_async_read(bh);
1633 * Stage 3: start the IO. Check for uptodateness
1634 * inside the buffer lock in case another process reading
1635 * the underlying blockdev brought it uptodate (the sct fix).
1637 for (i = 0; i < nr; i++) {
1639 if (buffer_uptodate(bh))
1640 btrfs_end_buffer_async_read(bh, 1);
1642 submit_bh(READ, bh);
1648 * Aside from a tiny bit of packed file data handling, this is the
1649 * same as the generic code.
1651 * While block_write_full_page is writing back the dirty buffers under
1652 * the page lock, whoever dirtied the buffers may decide to clean them
1653 * again at any time. We handle that by only looking at the buffer
1654 * state inside lock_buffer().
1656 * If block_write_full_page() is called for regular writeback
1657 * (wbc->sync_mode == WB_SYNC_NONE) then it will redirty a page which has a
1658 * locked buffer. This only can happen if someone has written the buffer
1659 * directly, with submit_bh(). At the address_space level PageWriteback
1660 * prevents this contention from occurring.
1662 static int __btrfs_write_full_page(struct inode *inode, struct page *page,
1663 struct writeback_control *wbc)
1667 sector_t last_block;
1668 struct buffer_head *bh, *head;
1669 const unsigned blocksize = 1 << inode->i_blkbits;
1670 int nr_underway = 0;
1671 struct btrfs_root *root = BTRFS_I(inode)->root;
1673 BUG_ON(!PageLocked(page));
1675 last_block = (i_size_read(inode) - 1) >> inode->i_blkbits;
1677 /* no csumming allowed when from PF_MEMALLOC */
1678 if (current->flags & PF_MEMALLOC) {
1679 redirty_page_for_writepage(wbc, page);
1684 if (!page_has_buffers(page)) {
1685 create_empty_buffers(page, blocksize,
1686 (1 << BH_Dirty)|(1 << BH_Uptodate));
1690 * Be very careful. We have no exclusion from __set_page_dirty_buffers
1691 * here, and the (potentially unmapped) buffers may become dirty at
1692 * any time. If a buffer becomes dirty here after we've inspected it
1693 * then we just miss that fact, and the page stays dirty.
1695 * Buffers outside i_size may be dirtied by __set_page_dirty_buffers;
1696 * handle that here by just cleaning them.
1699 block = (sector_t)page->index << (PAGE_CACHE_SHIFT - inode->i_blkbits);
1700 head = page_buffers(page);
1704 * Get all the dirty buffers mapped to disk addresses and
1705 * handle any aliases from the underlying blockdev's mapping.
1708 if (block > last_block) {
1710 * mapped buffers outside i_size will occur, because
1711 * this page can be outside i_size when there is a
1712 * truncate in progress.
1715 * The buffer was zeroed by block_write_full_page()
1717 clear_buffer_dirty(bh);
1718 set_buffer_uptodate(bh);
1719 } else if (!buffer_mapped(bh) && buffer_dirty(bh)) {
1720 WARN_ON(bh->b_size != blocksize);
1721 err = btrfs_get_block(inode, block, bh, 0);
1725 if (buffer_new(bh)) {
1726 /* blockdev mappings never come here */
1727 clear_buffer_new(bh);
1730 bh = bh->b_this_page;
1732 } while (bh != head);
1735 if (!buffer_mapped(bh))
1738 * If it's a fully non-blocking write attempt and we cannot
1739 * lock the buffer then redirty the page. Note that this can
1740 * potentially cause a busy-wait loop from pdflush and kswapd
1741 * activity, but those code paths have their own higher-level
1744 if (wbc->sync_mode != WB_SYNC_NONE || !wbc->nonblocking) {
1746 } else if (test_set_buffer_locked(bh)) {
1747 redirty_page_for_writepage(wbc, page);
1750 if (test_clear_buffer_dirty(bh) && bh->b_blocknr != 0) {
1751 struct btrfs_trans_handle *trans;
1753 u64 off = page->index << PAGE_CACHE_SHIFT;
1756 off += bh_offset(bh);
1757 mutex_lock(&root->fs_info->fs_mutex);
1758 trans = btrfs_start_transaction(root, 1);
1759 btrfs_set_trans_block_group(trans, inode);
1761 btrfs_csum_file_block(trans, root, inode->i_ino,
1762 off, kaddr + bh_offset(bh),
1765 ret = btrfs_end_transaction(trans, root);
1767 mutex_unlock(&root->fs_info->fs_mutex);
1768 mark_buffer_async_write(bh);
1772 } while ((bh = bh->b_this_page) != head);
1775 * The page and its buffers are protected by PageWriteback(), so we can
1776 * drop the bh refcounts early.
1778 BUG_ON(PageWriteback(page));
1779 set_page_writeback(page);
1782 struct buffer_head *next = bh->b_this_page;
1783 if (buffer_async_write(bh)) {
1784 submit_bh(WRITE, bh);
1788 } while (bh != head);
1793 if (nr_underway == 0) {
1795 * The page was marked dirty, but the buffers were
1796 * clean. Someone wrote them back by hand with
1797 * ll_rw_block/submit_bh. A rare case.
1801 if (!buffer_uptodate(bh)) {
1805 bh = bh->b_this_page;
1806 } while (bh != head);
1808 SetPageUptodate(page);
1809 end_page_writeback(page);
1815 * ENOSPC, or some other error. We may already have added some
1816 * blocks to the file, so we need to write these out to avoid
1817 * exposing stale data.
1818 * The page is currently locked and not marked for writeback
1821 /* Recovery: lock and submit the mapped buffers */
1823 if (buffer_mapped(bh) && buffer_dirty(bh)) {
1825 mark_buffer_async_write(bh);
1828 * The buffer may have been set dirty during
1829 * attachment to a dirty page.
1831 clear_buffer_dirty(bh);
1833 } while ((bh = bh->b_this_page) != head);
1835 BUG_ON(PageWriteback(page));
1836 set_page_writeback(page);
1838 struct buffer_head *next = bh->b_this_page;
1839 if (buffer_async_write(bh)) {
1840 clear_buffer_dirty(bh);
1841 submit_bh(WRITE, bh);
1845 } while (bh != head);
1850 static int btrfs_writepage(struct page *page, struct writeback_control *wbc)
1852 struct inode * const inode = page->mapping->host;
1853 loff_t i_size = i_size_read(inode);
1854 const pgoff_t end_index = i_size >> PAGE_CACHE_SHIFT;
1858 /* Is the page fully inside i_size? */
1859 if (page->index < end_index)
1860 return __btrfs_write_full_page(inode, page, wbc);
1862 /* Is the page fully outside i_size? (truncate in progress) */
1863 offset = i_size & (PAGE_CACHE_SIZE-1);
1864 if (page->index >= end_index+1 || !offset) {
1866 * The page may have dirty, unmapped buffers. For example,
1867 * they may have been added in ext3_writepage(). Make them
1868 * freeable here, so the page does not leak.
1870 block_invalidatepage(page, 0);
1872 return 0; /* don't care */
1876 * The page straddles i_size. It must be zeroed out on each and every
1877 * writepage invokation because it may be mmapped. "A file is mapped
1878 * in multiples of the page size. For a file that is not a multiple of
1879 * the page size, the remaining memory is zeroed when mapped, and
1880 * writes to that region are not written out to the file."
1882 kaddr = kmap_atomic(page, KM_USER0);
1883 memset(kaddr + offset, 0, PAGE_CACHE_SIZE - offset);
1884 flush_dcache_page(page);
1885 kunmap_atomic(kaddr, KM_USER0);
1886 return __btrfs_write_full_page(inode, page, wbc);
1890 * btrfs_page_mkwrite() is not allowed to change the file size as it gets
1891 * called from a page fault handler when a page is first dirtied. Hence we must
1892 * be careful to check for EOF conditions here. We set the page up correctly
1893 * for a written page which means we get ENOSPC checking when writing into
1894 * holes and correct delalloc and unwritten extent mapping on filesystems that
1895 * support these features.
1897 * We are not allowed to take the i_mutex here so we have to play games to
1898 * protect against truncate races as the page could now be beyond EOF. Because
1899 * vmtruncate() writes the inode size before removing pages, once we have the
1900 * page lock we can determine safely if the page is beyond EOF. If it is not
1901 * beyond EOF, then the page is guaranteed safe against truncation until we
1904 int btrfs_page_mkwrite(struct vm_area_struct *vma, struct page *page)
1906 struct inode *inode = vma->vm_file->f_path.dentry->d_inode;
1912 wait_on_page_writeback(page);
1913 size = i_size_read(inode);
1914 if ((page->mapping != inode->i_mapping) ||
1915 ((page->index << PAGE_CACHE_SHIFT) > size)) {
1916 /* page got truncated out from underneath us */
1920 /* page is wholly or partially inside EOF */
1921 if (((page->index + 1) << PAGE_CACHE_SHIFT) > size)
1922 end = size & ~PAGE_CACHE_MASK;
1924 end = PAGE_CACHE_SIZE;
1926 ret = btrfs_prepare_write(NULL, page, 0, end);
1928 ret = btrfs_commit_write(NULL, page, 0, end);
1935 static void btrfs_truncate(struct inode *inode)
1937 struct btrfs_root *root = BTRFS_I(inode)->root;
1939 struct btrfs_trans_handle *trans;
1941 if (!S_ISREG(inode->i_mode))
1943 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
1946 btrfs_truncate_page(inode->i_mapping, inode->i_size);
1948 mutex_lock(&root->fs_info->fs_mutex);
1949 trans = btrfs_start_transaction(root, 1);
1950 btrfs_set_trans_block_group(trans, inode);
1952 /* FIXME, add redo link to tree so we don't leak on crash */
1953 ret = btrfs_truncate_in_trans(trans, root, inode);
1954 btrfs_update_inode(trans, root, inode);
1955 ret = btrfs_end_transaction(trans, root);
1957 mutex_unlock(&root->fs_info->fs_mutex);
1958 btrfs_btree_balance_dirty(root);
1961 int btrfs_commit_write(struct file *file, struct page *page,
1962 unsigned from, unsigned to)
1964 struct inode *inode = page->mapping->host;
1965 struct buffer_head *bh;
1966 loff_t pos = ((loff_t)page->index << PAGE_CACHE_SHIFT) + to;
1968 SetPageUptodate(page);
1969 bh = page_buffers(page);
1970 set_buffer_uptodate(bh);
1971 if (buffer_mapped(bh) && bh->b_blocknr != 0) {
1972 set_page_dirty(page);
1974 if (pos > inode->i_size) {
1975 i_size_write(inode, pos);
1976 mark_inode_dirty(inode);
1981 static int create_subvol(struct btrfs_root *root, char *name, int namelen)
1983 struct btrfs_trans_handle *trans;
1984 struct btrfs_key key;
1985 struct btrfs_root_item root_item;
1986 struct btrfs_inode_item *inode_item;
1987 struct buffer_head *subvol;
1988 struct btrfs_leaf *leaf;
1989 struct btrfs_root *new_root;
1990 struct inode *inode;
1995 u64 new_dirid = BTRFS_FIRST_FREE_OBJECTID;
1997 mutex_lock(&root->fs_info->fs_mutex);
1998 trans = btrfs_start_transaction(root, 1);
2001 subvol = btrfs_alloc_free_block(trans, root, 0, 0);
2003 return PTR_ERR(subvol);
2004 leaf = btrfs_buffer_leaf(subvol);
2005 btrfs_set_header_nritems(&leaf->header, 0);
2006 btrfs_set_header_level(&leaf->header, 0);
2007 btrfs_set_header_blocknr(&leaf->header, bh_blocknr(subvol));
2008 btrfs_set_header_generation(&leaf->header, trans->transid);
2009 btrfs_set_header_owner(&leaf->header, root->root_key.objectid);
2010 memcpy(leaf->header.fsid, root->fs_info->disk_super->fsid,
2011 sizeof(leaf->header.fsid));
2012 btrfs_mark_buffer_dirty(subvol);
2014 inode_item = &root_item.inode;
2015 memset(inode_item, 0, sizeof(*inode_item));
2016 btrfs_set_inode_generation(inode_item, 1);
2017 btrfs_set_inode_size(inode_item, 3);
2018 btrfs_set_inode_nlink(inode_item, 1);
2019 btrfs_set_inode_nblocks(inode_item, 1);
2020 btrfs_set_inode_mode(inode_item, S_IFDIR | 0755);
2022 btrfs_set_root_blocknr(&root_item, bh_blocknr(subvol));
2023 btrfs_set_root_refs(&root_item, 1);
2024 memset(&root_item.drop_progress, 0, sizeof(root_item.drop_progress));
2025 root_item.drop_level = 0;
2029 ret = btrfs_find_free_objectid(trans, root->fs_info->tree_root,
2034 btrfs_set_root_dirid(&root_item, new_dirid);
2036 key.objectid = objectid;
2039 btrfs_set_key_type(&key, BTRFS_ROOT_ITEM_KEY);
2040 ret = btrfs_insert_root(trans, root->fs_info->tree_root, &key,
2046 * insert the directory item
2048 key.offset = (u64)-1;
2049 dir = root->fs_info->sb->s_root->d_inode;
2050 ret = btrfs_insert_dir_item(trans, root->fs_info->tree_root,
2051 name, namelen, dir->i_ino, &key,
2056 ret = btrfs_commit_transaction(trans, root);
2060 new_root = btrfs_read_fs_root(root->fs_info, &key);
2063 trans = btrfs_start_transaction(new_root, 1);
2066 inode = btrfs_new_inode(trans, new_root, new_dirid,
2067 BTRFS_I(dir)->block_group, S_IFDIR | 0700);
2070 inode->i_op = &btrfs_dir_inode_operations;
2071 inode->i_fop = &btrfs_dir_file_operations;
2072 new_root->inode = inode;
2074 ret = btrfs_make_empty_dir(trans, new_root, new_dirid, new_dirid);
2080 ret = btrfs_update_inode(trans, new_root, inode);
2084 err = btrfs_commit_transaction(trans, root);
2088 mutex_unlock(&root->fs_info->fs_mutex);
2089 btrfs_btree_balance_dirty(root);
2093 static int create_snapshot(struct btrfs_root *root, char *name, int namelen)
2095 struct btrfs_trans_handle *trans;
2096 struct btrfs_key key;
2097 struct btrfs_root_item new_root_item;
2102 if (!root->ref_cows)
2105 mutex_lock(&root->fs_info->fs_mutex);
2106 trans = btrfs_start_transaction(root, 1);
2109 ret = btrfs_update_inode(trans, root, root->inode);
2113 ret = btrfs_find_free_objectid(trans, root->fs_info->tree_root,
2118 memcpy(&new_root_item, &root->root_item,
2119 sizeof(new_root_item));
2121 key.objectid = objectid;
2124 btrfs_set_key_type(&key, BTRFS_ROOT_ITEM_KEY);
2125 btrfs_set_root_blocknr(&new_root_item, bh_blocknr(root->node));
2127 ret = btrfs_insert_root(trans, root->fs_info->tree_root, &key,
2133 * insert the directory item
2135 key.offset = (u64)-1;
2136 ret = btrfs_insert_dir_item(trans, root->fs_info->tree_root,
2138 root->fs_info->sb->s_root->d_inode->i_ino,
2139 &key, BTRFS_FT_DIR);
2144 ret = btrfs_inc_root_ref(trans, root);
2149 err = btrfs_commit_transaction(trans, root);
2152 mutex_unlock(&root->fs_info->fs_mutex);
2153 btrfs_btree_balance_dirty(root);
2157 int btrfs_ioctl(struct inode *inode, struct file *filp, unsigned int
2158 cmd, unsigned long arg)
2160 struct btrfs_root *root = BTRFS_I(inode)->root;
2161 struct btrfs_ioctl_vol_args vol_args;
2163 struct btrfs_dir_item *di;
2165 struct btrfs_path *path;
2169 case BTRFS_IOC_SNAP_CREATE:
2170 if (copy_from_user(&vol_args,
2171 (struct btrfs_ioctl_vol_args __user *)arg,
2174 namelen = strlen(vol_args.name);
2175 if (namelen > BTRFS_VOL_NAME_MAX)
2177 if (strchr(vol_args.name, '/'))
2179 path = btrfs_alloc_path();
2182 root_dirid = root->fs_info->sb->s_root->d_inode->i_ino,
2183 mutex_lock(&root->fs_info->fs_mutex);
2184 di = btrfs_lookup_dir_item(NULL, root->fs_info->tree_root,
2186 vol_args.name, namelen, 0);
2187 mutex_unlock(&root->fs_info->fs_mutex);
2188 btrfs_free_path(path);
2189 if (di && !IS_ERR(di))
2194 if (root == root->fs_info->tree_root)
2195 ret = create_subvol(root, vol_args.name, namelen);
2197 ret = create_snapshot(root, vol_args.name, namelen);
2200 case BTRFS_IOC_DEFRAG:
2201 mutex_lock(&root->fs_info->fs_mutex);
2202 btrfs_defrag_root(root, 0);
2203 btrfs_defrag_root(root->fs_info->extent_root, 0);
2204 mutex_unlock(&root->fs_info->fs_mutex);
2213 #ifdef CONFIG_COMPAT
2214 long btrfs_compat_ioctl(struct file *file, unsigned int cmd,
2217 struct inode *inode = file->f_path.dentry->d_inode;
2220 ret = btrfs_ioctl(inode, file, cmd, (unsigned long) compat_ptr(arg));
2228 * Called inside transaction, so use GFP_NOFS
2230 struct inode *btrfs_alloc_inode(struct super_block *sb)
2232 struct btrfs_inode *ei;
2234 ei = kmem_cache_alloc(btrfs_inode_cachep, GFP_NOFS);
2237 return &ei->vfs_inode;
2240 void btrfs_destroy_inode(struct inode *inode)
2242 WARN_ON(!list_empty(&inode->i_dentry));
2243 WARN_ON(inode->i_data.nrpages);
2245 kmem_cache_free(btrfs_inode_cachep, BTRFS_I(inode));
2248 static void init_once(void * foo, struct kmem_cache * cachep,
2249 unsigned long flags)
2251 struct btrfs_inode *ei = (struct btrfs_inode *) foo;
2253 inode_init_once(&ei->vfs_inode);
2256 void btrfs_destroy_cachep(void)
2258 if (btrfs_inode_cachep)
2259 kmem_cache_destroy(btrfs_inode_cachep);
2260 if (btrfs_trans_handle_cachep)
2261 kmem_cache_destroy(btrfs_trans_handle_cachep);
2262 if (btrfs_transaction_cachep)
2263 kmem_cache_destroy(btrfs_transaction_cachep);
2264 if (btrfs_bit_radix_cachep)
2265 kmem_cache_destroy(btrfs_bit_radix_cachep);
2266 if (btrfs_path_cachep)
2267 kmem_cache_destroy(btrfs_path_cachep);
2270 static struct kmem_cache *cache_create(const char *name, size_t size,
2271 unsigned long extra_flags,
2272 void (*ctor)(void *, struct kmem_cache *,
2275 return kmem_cache_create(name, size, 0, (SLAB_RECLAIM_ACCOUNT |
2276 SLAB_MEM_SPREAD | extra_flags), ctor
2277 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
2283 int btrfs_init_cachep(void)
2285 btrfs_inode_cachep = cache_create("btrfs_inode_cache",
2286 sizeof(struct btrfs_inode),
2288 if (!btrfs_inode_cachep)
2290 btrfs_trans_handle_cachep = cache_create("btrfs_trans_handle_cache",
2291 sizeof(struct btrfs_trans_handle),
2293 if (!btrfs_trans_handle_cachep)
2295 btrfs_transaction_cachep = cache_create("btrfs_transaction_cache",
2296 sizeof(struct btrfs_transaction),
2298 if (!btrfs_transaction_cachep)
2300 btrfs_path_cachep = cache_create("btrfs_path_cache",
2301 sizeof(struct btrfs_transaction),
2303 if (!btrfs_path_cachep)
2305 btrfs_bit_radix_cachep = cache_create("btrfs_radix", 256,
2306 SLAB_DESTROY_BY_RCU, NULL);
2307 if (!btrfs_bit_radix_cachep)
2311 btrfs_destroy_cachep();
2315 static int btrfs_getattr(struct vfsmount *mnt,
2316 struct dentry *dentry, struct kstat *stat)
2318 struct inode *inode = dentry->d_inode;
2319 generic_fillattr(inode, stat);
2320 stat->blksize = 256 * 1024;
2324 static int btrfs_rename(struct inode * old_dir, struct dentry *old_dentry,
2325 struct inode * new_dir,struct dentry *new_dentry)
2327 struct btrfs_trans_handle *trans;
2328 struct btrfs_root *root = BTRFS_I(old_dir)->root;
2329 struct inode *new_inode = new_dentry->d_inode;
2330 struct inode *old_inode = old_dentry->d_inode;
2331 struct timespec ctime = CURRENT_TIME;
2332 struct btrfs_path *path;
2333 struct btrfs_dir_item *di;
2336 if (S_ISDIR(old_inode->i_mode) && new_inode &&
2337 new_inode->i_size > BTRFS_EMPTY_DIR_SIZE) {
2340 mutex_lock(&root->fs_info->fs_mutex);
2341 trans = btrfs_start_transaction(root, 1);
2342 btrfs_set_trans_block_group(trans, new_dir);
2343 path = btrfs_alloc_path();
2349 old_dentry->d_inode->i_nlink++;
2350 old_dir->i_ctime = old_dir->i_mtime = ctime;
2351 new_dir->i_ctime = new_dir->i_mtime = ctime;
2352 old_inode->i_ctime = ctime;
2353 if (S_ISDIR(old_inode->i_mode) && old_dir != new_dir) {
2354 struct btrfs_key *location = &BTRFS_I(new_dir)->location;
2356 di = btrfs_lookup_dir_item(trans, root, path, old_inode->i_ino,
2366 old_parent_oid = btrfs_disk_key_objectid(&di->location);
2367 ret = btrfs_del_item(trans, root, path);
2371 btrfs_release_path(root, path);
2373 di = btrfs_lookup_dir_index_item(trans, root, path,
2385 ret = btrfs_del_item(trans, root, path);
2389 btrfs_release_path(root, path);
2391 ret = btrfs_insert_dir_item(trans, root, "..", 2,
2392 old_inode->i_ino, location,
2399 ret = btrfs_unlink_trans(trans, root, old_dir, old_dentry);
2404 new_inode->i_ctime = CURRENT_TIME;
2405 ret = btrfs_unlink_trans(trans, root, new_dir, new_dentry);
2408 if (S_ISDIR(new_inode->i_mode))
2409 clear_nlink(new_inode);
2411 drop_nlink(new_inode);
2412 ret = btrfs_update_inode(trans, root, new_inode);
2416 ret = btrfs_add_link(trans, new_dentry, old_inode);
2421 btrfs_free_path(path);
2422 btrfs_end_transaction(trans, root);
2423 mutex_unlock(&root->fs_info->fs_mutex);
2427 static int btrfs_symlink(struct inode *dir, struct dentry *dentry,
2428 const char *symname)
2430 struct btrfs_trans_handle *trans;
2431 struct btrfs_root *root = BTRFS_I(dir)->root;
2432 struct btrfs_path *path;
2433 struct btrfs_key key;
2434 struct inode *inode;
2441 struct btrfs_file_extent_item *ei;
2443 name_len = strlen(symname) + 1;
2444 if (name_len > BTRFS_MAX_INLINE_DATA_SIZE(root))
2445 return -ENAMETOOLONG;
2446 mutex_lock(&root->fs_info->fs_mutex);
2447 trans = btrfs_start_transaction(root, 1);
2448 btrfs_set_trans_block_group(trans, dir);
2450 err = btrfs_find_free_objectid(trans, root, dir->i_ino, &objectid);
2456 inode = btrfs_new_inode(trans, root, objectid,
2457 BTRFS_I(dir)->block_group, S_IFLNK|S_IRWXUGO);
2458 err = PTR_ERR(inode);
2462 btrfs_set_trans_block_group(trans, inode);
2463 err = btrfs_add_nondir(trans, dentry, inode);
2467 inode->i_mapping->a_ops = &btrfs_aops;
2468 inode->i_fop = &btrfs_file_operations;
2469 inode->i_op = &btrfs_file_inode_operations;
2471 dir->i_sb->s_dirt = 1;
2472 btrfs_update_inode_block_group(trans, inode);
2473 btrfs_update_inode_block_group(trans, dir);
2477 path = btrfs_alloc_path();
2479 key.objectid = inode->i_ino;
2482 btrfs_set_key_type(&key, BTRFS_EXTENT_DATA_KEY);
2483 datasize = btrfs_file_extent_calc_inline_size(name_len);
2484 err = btrfs_insert_empty_item(trans, root, path, &key,
2490 ei = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]),
2491 path->slots[0], struct btrfs_file_extent_item);
2492 btrfs_set_file_extent_generation(ei, trans->transid);
2493 btrfs_set_file_extent_type(ei,
2494 BTRFS_FILE_EXTENT_INLINE);
2495 ptr = btrfs_file_extent_inline_start(ei);
2496 btrfs_memcpy(root, path->nodes[0]->b_data,
2497 ptr, symname, name_len);
2498 btrfs_mark_buffer_dirty(path->nodes[0]);
2499 btrfs_free_path(path);
2500 inode->i_op = &btrfs_symlink_inode_operations;
2501 inode->i_mapping->a_ops = &btrfs_symlink_aops;
2502 inode->i_size = name_len - 1;
2503 err = btrfs_update_inode(trans, root, inode);
2508 btrfs_end_transaction(trans, root);
2509 mutex_unlock(&root->fs_info->fs_mutex);
2511 inode_dec_link_count(inode);
2514 btrfs_btree_balance_dirty(root);
2518 static struct inode_operations btrfs_dir_inode_operations = {
2519 .lookup = btrfs_lookup,
2520 .create = btrfs_create,
2521 .unlink = btrfs_unlink,
2523 .mkdir = btrfs_mkdir,
2524 .rmdir = btrfs_rmdir,
2525 .rename = btrfs_rename,
2526 .symlink = btrfs_symlink,
2527 .setattr = btrfs_setattr,
2528 .mknod = btrfs_mknod,
2531 static struct inode_operations btrfs_dir_ro_inode_operations = {
2532 .lookup = btrfs_lookup,
2535 static struct file_operations btrfs_dir_file_operations = {
2536 .llseek = generic_file_llseek,
2537 .read = generic_read_dir,
2538 .readdir = btrfs_readdir,
2539 .ioctl = btrfs_ioctl,
2540 #ifdef CONFIG_COMPAT
2541 .compat_ioctl = btrfs_compat_ioctl,
2545 static struct address_space_operations btrfs_aops = {
2546 .readpage = btrfs_readpage,
2547 .writepage = btrfs_writepage,
2548 .sync_page = block_sync_page,
2549 .prepare_write = btrfs_prepare_write,
2550 .commit_write = btrfs_commit_write,
2554 static struct address_space_operations btrfs_symlink_aops = {
2555 .readpage = btrfs_readpage,
2556 .writepage = btrfs_writepage,
2559 static struct inode_operations btrfs_file_inode_operations = {
2560 .truncate = btrfs_truncate,
2561 .getattr = btrfs_getattr,
2562 .setattr = btrfs_setattr,
2565 static struct inode_operations btrfs_special_inode_operations = {
2566 .getattr = btrfs_getattr,
2567 .setattr = btrfs_setattr,
2570 static struct inode_operations btrfs_symlink_inode_operations = {
2571 .readlink = generic_readlink,
2572 .follow_link = page_follow_link_light,
2573 .put_link = page_put_link,