linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3 v2] badblocks: add function to check for unacked badblocks
@ 2016-10-18 14:08 Tomasz Majchrzak
  0 siblings, 0 replies; only message in thread
From: Tomasz Majchrzak @ 2016-10-18 14:08 UTC (permalink / raw)
  To: linux-block
  Cc: shli, aleksey.obitotskiy, pawel.baldysiak, artur.paszkiewicz,
	maksymilian.kunt, mariusz.dabrowski, axboe, dan.j.williams,
	linux-raid, Tomasz Majchrzak

Add new function that checks if unacknowledged badblocks exist in a list
and clears ->unacked_exists flag if possible. It is required for storing
badblock information by userspace metadata handlers. Similar function
ack_all_badblocks is of no use in this case as userspace reads badblocks
data from sysfs file so it cannot be sure if the list available in sysfs
at the moment is complete (potential race with other badblocks reported
at the same time).

Signed-off-by: Tomasz Majchrzak <tomasz.majchrzak@intel.com>
---
 block/badblocks.c         | 36 ++++++++++++++++++++++++++++++++++++
 include/linux/badblocks.h |  1 +
 2 files changed, 37 insertions(+)

diff --git a/block/badblocks.c b/block/badblocks.c
index 7be53cb..1f4a193 100644
--- a/block/badblocks.c
+++ b/block/badblocks.c
@@ -439,6 +439,42 @@ void ack_all_badblocks(struct badblocks *bb)
 EXPORT_SYMBOL_GPL(ack_all_badblocks);
 
 /**
+ * check_if_badblocks_acked() - Check if all badblocks in list are acknowledged
+ * @bb:		the badblocks structure that holds all badblock information
+ *
+ * It clears ->changed and ->unacked_exist if successful. It is used by
+ * userspace metadata updates
+ *
+ *  Return:
+ *   True if all badblocks are acknowledged, false otherwise
+ */
+int check_if_badblocks_acked(struct badblocks *bb)
+{
+	int acked = 1;
+
+	write_seqlock_irq(&bb->lock);
+	if (bb->unacked_exist) {
+		u64 *p = bb->page;
+		int i;
+
+		for (i = 0; i < bb->count ; i++) {
+			if (!BB_ACK(p[i])) {
+				acked = 0;
+				break;
+			}
+		}
+		if (acked) {
+			bb->unacked_exist = 0;
+			bb->changed = 0;
+		}
+	}
+	write_sequnlock_irq(&bb->lock);
+
+	return acked;
+}
+EXPORT_SYMBOL_GPL(check_if_badblocks_acked);
+
+/**
  * badblocks_show() - sysfs access to bad-blocks list
  * @bb:		the badblocks structure that holds all badblock information
  * @page:	buffer received from sysfs
diff --git a/include/linux/badblocks.h b/include/linux/badblocks.h
index c3bdf8c..6569d4e 100644
--- a/include/linux/badblocks.h
+++ b/include/linux/badblocks.h
@@ -46,6 +46,7 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors,
 			int acknowledged);
 int badblocks_clear(struct badblocks *bb, sector_t s, int sectors);
 void ack_all_badblocks(struct badblocks *bb);
+int check_if_badblocks_acked(struct badblocks *bb);
 ssize_t badblocks_show(struct badblocks *bb, char *page, int unack);
 ssize_t badblocks_store(struct badblocks *bb, const char *page, size_t len,
 			int unack);
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2016-10-18 14:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-18 14:08 [PATCH 1/3 v2] badblocks: add function to check for unacked badblocks Tomasz Majchrzak

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).