Every sg device has a reference to the underlying scsi device, so
this patch adds dev_printk() macros to have the messages prefixed
with the correct device.
Before:
[772330.437378] sg_open: dev=2, flags=0x8800
[772330.475425] sg_add_sfp: sfp=0x880429d3e000
After:
[ 409.399888] sr 2:0:0:0: [sg2] sg_open: flags=0x8800
[ 409.446029] sr 2:0:0:0: [sg2] sg_add_sfp: sfp=0x880425856000
Cc: Kay Sievers
Cc: Doug Gilbert
Signed-off-by: Hannes Reinecke
---
drivers/scsi/sg.c | 187 +++--
1 files changed, 109 insertions(+), 78 deletions(-)
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 9c5c5f2..2e6056f 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -101,6 +101,13 @@ static int scatter_elem_sz_prev = SG_SCATTER_SZ;
#define SG_SECTOR_SZ 512
+#define sgdev_printk(prefix, sgdev, fmt, a...) \
+ dev_printk(prefix, &(sgdev)->device->sdev_gendev, "[%s] " fmt, \
+ (sgdev)->disk->disk_name, ##a)
+
+#define sgfp_printk(prefix, sgfp, fmt, a...) \
+ sgdev_printk(prefix, (sgfp)->parentdp, fmt, ##a)
+
static int sg_add(struct device *, struct class_interface *);
static void sg_remove(struct device *, struct class_interface *);
@@ -196,7 +203,7 @@ static ssize_t sg_new_write(Sg_fd *sfp, struct file *file,
static int sg_common_write(Sg_fd * sfp, Sg_request * srp,
unsigned char *cmnd, int timeout, int blocking);
static int sg_read_oxfer(Sg_request * srp, char __user *outp, int
num_read_xfer);
-static void sg_remove_scat(Sg_scatter_hold * schp);
+static void sg_remove_scat(Sg_scatter_hold * schp, Sg_fd * sfp);
static void sg_build_reserve(Sg_fd * sfp, int req_size);
static void sg_link_reserve(Sg_fd * sfp, Sg_request * srp, int size);
static void sg_unlink_reserve(Sg_fd * sfp, Sg_request * srp);
@@ -268,13 +275,14 @@ sg_open(struct inode *inode, struct file *filp)
int retval;
nonseekable_open(inode, filp);
- SCSI_LOG_TIMEOUT(3, printk("sg_open: dev=%d, flags=0x%x\n", dev,
flags));
sdp = sg_get_dev(dev);
if (IS_ERR(sdp)) {
retval = PTR_ERR(sdp);
sdp = NULL;
goto sg_put;
}
+ SCSI_LOG_TIMEOUT(3, sgdev_printk(KERN_INFO, sdp,
+"sg_open: flags=0x%x\n", flags));
/* This driver's module count bumped by fops_get in */
/* Prevent the device driver from vanishing while we sleep */
@@ -360,7 +368,7 @@ sg_release(struct inode *inode, struct file *filp)
if ((!(sfp = (Sg_fd *) filp->private_data)) || (!(sdp = sfp->parentdp)))
return -ENXIO;
- SCSI_LOG_TIMEOUT(3, printk("sg_release: %s\n", sdp->disk->disk_name));
+ SCSI_LOG_TIMEOUT(3, sgdev_printk(KERN_INFO, sdp, "sg_release"));
set_exclude(sdp, 0);
wake_up_interruptible(&sdp->o_excl_wait);
@@ -383,8 +391,8 @@ sg_read(struct file *filp, char __user *buf, size_t count,
loff_t * ppos)
if ((!(sfp = (Sg_fd *) filp->private_data)) || (!(sdp = sfp->parentdp)))
return -ENXIO;
- SCSI_LOG_TIMEOUT(3, printk("sg_read: %s, count=%d\n",
- sdp->disk->disk_name, (int) count));
+ SCSI_LOG_TIMEOUT(3, sgdev_printk(KERN_INFO, sdp, "sg_read: count=%d",
+(int) count));
if (!access_ok(VERIFY_WRITE, buf, count))
return -EFAULT;
@@ -569,8 +577,8 @@ sg_write(struct file *filp, const char __user *buf, size_t
count, loff_t * ppos)
if ((!(sfp = (Sg_fd *) filp->private_data)) || (!(sdp = sfp->parentdp)))
return -ENXIO;
- SCSI_LOG_TIMEOUT(3, printk("sg_write: %s, count=%d\n",
- sdp->disk->disk_name, (int) count));
+ SCSI_LOG_TIMEOUT(3, sgdev_printk(KERN_INFO, sdp, "sg_write: count=%d",
+(int) count));
if (sdp->detached)
return -ENODEV;
if (!((filp->f_flags & O_NONBLOCK) ||
@@ -591,14 +599,17 @@ sg_write(struct file *filp, const char __user *buf,
size_t count, loff_t * ppos)
return -EIO;/* The minimum scsi command length is 6 bytes.
*/
if (!(srp = sg_add_request(sfp))) {
- SCSI_LOG_TIMEOUT(1, printk("sg_write: queue full\n"));
+ SCSI_LOG_TIMEOUT(1, sgdev_printk(KERN_INFO, sdp,
+"sg_write: queue full"));
return -EDOM;
}
buf += SZ_SG_HEADER;
__get_user(opcode, buf);
if (sfp->next_cmd_len > 0) {
if (sfp->next_cmd_len > MAX_COMMAND_SIZE) {
- SCSI_LOG_TIMEOUT(1, printk("sg_write: command length
too long\n"));
+ SCSI_LOG_TIMEOUT(1, sgdev_printk(KERN_INFO, sdp,
+"sg_write: command "
+