public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: "Jörn Engel" <joern@logfs.org>
Cc: linux-kernel@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Borislav Petkov <bp@alien8.de>, Jeff Moyer <jmoyer@redhat.com>
Subject: [PATCH 2/3] block/partitions: Support dynamic addition of partition checkers
Date: Thu,  7 Mar 2013 19:51:06 +0100	[thread overview]
Message-ID: <1362682267-10188-3-git-send-email-tiwai@suse.de> (raw)
In-Reply-To: <1362682267-10188-1-git-send-email-tiwai@suse.de>

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


  parent reply	other threads:[~2013-03-07 18:51 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-28 21:39 [PATCH 0/9] Add blockconsole version 1.1 (try 2) Joern Engel
2013-02-28 21:39 ` [PATCH 1/9] do_mounts: constify name_to_dev_t parameter Joern Engel
2013-02-28 21:39 ` [PATCH 2/9] add blockconsole version 1.1 Joern Engel
2013-02-28 21:39 ` [PATCH 3/9] printk: add CON_ALLDATA console flag Joern Engel
2013-03-01 14:52   ` Jeff Moyer
2013-03-01 14:58     ` Borislav Petkov
2013-03-01 15:08       ` Jeff Moyer
2013-03-01 15:31         ` Borislav Petkov
2013-03-01 15:42           ` Jeff Moyer
2013-03-01 15:58             ` Borislav Petkov
2013-03-01 16:15         ` Jörn Engel
2013-02-28 21:39 ` [PATCH 4/9] netconsole: use CON_ALLDATA Joern Engel
2013-02-28 21:39 ` [PATCH 5/9] blockconsole: " Joern Engel
2013-03-01 16:11   ` Jeff Moyer
2013-03-01 16:20     ` Jörn Engel
2013-03-01 17:52       ` Borislav Petkov
2013-03-01 16:31         ` Jörn Engel
2013-03-01 17:56           ` Borislav Petkov
2013-02-28 21:39 ` [PATCH 6/9] bcon: add a release work struct Joern Engel
2013-02-28 21:40 ` [PATCH 7/9] bcon: check for hdparm in bcon_tail Joern Engel
2013-02-28 21:40 ` [PATCH 8/9] blockconsole: Allow to pass a device file path to bcon_tail Joern Engel
2013-02-28 21:40 ` [PATCH 9/9] bcon: remove version 1.0 support Joern Engel
2013-03-01 17:15 ` [PATCH 0/9] Add blockconsole version 1.1 (try 2) Takashi Iwai
2013-03-01 16:22   ` Jörn Engel
2013-03-05 17:36     ` Takashi Iwai
2013-03-06 19:49       ` Jörn Engel
2013-03-07 18:46         ` Takashi Iwai
2013-03-07 18:51           ` [PATCH 0/3] blockconsole: make it a module Takashi Iwai
2013-03-07 18:51             ` [PATCH 1/3] Export sched_setscheduler_nocheck() Takashi Iwai
2013-03-07 18:51             ` Takashi Iwai [this message]
2013-03-07 18:51             ` [PATCH 3/3] blockconsole: Allow to be a module Takashi Iwai
2013-03-01 17:17   ` [PATCH 1/3] blockconsole: Fix undefined MAX_RT_PRIO Takashi Iwai
2013-03-01 17:17     ` [PATCH 2/3] blockconsole: Rename device_lock with bc_device_lock Takashi Iwai
2013-03-01 17:17     ` [PATCH 3/3] blockconsole: Mark a local work struct static Takashi Iwai
2013-03-20 22:52 ` [PATCH 0/9] Add blockconsole version 1.1 (try 2) Borislav Petkov
2013-03-21  6:30   ` Takashi Iwai

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=1362682267-10188-3-git-send-email-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=bp@alien8.de \
    --cc=jmoyer@redhat.com \
    --cc=joern@logfs.org \
    --cc=linux-kernel@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