Commit 3197f480 authored by Alexander Viro's avatar Alexander Viro Committed by Jens Axboe

[PATCH] devfs_register_tape() cleanup

devfs_register_tape() returns the number it had assigned to tape.

new helper: devfs_unregister_tape(number) - removes symlink created by
devfs_register_tape()

devfs_register_tape() doesn't use devfs_auto_unregister() anymore.

devfs_register_tape() gets devfs entry of directory, instead of that of
a random file in that directory.

users updated
parent 81780a58
......@@ -6122,6 +6122,7 @@ static int idetape_cleanup (ide_drive_t *drive)
drive->driver_data = NULL;
devfs_unregister(tape->de_r);
devfs_unregister(tape->de_n);
devfs_unregister_tape(drive->disk->number);
kfree (tape);
drive->disk->fops = ide_fops;
return 0;
......@@ -6269,7 +6270,7 @@ static int idetape_attach (ide_drive_t *drive)
HWIF(drive)->major, minor + 128,
S_IFCHR | S_IRUGO | S_IWUGO,
&idetape_fops, NULL);
devfs_register_tape(tape->de_r);
drive->disk->number = devfs_register_tape(drive->de);
drive->disk->fops = &idetape_block_ops;
return 0;
failed:
......
......@@ -5486,7 +5486,7 @@ static int osst_attach(Scsi_Device * SDp)
0, 0, &osst_fops, NULL);
# endif
}
devfs_register_tape (tpnt->de_r[0]);
disk->number = devfs_register_tape(SDp->de);
#endif
tpnt->device = SDp;
......@@ -5647,6 +5647,7 @@ static void osst_detach(Scsi_Device * SDp)
devfs_unregister (tpnt->de_n[mode]);
tpnt->de_n[mode] = NULL;
}
devfs_unregister_tape(tpnt->disk->number);
#endif
put_disk(tpnt->disk);
kfree(tpnt);
......
......@@ -3874,7 +3874,7 @@ static int st_attach(Scsi_Device * SDp)
S_IFCHR | S_IRUGO | S_IWUGO,
&st_fops, NULL);
}
devfs_register_tape (tpnt->de_r[0]);
disk->number = devfs_register_tape(SDp->de);
printk(KERN_WARNING
"Attached scsi tape %s at scsi%d, channel %d, id %d, lun %d\n",
......@@ -3908,6 +3908,7 @@ static void st_detach(Scsi_Device * SDp)
devfs_unregister (tpnt->de_n[mode]);
tpnt->de_n[mode] = NULL;
}
devfs_unregister_tape(tpnt->disk->number);
scsi_tapes[i] = 0;
scsi_slave_detach(SDp);
st_nr_dev--;
......
......@@ -80,26 +80,33 @@
* @de: Any tape device entry in the device directory.
*/
void devfs_register_tape (devfs_handle_t de)
int devfs_register_tape (devfs_handle_t de)
{
int pos;
devfs_handle_t parent, slave;
char name[16], dest[64];
devfs_handle_t slave;
char name[32], dest[64];
static unsigned int tape_counter;
static devfs_handle_t tape_dir;
int n = tape_counter++;
if (tape_dir == NULL) tape_dir = devfs_mk_dir (NULL, "tapes", NULL);
parent = devfs_get_parent (de);
pos = devfs_generate_path (parent, dest + 3, sizeof dest - 3);
if (pos < 0) return;
pos = devfs_generate_path (de, dest + 3, sizeof dest - 3);
if (pos < 0) return -1;
strncpy (dest + pos, "../", 3);
sprintf (name, "tape%u", tape_counter++);
devfs_mk_symlink (tape_dir, name, DEVFS_FL_DEFAULT, dest + pos,
&slave, NULL);
devfs_auto_unregister (de, slave);
sprintf (name, "tapes/tape%u", n);
devfs_mk_symlink (NULL, name, DEVFS_FL_DEFAULT, dest + pos, &slave, NULL);
return n;
} /* End Function devfs_register_tape */
EXPORT_SYMBOL(devfs_register_tape);
void devfs_unregister_tape(int num)
{
if (num >= 0) {
char name[32];
sprintf(name, "tapes/tape%u", num);
devfs_find_and_unregister(NULL, name, 0, 0, 0, 0);
}
}
EXPORT_SYMBOL(devfs_unregister_tape);
/**
* devfs_register_series - Register a sequence of device entries.
......
......@@ -88,7 +88,8 @@ extern void devfs_auto_unregister (devfs_handle_t master,devfs_handle_t slave);
extern devfs_handle_t devfs_get_unregister_slave (devfs_handle_t master);
extern const char *devfs_get_name (devfs_handle_t de, unsigned int *namelen);
extern int devfs_only (void);
extern void devfs_register_tape (devfs_handle_t de);
extern int devfs_register_tape (devfs_handle_t de);
extern void devfs_unregister_tape(int num);
extern void devfs_register_series (devfs_handle_t dir, const char *format,
unsigned int num_entries,
unsigned int flags, unsigned int major,
......@@ -230,11 +231,13 @@ static inline int devfs_only (void)
{
return 0;
}
static inline void devfs_register_tape (devfs_handle_t de)
static inline int devfs_register_tape (devfs_handle_t de)
{
return -1;
}
static inline void devfs_unregister_tape(int num)
{
return;
}
static inline void devfs_register_series (devfs_handle_t dir,
const char *format,
unsigned int num_entries,
......
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