linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Li Dongyang <lidongyang@novell.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH v2] Btrfs: add discard flag to btrfs_device
Date: Fri, 24 Jun 2011 15:49:27 +0800	[thread overview]
Message-ID: <1308901767-4580-1-git-send-email-lidongyang@novell.com> (raw)

With discard flag in btrfs_device, we will only push trim request to the
devices support that.
Now we don't return EOPNOTSUPP to the caller, so we won't trigger BUG_ONs
in the walk_log_tree functions if we mount a drive without DISCARD
using -o discard, but it is still possible if we get errors from
blkdev_issue_discard.
This won't affect the return value of fstrim on the drives without DISCARD,
because we've already checked that in btrfs_ioctl_fitrim, Thanks

Changes v2:
  better name for the discard flag

Signed-off-by: Li Dongyang <lidongyang@novell.com>
---
 fs/btrfs/extent-tree.c |   24 ++++++++++++------------
 fs/btrfs/volumes.c     |    4 ++++
 fs/btrfs/volumes.h     |    1 +
 3 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 1f61bf5..81ccae2 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -1774,7 +1774,6 @@ static int btrfs_discard_extent(struct btrfs_root *root, u64 bytenr,
 	u64 discarded_bytes = 0;
 	struct btrfs_multi_bio *multi = NULL;
 
-
 	/* Tell the block device(s) that the sectors can be discarded */
 	ret = btrfs_map_block(&root->fs_info->mapping_tree, REQ_DISCARD,
 			      bytenr, &num_bytes, &multi, 0);
@@ -1782,25 +1781,26 @@ static int btrfs_discard_extent(struct btrfs_root *root, u64 bytenr,
 		struct btrfs_bio_stripe *stripe = multi->stripes;
 		int i;
 
-
 		for (i = 0; i < multi->num_stripes; i++, stripe++) {
-			ret = btrfs_issue_discard(stripe->dev->bdev,
-						  stripe->physical,
-						  stripe->length);
-			if (!ret)
-				discarded_bytes += stripe->length;
-			else if (ret != -EOPNOTSUPP)
-				break;
+			if (stripe->dev->has_trim) {
+				ret = btrfs_issue_discard(stripe->dev->bdev,
+							  stripe->physical,
+							  stripe->length);
+				if (!ret)
+					discarded_bytes += stripe->length;
+				else if (ret == -EOPNOTSUPP) {
+					stripe->dev->has_trim = 0;
+					ret = 0;
+				} else
+					break;
+			}
 		}
 		kfree(multi);
 	}
-	if (discarded_bytes && ret == -EOPNOTSUPP)
-		ret = 0;
 
 	if (actual_bytes)
 		*actual_bytes = discarded_bytes;
 
-
 	return ret;
 }
 
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 1efa56e..3d86b35 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -341,6 +341,7 @@ static noinline int device_list_add(const char *path,
 		device->work.func = pending_bios_fn;
 		memcpy(device->uuid, disk_super->dev_item.uuid,
 		       BTRFS_UUID_SIZE);
+		device->has_trim = 1;
 		spin_lock_init(&device->io_lock);
 		device->name = kstrdup(path, GFP_NOFS);
 		if (!device->name) {
@@ -408,6 +409,7 @@ static struct btrfs_fs_devices *clone_fs_devices(struct btrfs_fs_devices *orig)
 		device->devid = orig_dev->devid;
 		device->work.func = pending_bios_fn;
 		memcpy(device->uuid, orig_dev->uuid, sizeof(device->uuid));
+		device->has_trim = 1;
 		spin_lock_init(&device->io_lock);
 		INIT_LIST_HEAD(&device->dev_list);
 		INIT_LIST_HEAD(&device->dev_alloc_list);
@@ -1612,6 +1614,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
 	lock_chunks(root);
 
 	device->writeable = 1;
+	device->has_trim = 1;
 	device->work.func = pending_bios_fn;
 	generate_random_uuid(device->uuid);
 	spin_lock_init(&device->io_lock);
@@ -3342,6 +3345,7 @@ static struct btrfs_device *add_missing_dev(struct btrfs_root *root,
 		return NULL;
 	list_add(&device->dev_list,
 		 &fs_devices->devices);
+	device->has_trim = 1;
 	device->dev_root = root->fs_info->dev_root;
 	device->devid = devid;
 	device->work.func = pending_bios_fn;
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 7c12d61..376d71c 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -45,6 +45,7 @@ struct btrfs_device {
 	int running_pending;
 	u64 generation;
 
+	int has_trim;
 	int writeable;
 	int in_fs_metadata;
 	int missing;
-- 
1.7.5.4


                 reply	other threads:[~2011-06-24  7:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1308901767-4580-1-git-send-email-lidongyang@novell.com \
    --to=lidongyang@novell.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).