Skip to contentSkip to conversation

add snapshot/subvolume destroy ioctl

PATCH In review Yan, Zheng 3 participants 4 messages Sep 18, 2009 – Sep 25, 2009 1 message not in the archive Btrfs file system

lore
Share & tools
lore

Yan, Zheng

author
#0 lore raw

PATCH 4/4 add snapshot/subvolume destroy ioctl

This patch adds snapshot/subvolume destroy ioctl. Subvolume that isn't being used and doesn't contains links to other subvolumes can be destroyed.

---

fs/btrfs/ctree.h +11 -5
diff -urp 4/fs/btrfs/ctree.h 5/fs/btrfs/ctree.h
@@ -828,11 +828,7 @@ struct btrfs_fs_info {
 	struct mutex transaction_kthread_mutex;
 	struct mutex cleaner_mutex;
 	struct mutex chunk_mutex;
-	struct mutex drop_mutex;
 	struct mutex volume_mutex;
-	struct mutex tree_reloc_mutex;
-	struct rw_semaphore extent_commit_sem;
-
 	/*
 	 * this protects the ordered operations list only while we are
 	 * processing all of the entries on it.  This way we make
@@ -842,6 +838,12 @@ struct btrfs_fs_info {
 	 */
 	struct mutex ordered_operations_mutex;
 
+	struct rw_semaphore extent_commit_sem;
+
+	struct rw_semaphore subvol_sem;
+
+	struct srcu_struct subvol_srcu;
+
 	struct list_head trans_list;
 	struct list_head hashers;
 	struct list_head dead_roots;
@@ -2131,6 +2133,7 @@ int btrfs_find_last_root(struct btrfs_ro
 int btrfs_search_root(struct btrfs_root *root, u64 search_start,
 		      u64 *found_objectid);
 int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid);
+int btrfs_find_orphan_roots(struct btrfs_root *tree_root);
 int btrfs_set_root_node(struct btrfs_root_item *item,
 			struct extent_buffer *node);
 /* dir-item.c */
@@ -2262,7 +2265,7 @@ int btrfs_set_extent_delalloc(struct ino
 int btrfs_writepages(struct address_space *mapping,
 		     struct writeback_control *wbc);
 int btrfs_create_subvol_root(struct btrfs_trans_handle *trans,
-			     struct btrfs_root *new_root, struct dentry *dentry,
+			     struct btrfs_root *new_root,
 			     u64 new_dirid, u64 alloc_hint);
 int btrfs_merge_bio_hook(struct page *page, unsigned long offset,
 			 size_t size, struct bio *bio, unsigned long bio_flags);
@@ -2278,6 +2281,7 @@ int btrfs_write_inode(struct inode *inod
 void btrfs_dirty_inode(struct inode *inode);
 struct inode *btrfs_alloc_inode(struct super_block *sb);
 void btrfs_destroy_inode(struct inode *inode);
+void btrfs_drop_inode(struct inode *inode);
 int btrfs_init_cachep(void);
 void btrfs_destroy_cachep(void);
 long btrfs_ioctl_trans_end(struct file *file);
@@ -2295,6 +2299,8 @@ int btrfs_orphan_add(struct btrfs_trans_
 int btrfs_orphan_del(struct btrfs_trans_handle *trans, struct inode *inode);
 void btrfs_orphan_cleanup(struct btrfs_root *root);
 int btrfs_cont_expand(struct inode *inode, loff_t size);
+int btrfs_invalidate_inodes(struct btrfs_root *root);
+extern struct dentry_operations btrfs_dentry_operations;
 
 /* ioctl.c */
 long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
fs/btrfs/disk-io.c +62 -19

175 lines not on this page · raw message

fs/btrfs/export.c +85 -48

199 lines not on this page · raw message

fs/btrfs/extent-tree.c +18 -3
diff -urp 4/fs/btrfs/extent-tree.c 5/fs/btrfs/extent-tree.c
@@ -5356,9 +5356,24 @@ int btrfs_drop_snapshot(struct btrfs_roo
 	ret = btrfs_del_root(trans, tree_root, &root->root_key);
 	BUG_ON(ret);
 
-	free_extent_buffer(root->node);
-	free_extent_buffer(root->commit_root);
-	kfree(root);
+	if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID) {
+		ret = btrfs_find_last_root(tree_root, root->root_key.objectid,
+					   NULL, NULL);
+		BUG_ON(ret < 0);
+		if (ret > 0) {
+			ret = btrfs_del_orphan_item(trans, tree_root,
+						    root->root_key.objectid);
+			BUG_ON(ret);
+		}
+	}
+
+	if (root->in_radix) {
+		btrfs_free_fs_root(tree_root->fs_info, root);
+	} else {
+		free_extent_buffer(root->node);
+		free_extent_buffer(root->commit_root);
+		kfree(root);
+	}
 out:
 	btrfs_end_transaction(trans, tree_root);
 	kfree(wc);
fs/btrfs/inode.c +127 -7

229 lines not on this page · raw message

fs/btrfs/ioctl.c +184 -136

433 lines not on this page · raw message

fs/btrfs/ioctl.h +2 -1
diff -urp 4/fs/btrfs/ioctl.h 5/fs/btrfs/ioctl.h
@@ -65,5 +65,6 @@ struct btrfs_ioctl_clone_range_args {
 
 #define BTRFS_IOC_SUBVOL_CREATE _IOW(BTRFS_IOCTL_MAGIC, 14, \
 				   struct btrfs_ioctl_vol_args)
-
+#define BTRFS_IOC_SNAP_DESTROY _IOW(BTRFS_IOCTL_MAGIC, 15, \
+				struct btrfs_ioctl_vol_args)
 #endif
fs/btrfs/relocation.c +35 -6

75 lines not on this page · raw message

fs/btrfs/root-tree.c +64 -5

87 lines not on this page · raw message

fs/btrfs/super.c +1 -0
diff -urp 4/fs/btrfs/super.c 5/fs/btrfs/super.c
@@ -676,6 +676,7 @@ static int btrfs_unfreeze(struct super_b
 }
 
 static struct super_operations btrfs_super_ops = {
+	.drop_inode 	= btrfs_drop_inode,
 	.delete_inode	= btrfs_delete_inode,
 	.put_super	= btrfs_put_super,
 	.sync_fs	= btrfs_sync_fs,
fs/btrfs/transaction.c +7 -3
diff -urp 4/fs/btrfs/transaction.c 5/fs/btrfs/transaction.c
@@ -104,7 +104,6 @@ static noinline int record_root_in_trans
 {
 	if (root->ref_cows && root->last_trans < trans->transid) {
 		WARN_ON(root == root->fs_info->extent_root);
-		WARN_ON(root->root_item.refs == 0);
 		WARN_ON(root->commit_root != root->node);
 
 		radix_tree_tag_set(&root->fs_info->fs_roots_radix,
@@ -1087,8 +1086,13 @@ int btrfs_clean_old_snapshots(struct btr
 
 	while (!list_empty(&list)) {
 		root = list_entry(list.next, struct btrfs_root, root_list);
-		list_del_init(&root->root_list);
-		btrfs_drop_snapshot(root, 0);
+		list_del(&root->root_list);
+
+		if (btrfs_header_backref_rev(root->node) <
+		    BTRFS_MIXED_BACKREF_REV)
+			btrfs_drop_snapshot(root, 0);
+		else
+			btrfs_drop_snapshot(root, 1);
 	}
 	return 0;
 }
fs/btrfs/tree-log.c +11 -2
diff -urp 4/fs/btrfs/tree-log.c 5/fs/btrfs/tree-log.c
@@ -2841,7 +2841,7 @@ static noinline int check_parent_dirs_fo
 		if (!parent || !parent->d_inode || sb != parent->d_inode->i_sb)
 			break;
 
-		if (parent == sb->s_root)
+		if (IS_ROOT(parent))
 			break;
 
 		parent = parent->d_parent;
@@ -2880,6 +2880,12 @@ int btrfs_log_inode_parent(struct btrfs_
 		goto end_no_trans;
 	}
 
+	if (root != BTRFS_I(inode)->root ||
+	    btrfs_root_refs(&root->root_item) == 0) {
+		ret = 1;
+		goto end_no_trans;
+	}
+
 	ret = check_parent_dirs_for_sync(trans, inode, parent,
 					 sb, last_committed);
 	if (ret)
@@ -2907,12 +2913,15 @@ int btrfs_log_inode_parent(struct btrfs_
 			break;
 
 		inode = parent->d_inode;
+		if (root != BTRFS_I(inode)->root)
+			break;
+
 		if (BTRFS_I(inode)->generation >
 		    root->fs_info->last_trans_committed) {
 			ret = btrfs_log_inode(trans, root, inode, inode_only);
 			BUG_ON(ret);
 		}
-		if (parent == sb->s_root)
+		if (IS_ROOT(parent))
 			break;
 
 		parent = parent->d_parent;
#2 lore raw
In reply to a message not in the archive
Quoted 8 lines · john

After a git bisect, I think this patch may introduce a performance regression(about 15% slower) in postmark benchmark. Sometimes(last a few seconds) in the test, CPU usage is 100% wait but NO IO is performing, it's not IO-wait. This didn't happen for earlier versions. test*environment:
hard disk: INTEL X25-E SSD 64G
mkfs options: mkfs.btrfs -m single /dev/xxx
mount options: -o ssd,nodatasum,nodatacow

Thanks, I'll give this a shot here.

-chris

#3 lore raw
Quoted 11 lines · Chris Mason
Quoted 8 lines · john

After a git bisect, I think this patch may introduce a performance regression(about 15% slower) in postmark benchmark. Sometimes(last a few seconds) in the test, CPU usage is 100% wait but NO IO is performing, it's not IO-wait. This didn't happen for earlier versions. test*environment:
hard disk: INTEL X25-E SSD 64G
mkfs options: mkfs.btrfs -m single /dev/xxx
mount options: -o ssd,nodatasum,nodatacow

Thanks, I'll give this a shot here.

Looks like Yan Zheng already tracked it down. I've pushed his fix out to the master branch.

Thanks,
Chris

#4 lore raw

My test result confirms that it has been fixed. Thanks for your time.

2009/9/24 Chris Mason <[email protected]>:

Quoted 3 lines · Chris Mason
Quoted 2 lines · john
Quoted 1 line

=A0 =A0After a git bisect, I think this patch may introduce a perf=

ormance

Quoted 1 line
Quoted 1 line
Quoted 1 line

=A0 =A0regression(about 15% slower) in postmark benchmark. Sometim=

es(last a few

Quoted 1 line
Quoted 1 line
Quoted 1 line

=A0 =A0seconds) in the test, CPU usage is 100% wait but NO IO is p=

erforming, it's

Quoted 9 lines
Quoted 7 lines
Quoted 5 lines

=A0 =A0not IO-wait. This didn't happen for earlier versions. =A0 =A0test*environment:
=A0 =A0hard disk: INTEL X25-E SSD 64G
=A0 =A0mkfs options: mkfs.btrfs -m single /dev/xxx =A0 =A0mount options: -o ssd,nodatasum,nodatacow

Thanks, I'll give this a shot here.

Looks like Yan Zheng already tracked it down. =A0I've pushed his fix =

out

Quoted 6 lines

to the master branch.

Thanks,
Chris

--=20
Zhang Jingwang
National Research Centre for High Performance Computers Institute of Computing Technology, Chinese Academy of Sciences No. 6, South Kexueyuan Road, Haidian District
Beijing, China
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" = in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html