Magellan Linux

Contents of /trunk/kernel26-magellan-server/patches-2.6.27-r2/0107-2.6.27.8-all-fixes.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 728 - (show annotations) (download)
Tue Dec 23 09:41:15 2008 UTC (15 years, 10 months ago) by niro
File size: 249928 byte(s)
-ver bump to 2.6.27-r2:
- updated to linux-2.6.27.10
- using tuxonice current-20081025
- adjusted kernel-configs to use tuxonice and enabled ufs filesystem support

1 diff --git a/Documentation/filesystems/proc.txt b/Documentation/filesystems/proc.txt
2 index f566ad9..23f3edc 100644
3 --- a/Documentation/filesystems/proc.txt
4 +++ b/Documentation/filesystems/proc.txt
5 @@ -44,6 +44,7 @@ Table of Contents
6 2.14 /proc/<pid>/io - Display the IO accounting fields
7 2.15 /proc/<pid>/coredump_filter - Core dump filtering settings
8 2.16 /proc/<pid>/mountinfo - Information about mounts
9 + 2.17 /proc/sys/fs/epoll - Configuration options for the epoll interface
10
11 ------------------------------------------------------------------------------
12 Preface
13 @@ -2471,4 +2472,30 @@ For more information on mount propagation see:
14
15 Documentation/filesystems/sharedsubtree.txt
16
17 +2.17 /proc/sys/fs/epoll - Configuration options for the epoll interface
18 +--------------------------------------------------------
19 +
20 +This directory contains configuration options for the epoll(7) interface.
21 +
22 +max_user_instances
23 +------------------
24 +
25 +This is the maximum number of epoll file descriptors that a single user can
26 +have open at a given time. The default value is 128, and should be enough
27 +for normal users.
28 +
29 +max_user_watches
30 +----------------
31 +
32 +Every epoll file descriptor can store a number of files to be monitored
33 +for event readiness. Each one of these monitored files constitutes a "watch".
34 +This configuration option sets the maximum number of "watches" that are
35 +allowed for each user.
36 +Each "watch" costs roughly 90 bytes on a 32bit kernel, and roughly 160 bytes
37 +on a 64bit one.
38 +The current default value for max_user_watches is the 1/32 of the available
39 +low memory, divided for the "watch" cost in bytes.
40 +
41 +
42 ------------------------------------------------------------------------------
43 +
44 diff --git a/arch/ia64/kernel/acpi.c b/arch/ia64/kernel/acpi.c
45 index 5d1eb7e..8a7e508 100644
46 --- a/arch/ia64/kernel/acpi.c
47 +++ b/arch/ia64/kernel/acpi.c
48 @@ -656,6 +656,30 @@ static int __init acpi_parse_fadt(struct acpi_table_header *table)
49 return 0;
50 }
51
52 +int __init early_acpi_boot_init(void)
53 +{
54 + int ret;
55 +
56 + /*
57 + * do a partial walk of MADT to determine how many CPUs
58 + * we have including offline CPUs
59 + */
60 + if (acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
61 + printk(KERN_ERR PREFIX "Can't find MADT\n");
62 + return 0;
63 + }
64 +
65 + ret = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC,
66 + acpi_parse_lsapic, NR_CPUS);
67 + if (ret < 1)
68 + printk(KERN_ERR PREFIX
69 + "Error parsing MADT - no LAPIC entries\n");
70 +
71 + return 0;
72 +}
73 +
74 +
75 +
76 int __init acpi_boot_init(void)
77 {
78
79 @@ -679,11 +703,6 @@ int __init acpi_boot_init(void)
80 printk(KERN_ERR PREFIX
81 "Error parsing LAPIC address override entry\n");
82
83 - if (acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC, acpi_parse_lsapic, NR_CPUS)
84 - < 1)
85 - printk(KERN_ERR PREFIX
86 - "Error parsing MADT - no LAPIC entries\n");
87 -
88 if (acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_NMI, acpi_parse_lapic_nmi, 0)
89 < 0)
90 printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
91 diff --git a/arch/ia64/kernel/setup.c b/arch/ia64/kernel/setup.c
92 index de636b2..6030236 100644
93 --- a/arch/ia64/kernel/setup.c
94 +++ b/arch/ia64/kernel/setup.c
95 @@ -549,8 +549,12 @@ setup_arch (char **cmdline_p)
96 #ifdef CONFIG_ACPI
97 /* Initialize the ACPI boot-time table parser */
98 acpi_table_init();
99 + early_acpi_boot_init();
100 # ifdef CONFIG_ACPI_NUMA
101 acpi_numa_init();
102 +#ifdef CONFIG_ACPI_HOTPLUG_CPU
103 + prefill_possible_map();
104 +#endif
105 per_cpu_scan_finalize((cpus_weight(early_cpu_possible_map) == 0 ?
106 32 : cpus_weight(early_cpu_possible_map)),
107 additional_cpus > 0 ? additional_cpus : 0);
108 @@ -841,9 +845,6 @@ void __init
109 setup_per_cpu_areas (void)
110 {
111 /* start_kernel() requires this... */
112 -#ifdef CONFIG_ACPI_HOTPLUG_CPU
113 - prefill_possible_map();
114 -#endif
115 }
116
117 /*
118 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
119 index 675f1d0..4c771cd 100644
120 --- a/arch/parisc/kernel/traps.c
121 +++ b/arch/parisc/kernel/traps.c
122 @@ -24,7 +24,6 @@
123 #include <linux/init.h>
124 #include <linux/interrupt.h>
125 #include <linux/console.h>
126 -#include <linux/kallsyms.h>
127 #include <linux/bug.h>
128
129 #include <asm/assembly.h>
130 @@ -51,7 +50,7 @@
131 DEFINE_SPINLOCK(pa_dbit_lock);
132 #endif
133
134 -void parisc_show_stack(struct task_struct *t, unsigned long *sp,
135 +static void parisc_show_stack(struct task_struct *task, unsigned long *sp,
136 struct pt_regs *regs);
137
138 static int printbinary(char *buf, unsigned long x, int nbits)
139 @@ -121,18 +120,19 @@ static void print_fr(char *level, struct pt_regs *regs)
140
141 void show_regs(struct pt_regs *regs)
142 {
143 - int i;
144 + int i, user;
145 char *level;
146 unsigned long cr30, cr31;
147
148 - level = user_mode(regs) ? KERN_DEBUG : KERN_CRIT;
149 + user = user_mode(regs);
150 + level = user ? KERN_DEBUG : KERN_CRIT;
151
152 print_gr(level, regs);
153
154 for (i = 0; i < 8; i += 4)
155 PRINTREGS(level, regs->sr, "sr", RFMT, i);
156
157 - if (user_mode(regs))
158 + if (user)
159 print_fr(level, regs);
160
161 cr30 = mfctl(30);
162 @@ -145,14 +145,18 @@ void show_regs(struct pt_regs *regs)
163 printk("%s CPU: %8d CR30: " RFMT " CR31: " RFMT "\n",
164 level, current_thread_info()->cpu, cr30, cr31);
165 printk("%s ORIG_R28: " RFMT "\n", level, regs->orig_r28);
166 - printk(level);
167 - print_symbol(" IAOQ[0]: %s\n", regs->iaoq[0]);
168 - printk(level);
169 - print_symbol(" IAOQ[1]: %s\n", regs->iaoq[1]);
170 - printk(level);
171 - print_symbol(" RP(r2): %s\n", regs->gr[2]);
172 -
173 - parisc_show_stack(current, NULL, regs);
174 +
175 + if (user) {
176 + printk("%s IAOQ[0]: " RFMT "\n", level, regs->iaoq[0]);
177 + printk("%s IAOQ[1]: " RFMT "\n", level, regs->iaoq[1]);
178 + printk("%s RP(r2): " RFMT "\n", level, regs->gr[2]);
179 + } else {
180 + printk("%s IAOQ[0]: %pS\n", level, (void *) regs->iaoq[0]);
181 + printk("%s IAOQ[1]: %pS\n", level, (void *) regs->iaoq[1]);
182 + printk("%s RP(r2): %pS\n", level, (void *) regs->gr[2]);
183 +
184 + parisc_show_stack(current, NULL, regs);
185 + }
186 }
187
188
189 @@ -173,20 +177,15 @@ static void do_show_stack(struct unwind_frame_info *info)
190 break;
191
192 if (__kernel_text_address(info->ip)) {
193 - printk("%s [<" RFMT ">] ", (i&0x3)==1 ? KERN_CRIT : "", info->ip);
194 -#ifdef CONFIG_KALLSYMS
195 - print_symbol("%s\n", info->ip);
196 -#else
197 - if ((i & 0x03) == 0)
198 - printk("\n");
199 -#endif
200 + printk(KERN_CRIT " [<" RFMT ">] %pS\n",
201 + info->ip, (void *) info->ip);
202 i++;
203 }
204 }
205 - printk("\n");
206 + printk(KERN_CRIT "\n");
207 }
208
209 -void parisc_show_stack(struct task_struct *task, unsigned long *sp,
210 +static void parisc_show_stack(struct task_struct *task, unsigned long *sp,
211 struct pt_regs *regs)
212 {
213 struct unwind_frame_info info;
214 diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
215 index 010a51f..d5c3b45 100644
216 --- a/arch/powerpc/platforms/cell/spufs/file.c
217 +++ b/arch/powerpc/platforms/cell/spufs/file.c
218 @@ -390,6 +390,9 @@ static int spufs_ps_fault(struct vm_area_struct *vma,
219 if (offset >= ps_size)
220 return VM_FAULT_SIGBUS;
221
222 + if (fatal_signal_pending(current))
223 + return VM_FAULT_SIGBUS;
224 +
225 /*
226 * Because we release the mmap_sem, the context may be destroyed while
227 * we're in spu_wait. Grab an extra reference so it isn't destroyed
228 diff --git a/arch/powerpc/platforms/cell/spufs/inode.c b/arch/powerpc/platforms/cell/spufs/inode.c
229 index 690ca7b..5c73b62 100644
230 --- a/arch/powerpc/platforms/cell/spufs/inode.c
231 +++ b/arch/powerpc/platforms/cell/spufs/inode.c
232 @@ -496,6 +496,8 @@ spufs_create_context(struct inode *inode, struct dentry *dentry,
233 ret = spufs_context_open(dget(dentry), mntget(mnt));
234 if (ret < 0) {
235 WARN_ON(spufs_rmdir(inode, dentry));
236 + if (affinity)
237 + mutex_unlock(&gang->aff_mutex);
238 mutex_unlock(&inode->i_mutex);
239 spu_forget(SPUFS_I(dentry->d_inode)->i_ctx);
240 goto out;
241 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
242 index c102af8..7d58e7f 100644
243 --- a/arch/x86/kernel/acpi/boot.c
244 +++ b/arch/x86/kernel/acpi/boot.c
245 @@ -1593,6 +1593,11 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
246 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
247 },
248 },
249 + {}
250 +};
251 +
252 +/* second table for DMI checks that should run after early-quirks */
253 +static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
254 /*
255 * HP laptops which use a DSDT reporting as HP/SB400/10000,
256 * which includes some code which overrides all temperature
257 @@ -1721,6 +1726,9 @@ int __init early_acpi_boot_init(void)
258
259 int __init acpi_boot_init(void)
260 {
261 + /* those are executed after early-quirks are executed */
262 + dmi_check_system(acpi_dmi_table_late);
263 +
264 /*
265 * If acpi_disabled, bail out
266 * One exception: acpi=ht continues far enough to enumerate LAPICs
267 diff --git a/arch/x86/kernel/cpu/cpufreq/powernow-k8.c b/arch/x86/kernel/cpu/cpufreq/powernow-k8.c
268 index 84bb395..20bda8c 100644
269 --- a/arch/x86/kernel/cpu/cpufreq/powernow-k8.c
270 +++ b/arch/x86/kernel/cpu/cpufreq/powernow-k8.c
271 @@ -116,9 +116,20 @@ static int query_current_values_with_pending_wait(struct powernow_k8_data *data)
272 u32 i = 0;
273
274 if (cpu_family == CPU_HW_PSTATE) {
275 - rdmsr(MSR_PSTATE_STATUS, lo, hi);
276 - i = lo & HW_PSTATE_MASK;
277 - data->currpstate = i;
278 + if (data->currpstate == HW_PSTATE_INVALID) {
279 + /* read (initial) hw pstate if not yet set */
280 + rdmsr(MSR_PSTATE_STATUS, lo, hi);
281 + i = lo & HW_PSTATE_MASK;
282 +
283 + /*
284 + * a workaround for family 11h erratum 311 might cause
285 + * an "out-of-range Pstate if the core is in Pstate-0
286 + */
287 + if (i >= data->numps)
288 + data->currpstate = HW_PSTATE_0;
289 + else
290 + data->currpstate = i;
291 + }
292 return 0;
293 }
294 do {
295 @@ -1117,6 +1128,7 @@ static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol)
296 }
297
298 data->cpu = pol->cpu;
299 + data->currpstate = HW_PSTATE_INVALID;
300
301 if (powernow_k8_cpu_init_acpi(data)) {
302 /*
303 diff --git a/arch/x86/kernel/cpu/cpufreq/powernow-k8.h b/arch/x86/kernel/cpu/cpufreq/powernow-k8.h
304 index ab48cfe..65cfb5d 100644
305 --- a/arch/x86/kernel/cpu/cpufreq/powernow-k8.h
306 +++ b/arch/x86/kernel/cpu/cpufreq/powernow-k8.h
307 @@ -5,6 +5,19 @@
308 * http://www.gnu.org/licenses/gpl.html
309 */
310
311 +
312 +enum pstate {
313 + HW_PSTATE_INVALID = 0xff,
314 + HW_PSTATE_0 = 0,
315 + HW_PSTATE_1 = 1,
316 + HW_PSTATE_2 = 2,
317 + HW_PSTATE_3 = 3,
318 + HW_PSTATE_4 = 4,
319 + HW_PSTATE_5 = 5,
320 + HW_PSTATE_6 = 6,
321 + HW_PSTATE_7 = 7,
322 +};
323 +
324 struct powernow_k8_data {
325 unsigned int cpu;
326
327 @@ -23,7 +36,9 @@ struct powernow_k8_data {
328 u32 exttype; /* extended interface = 1 */
329
330 /* keep track of the current fid / vid or pstate */
331 - u32 currvid, currfid, currpstate;
332 + u32 currvid;
333 + u32 currfid;
334 + enum pstate currpstate;
335
336 /* the powernow_table includes all frequency and vid/fid pairings:
337 * fid are the lower 8 bits of the index, vid are the upper 8 bits.
338 diff --git a/arch/x86/kernel/early-quirks.c b/arch/x86/kernel/early-quirks.c
339 index 6b839b1..1b894b7 100644
340 --- a/arch/x86/kernel/early-quirks.c
341 +++ b/arch/x86/kernel/early-quirks.c
342 @@ -95,7 +95,8 @@ static void __init nvidia_bugs(int num, int slot, int func)
343
344 }
345
346 -static u32 ati_ixp4x0_rev(int num, int slot, int func)
347 +#if defined(CONFIG_ACPI) && defined(CONFIG_X86_IO_APIC)
348 +static u32 __init ati_ixp4x0_rev(int num, int slot, int func)
349 {
350 u32 d;
351 u8 b;
352 @@ -115,7 +116,6 @@ static u32 ati_ixp4x0_rev(int num, int slot, int func)
353
354 static void __init ati_bugs(int num, int slot, int func)
355 {
356 -#if defined(CONFIG_ACPI) && defined (CONFIG_X86_IO_APIC)
357 u32 d;
358 u8 b;
359
360 @@ -138,9 +138,56 @@ static void __init ati_bugs(int num, int slot, int func)
361 printk(KERN_INFO "If you got timer trouble "
362 "try acpi_use_timer_override\n");
363 }
364 -#endif
365 }
366
367 +static u32 __init ati_sbx00_rev(int num, int slot, int func)
368 +{
369 + u32 old, d;
370 +
371 + d = read_pci_config(num, slot, func, 0x70);
372 + old = d;
373 + d &= ~(1<<8);
374 + write_pci_config(num, slot, func, 0x70, d);
375 + d = read_pci_config(num, slot, func, 0x8);
376 + d &= 0xff;
377 + write_pci_config(num, slot, func, 0x70, old);
378 +
379 + return d;
380 +}
381 +
382 +static void __init ati_bugs_contd(int num, int slot, int func)
383 +{
384 + u32 d, rev;
385 +
386 + if (acpi_use_timer_override)
387 + return;
388 +
389 + rev = ati_sbx00_rev(num, slot, func);
390 + if (rev > 0x13)
391 + return;
392 +
393 + /* check for IRQ0 interrupt swap */
394 + d = read_pci_config(num, slot, func, 0x64);
395 + if (!(d & (1<<14)))
396 + acpi_skip_timer_override = 1;
397 +
398 + if (acpi_skip_timer_override) {
399 + printk(KERN_INFO "SB600 revision 0x%x\n", rev);
400 + printk(KERN_INFO "Ignoring ACPI timer override.\n");
401 + printk(KERN_INFO "If you got timer trouble "
402 + "try acpi_use_timer_override\n");
403 + }
404 +}
405 +#else
406 +static void __init ati_bugs(int num, int slot, int func)
407 +{
408 +}
409 +
410 +static void __init ati_bugs_contd(int num, int slot, int func)
411 +{
412 +}
413 +#endif
414 +
415 #define QFLAG_APPLY_ONCE 0x1
416 #define QFLAG_APPLIED 0x2
417 #define QFLAG_DONE (QFLAG_APPLY_ONCE|QFLAG_APPLIED)
418 @@ -162,6 +209,8 @@ static struct chipset early_qrk[] __initdata = {
419 PCI_CLASS_BRIDGE_HOST, PCI_ANY_ID, 0, fix_hypertransport_config },
420 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_SMBUS,
421 PCI_CLASS_SERIAL_SMBUS, PCI_ANY_ID, 0, ati_bugs },
422 + { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS,
423 + PCI_CLASS_SERIAL_SMBUS, PCI_ANY_ID, 0, ati_bugs_contd },
424 {}
425 };
426
427 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
428 index 64b5c42..7667443 100644
429 --- a/arch/x86/kernel/setup.c
430 +++ b/arch/x86/kernel/setup.c
431 @@ -604,7 +604,7 @@ static struct dmi_system_id __initdata bad_bios_dmi_table[] = {
432 .callback = dmi_low_memory_corruption,
433 .ident = "Phoenix BIOS",
434 .matches = {
435 - DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies, LTD"),
436 + DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies"),
437 },
438 },
439 #endif
440 diff --git a/arch/x86/mm/discontig_32.c b/arch/x86/mm/discontig_32.c
441 index 62fa440..62aec7e 100644
442 --- a/arch/x86/mm/discontig_32.c
443 +++ b/arch/x86/mm/discontig_32.c
444 @@ -222,6 +222,41 @@ static void __init remap_numa_kva(void)
445 }
446 }
447
448 +#ifdef CONFIG_HIBERNATION
449 +/**
450 + * resume_map_numa_kva - add KVA mapping to the temporary page tables created
451 + * during resume from hibernation
452 + * @pgd_base - temporary resume page directory
453 + */
454 +void resume_map_numa_kva(pgd_t *pgd_base)
455 +{
456 + int node;
457 +
458 + for_each_online_node(node) {
459 + unsigned long start_va, start_pfn, size, pfn;
460 +
461 + start_va = (unsigned long)node_remap_start_vaddr[node];
462 + start_pfn = node_remap_start_pfn[node];
463 + size = node_remap_size[node];
464 +
465 + printk(KERN_DEBUG "%s: node %d\n", __FUNCTION__, node);
466 +
467 + for (pfn = 0; pfn < size; pfn += PTRS_PER_PTE) {
468 + unsigned long vaddr = start_va + (pfn << PAGE_SHIFT);
469 + pgd_t *pgd = pgd_base + pgd_index(vaddr);
470 + pud_t *pud = pud_offset(pgd, vaddr);
471 + pmd_t *pmd = pmd_offset(pud, vaddr);
472 +
473 + set_pmd(pmd, pfn_pmd(start_pfn + pfn,
474 + PAGE_KERNEL_LARGE_EXEC));
475 +
476 + printk(KERN_DEBUG "%s: %08lx -> pfn %08lx\n",
477 + __FUNCTION__, vaddr, start_pfn + pfn);
478 + }
479 + }
480 +}
481 +#endif
482 +
483 static unsigned long calculate_numa_remap_pages(void)
484 {
485 int nid;
486 diff --git a/arch/x86/power/hibernate_32.c b/arch/x86/power/hibernate_32.c
487 index f2b6e3f..81197c6 100644
488 --- a/arch/x86/power/hibernate_32.c
489 +++ b/arch/x86/power/hibernate_32.c
490 @@ -12,6 +12,7 @@
491 #include <asm/system.h>
492 #include <asm/page.h>
493 #include <asm/pgtable.h>
494 +#include <asm/mmzone.h>
495
496 /* Defined in hibernate_asm_32.S */
497 extern int restore_image(void);
498 @@ -127,6 +128,9 @@ static int resume_physical_mapping_init(pgd_t *pgd_base)
499 }
500 }
501 }
502 +
503 + resume_map_numa_kva(pgd_base);
504 +
505 return 0;
506 }
507
508 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
509 index a4e201b..6bbcf8a 100644
510 --- a/arch/x86/xen/enlighten.c
511 +++ b/arch/x86/xen/enlighten.c
512 @@ -1413,7 +1413,7 @@ static void __init xen_reserve_top(void)
513 if (HYPERVISOR_xen_version(XENVER_platform_parameters, &pp) == 0)
514 top = pp.virt_start;
515
516 - reserve_top_address(-top + 2 * PAGE_SIZE);
517 + reserve_top_address(-top);
518 #endif /* CONFIG_X86_32 */
519 }
520
521 diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
522 index 41b8e7c..9ab3fb9 100644
523 --- a/drivers/acpi/ec.c
524 +++ b/drivers/acpi/ec.c
525 @@ -219,7 +219,8 @@ static void gpe_transaction(struct acpi_ec *ec, u8 status)
526 goto unlock;
527 err:
528 /* false interrupt, state didn't change */
529 - ++ec->curr->irq_count;
530 + if (in_interrupt())
531 + ++ec->curr->irq_count;
532 unlock:
533 spin_unlock_irqrestore(&ec->curr_lock, flags);
534 }
535 diff --git a/drivers/acpi/pci_slot.c b/drivers/acpi/pci_slot.c
536 index d5b4ef8..8d4a568 100644
537 --- a/drivers/acpi/pci_slot.c
538 +++ b/drivers/acpi/pci_slot.c
539 @@ -150,7 +150,7 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
540 }
541
542 snprintf(name, sizeof(name), "%u", (u32)sun);
543 - pci_slot = pci_create_slot(pci_bus, device, name);
544 + pci_slot = pci_create_slot(pci_bus, device, name, NULL);
545 if (IS_ERR(pci_slot)) {
546 err("pci_create_slot returned %ld\n", PTR_ERR(pci_slot));
547 kfree(slot);
548 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
549 index 8228ae3..b551cda 100644
550 --- a/drivers/ata/libata-core.c
551 +++ b/drivers/ata/libata-core.c
552 @@ -551,7 +551,7 @@ u64 ata_tf_read_block(struct ata_taskfile *tf, struct ata_device *dev)
553 if (tf->flags & ATA_TFLAG_LBA48) {
554 block |= (u64)tf->hob_lbah << 40;
555 block |= (u64)tf->hob_lbam << 32;
556 - block |= tf->hob_lbal << 24;
557 + block |= (u64)tf->hob_lbal << 24;
558 } else
559 block |= (tf->device & 0xf) << 24;
560
561 @@ -1207,7 +1207,7 @@ u64 ata_tf_to_lba48(const struct ata_taskfile *tf)
562
563 sectors |= ((u64)(tf->hob_lbah & 0xff)) << 40;
564 sectors |= ((u64)(tf->hob_lbam & 0xff)) << 32;
565 - sectors |= (tf->hob_lbal & 0xff) << 24;
566 + sectors |= ((u64)(tf->hob_lbal & 0xff)) << 24;
567 sectors |= (tf->lbah & 0xff) << 16;
568 sectors |= (tf->lbam & 0xff) << 8;
569 sectors |= (tf->lbal & 0xff);
570 @@ -2428,6 +2428,13 @@ int ata_dev_configure(struct ata_device *dev)
571 }
572 }
573
574 + if ((dev->horkage & ATA_HORKAGE_FIRMWARE_WARN) && print_info) {
575 + ata_dev_printk(dev, KERN_WARNING, "WARNING: device requires "
576 + "firmware update to be fully functional.\n");
577 + ata_dev_printk(dev, KERN_WARNING, " contact the vendor "
578 + "or visit http://ata.wiki.kernel.org.\n");
579 + }
580 +
581 return 0;
582
583 err_out_nosup:
584 @@ -3971,6 +3978,20 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
585 { "ST380817AS", "3.42", ATA_HORKAGE_NONCQ },
586 { "ST3160023AS", "3.42", ATA_HORKAGE_NONCQ },
587
588 + /* Seagate NCQ + FLUSH CACHE firmware bug */
589 + { "ST31500341AS", "9JU138", ATA_HORKAGE_NONCQ |
590 + ATA_HORKAGE_FIRMWARE_WARN },
591 + { "ST31000333AS", "9FZ136", ATA_HORKAGE_NONCQ |
592 + ATA_HORKAGE_FIRMWARE_WARN },
593 + { "ST3640623AS", "9FZ164", ATA_HORKAGE_NONCQ |
594 + ATA_HORKAGE_FIRMWARE_WARN },
595 + { "ST3640323AS", "9FZ134", ATA_HORKAGE_NONCQ |
596 + ATA_HORKAGE_FIRMWARE_WARN },
597 + { "ST3320813AS", "9FZ182", ATA_HORKAGE_NONCQ |
598 + ATA_HORKAGE_FIRMWARE_WARN },
599 + { "ST3320613AS", "9FZ162", ATA_HORKAGE_NONCQ |
600 + ATA_HORKAGE_FIRMWARE_WARN },
601 +
602 /* Blacklist entries taken from Silicon Image 3124/3132
603 Windows driver .inf file - also several Linux problem reports */
604 { "HTS541060G9SA00", "MB3OC60D", ATA_HORKAGE_NONCQ, },
605 diff --git a/drivers/firewire/fw-sbp2.c b/drivers/firewire/fw-sbp2.c
606 index 4f73537..64142c1 100644
607 --- a/drivers/firewire/fw-sbp2.c
608 +++ b/drivers/firewire/fw-sbp2.c
609 @@ -365,6 +365,11 @@ static const struct {
610 },
611 /* iPod mini */ {
612 .firmware_revision = 0x0a2700,
613 + .model = 0x000022,
614 + .workarounds = SBP2_WORKAROUND_FIX_CAPACITY,
615 + },
616 + /* iPod mini */ {
617 + .firmware_revision = 0x0a2700,
618 .model = 0x000023,
619 .workarounds = SBP2_WORKAROUND_FIX_CAPACITY,
620 },
621 diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
622 index 59f6ad8..9ed5947 100644
623 --- a/drivers/gpio/gpiolib.c
624 +++ b/drivers/gpio/gpiolib.c
625 @@ -1049,7 +1049,7 @@ static void gpiolib_dbg_show(struct seq_file *s, struct gpio_chip *chip)
626 continue;
627
628 is_out = test_bit(FLAG_IS_OUT, &gdesc->flags);
629 - seq_printf(s, " gpio-%-3d (%-12s) %s %s",
630 + seq_printf(s, " gpio-%-3d (%-20.20s) %s %s",
631 gpio, gdesc->label,
632 is_out ? "out" : "in ",
633 chip->get
634 diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c
635 index 1d6ad34..bad46ea 100644
636 --- a/drivers/ieee1394/sbp2.c
637 +++ b/drivers/ieee1394/sbp2.c
638 @@ -402,6 +402,11 @@ static const struct {
639 },
640 /* iPod mini */ {
641 .firmware_revision = 0x0a2700,
642 + .model_id = 0x000022,
643 + .workarounds = SBP2_WORKAROUND_FIX_CAPACITY,
644 + },
645 + /* iPod mini */ {
646 + .firmware_revision = 0x0a2700,
647 .model_id = 0x000023,
648 .workarounds = SBP2_WORKAROUND_FIX_CAPACITY,
649 },
650 diff --git a/drivers/infiniband/hw/mlx4/cq.c b/drivers/infiniband/hw/mlx4/cq.c
651 index d0866a3..1830849 100644
652 --- a/drivers/infiniband/hw/mlx4/cq.c
653 +++ b/drivers/infiniband/hw/mlx4/cq.c
654 @@ -343,6 +343,7 @@ int mlx4_ib_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
655 {
656 struct mlx4_ib_dev *dev = to_mdev(ibcq->device);
657 struct mlx4_ib_cq *cq = to_mcq(ibcq);
658 + struct mlx4_mtt mtt;
659 int outst_cqe;
660 int err;
661
662 @@ -376,10 +377,13 @@ int mlx4_ib_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
663 goto out;
664 }
665
666 + mtt = cq->buf.mtt;
667 +
668 err = mlx4_cq_resize(dev->dev, &cq->mcq, entries, &cq->resize_buf->buf.mtt);
669 if (err)
670 goto err_buf;
671
672 + mlx4_mtt_cleanup(dev->dev, &mtt);
673 if (ibcq->uobject) {
674 cq->buf = cq->resize_buf->buf;
675 cq->ibcq.cqe = cq->resize_buf->cqe;
676 @@ -406,6 +410,7 @@ int mlx4_ib_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
677 goto out;
678
679 err_buf:
680 + mlx4_mtt_cleanup(dev->dev, &cq->resize_buf->buf.mtt);
681 if (!ibcq->uobject)
682 mlx4_ib_free_cq_buf(dev, &cq->resize_buf->buf,
683 cq->resize_buf->cqe);
684 diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
685 index e32c24d..c694eaa 100644
686 --- a/drivers/input/keyboard/atkbd.c
687 +++ b/drivers/input/keyboard/atkbd.c
688 @@ -868,6 +868,22 @@ static void atkbd_hp_keymap_fixup(struct atkbd *atkbd)
689 }
690
691 /*
692 + * Inventec system with broken key release on volume keys
693 + */
694 +static void atkbd_inventec_keymap_fixup(struct atkbd *atkbd)
695 +{
696 + const unsigned int forced_release_keys[] = {
697 + 0xae, 0xb0,
698 + };
699 + int i;
700 +
701 + if (atkbd->set == 2)
702 + for (i = 0; i < ARRAY_SIZE(forced_release_keys); i++)
703 + __set_bit(forced_release_keys[i],
704 + atkbd->force_release_mask);
705 +}
706 +
707 +/*
708 * atkbd_set_keycode_table() initializes keyboard's keycode table
709 * according to the selected scancode set
710 */
711 @@ -1478,6 +1494,15 @@ static struct dmi_system_id atkbd_dmi_quirk_table[] __initdata = {
712 .callback = atkbd_setup_fixup,
713 .driver_data = atkbd_hp_keymap_fixup,
714 },
715 + {
716 + .ident = "Inventec Symphony",
717 + .matches = {
718 + DMI_MATCH(DMI_SYS_VENDOR, "INVENTEC"),
719 + DMI_MATCH(DMI_PRODUCT_NAME, "SYMPHONY 6.0/7.0"),
720 + },
721 + .callback = atkbd_setup_fixup,
722 + .driver_data = atkbd_inventec_keymap_fixup,
723 + },
724 { }
725 };
726
727 diff --git a/drivers/media/video/compat_ioctl32.c b/drivers/media/video/compat_ioctl32.c
728 index bd5d9de..e6ca401 100644
729 --- a/drivers/media/video/compat_ioctl32.c
730 +++ b/drivers/media/video/compat_ioctl32.c
731 @@ -867,6 +867,7 @@ long v4l_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)
732 case VIDIOC_STREAMON32:
733 case VIDIOC_STREAMOFF32:
734 case VIDIOC_G_PARM:
735 + case VIDIOC_S_PARM:
736 case VIDIOC_G_STD:
737 case VIDIOC_S_STD:
738 case VIDIOC_G_TUNER:
739 @@ -885,6 +886,8 @@ long v4l_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)
740 case VIDIOC_S_INPUT32:
741 case VIDIOC_TRY_FMT32:
742 case VIDIOC_S_HW_FREQ_SEEK:
743 + case VIDIOC_ENUM_FRAMESIZES:
744 + case VIDIOC_ENUM_FRAMEINTERVALS:
745 ret = do_video_ioctl(file, cmd, arg);
746 break;
747
748 diff --git a/drivers/net/atl1e/atl1e_hw.c b/drivers/net/atl1e/atl1e_hw.c
749 index 949e753..c0d5f7c 100644
750 --- a/drivers/net/atl1e/atl1e_hw.c
751 +++ b/drivers/net/atl1e/atl1e_hw.c
752 @@ -163,9 +163,6 @@ int atl1e_read_mac_addr(struct atl1e_hw *hw)
753 * atl1e_hash_mc_addr
754 * purpose
755 * set hash value for a multicast address
756 - * hash calcu processing :
757 - * 1. calcu 32bit CRC for multicast address
758 - * 2. reverse crc with MSB to LSB
759 */
760 u32 atl1e_hash_mc_addr(struct atl1e_hw *hw, u8 *mc_addr)
761 {
762 @@ -174,7 +171,6 @@ u32 atl1e_hash_mc_addr(struct atl1e_hw *hw, u8 *mc_addr)
763 int i;
764
765 crc32 = ether_crc_le(6, mc_addr);
766 - crc32 = ~crc32;
767 for (i = 0; i < 32; i++)
768 value |= (((crc32 >> i) & 1) << (31 - i));
769
770 diff --git a/drivers/net/e1000/e1000_ethtool.c b/drivers/net/e1000/e1000_ethtool.c
771 index 6a3893a..c854c96 100644
772 --- a/drivers/net/e1000/e1000_ethtool.c
773 +++ b/drivers/net/e1000/e1000_ethtool.c
774 @@ -1774,7 +1774,8 @@ static void e1000_get_wol(struct net_device *netdev,
775
776 /* this function will set ->supported = 0 and return 1 if wol is not
777 * supported by this hardware */
778 - if (e1000_wol_exclusion(adapter, wol))
779 + if (e1000_wol_exclusion(adapter, wol) ||
780 + !device_can_wakeup(&adapter->pdev->dev))
781 return;
782
783 /* apply any specific unsupported masks here */
784 @@ -1811,7 +1812,8 @@ static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
785 if (wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE))
786 return -EOPNOTSUPP;
787
788 - if (e1000_wol_exclusion(adapter, wol))
789 + if (e1000_wol_exclusion(adapter, wol) ||
790 + !device_can_wakeup(&adapter->pdev->dev))
791 return wol->wolopts ? -EOPNOTSUPP : 0;
792
793 switch (hw->device_id) {
794 @@ -1838,6 +1840,8 @@ static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
795 if (wol->wolopts & WAKE_MAGIC)
796 adapter->wol |= E1000_WUFC_MAG;
797
798 + device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
799 +
800 return 0;
801 }
802
803 diff --git a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c
804 index ad6da7b..872ea58 100644
805 --- a/drivers/net/e1000/e1000_main.c
806 +++ b/drivers/net/e1000/e1000_main.c
807 @@ -1180,6 +1180,7 @@ static int __devinit e1000_probe(struct pci_dev *pdev,
808
809 /* initialize the wol settings based on the eeprom settings */
810 adapter->wol = adapter->eeprom_wol;
811 + device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
812
813 /* print bus type/speed/width info */
814 DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
815 diff --git a/drivers/net/e1000e/ethtool.c b/drivers/net/e1000e/ethtool.c
816 index 33a3ff1..e2a30dd 100644
817 --- a/drivers/net/e1000e/ethtool.c
818 +++ b/drivers/net/e1000e/ethtool.c
819 @@ -1681,7 +1681,8 @@ static void e1000_get_wol(struct net_device *netdev,
820 wol->supported = 0;
821 wol->wolopts = 0;
822
823 - if (!(adapter->flags & FLAG_HAS_WOL))
824 + if (!(adapter->flags & FLAG_HAS_WOL) ||
825 + !device_can_wakeup(&adapter->pdev->dev))
826 return;
827
828 wol->supported = WAKE_UCAST | WAKE_MCAST |
829 @@ -1719,7 +1720,8 @@ static int e1000_set_wol(struct net_device *netdev,
830 if (wol->wolopts & WAKE_MAGICSECURE)
831 return -EOPNOTSUPP;
832
833 - if (!(adapter->flags & FLAG_HAS_WOL))
834 + if (!(adapter->flags & FLAG_HAS_WOL) ||
835 + !device_can_wakeup(&adapter->pdev->dev))
836 return wol->wolopts ? -EOPNOTSUPP : 0;
837
838 /* these settings will always override what we currently have */
839 @@ -1738,6 +1740,8 @@ static int e1000_set_wol(struct net_device *netdev,
840 if (wol->wolopts & WAKE_ARP)
841 adapter->wol |= E1000_WUFC_ARP;
842
843 + device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
844 +
845 return 0;
846 }
847
848 diff --git a/drivers/net/e1000e/netdev.c b/drivers/net/e1000e/netdev.c
849 index b81c423..660c85a 100644
850 --- a/drivers/net/e1000e/netdev.c
851 +++ b/drivers/net/e1000e/netdev.c
852 @@ -4616,6 +4616,7 @@ static int __devinit e1000_probe(struct pci_dev *pdev,
853
854 /* initialize the wol settings based on the eeprom settings */
855 adapter->wol = adapter->eeprom_wol;
856 + device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
857
858 /* reset the hardware with the new settings */
859 e1000e_reset(adapter);
860 diff --git a/drivers/net/igb/igb_ethtool.c b/drivers/net/igb/igb_ethtool.c
861 index 58906c9..89964fa 100644
862 --- a/drivers/net/igb/igb_ethtool.c
863 +++ b/drivers/net/igb/igb_ethtool.c
864 @@ -1776,7 +1776,8 @@ static void igb_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
865
866 /* this function will set ->supported = 0 and return 1 if wol is not
867 * supported by this hardware */
868 - if (igb_wol_exclusion(adapter, wol))
869 + if (igb_wol_exclusion(adapter, wol) ||
870 + !device_can_wakeup(&adapter->pdev->dev))
871 return;
872
873 /* apply any specific unsupported masks here */
874 @@ -1805,7 +1806,8 @@ static int igb_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
875 if (wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE))
876 return -EOPNOTSUPP;
877
878 - if (igb_wol_exclusion(adapter, wol))
879 + if (igb_wol_exclusion(adapter, wol) ||
880 + !device_can_wakeup(&adapter->pdev->dev))
881 return wol->wolopts ? -EOPNOTSUPP : 0;
882
883 switch (hw->device_id) {
884 @@ -1825,6 +1827,8 @@ static int igb_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
885 if (wol->wolopts & WAKE_MAGIC)
886 adapter->wol |= E1000_WUFC_MAG;
887
888 + device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
889 +
890 return 0;
891 }
892
893 diff --git a/drivers/net/igb/igb_main.c b/drivers/net/igb/igb_main.c
894 index 634c4c9..11b5df3 100644
895 --- a/drivers/net/igb/igb_main.c
896 +++ b/drivers/net/igb/igb_main.c
897 @@ -1220,6 +1220,7 @@ static int __devinit igb_probe(struct pci_dev *pdev,
898
899 /* initialize the wol settings based on the eeprom settings */
900 adapter->wol = adapter->eeprom_wol;
901 + device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
902
903 /* reset the hardware with the new settings */
904 igb_reset(adapter);
905 diff --git a/drivers/net/pcmcia/axnet_cs.c b/drivers/net/pcmcia/axnet_cs.c
906 index 52bf11b..2f68295 100644
907 --- a/drivers/net/pcmcia/axnet_cs.c
908 +++ b/drivers/net/pcmcia/axnet_cs.c
909 @@ -787,6 +787,7 @@ static struct pcmcia_device_id axnet_ids[] = {
910 PCMCIA_DEVICE_PROD_ID12("IO DATA", "ETXPCM", 0x547e66dc, 0x233adac2),
911 PCMCIA_DEVICE_PROD_ID12("Linksys", "EtherFast 10/100 PC Card (PCMPC100 V3)", 0x0733cc81, 0x232019a8),
912 PCMCIA_DEVICE_PROD_ID12("MELCO", "LPC3-TX", 0x481e0094, 0xf91af609),
913 + PCMCIA_DEVICE_PROD_ID12("NETGEAR", "FA411", 0x9aa79dc3, 0x40fad875),
914 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "100BASE", 0x281f1c5d, 0x7c2add04),
915 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "FastEtherCard", 0x281f1c5d, 0x7ef26116),
916 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "FEP501", 0x281f1c5d, 0x2e272058),
917 diff --git a/drivers/net/pcmcia/pcnet_cs.c b/drivers/net/pcmcia/pcnet_cs.c
918 index ebc1ae6..7d6cf02 100644
919 --- a/drivers/net/pcmcia/pcnet_cs.c
920 +++ b/drivers/net/pcmcia/pcnet_cs.c
921 @@ -1697,7 +1697,6 @@ static struct pcmcia_device_id pcnet_ids[] = {
922 PCMCIA_DEVICE_PROD_ID12("National Semiconductor", "InfoMover NE4100", 0x36e1191f, 0xa6617ec8),
923 PCMCIA_DEVICE_PROD_ID12("NEC", "PC-9801N-J12", 0x18df0ba0, 0xbc912d76),
924 PCMCIA_DEVICE_PROD_ID12("NETGEAR", "FA410TX", 0x9aa79dc3, 0x60e5bc0e),
925 - PCMCIA_DEVICE_PROD_ID12("NETGEAR", "FA411", 0x9aa79dc3, 0x40fad875),
926 PCMCIA_DEVICE_PROD_ID12("Network Everywhere", "Fast Ethernet 10/100 PC Card", 0x820a67b6, 0x31ed1a5f),
927 PCMCIA_DEVICE_PROD_ID12("NextCom K.K.", "Next Hawk", 0xaedaec74, 0xad050ef1),
928 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "10/100Mbps Ethernet Card", 0x281f1c5d, 0x6e41773b),
929 diff --git a/drivers/net/wireless/ath9k/recv.c b/drivers/net/wireless/ath9k/recv.c
930 index 20ddb7a..0941589 100644
931 --- a/drivers/net/wireless/ath9k/recv.c
932 +++ b/drivers/net/wireless/ath9k/recv.c
933 @@ -52,7 +52,7 @@ static void ath_rx_buf_link(struct ath_softc *sc, struct ath_buf *bf)
934 /* setup rx descriptors */
935 ath9k_hw_setuprxdesc(ah,
936 ds,
937 - skb_tailroom(skb), /* buffer size */
938 + sc->sc_rxbufsize,
939 0);
940
941 if (sc->sc_rxlink == NULL)
942 @@ -1011,7 +1011,7 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush)
943
944 pci_dma_sync_single_for_cpu(sc->pdev,
945 bf->bf_buf_addr,
946 - skb_tailroom(skb),
947 + sc->sc_rxbufsize,
948 PCI_DMA_FROMDEVICE);
949 pci_unmap_single(sc->pdev,
950 bf->bf_buf_addr,
951 @@ -1303,8 +1303,7 @@ dma_addr_t ath_skb_map_single(struct ath_softc *sc,
952 * NB: do NOT use skb->len, which is 0 on initialization.
953 * Use skb's entire data area instead.
954 */
955 - *pa = pci_map_single(sc->pdev, skb->data,
956 - skb_end_pointer(skb) - skb->head, direction);
957 + *pa = pci_map_single(sc->pdev, skb->data, sc->sc_rxbufsize, direction);
958 return *pa;
959 }
960
961 @@ -1314,6 +1313,5 @@ void ath_skb_unmap_single(struct ath_softc *sc,
962 dma_addr_t *pa)
963 {
964 /* Unmap skb's entire data area */
965 - pci_unmap_single(sc->pdev, *pa,
966 - skb_end_pointer(skb) - skb->head, direction);
967 + pci_unmap_single(sc->pdev, *pa, sc->sc_rxbufsize, direction);
968 }
969 diff --git a/drivers/net/wireless/rtl8187_dev.c b/drivers/net/wireless/rtl8187_dev.c
970 index 0cebbc4..1640096 100644
971 --- a/drivers/net/wireless/rtl8187_dev.c
972 +++ b/drivers/net/wireless/rtl8187_dev.c
973 @@ -33,10 +33,13 @@ MODULE_LICENSE("GPL");
974 static struct usb_device_id rtl8187_table[] __devinitdata = {
975 /* Asus */
976 {USB_DEVICE(0x0b05, 0x171d), .driver_info = DEVICE_RTL8187},
977 + /* Belkin */
978 + {USB_DEVICE(0x050d, 0x705e), .driver_info = DEVICE_RTL8187B},
979 /* Realtek */
980 {USB_DEVICE(0x0bda, 0x8187), .driver_info = DEVICE_RTL8187},
981 {USB_DEVICE(0x0bda, 0x8189), .driver_info = DEVICE_RTL8187B},
982 {USB_DEVICE(0x0bda, 0x8197), .driver_info = DEVICE_RTL8187B},
983 + {USB_DEVICE(0x0bda, 0x8198), .driver_info = DEVICE_RTL8187B},
984 /* Netgear */
985 {USB_DEVICE(0x0846, 0x6100), .driver_info = DEVICE_RTL8187},
986 {USB_DEVICE(0x0846, 0x6a00), .driver_info = DEVICE_RTL8187},
987 diff --git a/drivers/parport/parport_serial.c b/drivers/parport/parport_serial.c
988 index e2e95b3..101ed49 100644
989 --- a/drivers/parport/parport_serial.c
990 +++ b/drivers/parport/parport_serial.c
991 @@ -70,6 +70,8 @@ static int __devinit netmos_parallel_init(struct pci_dev *dev, struct parport_pc
992 * parallel ports and <S> is the number of serial ports.
993 */
994 card->numports = (dev->subsystem_device & 0xf0) >> 4;
995 + if (card->numports > ARRAY_SIZE(card->addr))
996 + card->numports = ARRAY_SIZE(card->addr);
997 return 0;
998 }
999
1000 diff --git a/drivers/pci/hotplug/acpiphp.h b/drivers/pci/hotplug/acpiphp.h
1001 index 5a58b07..f9e244d 100644
1002 --- a/drivers/pci/hotplug/acpiphp.h
1003 +++ b/drivers/pci/hotplug/acpiphp.h
1004 @@ -50,9 +50,6 @@
1005 #define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME , ## arg)
1006 #define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME , ## arg)
1007
1008 -/* name size which is used for entries in pcihpfs */
1009 -#define SLOT_NAME_SIZE 20 /* {_SUN} */
1010 -
1011 struct acpiphp_bridge;
1012 struct acpiphp_slot;
1013
1014 @@ -63,9 +60,13 @@ struct slot {
1015 struct hotplug_slot *hotplug_slot;
1016 struct acpiphp_slot *acpi_slot;
1017 struct hotplug_slot_info info;
1018 - char name[SLOT_NAME_SIZE];
1019 };
1020
1021 +static inline const char *slot_name(struct slot *slot)
1022 +{
1023 + return hotplug_slot_name(slot->hotplug_slot);
1024 +}
1025 +
1026 /*
1027 * struct acpiphp_bridge - PCI bridge information
1028 *
1029 diff --git a/drivers/pci/hotplug/acpiphp_core.c b/drivers/pci/hotplug/acpiphp_core.c
1030 index 0e496e8..95b536a 100644
1031 --- a/drivers/pci/hotplug/acpiphp_core.c
1032 +++ b/drivers/pci/hotplug/acpiphp_core.c
1033 @@ -44,6 +44,9 @@
1034
1035 #define MY_NAME "acpiphp"
1036
1037 +/* name size which is used for entries in pcihpfs */
1038 +#define SLOT_NAME_SIZE 21 /* {_SUN} */
1039 +
1040 static int debug;
1041 int acpiphp_debug;
1042
1043 @@ -84,7 +87,6 @@ static struct hotplug_slot_ops acpi_hotplug_slot_ops = {
1044 .get_adapter_status = get_adapter_status,
1045 };
1046
1047 -
1048 /**
1049 * acpiphp_register_attention - set attention LED callback
1050 * @info: must be completely filled with LED callbacks
1051 @@ -136,7 +138,7 @@ static int enable_slot(struct hotplug_slot *hotplug_slot)
1052 {
1053 struct slot *slot = hotplug_slot->private;
1054
1055 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
1056 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
1057
1058 /* enable the specified slot */
1059 return acpiphp_enable_slot(slot->acpi_slot);
1060 @@ -154,7 +156,7 @@ static int disable_slot(struct hotplug_slot *hotplug_slot)
1061 struct slot *slot = hotplug_slot->private;
1062 int retval;
1063
1064 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
1065 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
1066
1067 /* disable the specified slot */
1068 retval = acpiphp_disable_slot(slot->acpi_slot);
1069 @@ -177,7 +179,7 @@ static int disable_slot(struct hotplug_slot *hotplug_slot)
1070 {
1071 int retval = -ENODEV;
1072
1073 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
1074 + dbg("%s - physical_slot = %s\n", __func__, hotplug_slot_name(hotplug_slot));
1075
1076 if (attention_info && try_module_get(attention_info->owner)) {
1077 retval = attention_info->set_attn(hotplug_slot, status);
1078 @@ -200,7 +202,7 @@ static int get_power_status(struct hotplug_slot *hotplug_slot, u8 *value)
1079 {
1080 struct slot *slot = hotplug_slot->private;
1081
1082 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
1083 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
1084
1085 *value = acpiphp_get_power_status(slot->acpi_slot);
1086
1087 @@ -222,7 +224,7 @@ static int get_attention_status(struct hotplug_slot *hotplug_slot, u8 *value)
1088 {
1089 int retval = -EINVAL;
1090
1091 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
1092 + dbg("%s - physical_slot = %s\n", __func__, hotplug_slot_name(hotplug_slot));
1093
1094 if (attention_info && try_module_get(attention_info->owner)) {
1095 retval = attention_info->get_attn(hotplug_slot, value);
1096 @@ -245,7 +247,7 @@ static int get_latch_status(struct hotplug_slot *hotplug_slot, u8 *value)
1097 {
1098 struct slot *slot = hotplug_slot->private;
1099
1100 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
1101 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
1102
1103 *value = acpiphp_get_latch_status(slot->acpi_slot);
1104
1105 @@ -265,7 +267,7 @@ static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)
1106 {
1107 struct slot *slot = hotplug_slot->private;
1108
1109 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
1110 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
1111
1112 *value = acpiphp_get_adapter_status(slot->acpi_slot);
1113
1114 @@ -299,7 +301,7 @@ static void release_slot(struct hotplug_slot *hotplug_slot)
1115 {
1116 struct slot *slot = hotplug_slot->private;
1117
1118 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
1119 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
1120
1121 kfree(slot->hotplug_slot);
1122 kfree(slot);
1123 @@ -310,6 +312,7 @@ int acpiphp_register_hotplug_slot(struct acpiphp_slot *acpiphp_slot)
1124 {
1125 struct slot *slot;
1126 int retval = -ENOMEM;
1127 + char name[SLOT_NAME_SIZE];
1128
1129 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
1130 if (!slot)
1131 @@ -321,8 +324,6 @@ int acpiphp_register_hotplug_slot(struct acpiphp_slot *acpiphp_slot)
1132
1133 slot->hotplug_slot->info = &slot->info;
1134
1135 - slot->hotplug_slot->name = slot->name;
1136 -
1137 slot->hotplug_slot->private = slot;
1138 slot->hotplug_slot->release = &release_slot;
1139 slot->hotplug_slot->ops = &acpi_hotplug_slot_ops;
1140 @@ -336,11 +337,12 @@ int acpiphp_register_hotplug_slot(struct acpiphp_slot *acpiphp_slot)
1141 slot->hotplug_slot->info->cur_bus_speed = PCI_SPEED_UNKNOWN;
1142
1143 acpiphp_slot->slot = slot;
1144 - snprintf(slot->name, sizeof(slot->name), "%u", slot->acpi_slot->sun);
1145 + snprintf(name, SLOT_NAME_SIZE, "%u", slot->acpi_slot->sun);
1146
1147 retval = pci_hp_register(slot->hotplug_slot,
1148 acpiphp_slot->bridge->pci_bus,
1149 - acpiphp_slot->device);
1150 + acpiphp_slot->device,
1151 + name);
1152 if (retval == -EBUSY)
1153 goto error_hpslot;
1154 if (retval) {
1155 @@ -348,7 +350,7 @@ int acpiphp_register_hotplug_slot(struct acpiphp_slot *acpiphp_slot)
1156 goto error_hpslot;
1157 }
1158
1159 - info("Slot [%s] registered\n", slot->hotplug_slot->name);
1160 + info("Slot [%s] registered\n", slot_name(slot));
1161
1162 return 0;
1163 error_hpslot:
1164 @@ -365,7 +367,7 @@ void acpiphp_unregister_hotplug_slot(struct acpiphp_slot *acpiphp_slot)
1165 struct slot *slot = acpiphp_slot->slot;
1166 int retval = 0;
1167
1168 - info ("Slot [%s] unregistered\n", slot->hotplug_slot->name);
1169 + info("Slot [%s] unregistered\n", slot_name(slot));
1170
1171 retval = pci_hp_deregister(slot->hotplug_slot);
1172 if (retval)
1173 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
1174 index d9769b3..9fff878 100644
1175 --- a/drivers/pci/hotplug/cpci_hotplug.h
1176 +++ b/drivers/pci/hotplug/cpci_hotplug.h
1177 @@ -30,6 +30,7 @@
1178
1179 #include <linux/types.h>
1180 #include <linux/pci.h>
1181 +#include <linux/pci_hotplug.h>
1182
1183 /* PICMG 2.1 R2.0 HS CSR bits: */
1184 #define HS_CSR_INS 0x0080
1185 @@ -69,6 +70,11 @@ struct cpci_hp_controller {
1186 struct cpci_hp_controller_ops *ops;
1187 };
1188
1189 +static inline const char *slot_name(struct slot *slot)
1190 +{
1191 + return hotplug_slot_name(slot->hotplug_slot);
1192 +}
1193 +
1194 extern int cpci_hp_register_controller(struct cpci_hp_controller *controller);
1195 extern int cpci_hp_unregister_controller(struct cpci_hp_controller *controller);
1196 extern int cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last);
1197 diff --git a/drivers/pci/hotplug/cpci_hotplug_core.c b/drivers/pci/hotplug/cpci_hotplug_core.c
1198 index 9359479..de94f4f 100644
1199 --- a/drivers/pci/hotplug/cpci_hotplug_core.c
1200 +++ b/drivers/pci/hotplug/cpci_hotplug_core.c
1201 @@ -108,7 +108,7 @@ enable_slot(struct hotplug_slot *hotplug_slot)
1202 struct slot *slot = hotplug_slot->private;
1203 int retval = 0;
1204
1205 - dbg("%s - physical_slot = %s", __func__, hotplug_slot->name);
1206 + dbg("%s - physical_slot = %s", __func__, slot_name(slot));
1207
1208 if (controller->ops->set_power)
1209 retval = controller->ops->set_power(slot, 1);
1210 @@ -121,25 +121,23 @@ disable_slot(struct hotplug_slot *hotplug_slot)
1211 struct slot *slot = hotplug_slot->private;
1212 int retval = 0;
1213
1214 - dbg("%s - physical_slot = %s", __func__, hotplug_slot->name);
1215 + dbg("%s - physical_slot = %s", __func__, slot_name(slot));
1216
1217 down_write(&list_rwsem);
1218
1219 /* Unconfigure device */
1220 - dbg("%s - unconfiguring slot %s",
1221 - __func__, slot->hotplug_slot->name);
1222 + dbg("%s - unconfiguring slot %s", __func__, slot_name(slot));
1223 if ((retval = cpci_unconfigure_slot(slot))) {
1224 err("%s - could not unconfigure slot %s",
1225 - __func__, slot->hotplug_slot->name);
1226 + __func__, slot_name(slot));
1227 goto disable_error;
1228 }
1229 - dbg("%s - finished unconfiguring slot %s",
1230 - __func__, slot->hotplug_slot->name);
1231 + dbg("%s - finished unconfiguring slot %s", __func__, slot_name(slot));
1232
1233 /* Clear EXT (by setting it) */
1234 if (cpci_clear_ext(slot)) {
1235 err("%s - could not clear EXT for slot %s",
1236 - __func__, slot->hotplug_slot->name);
1237 + __func__, slot_name(slot));
1238 retval = -ENODEV;
1239 goto disable_error;
1240 }
1241 @@ -214,7 +212,6 @@ static void release_slot(struct hotplug_slot *hotplug_slot)
1242 struct slot *slot = hotplug_slot->private;
1243
1244 kfree(slot->hotplug_slot->info);
1245 - kfree(slot->hotplug_slot->name);
1246 kfree(slot->hotplug_slot);
1247 if (slot->dev)
1248 pci_dev_put(slot->dev);
1249 @@ -222,12 +219,6 @@ static void release_slot(struct hotplug_slot *hotplug_slot)
1250 }
1251
1252 #define SLOT_NAME_SIZE 6
1253 -static void
1254 -make_slot_name(struct slot *slot)
1255 -{
1256 - snprintf(slot->hotplug_slot->name,
1257 - SLOT_NAME_SIZE, "%02x:%02x", slot->bus->number, slot->number);
1258 -}
1259
1260 int
1261 cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last)
1262 @@ -235,7 +226,7 @@ cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last)
1263 struct slot *slot;
1264 struct hotplug_slot *hotplug_slot;
1265 struct hotplug_slot_info *info;
1266 - char *name;
1267 + char name[SLOT_NAME_SIZE];
1268 int status = -ENOMEM;
1269 int i;
1270
1271 @@ -262,34 +253,31 @@ cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last)
1272 goto error_hpslot;
1273 hotplug_slot->info = info;
1274
1275 - name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL);
1276 - if (!name)
1277 - goto error_info;
1278 - hotplug_slot->name = name;
1279 -
1280 slot->bus = bus;
1281 slot->number = i;
1282 slot->devfn = PCI_DEVFN(i, 0);
1283
1284 + snprintf(name, SLOT_NAME_SIZE, "%02x:%02x", bus->number, i);
1285 +
1286 hotplug_slot->private = slot;
1287 hotplug_slot->release = &release_slot;
1288 - make_slot_name(slot);
1289 hotplug_slot->ops = &cpci_hotplug_slot_ops;
1290
1291 /*
1292 * Initialize the slot info structure with some known
1293 * good values.
1294 */
1295 - dbg("initializing slot %s", slot->hotplug_slot->name);
1296 + dbg("initializing slot %s", name);
1297 info->power_status = cpci_get_power_status(slot);
1298 info->attention_status = cpci_get_attention_status(slot);
1299
1300 - dbg("registering slot %s", slot->hotplug_slot->name);
1301 - status = pci_hp_register(slot->hotplug_slot, bus, i);
1302 + dbg("registering slot %s", name);
1303 + status = pci_hp_register(slot->hotplug_slot, bus, i, name);
1304 if (status) {
1305 err("pci_hp_register failed with error %d", status);
1306 - goto error_name;
1307 + goto error_info;
1308 }
1309 + dbg("slot registered with name: %s", slot_name(slot));
1310
1311 /* Add slot to our internal list */
1312 down_write(&list_rwsem);
1313 @@ -298,8 +286,6 @@ cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last)
1314 up_write(&list_rwsem);
1315 }
1316 return 0;
1317 -error_name:
1318 - kfree(name);
1319 error_info:
1320 kfree(info);
1321 error_hpslot:
1322 @@ -327,7 +313,7 @@ cpci_hp_unregister_bus(struct pci_bus *bus)
1323 list_del(&slot->slot_list);
1324 slots--;
1325
1326 - dbg("deregistering slot %s", slot->hotplug_slot->name);
1327 + dbg("deregistering slot %s", slot_name(slot));
1328 status = pci_hp_deregister(slot->hotplug_slot);
1329 if (status) {
1330 err("pci_hp_deregister failed with error %d",
1331 @@ -379,11 +365,10 @@ init_slots(int clear_ins)
1332 return -1;
1333 }
1334 list_for_each_entry(slot, &slot_list, slot_list) {
1335 - dbg("%s - looking at slot %s",
1336 - __func__, slot->hotplug_slot->name);
1337 + dbg("%s - looking at slot %s", __func__, slot_name(slot));
1338 if (clear_ins && cpci_check_and_clear_ins(slot))
1339 dbg("%s - cleared INS for slot %s",
1340 - __func__, slot->hotplug_slot->name);
1341 + __func__, slot_name(slot));
1342 dev = pci_get_slot(slot->bus, PCI_DEVFN(slot->number, 0));
1343 if (dev) {
1344 if (update_adapter_status(slot->hotplug_slot, 1))
1345 @@ -414,8 +399,7 @@ check_slots(void)
1346 }
1347 extracted = inserted = 0;
1348 list_for_each_entry(slot, &slot_list, slot_list) {
1349 - dbg("%s - looking at slot %s",
1350 - __func__, slot->hotplug_slot->name);
1351 + dbg("%s - looking at slot %s", __func__, slot_name(slot));
1352 if (cpci_check_and_clear_ins(slot)) {
1353 /*
1354 * Some broken hardware (e.g. PLX 9054AB) asserts
1355 @@ -423,35 +407,34 @@ check_slots(void)
1356 */
1357 if (slot->dev) {
1358 warn("slot %s already inserted",
1359 - slot->hotplug_slot->name);
1360 + slot_name(slot));
1361 inserted++;
1362 continue;
1363 }
1364
1365 /* Process insertion */
1366 - dbg("%s - slot %s inserted",
1367 - __func__, slot->hotplug_slot->name);
1368 + dbg("%s - slot %s inserted", __func__, slot_name(slot));
1369
1370 /* GSM, debug */
1371 hs_csr = cpci_get_hs_csr(slot);
1372 dbg("%s - slot %s HS_CSR (1) = %04x",
1373 - __func__, slot->hotplug_slot->name, hs_csr);
1374 + __func__, slot_name(slot), hs_csr);
1375
1376 /* Configure device */
1377 dbg("%s - configuring slot %s",
1378 - __func__, slot->hotplug_slot->name);
1379 + __func__, slot_name(slot));
1380 if (cpci_configure_slot(slot)) {
1381 err("%s - could not configure slot %s",
1382 - __func__, slot->hotplug_slot->name);
1383 + __func__, slot_name(slot));
1384 continue;
1385 }
1386 dbg("%s - finished configuring slot %s",
1387 - __func__, slot->hotplug_slot->name);
1388 + __func__, slot_name(slot));
1389
1390 /* GSM, debug */
1391 hs_csr = cpci_get_hs_csr(slot);
1392 dbg("%s - slot %s HS_CSR (2) = %04x",
1393 - __func__, slot->hotplug_slot->name, hs_csr);
1394 + __func__, slot_name(slot), hs_csr);
1395
1396 if (update_latch_status(slot->hotplug_slot, 1))
1397 warn("failure to update latch file");
1398 @@ -464,18 +447,18 @@ check_slots(void)
1399 /* GSM, debug */
1400 hs_csr = cpci_get_hs_csr(slot);
1401 dbg("%s - slot %s HS_CSR (3) = %04x",
1402 - __func__, slot->hotplug_slot->name, hs_csr);
1403 + __func__, slot_name(slot), hs_csr);
1404
1405 inserted++;
1406 } else if (cpci_check_ext(slot)) {
1407 /* Process extraction request */
1408 dbg("%s - slot %s extracted",
1409 - __func__, slot->hotplug_slot->name);
1410 + __func__, slot_name(slot));
1411
1412 /* GSM, debug */
1413 hs_csr = cpci_get_hs_csr(slot);
1414 dbg("%s - slot %s HS_CSR = %04x",
1415 - __func__, slot->hotplug_slot->name, hs_csr);
1416 + __func__, slot_name(slot), hs_csr);
1417
1418 if (!slot->extracting) {
1419 if (update_latch_status(slot->hotplug_slot, 0)) {
1420 @@ -493,7 +476,7 @@ check_slots(void)
1421 * bother trying to tell the driver or not?
1422 */
1423 err("card in slot %s was improperly removed",
1424 - slot->hotplug_slot->name);
1425 + slot_name(slot));
1426 if (update_adapter_status(slot->hotplug_slot, 0))
1427 warn("failure to update adapter file");
1428 slot->extracting = 0;
1429 diff --git a/drivers/pci/hotplug/cpci_hotplug_pci.c b/drivers/pci/hotplug/cpci_hotplug_pci.c
1430 index df82b95..829c327 100644
1431 --- a/drivers/pci/hotplug/cpci_hotplug_pci.c
1432 +++ b/drivers/pci/hotplug/cpci_hotplug_pci.c
1433 @@ -209,7 +209,7 @@ int cpci_led_on(struct slot* slot)
1434 hs_cap + 2,
1435 hs_csr)) {
1436 err("Could not set LOO for slot %s",
1437 - slot->hotplug_slot->name);
1438 + hotplug_slot_name(slot->hotplug_slot));
1439 return -ENODEV;
1440 }
1441 }
1442 @@ -238,7 +238,7 @@ int cpci_led_off(struct slot* slot)
1443 hs_cap + 2,
1444 hs_csr)) {
1445 err("Could not clear LOO for slot %s",
1446 - slot->hotplug_slot->name);
1447 + hotplug_slot_name(slot->hotplug_slot));
1448 return -ENODEV;
1449 }
1450 }
1451 diff --git a/drivers/pci/hotplug/cpqphp.h b/drivers/pci/hotplug/cpqphp.h
1452 index b1decfa..afaf8f6 100644
1453 --- a/drivers/pci/hotplug/cpqphp.h
1454 +++ b/drivers/pci/hotplug/cpqphp.h
1455 @@ -449,6 +449,11 @@ extern u8 cpqhp_disk_irq;
1456
1457 /* inline functions */
1458
1459 +static inline char *slot_name(struct slot *slot)
1460 +{
1461 + return hotplug_slot_name(slot->hotplug_slot);
1462 +}
1463 +
1464 /*
1465 * return_resource
1466 *
1467 @@ -696,14 +701,6 @@ static inline int get_presence_status(struct controller *ctrl, struct slot *slot
1468 return presence_save;
1469 }
1470
1471 -#define SLOT_NAME_SIZE 10
1472 -
1473 -static inline void make_slot_name(char *buffer, int buffer_size, struct slot *slot)
1474 -{
1475 - snprintf(buffer, buffer_size, "%d", slot->number);
1476 -}
1477 -
1478 -
1479 static inline int wait_for_ctrl_irq(struct controller *ctrl)
1480 {
1481 DECLARE_WAITQUEUE(wait, current);
1482 diff --git a/drivers/pci/hotplug/cpqphp_core.c b/drivers/pci/hotplug/cpqphp_core.c
1483 index 87a68d2..8514c3a 100644
1484 --- a/drivers/pci/hotplug/cpqphp_core.c
1485 +++ b/drivers/pci/hotplug/cpqphp_core.c
1486 @@ -315,14 +315,15 @@ static void release_slot(struct hotplug_slot *hotplug_slot)
1487 {
1488 struct slot *slot = hotplug_slot->private;
1489
1490 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
1491 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
1492
1493 kfree(slot->hotplug_slot->info);
1494 - kfree(slot->hotplug_slot->name);
1495 kfree(slot->hotplug_slot);
1496 kfree(slot);
1497 }
1498
1499 +#define SLOT_NAME_SIZE 10
1500 +
1501 static int ctrl_slot_setup(struct controller *ctrl,
1502 void __iomem *smbios_start,
1503 void __iomem *smbios_table)
1504 @@ -335,6 +336,7 @@ static int ctrl_slot_setup(struct controller *ctrl,
1505 u8 slot_number;
1506 u8 ctrl_slot;
1507 u32 tempdword;
1508 + char name[SLOT_NAME_SIZE];
1509 void __iomem *slot_entry= NULL;
1510 int result = -ENOMEM;
1511
1512 @@ -363,16 +365,12 @@ static int ctrl_slot_setup(struct controller *ctrl,
1513 if (!hotplug_slot->info)
1514 goto error_hpslot;
1515 hotplug_slot_info = hotplug_slot->info;
1516 - hotplug_slot->name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL);
1517 -
1518 - if (!hotplug_slot->name)
1519 - goto error_info;
1520
1521 slot->ctrl = ctrl;
1522 slot->bus = ctrl->bus;
1523 slot->device = slot_device;
1524 slot->number = slot_number;
1525 - dbg("slot->number = %d\n", slot->number);
1526 + dbg("slot->number = %u\n", slot->number);
1527
1528 slot_entry = get_SMBIOS_entry(smbios_start, smbios_table, 9,
1529 slot_entry);
1530 @@ -418,9 +416,9 @@ static int ctrl_slot_setup(struct controller *ctrl,
1531 /* register this slot with the hotplug pci core */
1532 hotplug_slot->release = &release_slot;
1533 hotplug_slot->private = slot;
1534 - make_slot_name(hotplug_slot->name, SLOT_NAME_SIZE, slot);
1535 + snprintf(name, SLOT_NAME_SIZE, "%u", slot->number);
1536 hotplug_slot->ops = &cpqphp_hotplug_slot_ops;
1537 -
1538 +
1539 hotplug_slot_info->power_status = get_slot_enabled(ctrl, slot);
1540 hotplug_slot_info->attention_status =
1541 cpq_get_attention_status(ctrl, slot);
1542 @@ -436,10 +434,11 @@ static int ctrl_slot_setup(struct controller *ctrl,
1543 slot_number);
1544 result = pci_hp_register(hotplug_slot,
1545 ctrl->pci_dev->bus,
1546 - slot->device);
1547 + slot->device,
1548 + name);
1549 if (result) {
1550 err("pci_hp_register failed with error %d\n", result);
1551 - goto error_name;
1552 + goto error_info;
1553 }
1554
1555 slot->next = ctrl->slot;
1556 @@ -451,8 +450,6 @@ static int ctrl_slot_setup(struct controller *ctrl,
1557 }
1558
1559 return 0;
1560 -error_name:
1561 - kfree(hotplug_slot->name);
1562 error_info:
1563 kfree(hotplug_slot_info);
1564 error_hpslot:
1565 @@ -638,7 +635,7 @@ static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status)
1566 u8 device;
1567 u8 function;
1568
1569 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
1570 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
1571
1572 if (cpqhp_get_bus_dev(ctrl, &bus, &devfn, slot->number) == -1)
1573 return -ENODEV;
1574 @@ -665,7 +662,7 @@ static int process_SI(struct hotplug_slot *hotplug_slot)
1575 u8 device;
1576 u8 function;
1577
1578 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
1579 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
1580
1581 if (cpqhp_get_bus_dev(ctrl, &bus, &devfn, slot->number) == -1)
1582 return -ENODEV;
1583 @@ -697,7 +694,7 @@ static int process_SS(struct hotplug_slot *hotplug_slot)
1584 u8 device;
1585 u8 function;
1586
1587 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
1588 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
1589
1590 if (cpqhp_get_bus_dev(ctrl, &bus, &devfn, slot->number) == -1)
1591 return -ENODEV;
1592 @@ -720,7 +717,7 @@ static int hardware_test(struct hotplug_slot *hotplug_slot, u32 value)
1593 struct slot *slot = hotplug_slot->private;
1594 struct controller *ctrl = slot->ctrl;
1595
1596 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
1597 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
1598
1599 return cpqhp_hardware_test(ctrl, value);
1600 }
1601 @@ -731,7 +728,7 @@ static int get_power_status(struct hotplug_slot *hotplug_slot, u8 *value)
1602 struct slot *slot = hotplug_slot->private;
1603 struct controller *ctrl = slot->ctrl;
1604
1605 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
1606 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
1607
1608 *value = get_slot_enabled(ctrl, slot);
1609 return 0;
1610 @@ -742,7 +739,7 @@ static int get_attention_status(struct hotplug_slot *hotplug_slot, u8 *value)
1611 struct slot *slot = hotplug_slot->private;
1612 struct controller *ctrl = slot->ctrl;
1613
1614 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
1615 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
1616
1617 *value = cpq_get_attention_status(ctrl, slot);
1618 return 0;
1619 @@ -753,7 +750,7 @@ static int get_latch_status(struct hotplug_slot *hotplug_slot, u8 *value)
1620 struct slot *slot = hotplug_slot->private;
1621 struct controller *ctrl = slot->ctrl;
1622
1623 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
1624 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
1625
1626 *value = cpq_get_latch_status(ctrl, slot);
1627
1628 @@ -765,7 +762,7 @@ static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)
1629 struct slot *slot = hotplug_slot->private;
1630 struct controller *ctrl = slot->ctrl;
1631
1632 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
1633 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
1634
1635 *value = get_presence_status(ctrl, slot);
1636
1637 @@ -777,7 +774,7 @@ static int get_max_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_sp
1638 struct slot *slot = hotplug_slot->private;
1639 struct controller *ctrl = slot->ctrl;
1640
1641 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
1642 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
1643
1644 *value = ctrl->speed_capability;
1645
1646 @@ -789,7 +786,7 @@ static int get_cur_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_sp
1647 struct slot *slot = hotplug_slot->private;
1648 struct controller *ctrl = slot->ctrl;
1649
1650 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
1651 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
1652
1653 *value = ctrl->speed;
1654
1655 diff --git a/drivers/pci/hotplug/fakephp.c b/drivers/pci/hotplug/fakephp.c
1656 index 146ca9c..24dcbf1 100644
1657 --- a/drivers/pci/hotplug/fakephp.c
1658 +++ b/drivers/pci/hotplug/fakephp.c
1659 @@ -66,7 +66,6 @@ struct dummy_slot {
1660 struct pci_dev *dev;
1661 struct work_struct remove_work;
1662 unsigned long removed;
1663 - char name[8];
1664 };
1665
1666 static int debug;
1667 @@ -96,10 +95,13 @@ static void dummy_release(struct hotplug_slot *slot)
1668 kfree(dslot);
1669 }
1670
1671 +#define SLOT_NAME_SIZE 8
1672 +
1673 static int add_slot(struct pci_dev *dev)
1674 {
1675 struct dummy_slot *dslot;
1676 struct hotplug_slot *slot;
1677 + char name[SLOT_NAME_SIZE];
1678 int retval = -ENOMEM;
1679 static int count = 1;
1680
1681 @@ -119,19 +121,18 @@ static int add_slot(struct pci_dev *dev)
1682 if (!dslot)
1683 goto error_info;
1684
1685 - slot->name = dslot->name;
1686 - snprintf(slot->name, sizeof(dslot->name), "fake%d", count++);
1687 - dbg("slot->name = %s\n", slot->name);
1688 + snprintf(name, SLOT_NAME_SIZE, "fake%d", count++);
1689 slot->ops = &dummy_hotplug_slot_ops;
1690 slot->release = &dummy_release;
1691 slot->private = dslot;
1692
1693 - retval = pci_hp_register(slot, dev->bus, PCI_SLOT(dev->devfn));
1694 + retval = pci_hp_register(slot, dev->bus, PCI_SLOT(dev->devfn), name);
1695 if (retval) {
1696 err("pci_hp_register failed with error %d\n", retval);
1697 goto error_dslot;
1698 }
1699
1700 + dbg("slot->name = %s\n", hotplug_slot_name(slot));
1701 dslot->slot = slot;
1702 dslot->dev = pci_dev_get(dev);
1703 list_add (&dslot->node, &slot_list);
1704 @@ -167,10 +168,11 @@ static void remove_slot(struct dummy_slot *dslot)
1705 {
1706 int retval;
1707
1708 - dbg("removing slot %s\n", dslot->slot->name);
1709 + dbg("removing slot %s\n", hotplug_slot_name(dslot->slot));
1710 retval = pci_hp_deregister(dslot->slot);
1711 if (retval)
1712 - err("Problem unregistering a slot %s\n", dslot->slot->name);
1713 + err("Problem unregistering a slot %s\n",
1714 + hotplug_slot_name(dslot->slot));
1715 }
1716
1717 /* called from the single-threaded workqueue handler to remove a slot */
1718 @@ -308,7 +310,7 @@ static int disable_slot(struct hotplug_slot *slot)
1719 return -ENODEV;
1720 dslot = slot->private;
1721
1722 - dbg("%s - physical_slot = %s\n", __func__, slot->name);
1723 + dbg("%s - physical_slot = %s\n", __func__, hotplug_slot_name(slot));
1724
1725 for (func = 7; func >= 0; func--) {
1726 dev = pci_get_slot(dslot->dev->bus, dslot->dev->devfn + func);
1727 diff --git a/drivers/pci/hotplug/ibmphp.h b/drivers/pci/hotplug/ibmphp.h
1728 index 612d963..a8d391a 100644
1729 --- a/drivers/pci/hotplug/ibmphp.h
1730 +++ b/drivers/pci/hotplug/ibmphp.h
1731 @@ -707,17 +707,16 @@ struct slot {
1732 u8 device;
1733 u8 number;
1734 u8 real_physical_slot_num;
1735 - char name[100];
1736 u32 capabilities;
1737 u8 supported_speed;
1738 u8 supported_bus_mode;
1739 + u8 flag; /* this is for disable slot and polling */
1740 + u8 ctlr_index;
1741 struct hotplug_slot *hotplug_slot;
1742 struct controller *ctrl;
1743 struct pci_func *func;
1744 u8 irq[4];
1745 - u8 flag; /* this is for disable slot and polling */
1746 int bit_mode; /* 0 = 32, 1 = 64 */
1747 - u8 ctlr_index;
1748 struct bus_info *bus_on;
1749 struct list_head ibm_slot_list;
1750 u8 status;
1751 diff --git a/drivers/pci/hotplug/ibmphp_ebda.c b/drivers/pci/hotplug/ibmphp_ebda.c
1752 index 8467d02..8431246 100644
1753 --- a/drivers/pci/hotplug/ibmphp_ebda.c
1754 +++ b/drivers/pci/hotplug/ibmphp_ebda.c
1755 @@ -620,11 +620,14 @@ static u8 calculate_first_slot (u8 slot_num)
1756 return first_slot + 1;
1757
1758 }
1759 +
1760 +#define SLOT_NAME_SIZE 30
1761 +
1762 static char *create_file_name (struct slot * slot_cur)
1763 {
1764 struct opt_rio *opt_vg_ptr = NULL;
1765 struct opt_rio_lo *opt_lo_ptr = NULL;
1766 - static char str[30];
1767 + static char str[SLOT_NAME_SIZE];
1768 int which = 0; /* rxe = 1, chassis = 0 */
1769 u8 number = 1; /* either chassis or rxe # */
1770 u8 first_slot = 1;
1771 @@ -736,7 +739,6 @@ static void release_slot(struct hotplug_slot *hotplug_slot)
1772
1773 slot = hotplug_slot->private;
1774 kfree(slot->hotplug_slot->info);
1775 - kfree(slot->hotplug_slot->name);
1776 kfree(slot->hotplug_slot);
1777 slot->ctrl = NULL;
1778 slot->bus_on = NULL;
1779 @@ -768,6 +770,7 @@ static int __init ebda_rsrc_controller (void)
1780 int rc;
1781 struct slot *tmp_slot;
1782 struct list_head *list;
1783 + char name[SLOT_NAME_SIZE];
1784
1785 addr = hpc_list_ptr->phys_addr;
1786 for (ctlr = 0; ctlr < hpc_list_ptr->num_ctlrs; ctlr++) {
1787 @@ -931,12 +934,6 @@ static int __init ebda_rsrc_controller (void)
1788 goto error_no_hp_info;
1789 }
1790
1791 - hp_slot_ptr->name = kmalloc(30, GFP_KERNEL);
1792 - if (!hp_slot_ptr->name) {
1793 - rc = -ENOMEM;
1794 - goto error_no_hp_name;
1795 - }
1796 -
1797 tmp_slot = kzalloc(sizeof(*tmp_slot), GFP_KERNEL);
1798 if (!tmp_slot) {
1799 rc = -ENOMEM;
1800 @@ -1000,9 +997,9 @@ static int __init ebda_rsrc_controller (void)
1801 list_for_each (list, &ibmphp_slot_head) {
1802 tmp_slot = list_entry (list, struct slot, ibm_slot_list);
1803
1804 - snprintf (tmp_slot->hotplug_slot->name, 30, "%s", create_file_name (tmp_slot));
1805 + snprintf(name, SLOT_NAME_SIZE, "%s", create_file_name(tmp_slot));
1806 pci_hp_register(tmp_slot->hotplug_slot,
1807 - pci_find_bus(0, tmp_slot->bus), tmp_slot->device);
1808 + pci_find_bus(0, tmp_slot->bus), tmp_slot->device, name);
1809 }
1810
1811 print_ebda_hpc ();
1812 @@ -1012,8 +1009,6 @@ static int __init ebda_rsrc_controller (void)
1813 error:
1814 kfree (hp_slot_ptr->private);
1815 error_no_slot:
1816 - kfree (hp_slot_ptr->name);
1817 -error_no_hp_name:
1818 kfree (hp_slot_ptr->info);
1819 error_no_hp_info:
1820 kfree (hp_slot_ptr);
1821 diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
1822 index 5f85b1b..4871b96 100644
1823 --- a/drivers/pci/hotplug/pci_hotplug_core.c
1824 +++ b/drivers/pci/hotplug/pci_hotplug_core.c
1825 @@ -37,6 +37,7 @@
1826 #include <linux/init.h>
1827 #include <linux/mount.h>
1828 #include <linux/namei.h>
1829 +#include <linux/mutex.h>
1830 #include <linux/pci.h>
1831 #include <linux/pci_hotplug.h>
1832 #include <asm/uaccess.h>
1833 @@ -61,7 +62,7 @@ static int debug;
1834 //////////////////////////////////////////////////////////////////
1835
1836 static LIST_HEAD(pci_hotplug_slot_list);
1837 -static DEFINE_SPINLOCK(pci_hotplug_slot_list_lock);
1838 +static DEFINE_MUTEX(pci_hp_mutex);
1839
1840 /* these strings match up with the values in pci_bus_speed */
1841 static char *pci_bus_speed_strings[] = {
1842 @@ -530,16 +531,12 @@ static struct hotplug_slot *get_slot_from_name (const char *name)
1843 struct hotplug_slot *slot;
1844 struct list_head *tmp;
1845
1846 - spin_lock(&pci_hotplug_slot_list_lock);
1847 list_for_each (tmp, &pci_hotplug_slot_list) {
1848 slot = list_entry (tmp, struct hotplug_slot, slot_list);
1849 - if (strcmp(slot->name, name) == 0)
1850 - goto out;
1851 + if (strcmp(hotplug_slot_name(slot), name) == 0)
1852 + return slot;
1853 }
1854 - slot = NULL;
1855 -out:
1856 - spin_unlock(&pci_hotplug_slot_list_lock);
1857 - return slot;
1858 + return NULL;
1859 }
1860
1861 /**
1862 @@ -547,13 +544,15 @@ out:
1863 * @bus: bus this slot is on
1864 * @slot: pointer to the &struct hotplug_slot to register
1865 * @slot_nr: slot number
1866 + * @name: name registered with kobject core
1867 *
1868 * Registers a hotplug slot with the pci hotplug subsystem, which will allow
1869 * userspace interaction to the slot.
1870 *
1871 * Returns 0 if successful, anything else for an error.
1872 */
1873 -int pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus, int slot_nr)
1874 +int pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus, int slot_nr,
1875 + const char *name)
1876 {
1877 int result;
1878 struct pci_slot *pci_slot;
1879 @@ -568,48 +567,29 @@ int pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus, int slot_nr)
1880 return -EINVAL;
1881 }
1882
1883 - /* Check if we have already registered a slot with the same name. */
1884 - if (get_slot_from_name(slot->name))
1885 - return -EEXIST;
1886 + mutex_lock(&pci_hp_mutex);
1887
1888 /*
1889 * No problems if we call this interface from both ACPI_PCI_SLOT
1890 * driver and call it here again. If we've already created the
1891 * pci_slot, the interface will simply bump the refcount.
1892 */
1893 - pci_slot = pci_create_slot(bus, slot_nr, slot->name);
1894 - if (IS_ERR(pci_slot))
1895 - return PTR_ERR(pci_slot);
1896 -
1897 - if (pci_slot->hotplug) {
1898 - dbg("%s: already claimed\n", __func__);
1899 - pci_destroy_slot(pci_slot);
1900 - return -EBUSY;
1901 + pci_slot = pci_create_slot(bus, slot_nr, name, slot);
1902 + if (IS_ERR(pci_slot)) {
1903 + result = PTR_ERR(pci_slot);
1904 + goto out;
1905 }
1906
1907 slot->pci_slot = pci_slot;
1908 pci_slot->hotplug = slot;
1909
1910 - /*
1911 - * Allow pcihp drivers to override the ACPI_PCI_SLOT name.
1912 - */
1913 - if (strcmp(kobject_name(&pci_slot->kobj), slot->name)) {
1914 - result = kobject_rename(&pci_slot->kobj, slot->name);
1915 - if (result) {
1916 - pci_destroy_slot(pci_slot);
1917 - return result;
1918 - }
1919 - }
1920 -
1921 - spin_lock(&pci_hotplug_slot_list_lock);
1922 list_add(&slot->slot_list, &pci_hotplug_slot_list);
1923 - spin_unlock(&pci_hotplug_slot_list_lock);
1924
1925 result = fs_add_slot(pci_slot);
1926 kobject_uevent(&pci_slot->kobj, KOBJ_ADD);
1927 - dbg("Added slot %s to the list\n", slot->name);
1928 -
1929 -
1930 + dbg("Added slot %s to the list\n", name);
1931 +out:
1932 + mutex_unlock(&pci_hp_mutex);
1933 return result;
1934 }
1935
1936 @@ -630,21 +610,23 @@ int pci_hp_deregister(struct hotplug_slot *hotplug)
1937 if (!hotplug)
1938 return -ENODEV;
1939
1940 - temp = get_slot_from_name(hotplug->name);
1941 - if (temp != hotplug)
1942 + mutex_lock(&pci_hp_mutex);
1943 + temp = get_slot_from_name(hotplug_slot_name(hotplug));
1944 + if (temp != hotplug) {
1945 + mutex_unlock(&pci_hp_mutex);
1946 return -ENODEV;
1947 + }
1948
1949 - spin_lock(&pci_hotplug_slot_list_lock);
1950 list_del(&hotplug->slot_list);
1951 - spin_unlock(&pci_hotplug_slot_list_lock);
1952
1953 slot = hotplug->pci_slot;
1954 fs_remove_slot(slot);
1955 - dbg("Removed slot %s from the list\n", hotplug->name);
1956 + dbg("Removed slot %s from the list\n", hotplug_slot_name(hotplug));
1957
1958 hotplug->release(hotplug);
1959 slot->hotplug = NULL;
1960 pci_destroy_slot(slot);
1961 + mutex_unlock(&pci_hp_mutex);
1962
1963 return 0;
1964 }
1965 diff --git a/drivers/pci/hotplug/pciehp.h b/drivers/pci/hotplug/pciehp.h
1966 index 9e6cec6..0187af7 100644
1967 --- a/drivers/pci/hotplug/pciehp.h
1968 +++ b/drivers/pci/hotplug/pciehp.h
1969 @@ -61,15 +61,13 @@ extern struct workqueue_struct *pciehp_wq;
1970 struct slot {
1971 u8 bus;
1972 u8 device;
1973 - u32 number;
1974 u8 state;
1975 - struct timer_list task_event;
1976 u8 hp_slot;
1977 + u32 number;
1978 struct controller *ctrl;
1979 struct hpc_ops *hpc_ops;
1980 struct hotplug_slot *hotplug_slot;
1981 struct list_head slot_list;
1982 - char name[SLOT_NAME_SIZE];
1983 unsigned long last_emi_toggle;
1984 struct delayed_work work; /* work for button event */
1985 struct mutex lock;
1986 @@ -161,6 +159,11 @@ int pciehp_enable_slot(struct slot *p_slot);
1987 int pciehp_disable_slot(struct slot *p_slot);
1988 int pcie_enable_notification(struct controller *ctrl);
1989
1990 +static inline const char *slot_name(struct slot *slot)
1991 +{
1992 + return hotplug_slot_name(slot->hotplug_slot);
1993 +}
1994 +
1995 static inline struct slot *pciehp_find_slot(struct controller *ctrl, u8 device)
1996 {
1997 struct slot *slot;
1998 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
1999 index 4fd5355..6e18736 100644
2000 --- a/drivers/pci/hotplug/pciehp_core.c
2001 +++ b/drivers/pci/hotplug/pciehp_core.c
2002 @@ -180,7 +180,8 @@ static struct hotplug_slot_attribute hotplug_slot_attr_lock = {
2003 */
2004 static void release_slot(struct hotplug_slot *hotplug_slot)
2005 {
2006 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
2007 + dbg("%s - physical_slot = %s\n", __func__,
2008 + hotplug_slot_name(hotplug_slot));
2009
2010 kfree(hotplug_slot->info);
2011 kfree(hotplug_slot);
2012 @@ -191,7 +192,7 @@ static int init_slots(struct controller *ctrl)
2013 struct slot *slot;
2014 struct hotplug_slot *hotplug_slot;
2015 struct hotplug_slot_info *info;
2016 - int len, dup = 1;
2017 + char name[SLOT_NAME_SIZE];
2018 int retval = -ENOMEM;
2019
2020 list_for_each_entry(slot, &ctrl->slot_list, slot_list) {
2021 @@ -205,39 +206,27 @@ static int init_slots(struct controller *ctrl)
2022
2023 /* register this slot with the hotplug pci core */
2024 hotplug_slot->info = info;
2025 - hotplug_slot->name = slot->name;
2026 hotplug_slot->private = slot;
2027 hotplug_slot->release = &release_slot;
2028 hotplug_slot->ops = &pciehp_hotplug_slot_ops;
2029 - get_power_status(hotplug_slot, &info->power_status);
2030 - get_attention_status(hotplug_slot, &info->attention_status);
2031 - get_latch_status(hotplug_slot, &info->latch_status);
2032 - get_adapter_status(hotplug_slot, &info->adapter_status);
2033 slot->hotplug_slot = hotplug_slot;
2034 + snprintf(name, SLOT_NAME_SIZE, "%u", slot->number);
2035
2036 dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x "
2037 "slot_device_offset=%x\n", slot->bus, slot->device,
2038 slot->hp_slot, slot->number, ctrl->slot_device_offset);
2039 -duplicate_name:
2040 retval = pci_hp_register(hotplug_slot,
2041 ctrl->pci_dev->subordinate,
2042 - slot->device);
2043 + slot->device,
2044 + name);
2045 if (retval) {
2046 - /*
2047 - * If slot N already exists, we'll try to create
2048 - * slot N-1, N-2 ... N-M, until we overflow.
2049 - */
2050 - if (retval == -EEXIST) {
2051 - len = snprintf(slot->name, SLOT_NAME_SIZE,
2052 - "%d-%d", slot->number, dup++);
2053 - if (len < SLOT_NAME_SIZE)
2054 - goto duplicate_name;
2055 - else
2056 - err("duplicate slot name overflow\n");
2057 - }
2058 err("pci_hp_register failed with error %d\n", retval);
2059 goto error_info;
2060 }
2061 + get_power_status(hotplug_slot, &info->power_status);
2062 + get_attention_status(hotplug_slot, &info->attention_status);
2063 + get_latch_status(hotplug_slot, &info->latch_status);
2064 + get_adapter_status(hotplug_slot, &info->adapter_status);
2065 /* create additional sysfs entries */
2066 if (EMI(ctrl)) {
2067 retval = sysfs_create_file(&hotplug_slot->pci_slot->kobj,
2068 @@ -278,7 +267,7 @@ static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 status)
2069 {
2070 struct slot *slot = hotplug_slot->private;
2071
2072 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
2073 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
2074
2075 hotplug_slot->info->attention_status = status;
2076
2077 @@ -293,7 +282,7 @@ static int enable_slot(struct hotplug_slot *hotplug_slot)
2078 {
2079 struct slot *slot = hotplug_slot->private;
2080
2081 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
2082 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
2083
2084 return pciehp_sysfs_enable_slot(slot);
2085 }
2086 @@ -303,7 +292,7 @@ static int disable_slot(struct hotplug_slot *hotplug_slot)
2087 {
2088 struct slot *slot = hotplug_slot->private;
2089
2090 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
2091 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
2092
2093 return pciehp_sysfs_disable_slot(slot);
2094 }
2095 @@ -313,7 +302,7 @@ static int get_power_status(struct hotplug_slot *hotplug_slot, u8 *value)
2096 struct slot *slot = hotplug_slot->private;
2097 int retval;
2098
2099 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
2100 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
2101
2102 retval = slot->hpc_ops->get_power_status(slot, value);
2103 if (retval < 0)
2104 @@ -327,7 +316,7 @@ static int get_attention_status(struct hotplug_slot *hotplug_slot, u8 *value)
2105 struct slot *slot = hotplug_slot->private;
2106 int retval;
2107
2108 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
2109 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
2110
2111 retval = slot->hpc_ops->get_attention_status(slot, value);
2112 if (retval < 0)
2113 @@ -341,7 +330,7 @@ static int get_latch_status(struct hotplug_slot *hotplug_slot, u8 *value)
2114 struct slot *slot = hotplug_slot->private;
2115 int retval;
2116
2117 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
2118 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
2119
2120 retval = slot->hpc_ops->get_latch_status(slot, value);
2121 if (retval < 0)
2122 @@ -355,7 +344,7 @@ static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)
2123 struct slot *slot = hotplug_slot->private;
2124 int retval;
2125
2126 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
2127 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
2128
2129 retval = slot->hpc_ops->get_adapter_status(slot, value);
2130 if (retval < 0)
2131 @@ -370,7 +359,7 @@ static int get_max_bus_speed(struct hotplug_slot *hotplug_slot,
2132 struct slot *slot = hotplug_slot->private;
2133 int retval;
2134
2135 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
2136 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
2137
2138 retval = slot->hpc_ops->get_max_bus_speed(slot, value);
2139 if (retval < 0)
2140 @@ -384,7 +373,7 @@ static int get_cur_bus_speed(struct hotplug_slot *hotplug_slot, enum pci_bus_spe
2141 struct slot *slot = hotplug_slot->private;
2142 int retval;
2143
2144 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
2145 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
2146
2147 retval = slot->hpc_ops->get_cur_bus_speed(slot, value);
2148 if (retval < 0)
2149 diff --git a/drivers/pci/hotplug/pciehp_ctrl.c b/drivers/pci/hotplug/pciehp_ctrl.c
2150 index 96a5d55..7266fbd 100644
2151 --- a/drivers/pci/hotplug/pciehp_ctrl.c
2152 +++ b/drivers/pci/hotplug/pciehp_ctrl.c
2153 @@ -65,7 +65,7 @@ u8 pciehp_handle_attention_button(struct slot *p_slot)
2154 /*
2155 * Button pressed - See if need to TAKE ACTION!!!
2156 */
2157 - info("Button pressed on Slot(%s)\n", p_slot->name);
2158 + info("Button pressed on Slot(%s)\n", slot_name(p_slot));
2159 event_type = INT_BUTTON_PRESS;
2160
2161 queue_interrupt_event(p_slot, event_type);
2162 @@ -86,13 +86,13 @@ u8 pciehp_handle_switch_change(struct slot *p_slot)
2163 /*
2164 * Switch opened
2165 */
2166 - info("Latch open on Slot(%s)\n", p_slot->name);
2167 + info("Latch open on Slot(%s)\n", slot_name(p_slot));
2168 event_type = INT_SWITCH_OPEN;
2169 } else {
2170 /*
2171 * Switch closed
2172 */
2173 - info("Latch close on Slot(%s)\n", p_slot->name);
2174 + info("Latch close on Slot(%s)\n", slot_name(p_slot));
2175 event_type = INT_SWITCH_CLOSE;
2176 }
2177
2178 @@ -117,13 +117,13 @@ u8 pciehp_handle_presence_change(struct slot *p_slot)
2179 /*
2180 * Card Present
2181 */
2182 - info("Card present on Slot(%s)\n", p_slot->name);
2183 + info("Card present on Slot(%s)\n", slot_name(p_slot));
2184 event_type = INT_PRESENCE_ON;
2185 } else {
2186 /*
2187 * Not Present
2188 */
2189 - info("Card not present on Slot(%s)\n", p_slot->name);
2190 + info("Card not present on Slot(%s)\n", slot_name(p_slot));
2191 event_type = INT_PRESENCE_OFF;
2192 }
2193
2194 @@ -143,13 +143,13 @@ u8 pciehp_handle_power_fault(struct slot *p_slot)
2195 /*
2196 * power fault Cleared
2197 */
2198 - info("Power fault cleared on Slot(%s)\n", p_slot->name);
2199 + info("Power fault cleared on Slot(%s)\n", slot_name(p_slot));
2200 event_type = INT_POWER_FAULT_CLEAR;
2201 } else {
2202 /*
2203 * power fault
2204 */
2205 - info("Power fault on Slot(%s)\n", p_slot->name);
2206 + info("Power fault on Slot(%s)\n", slot_name(p_slot));
2207 event_type = INT_POWER_FAULT;
2208 info("power fault bit %x set\n", 0);
2209 }
2210 @@ -404,11 +404,11 @@ static void handle_button_press_event(struct slot *p_slot)
2211 if (getstatus) {
2212 p_slot->state = BLINKINGOFF_STATE;
2213 info("PCI slot #%s - powering off due to button "
2214 - "press.\n", p_slot->name);
2215 + "press.\n", slot_name(p_slot));
2216 } else {
2217 p_slot->state = BLINKINGON_STATE;
2218 info("PCI slot #%s - powering on due to button "
2219 - "press.\n", p_slot->name);
2220 + "press.\n", slot_name(p_slot));
2221 }
2222 /* blink green LED and turn off amber */
2223 if (PWR_LED(ctrl))
2224 @@ -425,7 +425,7 @@ static void handle_button_press_event(struct slot *p_slot)
2225 * press the attention again before the 5 sec. limit
2226 * expires to cancel hot-add or hot-remove
2227 */
2228 - info("Button cancel on Slot(%s)\n", p_slot->name);
2229 + info("Button cancel on Slot(%s)\n", slot_name(p_slot));
2230 dbg("%s: button cancel\n", __func__);
2231 cancel_delayed_work(&p_slot->work);
2232 if (p_slot->state == BLINKINGOFF_STATE) {
2233 @@ -438,7 +438,7 @@ static void handle_button_press_event(struct slot *p_slot)
2234 if (ATTN_LED(ctrl))
2235 p_slot->hpc_ops->set_attention_status(p_slot, 0);
2236 info("PCI slot #%s - action canceled due to button press\n",
2237 - p_slot->name);
2238 + slot_name(p_slot));
2239 p_slot->state = STATIC_STATE;
2240 break;
2241 case POWEROFF_STATE:
2242 @@ -448,7 +448,7 @@ static void handle_button_press_event(struct slot *p_slot)
2243 * this means that the previous attention button action
2244 * to hot-add or hot-remove is undergoing
2245 */
2246 - info("Button ignore on Slot(%s)\n", p_slot->name);
2247 + info("Button ignore on Slot(%s)\n", slot_name(p_slot));
2248 update_slot_info(p_slot);
2249 break;
2250 default:
2251 @@ -529,7 +529,7 @@ int pciehp_enable_slot(struct slot *p_slot)
2252 rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
2253 if (rc || !getstatus) {
2254 info("%s: no adapter on slot(%s)\n", __func__,
2255 - p_slot->name);
2256 + slot_name(p_slot));
2257 mutex_unlock(&p_slot->ctrl->crit_sect);
2258 return -ENODEV;
2259 }
2260 @@ -537,7 +537,7 @@ int pciehp_enable_slot(struct slot *p_slot)
2261 rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
2262 if (rc || getstatus) {
2263 info("%s: latch open on slot(%s)\n", __func__,
2264 - p_slot->name);
2265 + slot_name(p_slot));
2266 mutex_unlock(&p_slot->ctrl->crit_sect);
2267 return -ENODEV;
2268 }
2269 @@ -547,7 +547,7 @@ int pciehp_enable_slot(struct slot *p_slot)
2270 rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
2271 if (rc || getstatus) {
2272 info("%s: already enabled on slot(%s)\n", __func__,
2273 - p_slot->name);
2274 + slot_name(p_slot));
2275 mutex_unlock(&p_slot->ctrl->crit_sect);
2276 return -EINVAL;
2277 }
2278 @@ -582,7 +582,7 @@ int pciehp_disable_slot(struct slot *p_slot)
2279 ret = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
2280 if (ret || !getstatus) {
2281 info("%s: no adapter on slot(%s)\n", __func__,
2282 - p_slot->name);
2283 + slot_name(p_slot));
2284 mutex_unlock(&p_slot->ctrl->crit_sect);
2285 return -ENODEV;
2286 }
2287 @@ -592,7 +592,7 @@ int pciehp_disable_slot(struct slot *p_slot)
2288 ret = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
2289 if (ret || getstatus) {
2290 info("%s: latch open on slot(%s)\n", __func__,
2291 - p_slot->name);
2292 + slot_name(p_slot));
2293 mutex_unlock(&p_slot->ctrl->crit_sect);
2294 return -ENODEV;
2295 }
2296 @@ -602,7 +602,7 @@ int pciehp_disable_slot(struct slot *p_slot)
2297 ret = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
2298 if (ret || !getstatus) {
2299 info("%s: already disabled slot(%s)\n", __func__,
2300 - p_slot->name);
2301 + slot_name(p_slot));
2302 mutex_unlock(&p_slot->ctrl->crit_sect);
2303 return -EINVAL;
2304 }
2305 @@ -632,14 +632,14 @@ int pciehp_sysfs_enable_slot(struct slot *p_slot)
2306 break;
2307 case POWERON_STATE:
2308 info("Slot %s is already in powering on state\n",
2309 - p_slot->name);
2310 + slot_name(p_slot));
2311 break;
2312 case BLINKINGOFF_STATE:
2313 case POWEROFF_STATE:
2314 - info("Already enabled on slot %s\n", p_slot->name);
2315 + info("Already enabled on slot %s\n", slot_name(p_slot));
2316 break;
2317 default:
2318 - err("Not a valid state on slot %s\n", p_slot->name);
2319 + err("Not a valid state on slot %s\n", slot_name(p_slot));
2320 break;
2321 }
2322 mutex_unlock(&p_slot->lock);
2323 @@ -664,14 +664,14 @@ int pciehp_sysfs_disable_slot(struct slot *p_slot)
2324 break;
2325 case POWEROFF_STATE:
2326 info("Slot %s is already in powering off state\n",
2327 - p_slot->name);
2328 + slot_name(p_slot));
2329 break;
2330 case BLINKINGON_STATE:
2331 case POWERON_STATE:
2332 - info("Already disabled on slot %s\n", p_slot->name);
2333 + info("Already disabled on slot %s\n", slot_name(p_slot));
2334 break;
2335 default:
2336 - err("Not a valid state on slot %s\n", p_slot->name);
2337 + err("Not a valid state on slot %s\n", slot_name(p_slot));
2338 break;
2339 }
2340 mutex_unlock(&p_slot->lock);
2341 diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c
2342 index 9d934dd..d3cf6f9 100644
2343 --- a/drivers/pci/hotplug/pciehp_hpc.c
2344 +++ b/drivers/pci/hotplug/pciehp_hpc.c
2345 @@ -1044,7 +1044,6 @@ static int pcie_init_slot(struct controller *ctrl)
2346 slot->device = ctrl->slot_device_offset + slot->hp_slot;
2347 slot->hpc_ops = ctrl->hpc_ops;
2348 slot->number = ctrl->first_slot;
2349 - snprintf(slot->name, SLOT_NAME_SIZE, "%d", slot->number);
2350 mutex_init(&slot->lock);
2351 INIT_DELAYED_WORK(&slot->work, pciehp_queue_pushbutton_work);
2352 list_add(&slot->slot_list, &ctrl->slot_list);
2353 diff --git a/drivers/pci/hotplug/rpaphp_slot.c b/drivers/pci/hotplug/rpaphp_slot.c
2354 index 9b714ea..23be8a2 100644
2355 --- a/drivers/pci/hotplug/rpaphp_slot.c
2356 +++ b/drivers/pci/hotplug/rpaphp_slot.c
2357 @@ -43,7 +43,7 @@ static void rpaphp_release_slot(struct hotplug_slot *hotplug_slot)
2358 void dealloc_slot_struct(struct slot *slot)
2359 {
2360 kfree(slot->hotplug_slot->info);
2361 - kfree(slot->hotplug_slot->name);
2362 + kfree(slot->name);
2363 kfree(slot->hotplug_slot);
2364 kfree(slot);
2365 }
2366 @@ -63,11 +63,9 @@ struct slot *alloc_slot_struct(struct device_node *dn,
2367 GFP_KERNEL);
2368 if (!slot->hotplug_slot->info)
2369 goto error_hpslot;
2370 - slot->hotplug_slot->name = kmalloc(strlen(drc_name) + 1, GFP_KERNEL);
2371 - if (!slot->hotplug_slot->name)
2372 + slot->name = kstrdup(drc_name, GFP_KERNEL);
2373 + if (!slot->name)
2374 goto error_info;
2375 - slot->name = slot->hotplug_slot->name;
2376 - strcpy(slot->name, drc_name);
2377 slot->dn = dn;
2378 slot->index = drc_index;
2379 slot->power_domain = power_domain;
2380 @@ -137,7 +135,7 @@ int rpaphp_register_slot(struct slot *slot)
2381 slotno = PCI_SLOT(PCI_DN(slot->dn->child)->devfn);
2382 else
2383 slotno = -1;
2384 - retval = pci_hp_register(php_slot, slot->bus, slotno);
2385 + retval = pci_hp_register(php_slot, slot->bus, slotno, slot->name);
2386 if (retval) {
2387 err("pci_hp_register failed with error %d\n", retval);
2388 return retval;
2389 diff --git a/drivers/pci/hotplug/sgi_hotplug.c b/drivers/pci/hotplug/sgi_hotplug.c
2390 index 410fe03..d748698 100644
2391 --- a/drivers/pci/hotplug/sgi_hotplug.c
2392 +++ b/drivers/pci/hotplug/sgi_hotplug.c
2393 @@ -161,7 +161,8 @@ static int sn_pci_bus_valid(struct pci_bus *pci_bus)
2394 }
2395
2396 static int sn_hp_slot_private_alloc(struct hotplug_slot *bss_hotplug_slot,
2397 - struct pci_bus *pci_bus, int device)
2398 + struct pci_bus *pci_bus, int device,
2399 + char *name)
2400 {
2401 struct pcibus_info *pcibus_info;
2402 struct slot *slot;
2403 @@ -173,15 +174,9 @@ static int sn_hp_slot_private_alloc(struct hotplug_slot *bss_hotplug_slot,
2404 return -ENOMEM;
2405 bss_hotplug_slot->private = slot;
2406
2407 - bss_hotplug_slot->name = kmalloc(SN_SLOT_NAME_SIZE, GFP_KERNEL);
2408 - if (!bss_hotplug_slot->name) {
2409 - kfree(bss_hotplug_slot->private);
2410 - return -ENOMEM;
2411 - }
2412 -
2413 slot->device_num = device;
2414 slot->pci_bus = pci_bus;
2415 - sprintf(bss_hotplug_slot->name, "%04x:%02x:%02x",
2416 + sprintf(name, "%04x:%02x:%02x",
2417 pci_domain_nr(pci_bus),
2418 ((u16)pcibus_info->pbi_buscommon.bs_persist_busnum),
2419 device + 1);
2420 @@ -608,7 +603,6 @@ static inline int get_power_status(struct hotplug_slot *bss_hotplug_slot,
2421 static void sn_release_slot(struct hotplug_slot *bss_hotplug_slot)
2422 {
2423 kfree(bss_hotplug_slot->info);
2424 - kfree(bss_hotplug_slot->name);
2425 kfree(bss_hotplug_slot->private);
2426 kfree(bss_hotplug_slot);
2427 }
2428 @@ -618,6 +612,7 @@ static int sn_hotplug_slot_register(struct pci_bus *pci_bus)
2429 int device;
2430 struct pci_slot *pci_slot;
2431 struct hotplug_slot *bss_hotplug_slot;
2432 + char name[SN_SLOT_NAME_SIZE];
2433 int rc = 0;
2434
2435 /*
2436 @@ -645,15 +640,14 @@ static int sn_hotplug_slot_register(struct pci_bus *pci_bus)
2437 }
2438
2439 if (sn_hp_slot_private_alloc(bss_hotplug_slot,
2440 - pci_bus, device)) {
2441 + pci_bus, device, name)) {
2442 rc = -ENOMEM;
2443 goto alloc_err;
2444 }
2445 -
2446 bss_hotplug_slot->ops = &sn_hotplug_slot_ops;
2447 bss_hotplug_slot->release = &sn_release_slot;
2448
2449 - rc = pci_hp_register(bss_hotplug_slot, pci_bus, device);
2450 + rc = pci_hp_register(bss_hotplug_slot, pci_bus, device, name);
2451 if (rc)
2452 goto register_err;
2453
2454 diff --git a/drivers/pci/hotplug/shpchp.h b/drivers/pci/hotplug/shpchp.h
2455 index 8a026f7..4d9fed0 100644
2456 --- a/drivers/pci/hotplug/shpchp.h
2457 +++ b/drivers/pci/hotplug/shpchp.h
2458 @@ -69,15 +69,13 @@ struct slot {
2459 u8 state;
2460 u8 presence_save;
2461 u8 pwr_save;
2462 - struct timer_list task_event;
2463 - u8 hp_slot;
2464 struct controller *ctrl;
2465 struct hpc_ops *hpc_ops;
2466 struct hotplug_slot *hotplug_slot;
2467 struct list_head slot_list;
2468 - char name[SLOT_NAME_SIZE];
2469 struct delayed_work work; /* work for button event */
2470 struct mutex lock;
2471 + u8 hp_slot;
2472 };
2473
2474 struct event_info {
2475 @@ -169,6 +167,11 @@ extern void cleanup_slots(struct controller *ctrl);
2476 extern void shpchp_queue_pushbutton_work(struct work_struct *work);
2477 extern int shpc_init( struct controller *ctrl, struct pci_dev *pdev);
2478
2479 +static inline const char *slot_name(struct slot *slot)
2480 +{
2481 + return hotplug_slot_name(slot->hotplug_slot);
2482 +}
2483 +
2484 #ifdef CONFIG_ACPI
2485 #include <linux/pci-acpi.h>
2486 static inline int get_hp_params_from_firmware(struct pci_dev *dev,
2487 diff --git a/drivers/pci/hotplug/shpchp_core.c b/drivers/pci/hotplug/shpchp_core.c
2488 index cc38615..7af9191 100644
2489 --- a/drivers/pci/hotplug/shpchp_core.c
2490 +++ b/drivers/pci/hotplug/shpchp_core.c
2491 @@ -89,7 +89,7 @@ static void release_slot(struct hotplug_slot *hotplug_slot)
2492 {
2493 struct slot *slot = hotplug_slot->private;
2494
2495 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
2496 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
2497
2498 kfree(slot->hotplug_slot->info);
2499 kfree(slot->hotplug_slot);
2500 @@ -101,8 +101,9 @@ static int init_slots(struct controller *ctrl)
2501 struct slot *slot;
2502 struct hotplug_slot *hotplug_slot;
2503 struct hotplug_slot_info *info;
2504 + char name[SLOT_NAME_SIZE];
2505 int retval = -ENOMEM;
2506 - int i, len, dup = 1;
2507 + int i;
2508
2509 for (i = 0; i < ctrl->num_slots; i++) {
2510 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
2511 @@ -119,8 +120,6 @@ static int init_slots(struct controller *ctrl)
2512 goto error_hpslot;
2513 hotplug_slot->info = info;
2514
2515 - hotplug_slot->name = slot->name;
2516 -
2517 slot->hp_slot = i;
2518 slot->ctrl = ctrl;
2519 slot->bus = ctrl->pci_dev->subordinate->number;
2520 @@ -133,37 +132,24 @@ static int init_slots(struct controller *ctrl)
2521 /* register this slot with the hotplug pci core */
2522 hotplug_slot->private = slot;
2523 hotplug_slot->release = &release_slot;
2524 - snprintf(slot->name, SLOT_NAME_SIZE, "%d", slot->number);
2525 + snprintf(name, SLOT_NAME_SIZE, "%d", slot->number);
2526 hotplug_slot->ops = &shpchp_hotplug_slot_ops;
2527
2528 - get_power_status(hotplug_slot, &info->power_status);
2529 - get_attention_status(hotplug_slot, &info->attention_status);
2530 - get_latch_status(hotplug_slot, &info->latch_status);
2531 - get_adapter_status(hotplug_slot, &info->adapter_status);
2532 -
2533 dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x "
2534 "slot_device_offset=%x\n", slot->bus, slot->device,
2535 slot->hp_slot, slot->number, ctrl->slot_device_offset);
2536 -duplicate_name:
2537 retval = pci_hp_register(slot->hotplug_slot,
2538 - ctrl->pci_dev->subordinate, slot->device);
2539 + ctrl->pci_dev->subordinate, slot->device, name);
2540 if (retval) {
2541 - /*
2542 - * If slot N already exists, we'll try to create
2543 - * slot N-1, N-2 ... N-M, until we overflow.
2544 - */
2545 - if (retval == -EEXIST) {
2546 - len = snprintf(slot->name, SLOT_NAME_SIZE,
2547 - "%d-%d", slot->number, dup++);
2548 - if (len < SLOT_NAME_SIZE)
2549 - goto duplicate_name;
2550 - else
2551 - err("duplicate slot name overflow\n");
2552 - }
2553 err("pci_hp_register failed with error %d\n", retval);
2554 goto error_info;
2555 }
2556
2557 + get_power_status(hotplug_slot, &info->power_status);
2558 + get_attention_status(hotplug_slot, &info->attention_status);
2559 + get_latch_status(hotplug_slot, &info->latch_status);
2560 + get_adapter_status(hotplug_slot, &info->adapter_status);
2561 +
2562 list_add(&slot->slot_list, &ctrl->slot_list);
2563 }
2564
2565 @@ -201,7 +187,7 @@ static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status)
2566 {
2567 struct slot *slot = get_slot(hotplug_slot);
2568
2569 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
2570 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
2571
2572 hotplug_slot->info->attention_status = status;
2573 slot->hpc_ops->set_attention_status(slot, status);
2574 @@ -213,7 +199,7 @@ static int enable_slot (struct hotplug_slot *hotplug_slot)
2575 {
2576 struct slot *slot = get_slot(hotplug_slot);
2577
2578 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
2579 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
2580
2581 return shpchp_sysfs_enable_slot(slot);
2582 }
2583 @@ -222,7 +208,7 @@ static int disable_slot (struct hotplug_slot *hotplug_slot)
2584 {
2585 struct slot *slot = get_slot(hotplug_slot);
2586
2587 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
2588 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
2589
2590 return shpchp_sysfs_disable_slot(slot);
2591 }
2592 @@ -232,7 +218,7 @@ static int get_power_status (struct hotplug_slot *hotplug_slot, u8 *value)
2593 struct slot *slot = get_slot(hotplug_slot);
2594 int retval;
2595
2596 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
2597 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
2598
2599 retval = slot->hpc_ops->get_power_status(slot, value);
2600 if (retval < 0)
2601 @@ -246,7 +232,7 @@ static int get_attention_status (struct hotplug_slot *hotplug_slot, u8 *value)
2602 struct slot *slot = get_slot(hotplug_slot);
2603 int retval;
2604
2605 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
2606 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
2607
2608 retval = slot->hpc_ops->get_attention_status(slot, value);
2609 if (retval < 0)
2610 @@ -260,7 +246,7 @@ static int get_latch_status (struct hotplug_slot *hotplug_slot, u8 *value)
2611 struct slot *slot = get_slot(hotplug_slot);
2612 int retval;
2613
2614 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
2615 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
2616
2617 retval = slot->hpc_ops->get_latch_status(slot, value);
2618 if (retval < 0)
2619 @@ -274,7 +260,7 @@ static int get_adapter_status (struct hotplug_slot *hotplug_slot, u8 *value)
2620 struct slot *slot = get_slot(hotplug_slot);
2621 int retval;
2622
2623 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
2624 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
2625
2626 retval = slot->hpc_ops->get_adapter_status(slot, value);
2627 if (retval < 0)
2628 @@ -289,7 +275,7 @@ static int get_max_bus_speed(struct hotplug_slot *hotplug_slot,
2629 struct slot *slot = get_slot(hotplug_slot);
2630 int retval;
2631
2632 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
2633 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
2634
2635 retval = slot->hpc_ops->get_max_bus_speed(slot, value);
2636 if (retval < 0)
2637 @@ -303,7 +289,7 @@ static int get_cur_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_sp
2638 struct slot *slot = get_slot(hotplug_slot);
2639 int retval;
2640
2641 - dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
2642 + dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
2643
2644 retval = slot->hpc_ops->get_cur_bus_speed(slot, value);
2645 if (retval < 0)
2646 diff --git a/drivers/pci/hotplug/shpchp_ctrl.c b/drivers/pci/hotplug/shpchp_ctrl.c
2647 index dfb5393..919b1ee 100644
2648 --- a/drivers/pci/hotplug/shpchp_ctrl.c
2649 +++ b/drivers/pci/hotplug/shpchp_ctrl.c
2650 @@ -70,7 +70,7 @@ u8 shpchp_handle_attention_button(u8 hp_slot, struct controller *ctrl)
2651 /*
2652 * Button pressed - See if need to TAKE ACTION!!!
2653 */
2654 - info("Button pressed on Slot(%s)\n", p_slot->name);
2655 + info("Button pressed on Slot(%s)\n", slot_name(p_slot));
2656 event_type = INT_BUTTON_PRESS;
2657
2658 queue_interrupt_event(p_slot, event_type);
2659 @@ -98,7 +98,7 @@ u8 shpchp_handle_switch_change(u8 hp_slot, struct controller *ctrl)
2660 /*
2661 * Switch opened
2662 */
2663 - info("Latch open on Slot(%s)\n", p_slot->name);
2664 + info("Latch open on Slot(%s)\n", slot_name(p_slot));
2665 event_type = INT_SWITCH_OPEN;
2666 if (p_slot->pwr_save && p_slot->presence_save) {
2667 event_type = INT_POWER_FAULT;
2668 @@ -108,7 +108,7 @@ u8 shpchp_handle_switch_change(u8 hp_slot, struct controller *ctrl)
2669 /*
2670 * Switch closed
2671 */
2672 - info("Latch close on Slot(%s)\n", p_slot->name);
2673 + info("Latch close on Slot(%s)\n", slot_name(p_slot));
2674 event_type = INT_SWITCH_CLOSE;
2675 }
2676
2677 @@ -135,13 +135,13 @@ u8 shpchp_handle_presence_change(u8 hp_slot, struct controller *ctrl)
2678 /*
2679 * Card Present
2680 */
2681 - info("Card present on Slot(%s)\n", p_slot->name);
2682 + info("Card present on Slot(%s)\n", slot_name(p_slot));
2683 event_type = INT_PRESENCE_ON;
2684 } else {
2685 /*
2686 * Not Present
2687 */
2688 - info("Card not present on Slot(%s)\n", p_slot->name);
2689 + info("Card not present on Slot(%s)\n", slot_name(p_slot));
2690 event_type = INT_PRESENCE_OFF;
2691 }
2692
2693 @@ -164,14 +164,14 @@ u8 shpchp_handle_power_fault(u8 hp_slot, struct controller *ctrl)
2694 /*
2695 * Power fault Cleared
2696 */
2697 - info("Power fault cleared on Slot(%s)\n", p_slot->name);
2698 + info("Power fault cleared on Slot(%s)\n", slot_name(p_slot));
2699 p_slot->status = 0x00;
2700 event_type = INT_POWER_FAULT_CLEAR;
2701 } else {
2702 /*
2703 * Power fault
2704 */
2705 - info("Power fault on Slot(%s)\n", p_slot->name);
2706 + info("Power fault on Slot(%s)\n", slot_name(p_slot));
2707 event_type = INT_POWER_FAULT;
2708 /* set power fault status for this board */
2709 p_slot->status = 0xFF;
2710 @@ -493,11 +493,11 @@ static void handle_button_press_event(struct slot *p_slot)
2711 if (getstatus) {
2712 p_slot->state = BLINKINGOFF_STATE;
2713 info("PCI slot #%s - powering off due to button "
2714 - "press.\n", p_slot->name);
2715 + "press.\n", slot_name(p_slot));
2716 } else {
2717 p_slot->state = BLINKINGON_STATE;
2718 info("PCI slot #%s - powering on due to button "
2719 - "press.\n", p_slot->name);
2720 + "press.\n", slot_name(p_slot));
2721 }
2722 /* blink green LED and turn off amber */
2723 p_slot->hpc_ops->green_led_blink(p_slot);
2724 @@ -512,7 +512,7 @@ static void handle_button_press_event(struct slot *p_slot)
2725 * press the attention again before the 5 sec. limit
2726 * expires to cancel hot-add or hot-remove
2727 */
2728 - info("Button cancel on Slot(%s)\n", p_slot->name);
2729 + info("Button cancel on Slot(%s)\n", slot_name(p_slot));
2730 dbg("%s: button cancel\n", __func__);
2731 cancel_delayed_work(&p_slot->work);
2732 if (p_slot->state == BLINKINGOFF_STATE)
2733 @@ -521,7 +521,7 @@ static void handle_button_press_event(struct slot *p_slot)
2734 p_slot->hpc_ops->green_led_off(p_slot);
2735 p_slot->hpc_ops->set_attention_status(p_slot, 0);
2736 info("PCI slot #%s - action canceled due to button press\n",
2737 - p_slot->name);
2738 + slot_name(p_slot));
2739 p_slot->state = STATIC_STATE;
2740 break;
2741 case POWEROFF_STATE:
2742 @@ -531,7 +531,7 @@ static void handle_button_press_event(struct slot *p_slot)
2743 * this means that the previous attention button action
2744 * to hot-add or hot-remove is undergoing
2745 */
2746 - info("Button ignore on Slot(%s)\n", p_slot->name);
2747 + info("Button ignore on Slot(%s)\n", slot_name(p_slot));
2748 update_slot_info(p_slot);
2749 break;
2750 default:
2751 @@ -574,17 +574,17 @@ static int shpchp_enable_slot (struct slot *p_slot)
2752 mutex_lock(&p_slot->ctrl->crit_sect);
2753 rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
2754 if (rc || !getstatus) {
2755 - info("No adapter on slot(%s)\n", p_slot->name);
2756 + info("No adapter on slot(%s)\n", slot_name(p_slot));
2757 goto out;
2758 }
2759 rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
2760 if (rc || getstatus) {
2761 - info("Latch open on slot(%s)\n", p_slot->name);
2762 + info("Latch open on slot(%s)\n", slot_name(p_slot));
2763 goto out;
2764 }
2765 rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
2766 if (rc || getstatus) {
2767 - info("Already enabled on slot(%s)\n", p_slot->name);
2768 + info("Already enabled on slot(%s)\n", slot_name(p_slot));
2769 goto out;
2770 }
2771
2772 @@ -633,17 +633,17 @@ static int shpchp_disable_slot (struct slot *p_slot)
2773
2774 rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
2775 if (rc || !getstatus) {
2776 - info("No adapter on slot(%s)\n", p_slot->name);
2777 + info("No adapter on slot(%s)\n", slot_name(p_slot));
2778 goto out;
2779 }
2780 rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
2781 if (rc || getstatus) {
2782 - info("Latch open on slot(%s)\n", p_slot->name);
2783 + info("Latch open on slot(%s)\n", slot_name(p_slot));
2784 goto out;
2785 }
2786 rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
2787 if (rc || !getstatus) {
2788 - info("Already disabled slot(%s)\n", p_slot->name);
2789 + info("Already disabled slot(%s)\n", slot_name(p_slot));
2790 goto out;
2791 }
2792
2793 @@ -671,14 +671,14 @@ int shpchp_sysfs_enable_slot(struct slot *p_slot)
2794 break;
2795 case POWERON_STATE:
2796 info("Slot %s is already in powering on state\n",
2797 - p_slot->name);
2798 + slot_name(p_slot));
2799 break;
2800 case BLINKINGOFF_STATE:
2801 case POWEROFF_STATE:
2802 - info("Already enabled on slot %s\n", p_slot->name);
2803 + info("Already enabled on slot %s\n", slot_name(p_slot));
2804 break;
2805 default:
2806 - err("Not a valid state on slot %s\n", p_slot->name);
2807 + err("Not a valid state on slot %s\n", slot_name(p_slot));
2808 break;
2809 }
2810 mutex_unlock(&p_slot->lock);
2811 @@ -703,14 +703,14 @@ int shpchp_sysfs_disable_slot(struct slot *p_slot)
2812 break;
2813 case POWEROFF_STATE:
2814 info("Slot %s is already in powering off state\n",
2815 - p_slot->name);
2816 + slot_name(p_slot));
2817 break;
2818 case BLINKINGON_STATE:
2819 case POWERON_STATE:
2820 - info("Already disabled on slot %s\n", p_slot->name);
2821 + info("Already disabled on slot %s\n", slot_name(p_slot));
2822 break;
2823 default:
2824 - err("Not a valid state on slot %s\n", p_slot->name);
2825 + err("Not a valid state on slot %s\n", slot_name(p_slot));
2826 break;
2827 }
2828 mutex_unlock(&p_slot->lock);
2829 diff --git a/drivers/pci/slot.c b/drivers/pci/slot.c
2830 index 7e5b85c..b703b09 100644
2831 --- a/drivers/pci/slot.c
2832 +++ b/drivers/pci/slot.c
2833 @@ -73,18 +73,100 @@ static struct kobj_type pci_slot_ktype = {
2834 .default_attrs = pci_slot_default_attrs,
2835 };
2836
2837 +static char *make_slot_name(const char *name)
2838 +{
2839 + char *new_name;
2840 + int len, max, dup;
2841 +
2842 + new_name = kstrdup(name, GFP_KERNEL);
2843 + if (!new_name)
2844 + return NULL;
2845 +
2846 + /*
2847 + * Make sure we hit the realloc case the first time through the
2848 + * loop. 'len' will be strlen(name) + 3 at that point which is
2849 + * enough space for "name-X" and the trailing NUL.
2850 + */
2851 + len = strlen(name) + 2;
2852 + max = 1;
2853 + dup = 1;
2854 +
2855 + for (;;) {
2856 + struct kobject *dup_slot;
2857 + dup_slot = kset_find_obj(pci_slots_kset, new_name);
2858 + if (!dup_slot)
2859 + break;
2860 + kobject_put(dup_slot);
2861 + if (dup == max) {
2862 + len++;
2863 + max *= 10;
2864 + kfree(new_name);
2865 + new_name = kmalloc(len, GFP_KERNEL);
2866 + if (!new_name)
2867 + break;
2868 + }
2869 + sprintf(new_name, "%s-%d", name, dup++);
2870 + }
2871 +
2872 + return new_name;
2873 +}
2874 +
2875 +static int rename_slot(struct pci_slot *slot, const char *name)
2876 +{
2877 + int result = 0;
2878 + char *slot_name;
2879 +
2880 + if (strcmp(pci_slot_name(slot), name) == 0)
2881 + return result;
2882 +
2883 + slot_name = make_slot_name(name);
2884 + if (!slot_name)
2885 + return -ENOMEM;
2886 +
2887 + result = kobject_rename(&slot->kobj, slot_name);
2888 + kfree(slot_name);
2889 +
2890 + return result;
2891 +}
2892 +
2893 +static struct pci_slot *get_slot(struct pci_bus *parent, int slot_nr)
2894 +{
2895 + struct pci_slot *slot;
2896 + /*
2897 + * We already hold pci_bus_sem so don't worry
2898 + */
2899 + list_for_each_entry(slot, &parent->slots, list)
2900 + if (slot->number == slot_nr) {
2901 + kobject_get(&slot->kobj);
2902 + return slot;
2903 + }
2904 +
2905 + return NULL;
2906 +}
2907 +
2908 /**
2909 * pci_create_slot - create or increment refcount for physical PCI slot
2910 * @parent: struct pci_bus of parent bridge
2911 * @slot_nr: PCI_SLOT(pci_dev->devfn) or -1 for placeholder
2912 * @name: user visible string presented in /sys/bus/pci/slots/<name>
2913 + * @hotplug: set if caller is hotplug driver, NULL otherwise
2914 *
2915 * PCI slots have first class attributes such as address, speed, width,
2916 * and a &struct pci_slot is used to manage them. This interface will
2917 * either return a new &struct pci_slot to the caller, or if the pci_slot
2918 * already exists, its refcount will be incremented.
2919 *
2920 - * Slots are uniquely identified by a @pci_bus, @slot_nr, @name tuple.
2921 + * Slots are uniquely identified by a @pci_bus, @slot_nr tuple.
2922 + *
2923 + * There are known platforms with broken firmware that assign the same
2924 + * name to multiple slots. Workaround these broken platforms by renaming
2925 + * the slots on behalf of the caller. If firmware assigns name N to
2926 + * multiple slots:
2927 + *
2928 + * The first slot is assigned N
2929 + * The second slot is assigned N-1
2930 + * The third slot is assigned N-2
2931 + * etc.
2932 *
2933 * Placeholder slots:
2934 * In most cases, @pci_bus, @slot_nr will be sufficient to uniquely identify
2935 @@ -93,12 +175,8 @@ static struct kobj_type pci_slot_ktype = {
2936 * the slot. In this scenario, the caller may pass -1 for @slot_nr.
2937 *
2938 * The following semantics are imposed when the caller passes @slot_nr ==
2939 - * -1. First, the check for existing %struct pci_slot is skipped, as the
2940 - * caller may know about several unpopulated slots on a given %struct
2941 - * pci_bus, and each slot would have a @slot_nr of -1. Uniqueness for
2942 - * these slots is then determined by the @name parameter. We expect
2943 - * kobject_init_and_add() to warn us if the caller attempts to create
2944 - * multiple slots with the same name. The other change in semantics is
2945 + * -1. First, we no longer check for an existing %struct pci_slot, as there
2946 + * may be many slots with @slot_nr of -1. The other change in semantics is
2947 * user-visible, which is the 'address' parameter presented in sysfs will
2948 * consist solely of a dddd:bb tuple, where dddd is the PCI domain of the
2949 * %struct pci_bus and bb is the bus number. In other words, the devfn of
2950 @@ -106,47 +184,57 @@ static struct kobj_type pci_slot_ktype = {
2951 */
2952
2953 struct pci_slot *pci_create_slot(struct pci_bus *parent, int slot_nr,
2954 - const char *name)
2955 + const char *name,
2956 + struct hotplug_slot *hotplug)
2957 {
2958 struct pci_slot *slot;
2959 - int err;
2960 + int err = 0;
2961 + char *slot_name = NULL;
2962
2963 down_write(&pci_bus_sem);
2964
2965 if (slot_nr == -1)
2966 goto placeholder;
2967
2968 - /* If we've already created this slot, bump refcount and return. */
2969 - list_for_each_entry(slot, &parent->slots, list) {
2970 - if (slot->number == slot_nr) {
2971 - kobject_get(&slot->kobj);
2972 - pr_debug("%s: inc refcount to %d on %04x:%02x:%02x\n",
2973 - __func__,
2974 - atomic_read(&slot->kobj.kref.refcount),
2975 - pci_domain_nr(parent), parent->number,
2976 - slot_nr);
2977 - goto out;
2978 + /*
2979 + * Hotplug drivers are allowed to rename an existing slot,
2980 + * but only if not already claimed.
2981 + */
2982 + slot = get_slot(parent, slot_nr);
2983 + if (slot) {
2984 + if (hotplug) {
2985 + if ((err = slot->hotplug ? -EBUSY : 0)
2986 + || (err = rename_slot(slot, name))) {
2987 + kobject_put(&slot->kobj);
2988 + slot = NULL;
2989 + goto err;
2990 + }
2991 }
2992 + goto out;
2993 }
2994
2995 placeholder:
2996 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
2997 if (!slot) {
2998 - slot = ERR_PTR(-ENOMEM);
2999 - goto out;
3000 + err = -ENOMEM;
3001 + goto err;
3002 }
3003
3004 slot->bus = parent;
3005 slot->number = slot_nr;
3006
3007 slot->kobj.kset = pci_slots_kset;
3008 - err = kobject_init_and_add(&slot->kobj, &pci_slot_ktype, NULL,
3009 - "%s", name);
3010 - if (err) {
3011 - printk(KERN_ERR "Unable to register kobject %s\n", name);
3012 + slot_name = make_slot_name(name);
3013 + if (!slot_name) {
3014 + err = -ENOMEM;
3015 goto err;
3016 }
3017
3018 + err = kobject_init_and_add(&slot->kobj, &pci_slot_ktype, NULL,
3019 + "%s", slot_name);
3020 + if (err)
3021 + goto err;
3022 +
3023 INIT_LIST_HEAD(&slot->list);
3024 list_add(&slot->list, &parent->slots);
3025
3026 @@ -154,10 +242,10 @@ placeholder:
3027 pr_debug("%s: created pci_slot on %04x:%02x:%02x\n",
3028 __func__, pci_domain_nr(parent), parent->number, slot_nr);
3029
3030 - out:
3031 +out:
3032 up_write(&pci_bus_sem);
3033 return slot;
3034 - err:
3035 +err:
3036 kfree(slot);
3037 slot = ERR_PTR(err);
3038 goto out;
3039 @@ -203,7 +291,6 @@ EXPORT_SYMBOL_GPL(pci_update_slot_number);
3040 * just call kobject_put on its kobj and let our release methods do the
3041 * rest.
3042 */
3043 -
3044 void pci_destroy_slot(struct pci_slot *slot)
3045 {
3046 pr_debug("%s: dec refcount to %d on %04x:%02x:%02x\n", __func__,
3047 diff --git a/drivers/spi/pxa2xx_spi.c b/drivers/spi/pxa2xx_spi.c
3048 index d47d363..b5fc978 100644
3049 --- a/drivers/spi/pxa2xx_spi.c
3050 +++ b/drivers/spi/pxa2xx_spi.c
3051 @@ -348,21 +348,21 @@ static int map_dma_buffers(struct driver_data *drv_data)
3052 } else
3053 drv_data->tx_map_len = drv_data->len;
3054
3055 - /* Stream map the rx buffer */
3056 - drv_data->rx_dma = dma_map_single(dev, drv_data->rx,
3057 - drv_data->rx_map_len,
3058 - DMA_FROM_DEVICE);
3059 - if (dma_mapping_error(dev, drv_data->rx_dma))
3060 - return 0;
3061 -
3062 - /* Stream map the tx buffer */
3063 + /* Stream map the tx buffer. Always do DMA_TO_DEVICE first
3064 + * so we flush the cache *before* invalidating it, in case
3065 + * the tx and rx buffers overlap.
3066 + */
3067 drv_data->tx_dma = dma_map_single(dev, drv_data->tx,
3068 - drv_data->tx_map_len,
3069 - DMA_TO_DEVICE);
3070 + drv_data->tx_map_len, DMA_TO_DEVICE);
3071 + if (dma_mapping_error(dev, drv_data->tx_dma))
3072 + return 0;
3073
3074 - if (dma_mapping_error(dev, drv_data->tx_dma)) {
3075 - dma_unmap_single(dev, drv_data->rx_dma,
3076 + /* Stream map the rx buffer */
3077 + drv_data->rx_dma = dma_map_single(dev, drv_data->rx,
3078 drv_data->rx_map_len, DMA_FROM_DEVICE);
3079 + if (dma_mapping_error(dev, drv_data->rx_dma)) {
3080 + dma_unmap_single(dev, drv_data->tx_dma,
3081 + drv_data->tx_map_len, DMA_TO_DEVICE);
3082 return 0;
3083 }
3084
3085 diff --git a/drivers/usb/gadget/f_rndis.c b/drivers/usb/gadget/f_rndis.c
3086 index 659b3d9..428b599 100644
3087 --- a/drivers/usb/gadget/f_rndis.c
3088 +++ b/drivers/usb/gadget/f_rndis.c
3089 @@ -172,7 +172,6 @@ static struct usb_interface_descriptor rndis_data_intf __initdata = {
3090 .bDescriptorType = USB_DT_INTERFACE,
3091
3092 /* .bInterfaceNumber = DYNAMIC */
3093 - .bAlternateSetting = 1,
3094 .bNumEndpoints = 2,
3095 .bInterfaceClass = USB_CLASS_CDC_DATA,
3096 .bInterfaceSubClass = 0,
3097 @@ -303,7 +302,7 @@ static void rndis_response_available(void *_rndis)
3098 __le32 *data = req->buf;
3099 int status;
3100
3101 - if (atomic_inc_return(&rndis->notify_count))
3102 + if (atomic_inc_return(&rndis->notify_count) != 1)
3103 return;
3104
3105 /* Send RNDIS RESPONSE_AVAILABLE notification; a
3106 diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
3107 index c46a58f..36864f9 100644
3108 --- a/drivers/usb/host/ehci-pci.c
3109 +++ b/drivers/usb/host/ehci-pci.c
3110 @@ -66,6 +66,8 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
3111 {
3112 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
3113 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
3114 + struct pci_dev *p_smbus;
3115 + u8 rev;
3116 u32 temp;
3117 int retval;
3118
3119 @@ -166,6 +168,28 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
3120 pci_write_config_byte(pdev, 0x4b, tmp | 0x20);
3121 }
3122 break;
3123 + case PCI_VENDOR_ID_ATI:
3124 + /* SB600 and old version of SB700 have a bug in EHCI controller,
3125 + * which causes usb devices lose response in some cases.
3126 + */
3127 + if ((pdev->device == 0x4386) || (pdev->device == 0x4396)) {
3128 + p_smbus = pci_get_device(PCI_VENDOR_ID_ATI,
3129 + PCI_DEVICE_ID_ATI_SBX00_SMBUS,
3130 + NULL);
3131 + if (!p_smbus)
3132 + break;
3133 + rev = p_smbus->revision;
3134 + if ((pdev->device == 0x4386) || (rev == 0x3a)
3135 + || (rev == 0x3b)) {
3136 + u8 tmp;
3137 + ehci_info(ehci, "applying AMD SB600/SB700 USB "
3138 + "freeze workaround\n");
3139 + pci_read_config_byte(pdev, 0x53, &tmp);
3140 + pci_write_config_byte(pdev, 0x53, tmp | (1<<3));
3141 + }
3142 + pci_dev_put(p_smbus);
3143 + }
3144 + break;
3145 }
3146
3147 ehci_reset(ehci);
3148 diff --git a/drivers/usb/mon/mon_bin.c b/drivers/usb/mon/mon_bin.c
3149 index 6566fc0..0ada0fc 100644
3150 --- a/drivers/usb/mon/mon_bin.c
3151 +++ b/drivers/usb/mon/mon_bin.c
3152 @@ -687,7 +687,10 @@ static ssize_t mon_bin_read(struct file *file, char __user *buf,
3153 }
3154
3155 if (rp->b_read >= sizeof(struct mon_bin_hdr)) {
3156 - step_len = min(nbytes, (size_t)ep->len_cap);
3157 + step_len = ep->len_cap;
3158 + step_len -= rp->b_read - sizeof(struct mon_bin_hdr);
3159 + if (step_len > nbytes)
3160 + step_len = nbytes;
3161 offset = rp->b_out + PKT_SIZE;
3162 offset += rp->b_read - sizeof(struct mon_bin_hdr);
3163 if (offset >= rp->b_size)
3164 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
3165 index 98843c2..3f050e2 100644
3166 --- a/drivers/video/fbmem.c
3167 +++ b/drivers/video/fbmem.c
3168 @@ -232,7 +232,7 @@ static void fb_set_logo_directpalette(struct fb_info *info,
3169 greenshift = info->var.green.offset;
3170 blueshift = info->var.blue.offset;
3171
3172 - for (i = 32; i < logo->clutsize; i++)
3173 + for (i = 32; i < 32 + logo->clutsize; i++)
3174 palette[i] = i << redshift | i << greenshift | i << blueshift;
3175 }
3176
3177 diff --git a/drivers/watchdog/hpwdt.c b/drivers/watchdog/hpwdt.c
3178 index a3765e0..763c1ea 100644
3179 --- a/drivers/watchdog/hpwdt.c
3180 +++ b/drivers/watchdog/hpwdt.c
3181 @@ -40,6 +40,7 @@
3182 #include <linux/bootmem.h>
3183 #include <linux/slab.h>
3184 #include <asm/desc.h>
3185 +#include <asm/cacheflush.h>
3186
3187 #define PCI_BIOS32_SD_VALUE 0x5F32335F /* "_32_" */
3188 #define CRU_BIOS_SIGNATURE_VALUE 0x55524324
3189 @@ -394,6 +395,8 @@ static void __devinit dmi_find_cru(const struct dmi_header *dm)
3190 smbios_cru64_ptr->double_offset;
3191 cru_rom_addr = ioremap(cru_physical_address,
3192 smbios_cru64_ptr->double_length);
3193 + set_memory_x((unsigned long)cru_rom_addr & PAGE_MASK,
3194 + smbios_cru64_ptr->double_length >> PAGE_SHIFT);
3195 }
3196 }
3197 }
3198 @@ -482,7 +485,7 @@ static int hpwdt_pretimeout(struct notifier_block *nb, unsigned long ulReason,
3199 "Management Log for details.\n");
3200 }
3201
3202 - return NOTIFY_STOP;
3203 + return NOTIFY_OK;
3204 }
3205
3206 /*
3207 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
3208 index 69a12aa..490e34b 100644
3209 --- a/fs/cifs/cifs_debug.c
3210 +++ b/fs/cifs/cifs_debug.c
3211 @@ -107,12 +107,13 @@ void cifs_dump_mids(struct TCP_Server_Info *server)
3212 #ifdef CONFIG_PROC_FS
3213 static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
3214 {
3215 - struct list_head *tmp;
3216 - struct list_head *tmp1;
3217 + struct list_head *tmp1, *tmp2, *tmp3;
3218 struct mid_q_entry *mid_entry;
3219 + struct TCP_Server_Info *server;
3220 struct cifsSesInfo *ses;
3221 struct cifsTconInfo *tcon;
3222 - int i;
3223 + int i, j;
3224 + __u32 dev_type;
3225
3226 seq_puts(m,
3227 "Display Internal CIFS Data Structures for Debugging\n"
3228 @@ -122,46 +123,78 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
3229 seq_printf(m, "Servers:");
3230
3231 i = 0;
3232 - read_lock(&GlobalSMBSeslock);
3233 - list_for_each(tmp, &GlobalSMBSessionList) {
3234 + read_lock(&cifs_tcp_ses_lock);
3235 + list_for_each(tmp1, &cifs_tcp_ses_list) {
3236 + server = list_entry(tmp1, struct TCP_Server_Info,
3237 + tcp_ses_list);
3238 i++;
3239 - ses = list_entry(tmp, struct cifsSesInfo, cifsSessionList);
3240 - if ((ses->serverDomain == NULL) || (ses->serverOS == NULL) ||
3241 - (ses->serverNOS == NULL)) {
3242 - seq_printf(m, "\nentry for %s not fully "
3243 - "displayed\n\t", ses->serverName);
3244 - } else {
3245 - seq_printf(m,
3246 - "\n%d) Name: %s Domain: %s Mounts: %d OS:"
3247 - " %s \n\tNOS: %s\tCapability: 0x%x\n\tSMB"
3248 + list_for_each(tmp2, &server->smb_ses_list) {
3249 + ses = list_entry(tmp2, struct cifsSesInfo,
3250 + smb_ses_list);
3251 + if ((ses->serverDomain == NULL) ||
3252 + (ses->serverOS == NULL) ||
3253 + (ses->serverNOS == NULL)) {
3254 + seq_printf(m, "\n%d) entry for %s not fully "
3255 + "displayed\n\t", i, ses->serverName);
3256 + } else {
3257 + seq_printf(m,
3258 + "\n%d) Name: %s Domain: %s Uses: %d OS:"
3259 + " %s\n\tNOS: %s\tCapability: 0x%x\n\tSMB"
3260 " session status: %d\t",
3261 i, ses->serverName, ses->serverDomain,
3262 - atomic_read(&ses->inUse),
3263 - ses->serverOS, ses->serverNOS,
3264 + ses->ses_count, ses->serverOS, ses->serverNOS,
3265 ses->capabilities, ses->status);
3266 - }
3267 - if (ses->server) {
3268 + }
3269 seq_printf(m, "TCP status: %d\n\tLocal Users To "
3270 - "Server: %d SecMode: 0x%x Req On Wire: %d",
3271 - ses->server->tcpStatus,
3272 - atomic_read(&ses->server->socketUseCount),
3273 - ses->server->secMode,
3274 - atomic_read(&ses->server->inFlight));
3275 + "Server: %d SecMode: 0x%x Req On Wire: %d",
3276 + server->tcpStatus, server->srv_count,
3277 + server->secMode,
3278 + atomic_read(&server->inFlight));
3279
3280 #ifdef CONFIG_CIFS_STATS2
3281 seq_printf(m, " In Send: %d In MaxReq Wait: %d",
3282 - atomic_read(&ses->server->inSend),
3283 - atomic_read(&ses->server->num_waiters));
3284 + atomic_read(&server->inSend),
3285 + atomic_read(&server->num_waiters));
3286 #endif
3287
3288 - seq_puts(m, "\nMIDs:\n");
3289 + seq_puts(m, "\n\tShares:");
3290 + j = 0;
3291 + list_for_each(tmp3, &ses->tcon_list) {
3292 + tcon = list_entry(tmp3, struct cifsTconInfo,
3293 + tcon_list);
3294 + ++j;
3295 + dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
3296 + seq_printf(m, "\n\t%d) %s Mounts: %d ", j,
3297 + tcon->treeName, tcon->tc_count);
3298 + if (tcon->nativeFileSystem) {
3299 + seq_printf(m, "Type: %s ",
3300 + tcon->nativeFileSystem);
3301 + }
3302 + seq_printf(m, "DevInfo: 0x%x Attributes: 0x%x"
3303 + "\nPathComponentMax: %d Status: 0x%d",
3304 + le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
3305 + le32_to_cpu(tcon->fsAttrInfo.Attributes),
3306 + le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
3307 + tcon->tidStatus);
3308 + if (dev_type == FILE_DEVICE_DISK)
3309 + seq_puts(m, " type: DISK ");
3310 + else if (dev_type == FILE_DEVICE_CD_ROM)
3311 + seq_puts(m, " type: CDROM ");
3312 + else
3313 + seq_printf(m, " type: %d ", dev_type);
3314 +
3315 + if (tcon->need_reconnect)
3316 + seq_puts(m, "\tDISCONNECTED ");
3317 + seq_putc(m, '\n');
3318 + }
3319 +
3320 + seq_puts(m, "\n\tMIDs:\n");
3321
3322 spin_lock(&GlobalMid_Lock);
3323 - list_for_each(tmp1, &ses->server->pending_mid_q) {
3324 - mid_entry = list_entry(tmp1, struct
3325 - mid_q_entry,
3326 + list_for_each(tmp3, &server->pending_mid_q) {
3327 + mid_entry = list_entry(tmp3, struct mid_q_entry,
3328 qhead);
3329 - seq_printf(m, "State: %d com: %d pid:"
3330 + seq_printf(m, "\tState: %d com: %d pid:"
3331 " %d tsk: %p mid %d\n",
3332 mid_entry->midState,
3333 (int)mid_entry->command,
3334 @@ -171,44 +204,8 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
3335 }
3336 spin_unlock(&GlobalMid_Lock);
3337 }
3338 -
3339 - }
3340 - read_unlock(&GlobalSMBSeslock);
3341 - seq_putc(m, '\n');
3342 -
3343 - seq_puts(m, "Shares:");
3344 -
3345 - i = 0;
3346 - read_lock(&GlobalSMBSeslock);
3347 - list_for_each(tmp, &GlobalTreeConnectionList) {
3348 - __u32 dev_type;
3349 - i++;
3350 - tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
3351 - dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
3352 - seq_printf(m, "\n%d) %s Uses: %d ", i,
3353 - tcon->treeName, atomic_read(&tcon->useCount));
3354 - if (tcon->nativeFileSystem) {
3355 - seq_printf(m, "Type: %s ",
3356 - tcon->nativeFileSystem);
3357 - }
3358 - seq_printf(m, "DevInfo: 0x%x Attributes: 0x%x"
3359 - "\nPathComponentMax: %d Status: %d",
3360 - le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
3361 - le32_to_cpu(tcon->fsAttrInfo.Attributes),
3362 - le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
3363 - tcon->tidStatus);
3364 - if (dev_type == FILE_DEVICE_DISK)
3365 - seq_puts(m, " type: DISK ");
3366 - else if (dev_type == FILE_DEVICE_CD_ROM)
3367 - seq_puts(m, " type: CDROM ");
3368 - else
3369 - seq_printf(m, " type: %d ", dev_type);
3370 -
3371 - if (tcon->tidStatus == CifsNeedReconnect)
3372 - seq_puts(m, "\tDISCONNECTED ");
3373 }
3374 - read_unlock(&GlobalSMBSeslock);
3375 -
3376 + read_unlock(&cifs_tcp_ses_lock);
3377 seq_putc(m, '\n');
3378
3379 /* BB add code to dump additional info such as TCP session info now */
3380 @@ -234,7 +231,9 @@ static ssize_t cifs_stats_proc_write(struct file *file,
3381 {
3382 char c;
3383 int rc;
3384 - struct list_head *tmp;
3385 + struct list_head *tmp1, *tmp2, *tmp3;
3386 + struct TCP_Server_Info *server;
3387 + struct cifsSesInfo *ses;
3388 struct cifsTconInfo *tcon;
3389
3390 rc = get_user(c, buffer);
3391 @@ -242,33 +241,42 @@ static ssize_t cifs_stats_proc_write(struct file *file,
3392 return rc;
3393
3394 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
3395 - read_lock(&GlobalSMBSeslock);
3396 #ifdef CONFIG_CIFS_STATS2
3397 atomic_set(&totBufAllocCount, 0);
3398 atomic_set(&totSmBufAllocCount, 0);
3399 #endif /* CONFIG_CIFS_STATS2 */
3400 - list_for_each(tmp, &GlobalTreeConnectionList) {
3401 - tcon = list_entry(tmp, struct cifsTconInfo,
3402 - cifsConnectionList);
3403 - atomic_set(&tcon->num_smbs_sent, 0);
3404 - atomic_set(&tcon->num_writes, 0);
3405 - atomic_set(&tcon->num_reads, 0);
3406 - atomic_set(&tcon->num_oplock_brks, 0);
3407 - atomic_set(&tcon->num_opens, 0);
3408 - atomic_set(&tcon->num_closes, 0);
3409 - atomic_set(&tcon->num_deletes, 0);
3410 - atomic_set(&tcon->num_mkdirs, 0);
3411 - atomic_set(&tcon->num_rmdirs, 0);
3412 - atomic_set(&tcon->num_renames, 0);
3413 - atomic_set(&tcon->num_t2renames, 0);
3414 - atomic_set(&tcon->num_ffirst, 0);
3415 - atomic_set(&tcon->num_fnext, 0);
3416 - atomic_set(&tcon->num_fclose, 0);
3417 - atomic_set(&tcon->num_hardlinks, 0);
3418 - atomic_set(&tcon->num_symlinks, 0);
3419 - atomic_set(&tcon->num_locks, 0);
3420 + read_lock(&cifs_tcp_ses_lock);
3421 + list_for_each(tmp1, &cifs_tcp_ses_list) {
3422 + server = list_entry(tmp1, struct TCP_Server_Info,
3423 + tcp_ses_list);
3424 + list_for_each(tmp2, &server->smb_ses_list) {
3425 + ses = list_entry(tmp2, struct cifsSesInfo,
3426 + smb_ses_list);
3427 + list_for_each(tmp3, &ses->tcon_list) {
3428 + tcon = list_entry(tmp3,
3429 + struct cifsTconInfo,
3430 + tcon_list);
3431 + atomic_set(&tcon->num_smbs_sent, 0);
3432 + atomic_set(&tcon->num_writes, 0);
3433 + atomic_set(&tcon->num_reads, 0);
3434 + atomic_set(&tcon->num_oplock_brks, 0);
3435 + atomic_set(&tcon->num_opens, 0);
3436 + atomic_set(&tcon->num_closes, 0);
3437 + atomic_set(&tcon->num_deletes, 0);
3438 + atomic_set(&tcon->num_mkdirs, 0);
3439 + atomic_set(&tcon->num_rmdirs, 0);
3440 + atomic_set(&tcon->num_renames, 0);
3441 + atomic_set(&tcon->num_t2renames, 0);
3442 + atomic_set(&tcon->num_ffirst, 0);
3443 + atomic_set(&tcon->num_fnext, 0);
3444 + atomic_set(&tcon->num_fclose, 0);
3445 + atomic_set(&tcon->num_hardlinks, 0);
3446 + atomic_set(&tcon->num_symlinks, 0);
3447 + atomic_set(&tcon->num_locks, 0);
3448 + }
3449 + }
3450 }
3451 - read_unlock(&GlobalSMBSeslock);
3452 + read_unlock(&cifs_tcp_ses_lock);
3453 }
3454
3455 return count;
3456 @@ -277,7 +285,9 @@ static ssize_t cifs_stats_proc_write(struct file *file,
3457 static int cifs_stats_proc_show(struct seq_file *m, void *v)
3458 {
3459 int i;
3460 - struct list_head *tmp;
3461 + struct list_head *tmp1, *tmp2, *tmp3;
3462 + struct TCP_Server_Info *server;
3463 + struct cifsSesInfo *ses;
3464 struct cifsTconInfo *tcon;
3465
3466 seq_printf(m,
3467 @@ -306,44 +316,55 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
3468 GlobalCurrentXid, GlobalMaxActiveXid);
3469
3470 i = 0;
3471 - read_lock(&GlobalSMBSeslock);
3472 - list_for_each(tmp, &GlobalTreeConnectionList) {
3473 - i++;
3474 - tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
3475 - seq_printf(m, "\n%d) %s", i, tcon->treeName);
3476 - if (tcon->tidStatus == CifsNeedReconnect)
3477 - seq_puts(m, "\tDISCONNECTED ");
3478 - seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
3479 - atomic_read(&tcon->num_smbs_sent),
3480 - atomic_read(&tcon->num_oplock_brks));
3481 - seq_printf(m, "\nReads: %d Bytes: %lld",
3482 - atomic_read(&tcon->num_reads),
3483 - (long long)(tcon->bytes_read));
3484 - seq_printf(m, "\nWrites: %d Bytes: %lld",
3485 - atomic_read(&tcon->num_writes),
3486 - (long long)(tcon->bytes_written));
3487 - seq_printf(m,
3488 - "\nLocks: %d HardLinks: %d Symlinks: %d",
3489 - atomic_read(&tcon->num_locks),
3490 - atomic_read(&tcon->num_hardlinks),
3491 - atomic_read(&tcon->num_symlinks));
3492 -
3493 - seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
3494 - atomic_read(&tcon->num_opens),
3495 - atomic_read(&tcon->num_closes),
3496 - atomic_read(&tcon->num_deletes));
3497 - seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
3498 - atomic_read(&tcon->num_mkdirs),
3499 - atomic_read(&tcon->num_rmdirs));
3500 - seq_printf(m, "\nRenames: %d T2 Renames %d",
3501 - atomic_read(&tcon->num_renames),
3502 - atomic_read(&tcon->num_t2renames));
3503 - seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
3504 - atomic_read(&tcon->num_ffirst),
3505 - atomic_read(&tcon->num_fnext),
3506 - atomic_read(&tcon->num_fclose));
3507 + read_lock(&cifs_tcp_ses_lock);
3508 + list_for_each(tmp1, &cifs_tcp_ses_list) {
3509 + server = list_entry(tmp1, struct TCP_Server_Info,
3510 + tcp_ses_list);
3511 + list_for_each(tmp2, &server->smb_ses_list) {
3512 + ses = list_entry(tmp2, struct cifsSesInfo,
3513 + smb_ses_list);
3514 + list_for_each(tmp3, &ses->tcon_list) {
3515 + tcon = list_entry(tmp3,
3516 + struct cifsTconInfo,
3517 + tcon_list);
3518 + i++;
3519 + seq_printf(m, "\n%d) %s", i, tcon->treeName);
3520 + if (tcon->need_reconnect)
3521 + seq_puts(m, "\tDISCONNECTED ");
3522 + seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
3523 + atomic_read(&tcon->num_smbs_sent),
3524 + atomic_read(&tcon->num_oplock_brks));
3525 + seq_printf(m, "\nReads: %d Bytes: %lld",
3526 + atomic_read(&tcon->num_reads),
3527 + (long long)(tcon->bytes_read));
3528 + seq_printf(m, "\nWrites: %d Bytes: %lld",
3529 + atomic_read(&tcon->num_writes),
3530 + (long long)(tcon->bytes_written));
3531 + seq_printf(m, "\nLocks: %d HardLinks: %d "
3532 + "Symlinks: %d",
3533 + atomic_read(&tcon->num_locks),
3534 + atomic_read(&tcon->num_hardlinks),
3535 + atomic_read(&tcon->num_symlinks));
3536 + seq_printf(m, "\nOpens: %d Closes: %d"
3537 + "Deletes: %d",
3538 + atomic_read(&tcon->num_opens),
3539 + atomic_read(&tcon->num_closes),
3540 + atomic_read(&tcon->num_deletes));
3541 + seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
3542 + atomic_read(&tcon->num_mkdirs),
3543 + atomic_read(&tcon->num_rmdirs));
3544 + seq_printf(m, "\nRenames: %d T2 Renames %d",
3545 + atomic_read(&tcon->num_renames),
3546 + atomic_read(&tcon->num_t2renames));
3547 + seq_printf(m, "\nFindFirst: %d FNext %d "
3548 + "FClose %d",
3549 + atomic_read(&tcon->num_ffirst),
3550 + atomic_read(&tcon->num_fnext),
3551 + atomic_read(&tcon->num_fclose));
3552 + }
3553 + }
3554 }
3555 - read_unlock(&GlobalSMBSeslock);
3556 + read_unlock(&cifs_tcp_ses_lock);
3557
3558 seq_putc(m, '\n');
3559 return 0;
3560 diff --git a/fs/cifs/cifs_spnego.c b/fs/cifs/cifs_spnego.c
3561 index 117ef4b..d0758b2 100644
3562 --- a/fs/cifs/cifs_spnego.c
3563 +++ b/fs/cifs/cifs_spnego.c
3564 @@ -70,7 +70,8 @@ struct key_type cifs_spnego_key_type = {
3565 strlen("ver=0xFF") */
3566 #define MAX_MECH_STR_LEN 13 /* length of longest security mechanism name, eg
3567 in future could have strlen(";sec=ntlmsspi") */
3568 -#define MAX_IPV6_ADDR_LEN 42 /* eg FEDC:BA98:7654:3210:FEDC:BA98:7654:3210/60 */
3569 +/* max possible addr len eg FEDC:BA98:7654:3210:FEDC:BA98:7654:3210/128 */
3570 +#define MAX_IPV6_ADDR_LEN 43
3571 /* get a key struct with a SPNEGO security blob, suitable for session setup */
3572 struct key *
3573 cifs_get_spnego_key(struct cifsSesInfo *sesInfo)
3574 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
3575 index 25ecbd5..2fcc66c 100644
3576 --- a/fs/cifs/cifsfs.c
3577 +++ b/fs/cifs/cifsfs.c
3578 @@ -510,10 +510,11 @@ static void cifs_umount_begin(struct super_block *sb)
3579 tcon = cifs_sb->tcon;
3580 if (tcon == NULL)
3581 return;
3582 - down(&tcon->tconSem);
3583 - if (atomic_read(&tcon->useCount) == 1)
3584 +
3585 + read_lock(&cifs_tcp_ses_lock);
3586 + if (tcon->tc_count == 1)
3587 tcon->tidStatus = CifsExiting;
3588 - up(&tcon->tconSem);
3589 + read_unlock(&cifs_tcp_ses_lock);
3590
3591 /* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */
3592 /* cancel_notify_requests(tcon); */
3593 @@ -967,7 +968,7 @@ static int cifs_oplock_thread(void *dummyarg)
3594 not bother sending an oplock release if session
3595 to server still is disconnected since oplock
3596 already released by the server in that case */
3597 - if (pTcon->tidStatus != CifsNeedReconnect) {
3598 + if (!pTcon->need_reconnect) {
3599 rc = CIFSSMBLock(0, pTcon, netfid,
3600 0 /* len */ , 0 /* offset */, 0,
3601 0, LOCKING_ANDX_OPLOCK_RELEASE,
3602 @@ -985,24 +986,24 @@ static int cifs_oplock_thread(void *dummyarg)
3603 static int cifs_dnotify_thread(void *dummyarg)
3604 {
3605 struct list_head *tmp;
3606 - struct cifsSesInfo *ses;
3607 + struct TCP_Server_Info *server;
3608
3609 do {
3610 if (try_to_freeze())
3611 continue;
3612 set_current_state(TASK_INTERRUPTIBLE);
3613 schedule_timeout(15*HZ);
3614 - read_lock(&GlobalSMBSeslock);
3615 /* check if any stuck requests that need
3616 to be woken up and wakeq so the
3617 thread can wake up and error out */
3618 - list_for_each(tmp, &GlobalSMBSessionList) {
3619 - ses = list_entry(tmp, struct cifsSesInfo,
3620 - cifsSessionList);
3621 - if (ses->server && atomic_read(&ses->server->inFlight))
3622 - wake_up_all(&ses->server->response_q);
3623 + read_lock(&cifs_tcp_ses_lock);
3624 + list_for_each(tmp, &cifs_tcp_ses_list) {
3625 + server = list_entry(tmp, struct TCP_Server_Info,
3626 + tcp_ses_list);
3627 + if (atomic_read(&server->inFlight))
3628 + wake_up_all(&server->response_q);
3629 }
3630 - read_unlock(&GlobalSMBSeslock);
3631 + read_unlock(&cifs_tcp_ses_lock);
3632 } while (!kthread_should_stop());
3633
3634 return 0;
3635 @@ -1013,9 +1014,7 @@ init_cifs(void)
3636 {
3637 int rc = 0;
3638 cifs_proc_init();
3639 -/* INIT_LIST_HEAD(&GlobalServerList);*/ /* BB not implemented yet */
3640 - INIT_LIST_HEAD(&GlobalSMBSessionList);
3641 - INIT_LIST_HEAD(&GlobalTreeConnectionList);
3642 + INIT_LIST_HEAD(&cifs_tcp_ses_list);
3643 INIT_LIST_HEAD(&GlobalOplock_Q);
3644 #ifdef CONFIG_CIFS_EXPERIMENTAL
3645 INIT_LIST_HEAD(&GlobalDnotifyReqList);
3646 @@ -1043,6 +1042,7 @@ init_cifs(void)
3647 GlobalMaxActiveXid = 0;
3648 memset(Local_System_Name, 0, 15);
3649 rwlock_init(&GlobalSMBSeslock);
3650 + rwlock_init(&cifs_tcp_ses_lock);
3651 spin_lock_init(&GlobalMid_Lock);
3652
3653 if (cifs_max_pending < 2) {
3654 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
3655 index 0d22479..1ae6314 100644
3656 --- a/fs/cifs/cifsglob.h
3657 +++ b/fs/cifs/cifsglob.h
3658 @@ -85,8 +85,7 @@ enum securityEnum {
3659 };
3660
3661 enum protocolEnum {
3662 - IPV4 = 0,
3663 - IPV6,
3664 + TCP = 0,
3665 SCTP
3666 /* Netbios frames protocol not supported at this time */
3667 };
3668 @@ -122,6 +121,9 @@ struct cifs_cred {
3669 */
3670
3671 struct TCP_Server_Info {
3672 + struct list_head tcp_ses_list;
3673 + struct list_head smb_ses_list;
3674 + int srv_count; /* reference counter */
3675 /* 15 character server name + 0x20 16th byte indicating type = srv */
3676 char server_RFC1001_name[SERVER_NAME_LEN_WITH_NULL];
3677 char unicode_server_Name[SERVER_NAME_LEN_WITH_NULL * 2];
3678 @@ -141,7 +143,8 @@ struct TCP_Server_Info {
3679 char versionMajor;
3680 char versionMinor;
3681 bool svlocal:1; /* local server or remote */
3682 - atomic_t socketUseCount; /* number of open cifs sessions on socket */
3683 + bool noblocksnd; /* use blocking sendmsg */
3684 + bool noautotune; /* do not autotune send buf sizes */
3685 atomic_t inFlight; /* number of requests on the wire to server */
3686 #ifdef CONFIG_CIFS_STATS2
3687 atomic_t inSend; /* requests trying to send */
3688 @@ -192,13 +195,14 @@ struct cifsUidInfo {
3689 * Session structure. One of these for each uid session with a particular host
3690 */
3691 struct cifsSesInfo {
3692 - struct list_head cifsSessionList;
3693 + struct list_head smb_ses_list;
3694 + struct list_head tcon_list;
3695 struct semaphore sesSem;
3696 #if 0
3697 struct cifsUidInfo *uidInfo; /* pointer to user info */
3698 #endif
3699 struct TCP_Server_Info *server; /* pointer to server info */
3700 - atomic_t inUse; /* # of mounts (tree connections) on this ses */
3701 + int ses_count; /* reference counter */
3702 enum statusEnum status;
3703 unsigned overrideSecFlg; /* if non-zero override global sec flags */
3704 __u16 ipc_tid; /* special tid for connection to IPC share */
3705 @@ -214,6 +218,7 @@ struct cifsSesInfo {
3706 char userName[MAX_USERNAME_SIZE + 1];
3707 char *domainName;
3708 char *password;
3709 + bool need_reconnect:1; /* connection reset, uid now invalid */
3710 };
3711 /* no more than one of the following three session flags may be set */
3712 #define CIFS_SES_NT4 1
3713 @@ -228,16 +233,15 @@ struct cifsSesInfo {
3714 * session
3715 */
3716 struct cifsTconInfo {
3717 - struct list_head cifsConnectionList;
3718 + struct list_head tcon_list;
3719 + int tc_count;
3720 struct list_head openFileList;
3721 - struct semaphore tconSem;
3722 struct cifsSesInfo *ses; /* pointer to session associated with */
3723 char treeName[MAX_TREE_SIZE + 1]; /* UNC name of resource in ASCII */
3724 char *nativeFileSystem;
3725 __u16 tid; /* The 2 byte tree id */
3726 __u16 Flags; /* optional support bits */
3727 enum statusEnum tidStatus;
3728 - atomic_t useCount; /* how many explicit/implicit mounts to share */
3729 #ifdef CONFIG_CIFS_STATS
3730 atomic_t num_smbs_sent;
3731 atomic_t num_writes;
3732 @@ -285,6 +289,7 @@ struct cifsTconInfo {
3733 bool seal:1; /* transport encryption for this mounted share */
3734 bool unix_ext:1; /* if false disable Linux extensions to CIFS protocol
3735 for this mount even if server would support */
3736 + bool need_reconnect:1; /* connection reset, tid now invalid */
3737 /* BB add field for back pointer to sb struct(s)? */
3738 };
3739
3740 @@ -584,21 +589,21 @@ require use of the stronger protocol */
3741 #endif
3742
3743 /*
3744 - * The list of servers that did not respond with NT LM 0.12.
3745 - * This list helps improve performance and eliminate the messages indicating
3746 - * that we had a communications error talking to the server in this list.
3747 + * the list of TCP_Server_Info structures, ie each of the sockets
3748 + * connecting our client to a distinct server (ip address), is
3749 + * chained together by cifs_tcp_ses_list. The list of all our SMB
3750 + * sessions (and from that the tree connections) can be found
3751 + * by iterating over cifs_tcp_ses_list
3752 */
3753 -/* Feature not supported */
3754 -/* GLOBAL_EXTERN struct servers_not_supported *NotSuppList; */
3755 +GLOBAL_EXTERN struct list_head cifs_tcp_ses_list;
3756
3757 /*
3758 - * The following is a hash table of all the users we know about.
3759 + * This lock protects the cifs_tcp_ses_list, the list of smb sessions per
3760 + * tcp session, and the list of tcon's per smb session. It also protects
3761 + * the reference counters for the server, smb session, and tcon. Finally,
3762 + * changes to the tcon->tidStatus should be done while holding this lock.
3763 */
3764 -GLOBAL_EXTERN struct smbUidInfo *GlobalUidList[UID_HASH];
3765 -
3766 -/* GLOBAL_EXTERN struct list_head GlobalServerList; BB not implemented yet */
3767 -GLOBAL_EXTERN struct list_head GlobalSMBSessionList;
3768 -GLOBAL_EXTERN struct list_head GlobalTreeConnectionList;
3769 +GLOBAL_EXTERN rwlock_t cifs_tcp_ses_lock;
3770 GLOBAL_EXTERN rwlock_t GlobalSMBSeslock; /* protects list inserts on 3 above */
3771
3772 GLOBAL_EXTERN struct list_head GlobalOplock_Q;
3773 diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h
3774 index a729d08..ca91f16 100644
3775 --- a/fs/cifs/cifsproto.h
3776 +++ b/fs/cifs/cifsproto.h
3777 @@ -36,7 +36,7 @@ extern void cifs_buf_release(void *);
3778 extern struct smb_hdr *cifs_small_buf_get(void);
3779 extern void cifs_small_buf_release(void *);
3780 extern int smb_send(struct socket *, struct smb_hdr *,
3781 - unsigned int /* length */ , struct sockaddr *);
3782 + unsigned int /* length */ , struct sockaddr *, bool);
3783 extern unsigned int _GetXid(void);
3784 extern void _FreeXid(unsigned int);
3785 #define GetXid() (int)_GetXid(); cFYI(1,("CIFS VFS: in %s as Xid: %d with uid: %d",__func__, xid,current->fsuid));
3786 diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
3787 index 77a0d1f..8f0f86d 100644
3788 --- a/fs/cifs/cifssmb.c
3789 +++ b/fs/cifs/cifssmb.c
3790 @@ -190,10 +190,10 @@ small_smb_init(int smb_command, int wct, struct cifsTconInfo *tcon,
3791 /* need to prevent multiple threads trying to
3792 simultaneously reconnect the same SMB session */
3793 down(&tcon->ses->sesSem);
3794 - if (tcon->ses->status == CifsNeedReconnect)
3795 + if (tcon->ses->need_reconnect)
3796 rc = cifs_setup_session(0, tcon->ses,
3797 nls_codepage);
3798 - if (!rc && (tcon->tidStatus == CifsNeedReconnect)) {
3799 + if (!rc && (tcon->need_reconnect)) {
3800 mark_open_files_invalid(tcon);
3801 rc = CIFSTCon(0, tcon->ses, tcon->treeName,
3802 tcon, nls_codepage);
3803 @@ -337,10 +337,10 @@ smb_init(int smb_command, int wct, struct cifsTconInfo *tcon,
3804 /* need to prevent multiple threads trying to
3805 simultaneously reconnect the same SMB session */
3806 down(&tcon->ses->sesSem);
3807 - if (tcon->ses->status == CifsNeedReconnect)
3808 + if (tcon->ses->need_reconnect)
3809 rc = cifs_setup_session(0, tcon->ses,
3810 nls_codepage);
3811 - if (!rc && (tcon->tidStatus == CifsNeedReconnect)) {
3812 + if (!rc && (tcon->need_reconnect)) {
3813 mark_open_files_invalid(tcon);
3814 rc = CIFSTCon(0, tcon->ses, tcon->treeName,
3815 tcon, nls_codepage);
3816 @@ -664,8 +664,9 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
3817 rc = -EIO;
3818 goto neg_err_exit;
3819 }
3820 -
3821 - if (server->socketUseCount.counter > 1) {
3822 + read_lock(&cifs_tcp_ses_lock);
3823 + if (server->srv_count > 1) {
3824 + read_unlock(&cifs_tcp_ses_lock);
3825 if (memcmp(server->server_GUID,
3826 pSMBr->u.extended_response.
3827 GUID, 16) != 0) {
3828 @@ -674,9 +675,11 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
3829 pSMBr->u.extended_response.GUID,
3830 16);
3831 }
3832 - } else
3833 + } else {
3834 + read_unlock(&cifs_tcp_ses_lock);
3835 memcpy(server->server_GUID,
3836 pSMBr->u.extended_response.GUID, 16);
3837 + }
3838
3839 if (count == 16) {
3840 server->secType = RawNTLMSSP;
3841 @@ -739,50 +742,31 @@ CIFSSMBTDis(const int xid, struct cifsTconInfo *tcon)
3842 int rc = 0;
3843
3844 cFYI(1, ("In tree disconnect"));
3845 - /*
3846 - * If last user of the connection and
3847 - * connection alive - disconnect it
3848 - * If this is the last connection on the server session disconnect it
3849 - * (and inside session disconnect we should check if tcp socket needs
3850 - * to be freed and kernel thread woken up).
3851 - */
3852 - if (tcon)
3853 - down(&tcon->tconSem);
3854 - else
3855 - return -EIO;
3856
3857 - atomic_dec(&tcon->useCount);
3858 - if (atomic_read(&tcon->useCount) > 0) {
3859 - up(&tcon->tconSem);
3860 - return -EBUSY;
3861 - }
3862 + /* BB: do we need to check this? These should never be NULL. */
3863 + if ((tcon->ses == NULL) || (tcon->ses->server == NULL))
3864 + return -EIO;
3865
3866 - /* No need to return error on this operation if tid invalidated and
3867 - closed on server already e.g. due to tcp session crashing */
3868 - if (tcon->tidStatus == CifsNeedReconnect) {
3869 - up(&tcon->tconSem);
3870 + /*
3871 + * No need to return error on this operation if tid invalidated and
3872 + * closed on server already e.g. due to tcp session crashing. Also,
3873 + * the tcon is no longer on the list, so no need to take lock before
3874 + * checking this.
3875 + */
3876 + if (tcon->need_reconnect)
3877 return 0;
3878 - }
3879
3880 - if ((tcon->ses == NULL) || (tcon->ses->server == NULL)) {
3881 - up(&tcon->tconSem);
3882 - return -EIO;
3883 - }
3884 rc = small_smb_init(SMB_COM_TREE_DISCONNECT, 0, tcon,
3885 (void **)&smb_buffer);
3886 - if (rc) {
3887 - up(&tcon->tconSem);
3888 + if (rc)
3889 return rc;
3890 - }
3891
3892 rc = SendReceiveNoRsp(xid, tcon->ses, smb_buffer, 0);
3893 if (rc)
3894 cFYI(1, ("Tree disconnect failed %d", rc));
3895
3896 - up(&tcon->tconSem);
3897 -
3898 /* No need to return error on this operation if tid invalidated and
3899 - closed on server already e.g. due to tcp session crashing */
3900 + closed on server already e.g. due to tcp session crashing */
3901 if (rc == -EAGAIN)
3902 rc = 0;
3903
3904 @@ -796,43 +780,36 @@ CIFSSMBLogoff(const int xid, struct cifsSesInfo *ses)
3905 int rc = 0;
3906
3907 cFYI(1, ("In SMBLogoff for session disconnect"));
3908 - if (ses)
3909 - down(&ses->sesSem);
3910 - else
3911 +
3912 + /*
3913 + * BB: do we need to check validity of ses and server? They should
3914 + * always be valid since we have an active reference. If not, that
3915 + * should probably be a BUG()
3916 + */
3917 + if (!ses || !ses->server)
3918 return -EIO;
3919
3920 - atomic_dec(&ses->inUse);
3921 - if (atomic_read(&ses->inUse) > 0) {
3922 - up(&ses->sesSem);
3923 - return -EBUSY;
3924 - }
3925 + down(&ses->sesSem);
3926 + if (ses->need_reconnect)
3927 + goto session_already_dead; /* no need to send SMBlogoff if uid
3928 + already closed due to reconnect */
3929 rc = small_smb_init(SMB_COM_LOGOFF_ANDX, 2, NULL, (void **)&pSMB);
3930 if (rc) {
3931 up(&ses->sesSem);
3932 return rc;
3933 }
3934
3935 - if (ses->server) {
3936 - pSMB->hdr.Mid = GetNextMid(ses->server);
3937 + pSMB->hdr.Mid = GetNextMid(ses->server);
3938
3939 - if (ses->server->secMode &
3940 + if (ses->server->secMode &
3941 (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
3942 pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE;
3943 - }
3944
3945 pSMB->hdr.Uid = ses->Suid;
3946
3947 pSMB->AndXCommand = 0xFF;
3948 rc = SendReceiveNoRsp(xid, ses, (struct smb_hdr *) pSMB, 0);
3949 - if (ses->server) {
3950 - atomic_dec(&ses->server->socketUseCount);
3951 - if (atomic_read(&ses->server->socketUseCount) == 0) {
3952 - spin_lock(&GlobalMid_Lock);
3953 - ses->server->tcpStatus = CifsExiting;
3954 - spin_unlock(&GlobalMid_Lock);
3955 - rc = -ESHUTDOWN;
3956 - }
3957 - }
3958 +session_already_dead:
3959 up(&ses->sesSem);
3960
3961 /* if session dead then we do not need to do ulogoff,
3962 @@ -1534,7 +1511,7 @@ CIFSSMBWrite(const int xid, struct cifsTconInfo *tcon,
3963 __u32 bytes_sent;
3964 __u16 byte_count;
3965
3966 - /* cFYI(1,("write at %lld %d bytes",offset,count));*/
3967 + /* cFYI(1, ("write at %lld %d bytes",offset,count));*/
3968 if (tcon->ses == NULL)
3969 return -ECONNABORTED;
3970
3971 diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
3972 index 4c13bcd..6e2be4a 100644
3973 --- a/fs/cifs/connect.c
3974 +++ b/fs/cifs/connect.c
3975 @@ -90,6 +90,8 @@ struct smb_vol {
3976 bool nocase:1; /* request case insensitive filenames */
3977 bool nobrl:1; /* disable sending byte range locks to srv */
3978 bool seal:1; /* request transport encryption on share */
3979 + bool noblocksnd:1;
3980 + bool noautotune:1;
3981 unsigned int rsize;
3982 unsigned int wsize;
3983 unsigned int sockopt;
3984 @@ -100,9 +102,11 @@ struct smb_vol {
3985 static int ipv4_connect(struct sockaddr_in *psin_server,
3986 struct socket **csocket,
3987 char *netb_name,
3988 - char *server_netb_name);
3989 + char *server_netb_name,
3990 + bool noblocksnd,
3991 + bool nosndbuf); /* ipv6 never set sndbuf size */
3992 static int ipv6_connect(struct sockaddr_in6 *psin_server,
3993 - struct socket **csocket);
3994 + struct socket **csocket, bool noblocksnd);
3995
3996
3997 /*
3998 @@ -118,7 +122,7 @@ static int
3999 cifs_reconnect(struct TCP_Server_Info *server)
4000 {
4001 int rc = 0;
4002 - struct list_head *tmp;
4003 + struct list_head *tmp, *tmp2;
4004 struct cifsSesInfo *ses;
4005 struct cifsTconInfo *tcon;
4006 struct mid_q_entry *mid_entry;
4007 @@ -138,23 +142,17 @@ cifs_reconnect(struct TCP_Server_Info *server)
4008
4009 /* before reconnecting the tcp session, mark the smb session (uid)
4010 and the tid bad so they are not used until reconnected */
4011 - read_lock(&GlobalSMBSeslock);
4012 - list_for_each(tmp, &GlobalSMBSessionList) {
4013 - ses = list_entry(tmp, struct cifsSesInfo, cifsSessionList);
4014 - if (ses->server) {
4015 - if (ses->server == server) {
4016 - ses->status = CifsNeedReconnect;
4017 - ses->ipc_tid = 0;
4018 - }
4019 + read_lock(&cifs_tcp_ses_lock);
4020 + list_for_each(tmp, &server->smb_ses_list) {
4021 + ses = list_entry(tmp, struct cifsSesInfo, smb_ses_list);
4022 + ses->need_reconnect = true;
4023 + ses->ipc_tid = 0;
4024 + list_for_each(tmp2, &ses->tcon_list) {
4025 + tcon = list_entry(tmp2, struct cifsTconInfo, tcon_list);
4026 + tcon->need_reconnect = true;
4027 }
4028 - /* else tcp and smb sessions need reconnection */
4029 - }
4030 - list_for_each(tmp, &GlobalTreeConnectionList) {
4031 - tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
4032 - if ((tcon->ses) && (tcon->ses->server == server))
4033 - tcon->tidStatus = CifsNeedReconnect;
4034 }
4035 - read_unlock(&GlobalSMBSeslock);
4036 + read_unlock(&cifs_tcp_ses_lock);
4037 /* do not want to be sending data on a socket we are freeing */
4038 down(&server->tcpSem);
4039 if (server->ssocket) {
4040 @@ -186,14 +184,15 @@ cifs_reconnect(struct TCP_Server_Info *server)
4041
4042 while ((!kthread_should_stop()) && (server->tcpStatus != CifsGood)) {
4043 try_to_freeze();
4044 - if (server->protocolType == IPV6) {
4045 + if (server->addr.sockAddr6.sin6_family == AF_INET6) {
4046 rc = ipv6_connect(&server->addr.sockAddr6,
4047 - &server->ssocket);
4048 + &server->ssocket, server->noautotune);
4049 } else {
4050 rc = ipv4_connect(&server->addr.sockAddr,
4051 &server->ssocket,
4052 server->workstation_RFC1001_name,
4053 - server->server_RFC1001_name);
4054 + server->server_RFC1001_name,
4055 + server->noblocksnd, server->noautotune);
4056 }
4057 if (rc) {
4058 cFYI(1, ("reconnect error %d", rc));
4059 @@ -409,8 +408,14 @@ incomplete_rcv:
4060 msleep(1); /* minimum sleep to prevent looping
4061 allowing socket to clear and app threads to set
4062 tcpStatus CifsNeedReconnect if server hung */
4063 - if (pdu_length < 4)
4064 + if (pdu_length < 4) {
4065 + iov.iov_base = (4 - pdu_length) +
4066 + (char *)smb_buffer;
4067 + iov.iov_len = pdu_length;
4068 + smb_msg.msg_control = NULL;
4069 + smb_msg.msg_controllen = 0;
4070 goto incomplete_rcv;
4071 + }
4072 else
4073 continue;
4074 } else if (length <= 0) {
4075 @@ -646,6 +651,11 @@ multi_t2_fnd:
4076 }
4077 } /* end while !EXITING */
4078
4079 + /* take it off the list, if it's not already */
4080 + write_lock(&cifs_tcp_ses_lock);
4081 + list_del_init(&server->tcp_ses_list);
4082 + write_unlock(&cifs_tcp_ses_lock);
4083 +
4084 spin_lock(&GlobalMid_Lock);
4085 server->tcpStatus = CifsExiting;
4086 spin_unlock(&GlobalMid_Lock);
4087 @@ -686,29 +696,29 @@ multi_t2_fnd:
4088 if (smallbuf) /* no sense logging a debug message if NULL */
4089 cifs_small_buf_release(smallbuf);
4090
4091 - read_lock(&GlobalSMBSeslock);
4092 + /*
4093 + * BB: we shouldn't have to do any of this. It shouldn't be
4094 + * possible to exit from the thread with active SMB sessions
4095 + */
4096 + read_lock(&cifs_tcp_ses_lock);
4097 if (list_empty(&server->pending_mid_q)) {
4098 /* loop through server session structures attached to this and
4099 mark them dead */
4100 - list_for_each(tmp, &GlobalSMBSessionList) {
4101 - ses =
4102 - list_entry(tmp, struct cifsSesInfo,
4103 - cifsSessionList);
4104 - if (ses->server == server) {
4105 - ses->status = CifsExiting;
4106 - ses->server = NULL;
4107 - }
4108 + list_for_each(tmp, &server->smb_ses_list) {
4109 + ses = list_entry(tmp, struct cifsSesInfo,
4110 + smb_ses_list);
4111 + ses->status = CifsExiting;
4112 + ses->server = NULL;
4113 }
4114 - read_unlock(&GlobalSMBSeslock);
4115 + read_unlock(&cifs_tcp_ses_lock);
4116 } else {
4117 /* although we can not zero the server struct pointer yet,
4118 since there are active requests which may depnd on them,
4119 mark the corresponding SMB sessions as exiting too */
4120 - list_for_each(tmp, &GlobalSMBSessionList) {
4121 + list_for_each(tmp, &server->smb_ses_list) {
4122 ses = list_entry(tmp, struct cifsSesInfo,
4123 - cifsSessionList);
4124 - if (ses->server == server)
4125 - ses->status = CifsExiting;
4126 + smb_ses_list);
4127 + ses->status = CifsExiting;
4128 }
4129
4130 spin_lock(&GlobalMid_Lock);
4131 @@ -723,7 +733,7 @@ multi_t2_fnd:
4132 }
4133 }
4134 spin_unlock(&GlobalMid_Lock);
4135 - read_unlock(&GlobalSMBSeslock);
4136 + read_unlock(&cifs_tcp_ses_lock);
4137 /* 1/8th of sec is more than enough time for them to exit */
4138 msleep(125);
4139 }
4140 @@ -745,14 +755,13 @@ multi_t2_fnd:
4141 if there are any pointing to this (e.g
4142 if a crazy root user tried to kill cifsd
4143 kernel thread explicitly this might happen) */
4144 - write_lock(&GlobalSMBSeslock);
4145 - list_for_each(tmp, &GlobalSMBSessionList) {
4146 - ses = list_entry(tmp, struct cifsSesInfo,
4147 - cifsSessionList);
4148 - if (ses->server == server)
4149 - ses->server = NULL;
4150 + /* BB: This shouldn't be necessary, see above */
4151 + read_lock(&cifs_tcp_ses_lock);
4152 + list_for_each(tmp, &server->smb_ses_list) {
4153 + ses = list_entry(tmp, struct cifsSesInfo, smb_ses_list);
4154 + ses->server = NULL;
4155 }
4156 - write_unlock(&GlobalSMBSeslock);
4157 + read_unlock(&cifs_tcp_ses_lock);
4158
4159 kfree(server->hostname);
4160 kfree(server);
4161 @@ -1186,6 +1195,10 @@ cifs_parse_mount_options(char *options, const char *devname,
4162 /* ignore */
4163 } else if (strnicmp(data, "rw", 2) == 0) {
4164 vol->rw = true;
4165 + } else if (strnicmp(data, "noblocksnd", 11) == 0) {
4166 + vol->noblocksnd = true;
4167 + } else if (strnicmp(data, "noautotune", 10) == 0) {
4168 + vol->noautotune = true;
4169 } else if ((strnicmp(data, "suid", 4) == 0) ||
4170 (strnicmp(data, "nosuid", 6) == 0) ||
4171 (strnicmp(data, "exec", 4) == 0) ||
4172 @@ -1331,94 +1344,158 @@ cifs_parse_mount_options(char *options, const char *devname,
4173 return 0;
4174 }
4175
4176 -static struct cifsSesInfo *
4177 -cifs_find_tcp_session(struct in_addr *target_ip_addr,
4178 - struct in6_addr *target_ip6_addr,
4179 - char *userName, struct TCP_Server_Info **psrvTcp)
4180 +static struct TCP_Server_Info *
4181 +cifs_find_tcp_session(struct sockaddr *addr)
4182 {
4183 struct list_head *tmp;
4184 - struct cifsSesInfo *ses;
4185 -
4186 - *psrvTcp = NULL;
4187 + struct TCP_Server_Info *server;
4188 + struct sockaddr_in *addr4 = (struct sockaddr_in *) addr;
4189 + struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *) addr;
4190 +
4191 + write_lock(&cifs_tcp_ses_lock);
4192 + list_for_each(tmp, &cifs_tcp_ses_list) {
4193 + server = list_entry(tmp, struct TCP_Server_Info,
4194 + tcp_ses_list);
4195 + /*
4196 + * the demux thread can exit on its own while still in CifsNew
4197 + * so don't accept any sockets in that state. Since the
4198 + * tcpStatus never changes back to CifsNew it's safe to check
4199 + * for this without a lock.
4200 + */
4201 + if (server->tcpStatus == CifsNew)
4202 + continue;
4203
4204 - read_lock(&GlobalSMBSeslock);
4205 - list_for_each(tmp, &GlobalSMBSessionList) {
4206 - ses = list_entry(tmp, struct cifsSesInfo, cifsSessionList);
4207 - if (!ses->server)
4208 + if (addr->sa_family == AF_INET &&
4209 + (addr4->sin_addr.s_addr !=
4210 + server->addr.sockAddr.sin_addr.s_addr))
4211 + continue;
4212 + else if (addr->sa_family == AF_INET6 &&
4213 + memcmp(&server->addr.sockAddr6.sin6_addr,
4214 + &addr6->sin6_addr, sizeof(addr6->sin6_addr)))
4215 continue;
4216
4217 - if (target_ip_addr &&
4218 - ses->server->addr.sockAddr.sin_addr.s_addr != target_ip_addr->s_addr)
4219 - continue;
4220 - else if (target_ip6_addr &&
4221 - memcmp(&ses->server->addr.sockAddr6.sin6_addr,
4222 - target_ip6_addr, sizeof(*target_ip6_addr)))
4223 - continue;
4224 - /* BB lock server and tcp session; increment use count here?? */
4225 + ++server->srv_count;
4226 + write_unlock(&cifs_tcp_ses_lock);
4227 + cFYI(1, ("Existing tcp session with server found"));
4228 + return server;
4229 + }
4230 + write_unlock(&cifs_tcp_ses_lock);
4231 + return NULL;
4232 +}
4233
4234 - /* found a match on the TCP session */
4235 - *psrvTcp = ses->server;
4236 +static void
4237 +cifs_put_tcp_session(struct TCP_Server_Info *server)
4238 +{
4239 + struct task_struct *task;
4240
4241 - /* BB check if reconnection needed */
4242 - if (strncmp(ses->userName, userName, MAX_USERNAME_SIZE) == 0) {
4243 - read_unlock(&GlobalSMBSeslock);
4244 - /* Found exact match on both TCP and
4245 - SMB sessions */
4246 - return ses;
4247 - }
4248 - /* else tcp and smb sessions need reconnection */
4249 + write_lock(&cifs_tcp_ses_lock);
4250 + if (--server->srv_count > 0) {
4251 + write_unlock(&cifs_tcp_ses_lock);
4252 + return;
4253 }
4254 - read_unlock(&GlobalSMBSeslock);
4255
4256 - return NULL;
4257 + list_del_init(&server->tcp_ses_list);
4258 + write_unlock(&cifs_tcp_ses_lock);
4259 +
4260 + spin_lock(&GlobalMid_Lock);
4261 + server->tcpStatus = CifsExiting;
4262 + spin_unlock(&GlobalMid_Lock);
4263 +
4264 + task = xchg(&server->tsk, NULL);
4265 + if (task)
4266 + force_sig(SIGKILL, task);
4267 }
4268
4269 -static struct cifsTconInfo *
4270 -find_unc(__be32 new_target_ip_addr, char *uncName, char *userName)
4271 +static struct cifsSesInfo *
4272 +cifs_find_smb_ses(struct TCP_Server_Info *server, char *username)
4273 {
4274 struct list_head *tmp;
4275 - struct cifsTconInfo *tcon;
4276 - __be32 old_ip;
4277 -
4278 - read_lock(&GlobalSMBSeslock);
4279 + struct cifsSesInfo *ses;
4280
4281 - list_for_each(tmp, &GlobalTreeConnectionList) {
4282 - cFYI(1, ("Next tcon"));
4283 - tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
4284 - if (!tcon->ses || !tcon->ses->server)
4285 + write_lock(&cifs_tcp_ses_lock);
4286 + list_for_each(tmp, &server->smb_ses_list) {
4287 + ses = list_entry(tmp, struct cifsSesInfo, smb_ses_list);
4288 + if (strncmp(ses->userName, username, MAX_USERNAME_SIZE))
4289 continue;
4290
4291 - old_ip = tcon->ses->server->addr.sockAddr.sin_addr.s_addr;
4292 - cFYI(1, ("old ip addr: %x == new ip %x ?",
4293 - old_ip, new_target_ip_addr));
4294 + ++ses->ses_count;
4295 + write_unlock(&cifs_tcp_ses_lock);
4296 + return ses;
4297 + }
4298 + write_unlock(&cifs_tcp_ses_lock);
4299 + return NULL;
4300 +}
4301
4302 - if (old_ip != new_target_ip_addr)
4303 - continue;
4304 +static void
4305 +cifs_put_smb_ses(struct cifsSesInfo *ses)
4306 +{
4307 + int xid;
4308 + struct TCP_Server_Info *server = ses->server;
4309
4310 - /* BB lock tcon, server, tcp session and increment use count? */
4311 - /* found a match on the TCP session */
4312 - /* BB check if reconnection needed */
4313 - cFYI(1, ("IP match, old UNC: %s new: %s",
4314 - tcon->treeName, uncName));
4315 + write_lock(&cifs_tcp_ses_lock);
4316 + if (--ses->ses_count > 0) {
4317 + write_unlock(&cifs_tcp_ses_lock);
4318 + return;
4319 + }
4320
4321 - if (strncmp(tcon->treeName, uncName, MAX_TREE_SIZE))
4322 - continue;
4323 + list_del_init(&ses->smb_ses_list);
4324 + write_unlock(&cifs_tcp_ses_lock);
4325 +
4326 + if (ses->status == CifsGood) {
4327 + xid = GetXid();
4328 + CIFSSMBLogoff(xid, ses);
4329 + _FreeXid(xid);
4330 + }
4331 + sesInfoFree(ses);
4332 + cifs_put_tcp_session(server);
4333 +}
4334
4335 - cFYI(1, ("and old usr: %s new: %s",
4336 - tcon->treeName, uncName));
4337 +static struct cifsTconInfo *
4338 +cifs_find_tcon(struct cifsSesInfo *ses, const char *unc)
4339 +{
4340 + struct list_head *tmp;
4341 + struct cifsTconInfo *tcon;
4342
4343 - if (strncmp(tcon->ses->userName, userName, MAX_USERNAME_SIZE))
4344 + write_lock(&cifs_tcp_ses_lock);
4345 + list_for_each(tmp, &ses->tcon_list) {
4346 + tcon = list_entry(tmp, struct cifsTconInfo, tcon_list);
4347 + if (tcon->tidStatus == CifsExiting)
4348 + continue;
4349 + if (strncmp(tcon->treeName, unc, MAX_TREE_SIZE))
4350 continue;
4351
4352 - /* matched smb session (user name) */
4353 - read_unlock(&GlobalSMBSeslock);
4354 + ++tcon->tc_count;
4355 + write_unlock(&cifs_tcp_ses_lock);
4356 return tcon;
4357 }
4358 -
4359 - read_unlock(&GlobalSMBSeslock);
4360 + write_unlock(&cifs_tcp_ses_lock);
4361 return NULL;
4362 }
4363
4364 +static void
4365 +cifs_put_tcon(struct cifsTconInfo *tcon)
4366 +{
4367 + int xid;
4368 + struct cifsSesInfo *ses = tcon->ses;
4369 +
4370 + write_lock(&cifs_tcp_ses_lock);
4371 + if (--tcon->tc_count > 0) {
4372 + write_unlock(&cifs_tcp_ses_lock);
4373 + return;
4374 + }
4375 +
4376 + list_del_init(&tcon->tcon_list);
4377 + write_unlock(&cifs_tcp_ses_lock);
4378 +
4379 + xid = GetXid();
4380 + CIFSSMBTDis(xid, tcon);
4381 + _FreeXid(xid);
4382 +
4383 + DeleteTconOplockQEntries(tcon);
4384 + tconInfoFree(tcon);
4385 + cifs_put_smb_ses(ses);
4386 +}
4387 +
4388 int
4389 get_dfs_path(int xid, struct cifsSesInfo *pSesInfo, const char *old_path,
4390 const struct nls_table *nls_codepage, unsigned int *pnum_referrals,
4391 @@ -1506,7 +1583,8 @@ static void rfc1002mangle(char *target, char *source, unsigned int length)
4392
4393 static int
4394 ipv4_connect(struct sockaddr_in *psin_server, struct socket **csocket,
4395 - char *netbios_name, char *target_name)
4396 + char *netbios_name, char *target_name,
4397 + bool noblocksnd, bool noautotune)
4398 {
4399 int rc = 0;
4400 int connected = 0;
4401 @@ -1578,11 +1656,15 @@ ipv4_connect(struct sockaddr_in *psin_server, struct socket **csocket,
4402 (*csocket)->sk->sk_sndbuf,
4403 (*csocket)->sk->sk_rcvbuf, (*csocket)->sk->sk_rcvtimeo));
4404 (*csocket)->sk->sk_rcvtimeo = 7 * HZ;
4405 + if (!noblocksnd)
4406 + (*csocket)->sk->sk_sndtimeo = 3 * HZ;
4407 /* make the bufsizes depend on wsize/rsize and max requests */
4408 - if ((*csocket)->sk->sk_sndbuf < (200 * 1024))
4409 - (*csocket)->sk->sk_sndbuf = 200 * 1024;
4410 - if ((*csocket)->sk->sk_rcvbuf < (140 * 1024))
4411 - (*csocket)->sk->sk_rcvbuf = 140 * 1024;
4412 + if (noautotune) {
4413 + if ((*csocket)->sk->sk_sndbuf < (200 * 1024))
4414 + (*csocket)->sk->sk_sndbuf = 200 * 1024;
4415 + if ((*csocket)->sk->sk_rcvbuf < (140 * 1024))
4416 + (*csocket)->sk->sk_rcvbuf = 140 * 1024;
4417 + }
4418
4419 /* send RFC1001 sessinit */
4420 if (psin_server->sin_port == htons(RFC1001_PORT)) {
4421 @@ -1619,7 +1701,7 @@ ipv4_connect(struct sockaddr_in *psin_server, struct socket **csocket,
4422 /* sizeof RFC1002_SESSION_REQUEST with no scope */
4423 smb_buf->smb_buf_length = 0x81000044;
4424 rc = smb_send(*csocket, smb_buf, 0x44,
4425 - (struct sockaddr *)psin_server);
4426 + (struct sockaddr *)psin_server, noblocksnd);
4427 kfree(ses_init_buf);
4428 msleep(1); /* RFC1001 layer in at least one server
4429 requires very short break before negprot
4430 @@ -1639,7 +1721,8 @@ ipv4_connect(struct sockaddr_in *psin_server, struct socket **csocket,
4431 }
4432
4433 static int
4434 -ipv6_connect(struct sockaddr_in6 *psin_server, struct socket **csocket)
4435 +ipv6_connect(struct sockaddr_in6 *psin_server, struct socket **csocket,
4436 + bool noblocksnd)
4437 {
4438 int rc = 0;
4439 int connected = 0;
4440 @@ -1708,6 +1791,8 @@ ipv6_connect(struct sockaddr_in6 *psin_server, struct socket **csocket)
4441 the default. sock_setsockopt not used because it expects
4442 user space buffer */
4443 (*csocket)->sk->sk_rcvtimeo = 7 * HZ;
4444 + if (!noblocksnd)
4445 + (*csocket)->sk->sk_sndtimeo = 3 * HZ;
4446
4447 return rc;
4448 }
4449 @@ -1845,19 +1930,104 @@ convert_delimiter(char *path, char delim)
4450 }
4451 }
4452
4453 +static void setup_cifs_sb(struct smb_vol *pvolume_info,
4454 + struct cifs_sb_info *cifs_sb)
4455 +{
4456 + if (pvolume_info->rsize > CIFSMaxBufSize) {
4457 + cERROR(1, ("rsize %d too large, using MaxBufSize",
4458 + pvolume_info->rsize));
4459 + cifs_sb->rsize = CIFSMaxBufSize;
4460 + } else if ((pvolume_info->rsize) &&
4461 + (pvolume_info->rsize <= CIFSMaxBufSize))
4462 + cifs_sb->rsize = pvolume_info->rsize;
4463 + else /* default */
4464 + cifs_sb->rsize = CIFSMaxBufSize;
4465 +
4466 + if (pvolume_info->wsize > PAGEVEC_SIZE * PAGE_CACHE_SIZE) {
4467 + cERROR(1, ("wsize %d too large, using 4096 instead",
4468 + pvolume_info->wsize));
4469 + cifs_sb->wsize = 4096;
4470 + } else if (pvolume_info->wsize)
4471 + cifs_sb->wsize = pvolume_info->wsize;
4472 + else
4473 + cifs_sb->wsize = min_t(const int,
4474 + PAGEVEC_SIZE * PAGE_CACHE_SIZE,
4475 + 127*1024);
4476 + /* old default of CIFSMaxBufSize was too small now
4477 + that SMB Write2 can send multiple pages in kvec.
4478 + RFC1001 does not describe what happens when frame
4479 + bigger than 128K is sent so use that as max in
4480 + conjunction with 52K kvec constraint on arch with 4K
4481 + page size */
4482 +
4483 + if (cifs_sb->rsize < 2048) {
4484 + cifs_sb->rsize = 2048;
4485 + /* Windows ME may prefer this */
4486 + cFYI(1, ("readsize set to minimum: 2048"));
4487 + }
4488 + /* calculate prepath */
4489 + cifs_sb->prepath = pvolume_info->prepath;
4490 + if (cifs_sb->prepath) {
4491 + cifs_sb->prepathlen = strlen(cifs_sb->prepath);
4492 + /* we can not convert the / to \ in the path
4493 + separators in the prefixpath yet because we do not
4494 + know (until reset_cifs_unix_caps is called later)
4495 + whether POSIX PATH CAP is available. We normalize
4496 + the / to \ after reset_cifs_unix_caps is called */
4497 + pvolume_info->prepath = NULL;
4498 + } else
4499 + cifs_sb->prepathlen = 0;
4500 + cifs_sb->mnt_uid = pvolume_info->linux_uid;
4501 + cifs_sb->mnt_gid = pvolume_info->linux_gid;
4502 + cifs_sb->mnt_file_mode = pvolume_info->file_mode;
4503 + cifs_sb->mnt_dir_mode = pvolume_info->dir_mode;
4504 + cFYI(1, ("file mode: 0x%x dir mode: 0x%x",
4505 + cifs_sb->mnt_file_mode, cifs_sb->mnt_dir_mode));
4506 +
4507 + if (pvolume_info->noperm)
4508 + cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_PERM;
4509 + if (pvolume_info->setuids)
4510 + cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_SET_UID;
4511 + if (pvolume_info->server_ino)
4512 + cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_SERVER_INUM;
4513 + if (pvolume_info->remap)
4514 + cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MAP_SPECIAL_CHR;
4515 + if (pvolume_info->no_xattr)
4516 + cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_XATTR;
4517 + if (pvolume_info->sfu_emul)
4518 + cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_UNX_EMUL;
4519 + if (pvolume_info->nobrl)
4520 + cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_BRL;
4521 + if (pvolume_info->cifs_acl)
4522 + cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_ACL;
4523 + if (pvolume_info->override_uid)
4524 + cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_OVERR_UID;
4525 + if (pvolume_info->override_gid)
4526 + cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_OVERR_GID;
4527 + if (pvolume_info->dynperm)
4528 + cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DYNPERM;
4529 + if (pvolume_info->direct_io) {
4530 + cFYI(1, ("mounting share using direct i/o"));
4531 + cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DIRECT_IO;
4532 + }
4533 +
4534 + if ((pvolume_info->cifs_acl) && (pvolume_info->dynperm))
4535 + cERROR(1, ("mount option dynperm ignored if cifsacl "
4536 + "mount option supported"));
4537 +}
4538 +
4539 int
4540 cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
4541 char *mount_data, const char *devname)
4542 {
4543 int rc = 0;
4544 int xid;
4545 - int address_type = AF_INET;
4546 struct socket *csocket = NULL;
4547 - struct sockaddr_in sin_server;
4548 - struct sockaddr_in6 sin_server6;
4549 + struct sockaddr addr;
4550 + struct sockaddr_in *sin_server = (struct sockaddr_in *) &addr;
4551 + struct sockaddr_in6 *sin_server6 = (struct sockaddr_in6 *) &addr;
4552 struct smb_vol volume_info;
4553 struct cifsSesInfo *pSesInfo = NULL;
4554 - struct cifsSesInfo *existingCifsSes = NULL;
4555 struct cifsTconInfo *tcon = NULL;
4556 struct TCP_Server_Info *srvTcp = NULL;
4557
4558 @@ -1865,6 +2035,7 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
4559
4560 /* cFYI(1, ("Entering cifs_mount. Xid: %d with: %s", xid, mount_data)); */
4561
4562 + memset(&addr, 0, sizeof(struct sockaddr));
4563 memset(&volume_info, 0, sizeof(struct smb_vol));
4564 if (cifs_parse_mount_options(mount_data, devname, &volume_info)) {
4565 rc = -EINVAL;
4566 @@ -1887,16 +2058,16 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
4567
4568 if (volume_info.UNCip && volume_info.UNC) {
4569 rc = cifs_inet_pton(AF_INET, volume_info.UNCip,
4570 - &sin_server.sin_addr.s_addr);
4571 + &sin_server->sin_addr.s_addr);
4572
4573 if (rc <= 0) {
4574 /* not ipv4 address, try ipv6 */
4575 rc = cifs_inet_pton(AF_INET6, volume_info.UNCip,
4576 - &sin_server6.sin6_addr.in6_u);
4577 + &sin_server6->sin6_addr.in6_u);
4578 if (rc > 0)
4579 - address_type = AF_INET6;
4580 + addr.sa_family = AF_INET6;
4581 } else {
4582 - address_type = AF_INET;
4583 + addr.sa_family = AF_INET;
4584 }
4585
4586 if (rc <= 0) {
4587 @@ -1936,38 +2107,25 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
4588 }
4589 }
4590
4591 - if (address_type == AF_INET)
4592 - existingCifsSes = cifs_find_tcp_session(&sin_server.sin_addr,
4593 - NULL /* no ipv6 addr */,
4594 - volume_info.username, &srvTcp);
4595 - else if (address_type == AF_INET6) {
4596 - cFYI(1, ("looking for ipv6 address"));
4597 - existingCifsSes = cifs_find_tcp_session(NULL /* no ipv4 addr */,
4598 - &sin_server6.sin6_addr,
4599 - volume_info.username, &srvTcp);
4600 - } else {
4601 - rc = -EINVAL;
4602 - goto out;
4603 - }
4604 -
4605 - if (srvTcp) {
4606 - cFYI(1, ("Existing tcp session with server found"));
4607 - } else { /* create socket */
4608 - if (volume_info.port)
4609 - sin_server.sin_port = htons(volume_info.port);
4610 - else
4611 - sin_server.sin_port = 0;
4612 - if (address_type == AF_INET6) {
4613 + srvTcp = cifs_find_tcp_session(&addr);
4614 + if (!srvTcp) { /* create socket */
4615 + if (addr.sa_family == AF_INET6) {
4616 cFYI(1, ("attempting ipv6 connect"));
4617 /* BB should we allow ipv6 on port 139? */
4618 /* other OS never observed in Wild doing 139 with v6 */
4619 - rc = ipv6_connect(&sin_server6, &csocket);
4620 - } else
4621 - rc = ipv4_connect(&sin_server, &csocket,
4622 - volume_info.source_rfc1001_name,
4623 - volume_info.target_rfc1001_name);
4624 + sin_server6->sin6_port = htons(volume_info.port);
4625 + rc = ipv6_connect(sin_server6, &csocket,
4626 + volume_info.noblocksnd);
4627 + } else {
4628 + sin_server->sin_port = htons(volume_info.port);
4629 + rc = ipv4_connect(sin_server, &csocket,
4630 + volume_info.source_rfc1001_name,
4631 + volume_info.target_rfc1001_name,
4632 + volume_info.noblocksnd,
4633 + volume_info.noautotune);
4634 + }
4635 if (rc < 0) {
4636 - cERROR(1, ("Error connecting to IPv4 socket. "
4637 + cERROR(1, ("Error connecting to socket. "
4638 "Aborting operation"));
4639 if (csocket != NULL)
4640 sock_release(csocket);
4641 @@ -1980,12 +2138,17 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
4642 sock_release(csocket);
4643 goto out;
4644 } else {
4645 - memcpy(&srvTcp->addr.sockAddr, &sin_server,
4646 - sizeof(struct sockaddr_in));
4647 + srvTcp->noblocksnd = volume_info.noblocksnd;
4648 + srvTcp->noautotune = volume_info.noautotune;
4649 + if (addr.sa_family == AF_INET6)
4650 + memcpy(&srvTcp->addr.sockAddr6, sin_server6,
4651 + sizeof(struct sockaddr_in6));
4652 + else
4653 + memcpy(&srvTcp->addr.sockAddr, sin_server,
4654 + sizeof(struct sockaddr_in));
4655 atomic_set(&srvTcp->inFlight, 0);
4656 /* BB Add code for ipv6 case too */
4657 srvTcp->ssocket = csocket;
4658 - srvTcp->protocolType = IPV4;
4659 srvTcp->hostname = extract_hostname(volume_info.UNC);
4660 if (IS_ERR(srvTcp->hostname)) {
4661 rc = PTR_ERR(srvTcp->hostname);
4662 @@ -2015,15 +2178,28 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
4663 memcpy(srvTcp->server_RFC1001_name,
4664 volume_info.target_rfc1001_name, 16);
4665 srvTcp->sequence_number = 0;
4666 + INIT_LIST_HEAD(&srvTcp->tcp_ses_list);
4667 + INIT_LIST_HEAD(&srvTcp->smb_ses_list);
4668 + ++srvTcp->srv_count;
4669 + write_lock(&cifs_tcp_ses_lock);
4670 + list_add(&srvTcp->tcp_ses_list,
4671 + &cifs_tcp_ses_list);
4672 + write_unlock(&cifs_tcp_ses_lock);
4673 }
4674 }
4675
4676 - if (existingCifsSes) {
4677 - pSesInfo = existingCifsSes;
4678 + pSesInfo = cifs_find_smb_ses(srvTcp, volume_info.username);
4679 + if (pSesInfo) {
4680 cFYI(1, ("Existing smb sess found (status=%d)",
4681 pSesInfo->status));
4682 + /*
4683 + * The existing SMB session already has a reference to srvTcp,
4684 + * so we can put back the extra one we got before
4685 + */
4686 + cifs_put_tcp_session(srvTcp);
4687 +
4688 down(&pSesInfo->sesSem);
4689 - if (pSesInfo->status == CifsNeedReconnect) {
4690 + if (pSesInfo->need_reconnect) {
4691 cFYI(1, ("Session needs reconnect"));
4692 rc = cifs_setup_session(xid, pSesInfo,
4693 cifs_sb->local_nls);
4694 @@ -2032,180 +2208,94 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
4695 } else if (!rc) {
4696 cFYI(1, ("Existing smb sess not found"));
4697 pSesInfo = sesInfoAlloc();
4698 - if (pSesInfo == NULL)
4699 + if (pSesInfo == NULL) {
4700 rc = -ENOMEM;
4701 - else {
4702 - pSesInfo->server = srvTcp;
4703 - sprintf(pSesInfo->serverName, "%u.%u.%u.%u",
4704 - NIPQUAD(sin_server.sin_addr.s_addr));
4705 - }
4706 + goto mount_fail_check;
4707 + }
4708 +
4709 + /* new SMB session uses our srvTcp ref */
4710 + pSesInfo->server = srvTcp;
4711 + sprintf(pSesInfo->serverName, "%u.%u.%u.%u",
4712 + NIPQUAD(sin_server->sin_addr.s_addr));
4713 +
4714 + write_lock(&cifs_tcp_ses_lock);
4715 + list_add(&pSesInfo->smb_ses_list, &srvTcp->smb_ses_list);
4716 + write_unlock(&cifs_tcp_ses_lock);
4717 +
4718 + /* volume_info.password freed at unmount */
4719 + if (volume_info.password) {
4720 + pSesInfo->password = volume_info.password;
4721 + /* set to NULL to prevent freeing on exit */
4722 + volume_info.password = NULL;
4723 + }
4724 + if (volume_info.username)
4725 + strncpy(pSesInfo->userName, volume_info.username,
4726 + MAX_USERNAME_SIZE);
4727 + if (volume_info.domainname) {
4728 + int len = strlen(volume_info.domainname);
4729 + pSesInfo->domainName = kmalloc(len + 1, GFP_KERNEL);
4730 + if (pSesInfo->domainName)
4731 + strcpy(pSesInfo->domainName,
4732 + volume_info.domainname);
4733 + }
4734 + pSesInfo->linux_uid = volume_info.linux_uid;
4735 + pSesInfo->overrideSecFlg = volume_info.secFlg;
4736 + down(&pSesInfo->sesSem);
4737
4738 - if (!rc) {
4739 - /* volume_info.password freed at unmount */
4740 - if (volume_info.password) {
4741 - pSesInfo->password = volume_info.password;
4742 - /* set to NULL to prevent freeing on exit */
4743 - volume_info.password = NULL;
4744 - }
4745 - if (volume_info.username)
4746 - strncpy(pSesInfo->userName,
4747 - volume_info.username,
4748 - MAX_USERNAME_SIZE);
4749 - if (volume_info.domainname) {
4750 - int len = strlen(volume_info.domainname);
4751 - pSesInfo->domainName =
4752 - kmalloc(len + 1, GFP_KERNEL);
4753 - if (pSesInfo->domainName)
4754 - strcpy(pSesInfo->domainName,
4755 - volume_info.domainname);
4756 - }
4757 - pSesInfo->linux_uid = volume_info.linux_uid;
4758 - pSesInfo->overrideSecFlg = volume_info.secFlg;
4759 - down(&pSesInfo->sesSem);
4760 - /* BB FIXME need to pass vol->secFlgs BB */
4761 - rc = cifs_setup_session(xid, pSesInfo,
4762 - cifs_sb->local_nls);
4763 - up(&pSesInfo->sesSem);
4764 - if (!rc)
4765 - atomic_inc(&srvTcp->socketUseCount);
4766 - }
4767 + /* BB FIXME need to pass vol->secFlgs BB */
4768 + rc = cifs_setup_session(xid, pSesInfo,
4769 + cifs_sb->local_nls);
4770 + up(&pSesInfo->sesSem);
4771 }
4772
4773 /* search for existing tcon to this server share */
4774 if (!rc) {
4775 - if (volume_info.rsize > CIFSMaxBufSize) {
4776 - cERROR(1, ("rsize %d too large, using MaxBufSize",
4777 - volume_info.rsize));
4778 - cifs_sb->rsize = CIFSMaxBufSize;
4779 - } else if ((volume_info.rsize) &&
4780 - (volume_info.rsize <= CIFSMaxBufSize))
4781 - cifs_sb->rsize = volume_info.rsize;
4782 - else /* default */
4783 - cifs_sb->rsize = CIFSMaxBufSize;
4784 -
4785 - if (volume_info.wsize > PAGEVEC_SIZE * PAGE_CACHE_SIZE) {
4786 - cERROR(1, ("wsize %d too large, using 4096 instead",
4787 - volume_info.wsize));
4788 - cifs_sb->wsize = 4096;
4789 - } else if (volume_info.wsize)
4790 - cifs_sb->wsize = volume_info.wsize;
4791 - else
4792 - cifs_sb->wsize =
4793 - min_t(const int, PAGEVEC_SIZE * PAGE_CACHE_SIZE,
4794 - 127*1024);
4795 - /* old default of CIFSMaxBufSize was too small now
4796 - that SMB Write2 can send multiple pages in kvec.
4797 - RFC1001 does not describe what happens when frame
4798 - bigger than 128K is sent so use that as max in
4799 - conjunction with 52K kvec constraint on arch with 4K
4800 - page size */
4801 -
4802 - if (cifs_sb->rsize < 2048) {
4803 - cifs_sb->rsize = 2048;
4804 - /* Windows ME may prefer this */
4805 - cFYI(1, ("readsize set to minimum: 2048"));
4806 - }
4807 - /* calculate prepath */
4808 - cifs_sb->prepath = volume_info.prepath;
4809 - if (cifs_sb->prepath) {
4810 - cifs_sb->prepathlen = strlen(cifs_sb->prepath);
4811 - /* we can not convert the / to \ in the path
4812 - separators in the prefixpath yet because we do not
4813 - know (until reset_cifs_unix_caps is called later)
4814 - whether POSIX PATH CAP is available. We normalize
4815 - the / to \ after reset_cifs_unix_caps is called */
4816 - volume_info.prepath = NULL;
4817 - } else
4818 - cifs_sb->prepathlen = 0;
4819 - cifs_sb->mnt_uid = volume_info.linux_uid;
4820 - cifs_sb->mnt_gid = volume_info.linux_gid;
4821 - cifs_sb->mnt_file_mode = volume_info.file_mode;
4822 - cifs_sb->mnt_dir_mode = volume_info.dir_mode;
4823 - cFYI(1, ("file mode: 0x%x dir mode: 0x%x",
4824 - cifs_sb->mnt_file_mode, cifs_sb->mnt_dir_mode));
4825 -
4826 - if (volume_info.noperm)
4827 - cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_PERM;
4828 - if (volume_info.setuids)
4829 - cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_SET_UID;
4830 - if (volume_info.server_ino)
4831 - cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_SERVER_INUM;
4832 - if (volume_info.remap)
4833 - cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MAP_SPECIAL_CHR;
4834 - if (volume_info.no_xattr)
4835 - cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_XATTR;
4836 - if (volume_info.sfu_emul)
4837 - cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_UNX_EMUL;
4838 - if (volume_info.nobrl)
4839 - cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_BRL;
4840 - if (volume_info.cifs_acl)
4841 - cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_ACL;
4842 - if (volume_info.override_uid)
4843 - cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_OVERR_UID;
4844 - if (volume_info.override_gid)
4845 - cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_OVERR_GID;
4846 - if (volume_info.dynperm)
4847 - cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DYNPERM;
4848 - if (volume_info.direct_io) {
4849 - cFYI(1, ("mounting share using direct i/o"));
4850 - cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DIRECT_IO;
4851 - }
4852 -
4853 - if ((volume_info.cifs_acl) && (volume_info.dynperm))
4854 - cERROR(1, ("mount option dynperm ignored if cifsacl "
4855 - "mount option supported"));
4856 -
4857 - tcon =
4858 - find_unc(sin_server.sin_addr.s_addr, volume_info.UNC,
4859 - volume_info.username);
4860 + setup_cifs_sb(&volume_info, cifs_sb);
4861 + tcon = cifs_find_tcon(pSesInfo, volume_info.UNC);
4862 if (tcon) {
4863 cFYI(1, ("Found match on UNC path"));
4864 - /* we can have only one retry value for a connection
4865 - to a share so for resources mounted more than once
4866 - to the same server share the last value passed in
4867 - for the retry flag is used */
4868 - tcon->retry = volume_info.retry;
4869 - tcon->nocase = volume_info.nocase;
4870 + /* existing tcon already has a reference */
4871 + cifs_put_smb_ses(pSesInfo);
4872 if (tcon->seal != volume_info.seal)
4873 cERROR(1, ("transport encryption setting "
4874 "conflicts with existing tid"));
4875 } else {
4876 tcon = tconInfoAlloc();
4877 - if (tcon == NULL)
4878 + if (tcon == NULL) {
4879 rc = -ENOMEM;
4880 - else {
4881 - /* check for null share name ie connecting to
4882 - * dfs root */
4883 -
4884 - /* BB check if this works for exactly length
4885 - * three strings */
4886 - if ((strchr(volume_info.UNC + 3, '\\') == NULL)
4887 - && (strchr(volume_info.UNC + 3, '/') ==
4888 - NULL)) {
4889 -/* rc = connect_to_dfs_path(xid, pSesInfo,
4890 - "", cifs_sb->local_nls,
4891 - cifs_sb->mnt_cifs_flags &
4892 - CIFS_MOUNT_MAP_SPECIAL_CHR);*/
4893 - cFYI(1, ("DFS root not supported"));
4894 - rc = -ENODEV;
4895 - goto out;
4896 - } else {
4897 - /* BB Do we need to wrap sesSem around
4898 - * this TCon call and Unix SetFS as
4899 - * we do on SessSetup and reconnect? */
4900 - rc = CIFSTCon(xid, pSesInfo,
4901 - volume_info.UNC,
4902 - tcon, cifs_sb->local_nls);
4903 - cFYI(1, ("CIFS Tcon rc = %d", rc));
4904 - }
4905 - if (!rc) {
4906 - atomic_inc(&pSesInfo->inUse);
4907 - tcon->retry = volume_info.retry;
4908 - tcon->nocase = volume_info.nocase;
4909 - tcon->seal = volume_info.seal;
4910 - }
4911 + goto mount_fail_check;
4912 + }
4913 + tcon->ses = pSesInfo;
4914 +
4915 + /* check for null share name ie connect to dfs root */
4916 + if ((strchr(volume_info.UNC + 3, '\\') == NULL)
4917 + && (strchr(volume_info.UNC + 3, '/') == NULL)) {
4918 + /* rc = connect_to_dfs_path(...) */
4919 + cFYI(1, ("DFS root not supported"));
4920 + rc = -ENODEV;
4921 + goto mount_fail_check;
4922 + } else {
4923 + /* BB Do we need to wrap sesSem around
4924 + * this TCon call and Unix SetFS as
4925 + * we do on SessSetup and reconnect? */
4926 + rc = CIFSTCon(xid, pSesInfo, volume_info.UNC,
4927 + tcon, cifs_sb->local_nls);
4928 + cFYI(1, ("CIFS Tcon rc = %d", rc));
4929 }
4930 + if (rc)
4931 + goto mount_fail_check;
4932 + tcon->seal = volume_info.seal;
4933 + write_lock(&cifs_tcp_ses_lock);
4934 + list_add(&tcon->tcon_list, &pSesInfo->tcon_list);
4935 + write_unlock(&cifs_tcp_ses_lock);
4936 }
4937 +
4938 + /* we can have only one retry value for a connection
4939 + to a share so for resources mounted more than once
4940 + to the same server share the last value passed in
4941 + for the retry flag is used */
4942 + tcon->retry = volume_info.retry;
4943 + tcon->nocase = volume_info.nocase;
4944 }
4945 if (pSesInfo) {
4946 if (pSesInfo->capabilities & CAP_LARGE_FILES) {
4947 @@ -2217,91 +2307,49 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
4948 /* BB FIXME fix time_gran to be larger for LANMAN sessions */
4949 sb->s_time_gran = 100;
4950
4951 -/* on error free sesinfo and tcon struct if needed */
4952 + /* on error free sesinfo and tcon struct if needed */
4953 +mount_fail_check:
4954 if (rc) {
4955 - /* if session setup failed, use count is zero but
4956 - we still need to free cifsd thread */
4957 - if (atomic_read(&srvTcp->socketUseCount) == 0) {
4958 - spin_lock(&GlobalMid_Lock);
4959 - srvTcp->tcpStatus = CifsExiting;
4960 - spin_unlock(&GlobalMid_Lock);
4961 - if (srvTcp->tsk) {
4962 - /* If we could verify that kthread_stop would
4963 - always wake up processes blocked in
4964 - tcp in recv_mesg then we could remove the
4965 - send_sig call */
4966 - force_sig(SIGKILL, srvTcp->tsk);
4967 - kthread_stop(srvTcp->tsk);
4968 - }
4969 - }
4970 /* If find_unc succeeded then rc == 0 so we can not end */
4971 - if (tcon) /* up accidently freeing someone elses tcon struct */
4972 - tconInfoFree(tcon);
4973 - if (existingCifsSes == NULL) {
4974 - if (pSesInfo) {
4975 - if ((pSesInfo->server) &&
4976 - (pSesInfo->status == CifsGood)) {
4977 - int temp_rc;
4978 - temp_rc = CIFSSMBLogoff(xid, pSesInfo);
4979 - /* if the socketUseCount is now zero */
4980 - if ((temp_rc == -ESHUTDOWN) &&
4981 - (pSesInfo->server) &&
4982 - (pSesInfo->server->tsk)) {
4983 - force_sig(SIGKILL,
4984 - pSesInfo->server->tsk);
4985 - kthread_stop(pSesInfo->server->tsk);
4986 - }
4987 - } else {
4988 - cFYI(1, ("No session or bad tcon"));
4989 - if ((pSesInfo->server) &&
4990 - (pSesInfo->server->tsk)) {
4991 - force_sig(SIGKILL,
4992 - pSesInfo->server->tsk);
4993 - kthread_stop(pSesInfo->server->tsk);
4994 - }
4995 - }
4996 - sesInfoFree(pSesInfo);
4997 - /* pSesInfo = NULL; */
4998 - }
4999 - }
5000 - } else {
5001 - atomic_inc(&tcon->useCount);
5002 - cifs_sb->tcon = tcon;
5003 - tcon->ses = pSesInfo;
5004 -
5005 - /* do not care if following two calls succeed - informational */
5006 - if (!tcon->ipc) {
5007 - CIFSSMBQFSDeviceInfo(xid, tcon);
5008 - CIFSSMBQFSAttributeInfo(xid, tcon);
5009 - }
5010 -
5011 - /* tell server which Unix caps we support */
5012 - if (tcon->ses->capabilities & CAP_UNIX)
5013 - /* reset of caps checks mount to see if unix extensions
5014 - disabled for just this mount */
5015 - reset_cifs_unix_caps(xid, tcon, sb, &volume_info);
5016 + /* up accidently freeing someone elses tcon struct */
5017 + if (tcon)
5018 + cifs_put_tcon(tcon);
5019 + else if (pSesInfo)
5020 + cifs_put_smb_ses(pSesInfo);
5021 else
5022 - tcon->unix_ext = 0; /* server does not support them */
5023 + cifs_put_tcp_session(srvTcp);
5024 + goto out;
5025 + }
5026 + cifs_sb->tcon = tcon;
5027
5028 - /* convert forward to back slashes in prepath here if needed */
5029 - if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS) == 0)
5030 - convert_delimiter(cifs_sb->prepath,
5031 - CIFS_DIR_SEP(cifs_sb));
5032 + /* do not care if following two calls succeed - informational */
5033 + if (!tcon->ipc) {
5034 + CIFSSMBQFSDeviceInfo(xid, tcon);
5035 + CIFSSMBQFSAttributeInfo(xid, tcon);
5036 + }
5037
5038 - if ((tcon->unix_ext == 0) && (cifs_sb->rsize > (1024 * 127))) {
5039 - cifs_sb->rsize = 1024 * 127;
5040 - cFYI(DBG2,
5041 - ("no very large read support, rsize now 127K"));
5042 - }
5043 - if (!(tcon->ses->capabilities & CAP_LARGE_WRITE_X))
5044 - cifs_sb->wsize = min(cifs_sb->wsize,
5045 - (tcon->ses->server->maxBuf -
5046 - MAX_CIFS_HDR_SIZE));
5047 - if (!(tcon->ses->capabilities & CAP_LARGE_READ_X))
5048 - cifs_sb->rsize = min(cifs_sb->rsize,
5049 - (tcon->ses->server->maxBuf -
5050 - MAX_CIFS_HDR_SIZE));
5051 + /* tell server which Unix caps we support */
5052 + if (tcon->ses->capabilities & CAP_UNIX)
5053 + /* reset of caps checks mount to see if unix extensions
5054 + disabled for just this mount */
5055 + reset_cifs_unix_caps(xid, tcon, sb, &volume_info);
5056 + else
5057 + tcon->unix_ext = 0; /* server does not support them */
5058 +
5059 + /* convert forward to back slashes in prepath here if needed */
5060 + if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS) == 0)
5061 + convert_delimiter(cifs_sb->prepath, CIFS_DIR_SEP(cifs_sb));
5062 +
5063 + if ((tcon->unix_ext == 0) && (cifs_sb->rsize > (1024 * 127))) {
5064 + cifs_sb->rsize = 1024 * 127;
5065 + cFYI(DBG2, ("no very large read support, rsize now 127K"));
5066 }
5067 + if (!(tcon->ses->capabilities & CAP_LARGE_WRITE_X))
5068 + cifs_sb->wsize = min(cifs_sb->wsize,
5069 + (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE));
5070 + if (!(tcon->ses->capabilities & CAP_LARGE_READ_X))
5071 + cifs_sb->rsize = min(cifs_sb->rsize,
5072 + (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE));
5073
5074 /* volume_info.password is freed above when existing session found
5075 (in which case it is not needed anymore) but when new sesion is created
5076 @@ -3471,6 +3519,7 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,
5077 /* above now done in SendReceive */
5078 if ((rc == 0) && (tcon != NULL)) {
5079 tcon->tidStatus = CifsGood;
5080 + tcon->need_reconnect = false;
5081 tcon->tid = smb_buffer_response->Tid;
5082 bcc_ptr = pByteArea(smb_buffer_response);
5083 length = strnlen(bcc_ptr, BCC(smb_buffer_response) - 2);
5084 @@ -3542,52 +3591,17 @@ int
5085 cifs_umount(struct super_block *sb, struct cifs_sb_info *cifs_sb)
5086 {
5087 int rc = 0;
5088 - int xid;
5089 - struct cifsSesInfo *ses = NULL;
5090 - struct task_struct *cifsd_task;
5091 char *tmp;
5092
5093 - xid = GetXid();
5094 -
5095 - if (cifs_sb->tcon) {
5096 - ses = cifs_sb->tcon->ses; /* save ptr to ses before delete tcon!*/
5097 - rc = CIFSSMBTDis(xid, cifs_sb->tcon);
5098 - if (rc == -EBUSY) {
5099 - FreeXid(xid);
5100 - return 0;
5101 - }
5102 - DeleteTconOplockQEntries(cifs_sb->tcon);
5103 - tconInfoFree(cifs_sb->tcon);
5104 - if ((ses) && (ses->server)) {
5105 - /* save off task so we do not refer to ses later */
5106 - cifsd_task = ses->server->tsk;
5107 - cFYI(1, ("About to do SMBLogoff "));
5108 - rc = CIFSSMBLogoff(xid, ses);
5109 - if (rc == -EBUSY) {
5110 - FreeXid(xid);
5111 - return 0;
5112 - } else if (rc == -ESHUTDOWN) {
5113 - cFYI(1, ("Waking up socket by sending signal"));
5114 - if (cifsd_task) {
5115 - force_sig(SIGKILL, cifsd_task);
5116 - kthread_stop(cifsd_task);
5117 - }
5118 - rc = 0;
5119 - } /* else - we have an smb session
5120 - left on this socket do not kill cifsd */
5121 - } else
5122 - cFYI(1, ("No session or bad tcon"));
5123 - }
5124 + if (cifs_sb->tcon)
5125 + cifs_put_tcon(cifs_sb->tcon);
5126
5127 cifs_sb->tcon = NULL;
5128 tmp = cifs_sb->prepath;
5129 cifs_sb->prepathlen = 0;
5130 cifs_sb->prepath = NULL;
5131 kfree(tmp);
5132 - if (ses)
5133 - sesInfoFree(ses);
5134
5135 - FreeXid(xid);
5136 return rc;
5137 }
5138
5139 @@ -3702,6 +3716,7 @@ int cifs_setup_session(unsigned int xid, struct cifsSesInfo *pSesInfo,
5140 } else {
5141 cFYI(1, ("CIFS Session Established successfully"));
5142 pSesInfo->status = CifsGood;
5143 + pSesInfo->need_reconnect = false;
5144 }
5145
5146 ss_err_exit:
5147 diff --git a/fs/cifs/file.c b/fs/cifs/file.c
5148 index cbefe1f..042b122 100644
5149 --- a/fs/cifs/file.c
5150 +++ b/fs/cifs/file.c
5151 @@ -493,7 +493,7 @@ int cifs_close(struct inode *inode, struct file *file)
5152 if (pTcon) {
5153 /* no sense reconnecting to close a file that is
5154 already closed */
5155 - if (pTcon->tidStatus != CifsNeedReconnect) {
5156 + if (!pTcon->need_reconnect) {
5157 timeout = 2;
5158 while ((atomic_read(&pSMBFile->wrtPending) != 0)
5159 && (timeout <= 2048)) {
5160 @@ -1396,7 +1396,10 @@ retry:
5161 if ((wbc->nr_to_write -= n_iov) <= 0)
5162 done = 1;
5163 index = next;
5164 - }
5165 + } else
5166 + /* Need to re-find the pages we skipped */
5167 + index = pvec.pages[0]->index + 1;
5168 +
5169 pagevec_release(&pvec);
5170 }
5171 if (!scanned && !done) {
5172 @@ -1813,7 +1816,7 @@ static int cifs_readpages(struct file *file, struct address_space *mapping,
5173 pTcon = cifs_sb->tcon;
5174
5175 pagevec_init(&lru_pvec, 0);
5176 - cFYI(DBG2, ("rpages: num pages %d", num_pages));
5177 + cFYI(DBG2, ("rpages: num pages %d", num_pages));
5178 for (i = 0; i < num_pages; ) {
5179 unsigned contig_pages;
5180 struct page *tmp_page;
5181 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
5182 index 4b17f8f..b891553 100644
5183 --- a/fs/cifs/misc.c
5184 +++ b/fs/cifs/misc.c
5185 @@ -75,12 +75,12 @@ sesInfoAlloc(void)
5186
5187 ret_buf = kzalloc(sizeof(struct cifsSesInfo), GFP_KERNEL);
5188 if (ret_buf) {
5189 - write_lock(&GlobalSMBSeslock);
5190 atomic_inc(&sesInfoAllocCount);
5191 ret_buf->status = CifsNew;
5192 - list_add(&ret_buf->cifsSessionList, &GlobalSMBSessionList);
5193 + ++ret_buf->ses_count;
5194 + INIT_LIST_HEAD(&ret_buf->smb_ses_list);
5195 + INIT_LIST_HEAD(&ret_buf->tcon_list);
5196 init_MUTEX(&ret_buf->sesSem);
5197 - write_unlock(&GlobalSMBSeslock);
5198 }
5199 return ret_buf;
5200 }
5201 @@ -93,10 +93,7 @@ sesInfoFree(struct cifsSesInfo *buf_to_free)
5202 return;
5203 }
5204
5205 - write_lock(&GlobalSMBSeslock);
5206 atomic_dec(&sesInfoAllocCount);
5207 - list_del(&buf_to_free->cifsSessionList);
5208 - write_unlock(&GlobalSMBSeslock);
5209 kfree(buf_to_free->serverOS);
5210 kfree(buf_to_free->serverDomain);
5211 kfree(buf_to_free->serverNOS);
5212 @@ -111,17 +108,14 @@ tconInfoAlloc(void)
5213 struct cifsTconInfo *ret_buf;
5214 ret_buf = kzalloc(sizeof(struct cifsTconInfo), GFP_KERNEL);
5215 if (ret_buf) {
5216 - write_lock(&GlobalSMBSeslock);
5217 atomic_inc(&tconInfoAllocCount);
5218 - list_add(&ret_buf->cifsConnectionList,
5219 - &GlobalTreeConnectionList);
5220 ret_buf->tidStatus = CifsNew;
5221 + ++ret_buf->tc_count;
5222 INIT_LIST_HEAD(&ret_buf->openFileList);
5223 - init_MUTEX(&ret_buf->tconSem);
5224 + INIT_LIST_HEAD(&ret_buf->tcon_list);
5225 #ifdef CONFIG_CIFS_STATS
5226 spin_lock_init(&ret_buf->stat_lock);
5227 #endif
5228 - write_unlock(&GlobalSMBSeslock);
5229 }
5230 return ret_buf;
5231 }
5232 @@ -133,10 +127,7 @@ tconInfoFree(struct cifsTconInfo *buf_to_free)
5233 cFYI(1, ("Null buffer passed to tconInfoFree"));
5234 return;
5235 }
5236 - write_lock(&GlobalSMBSeslock);
5237 atomic_dec(&tconInfoAllocCount);
5238 - list_del(&buf_to_free->cifsConnectionList);
5239 - write_unlock(&GlobalSMBSeslock);
5240 kfree(buf_to_free->nativeFileSystem);
5241 kfree(buf_to_free);
5242 }
5243 @@ -354,9 +345,9 @@ header_assemble(struct smb_hdr *buffer, char smb_command /* command */ ,
5244 if (current->fsuid != treeCon->ses->linux_uid) {
5245 cFYI(1, ("Multiuser mode and UID "
5246 "did not match tcon uid"));
5247 - read_lock(&GlobalSMBSeslock);
5248 - list_for_each(temp_item, &GlobalSMBSessionList) {
5249 - ses = list_entry(temp_item, struct cifsSesInfo, cifsSessionList);
5250 + read_lock(&cifs_tcp_ses_lock);
5251 + list_for_each(temp_item, &treeCon->ses->server->smb_ses_list) {
5252 + ses = list_entry(temp_item, struct cifsSesInfo, smb_ses_list);
5253 if (ses->linux_uid == current->fsuid) {
5254 if (ses->server == treeCon->ses->server) {
5255 cFYI(1, ("found matching uid substitute right smb_uid"));
5256 @@ -368,7 +359,7 @@ header_assemble(struct smb_hdr *buffer, char smb_command /* command */ ,
5257 }
5258 }
5259 }
5260 - read_unlock(&GlobalSMBSeslock);
5261 + read_unlock(&cifs_tcp_ses_lock);
5262 }
5263 }
5264 }
5265 @@ -501,9 +492,10 @@ bool
5266 is_valid_oplock_break(struct smb_hdr *buf, struct TCP_Server_Info *srv)
5267 {
5268 struct smb_com_lock_req *pSMB = (struct smb_com_lock_req *)buf;
5269 - struct list_head *tmp;
5270 - struct list_head *tmp1;
5271 + struct list_head *tmp, *tmp1, *tmp2;
5272 + struct cifsSesInfo *ses;
5273 struct cifsTconInfo *tcon;
5274 + struct cifsInodeInfo *pCifsInode;
5275 struct cifsFileInfo *netfile;
5276
5277 cFYI(1, ("Checking for oplock break or dnotify response"));
5278 @@ -558,42 +550,42 @@ is_valid_oplock_break(struct smb_hdr *buf, struct TCP_Server_Info *srv)
5279 return false;
5280
5281 /* look up tcon based on tid & uid */
5282 - read_lock(&GlobalSMBSeslock);
5283 - list_for_each(tmp, &GlobalTreeConnectionList) {
5284 - tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
5285 - if ((tcon->tid == buf->Tid) && (srv == tcon->ses->server)) {
5286 + read_lock(&cifs_tcp_ses_lock);
5287 + list_for_each(tmp, &srv->smb_ses_list) {
5288 + ses = list_entry(tmp, struct cifsSesInfo, smb_ses_list);
5289 + list_for_each(tmp1, &ses->tcon_list) {
5290 + tcon = list_entry(tmp1, struct cifsTconInfo, tcon_list);
5291 + if (tcon->tid != buf->Tid)
5292 + continue;
5293 +
5294 cifs_stats_inc(&tcon->num_oplock_brks);
5295 - list_for_each(tmp1, &tcon->openFileList) {
5296 - netfile = list_entry(tmp1, struct cifsFileInfo,
5297 + list_for_each(tmp2, &tcon->openFileList) {
5298 + netfile = list_entry(tmp2, struct cifsFileInfo,
5299 tlist);
5300 - if (pSMB->Fid == netfile->netfid) {
5301 - struct cifsInodeInfo *pCifsInode;
5302 - read_unlock(&GlobalSMBSeslock);
5303 - cFYI(1,
5304 - ("file id match, oplock break"));
5305 - pCifsInode =
5306 - CIFS_I(netfile->pInode);
5307 - pCifsInode->clientCanCacheAll = false;
5308 - if (pSMB->OplockLevel == 0)
5309 - pCifsInode->clientCanCacheRead
5310 - = false;
5311 - pCifsInode->oplockPending = true;
5312 - AllocOplockQEntry(netfile->pInode,
5313 - netfile->netfid,
5314 - tcon);
5315 - cFYI(1,
5316 - ("about to wake up oplock thread"));
5317 - if (oplockThread)
5318 - wake_up_process(oplockThread);
5319 - return true;
5320 - }
5321 + if (pSMB->Fid != netfile->netfid)
5322 + continue;
5323 +
5324 + read_unlock(&cifs_tcp_ses_lock);
5325 + cFYI(1, ("file id match, oplock break"));
5326 + pCifsInode = CIFS_I(netfile->pInode);
5327 + pCifsInode->clientCanCacheAll = false;
5328 + if (pSMB->OplockLevel == 0)
5329 + pCifsInode->clientCanCacheRead = false;
5330 + pCifsInode->oplockPending = true;
5331 + AllocOplockQEntry(netfile->pInode,
5332 + netfile->netfid, tcon);
5333 + cFYI(1, ("about to wake up oplock thread"));
5334 + if (oplockThread)
5335 + wake_up_process(oplockThread);
5336 +
5337 + return true;
5338 }
5339 - read_unlock(&GlobalSMBSeslock);
5340 + read_unlock(&cifs_tcp_ses_lock);
5341 cFYI(1, ("No matching file for oplock break"));
5342 return true;
5343 }
5344 }
5345 - read_unlock(&GlobalSMBSeslock);
5346 + read_unlock(&cifs_tcp_ses_lock);
5347 cFYI(1, ("Can not process oplock break for non-existent connection"));
5348 return true;
5349 }
5350 diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c
5351 index e286db9..bb0f329 100644
5352 --- a/fs/cifs/transport.c
5353 +++ b/fs/cifs/transport.c
5354 @@ -162,7 +162,7 @@ void DeleteTconOplockQEntries(struct cifsTconInfo *tcon)
5355
5356 int
5357 smb_send(struct socket *ssocket, struct smb_hdr *smb_buffer,
5358 - unsigned int smb_buf_length, struct sockaddr *sin)
5359 + unsigned int smb_buf_length, struct sockaddr *sin, bool noblocksnd)
5360 {
5361 int rc = 0;
5362 int i = 0;
5363 @@ -179,7 +179,10 @@ smb_send(struct socket *ssocket, struct smb_hdr *smb_buffer,
5364 smb_msg.msg_namelen = sizeof(struct sockaddr);
5365 smb_msg.msg_control = NULL;
5366 smb_msg.msg_controllen = 0;
5367 - smb_msg.msg_flags = MSG_DONTWAIT + MSG_NOSIGNAL; /* BB add more flags?*/
5368 + if (noblocksnd)
5369 + smb_msg.msg_flags = MSG_DONTWAIT + MSG_NOSIGNAL;
5370 + else
5371 + smb_msg.msg_flags = MSG_NOSIGNAL;
5372
5373 /* smb header is converted in header_assemble. bcc and rest of SMB word
5374 area, and byte area if necessary, is converted to littleendian in
5375 @@ -230,8 +233,8 @@ smb_send(struct socket *ssocket, struct smb_hdr *smb_buffer,
5376 }
5377
5378 static int
5379 -smb_send2(struct socket *ssocket, struct kvec *iov, int n_vec,
5380 - struct sockaddr *sin)
5381 +smb_send2(struct TCP_Server_Info *server, struct kvec *iov, int n_vec,
5382 + struct sockaddr *sin, bool noblocksnd)
5383 {
5384 int rc = 0;
5385 int i = 0;
5386 @@ -241,6 +244,7 @@ smb_send2(struct socket *ssocket, struct kvec *iov, int n_vec,
5387 unsigned int total_len;
5388 int first_vec = 0;
5389 unsigned int smb_buf_length = smb_buffer->smb_buf_length;
5390 + struct socket *ssocket = server->ssocket;
5391
5392 if (ssocket == NULL)
5393 return -ENOTSOCK; /* BB eventually add reconnect code here */
5394 @@ -249,7 +253,10 @@ smb_send2(struct socket *ssocket, struct kvec *iov, int n_vec,
5395 smb_msg.msg_namelen = sizeof(struct sockaddr);
5396 smb_msg.msg_control = NULL;
5397 smb_msg.msg_controllen = 0;
5398 - smb_msg.msg_flags = MSG_DONTWAIT + MSG_NOSIGNAL; /* BB add more flags?*/
5399 + if (noblocksnd)
5400 + smb_msg.msg_flags = MSG_DONTWAIT + MSG_NOSIGNAL;
5401 + else
5402 + smb_msg.msg_flags = MSG_NOSIGNAL;
5403
5404 /* smb header is converted in header_assemble. bcc and rest of SMB word
5405 area, and byte area if necessary, is converted to littleendian in
5406 @@ -284,8 +291,11 @@ smb_send2(struct socket *ssocket, struct kvec *iov, int n_vec,
5407 if (rc < 0)
5408 break;
5409
5410 - if (rc >= total_len) {
5411 - WARN_ON(rc > total_len);
5412 + if (rc == total_len) {
5413 + total_len = 0;
5414 + break;
5415 + } else if (rc > total_len) {
5416 + cERROR(1, ("sent %d requested %d", rc, total_len));
5417 break;
5418 }
5419 if (rc == 0) {
5420 @@ -313,6 +323,16 @@ smb_send2(struct socket *ssocket, struct kvec *iov, int n_vec,
5421 i = 0; /* in case we get ENOSPC on the next send */
5422 }
5423
5424 + if ((total_len > 0) && (total_len != smb_buf_length + 4)) {
5425 + cFYI(1, ("partial send (%d remaining), terminating session",
5426 + total_len));
5427 + /* If we have only sent part of an SMB then the next SMB
5428 + could be taken as the remainder of this one. We need
5429 + to kill the socket so the server throws away the partial
5430 + SMB */
5431 + server->tcpStatus = CifsNeedReconnect;
5432 + }
5433 +
5434 if (rc < 0) {
5435 cERROR(1, ("Error %d sending data on socket to server", rc));
5436 } else
5437 @@ -519,8 +539,9 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses,
5438 #ifdef CONFIG_CIFS_STATS2
5439 atomic_inc(&ses->server->inSend);
5440 #endif
5441 - rc = smb_send2(ses->server->ssocket, iov, n_vec,
5442 - (struct sockaddr *) &(ses->server->addr.sockAddr));
5443 + rc = smb_send2(ses->server, iov, n_vec,
5444 + (struct sockaddr *) &(ses->server->addr.sockAddr),
5445 + ses->server->noblocksnd);
5446 #ifdef CONFIG_CIFS_STATS2
5447 atomic_dec(&ses->server->inSend);
5448 midQ->when_sent = jiffies;
5449 @@ -712,7 +733,8 @@ SendReceive(const unsigned int xid, struct cifsSesInfo *ses,
5450 atomic_inc(&ses->server->inSend);
5451 #endif
5452 rc = smb_send(ses->server->ssocket, in_buf, in_buf->smb_buf_length,
5453 - (struct sockaddr *) &(ses->server->addr.sockAddr));
5454 + (struct sockaddr *) &(ses->server->addr.sockAddr),
5455 + ses->server->noblocksnd);
5456 #ifdef CONFIG_CIFS_STATS2
5457 atomic_dec(&ses->server->inSend);
5458 midQ->when_sent = jiffies;
5459 @@ -852,7 +874,8 @@ send_nt_cancel(struct cifsTconInfo *tcon, struct smb_hdr *in_buf,
5460 return rc;
5461 }
5462 rc = smb_send(ses->server->ssocket, in_buf, in_buf->smb_buf_length,
5463 - (struct sockaddr *) &(ses->server->addr.sockAddr));
5464 + (struct sockaddr *) &(ses->server->addr.sockAddr),
5465 + ses->server->noblocksnd);
5466 up(&ses->server->tcpSem);
5467 return rc;
5468 }
5469 @@ -942,7 +965,8 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifsTconInfo *tcon,
5470 atomic_inc(&ses->server->inSend);
5471 #endif
5472 rc = smb_send(ses->server->ssocket, in_buf, in_buf->smb_buf_length,
5473 - (struct sockaddr *) &(ses->server->addr.sockAddr));
5474 + (struct sockaddr *) &(ses->server->addr.sockAddr),
5475 + ses->server->noblocksnd);
5476 #ifdef CONFIG_CIFS_STATS2
5477 atomic_dec(&ses->server->inSend);
5478 midQ->when_sent = jiffies;
5479 diff --git a/fs/ecryptfs/keystore.c b/fs/ecryptfs/keystore.c
5480 index f5b76a3..59b9833 100644
5481 --- a/fs/ecryptfs/keystore.c
5482 +++ b/fs/ecryptfs/keystore.c
5483 @@ -1037,17 +1037,14 @@ static int
5484 decrypt_passphrase_encrypted_session_key(struct ecryptfs_auth_tok *auth_tok,
5485 struct ecryptfs_crypt_stat *crypt_stat)
5486 {
5487 - struct scatterlist dst_sg;
5488 - struct scatterlist src_sg;
5489 + struct scatterlist dst_sg[2];
5490 + struct scatterlist src_sg[2];
5491 struct mutex *tfm_mutex;
5492 struct blkcipher_desc desc = {
5493 .flags = CRYPTO_TFM_REQ_MAY_SLEEP
5494 };
5495 int rc = 0;
5496
5497 - sg_init_table(&dst_sg, 1);
5498 - sg_init_table(&src_sg, 1);
5499 -
5500 if (unlikely(ecryptfs_verbosity > 0)) {
5501 ecryptfs_printk(
5502 KERN_DEBUG, "Session key encryption key (size [%d]):\n",
5503 @@ -1066,8 +1063,8 @@ decrypt_passphrase_encrypted_session_key(struct ecryptfs_auth_tok *auth_tok,
5504 }
5505 rc = virt_to_scatterlist(auth_tok->session_key.encrypted_key,
5506 auth_tok->session_key.encrypted_key_size,
5507 - &src_sg, 1);
5508 - if (rc != 1) {
5509 + src_sg, 2);
5510 + if (rc < 1 || rc > 2) {
5511 printk(KERN_ERR "Internal error whilst attempting to convert "
5512 "auth_tok->session_key.encrypted_key to scatterlist; "
5513 "expected rc = 1; got rc = [%d]. "
5514 @@ -1079,8 +1076,8 @@ decrypt_passphrase_encrypted_session_key(struct ecryptfs_auth_tok *auth_tok,
5515 auth_tok->session_key.encrypted_key_size;
5516 rc = virt_to_scatterlist(auth_tok->session_key.decrypted_key,
5517 auth_tok->session_key.decrypted_key_size,
5518 - &dst_sg, 1);
5519 - if (rc != 1) {
5520 + dst_sg, 2);
5521 + if (rc < 1 || rc > 2) {
5522 printk(KERN_ERR "Internal error whilst attempting to convert "
5523 "auth_tok->session_key.decrypted_key to scatterlist; "
5524 "expected rc = 1; got rc = [%d]\n", rc);
5525 @@ -1096,7 +1093,7 @@ decrypt_passphrase_encrypted_session_key(struct ecryptfs_auth_tok *auth_tok,
5526 rc = -EINVAL;
5527 goto out;
5528 }
5529 - rc = crypto_blkcipher_decrypt(&desc, &dst_sg, &src_sg,
5530 + rc = crypto_blkcipher_decrypt(&desc, dst_sg, src_sg,
5531 auth_tok->session_key.encrypted_key_size);
5532 mutex_unlock(tfm_mutex);
5533 if (unlikely(rc)) {
5534 @@ -1541,8 +1538,8 @@ write_tag_3_packet(char *dest, size_t *remaining_bytes,
5535 size_t i;
5536 size_t encrypted_session_key_valid = 0;
5537 char session_key_encryption_key[ECRYPTFS_MAX_KEY_BYTES];
5538 - struct scatterlist dst_sg;
5539 - struct scatterlist src_sg;
5540 + struct scatterlist dst_sg[2];
5541 + struct scatterlist src_sg[2];
5542 struct mutex *tfm_mutex = NULL;
5543 u8 cipher_code;
5544 size_t packet_size_length;
5545 @@ -1621,8 +1618,8 @@ write_tag_3_packet(char *dest, size_t *remaining_bytes,
5546 ecryptfs_dump_hex(session_key_encryption_key, 16);
5547 }
5548 rc = virt_to_scatterlist(crypt_stat->key, key_rec->enc_key_size,
5549 - &src_sg, 1);
5550 - if (rc != 1) {
5551 + src_sg, 2);
5552 + if (rc < 1 || rc > 2) {
5553 ecryptfs_printk(KERN_ERR, "Error generating scatterlist "
5554 "for crypt_stat session key; expected rc = 1; "
5555 "got rc = [%d]. key_rec->enc_key_size = [%d]\n",
5556 @@ -1631,8 +1628,8 @@ write_tag_3_packet(char *dest, size_t *remaining_bytes,
5557 goto out;
5558 }
5559 rc = virt_to_scatterlist(key_rec->enc_key, key_rec->enc_key_size,
5560 - &dst_sg, 1);
5561 - if (rc != 1) {
5562 + dst_sg, 2);
5563 + if (rc < 1 || rc > 2) {
5564 ecryptfs_printk(KERN_ERR, "Error generating scatterlist "
5565 "for crypt_stat encrypted session key; "
5566 "expected rc = 1; got rc = [%d]. "
5567 @@ -1653,7 +1650,7 @@ write_tag_3_packet(char *dest, size_t *remaining_bytes,
5568 rc = 0;
5569 ecryptfs_printk(KERN_DEBUG, "Encrypting [%d] bytes of the key\n",
5570 crypt_stat->key_size);
5571 - rc = crypto_blkcipher_encrypt(&desc, &dst_sg, &src_sg,
5572 + rc = crypto_blkcipher_encrypt(&desc, dst_sg, src_sg,
5573 (*key_rec).enc_key_size);
5574 mutex_unlock(tfm_mutex);
5575 if (rc) {
5576 diff --git a/fs/eventpoll.c b/fs/eventpoll.c
5577 index 7cc0eb7..c8cec49 100644
5578 --- a/fs/eventpoll.c
5579 +++ b/fs/eventpoll.c
5580 @@ -102,6 +102,8 @@
5581
5582 #define EP_UNACTIVE_PTR ((void *) -1L)
5583
5584 +#define EP_ITEM_COST (sizeof(struct epitem) + sizeof(struct eppoll_entry))
5585 +
5586 struct epoll_filefd {
5587 struct file *file;
5588 int fd;
5589 @@ -200,6 +202,9 @@ struct eventpoll {
5590 * holding ->lock.
5591 */
5592 struct epitem *ovflist;
5593 +
5594 + /* The user that created the eventpoll descriptor */
5595 + struct user_struct *user;
5596 };
5597
5598 /* Wait structure used by the poll hooks */
5599 @@ -227,9 +232,17 @@ struct ep_pqueue {
5600 };
5601
5602 /*
5603 + * Configuration options available inside /proc/sys/fs/epoll/
5604 + */
5605 +/* Maximum number of epoll devices, per user */
5606 +static int max_user_instances __read_mostly;
5607 +/* Maximum number of epoll watched descriptors, per user */
5608 +static int max_user_watches __read_mostly;
5609 +
5610 +/*
5611 * This mutex is used to serialize ep_free() and eventpoll_release_file().
5612 */
5613 -static struct mutex epmutex;
5614 +static DEFINE_MUTEX(epmutex);
5615
5616 /* Safe wake up implementation */
5617 static struct poll_safewake psw;
5618 @@ -240,6 +253,33 @@ static struct kmem_cache *epi_cache __read_mostly;
5619 /* Slab cache used to allocate "struct eppoll_entry" */
5620 static struct kmem_cache *pwq_cache __read_mostly;
5621
5622 +#ifdef CONFIG_SYSCTL
5623 +
5624 +#include <linux/sysctl.h>
5625 +
5626 +static int zero;
5627 +
5628 +ctl_table epoll_table[] = {
5629 + {
5630 + .procname = "max_user_instances",
5631 + .data = &max_user_instances,
5632 + .maxlen = sizeof(int),
5633 + .mode = 0644,
5634 + .proc_handler = &proc_dointvec_minmax,
5635 + .extra1 = &zero,
5636 + },
5637 + {
5638 + .procname = "max_user_watches",
5639 + .data = &max_user_watches,
5640 + .maxlen = sizeof(int),
5641 + .mode = 0644,
5642 + .proc_handler = &proc_dointvec_minmax,
5643 + .extra1 = &zero,
5644 + },
5645 + { .ctl_name = 0 }
5646 +};
5647 +#endif /* CONFIG_SYSCTL */
5648 +
5649
5650 /* Setup the structure that is used as key for the RB tree */
5651 static inline void ep_set_ffd(struct epoll_filefd *ffd,
5652 @@ -402,6 +442,8 @@ static int ep_remove(struct eventpoll *ep, struct epitem *epi)
5653 /* At this point it is safe to free the eventpoll item */
5654 kmem_cache_free(epi_cache, epi);
5655
5656 + atomic_dec(&ep->user->epoll_watches);
5657 +
5658 DNPRINTK(3, (KERN_INFO "[%p] eventpoll: ep_remove(%p, %p)\n",
5659 current, ep, file));
5660
5661 @@ -449,6 +491,8 @@ static void ep_free(struct eventpoll *ep)
5662
5663 mutex_unlock(&epmutex);
5664 mutex_destroy(&ep->mtx);
5665 + atomic_dec(&ep->user->epoll_devs);
5666 + free_uid(ep->user);
5667 kfree(ep);
5668 }
5669
5670 @@ -532,10 +576,19 @@ void eventpoll_release_file(struct file *file)
5671
5672 static int ep_alloc(struct eventpoll **pep)
5673 {
5674 - struct eventpoll *ep = kzalloc(sizeof(*ep), GFP_KERNEL);
5675 + int error;
5676 + struct user_struct *user;
5677 + struct eventpoll *ep;
5678
5679 - if (!ep)
5680 - return -ENOMEM;
5681 + user = get_current_user();
5682 + error = -EMFILE;
5683 + if (unlikely(atomic_read(&user->epoll_devs) >=
5684 + max_user_instances))
5685 + goto free_uid;
5686 + error = -ENOMEM;
5687 + ep = kzalloc(sizeof(*ep), GFP_KERNEL);
5688 + if (unlikely(!ep))
5689 + goto free_uid;
5690
5691 spin_lock_init(&ep->lock);
5692 mutex_init(&ep->mtx);
5693 @@ -544,12 +597,17 @@ static int ep_alloc(struct eventpoll **pep)
5694 INIT_LIST_HEAD(&ep->rdllist);
5695 ep->rbr = RB_ROOT;
5696 ep->ovflist = EP_UNACTIVE_PTR;
5697 + ep->user = user;
5698
5699 *pep = ep;
5700
5701 DNPRINTK(3, (KERN_INFO "[%p] eventpoll: ep_alloc() ep=%p\n",
5702 current, ep));
5703 return 0;
5704 +
5705 +free_uid:
5706 + free_uid(user);
5707 + return error;
5708 }
5709
5710 /*
5711 @@ -703,9 +761,11 @@ static int ep_insert(struct eventpoll *ep, struct epoll_event *event,
5712 struct epitem *epi;
5713 struct ep_pqueue epq;
5714
5715 - error = -ENOMEM;
5716 + if (unlikely(atomic_read(&ep->user->epoll_watches) >=
5717 + max_user_watches))
5718 + return -ENOSPC;
5719 if (!(epi = kmem_cache_alloc(epi_cache, GFP_KERNEL)))
5720 - goto error_return;
5721 + return -ENOMEM;
5722
5723 /* Item initialization follow here ... */
5724 INIT_LIST_HEAD(&epi->rdllink);
5725 @@ -735,6 +795,7 @@ static int ep_insert(struct eventpoll *ep, struct epoll_event *event,
5726 * install process. Namely an allocation for a wait queue failed due
5727 * high memory pressure.
5728 */
5729 + error = -ENOMEM;
5730 if (epi->nwait < 0)
5731 goto error_unregister;
5732
5733 @@ -765,6 +826,8 @@ static int ep_insert(struct eventpoll *ep, struct epoll_event *event,
5734
5735 spin_unlock_irqrestore(&ep->lock, flags);
5736
5737 + atomic_inc(&ep->user->epoll_watches);
5738 +
5739 /* We have to call this outside the lock */
5740 if (pwake)
5741 ep_poll_safewake(&psw, &ep->poll_wait);
5742 @@ -789,7 +852,7 @@ error_unregister:
5743 spin_unlock_irqrestore(&ep->lock, flags);
5744
5745 kmem_cache_free(epi_cache, epi);
5746 -error_return:
5747 +
5748 return error;
5749 }
5750
5751 @@ -1074,6 +1137,7 @@ asmlinkage long sys_epoll_create1(int flags)
5752 flags & O_CLOEXEC);
5753 if (fd < 0)
5754 ep_free(ep);
5755 + atomic_inc(&ep->user->epoll_devs);
5756
5757 error_return:
5758 DNPRINTK(3, (KERN_INFO "[%p] eventpoll: sys_epoll_create(%d) = %d\n",
5759 @@ -1295,7 +1359,12 @@ asmlinkage long sys_epoll_pwait(int epfd, struct epoll_event __user *events,
5760
5761 static int __init eventpoll_init(void)
5762 {
5763 - mutex_init(&epmutex);
5764 + struct sysinfo si;
5765 +
5766 + si_meminfo(&si);
5767 + max_user_instances = 128;
5768 + max_user_watches = (((si.totalram - si.totalhigh) / 32) << PAGE_SHIFT) /
5769 + EP_ITEM_COST;
5770
5771 /* Initialize the structure used to perform safe poll wait head wake ups */
5772 ep_poll_safewake_init(&psw);
5773 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
5774 index 10bb02c..6dac7ba 100644
5775 --- a/fs/ext2/balloc.c
5776 +++ b/fs/ext2/balloc.c
5777 @@ -1295,6 +1295,7 @@ retry_alloc:
5778 * turn off reservation for this allocation
5779 */
5780 if (my_rsv && (free_blocks < windowsz)
5781 + && (free_blocks > 0)
5782 && (rsv_is_empty(&my_rsv->rsv_window)))
5783 my_rsv = NULL;
5784
5785 @@ -1332,7 +1333,7 @@ retry_alloc:
5786 * free blocks is less than half of the reservation
5787 * window size.
5788 */
5789 - if (free_blocks <= (windowsz/2))
5790 + if (my_rsv && (free_blocks <= (windowsz/2)))
5791 continue;
5792
5793 brelse(bitmap_bh);
5794 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
5795 index 92fd033..f5b57a2 100644
5796 --- a/fs/ext3/balloc.c
5797 +++ b/fs/ext3/balloc.c
5798 @@ -1547,6 +1547,7 @@ retry_alloc:
5799 * turn off reservation for this allocation
5800 */
5801 if (my_rsv && (free_blocks < windowsz)
5802 + && (free_blocks > 0)
5803 && (rsv_is_empty(&my_rsv->rsv_window)))
5804 my_rsv = NULL;
5805
5806 @@ -1585,7 +1586,7 @@ retry_alloc:
5807 * free blocks is less than half of the reservation
5808 * window size.
5809 */
5810 - if (free_blocks <= (windowsz/2))
5811 + if (my_rsv && (free_blocks <= (windowsz/2)))
5812 continue;
5813
5814 brelse(bitmap_bh);
5815 diff --git a/fs/ext3/dir.c b/fs/ext3/dir.c
5816 index 1b80f1c..5853f44 100644
5817 --- a/fs/ext3/dir.c
5818 +++ b/fs/ext3/dir.c
5819 @@ -414,7 +414,7 @@ static int call_filldir(struct file * filp, void * dirent,
5820 get_dtype(sb, fname->file_type));
5821 if (error) {
5822 filp->f_pos = curr_pos;
5823 - info->extra_fname = fname->next;
5824 + info->extra_fname = fname;
5825 return error;
5826 }
5827 fname = fname->next;
5828 @@ -453,11 +453,12 @@ static int ext3_dx_readdir(struct file * filp,
5829 * If there are any leftover names on the hash collision
5830 * chain, return them first.
5831 */
5832 - if (info->extra_fname &&
5833 - call_filldir(filp, dirent, filldir, info->extra_fname))
5834 - goto finished;
5835 -
5836 - if (!info->curr_node)
5837 + if (info->extra_fname) {
5838 + if (call_filldir(filp, dirent, filldir, info->extra_fname))
5839 + goto finished;
5840 + info->extra_fname = NULL;
5841 + goto next_node;
5842 + } else if (!info->curr_node)
5843 info->curr_node = rb_first(&info->root);
5844
5845 while (1) {
5846 @@ -488,9 +489,14 @@ static int ext3_dx_readdir(struct file * filp,
5847 info->curr_minor_hash = fname->minor_hash;
5848 if (call_filldir(filp, dirent, filldir, fname))
5849 break;
5850 -
5851 + next_node:
5852 info->curr_node = rb_next(info->curr_node);
5853 - if (!info->curr_node) {
5854 + if (info->curr_node) {
5855 + fname = rb_entry(info->curr_node, struct fname,
5856 + rb_hash);
5857 + info->curr_hash = fname->hash;
5858 + info->curr_minor_hash = fname->minor_hash;
5859 + } else {
5860 if (info->next_hash == ~0) {
5861 filp->f_pos = EXT3_HTREE_EOF;
5862 break;
5863 diff --git a/fs/ext3/resize.c b/fs/ext3/resize.c
5864 index 77278e9..78fdf38 100644
5865 --- a/fs/ext3/resize.c
5866 +++ b/fs/ext3/resize.c
5867 @@ -790,7 +790,8 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input)
5868
5869 if (reserved_gdb || gdb_off == 0) {
5870 if (!EXT3_HAS_COMPAT_FEATURE(sb,
5871 - EXT3_FEATURE_COMPAT_RESIZE_INODE)){
5872 + EXT3_FEATURE_COMPAT_RESIZE_INODE)
5873 + || !le16_to_cpu(es->s_reserved_gdt_blocks)) {
5874 ext3_warning(sb, __func__,
5875 "No reserved GDT blocks, can't resize");
5876 return -EPERM;
5877 diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
5878 index d1d6487..e45d086 100644
5879 --- a/fs/ext4/dir.c
5880 +++ b/fs/ext4/dir.c
5881 @@ -458,17 +458,8 @@ static int ext4_dx_readdir(struct file * filp,
5882 if (info->extra_fname) {
5883 if (call_filldir(filp, dirent, filldir, info->extra_fname))
5884 goto finished;
5885 -
5886 info->extra_fname = NULL;
5887 - info->curr_node = rb_next(info->curr_node);
5888 - if (!info->curr_node) {
5889 - if (info->next_hash == ~0) {
5890 - filp->f_pos = EXT4_HTREE_EOF;
5891 - goto finished;
5892 - }
5893 - info->curr_hash = info->next_hash;
5894 - info->curr_minor_hash = 0;
5895 - }
5896 + goto next_node;
5897 } else if (!info->curr_node)
5898 info->curr_node = rb_first(&info->root);
5899
5900 @@ -500,9 +491,14 @@ static int ext4_dx_readdir(struct file * filp,
5901 info->curr_minor_hash = fname->minor_hash;
5902 if (call_filldir(filp, dirent, filldir, fname))
5903 break;
5904 -
5905 + next_node:
5906 info->curr_node = rb_next(info->curr_node);
5907 - if (!info->curr_node) {
5908 + if (info->curr_node) {
5909 + fname = rb_entry(info->curr_node, struct fname,
5910 + rb_hash);
5911 + info->curr_hash = fname->hash;
5912 + info->curr_minor_hash = fname->minor_hash;
5913 + } else {
5914 if (info->next_hash == ~0) {
5915 filp->f_pos = EXT4_HTREE_EOF;
5916 break;
5917 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
5918 index 2950032..4829dac 100644
5919 --- a/fs/ext4/ext4.h
5920 +++ b/fs/ext4/ext4.h
5921 @@ -291,8 +291,6 @@ struct ext4_new_group_data {
5922 #define EXT4_IOC_SETFLAGS FS_IOC_SETFLAGS
5923 #define EXT4_IOC_GETVERSION _IOR('f', 3, long)
5924 #define EXT4_IOC_SETVERSION _IOW('f', 4, long)
5925 -#define EXT4_IOC_GROUP_EXTEND _IOW('f', 7, unsigned long)
5926 -#define EXT4_IOC_GROUP_ADD _IOW('f', 8,struct ext4_new_group_input)
5927 #define EXT4_IOC_GETVERSION_OLD FS_IOC_GETVERSION
5928 #define EXT4_IOC_SETVERSION_OLD FS_IOC_SETVERSION
5929 #ifdef CONFIG_JBD2_DEBUG
5930 @@ -300,7 +298,10 @@ struct ext4_new_group_data {
5931 #endif
5932 #define EXT4_IOC_GETRSVSZ _IOR('f', 5, long)
5933 #define EXT4_IOC_SETRSVSZ _IOW('f', 6, long)
5934 -#define EXT4_IOC_MIGRATE _IO('f', 7)
5935 +#define EXT4_IOC_GROUP_EXTEND _IOW('f', 7, unsigned long)
5936 +#define EXT4_IOC_GROUP_ADD _IOW('f', 8, struct ext4_new_group_input)
5937 +#define EXT4_IOC_MIGRATE _IO('f', 9)
5938 + /* note ioctl 11 reserved for filesystem-independent FIEMAP ioctl */
5939
5940 /*
5941 * ioctl commands in 32 bit emulation
5942 @@ -1083,8 +1084,7 @@ extern long ext4_ioctl(struct file *, unsigned int, unsigned long);
5943 extern long ext4_compat_ioctl (struct file *, unsigned int, unsigned long);
5944
5945 /* migrate.c */
5946 -extern int ext4_ext_migrate(struct inode *, struct file *, unsigned int,
5947 - unsigned long);
5948 +extern int ext4_ext_migrate(struct inode *);
5949 /* namei.c */
5950 extern int ext4_orphan_add(handle_t *, struct inode *);
5951 extern int ext4_orphan_del(handle_t *, struct inode *);
5952 diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
5953 index f344834..9805924 100644
5954 --- a/fs/ext4/ialloc.c
5955 +++ b/fs/ext4/ialloc.c
5956 @@ -715,6 +715,8 @@ got:
5957 gdp->bg_flags &= cpu_to_le16(~EXT4_BG_BLOCK_UNINIT);
5958 free = ext4_free_blocks_after_init(sb, group, gdp);
5959 gdp->bg_free_blocks_count = cpu_to_le16(free);
5960 + gdp->bg_checksum = ext4_group_desc_csum(sbi, group,
5961 + gdp);
5962 }
5963 spin_unlock(sb_bgl_lock(sbi, group));
5964
5965 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
5966 index 7e91913..846a790 100644
5967 --- a/fs/ext4/inode.c
5968 +++ b/fs/ext4/inode.c
5969 @@ -2242,6 +2242,8 @@ static int ext4_da_writepage(struct page *page,
5970 unlock_page(page);
5971 return 0;
5972 }
5973 + /* now mark the buffer_heads as dirty and uptodate */
5974 + block_commit_write(page, 0, PAGE_CACHE_SIZE);
5975 }
5976
5977 if (test_opt(inode->i_sb, NOBH) && ext4_should_writeback_data(inode))
5978 @@ -4444,9 +4446,10 @@ static int ext4_indirect_trans_blocks(struct inode *inode, int nrblocks,
5979 static int ext4_index_trans_blocks(struct inode *inode, int nrblocks, int chunk)
5980 {
5981 if (!(EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL))
5982 - return ext4_indirect_trans_blocks(inode, nrblocks, 0);
5983 - return ext4_ext_index_trans_blocks(inode, nrblocks, 0);
5984 + return ext4_indirect_trans_blocks(inode, nrblocks, chunk);
5985 + return ext4_ext_index_trans_blocks(inode, nrblocks, chunk);
5986 }
5987 +
5988 /*
5989 * Account for index blocks, block groups bitmaps and block group
5990 * descriptor blocks if modify datablocks and index blocks
5991 diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
5992 index 7a6c2f1..306bfd4 100644
5993 --- a/fs/ext4/ioctl.c
5994 +++ b/fs/ext4/ioctl.c
5995 @@ -267,7 +267,26 @@ setversion_out:
5996 }
5997
5998 case EXT4_IOC_MIGRATE:
5999 - return ext4_ext_migrate(inode, filp, cmd, arg);
6000 + {
6001 + int err;
6002 + if (!is_owner_or_cap(inode))
6003 + return -EACCES;
6004 +
6005 + err = mnt_want_write(filp->f_path.mnt);
6006 + if (err)
6007 + return err;
6008 + /*
6009 + * inode_mutex prevent write and truncate on the file.
6010 + * Read still goes through. We take i_data_sem in
6011 + * ext4_ext_swap_inode_data before we switch the
6012 + * inode format to prevent read.
6013 + */
6014 + mutex_lock(&(inode->i_mutex));
6015 + err = ext4_ext_migrate(inode);
6016 + mutex_unlock(&(inode->i_mutex));
6017 + mnt_drop_write(filp->f_path.mnt);
6018 + return err;
6019 + }
6020
6021 default:
6022 return -ENOTTY;
6023 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
6024 index e0e3a5e..ba86b56 100644
6025 --- a/fs/ext4/mballoc.c
6026 +++ b/fs/ext4/mballoc.c
6027 @@ -2575,7 +2575,7 @@ static void ext4_mb_cleanup_pa(struct ext4_group_info *grp)
6028 pa = list_entry(cur, struct ext4_prealloc_space, pa_group_list);
6029 list_del(&pa->pa_group_list);
6030 count++;
6031 - kfree(pa);
6032 + kmem_cache_free(ext4_pspace_cachep, pa);
6033 }
6034 if (count)
6035 mb_debug("mballoc: %u PAs left\n", count);
6036 @@ -2785,14 +2785,20 @@ static int ext4_mb_init_per_dev_proc(struct super_block *sb)
6037 mode_t mode = S_IFREG | S_IRUGO | S_IWUSR;
6038 struct ext4_sb_info *sbi = EXT4_SB(sb);
6039 struct proc_dir_entry *proc;
6040 - char devname[64];
6041 + char devname[BDEVNAME_SIZE], *p;
6042
6043 if (proc_root_ext4 == NULL) {
6044 sbi->s_mb_proc = NULL;
6045 return -EINVAL;
6046 }
6047 bdevname(sb->s_bdev, devname);
6048 + p = devname;
6049 + while ((p = strchr(p, '/')))
6050 + *p = '!';
6051 +
6052 sbi->s_mb_proc = proc_mkdir(devname, proc_root_ext4);
6053 + if (!sbi->s_mb_proc)
6054 + goto err_create_dir;
6055
6056 MB_PROC_HANDLER(EXT4_MB_STATS_NAME, stats);
6057 MB_PROC_HANDLER(EXT4_MB_MAX_TO_SCAN_NAME, max_to_scan);
6058 @@ -2804,7 +2810,6 @@ static int ext4_mb_init_per_dev_proc(struct super_block *sb)
6059 return 0;
6060
6061 err_out:
6062 - printk(KERN_ERR "EXT4-fs: Unable to create %s\n", devname);
6063 remove_proc_entry(EXT4_MB_GROUP_PREALLOC, sbi->s_mb_proc);
6064 remove_proc_entry(EXT4_MB_STREAM_REQ, sbi->s_mb_proc);
6065 remove_proc_entry(EXT4_MB_ORDER2_REQ, sbi->s_mb_proc);
6066 @@ -2813,6 +2818,8 @@ err_out:
6067 remove_proc_entry(EXT4_MB_STATS_NAME, sbi->s_mb_proc);
6068 remove_proc_entry(devname, proc_root_ext4);
6069 sbi->s_mb_proc = NULL;
6070 +err_create_dir:
6071 + printk(KERN_ERR "EXT4-fs: Unable to create %s\n", devname);
6072
6073 return -ENOMEM;
6074 }
6075 @@ -2820,12 +2827,15 @@ err_out:
6076 static int ext4_mb_destroy_per_dev_proc(struct super_block *sb)
6077 {
6078 struct ext4_sb_info *sbi = EXT4_SB(sb);
6079 - char devname[64];
6080 + char devname[BDEVNAME_SIZE], *p;
6081
6082 if (sbi->s_mb_proc == NULL)
6083 return -EINVAL;
6084
6085 bdevname(sb->s_bdev, devname);
6086 + p = devname;
6087 + while ((p = strchr(p, '/')))
6088 + *p = '!';
6089 remove_proc_entry(EXT4_MB_GROUP_PREALLOC, sbi->s_mb_proc);
6090 remove_proc_entry(EXT4_MB_STREAM_REQ, sbi->s_mb_proc);
6091 remove_proc_entry(EXT4_MB_ORDER2_REQ, sbi->s_mb_proc);
6092 diff --git a/fs/ext4/migrate.c b/fs/ext4/migrate.c
6093 index 46fc0b5..f2a9cf4 100644
6094 --- a/fs/ext4/migrate.c
6095 +++ b/fs/ext4/migrate.c
6096 @@ -447,8 +447,7 @@ static int free_ext_block(handle_t *handle, struct inode *inode)
6097
6098 }
6099
6100 -int ext4_ext_migrate(struct inode *inode, struct file *filp,
6101 - unsigned int cmd, unsigned long arg)
6102 +int ext4_ext_migrate(struct inode *inode)
6103 {
6104 handle_t *handle;
6105 int retval = 0, i;
6106 @@ -516,12 +515,6 @@ int ext4_ext_migrate(struct inode *inode, struct file *filp,
6107 * when we add extents we extent the journal
6108 */
6109 /*
6110 - * inode_mutex prevent write and truncate on the file. Read still goes
6111 - * through. We take i_data_sem in ext4_ext_swap_inode_data before we
6112 - * switch the inode format to prevent read.
6113 - */
6114 - mutex_lock(&(inode->i_mutex));
6115 - /*
6116 * Even though we take i_mutex we can still cause block allocation
6117 * via mmap write to holes. If we have allocated new blocks we fail
6118 * migrate. New block allocation will clear EXT4_EXT_MIGRATE flag.
6119 @@ -623,7 +616,6 @@ err_out:
6120 tmp_inode->i_nlink = 0;
6121
6122 ext4_journal_stop(handle);
6123 - mutex_unlock(&(inode->i_mutex));
6124
6125 if (tmp_inode)
6126 iput(tmp_inode);
6127 diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
6128 index b3d3560..3922a8b 100644
6129 --- a/fs/ext4/resize.c
6130 +++ b/fs/ext4/resize.c
6131 @@ -929,6 +929,15 @@ int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input)
6132 percpu_counter_add(&sbi->s_freeinodes_counter,
6133 EXT4_INODES_PER_GROUP(sb));
6134
6135 + if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG)) {
6136 + ext4_group_t flex_group;
6137 + flex_group = ext4_flex_group(sbi, input->group);
6138 + sbi->s_flex_groups[flex_group].free_blocks +=
6139 + input->free_blocks_count;
6140 + sbi->s_flex_groups[flex_group].free_inodes +=
6141 + EXT4_INODES_PER_GROUP(sb);
6142 + }
6143 +
6144 ext4_journal_dirty_metadata(handle, sbi->s_sbh);
6145 sb->s_dirt = 1;
6146
6147 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
6148 index 566344b..7726e8e 100644
6149 --- a/fs/ext4/super.c
6150 +++ b/fs/ext4/super.c
6151 @@ -1504,8 +1504,10 @@ static int ext4_fill_flex_info(struct super_block *sb)
6152 sbi->s_log_groups_per_flex = sbi->s_es->s_log_groups_per_flex;
6153 groups_per_flex = 1 << sbi->s_log_groups_per_flex;
6154
6155 - flex_group_count = (sbi->s_groups_count + groups_per_flex - 1) /
6156 - groups_per_flex;
6157 + /* We allocate both existing and potentially added groups */
6158 + flex_group_count = ((sbi->s_groups_count + groups_per_flex - 1) +
6159 + ((le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) + 1) <<
6160 + EXT4_DESC_PER_BLOCK_BITS(sb))) / groups_per_flex;
6161 sbi->s_flex_groups = kzalloc(flex_group_count *
6162 sizeof(struct flex_groups), GFP_KERNEL);
6163 if (sbi->s_flex_groups == NULL) {
6164 @@ -1623,8 +1625,10 @@ static int ext4_check_descriptors(struct super_block *sb)
6165 "Checksum for group %lu failed (%u!=%u)\n",
6166 i, le16_to_cpu(ext4_group_desc_csum(sbi, i,
6167 gdp)), le16_to_cpu(gdp->bg_checksum));
6168 - if (!(sb->s_flags & MS_RDONLY))
6169 + if (!(sb->s_flags & MS_RDONLY)) {
6170 + spin_unlock(sb_bgl_lock(sbi, i));
6171 return 0;
6172 + }
6173 }
6174 spin_unlock(sb_bgl_lock(sbi, i));
6175 if (!flexbg_flag)
6176 @@ -2444,6 +2448,21 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
6177 "available.\n");
6178 }
6179
6180 + if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) {
6181 + printk(KERN_WARNING "EXT4-fs: Ignoring delalloc option - "
6182 + "requested data journaling mode\n");
6183 + clear_opt(sbi->s_mount_opt, DELALLOC);
6184 + } else if (test_opt(sb, DELALLOC))
6185 + printk(KERN_INFO "EXT4-fs: delayed allocation enabled\n");
6186 +
6187 + ext4_ext_init(sb);
6188 + err = ext4_mb_init(sb, needs_recovery);
6189 + if (err) {
6190 + printk(KERN_ERR "EXT4-fs: failed to initalize mballoc (%d)\n",
6191 + err);
6192 + goto failed_mount4;
6193 + }
6194 +
6195 /*
6196 * akpm: core read_super() calls in here with the superblock locked.
6197 * That deadlocks, because orphan cleanup needs to lock the superblock
6198 @@ -2463,16 +2482,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
6199 test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA ? "ordered":
6200 "writeback");
6201
6202 - if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) {
6203 - printk(KERN_WARNING "EXT4-fs: Ignoring delalloc option - "
6204 - "requested data journaling mode\n");
6205 - clear_opt(sbi->s_mount_opt, DELALLOC);
6206 - } else if (test_opt(sb, DELALLOC))
6207 - printk(KERN_INFO "EXT4-fs: delayed allocation enabled\n");
6208 -
6209 - ext4_ext_init(sb);
6210 - ext4_mb_init(sb, needs_recovery);
6211 -
6212 lock_kernel();
6213 return 0;
6214
6215 @@ -2799,13 +2808,34 @@ static void ext4_commit_super(struct super_block *sb,
6216
6217 if (!sbh)
6218 return;
6219 + if (buffer_write_io_error(sbh)) {
6220 + /*
6221 + * Oh, dear. A previous attempt to write the
6222 + * superblock failed. This could happen because the
6223 + * USB device was yanked out. Or it could happen to
6224 + * be a transient write error and maybe the block will
6225 + * be remapped. Nothing we can do but to retry the
6226 + * write and hope for the best.
6227 + */
6228 + printk(KERN_ERR "ext4: previous I/O error to "
6229 + "superblock detected for %s.\n", sb->s_id);
6230 + clear_buffer_write_io_error(sbh);
6231 + set_buffer_uptodate(sbh);
6232 + }
6233 es->s_wtime = cpu_to_le32(get_seconds());
6234 ext4_free_blocks_count_set(es, ext4_count_free_blocks(sb));
6235 es->s_free_inodes_count = cpu_to_le32(ext4_count_free_inodes(sb));
6236 BUFFER_TRACE(sbh, "marking dirty");
6237 mark_buffer_dirty(sbh);
6238 - if (sync)
6239 + if (sync) {
6240 sync_dirty_buffer(sbh);
6241 + if (buffer_write_io_error(sbh)) {
6242 + printk(KERN_ERR "ext4: I/O error while writing "
6243 + "superblock for %s.\n", sb->s_id);
6244 + clear_buffer_write_io_error(sbh);
6245 + set_buffer_uptodate(sbh);
6246 + }
6247 + }
6248 }
6249
6250
6251 @@ -2890,12 +2920,9 @@ int ext4_force_commit(struct super_block *sb)
6252 /*
6253 * Ext4 always journals updates to the superblock itself, so we don't
6254 * have to propagate any other updates to the superblock on disk at this
6255 - * point. Just start an async writeback to get the buffers on their way
6256 - * to the disk.
6257 - *
6258 - * This implicitly triggers the writebehind on sync().
6259 + * point. (We can probably nuke this function altogether, and remove
6260 + * any mention to sb->s_dirt in all of fs/ext4; eventual cleanup...)
6261 */
6262 -
6263 static void ext4_write_super(struct super_block *sb)
6264 {
6265 if (mutex_trylock(&sb->s_lock) != 0)
6266 @@ -2905,14 +2932,14 @@ static void ext4_write_super(struct super_block *sb)
6267
6268 static int ext4_sync_fs(struct super_block *sb, int wait)
6269 {
6270 - tid_t target;
6271 + int ret = 0;
6272
6273 sb->s_dirt = 0;
6274 - if (jbd2_journal_start_commit(EXT4_SB(sb)->s_journal, &target)) {
6275 - if (wait)
6276 - jbd2_log_wait_commit(EXT4_SB(sb)->s_journal, target);
6277 - }
6278 - return 0;
6279 + if (wait)
6280 + ret = ext4_force_commit(sb);
6281 + else
6282 + jbd2_journal_start_commit(EXT4_SB(sb)->s_journal, NULL);
6283 + return ret;
6284 }
6285
6286 /*
6287 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
6288 index 8954208..362b0ed 100644
6289 --- a/fs/ext4/xattr.c
6290 +++ b/fs/ext4/xattr.c
6291 @@ -959,6 +959,7 @@ ext4_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,
6292 struct ext4_xattr_block_find bs = {
6293 .s = { .not_found = -ENODATA, },
6294 };
6295 + unsigned long no_expand;
6296 int error;
6297
6298 if (!name)
6299 @@ -966,6 +967,9 @@ ext4_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,
6300 if (strlen(name) > 255)
6301 return -ERANGE;
6302 down_write(&EXT4_I(inode)->xattr_sem);
6303 + no_expand = EXT4_I(inode)->i_state & EXT4_STATE_NO_EXPAND;
6304 + EXT4_I(inode)->i_state |= EXT4_STATE_NO_EXPAND;
6305 +
6306 error = ext4_get_inode_loc(inode, &is.iloc);
6307 if (error)
6308 goto cleanup;
6309 @@ -1042,6 +1046,8 @@ ext4_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,
6310 cleanup:
6311 brelse(is.iloc.bh);
6312 brelse(bs.bh);
6313 + if (no_expand == 0)
6314 + EXT4_I(inode)->i_state &= ~EXT4_STATE_NO_EXPAND;
6315 up_write(&EXT4_I(inode)->xattr_sem);
6316 return error;
6317 }
6318 diff --git a/fs/inotify.c b/fs/inotify.c
6319 index 690e725..7bbed1b 100644
6320 --- a/fs/inotify.c
6321 +++ b/fs/inotify.c
6322 @@ -106,6 +106,20 @@ void get_inotify_watch(struct inotify_watch *watch)
6323 }
6324 EXPORT_SYMBOL_GPL(get_inotify_watch);
6325
6326 +int pin_inotify_watch(struct inotify_watch *watch)
6327 +{
6328 + struct super_block *sb = watch->inode->i_sb;
6329 + spin_lock(&sb_lock);
6330 + if (sb->s_count >= S_BIAS) {
6331 + atomic_inc(&sb->s_active);
6332 + spin_unlock(&sb_lock);
6333 + atomic_inc(&watch->count);
6334 + return 1;
6335 + }
6336 + spin_unlock(&sb_lock);
6337 + return 0;
6338 +}
6339 +
6340 /**
6341 * put_inotify_watch - decrements the ref count on a given watch. cleans up
6342 * watch references if the count reaches zero. inotify_watch is freed by
6343 @@ -124,6 +138,13 @@ void put_inotify_watch(struct inotify_watch *watch)
6344 }
6345 EXPORT_SYMBOL_GPL(put_inotify_watch);
6346
6347 +void unpin_inotify_watch(struct inotify_watch *watch)
6348 +{
6349 + struct super_block *sb = watch->inode->i_sb;
6350 + put_inotify_watch(watch);
6351 + deactivate_super(sb);
6352 +}
6353 +
6354 /*
6355 * inotify_handle_get_wd - returns the next WD for use by the given handle
6356 *
6357 @@ -479,6 +500,112 @@ void inotify_init_watch(struct inotify_watch *watch)
6358 }
6359 EXPORT_SYMBOL_GPL(inotify_init_watch);
6360
6361 +/*
6362 + * Watch removals suck violently. To kick the watch out we need (in this
6363 + * order) inode->inotify_mutex and ih->mutex. That's fine if we have
6364 + * a hold on inode; however, for all other cases we need to make damn sure
6365 + * we don't race with umount. We can *NOT* just grab a reference to a
6366 + * watch - inotify_unmount_inodes() will happily sail past it and we'll end
6367 + * with reference to inode potentially outliving its superblock. Ideally
6368 + * we just want to grab an active reference to superblock if we can; that
6369 + * will make sure we won't go into inotify_umount_inodes() until we are
6370 + * done. Cleanup is just deactivate_super(). However, that leaves a messy
6371 + * case - what if we *are* racing with umount() and active references to
6372 + * superblock can't be acquired anymore? We can bump ->s_count, grab
6373 + * ->s_umount, which will almost certainly wait until the superblock is shut
6374 + * down and the watch in question is pining for fjords. That's fine, but
6375 + * there is a problem - we might have hit the window between ->s_active
6376 + * getting to 0 / ->s_count - below S_BIAS (i.e. the moment when superblock
6377 + * is past the point of no return and is heading for shutdown) and the
6378 + * moment when deactivate_super() acquires ->s_umount. We could just do
6379 + * drop_super() yield() and retry, but that's rather antisocial and this
6380 + * stuff is luser-triggerable. OTOH, having grabbed ->s_umount and having
6381 + * found that we'd got there first (i.e. that ->s_root is non-NULL) we know
6382 + * that we won't race with inotify_umount_inodes(). So we could grab a
6383 + * reference to watch and do the rest as above, just with drop_super() instead
6384 + * of deactivate_super(), right? Wrong. We had to drop ih->mutex before we
6385 + * could grab ->s_umount. So the watch could've been gone already.
6386 + *
6387 + * That still can be dealt with - we need to save watch->wd, do idr_find()
6388 + * and compare its result with our pointer. If they match, we either have
6389 + * the damn thing still alive or we'd lost not one but two races at once,
6390 + * the watch had been killed and a new one got created with the same ->wd
6391 + * at the same address. That couldn't have happened in inotify_destroy(),
6392 + * but inotify_rm_wd() could run into that. Still, "new one got created"
6393 + * is not a problem - we have every right to kill it or leave it alone,
6394 + * whatever's more convenient.
6395 + *
6396 + * So we can use idr_find(...) == watch && watch->inode->i_sb == sb as
6397 + * "grab it and kill it" check. If it's been our original watch, we are
6398 + * fine, if it's a newcomer - nevermind, just pretend that we'd won the
6399 + * race and kill the fscker anyway; we are safe since we know that its
6400 + * superblock won't be going away.
6401 + *
6402 + * And yes, this is far beyond mere "not very pretty"; so's the entire
6403 + * concept of inotify to start with.
6404 + */
6405 +
6406 +/**
6407 + * pin_to_kill - pin the watch down for removal
6408 + * @ih: inotify handle
6409 + * @watch: watch to kill
6410 + *
6411 + * Called with ih->mutex held, drops it. Possible return values:
6412 + * 0 - nothing to do, it has died
6413 + * 1 - remove it, drop the reference and deactivate_super()
6414 + * 2 - remove it, drop the reference and drop_super(); we tried hard to avoid
6415 + * that variant, since it involved a lot of PITA, but that's the best that
6416 + * could've been done.
6417 + */
6418 +static int pin_to_kill(struct inotify_handle *ih, struct inotify_watch *watch)
6419 +{
6420 + struct super_block *sb = watch->inode->i_sb;
6421 + s32 wd = watch->wd;
6422 +
6423 + spin_lock(&sb_lock);
6424 + if (sb->s_count >= S_BIAS) {
6425 + atomic_inc(&sb->s_active);
6426 + spin_unlock(&sb_lock);
6427 + get_inotify_watch(watch);
6428 + mutex_unlock(&ih->mutex);
6429 + return 1; /* the best outcome */
6430 + }
6431 + sb->s_count++;
6432 + spin_unlock(&sb_lock);
6433 + mutex_unlock(&ih->mutex); /* can't grab ->s_umount under it */
6434 + down_read(&sb->s_umount);
6435 + if (likely(!sb->s_root)) {
6436 + /* fs is already shut down; the watch is dead */
6437 + drop_super(sb);
6438 + return 0;
6439 + }
6440 + /* raced with the final deactivate_super() */
6441 + mutex_lock(&ih->mutex);
6442 + if (idr_find(&ih->idr, wd) != watch || watch->inode->i_sb != sb) {
6443 + /* the watch is dead */
6444 + mutex_unlock(&ih->mutex);
6445 + drop_super(sb);
6446 + return 0;
6447 + }
6448 + /* still alive or freed and reused with the same sb and wd; kill */
6449 + get_inotify_watch(watch);
6450 + mutex_unlock(&ih->mutex);
6451 + return 2;
6452 +}
6453 +
6454 +static void unpin_and_kill(struct inotify_watch *watch, int how)
6455 +{
6456 + struct super_block *sb = watch->inode->i_sb;
6457 + put_inotify_watch(watch);
6458 + switch (how) {
6459 + case 1:
6460 + deactivate_super(sb);
6461 + break;
6462 + case 2:
6463 + drop_super(sb);
6464 + }
6465 +}
6466 +
6467 /**
6468 * inotify_destroy - clean up and destroy an inotify instance
6469 * @ih: inotify handle
6470 @@ -490,11 +617,15 @@ void inotify_destroy(struct inotify_handle *ih)
6471 * pretty. We cannot do a simple iteration over the list, because we
6472 * do not know the inode until we iterate to the watch. But we need to
6473 * hold inode->inotify_mutex before ih->mutex. The following works.
6474 + *
6475 + * AV: it had to become even uglier to start working ;-/
6476 */
6477 while (1) {
6478 struct inotify_watch *watch;
6479 struct list_head *watches;
6480 + struct super_block *sb;
6481 struct inode *inode;
6482 + int how;
6483
6484 mutex_lock(&ih->mutex);
6485 watches = &ih->watches;
6486 @@ -503,8 +634,10 @@ void inotify_destroy(struct inotify_handle *ih)
6487 break;
6488 }
6489 watch = list_first_entry(watches, struct inotify_watch, h_list);
6490 - get_inotify_watch(watch);
6491 - mutex_unlock(&ih->mutex);
6492 + sb = watch->inode->i_sb;
6493 + how = pin_to_kill(ih, watch);
6494 + if (!how)
6495 + continue;
6496
6497 inode = watch->inode;
6498 mutex_lock(&inode->inotify_mutex);
6499 @@ -518,7 +651,7 @@ void inotify_destroy(struct inotify_handle *ih)
6500
6501 mutex_unlock(&ih->mutex);
6502 mutex_unlock(&inode->inotify_mutex);
6503 - put_inotify_watch(watch);
6504 + unpin_and_kill(watch, how);
6505 }
6506
6507 /* free this handle: the put matching the get in inotify_init() */
6508 @@ -719,7 +852,9 @@ void inotify_evict_watch(struct inotify_watch *watch)
6509 int inotify_rm_wd(struct inotify_handle *ih, u32 wd)
6510 {
6511 struct inotify_watch *watch;
6512 + struct super_block *sb;
6513 struct inode *inode;
6514 + int how;
6515
6516 mutex_lock(&ih->mutex);
6517 watch = idr_find(&ih->idr, wd);
6518 @@ -727,9 +862,12 @@ int inotify_rm_wd(struct inotify_handle *ih, u32 wd)
6519 mutex_unlock(&ih->mutex);
6520 return -EINVAL;
6521 }
6522 - get_inotify_watch(watch);
6523 + sb = watch->inode->i_sb;
6524 + how = pin_to_kill(ih, watch);
6525 + if (!how)
6526 + return 0;
6527 +
6528 inode = watch->inode;
6529 - mutex_unlock(&ih->mutex);
6530
6531 mutex_lock(&inode->inotify_mutex);
6532 mutex_lock(&ih->mutex);
6533 @@ -740,7 +878,7 @@ int inotify_rm_wd(struct inotify_handle *ih, u32 wd)
6534
6535 mutex_unlock(&ih->mutex);
6536 mutex_unlock(&inode->inotify_mutex);
6537 - put_inotify_watch(watch);
6538 + unpin_and_kill(watch, how);
6539
6540 return 0;
6541 }
6542 diff --git a/fs/jbd/transaction.c b/fs/jbd/transaction.c
6543 index 0540ca2..d15cd6e 100644
6544 --- a/fs/jbd/transaction.c
6545 +++ b/fs/jbd/transaction.c
6546 @@ -954,9 +954,10 @@ int journal_dirty_data(handle_t *handle, struct buffer_head *bh)
6547 journal_t *journal = handle->h_transaction->t_journal;
6548 int need_brelse = 0;
6549 struct journal_head *jh;
6550 + int ret = 0;
6551
6552 if (is_handle_aborted(handle))
6553 - return 0;
6554 + return ret;
6555
6556 jh = journal_add_journal_head(bh);
6557 JBUFFER_TRACE(jh, "entry");
6558 @@ -1067,7 +1068,16 @@ int journal_dirty_data(handle_t *handle, struct buffer_head *bh)
6559 time if it is redirtied */
6560 }
6561
6562 - /* journal_clean_data_list() may have got there first */
6563 + /*
6564 + * We cannot remove the buffer with io error from the
6565 + * committing transaction, because otherwise it would
6566 + * miss the error and the commit would not abort.
6567 + */
6568 + if (unlikely(!buffer_uptodate(bh))) {
6569 + ret = -EIO;
6570 + goto no_journal;
6571 + }
6572 +
6573 if (jh->b_transaction != NULL) {
6574 JBUFFER_TRACE(jh, "unfile from commit");
6575 __journal_temp_unlink_buffer(jh);
6576 @@ -1108,7 +1118,7 @@ no_journal:
6577 }
6578 JBUFFER_TRACE(jh, "exit");
6579 journal_put_journal_head(jh);
6580 - return 0;
6581 + return ret;
6582 }
6583
6584 /**
6585 diff --git a/fs/jbd2/checkpoint.c b/fs/jbd2/checkpoint.c
6586 index 91389c8..77255a3 100644
6587 --- a/fs/jbd2/checkpoint.c
6588 +++ b/fs/jbd2/checkpoint.c
6589 @@ -114,7 +114,7 @@ static int __try_to_free_cp_buf(struct journal_head *jh)
6590 */
6591 void __jbd2_log_wait_for_space(journal_t *journal)
6592 {
6593 - int nblocks;
6594 + int nblocks, space_left;
6595 assert_spin_locked(&journal->j_state_lock);
6596
6597 nblocks = jbd_space_needed(journal);
6598 @@ -126,14 +126,47 @@ void __jbd2_log_wait_for_space(journal_t *journal)
6599
6600 /*
6601 * Test again, another process may have checkpointed while we
6602 - * were waiting for the checkpoint lock
6603 + * were waiting for the checkpoint lock. If there are no
6604 + * transactions ready to be checkpointed, try to recover
6605 + * journal space by calling cleanup_journal_tail(), and if
6606 + * that doesn't work, by waiting for the currently committing
6607 + * transaction to complete. If there is absolutely no way
6608 + * to make progress, this is either a BUG or corrupted
6609 + * filesystem, so abort the journal and leave a stack
6610 + * trace for forensic evidence.
6611 */
6612 spin_lock(&journal->j_state_lock);
6613 + spin_lock(&journal->j_list_lock);
6614 nblocks = jbd_space_needed(journal);
6615 - if (__jbd2_log_space_left(journal) < nblocks) {
6616 + space_left = __jbd2_log_space_left(journal);
6617 + if (space_left < nblocks) {
6618 + int chkpt = journal->j_checkpoint_transactions != NULL;
6619 + tid_t tid = 0;
6620 +
6621 + if (journal->j_committing_transaction)
6622 + tid = journal->j_committing_transaction->t_tid;
6623 + spin_unlock(&journal->j_list_lock);
6624 spin_unlock(&journal->j_state_lock);
6625 - jbd2_log_do_checkpoint(journal);
6626 + if (chkpt) {
6627 + jbd2_log_do_checkpoint(journal);
6628 + } else if (jbd2_cleanup_journal_tail(journal) == 0) {
6629 + /* We were able to recover space; yay! */
6630 + ;
6631 + } else if (tid) {
6632 + jbd2_log_wait_commit(journal, tid);
6633 + } else {
6634 + printk(KERN_ERR "%s: needed %d blocks and "
6635 + "only had %d space available\n",
6636 + __func__, nblocks, space_left);
6637 + printk(KERN_ERR "%s: no way to get more "
6638 + "journal space in %s\n", __func__,
6639 + journal->j_devname);
6640 + WARN_ON(1);
6641 + jbd2_journal_abort(journal, 0);
6642 + }
6643 spin_lock(&journal->j_state_lock);
6644 + } else {
6645 + spin_unlock(&journal->j_list_lock);
6646 }
6647 mutex_unlock(&journal->j_checkpoint_mutex);
6648 }
6649 diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c
6650 index f2ad061..6caf22d 100644
6651 --- a/fs/jbd2/commit.c
6652 +++ b/fs/jbd2/commit.c
6653 @@ -126,8 +126,7 @@ static int journal_submit_commit_record(journal_t *journal,
6654
6655 JBUFFER_TRACE(descriptor, "submit commit block");
6656 lock_buffer(bh);
6657 - get_bh(bh);
6658 - set_buffer_dirty(bh);
6659 + clear_buffer_dirty(bh);
6660 set_buffer_uptodate(bh);
6661 bh->b_end_io = journal_end_buffer_io_sync;
6662
6663 @@ -160,7 +159,7 @@ static int journal_submit_commit_record(journal_t *journal,
6664 /* And try again, without the barrier */
6665 lock_buffer(bh);
6666 set_buffer_uptodate(bh);
6667 - set_buffer_dirty(bh);
6668 + clear_buffer_dirty(bh);
6669 ret = submit_bh(WRITE, bh);
6670 }
6671 *cbh = bh;
6672 diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
6673 index 8207a01..52d2bee 100644
6674 --- a/fs/jbd2/journal.c
6675 +++ b/fs/jbd2/journal.c
6676 @@ -901,10 +901,7 @@ static struct proc_dir_entry *proc_jbd2_stats;
6677
6678 static void jbd2_stats_proc_init(journal_t *journal)
6679 {
6680 - char name[BDEVNAME_SIZE];
6681 -
6682 - bdevname(journal->j_dev, name);
6683 - journal->j_proc_entry = proc_mkdir(name, proc_jbd2_stats);
6684 + journal->j_proc_entry = proc_mkdir(journal->j_devname, proc_jbd2_stats);
6685 if (journal->j_proc_entry) {
6686 proc_create_data("history", S_IRUGO, journal->j_proc_entry,
6687 &jbd2_seq_history_fops, journal);
6688 @@ -915,12 +912,9 @@ static void jbd2_stats_proc_init(journal_t *journal)
6689
6690 static void jbd2_stats_proc_exit(journal_t *journal)
6691 {
6692 - char name[BDEVNAME_SIZE];
6693 -
6694 - bdevname(journal->j_dev, name);
6695 remove_proc_entry("info", journal->j_proc_entry);
6696 remove_proc_entry("history", journal->j_proc_entry);
6697 - remove_proc_entry(name, proc_jbd2_stats);
6698 + remove_proc_entry(journal->j_devname, proc_jbd2_stats);
6699 }
6700
6701 static void journal_init_stats(journal_t *journal)
6702 @@ -1018,6 +1012,7 @@ journal_t * jbd2_journal_init_dev(struct block_device *bdev,
6703 {
6704 journal_t *journal = journal_init_common();
6705 struct buffer_head *bh;
6706 + char *p;
6707 int n;
6708
6709 if (!journal)
6710 @@ -1039,6 +1034,10 @@ journal_t * jbd2_journal_init_dev(struct block_device *bdev,
6711 journal->j_fs_dev = fs_dev;
6712 journal->j_blk_offset = start;
6713 journal->j_maxlen = len;
6714 + bdevname(journal->j_dev, journal->j_devname);
6715 + p = journal->j_devname;
6716 + while ((p = strchr(p, '/')))
6717 + *p = '!';
6718 jbd2_stats_proc_init(journal);
6719
6720 bh = __getblk(journal->j_dev, start, journal->j_blocksize);
6721 @@ -1061,6 +1060,7 @@ journal_t * jbd2_journal_init_inode (struct inode *inode)
6722 {
6723 struct buffer_head *bh;
6724 journal_t *journal = journal_init_common();
6725 + char *p;
6726 int err;
6727 int n;
6728 unsigned long long blocknr;
6729 @@ -1070,6 +1070,12 @@ journal_t * jbd2_journal_init_inode (struct inode *inode)
6730
6731 journal->j_dev = journal->j_fs_dev = inode->i_sb->s_bdev;
6732 journal->j_inode = inode;
6733 + bdevname(journal->j_dev, journal->j_devname);
6734 + p = journal->j_devname;
6735 + while ((p = strchr(p, '/')))
6736 + *p = '!';
6737 + p = journal->j_devname + strlen(journal->j_devname);
6738 + sprintf(p, ":%lu", journal->j_inode->i_ino);
6739 jbd_debug(1,
6740 "journal %p: inode %s/%ld, size %Ld, bits %d, blksize %ld\n",
6741 journal, inode->i_sb->s_id, inode->i_ino,
6742 @@ -1253,6 +1259,22 @@ void jbd2_journal_update_superblock(journal_t *journal, int wait)
6743 goto out;
6744 }
6745
6746 + if (buffer_write_io_error(bh)) {
6747 + /*
6748 + * Oh, dear. A previous attempt to write the journal
6749 + * superblock failed. This could happen because the
6750 + * USB device was yanked out. Or it could happen to
6751 + * be a transient write error and maybe the block will
6752 + * be remapped. Nothing we can do but to retry the
6753 + * write and hope for the best.
6754 + */
6755 + printk(KERN_ERR "JBD2: previous I/O error detected "
6756 + "for journal superblock update for %s.\n",
6757 + journal->j_devname);
6758 + clear_buffer_write_io_error(bh);
6759 + set_buffer_uptodate(bh);
6760 + }
6761 +
6762 spin_lock(&journal->j_state_lock);
6763 jbd_debug(1,"JBD: updating superblock (start %ld, seq %d, errno %d)\n",
6764 journal->j_tail, journal->j_tail_sequence, journal->j_errno);
6765 @@ -1264,9 +1286,16 @@ void jbd2_journal_update_superblock(journal_t *journal, int wait)
6766
6767 BUFFER_TRACE(bh, "marking dirty");
6768 mark_buffer_dirty(bh);
6769 - if (wait)
6770 + if (wait) {
6771 sync_dirty_buffer(bh);
6772 - else
6773 + if (buffer_write_io_error(bh)) {
6774 + printk(KERN_ERR "JBD2: I/O error detected "
6775 + "when updating journal superblock for %s.\n",
6776 + journal->j_devname);
6777 + clear_buffer_write_io_error(bh);
6778 + set_buffer_uptodate(bh);
6779 + }
6780 + } else
6781 ll_rw_block(SWRITE, 1, &bh);
6782
6783 out:
6784 diff --git a/include/asm-x86/mmzone_32.h b/include/asm-x86/mmzone_32.h
6785 index 5862e64..eb77583 100644
6786 --- a/include/asm-x86/mmzone_32.h
6787 +++ b/include/asm-x86/mmzone_32.h
6788 @@ -34,10 +34,14 @@ static inline void get_memcfg_numa(void)
6789
6790 extern int early_pfn_to_nid(unsigned long pfn);
6791
6792 +extern void resume_map_numa_kva(pgd_t *pgd);
6793 +
6794 #else /* !CONFIG_NUMA */
6795
6796 #define get_memcfg_numa get_memcfg_numa_flat
6797
6798 +static inline void resume_map_numa_kva(pgd_t *pgd) {}
6799 +
6800 #endif /* CONFIG_NUMA */
6801
6802 #ifdef CONFIG_DISCONTIGMEM
6803 diff --git a/include/asm-x86/pci_64.h b/include/asm-x86/pci_64.h
6804 index f330234..50d3df5 100644
6805 --- a/include/asm-x86/pci_64.h
6806 +++ b/include/asm-x86/pci_64.h
6807 @@ -34,8 +34,6 @@ extern void pci_iommu_alloc(void);
6808 */
6809 #define PCI_DMA_BUS_IS_PHYS (dma_ops->is_phys)
6810
6811 -#if defined(CONFIG_GART_IOMMU) || defined(CONFIG_CALGARY_IOMMU)
6812 -
6813 #define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME) \
6814 dma_addr_t ADDR_NAME;
6815 #define DECLARE_PCI_UNMAP_LEN(LEN_NAME) \
6816 @@ -49,18 +47,6 @@ extern void pci_iommu_alloc(void);
6817 #define pci_unmap_len_set(PTR, LEN_NAME, VAL) \
6818 (((PTR)->LEN_NAME) = (VAL))
6819
6820 -#else
6821 -/* No IOMMU */
6822 -
6823 -#define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME)
6824 -#define DECLARE_PCI_UNMAP_LEN(LEN_NAME)
6825 -#define pci_unmap_addr(PTR, ADDR_NAME) (0)
6826 -#define pci_unmap_addr_set(PTR, ADDR_NAME, VAL) do { } while (0)
6827 -#define pci_unmap_len(PTR, LEN_NAME) (0)
6828 -#define pci_unmap_len_set(PTR, LEN_NAME, VAL) do { } while (0)
6829 -
6830 -#endif
6831 -
6832 #endif /* __KERNEL__ */
6833
6834 #endif /* __x8664_PCI_H */
6835 diff --git a/include/linux/idr.h b/include/linux/idr.h
6836 index fa035f9..dd846df 100644
6837 --- a/include/linux/idr.h
6838 +++ b/include/linux/idr.h
6839 @@ -52,13 +52,14 @@ struct idr_layer {
6840 unsigned long bitmap; /* A zero bit means "space here" */
6841 struct idr_layer *ary[1<<IDR_BITS];
6842 int count; /* When zero, we can release it */
6843 + int layer; /* distance from leaf */
6844 struct rcu_head rcu_head;
6845 };
6846
6847 struct idr {
6848 struct idr_layer *top;
6849 struct idr_layer *id_free;
6850 - int layers;
6851 + int layers; /* only valid without concurrent changes */
6852 int id_free_cnt;
6853 spinlock_t lock;
6854 };
6855 diff --git a/include/linux/inotify.h b/include/linux/inotify.h
6856 index bd57857..37ea289 100644
6857 --- a/include/linux/inotify.h
6858 +++ b/include/linux/inotify.h
6859 @@ -134,6 +134,8 @@ extern void inotify_remove_watch_locked(struct inotify_handle *,
6860 struct inotify_watch *);
6861 extern void get_inotify_watch(struct inotify_watch *);
6862 extern void put_inotify_watch(struct inotify_watch *);
6863 +extern int pin_inotify_watch(struct inotify_watch *);
6864 +extern void unpin_inotify_watch(struct inotify_watch *);
6865
6866 #else
6867
6868 @@ -228,6 +230,15 @@ static inline void put_inotify_watch(struct inotify_watch *watch)
6869 {
6870 }
6871
6872 +extern inline int pin_inotify_watch(struct inotify_watch *watch)
6873 +{
6874 + return 0;
6875 +}
6876 +
6877 +extern inline void unpin_inotify_watch(struct inotify_watch *watch)
6878 +{
6879 +}
6880 +
6881 #endif /* CONFIG_INOTIFY */
6882
6883 #endif /* __KERNEL __ */
6884 diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h
6885 index 3dd2090..66c3499 100644
6886 --- a/include/linux/jbd2.h
6887 +++ b/include/linux/jbd2.h
6888 @@ -850,7 +850,8 @@ struct journal_s
6889 */
6890 struct block_device *j_dev;
6891 int j_blocksize;
6892 - unsigned long long j_blk_offset;
6893 + unsigned long long j_blk_offset;
6894 + char j_devname[BDEVNAME_SIZE+24];
6895
6896 /*
6897 * Device which holds the client fs. For internal journal this will be
6898 diff --git a/include/linux/libata.h b/include/linux/libata.h
6899 index 225bfc5..25062ac 100644
6900 --- a/include/linux/libata.h
6901 +++ b/include/linux/libata.h
6902 @@ -364,6 +364,7 @@ enum {
6903 ATA_HORKAGE_IPM = (1 << 7), /* Link PM problems */
6904 ATA_HORKAGE_IVB = (1 << 8), /* cbl det validity bit bugs */
6905 ATA_HORKAGE_STUCK_ERR = (1 << 9), /* stuck ERR on next PACKET */
6906 + ATA_HORKAGE_FIRMWARE_WARN = (1 << 12), /* firwmare update warning */
6907
6908 /* DMA mask for user DMA control: User visible values; DO NOT
6909 renumber */
6910 diff --git a/include/linux/pci.h b/include/linux/pci.h
6911 index 98dc624..426e029 100644
6912 --- a/include/linux/pci.h
6913 +++ b/include/linux/pci.h
6914 @@ -64,6 +64,11 @@ struct pci_slot {
6915 struct kobject kobj;
6916 };
6917
6918 +static inline const char *pci_slot_name(const struct pci_slot *slot)
6919 +{
6920 + return kobject_name(&slot->kobj);
6921 +}
6922 +
6923 /* File state for mmap()s on /proc/bus/pci/X/Y */
6924 enum pci_mmap_state {
6925 pci_mmap_io,
6926 @@ -509,7 +514,8 @@ struct pci_bus *pci_create_bus(struct device *parent, int bus,
6927 struct pci_bus *pci_add_new_bus(struct pci_bus *parent, struct pci_dev *dev,
6928 int busnr);
6929 struct pci_slot *pci_create_slot(struct pci_bus *parent, int slot_nr,
6930 - const char *name);
6931 + const char *name,
6932 + struct hotplug_slot *hotplug);
6933 void pci_destroy_slot(struct pci_slot *slot);
6934 void pci_update_slot_number(struct pci_slot *slot, int slot_nr);
6935 int pci_scan_slot(struct pci_bus *bus, int devfn);
6936 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
6937 index a08cd06..a00bd1a 100644
6938 --- a/include/linux/pci_hotplug.h
6939 +++ b/include/linux/pci_hotplug.h
6940 @@ -142,8 +142,6 @@ struct hotplug_slot_info {
6941
6942 /**
6943 * struct hotplug_slot - used to register a physical slot with the hotplug pci core
6944 - * @name: the name of the slot being registered. This string must
6945 - * be unique amoung slots registered on this system.
6946 * @ops: pointer to the &struct hotplug_slot_ops to be used for this slot
6947 * @info: pointer to the &struct hotplug_slot_info for the initial values for
6948 * this slot.
6949 @@ -153,7 +151,6 @@ struct hotplug_slot_info {
6950 * needs.
6951 */
6952 struct hotplug_slot {
6953 - char *name;
6954 struct hotplug_slot_ops *ops;
6955 struct hotplug_slot_info *info;
6956 void (*release) (struct hotplug_slot *slot);
6957 @@ -165,7 +162,13 @@ struct hotplug_slot {
6958 };
6959 #define to_hotplug_slot(n) container_of(n, struct hotplug_slot, kobj)
6960
6961 -extern int pci_hp_register(struct hotplug_slot *, struct pci_bus *, int nr);
6962 +static inline const char *hotplug_slot_name(const struct hotplug_slot *slot)
6963 +{
6964 + return pci_slot_name(slot->pci_slot);
6965 +}
6966 +
6967 +extern int pci_hp_register(struct hotplug_slot *, struct pci_bus *, int nr,
6968 + const char *name);
6969 extern int pci_hp_deregister(struct hotplug_slot *slot);
6970 extern int __must_check pci_hp_change_slot_info (struct hotplug_slot *slot,
6971 struct hotplug_slot_info *info);
6972 diff --git a/include/linux/sched.h b/include/linux/sched.h
6973 index 6bfb849..086f5e1 100644
6974 --- a/include/linux/sched.h
6975 +++ b/include/linux/sched.h
6976 @@ -587,6 +587,10 @@ struct user_struct {
6977 atomic_t inotify_watches; /* How many inotify watches does this user have? */
6978 atomic_t inotify_devs; /* How many inotify devs does this user have opened? */
6979 #endif
6980 +#ifdef CONFIG_EPOLL
6981 + atomic_t epoll_devs; /* The number of epoll descriptors currently open */
6982 + atomic_t epoll_watches; /* The number of file descriptors currently watched */
6983 +#endif
6984 #ifdef CONFIG_POSIX_MQUEUE
6985 /* protected by mq_lock */
6986 unsigned long mq_bytes; /* How many bytes can be allocated to mqueue? */
6987 diff --git a/include/net/af_unix.h b/include/net/af_unix.h
6988 index c29ff1d..1614d78 100644
6989 --- a/include/net/af_unix.h
6990 +++ b/include/net/af_unix.h
6991 @@ -9,6 +9,7 @@
6992 extern void unix_inflight(struct file *fp);
6993 extern void unix_notinflight(struct file *fp);
6994 extern void unix_gc(void);
6995 +extern void wait_for_unix_gc(void);
6996
6997 #define UNIX_HASH_SIZE 256
6998
6999 diff --git a/ipc/util.c b/ipc/util.c
7000 index 49b3ea6..361fd1c 100644
7001 --- a/ipc/util.c
7002 +++ b/ipc/util.c
7003 @@ -266,9 +266,17 @@ int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size)
7004 if (ids->in_use >= size)
7005 return -ENOSPC;
7006
7007 + spin_lock_init(&new->lock);
7008 + new->deleted = 0;
7009 + rcu_read_lock();
7010 + spin_lock(&new->lock);
7011 +
7012 err = idr_get_new(&ids->ipcs_idr, new, &id);
7013 - if (err)
7014 + if (err) {
7015 + spin_unlock(&new->lock);
7016 + rcu_read_unlock();
7017 return err;
7018 + }
7019
7020 ids->in_use++;
7021
7022 @@ -280,10 +288,6 @@ int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size)
7023 ids->seq = 0;
7024
7025 new->id = ipc_buildid(id, new->seq);
7026 - spin_lock_init(&new->lock);
7027 - new->deleted = 0;
7028 - rcu_read_lock();
7029 - spin_lock(&new->lock);
7030 return id;
7031 }
7032
7033 diff --git a/kernel/Makefile b/kernel/Makefile
7034 index 4e1d7df..143e8b6 100644
7035 --- a/kernel/Makefile
7036 +++ b/kernel/Makefile
7037 @@ -11,8 +11,6 @@ obj-y = sched.o fork.o exec_domain.o panic.o printk.o \
7038 hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \
7039 notifier.o ksysfs.o pm_qos_params.o sched_clock.o
7040
7041 -CFLAGS_REMOVE_sched.o = -mno-spe
7042 -
7043 ifdef CONFIG_FTRACE
7044 # Do not trace debug files and internal ftrace files
7045 CFLAGS_REMOVE_lockdep.o = -pg
7046 @@ -21,7 +19,7 @@ CFLAGS_REMOVE_mutex-debug.o = -pg
7047 CFLAGS_REMOVE_rtmutex-debug.o = -pg
7048 CFLAGS_REMOVE_cgroup-debug.o = -pg
7049 CFLAGS_REMOVE_sched_clock.o = -pg
7050 -CFLAGS_REMOVE_sched.o = -mno-spe -pg
7051 +CFLAGS_REMOVE_sched.o = -pg
7052 endif
7053
7054 obj-$(CONFIG_PROFILING) += profile.o
7055 diff --git a/kernel/audit_tree.c b/kernel/audit_tree.c
7056 index f7921a2..894b599 100644
7057 --- a/kernel/audit_tree.c
7058 +++ b/kernel/audit_tree.c
7059 @@ -24,6 +24,7 @@ struct audit_chunk {
7060 struct list_head trees; /* with root here */
7061 int dead;
7062 int count;
7063 + atomic_long_t refs;
7064 struct rcu_head head;
7065 struct node {
7066 struct list_head list;
7067 @@ -56,7 +57,8 @@ static LIST_HEAD(prune_list);
7068 * tree is refcounted; one reference for "some rules on rules_list refer to
7069 * it", one for each chunk with pointer to it.
7070 *
7071 - * chunk is refcounted by embedded inotify_watch.
7072 + * chunk is refcounted by embedded inotify_watch + .refs (non-zero refcount
7073 + * of watch contributes 1 to .refs).
7074 *
7075 * node.index allows to get from node.list to containing chunk.
7076 * MSB of that sucker is stolen to mark taggings that we might have to
7077 @@ -121,6 +123,7 @@ static struct audit_chunk *alloc_chunk(int count)
7078 INIT_LIST_HEAD(&chunk->hash);
7079 INIT_LIST_HEAD(&chunk->trees);
7080 chunk->count = count;
7081 + atomic_long_set(&chunk->refs, 1);
7082 for (i = 0; i < count; i++) {
7083 INIT_LIST_HEAD(&chunk->owners[i].list);
7084 chunk->owners[i].index = i;
7085 @@ -129,9 +132,8 @@ static struct audit_chunk *alloc_chunk(int count)
7086 return chunk;
7087 }
7088
7089 -static void __free_chunk(struct rcu_head *rcu)
7090 +static void free_chunk(struct audit_chunk *chunk)
7091 {
7092 - struct audit_chunk *chunk = container_of(rcu, struct audit_chunk, head);
7093 int i;
7094
7095 for (i = 0; i < chunk->count; i++) {
7096 @@ -141,14 +143,16 @@ static void __free_chunk(struct rcu_head *rcu)
7097 kfree(chunk);
7098 }
7099
7100 -static inline void free_chunk(struct audit_chunk *chunk)
7101 +void audit_put_chunk(struct audit_chunk *chunk)
7102 {
7103 - call_rcu(&chunk->head, __free_chunk);
7104 + if (atomic_long_dec_and_test(&chunk->refs))
7105 + free_chunk(chunk);
7106 }
7107
7108 -void audit_put_chunk(struct audit_chunk *chunk)
7109 +static void __put_chunk(struct rcu_head *rcu)
7110 {
7111 - put_inotify_watch(&chunk->watch);
7112 + struct audit_chunk *chunk = container_of(rcu, struct audit_chunk, head);
7113 + audit_put_chunk(chunk);
7114 }
7115
7116 enum {HASH_SIZE = 128};
7117 @@ -176,7 +180,7 @@ struct audit_chunk *audit_tree_lookup(const struct inode *inode)
7118
7119 list_for_each_entry_rcu(p, list, hash) {
7120 if (p->watch.inode == inode) {
7121 - get_inotify_watch(&p->watch);
7122 + atomic_long_inc(&p->refs);
7123 return p;
7124 }
7125 }
7126 @@ -194,17 +198,49 @@ int audit_tree_match(struct audit_chunk *chunk, struct audit_tree *tree)
7127
7128 /* tagging and untagging inodes with trees */
7129
7130 -static void untag_chunk(struct audit_chunk *chunk, struct node *p)
7131 +static struct audit_chunk *find_chunk(struct node *p)
7132 +{
7133 + int index = p->index & ~(1U<<31);
7134 + p -= index;
7135 + return container_of(p, struct audit_chunk, owners[0]);
7136 +}
7137 +
7138 +static void untag_chunk(struct node *p)
7139 {
7140 + struct audit_chunk *chunk = find_chunk(p);
7141 struct audit_chunk *new;
7142 struct audit_tree *owner;
7143 int size = chunk->count - 1;
7144 int i, j;
7145
7146 + if (!pin_inotify_watch(&chunk->watch)) {
7147 + /*
7148 + * Filesystem is shutting down; all watches are getting
7149 + * evicted, just take it off the node list for this
7150 + * tree and let the eviction logics take care of the
7151 + * rest.
7152 + */
7153 + owner = p->owner;
7154 + if (owner->root == chunk) {
7155 + list_del_init(&owner->same_root);
7156 + owner->root = NULL;
7157 + }
7158 + list_del_init(&p->list);
7159 + p->owner = NULL;
7160 + put_tree(owner);
7161 + return;
7162 + }
7163 +
7164 + spin_unlock(&hash_lock);
7165 +
7166 + /*
7167 + * pin_inotify_watch() succeeded, so the watch won't go away
7168 + * from under us.
7169 + */
7170 mutex_lock(&chunk->watch.inode->inotify_mutex);
7171 if (chunk->dead) {
7172 mutex_unlock(&chunk->watch.inode->inotify_mutex);
7173 - return;
7174 + goto out;
7175 }
7176
7177 owner = p->owner;
7178 @@ -221,7 +257,7 @@ static void untag_chunk(struct audit_chunk *chunk, struct node *p)
7179 inotify_evict_watch(&chunk->watch);
7180 mutex_unlock(&chunk->watch.inode->inotify_mutex);
7181 put_inotify_watch(&chunk->watch);
7182 - return;
7183 + goto out;
7184 }
7185
7186 new = alloc_chunk(size);
7187 @@ -263,7 +299,7 @@ static void untag_chunk(struct audit_chunk *chunk, struct node *p)
7188 inotify_evict_watch(&chunk->watch);
7189 mutex_unlock(&chunk->watch.inode->inotify_mutex);
7190 put_inotify_watch(&chunk->watch);
7191 - return;
7192 + goto out;
7193
7194 Fallback:
7195 // do the best we can
7196 @@ -277,6 +313,9 @@ Fallback:
7197 put_tree(owner);
7198 spin_unlock(&hash_lock);
7199 mutex_unlock(&chunk->watch.inode->inotify_mutex);
7200 +out:
7201 + unpin_inotify_watch(&chunk->watch);
7202 + spin_lock(&hash_lock);
7203 }
7204
7205 static int create_chunk(struct inode *inode, struct audit_tree *tree)
7206 @@ -387,13 +426,6 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree)
7207 return 0;
7208 }
7209
7210 -static struct audit_chunk *find_chunk(struct node *p)
7211 -{
7212 - int index = p->index & ~(1U<<31);
7213 - p -= index;
7214 - return container_of(p, struct audit_chunk, owners[0]);
7215 -}
7216 -
7217 static void kill_rules(struct audit_tree *tree)
7218 {
7219 struct audit_krule *rule, *next;
7220 @@ -431,17 +463,10 @@ static void prune_one(struct audit_tree *victim)
7221 spin_lock(&hash_lock);
7222 while (!list_empty(&victim->chunks)) {
7223 struct node *p;
7224 - struct audit_chunk *chunk;
7225
7226 p = list_entry(victim->chunks.next, struct node, list);
7227 - chunk = find_chunk(p);
7228 - get_inotify_watch(&chunk->watch);
7229 - spin_unlock(&hash_lock);
7230 -
7231 - untag_chunk(chunk, p);
7232
7233 - put_inotify_watch(&chunk->watch);
7234 - spin_lock(&hash_lock);
7235 + untag_chunk(p);
7236 }
7237 spin_unlock(&hash_lock);
7238 put_tree(victim);
7239 @@ -469,7 +494,6 @@ static void trim_marked(struct audit_tree *tree)
7240
7241 while (!list_empty(&tree->chunks)) {
7242 struct node *node;
7243 - struct audit_chunk *chunk;
7244
7245 node = list_entry(tree->chunks.next, struct node, list);
7246
7247 @@ -477,14 +501,7 @@ static void trim_marked(struct audit_tree *tree)
7248 if (!(node->index & (1U<<31)))
7249 break;
7250
7251 - chunk = find_chunk(node);
7252 - get_inotify_watch(&chunk->watch);
7253 - spin_unlock(&hash_lock);
7254 -
7255 - untag_chunk(chunk, node);
7256 -
7257 - put_inotify_watch(&chunk->watch);
7258 - spin_lock(&hash_lock);
7259 + untag_chunk(node);
7260 }
7261 if (!tree->root && !tree->goner) {
7262 tree->goner = 1;
7263 @@ -878,7 +895,7 @@ static void handle_event(struct inotify_watch *watch, u32 wd, u32 mask,
7264 static void destroy_watch(struct inotify_watch *watch)
7265 {
7266 struct audit_chunk *chunk = container_of(watch, struct audit_chunk, watch);
7267 - free_chunk(chunk);
7268 + call_rcu(&chunk->head, __put_chunk);
7269 }
7270
7271 static const struct inotify_operations rtree_inotify_ops = {
7272 diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c
7273 index b7d354e..9fd85a4 100644
7274 --- a/kernel/auditfilter.c
7275 +++ b/kernel/auditfilter.c
7276 @@ -1094,8 +1094,8 @@ static void audit_inotify_unregister(struct list_head *in_list)
7277 list_for_each_entry_safe(p, n, in_list, ilist) {
7278 list_del(&p->ilist);
7279 inotify_rm_watch(audit_ih, &p->wdata);
7280 - /* the put matching the get in audit_do_del_rule() */
7281 - put_inotify_watch(&p->wdata);
7282 + /* the unpin matching the pin in audit_do_del_rule() */
7283 + unpin_inotify_watch(&p->wdata);
7284 }
7285 }
7286
7287 @@ -1389,9 +1389,13 @@ static inline int audit_del_rule(struct audit_entry *entry,
7288 /* Put parent on the inotify un-registration
7289 * list. Grab a reference before releasing
7290 * audit_filter_mutex, to be released in
7291 - * audit_inotify_unregister(). */
7292 - list_add(&parent->ilist, &inotify_list);
7293 - get_inotify_watch(&parent->wdata);
7294 + * audit_inotify_unregister().
7295 + * If filesystem is going away, just leave
7296 + * the sucker alone, eviction will take
7297 + * care of it.
7298 + */
7299 + if (pin_inotify_watch(&parent->wdata))
7300 + list_add(&parent->ilist, &inotify_list);
7301 }
7302 }
7303 }
7304 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
7305 index d68bf2b..0ba3a5a 100644
7306 --- a/kernel/cgroup.c
7307 +++ b/kernel/cgroup.c
7308 @@ -2045,10 +2045,13 @@ int cgroupstats_build(struct cgroupstats *stats, struct dentry *dentry)
7309 struct cgroup *cgrp;
7310 struct cgroup_iter it;
7311 struct task_struct *tsk;
7312 +
7313 /*
7314 - * Validate dentry by checking the superblock operations
7315 + * Validate dentry by checking the superblock operations,
7316 + * and make sure it's a directory.
7317 */
7318 - if (dentry->d_sb->s_op != &cgroup_ops)
7319 + if (dentry->d_sb->s_op != &cgroup_ops ||
7320 + !S_ISDIR(dentry->d_inode->i_mode))
7321 goto err;
7322
7323 ret = 0;
7324 diff --git a/kernel/cpuset.c b/kernel/cpuset.c
7325 index 827cd9a..fbda85d 100644
7326 --- a/kernel/cpuset.c
7327 +++ b/kernel/cpuset.c
7328 @@ -587,7 +587,6 @@ static int generate_sched_domains(cpumask_t **domains,
7329 int ndoms; /* number of sched domains in result */
7330 int nslot; /* next empty doms[] cpumask_t slot */
7331
7332 - ndoms = 0;
7333 doms = NULL;
7334 dattr = NULL;
7335 csa = NULL;
7336 @@ -674,10 +673,8 @@ restart:
7337 * Convert <csn, csa> to <ndoms, doms> and populate cpu masks.
7338 */
7339 doms = kmalloc(ndoms * sizeof(cpumask_t), GFP_KERNEL);
7340 - if (!doms) {
7341 - ndoms = 0;
7342 + if (!doms)
7343 goto done;
7344 - }
7345
7346 /*
7347 * The rest of the code, including the scheduler, can deal with
7348 @@ -732,6 +729,13 @@ restart:
7349 done:
7350 kfree(csa);
7351
7352 + /*
7353 + * Fallback to the default domain if kmalloc() failed.
7354 + * See comments in partition_sched_domains().
7355 + */
7356 + if (doms == NULL)
7357 + ndoms = 1;
7358 +
7359 *domains = doms;
7360 *attributes = dattr;
7361 return ndoms;
7362 diff --git a/kernel/sched.c b/kernel/sched.c
7363 index ad1962d..a992cbe 100644
7364 --- a/kernel/sched.c
7365 +++ b/kernel/sched.c
7366 @@ -7692,13 +7692,14 @@ static int dattrs_equal(struct sched_domain_attr *cur, int idx_cur,
7367 *
7368 * The passed in 'doms_new' should be kmalloc'd. This routine takes
7369 * ownership of it and will kfree it when done with it. If the caller
7370 - * failed the kmalloc call, then it can pass in doms_new == NULL,
7371 - * and partition_sched_domains() will fallback to the single partition
7372 - * 'fallback_doms', it also forces the domains to be rebuilt.
7373 + * failed the kmalloc call, then it can pass in doms_new == NULL &&
7374 + * ndoms_new == 1, and partition_sched_domains() will fallback to
7375 + * the single partition 'fallback_doms', it also forces the domains
7376 + * to be rebuilt.
7377 *
7378 - * If doms_new==NULL it will be replaced with cpu_online_map.
7379 - * ndoms_new==0 is a special case for destroying existing domains.
7380 - * It will not create the default domain.
7381 + * If doms_new == NULL it will be replaced with cpu_online_map.
7382 + * ndoms_new == 0 is a special case for destroying existing domains,
7383 + * and it will not create the default domain.
7384 *
7385 * Call with hotplug lock held
7386 */
7387 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
7388 index 50ec088..6ffbed2 100644
7389 --- a/kernel/sysctl.c
7390 +++ b/kernel/sysctl.c
7391 @@ -179,6 +179,9 @@ extern struct ctl_table random_table[];
7392 #ifdef CONFIG_INOTIFY_USER
7393 extern struct ctl_table inotify_table[];
7394 #endif
7395 +#ifdef CONFIG_EPOLL
7396 +extern struct ctl_table epoll_table[];
7397 +#endif
7398
7399 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
7400 int sysctl_legacy_va_layout;
7401 @@ -1313,6 +1316,13 @@ static struct ctl_table fs_table[] = {
7402 .child = inotify_table,
7403 },
7404 #endif
7405 +#ifdef CONFIG_EPOLL
7406 + {
7407 + .procname = "epoll",
7408 + .mode = 0555,
7409 + .child = epoll_table,
7410 + },
7411 +#endif
7412 #endif
7413 {
7414 .ctl_name = KERN_SETUID_DUMPABLE,
7415 diff --git a/lib/idr.c b/lib/idr.c
7416 index e728c7f..7a785a0 100644
7417 --- a/lib/idr.c
7418 +++ b/lib/idr.c
7419 @@ -185,6 +185,7 @@ static int sub_alloc(struct idr *idp, int *starting_id, struct idr_layer **pa)
7420 new = get_from_free_list(idp);
7421 if (!new)
7422 return -1;
7423 + new->layer = l-1;
7424 rcu_assign_pointer(p->ary[m], new);
7425 p->count++;
7426 }
7427 @@ -210,6 +211,7 @@ build_up:
7428 if (unlikely(!p)) {
7429 if (!(p = get_from_free_list(idp)))
7430 return -1;
7431 + p->layer = 0;
7432 layers = 1;
7433 }
7434 /*
7435 @@ -237,6 +239,7 @@ build_up:
7436 }
7437 new->ary[0] = p;
7438 new->count = 1;
7439 + new->layer = layers-1;
7440 if (p->bitmap == IDR_FULL)
7441 __set_bit(0, &new->bitmap);
7442 p = new;
7443 @@ -493,17 +496,21 @@ void *idr_find(struct idr *idp, int id)
7444 int n;
7445 struct idr_layer *p;
7446
7447 - n = idp->layers * IDR_BITS;
7448 p = rcu_dereference(idp->top);
7449 + if (!p)
7450 + return NULL;
7451 + n = (p->layer+1) * IDR_BITS;
7452
7453 /* Mask off upper bits we don't use for the search. */
7454 id &= MAX_ID_MASK;
7455
7456 if (id >= (1 << n))
7457 return NULL;
7458 + BUG_ON(n == 0);
7459
7460 while (n > 0 && p) {
7461 n -= IDR_BITS;
7462 + BUG_ON(n != p->layer*IDR_BITS);
7463 p = rcu_dereference(p->ary[(id >> n) & IDR_MASK]);
7464 }
7465 return((void *)p);
7466 @@ -582,8 +589,11 @@ void *idr_replace(struct idr *idp, void *ptr, int id)
7467 int n;
7468 struct idr_layer *p, *old_p;
7469
7470 - n = idp->layers * IDR_BITS;
7471 p = idp->top;
7472 + if (!p)
7473 + return ERR_PTR(-EINVAL);
7474 +
7475 + n = (p->layer+1) * IDR_BITS;
7476
7477 id &= MAX_ID_MASK;
7478
7479 diff --git a/lib/scatterlist.c b/lib/scatterlist.c
7480 index 8d2688f..b7b449d 100644
7481 --- a/lib/scatterlist.c
7482 +++ b/lib/scatterlist.c
7483 @@ -395,7 +395,7 @@ void sg_miter_stop(struct sg_mapping_iter *miter)
7484 WARN_ON(!irqs_disabled());
7485 kunmap_atomic(miter->addr, KM_BIO_SRC_IRQ);
7486 } else
7487 - kunmap(miter->addr);
7488 + kunmap(miter->page);
7489
7490 miter->page = NULL;
7491 miter->addr = NULL;
7492 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
7493 index 8bde9bf..b0785ef 100644
7494 --- a/net/unix/af_unix.c
7495 +++ b/net/unix/af_unix.c
7496 @@ -1341,6 +1341,7 @@ static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock,
7497
7498 if (NULL == siocb->scm)
7499 siocb->scm = &tmp_scm;
7500 + wait_for_unix_gc();
7501 err = scm_send(sock, msg, siocb->scm);
7502 if (err < 0)
7503 return err;
7504 @@ -1491,6 +1492,7 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
7505
7506 if (NULL == siocb->scm)
7507 siocb->scm = &tmp_scm;
7508 + wait_for_unix_gc();
7509 err = scm_send(sock, msg, siocb->scm);
7510 if (err < 0)
7511 return err;
7512 diff --git a/net/unix/garbage.c b/net/unix/garbage.c
7513 index 6d4a9a8..abb3ab3 100644
7514 --- a/net/unix/garbage.c
7515 +++ b/net/unix/garbage.c
7516 @@ -80,6 +80,7 @@
7517 #include <linux/file.h>
7518 #include <linux/proc_fs.h>
7519 #include <linux/mutex.h>
7520 +#include <linux/wait.h>
7521
7522 #include <net/sock.h>
7523 #include <net/af_unix.h>
7524 @@ -91,6 +92,7 @@
7525 static LIST_HEAD(gc_inflight_list);
7526 static LIST_HEAD(gc_candidates);
7527 static DEFINE_SPINLOCK(unix_gc_lock);
7528 +static DECLARE_WAIT_QUEUE_HEAD(unix_gc_wait);
7529
7530 unsigned int unix_tot_inflight;
7531
7532 @@ -266,12 +268,16 @@ static void inc_inflight_move_tail(struct unix_sock *u)
7533 list_move_tail(&u->link, &gc_candidates);
7534 }
7535
7536 -/* The external entry point: unix_gc() */
7537 +static bool gc_in_progress = false;
7538
7539 -void unix_gc(void)
7540 +void wait_for_unix_gc(void)
7541 {
7542 - static bool gc_in_progress = false;
7543 + wait_event(unix_gc_wait, gc_in_progress == false);
7544 +}
7545
7546 +/* The external entry point: unix_gc() */
7547 +void unix_gc(void)
7548 +{
7549 struct unix_sock *u;
7550 struct unix_sock *next;
7551 struct sk_buff_head hitlist;
7552 @@ -376,6 +382,7 @@ void unix_gc(void)
7553 /* All candidates should have been detached by now. */
7554 BUG_ON(!list_empty(&gc_candidates));
7555 gc_in_progress = false;
7556 + wake_up(&unix_gc_wait);
7557
7558 out:
7559 spin_unlock(&unix_gc_lock);