Skip to content

Commit

Permalink
st: allow debug output to be enabled or disabled via sysfs
Browse files Browse the repository at this point in the history
Change st driver to allow enabling or disabling debug output
via sysfs file /sys/bus/scsi/drivers/st/debug_flag.

Previously the only way to enable debug output was:

1. loading the driver with the module parameter debug_flag=1
2. an ioctl call (this method was also the only way to dynamically
disable debug output).

To use the ioctl you need a second tape drive (if you are
actively testing the first tape drive) since a second process
cannot open the first tape drive if it is in use.

The this change is only functional if the value of the macro
DEBUG in st.c is a non-zero value (which it is by default).

Signed-off-by: Shane Seymour <[email protected]>
Reviewed-by: Laurence Oberman <[email protected]>
Acked-by: Kai Mäkisara <[email protected]>
Signed-off-by: James Bottomley <[email protected]>
  • Loading branch information
sms1123 authored and James Bottomley committed Nov 10, 2015
1 parent c59ab4e commit d9b43a1
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Documentation/ABI/testing/sysfs-driver-st
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
What: /sys/bus/scsi/drivers/st/debug_flag
Date: October 2015
Kernel Version: ?.?
Contact: [email protected]
Description:
This file allows you to turn debug output from the st driver
off if you write a '0' to the file or on if you write a '1'.
Note that debug output requires that the module be compiled
with the #define DEBUG set to a non-zero value (this is the
default). If DEBUG is set to 0 then this file will not
appear in sysfs as its presence is conditional upon debug
output support being compiled into the module.
4 changes: 3 additions & 1 deletion Documentation/scsi/st.txt
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,9 @@ Debugging code is now compiled in by default but debugging is turned off
with the kernel module parameter debug_flag defaulting to 0. Debugging
can still be switched on and off with an ioctl. To enable debug at
module load time add debug_flag=1 to the module load options, the
debugging output is not voluminous.
debugging output is not voluminous. Debugging can also be enabled
and disabled by writing a '0' (disable) or '1' (enable) to the sysfs
file /sys/bus/scsi/drivers/st/debug_flag.

If the tape seems to hang, I would be very interested to hear where
the driver is waiting. With the command 'ps -l' you can see the state
Expand Down
30 changes: 30 additions & 0 deletions drivers/scsi/st.c
Original file line number Diff line number Diff line change
Expand Up @@ -4452,11 +4452,41 @@ static ssize_t version_show(struct device_driver *ddd, char *buf)
}
static DRIVER_ATTR_RO(version);

#if DEBUG
static ssize_t debug_flag_store(struct device_driver *ddp,
const char *buf, size_t count)
{
/* We only care what the first byte of the data is the rest is unused.
* if it's a '1' we turn on debug and if it's a '0' we disable it. All
* other values have -EINVAL returned if they are passed in.
*/
if (count > 0) {
if (buf[0] == '0') {
debugging = NO_DEBUG;
return count;
} else if (buf[0] == '1') {
debugging = 1;
return count;
}
}
return -EINVAL;
}

static ssize_t debug_flag_show(struct device_driver *ddp, char *buf)
{
return scnprintf(buf, PAGE_SIZE, "%d\n", debugging);
}
static DRIVER_ATTR_RW(debug_flag);
#endif

static struct attribute *st_drv_attrs[] = {
&driver_attr_try_direct_io.attr,
&driver_attr_fixed_buffer_size.attr,
&driver_attr_max_sg_segs.attr,
&driver_attr_version.attr,
#if DEBUG
&driver_attr_debug_flag.attr,
#endif
NULL,
};
ATTRIBUTE_GROUPS(st_drv);
Expand Down

0 comments on commit d9b43a1

Please sign in to comment.