[PATCH 2/3] block/partitions: Support dynamic addition of partition checkers

Takashi Iwai
2013-03-07T18:51:21Z

Add helper functions to add / remove the partition checker function
dynamically. This also allows to move the partition checker code into
the driver itself, e.g. the blockconsole partition checker can be in a
part of blockconsole driver (even as a module).

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
block/partitions/check.c | 35 +++++++++++++++++++++++++++++++++++
block/partitions/check.h | 8 ++++++++
2 files changed, 43 insertions(+)

diff --git a/block/partitions/check.c b/block/partitions/check.c
index 21786ed..d71cb02 100644
--- a/block/partitions/check.c
+++ b/block/partitions/check.c
@@ -17,6 +17,7 @@
#include <linux/vmalloc.h>
#include <linux/ctype.h>
#include <linux/genhd.h>
+#include <linux/export.h>

#include "check.h"

@@ -110,6 +111,9 @@ static int (*check_part[])(struct parsed_partitions *) = {
NULL
};

+static DEFINE_MUTEX(check_part_mutex);
+static LIST_HEAD(check_part_list);
+
static struct parsed_partitions *allocate_partitions(struct gendisk *hd)
{
struct parsed_partitions *state;
@@ -172,6 +176,21 @@ check_partition(struct gendisk *hd, struct block_device *bdev)
}

}
+
+ if (res <= 0) {
+ struct partition_checker *c;
+ mutex_lock(&check_part_mutex);
+ list_for_each_entry(c, &check_part_list, list) {
+ memset(state->parts, 0, state->limit * sizeof(state->parts[0]));
+ res = c->check(state);
+ if (res < 0) {
+ err = res;
+ res = 0;
+ }
+ }
+ mutex_unlock(&check_part_mutex);
+ }
+
if (res > 0) {
printk(KERN_INFO "%s", state->pp_buf);

@@ -194,3 +213,19 @@ check_partition(struct gendisk *hd, struct block_device *bdev)
free_partitions(state);
return ERR_PTR(res);
}
+
+void append_partition_checker(struct partition_checker *c)
+{
+ mutex_lock(&check_part_mutex);
+ list_add_tail(&c->list, &check_part_list);
+ mutex_unlock(&check_part_mutex);
+}
+EXPORT_SYMBOL_GPL(append_partition_checker);
+
+void remove_partition_checker(struct partition_checker *c)
+{
+ mutex_lock(&check_part_mutex);
+ list_del(&c->list);
+ mutex_unlock(&check_part_mutex);
+}
+EXPORT_SYMBOL_GPL(remove_partition_checker);
diff --git a/block/partitions/check.h b/block/partitions/check.h
index bca9624..53c8508 100644
--- a/block/partitions/check.h
+++ b/block/partitions/check.h
@@ -55,3 +55,11 @@ extern int warn_no_part;
#ifdef CONFIG_BLOCKCONSOLE
int blockconsole_partition(struct parsed_partitions *state);
#endif
+
+struct partition_checker {
+ int (*check)(struct parsed_partitions *);
+ struct list_head list;
+};
+
+void append_partition_checker(struct partition_checker *c);
+void remove_partition_checker(struct partition_checker *c);
--
1.8.1.4