All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] rbd: improve warnings
@ 2012-11-01 15:24 Alex Elder
  2012-11-01 15:26 ` [PATCH 1/4] rbd: define and use rbd_warn() Alex Elder
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Alex Elder @ 2012-11-01 15:24 UTC (permalink / raw)
  To: ceph-devel

This series adds a utility function rbd_warn() that will
provide a central and unified way to generate warning messages
from rbd.  It then fleshes out some warning messages in a
few areas.  There is more to be done, but for now I'm just
getting the mechanism and these initial uses of it in place.

					-Alex

[PATCH 1/4] rbd: define and use rbd_warn()
[PATCH 2/4] rbd: add warning messages for missing arguments
[PATCH 3/4] rbd: add a warning in bio_chain_clone_range()
[PATCH 4/4] rbd: add warnings to rbd_dev_probe_update_spec()

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] rbd: define and use rbd_warn()
  2012-11-01 15:24 [PATCH 0/4] rbd: improve warnings Alex Elder
@ 2012-11-01 15:26 ` Alex Elder
  2012-11-01 15:26 ` [PATCH 2/4] rbd: add warning messages for missing arguments Alex Elder
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Alex Elder @ 2012-11-01 15:26 UTC (permalink / raw)
  To: ceph-devel

Define a new function rbd_warn() that produces a boilerplate warning
message, identifying in the resulting message the affected rbd
device in the best way available.  Use it in a few places that now
use pr_warning().

Signed-off-by: Alex Elder <elder@inktank.com>
---
 drivers/block/rbd.c |   43 +++++++++++++++++++++++++++++++++----------
 1 file changed, 33 insertions(+), 10 deletions(-)

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 503ee7f..85a5164 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -293,6 +293,33 @@ static struct device rbd_root_dev = {
 	.release =      rbd_root_dev_release,
 };

+static __printf(2, 3)
+void rbd_warn(struct rbd_device *rbd_dev, const char *fmt, ...)
+{
+	struct va_format vaf;
+	va_list args;
+
+	va_start(args, fmt);
+	vaf.fmt = fmt;
+	vaf.va = &args;
+
+	if (!rbd_dev)
+		printk(KERN_WARNING "%s: %pV\n", RBD_DRV_NAME, &vaf);
+	else if (rbd_dev->disk)
+		printk(KERN_WARNING "%s: %s: %pV\n",
+			RBD_DRV_NAME, rbd_dev->disk->disk_name, &vaf);
+	else if (rbd_dev->spec && rbd_dev->spec->image_name)
+		printk(KERN_WARNING "%s: image %s: %pV\n",
+			RBD_DRV_NAME, rbd_dev->spec->image_name, &vaf);
+	else if (rbd_dev->spec && rbd_dev->spec->image_id)
+		printk(KERN_WARNING "%s: id %s: %pV\n",
+			RBD_DRV_NAME, rbd_dev->spec->image_id, &vaf);
+	else	/* punt */
+		printk(KERN_WARNING "%s: rbd_dev %p: %pV\n",
+			RBD_DRV_NAME, rbd_dev, &vaf);
+	va_end(args);
+}
+
 #ifdef RBD_DEBUG
 #define rbd_assert(expr)						\
 		if (unlikely(!(expr))) {				\
@@ -1405,8 +1432,8 @@ static void rbd_watch_cb(u64 ver, u64 notify_id,
u8 opcode, void *data)
 		(unsigned int) opcode);
 	rc = rbd_dev_refresh(rbd_dev, &hver);
 	if (rc)
-		pr_warning(RBD_DRV_NAME "%d got notification but failed to "
-			   " update snaps: %d\n", rbd_dev->major, rc);
+		rbd_warn(rbd_dev, "got notification but failed to "
+			   " update snaps: %d\n", rc);

 	rbd_req_sync_notify_ack(rbd_dev, hver, notify_id);
 }
@@ -1769,15 +1796,13 @@ rbd_dev_v1_header_read(struct rbd_device
*rbd_dev, u64 *version)
 			goto out_err;
 		if (WARN_ON((size_t) ret < size)) {
 			ret = -ENXIO;
-			pr_warning("short header read for image %s"
-					" (want %zd got %d)\n",
-				rbd_dev->spec->image_name, size, ret);
+			rbd_warn(rbd_dev, "short header read (want %zd got %d)",
+				size, ret);
 			goto out_err;
 		}
 		if (!rbd_dev_ondisk_valid(ondisk)) {
 			ret = -ENXIO;
-			pr_warning("invalid header for image %s\n",
-				rbd_dev->spec->image_name);
+			rbd_warn(rbd_dev, "invalid header");
 			goto out_err;
 		}

@@ -2632,9 +2657,7 @@ static int rbd_dev_probe_update_spec(struct
rbd_device *rbd_dev)
 	if (name)
 		rbd_dev->spec->image_name = (char *) name;
 	else
-		pr_warning(RBD_DRV_NAME "%d "
-			"unable to get image name for image id %s\n",
-			rbd_dev->major, rbd_dev->spec->image_id);
+		rbd_warn(rbd_dev, "unable to get image name");

 	/* Look up the snapshot name. */

-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/4] rbd: add warning messages for missing arguments
  2012-11-01 15:24 [PATCH 0/4] rbd: improve warnings Alex Elder
  2012-11-01 15:26 ` [PATCH 1/4] rbd: define and use rbd_warn() Alex Elder
@ 2012-11-01 15:26 ` Alex Elder
  2012-11-01 15:26 ` [PATCH 3/4] rbd: add a warning in bio_chain_clone_range() Alex Elder
  2012-11-01 15:27 ` [PATCH 4/4] rbd: add warnings to rbd_dev_probe_update_spec() Alex Elder
  3 siblings, 0 replies; 5+ messages in thread
From: Alex Elder @ 2012-11-01 15:26 UTC (permalink / raw)
  To: ceph-devel

Tell the user (via dmesg) what was wrong with the arguments provided
via /sys/bus/rbd/add.

Signed-off-by: Alex Elder <elder@inktank.com>
---
 drivers/block/rbd.c |   24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 85a5164..de1d3b1 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -3246,8 +3246,10 @@ static int rbd_add_parse_args(const char *buf,
 	/* The first four tokens are required */

 	len = next_token(&buf);
-	if (!len)
-		return -EINVAL;	/* Missing monitor address(es) */
+	if (!len) {
+		rbd_warn(NULL, "no monitor address(es) provided");
+		return -EINVAL;
+	}
 	mon_addrs = buf;
 	mon_addrs_size = len + 1;
 	buf += len;
@@ -3256,8 +3258,10 @@ static int rbd_add_parse_args(const char *buf,
 	options = dup_token(&buf, NULL);
 	if (!options)
 		return -ENOMEM;
-	if (!*options)
-		goto out_err;	/* Missing options */
+	if (!*options) {
+		rbd_warn(NULL, "no options provided");
+		goto out_err;
+	}

 	spec = rbd_spec_alloc();
 	if (!spec)
@@ -3266,14 +3270,18 @@ static int rbd_add_parse_args(const char *buf,
 	spec->pool_name = dup_token(&buf, NULL);
 	if (!spec->pool_name)
 		goto out_mem;
-	if (!*spec->pool_name)
-		goto out_err;	/* Missing pool name */
+	if (!*spec->pool_name) {
+		rbd_warn(NULL, "no pool name provided");
+		goto out_err;
+	}

 	spec->image_name = dup_token(&buf, NULL);
 	if (!spec->image_name)
 		goto out_mem;
-	if (!*spec->image_name)
-		goto out_err;	/* Missing image name */
+	if (!*spec->image_name) {
+		rbd_warn(NULL, "no image name provided");
+		goto out_err;
+	}

 	/*
 	 * Snapshot name is optional; default is to use "-"
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/4] rbd: add a warning in bio_chain_clone_range()
  2012-11-01 15:24 [PATCH 0/4] rbd: improve warnings Alex Elder
  2012-11-01 15:26 ` [PATCH 1/4] rbd: define and use rbd_warn() Alex Elder
  2012-11-01 15:26 ` [PATCH 2/4] rbd: add warning messages for missing arguments Alex Elder
@ 2012-11-01 15:26 ` Alex Elder
  2012-11-01 15:27 ` [PATCH 4/4] rbd: add warnings to rbd_dev_probe_update_spec() Alex Elder
  3 siblings, 0 replies; 5+ messages in thread
From: Alex Elder @ 2012-11-01 15:26 UTC (permalink / raw)
  To: ceph-devel

Add a warning in bio_chain_clone_range() to help a user determine
what exactly might have led to a failure.  There is only one; please
say something if you disagree with the following reasoning.

There are three places this can return abnormally:
    - Initially, if there is nothing to clone.  It turns out that
      right now this cannot happen anyway.  The test is in place
      because the code below it doesn't work if those conditions
      don't hold.  As such they could be assertions but since I can
      return a null to indicate an error I just do that instead.
      I have not added a warning here because it won't happen.
    - While processing bio's, if none remain but there are supposed
      to be more bytes to clone.  Here I have added a warning.
    - If bio_clone_range() returns a null pointer.  That function
      will have already produced a warning (at least the first
      time, via WARN_ON_ONCE()) to distinguish the cause of the
      error.  The only exception is memory exhaustion, and I'd
      rather not pepper the code with warnings in all those spots.
      So no warning is added in that place.

Signed-off-by: Alex Elder <elder@inktank.com>
---
 drivers/block/rbd.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index de1d3b1..3ab3970 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -995,8 +995,10 @@ static struct bio *bio_chain_clone_range(struct bio
**bio_src,
 		unsigned int bi_size;
 		struct bio *bio;

-		if (!bi)
+		if (!bi) {
+			rbd_warn(NULL, "bio_chain exhausted with %u left", len);
 			goto out_err;	/* EINVAL; ran out of bio's */
+		}
 		bi_size = min_t(unsigned int, bi->bi_size - off, len);
 		bio = bio_clone_range(bi, off, bi_size, gfpmask);
 		if (!bio)
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/4] rbd: add warnings to rbd_dev_probe_update_spec()
  2012-11-01 15:24 [PATCH 0/4] rbd: improve warnings Alex Elder
                   ` (2 preceding siblings ...)
  2012-11-01 15:26 ` [PATCH 3/4] rbd: add a warning in bio_chain_clone_range() Alex Elder
@ 2012-11-01 15:27 ` Alex Elder
  3 siblings, 0 replies; 5+ messages in thread
From: Alex Elder @ 2012-11-01 15:27 UTC (permalink / raw)
  To: ceph-devel

Josh suggested adding warnings to this function to help users
diagnose problems.

Other than memory allocatino errors, there are two places where
errors can be returned.  Both represent problems that should
have been caught earlier, and as such might well have been
handled with BUG_ON() calls.  But if either ever did manage to
happen, it will be reported.

Signed-off-by: Alex Elder <elder@inktank.com>
---
 drivers/block/rbd.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 3ab3970..5de49a1 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -2646,8 +2646,11 @@ static int rbd_dev_probe_update_spec(struct
rbd_device *rbd_dev)

 	osdc = &rbd_dev->rbd_client->client->osdc;
 	name = ceph_pg_pool_name_by_id(osdc->osdmap, rbd_dev->spec->pool_id);
-	if (!name)
-		return -EIO;	/* pool id too large (>= 2^31) */
+	if (!name) {
+		rbd_warn(rbd_dev, "there is no pool with id %llu",
+			rbd_dev->spec->pool_id);	/* Really a BUG() */
+		return -EIO;
+	}

 	rbd_dev->spec->pool_name = kstrdup(name, GFP_KERNEL);
 	if (!rbd_dev->spec->pool_name)
@@ -2665,6 +2668,8 @@ static int rbd_dev_probe_update_spec(struct
rbd_device *rbd_dev)

 	name = rbd_snap_name(rbd_dev, rbd_dev->spec->snap_id);
 	if (!name) {
+		rbd_warn(rbd_dev, "no snapshot with id %llu",
+			rbd_dev->spec->snap_id);	/* Really a BUG() */
 		ret = -EIO;
 		goto out_err;
 	}
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-11-01 15:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-01 15:24 [PATCH 0/4] rbd: improve warnings Alex Elder
2012-11-01 15:26 ` [PATCH 1/4] rbd: define and use rbd_warn() Alex Elder
2012-11-01 15:26 ` [PATCH 2/4] rbd: add warning messages for missing arguments Alex Elder
2012-11-01 15:26 ` [PATCH 3/4] rbd: add a warning in bio_chain_clone_range() Alex Elder
2012-11-01 15:27 ` [PATCH 4/4] rbd: add warnings to rbd_dev_probe_update_spec() Alex Elder

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.