linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tomasz Majchrzak <tomasz.majchrzak@intel.com>
To: linux-raid@vger.kernel.org
Cc: Jes.Sorensen@redhat.com, Tomasz Majchrzak <tomasz.majchrzak@intel.com>
Subject: [PATCH v2 8/9] imsm: implement "--examine-badblocks" command
Date: Tue, 29 Nov 2016 14:02:34 +0100	[thread overview]
Message-ID: <1480424555-31509-9-git-send-email-tomasz.majchrzak@intel.com> (raw)
In-Reply-To: <1480424555-31509-1-git-send-email-tomasz.majchrzak@intel.com>

Implement "--examine-badblocks" command to provide list of bad blocks in
metadata for a disk.

Signed-off-by: Tomasz Majchrzak <tomasz.majchrzak@intel.com>
---
 super-intel.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/super-intel.c b/super-intel.c
index fd2145c..ab14fce 100644
--- a/super-intel.c
+++ b/super-intel.c
@@ -9900,6 +9900,61 @@ static struct md_bb *imsm_get_badblocks(struct active_array *a, int slot)
 	return &super->bb;
 }
 /*******************************************************************************
+* Function:   examine_badblocks_imsm
+* Description: Prints list of bad blocks on a disk to the standard output
+*
+* Parameters:
+*     st	: metadata handler
+*     fd	: open file descriptor for device
+*     devname	: device name
+* Returns:
+*     0 : Success
+*     1 : Error
+******************************************************************************/
+static int examine_badblocks_imsm(struct supertype *st, int fd, char *devname)
+{
+	struct intel_super *super = st->sb;
+	struct bbm_log *log = super->bbm_log;
+	struct dl *d = NULL;
+	int any = 0;
+
+	for (d = super->disks; d ; d = d->next) {
+		if (strcmp(d->devname, devname) == 0)
+			break;
+	}
+
+	if ((d == NULL) || (d->index < 0)) { /* serial mismatch probably */
+		pr_err("%s doesn't appear to be part of a raid array\n",
+		       devname);
+		return 1;
+	}
+
+	if (log != NULL) {
+		unsigned int i;
+		struct bbm_log_entry *entry = &log->marked_block_entries[0];
+
+		for (i = 0; i < log->entry_count; i++) {
+			if (entry[i].disk_ordinal == d->index) {
+				unsigned long long sector = __le48_to_cpu(
+					&entry[i].defective_block_start);
+				int cnt = entry[i].marked_count + 1;
+
+				if (!any) {
+					printf("Bad-blocks on %s:\n", devname);
+					any = 1;
+				}
+
+				printf("%20llu for %d sectors\n", sector, cnt);
+			}
+		}
+	}
+
+	if (!any)
+		printf("No bad-blocks list configured on %s\n", devname);
+
+	return 0;
+}
+/*******************************************************************************
  * Function:	init_migr_record_imsm
  * Description:	Function inits imsm migration record
  * Parameters:
@@ -11420,6 +11475,7 @@ struct superswitch super_imsm = {
 	.manage_reshape = imsm_manage_reshape,
 	.recover_backup = recover_backup_imsm,
 	.copy_metadata = copy_metadata_imsm,
+	.examine_badblocks = examine_badblocks_imsm,
 #endif
 	.match_home	= match_home_imsm,
 	.uuid_from_super= uuid_from_super_imsm,
-- 
1.8.3.1


  parent reply	other threads:[~2016-11-29 13:02 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-29 13:02 [PATCH v2 0/9] Bad block support for IMSM metadata Tomasz Majchrzak
2016-11-29 13:02 ` [PATCH v2 1/9] imsm: parse bad block log in metadata on startup Tomasz Majchrzak
2016-11-29 15:40   ` [PATCH v3 " Tomasz Majchrzak
2016-11-29 13:02 ` [PATCH v2 2/9] imsm: write bad block log on metadata sync Tomasz Majchrzak
2016-11-29 13:02 ` [PATCH v2 3/9] imsm: give md list of known bad blocks on startup Tomasz Majchrzak
2016-11-29 22:27   ` Jes Sorensen
2016-11-30  8:41     ` [PATCH v3 " Tomasz Majchrzak
2016-11-30  8:51     ` [PATCH v2 " Tomasz Majchrzak
2016-12-01 22:33       ` Jes Sorensen
2016-11-29 13:02 ` [PATCH v2 4/9] imsm: record new bad block in bad block log Tomasz Majchrzak
2016-11-29 13:02 ` [PATCH v2 5/9] imsm: clear bad block from " Tomasz Majchrzak
2016-11-29 13:02 ` [PATCH v2 6/9] imsm: clear bad blocks if disk becomes unavailable Tomasz Majchrzak
2016-11-29 13:02 ` [PATCH v2 7/9] imsm: provide list of bad blocks for an array Tomasz Majchrzak
2016-12-01 22:34   ` Jes Sorensen
2016-12-02 12:54     ` [PATCH v3 " Tomasz Majchrzak
2016-11-29 13:02 ` Tomasz Majchrzak [this message]
2016-11-29 13:02 ` [PATCH v2 9/9] imsm: 4kn support for bad block log Tomasz Majchrzak
2016-12-02 16:04 ` [PATCH v2 0/9] Bad block support for IMSM metadata Jes Sorensen

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=1480424555-31509-9-git-send-email-tomasz.majchrzak@intel.com \
    --to=tomasz.majchrzak@intel.com \
    --cc=Jes.Sorensen@redhat.com \
    --cc=linux-raid@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).