All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hannes Reinecke <hare@suse.de>
To: Karel Zak <kzak@redhat.com>
Cc: Werner Fink <werner@suse.de>, Stanislav Brabec <sbrabec@suse.com>,
	<util-linux@vger.kernel.org>, Hannes Reinecke <hare@suse.de>
Subject: [PATCH 1/2] blkid: stop scanning on I/O error
Date: Wed, 19 Mar 2014 14:50:55 +0100	[thread overview]
Message-ID: <1395237056-26595-2-git-send-email-hare@suse.de> (raw)
In-Reply-To: <1395237056-26595-1-git-send-email-hare@suse.de>

Whenever we fail to read from a device it's pointless to
continue with probing; we should be failing immediately.
Otherwise the system will continue logging I/O errors.

This patch updates the probe functions to return -1
on I/O error and 1 if not found.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 libblkid/src/partitions/partitions.c   | 13 +++++++++----
 libblkid/src/probe.c                   | 13 +++++++++++--
 libblkid/src/superblocks/superblocks.c | 13 ++++++++++---
 3 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/libblkid/src/partitions/partitions.c b/libblkid/src/partitions/partitions.c
index d9419f2..53e5009 100644
--- a/libblkid/src/partitions/partitions.c
+++ b/libblkid/src/partitions/partitions.c
@@ -540,7 +540,8 @@ static int idinfo_probe(blkid_probe pr, const struct blkid_idinfo *id,
 	if (pr->size <= 0 || (id->minsz && id->minsz > pr->size))
 		goto nothing;	/* the device is too small */
 
-	if (blkid_probe_get_idmag(pr, id, &off, &mag))
+	rc = blkid_probe_get_idmag(pr, id, &off, &mag);
+	if (rc != 0)
 		goto nothing;
 
 	/* final check by probing function */
@@ -548,12 +549,13 @@ static int idinfo_probe(blkid_probe pr, const struct blkid_idinfo *id,
 		DBG(LOWPROBE, blkid_debug(
 			"%s: ---> call probefunc()", id->name));
 		rc = id->probefunc(pr, mag);
-	        if (rc == -1) {
+		if (rc != 0) {
 			/* reset after error */
 			reset_partlist(blkid_probe_get_partlist(pr));
 			if (chn && !chn->binary)
 				blkid_probe_chain_reset_vals(pr, chn);
-			DBG(LOWPROBE, blkid_debug("%s probefunc failed", id->name));
+			DBG(LOWPROBE, blkid_debug("%s probefunc failed, rc %d",
+						  id->name, rc));
 		}
 		if (rc == 0 && mag && chn && !chn->binary)
 			rc = blkid_probe_set_magic(pr, off, mag->len,
@@ -599,7 +601,10 @@ static int partitions_probe(blkid_probe pr, struct blkid_chain *chn)
 			continue;
 
 		/* apply checks from idinfo */
-		if (idinfo_probe(pr, idinfos[i], chn) != 0)
+		rc = idinfo_probe(pr, idinfos[i], chn);
+		if (rc < 0)
+			return rc;
+		if (rc > 0)
 			continue;
 
 		name = idinfos[i]->name;
diff --git a/libblkid/src/probe.c b/libblkid/src/probe.c
index e20c61b..f33fd85 100644
--- a/libblkid/src/probe.c
+++ b/libblkid/src/probe.c
@@ -569,13 +569,17 @@ unsigned char *blkid_probe_get_buffer(blkid_probe pr,
 	if (!bf) {
 		ssize_t ret;
 
-		if (blkid_llseek(pr->fd, pr->off + off, SEEK_SET) < 0)
+		if (blkid_llseek(pr->fd, pr->off + off, SEEK_SET) < 0) {
+			errno = 0;
 			return NULL;
+		}
 
 		/* allocate info and space for data by why call */
 		bf = calloc(1, sizeof(struct blkid_bufinfo) + len);
-		if (!bf)
+		if (!bf) {
+			errno = 0;
 			return NULL;
+		}
 
 		bf->data = ((unsigned char *) bf) + sizeof(struct blkid_bufinfo);
 		bf->len = len;
@@ -587,7 +591,10 @@ unsigned char *blkid_probe_get_buffer(blkid_probe pr,
 
 		ret = read(pr->fd, bf->data, len);
 		if (ret != (ssize_t) len) {
+			DBG(LOWPROBE, blkid_debug("\tbuffer read: return %d error %d", ret, errno));
 			free(bf);
+			if (ret >= 0 || errno != EIO)
+				errno = 0;
 			return NULL;
 		}
 		list_add_tail(&bf->bufs, &pr->buffers);
@@ -794,6 +801,8 @@ int blkid_probe_get_idmag(blkid_probe pr, const struct blkid_idinfo *id,
 		off = (mag->kboff + (mag->sboff >> 10)) << 10;
 		buf = blkid_probe_get_buffer(pr, off, 1024);
 
+		if (!buf && errno)
+			return -1;
 		if (buf && !memcmp(mag->magic,
 				buf + (mag->sboff & 0x3ff), mag->len)) {
 			DBG(LOWPROBE, blkid_debug("\tmagic sboff=%u, kboff=%ld",
diff --git a/libblkid/src/superblocks/superblocks.c b/libblkid/src/superblocks/superblocks.c
index c6394c4..35cfd50 100644
--- a/libblkid/src/superblocks/superblocks.c
+++ b/libblkid/src/superblocks/superblocks.c
@@ -379,15 +379,22 @@ static int superblocks_probe(blkid_probe pr, struct blkid_chain *chn)
 
 		DBG(LOWPROBE, blkid_debug("[%zd] %s:", i, id->name));
 
-		if (blkid_probe_get_idmag(pr, id, &off, &mag))
+		rc = blkid_probe_get_idmag(pr, id, &off, &mag);
+		if (rc < 0)
+			break;
+		if (rc > 0)
 			continue;
 
 		/* final check by probing function */
 		if (id->probefunc) {
 			DBG(LOWPROBE, blkid_debug("\tcall probefunc()"));
-			if (id->probefunc(pr, mag) != 0) {
+			rc = id->probefunc(pr, mag);
+			if (rc != 0) {
 				blkid_probe_chain_reset_vals(pr, chn);
-				continue;
+				if (rc < 0)
+					break;
+				else
+					continue;
 			}
 		}
 
-- 
1.7.12.4


  reply	other threads:[~2014-03-19 13:51 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-19 13:50 [PATCHv2 0/2] Abort blkid on I/O errors Hannes Reinecke
2014-03-19 13:50 ` Hannes Reinecke [this message]
2014-03-19 17:38   ` [PATCH 1/2] blkid: stop scanning on I/O error Karel Zak
2014-03-19 20:20     ` Hannes Reinecke
2014-03-19 13:50 ` [PATCH 2/2] blkid: convert superblocks to new calling convention Hannes Reinecke
2014-03-19 17:55   ` Karel Zak
2014-03-19 20:57     ` Hannes Reinecke
2014-03-20  9:18       ` Karel Zak
  -- strict thread matches above, loose matches on Subject: below --
2014-03-20 10:03 [PATCHv3 0/2] Abort blkid probing errors Hannes Reinecke
2014-03-20 10:03 ` [PATCH 1/2] blkid: stop scanning on I/O error Hannes Reinecke
2014-03-20 10:48   ` Karel Zak
2014-03-19 10:59 [PATCH 0/2] Abort blkid on I/O errors Hannes Reinecke
2014-03-19 10:59 ` [PATCH 1/2] blkid: stop scanning on I/O error Hannes Reinecke

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=1395237056-26595-2-git-send-email-hare@suse.de \
    --to=hare@suse.de \
    --cc=kzak@redhat.com \
    --cc=sbrabec@suse.com \
    --cc=util-linux@vger.kernel.org \
    --cc=werner@suse.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.