Commit 32735425 authored by Linus Torvalds's avatar Linus Torvalds

Merge bk://linux-input.bkbits.net/linux-input

into penguin.transmeta.com:/home/penguin/torvalds/repositories/kernel/linux
parents 26c69294 3197f480
......@@ -673,31 +673,22 @@ void blk_recount_segments(request_queue_t *q, struct bio *bio)
seg_size = nr_phys_segs = nr_hw_segs = 0;
bio_for_each_segment(bv, bio, i) {
if (bvprv && cluster) {
int phys, seg;
if (seg_size + bv->bv_len > q->max_segment_size) {
nr_phys_segs++;
if (seg_size + bv->bv_len > q->max_segment_size)
goto new_segment;
}
phys = BIOVEC_PHYS_MERGEABLE(bvprv, bv);
seg = BIOVEC_SEG_BOUNDARY(q, bvprv, bv);
if (!phys || !seg)
nr_phys_segs++;
if (!seg)
if (!BIOVEC_PHYS_MERGEABLE(bvprv, bv))
goto new_segment;
if (!BIOVEC_VIRT_MERGEABLE(bvprv, bv))
if (!BIOVEC_SEG_BOUNDARY(q, bvprv, bv))
goto new_segment;
seg_size += bv->bv_len;
bvprv = bv;
continue;
} else {
nr_phys_segs++;
}
new_segment:
nr_hw_segs++;
if (!bvprv || !BIOVEC_VIRT_MERGEABLE(bvprv, bv))
nr_hw_segs++;
nr_phys_segs++;
bvprv = bv;
seg_size = bv->bv_len;
}
......
......@@ -42,47 +42,47 @@
#define MAX_PROTOS 32
static struct pi_protocol *protocols[MAX_PROTOS];
static struct pi_protocol *protocols[MAX_PROTOS];
static spinlock_t pi_spinlock = SPIN_LOCK_UNLOCKED;
static spinlock_t pi_spinlock = SPIN_LOCK_UNLOCKED;
void pi_write_regr( PIA *pi, int cont, int regr, int val)
{ pi->proto->write_regr(pi,cont,regr,val);
void pi_write_regr(PIA * pi, int cont, int regr, int val)
{
pi->proto->write_regr(pi, cont, regr, val);
}
EXPORT_SYMBOL(pi_write_regr);
int pi_read_regr( PIA *pi, int cont, int regr)
{ return pi->proto->read_regr(pi,cont,regr);
int pi_read_regr(PIA * pi, int cont, int regr)
{
return pi->proto->read_regr(pi, cont, regr);
}
EXPORT_SYMBOL(pi_read_regr);
void pi_write_block( PIA *pi, char * buf, int count)
{ pi->proto->write_block(pi,buf,count);
void pi_write_block(PIA * pi, char *buf, int count)
{
pi->proto->write_block(pi, buf, count);
}
EXPORT_SYMBOL(pi_write_block);
void pi_read_block( PIA *pi, char * buf, int count)
{ pi->proto->read_block(pi,buf,count);
void pi_read_block(PIA * pi, char *buf, int count)
{
pi->proto->read_block(pi, buf, count);
}
EXPORT_SYMBOL(pi_read_block);
#ifdef CONFIG_PARPORT
static void pi_wake_up( void *p)
{ PIA *pi = (PIA *) p;
static void pi_wake_up(void *p)
{
PIA *pi = (PIA *) p;
unsigned long flags;
void (*cont)(void) = NULL;
void (*cont) (void) = NULL;
spin_lock_irqsave(&pi_spinlock,flags);
spin_lock_irqsave(&pi_spinlock, flags);
if (pi->claim_cont && !parport_claim(pi->pardev)) {
cont = pi->claim_cont;
......@@ -90,95 +90,91 @@ static void pi_wake_up( void *p)
pi->claimed = 1;
}
spin_unlock_irqrestore(&pi_spinlock,flags);
spin_unlock_irqrestore(&pi_spinlock, flags);
wake_up(&(pi->parq));
if (cont) cont();
if (cont)
cont();
}
#endif
void pi_do_claimed( PIA *pi, void(*cont)(void))
void pi_do_claimed(PIA * pi, void (*cont) (void))
{
#ifdef CONFIG_PARPORT
unsigned long flags;
{ unsigned long flags;
spin_lock_irqsave(&pi_spinlock,flags);
spin_lock_irqsave(&pi_spinlock, flags);
if (!pi->pardev || !parport_claim(pi->pardev)) {
pi->claimed = 1;
spin_unlock_irqrestore(&pi_spinlock,flags);
cont();
} else {
if (pi->pardev && parport_claim(pi->pardev)) {
pi->claim_cont = cont;
spin_unlock_irqrestore(&pi_spinlock,flags);
spin_unlock_irqrestore(&pi_spinlock, flags);
return;
}
pi->claimed = 1;
spin_unlock_irqrestore(&pi_spinlock, flags);
#endif
cont();
}
#else
{ cont();
}
#endif
EXPORT_SYMBOL(pi_do_claimed);
static void pi_claim( PIA *pi)
{ if (pi->claimed) return;
static void pi_claim(PIA * pi)
{
if (pi->claimed)
return;
pi->claimed = 1;
#ifdef CONFIG_PARPORT
if (pi->pardev)
wait_event (pi->parq,
!parport_claim ((struct pardevice *)pi->pardev));
if (pi->pardev)
wait_event(pi->parq,
!parport_claim((struct pardevice *) pi->pardev));
#endif
}
static void pi_unclaim( PIA *pi)
{ pi->claimed = 0;
static void pi_unclaim(PIA * pi)
{
pi->claimed = 0;
#ifdef CONFIG_PARPORT
if (pi->pardev) parport_release((struct pardevice *)(pi->pardev));
#endif
if (pi->pardev)
parport_release((struct pardevice *) (pi->pardev));
#endif
}
void pi_connect( PIA *pi)
{ pi_claim(pi);
void pi_connect(PIA * pi)
{
pi_claim(pi);
pi->proto->connect(pi);
}
EXPORT_SYMBOL(pi_connect);
void pi_disconnect( PIA *pi)
{ pi->proto->disconnect(pi);
void pi_disconnect(PIA * pi)
{
pi->proto->disconnect(pi);
pi_unclaim(pi);
}
EXPORT_SYMBOL(pi_disconnect);
static void pi_unregister_parport( PIA *pi)
static void pi_unregister_parport(PIA * pi)
{
#ifdef CONFIG_PARPORT
if (pi->pardev) {
parport_unregister_device((struct pardevice *)(pi->pardev));
pi->pardev = NULL;
if (pi->pardev) {
parport_unregister_device((struct pardevice *) (pi->pardev));
pi->pardev = NULL;
}
#endif
}
void pi_release( PIA *pi)
{ pi_unregister_parport(pi);
void pi_release(PIA * pi)
{
pi_unregister_parport(pi);
#ifndef CONFIG_PARPORT
if (pi->reserved)
release_region(pi->port,pi->reserved);
#endif /* !CONFIG_PARPORT */
release_region(pi->port, pi->reserved);
#endif /* !CONFIG_PARPORT */
pi->proto->release_proto(pi);
}
......@@ -187,50 +183,53 @@ EXPORT_SYMBOL(pi_release);
#define WR(r,v) pi_write_regr(pi,0,r,v)
#define RR(r) (pi_read_regr(pi,0,r))
static int pi_test_proto( PIA *pi, char * scratch, int verbose )
{ int j, k;
int e[2] = {0,0};
static int pi_test_proto(PIA * pi, char *scratch, int verbose)
{
int j, k;
int e[2] = { 0, 0 };
if (pi->proto->test_proto) {
pi_claim(pi);
j = pi->proto->test_proto(pi,scratch,verbose);
j = pi->proto->test_proto(pi, scratch, verbose);
pi_unclaim(pi);
return j;
}
pi_connect(pi);
pi_connect(pi);
for (j=0;j<2;j++) {
WR(6,0xa0+j*0x10);
for (k=0;k<256;k++) {
WR(2,k^0xaa);
WR(3,k^0x55);
if (RR(2) != (k^0xaa)) e[j]++;
}
}
for (j = 0; j < 2; j++) {
WR(6, 0xa0 + j * 0x10);
for (k = 0; k < 256; k++) {
WR(2, k ^ 0xaa);
WR(3, k ^ 0x55);
if (RR(2) != (k ^ 0xaa))
e[j]++;
}
}
pi_disconnect(pi);
pi_disconnect(pi);
if (verbose)
printk("%s: %s: port 0x%x, mode %d, test=(%d,%d)\n",
pi->device,pi->proto->name,pi->port,
pi->mode,e[0],e[1]);
if (verbose)
printk("%s: %s: port 0x%x, mode %d, test=(%d,%d)\n",
pi->device, pi->proto->name, pi->port,
pi->mode, e[0], e[1]);
return (e[0] && e[1]); /* not here if both > 0 */
return (e[0] && e[1]); /* not here if both > 0 */
}
int pi_register( PIP *pr)
{ int k;
int pi_register(PIP * pr)
{
int k;
for (k=0;k<MAX_PROTOS;k++)
if (protocols[k] && !strcmp(pr->name,protocols[k]->name)) {
printk("paride: %s protocol already registered\n",pr->name);
return 0;
}
for (k = 0; k < MAX_PROTOS; k++)
if (protocols[k] && !strcmp(pr->name, protocols[k]->name)) {
printk("paride: %s protocol already registered\n",
pr->name);
return 0;
}
k = 0;
while((k<MAX_PROTOS) && (protocols[k])) k++;
while ((k < MAX_PROTOS) && (protocols[k]))
k++;
if (k == MAX_PROTOS) {
printk("paride: protocol table full\n");
return 0;
......@@ -238,194 +237,209 @@ int pi_register( PIP *pr)
MOD_INC_USE_COUNT;
protocols[k] = pr;
pr->index = k;
printk("paride: %s registered as protocol %d\n",pr->name,k);
printk("paride: %s registered as protocol %d\n", pr->name, k);
return 1;
}
}
EXPORT_SYMBOL(pi_register);
void pi_unregister( PIP *pr)
{ if (!pr) return;
void pi_unregister(PIP * pr)
{
if (!pr)
return;
if (protocols[pr->index] != pr) {
printk("paride: %s not registered\n",pr->name);
printk("paride: %s not registered\n", pr->name);
return;
}
}
protocols[pr->index] = 0;
MOD_DEC_USE_COUNT;
}
EXPORT_SYMBOL(pi_unregister);
static int pi_register_parport( PIA *pi, int verbose)
static int pi_register_parport(PIA * pi, int verbose)
{
#ifdef CONFIG_PARPORT
struct parport *port;
port = parport_find_base (pi->port);
port = parport_find_base(pi->port);
if (!port)
return 0;
return 0;
pi->pardev = parport_register_device(port,
pi->device,NULL,
pi_wake_up,NULL,
0,(void *)pi);
parport_put_port (port);
pi->device, NULL,
pi_wake_up, NULL, 0, (void *) pi);
parport_put_port(port);
if (!pi->pardev)
return 0;
return 0;
init_waitqueue_head(&pi->parq);
if (verbose) printk("%s: 0x%x is %s\n",pi->device,pi->port,
port->name);
pi->parname = (char *)port->name;
if (verbose)
printk("%s: 0x%x is %s\n", pi->device, pi->port, port->name);
pi->parname = (char *) port->name;
#endif
return 1;
}
static int pi_probe_mode( PIA *pi, int max, char * scratch, int verbose)
{ int best, range;
static int pi_probe_mode(PIA * pi, int max, char *scratch, int verbose)
{
int best, range;
if (pi->mode != -1) {
if (pi->mode >= max) return 0;
if (pi->mode >= max)
return 0;
range = 3;
if (pi->mode >= pi->proto->epp_first) range = 8;
if ((range == 8) && (pi->port % 8)) return 0;
if (pi->mode >= pi->proto->epp_first)
range = 8;
if ((range == 8) && (pi->port % 8))
return 0;
pi->reserved = range;
return (!pi_test_proto(pi,scratch,verbose));
return (!pi_test_proto(pi, scratch, verbose));
}
best = -1;
for(pi->mode=0;pi->mode<max;pi->mode++) {
for (pi->mode = 0; pi->mode < max; pi->mode++) {
range = 3;
if (pi->mode >= pi->proto->epp_first) range = 8;
if ((range == 8) && (pi->port % 8)) break;
if (pi->mode >= pi->proto->epp_first)
range = 8;
if ((range == 8) && (pi->port % 8))
break;
pi->reserved = range;
if (!pi_test_proto(pi,scratch,verbose)) best = pi->mode;
if (!pi_test_proto(pi, scratch, verbose))
best = pi->mode;
}
pi->mode = best;
return (best > -1);
}
static int pi_probe_unit( PIA *pi, int unit, char * scratch, int verbose)
{ int max,s,e;
static int pi_probe_unit(PIA * pi, int unit, char *scratch, int verbose)
{
int max, s, e;
s = unit; e = s+1;
s = unit;
e = s + 1;
if (s == -1) {
s = 0;
e = pi->proto->max_units;
if (s == -1) {
s = 0;
e = pi->proto->max_units;
}
if (!pi_register_parport(pi,verbose))
return 0;
if (!pi_register_parport(pi, verbose))
return 0;
if (pi->proto->test_port) {
pi_claim(pi);
max = pi->proto->test_port(pi);
pi_unclaim(pi);
}
else max = pi->proto->max_mode;
} else
max = pi->proto->max_mode;
if (pi->proto->probe_unit) {
pi_claim(pi);
for (pi->unit=s;pi->unit<e;pi->unit++)
if (pi->proto->probe_unit(pi)) {
pi_unclaim(pi);
if (pi_probe_mode(pi,max,scratch,verbose)) return 1;
pi_unregister_parport(pi);
return 0;
}
pi_unclaim(pi);
pi_unregister_parport(pi);
return 0;
}
if (!pi_probe_mode(pi,max,scratch,verbose)) {
pi_unregister_parport(pi);
return 0;
pi_claim(pi);
for (pi->unit = s; pi->unit < e; pi->unit++)
if (pi->proto->probe_unit(pi)) {
pi_unclaim(pi);
if (pi_probe_mode(pi, max, scratch, verbose))
return 1;
pi_unregister_parport(pi);
return 0;
}
pi_unclaim(pi);
pi_unregister_parport(pi);
return 0;
}
if (!pi_probe_mode(pi, max, scratch, verbose)) {
pi_unregister_parport(pi);
return 0;
}
return 1;
}
int pi_init(PIA *pi, int autoprobe, int port, int mode,
int unit, int protocol, int delay, char * scratch,
int devtype, int verbose, char *device )
}
{ int p,k,s,e;
int lpts[7] = {0x3bc,0x378,0x278,0x268,0x27c,0x26c,0};
int pi_init(PIA * pi, int autoprobe, int port, int mode,
int unit, int protocol, int delay, char *scratch,
int devtype, int verbose, char *device)
{
int p, k, s, e;
int lpts[7] = { 0x3bc, 0x378, 0x278, 0x268, 0x27c, 0x26c, 0 };
s = protocol; e = s+1;
s = protocol;
e = s + 1;
if (!protocols[0])
request_module ("paride_protocol");
request_module("paride_protocol");
if (autoprobe) {
s = 0;
s = 0;
e = MAX_PROTOS;
} else if ((s < 0) || (s >= MAX_PROTOS) || (port <= 0) ||
(!protocols[s]) || (unit < 0) ||
(unit >= protocols[s]->max_units)) {
printk("%s: Invalid parameters\n",device);
return 0;
}
for (p=s;p<e;p++) {
if (protocols[p]) {
pi->proto = protocols[p];
pi->private = 0;
pi->proto->init_proto(pi);
if (delay == -1) pi->delay = pi->proto->default_delay;
else pi->delay = delay;
pi->devtype = devtype;
pi->device = device;
pi->parname = NULL;
pi->pardev = NULL;
init_waitqueue_head(&pi->parq);
pi->claimed = 0;
pi->claim_cont = NULL;
pi->mode = mode;
if (port != -1) {
pi->port = port;
if (pi_probe_unit(pi,unit,scratch,verbose)) break;
pi->port = 0;
} else {
k = 0;
while ((pi->port = lpts[k++]))
if (pi_probe_unit(pi,unit,scratch,verbose)) break;
if (pi->port) break;
(!protocols[s]) || (unit < 0) ||
(unit >= protocols[s]->max_units)) {
printk("%s: Invalid parameters\n", device);
return 0;
}
for (p = s; p < e; p++) {
if (protocols[p]) {
pi->proto = protocols[p];
pi->private = 0;
pi->proto->init_proto(pi);
if (delay == -1)
pi->delay = pi->proto->default_delay;
else
pi->delay = delay;
pi->devtype = devtype;
pi->device = device;
pi->parname = NULL;
pi->pardev = NULL;
init_waitqueue_head(&pi->parq);
pi->claimed = 0;
pi->claim_cont = NULL;
pi->mode = mode;
if (port != -1) {
pi->port = port;
if (pi_probe_unit(pi, unit, scratch, verbose))
break;
pi->port = 0;
} else {
k = 0;
while ((pi->port = lpts[k++]))
if (pi_probe_unit
(pi, unit, scratch, verbose))
break;
if (pi->port)
break;
}
pi->proto->release_proto(pi);
}
pi->proto->release_proto(pi);
}
}
if (!pi->port) {
if (autoprobe) printk("%s: Autoprobe failed\n",device);
else printk("%s: Adapter not found\n",device);
if (autoprobe)
printk("%s: Autoprobe failed\n", device);
else
printk("%s: Adapter not found\n", device);
return 0;
}
#ifndef CONFIG_PARPORT
if (!request_region(pi->port,pi->reserved,pi->device))
{
printk(KERN_WARNING"paride: Unable to request region 0x%x\n", pi->port);
if (!request_region(pi->port, pi->reserved, pi->device)) {
printk(KERN_WARNING "paride: Unable to request region 0x%x\n",
pi->port);
return 0;
}
#endif /* !CONFIG_PARPORT */
}
#endif /* !CONFIG_PARPORT */
if (pi->parname)
printk("%s: Sharing %s at 0x%x\n",pi->device,
pi->parname,pi->port);
printk("%s: Sharing %s at 0x%x\n", pi->device,
pi->parname, pi->port);
pi->proto->log_adapter(pi,scratch,verbose);
pi->proto->log_adapter(pi, scratch, verbose);
return 1;
}
......
......@@ -5871,8 +5871,8 @@ int __init sbpcd_init(void)
disk->fops = &sbpcd_bdops;
strcpy(disk->disk_name, sbpcd_infop->name);
disk->flags = GENHD_FL_CD;
sprintf(nbuff, "c0t%d", p->drv_id);
disk->de = devfs_mk_dir(devfs_handle, nbuff, NULL);
sprintf(nbuff, "sbp/c0t%d", p->drv_id);
disk->de = devfs_mk_dir(NULL, nbuff, NULL);
p->disk = disk;
if (register_cdrom(sbpcd_infop))
{
......
......@@ -1047,7 +1047,6 @@ static int alloc_disks(ide_hwif_t *hwif)
static void init_gendisk (ide_hwif_t *hwif)
{
unsigned int unit;
extern devfs_handle_t ide_devfs_handle;
for (unit = 0; unit < MAX_DRIVES; ++unit) {
ide_drive_t * drive = &hwif->drives[unit];
......@@ -1059,13 +1058,13 @@ static void init_gendisk (ide_hwif_t *hwif)
"%s","IDE Drive");
drive->gendev.parent = &hwif->gendev;
drive->gendev.bus = &ide_bus_type;
sprintf (name, "host%d/bus%d/target%d/lun%d",
sprintf (name, "ide/host%d/bus%d/target%d/lun%d",
(hwif->channel && hwif->mate) ?
hwif->mate->index : hwif->index,
hwif->channel, unit, drive->lun);
if (drive->present) {
device_register(&drive->gendev);
drive->de = devfs_mk_dir(ide_devfs_handle, name, NULL);
drive->de = devfs_mk_dir(NULL, name, NULL);
}
}
blk_register_region(MKDEV(hwif->major, 0), MAX_DRIVES << PARTN_BITS,
......
......@@ -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:
......
......@@ -169,15 +169,6 @@ static spinlock_t dv1394_cards_lock = SPIN_LOCK_UNLOCKED;
static struct hpsb_highlevel *hl_handle; /* = NULL; */
static LIST_HEAD(dv1394_devfs);
struct dv1394_devfs_entry {
struct list_head list;
devfs_handle_t devfs;
char name[32];
struct dv1394_devfs_entry *parent;
};
static spinlock_t dv1394_devfs_lock = SPIN_LOCK_UNLOCKED;
/* translate from a struct file* to the corresponding struct video_card* */
static inline struct video_card* file_to_video_card(struct file *file)
......@@ -2564,135 +2555,42 @@ static struct file_operations dv1394_fops=
/*** DEVFS HELPERS *********************************************************/
struct dv1394_devfs_entry *
dv1394_devfs_find( char *name)
{
struct list_head *lh;
struct dv1394_devfs_entry *p;
spin_lock( &dv1394_devfs_lock);
if(!list_empty(&dv1394_devfs)) {
list_for_each(lh, &dv1394_devfs) {
p = list_entry(lh, struct dv1394_devfs_entry, list);
if(!strncmp(p->name, name, sizeof(p->name))) {
goto found;
}
}
}
p = NULL;
found:
spin_unlock( &dv1394_devfs_lock);
return p;
}
#ifdef CONFIG_DEVFS_FS
static int dv1394_devfs_add_entry(struct video_card *video)
{
char buf[32];
struct dv1394_devfs_entry *p;
struct dv1394_devfs_entry *parent;
char buf[64];
snprintf(buf, sizeof(buf), "ieee1394/dv/host%d/%s/%s",
(video->id>>2),
(video->pal_or_ntsc == DV1394_NTSC ? "NTSC" : "PAL"),
(video->mode == MODE_RECEIVE ? "in" : "out"));
p = kmalloc(sizeof(struct dv1394_devfs_entry), GFP_KERNEL);
if(!p) {
printk(KERN_ERR "dv1394: cannot allocate dv1394_devfs_entry\n");
goto err;
}
memset(p, 0, sizeof(struct dv1394_devfs_entry));
snprintf(buf, sizeof(buf), "dv/host%d/%s", (video->id>>2),
(video->pal_or_ntsc == DV1394_NTSC ? "NTSC" : "PAL"));
parent = dv1394_devfs_find(buf);
if (parent == NULL) {
printk(KERN_ERR "dv1394: unable to locate parent devfs of %s\n", buf);
goto err_free;
}
video->devfs_handle = devfs_register(
parent->devfs,
(video->mode == MODE_RECEIVE ? "in" : "out"),
DEVFS_FL_NONE,
video->devfs_handle = devfs_register(NULL, buf, DEVFS_FL_NONE,
IEEE1394_MAJOR,
IEEE1394_MINOR_BLOCK_DV1394*16 + video->id,
S_IFCHR | S_IRUGO | S_IWUGO,
&dv1394_fops,
(void*) video);
p->devfs = video->devfs_handle;
if (p->devfs == NULL) {
printk(KERN_ERR "dv1394: unable to create /dev/ieee1394/%s/%s\n",
parent->name,
(video->mode == MODE_RECEIVE ? "in" : "out"));
goto err_free;
if (video->devfs_handle == NULL) {
printk(KERN_ERR "dv1394: unable to create /dev/%s\n", buf);
return -ENOMEM;
}
spin_lock( &dv1394_devfs_lock);
INIT_LIST_HEAD(&p->list);
list_add_tail(&p->list, &dv1394_devfs);
spin_unlock( &dv1394_devfs_lock);
return 0;
err_free:
kfree(p);
err:
return -ENOMEM;
}
static int
dv1394_devfs_add_dir( char *name,
struct dv1394_devfs_entry *parent,
struct dv1394_devfs_entry **out)
static int dv1394_devfs_add_dir(char *name)
{
struct dv1394_devfs_entry *p;
p = kmalloc(sizeof(struct dv1394_devfs_entry), GFP_KERNEL);
if(!p) {
printk(KERN_ERR "dv1394: cannot allocate dv1394_devfs_entry\n");
goto err;
}
memset(p, 0, sizeof(struct dv1394_devfs_entry));
if (parent == NULL) {
snprintf(p->name, sizeof(p->name), "%s", name);
p->devfs = devfs_mk_dir(ieee1394_devfs_handle, name, NULL);
} else {
snprintf(p->name, sizeof(p->name), "%s/%s", parent->name, name);
p->devfs = devfs_mk_dir(parent->devfs, name, NULL);
}
if (p->devfs == NULL) {
printk(KERN_ERR "dv1394: unable to create /dev/ieee1394/%s\n", p->name);
goto err_free;
if (!devfs_mk_dir(NULL, name, NULL))
printk(KERN_ERR "dv1394: unable to create /dev/%s\n", name);
return -ENOMEM;
}
p->parent = parent;
if (out != NULL) *out = p;
spin_lock( &dv1394_devfs_lock);
INIT_LIST_HEAD(&p->list);
list_add_tail(&p->list, &dv1394_devfs);
spin_unlock( &dv1394_devfs_lock);
return 0;
err_free:
kfree(p);
err:
return -ENOMEM;
}
void dv1394_devfs_del( char *name)
void dv1394_devfs_del(char *name)
{
struct dv1394_devfs_entry *p = dv1394_devfs_find(name);
if (p != NULL) {
devfs_unregister(p->devfs);
spin_lock( &dv1394_devfs_lock);
list_del(&p->list);
spin_unlock( &dv1394_devfs_lock);
kfree(p);
}
char s[64];
sprintf(s, "ieee1394/%s", name);
devfs_find_and_unregister(NULL, s, 0, 0, 0, 0);
}
#endif /* CONFIG_DEVFS_FS */
......@@ -2874,15 +2772,12 @@ static void dv1394_add_host (struct hpsb_host *host)
#endif
#ifdef CONFIG_DEVFS_FS
{
struct dv1394_devfs_entry *devfs_entry = dv1394_devfs_find("dv");
if (devfs_entry != NULL) {
snprintf(buf, sizeof(buf), "host%d", ohci->id);
dv1394_devfs_add_dir(buf, devfs_entry, &devfs_entry);
dv1394_devfs_add_dir("NTSC", devfs_entry, NULL);
dv1394_devfs_add_dir("PAL", devfs_entry, NULL);
}
}
snprintf(buf, sizeof(buf), "ieee1394/dv/host%d", ohci->id);
dv1394_devfs_add_dir(buf);
snprintf(buf, sizeof(buf), "ieee1394/dv/host%d/NTSC", ohci->id);
dv1394_devfs_add_dir(buf);
snprintf(buf, sizeof(buf), "ieee1394/dv/host%d/PAL", ohci->id);
dv1394_devfs_add_dir(buf);
#endif
dv1394_init(ohci, DV1394_NTSC, MODE_RECEIVE);
......@@ -3042,7 +2937,7 @@ static int __init dv1394_init_module(void)
}
#ifdef CONFIG_DEVFS_FS
if (dv1394_devfs_add_dir("dv", NULL, NULL) < 0) {
if (dv1394_devfs_add_dir("ieee1394/dv") < 0) {
printk(KERN_ERR "dv1394: unable to create /dev/ieee1394/dv\n");
ieee1394_unregister_chardev(IEEE1394_MINOR_BLOCK_DV1394);
return -ENOMEM;
......
......@@ -1078,7 +1078,6 @@ static struct miscdevice _dm_misc = {
int __init dm_interface_init(void)
{
int r;
char rname[64];
r = dm_hash_init();
if (r)
......@@ -1091,25 +1090,12 @@ int __init dm_interface_init(void)
return r;
}
r = devfs_generate_path(_dm_misc.devfs_handle, rname + 3,
sizeof rname - 3);
if (r == -ENOSYS)
return 0; /* devfs not present */
if (r < 0) {
DMERR("devfs_generate_path failed for control device");
goto failed;
}
strncpy(rname + r, "../", 3);
r = devfs_mk_symlink(NULL, DM_DIR "/control",
DEVFS_FL_DEFAULT, rname + r, &_ctl_handle, NULL);
r = devfs_mk_symlink(NULL, DM_DIR "/control", DEVFS_FL_DEFAULT,
"../misc/" DM_NAME, &_ctl_handle, NULL);
if (r) {
DMERR("devfs_mk_symlink failed for control device");
goto failed;
}
devfs_auto_unregister(_dm_misc.devfs_handle, _ctl_handle);
DMINFO("%d.%d.%d%s initialised: %s", DM_VERSION_MAJOR,
DM_VERSION_MINOR, DM_VERSION_PATCHLEVEL, DM_VERSION_EXTRA,
DM_DRIVER_EMAIL);
......@@ -1125,6 +1111,8 @@ void dm_interface_exit(void)
{
dm_hash_exit();
devfs_find_and_unregister(NULL, DM_DIR "/control", 0, 0, 0, 0);
if (misc_deregister(&_dm_misc) < 0)
DMERR("misc_deregister failed for control device");
}
......@@ -350,7 +350,7 @@ int dvbdev_get_free_adapter_num (void)
int dvb_register_adapter(dvb_adapter_t **padap, char *name)
{
char dirname[10];
char dirname[16];
dvb_adapter_t *adap;
int num;
......@@ -374,8 +374,8 @@ int dvb_register_adapter(dvb_adapter_t **padap, char *name)
printk ("%s: registering new adapter (%s).\n", __FUNCTION__, name);
sprintf(dirname, "adapter%d", num);
adap->devfs_handle = devfs_mk_dir(dvb_devfs_handle, dirname, NULL);
sprintf(dirname, "dvb/adapter%d", num);
adap->devfs_handle = devfs_mk_dir(NULL, dirname, NULL);
adap->num = num;
list_add_tail (&adap->list_head, &dvb_adapter_list);
......
......@@ -283,7 +283,7 @@ dasd_free_device(dasd_device_t *device)
static inline int
dasd_state_new_to_known(dasd_device_t *device)
{
char buffer[5];
char buffer[10];
dasd_devmap_t *devmap;
umode_t devfs_perm;
devfs_handle_t dir;
......@@ -303,8 +303,8 @@ dasd_state_new_to_known(dasd_device_t *device)
return rc;
/* Add a proc directory and the dasd device entry to devfs. */
sprintf(buffer, "%04x", device->devinfo.devno);
dir = devfs_mk_dir(dasd_devfs_handle, buffer, device);
sprintf(buffer, "dasd/%04x", device->devinfo.devno);
dir = devfs_mk_dir(NULL, buffer, NULL);
device->gdp->de = dir;
if (devmap->features & DASD_FEATURE_READONLY)
devfs_perm = S_IFBLK | S_IRUSR;
......
......@@ -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);
......
......@@ -1323,7 +1323,6 @@ static int scsi_add_lun(Scsi_Device *sdevscan, Scsi_Device **sdevnew,
{
Scsi_Device *sdev;
char devname[64];
extern devfs_handle_t scsi_devfs_handle;
sdev = scsi_alloc_sdev(sdevscan->host, sdevscan->channel,
sdevscan->id, sdevscan->lun);
......@@ -1445,13 +1444,13 @@ static int scsi_add_lun(Scsi_Device *sdevscan, Scsi_Device **sdevnew,
*/
device_create_file(&sdev->sdev_driverfs_dev, &dev_attr_type);
sprintf(devname, "host%d/bus%d/target%d/lun%d",
sprintf(devname, "scsi/host%d/bus%d/target%d/lun%d",
sdev->host->host_no, sdev->channel, sdev->id, sdev->lun);
if (sdev->de)
printk(KERN_WARNING "scsi devfs dir: \"%s\" already exists\n",
devname);
else
sdev->de = devfs_mk_dir(scsi_devfs_handle, devname, NULL);
sdev->de = devfs_mk_dir(NULL, devname, NULL);
/*
* End driverfs/devfs code.
*/
......
......@@ -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.
......
......@@ -27,6 +27,7 @@
#include <linux/list.h>
#include <linux/hash.h>
#include <linux/spinlock.h>
#include <linux/rwsem.h>
#include <linux/wait.h>
#include <asm/bitops.h>
#include <asm/uaccess.h>
......@@ -65,13 +66,6 @@
/* Minimum size of the hash in bits ( 2^N ) */
#define EP_MIN_HASH_BITS 9
/*
* Event buffer dimension used to cache events before sending them in
* userspace with a __copy_to_user(). The event buffer is in stack,
* so keep this size fairly small.
*/
#define EP_EVENT_BUFF_SIZE 32
/* Maximum number of wait queue we can attach to */
#define EP_MAX_POLL_QUEUE 2
......@@ -110,6 +104,17 @@
/* Get the "struct epitem" from an epoll queue wrapper */
#define EP_ITEM_FROM_EPQUEUE(p) (container_of(p, struct ep_pqueue, pt)->dpi)
/*
* This is used to optimize the event transfer to userspace. Since this
* is kept on stack, it should be pretty small.
*/
#define EP_MAX_BUF_EVENTS 32
/*
* Used to optimize ready items collection by reducing the irqlock/irqunlock
* switching rate. This is kept in stack too, so do not go wild with this number.
*/
#define EP_MAX_COLLECT_ITEMS 64
......@@ -119,9 +124,6 @@
* interface.
*/
struct eventpoll {
/* Used to link to the "struct eventpoll" list ( eplist ) */
struct list_head llink;
/* Protect the this structure access */
rwlock_t lock;
......@@ -187,6 +189,9 @@ struct epitem {
* that the structure will desappear from underneath our processing.
*/
atomic_t usecnt;
/* List header used to link this item to the "struct file" items list */
struct list_head fllink;
};
/* Wrapper struct used by poll queueing */
......@@ -212,11 +217,15 @@ static void ep_release_epitem(struct epitem *dpi);
static void ep_ptable_queue_proc(struct file *file, wait_queue_head_t *whead, poll_table *pt);
static int ep_insert(struct eventpoll *ep, struct pollfd *pfd, struct file *tfile);
static int ep_modify(struct eventpoll *ep, struct epitem *dpi, unsigned int events);
static void ep_unregister_pollwait(struct eventpoll *ep, struct epitem *dpi);
static int ep_unlink(struct eventpoll *ep, struct epitem *dpi);
static int ep_remove(struct eventpoll *ep, struct epitem *dpi);
static int ep_poll_callback(wait_queue_t *wait, unsigned mode, int sync);
static int ep_eventpoll_close(struct inode *inode, struct file *file);
static unsigned int ep_eventpoll_poll(struct file *file, poll_table *wait);
static int ep_collect_ready_items(struct eventpoll *ep, struct epitem **adpi, int maxdpi);
static int ep_send_events(struct eventpoll *ep, struct epitem **adpi, int ndpi,
struct pollfd *events);
static int ep_events_transfer(struct eventpoll *ep, struct pollfd *events, int maxevents);
static int ep_poll(struct eventpoll *ep, struct pollfd *events, int maxevents,
int timeout);
......@@ -226,12 +235,15 @@ static struct super_block *eventpollfs_get_sb(struct file_system_type *fs_type,
int flags, char *dev_name, void *data);
/* Use to link togheter all the "struct eventpoll" */
static struct list_head eplist;
/* Serialize the access to "eplist" */
static rwlock_t eplock;
/*
* This semaphore is used to ensure that files are not removed
* while epoll is using them. Namely the f_op->poll(), since
* it has to be called from outside the lock, must be protected.
* This is read-held during the event transfer loop to userspace
* and it is write-held during the file cleanup path and the epoll
* exit code.
*/
struct rw_semaphore epsem;
/* Slab cache used to allocate "struct epitem" */
static kmem_cache_t *dpi_cache;
......@@ -275,6 +287,15 @@ static unsigned int ep_get_hash_bits(unsigned int hintsize)
}
/* Used to initialize the epoll bits inside the "struct file" */
void ep_init_file_struct(struct file *file)
{
INIT_LIST_HEAD(&file->f_ep_links);
spin_lock_init(&file->f_ep_lock);
}
/*
* This is called from inside fs/file_table.c:__fput() to unlink files
* from the eventpoll interface. We need to have this facility to cleanup
......@@ -283,21 +304,18 @@ static unsigned int ep_get_hash_bits(unsigned int hintsize)
*/
void ep_notify_file_close(struct file *file)
{
unsigned long flags;
struct list_head *lnk;
struct eventpoll *ep;
struct list_head *lsthead = &file->f_ep_links;
struct epitem *dpi;
read_lock_irqsave(&eplock, flags);
list_for_each(lnk, &eplist) {
ep = list_entry(lnk, struct eventpoll, llink);
down_write(&epsem);
while (!list_empty(lsthead)) {
dpi = list_entry(lsthead->next, struct epitem, fllink);
while ((dpi = ep_find(ep, file))) {
ep_remove(ep, dpi);
ep_release_epitem(dpi);
}
EP_LIST_DEL(&dpi->fllink);
ep_remove(dpi->ep, dpi);
}
read_unlock_irqrestore(&eplock, flags);
up_write(&epsem);
}
......@@ -438,14 +456,14 @@ asmlinkage int sys_epoll_ctl(int epfd, int op, int fd, unsigned int events)
if (dpi)
ep_release_epitem(dpi);
DNPRINTK(3, (KERN_INFO "[%p] eventpoll: sys_epoll_ctl(%d, %d, %d, %u) = %d\n",
current, epfd, op, fd, events, error));
eexit_3:
fput(tfile);
eexit_2:
fput(file);
eexit_1:
DNPRINTK(3, (KERN_INFO "[%p] eventpoll: sys_epoll_ctl(%d, %d, %d, %u) = %d\n",
current, epfd, op, fd, events, error));
return error;
}
......@@ -495,12 +513,12 @@ asmlinkage int sys_epoll_wait(int epfd, struct pollfd *events, int maxevents,
/* Time to fish for events ... */
error = ep_poll(ep, events, maxevents, timeout);
DNPRINTK(3, (KERN_INFO "[%p] eventpoll: sys_epoll_wait(%d, %p, %d, %d) = %d\n",
current, epfd, events, maxevents, timeout, error));
eexit_2:
fput(file);
eexit_1:
DNPRINTK(3, (KERN_INFO "[%p] eventpoll: sys_epoll_wait(%d, %p, %d, %d) = %d\n",
current, epfd, events, maxevents, timeout, error));
return error;
}
......@@ -616,7 +634,6 @@ static int ep_free_pages(char **pages, int numpages)
static int ep_file_init(struct file *file, unsigned int hashbits)
{
int error;
unsigned long flags;
struct eventpoll *ep;
if (!(ep = kmalloc(sizeof(struct eventpoll), GFP_KERNEL)))
......@@ -632,11 +649,6 @@ static int ep_file_init(struct file *file, unsigned int hashbits)
file->private_data = ep;
/* Add the structure to the linked list that links "struct eventpoll" */
write_lock_irqsave(&eplock, flags);
list_add(&ep->llink, &eplist);
write_unlock_irqrestore(&eplock, flags);
DNPRINTK(3, (KERN_INFO "[%p] eventpoll: ep_file_init() ep=%p\n",
current, ep));
return 0;
......@@ -669,7 +681,6 @@ static int ep_init(struct eventpoll *ep, unsigned int hashbits)
int error;
unsigned int i, hsize;
INIT_LIST_HEAD(&ep->llink);
rwlock_init(&ep->lock);
init_waitqueue_head(&ep->wq);
init_waitqueue_head(&ep->poll_wait);
......@@ -694,44 +705,45 @@ static int ep_init(struct eventpoll *ep, unsigned int hashbits)
static void ep_free(struct eventpoll *ep)
{
unsigned int i, hsize;
unsigned long flags;
struct list_head *lsthead;
struct list_head *lsthead, *lnk;
/*
* We need to lock this because we could be hit by
* ep_notify_file_close() while we're freeing the
* "struct eventpoll".
*/
down_write(&epsem);
/*
* Walks through the whole hash by unregistering file callbacks and
* freeing each "struct epitem".
* Walks through the whole hash by unregistering poll callbacks.
*/
for (i = 0, hsize = 1 << ep->hashbits; i < hsize; i++) {
lsthead = ep_hash_entry(ep, i);
/*
* We need to lock this because we could be hit by
* ep_notify_file_close() while we're freeing this.
*/
write_lock_irqsave(&ep->lock, flags);
list_for_each(lnk, lsthead) {
struct epitem *dpi = list_entry(lnk, struct epitem, llink);
while (!list_empty(lsthead)) {
struct epitem *dpi = list_entry(lsthead->next, struct epitem, llink);
/* The function ep_unlink() must be called with held lock */
ep_unlink(ep, dpi);
ep_unregister_pollwait(ep, dpi);
}
}
/* We release the lock before releasing the "struct epitem" */
write_unlock_irqrestore(&ep->lock, flags);
/*
* Walks through the whole hash by freeing each "struct epitem". At this
* point we are sure no poll callbacks will be lingering around, and also by
* write-holding "epsem" we can be sure that no file cleanup code will hit
* us during this operation. So we can avoid the lock on "ep->lock".
*/
for (i = 0, hsize = 1 << ep->hashbits; i < hsize; i++) {
lsthead = ep_hash_entry(ep, i);
ep_release_epitem(dpi);
while (!list_empty(lsthead)) {
struct epitem *dpi = list_entry(lsthead->next, struct epitem, llink);
/* And then we reaquire the lock ... */
write_lock_irqsave(&ep->lock, flags);
ep_remove(ep, dpi);
}
write_unlock_irqrestore(&ep->lock, flags);
}
/* Remove the structure to the linked list that links "struct eventpoll" */
write_lock_irqsave(&eplock, flags);
EP_LIST_DEL(&ep->llink);
write_unlock_irqrestore(&eplock, flags);
up_write(&epsem);
/* Free hash pages */
ep_free_pages(ep->hpages, EP_HASH_PAGES(ep->hashbits));
......@@ -826,6 +838,7 @@ static int ep_insert(struct eventpoll *ep, struct pollfd *pfd, struct file *tfil
/* Item initialization follow here ... */
INIT_LIST_HEAD(&dpi->llink);
INIT_LIST_HEAD(&dpi->rdllink);
INIT_LIST_HEAD(&dpi->fllink);
dpi->ep = ep;
dpi->file = tfile;
dpi->pfd = *pfd;
......@@ -839,7 +852,16 @@ static int ep_insert(struct eventpoll *ep, struct pollfd *pfd, struct file *tfil
/* Initialize the poll table using the queue callback */
epq.dpi = dpi;
poll_initwait_ex(&epq.pt, ep_ptable_queue_proc);
poll_initwait_ex(&epq.pt, ep_ptable_queue_proc, NULL);
/*
* Attach the item to the poll hooks and get current event bits.
* We can safely use the file* here because its usage count has
* been increased by the caller of this function.
*/
revents = tfile->f_op->poll(tfile, &epq.pt);
poll_freewait(&epq.pt);
/* We have to drop the new item inside our item list to keep track of it */
write_lock_irqsave(&ep->lock, flags);
......@@ -847,9 +869,6 @@ static int ep_insert(struct eventpoll *ep, struct pollfd *pfd, struct file *tfil
/* Add the current item to the hash table */
list_add(&dpi->llink, ep_hash_entry(ep, ep_hash_index(ep, tfile)));
/* Attach the item to the poll hooks and get current event bits */
revents = tfile->f_op->poll(tfile, &epq.pt);
/* If the file is already "ready" we drop it inside the ready list */
if ((revents & pfd->events) && !EP_IS_LINKED(&dpi->rdllink)) {
list_add_tail(&dpi->rdllink, &ep->rdllist);
......@@ -863,7 +882,10 @@ static int ep_insert(struct eventpoll *ep, struct pollfd *pfd, struct file *tfil
write_unlock_irqrestore(&ep->lock, flags);
poll_freewait(&epq.pt);
/* Add the current item to the list of active epoll hook for this file */
spin_lock(&tfile->f_ep_lock);
list_add_tail(&dpi->fllink, &tfile->f_ep_links);
spin_unlock(&tfile->f_ep_lock);
DNPRINTK(3, (KERN_INFO "[%p] eventpoll: ep_insert(%p, %d)\n",
current, ep, pfd->fd));
......@@ -884,13 +906,21 @@ static int ep_modify(struct eventpoll *ep, struct epitem *dpi, unsigned int even
unsigned int revents;
unsigned long flags;
write_lock_irqsave(&ep->lock, flags);
/*
* Set the new event interest mask before calling f_op->poll(), otherwise
* a potential race might occur. In fact if we do this operation inside
* the lock, an event might happen between the f_op->poll() call and the
* new event set registering.
*/
dpi->pfd.events = events;
/* Get current event bits */
/*
* Get current event bits. We can safely use the file* here because
* its usage count has been increased by the caller of this function.
*/
revents = dpi->file->f_op->poll(dpi->file, NULL);
/* Set the new event interest mask */
dpi->pfd.events = events;
write_lock_irqsave(&ep->lock, flags);
/* If the file is already "ready" we drop it inside the ready list */
if ((revents & events) && EP_IS_LINKED(&dpi->llink) &&
......@@ -910,20 +940,39 @@ static int ep_modify(struct eventpoll *ep, struct epitem *dpi, unsigned int even
}
/*
* This function unregister poll callbacks from the associated file descriptor.
* Since this must be called without holding "ep->lock" the atomic exchange trick
* will protect us from multiple unregister.
*/
static void ep_unregister_pollwait(struct eventpoll *ep, struct epitem *dpi)
{
int i, nwait;
/* This is called without locks, so we need the atomic exchange */
nwait = xchg(&dpi->nwait, 0);
/* Removes poll wait queue hooks */
for (i = 0; i < nwait; i++)
remove_wait_queue(dpi->wait[i].whead, &dpi->wait[i].wait);
}
/*
* Unlink the "struct epitem" from all places it might have been hooked up.
* This function must be called with write IRQ lock on "ep->lock".
*/
static int ep_unlink(struct eventpoll *ep, struct epitem *dpi)
{
int i;
int error;
/*
* It can happen that this one is called for an item already unlinked.
* The check protect us from doing a double unlink ( crash ).
*/
error = -ENOENT;
if (!EP_IS_LINKED(&dpi->llink))
goto not_linked;
goto eexit_1;
/*
* At this point is safe to do the job, unlink the item from our list.
......@@ -932,10 +981,6 @@ static int ep_unlink(struct eventpoll *ep, struct epitem *dpi)
*/
EP_LIST_DEL(&dpi->llink);
/* Removes poll wait queue hooks */
for (i = 0; i < dpi->nwait; i++)
remove_wait_queue(dpi->wait[i].whead, &dpi->wait[i].wait);
/*
* If the item we are going to remove is inside the ready file descriptors
* we want to remove it from this list to avoid stale events.
......@@ -943,12 +988,13 @@ static int ep_unlink(struct eventpoll *ep, struct epitem *dpi)
if (EP_IS_LINKED(&dpi->rdllink))
EP_LIST_DEL(&dpi->rdllink);
not_linked:
error = 0;
eexit_1:
DNPRINTK(3, (KERN_INFO "[%p] eventpoll: ep_unlink(%p, %d)\n",
current, ep, dpi->pfd.fd));
DNPRINTK(3, (KERN_INFO "[%p] eventpoll: ep_unlink(%p, %d) = %d\n",
current, ep, dpi->pfd.fd, error));
return 0;
return error;
}
......@@ -961,6 +1007,22 @@ static int ep_remove(struct eventpoll *ep, struct epitem *dpi)
int error;
unsigned long flags;
/*
* Removes poll wait queue hooks. We _have_ to do this without holding
* the "ep->lock" otherwise a deadlock might occur. This because of the
* sequence of the lock acquisition. Here we do "ep->lock" then the wait
* queue head lock when unregistering the wait queue. The wakeup callback
* will run by holding the wait queue head lock and will call our callback
* that will try to get "ep->lock".
*/
ep_unregister_pollwait(ep, dpi);
/* Remove the current item from the list of epoll hooks */
spin_lock(&dpi->file->f_ep_lock);
if (EP_IS_LINKED(&dpi->fllink))
EP_LIST_DEL(&dpi->fllink);
spin_unlock(&dpi->file->f_ep_lock);
/* We need to acquire the write IRQ lock before calling ep_unlink() */
write_lock_irqsave(&ep->lock, flags);
......@@ -972,14 +1034,14 @@ static int ep_remove(struct eventpoll *ep, struct epitem *dpi)
if (error)
goto eexit_1;
DNPRINTK(3, (KERN_INFO "[%p] eventpoll: ep_remove(%p, %d)\n",
current, ep, dpi->pfd.fd));
/* At this point it is safe to free the eventpoll item */
ep_release_epitem(dpi);
error = 0;
eexit_1:
DNPRINTK(3, (KERN_INFO "[%p] eventpoll: ep_remove(%p, %d) = %d\n",
current, ep, dpi->pfd.fd, error));
return error;
}
......@@ -1055,19 +1117,19 @@ static unsigned int ep_eventpoll_poll(struct file *file, poll_table *wait)
/*
* Perform the transfer of events to user space. Optimize the copy by
* caching EP_EVENT_BUFF_SIZE events at a time and then copying it to user space.
* Since we have to release the lock during the __copy_to_user() operation and
* during the f_op->poll() call, we try to collect the maximum number of items
* by reducing the irqlock/irqunlock switching rate.
*/
static int ep_events_transfer(struct eventpoll *ep, struct pollfd *events, int maxevents)
static int ep_collect_ready_items(struct eventpoll *ep, struct epitem **adpi, int maxdpi)
{
int eventcnt, ebufcnt, revents;
int ndpi;
unsigned long flags;
struct list_head *lsthead = &ep->rdllist;
struct pollfd eventbuf[EP_EVENT_BUFF_SIZE];
write_lock_irqsave(&ep->lock, flags);
for (eventcnt = 0, ebufcnt = 0; (eventcnt + ebufcnt) < maxevents && !list_empty(lsthead);) {
for (ndpi = 0; ndpi < maxdpi && !list_empty(lsthead);) {
struct epitem *dpi = list_entry(lsthead->next, struct epitem, rdllink);
/* Remove the item from the ready list */
......@@ -1081,41 +1143,112 @@ static int ep_events_transfer(struct eventpoll *ep, struct pollfd *events, int m
if (!EP_IS_LINKED(&dpi->llink))
continue;
/* Fetch event bits from the signaled file */
/*
* We need to increase the usage count of the "struct epitem" because
* another thread might call EP_CTL_DEL on this target and make the
* object to vanish underneath our nose.
*/
ep_use_epitem(dpi);
adpi[ndpi++] = dpi;
}
write_unlock_irqrestore(&ep->lock, flags);
return ndpi;
}
/*
* This function is called without holding the "ep->lock" since the call to
* __copy_to_user() might sleep, and also f_op->poll() might reenable the IRQ
* because of the way poll() is traditionally implemented in Linux.
*/
static int ep_send_events(struct eventpoll *ep, struct epitem **adpi, int ndpi,
struct pollfd *events)
{
int i, eventcnt, eventbuf, revents;
struct epitem *dpi;
struct pollfd pfd[EP_MAX_BUF_EVENTS];
for (i = 0, eventcnt = 0, eventbuf = 0; i < ndpi; i++, adpi++) {
dpi = *adpi;
/* Get the ready file event set */
revents = dpi->file->f_op->poll(dpi->file, NULL);
if (revents & dpi->pfd.events) {
eventbuf[ebufcnt] = dpi->pfd;
eventbuf[ebufcnt].revents = revents & eventbuf[ebufcnt].events;
ebufcnt++;
/* If our buffer page is full we need to flush it to user space */
if (ebufcnt == EP_EVENT_BUFF_SIZE) {
/*
* We need to drop the irqlock before using the function
* __copy_to_user() because it might fault.
*/
write_unlock_irqrestore(&ep->lock, flags);
if (__copy_to_user(&events[eventcnt], eventbuf,
ebufcnt * sizeof(struct pollfd)))
pfd[eventbuf] = dpi->pfd;
pfd[eventbuf].revents = revents & pfd[eventbuf].events;
eventbuf++;
if (eventbuf == EP_MAX_BUF_EVENTS) {
if (__copy_to_user(&events[eventcnt], pfd,
eventbuf * sizeof(struct pollfd))) {
for (; i < ndpi; i++, adpi++)
ep_release_epitem(*adpi);
return -EFAULT;
eventcnt += ebufcnt;
ebufcnt = 0;
write_lock_irqsave(&ep->lock, flags);
}
eventcnt += eventbuf;
eventbuf = 0;
}
}
ep_release_epitem(dpi);
}
write_unlock_irqrestore(&ep->lock, flags);
/* There might be still something inside our event buffer */
if (ebufcnt) {
if (__copy_to_user(&events[eventcnt], eventbuf,
ebufcnt * sizeof(struct pollfd)))
eventcnt = -EFAULT;
else
eventcnt += ebufcnt;
if (eventbuf) {
if (__copy_to_user(&events[eventcnt], pfd,
eventbuf * sizeof(struct pollfd)))
return -EFAULT;
eventcnt += eventbuf;
}
return eventcnt;
}
/*
* Perform the transfer of events to user space.
*/
static int ep_events_transfer(struct eventpoll *ep, struct pollfd *events, int maxevents)
{
int eventcnt, ndpi, sdpi, maxdpi;
struct epitem *adpi[EP_MAX_COLLECT_ITEMS];
/*
* We need to lock this because we could be hit by
* ep_notify_file_close() while we're transfering
* events to userspace. Read-holding "epsem" will lock
* out ep_notify_file_close() during the whole
* transfer loop and this will garantie us that the
* file will not vanish underneath our nose when
* we will call f_op->poll() from ep_send_events().
*/
down_read(&epsem);
for (eventcnt = 0; eventcnt < maxevents;) {
/* Maximum items we can extract this time */
maxdpi = min(EP_MAX_COLLECT_ITEMS, maxevents - eventcnt);
/* Collect/extract ready items */
ndpi = ep_collect_ready_items(ep, adpi, maxdpi);
if (ndpi) {
/* Send events to userspace */
sdpi = ep_send_events(ep, adpi, ndpi, &events[eventcnt]);
if (sdpi < 0) {
up_read(&epsem);
return sdpi;
}
eventcnt += sdpi;
}
if (ndpi < maxdpi)
break;
}
up_read(&epsem);
return eventcnt;
}
......@@ -1236,11 +1369,7 @@ static int __init eventpoll_init(void)
{
int error;
/* Initialize the list that will link "struct eventpoll" */
INIT_LIST_HEAD(&eplist);
/* Initialize the rwlock used to access "eplist" */
rwlock_init(&eplock);
init_rwsem(&epsem);
/* Allocates slab cache used to allocate "struct epitem" items */
error = -ENOMEM;
......
......@@ -50,6 +50,7 @@ struct file * get_empty_filp(void)
file_list_unlock();
return NULL;
}
ep_init_file_struct(f);
atomic_set(&f->f_count,1);
f->f_version = 0;
f->f_uid = current->fsuid;
......@@ -94,6 +95,7 @@ struct file * get_empty_filp(void)
int init_private_file(struct file *filp, struct dentry *dentry, int mode)
{
memset(filp, 0, sizeof(*filp));
ep_init_file_struct(filp);
filp->f_mode = mode;
atomic_set(&filp->f_count, 1);
filp->f_dentry = dentry;
......@@ -121,6 +123,10 @@ void __fput(struct file * file)
struct vfsmount * mnt = file->f_vfsmnt;
struct inode * inode = dentry->d_inode;
/*
* The function ep_notify_file_close() should be the first called
* in the file cleanup chain.
*/
ep_notify_file_close(file);
locks_remove_flock(file);
......
......@@ -163,7 +163,7 @@ static void devfs_register_partition(struct gendisk *dev, int part)
if (p[part-1].de)
return;
dir = devfs_get_parent(dev->disk_de);
dir = dev->de;
if (!dir)
return;
if (dev->flags & GENHD_FL_REMOVABLE)
......@@ -178,7 +178,6 @@ static void devfs_register_partition(struct gendisk *dev, int part)
#ifdef CONFIG_DEVFS_FS
static struct unique_numspace disc_numspace = UNIQUE_NUMBERSPACE_INITIALISER;
static devfs_handle_t cdroms;
static struct unique_numspace cdrom_numspace = UNIQUE_NUMBERSPACE_INITIALISER;
#endif
......@@ -189,7 +188,6 @@ static void devfs_create_partitions(struct gendisk *dev)
devfs_handle_t dir, slave;
unsigned int devfs_flags = DEVFS_FL_DEFAULT;
char dirname[64], symlink[16];
static devfs_handle_t devfs_handle;
if (dev->flags & GENHD_FL_REMOVABLE)
devfs_flags |= DEVFS_FL_REMOVABLE;
......@@ -206,19 +204,15 @@ static void devfs_create_partitions(struct gendisk *dev)
sprintf(dirname, "../%s/disc%d", dev->disk_name,
dev->first_minor >> dev->minor_shift);
dir = devfs_mk_dir(NULL, dirname + 3, NULL);
dev->de = dir;
}
if (!devfs_handle)
devfs_handle = devfs_mk_dir(NULL, "discs", NULL);
dev->number = devfs_alloc_unique_number (&disc_numspace);
sprintf(symlink, "disc%d", dev->number);
devfs_mk_symlink (devfs_handle, symlink, DEVFS_FL_DEFAULT,
sprintf(symlink, "discs/disc%d", dev->number);
devfs_mk_symlink(NULL, symlink, DEVFS_FL_DEFAULT,
dirname + pos, &slave, NULL);
dev->disk_de = devfs_register(dir, "disc", devfs_flags,
dev->major, dev->first_minor,
S_IFBLK | S_IRUSR | S_IWUSR, dev->fops, NULL);
devfs_auto_unregister(dev->disk_de, slave);
if (!(dev->flags & GENHD_FL_DEVFS))
devfs_auto_unregister (slave, dir);
#endif
}
......@@ -227,11 +221,8 @@ static void devfs_create_cdrom(struct gendisk *dev)
#ifdef CONFIG_DEVFS_FS
char vname[23];
if (!cdroms)
cdroms = devfs_mk_dir (NULL, "cdroms", NULL);
dev->number = devfs_alloc_unique_number(&cdrom_numspace);
sprintf(vname, "cdrom%d", dev->number);
sprintf(vname, "cdroms/cdrom%d", dev->number);
if (dev->de) {
int pos;
devfs_handle_t slave;
......@@ -245,10 +236,8 @@ static void devfs_create_cdrom(struct gendisk *dev)
pos = devfs_generate_path(dev->disk_de, rname+3, sizeof(rname)-3);
if (pos >= 0) {
strncpy(rname + pos, "../", 3);
devfs_mk_symlink(cdroms, vname,
DEVFS_FL_DEFAULT,
devfs_mk_symlink(NULL, vname, DEVFS_FL_DEFAULT,
rname + pos, &slave, NULL);
devfs_auto_unregister(dev->de, slave);
}
} else {
dev->disk_de = devfs_register (NULL, vname, DEVFS_FL_DEFAULT,
......@@ -264,10 +253,22 @@ static void devfs_remove_partitions(struct gendisk *dev)
#ifdef CONFIG_DEVFS_FS
devfs_unregister(dev->disk_de);
dev->disk_de = NULL;
if (dev->flags & GENHD_FL_CD)
if (dev->flags & GENHD_FL_CD) {
char name[64];
sprintf(name, "cdroms/cdrom%d", dev->number);
if (dev->de)
devfs_find_and_unregister(NULL, name, 0, 0, 0, 0);
devfs_dealloc_unique_number(&cdrom_numspace, dev->number);
else
} else {
char name[64];
sprintf(name, "discs/disc%d", dev->number);
devfs_find_and_unregister(NULL, name, 0, 0, 0, 0);
if (!(dev->flags & GENHD_FL_DEVFS)) {
devfs_unregister(dev->de);
dev->de = NULL;
}
devfs_dealloc_unique_number(&disc_numspace, dev->number);
}
#endif
}
......
......@@ -54,7 +54,7 @@ struct poll_table_page {
* poll table.
*/
void poll_freewait(poll_table* pt)
void __pollfreewait(poll_table* pt)
{
struct poll_table_page * p = pt->table;
while (p) {
......
......@@ -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,
......
......@@ -34,6 +34,9 @@ asmlinkage int sys_epoll_ctl(int epfd, int op, int fd, unsigned int events);
asmlinkage int sys_epoll_wait(int epfd, struct pollfd *events, int maxevents,
int timeout);
/* Used to initialize the epoll bits inside the "struct file" */
void ep_init_file_struct(struct file *file);
/* Used in fs/file_table.c:__fput() to unlink files from the eventpoll interface */
void ep_notify_file_close(struct file *file);
......
......@@ -506,6 +506,10 @@ struct file {
/* needed for tty driver, and maybe others */
void *private_data;
/* Used by fs/eventpoll.c to link all the hooks to this file */
struct list_head f_ep_links;
spinlock_t f_ep_lock;
};
extern spinlock_t files_lock;
#define file_list_lock() spin_lock(&files_lock);
......
......@@ -14,14 +14,17 @@ struct poll_table_page;
struct poll_table_struct;
typedef void (*poll_queue_proc)(struct file *, wait_queue_head_t *, struct poll_table_struct *);
typedef void (*poll_free_proc)(struct poll_table_struct *);
typedef struct poll_table_struct {
poll_queue_proc qproc;
poll_free_proc fproc;
int error;
struct poll_table_page * table;
} poll_table;
extern void __pollwait(struct file * filp, wait_queue_head_t * wait_address, poll_table *p);
extern void __pollfreewait(poll_table* pt);
static inline void poll_wait(struct file * filp, wait_queue_head_t * wait_address, poll_table *p)
{
......@@ -29,9 +32,10 @@ static inline void poll_wait(struct file * filp, wait_queue_head_t * wait_addres
p->qproc(filp, wait_address, p);
}
static inline void poll_initwait_ex(poll_table* pt, poll_queue_proc qproc)
static inline void poll_initwait_ex(poll_table* pt, poll_queue_proc qproc, poll_free_proc fproc)
{
pt->qproc = qproc;
pt->fproc = fproc;
pt->error = 0;
pt->table = NULL;
}
......@@ -39,10 +43,15 @@ static inline void poll_initwait_ex(poll_table* pt, poll_queue_proc qproc)
static inline void poll_initwait(poll_table* pt)
{
poll_initwait_ex(pt, __pollwait);
poll_initwait_ex(pt, __pollwait, __pollfreewait);
}
extern void poll_freewait(poll_table* pt);
static inline void poll_freewait(poll_table* pt)
{
if (pt && pt->fproc)
pt->fproc(pt);
}
/*
......
......@@ -269,7 +269,7 @@ EXPORT_SYMBOL(generic_file_llseek);
EXPORT_SYMBOL(remote_llseek);
EXPORT_SYMBOL(no_llseek);
EXPORT_SYMBOL(__pollwait);
EXPORT_SYMBOL(poll_freewait);
EXPORT_SYMBOL(__pollfreewait);
EXPORT_SYMBOL(ROOT_DEV);
EXPORT_SYMBOL(find_get_page);
EXPORT_SYMBOL(find_lock_page);
......
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