Commit 3596b664 authored by Tejun Heo's avatar Tejun Heo Committed by Jens Axboe

ide-tape: unify r/w init paths

Impact: cleanup

Read and write init paths are almost identical.  Unify them into
idetape_init_rw().
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
parent 6cf3d545
...@@ -987,42 +987,50 @@ static void ide_tape_flush_merge_buffer(ide_drive_t *drive) ...@@ -987,42 +987,50 @@ static void ide_tape_flush_merge_buffer(ide_drive_t *drive)
tape->chrdev_dir = IDETAPE_DIR_NONE; tape->chrdev_dir = IDETAPE_DIR_NONE;
} }
static int idetape_init_read(ide_drive_t *drive) static int idetape_init_rw(ide_drive_t *drive, int dir)
{ {
idetape_tape_t *tape = drive->driver_data; idetape_tape_t *tape = drive->driver_data;
int bytes_read; int rc;
/* Initialize read operation */ BUG_ON(dir != IDETAPE_DIR_READ && dir != IDETAPE_DIR_WRITE);
if (tape->chrdev_dir != IDETAPE_DIR_READ) {
if (tape->chrdev_dir == IDETAPE_DIR_WRITE) {
ide_tape_flush_merge_buffer(drive);
idetape_flush_tape_buffers(drive);
}
if (tape->buf || tape->valid) {
printk(KERN_ERR "ide-tape: valid should be 0 now\n");
tape->valid = 0;
}
tape->buf = kmalloc(tape->buffer_size, GFP_KERNEL);
if (!tape->buf)
return -ENOMEM;
tape->chrdev_dir = IDETAPE_DIR_READ;
tape->cur = tape->buf;
/* if (tape->chrdev_dir == dir)
* Issue a read 0 command to ensure that DSC handshake is return 0;
* switched from completion mode to buffer available mode.
* No point in issuing this if DSC overlap isn't supported, some if (tape->chrdev_dir == IDETAPE_DIR_READ)
* drives (Seagate STT3401A) will return an error. ide_tape_discard_merge_buffer(drive, 1);
*/ else if (tape->chrdev_dir == IDETAPE_DIR_WRITE) {
if (drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) { ide_tape_flush_merge_buffer(drive);
bytes_read = idetape_queue_rw_tail(drive, idetape_flush_tape_buffers(drive);
REQ_IDETAPE_READ, 0); }
if (bytes_read < 0) {
kfree(tape->buf); if (tape->buf || tape->valid) {
tape->buf = NULL; printk(KERN_ERR "ide-tape: valid should be 0 now\n");
tape->chrdev_dir = IDETAPE_DIR_NONE; tape->valid = 0;
return bytes_read; }
}
tape->buf = kmalloc(tape->buffer_size, GFP_KERNEL);
if (!tape->buf)
return -ENOMEM;
tape->chrdev_dir = dir;
tape->cur = tape->buf;
/*
* Issue a 0 rw command to ensure that DSC handshake is
* switched from completion mode to buffer available mode. No
* point in issuing this if DSC overlap isn't supported, some
* drives (Seagate STT3401A) will return an error.
*/
if (drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) {
int cmd = dir == IDETAPE_DIR_READ ? REQ_IDETAPE_READ
: REQ_IDETAPE_WRITE;
rc = idetape_queue_rw_tail(drive, cmd, 0);
if (rc < 0) {
kfree(tape->buf);
tape->buf = NULL;
tape->chrdev_dir = IDETAPE_DIR_NONE;
return rc;
} }
} }
...@@ -1038,7 +1046,7 @@ static int idetape_add_chrdev_read_request(ide_drive_t *drive, int blocks) ...@@ -1038,7 +1046,7 @@ static int idetape_add_chrdev_read_request(ide_drive_t *drive, int blocks)
if (test_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags)) if (test_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags))
return 0; return 0;
idetape_init_read(drive); idetape_init_rw(drive, IDETAPE_DIR_READ);
return idetape_queue_rw_tail(drive, REQ_IDETAPE_READ, blocks); return idetape_queue_rw_tail(drive, REQ_IDETAPE_READ, blocks);
} }
...@@ -1195,7 +1203,7 @@ static ssize_t idetape_chrdev_read(struct file *file, char __user *buf, ...@@ -1195,7 +1203,7 @@ static ssize_t idetape_chrdev_read(struct file *file, char __user *buf,
(count % tape->blk_size) == 0) (count % tape->blk_size) == 0)
tape->user_bs_factor = count / tape->blk_size; tape->user_bs_factor = count / tape->blk_size;
} }
rc = idetape_init_read(drive); rc = idetape_init_rw(drive, IDETAPE_DIR_READ);
if (rc < 0) if (rc < 0)
return rc; return rc;
if (count == 0) if (count == 0)
...@@ -1249,6 +1257,7 @@ static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf, ...@@ -1249,6 +1257,7 @@ static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf,
ssize_t actually_written = 0; ssize_t actually_written = 0;
ssize_t ret = 0; ssize_t ret = 0;
u16 ctl = *(u16 *)&tape->caps[12]; u16 ctl = *(u16 *)&tape->caps[12];
int rc;
/* The drive is write protected. */ /* The drive is write protected. */
if (tape->write_prot) if (tape->write_prot)
...@@ -1257,36 +1266,9 @@ static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf, ...@@ -1257,36 +1266,9 @@ static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf,
debug_log(DBG_CHRDEV, "Enter %s, count %Zd\n", __func__, count); debug_log(DBG_CHRDEV, "Enter %s, count %Zd\n", __func__, count);
/* Initialize write operation */ /* Initialize write operation */
if (tape->chrdev_dir != IDETAPE_DIR_WRITE) { rc = idetape_init_rw(drive, IDETAPE_DIR_WRITE);
if (tape->chrdev_dir == IDETAPE_DIR_READ) if (rc < 0)
ide_tape_discard_merge_buffer(drive, 1); return rc;
if (tape->buf || tape->valid) {
printk(KERN_ERR "ide-tape: valid should be 0 now\n");
tape->valid = 0;
}
tape->buf = kmalloc(tape->buffer_size, GFP_KERNEL);
if (!tape->buf)
return -ENOMEM;
tape->chrdev_dir = IDETAPE_DIR_WRITE;
tape->cur = tape->buf;
/*
* Issue a write 0 command to ensure that DSC handshake is
* switched from completion mode to buffer available mode. No
* point in issuing this if DSC overlap isn't supported, some
* drives (Seagate STT3401A) will return an error.
*/
if (drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) {
ssize_t retval = idetape_queue_rw_tail(drive,
REQ_IDETAPE_WRITE, 0);
if (retval < 0) {
kfree(tape->buf);
tape->buf = NULL;
tape->chrdev_dir = IDETAPE_DIR_NONE;
return retval;
}
}
}
if (count == 0) if (count == 0)
return (0); return (0);
if (tape->valid < tape->buffer_size) { if (tape->valid < tape->buffer_size) {
......
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