rbd: improve warnings
Subsystems (2)
cover rbd: improve warnings
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()
PATCH 1/4 rbd: define and use rbd_warn()
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().
--- drivers/block/rbd.c | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-)
drivers/block/rbd.c +27 -0
@@ -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. */
Signature · 1 line
1.7.9.5
PATCH 2/4 rbd: add warning messages for missing arguments
In reply to Alex ElderTell the user (via dmesg) what was wrong with the arguments provided via /sys/bus/rbd/add.
--- drivers/block/rbd.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)
drivers/block/rbd.c +16 -8
@@ -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 "-"
Signature · 1 line
1.7.9.5
PATCH 3/4 rbd: add a warning in bio_chain_clone_range()
In reply to Alex ElderAdd 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.
--- drivers/block/rbd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/block/rbd.c +0 -0
@@ -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)
Signature · 1 line
1.7.9.5
PATCH 4/4 rbd: add warnings to rbd_dev_probe_update_spec()
In reply to Alex ElderJosh 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.
--- drivers/block/rbd.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/block/rbd.c +0 -0
@@ -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;
}
Signature · 1 line
1.7.9.5