linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anand Jain <anand.jain@oracle.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 2/2] btrfs: clean up btrfs_report_missing_device() usage
Date: Fri,  6 Oct 2017 18:04:43 +0800	[thread overview]
Message-ID: <20171006100443.20007-2-anand.jain@oracle.com> (raw)
In-Reply-To: <20171006100443.20007-1-anand.jain@oracle.com>

This patch makes the following changes..
When -o degraded flag is not set and one of the device
is missing then we should log an error instead of warning.
So move the check for DEGRADED flag into the same function
and rename it. Also does code cleanup around this, including
making this function as static. And to print warning, just
open code it.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/volumes.c | 41 +++++++++++++++++++++++------------------
 fs/btrfs/volumes.h |  3 ---
 2 files changed, 23 insertions(+), 21 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index f4b659b6ef4c..317d6d1b58d0 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -6377,6 +6377,22 @@ static int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info,
 	return 0;
 }
 
+static int check_report_degraded(struct btrfs_fs_info *fs_info,
+					u64 devid, u8 *uuid, int warn)
+{
+	if (!btrfs_test_opt(fs_info, DEGRADED)) {
+		btrfs_err_rl(fs_info, "devid %llu uuid %pU is missing",
+				devid, uuid);
+		return 1;
+	}
+
+	if (warn)
+		btrfs_warn_rl(fs_info, "devid %llu uuid %pU is missing",
+				devid, uuid);
+	return 0;
+}
+
+
 static int read_one_chunk(struct btrfs_fs_info *fs_info, struct btrfs_key *key,
 			  struct extent_buffer *leaf,
 			  struct btrfs_chunk *chunk)
@@ -6445,9 +6461,8 @@ static int read_one_chunk(struct btrfs_fs_info *fs_info, struct btrfs_key *key,
 		map->stripes[i].dev = btrfs_find_device(fs_info, devid,
 							uuid, NULL);
 		if (!map->stripes[i].dev &&
-		    !btrfs_test_opt(fs_info, DEGRADED)) {
+			check_report_degraded(fs_info, devid, uuid, 0)) {
 			free_extent_map(em);
-			btrfs_report_missing_device(fs_info, devid, uuid);
 			return -EINVAL;
 		}
 		if (!map->stripes[i].dev) {
@@ -6461,7 +6476,7 @@ static int read_one_chunk(struct btrfs_fs_info *fs_info, struct btrfs_key *key,
 					devid, PTR_ERR(map->stripes[i].dev));
 				return PTR_ERR(map->stripes[i].dev);
 			}
-			btrfs_report_missing_device(fs_info, devid, uuid);
+			check_report_degraded(fs_info, devid, uuid, 1);
 		}
 		map->stripes[i].dev->in_fs_metadata = 1;
 	}
@@ -6579,21 +6594,17 @@ static int read_one_dev(struct btrfs_fs_info *fs_info,
 
 	device = btrfs_find_device(fs_info, devid, dev_uuid, fs_uuid);
 	if (!device) {
-		if (!btrfs_test_opt(fs_info, DEGRADED)) {
-			btrfs_report_missing_device(fs_info, devid, dev_uuid);
+		if (check_report_degraded(fs_info, devid, dev_uuid, 0))
 			return -EINVAL;
-		}
 
 		device = add_missing_dev(fs_devices, devid, dev_uuid);
 		if (IS_ERR(device))
 			return PTR_ERR(device);
-		btrfs_report_missing_device(fs_info, devid, dev_uuid);
+		check_report_degraded(fs_info, devid, dev_uuid, 1);
 	} else {
-		if (!device->bdev) {
-			btrfs_report_missing_device(fs_info, devid, dev_uuid);
-			if (!btrfs_test_opt(fs_info, DEGRADED))
-				return -EIO;
-		}
+		if (!device->bdev &&
+			check_report_degraded(fs_info, devid, dev_uuid, 1))
+			return -EINVAL;
 
 		if(!device->bdev && !device->missing) {
 			/*
@@ -6759,12 +6770,6 @@ int btrfs_read_sys_array(struct btrfs_fs_info *fs_info)
 	return -EIO;
 }
 
-void btrfs_report_missing_device(struct btrfs_fs_info *fs_info, u64 devid,
-				 u8 *uuid)
-{
-	btrfs_warn_rl(fs_info, "devid %llu uuid %pU is missing", devid, uuid);
-}
-
 /*
  * Check if all chunks in the fs are OK for read-write degraded mount
  *
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 6c807a1c0531..e40b6f207533 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -541,7 +541,4 @@ void btrfs_set_fs_info_ptr(struct btrfs_fs_info *fs_info);
 void btrfs_reset_fs_info_ptr(struct btrfs_fs_info *fs_info);
 
 bool btrfs_check_rw_degradable(struct btrfs_fs_info *fs_info);
-void btrfs_report_missing_device(struct btrfs_fs_info *fs_info, u64 devid,
-				 u8 *uuid);
-
 #endif
-- 
2.13.1


  reply	other threads:[~2017-10-06 10:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-06 10:04 [PATCH 1/2] btrfs: fix read_one_chunk() return error code Anand Jain
2017-10-06 10:04 ` Anand Jain [this message]
2017-10-06 18:48 ` David Sterba

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=20171006100443.20007-2-anand.jain@oracle.com \
    --to=anand.jain@oracle.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).