aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrond Myklebust <Trond.Myklebust@netapp.com>2005-10-18 17:24:35 -0400
committerTrond Myklebust <Trond.Myklebust@netapp.com>2005-10-18 17:24:35 -0400
commitba9b543d5bec0a7605952e2ba501fb8b0f3b6407 (patch)
treeedf67143a032c7b7867ee999f1deb01437a6bc99
parentc8f32be3874a310fa963d47b534a98be1a05a4cc (diff)
parent6fe43f9e3701f7a9f2be151a5e6cfe94b87e92f9 (diff)
Merge branch 'master' of ssh://rsync.linux-nfs.org/home/trondmy/www_sites/rsync.linux-nfs.org/pub/linux/nfs-2.6
-rw-r--r--MAINTAINERS7
-rw-r--r--Makefile4
-rw-r--r--arch/arm/kernel/vmlinux.lds.S15
-rw-r--r--arch/arm/mach-l7200/core.c20
-rw-r--r--arch/arm/mach-pxa/corgi_lcd.c20
-rw-r--r--arch/arm/mach-pxa/generic.c5
-rw-r--r--arch/arm/mach-pxa/spitz.c4
-rw-r--r--arch/arm/mach-s3c2410/Kconfig1
-rw-r--r--arch/m32r/kernel/smp.c12
-rw-r--r--arch/mips/pci/fixup-tb0226.c33
-rw-r--r--arch/ppc64/kernel/pmac_setup.c3
-rw-r--r--arch/sparc64/kernel/pci_iommu.c363
-rw-r--r--arch/sparc64/kernel/pci_psycho.c44
-rw-r--r--arch/sparc64/kernel/pci_sabre.c39
-rw-r--r--arch/sparc64/kernel/pci_schizo.c57
-rw-r--r--arch/sparc64/kernel/smp.c7
-rw-r--r--arch/sparc64/mm/ultra.S16
-rw-r--r--arch/sparc64/prom/misc.c12
-rw-r--r--drivers/acpi/event.c5
-rw-r--r--drivers/char/mbcs.c3
-rw-r--r--drivers/char/n_r3964.c8
-rw-r--r--drivers/input/keyboard/Kconfig2
-rw-r--r--drivers/input/keyboard/spitzkbd.c2
-rw-r--r--drivers/input/misc/uinput.c4
-rw-r--r--drivers/media/radio/radio-cadet.c2
-rw-r--r--drivers/media/video/vpx3220.c32
-rw-r--r--drivers/net/wireless/Kconfig2
-rw-r--r--drivers/pci/quirks.c4
-rw-r--r--drivers/pcmcia/soc_common.c14
-rw-r--r--drivers/scsi/Kconfig5
-rw-r--r--drivers/scsi/aacraid/linit.c2
-rw-r--r--drivers/scsi/qlogicpti.c39
-rw-r--r--drivers/serial/8250_pnp.c2
-rw-r--r--drivers/serial/sh-sci.c2
-rw-r--r--drivers/usb/host/isp116x-hcd.c3
-rw-r--r--drivers/usb/input/hid-core.c3
-rw-r--r--drivers/usb/serial/generic.c2
-rw-r--r--drivers/video/console/vgacon.c9
-rw-r--r--drivers/video/sa1100fb.c2
-rw-r--r--drivers/w1/w1.c3
-rw-r--r--fs/aio.c26
-rw-r--r--fs/exec.c12
-rw-r--r--fs/locks.c42
-rw-r--r--fs/namei.c95
-rw-r--r--fs/nfs/delegation.c6
-rw-r--r--fs/nfs/delegation.h16
-rw-r--r--fs/nfs/dir.c44
-rw-r--r--fs/nfs/file.c30
-rw-r--r--fs/nfs/inode.c17
-rw-r--r--fs/nfs/nfs3proc.c2
-rw-r--r--fs/nfs/nfs4_fs.h53
-rw-r--r--fs/nfs/nfs4proc.c577
-rw-r--r--fs/nfs/nfs4state.c165
-rw-r--r--fs/nfs/nfs4xdr.c62
-rw-r--r--fs/nfs/proc.c2
-rw-r--r--fs/open.c79
-rw-r--r--fs/proc/base.c12
-rw-r--r--fs/proc/nommu.c1
-rw-r--r--include/asm-arm/arch-pxa/pxafb.h1
-rw-r--r--include/asm-arm/arch-s3c2410/io.h58
-rw-r--r--include/asm-sparc64/pbm.h30
-rw-r--r--include/linux/acct.h4
-rw-r--r--include/linux/aio.h7
-rw-r--r--include/linux/cpumask.h16
-rw-r--r--include/linux/list.h39
-rw-r--r--include/linux/namei.h8
-rw-r--r--include/linux/nfs_xdr.h36
-rw-r--r--include/linux/rcupdate.h1
-rw-r--r--include/linux/sunrpc/xprt.h1
-rw-r--r--kernel/posix-cpu-timers.c3
-rw-r--r--kernel/rcupdate.c13
-rw-r--r--kernel/time.c1
-rw-r--r--mm/vmscan.c13
-rw-r--r--net/ipv6/netfilter/ip6_tables.c1
-rw-r--r--net/sunrpc/clnt.c26
-rw-r--r--net/sunrpc/xprt.c8
76 files changed, 1340 insertions, 979 deletions
diff --git a/MAINTAINERS b/MAINTAINERS
index abf7f7a17a..767fb61096 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1618,6 +1618,13 @@ M: vandrove@vc.cvut.cz
1618L: linux-fbdev-devel@lists.sourceforge.net 1618L: linux-fbdev-devel@lists.sourceforge.net
1619S: Maintained 1619S: Maintained
1620 1620
1621MEGARAID SCSI DRIVERS
1622P: Neela Syam Kolli
1623M: Neela.Kolli@engenio.com
1624S: linux-scsi@vger.kernel.org
1625W: http://megaraid.lsilogic.com
1626S: Maintained
1627
1621MEMORY TECHNOLOGY DEVICES 1628MEMORY TECHNOLOGY DEVICES
1622P: David Woodhouse 1629P: David Woodhouse
1623M: dwmw2@infradead.org 1630M: dwmw2@infradead.org
diff --git a/Makefile b/Makefile
index 504ba3ceb2..be33d758c0 100644
--- a/Makefile
+++ b/Makefile
@@ -660,8 +660,10 @@ quiet_cmd_sysmap = SYSMAP
660# Link of vmlinux 660# Link of vmlinux
661# If CONFIG_KALLSYMS is set .version is already updated 661# If CONFIG_KALLSYMS is set .version is already updated
662# Generate System.map and verify that the content is consistent 662# Generate System.map and verify that the content is consistent
663 663# Use + in front of the vmlinux_version rule to silent warning with make -j2
664# First command is ':' to allow us to use + in front of the rule
664define rule_vmlinux__ 665define rule_vmlinux__
666 :
665 $(if $(CONFIG_KALLSYMS),,+$(call cmd,vmlinux_version)) 667 $(if $(CONFIG_KALLSYMS),,+$(call cmd,vmlinux_version))
666 668
667 $(call cmd,vmlinux__) 669 $(call cmd,vmlinux__)
diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
index 08e58ecd44..0d5db5279c 100644
--- a/arch/arm/kernel/vmlinux.lds.S
+++ b/arch/arm/kernel/vmlinux.lds.S
@@ -89,13 +89,6 @@ SECTIONS
89 *(.got) /* Global offset table */ 89 *(.got) /* Global offset table */
90 } 90 }
91 91
92 . = ALIGN(16);
93 __ex_table : { /* Exception table */
94 __start___ex_table = .;
95 *(__ex_table)
96 __stop___ex_table = .;
97 }
98
99 RODATA 92 RODATA
100 93
101 _etext = .; /* End of text and rodata section */ 94 _etext = .; /* End of text and rodata section */
@@ -138,6 +131,14 @@ SECTIONS
138 *(.data.cacheline_aligned) 131 *(.data.cacheline_aligned)
139 132
140 /* 133 /*
134 * The exception fixup table (might need resorting at runtime)
135 */
136 . = ALIGN(32);
137 __start___ex_table = .;
138 *(__ex_table)
139 __stop___ex_table = .;
140
141 /*
141 * and the usual data section 142 * and the usual data section
142 */ 143 */
143 *(.data) 144 *(.data)
diff --git a/arch/arm/mach-l7200/core.c b/arch/arm/mach-l7200/core.c
index 5fd8c9f97f..03ed742ae2 100644
--- a/arch/arm/mach-l7200/core.c
+++ b/arch/arm/mach-l7200/core.c
@@ -7,11 +7,17 @@
7 */ 7 */
8#include <linux/kernel.h> 8#include <linux/kernel.h>
9#include <linux/init.h> 9#include <linux/init.h>
10#include <linux/device.h>
10 11
12#include <asm/types.h>
13#include <asm/irq.h>
14#include <asm/mach-types.h>
11#include <asm/hardware.h> 15#include <asm/hardware.h>
12#include <asm/page.h> 16#include <asm/page.h>
13 17
18#include <asm/mach/arch.h>
14#include <asm/mach/map.h> 19#include <asm/mach/map.h>
20#include <asm/mach/irq.h>
15 21
16/* 22/*
17 * IRQ base register 23 * IRQ base register
@@ -47,6 +53,12 @@ static void l7200_unmask_irq(unsigned int irq)
47{ 53{
48 IRQ_ENABLE = 1 << irq; 54 IRQ_ENABLE = 1 << irq;
49} 55}
56
57static struct irqchip l7200_irq_chip = {
58 .ack = l7200_mask_irq,
59 .mask = l7200_mask_irq,
60 .unmask = l7200_unmask_irq
61};
50 62
51static void __init l7200_init_irq(void) 63static void __init l7200_init_irq(void)
52{ 64{
@@ -56,11 +68,9 @@ static void __init l7200_init_irq(void)
56 FIQ_ENABLECLEAR = 0xffffffff; /* clear all fast interrupt enables */ 68 FIQ_ENABLECLEAR = 0xffffffff; /* clear all fast interrupt enables */
57 69
58 for (irq = 0; irq < NR_IRQS; irq++) { 70 for (irq = 0; irq < NR_IRQS; irq++) {
59 irq_desc[irq].valid = 1; 71 set_irq_chip(irq, &l7200_irq_chip);
60 irq_desc[irq].probe_ok = 1; 72 set_irq_flags(irq, IRQF_VALID);
61 irq_desc[irq].mask_ack = l7200_mask_irq; 73 set_irq_handler(irq, do_level_IRQ);
62 irq_desc[irq].mask = l7200_mask_irq;
63 irq_desc[irq].unmask = l7200_unmask_irq;
64 } 74 }
65 75
66 init_FIQ(); 76 init_FIQ();
diff --git a/arch/arm/mach-pxa/corgi_lcd.c b/arch/arm/mach-pxa/corgi_lcd.c
index c02ef7c0f7..850538fade 100644
--- a/arch/arm/mach-pxa/corgi_lcd.c
+++ b/arch/arm/mach-pxa/corgi_lcd.c
@@ -467,6 +467,7 @@ void corgi_put_hsync(void)
467{ 467{
468 if (get_hsync_time) 468 if (get_hsync_time)
469 symbol_put(w100fb_get_hsynclen); 469 symbol_put(w100fb_get_hsynclen);
470 get_hsync_time = NULL;
470} 471}
471 472
472void corgi_wait_hsync(void) 473void corgi_wait_hsync(void)
@@ -476,20 +477,37 @@ void corgi_wait_hsync(void)
476#endif 477#endif
477 478
478#ifdef CONFIG_PXA_SHARP_Cxx00 479#ifdef CONFIG_PXA_SHARP_Cxx00
480static struct device *spitz_pxafb_dev;
481
482static int is_pxafb_device(struct device * dev, void * data)
483{
484 struct platform_device *pdev = container_of(dev, struct platform_device, dev);
485
486 return (strncmp(pdev->name, "pxa2xx-fb", 9) == 0);
487}
488
479unsigned long spitz_get_hsync_len(void) 489unsigned long spitz_get_hsync_len(void)
480{ 490{
491 if (!spitz_pxafb_dev) {
492 spitz_pxafb_dev = bus_find_device(&platform_bus_type, NULL, NULL, is_pxafb_device);
493 if (!spitz_pxafb_dev)
494 return 0;
495 }
481 if (!get_hsync_time) 496 if (!get_hsync_time)
482 get_hsync_time = symbol_get(pxafb_get_hsync_time); 497 get_hsync_time = symbol_get(pxafb_get_hsync_time);
483 if (!get_hsync_time) 498 if (!get_hsync_time)
484 return 0; 499 return 0;
485 500
486 return pxafb_get_hsync_time(&pxafb_device.dev); 501 return pxafb_get_hsync_time(spitz_pxafb_dev);
487} 502}
488 503
489void spitz_put_hsync(void) 504void spitz_put_hsync(void)
490{ 505{
506 put_device(spitz_pxafb_dev);
491 if (get_hsync_time) 507 if (get_hsync_time)
492 symbol_put(pxafb_get_hsync_time); 508 symbol_put(pxafb_get_hsync_time);
509 spitz_pxafb_dev = NULL;
510 get_hsync_time = NULL;
493} 511}
494 512
495void spitz_wait_hsync(void) 513void spitz_wait_hsync(void)
diff --git a/arch/arm/mach-pxa/generic.c b/arch/arm/mach-pxa/generic.c
index d0660a8c4b..d327c127ed 100644
--- a/arch/arm/mach-pxa/generic.c
+++ b/arch/arm/mach-pxa/generic.c
@@ -208,6 +208,11 @@ static struct platform_device pxafb_device = {
208 .resource = pxafb_resources, 208 .resource = pxafb_resources,
209}; 209};
210 210
211void __init set_pxa_fb_parent(struct device *parent_dev)
212{
213 pxafb_device.dev.parent = parent_dev;
214}
215
211static struct platform_device ffuart_device = { 216static struct platform_device ffuart_device = {
212 .name = "pxa2xx-uart", 217 .name = "pxa2xx-uart",
213 .id = 0, 218 .id = 0,
diff --git a/arch/arm/mach-pxa/spitz.c b/arch/arm/mach-pxa/spitz.c
index 568afe3d6e..d0ab428c2d 100644
--- a/arch/arm/mach-pxa/spitz.c
+++ b/arch/arm/mach-pxa/spitz.c
@@ -36,7 +36,6 @@
36#include <asm/arch/irq.h> 36#include <asm/arch/irq.h>
37#include <asm/arch/mmc.h> 37#include <asm/arch/mmc.h>
38#include <asm/arch/udc.h> 38#include <asm/arch/udc.h>
39#include <asm/arch/ohci.h>
40#include <asm/arch/pxafb.h> 39#include <asm/arch/pxafb.h>
41#include <asm/arch/akita.h> 40#include <asm/arch/akita.h>
42#include <asm/arch/spitz.h> 41#include <asm/arch/spitz.h>
@@ -304,7 +303,6 @@ static struct platform_device *devices[] __initdata = {
304 &spitzkbd_device, 303 &spitzkbd_device,
305 &spitzts_device, 304 &spitzts_device,
306 &spitzbl_device, 305 &spitzbl_device,
307 &spitzbattery_device,
308}; 306};
309 307
310static void __init common_init(void) 308static void __init common_init(void)
@@ -328,7 +326,7 @@ static void __init common_init(void)
328 326
329 platform_add_devices(devices, ARRAY_SIZE(devices)); 327 platform_add_devices(devices, ARRAY_SIZE(devices));
330 pxa_set_mci_info(&spitz_mci_platform_data); 328 pxa_set_mci_info(&spitz_mci_platform_data);
331 pxafb_device.dev.parent = &spitzssp_device.dev; 329 set_pxa_fb_parent(&spitzssp_device.dev);
332 set_pxa_fb_info(&spitz_pxafb_info); 330 set_pxa_fb_info(&spitz_pxafb_info);
333} 331}
334 332
diff --git a/arch/arm/mach-s3c2410/Kconfig b/arch/arm/mach-s3c2410/Kconfig
index 06807c6ee6..c796bcdd61 100644
--- a/arch/arm/mach-s3c2410/Kconfig
+++ b/arch/arm/mach-s3c2410/Kconfig
@@ -12,6 +12,7 @@ config MACH_ANUBIS
12config ARCH_BAST 12config ARCH_BAST
13 bool "Simtec Electronics BAST (EB2410ITX)" 13 bool "Simtec Electronics BAST (EB2410ITX)"
14 select CPU_S3C2410 14 select CPU_S3C2410
15 select ISA
15 help 16 help
16 Say Y here if you are using the Simtec Electronics EB2410ITX 17 Say Y here if you are using the Simtec Electronics EB2410ITX
17 development board (also known as BAST) 18 development board (also known as BAST)
diff --git a/arch/m32r/kernel/smp.c b/arch/m32r/kernel/smp.c
index a4576ac7e8..8b1f6eb768 100644
--- a/arch/m32r/kernel/smp.c
+++ b/arch/m32r/kernel/smp.c
@@ -275,12 +275,14 @@ static void flush_tlb_all_ipi(void *info)
275 *==========================================================================*/ 275 *==========================================================================*/
276void smp_flush_tlb_mm(struct mm_struct *mm) 276void smp_flush_tlb_mm(struct mm_struct *mm)
277{ 277{
278 int cpu_id = smp_processor_id(); 278 int cpu_id;
279 cpumask_t cpu_mask; 279 cpumask_t cpu_mask;
280 unsigned long *mmc = &mm->context[cpu_id]; 280 unsigned long *mmc;
281 unsigned long flags; 281 unsigned long flags;
282 282
283 preempt_disable(); 283 preempt_disable();
284 cpu_id = smp_processor_id();
285 mmc = &mm->context[cpu_id];
284 cpu_mask = mm->cpu_vm_mask; 286 cpu_mask = mm->cpu_vm_mask;
285 cpu_clear(cpu_id, cpu_mask); 287 cpu_clear(cpu_id, cpu_mask);
286 288
@@ -343,12 +345,14 @@ void smp_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
343void smp_flush_tlb_page(struct vm_area_struct *vma, unsigned long va) 345void smp_flush_tlb_page(struct vm_area_struct *vma, unsigned long va)
344{ 346{
345 struct mm_struct *mm = vma->vm_mm; 347 struct mm_struct *mm = vma->vm_mm;
346 int cpu_id = smp_processor_id(); 348 int cpu_id;
347 cpumask_t cpu_mask; 349 cpumask_t cpu_mask;
348 unsigned long *mmc = &mm->context[cpu_id]; 350 unsigned long *mmc;
349 unsigned long flags; 351 unsigned long flags;
350 352
351 preempt_disable(); 353 preempt_disable();
354 cpu_id = smp_processor_id();
355 mmc = &mm->context[cpu_id];
352 cpu_mask = mm->cpu_vm_mask; 356 cpu_mask = mm->cpu_vm_mask;
353 cpu_clear(cpu_id, cpu_mask); 357 cpu_clear(cpu_id, cpu_mask);
354 358
diff --git a/arch/mips/pci/fixup-tb0226.c b/arch/mips/pci/fixup-tb0226.c
index 61513d5d97..b5d42b12de 100644
--- a/arch/mips/pci/fixup-tb0226.c
+++ b/arch/mips/pci/fixup-tb0226.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * fixup-tb0226.c, The TANBAC TB0226 specific PCI fixups. 2 * fixup-tb0226.c, The TANBAC TB0226 specific PCI fixups.
3 * 3 *
4 * Copyright (C) 2002-2004 Yoichi Yuasa <yuasa@hh.iij4u.or.jp> 4 * Copyright (C) 2002-2005 Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
@@ -20,6 +20,7 @@
20#include <linux/init.h> 20#include <linux/init.h>
21#include <linux/pci.h> 21#include <linux/pci.h>
22 22
23#include <asm/vr41xx/giu.h>
23#include <asm/vr41xx/tb0226.h> 24#include <asm/vr41xx/tb0226.h>
24 25
25int __init pcibios_map_irq(struct pci_dev *dev, u8 slot, u8 pin) 26int __init pcibios_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
@@ -29,42 +30,42 @@ int __init pcibios_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
29 switch (slot) { 30 switch (slot) {
30 case 12: 31 case 12:
31 vr41xx_set_irq_trigger(GD82559_1_PIN, 32 vr41xx_set_irq_trigger(GD82559_1_PIN,
32 TRIGGER_LEVEL, 33 IRQ_TRIGGER_LEVEL,
33 SIGNAL_THROUGH); 34 IRQ_SIGNAL_THROUGH);
34 vr41xx_set_irq_level(GD82559_1_PIN, LEVEL_LOW); 35 vr41xx_set_irq_level(GD82559_1_PIN, IRQ_LEVEL_LOW);
35 irq = GD82559_1_IRQ; 36 irq = GD82559_1_IRQ;
36 break; 37 break;
37 case 13: 38 case 13:
38 vr41xx_set_irq_trigger(GD82559_2_PIN, 39 vr41xx_set_irq_trigger(GD82559_2_PIN,
39 TRIGGER_LEVEL, 40 IRQ_TRIGGER_LEVEL,
40 SIGNAL_THROUGH); 41 IRQ_SIGNAL_THROUGH);
41 vr41xx_set_irq_level(GD82559_2_PIN, LEVEL_LOW); 42 vr41xx_set_irq_level(GD82559_2_PIN, IRQ_LEVEL_LOW);
42 irq = GD82559_2_IRQ; 43 irq = GD82559_2_IRQ;
43 break; 44 break;
44 case 14: 45 case 14:
45 switch (pin) { 46 switch (pin) {
46 case 1: 47 case 1:
47 vr41xx_set_irq_trigger(UPD720100_INTA_PIN, 48 vr41xx_set_irq_trigger(UPD720100_INTA_PIN,
48 TRIGGER_LEVEL, 49 IRQ_TRIGGER_LEVEL,
49 SIGNAL_THROUGH); 50 IRQ_SIGNAL_THROUGH);
50 vr41xx_set_irq_level(UPD720100_INTA_PIN, 51 vr41xx_set_irq_level(UPD720100_INTA_PIN,
51 LEVEL_LOW); 52 IRQ_LEVEL_LOW);
52 irq = UPD720100_INTA_IRQ; 53 irq = UPD720100_INTA_IRQ;
53 break; 54 break;
54 case 2: 55 case 2:
55 vr41xx_set_irq_trigger(UPD720100_INTB_PIN, 56 vr41xx_set_irq_trigger(UPD720100_INTB_PIN,
56 TRIGGER_LEVEL, 57 IRQ_TRIGGER_LEVEL,
57 SIGNAL_THROUGH); 58 IRQ_SIGNAL_THROUGH);
58 vr41xx_set_irq_level(UPD720100_INTB_PIN, 59 vr41xx_set_irq_level(UPD720100_INTB_PIN,
59 LEVEL_LOW); 60 IRQ_LEVEL_LOW);
60 irq = UPD720100_INTB_IRQ; 61 irq = UPD720100_INTB_IRQ;
61 break; 62 break;
62 case 3: 63 case 3:
63 vr41xx_set_irq_trigger(UPD720100_INTC_PIN, 64 vr41xx_set_irq_trigger(UPD720100_INTC_PIN,
64 TRIGGER_LEVEL, 65 IRQ_TRIGGER_LEVEL,
65 SIGNAL_THROUGH); 66 IRQ_SIGNAL_THROUGH);
66 vr41xx_set_irq_level(UPD720100_INTC_PIN, 67 vr41xx_set_irq_level(UPD720100_INTC_PIN,
67 LEVEL_LOW); 68 IRQ_LEVEL_LOW);
68 irq = UPD720100_INTC_IRQ; 69 irq = UPD720100_INTC_IRQ;
69 break; 70 break;
70 default: 71 default:
diff --git a/arch/ppc64/kernel/pmac_setup.c b/arch/ppc64/kernel/pmac_setup.c
index 2575525206..fa8121d53b 100644
--- a/arch/ppc64/kernel/pmac_setup.c
+++ b/arch/ppc64/kernel/pmac_setup.c
@@ -115,7 +115,7 @@ static void __pmac pmac_show_cpuinfo(struct seq_file *m)
115 115
116 /* find motherboard type */ 116 /* find motherboard type */
117 seq_printf(m, "machine\t\t: "); 117 seq_printf(m, "machine\t\t: ");
118 np = find_devices("device-tree"); 118 np = of_find_node_by_path("/");
119 if (np != NULL) { 119 if (np != NULL) {
120 pp = (char *) get_property(np, "model", NULL); 120 pp = (char *) get_property(np, "model", NULL);
121 if (pp != NULL) 121 if (pp != NULL)
@@ -133,6 +133,7 @@ static void __pmac pmac_show_cpuinfo(struct seq_file *m)
133 } 133 }
134 seq_printf(m, "\n"); 134 seq_printf(m, "\n");
135 } 135 }
136 of_node_put(np);
136 } else 137 } else
137 seq_printf(m, "PowerMac\n"); 138 seq_printf(m, "PowerMac\n");
138 139
diff --git a/arch/sparc64/kernel/pci_iommu.c b/arch/sparc64/kernel/pci_iommu.c
index 425c60cfea..a11910be10 100644
--- a/arch/sparc64/kernel/pci_iommu.c
+++ b/arch/sparc64/kernel/pci_iommu.c
@@ -49,12 +49,6 @@ static void __iommu_flushall(struct pci_iommu *iommu)
49 49
50 /* Ensure completion of previous PIO writes. */ 50 /* Ensure completion of previous PIO writes. */
51 (void) pci_iommu_read(iommu->write_complete_reg); 51 (void) pci_iommu_read(iommu->write_complete_reg);
52
53 /* Now update everyone's flush point. */
54 for (entry = 0; entry < PBM_NCLUSTERS; entry++) {
55 iommu->alloc_info[entry].flush =
56 iommu->alloc_info[entry].next;
57 }
58} 52}
59 53
60#define IOPTE_CONSISTENT(CTX) \ 54#define IOPTE_CONSISTENT(CTX) \
@@ -80,120 +74,117 @@ static void inline iopte_make_dummy(struct pci_iommu *iommu, iopte_t *iopte)
80 iopte_val(*iopte) = val; 74 iopte_val(*iopte) = val;
81} 75}
82 76
83void pci_iommu_table_init(struct pci_iommu *iommu, int tsbsize) 77/* Based largely upon the ppc64 iommu allocator. */
78static long pci_arena_alloc(struct pci_iommu *iommu, unsigned long npages)
84{ 79{
85 int i; 80 struct pci_iommu_arena *arena = &iommu->arena;
86 81 unsigned long n, i, start, end, limit;
87 tsbsize /= sizeof(iopte_t); 82 int pass;
88 83
89 for (i = 0; i < tsbsize; i++) 84 limit = arena->limit;
90 iopte_make_dummy(iommu, &iommu->page_table[i]); 85 start = arena->hint;
91} 86 pass = 0;
92 87
93static iopte_t *alloc_streaming_cluster(struct pci_iommu *iommu, unsigned long npages) 88again:
94{ 89 n = find_next_zero_bit(arena->map, limit, start);
95 iopte_t *iopte, *limit, *first; 90 end = n + npages;
96 unsigned long cnum, ent, flush_point; 91 if (unlikely(end >= limit)) {
97 92 if (likely(pass < 1)) {
98 cnum = 0; 93 limit = start;
99 while ((1UL << cnum) < npages) 94 start = 0;
100 cnum++; 95 __iommu_flushall(iommu);
101 iopte = (iommu->page_table + 96 pass++;
102 (cnum << (iommu->page_table_sz_bits - PBM_LOGCLUSTERS))); 97 goto again;
103 98 } else {
104 if (cnum == 0) 99 /* Scanned the whole thing, give up. */
105 limit = (iommu->page_table + 100 return -1;
106 iommu->lowest_consistent_map);
107 else
108 limit = (iopte +
109 (1 << (iommu->page_table_sz_bits - PBM_LOGCLUSTERS)));
110
111 iopte += ((ent = iommu->alloc_info[cnum].next) << cnum);
112 flush_point = iommu->alloc_info[cnum].flush;
113
114 first = iopte;
115 for (;;) {
116 if (IOPTE_IS_DUMMY(iommu, iopte)) {
117 if ((iopte + (1 << cnum)) >= limit)
118 ent = 0;
119 else
120 ent = ent + 1;
121 iommu->alloc_info[cnum].next = ent;
122 if (ent == flush_point)
123 __iommu_flushall(iommu);
124 break;
125 } 101 }
126 iopte += (1 << cnum); 102 }
127 ent++; 103
128 if (iopte >= limit) { 104 for (i = n; i < end; i++) {
129 iopte = (iommu->page_table + 105 if (test_bit(i, arena->map)) {
130 (cnum << 106 start = i + 1;
131 (iommu->page_table_sz_bits - PBM_LOGCLUSTERS))); 107 goto again;
132 ent = 0;
133 } 108 }
134 if (ent == flush_point)
135 __iommu_flushall(iommu);
136 if (iopte == first)
137 goto bad;
138 } 109 }
139 110
140 /* I've got your streaming cluster right here buddy boy... */ 111 for (i = n; i < end; i++)
141 return iopte; 112 __set_bit(i, arena->map);
142 113
143bad: 114 arena->hint = end;
144 printk(KERN_EMERG "pci_iommu: alloc_streaming_cluster of npages(%ld) failed!\n", 115
145 npages); 116 return n;
146 return NULL;
147} 117}
148 118
149static void free_streaming_cluster(struct pci_iommu *iommu, dma_addr_t base, 119static void pci_arena_free(struct pci_iommu_arena *arena, unsigned long base, unsigned long npages)
150 unsigned long npages, unsigned long ctx)
151{ 120{
152 unsigned long cnum, ent; 121 unsigned long i;
153 122
154 cnum = 0; 123 for (i = base; i < (base + npages); i++)
155 while ((1UL << cnum) < npages) 124 __clear_bit(i, arena->map);
156 cnum++; 125}
157 126
158 ent = (base << (32 - IO_PAGE_SHIFT + PBM_LOGCLUSTERS - iommu->page_table_sz_bits)) 127void pci_iommu_table_init(struct pci_iommu *iommu, int tsbsize, u32 dma_offset, u32 dma_addr_mask)
159 >> (32 + PBM_LOGCLUSTERS + cnum - iommu->page_table_sz_bits); 128{
129 unsigned long i, tsbbase, order, sz, num_tsb_entries;
130
131 num_tsb_entries = tsbsize / sizeof(iopte_t);
132
133 /* Setup initial software IOMMU state. */
134 spin_lock_init(&iommu->lock);
135 iommu->ctx_lowest_free = 1;
136 iommu->page_table_map_base = dma_offset;
137 iommu->dma_addr_mask = dma_addr_mask;
138
139 /* Allocate and initialize the free area map. */
140 sz = num_tsb_entries / 8;
141 sz = (sz + 7UL) & ~7UL;
142 iommu->arena.map = kmalloc(sz, GFP_KERNEL);
143 if (!iommu->arena.map) {
144 prom_printf("PCI_IOMMU: Error, kmalloc(arena.map) failed.\n");
145 prom_halt();
146 }
147 memset(iommu->arena.map, 0, sz);
148 iommu->arena.limit = num_tsb_entries;
160 149
161 /* If the global flush might not have caught this entry, 150 /* Allocate and initialize the dummy page which we
162 * adjust the flush point such that we will flush before 151 * set inactive IO PTEs to point to.
163 * ever trying to reuse it.
164 */ 152 */
165#define between(X,Y,Z) (((Z) - (Y)) >= ((X) - (Y))) 153 iommu->dummy_page = __get_free_pages(GFP_KERNEL, 0);
166 if (between(ent, iommu->alloc_info[cnum].next, iommu->alloc_info[cnum].flush)) 154 if (!iommu->dummy_page) {
167 iommu->alloc_info[cnum].flush = ent; 155 prom_printf("PCI_IOMMU: Error, gfp(dummy_page) failed.\n");
168#undef between 156 prom_halt();
157 }
158 memset((void *)iommu->dummy_page, 0, PAGE_SIZE);
159 iommu->dummy_page_pa = (unsigned long) __pa(iommu->dummy_page);
160
161 /* Now allocate and setup the IOMMU page table itself. */
162 order = get_order(tsbsize);
163 tsbbase = __get_free_pages(GFP_KERNEL, order);
164 if (!tsbbase) {
165 prom_printf("PCI_IOMMU: Error, gfp(tsb) failed.\n");
166 prom_halt();
167 }
168 iommu->page_table = (iopte_t *)tsbbase;
169
170 for (i = 0; i < num_tsb_entries; i++)
171 iopte_make_dummy(iommu, &iommu->page_table[i]);
169} 172}
170 173
171/* We allocate consistent mappings from the end of cluster zero. */ 174static inline iopte_t *alloc_npages(struct pci_iommu *iommu, unsigned long npages)
172static iopte_t *alloc_consistent_cluster(struct pci_iommu *iommu, unsigned long npages)
173{ 175{
174 iopte_t *iopte; 176 long entry;
175 177
176 iopte = iommu->page_table + (1 << (iommu->page_table_sz_bits - PBM_LOGCLUSTERS)); 178 entry = pci_arena_alloc(iommu, npages);
177 while (iopte > iommu->page_table) { 179 if (unlikely(entry < 0))
178 iopte--; 180 return NULL;
179 if (IOPTE_IS_DUMMY(iommu, iopte)) {
180 unsigned long tmp = npages;
181 181
182 while (--tmp) { 182 return iommu->page_table + entry;
183 iopte--; 183}
184 if (!IOPTE_IS_DUMMY(iommu, iopte))
185 break;
186 }
187 if (tmp == 0) {
188 u32 entry = (iopte - iommu->page_table);
189 184
190 if (entry < iommu->lowest_consistent_map) 185static inline void free_npages(struct pci_iommu *iommu, dma_addr_t base, unsigned long npages)
191 iommu->lowest_consistent_map = entry; 186{
192 return iopte; 187 pci_arena_free(&iommu->arena, base >> IO_PAGE_SHIFT, npages);
193 }
194 }
195 }
196 return NULL;
197} 188}
198 189
199static int iommu_alloc_ctx(struct pci_iommu *iommu) 190static int iommu_alloc_ctx(struct pci_iommu *iommu)
@@ -233,7 +224,7 @@ void *pci_alloc_consistent(struct pci_dev *pdev, size_t size, dma_addr_t *dma_ad
233 struct pcidev_cookie *pcp; 224 struct pcidev_cookie *pcp;
234 struct pci_iommu *iommu; 225 struct pci_iommu *iommu;
235 iopte_t *iopte; 226 iopte_t *iopte;
236 unsigned long flags, order, first_page, ctx; 227 unsigned long flags, order, first_page;
237 void *ret; 228 void *ret;
238 int npages; 229 int npages;
239 230
@@ -251,9 +242,10 @@ void *pci_alloc_consistent(struct pci_dev *pdev, size_t size, dma_addr_t *dma_ad
251 iommu = pcp->pbm->iommu; 242 iommu = pcp->pbm->iommu;
252 243
253 spin_lock_irqsave(&iommu->lock, flags); 244 spin_lock_irqsave(&iommu->lock, flags);
254 iopte = alloc_consistent_cluster(iommu, size >> IO_PAGE_SHIFT); 245 iopte = alloc_npages(iommu, size >> IO_PAGE_SHIFT);
255 if (iopte == NULL) { 246 spin_unlock_irqrestore(&iommu->lock, flags);
256 spin_unlock_irqrestore(&iommu->lock, flags); 247
248 if (unlikely(iopte == NULL)) {
257 free_pages(first_page, order); 249 free_pages(first_page, order);
258 return NULL; 250 return NULL;
259 } 251 }
@@ -262,31 +254,15 @@ void *pci_alloc_consistent(struct pci_dev *pdev, size_t size, dma_addr_t *dma_ad
262 ((iopte - iommu->page_table) << IO_PAGE_SHIFT)); 254 ((iopte - iommu->page_table) << IO_PAGE_SHIFT));
263 ret = (void *) first_page; 255 ret = (void *) first_page;
264 npages = size >> IO_PAGE_SHIFT; 256 npages = size >> IO_PAGE_SHIFT;
265 ctx = 0;
266 if (iommu->iommu_ctxflush)
267 ctx = iommu_alloc_ctx(iommu);
268 first_page = __pa(first_page); 257 first_page = __pa(first_page);
269 while (npages--) { 258 while (npages--) {
270 iopte_val(*iopte) = (IOPTE_CONSISTENT(ctx) | 259 iopte_val(*iopte) = (IOPTE_CONSISTENT(0UL) |
271 IOPTE_WRITE | 260 IOPTE_WRITE |
272 (first_page & IOPTE_PAGE)); 261 (first_page & IOPTE_PAGE));
273 iopte++; 262 iopte++;
274 first_page += IO_PAGE_SIZE; 263 first_page += IO_PAGE_SIZE;
275 } 264 }
276 265
277 {
278 int i;
279 u32 daddr = *dma_addrp;
280
281 npages = size >> IO_PAGE_SHIFT;
282 for (i = 0; i < npages; i++) {
283 pci_iommu_write(iommu->iommu_flush, daddr);
284 daddr += IO_PAGE_SIZE;
285 }
286 }
287
288 spin_unlock_irqrestore(&iommu->lock, flags);
289
290 return ret; 266 return ret;
291} 267}
292 268
@@ -296,7 +272,7 @@ void pci_free_consistent(struct pci_dev *pdev, size_t size, void *cpu, dma_addr_
296 struct pcidev_cookie *pcp; 272 struct pcidev_cookie *pcp;
297 struct pci_iommu *iommu; 273 struct pci_iommu *iommu;
298 iopte_t *iopte; 274 iopte_t *iopte;
299 unsigned long flags, order, npages, i, ctx; 275 unsigned long flags, order, npages;
300 276
301 npages = IO_PAGE_ALIGN(size) >> IO_PAGE_SHIFT; 277 npages = IO_PAGE_ALIGN(size) >> IO_PAGE_SHIFT;
302 pcp = pdev->sysdata; 278 pcp = pdev->sysdata;
@@ -306,46 +282,7 @@ void pci_free_consistent(struct pci_dev *pdev, size_t size, void *cpu, dma_addr_
306 282
307 spin_lock_irqsave(&iommu->lock, flags); 283 spin_lock_irqsave(&iommu->lock, flags);
308 284
309 if ((iopte - iommu->page_table) == 285 free_npages(iommu, dvma, npages);
310 iommu->lowest_consistent_map) {
311 iopte_t *walk = iopte + npages;
312 iopte_t *limit;
313
314 limit = (iommu->page_table +
315 (1 << (iommu->page_table_sz_bits - PBM_LOGCLUSTERS)));
316 while (walk < limit) {
317 if (!IOPTE_IS_DUMMY(iommu, walk))
318 break;
319 walk++;
320 }
321 iommu->lowest_consistent_map =
322 (walk - iommu->page_table);
323 }
324
325 /* Data for consistent mappings cannot enter the streaming
326 * buffers, so we only need to update the TSB. We flush
327 * the IOMMU here as well to prevent conflicts with the
328 * streaming mapping deferred tlb flush scheme.
329 */
330
331 ctx = 0;
332 if (iommu->iommu_ctxflush)
333 ctx = (iopte_val(*iopte) & IOPTE_CONTEXT) >> 47UL;
334
335 for (i = 0; i < npages; i++, iopte++)
336 iopte_make_dummy(iommu, iopte);
337
338 if (iommu->iommu_ctxflush) {
339 pci_iommu_write(iommu->iommu_ctxflush, ctx);
340 } else {
341 for (i = 0; i < npages; i++) {
342 u32 daddr = dvma + (i << IO_PAGE_SHIFT);
343
344 pci_iommu_write(iommu->iommu_flush, daddr);
345 }
346 }
347
348 iommu_free_ctx(iommu, ctx);
349 286
350 spin_unlock_irqrestore(&iommu->lock, flags); 287 spin_unlock_irqrestore(&iommu->lock, flags);
351 288
@@ -372,25 +309,27 @@ dma_addr_t pci_map_single(struct pci_dev *pdev, void *ptr, size_t sz, int direct
372 iommu = pcp->pbm->iommu; 309 iommu = pcp->pbm->iommu;
373 strbuf = &pcp->pbm->stc; 310 strbuf = &pcp->pbm->stc;
374 311
375 if (direction == PCI_DMA_NONE) 312 if (unlikely(direction == PCI_DMA_NONE))
376 BUG(); 313 goto bad_no_ctx;
377 314
378 oaddr = (unsigned long)ptr; 315 oaddr = (unsigned long)ptr;
379 npages = IO_PAGE_ALIGN(oaddr + sz) - (oaddr & IO_PAGE_MASK); 316 npages = IO_PAGE_ALIGN(oaddr + sz) - (oaddr & IO_PAGE_MASK);
380 npages >>= IO_PAGE_SHIFT; 317 npages >>= IO_PAGE_SHIFT;
381 318
382 spin_lock_irqsave(&iommu->lock, flags); 319 spin_lock_irqsave(&iommu->lock, flags);
320 base = alloc_npages(iommu, npages);
321 ctx = 0;
322 if (iommu->iommu_ctxflush)
323 ctx = iommu_alloc_ctx(iommu);
324 spin_unlock_irqrestore(&iommu->lock, flags);
383 325
384 base = alloc_streaming_cluster(iommu, npages); 326 if (unlikely(!base))
385 if (base == NULL)
386 goto bad; 327 goto bad;
328
387 bus_addr = (iommu->page_table_map_base + 329 bus_addr = (iommu->page_table_map_base +
388 ((base - iommu->page_table) << IO_PAGE_SHIFT)); 330 ((base - iommu->page_table) << IO_PAGE_SHIFT));
389 ret = bus_addr | (oaddr & ~IO_PAGE_MASK); 331 ret = bus_addr | (oaddr & ~IO_PAGE_MASK);
390 base_paddr = __pa(oaddr & IO_PAGE_MASK); 332 base_paddr = __pa(oaddr & IO_PAGE_MASK);
391 ctx = 0;
392 if (iommu->iommu_ctxflush)
393 ctx = iommu_alloc_ctx(iommu);
394 if (strbuf->strbuf_enabled) 333 if (strbuf->strbuf_enabled)
395 iopte_protection = IOPTE_STREAMING(ctx); 334 iopte_protection = IOPTE_STREAMING(ctx);
396 else 335 else
@@ -401,12 +340,13 @@ dma_addr_t pci_map_single(struct pci_dev *pdev, void *ptr, size_t sz, int direct
401 for (i = 0; i < npages; i++, base++, base_paddr += IO_PAGE_SIZE) 340 for (i = 0; i < npages; i++, base++, base_paddr += IO_PAGE_SIZE)
402 iopte_val(*base) = iopte_protection | base_paddr; 341 iopte_val(*base) = iopte_protection | base_paddr;
403 342
404 spin_unlock_irqrestore(&iommu->lock, flags);
405
406 return ret; 343 return ret;
407 344
408bad: 345bad:
409 spin_unlock_irqrestore(&iommu->lock, flags); 346 iommu_free_ctx(iommu, ctx);
347bad_no_ctx:
348 if (printk_ratelimit())
349 WARN_ON(1);
410 return PCI_DMA_ERROR_CODE; 350 return PCI_DMA_ERROR_CODE;
411} 351}
412 352
@@ -481,10 +421,13 @@ void pci_unmap_single(struct pci_dev *pdev, dma_addr_t bus_addr, size_t sz, int
481 struct pci_iommu *iommu; 421 struct pci_iommu *iommu;
482 struct pci_strbuf *strbuf; 422 struct pci_strbuf *strbuf;
483 iopte_t *base; 423 iopte_t *base;
484 unsigned long flags, npages, ctx; 424 unsigned long flags, npages, ctx, i;
485 425
486 if (direction == PCI_DMA_NONE) 426 if (unlikely(direction == PCI_DMA_NONE)) {
487 BUG(); 427 if (printk_ratelimit())
428 WARN_ON(1);
429 return;
430 }
488 431
489 pcp = pdev->sysdata; 432 pcp = pdev->sysdata;
490 iommu = pcp->pbm->iommu; 433 iommu = pcp->pbm->iommu;
@@ -510,13 +453,14 @@ void pci_unmap_single(struct pci_dev *pdev, dma_addr_t bus_addr, size_t sz, int
510 453
511 /* Step 1: Kick data out of streaming buffers if necessary. */ 454 /* Step 1: Kick data out of streaming buffers if necessary. */
512 if (strbuf->strbuf_enabled) 455 if (strbuf->strbuf_enabled)
513 pci_strbuf_flush(strbuf, iommu, bus_addr, ctx, npages, direction); 456 pci_strbuf_flush(strbuf, iommu, bus_addr, ctx,
457 npages, direction);
514 458
515 /* Step 2: Clear out first TSB entry. */ 459 /* Step 2: Clear out TSB entries. */
516 iopte_make_dummy(iommu, base); 460 for (i = 0; i < npages; i++)
461 iopte_make_dummy(iommu, base + i);
517 462
518 free_streaming_cluster(iommu, bus_addr - iommu->page_table_map_base, 463 free_npages(iommu, bus_addr - iommu->page_table_map_base, npages);
519 npages, ctx);
520 464
521 iommu_free_ctx(iommu, ctx); 465 iommu_free_ctx(iommu, ctx);
522 466
@@ -621,6 +565,8 @@ int pci_map_sg(struct pci_dev *pdev, struct scatterlist *sglist, int nelems, int
621 pci_map_single(pdev, 565 pci_map_single(pdev,
622 (page_address(sglist->page) + sglist->offset), 566 (page_address(sglist->page) + sglist->offset),
623 sglist->length, direction); 567 sglist->length, direction);
568 if (unlikely(sglist->dma_address == PCI_DMA_ERROR_CODE))
569 return 0;
624 sglist->dma_length = sglist->length; 570 sglist->dma_length = sglist->length;
625 return 1; 571 return 1;
626 } 572 }
@@ -629,21 +575,29 @@ int pci_map_sg(struct pci_dev *pdev, struct scatterlist *sglist, int nelems, int
629 iommu = pcp->pbm->iommu; 575 iommu = pcp->pbm->iommu;
630 strbuf = &pcp->pbm->stc; 576 strbuf = &pcp->pbm->stc;
631 577
632 if (direction == PCI_DMA_NONE) 578 if (unlikely(direction == PCI_DMA_NONE))
633 BUG(); 579 goto bad_no_ctx;
634 580
635 /* Step 1: Prepare scatter list. */ 581 /* Step 1: Prepare scatter list. */
636 582
637 npages = prepare_sg(sglist, nelems); 583 npages = prepare_sg(sglist, nelems);
638 584
639 /* Step 2: Allocate a cluster. */ 585 /* Step 2: Allocate a cluster and context, if necessary. */
640 586
641 spin_lock_irqsave(&iommu->lock, flags); 587 spin_lock_irqsave(&iommu->lock, flags);
642 588
643 base = alloc_streaming_cluster(iommu, npages); 589 base = alloc_npages(iommu, npages);
590 ctx = 0;
591 if (iommu->iommu_ctxflush)
592 ctx = iommu_alloc_ctx(iommu);
593
594 spin_unlock_irqrestore(&iommu->lock, flags);
595
644 if (base == NULL) 596 if (base == NULL)
645 goto bad; 597 goto bad;
646 dma_base = iommu->page_table_map_base + ((base - iommu->page_table) << IO_PAGE_SHIFT); 598
599 dma_base = iommu->page_table_map_base +
600 ((base - iommu->page_table) << IO_PAGE_SHIFT);
647 601
648 /* Step 3: Normalize DMA addresses. */ 602 /* Step 3: Normalize DMA addresses. */
649 used = nelems; 603 used = nelems;
@@ -656,30 +610,28 @@ int pci_map_sg(struct pci_dev *pdev, struct scatterlist *sglist, int nelems, int
656 } 610 }
657 used = nelems - used; 611 used = nelems - used;
658 612
659 /* Step 4: Choose a context if necessary. */ 613 /* Step 4: Create the mappings. */
660 ctx = 0;
661 if (iommu->iommu_ctxflush)
662 ctx = iommu_alloc_ctx(iommu);
663
664 /* Step 5: Create the mappings. */
665 if (strbuf->strbuf_enabled) 614 if (strbuf->strbuf_enabled)
666 iopte_protection = IOPTE_STREAMING(ctx); 615 iopte_protection = IOPTE_STREAMING(ctx);
667 else 616 else
668 iopte_protection = IOPTE_CONSISTENT(ctx); 617 iopte_protection = IOPTE_CONSISTENT(ctx);
669 if (direction != PCI_DMA_TODEVICE) 618 if (direction != PCI_DMA_TODEVICE)
670 iopte_protection |= IOPTE_WRITE; 619 iopte_protection |= IOPTE_WRITE;
671 fill_sg (base, sglist, used, nelems, iopte_protection); 620
621 fill_sg(base, sglist, used, nelems, iopte_protection);
622
672#ifdef VERIFY_SG 623#ifdef VERIFY_SG
673 verify_sglist(sglist, nelems, base, npages); 624 verify_sglist(sglist, nelems, base, npages);
674#endif 625#endif
675 626
676 spin_unlock_irqrestore(&iommu->lock, flags);
677
678 return used; 627 return used;
679 628
680bad: 629bad:
681 spin_unlock_irqrestore(&iommu->lock, flags); 630 iommu_free_ctx(iommu, ctx);
682 return PCI_DMA_ERROR_CODE; 631bad_no_ctx:
632 if (printk_ratelimit())
633 WARN_ON(1);
634 return 0;
683} 635}
684 636
685/* Unmap a set of streaming mode DMA translations. */ 637/* Unmap a set of streaming mode DMA translations. */
@@ -692,8 +644,10 @@ void pci_unmap_sg(struct pci_dev *pdev, struct scatterlist *sglist, int nelems,
692 unsigned long flags, ctx, i, npages; 644 unsigned long flags, ctx, i, npages;
693 u32 bus_addr; 645 u32 bus_addr;
694 646
695 if (direction == PCI_DMA_NONE) 647 if (unlikely(direction == PCI_DMA_NONE)) {
696 BUG(); 648 if (printk_ratelimit())
649 WARN_ON(1);
650 }
697 651
698 pcp = pdev->sysdata; 652 pcp = pdev->sysdata;
699 iommu = pcp->pbm->iommu; 653 iommu = pcp->pbm->iommu;
@@ -705,7 +659,8 @@ void pci_unmap_sg(struct pci_dev *pdev, struct scatterlist *sglist, int nelems,
705 if (sglist[i].dma_length == 0) 659 if (sglist[i].dma_length == 0)
706 break; 660 break;
707 i--; 661 i--;
708 npages = (IO_PAGE_ALIGN(sglist[i].dma_address + sglist[i].dma_length) - bus_addr) >> IO_PAGE_SHIFT; 662 npages = (IO_PAGE_ALIGN(sglist[i].dma_address + sglist[i].dma_length) -
663 bus_addr) >> IO_PAGE_SHIFT;
709 664
710 base = iommu->page_table + 665 base = iommu->page_table +
711 ((bus_addr - iommu->page_table_map_base) >> IO_PAGE_SHIFT); 666 ((bus_addr - iommu->page_table_map_base) >> IO_PAGE_SHIFT);
@@ -726,11 +681,11 @@ void pci_unmap_sg(struct pci_dev *pdev, struct scatterlist *sglist, int nelems,
726 if (strbuf->strbuf_enabled) 681 if (strbuf->strbuf_enabled)
727 pci_strbuf_flush(strbuf, iommu, bus_addr, ctx, npages, direction); 682 pci_strbuf_flush(strbuf, iommu, bus_addr, ctx, npages, direction);
728 683
729 /* Step 2: Clear out first TSB entry. */ 684 /* Step 2: Clear out the TSB entries. */
730 iopte_make_dummy(iommu, base); 685 for (i = 0; i < npages; i++)
686 iopte_make_dummy(iommu, base + i);
731 687
732 free_streaming_cluster(iommu, bus_addr - iommu->page_table_map_base, 688 free_npages(iommu, bus_addr - iommu->page_table_map_base, npages);
733 npages, ctx);
734 689
735 iommu_free_ctx(iommu, ctx); 690 iommu_free_ctx(iommu, ctx);
736 691
diff --git a/arch/sparc64/kernel/pci_psycho.c b/arch/sparc64/kernel/pci_psycho.c
index 6ed1ef25e0..c03ed5f49d 100644
--- a/arch/sparc64/kernel/pci_psycho.c
+++ b/arch/sparc64/kernel/pci_psycho.c
@@ -1207,13 +1207,9 @@ static void psycho_scan_bus(struct pci_controller_info *p)
1207static void psycho_iommu_init(struct pci_controller_info *p) 1207static void psycho_iommu_init(struct pci_controller_info *p)
1208{ 1208{
1209 struct pci_iommu *iommu = p->pbm_A.iommu; 1209 struct pci_iommu *iommu = p->pbm_A.iommu;
1210 unsigned long tsbbase, i; 1210 unsigned long i;
1211 u64 control; 1211 u64 control;
1212 1212
1213 /* Setup initial software IOMMU state. */
1214 spin_lock_init(&iommu->lock);
1215 iommu->ctx_lowest_free = 1;
1216
1217 /* Register addresses. */ 1213 /* Register addresses. */
1218 iommu->iommu_control = p->pbm_A.controller_regs + PSYCHO_IOMMU_CONTROL; 1214 iommu->iommu_control = p->pbm_A.controller_regs + PSYCHO_IOMMU_CONTROL;
1219 iommu->iommu_tsbbase = p->pbm_A.controller_regs + PSYCHO_IOMMU_TSBBASE; 1215 iommu->iommu_tsbbase = p->pbm_A.controller_regs + PSYCHO_IOMMU_TSBBASE;
@@ -1240,40 +1236,10 @@ static void psycho_iommu_init(struct pci_controller_info *p)
1240 /* Leave diag mode enabled for full-flushing done 1236 /* Leave diag mode enabled for full-flushing done
1241 * in pci_iommu.c 1237 * in pci_iommu.c
1242 */ 1238 */
1239 pci_iommu_table_init(iommu, IO_TSB_SIZE, 0xc0000000, 0xffffffff);
1243 1240
1244 iommu->dummy_page = __get_free_pages(GFP_KERNEL, 0); 1241 psycho_write(p->pbm_A.controller_regs + PSYCHO_IOMMU_TSBBASE,
1245 if (!iommu->dummy_page) { 1242 __pa(iommu->page_table));
1246 prom_printf("PSYCHO_IOMMU: Error, gfp(dummy_page) failed.\n");
1247 prom_halt();
1248 }
1249 memset((void *)iommu->dummy_page, 0, PAGE_SIZE);
1250 iommu->dummy_page_pa = (unsigned long) __pa(iommu->dummy_page);
1251
1252 /* Using assumed page size 8K with 128K entries we need 1MB iommu page
1253 * table (128K ioptes * 8 bytes per iopte). This is
1254 * page order 7 on UltraSparc.
1255 */
1256 tsbbase = __get_free_pages(GFP_KERNEL, get_order(IO_TSB_SIZE));
1257 if (!tsbbase) {
1258 prom_printf("PSYCHO_IOMMU: Error, gfp(tsb) failed.\n");
1259 prom_halt();
1260 }
1261 iommu->page_table = (iopte_t *)tsbbase;
1262 iommu->page_table_sz_bits = 17;
1263 iommu->page_table_map_base = 0xc0000000;
1264 iommu->dma_addr_mask = 0xffffffff;
1265 pci_iommu_table_init(iommu, IO_TSB_SIZE);
1266
1267 /* We start with no consistent mappings. */
1268 iommu->lowest_consistent_map =
1269 1 << (iommu->page_table_sz_bits - PBM_LOGCLUSTERS);
1270
1271 for (i = 0; i < PBM_NCLUSTERS; i++) {
1272 iommu->alloc_info[i].flush = 0;
1273 iommu->alloc_info[i].next = 0;
1274 }
1275
1276 psycho_write(p->pbm_A.controller_regs + PSYCHO_IOMMU_TSBBASE, __pa(tsbbase));
1277 1243
1278 control = psycho_read(p->pbm_A.controller_regs + PSYCHO_IOMMU_CONTROL); 1244 control = psycho_read(p->pbm_A.controller_regs + PSYCHO_IOMMU_CONTROL);
1279 control &= ~(PSYCHO_IOMMU_CTRL_TSBSZ | PSYCHO_IOMMU_CTRL_TBWSZ); 1245 control &= ~(PSYCHO_IOMMU_CTRL_TSBSZ | PSYCHO_IOMMU_CTRL_TBWSZ);
@@ -1281,7 +1247,7 @@ static void psycho_iommu_init(struct pci_controller_info *p)
1281 psycho_write(p->pbm_A.controller_regs + PSYCHO_IOMMU_CONTROL, control); 1247 psycho_write(p->pbm_A.controller_regs + PSYCHO_IOMMU_CONTROL, control);
1282 1248
1283 /* If necessary, hook us up for starfire IRQ translations. */ 1249 /* If necessary, hook us up for starfire IRQ translations. */
1284 if(this_is_starfire) 1250 if (this_is_starfire)
1285 p->starfire_cookie = starfire_hookup(p->pbm_A.portid); 1251 p->starfire_cookie = starfire_hookup(p->pbm_A.portid);
1286 else 1252 else
1287 p->starfire_cookie = NULL; 1253 p->starfire_cookie = NULL;
diff --git a/arch/sparc64/kernel/pci_sabre.c b/arch/sparc64/kernel/pci_sabre.c
index 0ee6bd5b9a..da8e136419 100644
--- a/arch/sparc64/kernel/pci_sabre.c
+++ b/arch/sparc64/kernel/pci_sabre.c
@@ -1267,13 +1267,9 @@ static void sabre_iommu_init(struct pci_controller_info *p,
1267 u32 dma_mask) 1267 u32 dma_mask)
1268{ 1268{
1269 struct pci_iommu *iommu = p->pbm_A.iommu; 1269 struct pci_iommu *iommu = p->pbm_A.iommu;
1270 unsigned long tsbbase, i, order; 1270 unsigned long i;
1271 u64 control; 1271 u64 control;
1272 1272
1273 /* Setup initial software IOMMU state. */
1274 spin_lock_init(&iommu->lock);
1275 iommu->ctx_lowest_free = 1;
1276
1277 /* Register addresses. */ 1273 /* Register addresses. */
1278 iommu->iommu_control = p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL; 1274 iommu->iommu_control = p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL;
1279 iommu->iommu_tsbbase = p->pbm_A.controller_regs + SABRE_IOMMU_TSBBASE; 1275 iommu->iommu_tsbbase = p->pbm_A.controller_regs + SABRE_IOMMU_TSBBASE;
@@ -1295,26 +1291,10 @@ static void sabre_iommu_init(struct pci_controller_info *p,
1295 /* Leave diag mode enabled for full-flushing done 1291 /* Leave diag mode enabled for full-flushing done
1296 * in pci_iommu.c 1292 * in pci_iommu.c
1297 */ 1293 */
1294 pci_iommu_table_init(iommu, tsbsize * 1024 * 8, dvma_offset, dma_mask);
1298 1295
1299 iommu->dummy_page = __get_free_pages(GFP_KERNEL, 0); 1296 sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_TSBBASE,
1300 if (!iommu->dummy_page) { 1297 __pa(iommu->page_table));
1301 prom_printf("PSYCHO_IOMMU: Error, gfp(dummy_page) failed.\n");
1302 prom_halt();
1303 }
1304 memset((void *)iommu->dummy_page, 0, PAGE_SIZE);
1305 iommu->dummy_page_pa = (unsigned long) __pa(iommu->dummy_page);
1306
1307 tsbbase = __get_free_pages(GFP_KERNEL, order = get_order(tsbsize * 1024 * 8));
1308 if (!tsbbase) {
1309 prom_printf("SABRE_IOMMU: Error, gfp(tsb) failed.\n");
1310 prom_halt();
1311 }
1312 iommu->page_table = (iopte_t *)tsbbase;
1313 iommu->page_table_map_base = dvma_offset;
1314 iommu->dma_addr_mask = dma_mask;
1315 pci_iommu_table_init(iommu, PAGE_SIZE << order);
1316
1317 sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_TSBBASE, __pa(tsbbase));
1318 1298
1319 control = sabre_read(p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL); 1299 control = sabre_read(p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL);
1320 control &= ~(SABRE_IOMMUCTRL_TSBSZ | SABRE_IOMMUCTRL_TBWSZ); 1300 control &= ~(SABRE_IOMMUCTRL_TSBSZ | SABRE_IOMMUCTRL_TBWSZ);
@@ -1322,11 +1302,9 @@ static void sabre_iommu_init(struct pci_controller_info *p,
1322 switch(tsbsize) { 1302 switch(tsbsize) {
1323 case 64: 1303 case 64:
1324 control |= SABRE_IOMMU_TSBSZ_64K; 1304 control |= SABRE_IOMMU_TSBSZ_64K;
1325 iommu->page_table_sz_bits = 16;
1326 break; 1305 break;
1327 case 128: 1306 case 128:
1328 control |= SABRE_IOMMU_TSBSZ_128K; 1307 control |= SABRE_IOMMU_TSBSZ_128K;
1329 iommu->page_table_sz_bits = 17;
1330 break; 1308 break;
1331 default: 1309 default:
1332 prom_printf("iommu_init: Illegal TSB size %d\n", tsbsize); 1310 prom_printf("iommu_init: Illegal TSB size %d\n", tsbsize);
@@ -1334,15 +1312,6 @@ static void sabre_iommu_init(struct pci_controller_info *p,
1334 break; 1312 break;
1335 } 1313 }
1336 sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL, control); 1314 sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL, control);
1337
1338 /* We start with no consistent mappings. */
1339 iommu->lowest_consistent_map =
1340 1 << (iommu->page_table_sz_bits - PBM_LOGCLUSTERS);
1341
1342 for (i = 0; i < PBM_NCLUSTERS; i++) {
1343 iommu->alloc_info[i].flush = 0;
1344 iommu->alloc_info[i].next = 0;
1345 }
1346} 1315}
1347 1316
1348static void pbm_register_toplevel_resources(struct pci_controller_info *p, 1317static void pbm_register_toplevel_resources(struct pci_controller_info *p,
diff --git a/arch/sparc64/kernel/pci_schizo.c b/arch/sparc64/kernel/pci_schizo.c
index cae5b61fe2..d8c4e0919b 100644
--- a/arch/sparc64/kernel/pci_schizo.c
+++ b/arch/sparc64/kernel/pci_schizo.c
@@ -1765,7 +1765,7 @@ static void schizo_pbm_strbuf_init(struct pci_pbm_info *pbm)
1765static void schizo_pbm_iommu_init(struct pci_pbm_info *pbm) 1765static void schizo_pbm_iommu_init(struct pci_pbm_info *pbm)
1766{ 1766{
1767 struct pci_iommu *iommu = pbm->iommu; 1767 struct pci_iommu *iommu = pbm->iommu;
1768 unsigned long tsbbase, i, tagbase, database, order; 1768 unsigned long i, tagbase, database;
1769 u32 vdma[2], dma_mask; 1769 u32 vdma[2], dma_mask;
1770 u64 control; 1770 u64 control;
1771 int err, tsbsize; 1771 int err, tsbsize;
@@ -1800,10 +1800,6 @@ static void schizo_pbm_iommu_init(struct pci_pbm_info *pbm)
1800 prom_halt(); 1800 prom_halt();
1801 }; 1801 };
1802 1802
1803 /* Setup initial software IOMMU state. */
1804 spin_lock_init(&iommu->lock);
1805 iommu->ctx_lowest_free = 1;
1806
1807 /* Register addresses, SCHIZO has iommu ctx flushing. */ 1803 /* Register addresses, SCHIZO has iommu ctx flushing. */
1808 iommu->iommu_control = pbm->pbm_regs + SCHIZO_IOMMU_CONTROL; 1804 iommu->iommu_control = pbm->pbm_regs + SCHIZO_IOMMU_CONTROL;
1809 iommu->iommu_tsbbase = pbm->pbm_regs + SCHIZO_IOMMU_TSBBASE; 1805 iommu->iommu_tsbbase = pbm->pbm_regs + SCHIZO_IOMMU_TSBBASE;
@@ -1832,56 +1828,9 @@ static void schizo_pbm_iommu_init(struct pci_pbm_info *pbm)
1832 /* Leave diag mode enabled for full-flushing done 1828 /* Leave diag mode enabled for full-flushing done
1833 * in pci_iommu.c 1829 * in pci_iommu.c
1834 */ 1830 */
1831 pci_iommu_table_init(iommu, tsbsize * 8 * 1024, vdma[0], dma_mask);
1835 1832
1836 iommu->dummy_page = __get_free_pages(GFP_KERNEL, 0); 1833 schizo_write(iommu->iommu_tsbbase, __pa(iommu->page_table));
1837 if (!iommu->dummy_page) {
1838 prom_printf("PSYCHO_IOMMU: Error, gfp(dummy_page) failed.\n");
1839 prom_halt();
1840 }
1841 memset((void *)iommu->dummy_page, 0, PAGE_SIZE);
1842 iommu->dummy_page_pa = (unsigned long) __pa(iommu->dummy_page);
1843
1844 /* Using assumed page size 8K with 128K entries we need 1MB iommu page
1845 * table (128K ioptes * 8 bytes per iopte). This is
1846 * page order 7 on UltraSparc.
1847 */
1848 order = get_order(tsbsize * 8 * 1024);
1849 tsbbase = __get_free_pages(GFP_KERNEL, order);
1850 if (!tsbbase) {
1851 prom_printf("%s: Error, gfp(tsb) failed.\n", pbm->name);
1852 prom_halt();
1853 }
1854
1855 iommu->page_table = (iopte_t *)tsbbase;
1856 iommu->page_table_map_base = vdma[0];
1857 iommu->dma_addr_mask = dma_mask;
1858 pci_iommu_table_init(iommu, PAGE_SIZE << order);
1859
1860 switch (tsbsize) {
1861 case 64:
1862 iommu->page_table_sz_bits = 16;
1863 break;
1864
1865 case 128:
1866 iommu->page_table_sz_bits = 17;
1867 break;
1868
1869 default:
1870 prom_printf("iommu_init: Illegal TSB size %d\n", tsbsize);
1871 prom_halt();
1872 break;
1873 };
1874
1875 /* We start with no consistent mappings. */
1876 iommu->lowest_consistent_map =
1877 1 << (iommu->page_table_sz_bits - PBM_LOGCLUSTERS);
1878
1879 for (i = 0; i < PBM_NCLUSTERS; i++) {
1880 iommu->alloc_info[i].flush = 0;
1881 iommu->alloc_info[i].next = 0;
1882 }
1883
1884 schizo_write(iommu->iommu_tsbbase, __pa(tsbbase));
1885 1834
1886 control = schizo_read(iommu->iommu_control); 1835 control = schizo_read(iommu->iommu_control);
1887 control &= ~(SCHIZO_IOMMU_CTRL_TSBSZ | SCHIZO_IOMMU_CTRL_TBWSZ); 1836 control &= ~(SCHIZO_IOMMU_CTRL_TSBSZ | SCHIZO_IOMMU_CTRL_TBWSZ);
diff --git a/arch/sparc64/kernel/smp.c b/arch/sparc64/kernel/smp.c
index 590df5a16f..b137fd63f5 100644
--- a/arch/sparc64/kernel/smp.c
+++ b/arch/sparc64/kernel/smp.c
@@ -1001,13 +1001,6 @@ void smp_penguin_jailcell(int irq, struct pt_regs *regs)
1001 preempt_enable(); 1001 preempt_enable();
1002} 1002}
1003 1003
1004extern unsigned long xcall_promstop;
1005
1006void smp_promstop_others(void)
1007{
1008 smp_cross_call(&xcall_promstop, 0, 0, 0);
1009}
1010
1011#define prof_multiplier(__cpu) cpu_data(__cpu).multiplier 1004#define prof_multiplier(__cpu) cpu_data(__cpu).multiplier
1012#define prof_counter(__cpu) cpu_data(__cpu).counter 1005#define prof_counter(__cpu) cpu_data(__cpu).counter
1013 1006
diff --git a/arch/sparc64/mm/ultra.S b/arch/sparc64/mm/ultra.S
index 058b8126c1..e4c9151fa1 100644
--- a/arch/sparc64/mm/ultra.S
+++ b/arch/sparc64/mm/ultra.S
@@ -453,22 +453,6 @@ xcall_flush_dcache_page_spitfire: /* %g1 == physical page address
453 nop 453 nop
454 nop 454 nop
455 455
456 .globl xcall_promstop
457xcall_promstop:
458 rdpr %pstate, %g2
459 wrpr %g2, PSTATE_IG | PSTATE_AG, %pstate
460 rdpr %pil, %g2
461 wrpr %g0, 15, %pil
462 sethi %hi(109f), %g7
463 b,pt %xcc, etrap_irq
464109: or %g7, %lo(109b), %g7
465 flushw
466 call prom_stopself
467 nop
468 /* We should not return, just spin if we do... */
4691: b,a,pt %xcc, 1b
470 nop
471
472 .data 456 .data
473 457
474errata32_hwbug: 458errata32_hwbug:
diff --git a/arch/sparc64/prom/misc.c b/arch/sparc64/prom/misc.c
index 9b895faf07..87f5cfce23 100644
--- a/arch/sparc64/prom/misc.c
+++ b/arch/sparc64/prom/misc.c
@@ -68,19 +68,11 @@ void prom_cmdline(void)
68 local_irq_restore(flags); 68 local_irq_restore(flags);
69} 69}
70 70
71#ifdef CONFIG_SMP
72extern void smp_promstop_others(void);
73#endif
74
75/* Drop into the prom, but completely terminate the program. 71/* Drop into the prom, but completely terminate the program.
76 * No chance of continuing. 72 * No chance of continuing.
77 */ 73 */
78void prom_halt(void) 74void prom_halt(void)
79{ 75{
80#ifdef CONFIG_SMP
81 smp_promstop_others();
82 udelay(8000);
83#endif
84again: 76again:
85 p1275_cmd("exit", P1275_INOUT(0, 0)); 77 p1275_cmd("exit", P1275_INOUT(0, 0));
86 goto again; /* PROM is out to get me -DaveM */ 78 goto again; /* PROM is out to get me -DaveM */
@@ -88,10 +80,6 @@ again:
88 80
89void prom_halt_power_off(void) 81void prom_halt_power_off(void)
90{ 82{
91#ifdef CONFIG_SMP
92 smp_promstop_others();
93 udelay(8000);
94#endif
95 p1275_cmd("SUNW,power-off", P1275_INOUT(0, 0)); 83 p1275_cmd("SUNW,power-off", P1275_INOUT(0, 0));
96 84
97 /* if nothing else helps, we just halt */ 85 /* if nothing else helps, we just halt */
diff --git a/drivers/acpi/event.c b/drivers/acpi/event.c
index bfa8b76de4..2dbb1b0f11 100644
--- a/drivers/acpi/event.c
+++ b/drivers/acpi/event.c
@@ -58,9 +58,8 @@ acpi_system_read_event(struct file *file, char __user * buffer, size_t count,
58 return_VALUE(-EAGAIN); 58 return_VALUE(-EAGAIN);
59 59
60 result = acpi_bus_receive_event(&event); 60 result = acpi_bus_receive_event(&event);
61 if (result) { 61 if (result)
62 return_VALUE(-EIO); 62 return_VALUE(result);
63 }
64 63
65 chars_remaining = sprintf(str, "%s %s %08x %08x\n", 64 chars_remaining = sprintf(str, "%s %s %08x %08x\n",
66 event.device_class ? event. 65 event.device_class ? event.
diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
index 3fa64c6311..c268ee04b2 100644
--- a/drivers/char/mbcs.c
+++ b/drivers/char/mbcs.c
@@ -830,6 +830,9 @@ static int __init mbcs_init(void)
830{ 830{
831 int rv; 831 int rv;
832 832
833 if (!ia64_platform_is("sn2"))
834 return -ENODEV;
835
833 // Put driver into chrdevs[]. Get major number. 836 // Put driver into chrdevs[]. Get major number.
834 rv = register_chrdev(mbcs_major, DEVICE_NAME, &mbcs_ops); 837 rv = register_chrdev(mbcs_major, DEVICE_NAME, &mbcs_ops);
835 if (rv < 0) { 838 if (rv < 0) {
diff --git a/drivers/char/n_r3964.c b/drivers/char/n_r3964.c
index 97d6dc24b8..853c98cee6 100644
--- a/drivers/char/n_r3964.c
+++ b/drivers/char/n_r3964.c
@@ -695,7 +695,7 @@ static void receive_char(struct r3964_info *pInfo, const unsigned char c)
695 { 695 {
696 TRACE_PE("IDLE - got STX but no space in rx_queue!"); 696 TRACE_PE("IDLE - got STX but no space in rx_queue!");
697 pInfo->state=R3964_WAIT_FOR_RX_BUF; 697 pInfo->state=R3964_WAIT_FOR_RX_BUF;
698 mod_timer(&pInfo->tmr, R3964_TO_NO_BUF); 698 mod_timer(&pInfo->tmr, jiffies + R3964_TO_NO_BUF);
699 break; 699 break;
700 } 700 }
701start_receiving: 701start_receiving:
@@ -705,7 +705,7 @@ start_receiving:
705 pInfo->last_rx = 0; 705 pInfo->last_rx = 0;
706 pInfo->flags &= ~R3964_ERROR; 706 pInfo->flags &= ~R3964_ERROR;
707 pInfo->state=R3964_RECEIVING; 707 pInfo->state=R3964_RECEIVING;
708 mod_timer(&pInfo->tmr, R3964_TO_ZVZ); 708 mod_timer(&pInfo->tmr, jiffies + R3964_TO_ZVZ);
709 pInfo->nRetry = 0; 709 pInfo->nRetry = 0;
710 put_char(pInfo, DLE); 710 put_char(pInfo, DLE);
711 flush(pInfo); 711 flush(pInfo);
@@ -732,7 +732,7 @@ start_receiving:
732 if(pInfo->flags & R3964_BCC) 732 if(pInfo->flags & R3964_BCC)
733 { 733 {
734 pInfo->state = R3964_WAIT_FOR_BCC; 734 pInfo->state = R3964_WAIT_FOR_BCC;
735 mod_timer(&pInfo->tmr, R3964_TO_ZVZ); 735 mod_timer(&pInfo->tmr, jiffies + R3964_TO_ZVZ);
736 } 736 }
737 else 737 else
738 { 738 {
@@ -744,7 +744,7 @@ start_receiving:
744 pInfo->last_rx = c; 744 pInfo->last_rx = c;
745char_to_buf: 745char_to_buf:
746 pInfo->rx_buf[pInfo->rx_position++] = c; 746 pInfo->rx_buf[pInfo->rx_position++] = c;
747 mod_timer(&pInfo->tmr, R3964_TO_ZVZ); 747 mod_timer(&pInfo->tmr, jiffies + R3964_TO_ZVZ);
748 } 748 }
749 } 749 }
750 /* else: overflow-msg? BUF_SIZE>MTU; should not happen? */ 750 /* else: overflow-msg? BUF_SIZE>MTU; should not happen? */
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index 444f7756fe..571a68691a 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -93,7 +93,7 @@ config KEYBOARD_LKKBD
93 93
94config KEYBOARD_LOCOMO 94config KEYBOARD_LOCOMO
95 tristate "LoCoMo Keyboard Support" 95 tristate "LoCoMo Keyboard Support"
96 depends on SHARP_LOCOMO 96 depends on SHARP_LOCOMO && INPUT_KEYBOARD
97 help 97 help
98 Say Y here if you are running Linux on a Sharp Zaurus Collie or Poodle based PDA 98 Say Y here if you are running Linux on a Sharp Zaurus Collie or Poodle based PDA
99 99
diff --git a/drivers/input/keyboard/spitzkbd.c b/drivers/input/keyboard/spitzkbd.c
index 1714045a18..344f460054 100644
--- a/drivers/input/keyboard/spitzkbd.c
+++ b/drivers/input/keyboard/spitzkbd.c
@@ -53,7 +53,7 @@ static unsigned char spitzkbd_keycode[NR_SCANCODES] = {
53 KEY_LEFTCTRL, KEY_1, KEY_3, KEY_5, KEY_6, KEY_7, KEY_9, KEY_0, KEY_BACKSPACE, SPITZ_KEY_EXOK, SPITZ_KEY_EXCANCEL, 0, 0, 0, 0, 0, /* 1-16 */ 53 KEY_LEFTCTRL, KEY_1, KEY_3, KEY_5, KEY_6, KEY_7, KEY_9, KEY_0, KEY_BACKSPACE, SPITZ_KEY_EXOK, SPITZ_KEY_EXCANCEL, 0, 0, 0, 0, 0, /* 1-16 */
54 0, KEY_2, KEY_4, KEY_R, KEY_Y, KEY_8, KEY_I, KEY_O, KEY_P, SPITZ_KEY_EXJOGDOWN, SPITZ_KEY_EXJOGUP, 0, 0, 0, 0, 0, /* 17-32 */ 54 0, KEY_2, KEY_4, KEY_R, KEY_Y, KEY_8, KEY_I, KEY_O, KEY_P, SPITZ_KEY_EXJOGDOWN, SPITZ_KEY_EXJOGUP, 0, 0, 0, 0, 0, /* 17-32 */
55 KEY_TAB, KEY_Q, KEY_E, KEY_T, KEY_G, KEY_U, KEY_J, KEY_K, 0, 0, 0, 0, 0, 0, 0, 0, /* 33-48 */ 55 KEY_TAB, KEY_Q, KEY_E, KEY_T, KEY_G, KEY_U, KEY_J, KEY_K, 0, 0, 0, 0, 0, 0, 0, 0, /* 33-48 */
56 SPITZ_KEY_CALENDER, KEY_W, KEY_S, KEY_F, KEY_V, KEY_H, KEY_M, KEY_L, 0, 0, KEY_RIGHTSHIFT, 0, 0, 0, 0, 0, /* 49-64 */ 56 SPITZ_KEY_CALENDER, KEY_W, KEY_S, KEY_F, KEY_V, KEY_H, KEY_M, KEY_L, 0, KEY_RIGHTSHIFT, 0, 0, 0, 0, 0, 0, /* 49-64 */
57 SPITZ_KEY_ADDRESS, KEY_A, KEY_D, KEY_C, KEY_B, KEY_N, KEY_DOT, 0, KEY_ENTER, KEY_LEFTSHIFT, 0, 0, 0, 0, 0, 0, /* 65-80 */ 57 SPITZ_KEY_ADDRESS, KEY_A, KEY_D, KEY_C, KEY_B, KEY_N, KEY_DOT, 0, KEY_ENTER, KEY_LEFTSHIFT, 0, 0, 0, 0, 0, 0, /* 65-80 */
58 SPITZ_KEY_MAIL, KEY_Z, KEY_X, KEY_MINUS, KEY_SPACE, KEY_COMMA, 0, KEY_UP, 0, 0, SPITZ_KEY_FN, 0, 0, 0, 0, 0, /* 81-96 */ 58 SPITZ_KEY_MAIL, KEY_Z, KEY_X, KEY_MINUS, KEY_SPACE, KEY_COMMA, 0, KEY_UP, 0, 0, SPITZ_KEY_FN, 0, 0, 0, 0, 0, /* 81-96 */
59 KEY_SYSRQ, SPITZ_KEY_JAP1, SPITZ_KEY_JAP2, SPITZ_KEY_CANCEL, SPITZ_KEY_OK, SPITZ_KEY_MENU, KEY_LEFT, KEY_DOWN, KEY_RIGHT, 0, 0, 0, 0, 0, 0, 0 /* 97-112 */ 59 KEY_SYSRQ, SPITZ_KEY_JAP1, SPITZ_KEY_JAP2, SPITZ_KEY_CANCEL, SPITZ_KEY_OK, SPITZ_KEY_MENU, KEY_LEFT, KEY_DOWN, KEY_RIGHT, 0, 0, 0, 0, 0, 0, 0 /* 97-112 */
diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
index d5c5b32045..4015a91f4b 100644
--- a/drivers/input/misc/uinput.c
+++ b/drivers/input/misc/uinput.c
@@ -90,11 +90,11 @@ static inline int uinput_request_reserve_slot(struct uinput_device *udev, struct
90 90
91static void uinput_request_done(struct uinput_device *udev, struct uinput_request *request) 91static void uinput_request_done(struct uinput_device *udev, struct uinput_request *request)
92{ 92{
93 complete(&request->done);
94
95 /* Mark slot as available */ 93 /* Mark slot as available */
96 udev->requests[request->id] = NULL; 94 udev->requests[request->id] = NULL;
97 wake_up_interruptible(&udev->requests_waitq); 95 wake_up_interruptible(&udev->requests_waitq);
96
97 complete(&request->done);
98} 98}
99 99
100static int uinput_request_submit(struct input_dev *dev, struct uinput_request *request) 100static int uinput_request_submit(struct input_dev *dev, struct uinput_request *request)
diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
index 022913da8c..9b0406318f 100644
--- a/drivers/media/radio/radio-cadet.c
+++ b/drivers/media/radio/radio-cadet.c
@@ -543,7 +543,7 @@ static int cadet_probe(void)
543 543
544 for(i=0;i<8;i++) { 544 for(i=0;i<8;i++) {
545 io=iovals[i]; 545 io=iovals[i];
546 if(request_region(io,2, "cadet-probe")>=0) { 546 if (request_region(io, 2, "cadet-probe")) {
547 cadet_setfreq(1410); 547 cadet_setfreq(1410);
548 if(cadet_getfreq()==1410) { 548 if(cadet_getfreq()==1410) {
549 release_region(io, 2); 549 release_region(io, 2);
diff --git a/drivers/media/video/vpx3220.c b/drivers/media/video/vpx3220.c
index 4437bdebe2..137b58f2c6 100644
--- a/drivers/media/video/vpx3220.c
+++ b/drivers/media/video/vpx3220.c
@@ -203,7 +203,7 @@ static const unsigned short init_ntsc[] = {
203 0x8c, 640, /* Horizontal length */ 203 0x8c, 640, /* Horizontal length */
204 0x8d, 640, /* Number of pixels */ 204 0x8d, 640, /* Number of pixels */
205 0x8f, 0xc00, /* Disable window 2 */ 205 0x8f, 0xc00, /* Disable window 2 */
206 0xf0, 0x173, /* 13.5 MHz transport, Forced 206 0xf0, 0x73, /* 13.5 MHz transport, Forced
207 * mode, latch windows */ 207 * mode, latch windows */
208 0xf2, 0x13, /* NTSC M, composite input */ 208 0xf2, 0x13, /* NTSC M, composite input */
209 0xe7, 0x1e1, /* Enable vertical standard 209 0xe7, 0x1e1, /* Enable vertical standard
@@ -212,38 +212,36 @@ static const unsigned short init_ntsc[] = {
212 212
213static const unsigned short init_pal[] = { 213static const unsigned short init_pal[] = {
214 0x88, 23, /* Window 1 vertical begin */ 214 0x88, 23, /* Window 1 vertical begin */
215 0x89, 288 + 16, /* Vertical lines in (16 lines 215 0x89, 288, /* Vertical lines in (16 lines
216 * skipped by the VFE) */ 216 * skipped by the VFE) */
217 0x8a, 288 + 16, /* Vertical lines out (16 lines 217 0x8a, 288, /* Vertical lines out (16 lines
218 * skipped by the VFE) */ 218 * skipped by the VFE) */
219 0x8b, 16, /* Horizontal begin */ 219 0x8b, 16, /* Horizontal begin */
220 0x8c, 768, /* Horizontal length */ 220 0x8c, 768, /* Horizontal length */
221 0x8d, 784, /* Number of pixels 221 0x8d, 784, /* Number of pixels
222 * Must be >= Horizontal begin + Horizontal length */ 222 * Must be >= Horizontal begin + Horizontal length */
223 0x8f, 0xc00, /* Disable window 2 */ 223 0x8f, 0xc00, /* Disable window 2 */
224 0xf0, 0x177, /* 13.5 MHz transport, Forced 224 0xf0, 0x77, /* 13.5 MHz transport, Forced
225 * mode, latch windows */ 225 * mode, latch windows */
226 0xf2, 0x3d1, /* PAL B,G,H,I, composite input */ 226 0xf2, 0x3d1, /* PAL B,G,H,I, composite input */
227 0xe7, 0x261, /* PAL/SECAM set to 288 + 16 lines 227 0xe7, 0x241, /* PAL/SECAM set to 288 lines */
228 * change to 0x241 for 288 lines */
229}; 228};
230 229
231static const unsigned short init_secam[] = { 230static const unsigned short init_secam[] = {
232 0x88, 23 - 16, /* Window 1 vertical begin */ 231 0x88, 23, /* Window 1 vertical begin */
233 0x89, 288 + 16, /* Vertical lines in (16 lines 232 0x89, 288, /* Vertical lines in (16 lines
234 * skipped by the VFE) */ 233 * skipped by the VFE) */
235 0x8a, 288 + 16, /* Vertical lines out (16 lines 234 0x8a, 288, /* Vertical lines out (16 lines
236 * skipped by the VFE) */ 235 * skipped by the VFE) */
237 0x8b, 16, /* Horizontal begin */ 236 0x8b, 16, /* Horizontal begin */
238 0x8c, 768, /* Horizontal length */ 237 0x8c, 768, /* Horizontal length */
239 0x8d, 784, /* Number of pixels 238 0x8d, 784, /* Number of pixels
240 * Must be >= Horizontal begin + Horizontal length */ 239 * Must be >= Horizontal begin + Horizontal length */
241 0x8f, 0xc00, /* Disable window 2 */ 240 0x8f, 0xc00, /* Disable window 2 */
242 0xf0, 0x177, /* 13.5 MHz transport, Forced 241 0xf0, 0x77, /* 13.5 MHz transport, Forced
243 * mode, latch windows */ 242 * mode, latch windows */
244 0xf2, 0x3d5, /* SECAM, composite input */ 243 0xf2, 0x3d5, /* SECAM, composite input */
245 0xe7, 0x261, /* PAL/SECAM set to 288 + 16 lines 244 0xe7, 0x241, /* PAL/SECAM set to 288 lines */
246 * change to 0x241 for 288 lines */
247}; 245};
248 246
249static const unsigned char init_common[] = { 247static const unsigned char init_common[] = {
@@ -410,6 +408,12 @@ vpx3220_command (struct i2c_client *client,
410 case DECODER_SET_NORM: 408 case DECODER_SET_NORM:
411 { 409 {
412 int *iarg = arg, data; 410 int *iarg = arg, data;
411 int temp_input;
412
413 /* Here we back up the input selection because it gets
414 overwritten when we fill the registers with the
415 choosen video norm */
416 temp_input = vpx3220_fp_read(client, 0xf2);
413 417
414 dprintk(1, KERN_DEBUG "%s: DECODER_SET_NORM %d\n", 418 dprintk(1, KERN_DEBUG "%s: DECODER_SET_NORM %d\n",
415 I2C_NAME(client), *iarg); 419 I2C_NAME(client), *iarg);
@@ -449,6 +453,10 @@ vpx3220_command (struct i2c_client *client,
449 453
450 } 454 }
451 decoder->norm = *iarg; 455 decoder->norm = *iarg;
456
457 /* And here we set the backed up video input again */
458 vpx3220_fp_write(client, 0xf2, temp_input | 0x0010);
459 udelay(10);
452 } 460 }
453 break; 461 break;
454 462
diff --git a/drivers/net/wireless/Kconfig b/drivers/net/wireless/Kconfig
index 00a07f32a8..7187958e40 100644
--- a/drivers/net/wireless/Kconfig
+++ b/drivers/net/wireless/Kconfig
@@ -243,7 +243,7 @@ config IPW_DEBUG
243 243
244config AIRO 244config AIRO
245 tristate "Cisco/Aironet 34X/35X/4500/4800 ISA and PCI cards" 245 tristate "Cisco/Aironet 34X/35X/4500/4800 ISA and PCI cards"
246 depends on NET_RADIO && ISA && (PCI || BROKEN) 246 depends on NET_RADIO && ISA_DMA_API && (PCI || BROKEN)
247 ---help--- 247 ---help---
248 This is the standard Linux driver to support Cisco/Aironet ISA and 248 This is the standard Linux driver to support Cisco/Aironet ISA and
249 PCI 802.11 wireless cards. 249 PCI 802.11 wireless cards.
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 11ca44387c..a6a630a950 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -1233,7 +1233,7 @@ static void __init quirk_alder_ioapic(struct pci_dev *pdev)
1233DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_EESSC, quirk_alder_ioapic ); 1233DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_EESSC, quirk_alder_ioapic );
1234#endif 1234#endif
1235 1235
1236#ifdef CONFIG_SCSI_SATA 1236#ifdef CONFIG_SCSI_SATA_INTEL_COMBINED
1237static void __devinit quirk_intel_ide_combined(struct pci_dev *pdev) 1237static void __devinit quirk_intel_ide_combined(struct pci_dev *pdev)
1238{ 1238{
1239 u8 prog, comb, tmp; 1239 u8 prog, comb, tmp;
@@ -1310,7 +1310,7 @@ static void __devinit quirk_intel_ide_combined(struct pci_dev *pdev)
1310 request_region(0x170, 8, "libata"); /* port 1 */ 1310 request_region(0x170, 8, "libata"); /* port 1 */
1311} 1311}
1312DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_ANY_ID, quirk_intel_ide_combined ); 1312DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_ANY_ID, quirk_intel_ide_combined );
1313#endif /* CONFIG_SCSI_SATA */ 1313#endif /* CONFIG_SCSI_SATA_INTEL_COMBINED */
1314 1314
1315 1315
1316int pcie_mch_quirk; 1316int pcie_mch_quirk;
diff --git a/drivers/pcmcia/soc_common.c b/drivers/pcmcia/soc_common.c
index 888b70e6a4..9e7ccd8a43 100644
--- a/drivers/pcmcia/soc_common.c
+++ b/drivers/pcmcia/soc_common.c
@@ -66,7 +66,7 @@ void soc_pcmcia_debug(struct soc_pcmcia_socket *skt, const char *func,
66 if (pc_debug > lvl) { 66 if (pc_debug > lvl) {
67 printk(KERN_DEBUG "skt%u: %s: ", skt->nr, func); 67 printk(KERN_DEBUG "skt%u: %s: ", skt->nr, func);
68 va_start(args, fmt); 68 va_start(args, fmt);
69 printk(fmt, args); 69 vprintk(fmt, args);
70 va_end(args); 70 va_end(args);
71 } 71 }
72} 72}
@@ -321,8 +321,6 @@ soc_common_pcmcia_get_socket(struct pcmcia_socket *sock, socket_state_t *state)
321 * less punt all of this work and let the kernel handle the details 321 * less punt all of this work and let the kernel handle the details
322 * of power configuration, reset, &c. We also record the value of 322 * of power configuration, reset, &c. We also record the value of
323 * `state' in order to regurgitate it to the PCMCIA core later. 323 * `state' in order to regurgitate it to the PCMCIA core later.
324 *
325 * Returns: 0
326 */ 324 */
327static int 325static int
328soc_common_pcmcia_set_socket(struct pcmcia_socket *sock, socket_state_t *state) 326soc_common_pcmcia_set_socket(struct pcmcia_socket *sock, socket_state_t *state)
@@ -407,7 +405,7 @@ soc_common_pcmcia_set_io_map(struct pcmcia_socket *sock, struct pccard_io_map *m
407 * the map speed as requested, but override the address ranges 405 * the map speed as requested, but override the address ranges
408 * supplied by Card Services. 406 * supplied by Card Services.
409 * 407 *
410 * Returns: 0 on success, -1 on error 408 * Returns: 0 on success, -ERRNO on error
411 */ 409 */
412static int 410static int
413soc_common_pcmcia_set_mem_map(struct pcmcia_socket *sock, struct pccard_mem_map *map) 411soc_common_pcmcia_set_mem_map(struct pcmcia_socket *sock, struct pccard_mem_map *map)
@@ -655,8 +653,8 @@ static void soc_pcmcia_cpufreq_unregister(void)
655} 653}
656 654
657#else 655#else
658#define soc_pcmcia_cpufreq_register() 656static int soc_pcmcia_cpufreq_register(void) { return 0; }
659#define soc_pcmcia_cpufreq_unregister() 657static void soc_pcmcia_cpufreq_unregister(void) {}
660#endif 658#endif
661 659
662int soc_common_drv_pcmcia_probe(struct device *dev, struct pcmcia_low_level *ops, int first, int nr) 660int soc_common_drv_pcmcia_probe(struct device *dev, struct pcmcia_low_level *ops, int first, int nr)
@@ -738,7 +736,7 @@ int soc_common_drv_pcmcia_probe(struct device *dev, struct pcmcia_low_level *ops
738 goto out_err_5; 736 goto out_err_5;
739 } 737 }
740 738
741 if ( list_empty(&soc_pcmcia_sockets) ) 739 if (list_empty(&soc_pcmcia_sockets))
742 soc_pcmcia_cpufreq_register(); 740 soc_pcmcia_cpufreq_register();
743 741
744 list_add(&skt->node, &soc_pcmcia_sockets); 742 list_add(&skt->node, &soc_pcmcia_sockets);
@@ -839,7 +837,7 @@ int soc_common_drv_pcmcia_remove(struct device *dev)
839 release_resource(&skt->res_io); 837 release_resource(&skt->res_io);
840 release_resource(&skt->res_skt); 838 release_resource(&skt->res_skt);
841 } 839 }
842 if ( list_empty(&soc_pcmcia_sockets) ) 840 if (list_empty(&soc_pcmcia_sockets))
843 soc_pcmcia_cpufreq_unregister(); 841 soc_pcmcia_cpufreq_unregister();
844 842
845 up(&soc_pcmcia_sockets_lock); 843 up(&soc_pcmcia_sockets_lock);
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 20019b82b4..3ee9b8b33b 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -553,6 +553,11 @@ config SCSI_SATA_VITESSE
553 553
554 If unsure, say N. 554 If unsure, say N.
555 555
556config SCSI_SATA_INTEL_COMBINED
557 bool
558 depends on IDE=y && !BLK_DEV_IDE_SATA && (SCSI_SATA_AHCI || SCSI_ATA_PIIX)
559 default y
560
556config SCSI_BUSLOGIC 561config SCSI_BUSLOGIC
557 tristate "BusLogic SCSI support" 562 tristate "BusLogic SCSI support"
558 depends on (PCI || ISA || MCA) && SCSI && ISA_DMA_API 563 depends on (PCI || ISA || MCA) && SCSI && ISA_DMA_API
diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index de8490a928..a1f9ceef0a 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -453,9 +453,9 @@ static int aac_eh_reset(struct scsi_cmnd* cmd)
453 /* 453 /*
454 * We can exit If all the commands are complete 454 * We can exit If all the commands are complete
455 */ 455 */
456 spin_unlock_irq(host->host_lock);
456 if (active == 0) 457 if (active == 0)
457 return SUCCESS; 458 return SUCCESS;
458 spin_unlock_irq(host->host_lock);
459 ssleep(1); 459 ssleep(1);
460 spin_lock_irq(host->host_lock); 460 spin_lock_irq(host->host_lock);
461 } 461 }
diff --git a/drivers/scsi/qlogicpti.c b/drivers/scsi/qlogicpti.c
index a917ab7475..1fd5fc6d0f 100644
--- a/drivers/scsi/qlogicpti.c
+++ b/drivers/scsi/qlogicpti.c
@@ -1119,6 +1119,36 @@ static inline void update_can_queue(struct Scsi_Host *host, u_int in_ptr, u_int
1119 host->sg_tablesize = QLOGICPTI_MAX_SG(num_free); 1119 host->sg_tablesize = QLOGICPTI_MAX_SG(num_free);
1120} 1120}
1121 1121
1122static unsigned int scsi_rbuf_get(struct scsi_cmnd *cmd, unsigned char **buf_out)
1123{
1124 unsigned char *buf;
1125 unsigned int buflen;
1126
1127 if (cmd->use_sg) {
1128 struct scatterlist *sg;
1129
1130 sg = (struct scatterlist *) cmd->request_buffer;
1131 buf = kmap_atomic(sg->page, KM_IRQ0) + sg->offset;
1132 buflen = sg->length;
1133 } else {
1134 buf = cmd->request_buffer;
1135 buflen = cmd->request_bufflen;
1136 }
1137
1138 *buf_out = buf;
1139 return buflen;
1140}
1141
1142static void scsi_rbuf_put(struct scsi_cmnd *cmd, unsigned char *buf)
1143{
1144 if (cmd->use_sg) {
1145 struct scatterlist *sg;
1146
1147 sg = (struct scatterlist *) cmd->request_buffer;
1148 kunmap_atomic(buf - sg->offset, KM_IRQ0);
1149 }
1150}
1151
1122/* 1152/*
1123 * Until we scan the entire bus with inquiries, go throught this fella... 1153 * Until we scan the entire bus with inquiries, go throught this fella...
1124 */ 1154 */
@@ -1145,11 +1175,9 @@ static void ourdone(struct scsi_cmnd *Cmnd)
1145 int ok = host_byte(Cmnd->result) == DID_OK; 1175 int ok = host_byte(Cmnd->result) == DID_OK;
1146 if (Cmnd->cmnd[0] == 0x12 && ok) { 1176 if (Cmnd->cmnd[0] == 0x12 && ok) {
1147 unsigned char *iqd; 1177 unsigned char *iqd;
1178 unsigned int iqd_len;
1148 1179
1149 if (Cmnd->use_sg != 0) 1180 iqd_len = scsi_rbuf_get(Cmnd, &iqd);
1150 BUG();
1151
1152 iqd = ((unsigned char *)Cmnd->buffer);
1153 1181
1154 /* tags handled in midlayer */ 1182 /* tags handled in midlayer */
1155 /* enable sync mode? */ 1183 /* enable sync mode? */
@@ -1163,6 +1191,9 @@ static void ourdone(struct scsi_cmnd *Cmnd)
1163 if (iqd[7] & 0x20) { 1191 if (iqd[7] & 0x20) {
1164 qpti->dev_param[tgt].device_flags |= 0x20; 1192 qpti->dev_param[tgt].device_flags |= 0x20;
1165 } 1193 }
1194
1195 scsi_rbuf_put(Cmnd, iqd);
1196
1166 qpti->sbits |= (1 << tgt); 1197 qpti->sbits |= (1 << tgt);
1167 } else if (!ok) { 1198 } else if (!ok) {
1168 qpti->sbits |= (1 << tgt); 1199 qpti->sbits |= (1 << tgt);
diff --git a/drivers/serial/8250_pnp.c b/drivers/serial/8250_pnp.c
index 6b321e82ca..c2786fc41c 100644
--- a/drivers/serial/8250_pnp.c
+++ b/drivers/serial/8250_pnp.c
@@ -272,6 +272,8 @@ static const struct pnp_device_id pnp_dev_table[] = {
272 { "SUP1421", 0 }, 272 { "SUP1421", 0 },
273 /* SupraExpress 33.6 Data/Fax PnP modem */ 273 /* SupraExpress 33.6 Data/Fax PnP modem */
274 { "SUP1590", 0 }, 274 { "SUP1590", 0 },
275 /* SupraExpress 336i Sp ASVD */
276 { "SUP1620", 0 },
275 /* SupraExpress 33.6 Data/Fax PnP modem */ 277 /* SupraExpress 33.6 Data/Fax PnP modem */
276 { "SUP1760", 0 }, 278 { "SUP1760", 0 },
277 /* Phoebe Micro */ 279 /* Phoebe Micro */
diff --git a/drivers/serial/sh-sci.c b/drivers/serial/sh-sci.c
index 5122663078..430754ebac 100644
--- a/drivers/serial/sh-sci.c
+++ b/drivers/serial/sh-sci.c
@@ -967,7 +967,7 @@ static int sci_startup(struct uart_port *port)
967#endif 967#endif
968 968
969 sci_request_irq(s); 969 sci_request_irq(s);
970 sci_start_tx(port, 1); 970 sci_start_tx(port);
971 sci_start_rx(port, 1); 971 sci_start_rx(port, 1);
972 972
973 return 0; 973 return 0;
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c
index 41bbae83fc..e142056b0d 100644
--- a/drivers/usb/host/isp116x-hcd.c
+++ b/drivers/usb/host/isp116x-hcd.c
@@ -326,7 +326,8 @@ static void postproc_atl_queue(struct isp116x *isp116x)
326 usb_settoggle(udev, ep->epnum, 326 usb_settoggle(udev, ep->epnum,
327 ep->nextpid == 327 ep->nextpid ==
328 USB_PID_OUT, 328 USB_PID_OUT,
329 PTD_GET_TOGGLE(ptd) ^ 1); 329 PTD_GET_TOGGLE(ptd));
330 urb->actual_length += PTD_GET_COUNT(ptd);
330 urb->status = cc_to_error[TD_DATAUNDERRUN]; 331 urb->status = cc_to_error[TD_DATAUNDERRUN];
331 spin_unlock(&urb->lock); 332 spin_unlock(&urb->lock);
332 continue; 333 continue;
diff --git a/drivers/usb/input/hid-core.c b/drivers/usb/input/hid-core.c
index a99865c689..41f92b9247 100644
--- a/drivers/usb/input/hid-core.c
+++ b/drivers/usb/input/hid-core.c
@@ -1702,10 +1702,7 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1702 if ((endpoint->bmAttributes & 3) != 3) /* Not an interrupt endpoint */ 1702 if ((endpoint->bmAttributes & 3) != 3) /* Not an interrupt endpoint */
1703 continue; 1703 continue;
1704 1704
1705 /* handle potential highspeed HID correctly */
1706 interval = endpoint->bInterval; 1705 interval = endpoint->bInterval;
1707 if (dev->speed == USB_SPEED_HIGH)
1708 interval = 1 << (interval - 1);
1709 1706
1710 /* Change the polling interval of mice. */ 1707 /* Change the polling interval of mice. */
1711 if (hid->collection->usage == HID_GD_MOUSE && hid_mousepoll_interval > 0) 1708 if (hid->collection->usage == HID_GD_MOUSE && hid_mousepoll_interval > 0)
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index ddde5fb13f..5f7d3193d3 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -223,7 +223,7 @@ int usb_serial_generic_write_room (struct usb_serial_port *port)
223 dbg("%s - port %d", __FUNCTION__, port->number); 223 dbg("%s - port %d", __FUNCTION__, port->number);
224 224
225 if (serial->num_bulk_out) { 225 if (serial->num_bulk_out) {
226 if (port->write_urb_busy) 226 if (!(port->write_urb_busy))
227 room = port->bulk_out_size; 227 room = port->bulk_out_size;
228 } 228 }
229 229
diff --git a/drivers/video/console/vgacon.c b/drivers/video/console/vgacon.c
index 6ef6f7760e..809fee2140 100644
--- a/drivers/video/console/vgacon.c
+++ b/drivers/video/console/vgacon.c
@@ -565,7 +565,11 @@ static int vgacon_switch(struct vc_data *c)
565 scr_memcpyw((u16 *) c->vc_origin, (u16 *) c->vc_screenbuf, 565 scr_memcpyw((u16 *) c->vc_origin, (u16 *) c->vc_screenbuf,
566 c->vc_screenbuf_size > vga_vram_size ? 566 c->vc_screenbuf_size > vga_vram_size ?
567 vga_vram_size : c->vc_screenbuf_size); 567 vga_vram_size : c->vc_screenbuf_size);
568 vgacon_doresize(c, c->vc_cols, c->vc_rows); 568 if (!(vga_video_num_columns % 2) &&
569 vga_video_num_columns <= ORIG_VIDEO_COLS &&
570 vga_video_num_lines <= (ORIG_VIDEO_LINES *
571 vga_default_font_height) / c->vc_font.height)
572 vgacon_doresize(c, c->vc_cols, c->vc_rows);
569 } 573 }
570 574
571 return 0; /* Redrawing not needed */ 575 return 0; /* Redrawing not needed */
@@ -1023,7 +1027,8 @@ static int vgacon_resize(struct vc_data *c, unsigned int width,
1023 if (width % 2 || width > ORIG_VIDEO_COLS || 1027 if (width % 2 || width > ORIG_VIDEO_COLS ||
1024 height > (ORIG_VIDEO_LINES * vga_default_font_height)/ 1028 height > (ORIG_VIDEO_LINES * vga_default_font_height)/
1025 c->vc_font.height) 1029 c->vc_font.height)
1026 return -EINVAL; 1030 /* let svgatextmode tinker with video timings */
1031 return 0;
1027 1032
1028 if (CON_IS_VISIBLE(c) && !vga_is_gfx) /* who knows */ 1033 if (CON_IS_VISIBLE(c) && !vga_is_gfx) /* who knows */
1029 vgacon_doresize(c, width, height); 1034 vgacon_doresize(c, width, height);
diff --git a/drivers/video/sa1100fb.c b/drivers/video/sa1100fb.c
index beeec7b514..8000890e42 100644
--- a/drivers/video/sa1100fb.c
+++ b/drivers/video/sa1100fb.c
@@ -592,6 +592,7 @@ sa1100fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
592 return ret; 592 return ret;
593} 593}
594 594
595#ifdef CONFIG_CPU_FREQ
595/* 596/*
596 * sa1100fb_display_dma_period() 597 * sa1100fb_display_dma_period()
597 * Calculate the minimum period (in picoseconds) between two DMA 598 * Calculate the minimum period (in picoseconds) between two DMA
@@ -606,6 +607,7 @@ static inline unsigned int sa1100fb_display_dma_period(struct fb_var_screeninfo
606 */ 607 */
607 return var->pixclock * 8 * 16 / var->bits_per_pixel; 608 return var->pixclock * 8 * 16 / var->bits_per_pixel;
608} 609}
610#endif
609 611
610/* 612/*
611 * sa1100fb_check_var(): 613 * sa1100fb_check_var():
diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
index 1b6b74c116..14016b1cd9 100644
--- a/drivers/w1/w1.c
+++ b/drivers/w1/w1.c
@@ -77,8 +77,7 @@ static void w1_master_release(struct device *dev)
77 77
78 dev_dbg(dev, "%s: Releasing %s.\n", __func__, md->name); 78 dev_dbg(dev, "%s: Releasing %s.\n", __func__, md->name);
79 79
80 if (md->nls && md->nls->sk_socket) 80 dev_fini_netlink(md);
81 sock_release(md->nls->sk_socket);
82 memset(md, 0, sizeof(struct w1_master) + sizeof(struct w1_bus_master)); 81 memset(md, 0, sizeof(struct w1_master) + sizeof(struct w1_bus_master));
83 kfree(md); 82 kfree(md);
84} 83}
diff --git a/fs/aio.c b/fs/aio.c
index d6b1551342..9fe7216457 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -398,7 +398,7 @@ static struct kiocb fastcall *__aio_get_req(struct kioctx *ctx)
398 if (unlikely(!req)) 398 if (unlikely(!req))
399 return NULL; 399 return NULL;
400 400
401 req->ki_flags = 1 << KIF_LOCKED; 401 req->ki_flags = 0;
402 req->ki_users = 2; 402 req->ki_users = 2;
403 req->ki_key = 0; 403 req->ki_key = 0;
404 req->ki_ctx = ctx; 404 req->ki_ctx = ctx;
@@ -547,25 +547,6 @@ struct kioctx *lookup_ioctx(unsigned long ctx_id)
547 return ioctx; 547 return ioctx;
548} 548}
549 549
550static int lock_kiocb_action(void *param)
551{
552 schedule();
553 return 0;
554}
555
556static inline void lock_kiocb(struct kiocb *iocb)
557{
558 wait_on_bit_lock(&iocb->ki_flags, KIF_LOCKED, lock_kiocb_action,
559 TASK_UNINTERRUPTIBLE);
560}
561
562static inline void unlock_kiocb(struct kiocb *iocb)
563{
564 kiocbClearLocked(iocb);
565 smp_mb__after_clear_bit();
566 wake_up_bit(&iocb->ki_flags, KIF_LOCKED);
567}
568
569/* 550/*
570 * use_mm 551 * use_mm
571 * Makes the calling kernel thread take on the specified 552 * Makes the calling kernel thread take on the specified
@@ -796,9 +777,7 @@ static int __aio_run_iocbs(struct kioctx *ctx)
796 * Hold an extra reference while retrying i/o. 777 * Hold an extra reference while retrying i/o.
797 */ 778 */
798 iocb->ki_users++; /* grab extra reference */ 779 iocb->ki_users++; /* grab extra reference */
799 lock_kiocb(iocb);
800 aio_run_iocb(iocb); 780 aio_run_iocb(iocb);
801 unlock_kiocb(iocb);
802 if (__aio_put_req(ctx, iocb)) /* drop extra ref */ 781 if (__aio_put_req(ctx, iocb)) /* drop extra ref */
803 put_ioctx(ctx); 782 put_ioctx(ctx);
804 } 783 }
@@ -1542,7 +1521,6 @@ int fastcall io_submit_one(struct kioctx *ctx, struct iocb __user *user_iocb,
1542 1521
1543 spin_lock_irq(&ctx->ctx_lock); 1522 spin_lock_irq(&ctx->ctx_lock);
1544 aio_run_iocb(req); 1523 aio_run_iocb(req);
1545 unlock_kiocb(req);
1546 if (!list_empty(&ctx->run_list)) { 1524 if (!list_empty(&ctx->run_list)) {
1547 /* drain the run list */ 1525 /* drain the run list */
1548 while (__aio_run_iocbs(ctx)) 1526 while (__aio_run_iocbs(ctx))
@@ -1674,7 +1652,6 @@ asmlinkage long sys_io_cancel(aio_context_t ctx_id, struct iocb __user *iocb,
1674 if (NULL != cancel) { 1652 if (NULL != cancel) {
1675 struct io_event tmp; 1653 struct io_event tmp;
1676 pr_debug("calling cancel\n"); 1654 pr_debug("calling cancel\n");
1677 lock_kiocb(kiocb);
1678 memset(&tmp, 0, sizeof(tmp)); 1655 memset(&tmp, 0, sizeof(tmp));
1679 tmp.obj = (u64)(unsigned long)kiocb->ki_obj.user; 1656 tmp.obj = (u64)(unsigned long)kiocb->ki_obj.user;
1680 tmp.data = kiocb->ki_user_data; 1657 tmp.data = kiocb->ki_user_data;
@@ -1686,7 +1663,6 @@ asmlinkage long sys_io_cancel(aio_context_t ctx_id, struct iocb __user *iocb,
1686 if (copy_to_user(result, &tmp, sizeof(tmp))) 1663 if (copy_to_user(result, &tmp, sizeof(tmp)))
1687 ret = -EFAULT; 1664 ret = -EFAULT;
1688 } 1665 }
1689 unlock_kiocb(kiocb);
1690 } else 1666 } else
1691 ret = -EINVAL; 1667 ret = -EINVAL;
1692 1668
diff --git a/fs/exec.c b/fs/exec.c
index a04a575ad4..d2208f7c87 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -126,8 +126,7 @@ asmlinkage long sys_uselib(const char __user * library)
126 struct nameidata nd; 126 struct nameidata nd;
127 int error; 127 int error;
128 128
129 nd.intent.open.flags = FMODE_READ; 129 error = __user_path_lookup_open(library, LOOKUP_FOLLOW, &nd, FMODE_READ);
130 error = __user_walk(library, LOOKUP_FOLLOW|LOOKUP_OPEN, &nd);
131 if (error) 130 if (error)
132 goto out; 131 goto out;
133 132
@@ -139,7 +138,7 @@ asmlinkage long sys_uselib(const char __user * library)
139 if (error) 138 if (error)
140 goto exit; 139 goto exit;
141 140
142 file = dentry_open(nd.dentry, nd.mnt, O_RDONLY); 141 file = nameidata_to_filp(&nd, O_RDONLY);
143 error = PTR_ERR(file); 142 error = PTR_ERR(file);
144 if (IS_ERR(file)) 143 if (IS_ERR(file))
145 goto out; 144 goto out;
@@ -167,6 +166,7 @@ asmlinkage long sys_uselib(const char __user * library)
167out: 166out:
168 return error; 167 return error;
169exit: 168exit:
169 release_open_intent(&nd);
170 path_release(&nd); 170 path_release(&nd);
171 goto out; 171 goto out;
172} 172}
@@ -490,8 +490,7 @@ struct file *open_exec(const char *name)
490 int err; 490 int err;
491 struct file *file; 491 struct file *file;
492 492
493 nd.intent.open.flags = FMODE_READ; 493 err = path_lookup_open(name, LOOKUP_FOLLOW, &nd, FMODE_READ);
494 err = path_lookup(name, LOOKUP_FOLLOW|LOOKUP_OPEN, &nd);
495 file = ERR_PTR(err); 494 file = ERR_PTR(err);
496 495
497 if (!err) { 496 if (!err) {
@@ -504,7 +503,7 @@ struct file *open_exec(const char *name)
504 err = -EACCES; 503 err = -EACCES;
505 file = ERR_PTR(err); 504 file = ERR_PTR(err);
506 if (!err) { 505 if (!err) {
507 file = dentry_open(nd.dentry, nd.mnt, O_RDONLY); 506 file = nameidata_to_filp(&nd, O_RDONLY);
508 if (!IS_ERR(file)) { 507 if (!IS_ERR(file)) {
509 err = deny_write_access(file); 508 err = deny_write_access(file);
510 if (err) { 509 if (err) {
@@ -516,6 +515,7 @@ out:
516 return file; 515 return file;
517 } 516 }
518 } 517 }
518 release_open_intent(&nd);
519 path_release(&nd); 519 path_release(&nd);
520 } 520 }
521 goto out; 521 goto out;
diff --git a/fs/locks.c b/fs/locks.c
index 7eb1d77b92..a1e8b22480 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -316,21 +316,22 @@ static int flock_to_posix_lock(struct file *filp, struct file_lock *fl,
316 /* POSIX-1996 leaves the case l->l_len < 0 undefined; 316 /* POSIX-1996 leaves the case l->l_len < 0 undefined;
317 POSIX-2001 defines it. */ 317 POSIX-2001 defines it. */
318 start += l->l_start; 318 start += l->l_start;
319 end = start + l->l_len - 1; 319 if (start < 0)
320 if (l->l_len < 0) { 320 return -EINVAL;
321 fl->fl_end = OFFSET_MAX;
322 if (l->l_len > 0) {
323 end = start + l->l_len - 1;
324 fl->fl_end = end;
325 } else if (l->l_len < 0) {
321 end = start - 1; 326 end = start - 1;
327 fl->fl_end = end;
322 start += l->l_len; 328 start += l->l_len;
329 if (start < 0)
330 return -EINVAL;
323 } 331 }
324
325 if (start < 0)
326 return -EINVAL;
327 if (l->l_len > 0 && end < 0)
328 return -EOVERFLOW;
329
330 fl->fl_start = start; /* we record the absolute position */ 332 fl->fl_start = start; /* we record the absolute position */
331 fl->fl_end = end; 333 if (fl->fl_end < fl->fl_start)
332 if (l->l_len == 0) 334 return -EOVERFLOW;
333 fl->fl_end = OFFSET_MAX;
334 335
335 fl->fl_owner = current->files; 336 fl->fl_owner = current->files;
336 fl->fl_pid = current->tgid; 337 fl->fl_pid = current->tgid;
@@ -362,14 +363,21 @@ static int flock64_to_posix_lock(struct file *filp, struct file_lock *fl,
362 return -EINVAL; 363 return -EINVAL;
363 } 364 }
364 365
365 if (((start += l->l_start) < 0) || (l->l_len < 0)) 366 start += l->l_start;
367 if (start < 0)
366 return -EINVAL; 368 return -EINVAL;
367 fl->fl_end = start + l->l_len - 1; 369 fl->fl_end = OFFSET_MAX;
368 if (l->l_len > 0 && fl->fl_end < 0) 370 if (l->l_len > 0) {
369 return -EOVERFLOW; 371 fl->fl_end = start + l->l_len - 1;
372 } else if (l->l_len < 0) {
373 fl->fl_end = start - 1;
374 start += l->l_len;
375 if (start < 0)
376 return -EINVAL;
377 }
370 fl->fl_start = start; /* we record the absolute position */ 378 fl->fl_start = start; /* we record the absolute position */
371 if (l->l_len == 0) 379 if (fl->fl_end < fl->fl_start)
372 fl->fl_end = OFFSET_MAX; 380 return -EOVERFLOW;
373 381
374 fl->fl_owner = current->files; 382 fl->fl_owner = current->files;
375 fl->fl_pid = current->tgid; 383 fl->fl_pid = current->tgid;
diff --git a/fs/namei.c b/fs/namei.c
index aa62dbda93..aaaa810362 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -28,6 +28,7 @@
28#include <linux/syscalls.h> 28#include <linux/syscalls.h>
29#include <linux/mount.h> 29#include <linux/mount.h>
30#include <linux/audit.h> 30#include <linux/audit.h>
31#include <linux/file.h>
31#include <asm/namei.h> 32#include <asm/namei.h>
32#include <asm/uaccess.h> 33#include <asm/uaccess.h>
33 34
@@ -317,6 +318,18 @@ void path_release_on_umount(struct nameidata *nd)
317 mntput_no_expire(nd->mnt); 318 mntput_no_expire(nd->mnt);
318} 319}
319 320
321/**
322 * release_open_intent - free up open intent resources
323 * @nd: pointer to nameidata
324 */
325void release_open_intent(struct nameidata *nd)
326{
327 if (nd->intent.open.file->f_dentry == NULL)
328 put_filp(nd->intent.open.file);
329 else
330 fput(nd->intent.open.file);
331}
332
320/* 333/*
321 * Internal lookup() using the new generic dcache. 334 * Internal lookup() using the new generic dcache.
322 * SMP-safe 335 * SMP-safe
@@ -750,6 +763,7 @@ static fastcall int __link_path_walk(const char * name, struct nameidata *nd)
750 struct qstr this; 763 struct qstr this;
751 unsigned int c; 764 unsigned int c;
752 765
766 nd->flags |= LOOKUP_CONTINUE;
753 err = exec_permission_lite(inode, nd); 767 err = exec_permission_lite(inode, nd);
754 if (err == -EAGAIN) { 768 if (err == -EAGAIN) {
755 err = permission(inode, MAY_EXEC, nd); 769 err = permission(inode, MAY_EXEC, nd);
@@ -802,7 +816,6 @@ static fastcall int __link_path_walk(const char * name, struct nameidata *nd)
802 if (err < 0) 816 if (err < 0)
803 break; 817 break;
804 } 818 }
805 nd->flags |= LOOKUP_CONTINUE;
806 /* This does the actual lookups.. */ 819 /* This does the actual lookups.. */
807 err = do_lookup(nd, &this, &next); 820 err = do_lookup(nd, &this, &next);
808 if (err) 821 if (err)
@@ -1052,6 +1065,70 @@ out:
1052 return retval; 1065 return retval;
1053} 1066}
1054 1067
1068static int __path_lookup_intent_open(const char *name, unsigned int lookup_flags,
1069 struct nameidata *nd, int open_flags, int create_mode)
1070{
1071 struct file *filp = get_empty_filp();
1072 int err;
1073
1074 if (filp == NULL)
1075 return -ENFILE;
1076 nd->intent.open.file = filp;
1077 nd->intent.open.flags = open_flags;
1078 nd->intent.open.create_mode = create_mode;
1079 err = path_lookup(name, lookup_flags|LOOKUP_OPEN, nd);
1080 if (IS_ERR(nd->intent.open.file)) {
1081 if (err == 0) {
1082 err = PTR_ERR(nd->intent.open.file);
1083 path_release(nd);
1084 }
1085 } else if (err != 0)
1086 release_open_intent(nd);
1087 return err;
1088}
1089
1090/**
1091 * path_lookup_open - lookup a file path with open intent
1092 * @name: pointer to file name
1093 * @lookup_flags: lookup intent flags
1094 * @nd: pointer to nameidata
1095 * @open_flags: open intent flags
1096 */
1097int path_lookup_open(const char *name, unsigned int lookup_flags,
1098 struct nameidata *nd, int open_flags)
1099{
1100 return __path_lookup_intent_open(name, lookup_flags, nd,
1101 open_flags, 0);
1102}
1103
1104/**
1105 * path_lookup_create - lookup a file path with open + create intent
1106 * @name: pointer to file name
1107 * @lookup_flags: lookup intent flags
1108 * @nd: pointer to nameidata
1109 * @open_flags: open intent flags
1110 * @create_mode: create intent flags
1111 */
1112int path_lookup_create(const char *name, unsigned int lookup_flags,
1113 struct nameidata *nd, int open_flags, int create_mode)
1114{
1115 return __path_lookup_intent_open(name, lookup_flags|LOOKUP_CREATE, nd,
1116 open_flags, create_mode);
1117}
1118
1119int __user_path_lookup_open(const char __user *name, unsigned int lookup_flags,
1120 struct nameidata *nd, int open_flags)
1121{
1122 char *tmp = getname(name);
1123 int err = PTR_ERR(tmp);
1124
1125 if (!IS_ERR(tmp)) {
1126 err = __path_lookup_intent_open(tmp, lookup_flags, nd, open_flags, 0);
1127 putname(tmp);
1128 }
1129 return err;
1130}
1131
1055/* 1132/*
1056 * Restricted form of lookup. Doesn't follow links, single-component only, 1133 * Restricted form of lookup. Doesn't follow links, single-component only,
1057 * needs parent already locked. Doesn't follow mounts. 1134 * needs parent already locked. Doesn't follow mounts.
@@ -1416,27 +1493,27 @@ int may_open(struct nameidata *nd, int acc_mode, int flag)
1416 */ 1493 */
1417int open_namei(const char * pathname, int flag, int mode, struct nameidata *nd) 1494int open_namei(const char * pathname, int flag, int mode, struct nameidata *nd)
1418{ 1495{
1419 int acc_mode, error = 0; 1496 int acc_mode, error;
1420 struct path path; 1497 struct path path;
1421 struct dentry *dir; 1498 struct dentry *dir;
1422 int count = 0; 1499 int count = 0;
1423 1500
1424 acc_mode = ACC_MODE(flag); 1501 acc_mode = ACC_MODE(flag);
1425 1502
1503 /* O_TRUNC implies we need access checks for write permissions */
1504 if (flag & O_TRUNC)
1505 acc_mode |= MAY_WRITE;
1506
1426 /* Allow the LSM permission hook to distinguish append 1507 /* Allow the LSM permission hook to distinguish append
1427 access from general write access. */ 1508 access from general write access. */
1428 if (flag & O_APPEND) 1509 if (flag & O_APPEND)
1429 acc_mode |= MAY_APPEND; 1510 acc_mode |= MAY_APPEND;
1430 1511
1431 /* Fill in the open() intent data */
1432 nd->intent.open.flags = flag;
1433 nd->intent.open.create_mode = mode;
1434
1435 /* 1512 /*
1436 * The simplest case - just a plain lookup. 1513 * The simplest case - just a plain lookup.
1437 */ 1514 */
1438 if (!(flag & O_CREAT)) { 1515 if (!(flag & O_CREAT)) {
1439 error = path_lookup(pathname, lookup_flags(flag)|LOOKUP_OPEN, nd); 1516 error = path_lookup_open(pathname, lookup_flags(flag), nd, flag);
1440 if (error) 1517 if (error)
1441 return error; 1518 return error;
1442 goto ok; 1519 goto ok;
@@ -1445,7 +1522,7 @@ int open_namei(const char * pathname, int flag, int mode, struct nameidata *nd)
1445 /* 1522 /*
1446 * Create - we need to know the parent. 1523 * Create - we need to know the parent.
1447 */ 1524 */
1448 error = path_lookup(pathname, LOOKUP_PARENT|LOOKUP_OPEN|LOOKUP_CREATE, nd); 1525 error = path_lookup_create(pathname, LOOKUP_PARENT, nd, flag, mode);
1449 if (error) 1526 if (error)
1450 return error; 1527 return error;
1451 1528
@@ -1520,6 +1597,8 @@ ok:
1520exit_dput: 1597exit_dput:
1521 dput_path(&path, nd); 1598 dput_path(&path, nd);
1522exit: 1599exit:
1600 if (!IS_ERR(nd->intent.open.file))
1601 release_open_intent(nd);
1523 path_release(nd); 1602 path_release(nd);
1524 return error; 1603 return error;
1525 1604
diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c
index d7f7eb669d..44135af989 100644
--- a/fs/nfs/delegation.c
+++ b/fs/nfs/delegation.c
@@ -85,6 +85,10 @@ int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct
85 struct nfs_delegation *delegation; 85 struct nfs_delegation *delegation;
86 int status = 0; 86 int status = 0;
87 87
88 /* Ensure we first revalidate the attributes and page cache! */
89 if ((nfsi->cache_validity & (NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_ATTR)))
90 __nfs_revalidate_inode(NFS_SERVER(inode), inode);
91
88 delegation = nfs_alloc_delegation(); 92 delegation = nfs_alloc_delegation();
89 if (delegation == NULL) 93 if (delegation == NULL)
90 return -ENOMEM; 94 return -ENOMEM;
@@ -138,7 +142,7 @@ static void nfs_msync_inode(struct inode *inode)
138/* 142/*
139 * Basic procedure for returning a delegation to the server 143 * Basic procedure for returning a delegation to the server
140 */ 144 */
141int nfs_inode_return_delegation(struct inode *inode) 145int __nfs_inode_return_delegation(struct inode *inode)
142{ 146{
143 struct nfs4_client *clp = NFS_SERVER(inode)->nfs4_state; 147 struct nfs4_client *clp = NFS_SERVER(inode)->nfs4_state;
144 struct nfs_inode *nfsi = NFS_I(inode); 148 struct nfs_inode *nfsi = NFS_I(inode);
diff --git a/fs/nfs/delegation.h b/fs/nfs/delegation.h
index 3f6c45a29d..8017846b56 100644
--- a/fs/nfs/delegation.h
+++ b/fs/nfs/delegation.h
@@ -25,7 +25,7 @@ struct nfs_delegation {
25 25
26int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res); 26int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res);
27void nfs_inode_reclaim_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res); 27void nfs_inode_reclaim_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res);
28int nfs_inode_return_delegation(struct inode *inode); 28int __nfs_inode_return_delegation(struct inode *inode);
29int nfs_async_inode_return_delegation(struct inode *inode, const nfs4_stateid *stateid); 29int nfs_async_inode_return_delegation(struct inode *inode, const nfs4_stateid *stateid);
30 30
31struct inode *nfs_delegation_find_inode(struct nfs4_client *clp, const struct nfs_fh *fhandle); 31struct inode *nfs_delegation_find_inode(struct nfs4_client *clp, const struct nfs_fh *fhandle);
@@ -47,11 +47,25 @@ static inline int nfs_have_delegation(struct inode *inode, int flags)
47 return 1; 47 return 1;
48 return 0; 48 return 0;
49} 49}
50
51static inline int nfs_inode_return_delegation(struct inode *inode)
52{
53 int err = 0;
54
55 if (NFS_I(inode)->delegation != NULL)
56 err = __nfs_inode_return_delegation(inode);
57 return err;
58}
50#else 59#else
51static inline int nfs_have_delegation(struct inode *inode, int flags) 60static inline int nfs_have_delegation(struct inode *inode, int flags)
52{ 61{
53 return 0; 62 return 0;
54} 63}
64
65static inline int nfs_inode_return_delegation(struct inode *inode)
66{
67 return 0;
68}
55#endif 69#endif
56 70
57#endif 71#endif
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index c70eabd6d1..eb50c19fc2 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -801,6 +801,7 @@ static int nfs_dentry_delete(struct dentry *dentry)
801 */ 801 */
802static void nfs_dentry_iput(struct dentry *dentry, struct inode *inode) 802static void nfs_dentry_iput(struct dentry *dentry, struct inode *inode)
803{ 803{
804 nfs_inode_return_delegation(inode);
804 if (dentry->d_flags & DCACHE_NFSFS_RENAMED) { 805 if (dentry->d_flags & DCACHE_NFSFS_RENAMED) {
805 lock_kernel(); 806 lock_kernel();
806 inode->i_nlink--; 807 inode->i_nlink--;
@@ -914,7 +915,6 @@ static int is_atomic_open(struct inode *dir, struct nameidata *nd)
914static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd) 915static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
915{ 916{
916 struct dentry *res = NULL; 917 struct dentry *res = NULL;
917 struct inode *inode = NULL;
918 int error; 918 int error;
919 919
920 /* Check that we are indeed trying to open this file */ 920 /* Check that we are indeed trying to open this file */
@@ -928,8 +928,10 @@ static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry
928 dentry->d_op = NFS_PROTO(dir)->dentry_ops; 928 dentry->d_op = NFS_PROTO(dir)->dentry_ops;
929 929
930 /* Let vfs_create() deal with O_EXCL */ 930 /* Let vfs_create() deal with O_EXCL */
931 if (nd->intent.open.flags & O_EXCL) 931 if (nd->intent.open.flags & O_EXCL) {
932 goto no_entry; 932 d_add(dentry, NULL);
933 goto out;
934 }
933 935
934 /* Open the file on the server */ 936 /* Open the file on the server */
935 lock_kernel(); 937 lock_kernel();
@@ -943,32 +945,30 @@ static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry
943 945
944 if (nd->intent.open.flags & O_CREAT) { 946 if (nd->intent.open.flags & O_CREAT) {
945 nfs_begin_data_update(dir); 947 nfs_begin_data_update(dir);
946 inode = nfs4_atomic_open(dir, dentry, nd); 948 res = nfs4_atomic_open(dir, dentry, nd);
947 nfs_end_data_update(dir); 949 nfs_end_data_update(dir);
948 } else 950 } else
949 inode = nfs4_atomic_open(dir, dentry, nd); 951 res = nfs4_atomic_open(dir, dentry, nd);
950 unlock_kernel(); 952 unlock_kernel();
951 if (IS_ERR(inode)) { 953 if (IS_ERR(res)) {
952 error = PTR_ERR(inode); 954 error = PTR_ERR(res);
953 switch (error) { 955 switch (error) {
954 /* Make a negative dentry */ 956 /* Make a negative dentry */
955 case -ENOENT: 957 case -ENOENT:
956 inode = NULL; 958 res = NULL;
957 break; 959 goto out;
958 /* This turned out not to be a regular file */ 960 /* This turned out not to be a regular file */
961 case -EISDIR:
962 case -ENOTDIR:
963 goto no_open;
959 case -ELOOP: 964 case -ELOOP:
960 if (!(nd->intent.open.flags & O_NOFOLLOW)) 965 if (!(nd->intent.open.flags & O_NOFOLLOW))
961 goto no_open; 966 goto no_open;
962 /* case -EISDIR: */
963 /* case -EINVAL: */ 967 /* case -EINVAL: */
964 default: 968 default:
965 res = ERR_PTR(error);
966 goto out; 969 goto out;
967 } 970 }
968 } 971 } else if (res != NULL)
969no_entry:
970 res = d_add_unique(dentry, inode);
971 if (res != NULL)
972 dentry = res; 972 dentry = res;
973 nfs_renew_times(dentry); 973 nfs_renew_times(dentry);
974 nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); 974 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
@@ -1012,7 +1012,7 @@ static int nfs_open_revalidate(struct dentry *dentry, struct nameidata *nd)
1012 */ 1012 */
1013 lock_kernel(); 1013 lock_kernel();
1014 verifier = nfs_save_change_attribute(dir); 1014 verifier = nfs_save_change_attribute(dir);
1015 ret = nfs4_open_revalidate(dir, dentry, openflags); 1015 ret = nfs4_open_revalidate(dir, dentry, openflags, nd);
1016 if (!ret) 1016 if (!ret)
1017 nfs_set_verifier(dentry, verifier); 1017 nfs_set_verifier(dentry, verifier);
1018 unlock_kernel(); 1018 unlock_kernel();
@@ -1135,7 +1135,7 @@ static int nfs_create(struct inode *dir, struct dentry *dentry, int mode,
1135 1135
1136 lock_kernel(); 1136 lock_kernel();
1137 nfs_begin_data_update(dir); 1137 nfs_begin_data_update(dir);
1138 error = NFS_PROTO(dir)->create(dir, dentry, &attr, open_flags); 1138 error = NFS_PROTO(dir)->create(dir, dentry, &attr, open_flags, nd);
1139 nfs_end_data_update(dir); 1139 nfs_end_data_update(dir);
1140 if (error != 0) 1140 if (error != 0)
1141 goto out_err; 1141 goto out_err;
@@ -1330,6 +1330,7 @@ static int nfs_safe_remove(struct dentry *dentry)
1330 1330
1331 nfs_begin_data_update(dir); 1331 nfs_begin_data_update(dir);
1332 if (inode != NULL) { 1332 if (inode != NULL) {
1333 nfs_inode_return_delegation(inode);
1333 nfs_begin_data_update(inode); 1334 nfs_begin_data_update(inode);
1334 error = NFS_PROTO(dir)->remove(dir, &dentry->d_name); 1335 error = NFS_PROTO(dir)->remove(dir, &dentry->d_name);
1335 /* The VFS may want to delete this inode */ 1336 /* The VFS may want to delete this inode */
@@ -1510,9 +1511,11 @@ static int nfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1510 */ 1511 */
1511 if (!new_inode) 1512 if (!new_inode)
1512 goto go_ahead; 1513 goto go_ahead;
1513 if (S_ISDIR(new_inode->i_mode)) 1514 if (S_ISDIR(new_inode->i_mode)) {
1514 goto out; 1515 error = -EISDIR;
1515 else if (atomic_read(&new_dentry->d_count) > 2) { 1516 if (!S_ISDIR(old_inode->i_mode))
1517 goto out;
1518 } else if (atomic_read(&new_dentry->d_count) > 2) {
1516 int err; 1519 int err;
1517 /* copy the target dentry's name */ 1520 /* copy the target dentry's name */
1518 dentry = d_alloc(new_dentry->d_parent, 1521 dentry = d_alloc(new_dentry->d_parent,
@@ -1548,6 +1551,7 @@ go_ahead:
1548 nfs_wb_all(old_inode); 1551 nfs_wb_all(old_inode);
1549 shrink_dcache_parent(old_dentry); 1552 shrink_dcache_parent(old_dentry);
1550 } 1553 }
1554 nfs_inode_return_delegation(old_inode);
1551 1555
1552 if (new_inode) 1556 if (new_inode)
1553 d_delete(new_dentry); 1557 d_delete(new_dentry);
diff --git a/fs/nfs/file.c b/fs/nfs/file.c
index f6b9eda925..572d859348 100644
--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -137,7 +137,8 @@ static int nfs_revalidate_file(struct inode *inode, struct file *filp)
137 struct nfs_inode *nfsi = NFS_I(inode); 137 struct nfs_inode *nfsi = NFS_I(inode);
138 int retval = 0; 138 int retval = 0;
139 139
140 if ((nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE) || nfs_attribute_timeout(inode)) 140 if ((nfsi->cache_validity & (NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_ATTR))
141 || nfs_attribute_timeout(inode))
141 retval = __nfs_revalidate_inode(NFS_SERVER(inode), inode); 142 retval = __nfs_revalidate_inode(NFS_SERVER(inode), inode);
142 nfs_revalidate_mapping(inode, filp->f_mapping); 143 nfs_revalidate_mapping(inode, filp->f_mapping);
143 return 0; 144 return 0;
@@ -375,22 +376,31 @@ out_swapfile:
375 376
376static int do_getlk(struct file *filp, int cmd, struct file_lock *fl) 377static int do_getlk(struct file *filp, int cmd, struct file_lock *fl)
377{ 378{
379 struct file_lock *cfl;
378 struct inode *inode = filp->f_mapping->host; 380 struct inode *inode = filp->f_mapping->host;
379 int status = 0; 381 int status = 0;
380 382
381 lock_kernel(); 383 lock_kernel();
382 /* Use local locking if mounted with "-onolock" */ 384 /* Try local locking first */
383 if (!(NFS_SERVER(inode)->flags & NFS_MOUNT_NONLM)) 385 cfl = posix_test_lock(filp, fl);
384 status = NFS_PROTO(inode)->lock(filp, cmd, fl); 386 if (cfl != NULL) {
385 else { 387 locks_copy_lock(fl, cfl);
386 struct file_lock *cfl = posix_test_lock(filp, fl); 388 goto out;
387
388 fl->fl_type = F_UNLCK;
389 if (cfl != NULL)
390 memcpy(fl, cfl, sizeof(*fl));
391 } 389 }
390
391 if (nfs_have_delegation(inode, FMODE_READ))
392 goto out_noconflict;
393
394 if (NFS_SERVER(inode)->flags & NFS_MOUNT_NONLM)
395 goto out_noconflict;
396
397 status = NFS_PROTO(inode)->lock(filp, cmd, fl);
398out:
392 unlock_kernel(); 399 unlock_kernel();
393 return status; 400 return status;
401out_noconflict:
402 fl->fl_type = F_UNLCK;
403 goto out;
394} 404}
395 405
396static int do_vfs_lock(struct file *file, struct file_lock *fl) 406static int do_vfs_lock(struct file *file, struct file_lock *fl)
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index 358d8ef8c0..65d5ab45dd 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -853,6 +853,11 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr)
853 filemap_fdatawait(inode->i_mapping); 853 filemap_fdatawait(inode->i_mapping);
854 nfs_wb_all(inode); 854 nfs_wb_all(inode);
855 } 855 }
856 /*
857 * Return any delegations if we're going to change ACLs
858 */
859 if ((attr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0)
860 nfs_inode_return_delegation(inode);
856 error = NFS_PROTO(inode)->setattr(dentry, &fattr, attr); 861 error = NFS_PROTO(inode)->setattr(dentry, &fattr, attr);
857 if (error == 0) 862 if (error == 0)
858 nfs_refresh_inode(inode, &fattr); 863 nfs_refresh_inode(inode, &fattr);
@@ -909,12 +914,10 @@ static int nfs_wait_on_inode(struct inode *inode)
909 sigset_t oldmask; 914 sigset_t oldmask;
910 int error; 915 int error;
911 916
912 atomic_inc(&inode->i_count);
913 rpc_clnt_sigmask(clnt, &oldmask); 917 rpc_clnt_sigmask(clnt, &oldmask);
914 error = wait_on_bit_lock(&nfsi->flags, NFS_INO_REVALIDATING, 918 error = wait_on_bit_lock(&nfsi->flags, NFS_INO_REVALIDATING,
915 nfs_wait_schedule, TASK_INTERRUPTIBLE); 919 nfs_wait_schedule, TASK_INTERRUPTIBLE);
916 rpc_clnt_sigunmask(clnt, &oldmask); 920 rpc_clnt_sigunmask(clnt, &oldmask);
917 iput(inode);
918 921
919 return error; 922 return error;
920} 923}
@@ -1258,10 +1261,6 @@ int nfs_refresh_inode(struct inode *inode, struct nfs_fattr *fattr)
1258 loff_t cur_size, new_isize; 1261 loff_t cur_size, new_isize;
1259 int data_unstable; 1262 int data_unstable;
1260 1263
1261 /* Do we hold a delegation? */
1262 if (nfs_have_delegation(inode, FMODE_READ))
1263 return 0;
1264
1265 spin_lock(&inode->i_lock); 1264 spin_lock(&inode->i_lock);
1266 1265
1267 /* Are we in the process of updating data on the server? */ 1266 /* Are we in the process of updating data on the server? */
@@ -1382,7 +1381,8 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr, unsign
1382 nfsi->read_cache_jiffies = fattr->timestamp; 1381 nfsi->read_cache_jiffies = fattr->timestamp;
1383 1382
1384 /* Are we racing with known updates of the metadata on the server? */ 1383 /* Are we racing with known updates of the metadata on the server? */
1385 data_unstable = ! nfs_verify_change_attribute(inode, verifier); 1384 data_unstable = ! (nfs_verify_change_attribute(inode, verifier) ||
1385 (nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE));
1386 1386
1387 /* Check if our cached file size is stale */ 1387 /* Check if our cached file size is stale */
1388 new_isize = nfs_size_to_loff_t(fattr->size); 1388 new_isize = nfs_size_to_loff_t(fattr->size);
@@ -1676,8 +1676,7 @@ static void nfs4_clear_inode(struct inode *inode)
1676 struct nfs_inode *nfsi = NFS_I(inode); 1676 struct nfs_inode *nfsi = NFS_I(inode);
1677 1677
1678 /* If we are holding a delegation, return it! */ 1678 /* If we are holding a delegation, return it! */
1679 if (nfsi->delegation != NULL) 1679 nfs_inode_return_delegation(inode);
1680 nfs_inode_return_delegation(inode);
1681 /* First call standard NFS clear_inode() code */ 1680 /* First call standard NFS clear_inode() code */
1682 nfs_clear_inode(inode); 1681 nfs_clear_inode(inode);
1683 /* Now clear out any remaining state */ 1682 /* Now clear out any remaining state */
diff --git a/fs/nfs/nfs3proc.c b/fs/nfs/nfs3proc.c
index edc9551404..df80477c5a 100644
--- a/fs/nfs/nfs3proc.c
+++ b/fs/nfs/nfs3proc.c
@@ -299,7 +299,7 @@ static int nfs3_proc_commit(struct nfs_write_data *cdata)
299 */ 299 */
300static int 300static int
301nfs3_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, 301nfs3_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
302 int flags) 302 int flags, struct nameidata *nd)
303{ 303{
304 struct nfs_fh fhandle; 304 struct nfs_fh fhandle;
305 struct nfs_fattr fattr; 305 struct nfs_fattr fattr;
diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h
index ec1a22d7b8..8a37881990 100644
--- a/fs/nfs/nfs4_fs.h
+++ b/fs/nfs/nfs4_fs.h
@@ -93,25 +93,50 @@ struct nfs4_client {
93}; 93};
94 94
95/* 95/*
96 * struct rpc_sequence ensures that RPC calls are sent in the exact
97 * order that they appear on the list.
98 */
99struct rpc_sequence {
100 struct rpc_wait_queue wait; /* RPC call delay queue */
101 spinlock_t lock; /* Protects the list */
102 struct list_head list; /* Defines sequence of RPC calls */
103};
104
105#define NFS_SEQID_CONFIRMED 1
106struct nfs_seqid_counter {
107 struct rpc_sequence *sequence;
108 int flags;
109 u32 counter;
110};
111
112struct nfs_seqid {
113 struct list_head list;
114 struct nfs_seqid_counter *sequence;
115 struct rpc_task *task;
116};
117
118static inline void nfs_confirm_seqid(struct nfs_seqid_counter *seqid, int status)
119{
120 if (seqid_mutating_err(-status))
121 seqid->flags |= NFS_SEQID_CONFIRMED;
122}
123
124/*
96 * NFS4 state_owners and lock_owners are simply labels for ordered 125 * NFS4 state_owners and lock_owners are simply labels for ordered
97 * sequences of RPC calls. Their sole purpose is to provide once-only 126 * sequences of RPC calls. Their sole purpose is to provide once-only
98 * semantics by allowing the server to identify replayed requests. 127 * semantics by allowing the server to identify replayed requests.
99 *
100 * The ->so_sema is held during all state_owner seqid-mutating operations:
101 * OPEN, OPEN_DOWNGRADE, and CLOSE. Its purpose is to properly serialize
102 * so_seqid.
103 */ 128 */
104struct nfs4_state_owner { 129struct nfs4_state_owner {
105 struct list_head so_list; /* per-clientid list of state_owners */ 130 struct list_head so_list; /* per-clientid list of state_owners */
106 struct nfs4_client *so_client; 131 struct nfs4_client *so_client;
107 u32 so_id; /* 32-bit identifier, unique */ 132 u32 so_id; /* 32-bit identifier, unique */
108 struct semaphore so_sema;
109 u32 so_seqid; /* protected by so_sema */
110 atomic_t so_count; 133 atomic_t so_count;
111 134
112 struct rpc_cred *so_cred; /* Associated cred */ 135 struct rpc_cred *so_cred; /* Associated cred */
113 struct list_head so_states; 136 struct list_head so_states;
114 struct list_head so_delegations; 137 struct list_head so_delegations;
138 struct nfs_seqid_counter so_seqid;
139 struct rpc_sequence so_sequence;
115}; 140};
116 141
117/* 142/*
@@ -132,7 +157,7 @@ struct nfs4_lock_state {
132 fl_owner_t ls_owner; /* POSIX lock owner */ 157 fl_owner_t ls_owner; /* POSIX lock owner */
133#define NFS_LOCK_INITIALIZED 1 158#define NFS_LOCK_INITIALIZED 1
134 int ls_flags; 159 int ls_flags;
135 u32 ls_seqid; 160 struct nfs_seqid_counter ls_seqid;
136 u32 ls_id; 161 u32 ls_id;
137 nfs4_stateid ls_stateid; 162 nfs4_stateid ls_stateid;
138 atomic_t ls_count; 163 atomic_t ls_count;
@@ -153,7 +178,6 @@ struct nfs4_state {
153 struct inode *inode; /* Pointer to the inode */ 178 struct inode *inode; /* Pointer to the inode */
154 179
155 unsigned long flags; /* Do we hold any locks? */ 180 unsigned long flags; /* Do we hold any locks? */
156 struct semaphore lock_sema; /* Serializes file locking operations */
157 spinlock_t state_lock; /* Protects the lock_states list */ 181 spinlock_t state_lock; /* Protects the lock_states list */
158 182
159 nfs4_stateid stateid; 183 nfs4_stateid stateid;
@@ -191,8 +215,8 @@ extern int nfs4_proc_setclientid_confirm(struct nfs4_client *);
191extern int nfs4_proc_async_renew(struct nfs4_client *); 215extern int nfs4_proc_async_renew(struct nfs4_client *);
192extern int nfs4_proc_renew(struct nfs4_client *); 216extern int nfs4_proc_renew(struct nfs4_client *);
193extern int nfs4_do_close(struct inode *inode, struct nfs4_state *state, mode_t mode); 217extern int nfs4_do_close(struct inode *inode, struct nfs4_state *state, mode_t mode);
194extern struct inode *nfs4_atomic_open(struct inode *, struct dentry *, struct nameidata *); 218extern struct dentry *nfs4_atomic_open(struct inode *, struct dentry *, struct nameidata *);
195extern int nfs4_open_revalidate(struct inode *, struct dentry *, int); 219extern int nfs4_open_revalidate(struct inode *, struct dentry *, int, struct nameidata *);
196 220
197extern struct nfs4_state_recovery_ops nfs4_reboot_recovery_ops; 221extern struct nfs4_state_recovery_ops nfs4_reboot_recovery_ops;
198extern struct nfs4_state_recovery_ops nfs4_network_partition_recovery_ops; 222extern struct nfs4_state_recovery_ops nfs4_network_partition_recovery_ops;
@@ -224,12 +248,17 @@ extern struct nfs4_state * nfs4_get_open_state(struct inode *, struct nfs4_state
224extern void nfs4_put_open_state(struct nfs4_state *); 248extern void nfs4_put_open_state(struct nfs4_state *);
225extern void nfs4_close_state(struct nfs4_state *, mode_t); 249extern void nfs4_close_state(struct nfs4_state *, mode_t);
226extern struct nfs4_state *nfs4_find_state(struct inode *, struct rpc_cred *, mode_t mode); 250extern struct nfs4_state *nfs4_find_state(struct inode *, struct rpc_cred *, mode_t mode);
227extern void nfs4_increment_seqid(int status, struct nfs4_state_owner *sp);
228extern void nfs4_schedule_state_recovery(struct nfs4_client *); 251extern void nfs4_schedule_state_recovery(struct nfs4_client *);
252extern void nfs4_put_lock_state(struct nfs4_lock_state *lsp);
229extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl); 253extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl);
230extern void nfs4_increment_lock_seqid(int status, struct nfs4_lock_state *ls);
231extern void nfs4_copy_stateid(nfs4_stateid *, struct nfs4_state *, fl_owner_t); 254extern void nfs4_copy_stateid(nfs4_stateid *, struct nfs4_state *, fl_owner_t);
232 255
256extern struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter);
257extern int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task);
258extern void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid);
259extern void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid);
260extern void nfs_free_seqid(struct nfs_seqid *seqid);
261
233extern const nfs4_stateid zero_stateid; 262extern const nfs4_stateid zero_stateid;
234 263
235/* nfs4xdr.c */ 264/* nfs4xdr.c */
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 9701ca8c94..ff378126cc 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -47,6 +47,7 @@
47#include <linux/nfs_page.h> 47#include <linux/nfs_page.h>
48#include <linux/smp_lock.h> 48#include <linux/smp_lock.h>
49#include <linux/namei.h> 49#include <linux/namei.h>
50#include <linux/mount.h>
50 51
51#include "nfs4_fs.h" 52#include "nfs4_fs.h"
52#include "delegation.h" 53#include "delegation.h"
@@ -56,10 +57,11 @@
56#define NFS4_POLL_RETRY_MIN (1*HZ) 57#define NFS4_POLL_RETRY_MIN (1*HZ)
57#define NFS4_POLL_RETRY_MAX (15*HZ) 58#define NFS4_POLL_RETRY_MAX (15*HZ)
58 59
60static int _nfs4_proc_open_confirm(struct rpc_clnt *clnt, const struct nfs_fh *fh, struct nfs4_state_owner *sp, nfs4_stateid *stateid, struct nfs_seqid *seqid);
59static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); 61static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *);
60static int nfs4_async_handle_error(struct rpc_task *, struct nfs_server *); 62static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *);
61static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry); 63static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry);
62static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception); 64static int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct nfs4_exception *exception);
63extern u32 *nfs4_decode_dirent(u32 *p, struct nfs_entry *entry, int plus); 65extern u32 *nfs4_decode_dirent(u32 *p, struct nfs_entry *entry, int plus);
64extern struct rpc_procinfo nfs4_procedures[]; 66extern struct rpc_procinfo nfs4_procedures[];
65 67
@@ -189,6 +191,21 @@ static void update_changeattr(struct inode *inode, struct nfs4_change_info *cinf
189 nfsi->change_attr = cinfo->after; 191 nfsi->change_attr = cinfo->after;
190} 192}
191 193
194/* Helper for asynchronous RPC calls */
195static int nfs4_call_async(struct rpc_clnt *clnt, rpc_action tk_begin,
196 rpc_action tk_exit, void *calldata)
197{
198 struct rpc_task *task;
199
200 if (!(task = rpc_new_task(clnt, tk_exit, RPC_TASK_ASYNC)))
201 return -ENOMEM;
202
203 task->tk_calldata = calldata;
204 task->tk_action = tk_begin;
205 rpc_execute(task);
206 return 0;
207}
208
192static void update_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, int open_flags) 209static void update_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, int open_flags)
193{ 210{
194 struct inode *inode = state->inode; 211 struct inode *inode = state->inode;
@@ -209,7 +226,6 @@ static void update_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid,
209/* 226/*
210 * OPEN_RECLAIM: 227 * OPEN_RECLAIM:
211 * reclaim state on the server after a reboot. 228 * reclaim state on the server after a reboot.
212 * Assumes caller is holding the sp->so_sem
213 */ 229 */
214static int _nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) 230static int _nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state)
215{ 231{
@@ -218,7 +234,6 @@ static int _nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *st
218 struct nfs_delegation *delegation = NFS_I(inode)->delegation; 234 struct nfs_delegation *delegation = NFS_I(inode)->delegation;
219 struct nfs_openargs o_arg = { 235 struct nfs_openargs o_arg = {
220 .fh = NFS_FH(inode), 236 .fh = NFS_FH(inode),
221 .seqid = sp->so_seqid,
222 .id = sp->so_id, 237 .id = sp->so_id,
223 .open_flags = state->state, 238 .open_flags = state->state,
224 .clientid = server->nfs4_state->cl_clientid, 239 .clientid = server->nfs4_state->cl_clientid,
@@ -245,8 +260,13 @@ static int _nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *st
245 } 260 }
246 o_arg.u.delegation_type = delegation->type; 261 o_arg.u.delegation_type = delegation->type;
247 } 262 }
263 o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid);
264 if (o_arg.seqid == NULL)
265 return -ENOMEM;
248 status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR); 266 status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
249 nfs4_increment_seqid(status, sp); 267 /* Confirm the sequence as being established */
268 nfs_confirm_seqid(&sp->so_seqid, status);
269 nfs_increment_open_seqid(status, o_arg.seqid);
250 if (status == 0) { 270 if (status == 0) {
251 memcpy(&state->stateid, &o_res.stateid, sizeof(state->stateid)); 271 memcpy(&state->stateid, &o_res.stateid, sizeof(state->stateid));
252 if (o_res.delegation_type != 0) { 272 if (o_res.delegation_type != 0) {
@@ -256,6 +276,7 @@ static int _nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *st
256 nfs_async_inode_return_delegation(inode, &o_res.stateid); 276 nfs_async_inode_return_delegation(inode, &o_res.stateid);
257 } 277 }
258 } 278 }
279 nfs_free_seqid(o_arg.seqid);
259 clear_bit(NFS_DELEGATED_STATE, &state->flags); 280 clear_bit(NFS_DELEGATED_STATE, &state->flags);
260 /* Ensure we update the inode attributes */ 281 /* Ensure we update the inode attributes */
261 NFS_CACHEINV(inode); 282 NFS_CACHEINV(inode);
@@ -302,23 +323,35 @@ static int _nfs4_open_delegation_recall(struct dentry *dentry, struct nfs4_state
302 }; 323 };
303 int status = 0; 324 int status = 0;
304 325
305 down(&sp->so_sema);
306 if (!test_bit(NFS_DELEGATED_STATE, &state->flags)) 326 if (!test_bit(NFS_DELEGATED_STATE, &state->flags))
307 goto out; 327 goto out;
308 if (state->state == 0) 328 if (state->state == 0)
309 goto out; 329 goto out;
310 arg.seqid = sp->so_seqid; 330 arg.seqid = nfs_alloc_seqid(&sp->so_seqid);
331 status = -ENOMEM;
332 if (arg.seqid == NULL)
333 goto out;
311 arg.open_flags = state->state; 334 arg.open_flags = state->state;
312 memcpy(arg.u.delegation.data, state->stateid.data, sizeof(arg.u.delegation.data)); 335 memcpy(arg.u.delegation.data, state->stateid.data, sizeof(arg.u.delegation.data));
313 status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR); 336 status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
314 nfs4_increment_seqid(status, sp); 337 nfs_increment_open_seqid(status, arg.seqid);
338 if (status != 0)
339 goto out_free;
340 if(res.rflags & NFS4_OPEN_RESULT_CONFIRM) {
341 status = _nfs4_proc_open_confirm(server->client, NFS_FH(inode),
342 sp, &res.stateid, arg.seqid);
343 if (status != 0)
344 goto out_free;
345 }
346 nfs_confirm_seqid(&sp->so_seqid, 0);
315 if (status >= 0) { 347 if (status >= 0) {
316 memcpy(state->stateid.data, res.stateid.data, 348 memcpy(state->stateid.data, res.stateid.data,
317 sizeof(state->stateid.data)); 349 sizeof(state->stateid.data));
318 clear_bit(NFS_DELEGATED_STATE, &state->flags); 350 clear_bit(NFS_DELEGATED_STATE, &state->flags);
319 } 351 }
352out_free:
353 nfs_free_seqid(arg.seqid);
320out: 354out:
321 up(&sp->so_sema);
322 dput(parent); 355 dput(parent);
323 return status; 356 return status;
324} 357}
@@ -345,11 +378,11 @@ int nfs4_open_delegation_recall(struct dentry *dentry, struct nfs4_state *state)
345 return err; 378 return err;
346} 379}
347 380
348static inline int _nfs4_proc_open_confirm(struct rpc_clnt *clnt, const struct nfs_fh *fh, struct nfs4_state_owner *sp, nfs4_stateid *stateid) 381static int _nfs4_proc_open_confirm(struct rpc_clnt *clnt, const struct nfs_fh *fh, struct nfs4_state_owner *sp, nfs4_stateid *stateid, struct nfs_seqid *seqid)
349{ 382{
350 struct nfs_open_confirmargs arg = { 383 struct nfs_open_confirmargs arg = {
351 .fh = fh, 384 .fh = fh,
352 .seqid = sp->so_seqid, 385 .seqid = seqid,
353 .stateid = *stateid, 386 .stateid = *stateid,
354 }; 387 };
355 struct nfs_open_confirmres res; 388 struct nfs_open_confirmres res;
@@ -362,7 +395,9 @@ static inline int _nfs4_proc_open_confirm(struct rpc_clnt *clnt, const struct nf
362 int status; 395 int status;
363 396
364 status = rpc_call_sync(clnt, &msg, RPC_TASK_NOINTR); 397 status = rpc_call_sync(clnt, &msg, RPC_TASK_NOINTR);
365 nfs4_increment_seqid(status, sp); 398 /* Confirm the sequence as being established */
399 nfs_confirm_seqid(&sp->so_seqid, status);
400 nfs_increment_open_seqid(status, seqid);
366 if (status >= 0) 401 if (status >= 0)
367 memcpy(stateid, &res.stateid, sizeof(*stateid)); 402 memcpy(stateid, &res.stateid, sizeof(*stateid));
368 return status; 403 return status;
@@ -380,21 +415,37 @@ static int _nfs4_proc_open(struct inode *dir, struct nfs4_state_owner *sp, stru
380 int status; 415 int status;
381 416
382 /* Update sequence id. The caller must serialize! */ 417 /* Update sequence id. The caller must serialize! */
383 o_arg->seqid = sp->so_seqid;
384 o_arg->id = sp->so_id; 418 o_arg->id = sp->so_id;
385 o_arg->clientid = sp->so_client->cl_clientid; 419 o_arg->clientid = sp->so_client->cl_clientid;
386 420
387 status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR); 421 status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
388 nfs4_increment_seqid(status, sp); 422 if (status == 0) {
423 /* OPEN on anything except a regular file is disallowed in NFSv4 */
424 switch (o_res->f_attr->mode & S_IFMT) {
425 case S_IFREG:
426 break;
427 case S_IFLNK:
428 status = -ELOOP;
429 break;
430 case S_IFDIR:
431 status = -EISDIR;
432 break;
433 default:
434 status = -ENOTDIR;
435 }
436 }
437
438 nfs_increment_open_seqid(status, o_arg->seqid);
389 if (status != 0) 439 if (status != 0)
390 goto out; 440 goto out;
391 update_changeattr(dir, &o_res->cinfo); 441 update_changeattr(dir, &o_res->cinfo);
392 if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { 442 if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) {
393 status = _nfs4_proc_open_confirm(server->client, &o_res->fh, 443 status = _nfs4_proc_open_confirm(server->client, &o_res->fh,
394 sp, &o_res->stateid); 444 sp, &o_res->stateid, o_arg->seqid);
395 if (status != 0) 445 if (status != 0)
396 goto out; 446 goto out;
397 } 447 }
448 nfs_confirm_seqid(&sp->so_seqid, 0);
398 if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) 449 if (!(o_res->f_attr->valid & NFS_ATTR_FATTR))
399 status = server->rpc_ops->getattr(server, &o_res->fh, o_res->f_attr); 450 status = server->rpc_ops->getattr(server, &o_res->fh, o_res->f_attr);
400out: 451out:
@@ -465,6 +516,10 @@ static int _nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *st
465 set_bit(NFS_DELEGATED_STATE, &state->flags); 516 set_bit(NFS_DELEGATED_STATE, &state->flags);
466 goto out; 517 goto out;
467 } 518 }
519 o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid);
520 status = -ENOMEM;
521 if (o_arg.seqid == NULL)
522 goto out;
468 status = _nfs4_proc_open(dir, sp, &o_arg, &o_res); 523 status = _nfs4_proc_open(dir, sp, &o_arg, &o_res);
469 if (status != 0) 524 if (status != 0)
470 goto out_nodeleg; 525 goto out_nodeleg;
@@ -490,6 +545,7 @@ static int _nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *st
490 nfs_inode_reclaim_delegation(inode, sp->so_cred, &o_res); 545 nfs_inode_reclaim_delegation(inode, sp->so_cred, &o_res);
491 } 546 }
492out_nodeleg: 547out_nodeleg:
548 nfs_free_seqid(o_arg.seqid);
493 clear_bit(NFS_DELEGATED_STATE, &state->flags); 549 clear_bit(NFS_DELEGATED_STATE, &state->flags);
494out: 550out:
495 dput(parent); 551 dput(parent);
@@ -564,7 +620,6 @@ static int _nfs4_open_delegated(struct inode *inode, int flags, struct rpc_cred
564 dprintk("%s: nfs4_get_state_owner failed!\n", __FUNCTION__); 620 dprintk("%s: nfs4_get_state_owner failed!\n", __FUNCTION__);
565 goto out_err; 621 goto out_err;
566 } 622 }
567 down(&sp->so_sema);
568 state = nfs4_get_open_state(inode, sp); 623 state = nfs4_get_open_state(inode, sp);
569 if (state == NULL) 624 if (state == NULL)
570 goto out_err; 625 goto out_err;
@@ -589,7 +644,6 @@ static int _nfs4_open_delegated(struct inode *inode, int flags, struct rpc_cred
589 set_bit(NFS_DELEGATED_STATE, &state->flags); 644 set_bit(NFS_DELEGATED_STATE, &state->flags);
590 update_open_stateid(state, &delegation->stateid, open_flags); 645 update_open_stateid(state, &delegation->stateid, open_flags);
591out_ok: 646out_ok:
592 up(&sp->so_sema);
593 nfs4_put_state_owner(sp); 647 nfs4_put_state_owner(sp);
594 up_read(&nfsi->rwsem); 648 up_read(&nfsi->rwsem);
595 up_read(&clp->cl_sem); 649 up_read(&clp->cl_sem);
@@ -600,11 +654,12 @@ out_err:
600 if (sp != NULL) { 654 if (sp != NULL) {
601 if (state != NULL) 655 if (state != NULL)
602 nfs4_put_open_state(state); 656 nfs4_put_open_state(state);
603 up(&sp->so_sema);
604 nfs4_put_state_owner(sp); 657 nfs4_put_state_owner(sp);
605 } 658 }
606 up_read(&nfsi->rwsem); 659 up_read(&nfsi->rwsem);
607 up_read(&clp->cl_sem); 660 up_read(&clp->cl_sem);
661 if (err != -EACCES)
662 nfs_inode_return_delegation(inode);
608 return err; 663 return err;
609} 664}
610 665
@@ -665,8 +720,10 @@ static int _nfs4_do_open(struct inode *dir, struct dentry *dentry, int flags, st
665 } else 720 } else
666 o_arg.u.attrs = sattr; 721 o_arg.u.attrs = sattr;
667 /* Serialization for the sequence id */ 722 /* Serialization for the sequence id */
668 down(&sp->so_sema);
669 723
724 o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid);
725 if (o_arg.seqid == NULL)
726 return -ENOMEM;
670 status = _nfs4_proc_open(dir, sp, &o_arg, &o_res); 727 status = _nfs4_proc_open(dir, sp, &o_arg, &o_res);
671 if (status != 0) 728 if (status != 0)
672 goto out_err; 729 goto out_err;
@@ -681,7 +738,7 @@ static int _nfs4_do_open(struct inode *dir, struct dentry *dentry, int flags, st
681 update_open_stateid(state, &o_res.stateid, flags); 738 update_open_stateid(state, &o_res.stateid, flags);
682 if (o_res.delegation_type != 0) 739 if (o_res.delegation_type != 0)
683 nfs_inode_set_delegation(inode, cred, &o_res); 740 nfs_inode_set_delegation(inode, cred, &o_res);
684 up(&sp->so_sema); 741 nfs_free_seqid(o_arg.seqid);
685 nfs4_put_state_owner(sp); 742 nfs4_put_state_owner(sp);
686 up_read(&clp->cl_sem); 743 up_read(&clp->cl_sem);
687 *res = state; 744 *res = state;
@@ -690,7 +747,7 @@ out_err:
690 if (sp != NULL) { 747 if (sp != NULL) {
691 if (state != NULL) 748 if (state != NULL)
692 nfs4_put_open_state(state); 749 nfs4_put_open_state(state);
693 up(&sp->so_sema); 750 nfs_free_seqid(o_arg.seqid);
694 nfs4_put_state_owner(sp); 751 nfs4_put_state_owner(sp);
695 } 752 }
696 /* Note: clp->cl_sem must be released before nfs4_put_open_state()! */ 753 /* Note: clp->cl_sem must be released before nfs4_put_open_state()! */
@@ -718,7 +775,7 @@ static struct nfs4_state *nfs4_do_open(struct inode *dir, struct dentry *dentry,
718 * It is actually a sign of a bug on the client or on the server. 775 * It is actually a sign of a bug on the client or on the server.
719 * 776 *
720 * If we receive a BAD_SEQID error in the particular case of 777 * If we receive a BAD_SEQID error in the particular case of
721 * doing an OPEN, we assume that nfs4_increment_seqid() will 778 * doing an OPEN, we assume that nfs_increment_open_seqid() will
722 * have unhashed the old state_owner for us, and that we can 779 * have unhashed the old state_owner for us, and that we can
723 * therefore safely retry using a new one. We should still warn 780 * therefore safely retry using a new one. We should still warn
724 * the user though... 781 * the user though...
@@ -728,6 +785,16 @@ static struct nfs4_state *nfs4_do_open(struct inode *dir, struct dentry *dentry,
728 exception.retry = 1; 785 exception.retry = 1;
729 continue; 786 continue;
730 } 787 }
788 /*
789 * BAD_STATEID on OPEN means that the server cancelled our
790 * state before it received the OPEN_CONFIRM.
791 * Recover by retrying the request as per the discussion
792 * on Page 181 of RFC3530.
793 */
794 if (status == -NFS4ERR_BAD_STATEID) {
795 exception.retry = 1;
796 continue;
797 }
731 res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), 798 res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir),
732 status, &exception)); 799 status, &exception));
733 } while (exception.retry); 800 } while (exception.retry);
@@ -789,17 +856,27 @@ struct nfs4_closedata {
789 struct nfs_closeres res; 856 struct nfs_closeres res;
790}; 857};
791 858
859static void nfs4_free_closedata(struct nfs4_closedata *calldata)
860{
861 struct nfs4_state *state = calldata->state;
862 struct nfs4_state_owner *sp = state->owner;
863
864 nfs4_put_open_state(calldata->state);
865 nfs_free_seqid(calldata->arg.seqid);
866 nfs4_put_state_owner(sp);
867 kfree(calldata);
868}
869
792static void nfs4_close_done(struct rpc_task *task) 870static void nfs4_close_done(struct rpc_task *task)
793{ 871{
794 struct nfs4_closedata *calldata = (struct nfs4_closedata *)task->tk_calldata; 872 struct nfs4_closedata *calldata = (struct nfs4_closedata *)task->tk_calldata;
795 struct nfs4_state *state = calldata->state; 873 struct nfs4_state *state = calldata->state;
796 struct nfs4_state_owner *sp = state->owner;
797 struct nfs_server *server = NFS_SERVER(calldata->inode); 874 struct nfs_server *server = NFS_SERVER(calldata->inode);
798 875
799 /* hmm. we are done with the inode, and in the process of freeing 876 /* hmm. we are done with the inode, and in the process of freeing
800 * the state_owner. we keep this around to process errors 877 * the state_owner. we keep this around to process errors
801 */ 878 */
802 nfs4_increment_seqid(task->tk_status, sp); 879 nfs_increment_open_seqid(task->tk_status, calldata->arg.seqid);
803 switch (task->tk_status) { 880 switch (task->tk_status) {
804 case 0: 881 case 0:
805 memcpy(&state->stateid, &calldata->res.stateid, 882 memcpy(&state->stateid, &calldata->res.stateid,
@@ -817,24 +894,46 @@ static void nfs4_close_done(struct rpc_task *task)
817 } 894 }
818 } 895 }
819 state->state = calldata->arg.open_flags; 896 state->state = calldata->arg.open_flags;
820 nfs4_put_open_state(state); 897 nfs4_free_closedata(calldata);
821 up(&sp->so_sema);
822 nfs4_put_state_owner(sp);
823 up_read(&server->nfs4_state->cl_sem);
824 kfree(calldata);
825} 898}
826 899
827static inline int nfs4_close_call(struct rpc_clnt *clnt, struct nfs4_closedata *calldata) 900static void nfs4_close_begin(struct rpc_task *task)
828{ 901{
902 struct nfs4_closedata *calldata = (struct nfs4_closedata *)task->tk_calldata;
903 struct nfs4_state *state = calldata->state;
829 struct rpc_message msg = { 904 struct rpc_message msg = {
830 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], 905 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE],
831 .rpc_argp = &calldata->arg, 906 .rpc_argp = &calldata->arg,
832 .rpc_resp = &calldata->res, 907 .rpc_resp = &calldata->res,
833 .rpc_cred = calldata->state->owner->so_cred, 908 .rpc_cred = state->owner->so_cred,
834 }; 909 };
835 if (calldata->arg.open_flags != 0) 910 int mode = 0;
911 int status;
912
913 status = nfs_wait_on_sequence(calldata->arg.seqid, task);
914 if (status != 0)
915 return;
916 /* Don't reorder reads */
917 smp_rmb();
918 /* Recalculate the new open mode in case someone reopened the file
919 * while we were waiting in line to be scheduled.
920 */
921 if (state->nreaders != 0)
922 mode |= FMODE_READ;
923 if (state->nwriters != 0)
924 mode |= FMODE_WRITE;
925 if (test_bit(NFS_DELEGATED_STATE, &state->flags))
926 state->state = mode;
927 if (mode == state->state) {
928 nfs4_free_closedata(calldata);
929 task->tk_exit = NULL;
930 rpc_exit(task, 0);
931 return;
932 }
933 if (mode != 0)
836 msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; 934 msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE];
837 return rpc_call_async(clnt, &msg, 0, nfs4_close_done, calldata); 935 calldata->arg.open_flags = mode;
936 rpc_call_setup(task, &msg, 0);
838} 937}
839 938
840/* 939/*
@@ -851,39 +950,52 @@ static inline int nfs4_close_call(struct rpc_clnt *clnt, struct nfs4_closedata *
851int nfs4_do_close(struct inode *inode, struct nfs4_state *state, mode_t mode) 950int nfs4_do_close(struct inode *inode, struct nfs4_state *state, mode_t mode)
852{ 951{
853 struct nfs4_closedata *calldata; 952 struct nfs4_closedata *calldata;
854 int status; 953 int status = -ENOMEM;
855 954
856 /* Tell caller we're done */ 955 calldata = kmalloc(sizeof(*calldata), GFP_KERNEL);
857 if (test_bit(NFS_DELEGATED_STATE, &state->flags)) {
858 state->state = mode;
859 return 0;
860 }
861 calldata = (struct nfs4_closedata *)kmalloc(sizeof(*calldata), GFP_KERNEL);
862 if (calldata == NULL) 956 if (calldata == NULL)
863 return -ENOMEM; 957 goto out;
864 calldata->inode = inode; 958 calldata->inode = inode;
865 calldata->state = state; 959 calldata->state = state;
866 calldata->arg.fh = NFS_FH(inode); 960 calldata->arg.fh = NFS_FH(inode);
961 calldata->arg.stateid = &state->stateid;
867 /* Serialization for the sequence id */ 962 /* Serialization for the sequence id */
868 calldata->arg.seqid = state->owner->so_seqid; 963 calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid);
869 calldata->arg.open_flags = mode; 964 if (calldata->arg.seqid == NULL)
870 memcpy(&calldata->arg.stateid, &state->stateid, 965 goto out_free_calldata;
871 sizeof(calldata->arg.stateid)); 966
872 status = nfs4_close_call(NFS_SERVER(inode)->client, calldata); 967 status = nfs4_call_async(NFS_SERVER(inode)->client, nfs4_close_begin,
873 /* 968 nfs4_close_done, calldata);
874 * Return -EINPROGRESS on success in order to indicate to the 969 if (status == 0)
875 * caller that an asynchronous RPC call has been launched, and 970 goto out;
876 * that it will release the semaphores on completion. 971
877 */ 972 nfs_free_seqid(calldata->arg.seqid);
878 return (status == 0) ? -EINPROGRESS : status; 973out_free_calldata:
974 kfree(calldata);
975out:
976 return status;
977}
978
979static void nfs4_intent_set_file(struct nameidata *nd, struct dentry *dentry, struct nfs4_state *state)
980{
981 struct file *filp;
982
983 filp = lookup_instantiate_filp(nd, dentry, NULL);
984 if (!IS_ERR(filp)) {
985 struct nfs_open_context *ctx;
986 ctx = (struct nfs_open_context *)filp->private_data;
987 ctx->state = state;
988 } else
989 nfs4_close_state(state, nd->intent.open.flags);
879} 990}
880 991
881struct inode * 992struct dentry *
882nfs4_atomic_open(struct inode *dir, struct dentry *dentry, struct nameidata *nd) 993nfs4_atomic_open(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
883{ 994{
884 struct iattr attr; 995 struct iattr attr;
885 struct rpc_cred *cred; 996 struct rpc_cred *cred;
886 struct nfs4_state *state; 997 struct nfs4_state *state;
998 struct dentry *res;
887 999
888 if (nd->flags & LOOKUP_CREATE) { 1000 if (nd->flags & LOOKUP_CREATE) {
889 attr.ia_mode = nd->intent.open.create_mode; 1001 attr.ia_mode = nd->intent.open.create_mode;
@@ -897,16 +1009,23 @@ nfs4_atomic_open(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
897 1009
898 cred = rpcauth_lookupcred(NFS_SERVER(dir)->client->cl_auth, 0); 1010 cred = rpcauth_lookupcred(NFS_SERVER(dir)->client->cl_auth, 0);
899 if (IS_ERR(cred)) 1011 if (IS_ERR(cred))
900 return (struct inode *)cred; 1012 return (struct dentry *)cred;
901 state = nfs4_do_open(dir, dentry, nd->intent.open.flags, &attr, cred); 1013 state = nfs4_do_open(dir, dentry, nd->intent.open.flags, &attr, cred);
902 put_rpccred(cred); 1014 put_rpccred(cred);
903 if (IS_ERR(state)) 1015 if (IS_ERR(state)) {
904 return (struct inode *)state; 1016 if (PTR_ERR(state) == -ENOENT)
905 return state->inode; 1017 d_add(dentry, NULL);
1018 return (struct dentry *)state;
1019 }
1020 res = d_add_unique(dentry, state->inode);
1021 if (res != NULL)
1022 dentry = res;
1023 nfs4_intent_set_file(nd, dentry, state);
1024 return res;
906} 1025}
907 1026
908int 1027int
909nfs4_open_revalidate(struct inode *dir, struct dentry *dentry, int openflags) 1028nfs4_open_revalidate(struct inode *dir, struct dentry *dentry, int openflags, struct nameidata *nd)
910{ 1029{
911 struct rpc_cred *cred; 1030 struct rpc_cred *cred;
912 struct nfs4_state *state; 1031 struct nfs4_state *state;
@@ -919,18 +1038,30 @@ nfs4_open_revalidate(struct inode *dir, struct dentry *dentry, int openflags)
919 if (IS_ERR(state)) 1038 if (IS_ERR(state))
920 state = nfs4_do_open(dir, dentry, openflags, NULL, cred); 1039 state = nfs4_do_open(dir, dentry, openflags, NULL, cred);
921 put_rpccred(cred); 1040 put_rpccred(cred);
922 if (state == ERR_PTR(-ENOENT) && dentry->d_inode == 0) 1041 if (IS_ERR(state)) {
923 return 1; 1042 switch (PTR_ERR(state)) {
924 if (IS_ERR(state)) 1043 case -EPERM:
925 return 0; 1044 case -EACCES:
1045 case -EDQUOT:
1046 case -ENOSPC:
1047 case -EROFS:
1048 lookup_instantiate_filp(nd, (struct dentry *)state, NULL);
1049 return 1;
1050 case -ENOENT:
1051 if (dentry->d_inode == NULL)
1052 return 1;
1053 }
1054 goto out_drop;
1055 }
926 inode = state->inode; 1056 inode = state->inode;
1057 iput(inode);
927 if (inode == dentry->d_inode) { 1058 if (inode == dentry->d_inode) {
928 iput(inode); 1059 nfs4_intent_set_file(nd, dentry, state);
929 return 1; 1060 return 1;
930 } 1061 }
931 d_drop(dentry);
932 nfs4_close_state(state, openflags); 1062 nfs4_close_state(state, openflags);
933 iput(inode); 1063out_drop:
1064 d_drop(dentry);
934 return 0; 1065 return 0;
935} 1066}
936 1067
@@ -1431,7 +1562,7 @@ static int nfs4_proc_commit(struct nfs_write_data *cdata)
1431 1562
1432static int 1563static int
1433nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, 1564nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
1434 int flags) 1565 int flags, struct nameidata *nd)
1435{ 1566{
1436 struct nfs4_state *state; 1567 struct nfs4_state *state;
1437 struct rpc_cred *cred; 1568 struct rpc_cred *cred;
@@ -1453,13 +1584,13 @@ nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
1453 struct nfs_fattr fattr; 1584 struct nfs_fattr fattr;
1454 status = nfs4_do_setattr(NFS_SERVER(dir), &fattr, 1585 status = nfs4_do_setattr(NFS_SERVER(dir), &fattr,
1455 NFS_FH(state->inode), sattr, state); 1586 NFS_FH(state->inode), sattr, state);
1456 if (status == 0) { 1587 if (status == 0)
1457 nfs_setattr_update_inode(state->inode, sattr); 1588 nfs_setattr_update_inode(state->inode, sattr);
1458 goto out; 1589 }
1459 } 1590 if (status == 0 && nd != NULL && (nd->flags & LOOKUP_OPEN))
1460 } else if (flags != 0) 1591 nfs4_intent_set_file(nd, dentry, state);
1461 goto out; 1592 else
1462 nfs4_close_state(state, flags); 1593 nfs4_close_state(state, flags);
1463out: 1594out:
1464 return status; 1595 return status;
1465} 1596}
@@ -2106,65 +2237,6 @@ nfs4_proc_renew(struct nfs4_client *clp)
2106 return 0; 2237 return 0;
2107} 2238}
2108 2239
2109/*
2110 * We will need to arrange for the VFS layer to provide an atomic open.
2111 * Until then, this open method is prone to inefficiency and race conditions
2112 * due to the lookup, potential create, and open VFS calls from sys_open()
2113 * placed on the wire.
2114 */
2115static int
2116nfs4_proc_file_open(struct inode *inode, struct file *filp)
2117{
2118 struct dentry *dentry = filp->f_dentry;
2119 struct nfs_open_context *ctx;
2120 struct nfs4_state *state = NULL;
2121 struct rpc_cred *cred;
2122 int status = -ENOMEM;
2123
2124 dprintk("nfs4_proc_file_open: starting on (%.*s/%.*s)\n",
2125 (int)dentry->d_parent->d_name.len,
2126 dentry->d_parent->d_name.name,
2127 (int)dentry->d_name.len, dentry->d_name.name);
2128
2129
2130 /* Find our open stateid */
2131 cred = rpcauth_lookupcred(NFS_SERVER(inode)->client->cl_auth, 0);
2132 if (IS_ERR(cred))
2133 return PTR_ERR(cred);
2134 ctx = alloc_nfs_open_context(dentry, cred);
2135 put_rpccred(cred);
2136 if (unlikely(ctx == NULL))
2137 return -ENOMEM;
2138 status = -EIO; /* ERACE actually */
2139 state = nfs4_find_state(inode, cred, filp->f_mode);
2140 if (unlikely(state == NULL))
2141 goto no_state;
2142 ctx->state = state;
2143 nfs4_close_state(state, filp->f_mode);
2144 ctx->mode = filp->f_mode;
2145 nfs_file_set_open_context(filp, ctx);
2146 put_nfs_open_context(ctx);
2147 if (filp->f_mode & FMODE_WRITE)
2148 nfs_begin_data_update(inode);
2149 return 0;
2150no_state:
2151 printk(KERN_WARNING "NFS: v4 raced in function %s\n", __FUNCTION__);
2152 put_nfs_open_context(ctx);
2153 return status;
2154}
2155
2156/*
2157 * Release our state
2158 */
2159static int
2160nfs4_proc_file_release(struct inode *inode, struct file *filp)
2161{
2162 if (filp->f_mode & FMODE_WRITE)
2163 nfs_end_data_update(inode);
2164 nfs_file_clear_open_context(filp);
2165 return 0;
2166}
2167
2168static inline int nfs4_server_supports_acls(struct nfs_server *server) 2240static inline int nfs4_server_supports_acls(struct nfs_server *server)
2169{ 2241{
2170 return (server->caps & NFS_CAP_ACLS) 2242 return (server->caps & NFS_CAP_ACLS)
@@ -2345,6 +2417,7 @@ static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen
2345 2417
2346 if (!nfs4_server_supports_acls(server)) 2418 if (!nfs4_server_supports_acls(server))
2347 return -EOPNOTSUPP; 2419 return -EOPNOTSUPP;
2420 nfs_inode_return_delegation(inode);
2348 buf_to_pages(buf, buflen, arg.acl_pages, &arg.acl_pgbase); 2421 buf_to_pages(buf, buflen, arg.acl_pages, &arg.acl_pgbase);
2349 ret = rpc_call_sync(NFS_SERVER(inode)->client, &msg, 0); 2422 ret = rpc_call_sync(NFS_SERVER(inode)->client, &msg, 0);
2350 if (ret == 0) 2423 if (ret == 0)
@@ -2353,7 +2426,7 @@ static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen
2353} 2426}
2354 2427
2355static int 2428static int
2356nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server) 2429nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server)
2357{ 2430{
2358 struct nfs4_client *clp = server->nfs4_state; 2431 struct nfs4_client *clp = server->nfs4_state;
2359 2432
@@ -2431,7 +2504,7 @@ static int nfs4_delay(struct rpc_clnt *clnt, long *timeout)
2431/* This is the error handling routine for processes that are allowed 2504/* This is the error handling routine for processes that are allowed
2432 * to sleep. 2505 * to sleep.
2433 */ 2506 */
2434int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) 2507int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct nfs4_exception *exception)
2435{ 2508{
2436 struct nfs4_client *clp = server->nfs4_state; 2509 struct nfs4_client *clp = server->nfs4_state;
2437 int ret = errorcode; 2510 int ret = errorcode;
@@ -2632,7 +2705,6 @@ static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock
2632 2705
2633 down_read(&clp->cl_sem); 2706 down_read(&clp->cl_sem);
2634 nlo.clientid = clp->cl_clientid; 2707 nlo.clientid = clp->cl_clientid;
2635 down(&state->lock_sema);
2636 status = nfs4_set_lock_state(state, request); 2708 status = nfs4_set_lock_state(state, request);
2637 if (status != 0) 2709 if (status != 0)
2638 goto out; 2710 goto out;
@@ -2659,7 +2731,6 @@ static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock
2659 status = 0; 2731 status = 0;
2660 } 2732 }
2661out: 2733out:
2662 up(&state->lock_sema);
2663 up_read(&clp->cl_sem); 2734 up_read(&clp->cl_sem);
2664 return status; 2735 return status;
2665} 2736}
@@ -2696,79 +2767,149 @@ static int do_vfs_lock(struct file *file, struct file_lock *fl)
2696 return res; 2767 return res;
2697} 2768}
2698 2769
2699static int _nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) 2770struct nfs4_unlockdata {
2771 struct nfs_lockargs arg;
2772 struct nfs_locku_opargs luargs;
2773 struct nfs_lockres res;
2774 struct nfs4_lock_state *lsp;
2775 struct nfs_open_context *ctx;
2776 atomic_t refcount;
2777 struct completion completion;
2778};
2779
2780static void nfs4_locku_release_calldata(struct nfs4_unlockdata *calldata)
2700{ 2781{
2701 struct inode *inode = state->inode; 2782 if (atomic_dec_and_test(&calldata->refcount)) {
2702 struct nfs_server *server = NFS_SERVER(inode); 2783 nfs_free_seqid(calldata->luargs.seqid);
2703 struct nfs4_client *clp = server->nfs4_state; 2784 nfs4_put_lock_state(calldata->lsp);
2704 struct nfs_lockargs arg = { 2785 put_nfs_open_context(calldata->ctx);
2705 .fh = NFS_FH(inode), 2786 kfree(calldata);
2706 .type = nfs4_lck_type(cmd, request), 2787 }
2707 .offset = request->fl_start, 2788}
2708 .length = nfs4_lck_length(request), 2789
2709 }; 2790static void nfs4_locku_complete(struct nfs4_unlockdata *calldata)
2710 struct nfs_lockres res = { 2791{
2711 .server = server, 2792 complete(&calldata->completion);
2712 }; 2793 nfs4_locku_release_calldata(calldata);
2794}
2795
2796static void nfs4_locku_done(struct rpc_task *task)
2797{
2798 struct nfs4_unlockdata *calldata = (struct nfs4_unlockdata *)task->tk_calldata;
2799
2800 nfs_increment_lock_seqid(task->tk_status, calldata->luargs.seqid);
2801 switch (task->tk_status) {
2802 case 0:
2803 memcpy(calldata->lsp->ls_stateid.data,
2804 calldata->res.u.stateid.data,
2805 sizeof(calldata->lsp->ls_stateid.data));
2806 break;
2807 case -NFS4ERR_STALE_STATEID:
2808 case -NFS4ERR_EXPIRED:
2809 nfs4_schedule_state_recovery(calldata->res.server->nfs4_state);
2810 break;
2811 default:
2812 if (nfs4_async_handle_error(task, calldata->res.server) == -EAGAIN) {
2813 rpc_restart_call(task);
2814 return;
2815 }
2816 }
2817 nfs4_locku_complete(calldata);
2818}
2819
2820static void nfs4_locku_begin(struct rpc_task *task)
2821{
2822 struct nfs4_unlockdata *calldata = (struct nfs4_unlockdata *)task->tk_calldata;
2713 struct rpc_message msg = { 2823 struct rpc_message msg = {
2714 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], 2824 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU],
2715 .rpc_argp = &arg, 2825 .rpc_argp = &calldata->arg,
2716 .rpc_resp = &res, 2826 .rpc_resp = &calldata->res,
2717 .rpc_cred = state->owner->so_cred, 2827 .rpc_cred = calldata->lsp->ls_state->owner->so_cred,
2718 }; 2828 };
2829 int status;
2830
2831 status = nfs_wait_on_sequence(calldata->luargs.seqid, task);
2832 if (status != 0)
2833 return;
2834 if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) {
2835 nfs4_locku_complete(calldata);
2836 task->tk_exit = NULL;
2837 rpc_exit(task, 0);
2838 return;
2839 }
2840 rpc_call_setup(task, &msg, 0);
2841}
2842
2843static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request)
2844{
2845 struct nfs4_unlockdata *calldata;
2846 struct inode *inode = state->inode;
2847 struct nfs_server *server = NFS_SERVER(inode);
2719 struct nfs4_lock_state *lsp; 2848 struct nfs4_lock_state *lsp;
2720 struct nfs_locku_opargs luargs;
2721 int status; 2849 int status;
2722 2850
2723 down_read(&clp->cl_sem);
2724 down(&state->lock_sema);
2725 status = nfs4_set_lock_state(state, request); 2851 status = nfs4_set_lock_state(state, request);
2726 if (status != 0) 2852 if (status != 0)
2727 goto out; 2853 return status;
2728 lsp = request->fl_u.nfs4_fl.owner; 2854 lsp = request->fl_u.nfs4_fl.owner;
2729 /* We might have lost the locks! */ 2855 /* We might have lost the locks! */
2730 if ((lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) 2856 if ((lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0)
2731 goto out; 2857 return 0;
2732 luargs.seqid = lsp->ls_seqid; 2858 calldata = kmalloc(sizeof(*calldata), GFP_KERNEL);
2733 memcpy(&luargs.stateid, &lsp->ls_stateid, sizeof(luargs.stateid)); 2859 if (calldata == NULL)
2734 arg.u.locku = &luargs; 2860 return -ENOMEM;
2735 status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR); 2861 calldata->luargs.seqid = nfs_alloc_seqid(&lsp->ls_seqid);
2736 nfs4_increment_lock_seqid(status, lsp); 2862 if (calldata->luargs.seqid == NULL) {
2737 2863 kfree(calldata);
2738 if (status == 0) 2864 return -ENOMEM;
2739 memcpy(&lsp->ls_stateid, &res.u.stateid, 2865 }
2740 sizeof(lsp->ls_stateid)); 2866 calldata->luargs.stateid = &lsp->ls_stateid;
2741out: 2867 calldata->arg.fh = NFS_FH(inode);
2742 up(&state->lock_sema); 2868 calldata->arg.type = nfs4_lck_type(cmd, request);
2869 calldata->arg.offset = request->fl_start;
2870 calldata->arg.length = nfs4_lck_length(request);
2871 calldata->arg.u.locku = &calldata->luargs;
2872 calldata->res.server = server;
2873 calldata->lsp = lsp;
2874 atomic_inc(&lsp->ls_count);
2875
2876 /* Ensure we don't close file until we're done freeing locks! */
2877 calldata->ctx = get_nfs_open_context((struct nfs_open_context*)request->fl_file->private_data);
2878
2879 atomic_set(&calldata->refcount, 2);
2880 init_completion(&calldata->completion);
2881
2882 status = nfs4_call_async(NFS_SERVER(inode)->client, nfs4_locku_begin,
2883 nfs4_locku_done, calldata);
2743 if (status == 0) 2884 if (status == 0)
2744 do_vfs_lock(request->fl_file, request); 2885 wait_for_completion_interruptible(&calldata->completion);
2745 up_read(&clp->cl_sem); 2886 do_vfs_lock(request->fl_file, request);
2887 nfs4_locku_release_calldata(calldata);
2746 return status; 2888 return status;
2747} 2889}
2748 2890
2749static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request)
2750{
2751 struct nfs4_exception exception = { };
2752 int err;
2753
2754 do {
2755 err = nfs4_handle_exception(NFS_SERVER(state->inode),
2756 _nfs4_proc_unlck(state, cmd, request),
2757 &exception);
2758 } while (exception.retry);
2759 return err;
2760}
2761
2762static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *request, int reclaim) 2891static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *request, int reclaim)
2763{ 2892{
2764 struct inode *inode = state->inode; 2893 struct inode *inode = state->inode;
2765 struct nfs_server *server = NFS_SERVER(inode); 2894 struct nfs_server *server = NFS_SERVER(inode);
2766 struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; 2895 struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner;
2896 struct nfs_lock_opargs largs = {
2897 .lock_stateid = &lsp->ls_stateid,
2898 .open_stateid = &state->stateid,
2899 .lock_owner = {
2900 .clientid = server->nfs4_state->cl_clientid,
2901 .id = lsp->ls_id,
2902 },
2903 .reclaim = reclaim,
2904 };
2767 struct nfs_lockargs arg = { 2905 struct nfs_lockargs arg = {
2768 .fh = NFS_FH(inode), 2906 .fh = NFS_FH(inode),
2769 .type = nfs4_lck_type(cmd, request), 2907 .type = nfs4_lck_type(cmd, request),
2770 .offset = request->fl_start, 2908 .offset = request->fl_start,
2771 .length = nfs4_lck_length(request), 2909 .length = nfs4_lck_length(request),
2910 .u = {
2911 .lock = &largs,
2912 },
2772 }; 2913 };
2773 struct nfs_lockres res = { 2914 struct nfs_lockres res = {
2774 .server = server, 2915 .server = server,
@@ -2779,53 +2920,39 @@ static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *r
2779 .rpc_resp = &res, 2920 .rpc_resp = &res,
2780 .rpc_cred = state->owner->so_cred, 2921 .rpc_cred = state->owner->so_cred,
2781 }; 2922 };
2782 struct nfs_lock_opargs largs = { 2923 int status = -ENOMEM;
2783 .reclaim = reclaim,
2784 .new_lock_owner = 0,
2785 };
2786 int status;
2787 2924
2788 if (!(lsp->ls_flags & NFS_LOCK_INITIALIZED)) { 2925 largs.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid);
2926 if (largs.lock_seqid == NULL)
2927 return -ENOMEM;
2928 if (!(lsp->ls_seqid.flags & NFS_SEQID_CONFIRMED)) {
2789 struct nfs4_state_owner *owner = state->owner; 2929 struct nfs4_state_owner *owner = state->owner;
2790 struct nfs_open_to_lock otl = { 2930
2791 .lock_owner = { 2931 largs.open_seqid = nfs_alloc_seqid(&owner->so_seqid);
2792 .clientid = server->nfs4_state->cl_clientid, 2932 if (largs.open_seqid == NULL)
2793 }, 2933 goto out;
2794 };
2795
2796 otl.lock_seqid = lsp->ls_seqid;
2797 otl.lock_owner.id = lsp->ls_id;
2798 memcpy(&otl.open_stateid, &state->stateid, sizeof(otl.open_stateid));
2799 largs.u.open_lock = &otl;
2800 largs.new_lock_owner = 1; 2934 largs.new_lock_owner = 1;
2801 arg.u.lock = &largs;
2802 down(&owner->so_sema);
2803 otl.open_seqid = owner->so_seqid;
2804 status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR); 2935 status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
2805 /* increment open_owner seqid on success, and 2936 /* increment open seqid on success, and seqid mutating errors */
2806 * seqid mutating errors */ 2937 if (largs.new_lock_owner != 0) {
2807 nfs4_increment_seqid(status, owner); 2938 nfs_increment_open_seqid(status, largs.open_seqid);
2808 up(&owner->so_sema); 2939 if (status == 0)
2809 if (status == 0) { 2940 nfs_confirm_seqid(&lsp->ls_seqid, 0);
2810 lsp->ls_flags |= NFS_LOCK_INITIALIZED;
2811 lsp->ls_seqid++;
2812 } 2941 }
2813 } else { 2942 nfs_free_seqid(largs.open_seqid);
2814 struct nfs_exist_lock el = { 2943 } else
2815 .seqid = lsp->ls_seqid,
2816 };
2817 memcpy(&el.stateid, &lsp->ls_stateid, sizeof(el.stateid));
2818 largs.u.exist_lock = &el;
2819 arg.u.lock = &largs;
2820 status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR); 2944 status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
2821 /* increment seqid on success, and * seqid mutating errors*/ 2945 /* increment lock seqid on success, and seqid mutating errors*/
2822 nfs4_increment_lock_seqid(status, lsp); 2946 nfs_increment_lock_seqid(status, largs.lock_seqid);
2823 }
2824 /* save the returned stateid. */ 2947 /* save the returned stateid. */
2825 if (status == 0) 2948 if (status == 0) {
2826 memcpy(&lsp->ls_stateid, &res.u.stateid, sizeof(nfs4_stateid)); 2949 memcpy(lsp->ls_stateid.data, res.u.stateid.data,
2827 else if (status == -NFS4ERR_DENIED) 2950 sizeof(lsp->ls_stateid.data));
2951 lsp->ls_flags |= NFS_LOCK_INITIALIZED;
2952 } else if (status == -NFS4ERR_DENIED)
2828 status = -EAGAIN; 2953 status = -EAGAIN;
2954out:
2955 nfs_free_seqid(largs.lock_seqid);
2829 return status; 2956 return status;
2830} 2957}
2831 2958
@@ -2865,11 +2992,9 @@ static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock
2865 int status; 2992 int status;
2866 2993
2867 down_read(&clp->cl_sem); 2994 down_read(&clp->cl_sem);
2868 down(&state->lock_sema);
2869 status = nfs4_set_lock_state(state, request); 2995 status = nfs4_set_lock_state(state, request);
2870 if (status == 0) 2996 if (status == 0)
2871 status = _nfs4_do_setlk(state, cmd, request, 0); 2997 status = _nfs4_do_setlk(state, cmd, request, 0);
2872 up(&state->lock_sema);
2873 if (status == 0) { 2998 if (status == 0) {
2874 /* Note: we always want to sleep here! */ 2999 /* Note: we always want to sleep here! */
2875 request->fl_flags |= FL_SLEEP; 3000 request->fl_flags |= FL_SLEEP;
@@ -3024,8 +3149,8 @@ struct nfs_rpc_ops nfs_v4_clientops = {
3024 .read_setup = nfs4_proc_read_setup, 3149 .read_setup = nfs4_proc_read_setup,
3025 .write_setup = nfs4_proc_write_setup, 3150 .write_setup = nfs4_proc_write_setup,
3026 .commit_setup = nfs4_proc_commit_setup, 3151 .commit_setup = nfs4_proc_commit_setup,
3027 .file_open = nfs4_proc_file_open, 3152 .file_open = nfs_open,
3028 .file_release = nfs4_proc_file_release, 3153 .file_release = nfs_release,
3029 .lock = nfs4_proc_lock, 3154 .lock = nfs4_proc_lock,
3030 .clear_acl_cache = nfs4_zap_acl_attr, 3155 .clear_acl_cache = nfs4_zap_acl_attr,
3031}; 3156};
diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
index afe587d82f..23834c8fb7 100644
--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -264,13 +264,15 @@ nfs4_alloc_state_owner(void)
264{ 264{
265 struct nfs4_state_owner *sp; 265 struct nfs4_state_owner *sp;
266 266
267 sp = kmalloc(sizeof(*sp),GFP_KERNEL); 267 sp = kzalloc(sizeof(*sp),GFP_KERNEL);
268 if (!sp) 268 if (!sp)
269 return NULL; 269 return NULL;
270 init_MUTEX(&sp->so_sema);
271 sp->so_seqid = 0; /* arbitrary */
272 INIT_LIST_HEAD(&sp->so_states); 270 INIT_LIST_HEAD(&sp->so_states);
273 INIT_LIST_HEAD(&sp->so_delegations); 271 INIT_LIST_HEAD(&sp->so_delegations);
272 rpc_init_wait_queue(&sp->so_sequence.wait, "Seqid_waitqueue");
273 sp->so_seqid.sequence = &sp->so_sequence;
274 spin_lock_init(&sp->so_sequence.lock);
275 INIT_LIST_HEAD(&sp->so_sequence.list);
274 atomic_set(&sp->so_count, 1); 276 atomic_set(&sp->so_count, 1);
275 return sp; 277 return sp;
276} 278}
@@ -359,7 +361,6 @@ nfs4_alloc_open_state(void)
359 memset(state->stateid.data, 0, sizeof(state->stateid.data)); 361 memset(state->stateid.data, 0, sizeof(state->stateid.data));
360 atomic_set(&state->count, 1); 362 atomic_set(&state->count, 1);
361 INIT_LIST_HEAD(&state->lock_states); 363 INIT_LIST_HEAD(&state->lock_states);
362 init_MUTEX(&state->lock_sema);
363 spin_lock_init(&state->state_lock); 364 spin_lock_init(&state->state_lock);
364 return state; 365 return state;
365} 366}
@@ -441,7 +442,6 @@ nfs4_get_open_state(struct inode *inode, struct nfs4_state_owner *owner)
441 state = __nfs4_find_state_byowner(inode, owner); 442 state = __nfs4_find_state_byowner(inode, owner);
442 if (state == NULL && new != NULL) { 443 if (state == NULL && new != NULL) {
443 state = new; 444 state = new;
444 /* Caller *must* be holding owner->so_sem */
445 /* Note: The reclaim code dictates that we add stateless 445 /* Note: The reclaim code dictates that we add stateless
446 * and read-only stateids to the end of the list */ 446 * and read-only stateids to the end of the list */
447 list_add_tail(&state->open_states, &owner->so_states); 447 list_add_tail(&state->open_states, &owner->so_states);
@@ -461,7 +461,7 @@ out:
461 461
462/* 462/*
463 * Beware! Caller must be holding exactly one 463 * Beware! Caller must be holding exactly one
464 * reference to clp->cl_sem and owner->so_sema! 464 * reference to clp->cl_sem!
465 */ 465 */
466void nfs4_put_open_state(struct nfs4_state *state) 466void nfs4_put_open_state(struct nfs4_state *state)
467{ 467{
@@ -481,19 +481,15 @@ void nfs4_put_open_state(struct nfs4_state *state)
481} 481}
482 482
483/* 483/*
484 * Beware! Caller must be holding no references to clp->cl_sem! 484 * Close the current file.
485 * of owner->so_sema!
486 */ 485 */
487void nfs4_close_state(struct nfs4_state *state, mode_t mode) 486void nfs4_close_state(struct nfs4_state *state, mode_t mode)
488{ 487{
489 struct inode *inode = state->inode; 488 struct inode *inode = state->inode;
490 struct nfs4_state_owner *owner = state->owner; 489 struct nfs4_state_owner *owner = state->owner;
491 struct nfs4_client *clp = owner->so_client;
492 int newstate; 490 int newstate;
493 491
494 atomic_inc(&owner->so_count); 492 atomic_inc(&owner->so_count);
495 down_read(&clp->cl_sem);
496 down(&owner->so_sema);
497 /* Protect against nfs4_find_state() */ 493 /* Protect against nfs4_find_state() */
498 spin_lock(&inode->i_lock); 494 spin_lock(&inode->i_lock);
499 if (mode & FMODE_READ) 495 if (mode & FMODE_READ)
@@ -515,14 +511,16 @@ void nfs4_close_state(struct nfs4_state *state, mode_t mode)
515 newstate |= FMODE_WRITE; 511 newstate |= FMODE_WRITE;
516 if (state->state == newstate) 512 if (state->state == newstate)
517 goto out; 513 goto out;
518 if (nfs4_do_close(inode, state, newstate) == -EINPROGRESS) 514 if (test_bit(NFS_DELEGATED_STATE, &state->flags)) {
515 state->state = newstate;
516 goto out;
517 }
518 if (nfs4_do_close(inode, state, newstate) == 0)
519 return; 519 return;
520 } 520 }
521out: 521out:
522 nfs4_put_open_state(state); 522 nfs4_put_open_state(state);
523 up(&owner->so_sema);
524 nfs4_put_state_owner(owner); 523 nfs4_put_state_owner(owner);
525 up_read(&clp->cl_sem);
526} 524}
527 525
528/* 526/*
@@ -546,19 +544,16 @@ __nfs4_find_lock_state(struct nfs4_state *state, fl_owner_t fl_owner)
546 * Return a compatible lock_state. If no initialized lock_state structure 544 * Return a compatible lock_state. If no initialized lock_state structure
547 * exists, return an uninitialized one. 545 * exists, return an uninitialized one.
548 * 546 *
549 * The caller must be holding state->lock_sema
550 */ 547 */
551static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, fl_owner_t fl_owner) 548static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, fl_owner_t fl_owner)
552{ 549{
553 struct nfs4_lock_state *lsp; 550 struct nfs4_lock_state *lsp;
554 struct nfs4_client *clp = state->owner->so_client; 551 struct nfs4_client *clp = state->owner->so_client;
555 552
556 lsp = kmalloc(sizeof(*lsp), GFP_KERNEL); 553 lsp = kzalloc(sizeof(*lsp), GFP_KERNEL);
557 if (lsp == NULL) 554 if (lsp == NULL)
558 return NULL; 555 return NULL;
559 lsp->ls_flags = 0; 556 lsp->ls_seqid.sequence = &state->owner->so_sequence;
560 lsp->ls_seqid = 0; /* arbitrary */
561 memset(lsp->ls_stateid.data, 0, sizeof(lsp->ls_stateid.data));
562 atomic_set(&lsp->ls_count, 1); 557 atomic_set(&lsp->ls_count, 1);
563 lsp->ls_owner = fl_owner; 558 lsp->ls_owner = fl_owner;
564 spin_lock(&clp->cl_lock); 559 spin_lock(&clp->cl_lock);
@@ -572,7 +567,7 @@ static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, f
572 * Return a compatible lock_state. If no initialized lock_state structure 567 * Return a compatible lock_state. If no initialized lock_state structure
573 * exists, return an uninitialized one. 568 * exists, return an uninitialized one.
574 * 569 *
575 * The caller must be holding state->lock_sema and clp->cl_sem 570 * The caller must be holding clp->cl_sem
576 */ 571 */
577static struct nfs4_lock_state *nfs4_get_lock_state(struct nfs4_state *state, fl_owner_t owner) 572static struct nfs4_lock_state *nfs4_get_lock_state(struct nfs4_state *state, fl_owner_t owner)
578{ 573{
@@ -605,7 +600,7 @@ static struct nfs4_lock_state *nfs4_get_lock_state(struct nfs4_state *state, fl_
605 * Release reference to lock_state, and free it if we see that 600 * Release reference to lock_state, and free it if we see that
606 * it is no longer in use 601 * it is no longer in use
607 */ 602 */
608static void nfs4_put_lock_state(struct nfs4_lock_state *lsp) 603void nfs4_put_lock_state(struct nfs4_lock_state *lsp)
609{ 604{
610 struct nfs4_state *state; 605 struct nfs4_state *state;
611 606
@@ -673,29 +668,98 @@ void nfs4_copy_stateid(nfs4_stateid *dst, struct nfs4_state *state, fl_owner_t f
673 nfs4_put_lock_state(lsp); 668 nfs4_put_lock_state(lsp);
674} 669}
675 670
676/* 671struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter)
677* Called with state->lock_sema and clp->cl_sem held. 672{
678*/ 673 struct rpc_sequence *sequence = counter->sequence;
679void nfs4_increment_lock_seqid(int status, struct nfs4_lock_state *lsp) 674 struct nfs_seqid *new;
675
676 new = kmalloc(sizeof(*new), GFP_KERNEL);
677 if (new != NULL) {
678 new->sequence = counter;
679 new->task = NULL;
680 spin_lock(&sequence->lock);
681 list_add_tail(&new->list, &sequence->list);
682 spin_unlock(&sequence->lock);
683 }
684 return new;
685}
686
687void nfs_free_seqid(struct nfs_seqid *seqid)
680{ 688{
681 if (status == NFS_OK || seqid_mutating_err(-status)) 689 struct rpc_sequence *sequence = seqid->sequence->sequence;
682 lsp->ls_seqid++; 690 struct rpc_task *next = NULL;
691
692 spin_lock(&sequence->lock);
693 list_del(&seqid->list);
694 if (!list_empty(&sequence->list)) {
695 next = list_entry(sequence->list.next, struct nfs_seqid, list)->task;
696 if (next)
697 rpc_wake_up_task(next);
698 }
699 spin_unlock(&sequence->lock);
700 kfree(seqid);
683} 701}
684 702
685/* 703/*
686* Called with sp->so_sema and clp->cl_sem held. 704 * Increment the seqid if the OPEN/OPEN_DOWNGRADE/CLOSE succeeded, or
687* 705 * failed with a seqid incrementing error -
688* Increment the seqid if the OPEN/OPEN_DOWNGRADE/CLOSE succeeded, or 706 * see comments nfs_fs.h:seqid_mutating_error()
689* failed with a seqid incrementing error - 707 */
690* see comments nfs_fs.h:seqid_mutating_error() 708static inline void nfs_increment_seqid(int status, struct nfs_seqid *seqid)
691*/ 709{
692void nfs4_increment_seqid(int status, struct nfs4_state_owner *sp) 710 switch (status) {
693{ 711 case 0:
694 if (status == NFS_OK || seqid_mutating_err(-status)) 712 break;
695 sp->so_seqid++; 713 case -NFS4ERR_BAD_SEQID:
696 /* If the server returns BAD_SEQID, unhash state_owner here */ 714 case -NFS4ERR_STALE_CLIENTID:
697 if (status == -NFS4ERR_BAD_SEQID) 715 case -NFS4ERR_STALE_STATEID:
716 case -NFS4ERR_BAD_STATEID:
717 case -NFS4ERR_BADXDR:
718 case -NFS4ERR_RESOURCE:
719 case -NFS4ERR_NOFILEHANDLE:
720 /* Non-seqid mutating errors */
721 return;
722 };
723 /*
724 * Note: no locking needed as we are guaranteed to be first
725 * on the sequence list
726 */
727 seqid->sequence->counter++;
728}
729
730void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid)
731{
732 if (status == -NFS4ERR_BAD_SEQID) {
733 struct nfs4_state_owner *sp = container_of(seqid->sequence,
734 struct nfs4_state_owner, so_seqid);
698 nfs4_drop_state_owner(sp); 735 nfs4_drop_state_owner(sp);
736 }
737 return nfs_increment_seqid(status, seqid);
738}
739
740/*
741 * Increment the seqid if the LOCK/LOCKU succeeded, or
742 * failed with a seqid incrementing error -
743 * see comments nfs_fs.h:seqid_mutating_error()
744 */
745void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid)
746{
747 return nfs_increment_seqid(status, seqid);
748}
749
750int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task)
751{
752 struct rpc_sequence *sequence = seqid->sequence->sequence;
753 int status = 0;
754
755 spin_lock(&sequence->lock);
756 if (sequence->list.next != &seqid->list) {
757 seqid->task = task;
758 rpc_sleep_on(&sequence->wait, task, NULL, NULL);
759 status = -EAGAIN;
760 }
761 spin_unlock(&sequence->lock);
762 return status;
699} 763}
700 764
701static int reclaimer(void *); 765static int reclaimer(void *);
@@ -791,8 +855,6 @@ static int nfs4_reclaim_open_state(struct nfs4_state_recovery_ops *ops, struct n
791 if (state->state == 0) 855 if (state->state == 0)
792 continue; 856 continue;
793 status = ops->recover_open(sp, state); 857 status = ops->recover_open(sp, state);
794 list_for_each_entry(lock, &state->lock_states, ls_locks)
795 lock->ls_flags &= ~NFS_LOCK_INITIALIZED;
796 if (status >= 0) { 858 if (status >= 0) {
797 status = nfs4_reclaim_locks(ops, state); 859 status = nfs4_reclaim_locks(ops, state);
798 if (status < 0) 860 if (status < 0)
@@ -831,6 +893,26 @@ out_err:
831 return status; 893 return status;
832} 894}
833 895
896static void nfs4_state_mark_reclaim(struct nfs4_client *clp)
897{
898 struct nfs4_state_owner *sp;
899 struct nfs4_state *state;
900 struct nfs4_lock_state *lock;
901
902 /* Reset all sequence ids to zero */
903 list_for_each_entry(sp, &clp->cl_state_owners, so_list) {
904 sp->so_seqid.counter = 0;
905 sp->so_seqid.flags = 0;
906 list_for_each_entry(state, &sp->so_states, open_states) {
907 list_for_each_entry(lock, &state->lock_states, ls_locks) {
908 lock->ls_seqid.counter = 0;
909 lock->ls_seqid.flags = 0;
910 lock->ls_flags &= ~NFS_LOCK_INITIALIZED;
911 }
912 }
913 }
914}
915
834static int reclaimer(void *ptr) 916static int reclaimer(void *ptr)
835{ 917{
836 struct reclaimer_args *args = (struct reclaimer_args *)ptr; 918 struct reclaimer_args *args = (struct reclaimer_args *)ptr;
@@ -864,6 +946,7 @@ restart_loop:
864 default: 946 default:
865 ops = &nfs4_network_partition_recovery_ops; 947 ops = &nfs4_network_partition_recovery_ops;
866 }; 948 };
949 nfs4_state_mark_reclaim(clp);
867 status = __nfs4_init_client(clp); 950 status = __nfs4_init_client(clp);
868 if (status) 951 if (status)
869 goto out_error; 952 goto out_error;
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index 6c564ef948..c5c75235c5 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -602,10 +602,10 @@ static int encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
602{ 602{
603 uint32_t *p; 603 uint32_t *p;
604 604
605 RESERVE_SPACE(8+sizeof(arg->stateid.data)); 605 RESERVE_SPACE(8+sizeof(arg->stateid->data));
606 WRITE32(OP_CLOSE); 606 WRITE32(OP_CLOSE);
607 WRITE32(arg->seqid); 607 WRITE32(arg->seqid->sequence->counter);
608 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data)); 608 WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data));
609 609
610 return 0; 610 return 0;
611} 611}
@@ -729,22 +729,18 @@ static int encode_lock(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
729 WRITE64(arg->length); 729 WRITE64(arg->length);
730 WRITE32(opargs->new_lock_owner); 730 WRITE32(opargs->new_lock_owner);
731 if (opargs->new_lock_owner){ 731 if (opargs->new_lock_owner){
732 struct nfs_open_to_lock *ol = opargs->u.open_lock;
733
734 RESERVE_SPACE(40); 732 RESERVE_SPACE(40);
735 WRITE32(ol->open_seqid); 733 WRITE32(opargs->open_seqid->sequence->counter);
736 WRITEMEM(&ol->open_stateid, sizeof(ol->open_stateid)); 734 WRITEMEM(opargs->open_stateid->data, sizeof(opargs->open_stateid->data));
737 WRITE32(ol->lock_seqid); 735 WRITE32(opargs->lock_seqid->sequence->counter);
738 WRITE64(ol->lock_owner.clientid); 736 WRITE64(opargs->lock_owner.clientid);
739 WRITE32(4); 737 WRITE32(4);
740 WRITE32(ol->lock_owner.id); 738 WRITE32(opargs->lock_owner.id);
741 } 739 }
742 else { 740 else {
743 struct nfs_exist_lock *el = opargs->u.exist_lock;
744
745 RESERVE_SPACE(20); 741 RESERVE_SPACE(20);
746 WRITEMEM(&el->stateid, sizeof(el->stateid)); 742 WRITEMEM(opargs->lock_stateid->data, sizeof(opargs->lock_stateid->data));
747 WRITE32(el->seqid); 743 WRITE32(opargs->lock_seqid->sequence->counter);
748 } 744 }
749 745
750 return 0; 746 return 0;
@@ -775,8 +771,8 @@ static int encode_locku(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
775 RESERVE_SPACE(44); 771 RESERVE_SPACE(44);
776 WRITE32(OP_LOCKU); 772 WRITE32(OP_LOCKU);
777 WRITE32(arg->type); 773 WRITE32(arg->type);
778 WRITE32(opargs->seqid); 774 WRITE32(opargs->seqid->sequence->counter);
779 WRITEMEM(&opargs->stateid, sizeof(opargs->stateid)); 775 WRITEMEM(opargs->stateid->data, sizeof(opargs->stateid->data));
780 WRITE64(arg->offset); 776 WRITE64(arg->offset);
781 WRITE64(arg->length); 777 WRITE64(arg->length);
782 778
@@ -826,7 +822,7 @@ static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_opena
826 */ 822 */
827 RESERVE_SPACE(8); 823 RESERVE_SPACE(8);
828 WRITE32(OP_OPEN); 824 WRITE32(OP_OPEN);
829 WRITE32(arg->seqid); 825 WRITE32(arg->seqid->sequence->counter);
830 encode_share_access(xdr, arg->open_flags); 826 encode_share_access(xdr, arg->open_flags);
831 RESERVE_SPACE(16); 827 RESERVE_SPACE(16);
832 WRITE64(arg->clientid); 828 WRITE64(arg->clientid);
@@ -941,7 +937,7 @@ static int encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_con
941 RESERVE_SPACE(8+sizeof(arg->stateid.data)); 937 RESERVE_SPACE(8+sizeof(arg->stateid.data));
942 WRITE32(OP_OPEN_CONFIRM); 938 WRITE32(OP_OPEN_CONFIRM);
943 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data)); 939 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
944 WRITE32(arg->seqid); 940 WRITE32(arg->seqid->sequence->counter);
945 941
946 return 0; 942 return 0;
947} 943}
@@ -950,10 +946,10 @@ static int encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closea
950{ 946{
951 uint32_t *p; 947 uint32_t *p;
952 948
953 RESERVE_SPACE(8+sizeof(arg->stateid.data)); 949 RESERVE_SPACE(8+sizeof(arg->stateid->data));
954 WRITE32(OP_OPEN_DOWNGRADE); 950 WRITE32(OP_OPEN_DOWNGRADE);
955 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data)); 951 WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data));
956 WRITE32(arg->seqid); 952 WRITE32(arg->seqid->sequence->counter);
957 encode_share_access(xdr, arg->open_flags); 953 encode_share_access(xdr, arg->open_flags);
958 return 0; 954 return 0;
959} 955}
@@ -1437,6 +1433,9 @@ static int nfs4_xdr_enc_open(struct rpc_rqst *req, uint32_t *p, struct nfs_opena
1437 }; 1433 };
1438 int status; 1434 int status;
1439 1435
1436 status = nfs_wait_on_sequence(args->seqid, req->rq_task);
1437 if (status != 0)
1438 goto out;
1440 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1439 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1441 encode_compound_hdr(&xdr, &hdr); 1440 encode_compound_hdr(&xdr, &hdr);
1442 status = encode_putfh(&xdr, args->fh); 1441 status = encode_putfh(&xdr, args->fh);
@@ -1464,6 +1463,9 @@ static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, uint32_t *p, struct n
1464 }; 1463 };
1465 int status; 1464 int status;
1466 1465
1466 status = nfs_wait_on_sequence(args->seqid, req->rq_task);
1467 if (status != 0)
1468 goto out;
1467 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1469 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1468 encode_compound_hdr(&xdr, &hdr); 1470 encode_compound_hdr(&xdr, &hdr);
1469 status = encode_putfh(&xdr, args->fh); 1471 status = encode_putfh(&xdr, args->fh);
@@ -1485,6 +1487,9 @@ static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, uint32_t *p, struct nf
1485 }; 1487 };
1486 int status; 1488 int status;
1487 1489
1490 status = nfs_wait_on_sequence(args->seqid, req->rq_task);
1491 if (status != 0)
1492 goto out;
1488 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1493 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1489 encode_compound_hdr(&xdr, &hdr); 1494 encode_compound_hdr(&xdr, &hdr);
1490 status = encode_putfh(&xdr, args->fh); 1495 status = encode_putfh(&xdr, args->fh);
@@ -1525,8 +1530,15 @@ static int nfs4_xdr_enc_lock(struct rpc_rqst *req, uint32_t *p, struct nfs_locka
1525 struct compound_hdr hdr = { 1530 struct compound_hdr hdr = {
1526 .nops = 2, 1531 .nops = 2,
1527 }; 1532 };
1533 struct nfs_lock_opargs *opargs = args->u.lock;
1528 int status; 1534 int status;
1529 1535
1536 status = nfs_wait_on_sequence(opargs->lock_seqid, req->rq_task);
1537 if (status != 0)
1538 goto out;
1539 /* Do we need to do an open_to_lock_owner? */
1540 if (opargs->lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)
1541 opargs->new_lock_owner = 0;
1530 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 1542 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1531 encode_compound_hdr(&xdr, &hdr); 1543 encode_compound_hdr(&xdr, &hdr);
1532 status = encode_putfh(&xdr, args->fh); 1544 status = encode_putfh(&xdr, args->fh);
@@ -2890,8 +2902,8 @@ static int decode_lock(struct xdr_stream *xdr, struct nfs_lockres *res)
2890 2902
2891 status = decode_op_hdr(xdr, OP_LOCK); 2903 status = decode_op_hdr(xdr, OP_LOCK);
2892 if (status == 0) { 2904 if (status == 0) {
2893 READ_BUF(sizeof(nfs4_stateid)); 2905 READ_BUF(sizeof(res->u.stateid.data));
2894 COPYMEM(&res->u.stateid, sizeof(res->u.stateid)); 2906 COPYMEM(res->u.stateid.data, sizeof(res->u.stateid.data));
2895 } else if (status == -NFS4ERR_DENIED) 2907 } else if (status == -NFS4ERR_DENIED)
2896 return decode_lock_denied(xdr, &res->u.denied); 2908 return decode_lock_denied(xdr, &res->u.denied);
2897 return status; 2909 return status;
@@ -2913,8 +2925,8 @@ static int decode_locku(struct xdr_stream *xdr, struct nfs_lockres *res)
2913 2925
2914 status = decode_op_hdr(xdr, OP_LOCKU); 2926 status = decode_op_hdr(xdr, OP_LOCKU);
2915 if (status == 0) { 2927 if (status == 0) {
2916 READ_BUF(sizeof(nfs4_stateid)); 2928 READ_BUF(sizeof(res->u.stateid.data));
2917 COPYMEM(&res->u.stateid, sizeof(res->u.stateid)); 2929 COPYMEM(res->u.stateid.data, sizeof(res->u.stateid.data));
2918 } 2930 }
2919 return status; 2931 return status;
2920} 2932}
diff --git a/fs/nfs/proc.c b/fs/nfs/proc.c
index be23c3fb92..8fef86523d 100644
--- a/fs/nfs/proc.c
+++ b/fs/nfs/proc.c
@@ -216,7 +216,7 @@ static int nfs_proc_write(struct nfs_write_data *wdata)
216 216
217static int 217static int
218nfs_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, 218nfs_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
219 int flags) 219 int flags, struct nameidata *nd)
220{ 220{
221 struct nfs_fh fhandle; 221 struct nfs_fh fhandle;
222 struct nfs_fattr fattr; 222 struct nfs_fattr fattr;
diff --git a/fs/open.c b/fs/open.c
index f0d90cf049..8d06ec911f 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -739,7 +739,8 @@ asmlinkage long sys_fchown(unsigned int fd, uid_t user, gid_t group)
739} 739}
740 740
741static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt, 741static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt,
742 int flags, struct file *f) 742 int flags, struct file *f,
743 int (*open)(struct inode *, struct file *))
743{ 744{
744 struct inode *inode; 745 struct inode *inode;
745 int error; 746 int error;
@@ -761,11 +762,14 @@ static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt,
761 f->f_op = fops_get(inode->i_fop); 762 f->f_op = fops_get(inode->i_fop);
762 file_move(f, &inode->i_sb->s_files); 763 file_move(f, &inode->i_sb->s_files);
763 764
764 if (f->f_op && f->f_op->open) { 765 if (!open && f->f_op)
765 error = f->f_op->open(inode,f); 766 open = f->f_op->open;
767 if (open) {
768 error = open(inode, f);
766 if (error) 769 if (error)
767 goto cleanup_all; 770 goto cleanup_all;
768 } 771 }
772
769 f->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC); 773 f->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC);
770 774
771 file_ra_state_init(&f->f_ra, f->f_mapping->host->i_mapping); 775 file_ra_state_init(&f->f_ra, f->f_mapping->host->i_mapping);
@@ -814,28 +818,75 @@ struct file *filp_open(const char * filename, int flags, int mode)
814{ 818{
815 int namei_flags, error; 819 int namei_flags, error;
816 struct nameidata nd; 820 struct nameidata nd;
817 struct file *f;
818 821
819 namei_flags = flags; 822 namei_flags = flags;
820 if ((namei_flags+1) & O_ACCMODE) 823 if ((namei_flags+1) & O_ACCMODE)
821 namei_flags++; 824 namei_flags++;
822 if (namei_flags & O_TRUNC)
823 namei_flags |= 2;
824
825 error = -ENFILE;
826 f = get_empty_filp();
827 if (f == NULL)
828 return ERR_PTR(error);
829 825
830 error = open_namei(filename, namei_flags, mode, &nd); 826 error = open_namei(filename, namei_flags, mode, &nd);
831 if (!error) 827 if (!error)
832 return __dentry_open(nd.dentry, nd.mnt, flags, f); 828 return nameidata_to_filp(&nd, flags);
833 829
834 put_filp(f);
835 return ERR_PTR(error); 830 return ERR_PTR(error);
836} 831}
837EXPORT_SYMBOL(filp_open); 832EXPORT_SYMBOL(filp_open);
838 833
834/**
835 * lookup_instantiate_filp - instantiates the open intent filp
836 * @nd: pointer to nameidata
837 * @dentry: pointer to dentry
838 * @open: open callback
839 *
840 * Helper for filesystems that want to use lookup open intents and pass back
841 * a fully instantiated struct file to the caller.
842 * This function is meant to be called from within a filesystem's
843 * lookup method.
844 * Note that in case of error, nd->intent.open.file is destroyed, but the
845 * path information remains valid.
846 * If the open callback is set to NULL, then the standard f_op->open()
847 * filesystem callback is substituted.
848 */
849struct file *lookup_instantiate_filp(struct nameidata *nd, struct dentry *dentry,
850 int (*open)(struct inode *, struct file *))
851{
852 if (IS_ERR(nd->intent.open.file))
853 goto out;
854 if (IS_ERR(dentry))
855 goto out_err;
856 nd->intent.open.file = __dentry_open(dget(dentry), mntget(nd->mnt),
857 nd->intent.open.flags - 1,
858 nd->intent.open.file,
859 open);
860out:
861 return nd->intent.open.file;
862out_err:
863 release_open_intent(nd);
864 nd->intent.open.file = (struct file *)dentry;
865 goto out;
866}
867EXPORT_SYMBOL_GPL(lookup_instantiate_filp);
868
869/**
870 * nameidata_to_filp - convert a nameidata to an open filp.
871 * @nd: pointer to nameidata
872 * @flags: open flags
873 *
874 * Note that this function destroys the original nameidata
875 */
876struct file *nameidata_to_filp(struct nameidata *nd, int flags)
877{
878 struct file *filp;
879
880 /* Pick up the filp from the open intent */
881 filp = nd->intent.open.file;
882 /* Has the filesystem initialised the file for us? */
883 if (filp->f_dentry == NULL)
884 filp = __dentry_open(nd->dentry, nd->mnt, flags, filp, NULL);
885 else
886 path_release(nd);
887 return filp;
888}
889
839struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags) 890struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags)
840{ 891{
841 int error; 892 int error;
@@ -846,7 +897,7 @@ struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags)
846 if (f == NULL) 897 if (f == NULL)
847 return ERR_PTR(error); 898 return ERR_PTR(error);
848 899
849 return __dentry_open(dentry, mnt, flags, f); 900 return __dentry_open(dentry, mnt, flags, f, NULL);
850} 901}
851EXPORT_SYMBOL(dentry_open); 902EXPORT_SYMBOL(dentry_open);
852 903
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 3b33f94020..a170450aad 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -103,7 +103,9 @@ enum pid_directory_inos {
103 PROC_TGID_NUMA_MAPS, 103 PROC_TGID_NUMA_MAPS,
104 PROC_TGID_MOUNTS, 104 PROC_TGID_MOUNTS,
105 PROC_TGID_WCHAN, 105 PROC_TGID_WCHAN,
106#ifdef CONFIG_MMU
106 PROC_TGID_SMAPS, 107 PROC_TGID_SMAPS,
108#endif
107#ifdef CONFIG_SCHEDSTATS 109#ifdef CONFIG_SCHEDSTATS
108 PROC_TGID_SCHEDSTAT, 110 PROC_TGID_SCHEDSTAT,
109#endif 111#endif
@@ -141,7 +143,9 @@ enum pid_directory_inos {
141 PROC_TID_NUMA_MAPS, 143 PROC_TID_NUMA_MAPS,
142 PROC_TID_MOUNTS, 144 PROC_TID_MOUNTS,
143 PROC_TID_WCHAN, 145 PROC_TID_WCHAN,
146#ifdef CONFIG_MMU
144 PROC_TID_SMAPS, 147 PROC_TID_SMAPS,
148#endif
145#ifdef CONFIG_SCHEDSTATS 149#ifdef CONFIG_SCHEDSTATS
146 PROC_TID_SCHEDSTAT, 150 PROC_TID_SCHEDSTAT,
147#endif 151#endif
@@ -195,7 +199,9 @@ static struct pid_entry tgid_base_stuff[] = {
195 E(PROC_TGID_ROOT, "root", S_IFLNK|S_IRWXUGO), 199 E(PROC_TGID_ROOT, "root", S_IFLNK|S_IRWXUGO),
196 E(PROC_TGID_EXE, "exe", S_IFLNK|S_IRWXUGO), 200 E(PROC_TGID_EXE, "exe", S_IFLNK|S_IRWXUGO),
197 E(PROC_TGID_MOUNTS, "mounts", S_IFREG|S_IRUGO), 201 E(PROC_TGID_MOUNTS, "mounts", S_IFREG|S_IRUGO),
202#ifdef CONFIG_MMU
198 E(PROC_TGID_SMAPS, "smaps", S_IFREG|S_IRUGO), 203 E(PROC_TGID_SMAPS, "smaps", S_IFREG|S_IRUGO),
204#endif
199#ifdef CONFIG_SECURITY 205#ifdef CONFIG_SECURITY
200 E(PROC_TGID_ATTR, "attr", S_IFDIR|S_IRUGO|S_IXUGO), 206 E(PROC_TGID_ATTR, "attr", S_IFDIR|S_IRUGO|S_IXUGO),
201#endif 207#endif
@@ -235,7 +241,9 @@ static struct pid_entry tid_base_stuff[] = {
235 E(PROC_TID_ROOT, "root", S_IFLNK|S_IRWXUGO), 241 E(PROC_TID_ROOT, "root", S_IFLNK|S_IRWXUGO),
236 E(PROC_TID_EXE, "exe", S_IFLNK|S_IRWXUGO), 242 E(PROC_TID_EXE, "exe", S_IFLNK|S_IRWXUGO),
237 E(PROC_TID_MOUNTS, "mounts", S_IFREG|S_IRUGO), 243 E(PROC_TID_MOUNTS, "mounts", S_IFREG|S_IRUGO),
244#ifdef CONFIG_MMU
238 E(PROC_TID_SMAPS, "smaps", S_IFREG|S_IRUGO), 245 E(PROC_TID_SMAPS, "smaps", S_IFREG|S_IRUGO),
246#endif
239#ifdef CONFIG_SECURITY 247#ifdef CONFIG_SECURITY
240 E(PROC_TID_ATTR, "attr", S_IFDIR|S_IRUGO|S_IXUGO), 248 E(PROC_TID_ATTR, "attr", S_IFDIR|S_IRUGO|S_IXUGO),
241#endif 249#endif
@@ -630,6 +638,7 @@ static struct file_operations proc_numa_maps_operations = {
630}; 638};
631#endif 639#endif
632 640
641#ifdef CONFIG_MMU
633extern struct seq_operations proc_pid_smaps_op; 642extern struct seq_operations proc_pid_smaps_op;
634static int smaps_open(struct inode *inode, struct file *file) 643static int smaps_open(struct inode *inode, struct file *file)
635{ 644{
@@ -648,6 +657,7 @@ static struct file_operations proc_smaps_operations = {
648 .llseek = seq_lseek, 657 .llseek = seq_lseek,
649 .release = seq_release, 658 .release = seq_release,
650}; 659};
660#endif
651 661
652extern struct seq_operations mounts_op; 662extern struct seq_operations mounts_op;
653static int mounts_open(struct inode *inode, struct file *file) 663static int mounts_open(struct inode *inode, struct file *file)
@@ -1681,10 +1691,12 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
1681 case PROC_TGID_MOUNTS: 1691 case PROC_TGID_MOUNTS:
1682 inode->i_fop = &proc_mounts_operations; 1692 inode->i_fop = &proc_mounts_operations;
1683 break; 1693 break;
1694#ifdef CONFIG_MMU
1684 case PROC_TID_SMAPS: 1695 case PROC_TID_SMAPS:
1685 case PROC_TGID_SMAPS: 1696 case PROC_TGID_SMAPS:
1686 inode->i_fop = &proc_smaps_operations; 1697 inode->i_fop = &proc_smaps_operations;
1687 break; 1698 break;
1699#endif
1688#ifdef CONFIG_SECURITY 1700#ifdef CONFIG_SECURITY
1689 case PROC_TID_ATTR: 1701 case PROC_TID_ATTR:
1690 inode->i_nlink = 2; 1702 inode->i_nlink = 2;
diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
index f3bf016d5e..cff10ab1af 100644
--- a/fs/proc/nommu.c
+++ b/fs/proc/nommu.c
@@ -91,6 +91,7 @@ static void *nommu_vma_list_start(struct seq_file *m, loff_t *_pos)
91 next = _rb; 91 next = _rb;
92 break; 92 break;
93 } 93 }
94 pos--;
94 } 95 }
95 96
96 return next; 97 return next;
diff --git a/include/asm-arm/arch-pxa/pxafb.h b/include/asm-arm/arch-pxa/pxafb.h
index 21c0e16dce..aba9b30f42 100644
--- a/include/asm-arm/arch-pxa/pxafb.h
+++ b/include/asm-arm/arch-pxa/pxafb.h
@@ -66,4 +66,5 @@ struct pxafb_mach_info {
66 66
67}; 67};
68void set_pxa_fb_info(struct pxafb_mach_info *hard_pxa_fb_info); 68void set_pxa_fb_info(struct pxafb_mach_info *hard_pxa_fb_info);
69void set_pxa_fb_parent(struct device *parent_dev);
69unsigned long pxafb_get_hsync_time(struct device *dev); 70unsigned long pxafb_get_hsync_time(struct device *dev);
diff --git a/include/asm-arm/arch-s3c2410/io.h b/include/asm-arm/arch-s3c2410/io.h
index 418233a7ee..4bf272ed9a 100644
--- a/include/asm-arm/arch-s3c2410/io.h
+++ b/include/asm-arm/arch-s3c2410/io.h
@@ -9,7 +9,7 @@
9 * 06-Dec-1997 RMK Created. 9 * 06-Dec-1997 RMK Created.
10 * 02-Sep-2003 BJD Modified for S3C2410 10 * 02-Sep-2003 BJD Modified for S3C2410
11 * 10-Mar-2005 LCVR Changed S3C2410_VA to S3C24XX_VA 11 * 10-Mar-2005 LCVR Changed S3C2410_VA to S3C24XX_VA
12 * 12 * 13-Oct-2005 BJD Fixed problems with LDRH/STRH offset range
13 */ 13 */
14 14
15#ifndef __ASM_ARM_ARCH_IO_H 15#ifndef __ASM_ARM_ARCH_IO_H
@@ -97,7 +97,7 @@ DECLARE_IO(int,l,"")
97 else \ 97 else \
98 __asm__ __volatile__( \ 98 __asm__ __volatile__( \
99 "strb %0, [%1, #0] @ outbc" \ 99 "strb %0, [%1, #0] @ outbc" \
100 : : "r" (value), "r" ((port))); \ 100 : : "r" (value), "r" ((port))); \
101}) 101})
102 102
103#define __inbc(port) \ 103#define __inbc(port) \
@@ -110,35 +110,61 @@ DECLARE_IO(int,l,"")
110 else \ 110 else \
111 __asm__ __volatile__( \ 111 __asm__ __volatile__( \
112 "ldrb %0, [%1, #0] @ inbc" \ 112 "ldrb %0, [%1, #0] @ inbc" \
113 : "=r" (result) : "r" ((port))); \ 113 : "=r" (result) : "r" ((port))); \
114 result; \ 114 result; \
115}) 115})
116 116
117#define __outwc(value,port) \ 117#define __outwc(value,port) \
118({ \ 118({ \
119 unsigned long v = value; \ 119 unsigned long v = value; \
120 if (__PORT_PCIO((port))) \ 120 if (__PORT_PCIO((port))) { \
121 __asm__ __volatile__( \ 121 if ((port) < 256 && (port) > -256) \
122 "strh %0, [%1, %2] @ outwc" \ 122 __asm__ __volatile__( \
123 : : "r" (v), "r" (PCIO_BASE), "Jr" ((port))); \ 123 "strh %0, [%1, %2] @ outwc" \
124 else \ 124 : : "r" (v), "r" (PCIO_BASE), "Jr" ((port))); \
125 else if ((port) > 0) \
126 __asm__ __volatile__( \
127 "strh %0, [%1, %2] @ outwc" \
128 : : "r" (v), \
129 "r" (PCIO_BASE + ((port) & ~0xff)), \
130 "Jr" (((port) & 0xff))); \
131 else \
132 __asm__ __volatile__( \
133 "strh %0, [%1, #0] @ outwc" \
134 : : "r" (v), \
135 "r" (PCIO_BASE + (port))); \
136 } else \
125 __asm__ __volatile__( \ 137 __asm__ __volatile__( \
126 "strh %0, [%1, #0] @ outwc" \ 138 "strh %0, [%1, #0] @ outwc" \
127 : : "r" (v), "r" ((port))); \ 139 : : "r" (v), "r" ((port))); \
128}) 140})
129 141
130#define __inwc(port) \ 142#define __inwc(port) \
131({ \ 143({ \
132 unsigned short result; \ 144 unsigned short result; \
133 if (__PORT_PCIO((port))) \ 145 if (__PORT_PCIO((port))) { \
134 __asm__ __volatile__( \ 146 if ((port) < 256 && (port) > -256 ) \
135 "ldrh %0, [%1, %2] @ inwc" \ 147 __asm__ __volatile__( \
136 : "=r" (result) : "r" (PCIO_BASE), "Jr" ((port))); \ 148 "ldrh %0, [%1, %2] @ inwc" \
137 else \ 149 : "=r" (result) \
150 : "r" (PCIO_BASE), \
151 "Jr" ((port))); \
152 else if ((port) > 0) \
153 __asm__ __volatile__( \
154 "ldrh %0, [%1, %2] @ inwc" \
155 : "=r" (result) \
156 : "r" (PCIO_BASE + ((port) & ~0xff)), \
157 "Jr" (((port) & 0xff))); \
158 else \
159 __asm__ __volatile__( \
160 "ldrh %0, [%1, #0] @ inwc" \
161 : "=r" (result) \
162 : "r" (PCIO_BASE + ((port)))); \
163 } else \
138 __asm__ __volatile__( \ 164 __asm__ __volatile__( \
139 "ldrh %0, [%1, #0] @ inwc" \ 165 "ldrh %0, [%1, #0] @ inwc" \
140 : "=r" (result) : "r" ((port))); \ 166 : "=r" (result) : "r" ((port))); \
141 result; \ 167 result; \
142}) 168})
143 169
144#define __outlc(value,port) \ 170#define __outlc(value,port) \
diff --git a/include/asm-sparc64/pbm.h b/include/asm-sparc64/pbm.h
index 38bbbccb40..dd35a2c779 100644
--- a/include/asm-sparc64/pbm.h
+++ b/include/asm-sparc64/pbm.h
@@ -27,23 +27,27 @@
27 * PCI bus. 27 * PCI bus.
28 */ 28 */
29 29
30#define PBM_LOGCLUSTERS 3
31#define PBM_NCLUSTERS (1 << PBM_LOGCLUSTERS)
32
33struct pci_controller_info; 30struct pci_controller_info;
34 31
35/* This contains the software state necessary to drive a PCI 32/* This contains the software state necessary to drive a PCI
36 * controller's IOMMU. 33 * controller's IOMMU.
37 */ 34 */
35struct pci_iommu_arena {
36 unsigned long *map;
37 unsigned int hint;
38 unsigned int limit;
39};
40
38struct pci_iommu { 41struct pci_iommu {
39 /* This protects the controller's IOMMU and all 42 /* This protects the controller's IOMMU and all
40 * streaming buffers underneath. 43 * streaming buffers underneath.
41 */ 44 */
42 spinlock_t lock; 45 spinlock_t lock;
43 46
47 struct pci_iommu_arena arena;
48
44 /* IOMMU page table, a linear array of ioptes. */ 49 /* IOMMU page table, a linear array of ioptes. */
45 iopte_t *page_table; /* The page table itself. */ 50 iopte_t *page_table; /* The page table itself. */
46 int page_table_sz_bits; /* log2 of ow many pages does it map? */
47 51
48 /* Base PCI memory space address where IOMMU mappings 52 /* Base PCI memory space address where IOMMU mappings
49 * begin. 53 * begin.
@@ -62,12 +66,6 @@ struct pci_iommu {
62 */ 66 */
63 unsigned long write_complete_reg; 67 unsigned long write_complete_reg;
64 68
65 /* The lowest used consistent mapping entry. Since
66 * we allocate consistent maps out of cluster 0 this
67 * is relative to the beginning of closter 0.
68 */
69 u32 lowest_consistent_map;
70
71 /* In order to deal with some buggy third-party PCI bridges that 69 /* In order to deal with some buggy third-party PCI bridges that
72 * do wrong prefetching, we never mark valid mappings as invalid. 70 * do wrong prefetching, we never mark valid mappings as invalid.
73 * Instead we point them at this dummy page. 71 * Instead we point them at this dummy page.
@@ -75,16 +73,6 @@ struct pci_iommu {
75 unsigned long dummy_page; 73 unsigned long dummy_page;
76 unsigned long dummy_page_pa; 74 unsigned long dummy_page_pa;
77 75
78 /* If PBM_NCLUSTERS is ever decreased to 4 or lower,
79 * or if largest supported page_table_sz * 8K goes above
80 * 2GB, you must increase the size of the type of
81 * these counters. You have been duly warned. -DaveM
82 */
83 struct {
84 u16 next;
85 u16 flush;
86 } alloc_info[PBM_NCLUSTERS];
87
88 /* CTX allocation. */ 76 /* CTX allocation. */
89 unsigned long ctx_lowest_free; 77 unsigned long ctx_lowest_free;
90 unsigned long ctx_bitmap[IOMMU_NUM_CTXS / (sizeof(unsigned long) * 8)]; 78 unsigned long ctx_bitmap[IOMMU_NUM_CTXS / (sizeof(unsigned long) * 8)];
@@ -102,7 +90,7 @@ struct pci_iommu {
102 u32 dma_addr_mask; 90 u32 dma_addr_mask;
103}; 91};
104 92
105extern void pci_iommu_table_init(struct pci_iommu *, int); 93extern void pci_iommu_table_init(struct pci_iommu *iommu, int tsbsize, u32 dma_offset, u32 dma_addr_mask);
106 94
107/* This describes a PCI bus module's streaming buffer. */ 95/* This describes a PCI bus module's streaming buffer. */
108struct pci_strbuf { 96struct pci_strbuf {
diff --git a/include/linux/acct.h b/include/linux/acct.h
index 1993a36917..19f70462b3 100644
--- a/include/linux/acct.h
+++ b/include/linux/acct.h
@@ -162,13 +162,13 @@ typedef struct acct acct_t;
162#ifdef __KERNEL__ 162#ifdef __KERNEL__
163/* 163/*
164 * Yet another set of HZ to *HZ helper functions. 164 * Yet another set of HZ to *HZ helper functions.
165 * See <linux/times.h> for the original. 165 * See <linux/jiffies.h> for the original.
166 */ 166 */
167 167
168static inline u32 jiffies_to_AHZ(unsigned long x) 168static inline u32 jiffies_to_AHZ(unsigned long x)
169{ 169{
170#if (TICK_NSEC % (NSEC_PER_SEC / AHZ)) == 0 170#if (TICK_NSEC % (NSEC_PER_SEC / AHZ)) == 0
171 return x / (HZ / USER_HZ); 171 return x / (HZ / AHZ);
172#else 172#else
173 u64 tmp = (u64)x * TICK_NSEC; 173 u64 tmp = (u64)x * TICK_NSEC;
174 do_div(tmp, (NSEC_PER_SEC / AHZ)); 174 do_div(tmp, (NSEC_PER_SEC / AHZ));
diff --git a/include/linux/aio.h b/include/linux/aio.h
index 60def658b2..0decf66117 100644
--- a/include/linux/aio.h
+++ b/include/linux/aio.h
@@ -24,7 +24,12 @@ struct kioctx;
24#define KIOCB_SYNC_KEY (~0U) 24#define KIOCB_SYNC_KEY (~0U)
25 25
26/* ki_flags bits */ 26/* ki_flags bits */
27#define KIF_LOCKED 0 27/*
28 * This may be used for cancel/retry serialization in the future, but
29 * for now it's unused and we probably don't want modules to even
30 * think they can use it.
31 */
32/* #define KIF_LOCKED 0 */
28#define KIF_KICKED 1 33#define KIF_KICKED 1
29#define KIF_CANCELLED 2 34#define KIF_CANCELLED 2
30 35
diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index fe9778301d..9bdba8169b 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -393,15 +393,13 @@ extern cpumask_t cpu_present_map;
393#define for_each_present_cpu(cpu) for_each_cpu_mask((cpu), cpu_present_map) 393#define for_each_present_cpu(cpu) for_each_cpu_mask((cpu), cpu_present_map)
394 394
395/* Find the highest possible smp_processor_id() */ 395/* Find the highest possible smp_processor_id() */
396static inline unsigned int highest_possible_processor_id(void) 396#define highest_possible_processor_id() \
397{ 397({ \
398 unsigned int cpu, highest = 0; 398 unsigned int cpu, highest = 0; \
399 399 for_each_cpu_mask(cpu, cpu_possible_map) \
400 for_each_cpu_mask(cpu, cpu_possible_map) 400 highest = cpu; \
401 highest = cpu; 401 highest; \
402 402})
403 return highest;
404}
405 403
406 404
407#endif /* __LINUX_CPUMASK_H */ 405#endif /* __LINUX_CPUMASK_H */
diff --git a/include/linux/list.h b/include/linux/list.h
index e6ec596822..084971f333 100644
--- a/include/linux/list.h
+++ b/include/linux/list.h
@@ -442,12 +442,14 @@ static inline void list_splice_init(struct list_head *list,
442 * as long as the traversal is guarded by rcu_read_lock(). 442 * as long as the traversal is guarded by rcu_read_lock().
443 */ 443 */
444#define list_for_each_rcu(pos, head) \ 444#define list_for_each_rcu(pos, head) \
445 for (pos = (head)->next; prefetch(pos->next), pos != (head); \ 445 for (pos = (head)->next; \
446 pos = rcu_dereference(pos->next)) 446 prefetch(rcu_dereference(pos)->next), pos != (head); \
447 pos = pos->next)
447 448
448#define __list_for_each_rcu(pos, head) \ 449#define __list_for_each_rcu(pos, head) \
449 for (pos = (head)->next; pos != (head); \ 450 for (pos = (head)->next; \
450 pos = rcu_dereference(pos->next)) 451 rcu_dereference(pos) != (head); \
452 pos = pos->next)
451 453
452/** 454/**
453 * list_for_each_safe_rcu - iterate over an rcu-protected list safe 455 * list_for_each_safe_rcu - iterate over an rcu-protected list safe
@@ -461,8 +463,9 @@ static inline void list_splice_init(struct list_head *list,
461 * as long as the traversal is guarded by rcu_read_lock(). 463 * as long as the traversal is guarded by rcu_read_lock().
462 */ 464 */
463#define list_for_each_safe_rcu(pos, n, head) \ 465#define list_for_each_safe_rcu(pos, n, head) \
464 for (pos = (head)->next, n = pos->next; pos != (head); \ 466 for (pos = (head)->next; \
465 pos = rcu_dereference(n), n = pos->next) 467 n = rcu_dereference(pos)->next, pos != (head); \
468 pos = n)
466 469
467/** 470/**
468 * list_for_each_entry_rcu - iterate over rcu list of given type 471 * list_for_each_entry_rcu - iterate over rcu list of given type
@@ -474,11 +477,11 @@ static inline void list_splice_init(struct list_head *list,
474 * the _rcu list-mutation primitives such as list_add_rcu() 477 * the _rcu list-mutation primitives such as list_add_rcu()
475 * as long as the traversal is guarded by rcu_read_lock(). 478 * as long as the traversal is guarded by rcu_read_lock().
476 */ 479 */
477#define list_for_each_entry_rcu(pos, head, member) \ 480#define list_for_each_entry_rcu(pos, head, member) \
478 for (pos = list_entry((head)->next, typeof(*pos), member); \ 481 for (pos = list_entry((head)->next, typeof(*pos), member); \
479 prefetch(pos->member.next), &pos->member != (head); \ 482 prefetch(rcu_dereference(pos)->member.next), \
480 pos = rcu_dereference(list_entry(pos->member.next, \ 483 &pos->member != (head); \
481 typeof(*pos), member))) 484 pos = list_entry(pos->member.next, typeof(*pos), member))
482 485
483 486
484/** 487/**
@@ -492,8 +495,9 @@ static inline void list_splice_init(struct list_head *list,
492 * as long as the traversal is guarded by rcu_read_lock(). 495 * as long as the traversal is guarded by rcu_read_lock().
493 */ 496 */
494#define list_for_each_continue_rcu(pos, head) \ 497#define list_for_each_continue_rcu(pos, head) \
495 for ((pos) = (pos)->next; prefetch((pos)->next), (pos) != (head); \ 498 for ((pos) = (pos)->next; \
496 (pos) = rcu_dereference((pos)->next)) 499 prefetch(rcu_dereference((pos))->next), (pos) != (head); \
500 (pos) = (pos)->next)
497 501
498/* 502/*
499 * Double linked lists with a single pointer list head. 503 * Double linked lists with a single pointer list head.
@@ -696,8 +700,9 @@ static inline void hlist_add_after_rcu(struct hlist_node *prev,
696 pos = n) 700 pos = n)
697 701
698#define hlist_for_each_rcu(pos, head) \ 702#define hlist_for_each_rcu(pos, head) \
699 for ((pos) = (head)->first; pos && ({ prefetch((pos)->next); 1; }); \ 703 for ((pos) = (head)->first; \
700 (pos) = rcu_dereference((pos)->next)) 704 rcu_dereference((pos)) && ({ prefetch((pos)->next); 1; }); \
705 (pos) = (pos)->next)
701 706
702/** 707/**
703 * hlist_for_each_entry - iterate over list of given type 708 * hlist_for_each_entry - iterate over list of given type
@@ -762,9 +767,9 @@ static inline void hlist_add_after_rcu(struct hlist_node *prev,
762 */ 767 */
763#define hlist_for_each_entry_rcu(tpos, pos, head, member) \ 768#define hlist_for_each_entry_rcu(tpos, pos, head, member) \
764 for (pos = (head)->first; \ 769 for (pos = (head)->first; \
765 pos && ({ prefetch(pos->next); 1;}) && \ 770 rcu_dereference(pos) && ({ prefetch(pos->next); 1;}) && \
766 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ 771 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
767 pos = rcu_dereference(pos->next)) 772 pos = pos->next)
768 773
769#else 774#else
770#warning "don't include kernel headers in userspace" 775#warning "don't include kernel headers in userspace"
diff --git a/include/linux/namei.h b/include/linux/namei.h
index 7db67b008c..1c975d0d9e 100644
--- a/include/linux/namei.h
+++ b/include/linux/namei.h
@@ -8,6 +8,7 @@ struct vfsmount;
8struct open_intent { 8struct open_intent {
9 int flags; 9 int flags;
10 int create_mode; 10 int create_mode;
11 struct file *file;
11}; 12};
12 13
13enum { MAX_NESTED_LINKS = 5 }; 14enum { MAX_NESTED_LINKS = 5 };
@@ -65,6 +66,13 @@ extern int FASTCALL(link_path_walk(const char *, struct nameidata *));
65extern void path_release(struct nameidata *); 66extern void path_release(struct nameidata *);
66extern void path_release_on_umount(struct nameidata *); 67extern void path_release_on_umount(struct nameidata *);
67 68
69extern int __user_path_lookup_open(const char __user *, unsigned lookup_flags, struct nameidata *nd, int open_flags);
70extern int path_lookup_open(const char *, unsigned lookup_flags, struct nameidata *, int open_flags);
71extern struct file *lookup_instantiate_filp(struct nameidata *nd, struct dentry *dentry,
72 int (*open)(struct inode *, struct file *));
73extern struct file *nameidata_to_filp(struct nameidata *nd, int flags);
74extern void release_open_intent(struct nameidata *);
75
68extern struct dentry * lookup_one_len(const char *, struct dentry *, int); 76extern struct dentry * lookup_one_len(const char *, struct dentry *, int);
69extern struct dentry * lookup_hash(struct qstr *, struct dentry *); 77extern struct dentry * lookup_hash(struct qstr *, struct dentry *);
70 78
diff --git a/include/linux/nfs_xdr.h b/include/linux/nfs_xdr.h
index a2bf6914ff..60086dac11 100644
--- a/include/linux/nfs_xdr.h
+++ b/include/linux/nfs_xdr.h
@@ -96,12 +96,13 @@ struct nfs4_change_info {
96 u64 after; 96 u64 after;
97}; 97};
98 98
99struct nfs_seqid;
99/* 100/*
100 * Arguments to the open call. 101 * Arguments to the open call.
101 */ 102 */
102struct nfs_openargs { 103struct nfs_openargs {
103 const struct nfs_fh * fh; 104 const struct nfs_fh * fh;
104 __u32 seqid; 105 struct nfs_seqid * seqid;
105 int open_flags; 106 int open_flags;
106 __u64 clientid; 107 __u64 clientid;
107 __u32 id; 108 __u32 id;
@@ -136,7 +137,7 @@ struct nfs_openres {
136struct nfs_open_confirmargs { 137struct nfs_open_confirmargs {
137 const struct nfs_fh * fh; 138 const struct nfs_fh * fh;
138 nfs4_stateid stateid; 139 nfs4_stateid stateid;
139 __u32 seqid; 140 struct nfs_seqid * seqid;
140}; 141};
141 142
142struct nfs_open_confirmres { 143struct nfs_open_confirmres {
@@ -148,8 +149,8 @@ struct nfs_open_confirmres {
148 */ 149 */
149struct nfs_closeargs { 150struct nfs_closeargs {
150 struct nfs_fh * fh; 151 struct nfs_fh * fh;
151 nfs4_stateid stateid; 152 nfs4_stateid * stateid;
152 __u32 seqid; 153 struct nfs_seqid * seqid;
153 int open_flags; 154 int open_flags;
154}; 155};
155 156
@@ -164,30 +165,19 @@ struct nfs_lowner {
164 u32 id; 165 u32 id;
165}; 166};
166 167
167struct nfs_open_to_lock {
168 __u32 open_seqid;
169 nfs4_stateid open_stateid;
170 __u32 lock_seqid;
171 struct nfs_lowner lock_owner;
172};
173
174struct nfs_exist_lock {
175 nfs4_stateid stateid;
176 __u32 seqid;
177};
178
179struct nfs_lock_opargs { 168struct nfs_lock_opargs {
169 struct nfs_seqid * lock_seqid;
170 nfs4_stateid * lock_stateid;
171 struct nfs_seqid * open_seqid;
172 nfs4_stateid * open_stateid;
173 struct nfs_lowner lock_owner;
180 __u32 reclaim; 174 __u32 reclaim;
181 __u32 new_lock_owner; 175 __u32 new_lock_owner;
182 union {
183 struct nfs_open_to_lock *open_lock;
184 struct nfs_exist_lock *exist_lock;
185 } u;
186}; 176};
187 177
188struct nfs_locku_opargs { 178struct nfs_locku_opargs {
189 __u32 seqid; 179 struct nfs_seqid * seqid;
190 nfs4_stateid stateid; 180 nfs4_stateid * stateid;
191}; 181};
192 182
193struct nfs_lockargs { 183struct nfs_lockargs {
@@ -722,7 +712,7 @@ struct nfs_rpc_ops {
722 int (*write) (struct nfs_write_data *); 712 int (*write) (struct nfs_write_data *);
723 int (*commit) (struct nfs_write_data *); 713 int (*commit) (struct nfs_write_data *);
724 int (*create) (struct inode *, struct dentry *, 714 int (*create) (struct inode *, struct dentry *,
725 struct iattr *, int); 715 struct iattr *, int, struct nameidata *);
726 int (*remove) (struct inode *, struct qstr *); 716 int (*remove) (struct inode *, struct qstr *);
727 int (*unlink_setup) (struct rpc_message *, 717 int (*unlink_setup) (struct rpc_message *,
728 struct dentry *, struct qstr *); 718 struct dentry *, struct qstr *);
diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index 4e65eb44ad..70191a5a14 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -94,6 +94,7 @@ struct rcu_data {
94 long batch; /* Batch # for current RCU batch */ 94 long batch; /* Batch # for current RCU batch */
95 struct rcu_head *nxtlist; 95 struct rcu_head *nxtlist;
96 struct rcu_head **nxttail; 96 struct rcu_head **nxttail;
97 long count; /* # of queued items */
97 struct rcu_head *curlist; 98 struct rcu_head *curlist;
98 struct rcu_head **curtail; 99 struct rcu_head **curtail;
99 struct rcu_head *donelist; 100 struct rcu_head *donelist;
diff --git a/include/linux/sunrpc/xprt.h b/include/linux/sunrpc/xprt.h
index 99cad3ead8..068e1fb086 100644
--- a/include/linux/sunrpc/xprt.h
+++ b/include/linux/sunrpc/xprt.h
@@ -211,6 +211,7 @@ int xprt_reserve_xprt(struct rpc_task *task);
211int xprt_reserve_xprt_cong(struct rpc_task *task); 211int xprt_reserve_xprt_cong(struct rpc_task *task);
212int xprt_prepare_transmit(struct rpc_task *task); 212int xprt_prepare_transmit(struct rpc_task *task);
213void xprt_transmit(struct rpc_task *task); 213void xprt_transmit(struct rpc_task *task);
214void xprt_abort_transmit(struct rpc_task *task);
214int xprt_adjust_timeout(struct rpc_rqst *req); 215int xprt_adjust_timeout(struct rpc_rqst *req);
215void xprt_release_xprt(struct rpc_xprt *xprt, struct rpc_task *task); 216void xprt_release_xprt(struct rpc_xprt *xprt, struct rpc_task *task);
216void xprt_release_xprt_cong(struct rpc_xprt *xprt, struct rpc_task *task); 217void xprt_release_xprt_cong(struct rpc_xprt *xprt, struct rpc_task *task);
diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
index ad85d3f0dc..7a51a5597c 100644
--- a/kernel/posix-cpu-timers.c
+++ b/kernel/posix-cpu-timers.c
@@ -424,6 +424,7 @@ static void cleanup_timers(struct list_head *head,
424 cputime_t ptime = cputime_add(utime, stime); 424 cputime_t ptime = cputime_add(utime, stime);
425 425
426 list_for_each_entry_safe(timer, next, head, entry) { 426 list_for_each_entry_safe(timer, next, head, entry) {
427 put_task_struct(timer->task);
427 timer->task = NULL; 428 timer->task = NULL;
428 list_del_init(&timer->entry); 429 list_del_init(&timer->entry);
429 if (cputime_lt(timer->expires.cpu, ptime)) { 430 if (cputime_lt(timer->expires.cpu, ptime)) {
@@ -436,6 +437,7 @@ static void cleanup_timers(struct list_head *head,
436 437
437 ++head; 438 ++head;
438 list_for_each_entry_safe(timer, next, head, entry) { 439 list_for_each_entry_safe(timer, next, head, entry) {
440 put_task_struct(timer->task);
439 timer->task = NULL; 441 timer->task = NULL;
440 list_del_init(&timer->entry); 442 list_del_init(&timer->entry);
441 if (cputime_lt(timer->expires.cpu, utime)) { 443 if (cputime_lt(timer->expires.cpu, utime)) {
@@ -448,6 +450,7 @@ static void cleanup_timers(struct list_head *head,
448 450
449 ++head; 451 ++head;
450 list_for_each_entry_safe(timer, next, head, entry) { 452 list_for_each_entry_safe(timer, next, head, entry) {
453 put_task_struct(timer->task);
451 timer->task = NULL; 454 timer->task = NULL;
452 list_del_init(&timer->entry); 455 list_del_init(&timer->entry);
453 if (timer->expires.sched < sched_time) { 456 if (timer->expires.sched < sched_time) {
diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
index bef3b6901b..2559d4b8f2 100644
--- a/kernel/rcupdate.c
+++ b/kernel/rcupdate.c
@@ -71,7 +71,7 @@ DEFINE_PER_CPU(struct rcu_data, rcu_bh_data) = { 0L };
71 71
72/* Fake initialization required by compiler */ 72/* Fake initialization required by compiler */
73static DEFINE_PER_CPU(struct tasklet_struct, rcu_tasklet) = {NULL}; 73static DEFINE_PER_CPU(struct tasklet_struct, rcu_tasklet) = {NULL};
74static int maxbatch = 10; 74static int maxbatch = 10000;
75 75
76#ifndef __HAVE_ARCH_CMPXCHG 76#ifndef __HAVE_ARCH_CMPXCHG
77/* 77/*
@@ -109,6 +109,10 @@ void fastcall call_rcu(struct rcu_head *head,
109 rdp = &__get_cpu_var(rcu_data); 109 rdp = &__get_cpu_var(rcu_data);
110 *rdp->nxttail = head; 110 *rdp->nxttail = head;
111 rdp->nxttail = &head->next; 111 rdp->nxttail = &head->next;
112
113 if (unlikely(++rdp->count > 10000))
114 set_need_resched();
115
112 local_irq_restore(flags); 116 local_irq_restore(flags);
113} 117}
114 118
@@ -140,6 +144,12 @@ void fastcall call_rcu_bh(struct rcu_head *head,
140 rdp = &__get_cpu_var(rcu_bh_data); 144 rdp = &__get_cpu_var(rcu_bh_data);
141 *rdp->nxttail = head; 145 *rdp->nxttail = head;
142 rdp->nxttail = &head->next; 146 rdp->nxttail = &head->next;
147 rdp->count++;
148/*
149 * Should we directly call rcu_do_batch() here ?
150 * if (unlikely(rdp->count > 10000))
151 * rcu_do_batch(rdp);
152 */
143 local_irq_restore(flags); 153 local_irq_restore(flags);
144} 154}
145 155
@@ -157,6 +167,7 @@ static void rcu_do_batch(struct rcu_data *rdp)
157 next = rdp->donelist = list->next; 167 next = rdp->donelist = list->next;
158 list->func(list); 168 list->func(list);
159 list = next; 169 list = next;
170 rdp->count--;
160 if (++count >= maxbatch) 171 if (++count >= maxbatch)
161 break; 172 break;
162 } 173 }
diff --git a/kernel/time.c b/kernel/time.c
index dd5ae1162a..40c2410ac9 100644
--- a/kernel/time.c
+++ b/kernel/time.c
@@ -570,6 +570,7 @@ void getnstimeofday(struct timespec *tv)
570 tv->tv_sec = x.tv_sec; 570 tv->tv_sec = x.tv_sec;
571 tv->tv_nsec = x.tv_usec * NSEC_PER_USEC; 571 tv->tv_nsec = x.tv_usec * NSEC_PER_USEC;
572} 572}
573EXPORT_SYMBOL_GPL(getnstimeofday);
573#endif 574#endif
574 575
575#if (BITS_PER_LONG < 64) 576#if (BITS_PER_LONG < 64)
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 0ea71e887b..64f9570cff 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -511,10 +511,11 @@ static int shrink_list(struct list_head *page_list, struct scan_control *sc)
511 * PageDirty _after_ making sure that the page is freeable and 511 * PageDirty _after_ making sure that the page is freeable and
512 * not in use by anybody. (pagecache + us == 2) 512 * not in use by anybody. (pagecache + us == 2)
513 */ 513 */
514 if (page_count(page) != 2 || PageDirty(page)) { 514 if (unlikely(page_count(page) != 2))
515 write_unlock_irq(&mapping->tree_lock); 515 goto cannot_free;
516 goto keep_locked; 516 smp_rmb();
517 } 517 if (unlikely(PageDirty(page)))
518 goto cannot_free;
518 519
519#ifdef CONFIG_SWAP 520#ifdef CONFIG_SWAP
520 if (PageSwapCache(page)) { 521 if (PageSwapCache(page)) {
@@ -538,6 +539,10 @@ free_it:
538 __pagevec_release_nonlru(&freed_pvec); 539 __pagevec_release_nonlru(&freed_pvec);
539 continue; 540 continue;
540 541
542cannot_free:
543 write_unlock_irq(&mapping->tree_lock);
544 goto keep_locked;
545
541activate_locked: 546activate_locked:
542 SetPageActive(page); 547 SetPageActive(page);
543 pgactivate++; 548 pgactivate++;
diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
index b03e90649e..21deec25a1 100644
--- a/net/ipv6/netfilter/ip6_tables.c
+++ b/net/ipv6/netfilter/ip6_tables.c
@@ -975,7 +975,6 @@ replace_table(struct ip6t_table *table,
975 struct ip6t_entry *table_base; 975 struct ip6t_entry *table_base;
976 unsigned int i; 976 unsigned int i;
977 977
978 for (i = 0; i < num_possible_cpus(); i++) {
979 for_each_cpu(i) { 978 for_each_cpu(i) {
980 table_base = 979 table_base =
981 (void *)newinfo->entries 980 (void *)newinfo->entries
diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
index 5a8f01d726..5342740563 100644
--- a/net/sunrpc/clnt.c
+++ b/net/sunrpc/clnt.c
@@ -678,13 +678,11 @@ call_allocate(struct rpc_task *task)
678static void 678static void
679call_encode(struct rpc_task *task) 679call_encode(struct rpc_task *task)
680{ 680{
681 struct rpc_clnt *clnt = task->tk_client;
682 struct rpc_rqst *req = task->tk_rqstp; 681 struct rpc_rqst *req = task->tk_rqstp;
683 struct xdr_buf *sndbuf = &req->rq_snd_buf; 682 struct xdr_buf *sndbuf = &req->rq_snd_buf;
684 struct xdr_buf *rcvbuf = &req->rq_rcv_buf; 683 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
685 unsigned int bufsiz; 684 unsigned int bufsiz;
686 kxdrproc_t encode; 685 kxdrproc_t encode;
687 int status;
688 u32 *p; 686 u32 *p;
689 687
690 dprintk("RPC: %4d call_encode (status %d)\n", 688 dprintk("RPC: %4d call_encode (status %d)\n",
@@ -712,12 +710,9 @@ call_encode(struct rpc_task *task)
712 rpc_exit(task, -EIO); 710 rpc_exit(task, -EIO);
713 return; 711 return;
714 } 712 }
715 if (encode && (status = rpcauth_wrap_req(task, encode, req, p, 713 if (encode != NULL)
716 task->tk_msg.rpc_argp)) < 0) { 714 task->tk_status = rpcauth_wrap_req(task, encode, req, p,
717 printk(KERN_WARNING "%s: can't encode arguments: %d\n", 715 task->tk_msg.rpc_argp);
718 clnt->cl_protname, -status);
719 rpc_exit(task, status);
720 }
721} 716}
722 717
723/* 718/*
@@ -759,7 +754,8 @@ call_bind_status(struct rpc_task *task)
759 case -EACCES: 754 case -EACCES:
760 dprintk("RPC: %4d remote rpcbind: RPC program/version unavailable\n", 755 dprintk("RPC: %4d remote rpcbind: RPC program/version unavailable\n",
761 task->tk_pid); 756 task->tk_pid);
762 break; 757 rpc_delay(task, 3*HZ);
758 goto retry_bind;
763 case -ETIMEDOUT: 759 case -ETIMEDOUT:
764 dprintk("RPC: %4d rpcbind request timed out\n", 760 dprintk("RPC: %4d rpcbind request timed out\n",
765 task->tk_pid); 761 task->tk_pid);
@@ -864,10 +860,12 @@ call_transmit(struct rpc_task *task)
864 if (task->tk_status != 0) 860 if (task->tk_status != 0)
865 return; 861 return;
866 /* Encode here so that rpcsec_gss can use correct sequence number. */ 862 /* Encode here so that rpcsec_gss can use correct sequence number. */
867 if (!task->tk_rqstp->rq_bytes_sent) 863 if (task->tk_rqstp->rq_bytes_sent == 0) {
868 call_encode(task); 864 call_encode(task);
869 if (task->tk_status < 0) 865 /* Did the encode result in an error condition? */
870 return; 866 if (task->tk_status != 0)
867 goto out_nosend;
868 }
871 xprt_transmit(task); 869 xprt_transmit(task);
872 if (task->tk_status < 0) 870 if (task->tk_status < 0)
873 return; 871 return;
@@ -875,6 +873,10 @@ call_transmit(struct rpc_task *task)
875 task->tk_action = NULL; 873 task->tk_action = NULL;
876 rpc_wake_up_task(task); 874 rpc_wake_up_task(task);
877 } 875 }
876 return;
877out_nosend:
878 /* release socket write lock before attempting to handle error */
879 xprt_abort_transmit(task);
878} 880}
879 881
880/* 882/*
diff --git a/net/sunrpc/xprt.c b/net/sunrpc/xprt.c
index 215be0d0ef..1ba55dc38b 100644
--- a/net/sunrpc/xprt.c
+++ b/net/sunrpc/xprt.c
@@ -709,6 +709,14 @@ out_unlock:
709 return err; 709 return err;
710} 710}
711 711
712void
713xprt_abort_transmit(struct rpc_task *task)
714{
715 struct rpc_xprt *xprt = task->tk_xprt;
716
717 xprt_release_write(xprt, task);
718}
719
712/** 720/**
713 * xprt_transmit - send an RPC request on a transport 721 * xprt_transmit - send an RPC request on a transport
714 * @task: controlling RPC task 722 * @task: controlling RPC task