Commit 02558d08 authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] file->private_data in st.c and osst.c

	->open() of st and osst sets file->private_data to Scsi_Tape in
question, other methods use it (same as in sg.c)
parent 10e76361
...@@ -3075,7 +3075,6 @@ static int osst_write_frame(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, int sync ...@@ -3075,7 +3075,6 @@ static int osst_write_frame(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, int sync
/* Write command */ /* Write command */
static ssize_t osst_write(struct file * filp, const char * buf, size_t count, loff_t *ppos) static ssize_t osst_write(struct file * filp, const char * buf, size_t count, loff_t *ppos)
{ {
struct inode *inode = filp->f_dentry->d_inode;
ssize_t total, retval = 0; ssize_t total, retval = 0;
ssize_t i, do_count, blks, transfer; ssize_t i, do_count, blks, transfer;
int write_threshold; int write_threshold;
...@@ -3084,8 +3083,7 @@ static ssize_t osst_write(struct file * filp, const char * buf, size_t count, lo ...@@ -3084,8 +3083,7 @@ static ssize_t osst_write(struct file * filp, const char * buf, size_t count, lo
Scsi_Request * SRpnt = NULL; Scsi_Request * SRpnt = NULL;
ST_mode * STm; ST_mode * STm;
ST_partstat * STps; ST_partstat * STps;
int dev = TAPE_NR(inode->i_rdev); OS_Scsi_Tape * STp = filp->private_data;
OS_Scsi_Tape * STp = os_scsi_tapes[dev];
char *name = tape_name(STp); char *name = tape_name(STp);
...@@ -3404,15 +3402,13 @@ if (SRpnt) printk(KERN_ERR "%s:A: Not supposed to have SRpnt at line %d\n", name ...@@ -3404,15 +3402,13 @@ if (SRpnt) printk(KERN_ERR "%s:A: Not supposed to have SRpnt at line %d\n", name
/* Read command */ /* Read command */
static ssize_t osst_read(struct file * filp, char * buf, size_t count, loff_t *ppos) static ssize_t osst_read(struct file * filp, char * buf, size_t count, loff_t *ppos)
{ {
struct inode * inode = filp->f_dentry->d_inode;
ssize_t total, retval = 0; ssize_t total, retval = 0;
ssize_t i, transfer; ssize_t i, transfer;
int special; int special;
ST_mode * STm; ST_mode * STm;
ST_partstat * STps; ST_partstat * STps;
Scsi_Request *SRpnt = NULL; Scsi_Request *SRpnt = NULL;
int dev = TAPE_NR(inode->i_rdev); OS_Scsi_Tape * STp = filp->private_data;
OS_Scsi_Tape * STp = os_scsi_tapes[dev];
char *name = tape_name(STp); char *name = tape_name(STp);
...@@ -4169,6 +4165,7 @@ static int os_scsi_tape_open(struct inode * inode, struct file * filp) ...@@ -4169,6 +4165,7 @@ static int os_scsi_tape_open(struct inode * inode, struct file * filp)
if (dev >= osst_template.dev_max || (STp = os_scsi_tapes[dev]) == NULL || !STp->device) if (dev >= osst_template.dev_max || (STp = os_scsi_tapes[dev]) == NULL || !STp->device)
return (-ENXIO); return (-ENXIO);
filp->private_data = STp;
name = tape_name(STp); name = tape_name(STp);
if( !scsi_block_when_processing_errors(STp->device) ) { if( !scsi_block_when_processing_errors(STp->device) ) {
...@@ -4540,11 +4537,8 @@ static int os_scsi_tape_open(struct inode * inode, struct file * filp) ...@@ -4540,11 +4537,8 @@ static int os_scsi_tape_open(struct inode * inode, struct file * filp)
/* Flush the tape buffer before close */ /* Flush the tape buffer before close */
static int os_scsi_tape_flush(struct file * filp) static int os_scsi_tape_flush(struct file * filp)
{ {
struct inode *inode = filp->f_dentry->d_inode;
kdev_t devt = inode->i_rdev;
int dev = TAPE_NR(devt);
int result = 0, result2; int result = 0, result2;
OS_Scsi_Tape * STp = os_scsi_tapes[dev]; OS_Scsi_Tape * STp = filp->private_data;
ST_mode * STm = &(STp->modes[STp->current_mode]); ST_mode * STm = &(STp->modes[STp->current_mode]);
ST_partstat * STps = &(STp->ps[STp->partition]); ST_partstat * STps = &(STp->ps[STp->partition]);
Scsi_Request *SRpnt = NULL; Scsi_Request *SRpnt = NULL;
...@@ -4646,9 +4640,7 @@ static int os_scsi_tape_flush(struct file * filp) ...@@ -4646,9 +4640,7 @@ static int os_scsi_tape_flush(struct file * filp)
static int os_scsi_tape_close(struct inode * inode, struct file * filp) static int os_scsi_tape_close(struct inode * inode, struct file * filp)
{ {
int result = 0; int result = 0;
kdev_t devt = inode->i_rdev; OS_Scsi_Tape * STp = filp->private_data;
int dev = TAPE_NR(devt);
OS_Scsi_Tape * STp = os_scsi_tapes[dev];
Scsi_Request * SRpnt = NULL; Scsi_Request * SRpnt = NULL;
if (STp->door_locked == ST_LOCKED_AUTO) if (STp->door_locked == ST_LOCKED_AUTO)
...@@ -4682,8 +4674,7 @@ static int osst_ioctl(struct inode * inode,struct file * file, ...@@ -4682,8 +4674,7 @@ static int osst_ioctl(struct inode * inode,struct file * file,
ST_mode *STm; ST_mode *STm;
ST_partstat *STps; ST_partstat *STps;
Scsi_Request *SRpnt = NULL; Scsi_Request *SRpnt = NULL;
int dev = TAPE_NR(inode->i_rdev); OS_Scsi_Tape *STp = file->private_data;
OS_Scsi_Tape *STp = os_scsi_tapes[dev];
char *name = tape_name(STp); char *name = tape_name(STp);
if (down_interruptible(&STp->lock)) if (down_interruptible(&STp->lock))
...@@ -5579,9 +5570,10 @@ static int osst_init() ...@@ -5579,9 +5570,10 @@ static int osst_init()
{ {
int i; int i;
if (osst_template.dev_noticed == 0) return 0; if (osst_template.dev_noticed == 0)
return 0;
if(!osst_registered) { if (!osst_registered) {
if (register_chrdev(MAJOR_NR,"osst",&osst_fops)) { if (register_chrdev(MAJOR_NR,"osst",&osst_fops)) {
printk(KERN_ERR "osst :W: Unable to get major %d for OnStream tapes\n",MAJOR_NR); printk(KERN_ERR "osst :W: Unable to get major %d for OnStream tapes\n",MAJOR_NR);
return 1; return 1;
...@@ -5589,26 +5581,26 @@ static int osst_init() ...@@ -5589,26 +5581,26 @@ static int osst_init()
osst_registered++; osst_registered++;
} }
if (os_scsi_tapes) return 0; if (os_scsi_tapes)
return 0;
osst_template.dev_max = OSST_MAX_TAPES; osst_template.dev_max = OSST_MAX_TAPES;
if (osst_template.dev_max > 128 / ST_NBR_MODES) if (osst_template.dev_max > 128 / ST_NBR_MODES)
printk(KERN_INFO "osst :I: Only %d tapes accessible.\n", 128 / ST_NBR_MODES); printk(KERN_INFO "osst :I: Only %d tapes accessible.\n", 128 / ST_NBR_MODES);
os_scsi_tapes = os_scsi_tapes = kmalloc(osst_template.dev_max * sizeof(OS_Scsi_Tape *),
(OS_Scsi_Tape **)kmalloc(osst_template.dev_max * sizeof(OS_Scsi_Tape *),
GFP_ATOMIC); GFP_ATOMIC);
if (os_scsi_tapes == NULL) { if (!os_scsi_tapes) {
printk(KERN_ERR "osst :W: Unable to allocate array for OnStream SCSI tapes.\n"); printk(KERN_ERR "osst :W: Unable to allocate array for OnStream SCSI tapes.\n");
unregister_chrdev(MAJOR_NR, "osst"); unregister_chrdev(MAJOR_NR, "osst");
return 1; return 1;
} }
for (i=0; i < osst_template.dev_max; ++i) os_scsi_tapes[i] = NULL; for (i=0; i < osst_template.dev_max; ++i)
os_scsi_tapes[i] = NULL;
/* Allocate the buffer pointers */ /* Allocate the buffer pointers */
osst_buffers = osst_buffers = kmalloc(osst_template.dev_max * sizeof(OSST_buffer *),
(OSST_buffer **)kmalloc(osst_template.dev_max * sizeof(OSST_buffer *),
GFP_ATOMIC); GFP_ATOMIC);
if (osst_buffers == NULL) { if (!osst_buffers) {
printk(KERN_ERR "osst :W: Unable to allocate tape buffer pointers.\n"); printk(KERN_ERR "osst :W: Unable to allocate tape buffer pointers.\n");
unregister_chrdev(MAJOR_NR, "osst"); unregister_chrdev(MAJOR_NR, "osst");
kfree(os_scsi_tapes); kfree(os_scsi_tapes);
...@@ -5671,23 +5663,25 @@ static void __exit exit_osst (void) ...@@ -5671,23 +5663,25 @@ static void __exit exit_osst (void)
scsi_unregister_device(&osst_template); scsi_unregister_device(&osst_template);
unregister_chrdev(MAJOR_NR, "osst"); unregister_chrdev(MAJOR_NR, "osst");
osst_registered--; osst_registered--;
if(os_scsi_tapes != NULL) { if (os_scsi_tapes) {
for (i=0; i < osst_template.dev_max; ++i) { for (i=0; i < osst_template.dev_max; ++i) {
if ((STp = os_scsi_tapes[i])) { STp = os_scsi_tapes[i];
if (STp->header_cache != NULL) vfree(STp->header_cache); if (!STp)
continue;
if (STp->header_cache)
vfree(STp->header_cache);
kfree(STp); kfree(STp);
} }
}
kfree(os_scsi_tapes); kfree(os_scsi_tapes);
if (osst_buffers != NULL) { if (osst_buffers) {
for (i=0; i < osst_nbr_buffers; i++) for (i=0; i < osst_nbr_buffers; i++) {
if (osst_buffers[i] != NULL) { if (osst_buffers[i]) {
osst_buffers[i]->orig_sg_segs = 0; osst_buffers[i]->orig_sg_segs = 0;
normalize_buffer(osst_buffers[i]); normalize_buffer(osst_buffers[i]);
kfree(osst_buffers[i]); kfree(osst_buffers[i]);
} }
}
kfree(osst_buffers); kfree(osst_buffers);
} }
} }
......
...@@ -986,6 +986,7 @@ static int st_open(struct inode *inode, struct file *filp) ...@@ -986,6 +986,7 @@ static int st_open(struct inode *inode, struct file *filp)
write_unlock(&st_dev_arr_lock); write_unlock(&st_dev_arr_lock);
return (-ENXIO); return (-ENXIO);
} }
filp->private_data = STp;
name = tape_name(STp); name = tape_name(STp);
if (STp->in_use) { if (STp->in_use) {
...@@ -1052,26 +1053,16 @@ static int st_open(struct inode *inode, struct file *filp) ...@@ -1052,26 +1053,16 @@ static int st_open(struct inode *inode, struct file *filp)
static int st_flush(struct file *filp) static int st_flush(struct file *filp)
{ {
int result = 0, result2; int result = 0, result2;
struct inode *inode = filp->f_dentry->d_inode;
kdev_t devt = inode->i_rdev;
int dev = TAPE_NR(devt);
unsigned char cmd[MAX_COMMAND_SIZE]; unsigned char cmd[MAX_COMMAND_SIZE];
Scsi_Request *SRpnt; Scsi_Request *SRpnt;
Scsi_Tape *STp; Scsi_Tape *STp = filp->private_data;
ST_mode *STm; ST_mode *STm = &(STp->modes[STp->current_mode]);
ST_partstat *STps; ST_partstat *STps = &(STp->ps[STp->partition]);
char *name; char *name = tape_name(STp);
if (file_count(filp) > 1) if (file_count(filp) > 1)
return 0; return 0;
read_lock(&st_dev_arr_lock);
STp = scsi_tapes[dev];
read_unlock(&st_dev_arr_lock);
STm = &(STp->modes[STp->current_mode]);
STps = &(STp->ps[STp->partition]);
name = tape_name(STp);
if (STps->rw == ST_WRITING && !STp->pos_unknown) { if (STps->rw == ST_WRITING && !STp->pos_unknown) {
result = flush_write_buffer(STp); result = flush_write_buffer(STp);
if (result != 0 && result != (-ENOSPC)) if (result != 0 && result != (-ENOSPC))
...@@ -1176,15 +1167,7 @@ static int st_flush(struct file *filp) ...@@ -1176,15 +1167,7 @@ static int st_flush(struct file *filp)
static int st_release(struct inode *inode, struct file *filp) static int st_release(struct inode *inode, struct file *filp)
{ {
int result = 0; int result = 0;
Scsi_Tape *STp; Scsi_Tape *STp = filp->private_data;
kdev_t devt = inode->i_rdev;
int dev;
dev = TAPE_NR(devt);
read_lock(&st_dev_arr_lock);
STp = scsi_tapes[dev];
read_unlock(&st_dev_arr_lock);
if (STp->door_locked == ST_LOCKED_AUTO) if (STp->door_locked == ST_LOCKED_AUTO)
do_door_lock(STp, 0); do_door_lock(STp, 0);
...@@ -1332,7 +1315,6 @@ static int setup_buffering(Scsi_Tape *STp, const char *buf, size_t count, int is ...@@ -1332,7 +1315,6 @@ static int setup_buffering(Scsi_Tape *STp, const char *buf, size_t count, int is
static ssize_t static ssize_t
st_write(struct file *filp, const char *buf, size_t count, loff_t * ppos) st_write(struct file *filp, const char *buf, size_t count, loff_t * ppos)
{ {
struct inode *inode = filp->f_dentry->d_inode;
ssize_t total; ssize_t total;
ssize_t i, do_count, blks, transfer; ssize_t i, do_count, blks, transfer;
ssize_t retval; ssize_t retval;
...@@ -1341,17 +1323,11 @@ static ssize_t ...@@ -1341,17 +1323,11 @@ static ssize_t
unsigned char cmd[MAX_COMMAND_SIZE]; unsigned char cmd[MAX_COMMAND_SIZE];
const char *b_point; const char *b_point;
Scsi_Request *SRpnt = NULL; Scsi_Request *SRpnt = NULL;
Scsi_Tape *STp; Scsi_Tape *STp = filp->private_data;
ST_mode *STm; ST_mode *STm;
ST_partstat *STps; ST_partstat *STps;
ST_buffer *STbp; ST_buffer *STbp;
int dev = TAPE_NR(inode->i_rdev); char *name = tape_name(STp);
char *name;
read_lock(&st_dev_arr_lock);
STp = scsi_tapes[dev];
read_unlock(&st_dev_arr_lock);
name = tape_name(STp);
if (down_interruptible(&STp->lock)) if (down_interruptible(&STp->lock))
return -ERESTARTSYS; return -ERESTARTSYS;
...@@ -1781,24 +1757,16 @@ static long read_tape(Scsi_Tape *STp, long count, Scsi_Request ** aSRpnt) ...@@ -1781,24 +1757,16 @@ static long read_tape(Scsi_Tape *STp, long count, Scsi_Request ** aSRpnt)
static ssize_t static ssize_t
st_read(struct file *filp, char *buf, size_t count, loff_t * ppos) st_read(struct file *filp, char *buf, size_t count, loff_t * ppos)
{ {
struct inode *inode = filp->f_dentry->d_inode;
ssize_t total; ssize_t total;
ssize_t retval = 0; ssize_t retval = 0;
ssize_t i, transfer; ssize_t i, transfer;
int special; int special;
Scsi_Request *SRpnt = NULL; Scsi_Request *SRpnt = NULL;
Scsi_Tape *STp; Scsi_Tape *STp = filp->private_data;
ST_mode *STm; ST_mode *STm;
ST_partstat *STps; ST_partstat *STps;
ST_buffer *STbp; ST_buffer *STbp = STp->buffer;
int dev = TAPE_NR(inode->i_rdev); DEB( char *name = tape_name(STp); )
char *name;
read_lock(&st_dev_arr_lock);
STp = scsi_tapes[dev];
read_unlock(&st_dev_arr_lock);
name = tape_name(STp);
STbp = STp->buffer;
if (down_interruptible(&STp->lock)) if (down_interruptible(&STp->lock))
return -ERESTARTSYS; return -ERESTARTSYS;
...@@ -3077,17 +3045,10 @@ static int st_ioctl(struct inode *inode, struct file *file, ...@@ -3077,17 +3045,10 @@ static int st_ioctl(struct inode *inode, struct file *file,
int i, cmd_nr, cmd_type, bt; int i, cmd_nr, cmd_type, bt;
int retval = 0; int retval = 0;
unsigned int blk; unsigned int blk;
Scsi_Tape *STp; Scsi_Tape *STp = file->private_data;
ST_mode *STm; ST_mode *STm;
ST_partstat *STps; ST_partstat *STps;
int dev = TAPE_NR(inode->i_rdev); char *name = tape_name(STp);
char *name;
read_lock(&st_dev_arr_lock);
STp = scsi_tapes[dev];
read_unlock(&st_dev_arr_lock);
name = tape_name(STp);
if (down_interruptible(&STp->lock)) if (down_interruptible(&STp->lock))
return -ERESTARTSYS; return -ERESTARTSYS;
......
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