Commit b30d8bca authored by Hannes Reinecke's avatar Hannes Reinecke Committed by Christoph Hellwig

scsi: Implement st_printk()

Update the st driver to use dev_printk() variants instead of
plain printk(); this will prefix logging messages with the
appropriate device.
Signed-off-by: default avatarHannes Reinecke <hare@suse.de>
Reviewed-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
parent 28c31729
...@@ -58,11 +58,11 @@ static const char *verstr = "20101219"; ...@@ -58,11 +58,11 @@ static const char *verstr = "20101219";
is defined and non-zero. */ is defined and non-zero. */
#define DEBUG 0 #define DEBUG 0
#define ST_DEB_MSG KERN_NOTICE
#if DEBUG #if DEBUG
/* The message level for the debug messages is currently set to KERN_NOTICE /* The message level for the debug messages is currently set to KERN_NOTICE
so that people can easily see the messages. Later when the debugging messages so that people can easily see the messages. Later when the debugging messages
in the drivers are more widely classified, this may be changed to KERN_DEBUG. */ in the drivers are more widely classified, this may be changed to KERN_DEBUG. */
#define ST_DEB_MSG KERN_NOTICE
#define DEB(a) a #define DEB(a) a
#define DEBC(a) if (debugging) { a ; } #define DEBC(a) if (debugging) { a ; }
#else #else
...@@ -305,6 +305,15 @@ static inline char *tape_name(struct scsi_tape *tape) ...@@ -305,6 +305,15 @@ static inline char *tape_name(struct scsi_tape *tape)
return tape->disk->disk_name; return tape->disk->disk_name;
} }
#define st_printk(prefix, t, fmt, a...) \
sdev_printk(prefix, (t)->device, "%s: " fmt, \
tape_name(t), ##a)
#ifdef DEBUG
#define DEBC_printk(t, fmt, a...) \
if (debugging) { st_printk(ST_DEB_MSG, t, fmt, ##a ); }
#else
#define DEBC_printk(t, fmt, a...)
#endif
static void st_analyze_sense(struct st_request *SRpnt, struct st_cmdstatus *s) static void st_analyze_sense(struct st_request *SRpnt, struct st_cmdstatus *s)
{ {
...@@ -358,21 +367,20 @@ static int st_chk_result(struct scsi_tape *STp, struct st_request * SRpnt) ...@@ -358,21 +367,20 @@ static int st_chk_result(struct scsi_tape *STp, struct st_request * SRpnt)
else else
scode = 0; scode = 0;
DEB( DEB(
if (debugging) { if (debugging) {
printk(ST_DEB_MSG "%s: Error: %x, cmd: %x %x %x %x %x %x\n", st_printk(ST_DEB_MSG, STp,
name, result, "Error: %x, cmd: %x %x %x %x %x %x\n", result,
SRpnt->cmd[0], SRpnt->cmd[1], SRpnt->cmd[2], SRpnt->cmd[0], SRpnt->cmd[1], SRpnt->cmd[2],
SRpnt->cmd[3], SRpnt->cmd[4], SRpnt->cmd[5]); SRpnt->cmd[3], SRpnt->cmd[4], SRpnt->cmd[5]);
if (cmdstatp->have_sense) if (cmdstatp->have_sense)
__scsi_print_sense(name, SRpnt->sense, SCSI_SENSE_BUFFERSIZE); __scsi_print_sense(name, SRpnt->sense, SCSI_SENSE_BUFFERSIZE);
} ) /* end DEB */ } ) /* end DEB */
if (!debugging) { /* Abnormal conditions for tape */ if (!debugging) { /* Abnormal conditions for tape */
if (!cmdstatp->have_sense) if (!cmdstatp->have_sense)
printk(KERN_WARNING st_printk(KERN_WARNING, STp,
"%s: Error %x (driver bt 0x%x, host bt 0x%x).\n", "Error %x (driver bt 0x%x, host bt 0x%x).\n",
name, result, driver_byte(result), result, driver_byte(result), host_byte(result));
host_byte(result));
else if (cmdstatp->have_sense && else if (cmdstatp->have_sense &&
scode != NO_SENSE && scode != NO_SENSE &&
scode != RECOVERED_ERROR && scode != RECOVERED_ERROR &&
...@@ -411,7 +419,7 @@ static int st_chk_result(struct scsi_tape *STp, struct st_request * SRpnt) ...@@ -411,7 +419,7 @@ static int st_chk_result(struct scsi_tape *STp, struct st_request * SRpnt)
STp->recover_count++; STp->recover_count++;
STp->recover_reg++; STp->recover_reg++;
DEB( DEB(
if (debugging) { if (debugging) {
if (SRpnt->cmd[0] == READ_6) if (SRpnt->cmd[0] == READ_6)
stp = "read"; stp = "read";
...@@ -419,8 +427,9 @@ static int st_chk_result(struct scsi_tape *STp, struct st_request * SRpnt) ...@@ -419,8 +427,9 @@ static int st_chk_result(struct scsi_tape *STp, struct st_request * SRpnt)
stp = "write"; stp = "write";
else else
stp = "ioctl"; stp = "ioctl";
printk(ST_DEB_MSG "%s: Recovered %s error (%d).\n", name, stp, st_printk(ST_DEB_MSG, STp,
STp->recover_count); "Recovered %s error (%d).\n",
stp, STp->recover_count);
} ) /* end DEB */ } ) /* end DEB */
if (cmdstatp->flags == 0) if (cmdstatp->flags == 0)
...@@ -437,8 +446,8 @@ static struct st_request *st_allocate_request(struct scsi_tape *stp) ...@@ -437,8 +446,8 @@ static struct st_request *st_allocate_request(struct scsi_tape *stp)
if (streq) if (streq)
streq->stp = stp; streq->stp = stp;
else { else {
DEBC(printk(KERN_ERR "%s: Can't get SCSI request.\n", st_printk(KERN_ERR, stp,
tape_name(stp));); "Can't get SCSI request.\n");
if (signal_pending(current)) if (signal_pending(current))
stp->buffer->syscall_result = -EINTR; stp->buffer->syscall_result = -EINTR;
else else
...@@ -525,8 +534,8 @@ st_do_scsi(struct st_request * SRpnt, struct scsi_tape * STp, unsigned char *cmd ...@@ -525,8 +534,8 @@ st_do_scsi(struct st_request * SRpnt, struct scsi_tape * STp, unsigned char *cmd
/* if async, make sure there's no command outstanding */ /* if async, make sure there's no command outstanding */
if (!do_wait && ((STp->buffer)->last_SRpnt)) { if (!do_wait && ((STp->buffer)->last_SRpnt)) {
printk(KERN_ERR "%s: Async command already active.\n", st_printk(KERN_ERR, STp,
tape_name(STp)); "Async command already active.\n");
if (signal_pending(current)) if (signal_pending(current))
(STp->buffer)->syscall_result = (-EINTR); (STp->buffer)->syscall_result = (-EINTR);
else else
...@@ -597,12 +606,12 @@ static int write_behind_check(struct scsi_tape * STp) ...@@ -597,12 +606,12 @@ static int write_behind_check(struct scsi_tape * STp)
if (!STbuffer->writing) if (!STbuffer->writing)
return 0; return 0;
DEB( DEB(
if (STp->write_pending) if (STp->write_pending)
STp->nbr_waits++; STp->nbr_waits++;
else else
STp->nbr_finished++; STp->nbr_finished++;
) /* end DEB */ ) /* end DEB */
wait_for_completion(&(STp->wait)); wait_for_completion(&(STp->wait));
SRpnt = STbuffer->last_SRpnt; SRpnt = STbuffer->last_SRpnt;
...@@ -639,8 +648,9 @@ static int write_behind_check(struct scsi_tape * STp) ...@@ -639,8 +648,9 @@ static int write_behind_check(struct scsi_tape * STp)
STbuffer->writing = 0; STbuffer->writing = 0;
DEB(if (debugging && retval) DEB(if (debugging && retval)
printk(ST_DEB_MSG "%s: Async write error %x, return value %d.\n", st_printk(ST_DEB_MSG, STp,
tape_name(STp), STbuffer->cmdstat.midlevel_result, retval);) /* end DEB */ "Async write error %x, return value %d.\n",
STbuffer->cmdstat.midlevel_result, retval);) /* end DEB */
return retval; return retval;
} }
...@@ -662,8 +672,8 @@ static int cross_eof(struct scsi_tape * STp, int forward) ...@@ -662,8 +672,8 @@ static int cross_eof(struct scsi_tape * STp, int forward)
cmd[2] = cmd[3] = cmd[4] = 0xff; /* -1 filemarks */ cmd[2] = cmd[3] = cmd[4] = 0xff; /* -1 filemarks */
cmd[5] = 0; cmd[5] = 0;
DEBC(printk(ST_DEB_MSG "%s: Stepping over filemark %s.\n", DEBC_printk(STp, "Stepping over filemark %s.\n",
tape_name(STp), forward ? "forward" : "backward")); forward ? "forward" : "backward");
SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE, SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE,
STp->device->request_queue->rq_timeout, STp->device->request_queue->rq_timeout,
...@@ -675,8 +685,9 @@ static int cross_eof(struct scsi_tape * STp, int forward) ...@@ -675,8 +685,9 @@ static int cross_eof(struct scsi_tape * STp, int forward)
SRpnt = NULL; SRpnt = NULL;
if ((STp->buffer)->cmdstat.midlevel_result != 0) if ((STp->buffer)->cmdstat.midlevel_result != 0)
printk(KERN_ERR "%s: Stepping over filemark %s failed.\n", st_printk(KERN_ERR, STp,
tape_name(STp), forward ? "forward" : "backward"); "Stepping over filemark %s failed.\n",
forward ? "forward" : "backward");
return (STp->buffer)->syscall_result; return (STp->buffer)->syscall_result;
} }
...@@ -699,8 +710,7 @@ static int st_flush_write_buffer(struct scsi_tape * STp) ...@@ -699,8 +710,7 @@ static int st_flush_write_buffer(struct scsi_tape * STp)
if (STp->dirty == 1) { if (STp->dirty == 1) {
transfer = STp->buffer->buffer_bytes; transfer = STp->buffer->buffer_bytes;
DEBC(printk(ST_DEB_MSG "%s: Flushing %d bytes.\n", DEBC_printk(STp, "Flushing %d bytes.\n", transfer);
tape_name(STp), transfer));
memset(cmd, 0, MAX_COMMAND_SIZE); memset(cmd, 0, MAX_COMMAND_SIZE);
cmd[0] = WRITE_6; cmd[0] = WRITE_6;
...@@ -732,8 +742,7 @@ static int st_flush_write_buffer(struct scsi_tape * STp) ...@@ -732,8 +742,7 @@ static int st_flush_write_buffer(struct scsi_tape * STp)
STps->drv_block += blks; STps->drv_block += blks;
result = (-ENOSPC); result = (-ENOSPC);
} else { } else {
printk(KERN_ERR "%s: Error on flush.\n", st_printk(KERN_ERR, STp, "Error on flush.\n");
tape_name(STp));
STps->drv_block = (-1); STps->drv_block = (-1);
result = (-EIO); result = (-EIO);
} }
...@@ -811,7 +820,6 @@ static int set_mode_densblk(struct scsi_tape * STp, struct st_modedef * STm) ...@@ -811,7 +820,6 @@ static int set_mode_densblk(struct scsi_tape * STp, struct st_modedef * STm)
{ {
int set_it = 0; int set_it = 0;
unsigned long arg; unsigned long arg;
char *name = tape_name(STp);
if (!STp->density_changed && if (!STp->density_changed &&
STm->default_density >= 0 && STm->default_density >= 0 &&
...@@ -830,9 +838,10 @@ static int set_mode_densblk(struct scsi_tape * STp, struct st_modedef * STm) ...@@ -830,9 +838,10 @@ static int set_mode_densblk(struct scsi_tape * STp, struct st_modedef * STm)
arg |= STp->block_size; arg |= STp->block_size;
if (set_it && if (set_it &&
st_int_ioctl(STp, SET_DENS_AND_BLK, arg)) { st_int_ioctl(STp, SET_DENS_AND_BLK, arg)) {
printk(KERN_WARNING st_printk(KERN_WARNING, STp,
"%s: Can't set default block size to %d bytes and density %x.\n", "Can't set default block size to %d bytes "
name, STm->default_blksize, STm->default_density); "and density %x.\n",
STm->default_blksize, STm->default_density);
if (modes_defined) if (modes_defined)
return (-EINVAL); return (-EINVAL);
} }
...@@ -844,12 +853,9 @@ static int set_mode_densblk(struct scsi_tape * STp, struct st_modedef * STm) ...@@ -844,12 +853,9 @@ static int set_mode_densblk(struct scsi_tape * STp, struct st_modedef * STm)
static int do_door_lock(struct scsi_tape * STp, int do_lock) static int do_door_lock(struct scsi_tape * STp, int do_lock)
{ {
int retval, cmd; int retval, cmd;
DEB(char *name = tape_name(STp);)
cmd = do_lock ? SCSI_IOCTL_DOORLOCK : SCSI_IOCTL_DOORUNLOCK; cmd = do_lock ? SCSI_IOCTL_DOORLOCK : SCSI_IOCTL_DOORUNLOCK;
DEBC(printk(ST_DEB_MSG "%s: %socking drive door.\n", name, DEBC_printk(STp, "%socking drive door.\n", do_lock ? "L" : "Unl");
do_lock ? "L" : "Unl"));
retval = scsi_ioctl(STp->device, cmd, NULL); retval = scsi_ioctl(STp->device, cmd, NULL);
if (!retval) { if (!retval) {
STp->door_locked = do_lock ? ST_LOCKED_EXPLICIT : ST_UNLOCKED; STp->door_locked = do_lock ? ST_LOCKED_EXPLICIT : ST_UNLOCKED;
...@@ -976,15 +982,14 @@ static int check_tape(struct scsi_tape *STp, struct file *filp) ...@@ -976,15 +982,14 @@ static int check_tape(struct scsi_tape *STp, struct file *filp)
struct st_request *SRpnt = NULL; struct st_request *SRpnt = NULL;
struct st_modedef *STm; struct st_modedef *STm;
struct st_partstat *STps; struct st_partstat *STps;
char *name = tape_name(STp);
struct inode *inode = file_inode(filp); struct inode *inode = file_inode(filp);
int mode = TAPE_MODE(inode); int mode = TAPE_MODE(inode);
STp->ready = ST_READY; STp->ready = ST_READY;
if (mode != STp->current_mode) { if (mode != STp->current_mode) {
DEBC(printk(ST_DEB_MSG "%s: Mode change from %d to %d.\n", DEBC_printk(STp, "Mode change from %d to %d.\n",
name, STp->current_mode, mode)); STp->current_mode, mode);
new_session = 1; new_session = 1;
STp->current_mode = mode; STp->current_mode = mode;
} }
...@@ -1055,13 +1060,12 @@ static int check_tape(struct scsi_tape *STp, struct file *filp) ...@@ -1055,13 +1060,12 @@ static int check_tape(struct scsi_tape *STp, struct file *filp)
STp->min_block = ((STp->buffer)->b_data[4] << 8) | STp->min_block = ((STp->buffer)->b_data[4] << 8) |
(STp->buffer)->b_data[5]; (STp->buffer)->b_data[5];
if ( DEB( debugging || ) !STp->inited) if ( DEB( debugging || ) !STp->inited)
printk(KERN_INFO st_printk(KERN_INFO, STp,
"%s: Block limits %d - %d bytes.\n", name, "Block limits %d - %d bytes.\n",
STp->min_block, STp->max_block); STp->min_block, STp->max_block);
} else { } else {
STp->min_block = STp->max_block = (-1); STp->min_block = STp->max_block = (-1);
DEBC(printk(ST_DEB_MSG "%s: Can't read block limits.\n", DEBC_printk(STp, "Can't read block limits.\n");
name));
} }
} }
...@@ -1078,56 +1082,58 @@ static int check_tape(struct scsi_tape *STp, struct file *filp) ...@@ -1078,56 +1082,58 @@ static int check_tape(struct scsi_tape *STp, struct file *filp)
} }
if ((STp->buffer)->syscall_result != 0) { if ((STp->buffer)->syscall_result != 0) {
DEBC(printk(ST_DEB_MSG "%s: No Mode Sense.\n", name)); DEBC_printk(STp, "No Mode Sense.\n");
STp->block_size = ST_DEFAULT_BLOCK; /* Educated guess (?) */ STp->block_size = ST_DEFAULT_BLOCK; /* Educated guess (?) */
(STp->buffer)->syscall_result = 0; /* Prevent error propagation */ (STp->buffer)->syscall_result = 0; /* Prevent error propagation */
STp->drv_write_prot = 0; STp->drv_write_prot = 0;
} else { } else {
DEBC(printk(ST_DEB_MSG DEBC_printk(STp,"Mode sense. Length %d, "
"%s: Mode sense. Length %d, medium %x, WBS %x, BLL %d\n", "medium %x, WBS %x, BLL %d\n",
name, (STp->buffer)->b_data[0],
(STp->buffer)->b_data[0], (STp->buffer)->b_data[1], (STp->buffer)->b_data[1],
(STp->buffer)->b_data[2], (STp->buffer)->b_data[3])); (STp->buffer)->b_data[2],
(STp->buffer)->b_data[3]);
if ((STp->buffer)->b_data[3] >= 8) { if ((STp->buffer)->b_data[3] >= 8) {
STp->drv_buffer = ((STp->buffer)->b_data[2] >> 4) & 7; STp->drv_buffer = ((STp->buffer)->b_data[2] >> 4) & 7;
STp->density = (STp->buffer)->b_data[4]; STp->density = (STp->buffer)->b_data[4];
STp->block_size = (STp->buffer)->b_data[9] * 65536 + STp->block_size = (STp->buffer)->b_data[9] * 65536 +
(STp->buffer)->b_data[10] * 256 + (STp->buffer)->b_data[11]; (STp->buffer)->b_data[10] * 256 + (STp->buffer)->b_data[11];
DEBC(printk(ST_DEB_MSG DEBC_printk(STp, "Density %x, tape length: %x, "
"%s: Density %x, tape length: %x, drv buffer: %d\n", "drv buffer: %d\n",
name, STp->density, (STp->buffer)->b_data[5] * 65536 + STp->density,
(STp->buffer)->b_data[6] * 256 + (STp->buffer)->b_data[7], (STp->buffer)->b_data[5] * 65536 +
STp->drv_buffer)); (STp->buffer)->b_data[6] * 256 +
(STp->buffer)->b_data[7],
STp->drv_buffer);
} }
STp->drv_write_prot = ((STp->buffer)->b_data[2] & 0x80) != 0; STp->drv_write_prot = ((STp->buffer)->b_data[2] & 0x80) != 0;
if (!STp->drv_buffer && STp->immediate_filemark) { if (!STp->drv_buffer && STp->immediate_filemark) {
printk(KERN_WARNING st_printk(KERN_WARNING, STp,
"%s: non-buffered tape: disabling writing immediate filemarks\n", "non-buffered tape: disabling "
name); "writing immediate filemarks\n");
STp->immediate_filemark = 0; STp->immediate_filemark = 0;
} }
} }
st_release_request(SRpnt); st_release_request(SRpnt);
SRpnt = NULL; SRpnt = NULL;
STp->inited = 1; STp->inited = 1;
if (STp->block_size > 0) if (STp->block_size > 0)
(STp->buffer)->buffer_blocks = (STp->buffer)->buffer_blocks =
(STp->buffer)->buffer_size / STp->block_size; (STp->buffer)->buffer_size / STp->block_size;
else else
(STp->buffer)->buffer_blocks = 1; (STp->buffer)->buffer_blocks = 1;
(STp->buffer)->buffer_bytes = (STp->buffer)->read_pointer = 0; (STp->buffer)->buffer_bytes = (STp->buffer)->read_pointer = 0;
DEBC(printk(ST_DEB_MSG DEBC_printk(STp, "Block size: %d, buffer size: %d (%d blocks).\n",
"%s: Block size: %d, buffer size: %d (%d blocks).\n", name, STp->block_size, (STp->buffer)->buffer_size,
STp->block_size, (STp->buffer)->buffer_size, (STp->buffer)->buffer_blocks);
(STp->buffer)->buffer_blocks));
if (STp->drv_write_prot) { if (STp->drv_write_prot) {
STp->write_prot = 1; STp->write_prot = 1;
DEBC(printk(ST_DEB_MSG "%s: Write protected\n", name)); DEBC_printk(STp, "Write protected\n");
if (do_wait && if (do_wait &&
((st_flags & O_ACCMODE) == O_WRONLY || ((st_flags & O_ACCMODE) == O_WRONLY ||
...@@ -1141,8 +1147,7 @@ static int check_tape(struct scsi_tape *STp, struct file *filp) ...@@ -1141,8 +1147,7 @@ static int check_tape(struct scsi_tape *STp, struct file *filp)
/* This code is reached when the device is opened for the first time /* This code is reached when the device is opened for the first time
after the driver has been initialized with tape in the drive and the after the driver has been initialized with tape in the drive and the
partition support has been enabled. */ partition support has been enabled. */
DEBC(printk(ST_DEB_MSG DEBC_printk(STp, "Updating partition number in status.\n");
"%s: Updating partition number in status.\n", name));
if ((STp->partition = find_partition(STp)) < 0) { if ((STp->partition = find_partition(STp)) < 0) {
retval = STp->partition; retval = STp->partition;
goto err_out; goto err_out;
...@@ -1160,9 +1165,10 @@ static int check_tape(struct scsi_tape *STp, struct file *filp) ...@@ -1160,9 +1165,10 @@ static int check_tape(struct scsi_tape *STp, struct file *filp)
if (STp->default_drvbuffer != 0xff) { if (STp->default_drvbuffer != 0xff) {
if (st_int_ioctl(STp, MTSETDRVBUFFER, STp->default_drvbuffer)) if (st_int_ioctl(STp, MTSETDRVBUFFER, STp->default_drvbuffer))
printk(KERN_WARNING st_printk(KERN_WARNING, STp,
"%s: Can't set default drive buffering to %d.\n", "Can't set default drive "
name, STp->default_drvbuffer); "buffering to %d.\n",
STp->default_drvbuffer);
} }
} }
...@@ -1182,7 +1188,6 @@ static int st_open(struct inode *inode, struct file *filp) ...@@ -1182,7 +1188,6 @@ static int st_open(struct inode *inode, struct file *filp)
struct scsi_tape *STp; struct scsi_tape *STp;
struct st_partstat *STps; struct st_partstat *STps;
int dev = TAPE_NR(inode); int dev = TAPE_NR(inode);
char *name;
/* /*
* We really want to do nonseekable_open(inode, filp); here, but some * We really want to do nonseekable_open(inode, filp); here, but some
...@@ -1196,13 +1201,12 @@ static int st_open(struct inode *inode, struct file *filp) ...@@ -1196,13 +1201,12 @@ static int st_open(struct inode *inode, struct file *filp)
} }
filp->private_data = STp; filp->private_data = STp;
name = tape_name(STp);
spin_lock(&st_use_lock); spin_lock(&st_use_lock);
if (STp->in_use) { if (STp->in_use) {
spin_unlock(&st_use_lock); spin_unlock(&st_use_lock);
scsi_tape_put(STp); scsi_tape_put(STp);
DEB( printk(ST_DEB_MSG "%s: Device already in use.\n", name); ) DEBC_printk(STp, "Device already in use.\n");
return (-EBUSY); return (-EBUSY);
} }
...@@ -1222,8 +1226,8 @@ static int st_open(struct inode *inode, struct file *filp) ...@@ -1222,8 +1226,8 @@ static int st_open(struct inode *inode, struct file *filp)
/* See that we have at least a one page buffer available */ /* See that we have at least a one page buffer available */
if (!enlarge_buffer(STp->buffer, PAGE_SIZE, STp->restr_dma)) { if (!enlarge_buffer(STp->buffer, PAGE_SIZE, STp->restr_dma)) {
printk(KERN_WARNING "%s: Can't allocate one page tape buffer.\n", st_printk(KERN_WARNING, STp,
name); "Can't allocate one page tape buffer.\n");
retval = (-EOVERFLOW); retval = (-EOVERFLOW);
goto err_out; goto err_out;
} }
...@@ -1279,7 +1283,6 @@ static int st_flush(struct file *filp, fl_owner_t id) ...@@ -1279,7 +1283,6 @@ static int st_flush(struct file *filp, fl_owner_t id)
struct scsi_tape *STp = filp->private_data; struct scsi_tape *STp = filp->private_data;
struct st_modedef *STm = &(STp->modes[STp->current_mode]); struct st_modedef *STm = &(STp->modes[STp->current_mode]);
struct st_partstat *STps = &(STp->ps[STp->partition]); struct st_partstat *STps = &(STp->ps[STp->partition]);
char *name = tape_name(STp);
if (file_count(filp) > 1) if (file_count(filp) > 1)
return 0; return 0;
...@@ -1292,24 +1295,25 @@ static int st_flush(struct file *filp, fl_owner_t id) ...@@ -1292,24 +1295,25 @@ static int st_flush(struct file *filp, fl_owner_t id)
if (STp->can_partitions && if (STp->can_partitions &&
(result2 = switch_partition(STp)) < 0) { (result2 = switch_partition(STp)) < 0) {
DEBC(printk(ST_DEB_MSG DEBC_printk(STp, "switch_partition at close failed.\n");
"%s: switch_partition at close failed.\n", name));
if (result == 0) if (result == 0)
result = result2; result = result2;
goto out; goto out;
} }
DEBC( if (STp->nbr_requests) DEBC( if (STp->nbr_requests)
printk(KERN_DEBUG "%s: Number of r/w requests %d, dio used in %d, pages %d.\n", st_printk(KERN_DEBUG, STp,
name, STp->nbr_requests, STp->nbr_dio, STp->nbr_pages)); "Number of r/w requests %d, dio used in %d, "
"pages %d.\n", STp->nbr_requests, STp->nbr_dio,
STp->nbr_pages));
if (STps->rw == ST_WRITING && !STp->pos_unknown) { if (STps->rw == ST_WRITING && !STp->pos_unknown) {
struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat;
DEBC(printk(ST_DEB_MSG "%s: Async write waits %d, finished %d.\n", #if DEBUG
name, STp->nbr_waits, STp->nbr_finished); DEBC_printk(STp, "Async write waits %d, finished %d.\n",
) STp->nbr_waits, STp->nbr_finished);
#endif
memset(cmd, 0, MAX_COMMAND_SIZE); memset(cmd, 0, MAX_COMMAND_SIZE);
cmd[0] = WRITE_FILEMARKS; cmd[0] = WRITE_FILEMARKS;
if (STp->immediate_filemark) if (STp->immediate_filemark)
...@@ -1343,13 +1347,13 @@ static int st_flush(struct file *filp, fl_owner_t id) ...@@ -1343,13 +1347,13 @@ static int st_flush(struct file *filp, fl_owner_t id)
else { /* Write error */ else { /* Write error */
st_release_request(SRpnt); st_release_request(SRpnt);
SRpnt = NULL; SRpnt = NULL;
printk(KERN_ERR "%s: Error on write filemark.\n", name); st_printk(KERN_ERR, STp,
"Error on write filemark.\n");
if (result == 0) if (result == 0)
result = (-EIO); result = (-EIO);
} }
DEBC(printk(ST_DEB_MSG "%s: Buffer flushed, %d EOF(s) written\n", DEBC_printk(STp, "Buffer flushed, %d EOF(s) written\n", cmd[4]);
name, cmd[4]));
} else if (!STp->rew_at_close) { } else if (!STp->rew_at_close) {
STps = &(STp->ps[STp->partition]); STps = &(STp->ps[STp->partition]);
if (!STm->sysv || STps->rw != ST_READING) { if (!STm->sysv || STps->rw != ST_READING) {
...@@ -1447,9 +1451,10 @@ static ssize_t rw_checks(struct scsi_tape *STp, struct file *filp, size_t count) ...@@ -1447,9 +1451,10 @@ static ssize_t rw_checks(struct scsi_tape *STp, struct file *filp, size_t count)
if (count == 0) if (count == 0)
goto out; goto out;
DEB( DEB(
if (!STp->in_use) { if (!STp->in_use) {
printk(ST_DEB_MSG "%s: Incorrect device.\n", tape_name(STp)); st_printk(ST_DEB_MSG, STp,
"Incorrect device.\n");
retval = (-EIO); retval = (-EIO);
goto out; goto out;
} ) /* end DEB */ } ) /* end DEB */
...@@ -1519,8 +1524,9 @@ static int setup_buffering(struct scsi_tape *STp, const char __user *buf, ...@@ -1519,8 +1524,9 @@ static int setup_buffering(struct scsi_tape *STp, const char __user *buf,
if (bufsize > STbp->buffer_size && if (bufsize > STbp->buffer_size &&
!enlarge_buffer(STbp, bufsize, STp->restr_dma)) { !enlarge_buffer(STbp, bufsize, STp->restr_dma)) {
printk(KERN_WARNING "%s: Can't allocate %d byte tape buffer.\n", st_printk(KERN_WARNING, STp,
tape_name(STp), bufsize); "Can't allocate %d byte tape buffer.\n",
bufsize);
retval = (-EOVERFLOW); retval = (-EOVERFLOW);
goto out; goto out;
} }
...@@ -1563,7 +1569,6 @@ st_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos) ...@@ -1563,7 +1569,6 @@ st_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos)
struct st_modedef *STm; struct st_modedef *STm;
struct st_partstat *STps; struct st_partstat *STps;
struct st_buffer *STbp; struct st_buffer *STbp;
char *name = tape_name(STp);
if (mutex_lock_interruptible(&STp->lock)) if (mutex_lock_interruptible(&STp->lock))
return -ERESTARTSYS; return -ERESTARTSYS;
...@@ -1574,8 +1579,8 @@ st_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos) ...@@ -1574,8 +1579,8 @@ st_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos)
/* Write must be integral number of blocks */ /* Write must be integral number of blocks */
if (STp->block_size != 0 && (count % STp->block_size) != 0) { if (STp->block_size != 0 && (count % STp->block_size) != 0) {
printk(KERN_WARNING "%s: Write not multiple of tape block size.\n", st_printk(KERN_WARNING, STp,
name); "Write not multiple of tape block size.\n");
retval = (-EINVAL); retval = (-EINVAL);
goto out; goto out;
} }
...@@ -1601,8 +1606,8 @@ st_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos) ...@@ -1601,8 +1606,8 @@ st_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos)
if (STm->default_compression != ST_DONT_TOUCH && if (STm->default_compression != ST_DONT_TOUCH &&
!(STp->compression_changed)) { !(STp->compression_changed)) {
if (st_compression(STp, (STm->default_compression == ST_YES))) { if (st_compression(STp, (STm->default_compression == ST_YES))) {
printk(KERN_WARNING "%s: Can't set default compression.\n", st_printk(KERN_WARNING, STp,
name); "Can't set default compression.\n");
if (modes_defined) { if (modes_defined) {
retval = (-EINVAL); retval = (-EINVAL);
goto out; goto out;
...@@ -1723,7 +1728,7 @@ st_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos) ...@@ -1723,7 +1728,7 @@ st_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos)
if (STbp->syscall_result != 0) { if (STbp->syscall_result != 0) {
struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat;
DEBC(printk(ST_DEB_MSG "%s: Error on write:\n", name)); DEBC_printk(STp, "Error on write:\n");
if (cmdstatp->have_sense && (cmdstatp->flags & SENSE_EOM)) { if (cmdstatp->have_sense && (cmdstatp->flags & SENSE_EOM)) {
scode = cmdstatp->sense_hdr.sense_key; scode = cmdstatp->sense_hdr.sense_key;
if (cmdstatp->remainder_valid) if (cmdstatp->remainder_valid)
...@@ -1750,9 +1755,9 @@ st_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos) ...@@ -1750,9 +1755,9 @@ st_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos)
if (STp->block_size == 0 || if (STp->block_size == 0 ||
undone > 0 || count == 0) undone > 0 || count == 0)
retval = (-ENOSPC); /* EOM within current request */ retval = (-ENOSPC); /* EOM within current request */
DEBC(printk(ST_DEB_MSG DEBC_printk(STp, "EOM with %d "
"%s: EOM with %d bytes unwritten.\n", "bytes unwritten.\n",
name, (int)count)); (int)count);
} else { } else {
/* EOT within data buffered earlier (possible only /* EOT within data buffered earlier (possible only
in fixed block mode without direct i/o) */ in fixed block mode without direct i/o) */
...@@ -1765,9 +1770,10 @@ st_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos) ...@@ -1765,9 +1770,10 @@ st_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos)
STp->block_size; STp->block_size;
} }
STps->eof = ST_EOM_OK; STps->eof = ST_EOM_OK;
DEBC(printk(ST_DEB_MSG DEBC_printk(STp, "Retry "
"%s: Retry write of %d bytes at EOM.\n", "write of %d "
name, STp->buffer->buffer_bytes)); "bytes at EOM.\n",
STp->buffer->buffer_bytes);
goto retry_write; goto retry_write;
} }
else { else {
...@@ -1778,9 +1784,8 @@ st_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos) ...@@ -1778,9 +1784,8 @@ st_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos)
STps->eof = ST_EOM_ERROR; STps->eof = ST_EOM_ERROR;
STps->drv_block = (-1); /* Too cautious? */ STps->drv_block = (-1); /* Too cautious? */
retval = (-EIO); /* EOM for old data */ retval = (-EIO); /* EOM for old data */
DEBC(printk(ST_DEB_MSG DEBC_printk(STp, "EOM with "
"%s: EOM with lost data.\n", "lost data.\n");
name));
} }
} }
} else { } else {
...@@ -1839,7 +1844,6 @@ static long read_tape(struct scsi_tape *STp, long count, ...@@ -1839,7 +1844,6 @@ static long read_tape(struct scsi_tape *STp, long count,
struct st_partstat *STps; struct st_partstat *STps;
struct st_buffer *STbp; struct st_buffer *STbp;
int retval = 0; int retval = 0;
char *name = tape_name(STp);
if (count == 0) if (count == 0)
return 0; return 0;
...@@ -1891,12 +1895,12 @@ static long read_tape(struct scsi_tape *STp, long count, ...@@ -1891,12 +1895,12 @@ static long read_tape(struct scsi_tape *STp, long count,
struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat;
retval = 1; retval = 1;
DEBC(printk(ST_DEB_MSG "%s: Sense: %2x %2x %2x %2x %2x %2x %2x %2x\n", DEBC_printk(STp,
name, "Sense: %2x %2x %2x %2x %2x %2x %2x %2x\n",
SRpnt->sense[0], SRpnt->sense[1], SRpnt->sense[0], SRpnt->sense[1],
SRpnt->sense[2], SRpnt->sense[3], SRpnt->sense[2], SRpnt->sense[3],
SRpnt->sense[4], SRpnt->sense[5], SRpnt->sense[4], SRpnt->sense[5],
SRpnt->sense[6], SRpnt->sense[7])); SRpnt->sense[6], SRpnt->sense[7]);
if (cmdstatp->have_sense) { if (cmdstatp->have_sense) {
if (cmdstatp->sense_hdr.sense_key == BLANK_CHECK) if (cmdstatp->sense_hdr.sense_key == BLANK_CHECK)
...@@ -1913,23 +1917,27 @@ static long read_tape(struct scsi_tape *STp, long count, ...@@ -1913,23 +1917,27 @@ static long read_tape(struct scsi_tape *STp, long count,
transfer = bytes; transfer = bytes;
if (cmdstatp->flags & SENSE_ILI) { /* ILI */ if (cmdstatp->flags & SENSE_ILI) { /* ILI */
if (STp->block_size == 0) { if (STp->block_size == 0 &&
if (transfer <= 0) { transfer < 0) {
if (transfer < 0) st_printk(KERN_NOTICE, STp,
printk(KERN_NOTICE "Failed to read %d "
"%s: Failed to read %d byte block with %d byte transfer.\n", "byte block with %d "
name, bytes - transfer, bytes); "byte transfer.\n",
if (STps->drv_block >= 0) bytes - transfer,
STps->drv_block += 1; bytes);
STbp->buffer_bytes = 0; if (STps->drv_block >= 0)
return (-ENOMEM); STps->drv_block += 1;
} STbp->buffer_bytes = 0;
return (-ENOMEM);
} else if (STp->block_size == 0) {
STbp->buffer_bytes = bytes - transfer; STbp->buffer_bytes = bytes - transfer;
} else { } else {
st_release_request(SRpnt); st_release_request(SRpnt);
SRpnt = *aSRpnt = NULL; SRpnt = *aSRpnt = NULL;
if (transfer == blks) { /* We did not get anything, error */ if (transfer == blks) { /* We did not get anything, error */
printk(KERN_NOTICE "%s: Incorrect block size.\n", name); st_printk(KERN_NOTICE, STp,
"Incorrect "
"block size.\n");
if (STps->drv_block >= 0) if (STps->drv_block >= 0)
STps->drv_block += blks - transfer + 1; STps->drv_block += blks - transfer + 1;
st_int_ioctl(STp, MTBSR, 1); st_int_ioctl(STp, MTBSR, 1);
...@@ -1938,9 +1946,11 @@ static long read_tape(struct scsi_tape *STp, long count, ...@@ -1938,9 +1946,11 @@ static long read_tape(struct scsi_tape *STp, long count,
/* We have some data, deliver it */ /* We have some data, deliver it */
STbp->buffer_bytes = (blks - transfer) * STbp->buffer_bytes = (blks - transfer) *
STp->block_size; STp->block_size;
DEBC(printk(ST_DEB_MSG DEBC_printk(STp, "ILI but "
"%s: ILI but enough data received %ld %d.\n", "enough data "
name, count, STbp->buffer_bytes)); "received %ld "
"%d.\n", count,
STbp->buffer_bytes);
if (STps->drv_block >= 0) if (STps->drv_block >= 0)
STps->drv_block += 1; STps->drv_block += 1;
if (st_int_ioctl(STp, MTBSR, 1)) if (st_int_ioctl(STp, MTBSR, 1))
...@@ -1956,9 +1966,9 @@ static long read_tape(struct scsi_tape *STp, long count, ...@@ -1956,9 +1966,9 @@ static long read_tape(struct scsi_tape *STp, long count,
else else
STbp->buffer_bytes = STbp->buffer_bytes =
bytes - transfer * STp->block_size; bytes - transfer * STp->block_size;
DEBC(printk(ST_DEB_MSG DEBC_printk(STp, "EOF detected (%d "
"%s: EOF detected (%d bytes read).\n", "bytes read).\n",
name, STbp->buffer_bytes)); STbp->buffer_bytes);
} else if (cmdstatp->flags & SENSE_EOM) { } else if (cmdstatp->flags & SENSE_EOM) {
if (STps->eof == ST_FM) if (STps->eof == ST_FM)
STps->eof = ST_EOD_1; STps->eof = ST_EOD_1;
...@@ -1970,20 +1980,20 @@ static long read_tape(struct scsi_tape *STp, long count, ...@@ -1970,20 +1980,20 @@ static long read_tape(struct scsi_tape *STp, long count,
STbp->buffer_bytes = STbp->buffer_bytes =
bytes - transfer * STp->block_size; bytes - transfer * STp->block_size;
DEBC(printk(ST_DEB_MSG "%s: EOM detected (%d bytes read).\n", DEBC_printk(STp, "EOM detected (%d "
name, STbp->buffer_bytes)); "bytes read).\n",
STbp->buffer_bytes);
} }
} }
/* end of EOF, EOM, ILI test */ /* end of EOF, EOM, ILI test */
else { /* nonzero sense key */ else { /* nonzero sense key */
DEBC(printk(ST_DEB_MSG DEBC_printk(STp, "Tape error while reading.\n");
"%s: Tape error while reading.\n", name));
STps->drv_block = (-1); STps->drv_block = (-1);
if (STps->eof == ST_FM && if (STps->eof == ST_FM &&
cmdstatp->sense_hdr.sense_key == BLANK_CHECK) { cmdstatp->sense_hdr.sense_key == BLANK_CHECK) {
DEBC(printk(ST_DEB_MSG DEBC_printk(STp, "Zero returned for "
"%s: Zero returned for first BLANK CHECK after EOF.\n", "first BLANK CHECK "
name)); "after EOF.\n");
STps->eof = ST_EOD_2; /* First BLANK_CHECK after FM */ STps->eof = ST_EOD_2; /* First BLANK_CHECK after FM */
} else /* Some other extended sense code */ } else /* Some other extended sense code */
retval = (-EIO); retval = (-EIO);
...@@ -1992,13 +2002,13 @@ static long read_tape(struct scsi_tape *STp, long count, ...@@ -1992,13 +2002,13 @@ static long read_tape(struct scsi_tape *STp, long count,
if (STbp->buffer_bytes < 0) /* Caused by bogus sense data */ if (STbp->buffer_bytes < 0) /* Caused by bogus sense data */
STbp->buffer_bytes = 0; STbp->buffer_bytes = 0;
} }
/* End of extended sense test */ /* End of extended sense test */
else { /* Non-extended sense */ else { /* Non-extended sense */
retval = STbp->syscall_result; retval = STbp->syscall_result;
} }
} }
/* End of error handling */ /* End of error handling */
else { /* Read successful */ else { /* Read successful */
STbp->buffer_bytes = bytes; STbp->buffer_bytes = bytes;
if (STp->sili) /* In fixed block mode residual is always zero here */ if (STp->sili) /* In fixed block mode residual is always zero here */
...@@ -2028,7 +2038,6 @@ st_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos) ...@@ -2028,7 +2038,6 @@ st_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos)
struct st_modedef *STm; struct st_modedef *STm;
struct st_partstat *STps; struct st_partstat *STps;
struct st_buffer *STbp = STp->buffer; struct st_buffer *STbp = STp->buffer;
DEB( char *name = tape_name(STp); )
if (mutex_lock_interruptible(&STp->lock)) if (mutex_lock_interruptible(&STp->lock))
return -ERESTARTSYS; return -ERESTARTSYS;
...@@ -2053,11 +2062,12 @@ st_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos) ...@@ -2053,11 +2062,12 @@ st_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos)
goto out; goto out;
STps->rw = ST_READING; STps->rw = ST_READING;
} }
DEB( DEB(
if (debugging && STps->eof != ST_NOEOF) if (debugging && STps->eof != ST_NOEOF)
printk(ST_DEB_MSG "%s: EOF/EOM flag up (%d). Bytes %d\n", name, st_printk(ST_DEB_MSG, STp,
STps->eof, STbp->buffer_bytes); "EOF/EOM flag up (%d). Bytes %d\n",
) /* end DEB */ STps->eof, STbp->buffer_bytes);
) /* end DEB */
retval = setup_buffering(STp, buf, count, 1); retval = setup_buffering(STp, buf, count, 1);
if (retval) if (retval)
...@@ -2104,13 +2114,13 @@ st_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos) ...@@ -2104,13 +2114,13 @@ st_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos)
/* Move the data from driver buffer to user buffer */ /* Move the data from driver buffer to user buffer */
if (STbp->buffer_bytes > 0) { if (STbp->buffer_bytes > 0) {
DEB( DEB(
if (debugging && STps->eof != ST_NOEOF) if (debugging && STps->eof != ST_NOEOF)
printk(ST_DEB_MSG st_printk(ST_DEB_MSG, STp,
"%s: EOF up (%d). Left %d, needed %d.\n", name, "EOF up (%d). Left %d, needed %d.\n",
STps->eof, STbp->buffer_bytes, STps->eof, STbp->buffer_bytes,
(int)(count - total)); (int)(count - total));
) /* end DEB */ ) /* end DEB */
transfer = STbp->buffer_bytes < count - total ? transfer = STbp->buffer_bytes < count - total ?
STbp->buffer_bytes : count - total; STbp->buffer_bytes : count - total;
if (!do_dio) { if (!do_dio) {
...@@ -2166,26 +2176,30 @@ st_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos) ...@@ -2166,26 +2176,30 @@ st_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos)
DEB( DEB(
/* Set the driver options */ /* Set the driver options */
static void st_log_options(struct scsi_tape * STp, struct st_modedef * STm, char *name) static void st_log_options(struct scsi_tape * STp, struct st_modedef * STm)
{ {
if (debugging) { if (debugging) {
printk(KERN_INFO st_printk(KERN_INFO, STp,
"%s: Mode %d options: buffer writes: %d, async writes: %d, read ahead: %d\n", "Mode %d options: buffer writes: %d, "
name, STp->current_mode, STm->do_buffer_writes, STm->do_async_writes, "async writes: %d, read ahead: %d\n",
STm->do_read_ahead); STp->current_mode, STm->do_buffer_writes,
printk(KERN_INFO STm->do_async_writes, STm->do_read_ahead);
"%s: can bsr: %d, two FMs: %d, fast mteom: %d, auto lock: %d,\n", st_printk(KERN_INFO, STp,
name, STp->can_bsr, STp->two_fm, STp->fast_mteom, STp->do_auto_lock); " can bsr: %d, two FMs: %d, "
printk(KERN_INFO "fast mteom: %d, auto lock: %d,\n",
"%s: defs for wr: %d, no block limits: %d, partitions: %d, s2 log: %d\n", STp->can_bsr, STp->two_fm, STp->fast_mteom,
name, STm->defaults_for_writes, STp->omit_blklims, STp->can_partitions, STp->do_auto_lock);
STp->scsi2_logical); st_printk(KERN_INFO, STp,
printk(KERN_INFO " defs for wr: %d, no block limits: %d, "
"%s: sysv: %d nowait: %d sili: %d nowait_filemark: %d\n", "partitions: %d, s2 log: %d\n",
name, STm->sysv, STp->immediate, STp->sili, STm->defaults_for_writes, STp->omit_blklims,
STp->immediate_filemark); STp->can_partitions, STp->scsi2_logical);
printk(KERN_INFO "%s: debugging: %d\n", st_printk(KERN_INFO, STp,
name, debugging); " sysv: %d nowait: %d sili: %d "
"nowait_filemark: %d\n",
STm->sysv, STp->immediate, STp->sili,
STp->immediate_filemark);
st_printk(KERN_INFO, STp, " debugging: %d\n", debugging);
} }
} }
) )
...@@ -2196,7 +2210,6 @@ static int st_set_options(struct scsi_tape *STp, long options) ...@@ -2196,7 +2210,6 @@ static int st_set_options(struct scsi_tape *STp, long options)
int value; int value;
long code; long code;
struct st_modedef *STm; struct st_modedef *STm;
char *name = tape_name(STp);
struct cdev *cd0, *cd1; struct cdev *cd0, *cd1;
struct device *d0, *d1; struct device *d0, *d1;
...@@ -2212,9 +2225,8 @@ static int st_set_options(struct scsi_tape *STp, long options) ...@@ -2212,9 +2225,8 @@ static int st_set_options(struct scsi_tape *STp, long options)
STm->devs[0] = d0; STm->devs[0] = d0;
STm->devs[1] = d1; STm->devs[1] = d1;
modes_defined = 1; modes_defined = 1;
DEBC(printk(ST_DEB_MSG DEBC_printk(STp, "Initialized mode %d definition from mode 0\n",
"%s: Initialized mode %d definition from mode 0\n", STp->current_mode);
name, STp->current_mode));
} }
code = options & MT_ST_OPTIONS; code = options & MT_ST_OPTIONS;
...@@ -2236,7 +2248,7 @@ static int st_set_options(struct scsi_tape *STp, long options) ...@@ -2236,7 +2248,7 @@ static int st_set_options(struct scsi_tape *STp, long options)
STm->sysv = (options & MT_ST_SYSV) != 0; STm->sysv = (options & MT_ST_SYSV) != 0;
STp->sili = (options & MT_ST_SILI) != 0; STp->sili = (options & MT_ST_SILI) != 0;
DEB( debugging = (options & MT_ST_DEBUGGING) != 0; DEB( debugging = (options & MT_ST_DEBUGGING) != 0;
st_log_options(STp, STm, name); ) st_log_options(STp, STm); )
} else if (code == MT_ST_SETBOOLEANS || code == MT_ST_CLEARBOOLEANS) { } else if (code == MT_ST_SETBOOLEANS || code == MT_ST_CLEARBOOLEANS) {
value = (code == MT_ST_SETBOOLEANS); value = (code == MT_ST_SETBOOLEANS);
if ((options & MT_ST_BUFFER_WRITES) != 0) if ((options & MT_ST_BUFFER_WRITES) != 0)
...@@ -2270,21 +2282,21 @@ static int st_set_options(struct scsi_tape *STp, long options) ...@@ -2270,21 +2282,21 @@ static int st_set_options(struct scsi_tape *STp, long options)
STm->sysv = value; STm->sysv = value;
if ((options & MT_ST_SILI) != 0) if ((options & MT_ST_SILI) != 0)
STp->sili = value; STp->sili = value;
DEB( DEB(
if ((options & MT_ST_DEBUGGING) != 0) if ((options & MT_ST_DEBUGGING) != 0)
debugging = value; debugging = value;
st_log_options(STp, STm, name); ) st_log_options(STp, STm); )
} else if (code == MT_ST_WRITE_THRESHOLD) { } else if (code == MT_ST_WRITE_THRESHOLD) {
/* Retained for compatibility */ /* Retained for compatibility */
} else if (code == MT_ST_DEF_BLKSIZE) { } else if (code == MT_ST_DEF_BLKSIZE) {
value = (options & ~MT_ST_OPTIONS); value = (options & ~MT_ST_OPTIONS);
if (value == ~MT_ST_OPTIONS) { if (value == ~MT_ST_OPTIONS) {
STm->default_blksize = (-1); STm->default_blksize = (-1);
DEBC( printk(KERN_INFO "%s: Default block size disabled.\n", name)); DEBC_printk(STp, "Default block size disabled.\n");
} else { } else {
STm->default_blksize = value; STm->default_blksize = value;
DEBC( printk(KERN_INFO "%s: Default block size set to %d bytes.\n", DEBC_printk(STp,"Default block size set to "
name, STm->default_blksize)); "%d bytes.\n", STm->default_blksize);
if (STp->ready == ST_READY) { if (STp->ready == ST_READY) {
STp->blksize_changed = 0; STp->blksize_changed = 0;
set_mode_densblk(STp, STm); set_mode_densblk(STp, STm);
...@@ -2294,13 +2306,13 @@ static int st_set_options(struct scsi_tape *STp, long options) ...@@ -2294,13 +2306,13 @@ static int st_set_options(struct scsi_tape *STp, long options)
value = (options & ~MT_ST_OPTIONS); value = (options & ~MT_ST_OPTIONS);
if ((value & MT_ST_SET_LONG_TIMEOUT) != 0) { if ((value & MT_ST_SET_LONG_TIMEOUT) != 0) {
STp->long_timeout = (value & ~MT_ST_SET_LONG_TIMEOUT) * HZ; STp->long_timeout = (value & ~MT_ST_SET_LONG_TIMEOUT) * HZ;
DEBC( printk(KERN_INFO "%s: Long timeout set to %d seconds.\n", name, DEBC_printk(STp, "Long timeout set to %d seconds.\n",
(value & ~MT_ST_SET_LONG_TIMEOUT))); (value & ~MT_ST_SET_LONG_TIMEOUT));
} else { } else {
blk_queue_rq_timeout(STp->device->request_queue, blk_queue_rq_timeout(STp->device->request_queue,
value * HZ); value * HZ);
DEBC( printk(KERN_INFO "%s: Normal timeout set to %d seconds.\n", DEBC_printk(STp, "Normal timeout set to %d seconds.\n",
name, value) ); value);
} }
} else if (code == MT_ST_SET_CLN) { } else if (code == MT_ST_SET_CLN) {
value = (options & ~MT_ST_OPTIONS) & 0xff; value = (options & ~MT_ST_OPTIONS) & 0xff;
...@@ -2311,21 +2323,21 @@ static int st_set_options(struct scsi_tape *STp, long options) ...@@ -2311,21 +2323,21 @@ static int st_set_options(struct scsi_tape *STp, long options)
STp->cln_mode = value; STp->cln_mode = value;
STp->cln_sense_mask = (options >> 8) & 0xff; STp->cln_sense_mask = (options >> 8) & 0xff;
STp->cln_sense_value = (options >> 16) & 0xff; STp->cln_sense_value = (options >> 16) & 0xff;
printk(KERN_INFO st_printk(KERN_INFO, STp,
"%s: Cleaning request mode %d, mask %02x, value %02x\n", "Cleaning request mode %d, mask %02x, value %02x\n",
name, value, STp->cln_sense_mask, STp->cln_sense_value); value, STp->cln_sense_mask, STp->cln_sense_value);
} else if (code == MT_ST_DEF_OPTIONS) { } else if (code == MT_ST_DEF_OPTIONS) {
code = (options & ~MT_ST_CLEAR_DEFAULT); code = (options & ~MT_ST_CLEAR_DEFAULT);
value = (options & MT_ST_CLEAR_DEFAULT); value = (options & MT_ST_CLEAR_DEFAULT);
if (code == MT_ST_DEF_DENSITY) { if (code == MT_ST_DEF_DENSITY) {
if (value == MT_ST_CLEAR_DEFAULT) { if (value == MT_ST_CLEAR_DEFAULT) {
STm->default_density = (-1); STm->default_density = (-1);
DEBC( printk(KERN_INFO "%s: Density default disabled.\n", DEBC_printk(STp,
name)); "Density default disabled.\n");
} else { } else {
STm->default_density = value & 0xff; STm->default_density = value & 0xff;
DEBC( printk(KERN_INFO "%s: Density default set to %x\n", DEBC_printk(STp, "Density default set to %x\n",
name, STm->default_density)); STm->default_density);
if (STp->ready == ST_READY) { if (STp->ready == ST_READY) {
STp->density_changed = 0; STp->density_changed = 0;
set_mode_densblk(STp, STm); set_mode_densblk(STp, STm);
...@@ -2334,31 +2346,33 @@ static int st_set_options(struct scsi_tape *STp, long options) ...@@ -2334,31 +2346,33 @@ static int st_set_options(struct scsi_tape *STp, long options)
} else if (code == MT_ST_DEF_DRVBUFFER) { } else if (code == MT_ST_DEF_DRVBUFFER) {
if (value == MT_ST_CLEAR_DEFAULT) { if (value == MT_ST_CLEAR_DEFAULT) {
STp->default_drvbuffer = 0xff; STp->default_drvbuffer = 0xff;
DEBC( printk(KERN_INFO DEBC_printk(STp,
"%s: Drive buffer default disabled.\n", name)); "Drive buffer default disabled.\n");
} else { } else {
STp->default_drvbuffer = value & 7; STp->default_drvbuffer = value & 7;
DEBC( printk(KERN_INFO DEBC_printk(STp,
"%s: Drive buffer default set to %x\n", "Drive buffer default set to %x\n",
name, STp->default_drvbuffer)); STp->default_drvbuffer);
if (STp->ready == ST_READY) if (STp->ready == ST_READY)
st_int_ioctl(STp, MTSETDRVBUFFER, STp->default_drvbuffer); st_int_ioctl(STp, MTSETDRVBUFFER, STp->default_drvbuffer);
} }
} else if (code == MT_ST_DEF_COMPRESSION) { } else if (code == MT_ST_DEF_COMPRESSION) {
if (value == MT_ST_CLEAR_DEFAULT) { if (value == MT_ST_CLEAR_DEFAULT) {
STm->default_compression = ST_DONT_TOUCH; STm->default_compression = ST_DONT_TOUCH;
DEBC( printk(KERN_INFO DEBC_printk(STp,
"%s: Compression default disabled.\n", name)); "Compression default disabled.\n");
} else { } else {
if ((value & 0xff00) != 0) { if ((value & 0xff00) != 0) {
STp->c_algo = (value & 0xff00) >> 8; STp->c_algo = (value & 0xff00) >> 8;
DEBC( printk(KERN_INFO "%s: Compression algorithm set to 0x%x.\n", DEBC_printk(STp, "Compression "
name, STp->c_algo)); "algorithm set to 0x%x.\n",
STp->c_algo);
} }
if ((value & 0xff) != 0xff) { if ((value & 0xff) != 0xff) {
STm->default_compression = (value & 1 ? ST_YES : ST_NO); STm->default_compression = (value & 1 ? ST_YES : ST_NO);
DEBC( printk(KERN_INFO "%s: Compression default set to %x\n", DEBC_printk(STp, "Compression default "
name, (value & 1))); "set to %x\n",
(value & 1));
if (STp->ready == ST_READY) { if (STp->ready == ST_READY) {
STp->compression_changed = 0; STp->compression_changed = 0;
st_compression(STp, (STm->default_compression == ST_YES)); st_compression(STp, (STm->default_compression == ST_YES));
...@@ -2473,7 +2487,6 @@ static int st_compression(struct scsi_tape * STp, int state) ...@@ -2473,7 +2487,6 @@ static int st_compression(struct scsi_tape * STp, int state)
int retval; int retval;
int mpoffs; /* Offset to mode page start */ int mpoffs; /* Offset to mode page start */
unsigned char *b_data = (STp->buffer)->b_data; unsigned char *b_data = (STp->buffer)->b_data;
DEB( char *name = tape_name(STp); )
if (STp->ready != ST_READY) if (STp->ready != ST_READY)
return (-EIO); return (-EIO);
...@@ -2481,18 +2494,17 @@ static int st_compression(struct scsi_tape * STp, int state) ...@@ -2481,18 +2494,17 @@ static int st_compression(struct scsi_tape * STp, int state)
/* Read the current page contents */ /* Read the current page contents */
retval = read_mode_page(STp, COMPRESSION_PAGE, 0); retval = read_mode_page(STp, COMPRESSION_PAGE, 0);
if (retval) { if (retval) {
DEBC(printk(ST_DEB_MSG "%s: Compression mode page not supported.\n", DEBC_printk(STp, "Compression mode page not supported.\n");
name));
return (-EIO); return (-EIO);
} }
mpoffs = MODE_HEADER_LENGTH + b_data[MH_OFF_BDESCS_LENGTH]; mpoffs = MODE_HEADER_LENGTH + b_data[MH_OFF_BDESCS_LENGTH];
DEBC(printk(ST_DEB_MSG "%s: Compression state is %d.\n", name, DEBC_printk(STp, "Compression state is %d.\n",
(b_data[mpoffs + CP_OFF_DCE_DCC] & DCE_MASK ? 1 : 0))); (b_data[mpoffs + CP_OFF_DCE_DCC] & DCE_MASK ? 1 : 0));
/* Check if compression can be changed */ /* Check if compression can be changed */
if ((b_data[mpoffs + CP_OFF_DCE_DCC] & DCC_MASK) == 0) { if ((b_data[mpoffs + CP_OFF_DCE_DCC] & DCC_MASK) == 0) {
DEBC(printk(ST_DEB_MSG "%s: Compression not supported.\n", name)); DEBC_printk(STp, "Compression not supported.\n");
return (-EIO); return (-EIO);
} }
...@@ -2510,11 +2522,10 @@ static int st_compression(struct scsi_tape * STp, int state) ...@@ -2510,11 +2522,10 @@ static int st_compression(struct scsi_tape * STp, int state)
retval = write_mode_page(STp, COMPRESSION_PAGE, 0); retval = write_mode_page(STp, COMPRESSION_PAGE, 0);
if (retval) { if (retval) {
DEBC(printk(ST_DEB_MSG "%s: Compression change failed.\n", name)); DEBC_printk(STp, "Compression change failed.\n");
return (-EIO); return (-EIO);
} }
DEBC(printk(ST_DEB_MSG "%s: Compression state changed to %d.\n", DEBC_printk(STp, "Compression state changed to %d.\n", state);
name, state));
STp->compression_changed = 1; STp->compression_changed = 1;
return 0; return 0;
...@@ -2525,7 +2536,6 @@ static int st_compression(struct scsi_tape * STp, int state) ...@@ -2525,7 +2536,6 @@ static int st_compression(struct scsi_tape * STp, int state)
static int do_load_unload(struct scsi_tape *STp, struct file *filp, int load_code) static int do_load_unload(struct scsi_tape *STp, struct file *filp, int load_code)
{ {
int retval = (-EIO), timeout; int retval = (-EIO), timeout;
DEB( char *name = tape_name(STp); )
unsigned char cmd[MAX_COMMAND_SIZE]; unsigned char cmd[MAX_COMMAND_SIZE];
struct st_partstat *STps; struct st_partstat *STps;
struct st_request *SRpnt; struct st_request *SRpnt;
...@@ -2546,9 +2556,9 @@ static int do_load_unload(struct scsi_tape *STp, struct file *filp, int load_cod ...@@ -2546,9 +2556,9 @@ static int do_load_unload(struct scsi_tape *STp, struct file *filp, int load_cod
*/ */
if (load_code >= 1 + MT_ST_HPLOADER_OFFSET if (load_code >= 1 + MT_ST_HPLOADER_OFFSET
&& load_code <= 6 + MT_ST_HPLOADER_OFFSET) { && load_code <= 6 + MT_ST_HPLOADER_OFFSET) {
DEBC(printk(ST_DEB_MSG "%s: Enhanced %sload slot %2d.\n", DEBC_printk(STp, " Enhanced %sload slot %2d.\n",
name, (cmd[4]) ? "" : "un", (cmd[4]) ? "" : "un",
load_code - MT_ST_HPLOADER_OFFSET)); load_code - MT_ST_HPLOADER_OFFSET);
cmd[3] = load_code - MT_ST_HPLOADER_OFFSET; /* MediaID field of C1553A */ cmd[3] = load_code - MT_ST_HPLOADER_OFFSET; /* MediaID field of C1553A */
} }
if (STp->immediate) { if (STp->immediate) {
...@@ -2560,9 +2570,9 @@ static int do_load_unload(struct scsi_tape *STp, struct file *filp, int load_cod ...@@ -2560,9 +2570,9 @@ static int do_load_unload(struct scsi_tape *STp, struct file *filp, int load_cod
DEBC( DEBC(
if (!load_code) if (!load_code)
printk(ST_DEB_MSG "%s: Unloading tape.\n", name); st_printk(ST_DEB_MSG, STp, "Unloading tape.\n");
else else
printk(ST_DEB_MSG "%s: Loading tape.\n", name); st_printk(ST_DEB_MSG, STp, "Loading tape.\n");
); );
SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE, SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE,
...@@ -2597,17 +2607,24 @@ static int do_load_unload(struct scsi_tape *STp, struct file *filp, int load_cod ...@@ -2597,17 +2607,24 @@ static int do_load_unload(struct scsi_tape *STp, struct file *filp, int load_cod
#if DEBUG #if DEBUG
#define ST_DEB_FORWARD 0 #define ST_DEB_FORWARD 0
#define ST_DEB_BACKWARD 1 #define ST_DEB_BACKWARD 1
static void deb_space_print(char *name, int direction, char *units, unsigned char *cmd) static void deb_space_print(struct scsi_tape *STp, int direction, char *units, unsigned char *cmd)
{ {
s32 sc; s32 sc;
if (!debugging)
return;
sc = cmd[2] & 0x80 ? 0xff000000 : 0; sc = cmd[2] & 0x80 ? 0xff000000 : 0;
sc |= (cmd[2] << 16) | (cmd[3] << 8) | cmd[4]; sc |= (cmd[2] << 16) | (cmd[3] << 8) | cmd[4];
if (direction) if (direction)
sc = -sc; sc = -sc;
printk(ST_DEB_MSG "%s: Spacing tape %s over %d %s.\n", name, st_printk(ST_DEB_MSG, STp, "Spacing tape %s over %d %s.\n",
direction ? "backward" : "forward", sc, units); direction ? "backward" : "forward", sc, units);
} }
#else
#define ST_DEB_FORWARD 0
#define ST_DEB_BACKWARD 1
static void deb_space_print(struct scsi_tape *STp, int direction, char *units, unsigned char *cmd) {}
#endif #endif
...@@ -2623,7 +2640,6 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon ...@@ -2623,7 +2640,6 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon
struct st_partstat *STps; struct st_partstat *STps;
int fileno, blkno, at_sm, undone; int fileno, blkno, at_sm, undone;
int datalen = 0, direction = DMA_NONE; int datalen = 0, direction = DMA_NONE;
char *name = tape_name(STp);
WARN_ON(STp->buffer->do_dio != 0); WARN_ON(STp->buffer->do_dio != 0);
if (STp->ready != ST_READY) { if (STp->ready != ST_READY) {
...@@ -2648,7 +2664,7 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon ...@@ -2648,7 +2664,7 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon
cmd[2] = (arg >> 16); cmd[2] = (arg >> 16);
cmd[3] = (arg >> 8); cmd[3] = (arg >> 8);
cmd[4] = arg; cmd[4] = arg;
DEBC(deb_space_print(name, ST_DEB_FORWARD, "filemarks", cmd);) deb_space_print(STp, ST_DEB_FORWARD, "filemarks", cmd);
if (fileno >= 0) if (fileno >= 0)
fileno += arg; fileno += arg;
blkno = 0; blkno = 0;
...@@ -2663,7 +2679,7 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon ...@@ -2663,7 +2679,7 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon
cmd[2] = (ltmp >> 16); cmd[2] = (ltmp >> 16);
cmd[3] = (ltmp >> 8); cmd[3] = (ltmp >> 8);
cmd[4] = ltmp; cmd[4] = ltmp;
DEBC(deb_space_print(name, ST_DEB_BACKWARD, "filemarks", cmd);) deb_space_print(STp, ST_DEB_BACKWARD, "filemarks", cmd);
if (fileno >= 0) if (fileno >= 0)
fileno -= arg; fileno -= arg;
blkno = (-1); /* We can't know the block number */ blkno = (-1); /* We can't know the block number */
...@@ -2675,7 +2691,7 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon ...@@ -2675,7 +2691,7 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon
cmd[2] = (arg >> 16); cmd[2] = (arg >> 16);
cmd[3] = (arg >> 8); cmd[3] = (arg >> 8);
cmd[4] = arg; cmd[4] = arg;
DEBC(deb_space_print(name, ST_DEB_FORWARD, "blocks", cmd);) deb_space_print(STp, ST_DEB_FORWARD, "blocks", cmd);
if (blkno >= 0) if (blkno >= 0)
blkno += arg; blkno += arg;
at_sm &= (arg == 0); at_sm &= (arg == 0);
...@@ -2687,7 +2703,7 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon ...@@ -2687,7 +2703,7 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon
cmd[2] = (ltmp >> 16); cmd[2] = (ltmp >> 16);
cmd[3] = (ltmp >> 8); cmd[3] = (ltmp >> 8);
cmd[4] = ltmp; cmd[4] = ltmp;
DEBC(deb_space_print(name, ST_DEB_BACKWARD, "blocks", cmd);) deb_space_print(STp, ST_DEB_BACKWARD, "blocks", cmd);
if (blkno >= 0) if (blkno >= 0)
blkno -= arg; blkno -= arg;
at_sm &= (arg == 0); at_sm &= (arg == 0);
...@@ -2698,7 +2714,7 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon ...@@ -2698,7 +2714,7 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon
cmd[2] = (arg >> 16); cmd[2] = (arg >> 16);
cmd[3] = (arg >> 8); cmd[3] = (arg >> 8);
cmd[4] = arg; cmd[4] = arg;
DEBC(deb_space_print(name, ST_DEB_FORWARD, "setmarks", cmd);) deb_space_print(STp, ST_DEB_FORWARD, "setmarks", cmd);
if (arg != 0) { if (arg != 0) {
blkno = fileno = (-1); blkno = fileno = (-1);
at_sm = 1; at_sm = 1;
...@@ -2711,7 +2727,7 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon ...@@ -2711,7 +2727,7 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon
cmd[2] = (ltmp >> 16); cmd[2] = (ltmp >> 16);
cmd[3] = (ltmp >> 8); cmd[3] = (ltmp >> 8);
cmd[4] = ltmp; cmd[4] = ltmp;
DEBC(deb_space_print(name, ST_DEB_BACKWARD, "setmarks", cmd);) deb_space_print(STp, ST_DEB_BACKWARD, "setmarks", cmd);
if (arg != 0) { if (arg != 0) {
blkno = fileno = (-1); blkno = fileno = (-1);
at_sm = 1; at_sm = 1;
...@@ -2732,13 +2748,19 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon ...@@ -2732,13 +2748,19 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon
cmd[3] = (arg >> 8); cmd[3] = (arg >> 8);
cmd[4] = arg; cmd[4] = arg;
timeout = STp->device->request_queue->rq_timeout; timeout = STp->device->request_queue->rq_timeout;
DEBC( DEBC(
if (cmd_in != MTWSM) if (cmd_in != MTWSM)
printk(ST_DEB_MSG "%s: Writing %d filemarks.\n", name, st_printk(ST_DEB_MSG, STp,
cmd[2] * 65536 + cmd[3] * 256 + cmd[4]); "Writing %d filemarks.\n",
else cmd[2] * 65536 +
printk(ST_DEB_MSG "%s: Writing %d setmarks.\n", name, cmd[3] * 256 +
cmd[2] * 65536 + cmd[3] * 256 + cmd[4]); cmd[4]);
else
st_printk(ST_DEB_MSG, STp,
"Writing %d setmarks.\n",
cmd[2] * 65536 +
cmd[3] * 256 +
cmd[4]);
) )
if (fileno >= 0) if (fileno >= 0)
fileno += arg; fileno += arg;
...@@ -2751,11 +2773,11 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon ...@@ -2751,11 +2773,11 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon
cmd[1] = 1; /* Don't wait for completion */ cmd[1] = 1; /* Don't wait for completion */
timeout = STp->device->request_queue->rq_timeout; timeout = STp->device->request_queue->rq_timeout;
} }
DEBC(printk(ST_DEB_MSG "%s: Rewinding tape.\n", name)); DEBC_printk(STp, "Rewinding tape.\n");
fileno = blkno = at_sm = 0; fileno = blkno = at_sm = 0;
break; break;
case MTNOP: case MTNOP:
DEBC(printk(ST_DEB_MSG "%s: No op on tape.\n", name)); DEBC_printk(STp, "No op on tape.\n");
return 0; /* Should do something ? */ return 0; /* Should do something ? */
break; break;
case MTRETEN: case MTRETEN:
...@@ -2765,7 +2787,7 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon ...@@ -2765,7 +2787,7 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon
timeout = STp->device->request_queue->rq_timeout; timeout = STp->device->request_queue->rq_timeout;
} }
cmd[4] = 3; cmd[4] = 3;
DEBC(printk(ST_DEB_MSG "%s: Retensioning tape.\n", name)); DEBC_printk(STp, "Retensioning tape.\n");
fileno = blkno = at_sm = 0; fileno = blkno = at_sm = 0;
break; break;
case MTEOM: case MTEOM:
...@@ -2783,8 +2805,7 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon ...@@ -2783,8 +2805,7 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon
fileno = (-1); fileno = (-1);
cmd[0] = SPACE; cmd[0] = SPACE;
cmd[1] = 3; cmd[1] = 3;
DEBC(printk(ST_DEB_MSG "%s: Spacing to end of recorded medium.\n", DEBC_printk(STp, "Spacing to end of recorded medium.\n");
name));
blkno = -1; blkno = -1;
at_sm = 0; at_sm = 0;
break; break;
...@@ -2800,7 +2821,7 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon ...@@ -2800,7 +2821,7 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon
else else
timeout = STp->long_timeout * 8; timeout = STp->long_timeout * 8;
DEBC(printk(ST_DEB_MSG "%s: Erasing tape.\n", name)); DEBC_printk(STp, "Erasing tape.\n");
fileno = blkno = at_sm = 0; fileno = blkno = at_sm = 0;
break; break;
case MTSETBLK: /* Set block length */ case MTSETBLK: /* Set block length */
...@@ -2815,7 +2836,7 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon ...@@ -2815,7 +2836,7 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon
STp->max_block > 0 && STp->max_block > 0 &&
((arg & MT_ST_BLKSIZE_MASK) < STp->min_block || ((arg & MT_ST_BLKSIZE_MASK) < STp->min_block ||
(arg & MT_ST_BLKSIZE_MASK) > STp->max_block)) { (arg & MT_ST_BLKSIZE_MASK) > STp->max_block)) {
printk(KERN_WARNING "%s: Illegal block size.\n", name); st_printk(KERN_WARNING, STp, "Illegal block size.\n");
return (-EINVAL); return (-EINVAL);
} }
cmd[0] = MODE_SELECT; cmd[0] = MODE_SELECT;
...@@ -2848,21 +2869,21 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon ...@@ -2848,21 +2869,21 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon
(STp->buffer)->b_data[10] = (ltmp >> 8); (STp->buffer)->b_data[10] = (ltmp >> 8);
(STp->buffer)->b_data[11] = ltmp; (STp->buffer)->b_data[11] = ltmp;
timeout = STp->device->request_queue->rq_timeout; timeout = STp->device->request_queue->rq_timeout;
DEBC( DEBC(
if (cmd_in == MTSETBLK || cmd_in == SET_DENS_AND_BLK) if (cmd_in == MTSETBLK || cmd_in == SET_DENS_AND_BLK)
printk(ST_DEB_MSG st_printk(ST_DEB_MSG, STp,
"%s: Setting block size to %d bytes.\n", name, "Setting block size to %d bytes.\n",
(STp->buffer)->b_data[9] * 65536 + (STp->buffer)->b_data[9] * 65536 +
(STp->buffer)->b_data[10] * 256 + (STp->buffer)->b_data[10] * 256 +
(STp->buffer)->b_data[11]); (STp->buffer)->b_data[11]);
if (cmd_in == MTSETDENSITY || cmd_in == SET_DENS_AND_BLK) if (cmd_in == MTSETDENSITY || cmd_in == SET_DENS_AND_BLK)
printk(ST_DEB_MSG st_printk(ST_DEB_MSG, STp,
"%s: Setting density code to %x.\n", name, "Setting density code to %x.\n",
(STp->buffer)->b_data[4]); (STp->buffer)->b_data[4]);
if (cmd_in == MTSETDRVBUFFER) if (cmd_in == MTSETDRVBUFFER)
printk(ST_DEB_MSG st_printk(ST_DEB_MSG, STp,
"%s: Setting drive buffer code to %d.\n", name, "Setting drive buffer code to %d.\n",
((STp->buffer)->b_data[2] >> 4) & 7); ((STp->buffer)->b_data[2] >> 4) & 7);
) )
break; break;
default: default:
...@@ -3019,7 +3040,6 @@ static int get_location(struct scsi_tape *STp, unsigned int *block, int *partiti ...@@ -3019,7 +3040,6 @@ static int get_location(struct scsi_tape *STp, unsigned int *block, int *partiti
int result; int result;
unsigned char scmd[MAX_COMMAND_SIZE]; unsigned char scmd[MAX_COMMAND_SIZE];
struct st_request *SRpnt; struct st_request *SRpnt;
DEB( char *name = tape_name(STp); )
if (STp->ready != ST_READY) if (STp->ready != ST_READY)
return (-EIO); return (-EIO);
...@@ -3043,7 +3063,7 @@ static int get_location(struct scsi_tape *STp, unsigned int *block, int *partiti ...@@ -3043,7 +3063,7 @@ static int get_location(struct scsi_tape *STp, unsigned int *block, int *partiti
(STp->device->scsi_level >= SCSI_2 && (STp->device->scsi_level >= SCSI_2 &&
((STp->buffer)->b_data[0] & 4) != 0)) { ((STp->buffer)->b_data[0] & 4) != 0)) {
*block = *partition = 0; *block = *partition = 0;
DEBC(printk(ST_DEB_MSG "%s: Can't read tape position.\n", name)); DEBC_printk(STp, " Can't read tape position.\n");
result = (-EIO); result = (-EIO);
} else { } else {
result = 0; result = 0;
...@@ -3062,8 +3082,8 @@ static int get_location(struct scsi_tape *STp, unsigned int *block, int *partiti ...@@ -3062,8 +3082,8 @@ static int get_location(struct scsi_tape *STp, unsigned int *block, int *partiti
(STp->buffer)->b_data[1] == 0) /* BOP of partition 0 */ (STp->buffer)->b_data[1] == 0) /* BOP of partition 0 */
STp->ps[0].drv_block = STp->ps[0].drv_file = 0; STp->ps[0].drv_block = STp->ps[0].drv_file = 0;
} }
DEBC(printk(ST_DEB_MSG "%s: Got tape pos. blk %d part %d.\n", name, DEBC_printk(STp, "Got tape pos. blk %d part %d.\n",
*block, *partition)); *block, *partition);
} }
st_release_request(SRpnt); st_release_request(SRpnt);
SRpnt = NULL; SRpnt = NULL;
...@@ -3083,15 +3103,14 @@ static int set_location(struct scsi_tape *STp, unsigned int block, int partition ...@@ -3083,15 +3103,14 @@ static int set_location(struct scsi_tape *STp, unsigned int block, int partition
int timeout; int timeout;
unsigned char scmd[MAX_COMMAND_SIZE]; unsigned char scmd[MAX_COMMAND_SIZE];
struct st_request *SRpnt; struct st_request *SRpnt;
DEB( char *name = tape_name(STp); )
if (STp->ready != ST_READY) if (STp->ready != ST_READY)
return (-EIO); return (-EIO);
timeout = STp->long_timeout; timeout = STp->long_timeout;
STps = &(STp->ps[STp->partition]); STps = &(STp->ps[STp->partition]);
DEBC(printk(ST_DEB_MSG "%s: Setting block to %d and partition to %d.\n", DEBC_printk(STp, "Setting block to %d and partition to %d.\n",
name, block, partition)); block, partition);
DEB(if (partition < 0) DEB(if (partition < 0)
return (-EIO); ) return (-EIO); )
...@@ -3105,9 +3124,9 @@ static int set_location(struct scsi_tape *STp, unsigned int block, int partition ...@@ -3105,9 +3124,9 @@ static int set_location(struct scsi_tape *STp, unsigned int block, int partition
else { else {
STps->last_block_valid = 1; STps->last_block_valid = 1;
STps->last_block_visited = blk; STps->last_block_visited = blk;
DEBC(printk(ST_DEB_MSG DEBC_printk(STp, "Visited block %d for "
"%s: Visited block %d for partition %d saved.\n", "partition %d saved.\n",
name, blk, STp->partition)); blk, STp->partition);
} }
} }
...@@ -3129,9 +3148,9 @@ static int set_location(struct scsi_tape *STp, unsigned int block, int partition ...@@ -3129,9 +3148,9 @@ static int set_location(struct scsi_tape *STp, unsigned int block, int partition
if (STp->partition != partition) { if (STp->partition != partition) {
scmd[1] |= 2; scmd[1] |= 2;
scmd[8] = partition; scmd[8] = partition;
DEBC(printk(ST_DEB_MSG DEBC_printk(STp, "Trying to change partition "
"%s: Trying to change partition from %d to %d\n", "from %d to %d\n", STp->partition,
name, STp->partition, partition)); partition);
} }
} }
if (STp->immediate) { if (STp->immediate) {
...@@ -3222,7 +3241,6 @@ static int switch_partition(struct scsi_tape *STp) ...@@ -3222,7 +3241,6 @@ static int switch_partition(struct scsi_tape *STp)
static int nbr_partitions(struct scsi_tape *STp) static int nbr_partitions(struct scsi_tape *STp)
{ {
int result; int result;
DEB( char *name = tape_name(STp); )
if (STp->ready != ST_READY) if (STp->ready != ST_READY)
return (-EIO); return (-EIO);
...@@ -3230,13 +3248,12 @@ static int nbr_partitions(struct scsi_tape *STp) ...@@ -3230,13 +3248,12 @@ static int nbr_partitions(struct scsi_tape *STp)
result = read_mode_page(STp, PART_PAGE, 1); result = read_mode_page(STp, PART_PAGE, 1);
if (result) { if (result) {
DEBC(printk(ST_DEB_MSG "%s: Can't read medium partition page.\n", DEBC_printk(STp, "Can't read medium partition page.\n");
name));
result = (-EIO); result = (-EIO);
} else { } else {
result = (STp->buffer)->b_data[MODE_HEADER_LENGTH + result = (STp->buffer)->b_data[MODE_HEADER_LENGTH +
PP_OFF_NBR_ADD_PARTS] + 1; PP_OFF_NBR_ADD_PARTS] + 1;
DEBC(printk(ST_DEB_MSG "%s: Number of partitions %d.\n", name, result)); DEBC_printk(STp, "Number of partitions %d.\n", result);
} }
return result; return result;
...@@ -3264,21 +3281,20 @@ static int nbr_partitions(struct scsi_tape *STp) ...@@ -3264,21 +3281,20 @@ static int nbr_partitions(struct scsi_tape *STp)
*/ */
static int partition_tape(struct scsi_tape *STp, int size) static int partition_tape(struct scsi_tape *STp, int size)
{ {
char *name = tape_name(STp);
int result; int result;
int pgo, psd_cnt, psdo; int pgo, psd_cnt, psdo;
unsigned char *bp; unsigned char *bp;
result = read_mode_page(STp, PART_PAGE, 0); result = read_mode_page(STp, PART_PAGE, 0);
if (result) { if (result) {
DEBC(printk(ST_DEB_MSG "%s: Can't read partition mode page.\n", name)); DEBC_printk(STp, "Can't read partition mode page.\n");
return result; return result;
} }
/* The mode page is in the buffer. Let's modify it and write it. */ /* The mode page is in the buffer. Let's modify it and write it. */
bp = (STp->buffer)->b_data; bp = (STp->buffer)->b_data;
pgo = MODE_HEADER_LENGTH + bp[MH_OFF_BDESCS_LENGTH]; pgo = MODE_HEADER_LENGTH + bp[MH_OFF_BDESCS_LENGTH];
DEBC(printk(ST_DEB_MSG "%s: Partition page length is %d bytes.\n", DEBC_printk(STp, "Partition page length is %d bytes.\n",
name, bp[pgo + MP_OFF_PAGE_LENGTH] + 2)); bp[pgo + MP_OFF_PAGE_LENGTH] + 2);
psd_cnt = (bp[pgo + MP_OFF_PAGE_LENGTH] + 2 - PART_PAGE_FIXED_LENGTH) / 2; psd_cnt = (bp[pgo + MP_OFF_PAGE_LENGTH] + 2 - PART_PAGE_FIXED_LENGTH) / 2;
psdo = pgo + PART_PAGE_FIXED_LENGTH; psdo = pgo + PART_PAGE_FIXED_LENGTH;
...@@ -3288,25 +3304,23 @@ static int partition_tape(struct scsi_tape *STp, int size) ...@@ -3288,25 +3304,23 @@ static int partition_tape(struct scsi_tape *STp, int size)
} }
memset(bp + psdo, 0, bp[pgo + PP_OFF_NBR_ADD_PARTS] * 2); memset(bp + psdo, 0, bp[pgo + PP_OFF_NBR_ADD_PARTS] * 2);
DEBC(printk("%s: psd_cnt %d, max.parts %d, nbr_parts %d\n", name, DEBC_printk(STp, "psd_cnt %d, max.parts %d, nbr_parts %d\n",
psd_cnt, bp[pgo + PP_OFF_MAX_ADD_PARTS], psd_cnt, bp[pgo + PP_OFF_MAX_ADD_PARTS],
bp[pgo + PP_OFF_NBR_ADD_PARTS])); bp[pgo + PP_OFF_NBR_ADD_PARTS]);
if (size <= 0) { if (size <= 0) {
bp[pgo + PP_OFF_NBR_ADD_PARTS] = 0; bp[pgo + PP_OFF_NBR_ADD_PARTS] = 0;
if (psd_cnt <= bp[pgo + PP_OFF_MAX_ADD_PARTS]) if (psd_cnt <= bp[pgo + PP_OFF_MAX_ADD_PARTS])
bp[pgo + MP_OFF_PAGE_LENGTH] = 6; bp[pgo + MP_OFF_PAGE_LENGTH] = 6;
DEBC(printk(ST_DEB_MSG "%s: Formatting tape with one partition.\n", DEBC_printk(STp, "Formatting tape with one partition.\n");
name));
} else { } else {
bp[psdo] = (size >> 8) & 0xff; bp[psdo] = (size >> 8) & 0xff;
bp[psdo + 1] = size & 0xff; bp[psdo + 1] = size & 0xff;
bp[pgo + 3] = 1; bp[pgo + 3] = 1;
if (bp[pgo + MP_OFF_PAGE_LENGTH] < 8) if (bp[pgo + MP_OFF_PAGE_LENGTH] < 8)
bp[pgo + MP_OFF_PAGE_LENGTH] = 8; bp[pgo + MP_OFF_PAGE_LENGTH] = 8;
DEBC(printk(ST_DEB_MSG DEBC_printk(STp, "Formatting tape with two partitions "
"%s: Formatting tape with two partitions (1 = %d MB).\n", "(1 = %d MB).\n", size);
name, size));
} }
bp[pgo + PP_OFF_PART_UNITS] = 0; bp[pgo + PP_OFF_PART_UNITS] = 0;
bp[pgo + PP_OFF_RESERVED] = 0; bp[pgo + PP_OFF_RESERVED] = 0;
...@@ -3314,7 +3328,7 @@ static int partition_tape(struct scsi_tape *STp, int size) ...@@ -3314,7 +3328,7 @@ static int partition_tape(struct scsi_tape *STp, int size)
result = write_mode_page(STp, PART_PAGE, 1); result = write_mode_page(STp, PART_PAGE, 1);
if (result) { if (result) {
printk(KERN_INFO "%s: Partitioning of tape failed.\n", name); st_printk(KERN_INFO, STp, "Partitioning of tape failed.\n");
result = (-EIO); result = (-EIO);
} }
...@@ -3332,15 +3346,14 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg) ...@@ -3332,15 +3346,14 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg)
struct scsi_tape *STp = file->private_data; struct scsi_tape *STp = file->private_data;
struct st_modedef *STm; struct st_modedef *STm;
struct st_partstat *STps; struct st_partstat *STps;
char *name = tape_name(STp);
void __user *p = (void __user *)arg; void __user *p = (void __user *)arg;
if (mutex_lock_interruptible(&STp->lock)) if (mutex_lock_interruptible(&STp->lock))
return -ERESTARTSYS; return -ERESTARTSYS;
DEB( DEB(
if (debugging && !STp->in_use) { if (debugging && !STp->in_use) {
printk(ST_DEB_MSG "%s: Incorrect device.\n", name); st_printk(ST_DEB_MSG, STp, "Incorrect device.\n");
retval = (-EIO); retval = (-EIO);
goto out; goto out;
} ) /* end DEB */ } ) /* end DEB */
...@@ -3378,8 +3391,8 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg) ...@@ -3378,8 +3391,8 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg)
} }
if (mtc.mt_op == MTSETDRVBUFFER && !capable(CAP_SYS_ADMIN)) { if (mtc.mt_op == MTSETDRVBUFFER && !capable(CAP_SYS_ADMIN)) {
printk(KERN_WARNING st_printk(KERN_WARNING, STp,
"%s: MTSETDRVBUFFER only allowed for root.\n", name); "MTSETDRVBUFFER only allowed for root.\n");
retval = (-EPERM); retval = (-EPERM);
goto out; goto out;
} }
...@@ -4087,7 +4100,8 @@ static int st_probe(struct device *dev) ...@@ -4087,7 +4100,8 @@ static int st_probe(struct device *dev)
return -ENODEV; return -ENODEV;
if ((stp = st_incompatible(SDp))) { if ((stp = st_incompatible(SDp))) {
sdev_printk(KERN_INFO, SDp, "Found incompatible tape\n"); sdev_printk(KERN_INFO, SDp, "Found incompatible tape\n");
printk(KERN_INFO "st: The suggested driver is %s.\n", stp); sdev_printk(KERN_INFO, SDp,
"st: The suggested driver is %s.\n", stp);
return -ENODEV; return -ENODEV;
} }
...@@ -4096,20 +4110,23 @@ static int st_probe(struct device *dev) ...@@ -4096,20 +4110,23 @@ static int st_probe(struct device *dev)
i = st_max_sg_segs; i = st_max_sg_segs;
buffer = new_tape_buffer((SDp->host)->unchecked_isa_dma, i); buffer = new_tape_buffer((SDp->host)->unchecked_isa_dma, i);
if (buffer == NULL) { if (buffer == NULL) {
printk(KERN_ERR sdev_printk(KERN_ERR, SDp,
"st: Can't allocate new tape buffer. Device not attached.\n"); "st: Can't allocate new tape buffer. "
"Device not attached.\n");
goto out; goto out;
} }
disk = alloc_disk(1); disk = alloc_disk(1);
if (!disk) { if (!disk) {
printk(KERN_ERR "st: out of memory. Device not attached.\n"); sdev_printk(KERN_ERR, SDp,
"st: out of memory. Device not attached.\n");
goto out_buffer_free; goto out_buffer_free;
} }
tpnt = kzalloc(sizeof(struct scsi_tape), GFP_ATOMIC); tpnt = kzalloc(sizeof(struct scsi_tape), GFP_ATOMIC);
if (tpnt == NULL) { if (tpnt == NULL) {
printk(KERN_ERR "st: Can't allocate device descriptor.\n"); sdev_printk(KERN_ERR, SDp,
"st: Can't allocate device descriptor.\n");
goto out_put_disk; goto out_put_disk;
} }
kref_init(&tpnt->kref); kref_init(&tpnt->kref);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment