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().

Signed-off-by: Alex Elder <elder@inktank.com>
Reviewed-by: Dan Mick <dan.mick@inktank.com>
Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
This commit is contained in:
Alex Elder 2012-11-01 10:17:15 -05:00 committed by Alex Elder
parent dd5f049dbd
commit 06ecc6cbf7

View File

@ -294,6 +294,33 @@ static struct device rbd_root_dev = {
.release = rbd_root_dev_release, .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 #ifdef RBD_DEBUG
#define rbd_assert(expr) \ #define rbd_assert(expr) \
if (unlikely(!(expr))) { \ if (unlikely(!(expr))) { \
@ -1403,8 +1430,8 @@ static void rbd_watch_cb(u64 ver, u64 notify_id, u8 opcode, void *data)
(unsigned int) opcode); (unsigned int) opcode);
rc = rbd_dev_refresh(rbd_dev, &hver); rc = rbd_dev_refresh(rbd_dev, &hver);
if (rc) if (rc)
pr_warning(RBD_DRV_NAME "%d got notification but failed to " rbd_warn(rbd_dev, "got notification but failed to "
" update snaps: %d\n", rbd_dev->major, rc); " update snaps: %d\n", rc);
rbd_req_sync_notify_ack(rbd_dev, hver, notify_id); rbd_req_sync_notify_ack(rbd_dev, hver, notify_id);
} }
@ -1767,15 +1794,13 @@ rbd_dev_v1_header_read(struct rbd_device *rbd_dev, u64 *version)
goto out_err; goto out_err;
if (WARN_ON((size_t) ret < size)) { if (WARN_ON((size_t) ret < size)) {
ret = -ENXIO; ret = -ENXIO;
pr_warning("short header read for image %s" rbd_warn(rbd_dev, "short header read (want %zd got %d)",
" (want %zd got %d)\n", size, ret);
rbd_dev->spec->image_name, size, ret);
goto out_err; goto out_err;
} }
if (!rbd_dev_ondisk_valid(ondisk)) { if (!rbd_dev_ondisk_valid(ondisk)) {
ret = -ENXIO; ret = -ENXIO;
pr_warning("invalid header for image %s\n", rbd_warn(rbd_dev, "invalid header");
rbd_dev->spec->image_name);
goto out_err; goto out_err;
} }
@ -2630,9 +2655,7 @@ static int rbd_dev_probe_update_spec(struct rbd_device *rbd_dev)
if (name) if (name)
rbd_dev->spec->image_name = (char *) name; rbd_dev->spec->image_name = (char *) name;
else else
pr_warning(RBD_DRV_NAME "%d " rbd_warn(rbd_dev, "unable to get image name");
"unable to get image name for image id %s\n",
rbd_dev->major, rbd_dev->spec->image_id);
/* Look up the snapshot name. */ /* Look up the snapshot name. */