diff options
Diffstat (limited to 'fs')
64 files changed, 1298 insertions, 974 deletions
diff --git a/fs/afs/file.c b/fs/afs/file.c index 7a1d942ef68d..0149dab365e7 100644 --- a/fs/afs/file.c +++ b/fs/afs/file.c | |||
@@ -102,6 +102,7 @@ int afs_release(struct inode *inode, struct file *file) | |||
102 | return 0; | 102 | return 0; |
103 | } | 103 | } |
104 | 104 | ||
105 | #ifdef CONFIG_AFS_FSCACHE | ||
105 | /* | 106 | /* |
106 | * deal with notification that a page was read from the cache | 107 | * deal with notification that a page was read from the cache |
107 | */ | 108 | */ |
@@ -117,6 +118,7 @@ static void afs_file_readpage_read_complete(struct page *page, | |||
117 | SetPageUptodate(page); | 118 | SetPageUptodate(page); |
118 | unlock_page(page); | 119 | unlock_page(page); |
119 | } | 120 | } |
121 | #endif | ||
120 | 122 | ||
121 | /* | 123 | /* |
122 | * AFS read page from file, directory or symlink | 124 | * AFS read page from file, directory or symlink |
diff --git a/fs/afs/netdevices.c b/fs/afs/netdevices.c index 49f189423063..7ad36506c256 100644 --- a/fs/afs/netdevices.c +++ b/fs/afs/netdevices.c | |||
@@ -20,8 +20,7 @@ int afs_get_MAC_address(u8 *mac, size_t maclen) | |||
20 | struct net_device *dev; | 20 | struct net_device *dev; |
21 | int ret = -ENODEV; | 21 | int ret = -ENODEV; |
22 | 22 | ||
23 | if (maclen != ETH_ALEN) | 23 | BUG_ON(maclen != ETH_ALEN); |
24 | BUG(); | ||
25 | 24 | ||
26 | rtnl_lock(); | 25 | rtnl_lock(); |
27 | dev = __dev_getfirstbyhwtype(&init_net, ARPHRD_ETHER); | 26 | dev = __dev_getfirstbyhwtype(&init_net, ARPHRD_ETHER); |
diff --git a/fs/befs/super.c b/fs/befs/super.c index 41f2b4d0093e..ca40f828f64d 100644 --- a/fs/befs/super.c +++ b/fs/befs/super.c | |||
@@ -8,6 +8,7 @@ | |||
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <linux/fs.h> | 10 | #include <linux/fs.h> |
11 | #include <asm/page.h> /* for PAGE_SIZE */ | ||
11 | 12 | ||
12 | #include "befs.h" | 13 | #include "befs.h" |
13 | #include "super.h" | 14 | #include "super.h" |
@@ -348,6 +348,24 @@ err: | |||
348 | return NULL; | 348 | return NULL; |
349 | } | 349 | } |
350 | 350 | ||
351 | /** | ||
352 | * bio_alloc - allocate a bio for I/O | ||
353 | * @gfp_mask: the GFP_ mask given to the slab allocator | ||
354 | * @nr_iovecs: number of iovecs to pre-allocate | ||
355 | * | ||
356 | * Description: | ||
357 | * bio_alloc will allocate a bio and associated bio_vec array that can hold | ||
358 | * at least @nr_iovecs entries. Allocations will be done from the | ||
359 | * fs_bio_set. Also see @bio_alloc_bioset. | ||
360 | * | ||
361 | * If %__GFP_WAIT is set, then bio_alloc will always be able to allocate | ||
362 | * a bio. This is due to the mempool guarantees. To make this work, callers | ||
363 | * must never allocate more than 1 bio at the time from this pool. Callers | ||
364 | * that need to allocate more than 1 bio must always submit the previously | ||
365 | * allocate bio for IO before attempting to allocate a new one. Failure to | ||
366 | * do so can cause livelocks under memory pressure. | ||
367 | * | ||
368 | **/ | ||
351 | struct bio *bio_alloc(gfp_t gfp_mask, int nr_iovecs) | 369 | struct bio *bio_alloc(gfp_t gfp_mask, int nr_iovecs) |
352 | { | 370 | { |
353 | struct bio *bio = bio_alloc_bioset(gfp_mask, nr_iovecs, fs_bio_set); | 371 | struct bio *bio = bio_alloc_bioset(gfp_mask, nr_iovecs, fs_bio_set); |
diff --git a/fs/buffer.c b/fs/buffer.c index 6e35762b6169..b3e5be7514f5 100644 --- a/fs/buffer.c +++ b/fs/buffer.c | |||
@@ -360,7 +360,7 @@ still_busy: | |||
360 | * Completion handler for block_write_full_page() - pages which are unlocked | 360 | * Completion handler for block_write_full_page() - pages which are unlocked |
361 | * during I/O, and which have PageWriteback cleared upon I/O completion. | 361 | * during I/O, and which have PageWriteback cleared upon I/O completion. |
362 | */ | 362 | */ |
363 | static void end_buffer_async_write(struct buffer_head *bh, int uptodate) | 363 | void end_buffer_async_write(struct buffer_head *bh, int uptodate) |
364 | { | 364 | { |
365 | char b[BDEVNAME_SIZE]; | 365 | char b[BDEVNAME_SIZE]; |
366 | unsigned long flags; | 366 | unsigned long flags; |
@@ -438,11 +438,17 @@ static void mark_buffer_async_read(struct buffer_head *bh) | |||
438 | set_buffer_async_read(bh); | 438 | set_buffer_async_read(bh); |
439 | } | 439 | } |
440 | 440 | ||
441 | void mark_buffer_async_write(struct buffer_head *bh) | 441 | void mark_buffer_async_write_endio(struct buffer_head *bh, |
442 | bh_end_io_t *handler) | ||
442 | { | 443 | { |
443 | bh->b_end_io = end_buffer_async_write; | 444 | bh->b_end_io = handler; |
444 | set_buffer_async_write(bh); | 445 | set_buffer_async_write(bh); |
445 | } | 446 | } |
447 | |||
448 | void mark_buffer_async_write(struct buffer_head *bh) | ||
449 | { | ||
450 | mark_buffer_async_write_endio(bh, end_buffer_async_write); | ||
451 | } | ||
446 | EXPORT_SYMBOL(mark_buffer_async_write); | 452 | EXPORT_SYMBOL(mark_buffer_async_write); |
447 | 453 | ||
448 | 454 | ||
@@ -547,7 +553,7 @@ repeat: | |||
547 | return err; | 553 | return err; |
548 | } | 554 | } |
549 | 555 | ||
550 | void do_thaw_all(unsigned long unused) | 556 | void do_thaw_all(struct work_struct *work) |
551 | { | 557 | { |
552 | struct super_block *sb; | 558 | struct super_block *sb; |
553 | char b[BDEVNAME_SIZE]; | 559 | char b[BDEVNAME_SIZE]; |
@@ -567,6 +573,7 @@ restart: | |||
567 | goto restart; | 573 | goto restart; |
568 | } | 574 | } |
569 | spin_unlock(&sb_lock); | 575 | spin_unlock(&sb_lock); |
576 | kfree(work); | ||
570 | printk(KERN_WARNING "Emergency Thaw complete\n"); | 577 | printk(KERN_WARNING "Emergency Thaw complete\n"); |
571 | } | 578 | } |
572 | 579 | ||
@@ -577,7 +584,13 @@ restart: | |||
577 | */ | 584 | */ |
578 | void emergency_thaw_all(void) | 585 | void emergency_thaw_all(void) |
579 | { | 586 | { |
580 | pdflush_operation(do_thaw_all, 0); | 587 | struct work_struct *work; |
588 | |||
589 | work = kmalloc(sizeof(*work), GFP_ATOMIC); | ||
590 | if (work) { | ||
591 | INIT_WORK(work, do_thaw_all); | ||
592 | schedule_work(work); | ||
593 | } | ||
581 | } | 594 | } |
582 | 595 | ||
583 | /** | 596 | /** |
@@ -1596,9 +1609,20 @@ EXPORT_SYMBOL(unmap_underlying_metadata); | |||
1596 | * locked buffer. This only can happen if someone has written the buffer | 1609 | * locked buffer. This only can happen if someone has written the buffer |
1597 | * directly, with submit_bh(). At the address_space level PageWriteback | 1610 | * directly, with submit_bh(). At the address_space level PageWriteback |
1598 | * prevents this contention from occurring. | 1611 | * prevents this contention from occurring. |
1612 | * | ||
1613 | * If block_write_full_page() is called with wbc->sync_mode == | ||
1614 | * WB_SYNC_ALL, the writes are posted using WRITE_SYNC_PLUG; this | ||
1615 | * causes the writes to be flagged as synchronous writes, but the | ||
1616 | * block device queue will NOT be unplugged, since usually many pages | ||
1617 | * will be pushed to the out before the higher-level caller actually | ||
1618 | * waits for the writes to be completed. The various wait functions, | ||
1619 | * such as wait_on_writeback_range() will ultimately call sync_page() | ||
1620 | * which will ultimately call blk_run_backing_dev(), which will end up | ||
1621 | * unplugging the device queue. | ||
1599 | */ | 1622 | */ |
1600 | static int __block_write_full_page(struct inode *inode, struct page *page, | 1623 | static int __block_write_full_page(struct inode *inode, struct page *page, |
1601 | get_block_t *get_block, struct writeback_control *wbc) | 1624 | get_block_t *get_block, struct writeback_control *wbc, |
1625 | bh_end_io_t *handler) | ||
1602 | { | 1626 | { |
1603 | int err; | 1627 | int err; |
1604 | sector_t block; | 1628 | sector_t block; |
@@ -1606,7 +1630,8 @@ static int __block_write_full_page(struct inode *inode, struct page *page, | |||
1606 | struct buffer_head *bh, *head; | 1630 | struct buffer_head *bh, *head; |
1607 | const unsigned blocksize = 1 << inode->i_blkbits; | 1631 | const unsigned blocksize = 1 << inode->i_blkbits; |
1608 | int nr_underway = 0; | 1632 | int nr_underway = 0; |
1609 | int write_op = (wbc->sync_mode == WB_SYNC_ALL ? WRITE_SYNC : WRITE); | 1633 | int write_op = (wbc->sync_mode == WB_SYNC_ALL ? |
1634 | WRITE_SYNC_PLUG : WRITE); | ||
1610 | 1635 | ||
1611 | BUG_ON(!PageLocked(page)); | 1636 | BUG_ON(!PageLocked(page)); |
1612 | 1637 | ||
@@ -1682,7 +1707,7 @@ static int __block_write_full_page(struct inode *inode, struct page *page, | |||
1682 | continue; | 1707 | continue; |
1683 | } | 1708 | } |
1684 | if (test_clear_buffer_dirty(bh)) { | 1709 | if (test_clear_buffer_dirty(bh)) { |
1685 | mark_buffer_async_write(bh); | 1710 | mark_buffer_async_write_endio(bh, handler); |
1686 | } else { | 1711 | } else { |
1687 | unlock_buffer(bh); | 1712 | unlock_buffer(bh); |
1688 | } | 1713 | } |
@@ -1735,7 +1760,7 @@ recover: | |||
1735 | if (buffer_mapped(bh) && buffer_dirty(bh) && | 1760 | if (buffer_mapped(bh) && buffer_dirty(bh) && |
1736 | !buffer_delay(bh)) { | 1761 | !buffer_delay(bh)) { |
1737 | lock_buffer(bh); | 1762 | lock_buffer(bh); |
1738 | mark_buffer_async_write(bh); | 1763 | mark_buffer_async_write_endio(bh, handler); |
1739 | } else { | 1764 | } else { |
1740 | /* | 1765 | /* |
1741 | * The buffer may have been set dirty during | 1766 | * The buffer may have been set dirty during |
@@ -2661,7 +2686,8 @@ int nobh_writepage(struct page *page, get_block_t *get_block, | |||
2661 | out: | 2686 | out: |
2662 | ret = mpage_writepage(page, get_block, wbc); | 2687 | ret = mpage_writepage(page, get_block, wbc); |
2663 | if (ret == -EAGAIN) | 2688 | if (ret == -EAGAIN) |
2664 | ret = __block_write_full_page(inode, page, get_block, wbc); | 2689 | ret = __block_write_full_page(inode, page, get_block, wbc, |
2690 | end_buffer_async_write); | ||
2665 | return ret; | 2691 | return ret; |
2666 | } | 2692 | } |
2667 | EXPORT_SYMBOL(nobh_writepage); | 2693 | EXPORT_SYMBOL(nobh_writepage); |
@@ -2819,9 +2845,10 @@ out: | |||
2819 | 2845 | ||
2820 | /* | 2846 | /* |
2821 | * The generic ->writepage function for buffer-backed address_spaces | 2847 | * The generic ->writepage function for buffer-backed address_spaces |
2848 | * this form passes in the end_io handler used to finish the IO. | ||
2822 | */ | 2849 | */ |
2823 | int block_write_full_page(struct page *page, get_block_t *get_block, | 2850 | int block_write_full_page_endio(struct page *page, get_block_t *get_block, |
2824 | struct writeback_control *wbc) | 2851 | struct writeback_control *wbc, bh_end_io_t *handler) |
2825 | { | 2852 | { |
2826 | struct inode * const inode = page->mapping->host; | 2853 | struct inode * const inode = page->mapping->host; |
2827 | loff_t i_size = i_size_read(inode); | 2854 | loff_t i_size = i_size_read(inode); |
@@ -2830,7 +2857,8 @@ int block_write_full_page(struct page *page, get_block_t *get_block, | |||
2830 | 2857 | ||
2831 | /* Is the page fully inside i_size? */ | 2858 | /* Is the page fully inside i_size? */ |
2832 | if (page->index < end_index) | 2859 | if (page->index < end_index) |
2833 | return __block_write_full_page(inode, page, get_block, wbc); | 2860 | return __block_write_full_page(inode, page, get_block, wbc, |
2861 | handler); | ||
2834 | 2862 | ||
2835 | /* Is the page fully outside i_size? (truncate in progress) */ | 2863 | /* Is the page fully outside i_size? (truncate in progress) */ |
2836 | offset = i_size & (PAGE_CACHE_SIZE-1); | 2864 | offset = i_size & (PAGE_CACHE_SIZE-1); |
@@ -2853,9 +2881,20 @@ int block_write_full_page(struct page *page, get_block_t *get_block, | |||
2853 | * writes to that region are not written out to the file." | 2881 | * writes to that region are not written out to the file." |
2854 | */ | 2882 | */ |
2855 | zero_user_segment(page, offset, PAGE_CACHE_SIZE); | 2883 | zero_user_segment(page, offset, PAGE_CACHE_SIZE); |
2856 | return __block_write_full_page(inode, page, get_block, wbc); | 2884 | return __block_write_full_page(inode, page, get_block, wbc, handler); |
2885 | } | ||
2886 | |||
2887 | /* | ||
2888 | * The generic ->writepage function for buffer-backed address_spaces | ||
2889 | */ | ||
2890 | int block_write_full_page(struct page *page, get_block_t *get_block, | ||
2891 | struct writeback_control *wbc) | ||
2892 | { | ||
2893 | return block_write_full_page_endio(page, get_block, wbc, | ||
2894 | end_buffer_async_write); | ||
2857 | } | 2895 | } |
2858 | 2896 | ||
2897 | |||
2859 | sector_t generic_block_bmap(struct address_space *mapping, sector_t block, | 2898 | sector_t generic_block_bmap(struct address_space *mapping, sector_t block, |
2860 | get_block_t *get_block) | 2899 | get_block_t *get_block) |
2861 | { | 2900 | { |
@@ -3324,9 +3363,11 @@ EXPORT_SYMBOL(block_read_full_page); | |||
3324 | EXPORT_SYMBOL(block_sync_page); | 3363 | EXPORT_SYMBOL(block_sync_page); |
3325 | EXPORT_SYMBOL(block_truncate_page); | 3364 | EXPORT_SYMBOL(block_truncate_page); |
3326 | EXPORT_SYMBOL(block_write_full_page); | 3365 | EXPORT_SYMBOL(block_write_full_page); |
3366 | EXPORT_SYMBOL(block_write_full_page_endio); | ||
3327 | EXPORT_SYMBOL(cont_write_begin); | 3367 | EXPORT_SYMBOL(cont_write_begin); |
3328 | EXPORT_SYMBOL(end_buffer_read_sync); | 3368 | EXPORT_SYMBOL(end_buffer_read_sync); |
3329 | EXPORT_SYMBOL(end_buffer_write_sync); | 3369 | EXPORT_SYMBOL(end_buffer_write_sync); |
3370 | EXPORT_SYMBOL(end_buffer_async_write); | ||
3330 | EXPORT_SYMBOL(file_fsync); | 3371 | EXPORT_SYMBOL(file_fsync); |
3331 | EXPORT_SYMBOL(generic_block_bmap); | 3372 | EXPORT_SYMBOL(generic_block_bmap); |
3332 | EXPORT_SYMBOL(generic_cont_expand_simple); | 3373 | EXPORT_SYMBOL(generic_cont_expand_simple); |
diff --git a/fs/cifs/CHANGES b/fs/cifs/CHANGES index 65984006192c..9d1fb6ec8a5a 100644 --- a/fs/cifs/CHANGES +++ b/fs/cifs/CHANGES | |||
@@ -15,7 +15,8 @@ Posix file open support added (turned off after one attempt if server | |||
15 | fails to support it properly, as with Samba server versions prior to 3.3.2) | 15 | fails to support it properly, as with Samba server versions prior to 3.3.2) |
16 | Fix "redzone overwritten" bug in cifs_put_tcon (CIFSTcon may allocate too | 16 | Fix "redzone overwritten" bug in cifs_put_tcon (CIFSTcon may allocate too |
17 | little memory for the "nativeFileSystem" field returned by the server | 17 | little memory for the "nativeFileSystem" field returned by the server |
18 | during mount). | 18 | during mount). Endian convert inode numbers if necessary (makes it easier |
19 | to compare inode numbers on network files from big endian systems). | ||
19 | 20 | ||
20 | Version 1.56 | 21 | Version 1.56 |
21 | ------------ | 22 | ------------ |
diff --git a/fs/cifs/cifs_spnego.c b/fs/cifs/cifs_spnego.c index 3fd3a9df043a..67bf93a40d2e 100644 --- a/fs/cifs/cifs_spnego.c +++ b/fs/cifs/cifs_spnego.c | |||
@@ -41,7 +41,7 @@ cifs_spnego_key_instantiate(struct key *key, const void *data, size_t datalen) | |||
41 | 41 | ||
42 | /* attach the data */ | 42 | /* attach the data */ |
43 | memcpy(payload, data, datalen); | 43 | memcpy(payload, data, datalen); |
44 | rcu_assign_pointer(key->payload.data, payload); | 44 | key->payload.data = payload; |
45 | ret = 0; | 45 | ret = 0; |
46 | 46 | ||
47 | error: | 47 | error: |
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index 38491fd3871d..0d6d8b573652 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c | |||
@@ -66,9 +66,6 @@ unsigned int sign_CIFS_PDUs = 1; | |||
66 | extern struct task_struct *oplockThread; /* remove sparse warning */ | 66 | extern struct task_struct *oplockThread; /* remove sparse warning */ |
67 | struct task_struct *oplockThread = NULL; | 67 | struct task_struct *oplockThread = NULL; |
68 | /* extern struct task_struct * dnotifyThread; remove sparse warning */ | 68 | /* extern struct task_struct * dnotifyThread; remove sparse warning */ |
69 | #ifdef CONFIG_CIFS_EXPERIMENTAL | ||
70 | static struct task_struct *dnotifyThread = NULL; | ||
71 | #endif | ||
72 | static const struct super_operations cifs_super_ops; | 69 | static const struct super_operations cifs_super_ops; |
73 | unsigned int CIFSMaxBufSize = CIFS_MAX_MSGSIZE; | 70 | unsigned int CIFSMaxBufSize = CIFS_MAX_MSGSIZE; |
74 | module_param(CIFSMaxBufSize, int, 0); | 71 | module_param(CIFSMaxBufSize, int, 0); |
@@ -316,6 +313,7 @@ cifs_alloc_inode(struct super_block *sb) | |||
316 | cifs_inode->clientCanCacheAll = false; | 313 | cifs_inode->clientCanCacheAll = false; |
317 | cifs_inode->delete_pending = false; | 314 | cifs_inode->delete_pending = false; |
318 | cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */ | 315 | cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */ |
316 | cifs_inode->server_eof = 0; | ||
319 | 317 | ||
320 | /* Can not set i_flags here - they get immediately overwritten | 318 | /* Can not set i_flags here - they get immediately overwritten |
321 | to zero by the VFS */ | 319 | to zero by the VFS */ |
@@ -1040,34 +1038,6 @@ static int cifs_oplock_thread(void *dummyarg) | |||
1040 | return 0; | 1038 | return 0; |
1041 | } | 1039 | } |
1042 | 1040 | ||
1043 | #ifdef CONFIG_CIFS_EXPERIMENTAL | ||
1044 | static int cifs_dnotify_thread(void *dummyarg) | ||
1045 | { | ||
1046 | struct list_head *tmp; | ||
1047 | struct TCP_Server_Info *server; | ||
1048 | |||
1049 | do { | ||
1050 | if (try_to_freeze()) | ||
1051 | continue; | ||
1052 | set_current_state(TASK_INTERRUPTIBLE); | ||
1053 | schedule_timeout(15*HZ); | ||
1054 | /* check if any stuck requests that need | ||
1055 | to be woken up and wakeq so the | ||
1056 | thread can wake up and error out */ | ||
1057 | read_lock(&cifs_tcp_ses_lock); | ||
1058 | list_for_each(tmp, &cifs_tcp_ses_list) { | ||
1059 | server = list_entry(tmp, struct TCP_Server_Info, | ||
1060 | tcp_ses_list); | ||
1061 | if (atomic_read(&server->inFlight)) | ||
1062 | wake_up_all(&server->response_q); | ||
1063 | } | ||
1064 | read_unlock(&cifs_tcp_ses_lock); | ||
1065 | } while (!kthread_should_stop()); | ||
1066 | |||
1067 | return 0; | ||
1068 | } | ||
1069 | #endif | ||
1070 | |||
1071 | static int __init | 1041 | static int __init |
1072 | init_cifs(void) | 1042 | init_cifs(void) |
1073 | { | 1043 | { |
@@ -1144,21 +1114,8 @@ init_cifs(void) | |||
1144 | goto out_unregister_dfs_key_type; | 1114 | goto out_unregister_dfs_key_type; |
1145 | } | 1115 | } |
1146 | 1116 | ||
1147 | #ifdef CONFIG_CIFS_EXPERIMENTAL | ||
1148 | dnotifyThread = kthread_run(cifs_dnotify_thread, NULL, "cifsdnotifyd"); | ||
1149 | if (IS_ERR(dnotifyThread)) { | ||
1150 | rc = PTR_ERR(dnotifyThread); | ||
1151 | cERROR(1, ("error %d create dnotify thread", rc)); | ||
1152 | goto out_stop_oplock_thread; | ||
1153 | } | ||
1154 | #endif | ||
1155 | |||
1156 | return 0; | 1117 | return 0; |
1157 | 1118 | ||
1158 | #ifdef CONFIG_CIFS_EXPERIMENTAL | ||
1159 | out_stop_oplock_thread: | ||
1160 | #endif | ||
1161 | kthread_stop(oplockThread); | ||
1162 | out_unregister_dfs_key_type: | 1119 | out_unregister_dfs_key_type: |
1163 | #ifdef CONFIG_CIFS_DFS_UPCALL | 1120 | #ifdef CONFIG_CIFS_DFS_UPCALL |
1164 | unregister_key_type(&key_type_dns_resolver); | 1121 | unregister_key_type(&key_type_dns_resolver); |
@@ -1196,9 +1153,6 @@ exit_cifs(void) | |||
1196 | cifs_destroy_inodecache(); | 1153 | cifs_destroy_inodecache(); |
1197 | cifs_destroy_mids(); | 1154 | cifs_destroy_mids(); |
1198 | cifs_destroy_request_bufs(); | 1155 | cifs_destroy_request_bufs(); |
1199 | #ifdef CONFIG_CIFS_EXPERIMENTAL | ||
1200 | kthread_stop(dnotifyThread); | ||
1201 | #endif | ||
1202 | kthread_stop(oplockThread); | 1156 | kthread_stop(oplockThread); |
1203 | } | 1157 | } |
1204 | 1158 | ||
diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index 9fbf4dff5da6..df40ab64cd95 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h | |||
@@ -350,7 +350,7 @@ struct cifsFileInfo { | |||
350 | bool invalidHandle:1; /* file closed via session abend */ | 350 | bool invalidHandle:1; /* file closed via session abend */ |
351 | bool messageMode:1; /* for pipes: message vs byte mode */ | 351 | bool messageMode:1; /* for pipes: message vs byte mode */ |
352 | atomic_t wrtPending; /* handle in use - defer close */ | 352 | atomic_t wrtPending; /* handle in use - defer close */ |
353 | struct semaphore fh_sem; /* prevents reopen race after dead ses*/ | 353 | struct mutex fh_mutex; /* prevents reopen race after dead ses*/ |
354 | struct cifs_search_info srch_inf; | 354 | struct cifs_search_info srch_inf; |
355 | }; | 355 | }; |
356 | 356 | ||
@@ -370,6 +370,7 @@ struct cifsInodeInfo { | |||
370 | bool clientCanCacheAll:1; /* read and writebehind oplock */ | 370 | bool clientCanCacheAll:1; /* read and writebehind oplock */ |
371 | bool oplockPending:1; | 371 | bool oplockPending:1; |
372 | bool delete_pending:1; /* DELETE_ON_CLOSE is set */ | 372 | bool delete_pending:1; /* DELETE_ON_CLOSE is set */ |
373 | u64 server_eof; /* current file size on server */ | ||
373 | struct inode vfs_inode; | 374 | struct inode vfs_inode; |
374 | }; | 375 | }; |
375 | 376 | ||
diff --git a/fs/cifs/cifspdu.h b/fs/cifs/cifspdu.h index b370489c8da5..a785f69dbc9f 100644 --- a/fs/cifs/cifspdu.h +++ b/fs/cifs/cifspdu.h | |||
@@ -2163,7 +2163,7 @@ typedef struct { | |||
2163 | __le32 Type; | 2163 | __le32 Type; |
2164 | __le64 DevMajor; | 2164 | __le64 DevMajor; |
2165 | __le64 DevMinor; | 2165 | __le64 DevMinor; |
2166 | __u64 UniqueId; | 2166 | __le64 UniqueId; |
2167 | __le64 Permissions; | 2167 | __le64 Permissions; |
2168 | __le64 Nlinks; | 2168 | __le64 Nlinks; |
2169 | } __attribute__((packed)) FILE_UNIX_BASIC_INFO; /* level 0x200 QPathInfo */ | 2169 | } __attribute__((packed)) FILE_UNIX_BASIC_INFO; /* level 0x200 QPathInfo */ |
@@ -2308,7 +2308,7 @@ struct unlink_psx_rq { /* level 0x20a SetPathInfo */ | |||
2308 | } __attribute__((packed)); | 2308 | } __attribute__((packed)); |
2309 | 2309 | ||
2310 | struct file_internal_info { | 2310 | struct file_internal_info { |
2311 | __u64 UniqueId; /* inode number */ | 2311 | __le64 UniqueId; /* inode number */ |
2312 | } __attribute__((packed)); /* level 0x3ee */ | 2312 | } __attribute__((packed)); /* level 0x3ee */ |
2313 | 2313 | ||
2314 | struct file_mode_info { | 2314 | struct file_mode_info { |
@@ -2338,7 +2338,7 @@ typedef struct { | |||
2338 | __le32 Type; | 2338 | __le32 Type; |
2339 | __le64 DevMajor; | 2339 | __le64 DevMajor; |
2340 | __le64 DevMinor; | 2340 | __le64 DevMinor; |
2341 | __u64 UniqueId; | 2341 | __le64 UniqueId; |
2342 | __le64 Permissions; | 2342 | __le64 Permissions; |
2343 | __le64 Nlinks; | 2343 | __le64 Nlinks; |
2344 | char FileName[1]; | 2344 | char FileName[1]; |
@@ -2386,7 +2386,7 @@ typedef struct { | |||
2386 | __le32 FileNameLength; | 2386 | __le32 FileNameLength; |
2387 | __le32 EaSize; /* EA size */ | 2387 | __le32 EaSize; /* EA size */ |
2388 | __le32 Reserved; | 2388 | __le32 Reserved; |
2389 | __u64 UniqueId; /* inode num - le since Samba puts ino in low 32 bit*/ | 2389 | __le64 UniqueId; /* inode num - le since Samba puts ino in low 32 bit*/ |
2390 | char FileName[1]; | 2390 | char FileName[1]; |
2391 | } __attribute__((packed)) SEARCH_ID_FULL_DIR_INFO; /* level 0x105 FF rsp data */ | 2391 | } __attribute__((packed)) SEARCH_ID_FULL_DIR_INFO; /* level 0x105 FF rsp data */ |
2392 | 2392 | ||
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index bc09c998631f..a0845dc7b8a9 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c | |||
@@ -1626,6 +1626,8 @@ CIFSSMBWrite2(const int xid, struct cifsTconInfo *tcon, | |||
1626 | int smb_hdr_len; | 1626 | int smb_hdr_len; |
1627 | int resp_buf_type = 0; | 1627 | int resp_buf_type = 0; |
1628 | 1628 | ||
1629 | *nbytes = 0; | ||
1630 | |||
1629 | cFYI(1, ("write2 at %lld %d bytes", (long long)offset, count)); | 1631 | cFYI(1, ("write2 at %lld %d bytes", (long long)offset, count)); |
1630 | 1632 | ||
1631 | if (tcon->ses->capabilities & CAP_LARGE_FILES) { | 1633 | if (tcon->ses->capabilities & CAP_LARGE_FILES) { |
@@ -1682,11 +1684,9 @@ CIFSSMBWrite2(const int xid, struct cifsTconInfo *tcon, | |||
1682 | cifs_stats_inc(&tcon->num_writes); | 1684 | cifs_stats_inc(&tcon->num_writes); |
1683 | if (rc) { | 1685 | if (rc) { |
1684 | cFYI(1, ("Send error Write2 = %d", rc)); | 1686 | cFYI(1, ("Send error Write2 = %d", rc)); |
1685 | *nbytes = 0; | ||
1686 | } else if (resp_buf_type == 0) { | 1687 | } else if (resp_buf_type == 0) { |
1687 | /* presumably this can not happen, but best to be safe */ | 1688 | /* presumably this can not happen, but best to be safe */ |
1688 | rc = -EIO; | 1689 | rc = -EIO; |
1689 | *nbytes = 0; | ||
1690 | } else { | 1690 | } else { |
1691 | WRITE_RSP *pSMBr = (WRITE_RSP *)iov[0].iov_base; | 1691 | WRITE_RSP *pSMBr = (WRITE_RSP *)iov[0].iov_base; |
1692 | *nbytes = le16_to_cpu(pSMBr->CountHigh); | 1692 | *nbytes = le16_to_cpu(pSMBr->CountHigh); |
@@ -3918,7 +3918,7 @@ GetInodeNumberRetry: | |||
3918 | } | 3918 | } |
3919 | pfinfo = (struct file_internal_info *) | 3919 | pfinfo = (struct file_internal_info *) |
3920 | (data_offset + (char *) &pSMBr->hdr.Protocol); | 3920 | (data_offset + (char *) &pSMBr->hdr.Protocol); |
3921 | *inode_number = pfinfo->UniqueId; | 3921 | *inode_number = le64_to_cpu(pfinfo->UniqueId); |
3922 | } | 3922 | } |
3923 | } | 3923 | } |
3924 | GetInodeNumOut: | 3924 | GetInodeNumOut: |
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 0de3b5615a22..bacdef1546b7 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c | |||
@@ -2214,9 +2214,58 @@ is_path_accessible(int xid, struct cifsTconInfo *tcon, | |||
2214 | return rc; | 2214 | return rc; |
2215 | } | 2215 | } |
2216 | 2216 | ||
2217 | static void | ||
2218 | cleanup_volume_info(struct smb_vol **pvolume_info) | ||
2219 | { | ||
2220 | struct smb_vol *volume_info; | ||
2221 | |||
2222 | if (!pvolume_info && !*pvolume_info) | ||
2223 | return; | ||
2224 | |||
2225 | volume_info = *pvolume_info; | ||
2226 | kzfree(volume_info->password); | ||
2227 | kfree(volume_info->UNC); | ||
2228 | kfree(volume_info->prepath); | ||
2229 | kfree(volume_info); | ||
2230 | *pvolume_info = NULL; | ||
2231 | return; | ||
2232 | } | ||
2233 | |||
2234 | #ifdef CONFIG_CIFS_DFS_UPCALL | ||
2235 | /* build_path_to_root returns full path to root when | ||
2236 | * we do not have an exiting connection (tcon) */ | ||
2237 | static char * | ||
2238 | build_unc_path_to_root(const struct smb_vol *volume_info, | ||
2239 | const struct cifs_sb_info *cifs_sb) | ||
2240 | { | ||
2241 | char *full_path; | ||
2242 | |||
2243 | int unc_len = strnlen(volume_info->UNC, MAX_TREE_SIZE + 1); | ||
2244 | full_path = kmalloc(unc_len + cifs_sb->prepathlen + 1, GFP_KERNEL); | ||
2245 | if (full_path == NULL) | ||
2246 | return ERR_PTR(-ENOMEM); | ||
2247 | |||
2248 | strncpy(full_path, volume_info->UNC, unc_len); | ||
2249 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS) { | ||
2250 | int i; | ||
2251 | for (i = 0; i < unc_len; i++) { | ||
2252 | if (full_path[i] == '\\') | ||
2253 | full_path[i] = '/'; | ||
2254 | } | ||
2255 | } | ||
2256 | |||
2257 | if (cifs_sb->prepathlen) | ||
2258 | strncpy(full_path + unc_len, cifs_sb->prepath, | ||
2259 | cifs_sb->prepathlen); | ||
2260 | |||
2261 | full_path[unc_len + cifs_sb->prepathlen] = 0; /* add trailing null */ | ||
2262 | return full_path; | ||
2263 | } | ||
2264 | #endif | ||
2265 | |||
2217 | int | 2266 | int |
2218 | cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb, | 2267 | cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb, |
2219 | char *mount_data, const char *devname) | 2268 | char *mount_data_global, const char *devname) |
2220 | { | 2269 | { |
2221 | int rc = 0; | 2270 | int rc = 0; |
2222 | int xid; | 2271 | int xid; |
@@ -2225,6 +2274,13 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb, | |||
2225 | struct cifsTconInfo *tcon = NULL; | 2274 | struct cifsTconInfo *tcon = NULL; |
2226 | struct TCP_Server_Info *srvTcp = NULL; | 2275 | struct TCP_Server_Info *srvTcp = NULL; |
2227 | char *full_path; | 2276 | char *full_path; |
2277 | char *mount_data = mount_data_global; | ||
2278 | #ifdef CONFIG_CIFS_DFS_UPCALL | ||
2279 | struct dfs_info3_param *referrals = NULL; | ||
2280 | unsigned int num_referrals = 0; | ||
2281 | try_mount_again: | ||
2282 | #endif | ||
2283 | full_path = NULL; | ||
2228 | 2284 | ||
2229 | xid = GetXid(); | 2285 | xid = GetXid(); |
2230 | 2286 | ||
@@ -2371,11 +2427,9 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb, | |||
2371 | } | 2427 | } |
2372 | } | 2428 | } |
2373 | 2429 | ||
2374 | /* check for null share name ie connect to dfs root */ | ||
2375 | if ((strchr(volume_info->UNC + 3, '\\') == NULL) | 2430 | if ((strchr(volume_info->UNC + 3, '\\') == NULL) |
2376 | && (strchr(volume_info->UNC + 3, '/') == NULL)) { | 2431 | && (strchr(volume_info->UNC + 3, '/') == NULL)) { |
2377 | /* rc = connect_to_dfs_path(...) */ | 2432 | cERROR(1, ("Missing share name")); |
2378 | cFYI(1, ("DFS root not supported")); | ||
2379 | rc = -ENODEV; | 2433 | rc = -ENODEV; |
2380 | goto mount_fail_check; | 2434 | goto mount_fail_check; |
2381 | } else { | 2435 | } else { |
@@ -2392,7 +2446,7 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb, | |||
2392 | } | 2446 | } |
2393 | } | 2447 | } |
2394 | if (rc) | 2448 | if (rc) |
2395 | goto mount_fail_check; | 2449 | goto remote_path_check; |
2396 | tcon->seal = volume_info->seal; | 2450 | tcon->seal = volume_info->seal; |
2397 | write_lock(&cifs_tcp_ses_lock); | 2451 | write_lock(&cifs_tcp_ses_lock); |
2398 | list_add(&tcon->tcon_list, &pSesInfo->tcon_list); | 2452 | list_add(&tcon->tcon_list, &pSesInfo->tcon_list); |
@@ -2417,19 +2471,9 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb, | |||
2417 | /* BB FIXME fix time_gran to be larger for LANMAN sessions */ | 2471 | /* BB FIXME fix time_gran to be larger for LANMAN sessions */ |
2418 | sb->s_time_gran = 100; | 2472 | sb->s_time_gran = 100; |
2419 | 2473 | ||
2420 | mount_fail_check: | 2474 | if (rc) |
2421 | /* on error free sesinfo and tcon struct if needed */ | 2475 | goto remote_path_check; |
2422 | if (rc) { | 2476 | |
2423 | /* If find_unc succeeded then rc == 0 so we can not end */ | ||
2424 | /* up accidently freeing someone elses tcon struct */ | ||
2425 | if (tcon) | ||
2426 | cifs_put_tcon(tcon); | ||
2427 | else if (pSesInfo) | ||
2428 | cifs_put_smb_ses(pSesInfo); | ||
2429 | else | ||
2430 | cifs_put_tcp_session(srvTcp); | ||
2431 | goto out; | ||
2432 | } | ||
2433 | cifs_sb->tcon = tcon; | 2477 | cifs_sb->tcon = tcon; |
2434 | 2478 | ||
2435 | /* do not care if following two calls succeed - informational */ | 2479 | /* do not care if following two calls succeed - informational */ |
@@ -2461,7 +2505,9 @@ mount_fail_check: | |||
2461 | cifs_sb->rsize = min(cifs_sb->rsize, | 2505 | cifs_sb->rsize = min(cifs_sb->rsize, |
2462 | (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE)); | 2506 | (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE)); |
2463 | 2507 | ||
2464 | if (!rc && cifs_sb->prepathlen) { | 2508 | remote_path_check: |
2509 | /* check if a whole path (including prepath) is not remote */ | ||
2510 | if (!rc && cifs_sb->prepathlen && tcon) { | ||
2465 | /* build_path_to_root works only when we have a valid tcon */ | 2511 | /* build_path_to_root works only when we have a valid tcon */ |
2466 | full_path = cifs_build_path_to_root(cifs_sb); | 2512 | full_path = cifs_build_path_to_root(cifs_sb); |
2467 | if (full_path == NULL) { | 2513 | if (full_path == NULL) { |
@@ -2469,31 +2515,79 @@ mount_fail_check: | |||
2469 | goto mount_fail_check; | 2515 | goto mount_fail_check; |
2470 | } | 2516 | } |
2471 | rc = is_path_accessible(xid, tcon, cifs_sb, full_path); | 2517 | rc = is_path_accessible(xid, tcon, cifs_sb, full_path); |
2472 | if (rc) { | 2518 | if (rc != -EREMOTE) { |
2473 | cERROR(1, ("Path %s in not accessible: %d", | ||
2474 | full_path, rc)); | ||
2475 | kfree(full_path); | 2519 | kfree(full_path); |
2476 | goto mount_fail_check; | 2520 | goto mount_fail_check; |
2477 | } | 2521 | } |
2478 | kfree(full_path); | 2522 | kfree(full_path); |
2479 | } | 2523 | } |
2480 | 2524 | ||
2525 | /* get referral if needed */ | ||
2526 | if (rc == -EREMOTE) { | ||
2527 | #ifdef CONFIG_CIFS_DFS_UPCALL | ||
2528 | /* convert forward to back slashes in prepath here if needed */ | ||
2529 | if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS) == 0) | ||
2530 | convert_delimiter(cifs_sb->prepath, | ||
2531 | CIFS_DIR_SEP(cifs_sb)); | ||
2532 | full_path = build_unc_path_to_root(volume_info, cifs_sb); | ||
2533 | if (IS_ERR(full_path)) { | ||
2534 | rc = PTR_ERR(full_path); | ||
2535 | goto mount_fail_check; | ||
2536 | } | ||
2537 | |||
2538 | cFYI(1, ("Getting referral for: %s", full_path)); | ||
2539 | rc = get_dfs_path(xid, pSesInfo , full_path + 1, | ||
2540 | cifs_sb->local_nls, &num_referrals, &referrals, | ||
2541 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); | ||
2542 | if (!rc && num_referrals > 0) { | ||
2543 | char *fake_devname = NULL; | ||
2544 | |||
2545 | if (mount_data != mount_data_global) | ||
2546 | kfree(mount_data); | ||
2547 | mount_data = cifs_compose_mount_options( | ||
2548 | cifs_sb->mountdata, full_path + 1, | ||
2549 | referrals, &fake_devname); | ||
2550 | kfree(fake_devname); | ||
2551 | free_dfs_info_array(referrals, num_referrals); | ||
2552 | |||
2553 | if (tcon) | ||
2554 | cifs_put_tcon(tcon); | ||
2555 | else if (pSesInfo) | ||
2556 | cifs_put_smb_ses(pSesInfo); | ||
2557 | |||
2558 | cleanup_volume_info(&volume_info); | ||
2559 | FreeXid(xid); | ||
2560 | kfree(full_path); | ||
2561 | goto try_mount_again; | ||
2562 | } | ||
2563 | #else /* No DFS support, return error on mount */ | ||
2564 | rc = -EOPNOTSUPP; | ||
2565 | #endif | ||
2566 | } | ||
2567 | |||
2568 | mount_fail_check: | ||
2569 | /* on error free sesinfo and tcon struct if needed */ | ||
2570 | if (rc) { | ||
2571 | if (mount_data != mount_data_global) | ||
2572 | kfree(mount_data); | ||
2573 | /* If find_unc succeeded then rc == 0 so we can not end */ | ||
2574 | /* up accidently freeing someone elses tcon struct */ | ||
2575 | if (tcon) | ||
2576 | cifs_put_tcon(tcon); | ||
2577 | else if (pSesInfo) | ||
2578 | cifs_put_smb_ses(pSesInfo); | ||
2579 | else | ||
2580 | cifs_put_tcp_session(srvTcp); | ||
2581 | goto out; | ||
2582 | } | ||
2583 | |||
2481 | /* volume_info->password is freed above when existing session found | 2584 | /* volume_info->password is freed above when existing session found |
2482 | (in which case it is not needed anymore) but when new sesion is created | 2585 | (in which case it is not needed anymore) but when new sesion is created |
2483 | the password ptr is put in the new session structure (in which case the | 2586 | the password ptr is put in the new session structure (in which case the |
2484 | password will be freed at unmount time) */ | 2587 | password will be freed at unmount time) */ |
2485 | out: | 2588 | out: |
2486 | /* zero out password before freeing */ | 2589 | /* zero out password before freeing */ |
2487 | if (volume_info) { | 2590 | cleanup_volume_info(&volume_info); |
2488 | if (volume_info->password != NULL) { | ||
2489 | memset(volume_info->password, 0, | ||
2490 | strlen(volume_info->password)); | ||
2491 | kfree(volume_info->password); | ||
2492 | } | ||
2493 | kfree(volume_info->UNC); | ||
2494 | kfree(volume_info->prepath); | ||
2495 | kfree(volume_info); | ||
2496 | } | ||
2497 | FreeXid(xid); | 2591 | FreeXid(xid); |
2498 | return rc; | 2592 | return rc; |
2499 | } | 2593 | } |
@@ -2673,8 +2767,7 @@ CIFSSessSetup(unsigned int xid, struct cifsSesInfo *ses, | |||
2673 | /* We look for obvious messed up bcc or strings in response so we do not go off | 2767 | /* We look for obvious messed up bcc or strings in response so we do not go off |
2674 | the end since (at least) WIN2K and Windows XP have a major bug in not null | 2768 | the end since (at least) WIN2K and Windows XP have a major bug in not null |
2675 | terminating last Unicode string in response */ | 2769 | terminating last Unicode string in response */ |
2676 | if (ses->serverOS) | 2770 | kfree(ses->serverOS); |
2677 | kfree(ses->serverOS); | ||
2678 | ses->serverOS = kzalloc(2 * (len + 1), | 2771 | ses->serverOS = kzalloc(2 * (len + 1), |
2679 | GFP_KERNEL); | 2772 | GFP_KERNEL); |
2680 | if (ses->serverOS == NULL) | 2773 | if (ses->serverOS == NULL) |
@@ -2710,8 +2803,7 @@ CIFSSessSetup(unsigned int xid, struct cifsSesInfo *ses, | |||
2710 | len = UniStrnlen((wchar_t *) bcc_ptr, remaining_words); | 2803 | len = UniStrnlen((wchar_t *) bcc_ptr, remaining_words); |
2711 | /* last string is not always null terminated | 2804 | /* last string is not always null terminated |
2712 | (for e.g. for Windows XP & 2000) */ | 2805 | (for e.g. for Windows XP & 2000) */ |
2713 | if (ses->serverDomain) | 2806 | kfree(ses->serverDomain); |
2714 | kfree(ses->serverDomain); | ||
2715 | ses->serverDomain = | 2807 | ses->serverDomain = |
2716 | kzalloc(2*(len+1), | 2808 | kzalloc(2*(len+1), |
2717 | GFP_KERNEL); | 2809 | GFP_KERNEL); |
@@ -2725,8 +2817,7 @@ CIFSSessSetup(unsigned int xid, struct cifsSesInfo *ses, | |||
2725 | ses->serverDomain[1+(2*len)] = 0; | 2817 | ses->serverDomain[1+(2*len)] = 0; |
2726 | } else { /* else no more room so create | 2818 | } else { /* else no more room so create |
2727 | dummy domain string */ | 2819 | dummy domain string */ |
2728 | if (ses->serverDomain) | 2820 | kfree(ses->serverDomain); |
2729 | kfree(ses->serverDomain); | ||
2730 | ses->serverDomain = | 2821 | ses->serverDomain = |
2731 | kzalloc(2, GFP_KERNEL); | 2822 | kzalloc(2, GFP_KERNEL); |
2732 | } | 2823 | } |
@@ -2772,8 +2863,7 @@ CIFSSessSetup(unsigned int xid, struct cifsSesInfo *ses, | |||
2772 | bcc_ptr++; | 2863 | bcc_ptr++; |
2773 | 2864 | ||
2774 | len = strnlen(bcc_ptr, 1024); | 2865 | len = strnlen(bcc_ptr, 1024); |
2775 | if (ses->serverDomain) | 2866 | kfree(ses->serverDomain); |
2776 | kfree(ses->serverDomain); | ||
2777 | ses->serverDomain = kzalloc(len + 1, | 2867 | ses->serverDomain = kzalloc(len + 1, |
2778 | GFP_KERNEL); | 2868 | GFP_KERNEL); |
2779 | if (ses->serverDomain == NULL) | 2869 | if (ses->serverDomain == NULL) |
@@ -3013,8 +3103,7 @@ CIFSNTLMSSPNegotiateSessSetup(unsigned int xid, | |||
3013 | /* We look for obvious messed up bcc or strings in response so we do not go off | 3103 | /* We look for obvious messed up bcc or strings in response so we do not go off |
3014 | the end since (at least) WIN2K and Windows XP have a major bug in not null | 3104 | the end since (at least) WIN2K and Windows XP have a major bug in not null |
3015 | terminating last Unicode string in response */ | 3105 | terminating last Unicode string in response */ |
3016 | if (ses->serverOS) | 3106 | kfree(ses->serverOS); |
3017 | kfree(ses->serverOS); | ||
3018 | ses->serverOS = | 3107 | ses->serverOS = |
3019 | kzalloc(2 * (len + 1), GFP_KERNEL); | 3108 | kzalloc(2 * (len + 1), GFP_KERNEL); |
3020 | cifs_strfromUCS_le(ses->serverOS, | 3109 | cifs_strfromUCS_le(ses->serverOS, |
@@ -3086,8 +3175,7 @@ CIFSNTLMSSPNegotiateSessSetup(unsigned int xid, | |||
3086 | if (((long) bcc_ptr + len) - (long) | 3175 | if (((long) bcc_ptr + len) - (long) |
3087 | pByteArea(smb_buffer_response) | 3176 | pByteArea(smb_buffer_response) |
3088 | <= BCC(smb_buffer_response)) { | 3177 | <= BCC(smb_buffer_response)) { |
3089 | if (ses->serverOS) | 3178 | kfree(ses->serverOS); |
3090 | kfree(ses->serverOS); | ||
3091 | ses->serverOS = | 3179 | ses->serverOS = |
3092 | kzalloc(len + 1, | 3180 | kzalloc(len + 1, |
3093 | GFP_KERNEL); | 3181 | GFP_KERNEL); |
@@ -3414,8 +3502,7 @@ CIFSNTLMSSPAuthSessSetup(unsigned int xid, struct cifsSesInfo *ses, | |||
3414 | /* We look for obvious messed up bcc or strings in response so we do not go off | 3502 | /* We look for obvious messed up bcc or strings in response so we do not go off |
3415 | the end since (at least) WIN2K and Windows XP have a major bug in not null | 3503 | the end since (at least) WIN2K and Windows XP have a major bug in not null |
3416 | terminating last Unicode string in response */ | 3504 | terminating last Unicode string in response */ |
3417 | if (ses->serverOS) | 3505 | kfree(ses->serverOS); |
3418 | kfree(ses->serverOS); | ||
3419 | ses->serverOS = | 3506 | ses->serverOS = |
3420 | kzalloc(2 * (len + 1), GFP_KERNEL); | 3507 | kzalloc(2 * (len + 1), GFP_KERNEL); |
3421 | cifs_strfromUCS_le(ses->serverOS, | 3508 | cifs_strfromUCS_le(ses->serverOS, |
@@ -3448,8 +3535,7 @@ CIFSNTLMSSPAuthSessSetup(unsigned int xid, struct cifsSesInfo *ses, | |||
3448 | if (remaining_words > 0) { | 3535 | if (remaining_words > 0) { |
3449 | len = UniStrnlen((wchar_t *) bcc_ptr, remaining_words); | 3536 | len = UniStrnlen((wchar_t *) bcc_ptr, remaining_words); |
3450 | /* last string not always null terminated (e.g. for Windows XP & 2000) */ | 3537 | /* last string not always null terminated (e.g. for Windows XP & 2000) */ |
3451 | if (ses->serverDomain) | 3538 | kfree(ses->serverDomain); |
3452 | kfree(ses->serverDomain); | ||
3453 | ses->serverDomain = | 3539 | ses->serverDomain = |
3454 | kzalloc(2 * | 3540 | kzalloc(2 * |
3455 | (len + | 3541 | (len + |
@@ -3476,13 +3562,11 @@ CIFSNTLMSSPAuthSessSetup(unsigned int xid, struct cifsSesInfo *ses, | |||
3476 | = 0; | 3562 | = 0; |
3477 | } /* else no more room so create dummy domain string */ | 3563 | } /* else no more room so create dummy domain string */ |
3478 | else { | 3564 | else { |
3479 | if (ses->serverDomain) | 3565 | kfree(ses->serverDomain); |
3480 | kfree(ses->serverDomain); | ||
3481 | ses->serverDomain = kzalloc(2,GFP_KERNEL); | 3566 | ses->serverDomain = kzalloc(2,GFP_KERNEL); |
3482 | } | 3567 | } |
3483 | } else { /* no room so create dummy domain and NOS string */ | 3568 | } else { /* no room so create dummy domain and NOS string */ |
3484 | if (ses->serverDomain) | 3569 | kfree(ses->serverDomain); |
3485 | kfree(ses->serverDomain); | ||
3486 | ses->serverDomain = kzalloc(2, GFP_KERNEL); | 3570 | ses->serverDomain = kzalloc(2, GFP_KERNEL); |
3487 | kfree(ses->serverNOS); | 3571 | kfree(ses->serverNOS); |
3488 | ses->serverNOS = kzalloc(2, GFP_KERNEL); | 3572 | ses->serverNOS = kzalloc(2, GFP_KERNEL); |
@@ -3492,8 +3576,7 @@ CIFSNTLMSSPAuthSessSetup(unsigned int xid, struct cifsSesInfo *ses, | |||
3492 | if (((long) bcc_ptr + len) - | 3576 | if (((long) bcc_ptr + len) - |
3493 | (long) pByteArea(smb_buffer_response) | 3577 | (long) pByteArea(smb_buffer_response) |
3494 | <= BCC(smb_buffer_response)) { | 3578 | <= BCC(smb_buffer_response)) { |
3495 | if (ses->serverOS) | 3579 | kfree(ses->serverOS); |
3496 | kfree(ses->serverOS); | ||
3497 | ses->serverOS = kzalloc(len + 1, GFP_KERNEL); | 3580 | ses->serverOS = kzalloc(len + 1, GFP_KERNEL); |
3498 | strncpy(ses->serverOS,bcc_ptr, len); | 3581 | strncpy(ses->serverOS,bcc_ptr, len); |
3499 | 3582 | ||
@@ -3512,8 +3595,7 @@ CIFSNTLMSSPAuthSessSetup(unsigned int xid, struct cifsSesInfo *ses, | |||
3512 | bcc_ptr++; | 3595 | bcc_ptr++; |
3513 | 3596 | ||
3514 | len = strnlen(bcc_ptr, 1024); | 3597 | len = strnlen(bcc_ptr, 1024); |
3515 | if (ses->serverDomain) | 3598 | kfree(ses->serverDomain); |
3516 | kfree(ses->serverDomain); | ||
3517 | ses->serverDomain = | 3599 | ses->serverDomain = |
3518 | kzalloc(len+1, | 3600 | kzalloc(len+1, |
3519 | GFP_KERNEL); | 3601 | GFP_KERNEL); |
@@ -3674,16 +3756,15 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses, | |||
3674 | BCC(smb_buffer_response)) { | 3756 | BCC(smb_buffer_response)) { |
3675 | kfree(tcon->nativeFileSystem); | 3757 | kfree(tcon->nativeFileSystem); |
3676 | tcon->nativeFileSystem = | 3758 | tcon->nativeFileSystem = |
3677 | kzalloc(2*(length + 1), GFP_KERNEL); | 3759 | kzalloc((4 * length) + 2, GFP_KERNEL); |
3678 | if (tcon->nativeFileSystem) | 3760 | if (tcon->nativeFileSystem) { |
3679 | cifs_strfromUCS_le( | 3761 | cifs_strfromUCS_le( |
3680 | tcon->nativeFileSystem, | 3762 | tcon->nativeFileSystem, |
3681 | (__le16 *) bcc_ptr, | 3763 | (__le16 *) bcc_ptr, |
3682 | length, nls_codepage); | 3764 | length, nls_codepage); |
3683 | bcc_ptr += 2 * length; | 3765 | cFYI(1, ("nativeFileSystem=%s", |
3684 | bcc_ptr[0] = 0; /* null terminate the string */ | 3766 | tcon->nativeFileSystem)); |
3685 | bcc_ptr[1] = 0; | 3767 | } |
3686 | bcc_ptr += 2; | ||
3687 | } | 3768 | } |
3688 | /* else do not bother copying these information fields*/ | 3769 | /* else do not bother copying these information fields*/ |
3689 | } else { | 3770 | } else { |
diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c index 54dce78fbb73..461750e01364 100644 --- a/fs/cifs/dir.c +++ b/fs/cifs/dir.c | |||
@@ -129,12 +129,62 @@ cifs_bp_rename_retry: | |||
129 | return full_path; | 129 | return full_path; |
130 | } | 130 | } |
131 | 131 | ||
132 | static void | ||
133 | cifs_fill_fileinfo(struct inode *newinode, __u16 fileHandle, | ||
134 | struct cifsTconInfo *tcon, bool write_only) | ||
135 | { | ||
136 | int oplock = 0; | ||
137 | struct cifsFileInfo *pCifsFile; | ||
138 | struct cifsInodeInfo *pCifsInode; | ||
139 | |||
140 | pCifsFile = kzalloc(sizeof(struct cifsFileInfo), GFP_KERNEL); | ||
141 | |||
142 | if (pCifsFile == NULL) | ||
143 | return; | ||
144 | |||
145 | if (oplockEnabled) | ||
146 | oplock = REQ_OPLOCK; | ||
147 | |||
148 | pCifsFile->netfid = fileHandle; | ||
149 | pCifsFile->pid = current->tgid; | ||
150 | pCifsFile->pInode = newinode; | ||
151 | pCifsFile->invalidHandle = false; | ||
152 | pCifsFile->closePend = false; | ||
153 | mutex_init(&pCifsFile->fh_mutex); | ||
154 | mutex_init(&pCifsFile->lock_mutex); | ||
155 | INIT_LIST_HEAD(&pCifsFile->llist); | ||
156 | atomic_set(&pCifsFile->wrtPending, 0); | ||
157 | |||
158 | /* set the following in open now | ||
159 | pCifsFile->pfile = file; */ | ||
160 | write_lock(&GlobalSMBSeslock); | ||
161 | list_add(&pCifsFile->tlist, &tcon->openFileList); | ||
162 | pCifsInode = CIFS_I(newinode); | ||
163 | if (pCifsInode) { | ||
164 | /* if readable file instance put first in list*/ | ||
165 | if (write_only) | ||
166 | list_add_tail(&pCifsFile->flist, | ||
167 | &pCifsInode->openFileList); | ||
168 | else | ||
169 | list_add(&pCifsFile->flist, &pCifsInode->openFileList); | ||
170 | |||
171 | if ((oplock & 0xF) == OPLOCK_EXCLUSIVE) { | ||
172 | pCifsInode->clientCanCacheAll = true; | ||
173 | pCifsInode->clientCanCacheRead = true; | ||
174 | cFYI(1, ("Exclusive Oplock inode %p", newinode)); | ||
175 | } else if ((oplock & 0xF) == OPLOCK_READ) | ||
176 | pCifsInode->clientCanCacheRead = true; | ||
177 | } | ||
178 | write_unlock(&GlobalSMBSeslock); | ||
179 | } | ||
180 | |||
132 | int cifs_posix_open(char *full_path, struct inode **pinode, | 181 | int cifs_posix_open(char *full_path, struct inode **pinode, |
133 | struct super_block *sb, int mode, int oflags, | 182 | struct super_block *sb, int mode, int oflags, |
134 | int *poplock, __u16 *pnetfid, int xid) | 183 | int *poplock, __u16 *pnetfid, int xid) |
135 | { | 184 | { |
136 | int rc; | 185 | int rc; |
137 | __u32 oplock; | 186 | __u32 oplock; |
187 | bool write_only = false; | ||
138 | FILE_UNIX_BASIC_INFO *presp_data; | 188 | FILE_UNIX_BASIC_INFO *presp_data; |
139 | __u32 posix_flags = 0; | 189 | __u32 posix_flags = 0; |
140 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); | 190 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); |
@@ -172,6 +222,8 @@ int cifs_posix_open(char *full_path, struct inode **pinode, | |||
172 | if (oflags & O_DIRECT) | 222 | if (oflags & O_DIRECT) |
173 | posix_flags |= SMB_O_DIRECT; | 223 | posix_flags |= SMB_O_DIRECT; |
174 | 224 | ||
225 | if (!(oflags & FMODE_READ)) | ||
226 | write_only = true; | ||
175 | 227 | ||
176 | rc = CIFSPOSIXCreate(xid, cifs_sb->tcon, posix_flags, mode, | 228 | rc = CIFSPOSIXCreate(xid, cifs_sb->tcon, posix_flags, mode, |
177 | pnetfid, presp_data, &oplock, full_path, | 229 | pnetfid, presp_data, &oplock, full_path, |
@@ -187,8 +239,10 @@ int cifs_posix_open(char *full_path, struct inode **pinode, | |||
187 | if (!pinode) | 239 | if (!pinode) |
188 | goto posix_open_ret; /* caller does not need info */ | 240 | goto posix_open_ret; /* caller does not need info */ |
189 | 241 | ||
190 | if (*pinode == NULL) | 242 | if (*pinode == NULL) { |
191 | *pinode = cifs_new_inode(sb, &presp_data->UniqueId); | 243 | __u64 unique_id = le64_to_cpu(presp_data->UniqueId); |
244 | *pinode = cifs_new_inode(sb, &unique_id); | ||
245 | } | ||
192 | /* else an inode was passed in. Update its info, don't create one */ | 246 | /* else an inode was passed in. Update its info, don't create one */ |
193 | 247 | ||
194 | /* We do not need to close the file if new_inode fails since | 248 | /* We do not need to close the file if new_inode fails since |
@@ -198,6 +252,8 @@ int cifs_posix_open(char *full_path, struct inode **pinode, | |||
198 | 252 | ||
199 | posix_fill_in_inode(*pinode, presp_data, 1); | 253 | posix_fill_in_inode(*pinode, presp_data, 1); |
200 | 254 | ||
255 | cifs_fill_fileinfo(*pinode, *pnetfid, cifs_sb->tcon, write_only); | ||
256 | |||
201 | posix_open_ret: | 257 | posix_open_ret: |
202 | kfree(presp_data); | 258 | kfree(presp_data); |
203 | return rc; | 259 | return rc; |
@@ -239,7 +295,6 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode, | |||
239 | char *full_path = NULL; | 295 | char *full_path = NULL; |
240 | FILE_ALL_INFO *buf = NULL; | 296 | FILE_ALL_INFO *buf = NULL; |
241 | struct inode *newinode = NULL; | 297 | struct inode *newinode = NULL; |
242 | struct cifsInodeInfo *pCifsInode; | ||
243 | int disposition = FILE_OVERWRITE_IF; | 298 | int disposition = FILE_OVERWRITE_IF; |
244 | bool write_only = false; | 299 | bool write_only = false; |
245 | 300 | ||
@@ -410,44 +465,8 @@ cifs_create_set_dentry: | |||
410 | /* mknod case - do not leave file open */ | 465 | /* mknod case - do not leave file open */ |
411 | CIFSSMBClose(xid, tcon, fileHandle); | 466 | CIFSSMBClose(xid, tcon, fileHandle); |
412 | } else if (newinode) { | 467 | } else if (newinode) { |
413 | struct cifsFileInfo *pCifsFile = | 468 | cifs_fill_fileinfo(newinode, fileHandle, |
414 | kzalloc(sizeof(struct cifsFileInfo), GFP_KERNEL); | 469 | cifs_sb->tcon, write_only); |
415 | |||
416 | if (pCifsFile == NULL) | ||
417 | goto cifs_create_out; | ||
418 | pCifsFile->netfid = fileHandle; | ||
419 | pCifsFile->pid = current->tgid; | ||
420 | pCifsFile->pInode = newinode; | ||
421 | pCifsFile->invalidHandle = false; | ||
422 | pCifsFile->closePend = false; | ||
423 | init_MUTEX(&pCifsFile->fh_sem); | ||
424 | mutex_init(&pCifsFile->lock_mutex); | ||
425 | INIT_LIST_HEAD(&pCifsFile->llist); | ||
426 | atomic_set(&pCifsFile->wrtPending, 0); | ||
427 | |||
428 | /* set the following in open now | ||
429 | pCifsFile->pfile = file; */ | ||
430 | write_lock(&GlobalSMBSeslock); | ||
431 | list_add(&pCifsFile->tlist, &tcon->openFileList); | ||
432 | pCifsInode = CIFS_I(newinode); | ||
433 | if (pCifsInode) { | ||
434 | /* if readable file instance put first in list*/ | ||
435 | if (write_only) { | ||
436 | list_add_tail(&pCifsFile->flist, | ||
437 | &pCifsInode->openFileList); | ||
438 | } else { | ||
439 | list_add(&pCifsFile->flist, | ||
440 | &pCifsInode->openFileList); | ||
441 | } | ||
442 | if ((oplock & 0xF) == OPLOCK_EXCLUSIVE) { | ||
443 | pCifsInode->clientCanCacheAll = true; | ||
444 | pCifsInode->clientCanCacheRead = true; | ||
445 | cFYI(1, ("Exclusive Oplock inode %p", | ||
446 | newinode)); | ||
447 | } else if ((oplock & 0xF) == OPLOCK_READ) | ||
448 | pCifsInode->clientCanCacheRead = true; | ||
449 | } | ||
450 | write_unlock(&GlobalSMBSeslock); | ||
451 | } | 470 | } |
452 | cifs_create_out: | 471 | cifs_create_out: |
453 | kfree(buf); | 472 | kfree(buf); |
@@ -580,17 +599,21 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, int mode, | |||
580 | return rc; | 599 | return rc; |
581 | } | 600 | } |
582 | 601 | ||
583 | |||
584 | struct dentry * | 602 | struct dentry * |
585 | cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry, | 603 | cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry, |
586 | struct nameidata *nd) | 604 | struct nameidata *nd) |
587 | { | 605 | { |
588 | int xid; | 606 | int xid; |
589 | int rc = 0; /* to get around spurious gcc warning, set to zero here */ | 607 | int rc = 0; /* to get around spurious gcc warning, set to zero here */ |
608 | int oplock = 0; | ||
609 | int mode; | ||
610 | __u16 fileHandle = 0; | ||
611 | bool posix_open = false; | ||
590 | struct cifs_sb_info *cifs_sb; | 612 | struct cifs_sb_info *cifs_sb; |
591 | struct cifsTconInfo *pTcon; | 613 | struct cifsTconInfo *pTcon; |
592 | struct inode *newInode = NULL; | 614 | struct inode *newInode = NULL; |
593 | char *full_path = NULL; | 615 | char *full_path = NULL; |
616 | struct file *filp; | ||
594 | 617 | ||
595 | xid = GetXid(); | 618 | xid = GetXid(); |
596 | 619 | ||
@@ -632,12 +655,37 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry, | |||
632 | } | 655 | } |
633 | cFYI(1, ("Full path: %s inode = 0x%p", full_path, direntry->d_inode)); | 656 | cFYI(1, ("Full path: %s inode = 0x%p", full_path, direntry->d_inode)); |
634 | 657 | ||
635 | if (pTcon->unix_ext) | 658 | if (pTcon->unix_ext) { |
636 | rc = cifs_get_inode_info_unix(&newInode, full_path, | 659 | if (!(nd->flags & (LOOKUP_PARENT | LOOKUP_DIRECTORY)) && |
637 | parent_dir_inode->i_sb, xid); | 660 | (nd->flags & LOOKUP_OPEN)) { |
638 | else | 661 | if (!((nd->intent.open.flags & O_CREAT) && |
662 | (nd->intent.open.flags & O_EXCL))) { | ||
663 | mode = nd->intent.open.create_mode & | ||
664 | ~current_umask(); | ||
665 | rc = cifs_posix_open(full_path, &newInode, | ||
666 | parent_dir_inode->i_sb, mode, | ||
667 | nd->intent.open.flags, &oplock, | ||
668 | &fileHandle, xid); | ||
669 | /* | ||
670 | * This code works around a bug in | ||
671 | * samba posix open in samba versions 3.3.1 | ||
672 | * and earlier where create works | ||
673 | * but open fails with invalid parameter. | ||
674 | * If either of these error codes are | ||
675 | * returned, follow the normal lookup. | ||
676 | * Otherwise, the error during posix open | ||
677 | * is handled. | ||
678 | */ | ||
679 | if ((rc != -EINVAL) && (rc != -EOPNOTSUPP)) | ||
680 | posix_open = true; | ||
681 | } | ||
682 | } | ||
683 | if (!posix_open) | ||
684 | rc = cifs_get_inode_info_unix(&newInode, full_path, | ||
685 | parent_dir_inode->i_sb, xid); | ||
686 | } else | ||
639 | rc = cifs_get_inode_info(&newInode, full_path, NULL, | 687 | rc = cifs_get_inode_info(&newInode, full_path, NULL, |
640 | parent_dir_inode->i_sb, xid, NULL); | 688 | parent_dir_inode->i_sb, xid, NULL); |
641 | 689 | ||
642 | if ((rc == 0) && (newInode != NULL)) { | 690 | if ((rc == 0) && (newInode != NULL)) { |
643 | if (pTcon->nocase) | 691 | if (pTcon->nocase) |
@@ -645,7 +693,8 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry, | |||
645 | else | 693 | else |
646 | direntry->d_op = &cifs_dentry_ops; | 694 | direntry->d_op = &cifs_dentry_ops; |
647 | d_add(direntry, newInode); | 695 | d_add(direntry, newInode); |
648 | 696 | if (posix_open) | |
697 | filp = lookup_instantiate_filp(nd, direntry, NULL); | ||
649 | /* since paths are not looked up by component - the parent | 698 | /* since paths are not looked up by component - the parent |
650 | directories are presumed to be good here */ | 699 | directories are presumed to be good here */ |
651 | renew_parental_timestamps(direntry); | 700 | renew_parental_timestamps(direntry); |
diff --git a/fs/cifs/dns_resolve.c b/fs/cifs/dns_resolve.c index 1e0c1bd8f2e4..df4a306f697e 100644 --- a/fs/cifs/dns_resolve.c +++ b/fs/cifs/dns_resolve.c | |||
@@ -78,7 +78,7 @@ dns_resolver_instantiate(struct key *key, const void *data, | |||
78 | } | 78 | } |
79 | 79 | ||
80 | key->type_data.x[0] = datalen; | 80 | key->type_data.x[0] = datalen; |
81 | rcu_assign_pointer(key->payload.data, ip); | 81 | key->payload.data = ip; |
82 | 82 | ||
83 | return rc; | 83 | return rc; |
84 | } | 84 | } |
diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 81747acca4c4..50ca088d8860 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c | |||
@@ -46,7 +46,7 @@ static inline struct cifsFileInfo *cifs_init_private( | |||
46 | memset(private_data, 0, sizeof(struct cifsFileInfo)); | 46 | memset(private_data, 0, sizeof(struct cifsFileInfo)); |
47 | private_data->netfid = netfid; | 47 | private_data->netfid = netfid; |
48 | private_data->pid = current->tgid; | 48 | private_data->pid = current->tgid; |
49 | init_MUTEX(&private_data->fh_sem); | 49 | mutex_init(&private_data->fh_mutex); |
50 | mutex_init(&private_data->lock_mutex); | 50 | mutex_init(&private_data->lock_mutex); |
51 | INIT_LIST_HEAD(&private_data->llist); | 51 | INIT_LIST_HEAD(&private_data->llist); |
52 | private_data->pfile = file; /* needed for writepage */ | 52 | private_data->pfile = file; /* needed for writepage */ |
@@ -284,35 +284,32 @@ int cifs_open(struct inode *inode, struct file *file) | |||
284 | cifs_sb = CIFS_SB(inode->i_sb); | 284 | cifs_sb = CIFS_SB(inode->i_sb); |
285 | tcon = cifs_sb->tcon; | 285 | tcon = cifs_sb->tcon; |
286 | 286 | ||
287 | if (file->f_flags & O_CREAT) { | 287 | /* search inode for this file and fill in file->private_data */ |
288 | /* search inode for this file and fill in file->private_data */ | 288 | pCifsInode = CIFS_I(file->f_path.dentry->d_inode); |
289 | pCifsInode = CIFS_I(file->f_path.dentry->d_inode); | 289 | read_lock(&GlobalSMBSeslock); |
290 | read_lock(&GlobalSMBSeslock); | 290 | list_for_each(tmp, &pCifsInode->openFileList) { |
291 | list_for_each(tmp, &pCifsInode->openFileList) { | 291 | pCifsFile = list_entry(tmp, struct cifsFileInfo, |
292 | pCifsFile = list_entry(tmp, struct cifsFileInfo, | 292 | flist); |
293 | flist); | 293 | if ((pCifsFile->pfile == NULL) && |
294 | if ((pCifsFile->pfile == NULL) && | 294 | (pCifsFile->pid == current->tgid)) { |
295 | (pCifsFile->pid == current->tgid)) { | 295 | /* mode set in cifs_create */ |
296 | /* mode set in cifs_create */ | 296 | |
297 | 297 | /* needed for writepage */ | |
298 | /* needed for writepage */ | 298 | pCifsFile->pfile = file; |
299 | pCifsFile->pfile = file; | 299 | |
300 | 300 | file->private_data = pCifsFile; | |
301 | file->private_data = pCifsFile; | 301 | break; |
302 | break; | ||
303 | } | ||
304 | } | ||
305 | read_unlock(&GlobalSMBSeslock); | ||
306 | if (file->private_data != NULL) { | ||
307 | rc = 0; | ||
308 | FreeXid(xid); | ||
309 | return rc; | ||
310 | } else { | ||
311 | if (file->f_flags & O_EXCL) | ||
312 | cERROR(1, ("could not find file instance for " | ||
313 | "new file %p", file)); | ||
314 | } | 302 | } |
315 | } | 303 | } |
304 | read_unlock(&GlobalSMBSeslock); | ||
305 | |||
306 | if (file->private_data != NULL) { | ||
307 | rc = 0; | ||
308 | FreeXid(xid); | ||
309 | return rc; | ||
310 | } else if ((file->f_flags & O_CREAT) && (file->f_flags & O_EXCL)) | ||
311 | cERROR(1, ("could not find file instance for " | ||
312 | "new file %p", file)); | ||
316 | 313 | ||
317 | full_path = build_path_from_dentry(file->f_path.dentry); | 314 | full_path = build_path_from_dentry(file->f_path.dentry); |
318 | if (full_path == NULL) { | 315 | if (full_path == NULL) { |
@@ -500,9 +497,9 @@ static int cifs_reopen_file(struct file *file, bool can_flush) | |||
500 | return -EBADF; | 497 | return -EBADF; |
501 | 498 | ||
502 | xid = GetXid(); | 499 | xid = GetXid(); |
503 | down(&pCifsFile->fh_sem); | 500 | mutex_unlock(&pCifsFile->fh_mutex); |
504 | if (!pCifsFile->invalidHandle) { | 501 | if (!pCifsFile->invalidHandle) { |
505 | up(&pCifsFile->fh_sem); | 502 | mutex_lock(&pCifsFile->fh_mutex); |
506 | FreeXid(xid); | 503 | FreeXid(xid); |
507 | return 0; | 504 | return 0; |
508 | } | 505 | } |
@@ -533,7 +530,7 @@ static int cifs_reopen_file(struct file *file, bool can_flush) | |||
533 | if (full_path == NULL) { | 530 | if (full_path == NULL) { |
534 | rc = -ENOMEM; | 531 | rc = -ENOMEM; |
535 | reopen_error_exit: | 532 | reopen_error_exit: |
536 | up(&pCifsFile->fh_sem); | 533 | mutex_lock(&pCifsFile->fh_mutex); |
537 | FreeXid(xid); | 534 | FreeXid(xid); |
538 | return rc; | 535 | return rc; |
539 | } | 536 | } |
@@ -575,14 +572,14 @@ reopen_error_exit: | |||
575 | cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & | 572 | cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & |
576 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 573 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
577 | if (rc) { | 574 | if (rc) { |
578 | up(&pCifsFile->fh_sem); | 575 | mutex_lock(&pCifsFile->fh_mutex); |
579 | cFYI(1, ("cifs_open returned 0x%x", rc)); | 576 | cFYI(1, ("cifs_open returned 0x%x", rc)); |
580 | cFYI(1, ("oplock: %d", oplock)); | 577 | cFYI(1, ("oplock: %d", oplock)); |
581 | } else { | 578 | } else { |
582 | reopen_success: | 579 | reopen_success: |
583 | pCifsFile->netfid = netfid; | 580 | pCifsFile->netfid = netfid; |
584 | pCifsFile->invalidHandle = false; | 581 | pCifsFile->invalidHandle = false; |
585 | up(&pCifsFile->fh_sem); | 582 | mutex_lock(&pCifsFile->fh_mutex); |
586 | pCifsInode = CIFS_I(inode); | 583 | pCifsInode = CIFS_I(inode); |
587 | if (pCifsInode) { | 584 | if (pCifsInode) { |
588 | if (can_flush) { | 585 | if (can_flush) { |
@@ -971,6 +968,40 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *pfLock) | |||
971 | return rc; | 968 | return rc; |
972 | } | 969 | } |
973 | 970 | ||
971 | /* | ||
972 | * Set the timeout on write requests past EOF. For some servers (Windows) | ||
973 | * these calls can be very long. | ||
974 | * | ||
975 | * If we're writing >10M past the EOF we give a 180s timeout. Anything less | ||
976 | * than that gets a 45s timeout. Writes not past EOF get 15s timeouts. | ||
977 | * The 10M cutoff is totally arbitrary. A better scheme for this would be | ||
978 | * welcome if someone wants to suggest one. | ||
979 | * | ||
980 | * We may be able to do a better job with this if there were some way to | ||
981 | * declare that a file should be sparse. | ||
982 | */ | ||
983 | static int | ||
984 | cifs_write_timeout(struct cifsInodeInfo *cifsi, loff_t offset) | ||
985 | { | ||
986 | if (offset <= cifsi->server_eof) | ||
987 | return CIFS_STD_OP; | ||
988 | else if (offset > (cifsi->server_eof + (10 * 1024 * 1024))) | ||
989 | return CIFS_VLONG_OP; | ||
990 | else | ||
991 | return CIFS_LONG_OP; | ||
992 | } | ||
993 | |||
994 | /* update the file size (if needed) after a write */ | ||
995 | static void | ||
996 | cifs_update_eof(struct cifsInodeInfo *cifsi, loff_t offset, | ||
997 | unsigned int bytes_written) | ||
998 | { | ||
999 | loff_t end_of_write = offset + bytes_written; | ||
1000 | |||
1001 | if (end_of_write > cifsi->server_eof) | ||
1002 | cifsi->server_eof = end_of_write; | ||
1003 | } | ||
1004 | |||
974 | ssize_t cifs_user_write(struct file *file, const char __user *write_data, | 1005 | ssize_t cifs_user_write(struct file *file, const char __user *write_data, |
975 | size_t write_size, loff_t *poffset) | 1006 | size_t write_size, loff_t *poffset) |
976 | { | 1007 | { |
@@ -981,6 +1012,7 @@ ssize_t cifs_user_write(struct file *file, const char __user *write_data, | |||
981 | struct cifsTconInfo *pTcon; | 1012 | struct cifsTconInfo *pTcon; |
982 | int xid, long_op; | 1013 | int xid, long_op; |
983 | struct cifsFileInfo *open_file; | 1014 | struct cifsFileInfo *open_file; |
1015 | struct cifsInodeInfo *cifsi = CIFS_I(file->f_path.dentry->d_inode); | ||
984 | 1016 | ||
985 | cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); | 1017 | cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); |
986 | 1018 | ||
@@ -1000,11 +1032,7 @@ ssize_t cifs_user_write(struct file *file, const char __user *write_data, | |||
1000 | 1032 | ||
1001 | xid = GetXid(); | 1033 | xid = GetXid(); |
1002 | 1034 | ||
1003 | if (*poffset > file->f_path.dentry->d_inode->i_size) | 1035 | long_op = cifs_write_timeout(cifsi, *poffset); |
1004 | long_op = CIFS_VLONG_OP; /* writes past EOF take long time */ | ||
1005 | else | ||
1006 | long_op = CIFS_LONG_OP; | ||
1007 | |||
1008 | for (total_written = 0; write_size > total_written; | 1036 | for (total_written = 0; write_size > total_written; |
1009 | total_written += bytes_written) { | 1037 | total_written += bytes_written) { |
1010 | rc = -EAGAIN; | 1038 | rc = -EAGAIN; |
@@ -1048,8 +1076,10 @@ ssize_t cifs_user_write(struct file *file, const char __user *write_data, | |||
1048 | FreeXid(xid); | 1076 | FreeXid(xid); |
1049 | return rc; | 1077 | return rc; |
1050 | } | 1078 | } |
1051 | } else | 1079 | } else { |
1080 | cifs_update_eof(cifsi, *poffset, bytes_written); | ||
1052 | *poffset += bytes_written; | 1081 | *poffset += bytes_written; |
1082 | } | ||
1053 | long_op = CIFS_STD_OP; /* subsequent writes fast - | 1083 | long_op = CIFS_STD_OP; /* subsequent writes fast - |
1054 | 15 seconds is plenty */ | 1084 | 15 seconds is plenty */ |
1055 | } | 1085 | } |
@@ -1085,6 +1115,7 @@ static ssize_t cifs_write(struct file *file, const char *write_data, | |||
1085 | struct cifsTconInfo *pTcon; | 1115 | struct cifsTconInfo *pTcon; |
1086 | int xid, long_op; | 1116 | int xid, long_op; |
1087 | struct cifsFileInfo *open_file; | 1117 | struct cifsFileInfo *open_file; |
1118 | struct cifsInodeInfo *cifsi = CIFS_I(file->f_path.dentry->d_inode); | ||
1088 | 1119 | ||
1089 | cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); | 1120 | cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); |
1090 | 1121 | ||
@@ -1099,11 +1130,7 @@ static ssize_t cifs_write(struct file *file, const char *write_data, | |||
1099 | 1130 | ||
1100 | xid = GetXid(); | 1131 | xid = GetXid(); |
1101 | 1132 | ||
1102 | if (*poffset > file->f_path.dentry->d_inode->i_size) | 1133 | long_op = cifs_write_timeout(cifsi, *poffset); |
1103 | long_op = CIFS_VLONG_OP; /* writes past EOF can be slow */ | ||
1104 | else | ||
1105 | long_op = CIFS_LONG_OP; | ||
1106 | |||
1107 | for (total_written = 0; write_size > total_written; | 1134 | for (total_written = 0; write_size > total_written; |
1108 | total_written += bytes_written) { | 1135 | total_written += bytes_written) { |
1109 | rc = -EAGAIN; | 1136 | rc = -EAGAIN; |
@@ -1166,8 +1193,10 @@ static ssize_t cifs_write(struct file *file, const char *write_data, | |||
1166 | FreeXid(xid); | 1193 | FreeXid(xid); |
1167 | return rc; | 1194 | return rc; |
1168 | } | 1195 | } |
1169 | } else | 1196 | } else { |
1197 | cifs_update_eof(cifsi, *poffset, bytes_written); | ||
1170 | *poffset += bytes_written; | 1198 | *poffset += bytes_written; |
1199 | } | ||
1171 | long_op = CIFS_STD_OP; /* subsequent writes fast - | 1200 | long_op = CIFS_STD_OP; /* subsequent writes fast - |
1172 | 15 seconds is plenty */ | 1201 | 15 seconds is plenty */ |
1173 | } | 1202 | } |
@@ -1380,11 +1409,12 @@ static int cifs_writepages(struct address_space *mapping, | |||
1380 | int nr_pages; | 1409 | int nr_pages; |
1381 | __u64 offset = 0; | 1410 | __u64 offset = 0; |
1382 | struct cifsFileInfo *open_file; | 1411 | struct cifsFileInfo *open_file; |
1412 | struct cifsInodeInfo *cifsi = CIFS_I(mapping->host); | ||
1383 | struct page *page; | 1413 | struct page *page; |
1384 | struct pagevec pvec; | 1414 | struct pagevec pvec; |
1385 | int rc = 0; | 1415 | int rc = 0; |
1386 | int scanned = 0; | 1416 | int scanned = 0; |
1387 | int xid; | 1417 | int xid, long_op; |
1388 | 1418 | ||
1389 | cifs_sb = CIFS_SB(mapping->host->i_sb); | 1419 | cifs_sb = CIFS_SB(mapping->host->i_sb); |
1390 | 1420 | ||
@@ -1528,12 +1558,15 @@ retry: | |||
1528 | cERROR(1, ("No writable handles for inode")); | 1558 | cERROR(1, ("No writable handles for inode")); |
1529 | rc = -EBADF; | 1559 | rc = -EBADF; |
1530 | } else { | 1560 | } else { |
1561 | long_op = cifs_write_timeout(cifsi, offset); | ||
1531 | rc = CIFSSMBWrite2(xid, cifs_sb->tcon, | 1562 | rc = CIFSSMBWrite2(xid, cifs_sb->tcon, |
1532 | open_file->netfid, | 1563 | open_file->netfid, |
1533 | bytes_to_write, offset, | 1564 | bytes_to_write, offset, |
1534 | &bytes_written, iov, n_iov, | 1565 | &bytes_written, iov, n_iov, |
1535 | CIFS_LONG_OP); | 1566 | long_op); |
1536 | atomic_dec(&open_file->wrtPending); | 1567 | atomic_dec(&open_file->wrtPending); |
1568 | cifs_update_eof(cifsi, offset, bytes_written); | ||
1569 | |||
1537 | if (rc || bytes_written < bytes_to_write) { | 1570 | if (rc || bytes_written < bytes_to_write) { |
1538 | cERROR(1, ("Write2 ret %d, wrote %d", | 1571 | cERROR(1, ("Write2 ret %d, wrote %d", |
1539 | rc, bytes_written)); | 1572 | rc, bytes_written)); |
diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c index f121a80fdd6f..f36b4e40e443 100644 --- a/fs/cifs/inode.c +++ b/fs/cifs/inode.c | |||
@@ -143,6 +143,7 @@ static void cifs_unix_info_to_inode(struct inode *inode, | |||
143 | 143 | ||
144 | inode->i_nlink = le64_to_cpu(info->Nlinks); | 144 | inode->i_nlink = le64_to_cpu(info->Nlinks); |
145 | 145 | ||
146 | cifsInfo->server_eof = end_of_file; | ||
146 | spin_lock(&inode->i_lock); | 147 | spin_lock(&inode->i_lock); |
147 | if (is_size_safe_to_change(cifsInfo, end_of_file)) { | 148 | if (is_size_safe_to_change(cifsInfo, end_of_file)) { |
148 | /* | 149 | /* |
@@ -276,7 +277,8 @@ int cifs_get_inode_info_unix(struct inode **pinode, | |||
276 | 277 | ||
277 | /* get new inode */ | 278 | /* get new inode */ |
278 | if (*pinode == NULL) { | 279 | if (*pinode == NULL) { |
279 | *pinode = cifs_new_inode(sb, &find_data.UniqueId); | 280 | __u64 unique_id = le64_to_cpu(find_data.UniqueId); |
281 | *pinode = cifs_new_inode(sb, &unique_id); | ||
280 | if (*pinode == NULL) { | 282 | if (*pinode == NULL) { |
281 | rc = -ENOMEM; | 283 | rc = -ENOMEM; |
282 | goto cgiiu_exit; | 284 | goto cgiiu_exit; |
@@ -605,12 +607,12 @@ int cifs_get_inode_info(struct inode **pinode, | |||
605 | inode->i_mode |= S_IFREG; | 607 | inode->i_mode |= S_IFREG; |
606 | } | 608 | } |
607 | 609 | ||
610 | cifsInfo->server_eof = le64_to_cpu(pfindData->EndOfFile); | ||
608 | spin_lock(&inode->i_lock); | 611 | spin_lock(&inode->i_lock); |
609 | if (is_size_safe_to_change(cifsInfo, | 612 | if (is_size_safe_to_change(cifsInfo, cifsInfo->server_eof)) { |
610 | le64_to_cpu(pfindData->EndOfFile))) { | ||
611 | /* can not safely shrink the file size here if the | 613 | /* can not safely shrink the file size here if the |
612 | client is writing to it due to potential races */ | 614 | client is writing to it due to potential races */ |
613 | i_size_write(inode, le64_to_cpu(pfindData->EndOfFile)); | 615 | i_size_write(inode, cifsInfo->server_eof); |
614 | 616 | ||
615 | /* 512 bytes (2**9) is the fake blocksize that must be | 617 | /* 512 bytes (2**9) is the fake blocksize that must be |
616 | used for this calculation */ | 618 | used for this calculation */ |
@@ -1138,6 +1140,7 @@ int cifs_mkdir(struct inode *inode, struct dentry *direntry, int mode) | |||
1138 | cFYI(1, ("posix mkdir returned 0x%x", rc)); | 1140 | cFYI(1, ("posix mkdir returned 0x%x", rc)); |
1139 | d_drop(direntry); | 1141 | d_drop(direntry); |
1140 | } else { | 1142 | } else { |
1143 | __u64 unique_id; | ||
1141 | if (pInfo->Type == cpu_to_le32(-1)) { | 1144 | if (pInfo->Type == cpu_to_le32(-1)) { |
1142 | /* no return info, go query for it */ | 1145 | /* no return info, go query for it */ |
1143 | kfree(pInfo); | 1146 | kfree(pInfo); |
@@ -1151,8 +1154,8 @@ int cifs_mkdir(struct inode *inode, struct dentry *direntry, int mode) | |||
1151 | else | 1154 | else |
1152 | direntry->d_op = &cifs_dentry_ops; | 1155 | direntry->d_op = &cifs_dentry_ops; |
1153 | 1156 | ||
1154 | newinode = cifs_new_inode(inode->i_sb, | 1157 | unique_id = le64_to_cpu(pInfo->UniqueId); |
1155 | &pInfo->UniqueId); | 1158 | newinode = cifs_new_inode(inode->i_sb, &unique_id); |
1156 | if (newinode == NULL) { | 1159 | if (newinode == NULL) { |
1157 | kfree(pInfo); | 1160 | kfree(pInfo); |
1158 | goto mkdir_get_info; | 1161 | goto mkdir_get_info; |
@@ -1450,7 +1453,8 @@ int cifs_rename(struct inode *source_dir, struct dentry *source_dentry, | |||
1450 | checking the UniqueId via FILE_INTERNAL_INFO */ | 1453 | checking the UniqueId via FILE_INTERNAL_INFO */ |
1451 | 1454 | ||
1452 | unlink_target: | 1455 | unlink_target: |
1453 | if ((rc == -EACCES) || (rc == -EEXIST)) { | 1456 | /* Try unlinking the target dentry if it's not negative */ |
1457 | if (target_dentry->d_inode && (rc == -EACCES || rc == -EEXIST)) { | ||
1454 | tmprc = cifs_unlink(target_dir, target_dentry); | 1458 | tmprc = cifs_unlink(target_dir, target_dentry); |
1455 | if (tmprc) | 1459 | if (tmprc) |
1456 | goto cifs_rename_exit; | 1460 | goto cifs_rename_exit; |
@@ -1753,6 +1757,7 @@ cifs_set_file_size(struct inode *inode, struct iattr *attrs, | |||
1753 | } | 1757 | } |
1754 | 1758 | ||
1755 | if (rc == 0) { | 1759 | if (rc == 0) { |
1760 | cifsInode->server_eof = attrs->ia_size; | ||
1756 | rc = cifs_vmtruncate(inode, attrs->ia_size); | 1761 | rc = cifs_vmtruncate(inode, attrs->ia_size); |
1757 | cifs_truncate_page(inode->i_mapping, inode->i_size); | 1762 | cifs_truncate_page(inode->i_mapping, inode->i_size); |
1758 | } | 1763 | } |
@@ -1792,20 +1797,21 @@ cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs) | |||
1792 | goto out; | 1797 | goto out; |
1793 | } | 1798 | } |
1794 | 1799 | ||
1795 | if ((attrs->ia_valid & ATTR_MTIME) || (attrs->ia_valid & ATTR_SIZE)) { | 1800 | /* |
1796 | /* | 1801 | * Attempt to flush data before changing attributes. We need to do |
1797 | Flush data before changing file size or changing the last | 1802 | * this for ATTR_SIZE and ATTR_MTIME for sure, and if we change the |
1798 | write time of the file on the server. If the | 1803 | * ownership or mode then we may also need to do this. Here, we take |
1799 | flush returns error, store it to report later and continue. | 1804 | * the safe way out and just do the flush on all setattr requests. If |
1800 | BB: This should be smarter. Why bother flushing pages that | 1805 | * the flush returns error, store it to report later and continue. |
1801 | will be truncated anyway? Also, should we error out here if | 1806 | * |
1802 | the flush returns error? | 1807 | * BB: This should be smarter. Why bother flushing pages that |
1803 | */ | 1808 | * will be truncated anyway? Also, should we error out here if |
1804 | rc = filemap_write_and_wait(inode->i_mapping); | 1809 | * the flush returns error? |
1805 | if (rc != 0) { | 1810 | */ |
1806 | cifsInode->write_behind_rc = rc; | 1811 | rc = filemap_write_and_wait(inode->i_mapping); |
1807 | rc = 0; | 1812 | if (rc != 0) { |
1808 | } | 1813 | cifsInode->write_behind_rc = rc; |
1814 | rc = 0; | ||
1809 | } | 1815 | } |
1810 | 1816 | ||
1811 | if (attrs->ia_valid & ATTR_SIZE) { | 1817 | if (attrs->ia_valid & ATTR_SIZE) { |
@@ -1903,20 +1909,21 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs) | |||
1903 | return -ENOMEM; | 1909 | return -ENOMEM; |
1904 | } | 1910 | } |
1905 | 1911 | ||
1906 | if ((attrs->ia_valid & ATTR_MTIME) || (attrs->ia_valid & ATTR_SIZE)) { | 1912 | /* |
1907 | /* | 1913 | * Attempt to flush data before changing attributes. We need to do |
1908 | Flush data before changing file size or changing the last | 1914 | * this for ATTR_SIZE and ATTR_MTIME for sure, and if we change the |
1909 | write time of the file on the server. If the | 1915 | * ownership or mode then we may also need to do this. Here, we take |
1910 | flush returns error, store it to report later and continue. | 1916 | * the safe way out and just do the flush on all setattr requests. If |
1911 | BB: This should be smarter. Why bother flushing pages that | 1917 | * the flush returns error, store it to report later and continue. |
1912 | will be truncated anyway? Also, should we error out here if | 1918 | * |
1913 | the flush returns error? | 1919 | * BB: This should be smarter. Why bother flushing pages that |
1914 | */ | 1920 | * will be truncated anyway? Also, should we error out here if |
1915 | rc = filemap_write_and_wait(inode->i_mapping); | 1921 | * the flush returns error? |
1916 | if (rc != 0) { | 1922 | */ |
1917 | cifsInode->write_behind_rc = rc; | 1923 | rc = filemap_write_and_wait(inode->i_mapping); |
1918 | rc = 0; | 1924 | if (rc != 0) { |
1919 | } | 1925 | cifsInode->write_behind_rc = rc; |
1926 | rc = 0; | ||
1920 | } | 1927 | } |
1921 | 1928 | ||
1922 | if (attrs->ia_valid & ATTR_SIZE) { | 1929 | if (attrs->ia_valid & ATTR_SIZE) { |
diff --git a/fs/cifs/readdir.c b/fs/cifs/readdir.c index c2c01ff4c32c..1a8be6228333 100644 --- a/fs/cifs/readdir.c +++ b/fs/cifs/readdir.c | |||
@@ -239,6 +239,7 @@ static void fill_in_inode(struct inode *tmp_inode, int new_buf_type, | |||
239 | if (atomic_read(&cifsInfo->inUse) == 0) | 239 | if (atomic_read(&cifsInfo->inUse) == 0) |
240 | atomic_set(&cifsInfo->inUse, 1); | 240 | atomic_set(&cifsInfo->inUse, 1); |
241 | 241 | ||
242 | cifsInfo->server_eof = end_of_file; | ||
242 | spin_lock(&tmp_inode->i_lock); | 243 | spin_lock(&tmp_inode->i_lock); |
243 | if (is_size_safe_to_change(cifsInfo, end_of_file)) { | 244 | if (is_size_safe_to_change(cifsInfo, end_of_file)) { |
244 | /* can not safely change the file size here if the | 245 | /* can not safely change the file size here if the |
@@ -375,6 +376,7 @@ static void unix_fill_in_inode(struct inode *tmp_inode, | |||
375 | tmp_inode->i_gid = le64_to_cpu(pfindData->Gid); | 376 | tmp_inode->i_gid = le64_to_cpu(pfindData->Gid); |
376 | tmp_inode->i_nlink = le64_to_cpu(pfindData->Nlinks); | 377 | tmp_inode->i_nlink = le64_to_cpu(pfindData->Nlinks); |
377 | 378 | ||
379 | cifsInfo->server_eof = end_of_file; | ||
378 | spin_lock(&tmp_inode->i_lock); | 380 | spin_lock(&tmp_inode->i_lock); |
379 | if (is_size_safe_to_change(cifsInfo, end_of_file)) { | 381 | if (is_size_safe_to_change(cifsInfo, end_of_file)) { |
380 | /* can not safely change the file size here if the | 382 | /* can not safely change the file size here if the |
@@ -840,7 +842,7 @@ static int cifs_get_name_from_search_buf(struct qstr *pqst, | |||
840 | len = strnlen(filename, PATH_MAX); | 842 | len = strnlen(filename, PATH_MAX); |
841 | } | 843 | } |
842 | 844 | ||
843 | *pinum = pFindData->UniqueId; | 845 | *pinum = le64_to_cpu(pFindData->UniqueId); |
844 | } else if (level == SMB_FIND_FILE_DIRECTORY_INFO) { | 846 | } else if (level == SMB_FIND_FILE_DIRECTORY_INFO) { |
845 | FILE_DIRECTORY_INFO *pFindData = | 847 | FILE_DIRECTORY_INFO *pFindData = |
846 | (FILE_DIRECTORY_INFO *)current_entry; | 848 | (FILE_DIRECTORY_INFO *)current_entry; |
@@ -856,7 +858,7 @@ static int cifs_get_name_from_search_buf(struct qstr *pqst, | |||
856 | (SEARCH_ID_FULL_DIR_INFO *)current_entry; | 858 | (SEARCH_ID_FULL_DIR_INFO *)current_entry; |
857 | filename = &pFindData->FileName[0]; | 859 | filename = &pFindData->FileName[0]; |
858 | len = le32_to_cpu(pFindData->FileNameLength); | 860 | len = le32_to_cpu(pFindData->FileNameLength); |
859 | *pinum = pFindData->UniqueId; | 861 | *pinum = le64_to_cpu(pFindData->UniqueId); |
860 | } else if (level == SMB_FIND_FILE_BOTH_DIRECTORY_INFO) { | 862 | } else if (level == SMB_FIND_FILE_BOTH_DIRECTORY_INFO) { |
861 | FILE_BOTH_DIRECTORY_INFO *pFindData = | 863 | FILE_BOTH_DIRECTORY_INFO *pFindData = |
862 | (FILE_BOTH_DIRECTORY_INFO *)current_entry; | 864 | (FILE_BOTH_DIRECTORY_INFO *)current_entry; |
diff --git a/fs/cifs/sess.c b/fs/cifs/sess.c index 5c68b4282be9..c652c73760dd 100644 --- a/fs/cifs/sess.c +++ b/fs/cifs/sess.c | |||
@@ -285,35 +285,36 @@ static int decode_unicode_ssetup(char **pbcc_area, int bleft, | |||
285 | int words_left, len; | 285 | int words_left, len; |
286 | char *data = *pbcc_area; | 286 | char *data = *pbcc_area; |
287 | 287 | ||
288 | |||
289 | |||
290 | cFYI(1, ("bleft %d", bleft)); | 288 | cFYI(1, ("bleft %d", bleft)); |
291 | 289 | ||
292 | 290 | /* | |
293 | /* SMB header is unaligned, so cifs servers word align start of | 291 | * Windows servers do not always double null terminate their final |
294 | Unicode strings */ | 292 | * Unicode string. Check to see if there are an uneven number of bytes |
295 | data++; | 293 | * left. If so, then add an extra NULL pad byte to the end of the |
296 | bleft--; /* Windows servers do not always double null terminate | 294 | * response. |
297 | their final Unicode string - in which case we | 295 | * |
298 | now will not attempt to decode the byte of junk | 296 | * See section 2.7.2 in "Implementing CIFS" for details |
299 | which follows it */ | 297 | */ |
298 | if (bleft % 2) { | ||
299 | data[bleft] = 0; | ||
300 | ++bleft; | ||
301 | } | ||
300 | 302 | ||
301 | words_left = bleft / 2; | 303 | words_left = bleft / 2; |
302 | 304 | ||
303 | /* save off server operating system */ | 305 | /* save off server operating system */ |
304 | len = UniStrnlen((wchar_t *) data, words_left); | 306 | len = UniStrnlen((wchar_t *) data, words_left); |
305 | 307 | ||
306 | /* We look for obvious messed up bcc or strings in response so we do not go off | ||
307 | the end since (at least) WIN2K and Windows XP have a major bug in not null | ||
308 | terminating last Unicode string in response */ | ||
309 | if (len >= words_left) | 308 | if (len >= words_left) |
310 | return rc; | 309 | return rc; |
311 | 310 | ||
312 | kfree(ses->serverOS); | 311 | kfree(ses->serverOS); |
313 | /* UTF-8 string will not grow more than four times as big as UCS-16 */ | 312 | /* UTF-8 string will not grow more than four times as big as UCS-16 */ |
314 | ses->serverOS = kzalloc((4 * len) + 2 /* trailing null */, GFP_KERNEL); | 313 | ses->serverOS = kzalloc((4 * len) + 2 /* trailing null */, GFP_KERNEL); |
315 | if (ses->serverOS != NULL) | 314 | if (ses->serverOS != NULL) { |
316 | cifs_strfromUCS_le(ses->serverOS, (__le16 *)data, len, nls_cp); | 315 | cifs_strfromUCS_le(ses->serverOS, (__le16 *)data, len, nls_cp); |
316 | cFYI(1, ("serverOS=%s", ses->serverOS)); | ||
317 | } | ||
317 | data += 2 * (len + 1); | 318 | data += 2 * (len + 1); |
318 | words_left -= len + 1; | 319 | words_left -= len + 1; |
319 | 320 | ||
@@ -328,6 +329,7 @@ static int decode_unicode_ssetup(char **pbcc_area, int bleft, | |||
328 | if (ses->serverNOS != NULL) { | 329 | if (ses->serverNOS != NULL) { |
329 | cifs_strfromUCS_le(ses->serverNOS, (__le16 *)data, len, | 330 | cifs_strfromUCS_le(ses->serverNOS, (__le16 *)data, len, |
330 | nls_cp); | 331 | nls_cp); |
332 | cFYI(1, ("serverNOS=%s", ses->serverNOS)); | ||
331 | if (strncmp(ses->serverNOS, "NT LAN Manager 4", 16) == 0) { | 333 | if (strncmp(ses->serverNOS, "NT LAN Manager 4", 16) == 0) { |
332 | cFYI(1, ("NT4 server")); | 334 | cFYI(1, ("NT4 server")); |
333 | ses->flags |= CIFS_SES_NT4; | 335 | ses->flags |= CIFS_SES_NT4; |
@@ -343,12 +345,11 @@ static int decode_unicode_ssetup(char **pbcc_area, int bleft, | |||
343 | return rc; | 345 | return rc; |
344 | 346 | ||
345 | kfree(ses->serverDomain); | 347 | kfree(ses->serverDomain); |
346 | ses->serverDomain = kzalloc(2 * (len + 1), GFP_KERNEL); /* BB FIXME wrong length */ | 348 | ses->serverDomain = kzalloc((4 * len) + 2, GFP_KERNEL); |
347 | if (ses->serverDomain != NULL) { | 349 | if (ses->serverDomain != NULL) { |
348 | cifs_strfromUCS_le(ses->serverDomain, (__le16 *)data, len, | 350 | cifs_strfromUCS_le(ses->serverDomain, (__le16 *)data, len, |
349 | nls_cp); | 351 | nls_cp); |
350 | ses->serverDomain[2*len] = 0; | 352 | cFYI(1, ("serverDomain=%s", ses->serverDomain)); |
351 | ses->serverDomain[(2*len) + 1] = 0; | ||
352 | } | 353 | } |
353 | data += 2 * (len + 1); | 354 | data += 2 * (len + 1); |
354 | words_left -= len + 1; | 355 | words_left -= len + 1; |
@@ -702,12 +703,18 @@ CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses, int first_time, | |||
702 | } | 703 | } |
703 | 704 | ||
704 | /* BB check if Unicode and decode strings */ | 705 | /* BB check if Unicode and decode strings */ |
705 | if (smb_buf->Flags2 & SMBFLG2_UNICODE) | 706 | if (smb_buf->Flags2 & SMBFLG2_UNICODE) { |
707 | /* unicode string area must be word-aligned */ | ||
708 | if (((unsigned long) bcc_ptr - (unsigned long) smb_buf) % 2) { | ||
709 | ++bcc_ptr; | ||
710 | --bytes_remaining; | ||
711 | } | ||
706 | rc = decode_unicode_ssetup(&bcc_ptr, bytes_remaining, | 712 | rc = decode_unicode_ssetup(&bcc_ptr, bytes_remaining, |
707 | ses, nls_cp); | 713 | ses, nls_cp); |
708 | else | 714 | } else { |
709 | rc = decode_ascii_ssetup(&bcc_ptr, bytes_remaining, | 715 | rc = decode_ascii_ssetup(&bcc_ptr, bytes_remaining, |
710 | ses, nls_cp); | 716 | ses, nls_cp); |
717 | } | ||
711 | 718 | ||
712 | ssetup_exit: | 719 | ssetup_exit: |
713 | if (spnego_key) { | 720 | if (spnego_key) { |
diff --git a/fs/direct-io.c b/fs/direct-io.c index da258e7249cc..05763bbc2050 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c | |||
@@ -307,8 +307,6 @@ dio_bio_alloc(struct dio *dio, struct block_device *bdev, | |||
307 | struct bio *bio; | 307 | struct bio *bio; |
308 | 308 | ||
309 | bio = bio_alloc(GFP_KERNEL, nr_vecs); | 309 | bio = bio_alloc(GFP_KERNEL, nr_vecs); |
310 | if (bio == NULL) | ||
311 | return -ENOMEM; | ||
312 | 310 | ||
313 | bio->bi_bdev = bdev; | 311 | bio->bi_bdev = bdev; |
314 | bio->bi_sector = first_sector; | 312 | bio->bi_sector = first_sector; |
diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c index b43b95563663..acf678831103 100644 --- a/fs/ext2/inode.c +++ b/fs/ext2/inode.c | |||
@@ -590,9 +590,8 @@ static int ext2_get_blocks(struct inode *inode, | |||
590 | 590 | ||
591 | if (depth == 0) | 591 | if (depth == 0) |
592 | return (err); | 592 | return (err); |
593 | reread: | ||
594 | partial = ext2_get_branch(inode, depth, offsets, chain, &err); | ||
595 | 593 | ||
594 | partial = ext2_get_branch(inode, depth, offsets, chain, &err); | ||
596 | /* Simplest case - block found, no allocation needed */ | 595 | /* Simplest case - block found, no allocation needed */ |
597 | if (!partial) { | 596 | if (!partial) { |
598 | first_block = le32_to_cpu(chain[depth - 1].key); | 597 | first_block = le32_to_cpu(chain[depth - 1].key); |
@@ -602,15 +601,16 @@ reread: | |||
602 | while (count < maxblocks && count <= blocks_to_boundary) { | 601 | while (count < maxblocks && count <= blocks_to_boundary) { |
603 | ext2_fsblk_t blk; | 602 | ext2_fsblk_t blk; |
604 | 603 | ||
605 | if (!verify_chain(chain, partial)) { | 604 | if (!verify_chain(chain, chain + depth - 1)) { |
606 | /* | 605 | /* |
607 | * Indirect block might be removed by | 606 | * Indirect block might be removed by |
608 | * truncate while we were reading it. | 607 | * truncate while we were reading it. |
609 | * Handling of that case: forget what we've | 608 | * Handling of that case: forget what we've |
610 | * got now, go to reread. | 609 | * got now, go to reread. |
611 | */ | 610 | */ |
611 | err = -EAGAIN; | ||
612 | count = 0; | 612 | count = 0; |
613 | goto changed; | 613 | break; |
614 | } | 614 | } |
615 | blk = le32_to_cpu(*(chain[depth-1].p + count)); | 615 | blk = le32_to_cpu(*(chain[depth-1].p + count)); |
616 | if (blk == first_block + count) | 616 | if (blk == first_block + count) |
@@ -618,7 +618,8 @@ reread: | |||
618 | else | 618 | else |
619 | break; | 619 | break; |
620 | } | 620 | } |
621 | goto got_it; | 621 | if (err != -EAGAIN) |
622 | goto got_it; | ||
622 | } | 623 | } |
623 | 624 | ||
624 | /* Next simple case - plain lookup or failed read of indirect block */ | 625 | /* Next simple case - plain lookup or failed read of indirect block */ |
@@ -626,6 +627,33 @@ reread: | |||
626 | goto cleanup; | 627 | goto cleanup; |
627 | 628 | ||
628 | mutex_lock(&ei->truncate_mutex); | 629 | mutex_lock(&ei->truncate_mutex); |
630 | /* | ||
631 | * If the indirect block is missing while we are reading | ||
632 | * the chain(ext3_get_branch() returns -EAGAIN err), or | ||
633 | * if the chain has been changed after we grab the semaphore, | ||
634 | * (either because another process truncated this branch, or | ||
635 | * another get_block allocated this branch) re-grab the chain to see if | ||
636 | * the request block has been allocated or not. | ||
637 | * | ||
638 | * Since we already block the truncate/other get_block | ||
639 | * at this point, we will have the current copy of the chain when we | ||
640 | * splice the branch into the tree. | ||
641 | */ | ||
642 | if (err == -EAGAIN || !verify_chain(chain, partial)) { | ||
643 | while (partial > chain) { | ||
644 | brelse(partial->bh); | ||
645 | partial--; | ||
646 | } | ||
647 | partial = ext2_get_branch(inode, depth, offsets, chain, &err); | ||
648 | if (!partial) { | ||
649 | count++; | ||
650 | mutex_unlock(&ei->truncate_mutex); | ||
651 | if (err) | ||
652 | goto cleanup; | ||
653 | clear_buffer_new(bh_result); | ||
654 | goto got_it; | ||
655 | } | ||
656 | } | ||
629 | 657 | ||
630 | /* | 658 | /* |
631 | * Okay, we need to do block allocation. Lazily initialize the block | 659 | * Okay, we need to do block allocation. Lazily initialize the block |
@@ -683,12 +711,6 @@ cleanup: | |||
683 | partial--; | 711 | partial--; |
684 | } | 712 | } |
685 | return err; | 713 | return err; |
686 | changed: | ||
687 | while (partial > chain) { | ||
688 | brelse(partial->bh); | ||
689 | partial--; | ||
690 | } | ||
691 | goto reread; | ||
692 | } | 714 | } |
693 | 715 | ||
694 | int ext2_get_block(struct inode *inode, sector_t iblock, struct buffer_head *bh_result, int create) | 716 | int ext2_get_block(struct inode *inode, sector_t iblock, struct buffer_head *bh_result, int create) |
diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c index 466a332e0bd1..fcfa24361856 100644 --- a/fs/ext3/inode.c +++ b/fs/ext3/inode.c | |||
@@ -1521,12 +1521,16 @@ static int ext3_ordered_writepage(struct page *page, | |||
1521 | if (!page_has_buffers(page)) { | 1521 | if (!page_has_buffers(page)) { |
1522 | create_empty_buffers(page, inode->i_sb->s_blocksize, | 1522 | create_empty_buffers(page, inode->i_sb->s_blocksize, |
1523 | (1 << BH_Dirty)|(1 << BH_Uptodate)); | 1523 | (1 << BH_Dirty)|(1 << BH_Uptodate)); |
1524 | } else if (!walk_page_buffers(NULL, page_buffers(page), 0, PAGE_CACHE_SIZE, NULL, buffer_unmapped)) { | 1524 | page_bufs = page_buffers(page); |
1525 | /* Provide NULL instead of get_block so that we catch bugs if buffers weren't really mapped */ | 1525 | } else { |
1526 | return block_write_full_page(page, NULL, wbc); | 1526 | page_bufs = page_buffers(page); |
1527 | if (!walk_page_buffers(NULL, page_bufs, 0, PAGE_CACHE_SIZE, | ||
1528 | NULL, buffer_unmapped)) { | ||
1529 | /* Provide NULL get_block() to catch bugs if buffers | ||
1530 | * weren't really mapped */ | ||
1531 | return block_write_full_page(page, NULL, wbc); | ||
1532 | } | ||
1527 | } | 1533 | } |
1528 | page_bufs = page_buffers(page); | ||
1529 | |||
1530 | handle = ext3_journal_start(inode, ext3_writepage_trans_blocks(inode)); | 1534 | handle = ext3_journal_start(inode, ext3_writepage_trans_blocks(inode)); |
1531 | 1535 | ||
1532 | if (IS_ERR(handle)) { | 1536 | if (IS_ERR(handle)) { |
@@ -1581,6 +1585,15 @@ static int ext3_writeback_writepage(struct page *page, | |||
1581 | if (ext3_journal_current_handle()) | 1585 | if (ext3_journal_current_handle()) |
1582 | goto out_fail; | 1586 | goto out_fail; |
1583 | 1587 | ||
1588 | if (page_has_buffers(page)) { | ||
1589 | if (!walk_page_buffers(NULL, page_buffers(page), 0, | ||
1590 | PAGE_CACHE_SIZE, NULL, buffer_unmapped)) { | ||
1591 | /* Provide NULL get_block() to catch bugs if buffers | ||
1592 | * weren't really mapped */ | ||
1593 | return block_write_full_page(page, NULL, wbc); | ||
1594 | } | ||
1595 | } | ||
1596 | |||
1584 | handle = ext3_journal_start(inode, ext3_writepage_trans_blocks(inode)); | 1597 | handle = ext3_journal_start(inode, ext3_writepage_trans_blocks(inode)); |
1585 | if (IS_ERR(handle)) { | 1598 | if (IS_ERR(handle)) { |
1586 | ret = PTR_ERR(handle); | 1599 | ret = PTR_ERR(handle); |
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index ac77d8b8251d..2a1cb0979768 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c | |||
@@ -342,7 +342,7 @@ static int ext4_valid_extent_idx(struct inode *inode, | |||
342 | ext4_fsblk_t block = idx_pblock(ext_idx); | 342 | ext4_fsblk_t block = idx_pblock(ext_idx); |
343 | struct ext4_super_block *es = EXT4_SB(inode->i_sb)->s_es; | 343 | struct ext4_super_block *es = EXT4_SB(inode->i_sb)->s_es; |
344 | if (unlikely(block < le32_to_cpu(es->s_first_data_block) || | 344 | if (unlikely(block < le32_to_cpu(es->s_first_data_block) || |
345 | (block > ext4_blocks_count(es)))) | 345 | (block >= ext4_blocks_count(es)))) |
346 | return 0; | 346 | return 0; |
347 | else | 347 | else |
348 | return 1; | 348 | return 1; |
@@ -2416,8 +2416,6 @@ static int ext4_ext_zeroout(struct inode *inode, struct ext4_extent *ex) | |||
2416 | len = ee_len; | 2416 | len = ee_len; |
2417 | 2417 | ||
2418 | bio = bio_alloc(GFP_NOIO, len); | 2418 | bio = bio_alloc(GFP_NOIO, len); |
2419 | if (!bio) | ||
2420 | return -ENOMEM; | ||
2421 | bio->bi_sector = ee_pblock; | 2419 | bio->bi_sector = ee_pblock; |
2422 | bio->bi_bdev = inode->i_sb->s_bdev; | 2420 | bio->bi_bdev = inode->i_sb->s_bdev; |
2423 | 2421 | ||
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index a2e7952bc5f9..c6bd6ced3bb7 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c | |||
@@ -372,16 +372,16 @@ static int ext4_block_to_path(struct inode *inode, | |||
372 | } | 372 | } |
373 | 373 | ||
374 | static int __ext4_check_blockref(const char *function, struct inode *inode, | 374 | static int __ext4_check_blockref(const char *function, struct inode *inode, |
375 | unsigned int *p, unsigned int max) { | 375 | __le32 *p, unsigned int max) { |
376 | 376 | ||
377 | unsigned int maxblocks = ext4_blocks_count(EXT4_SB(inode->i_sb)->s_es); | 377 | unsigned int maxblocks = ext4_blocks_count(EXT4_SB(inode->i_sb)->s_es); |
378 | unsigned int *bref = p; | 378 | __le32 *bref = p; |
379 | while (bref < p+max) { | 379 | while (bref < p+max) { |
380 | if (unlikely(*bref >= maxblocks)) { | 380 | if (unlikely(le32_to_cpu(*bref) >= maxblocks)) { |
381 | ext4_error(inode->i_sb, function, | 381 | ext4_error(inode->i_sb, function, |
382 | "block reference %u >= max (%u) " | 382 | "block reference %u >= max (%u) " |
383 | "in inode #%lu, offset=%d", | 383 | "in inode #%lu, offset=%d", |
384 | *bref, maxblocks, | 384 | le32_to_cpu(*bref), maxblocks, |
385 | inode->i_ino, (int)(bref-p)); | 385 | inode->i_ino, (int)(bref-p)); |
386 | return -EIO; | 386 | return -EIO; |
387 | } | 387 | } |
diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 9987bba99db3..2958f4e6f222 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c | |||
@@ -2508,6 +2508,15 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) | |||
2508 | if (EXT4_BLOCKS_PER_GROUP(sb) == 0) | 2508 | if (EXT4_BLOCKS_PER_GROUP(sb) == 0) |
2509 | goto cantfind_ext4; | 2509 | goto cantfind_ext4; |
2510 | 2510 | ||
2511 | /* check blocks count against device size */ | ||
2512 | blocks_count = sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits; | ||
2513 | if (blocks_count && ext4_blocks_count(es) > blocks_count) { | ||
2514 | printk(KERN_WARNING "EXT4-fs: bad geometry: block count %llu " | ||
2515 | "exceeds size of device (%llu blocks)\n", | ||
2516 | ext4_blocks_count(es), blocks_count); | ||
2517 | goto failed_mount; | ||
2518 | } | ||
2519 | |||
2511 | /* | 2520 | /* |
2512 | * It makes no sense for the first data block to be beyond the end | 2521 | * It makes no sense for the first data block to be beyond the end |
2513 | * of the filesystem. | 2522 | * of the filesystem. |
diff --git a/fs/fat/Kconfig b/fs/fat/Kconfig index d0a69ff25375..182f9ffe2b51 100644 --- a/fs/fat/Kconfig +++ b/fs/fat/Kconfig | |||
@@ -95,3 +95,6 @@ config FAT_DEFAULT_IOCHARSET | |||
95 | Note that "utf8" is not recommended for FAT filesystems. | 95 | Note that "utf8" is not recommended for FAT filesystems. |
96 | If unsure, you shouldn't set "utf8" here. | 96 | If unsure, you shouldn't set "utf8" here. |
97 | See <file:Documentation/filesystems/vfat.txt> for more information. | 97 | See <file:Documentation/filesystems/vfat.txt> for more information. |
98 | |||
99 | Enable any character sets you need in File Systems/Native Language | ||
100 | Support. | ||
diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 2b25133524a3..06f30e965676 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c | |||
@@ -938,9 +938,9 @@ static void fuse_release_user_pages(struct fuse_req *req, int write) | |||
938 | } | 938 | } |
939 | 939 | ||
940 | static int fuse_get_user_pages(struct fuse_req *req, const char __user *buf, | 940 | static int fuse_get_user_pages(struct fuse_req *req, const char __user *buf, |
941 | unsigned *nbytesp, int write) | 941 | size_t *nbytesp, int write) |
942 | { | 942 | { |
943 | unsigned nbytes = *nbytesp; | 943 | size_t nbytes = *nbytesp; |
944 | unsigned long user_addr = (unsigned long) buf; | 944 | unsigned long user_addr = (unsigned long) buf; |
945 | unsigned offset = user_addr & ~PAGE_MASK; | 945 | unsigned offset = user_addr & ~PAGE_MASK; |
946 | int npages; | 946 | int npages; |
@@ -955,7 +955,7 @@ static int fuse_get_user_pages(struct fuse_req *req, const char __user *buf, | |||
955 | return 0; | 955 | return 0; |
956 | } | 956 | } |
957 | 957 | ||
958 | nbytes = min(nbytes, (unsigned) FUSE_MAX_PAGES_PER_REQ << PAGE_SHIFT); | 958 | nbytes = min_t(size_t, nbytes, FUSE_MAX_PAGES_PER_REQ << PAGE_SHIFT); |
959 | npages = (nbytes + offset + PAGE_SIZE - 1) >> PAGE_SHIFT; | 959 | npages = (nbytes + offset + PAGE_SIZE - 1) >> PAGE_SHIFT; |
960 | npages = clamp(npages, 1, FUSE_MAX_PAGES_PER_REQ); | 960 | npages = clamp(npages, 1, FUSE_MAX_PAGES_PER_REQ); |
961 | down_read(¤t->mm->mmap_sem); | 961 | down_read(¤t->mm->mmap_sem); |
@@ -1298,6 +1298,8 @@ static int fuse_direct_mmap(struct file *file, struct vm_area_struct *vma) | |||
1298 | if (vma->vm_flags & VM_MAYSHARE) | 1298 | if (vma->vm_flags & VM_MAYSHARE) |
1299 | return -ENODEV; | 1299 | return -ENODEV; |
1300 | 1300 | ||
1301 | invalidate_inode_pages2(file->f_mapping); | ||
1302 | |||
1301 | return generic_file_mmap(file, vma); | 1303 | return generic_file_mmap(file, vma); |
1302 | } | 1304 | } |
1303 | 1305 | ||
diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 3984e47d1d33..1afd9f26bcb1 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c | |||
@@ -597,7 +597,6 @@ __acquires(&gl->gl_spin) | |||
597 | 597 | ||
598 | GLOCK_BUG_ON(gl, test_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags)); | 598 | GLOCK_BUG_ON(gl, test_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags)); |
599 | 599 | ||
600 | down_read(&gfs2_umount_flush_sem); | ||
601 | if (test_bit(GLF_DEMOTE, &gl->gl_flags) && | 600 | if (test_bit(GLF_DEMOTE, &gl->gl_flags) && |
602 | gl->gl_demote_state != gl->gl_state) { | 601 | gl->gl_demote_state != gl->gl_state) { |
603 | if (find_first_holder(gl)) | 602 | if (find_first_holder(gl)) |
@@ -614,15 +613,14 @@ __acquires(&gl->gl_spin) | |||
614 | if (ret == 0) | 613 | if (ret == 0) |
615 | goto out_unlock; | 614 | goto out_unlock; |
616 | if (ret == 2) | 615 | if (ret == 2) |
617 | goto out_sem; | 616 | goto out; |
618 | gh = find_first_waiter(gl); | 617 | gh = find_first_waiter(gl); |
619 | gl->gl_target = gh->gh_state; | 618 | gl->gl_target = gh->gh_state; |
620 | if (!(gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB))) | 619 | if (!(gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB))) |
621 | do_error(gl, 0); /* Fail queued try locks */ | 620 | do_error(gl, 0); /* Fail queued try locks */ |
622 | } | 621 | } |
623 | do_xmote(gl, gh, gl->gl_target); | 622 | do_xmote(gl, gh, gl->gl_target); |
624 | out_sem: | 623 | out: |
625 | up_read(&gfs2_umount_flush_sem); | ||
626 | return; | 624 | return; |
627 | 625 | ||
628 | out_sched: | 626 | out_sched: |
@@ -631,7 +629,7 @@ out_sched: | |||
631 | gfs2_glock_put(gl); | 629 | gfs2_glock_put(gl); |
632 | out_unlock: | 630 | out_unlock: |
633 | clear_bit(GLF_LOCK, &gl->gl_flags); | 631 | clear_bit(GLF_LOCK, &gl->gl_flags); |
634 | goto out_sem; | 632 | goto out; |
635 | } | 633 | } |
636 | 634 | ||
637 | static void glock_work_func(struct work_struct *work) | 635 | static void glock_work_func(struct work_struct *work) |
@@ -641,6 +639,7 @@ static void glock_work_func(struct work_struct *work) | |||
641 | 639 | ||
642 | if (test_and_clear_bit(GLF_REPLY_PENDING, &gl->gl_flags)) | 640 | if (test_and_clear_bit(GLF_REPLY_PENDING, &gl->gl_flags)) |
643 | finish_xmote(gl, gl->gl_reply); | 641 | finish_xmote(gl, gl->gl_reply); |
642 | down_read(&gfs2_umount_flush_sem); | ||
644 | spin_lock(&gl->gl_spin); | 643 | spin_lock(&gl->gl_spin); |
645 | if (test_and_clear_bit(GLF_PENDING_DEMOTE, &gl->gl_flags) && | 644 | if (test_and_clear_bit(GLF_PENDING_DEMOTE, &gl->gl_flags) && |
646 | gl->gl_state != LM_ST_UNLOCKED && | 645 | gl->gl_state != LM_ST_UNLOCKED && |
@@ -653,6 +652,7 @@ static void glock_work_func(struct work_struct *work) | |||
653 | } | 652 | } |
654 | run_queue(gl, 0); | 653 | run_queue(gl, 0); |
655 | spin_unlock(&gl->gl_spin); | 654 | spin_unlock(&gl->gl_spin); |
655 | up_read(&gfs2_umount_flush_sem); | ||
656 | if (!delay || | 656 | if (!delay || |
657 | queue_delayed_work(glock_workqueue, &gl->gl_work, delay) == 0) | 657 | queue_delayed_work(glock_workqueue, &gl->gl_work, delay) == 0) |
658 | gfs2_glock_put(gl); | 658 | gfs2_glock_put(gl); |
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 7b277d449155..5a31d426116f 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c | |||
@@ -137,15 +137,15 @@ void gfs2_set_iop(struct inode *inode) | |||
137 | if (S_ISREG(mode)) { | 137 | if (S_ISREG(mode)) { |
138 | inode->i_op = &gfs2_file_iops; | 138 | inode->i_op = &gfs2_file_iops; |
139 | if (gfs2_localflocks(sdp)) | 139 | if (gfs2_localflocks(sdp)) |
140 | inode->i_fop = gfs2_file_fops_nolock; | 140 | inode->i_fop = &gfs2_file_fops_nolock; |
141 | else | 141 | else |
142 | inode->i_fop = gfs2_file_fops; | 142 | inode->i_fop = &gfs2_file_fops; |
143 | } else if (S_ISDIR(mode)) { | 143 | } else if (S_ISDIR(mode)) { |
144 | inode->i_op = &gfs2_dir_iops; | 144 | inode->i_op = &gfs2_dir_iops; |
145 | if (gfs2_localflocks(sdp)) | 145 | if (gfs2_localflocks(sdp)) |
146 | inode->i_fop = gfs2_dir_fops_nolock; | 146 | inode->i_fop = &gfs2_dir_fops_nolock; |
147 | else | 147 | else |
148 | inode->i_fop = gfs2_dir_fops; | 148 | inode->i_fop = &gfs2_dir_fops; |
149 | } else if (S_ISLNK(mode)) { | 149 | } else if (S_ISLNK(mode)) { |
150 | inode->i_op = &gfs2_symlink_iops; | 150 | inode->i_op = &gfs2_symlink_iops; |
151 | } else { | 151 | } else { |
diff --git a/fs/gfs2/inode.h b/fs/gfs2/inode.h index dca4fee3078b..c30be2b66580 100644 --- a/fs/gfs2/inode.h +++ b/fs/gfs2/inode.h | |||
@@ -101,21 +101,23 @@ void gfs2_dinode_print(const struct gfs2_inode *ip); | |||
101 | extern const struct inode_operations gfs2_file_iops; | 101 | extern const struct inode_operations gfs2_file_iops; |
102 | extern const struct inode_operations gfs2_dir_iops; | 102 | extern const struct inode_operations gfs2_dir_iops; |
103 | extern const struct inode_operations gfs2_symlink_iops; | 103 | extern const struct inode_operations gfs2_symlink_iops; |
104 | extern const struct file_operations *gfs2_file_fops_nolock; | 104 | extern const struct file_operations gfs2_file_fops_nolock; |
105 | extern const struct file_operations *gfs2_dir_fops_nolock; | 105 | extern const struct file_operations gfs2_dir_fops_nolock; |
106 | 106 | ||
107 | extern void gfs2_set_inode_flags(struct inode *inode); | 107 | extern void gfs2_set_inode_flags(struct inode *inode); |
108 | 108 | ||
109 | #ifdef CONFIG_GFS2_FS_LOCKING_DLM | 109 | #ifdef CONFIG_GFS2_FS_LOCKING_DLM |
110 | extern const struct file_operations *gfs2_file_fops; | 110 | extern const struct file_operations gfs2_file_fops; |
111 | extern const struct file_operations *gfs2_dir_fops; | 111 | extern const struct file_operations gfs2_dir_fops; |
112 | |||
112 | static inline int gfs2_localflocks(const struct gfs2_sbd *sdp) | 113 | static inline int gfs2_localflocks(const struct gfs2_sbd *sdp) |
113 | { | 114 | { |
114 | return sdp->sd_args.ar_localflocks; | 115 | return sdp->sd_args.ar_localflocks; |
115 | } | 116 | } |
116 | #else /* Single node only */ | 117 | #else /* Single node only */ |
117 | #define gfs2_file_fops NULL | 118 | #define gfs2_file_fops gfs2_file_fops_nolock |
118 | #define gfs2_dir_fops NULL | 119 | #define gfs2_dir_fops gfs2_dir_fops_nolock |
120 | |||
119 | static inline int gfs2_localflocks(const struct gfs2_sbd *sdp) | 121 | static inline int gfs2_localflocks(const struct gfs2_sbd *sdp) |
120 | { | 122 | { |
121 | return 1; | 123 | return 1; |
diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index 70b9b8548945..101caf3ee861 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c | |||
@@ -705,7 +705,7 @@ static int gfs2_flock(struct file *file, int cmd, struct file_lock *fl) | |||
705 | } | 705 | } |
706 | } | 706 | } |
707 | 707 | ||
708 | const struct file_operations *gfs2_file_fops = &(const struct file_operations){ | 708 | const struct file_operations gfs2_file_fops = { |
709 | .llseek = gfs2_llseek, | 709 | .llseek = gfs2_llseek, |
710 | .read = do_sync_read, | 710 | .read = do_sync_read, |
711 | .aio_read = generic_file_aio_read, | 711 | .aio_read = generic_file_aio_read, |
@@ -723,7 +723,7 @@ const struct file_operations *gfs2_file_fops = &(const struct file_operations){ | |||
723 | .setlease = gfs2_setlease, | 723 | .setlease = gfs2_setlease, |
724 | }; | 724 | }; |
725 | 725 | ||
726 | const struct file_operations *gfs2_dir_fops = &(const struct file_operations){ | 726 | const struct file_operations gfs2_dir_fops = { |
727 | .readdir = gfs2_readdir, | 727 | .readdir = gfs2_readdir, |
728 | .unlocked_ioctl = gfs2_ioctl, | 728 | .unlocked_ioctl = gfs2_ioctl, |
729 | .open = gfs2_open, | 729 | .open = gfs2_open, |
@@ -735,7 +735,7 @@ const struct file_operations *gfs2_dir_fops = &(const struct file_operations){ | |||
735 | 735 | ||
736 | #endif /* CONFIG_GFS2_FS_LOCKING_DLM */ | 736 | #endif /* CONFIG_GFS2_FS_LOCKING_DLM */ |
737 | 737 | ||
738 | const struct file_operations *gfs2_file_fops_nolock = &(const struct file_operations){ | 738 | const struct file_operations gfs2_file_fops_nolock = { |
739 | .llseek = gfs2_llseek, | 739 | .llseek = gfs2_llseek, |
740 | .read = do_sync_read, | 740 | .read = do_sync_read, |
741 | .aio_read = generic_file_aio_read, | 741 | .aio_read = generic_file_aio_read, |
@@ -751,7 +751,7 @@ const struct file_operations *gfs2_file_fops_nolock = &(const struct file_operat | |||
751 | .setlease = generic_setlease, | 751 | .setlease = generic_setlease, |
752 | }; | 752 | }; |
753 | 753 | ||
754 | const struct file_operations *gfs2_dir_fops_nolock = &(const struct file_operations){ | 754 | const struct file_operations gfs2_dir_fops_nolock = { |
755 | .readdir = gfs2_readdir, | 755 | .readdir = gfs2_readdir, |
756 | .unlocked_ioctl = gfs2_ioctl, | 756 | .unlocked_ioctl = gfs2_ioctl, |
757 | .open = gfs2_open, | 757 | .open = gfs2_open, |
diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index 51883b3ad89c..650a730707b7 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c | |||
@@ -272,11 +272,6 @@ static int gfs2_read_super(struct gfs2_sbd *sdp, sector_t sector) | |||
272 | lock_page(page); | 272 | lock_page(page); |
273 | 273 | ||
274 | bio = bio_alloc(GFP_NOFS, 1); | 274 | bio = bio_alloc(GFP_NOFS, 1); |
275 | if (unlikely(!bio)) { | ||
276 | __free_page(page); | ||
277 | return -ENOBUFS; | ||
278 | } | ||
279 | |||
280 | bio->bi_sector = sector * (sb->s_blocksize >> 9); | 275 | bio->bi_sector = sector * (sb->s_blocksize >> 9); |
281 | bio->bi_bdev = sb->s_bdev; | 276 | bio->bi_bdev = sb->s_bdev; |
282 | bio_add_page(bio, page, PAGE_SIZE, 0); | 277 | bio_add_page(bio, page, PAGE_SIZE, 0); |
diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c index abd5429ae285..1c70fa5168d6 100644 --- a/fs/gfs2/ops_inode.c +++ b/fs/gfs2/ops_inode.c | |||
@@ -371,6 +371,7 @@ static int gfs2_symlink(struct inode *dir, struct dentry *dentry, | |||
371 | ip = ghs[1].gh_gl->gl_object; | 371 | ip = ghs[1].gh_gl->gl_object; |
372 | 372 | ||
373 | ip->i_disksize = size; | 373 | ip->i_disksize = size; |
374 | i_size_write(inode, size); | ||
374 | 375 | ||
375 | error = gfs2_meta_inode_buffer(ip, &dibh); | 376 | error = gfs2_meta_inode_buffer(ip, &dibh); |
376 | 377 | ||
diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c index 8d53f66b5bcc..152e6c4a0dca 100644 --- a/fs/gfs2/quota.c +++ b/fs/gfs2/quota.c | |||
@@ -81,7 +81,7 @@ struct gfs2_quota_change_host { | |||
81 | 81 | ||
82 | static LIST_HEAD(qd_lru_list); | 82 | static LIST_HEAD(qd_lru_list); |
83 | static atomic_t qd_lru_count = ATOMIC_INIT(0); | 83 | static atomic_t qd_lru_count = ATOMIC_INIT(0); |
84 | static spinlock_t qd_lru_lock = SPIN_LOCK_UNLOCKED; | 84 | static DEFINE_SPINLOCK(qd_lru_lock); |
85 | 85 | ||
86 | int gfs2_shrink_qd_memory(int nr, gfp_t gfp_mask) | 86 | int gfs2_shrink_qd_memory(int nr, gfp_t gfp_mask) |
87 | { | 87 | { |
@@ -1364,7 +1364,7 @@ int gfs2_quotad(void *data) | |||
1364 | refrigerator(); | 1364 | refrigerator(); |
1365 | t = min(quotad_timeo, statfs_timeo); | 1365 | t = min(quotad_timeo, statfs_timeo); |
1366 | 1366 | ||
1367 | prepare_to_wait(&sdp->sd_quota_wait, &wait, TASK_UNINTERRUPTIBLE); | 1367 | prepare_to_wait(&sdp->sd_quota_wait, &wait, TASK_INTERRUPTIBLE); |
1368 | spin_lock(&sdp->sd_trunc_lock); | 1368 | spin_lock(&sdp->sd_trunc_lock); |
1369 | empty = list_empty(&sdp->sd_trunc_list); | 1369 | empty = list_empty(&sdp->sd_trunc_list); |
1370 | spin_unlock(&sdp->sd_trunc_lock); | 1370 | spin_unlock(&sdp->sd_trunc_lock); |
diff --git a/fs/hfs/inode.c b/fs/hfs/inode.c index 9435dda8f1e0..a1cbff2b4d99 100644 --- a/fs/hfs/inode.c +++ b/fs/hfs/inode.c | |||
@@ -70,6 +70,10 @@ static int hfs_releasepage(struct page *page, gfp_t mask) | |||
70 | BUG(); | 70 | BUG(); |
71 | return 0; | 71 | return 0; |
72 | } | 72 | } |
73 | |||
74 | if (!tree) | ||
75 | return 0; | ||
76 | |||
73 | if (tree->node_size >= PAGE_CACHE_SIZE) { | 77 | if (tree->node_size >= PAGE_CACHE_SIZE) { |
74 | nidx = page->index >> (tree->node_size_shift - PAGE_CACHE_SHIFT); | 78 | nidx = page->index >> (tree->node_size_shift - PAGE_CACHE_SHIFT); |
75 | spin_lock(&tree->hash_lock); | 79 | spin_lock(&tree->hash_lock); |
diff --git a/fs/hfs/mdb.c b/fs/hfs/mdb.c index 36ca2e1a4fa3..7b6165f25fbe 100644 --- a/fs/hfs/mdb.c +++ b/fs/hfs/mdb.c | |||
@@ -349,6 +349,7 @@ void hfs_mdb_put(struct super_block *sb) | |||
349 | if (HFS_SB(sb)->nls_disk) | 349 | if (HFS_SB(sb)->nls_disk) |
350 | unload_nls(HFS_SB(sb)->nls_disk); | 350 | unload_nls(HFS_SB(sb)->nls_disk); |
351 | 351 | ||
352 | free_pages((unsigned long)HFS_SB(sb)->bitmap, PAGE_SIZE < 8192 ? 1 : 0); | ||
352 | kfree(HFS_SB(sb)); | 353 | kfree(HFS_SB(sb)); |
353 | sb->s_fs_info = NULL; | 354 | sb->s_fs_info = NULL; |
354 | } | 355 | } |
diff --git a/fs/inode.c b/fs/inode.c index d06d6d268de9..6ad14a1cd8c9 100644 --- a/fs/inode.c +++ b/fs/inode.c | |||
@@ -1470,42 +1470,6 @@ static void __wait_on_freeing_inode(struct inode *inode) | |||
1470 | spin_lock(&inode_lock); | 1470 | spin_lock(&inode_lock); |
1471 | } | 1471 | } |
1472 | 1472 | ||
1473 | /* | ||
1474 | * We rarely want to lock two inodes that do not have a parent/child | ||
1475 | * relationship (such as directory, child inode) simultaneously. The | ||
1476 | * vast majority of file systems should be able to get along fine | ||
1477 | * without this. Do not use these functions except as a last resort. | ||
1478 | */ | ||
1479 | void inode_double_lock(struct inode *inode1, struct inode *inode2) | ||
1480 | { | ||
1481 | if (inode1 == NULL || inode2 == NULL || inode1 == inode2) { | ||
1482 | if (inode1) | ||
1483 | mutex_lock(&inode1->i_mutex); | ||
1484 | else if (inode2) | ||
1485 | mutex_lock(&inode2->i_mutex); | ||
1486 | return; | ||
1487 | } | ||
1488 | |||
1489 | if (inode1 < inode2) { | ||
1490 | mutex_lock_nested(&inode1->i_mutex, I_MUTEX_PARENT); | ||
1491 | mutex_lock_nested(&inode2->i_mutex, I_MUTEX_CHILD); | ||
1492 | } else { | ||
1493 | mutex_lock_nested(&inode2->i_mutex, I_MUTEX_PARENT); | ||
1494 | mutex_lock_nested(&inode1->i_mutex, I_MUTEX_CHILD); | ||
1495 | } | ||
1496 | } | ||
1497 | EXPORT_SYMBOL(inode_double_lock); | ||
1498 | |||
1499 | void inode_double_unlock(struct inode *inode1, struct inode *inode2) | ||
1500 | { | ||
1501 | if (inode1) | ||
1502 | mutex_unlock(&inode1->i_mutex); | ||
1503 | |||
1504 | if (inode2 && inode2 != inode1) | ||
1505 | mutex_unlock(&inode2->i_mutex); | ||
1506 | } | ||
1507 | EXPORT_SYMBOL(inode_double_unlock); | ||
1508 | |||
1509 | static __initdata unsigned long ihash_entries; | 1473 | static __initdata unsigned long ihash_entries; |
1510 | static int __init set_ihash_entries(char *str) | 1474 | static int __init set_ihash_entries(char *str) |
1511 | { | 1475 | { |
diff --git a/fs/jbd/revoke.c b/fs/jbd/revoke.c index c7bd649bbbdc..3e9afc2a91d2 100644 --- a/fs/jbd/revoke.c +++ b/fs/jbd/revoke.c | |||
@@ -55,6 +55,25 @@ | |||
55 | * need do nothing. | 55 | * need do nothing. |
56 | * RevokeValid set, Revoked set: | 56 | * RevokeValid set, Revoked set: |
57 | * buffer has been revoked. | 57 | * buffer has been revoked. |
58 | * | ||
59 | * Locking rules: | ||
60 | * We keep two hash tables of revoke records. One hashtable belongs to the | ||
61 | * running transaction (is pointed to by journal->j_revoke), the other one | ||
62 | * belongs to the committing transaction. Accesses to the second hash table | ||
63 | * happen only from the kjournald and no other thread touches this table. Also | ||
64 | * journal_switch_revoke_table() which switches which hashtable belongs to the | ||
65 | * running and which to the committing transaction is called only from | ||
66 | * kjournald. Therefore we need no locks when accessing the hashtable belonging | ||
67 | * to the committing transaction. | ||
68 | * | ||
69 | * All users operating on the hash table belonging to the running transaction | ||
70 | * have a handle to the transaction. Therefore they are safe from kjournald | ||
71 | * switching hash tables under them. For operations on the lists of entries in | ||
72 | * the hash table j_revoke_lock is used. | ||
73 | * | ||
74 | * Finally, also replay code uses the hash tables but at this moment noone else | ||
75 | * can touch them (filesystem isn't mounted yet) and hence no locking is | ||
76 | * needed. | ||
58 | */ | 77 | */ |
59 | 78 | ||
60 | #ifndef __KERNEL__ | 79 | #ifndef __KERNEL__ |
@@ -402,8 +421,6 @@ int journal_revoke(handle_t *handle, unsigned long blocknr, | |||
402 | * the second time we would still have a pending revoke to cancel. So, | 421 | * the second time we would still have a pending revoke to cancel. So, |
403 | * do not trust the Revoked bit on buffers unless RevokeValid is also | 422 | * do not trust the Revoked bit on buffers unless RevokeValid is also |
404 | * set. | 423 | * set. |
405 | * | ||
406 | * The caller must have the journal locked. | ||
407 | */ | 424 | */ |
408 | int journal_cancel_revoke(handle_t *handle, struct journal_head *jh) | 425 | int journal_cancel_revoke(handle_t *handle, struct journal_head *jh) |
409 | { | 426 | { |
@@ -481,10 +498,7 @@ void journal_switch_revoke_table(journal_t *journal) | |||
481 | /* | 498 | /* |
482 | * Write revoke records to the journal for all entries in the current | 499 | * Write revoke records to the journal for all entries in the current |
483 | * revoke hash, deleting the entries as we go. | 500 | * revoke hash, deleting the entries as we go. |
484 | * | ||
485 | * Called with the journal lock held. | ||
486 | */ | 501 | */ |
487 | |||
488 | void journal_write_revoke_records(journal_t *journal, | 502 | void journal_write_revoke_records(journal_t *journal, |
489 | transaction_t *transaction) | 503 | transaction_t *transaction) |
490 | { | 504 | { |
diff --git a/fs/namespace.c b/fs/namespace.c index c6f54e4c4290..d9138f81ec10 100644 --- a/fs/namespace.c +++ b/fs/namespace.c | |||
@@ -1920,8 +1920,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page, | |||
1920 | if (data_page) | 1920 | if (data_page) |
1921 | ((char *)data_page)[PAGE_SIZE - 1] = 0; | 1921 | ((char *)data_page)[PAGE_SIZE - 1] = 0; |
1922 | 1922 | ||
1923 | /* Default to relatime */ | 1923 | /* Default to relatime unless overriden */ |
1924 | mnt_flags |= MNT_RELATIME; | 1924 | if (!(flags & MS_NOATIME)) |
1925 | mnt_flags |= MNT_RELATIME; | ||
1925 | 1926 | ||
1926 | /* Separate the per-mountpoint flags */ | 1927 | /* Separate the per-mountpoint flags */ |
1927 | if (flags & MS_NOSUID) | 1928 | if (flags & MS_NOSUID) |
diff --git a/fs/nilfs2/bmap.c b/fs/nilfs2/bmap.c index 24638e059bf3..064279e33bbb 100644 --- a/fs/nilfs2/bmap.c +++ b/fs/nilfs2/bmap.c | |||
@@ -688,6 +688,8 @@ static const struct nilfs_bmap_ptr_operations nilfs_bmap_ptr_ops_gc = { | |||
688 | .bpop_translate = NULL, | 688 | .bpop_translate = NULL, |
689 | }; | 689 | }; |
690 | 690 | ||
691 | static struct lock_class_key nilfs_bmap_dat_lock_key; | ||
692 | |||
691 | /** | 693 | /** |
692 | * nilfs_bmap_read - read a bmap from an inode | 694 | * nilfs_bmap_read - read a bmap from an inode |
693 | * @bmap: bmap | 695 | * @bmap: bmap |
@@ -715,6 +717,7 @@ int nilfs_bmap_read(struct nilfs_bmap *bmap, struct nilfs_inode *raw_inode) | |||
715 | bmap->b_pops = &nilfs_bmap_ptr_ops_p; | 717 | bmap->b_pops = &nilfs_bmap_ptr_ops_p; |
716 | bmap->b_last_allocated_key = 0; /* XXX: use macro */ | 718 | bmap->b_last_allocated_key = 0; /* XXX: use macro */ |
717 | bmap->b_last_allocated_ptr = NILFS_BMAP_NEW_PTR_INIT; | 719 | bmap->b_last_allocated_ptr = NILFS_BMAP_NEW_PTR_INIT; |
720 | lockdep_set_class(&bmap->b_sem, &nilfs_bmap_dat_lock_key); | ||
718 | break; | 721 | break; |
719 | case NILFS_CPFILE_INO: | 722 | case NILFS_CPFILE_INO: |
720 | case NILFS_SUFILE_INO: | 723 | case NILFS_SUFILE_INO: |
@@ -772,6 +775,7 @@ void nilfs_bmap_init_gcdat(struct nilfs_bmap *gcbmap, struct nilfs_bmap *bmap) | |||
772 | { | 775 | { |
773 | memcpy(gcbmap, bmap, sizeof(union nilfs_bmap_union)); | 776 | memcpy(gcbmap, bmap, sizeof(union nilfs_bmap_union)); |
774 | init_rwsem(&gcbmap->b_sem); | 777 | init_rwsem(&gcbmap->b_sem); |
778 | lockdep_set_class(&bmap->b_sem, &nilfs_bmap_dat_lock_key); | ||
775 | gcbmap->b_inode = &NILFS_BMAP_I(gcbmap)->vfs_inode; | 779 | gcbmap->b_inode = &NILFS_BMAP_I(gcbmap)->vfs_inode; |
776 | } | 780 | } |
777 | 781 | ||
@@ -779,5 +783,6 @@ void nilfs_bmap_commit_gcdat(struct nilfs_bmap *gcbmap, struct nilfs_bmap *bmap) | |||
779 | { | 783 | { |
780 | memcpy(bmap, gcbmap, sizeof(union nilfs_bmap_union)); | 784 | memcpy(bmap, gcbmap, sizeof(union nilfs_bmap_union)); |
781 | init_rwsem(&bmap->b_sem); | 785 | init_rwsem(&bmap->b_sem); |
786 | lockdep_set_class(&bmap->b_sem, &nilfs_bmap_dat_lock_key); | ||
782 | bmap->b_inode = &NILFS_BMAP_I(bmap)->vfs_inode; | 787 | bmap->b_inode = &NILFS_BMAP_I(bmap)->vfs_inode; |
783 | } | 788 | } |
diff --git a/fs/nilfs2/nilfs.h b/fs/nilfs2/nilfs.h index 7558c977db02..3d0c18a16db1 100644 --- a/fs/nilfs2/nilfs.h +++ b/fs/nilfs2/nilfs.h | |||
@@ -35,11 +35,6 @@ | |||
35 | #include "bmap_union.h" | 35 | #include "bmap_union.h" |
36 | 36 | ||
37 | /* | 37 | /* |
38 | * NILFS filesystem version | ||
39 | */ | ||
40 | #define NILFS_VERSION "2.0.5" | ||
41 | |||
42 | /* | ||
43 | * nilfs inode data in memory | 38 | * nilfs inode data in memory |
44 | */ | 39 | */ |
45 | struct nilfs_inode_info { | 40 | struct nilfs_inode_info { |
diff --git a/fs/nilfs2/recovery.c b/fs/nilfs2/recovery.c index 6ade0963fc1d..4fc081e47d70 100644 --- a/fs/nilfs2/recovery.c +++ b/fs/nilfs2/recovery.c | |||
@@ -413,7 +413,6 @@ static int nilfs_prepare_segment_for_recovery(struct the_nilfs *nilfs, | |||
413 | struct nilfs_segment_entry *ent, *n; | 413 | struct nilfs_segment_entry *ent, *n; |
414 | struct inode *sufile = nilfs->ns_sufile; | 414 | struct inode *sufile = nilfs->ns_sufile; |
415 | __u64 segnum[4]; | 415 | __u64 segnum[4]; |
416 | time_t mtime; | ||
417 | int err; | 416 | int err; |
418 | int i; | 417 | int i; |
419 | 418 | ||
@@ -442,24 +441,13 @@ static int nilfs_prepare_segment_for_recovery(struct the_nilfs *nilfs, | |||
442 | * Collecting segments written after the latest super root. | 441 | * Collecting segments written after the latest super root. |
443 | * These are marked dirty to avoid being reallocated in the next write. | 442 | * These are marked dirty to avoid being reallocated in the next write. |
444 | */ | 443 | */ |
445 | mtime = get_seconds(); | ||
446 | list_for_each_entry_safe(ent, n, head, list) { | 444 | list_for_each_entry_safe(ent, n, head, list) { |
447 | if (ent->segnum == segnum[0]) { | 445 | if (ent->segnum != segnum[0]) { |
448 | list_del(&ent->list); | 446 | err = nilfs_sufile_scrap(sufile, ent->segnum); |
449 | nilfs_free_segment_entry(ent); | 447 | if (unlikely(err)) |
450 | continue; | 448 | goto failed; |
451 | } | ||
452 | err = nilfs_open_segment_entry(ent, sufile); | ||
453 | if (unlikely(err)) | ||
454 | goto failed; | ||
455 | if (!nilfs_segment_usage_dirty(ent->raw_su)) { | ||
456 | /* make the segment garbage */ | ||
457 | ent->raw_su->su_nblocks = cpu_to_le32(0); | ||
458 | ent->raw_su->su_lastmod = cpu_to_le32(mtime); | ||
459 | nilfs_segment_usage_set_dirty(ent->raw_su); | ||
460 | } | 449 | } |
461 | list_del(&ent->list); | 450 | list_del(&ent->list); |
462 | nilfs_close_segment_entry(ent, sufile); | ||
463 | nilfs_free_segment_entry(ent); | 451 | nilfs_free_segment_entry(ent); |
464 | } | 452 | } |
465 | 453 | ||
diff --git a/fs/nilfs2/sufile.c b/fs/nilfs2/sufile.c index c774cf397e2f..98e68677f045 100644 --- a/fs/nilfs2/sufile.c +++ b/fs/nilfs2/sufile.c | |||
@@ -93,6 +93,52 @@ nilfs_sufile_get_segment_usage_block(struct inode *sufile, __u64 segnum, | |||
93 | create, NULL, bhp); | 93 | create, NULL, bhp); |
94 | } | 94 | } |
95 | 95 | ||
96 | static void nilfs_sufile_mod_counter(struct buffer_head *header_bh, | ||
97 | u64 ncleanadd, u64 ndirtyadd) | ||
98 | { | ||
99 | struct nilfs_sufile_header *header; | ||
100 | void *kaddr; | ||
101 | |||
102 | kaddr = kmap_atomic(header_bh->b_page, KM_USER0); | ||
103 | header = kaddr + bh_offset(header_bh); | ||
104 | le64_add_cpu(&header->sh_ncleansegs, ncleanadd); | ||
105 | le64_add_cpu(&header->sh_ndirtysegs, ndirtyadd); | ||
106 | kunmap_atomic(kaddr, KM_USER0); | ||
107 | |||
108 | nilfs_mdt_mark_buffer_dirty(header_bh); | ||
109 | } | ||
110 | |||
111 | int nilfs_sufile_update(struct inode *sufile, __u64 segnum, int create, | ||
112 | void (*dofunc)(struct inode *, __u64, | ||
113 | struct buffer_head *, | ||
114 | struct buffer_head *)) | ||
115 | { | ||
116 | struct buffer_head *header_bh, *bh; | ||
117 | int ret; | ||
118 | |||
119 | if (unlikely(segnum >= nilfs_sufile_get_nsegments(sufile))) { | ||
120 | printk(KERN_WARNING "%s: invalid segment number: %llu\n", | ||
121 | __func__, (unsigned long long)segnum); | ||
122 | return -EINVAL; | ||
123 | } | ||
124 | down_write(&NILFS_MDT(sufile)->mi_sem); | ||
125 | |||
126 | ret = nilfs_sufile_get_header_block(sufile, &header_bh); | ||
127 | if (ret < 0) | ||
128 | goto out_sem; | ||
129 | |||
130 | ret = nilfs_sufile_get_segment_usage_block(sufile, segnum, create, &bh); | ||
131 | if (!ret) { | ||
132 | dofunc(sufile, segnum, header_bh, bh); | ||
133 | brelse(bh); | ||
134 | } | ||
135 | brelse(header_bh); | ||
136 | |||
137 | out_sem: | ||
138 | up_write(&NILFS_MDT(sufile)->mi_sem); | ||
139 | return ret; | ||
140 | } | ||
141 | |||
96 | /** | 142 | /** |
97 | * nilfs_sufile_alloc - allocate a segment | 143 | * nilfs_sufile_alloc - allocate a segment |
98 | * @sufile: inode of segment usage file | 144 | * @sufile: inode of segment usage file |
@@ -113,7 +159,6 @@ nilfs_sufile_get_segment_usage_block(struct inode *sufile, __u64 segnum, | |||
113 | int nilfs_sufile_alloc(struct inode *sufile, __u64 *segnump) | 159 | int nilfs_sufile_alloc(struct inode *sufile, __u64 *segnump) |
114 | { | 160 | { |
115 | struct buffer_head *header_bh, *su_bh; | 161 | struct buffer_head *header_bh, *su_bh; |
116 | struct the_nilfs *nilfs; | ||
117 | struct nilfs_sufile_header *header; | 162 | struct nilfs_sufile_header *header; |
118 | struct nilfs_segment_usage *su; | 163 | struct nilfs_segment_usage *su; |
119 | size_t susz = NILFS_MDT(sufile)->mi_entry_size; | 164 | size_t susz = NILFS_MDT(sufile)->mi_entry_size; |
@@ -124,8 +169,6 @@ int nilfs_sufile_alloc(struct inode *sufile, __u64 *segnump) | |||
124 | 169 | ||
125 | down_write(&NILFS_MDT(sufile)->mi_sem); | 170 | down_write(&NILFS_MDT(sufile)->mi_sem); |
126 | 171 | ||
127 | nilfs = NILFS_MDT(sufile)->mi_nilfs; | ||
128 | |||
129 | ret = nilfs_sufile_get_header_block(sufile, &header_bh); | 172 | ret = nilfs_sufile_get_header_block(sufile, &header_bh); |
130 | if (ret < 0) | 173 | if (ret < 0) |
131 | goto out_sem; | 174 | goto out_sem; |
@@ -192,165 +235,84 @@ int nilfs_sufile_alloc(struct inode *sufile, __u64 *segnump) | |||
192 | return ret; | 235 | return ret; |
193 | } | 236 | } |
194 | 237 | ||
195 | /** | 238 | void nilfs_sufile_do_cancel_free(struct inode *sufile, __u64 segnum, |
196 | * nilfs_sufile_cancel_free - | 239 | struct buffer_head *header_bh, |
197 | * @sufile: inode of segment usage file | 240 | struct buffer_head *su_bh) |
198 | * @segnum: segment number | ||
199 | * | ||
200 | * Description: | ||
201 | * | ||
202 | * Return Value: On success, 0 is returned. On error, one of the following | ||
203 | * negative error codes is returned. | ||
204 | * | ||
205 | * %-EIO - I/O error. | ||
206 | * | ||
207 | * %-ENOMEM - Insufficient amount of memory available. | ||
208 | */ | ||
209 | int nilfs_sufile_cancel_free(struct inode *sufile, __u64 segnum) | ||
210 | { | 241 | { |
211 | struct buffer_head *header_bh, *su_bh; | ||
212 | struct the_nilfs *nilfs; | ||
213 | struct nilfs_sufile_header *header; | ||
214 | struct nilfs_segment_usage *su; | 242 | struct nilfs_segment_usage *su; |
215 | void *kaddr; | 243 | void *kaddr; |
216 | int ret; | ||
217 | |||
218 | down_write(&NILFS_MDT(sufile)->mi_sem); | ||
219 | |||
220 | nilfs = NILFS_MDT(sufile)->mi_nilfs; | ||
221 | |||
222 | ret = nilfs_sufile_get_header_block(sufile, &header_bh); | ||
223 | if (ret < 0) | ||
224 | goto out_sem; | ||
225 | |||
226 | ret = nilfs_sufile_get_segment_usage_block(sufile, segnum, 0, &su_bh); | ||
227 | if (ret < 0) | ||
228 | goto out_header; | ||
229 | 244 | ||
230 | kaddr = kmap_atomic(su_bh->b_page, KM_USER0); | 245 | kaddr = kmap_atomic(su_bh->b_page, KM_USER0); |
231 | su = nilfs_sufile_block_get_segment_usage( | 246 | su = nilfs_sufile_block_get_segment_usage(sufile, segnum, su_bh, kaddr); |
232 | sufile, segnum, su_bh, kaddr); | ||
233 | if (unlikely(!nilfs_segment_usage_clean(su))) { | 247 | if (unlikely(!nilfs_segment_usage_clean(su))) { |
234 | printk(KERN_WARNING "%s: segment %llu must be clean\n", | 248 | printk(KERN_WARNING "%s: segment %llu must be clean\n", |
235 | __func__, (unsigned long long)segnum); | 249 | __func__, (unsigned long long)segnum); |
236 | kunmap_atomic(kaddr, KM_USER0); | 250 | kunmap_atomic(kaddr, KM_USER0); |
237 | goto out_su_bh; | 251 | return; |
238 | } | 252 | } |
239 | nilfs_segment_usage_set_dirty(su); | 253 | nilfs_segment_usage_set_dirty(su); |
240 | kunmap_atomic(kaddr, KM_USER0); | 254 | kunmap_atomic(kaddr, KM_USER0); |
241 | 255 | ||
242 | kaddr = kmap_atomic(header_bh->b_page, KM_USER0); | 256 | nilfs_sufile_mod_counter(header_bh, -1, 1); |
243 | header = nilfs_sufile_block_get_header(sufile, header_bh, kaddr); | ||
244 | le64_add_cpu(&header->sh_ncleansegs, -1); | ||
245 | le64_add_cpu(&header->sh_ndirtysegs, 1); | ||
246 | kunmap_atomic(kaddr, KM_USER0); | ||
247 | |||
248 | nilfs_mdt_mark_buffer_dirty(header_bh); | ||
249 | nilfs_mdt_mark_buffer_dirty(su_bh); | 257 | nilfs_mdt_mark_buffer_dirty(su_bh); |
250 | nilfs_mdt_mark_dirty(sufile); | 258 | nilfs_mdt_mark_dirty(sufile); |
251 | |||
252 | out_su_bh: | ||
253 | brelse(su_bh); | ||
254 | out_header: | ||
255 | brelse(header_bh); | ||
256 | out_sem: | ||
257 | up_write(&NILFS_MDT(sufile)->mi_sem); | ||
258 | return ret; | ||
259 | } | 259 | } |
260 | 260 | ||
261 | /** | 261 | void nilfs_sufile_do_scrap(struct inode *sufile, __u64 segnum, |
262 | * nilfs_sufile_freev - free segments | 262 | struct buffer_head *header_bh, |
263 | * @sufile: inode of segment usage file | 263 | struct buffer_head *su_bh) |
264 | * @segnum: array of segment numbers | ||
265 | * @nsegs: number of segments | ||
266 | * | ||
267 | * Description: nilfs_sufile_freev() frees segments specified by @segnum and | ||
268 | * @nsegs, which must have been returned by a previous call to | ||
269 | * nilfs_sufile_alloc(). | ||
270 | * | ||
271 | * Return Value: On success, 0 is returned. On error, one of the following | ||
272 | * negative error codes is returned. | ||
273 | * | ||
274 | * %-EIO - I/O error. | ||
275 | * | ||
276 | * %-ENOMEM - Insufficient amount of memory available. | ||
277 | */ | ||
278 | #define NILFS_SUFILE_FREEV_PREALLOC 16 | ||
279 | int nilfs_sufile_freev(struct inode *sufile, __u64 *segnum, size_t nsegs) | ||
280 | { | 264 | { |
281 | struct buffer_head *header_bh, **su_bh, | ||
282 | *su_bh_prealloc[NILFS_SUFILE_FREEV_PREALLOC]; | ||
283 | struct the_nilfs *nilfs; | ||
284 | struct nilfs_sufile_header *header; | ||
285 | struct nilfs_segment_usage *su; | 265 | struct nilfs_segment_usage *su; |
286 | void *kaddr; | 266 | void *kaddr; |
287 | int ret, i; | 267 | int clean, dirty; |
288 | 268 | ||
289 | down_write(&NILFS_MDT(sufile)->mi_sem); | 269 | kaddr = kmap_atomic(su_bh->b_page, KM_USER0); |
290 | 270 | su = nilfs_sufile_block_get_segment_usage(sufile, segnum, su_bh, kaddr); | |
291 | nilfs = NILFS_MDT(sufile)->mi_nilfs; | 271 | if (su->su_flags == cpu_to_le32(1UL << NILFS_SEGMENT_USAGE_DIRTY) && |
292 | 272 | su->su_nblocks == cpu_to_le32(0)) { | |
293 | /* prepare resources */ | ||
294 | if (nsegs <= NILFS_SUFILE_FREEV_PREALLOC) | ||
295 | su_bh = su_bh_prealloc; | ||
296 | else { | ||
297 | su_bh = kmalloc(sizeof(*su_bh) * nsegs, GFP_NOFS); | ||
298 | if (su_bh == NULL) { | ||
299 | ret = -ENOMEM; | ||
300 | goto out_sem; | ||
301 | } | ||
302 | } | ||
303 | |||
304 | ret = nilfs_sufile_get_header_block(sufile, &header_bh); | ||
305 | if (ret < 0) | ||
306 | goto out_su_bh; | ||
307 | for (i = 0; i < nsegs; i++) { | ||
308 | ret = nilfs_sufile_get_segment_usage_block(sufile, segnum[i], | ||
309 | 0, &su_bh[i]); | ||
310 | if (ret < 0) | ||
311 | goto out_bh; | ||
312 | } | ||
313 | |||
314 | /* free segments */ | ||
315 | for (i = 0; i < nsegs; i++) { | ||
316 | kaddr = kmap_atomic(su_bh[i]->b_page, KM_USER0); | ||
317 | su = nilfs_sufile_block_get_segment_usage( | ||
318 | sufile, segnum[i], su_bh[i], kaddr); | ||
319 | WARN_ON(nilfs_segment_usage_error(su)); | ||
320 | nilfs_segment_usage_set_clean(su); | ||
321 | kunmap_atomic(kaddr, KM_USER0); | 273 | kunmap_atomic(kaddr, KM_USER0); |
322 | nilfs_mdt_mark_buffer_dirty(su_bh[i]); | 274 | return; |
323 | } | 275 | } |
324 | kaddr = kmap_atomic(header_bh->b_page, KM_USER0); | 276 | clean = nilfs_segment_usage_clean(su); |
325 | header = nilfs_sufile_block_get_header(sufile, header_bh, kaddr); | 277 | dirty = nilfs_segment_usage_dirty(su); |
326 | le64_add_cpu(&header->sh_ncleansegs, nsegs); | 278 | |
327 | le64_add_cpu(&header->sh_ndirtysegs, -(u64)nsegs); | 279 | /* make the segment garbage */ |
280 | su->su_lastmod = cpu_to_le64(0); | ||
281 | su->su_nblocks = cpu_to_le32(0); | ||
282 | su->su_flags = cpu_to_le32(1UL << NILFS_SEGMENT_USAGE_DIRTY); | ||
328 | kunmap_atomic(kaddr, KM_USER0); | 283 | kunmap_atomic(kaddr, KM_USER0); |
329 | nilfs_mdt_mark_buffer_dirty(header_bh); | 284 | |
285 | nilfs_sufile_mod_counter(header_bh, clean ? (u64)-1 : 0, dirty ? 0 : 1); | ||
286 | nilfs_mdt_mark_buffer_dirty(su_bh); | ||
330 | nilfs_mdt_mark_dirty(sufile); | 287 | nilfs_mdt_mark_dirty(sufile); |
288 | } | ||
331 | 289 | ||
332 | out_bh: | 290 | void nilfs_sufile_do_free(struct inode *sufile, __u64 segnum, |
333 | for (i--; i >= 0; i--) | 291 | struct buffer_head *header_bh, |
334 | brelse(su_bh[i]); | 292 | struct buffer_head *su_bh) |
335 | brelse(header_bh); | 293 | { |
294 | struct nilfs_segment_usage *su; | ||
295 | void *kaddr; | ||
296 | int sudirty; | ||
336 | 297 | ||
337 | out_su_bh: | 298 | kaddr = kmap_atomic(su_bh->b_page, KM_USER0); |
338 | if (su_bh != su_bh_prealloc) | 299 | su = nilfs_sufile_block_get_segment_usage(sufile, segnum, su_bh, kaddr); |
339 | kfree(su_bh); | 300 | if (nilfs_segment_usage_clean(su)) { |
301 | printk(KERN_WARNING "%s: segment %llu is already clean\n", | ||
302 | __func__, (unsigned long long)segnum); | ||
303 | kunmap_atomic(kaddr, KM_USER0); | ||
304 | return; | ||
305 | } | ||
306 | WARN_ON(nilfs_segment_usage_error(su)); | ||
307 | WARN_ON(!nilfs_segment_usage_dirty(su)); | ||
340 | 308 | ||
341 | out_sem: | 309 | sudirty = nilfs_segment_usage_dirty(su); |
342 | up_write(&NILFS_MDT(sufile)->mi_sem); | 310 | nilfs_segment_usage_set_clean(su); |
343 | return ret; | 311 | kunmap_atomic(kaddr, KM_USER0); |
344 | } | 312 | nilfs_mdt_mark_buffer_dirty(su_bh); |
345 | 313 | ||
346 | /** | 314 | nilfs_sufile_mod_counter(header_bh, 1, sudirty ? (u64)-1 : 0); |
347 | * nilfs_sufile_free - | 315 | nilfs_mdt_mark_dirty(sufile); |
348 | * @sufile: | ||
349 | * @segnum: | ||
350 | */ | ||
351 | int nilfs_sufile_free(struct inode *sufile, __u64 segnum) | ||
352 | { | ||
353 | return nilfs_sufile_freev(sufile, &segnum, 1); | ||
354 | } | 316 | } |
355 | 317 | ||
356 | /** | 318 | /** |
@@ -500,72 +462,28 @@ int nilfs_sufile_get_ncleansegs(struct inode *sufile, unsigned long *nsegsp) | |||
500 | return ret; | 462 | return ret; |
501 | } | 463 | } |
502 | 464 | ||
503 | /** | 465 | void nilfs_sufile_do_set_error(struct inode *sufile, __u64 segnum, |
504 | * nilfs_sufile_set_error - mark a segment as erroneous | 466 | struct buffer_head *header_bh, |
505 | * @sufile: inode of segment usage file | 467 | struct buffer_head *su_bh) |
506 | * @segnum: segment number | ||
507 | * | ||
508 | * Description: nilfs_sufile_set_error() marks the segment specified by | ||
509 | * @segnum as erroneous. The error segment will never be used again. | ||
510 | * | ||
511 | * Return Value: On success, 0 is returned. On error, one of the following | ||
512 | * negative error codes is returned. | ||
513 | * | ||
514 | * %-EIO - I/O error. | ||
515 | * | ||
516 | * %-ENOMEM - Insufficient amount of memory available. | ||
517 | * | ||
518 | * %-EINVAL - Invalid segment usage number. | ||
519 | */ | ||
520 | int nilfs_sufile_set_error(struct inode *sufile, __u64 segnum) | ||
521 | { | 468 | { |
522 | struct buffer_head *header_bh, *su_bh; | ||
523 | struct nilfs_segment_usage *su; | 469 | struct nilfs_segment_usage *su; |
524 | struct nilfs_sufile_header *header; | ||
525 | void *kaddr; | 470 | void *kaddr; |
526 | int ret; | 471 | int suclean; |
527 | |||
528 | if (unlikely(segnum >= nilfs_sufile_get_nsegments(sufile))) { | ||
529 | printk(KERN_WARNING "%s: invalid segment number: %llu\n", | ||
530 | __func__, (unsigned long long)segnum); | ||
531 | return -EINVAL; | ||
532 | } | ||
533 | down_write(&NILFS_MDT(sufile)->mi_sem); | ||
534 | |||
535 | ret = nilfs_sufile_get_header_block(sufile, &header_bh); | ||
536 | if (ret < 0) | ||
537 | goto out_sem; | ||
538 | ret = nilfs_sufile_get_segment_usage_block(sufile, segnum, 0, &su_bh); | ||
539 | if (ret < 0) | ||
540 | goto out_header; | ||
541 | 472 | ||
542 | kaddr = kmap_atomic(su_bh->b_page, KM_USER0); | 473 | kaddr = kmap_atomic(su_bh->b_page, KM_USER0); |
543 | su = nilfs_sufile_block_get_segment_usage(sufile, segnum, su_bh, kaddr); | 474 | su = nilfs_sufile_block_get_segment_usage(sufile, segnum, su_bh, kaddr); |
544 | if (nilfs_segment_usage_error(su)) { | 475 | if (nilfs_segment_usage_error(su)) { |
545 | kunmap_atomic(kaddr, KM_USER0); | 476 | kunmap_atomic(kaddr, KM_USER0); |
546 | brelse(su_bh); | 477 | return; |
547 | goto out_header; | ||
548 | } | 478 | } |
549 | 479 | suclean = nilfs_segment_usage_clean(su); | |
550 | nilfs_segment_usage_set_error(su); | 480 | nilfs_segment_usage_set_error(su); |
551 | kunmap_atomic(kaddr, KM_USER0); | 481 | kunmap_atomic(kaddr, KM_USER0); |
552 | brelse(su_bh); | ||
553 | 482 | ||
554 | kaddr = kmap_atomic(header_bh->b_page, KM_USER0); | 483 | if (suclean) |
555 | header = nilfs_sufile_block_get_header(sufile, header_bh, kaddr); | 484 | nilfs_sufile_mod_counter(header_bh, -1, 0); |
556 | le64_add_cpu(&header->sh_ndirtysegs, -1); | ||
557 | kunmap_atomic(kaddr, KM_USER0); | ||
558 | nilfs_mdt_mark_buffer_dirty(header_bh); | ||
559 | nilfs_mdt_mark_buffer_dirty(su_bh); | 485 | nilfs_mdt_mark_buffer_dirty(su_bh); |
560 | nilfs_mdt_mark_dirty(sufile); | 486 | nilfs_mdt_mark_dirty(sufile); |
561 | brelse(su_bh); | ||
562 | |||
563 | out_header: | ||
564 | brelse(header_bh); | ||
565 | |||
566 | out_sem: | ||
567 | up_write(&NILFS_MDT(sufile)->mi_sem); | ||
568 | return ret; | ||
569 | } | 487 | } |
570 | 488 | ||
571 | /** | 489 | /** |
@@ -625,7 +543,7 @@ ssize_t nilfs_sufile_get_suinfo(struct inode *sufile, __u64 segnum, | |||
625 | si[i + j].sui_nblocks = le32_to_cpu(su->su_nblocks); | 543 | si[i + j].sui_nblocks = le32_to_cpu(su->su_nblocks); |
626 | si[i + j].sui_flags = le32_to_cpu(su->su_flags) & | 544 | si[i + j].sui_flags = le32_to_cpu(su->su_flags) & |
627 | ~(1UL << NILFS_SEGMENT_USAGE_ACTIVE); | 545 | ~(1UL << NILFS_SEGMENT_USAGE_ACTIVE); |
628 | if (nilfs_segment_is_active(nilfs, segnum + i + j)) | 546 | if (nilfs_segment_is_active(nilfs, segnum + j)) |
629 | si[i + j].sui_flags |= | 547 | si[i + j].sui_flags |= |
630 | (1UL << NILFS_SEGMENT_USAGE_ACTIVE); | 548 | (1UL << NILFS_SEGMENT_USAGE_ACTIVE); |
631 | } | 549 | } |
diff --git a/fs/nilfs2/sufile.h b/fs/nilfs2/sufile.h index d595f33a768d..a2e2efd4ade1 100644 --- a/fs/nilfs2/sufile.h +++ b/fs/nilfs2/sufile.h | |||
@@ -36,9 +36,6 @@ static inline unsigned long nilfs_sufile_get_nsegments(struct inode *sufile) | |||
36 | } | 36 | } |
37 | 37 | ||
38 | int nilfs_sufile_alloc(struct inode *, __u64 *); | 38 | int nilfs_sufile_alloc(struct inode *, __u64 *); |
39 | int nilfs_sufile_cancel_free(struct inode *, __u64); | ||
40 | int nilfs_sufile_freev(struct inode *, __u64 *, size_t); | ||
41 | int nilfs_sufile_free(struct inode *, __u64); | ||
42 | int nilfs_sufile_get_segment_usage(struct inode *, __u64, | 39 | int nilfs_sufile_get_segment_usage(struct inode *, __u64, |
43 | struct nilfs_segment_usage **, | 40 | struct nilfs_segment_usage **, |
44 | struct buffer_head **); | 41 | struct buffer_head **); |
@@ -46,9 +43,83 @@ void nilfs_sufile_put_segment_usage(struct inode *, __u64, | |||
46 | struct buffer_head *); | 43 | struct buffer_head *); |
47 | int nilfs_sufile_get_stat(struct inode *, struct nilfs_sustat *); | 44 | int nilfs_sufile_get_stat(struct inode *, struct nilfs_sustat *); |
48 | int nilfs_sufile_get_ncleansegs(struct inode *, unsigned long *); | 45 | int nilfs_sufile_get_ncleansegs(struct inode *, unsigned long *); |
49 | int nilfs_sufile_set_error(struct inode *, __u64); | ||
50 | ssize_t nilfs_sufile_get_suinfo(struct inode *, __u64, struct nilfs_suinfo *, | 46 | ssize_t nilfs_sufile_get_suinfo(struct inode *, __u64, struct nilfs_suinfo *, |
51 | size_t); | 47 | size_t); |
52 | 48 | ||
49 | int nilfs_sufile_update(struct inode *, __u64, int, | ||
50 | void (*dofunc)(struct inode *, __u64, | ||
51 | struct buffer_head *, | ||
52 | struct buffer_head *)); | ||
53 | void nilfs_sufile_do_cancel_free(struct inode *, __u64, struct buffer_head *, | ||
54 | struct buffer_head *); | ||
55 | void nilfs_sufile_do_scrap(struct inode *, __u64, struct buffer_head *, | ||
56 | struct buffer_head *); | ||
57 | void nilfs_sufile_do_free(struct inode *, __u64, struct buffer_head *, | ||
58 | struct buffer_head *); | ||
59 | void nilfs_sufile_do_set_error(struct inode *, __u64, struct buffer_head *, | ||
60 | struct buffer_head *); | ||
61 | |||
62 | /** | ||
63 | * nilfs_sufile_cancel_free - | ||
64 | * @sufile: inode of segment usage file | ||
65 | * @segnum: segment number | ||
66 | * | ||
67 | * Description: | ||
68 | * | ||
69 | * Return Value: On success, 0 is returned. On error, one of the following | ||
70 | * negative error codes is returned. | ||
71 | * | ||
72 | * %-EIO - I/O error. | ||
73 | * | ||
74 | * %-ENOMEM - Insufficient amount of memory available. | ||
75 | */ | ||
76 | static inline int nilfs_sufile_cancel_free(struct inode *sufile, __u64 segnum) | ||
77 | { | ||
78 | return nilfs_sufile_update(sufile, segnum, 0, | ||
79 | nilfs_sufile_do_cancel_free); | ||
80 | } | ||
81 | |||
82 | /** | ||
83 | * nilfs_sufile_scrap - make a segment garbage | ||
84 | * @sufile: inode of segment usage file | ||
85 | * @segnum: segment number to be freed | ||
86 | */ | ||
87 | static inline int nilfs_sufile_scrap(struct inode *sufile, __u64 segnum) | ||
88 | { | ||
89 | return nilfs_sufile_update(sufile, segnum, 1, nilfs_sufile_do_scrap); | ||
90 | } | ||
91 | |||
92 | /** | ||
93 | * nilfs_sufile_free - free segment | ||
94 | * @sufile: inode of segment usage file | ||
95 | * @segnum: segment number to be freed | ||
96 | */ | ||
97 | static inline int nilfs_sufile_free(struct inode *sufile, __u64 segnum) | ||
98 | { | ||
99 | return nilfs_sufile_update(sufile, segnum, 0, nilfs_sufile_do_free); | ||
100 | } | ||
101 | |||
102 | /** | ||
103 | * nilfs_sufile_set_error - mark a segment as erroneous | ||
104 | * @sufile: inode of segment usage file | ||
105 | * @segnum: segment number | ||
106 | * | ||
107 | * Description: nilfs_sufile_set_error() marks the segment specified by | ||
108 | * @segnum as erroneous. The error segment will never be used again. | ||
109 | * | ||
110 | * Return Value: On success, 0 is returned. On error, one of the following | ||
111 | * negative error codes is returned. | ||
112 | * | ||
113 | * %-EIO - I/O error. | ||
114 | * | ||
115 | * %-ENOMEM - Insufficient amount of memory available. | ||
116 | * | ||
117 | * %-EINVAL - Invalid segment usage number. | ||
118 | */ | ||
119 | static inline int nilfs_sufile_set_error(struct inode *sufile, __u64 segnum) | ||
120 | { | ||
121 | return nilfs_sufile_update(sufile, segnum, 0, | ||
122 | nilfs_sufile_do_set_error); | ||
123 | } | ||
53 | 124 | ||
54 | #endif /* _NILFS_SUFILE_H */ | 125 | #endif /* _NILFS_SUFILE_H */ |
diff --git a/fs/nilfs2/super.c b/fs/nilfs2/super.c index e117e1ea9bff..6989b03e97ab 100644 --- a/fs/nilfs2/super.c +++ b/fs/nilfs2/super.c | |||
@@ -63,7 +63,6 @@ | |||
63 | MODULE_AUTHOR("NTT Corp."); | 63 | MODULE_AUTHOR("NTT Corp."); |
64 | MODULE_DESCRIPTION("A New Implementation of the Log-structured Filesystem " | 64 | MODULE_DESCRIPTION("A New Implementation of the Log-structured Filesystem " |
65 | "(NILFS)"); | 65 | "(NILFS)"); |
66 | MODULE_VERSION(NILFS_VERSION); | ||
67 | MODULE_LICENSE("GPL"); | 66 | MODULE_LICENSE("GPL"); |
68 | 67 | ||
69 | static int nilfs_remount(struct super_block *sb, int *flags, char *data); | 68 | static int nilfs_remount(struct super_block *sb, int *flags, char *data); |
@@ -476,11 +475,12 @@ static int nilfs_statfs(struct dentry *dentry, struct kstatfs *buf) | |||
476 | { | 475 | { |
477 | struct super_block *sb = dentry->d_sb; | 476 | struct super_block *sb = dentry->d_sb; |
478 | struct nilfs_sb_info *sbi = NILFS_SB(sb); | 477 | struct nilfs_sb_info *sbi = NILFS_SB(sb); |
478 | struct the_nilfs *nilfs = sbi->s_nilfs; | ||
479 | u64 id = huge_encode_dev(sb->s_bdev->bd_dev); | ||
479 | unsigned long long blocks; | 480 | unsigned long long blocks; |
480 | unsigned long overhead; | 481 | unsigned long overhead; |
481 | unsigned long nrsvblocks; | 482 | unsigned long nrsvblocks; |
482 | sector_t nfreeblocks; | 483 | sector_t nfreeblocks; |
483 | struct the_nilfs *nilfs = sbi->s_nilfs; | ||
484 | int err; | 484 | int err; |
485 | 485 | ||
486 | /* | 486 | /* |
@@ -514,6 +514,9 @@ static int nilfs_statfs(struct dentry *dentry, struct kstatfs *buf) | |||
514 | buf->f_files = atomic_read(&sbi->s_inodes_count); | 514 | buf->f_files = atomic_read(&sbi->s_inodes_count); |
515 | buf->f_ffree = 0; /* nilfs_count_free_inodes(sb); */ | 515 | buf->f_ffree = 0; /* nilfs_count_free_inodes(sb); */ |
516 | buf->f_namelen = NILFS_NAME_LEN; | 516 | buf->f_namelen = NILFS_NAME_LEN; |
517 | buf->f_fsid.val[0] = (u32)id; | ||
518 | buf->f_fsid.val[1] = (u32)(id >> 32); | ||
519 | |||
517 | return 0; | 520 | return 0; |
518 | } | 521 | } |
519 | 522 | ||
diff --git a/fs/nilfs2/the_nilfs.c b/fs/nilfs2/the_nilfs.c index 33400cf0bbe2..7f65b3be4aa9 100644 --- a/fs/nilfs2/the_nilfs.c +++ b/fs/nilfs2/the_nilfs.c | |||
@@ -115,6 +115,7 @@ void put_nilfs(struct the_nilfs *nilfs) | |||
115 | static int nilfs_load_super_root(struct the_nilfs *nilfs, | 115 | static int nilfs_load_super_root(struct the_nilfs *nilfs, |
116 | struct nilfs_sb_info *sbi, sector_t sr_block) | 116 | struct nilfs_sb_info *sbi, sector_t sr_block) |
117 | { | 117 | { |
118 | static struct lock_class_key dat_lock_key; | ||
118 | struct buffer_head *bh_sr; | 119 | struct buffer_head *bh_sr; |
119 | struct nilfs_super_root *raw_sr; | 120 | struct nilfs_super_root *raw_sr; |
120 | struct nilfs_super_block **sbp = nilfs->ns_sbp; | 121 | struct nilfs_super_block **sbp = nilfs->ns_sbp; |
@@ -163,6 +164,9 @@ static int nilfs_load_super_root(struct the_nilfs *nilfs, | |||
163 | if (unlikely(err)) | 164 | if (unlikely(err)) |
164 | goto failed_sufile; | 165 | goto failed_sufile; |
165 | 166 | ||
167 | lockdep_set_class(&NILFS_MDT(nilfs->ns_dat)->mi_sem, &dat_lock_key); | ||
168 | lockdep_set_class(&NILFS_MDT(nilfs->ns_gc_dat)->mi_sem, &dat_lock_key); | ||
169 | |||
166 | nilfs_mdt_set_shadow(nilfs->ns_dat, nilfs->ns_gc_dat); | 170 | nilfs_mdt_set_shadow(nilfs->ns_dat, nilfs->ns_gc_dat); |
167 | nilfs_mdt_set_entry_size(nilfs->ns_cpfile, checkpoint_size, | 171 | nilfs_mdt_set_entry_size(nilfs->ns_cpfile, checkpoint_size, |
168 | sizeof(struct nilfs_cpfile_header)); | 172 | sizeof(struct nilfs_cpfile_header)); |
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c index 8672b9536039..c2a87c885b73 100644 --- a/fs/ocfs2/file.c +++ b/fs/ocfs2/file.c | |||
@@ -1912,6 +1912,22 @@ out_sems: | |||
1912 | return written ? written : ret; | 1912 | return written ? written : ret; |
1913 | } | 1913 | } |
1914 | 1914 | ||
1915 | static int ocfs2_splice_to_file(struct pipe_inode_info *pipe, | ||
1916 | struct file *out, | ||
1917 | struct splice_desc *sd) | ||
1918 | { | ||
1919 | int ret; | ||
1920 | |||
1921 | ret = ocfs2_prepare_inode_for_write(out->f_path.dentry, &sd->pos, | ||
1922 | sd->total_len, 0, NULL); | ||
1923 | if (ret < 0) { | ||
1924 | mlog_errno(ret); | ||
1925 | return ret; | ||
1926 | } | ||
1927 | |||
1928 | return splice_from_pipe_feed(pipe, sd, pipe_to_file); | ||
1929 | } | ||
1930 | |||
1915 | static ssize_t ocfs2_file_splice_write(struct pipe_inode_info *pipe, | 1931 | static ssize_t ocfs2_file_splice_write(struct pipe_inode_info *pipe, |
1916 | struct file *out, | 1932 | struct file *out, |
1917 | loff_t *ppos, | 1933 | loff_t *ppos, |
@@ -1919,38 +1935,76 @@ static ssize_t ocfs2_file_splice_write(struct pipe_inode_info *pipe, | |||
1919 | unsigned int flags) | 1935 | unsigned int flags) |
1920 | { | 1936 | { |
1921 | int ret; | 1937 | int ret; |
1922 | struct inode *inode = out->f_path.dentry->d_inode; | 1938 | struct address_space *mapping = out->f_mapping; |
1939 | struct inode *inode = mapping->host; | ||
1940 | struct splice_desc sd = { | ||
1941 | .total_len = len, | ||
1942 | .flags = flags, | ||
1943 | .pos = *ppos, | ||
1944 | .u.file = out, | ||
1945 | }; | ||
1923 | 1946 | ||
1924 | mlog_entry("(0x%p, 0x%p, %u, '%.*s')\n", out, pipe, | 1947 | mlog_entry("(0x%p, 0x%p, %u, '%.*s')\n", out, pipe, |
1925 | (unsigned int)len, | 1948 | (unsigned int)len, |
1926 | out->f_path.dentry->d_name.len, | 1949 | out->f_path.dentry->d_name.len, |
1927 | out->f_path.dentry->d_name.name); | 1950 | out->f_path.dentry->d_name.name); |
1928 | 1951 | ||
1929 | mutex_lock_nested(&inode->i_mutex, I_MUTEX_PARENT); | 1952 | if (pipe->inode) |
1953 | mutex_lock_nested(&pipe->inode->i_mutex, I_MUTEX_PARENT); | ||
1930 | 1954 | ||
1931 | ret = ocfs2_rw_lock(inode, 1); | 1955 | splice_from_pipe_begin(&sd); |
1932 | if (ret < 0) { | 1956 | do { |
1933 | mlog_errno(ret); | 1957 | ret = splice_from_pipe_next(pipe, &sd); |
1934 | goto out; | 1958 | if (ret <= 0) |
1935 | } | 1959 | break; |
1936 | 1960 | ||
1937 | ret = ocfs2_prepare_inode_for_write(out->f_path.dentry, ppos, len, 0, | 1961 | mutex_lock_nested(&inode->i_mutex, I_MUTEX_CHILD); |
1938 | NULL); | 1962 | ret = ocfs2_rw_lock(inode, 1); |
1939 | if (ret < 0) { | 1963 | if (ret < 0) |
1940 | mlog_errno(ret); | 1964 | mlog_errno(ret); |
1941 | goto out_unlock; | 1965 | else { |
1942 | } | 1966 | ret = ocfs2_splice_to_file(pipe, out, &sd); |
1967 | ocfs2_rw_unlock(inode, 1); | ||
1968 | } | ||
1969 | mutex_unlock(&inode->i_mutex); | ||
1970 | } while (ret > 0); | ||
1971 | splice_from_pipe_end(pipe, &sd); | ||
1943 | 1972 | ||
1944 | if (pipe->inode) | 1973 | if (pipe->inode) |
1945 | mutex_lock_nested(&pipe->inode->i_mutex, I_MUTEX_CHILD); | ||
1946 | ret = generic_file_splice_write_nolock(pipe, out, ppos, len, flags); | ||
1947 | if (pipe->inode) | ||
1948 | mutex_unlock(&pipe->inode->i_mutex); | 1974 | mutex_unlock(&pipe->inode->i_mutex); |
1949 | 1975 | ||
1950 | out_unlock: | 1976 | if (sd.num_spliced) |
1951 | ocfs2_rw_unlock(inode, 1); | 1977 | ret = sd.num_spliced; |
1952 | out: | 1978 | |
1953 | mutex_unlock(&inode->i_mutex); | 1979 | if (ret > 0) { |
1980 | unsigned long nr_pages; | ||
1981 | |||
1982 | *ppos += ret; | ||
1983 | nr_pages = (ret + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; | ||
1984 | |||
1985 | /* | ||
1986 | * If file or inode is SYNC and we actually wrote some data, | ||
1987 | * sync it. | ||
1988 | */ | ||
1989 | if (unlikely((out->f_flags & O_SYNC) || IS_SYNC(inode))) { | ||
1990 | int err; | ||
1991 | |||
1992 | mutex_lock(&inode->i_mutex); | ||
1993 | err = ocfs2_rw_lock(inode, 1); | ||
1994 | if (err < 0) { | ||
1995 | mlog_errno(err); | ||
1996 | } else { | ||
1997 | err = generic_osync_inode(inode, mapping, | ||
1998 | OSYNC_METADATA|OSYNC_DATA); | ||
1999 | ocfs2_rw_unlock(inode, 1); | ||
2000 | } | ||
2001 | mutex_unlock(&inode->i_mutex); | ||
2002 | |||
2003 | if (err) | ||
2004 | ret = err; | ||
2005 | } | ||
2006 | balance_dirty_pages_ratelimited_nr(mapping, nr_pages); | ||
2007 | } | ||
1954 | 2008 | ||
1955 | mlog_exit(ret); | 2009 | mlog_exit(ret); |
1956 | return ret; | 2010 | return ret; |
@@ -37,6 +37,42 @@ | |||
37 | * -- Manfred Spraul <manfred@colorfullife.com> 2002-05-09 | 37 | * -- Manfred Spraul <manfred@colorfullife.com> 2002-05-09 |
38 | */ | 38 | */ |
39 | 39 | ||
40 | static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass) | ||
41 | { | ||
42 | if (pipe->inode) | ||
43 | mutex_lock_nested(&pipe->inode->i_mutex, subclass); | ||
44 | } | ||
45 | |||
46 | void pipe_lock(struct pipe_inode_info *pipe) | ||
47 | { | ||
48 | /* | ||
49 | * pipe_lock() nests non-pipe inode locks (for writing to a file) | ||
50 | */ | ||
51 | pipe_lock_nested(pipe, I_MUTEX_PARENT); | ||
52 | } | ||
53 | EXPORT_SYMBOL(pipe_lock); | ||
54 | |||
55 | void pipe_unlock(struct pipe_inode_info *pipe) | ||
56 | { | ||
57 | if (pipe->inode) | ||
58 | mutex_unlock(&pipe->inode->i_mutex); | ||
59 | } | ||
60 | EXPORT_SYMBOL(pipe_unlock); | ||
61 | |||
62 | void pipe_double_lock(struct pipe_inode_info *pipe1, | ||
63 | struct pipe_inode_info *pipe2) | ||
64 | { | ||
65 | BUG_ON(pipe1 == pipe2); | ||
66 | |||
67 | if (pipe1 < pipe2) { | ||
68 | pipe_lock_nested(pipe1, I_MUTEX_PARENT); | ||
69 | pipe_lock_nested(pipe2, I_MUTEX_CHILD); | ||
70 | } else { | ||
71 | pipe_lock_nested(pipe2, I_MUTEX_CHILD); | ||
72 | pipe_lock_nested(pipe1, I_MUTEX_PARENT); | ||
73 | } | ||
74 | } | ||
75 | |||
40 | /* Drop the inode semaphore and wait for a pipe event, atomically */ | 76 | /* Drop the inode semaphore and wait for a pipe event, atomically */ |
41 | void pipe_wait(struct pipe_inode_info *pipe) | 77 | void pipe_wait(struct pipe_inode_info *pipe) |
42 | { | 78 | { |
@@ -47,12 +83,10 @@ void pipe_wait(struct pipe_inode_info *pipe) | |||
47 | * is considered a noninteractive wait: | 83 | * is considered a noninteractive wait: |
48 | */ | 84 | */ |
49 | prepare_to_wait(&pipe->wait, &wait, TASK_INTERRUPTIBLE); | 85 | prepare_to_wait(&pipe->wait, &wait, TASK_INTERRUPTIBLE); |
50 | if (pipe->inode) | 86 | pipe_unlock(pipe); |
51 | mutex_unlock(&pipe->inode->i_mutex); | ||
52 | schedule(); | 87 | schedule(); |
53 | finish_wait(&pipe->wait, &wait); | 88 | finish_wait(&pipe->wait, &wait); |
54 | if (pipe->inode) | 89 | pipe_lock(pipe); |
55 | mutex_lock(&pipe->inode->i_mutex); | ||
56 | } | 90 | } |
57 | 91 | ||
58 | static int | 92 | static int |
diff --git a/fs/proc/base.c b/fs/proc/base.c index f71559784bfb..aa763ab00777 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c | |||
@@ -648,14 +648,14 @@ static unsigned mounts_poll(struct file *file, poll_table *wait) | |||
648 | { | 648 | { |
649 | struct proc_mounts *p = file->private_data; | 649 | struct proc_mounts *p = file->private_data; |
650 | struct mnt_namespace *ns = p->ns; | 650 | struct mnt_namespace *ns = p->ns; |
651 | unsigned res = 0; | 651 | unsigned res = POLLIN | POLLRDNORM; |
652 | 652 | ||
653 | poll_wait(file, &ns->poll, wait); | 653 | poll_wait(file, &ns->poll, wait); |
654 | 654 | ||
655 | spin_lock(&vfsmount_lock); | 655 | spin_lock(&vfsmount_lock); |
656 | if (p->event != ns->event) { | 656 | if (p->event != ns->event) { |
657 | p->event = ns->event; | 657 | p->event = ns->event; |
658 | res = POLLERR; | 658 | res |= POLLERR | POLLPRI; |
659 | } | 659 | } |
660 | spin_unlock(&vfsmount_lock); | 660 | spin_unlock(&vfsmount_lock); |
661 | 661 | ||
diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c index 12c20377772d..64a72e2e7650 100644 --- a/fs/proc/task_nommu.c +++ b/fs/proc/task_nommu.c | |||
@@ -135,7 +135,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma) | |||
135 | struct inode *inode = vma->vm_file->f_path.dentry->d_inode; | 135 | struct inode *inode = vma->vm_file->f_path.dentry->d_inode; |
136 | dev = inode->i_sb->s_dev; | 136 | dev = inode->i_sb->s_dev; |
137 | ino = inode->i_ino; | 137 | ino = inode->i_ino; |
138 | pgoff = (loff_t)vma->pg_off << PAGE_SHIFT; | 138 | pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT; |
139 | } | 139 | } |
140 | 140 | ||
141 | seq_printf(m, | 141 | seq_printf(m, |
diff --git a/fs/splice.c b/fs/splice.c index c18aa7e03e2b..666953d59a35 100644 --- a/fs/splice.c +++ b/fs/splice.c | |||
@@ -182,8 +182,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe, | |||
182 | do_wakeup = 0; | 182 | do_wakeup = 0; |
183 | page_nr = 0; | 183 | page_nr = 0; |
184 | 184 | ||
185 | if (pipe->inode) | 185 | pipe_lock(pipe); |
186 | mutex_lock(&pipe->inode->i_mutex); | ||
187 | 186 | ||
188 | for (;;) { | 187 | for (;;) { |
189 | if (!pipe->readers) { | 188 | if (!pipe->readers) { |
@@ -245,15 +244,13 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe, | |||
245 | pipe->waiting_writers--; | 244 | pipe->waiting_writers--; |
246 | } | 245 | } |
247 | 246 | ||
248 | if (pipe->inode) { | 247 | pipe_unlock(pipe); |
249 | mutex_unlock(&pipe->inode->i_mutex); | ||
250 | 248 | ||
251 | if (do_wakeup) { | 249 | if (do_wakeup) { |
252 | smp_mb(); | 250 | smp_mb(); |
253 | if (waitqueue_active(&pipe->wait)) | 251 | if (waitqueue_active(&pipe->wait)) |
254 | wake_up_interruptible(&pipe->wait); | 252 | wake_up_interruptible(&pipe->wait); |
255 | kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN); | 253 | kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN); |
256 | } | ||
257 | } | 254 | } |
258 | 255 | ||
259 | while (page_nr < spd_pages) | 256 | while (page_nr < spd_pages) |
@@ -555,8 +552,8 @@ static int pipe_to_sendpage(struct pipe_inode_info *pipe, | |||
555 | * SPLICE_F_MOVE isn't set, or we cannot move the page, we simply create | 552 | * SPLICE_F_MOVE isn't set, or we cannot move the page, we simply create |
556 | * a new page in the output file page cache and fill/dirty that. | 553 | * a new page in the output file page cache and fill/dirty that. |
557 | */ | 554 | */ |
558 | static int pipe_to_file(struct pipe_inode_info *pipe, struct pipe_buffer *buf, | 555 | int pipe_to_file(struct pipe_inode_info *pipe, struct pipe_buffer *buf, |
559 | struct splice_desc *sd) | 556 | struct splice_desc *sd) |
560 | { | 557 | { |
561 | struct file *file = sd->u.file; | 558 | struct file *file = sd->u.file; |
562 | struct address_space *mapping = file->f_mapping; | 559 | struct address_space *mapping = file->f_mapping; |
@@ -600,108 +597,177 @@ static int pipe_to_file(struct pipe_inode_info *pipe, struct pipe_buffer *buf, | |||
600 | out: | 597 | out: |
601 | return ret; | 598 | return ret; |
602 | } | 599 | } |
600 | EXPORT_SYMBOL(pipe_to_file); | ||
601 | |||
602 | static void wakeup_pipe_writers(struct pipe_inode_info *pipe) | ||
603 | { | ||
604 | smp_mb(); | ||
605 | if (waitqueue_active(&pipe->wait)) | ||
606 | wake_up_interruptible(&pipe->wait); | ||
607 | kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT); | ||
608 | } | ||
603 | 609 | ||
604 | /** | 610 | /** |
605 | * __splice_from_pipe - splice data from a pipe to given actor | 611 | * splice_from_pipe_feed - feed available data from a pipe to a file |
606 | * @pipe: pipe to splice from | 612 | * @pipe: pipe to splice from |
607 | * @sd: information to @actor | 613 | * @sd: information to @actor |
608 | * @actor: handler that splices the data | 614 | * @actor: handler that splices the data |
609 | * | 615 | * |
610 | * Description: | 616 | * Description: |
611 | * This function does little more than loop over the pipe and call | 617 | * This function loops over the pipe and calls @actor to do the |
612 | * @actor to do the actual moving of a single struct pipe_buffer to | 618 | * actual moving of a single struct pipe_buffer to the desired |
613 | * the desired destination. See pipe_to_file, pipe_to_sendpage, or | 619 | * destination. It returns when there's no more buffers left in |
614 | * pipe_to_user. | 620 | * the pipe or if the requested number of bytes (@sd->total_len) |
621 | * have been copied. It returns a positive number (one) if the | ||
622 | * pipe needs to be filled with more data, zero if the required | ||
623 | * number of bytes have been copied and -errno on error. | ||
615 | * | 624 | * |
625 | * This, together with splice_from_pipe_{begin,end,next}, may be | ||
626 | * used to implement the functionality of __splice_from_pipe() when | ||
627 | * locking is required around copying the pipe buffers to the | ||
628 | * destination. | ||
616 | */ | 629 | */ |
617 | ssize_t __splice_from_pipe(struct pipe_inode_info *pipe, struct splice_desc *sd, | 630 | int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd, |
618 | splice_actor *actor) | 631 | splice_actor *actor) |
619 | { | 632 | { |
620 | int ret, do_wakeup, err; | 633 | int ret; |
621 | |||
622 | ret = 0; | ||
623 | do_wakeup = 0; | ||
624 | |||
625 | for (;;) { | ||
626 | if (pipe->nrbufs) { | ||
627 | struct pipe_buffer *buf = pipe->bufs + pipe->curbuf; | ||
628 | const struct pipe_buf_operations *ops = buf->ops; | ||
629 | 634 | ||
630 | sd->len = buf->len; | 635 | while (pipe->nrbufs) { |
631 | if (sd->len > sd->total_len) | 636 | struct pipe_buffer *buf = pipe->bufs + pipe->curbuf; |
632 | sd->len = sd->total_len; | 637 | const struct pipe_buf_operations *ops = buf->ops; |
633 | 638 | ||
634 | err = actor(pipe, buf, sd); | 639 | sd->len = buf->len; |
635 | if (err <= 0) { | 640 | if (sd->len > sd->total_len) |
636 | if (!ret && err != -ENODATA) | 641 | sd->len = sd->total_len; |
637 | ret = err; | ||
638 | 642 | ||
639 | break; | 643 | ret = actor(pipe, buf, sd); |
640 | } | 644 | if (ret <= 0) { |
645 | if (ret == -ENODATA) | ||
646 | ret = 0; | ||
647 | return ret; | ||
648 | } | ||
649 | buf->offset += ret; | ||
650 | buf->len -= ret; | ||
641 | 651 | ||
642 | ret += err; | 652 | sd->num_spliced += ret; |
643 | buf->offset += err; | 653 | sd->len -= ret; |
644 | buf->len -= err; | 654 | sd->pos += ret; |
655 | sd->total_len -= ret; | ||
645 | 656 | ||
646 | sd->len -= err; | 657 | if (!buf->len) { |
647 | sd->pos += err; | 658 | buf->ops = NULL; |
648 | sd->total_len -= err; | 659 | ops->release(pipe, buf); |
649 | if (sd->len) | 660 | pipe->curbuf = (pipe->curbuf + 1) & (PIPE_BUFFERS - 1); |
650 | continue; | 661 | pipe->nrbufs--; |
662 | if (pipe->inode) | ||
663 | sd->need_wakeup = true; | ||
664 | } | ||
651 | 665 | ||
652 | if (!buf->len) { | 666 | if (!sd->total_len) |
653 | buf->ops = NULL; | 667 | return 0; |
654 | ops->release(pipe, buf); | 668 | } |
655 | pipe->curbuf = (pipe->curbuf + 1) & (PIPE_BUFFERS - 1); | ||
656 | pipe->nrbufs--; | ||
657 | if (pipe->inode) | ||
658 | do_wakeup = 1; | ||
659 | } | ||
660 | 669 | ||
661 | if (!sd->total_len) | 670 | return 1; |
662 | break; | 671 | } |
663 | } | 672 | EXPORT_SYMBOL(splice_from_pipe_feed); |
664 | 673 | ||
665 | if (pipe->nrbufs) | 674 | /** |
666 | continue; | 675 | * splice_from_pipe_next - wait for some data to splice from |
676 | * @pipe: pipe to splice from | ||
677 | * @sd: information about the splice operation | ||
678 | * | ||
679 | * Description: | ||
680 | * This function will wait for some data and return a positive | ||
681 | * value (one) if pipe buffers are available. It will return zero | ||
682 | * or -errno if no more data needs to be spliced. | ||
683 | */ | ||
684 | int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd) | ||
685 | { | ||
686 | while (!pipe->nrbufs) { | ||
667 | if (!pipe->writers) | 687 | if (!pipe->writers) |
668 | break; | 688 | return 0; |
669 | if (!pipe->waiting_writers) { | ||
670 | if (ret) | ||
671 | break; | ||
672 | } | ||
673 | 689 | ||
674 | if (sd->flags & SPLICE_F_NONBLOCK) { | 690 | if (!pipe->waiting_writers && sd->num_spliced) |
675 | if (!ret) | 691 | return 0; |
676 | ret = -EAGAIN; | ||
677 | break; | ||
678 | } | ||
679 | 692 | ||
680 | if (signal_pending(current)) { | 693 | if (sd->flags & SPLICE_F_NONBLOCK) |
681 | if (!ret) | 694 | return -EAGAIN; |
682 | ret = -ERESTARTSYS; | ||
683 | break; | ||
684 | } | ||
685 | 695 | ||
686 | if (do_wakeup) { | 696 | if (signal_pending(current)) |
687 | smp_mb(); | 697 | return -ERESTARTSYS; |
688 | if (waitqueue_active(&pipe->wait)) | 698 | |
689 | wake_up_interruptible_sync(&pipe->wait); | 699 | if (sd->need_wakeup) { |
690 | kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT); | 700 | wakeup_pipe_writers(pipe); |
691 | do_wakeup = 0; | 701 | sd->need_wakeup = false; |
692 | } | 702 | } |
693 | 703 | ||
694 | pipe_wait(pipe); | 704 | pipe_wait(pipe); |
695 | } | 705 | } |
696 | 706 | ||
697 | if (do_wakeup) { | 707 | return 1; |
698 | smp_mb(); | 708 | } |
699 | if (waitqueue_active(&pipe->wait)) | 709 | EXPORT_SYMBOL(splice_from_pipe_next); |
700 | wake_up_interruptible(&pipe->wait); | ||
701 | kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT); | ||
702 | } | ||
703 | 710 | ||
704 | return ret; | 711 | /** |
712 | * splice_from_pipe_begin - start splicing from pipe | ||
713 | * @sd: information about the splice operation | ||
714 | * | ||
715 | * Description: | ||
716 | * This function should be called before a loop containing | ||
717 | * splice_from_pipe_next() and splice_from_pipe_feed() to | ||
718 | * initialize the necessary fields of @sd. | ||
719 | */ | ||
720 | void splice_from_pipe_begin(struct splice_desc *sd) | ||
721 | { | ||
722 | sd->num_spliced = 0; | ||
723 | sd->need_wakeup = false; | ||
724 | } | ||
725 | EXPORT_SYMBOL(splice_from_pipe_begin); | ||
726 | |||
727 | /** | ||
728 | * splice_from_pipe_end - finish splicing from pipe | ||
729 | * @pipe: pipe to splice from | ||
730 | * @sd: information about the splice operation | ||
731 | * | ||
732 | * Description: | ||
733 | * This function will wake up pipe writers if necessary. It should | ||
734 | * be called after a loop containing splice_from_pipe_next() and | ||
735 | * splice_from_pipe_feed(). | ||
736 | */ | ||
737 | void splice_from_pipe_end(struct pipe_inode_info *pipe, struct splice_desc *sd) | ||
738 | { | ||
739 | if (sd->need_wakeup) | ||
740 | wakeup_pipe_writers(pipe); | ||
741 | } | ||
742 | EXPORT_SYMBOL(splice_from_pipe_end); | ||
743 | |||
744 | /** | ||
745 | * __splice_from_pipe - splice data from a pipe to given actor | ||
746 | * @pipe: pipe to splice from | ||
747 | * @sd: information to @actor | ||
748 | * @actor: handler that splices the data | ||
749 | * | ||
750 | * Description: | ||
751 | * This function does little more than loop over the pipe and call | ||
752 | * @actor to do the actual moving of a single struct pipe_buffer to | ||
753 | * the desired destination. See pipe_to_file, pipe_to_sendpage, or | ||
754 | * pipe_to_user. | ||
755 | * | ||
756 | */ | ||
757 | ssize_t __splice_from_pipe(struct pipe_inode_info *pipe, struct splice_desc *sd, | ||
758 | splice_actor *actor) | ||
759 | { | ||
760 | int ret; | ||
761 | |||
762 | splice_from_pipe_begin(sd); | ||
763 | do { | ||
764 | ret = splice_from_pipe_next(pipe, sd); | ||
765 | if (ret > 0) | ||
766 | ret = splice_from_pipe_feed(pipe, sd, actor); | ||
767 | } while (ret > 0); | ||
768 | splice_from_pipe_end(pipe, sd); | ||
769 | |||
770 | return sd->num_spliced ? sd->num_spliced : ret; | ||
705 | } | 771 | } |
706 | EXPORT_SYMBOL(__splice_from_pipe); | 772 | EXPORT_SYMBOL(__splice_from_pipe); |
707 | 773 | ||
@@ -715,7 +781,7 @@ EXPORT_SYMBOL(__splice_from_pipe); | |||
715 | * @actor: handler that splices the data | 781 | * @actor: handler that splices the data |
716 | * | 782 | * |
717 | * Description: | 783 | * Description: |
718 | * See __splice_from_pipe. This function locks the input and output inodes, | 784 | * See __splice_from_pipe. This function locks the pipe inode, |
719 | * otherwise it's identical to __splice_from_pipe(). | 785 | * otherwise it's identical to __splice_from_pipe(). |
720 | * | 786 | * |
721 | */ | 787 | */ |
@@ -724,7 +790,6 @@ ssize_t splice_from_pipe(struct pipe_inode_info *pipe, struct file *out, | |||
724 | splice_actor *actor) | 790 | splice_actor *actor) |
725 | { | 791 | { |
726 | ssize_t ret; | 792 | ssize_t ret; |
727 | struct inode *inode = out->f_mapping->host; | ||
728 | struct splice_desc sd = { | 793 | struct splice_desc sd = { |
729 | .total_len = len, | 794 | .total_len = len, |
730 | .flags = flags, | 795 | .flags = flags, |
@@ -732,30 +797,15 @@ ssize_t splice_from_pipe(struct pipe_inode_info *pipe, struct file *out, | |||
732 | .u.file = out, | 797 | .u.file = out, |
733 | }; | 798 | }; |
734 | 799 | ||
735 | /* | 800 | pipe_lock(pipe); |
736 | * The actor worker might be calling ->write_begin and | ||
737 | * ->write_end. Most of the time, these expect i_mutex to | ||
738 | * be held. Since this may result in an ABBA deadlock with | ||
739 | * pipe->inode, we have to order lock acquiry here. | ||
740 | * | ||
741 | * Outer lock must be inode->i_mutex, as pipe_wait() will | ||
742 | * release and reacquire pipe->inode->i_mutex, AND inode must | ||
743 | * never be a pipe. | ||
744 | */ | ||
745 | WARN_ON(S_ISFIFO(inode->i_mode)); | ||
746 | mutex_lock_nested(&inode->i_mutex, I_MUTEX_PARENT); | ||
747 | if (pipe->inode) | ||
748 | mutex_lock_nested(&pipe->inode->i_mutex, I_MUTEX_CHILD); | ||
749 | ret = __splice_from_pipe(pipe, &sd, actor); | 801 | ret = __splice_from_pipe(pipe, &sd, actor); |
750 | if (pipe->inode) | 802 | pipe_unlock(pipe); |
751 | mutex_unlock(&pipe->inode->i_mutex); | ||
752 | mutex_unlock(&inode->i_mutex); | ||
753 | 803 | ||
754 | return ret; | 804 | return ret; |
755 | } | 805 | } |
756 | 806 | ||
757 | /** | 807 | /** |
758 | * generic_file_splice_write_nolock - generic_file_splice_write without mutexes | 808 | * generic_file_splice_write - splice data from a pipe to a file |
759 | * @pipe: pipe info | 809 | * @pipe: pipe info |
760 | * @out: file to write to | 810 | * @out: file to write to |
761 | * @ppos: position in @out | 811 | * @ppos: position in @out |
@@ -764,13 +814,12 @@ ssize_t splice_from_pipe(struct pipe_inode_info *pipe, struct file *out, | |||
764 | * | 814 | * |
765 | * Description: | 815 | * Description: |
766 | * Will either move or copy pages (determined by @flags options) from | 816 | * Will either move or copy pages (determined by @flags options) from |
767 | * the given pipe inode to the given file. The caller is responsible | 817 | * the given pipe inode to the given file. |
768 | * for acquiring i_mutex on both inodes. | ||
769 | * | 818 | * |
770 | */ | 819 | */ |
771 | ssize_t | 820 | ssize_t |
772 | generic_file_splice_write_nolock(struct pipe_inode_info *pipe, struct file *out, | 821 | generic_file_splice_write(struct pipe_inode_info *pipe, struct file *out, |
773 | loff_t *ppos, size_t len, unsigned int flags) | 822 | loff_t *ppos, size_t len, unsigned int flags) |
774 | { | 823 | { |
775 | struct address_space *mapping = out->f_mapping; | 824 | struct address_space *mapping = out->f_mapping; |
776 | struct inode *inode = mapping->host; | 825 | struct inode *inode = mapping->host; |
@@ -781,76 +830,28 @@ generic_file_splice_write_nolock(struct pipe_inode_info *pipe, struct file *out, | |||
781 | .u.file = out, | 830 | .u.file = out, |
782 | }; | 831 | }; |
783 | ssize_t ret; | 832 | ssize_t ret; |
784 | int err; | ||
785 | |||
786 | err = file_remove_suid(out); | ||
787 | if (unlikely(err)) | ||
788 | return err; | ||
789 | |||
790 | ret = __splice_from_pipe(pipe, &sd, pipe_to_file); | ||
791 | if (ret > 0) { | ||
792 | unsigned long nr_pages; | ||
793 | 833 | ||
794 | *ppos += ret; | 834 | pipe_lock(pipe); |
795 | nr_pages = (ret + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; | ||
796 | |||
797 | /* | ||
798 | * If file or inode is SYNC and we actually wrote some data, | ||
799 | * sync it. | ||
800 | */ | ||
801 | if (unlikely((out->f_flags & O_SYNC) || IS_SYNC(inode))) { | ||
802 | err = generic_osync_inode(inode, mapping, | ||
803 | OSYNC_METADATA|OSYNC_DATA); | ||
804 | 835 | ||
805 | if (err) | 836 | splice_from_pipe_begin(&sd); |
806 | ret = err; | 837 | do { |
807 | } | 838 | ret = splice_from_pipe_next(pipe, &sd); |
808 | balance_dirty_pages_ratelimited_nr(mapping, nr_pages); | 839 | if (ret <= 0) |
809 | } | 840 | break; |
810 | 841 | ||
811 | return ret; | 842 | mutex_lock_nested(&inode->i_mutex, I_MUTEX_CHILD); |
812 | } | 843 | ret = file_remove_suid(out); |
844 | if (!ret) | ||
845 | ret = splice_from_pipe_feed(pipe, &sd, pipe_to_file); | ||
846 | mutex_unlock(&inode->i_mutex); | ||
847 | } while (ret > 0); | ||
848 | splice_from_pipe_end(pipe, &sd); | ||
813 | 849 | ||
814 | EXPORT_SYMBOL(generic_file_splice_write_nolock); | 850 | pipe_unlock(pipe); |
815 | 851 | ||
816 | /** | 852 | if (sd.num_spliced) |
817 | * generic_file_splice_write - splice data from a pipe to a file | 853 | ret = sd.num_spliced; |
818 | * @pipe: pipe info | ||
819 | * @out: file to write to | ||
820 | * @ppos: position in @out | ||
821 | * @len: number of bytes to splice | ||
822 | * @flags: splice modifier flags | ||
823 | * | ||
824 | * Description: | ||
825 | * Will either move or copy pages (determined by @flags options) from | ||
826 | * the given pipe inode to the given file. | ||
827 | * | ||
828 | */ | ||
829 | ssize_t | ||
830 | generic_file_splice_write(struct pipe_inode_info *pipe, struct file *out, | ||
831 | loff_t *ppos, size_t len, unsigned int flags) | ||
832 | { | ||
833 | struct address_space *mapping = out->f_mapping; | ||
834 | struct inode *inode = mapping->host; | ||
835 | struct splice_desc sd = { | ||
836 | .total_len = len, | ||
837 | .flags = flags, | ||
838 | .pos = *ppos, | ||
839 | .u.file = out, | ||
840 | }; | ||
841 | ssize_t ret; | ||
842 | 854 | ||
843 | WARN_ON(S_ISFIFO(inode->i_mode)); | ||
844 | mutex_lock_nested(&inode->i_mutex, I_MUTEX_PARENT); | ||
845 | ret = file_remove_suid(out); | ||
846 | if (likely(!ret)) { | ||
847 | if (pipe->inode) | ||
848 | mutex_lock_nested(&pipe->inode->i_mutex, I_MUTEX_CHILD); | ||
849 | ret = __splice_from_pipe(pipe, &sd, pipe_to_file); | ||
850 | if (pipe->inode) | ||
851 | mutex_unlock(&pipe->inode->i_mutex); | ||
852 | } | ||
853 | mutex_unlock(&inode->i_mutex); | ||
854 | if (ret > 0) { | 855 | if (ret > 0) { |
855 | unsigned long nr_pages; | 856 | unsigned long nr_pages; |
856 | 857 | ||
@@ -1339,8 +1340,7 @@ static long vmsplice_to_user(struct file *file, const struct iovec __user *iov, | |||
1339 | if (!pipe) | 1340 | if (!pipe) |
1340 | return -EBADF; | 1341 | return -EBADF; |
1341 | 1342 | ||
1342 | if (pipe->inode) | 1343 | pipe_lock(pipe); |
1343 | mutex_lock(&pipe->inode->i_mutex); | ||
1344 | 1344 | ||
1345 | error = ret = 0; | 1345 | error = ret = 0; |
1346 | while (nr_segs) { | 1346 | while (nr_segs) { |
@@ -1395,8 +1395,7 @@ static long vmsplice_to_user(struct file *file, const struct iovec __user *iov, | |||
1395 | iov++; | 1395 | iov++; |
1396 | } | 1396 | } |
1397 | 1397 | ||
1398 | if (pipe->inode) | 1398 | pipe_unlock(pipe); |
1399 | mutex_unlock(&pipe->inode->i_mutex); | ||
1400 | 1399 | ||
1401 | if (!ret) | 1400 | if (!ret) |
1402 | ret = error; | 1401 | ret = error; |
@@ -1524,7 +1523,7 @@ static int link_ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags) | |||
1524 | return 0; | 1523 | return 0; |
1525 | 1524 | ||
1526 | ret = 0; | 1525 | ret = 0; |
1527 | mutex_lock(&pipe->inode->i_mutex); | 1526 | pipe_lock(pipe); |
1528 | 1527 | ||
1529 | while (!pipe->nrbufs) { | 1528 | while (!pipe->nrbufs) { |
1530 | if (signal_pending(current)) { | 1529 | if (signal_pending(current)) { |
@@ -1542,7 +1541,7 @@ static int link_ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags) | |||
1542 | pipe_wait(pipe); | 1541 | pipe_wait(pipe); |
1543 | } | 1542 | } |
1544 | 1543 | ||
1545 | mutex_unlock(&pipe->inode->i_mutex); | 1544 | pipe_unlock(pipe); |
1546 | return ret; | 1545 | return ret; |
1547 | } | 1546 | } |
1548 | 1547 | ||
@@ -1562,7 +1561,7 @@ static int link_opipe_prep(struct pipe_inode_info *pipe, unsigned int flags) | |||
1562 | return 0; | 1561 | return 0; |
1563 | 1562 | ||
1564 | ret = 0; | 1563 | ret = 0; |
1565 | mutex_lock(&pipe->inode->i_mutex); | 1564 | pipe_lock(pipe); |
1566 | 1565 | ||
1567 | while (pipe->nrbufs >= PIPE_BUFFERS) { | 1566 | while (pipe->nrbufs >= PIPE_BUFFERS) { |
1568 | if (!pipe->readers) { | 1567 | if (!pipe->readers) { |
@@ -1583,7 +1582,7 @@ static int link_opipe_prep(struct pipe_inode_info *pipe, unsigned int flags) | |||
1583 | pipe->waiting_writers--; | 1582 | pipe->waiting_writers--; |
1584 | } | 1583 | } |
1585 | 1584 | ||
1586 | mutex_unlock(&pipe->inode->i_mutex); | 1585 | pipe_unlock(pipe); |
1587 | return ret; | 1586 | return ret; |
1588 | } | 1587 | } |
1589 | 1588 | ||
@@ -1599,10 +1598,10 @@ static int link_pipe(struct pipe_inode_info *ipipe, | |||
1599 | 1598 | ||
1600 | /* | 1599 | /* |
1601 | * Potential ABBA deadlock, work around it by ordering lock | 1600 | * Potential ABBA deadlock, work around it by ordering lock |
1602 | * grabbing by inode address. Otherwise two different processes | 1601 | * grabbing by pipe info address. Otherwise two different processes |
1603 | * could deadlock (one doing tee from A -> B, the other from B -> A). | 1602 | * could deadlock (one doing tee from A -> B, the other from B -> A). |
1604 | */ | 1603 | */ |
1605 | inode_double_lock(ipipe->inode, opipe->inode); | 1604 | pipe_double_lock(ipipe, opipe); |
1606 | 1605 | ||
1607 | do { | 1606 | do { |
1608 | if (!opipe->readers) { | 1607 | if (!opipe->readers) { |
@@ -1653,7 +1652,8 @@ static int link_pipe(struct pipe_inode_info *ipipe, | |||
1653 | if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK)) | 1652 | if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK)) |
1654 | ret = -EAGAIN; | 1653 | ret = -EAGAIN; |
1655 | 1654 | ||
1656 | inode_double_unlock(ipipe->inode, opipe->inode); | 1655 | pipe_unlock(ipipe); |
1656 | pipe_unlock(opipe); | ||
1657 | 1657 | ||
1658 | /* | 1658 | /* |
1659 | * If we put data in the output pipe, wakeup any potential readers. | 1659 | * If we put data in the output pipe, wakeup any potential readers. |
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index 289c43a47263..b1606e07b7a3 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c | |||
@@ -446,11 +446,11 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait) | |||
446 | if (buffer->event != atomic_read(&od->event)) | 446 | if (buffer->event != atomic_read(&od->event)) |
447 | goto trigger; | 447 | goto trigger; |
448 | 448 | ||
449 | return 0; | 449 | return DEFAULT_POLLMASK; |
450 | 450 | ||
451 | trigger: | 451 | trigger: |
452 | buffer->needs_read_fill = 1; | 452 | buffer->needs_read_fill = 1; |
453 | return POLLERR|POLLPRI; | 453 | return DEFAULT_POLLMASK|POLLERR|POLLPRI; |
454 | } | 454 | } |
455 | 455 | ||
456 | void sysfs_notify_dirent(struct sysfs_dirent *sd) | 456 | void sysfs_notify_dirent(struct sysfs_dirent *sd) |
@@ -667,6 +667,7 @@ struct sysfs_schedule_callback_struct { | |||
667 | struct work_struct work; | 667 | struct work_struct work; |
668 | }; | 668 | }; |
669 | 669 | ||
670 | static struct workqueue_struct *sysfs_workqueue; | ||
670 | static DEFINE_MUTEX(sysfs_workq_mutex); | 671 | static DEFINE_MUTEX(sysfs_workq_mutex); |
671 | static LIST_HEAD(sysfs_workq); | 672 | static LIST_HEAD(sysfs_workq); |
672 | static void sysfs_schedule_callback_work(struct work_struct *work) | 673 | static void sysfs_schedule_callback_work(struct work_struct *work) |
@@ -715,11 +716,20 @@ int sysfs_schedule_callback(struct kobject *kobj, void (*func)(void *), | |||
715 | mutex_lock(&sysfs_workq_mutex); | 716 | mutex_lock(&sysfs_workq_mutex); |
716 | list_for_each_entry_safe(ss, tmp, &sysfs_workq, workq_list) | 717 | list_for_each_entry_safe(ss, tmp, &sysfs_workq, workq_list) |
717 | if (ss->kobj == kobj) { | 718 | if (ss->kobj == kobj) { |
719 | module_put(owner); | ||
718 | mutex_unlock(&sysfs_workq_mutex); | 720 | mutex_unlock(&sysfs_workq_mutex); |
719 | return -EAGAIN; | 721 | return -EAGAIN; |
720 | } | 722 | } |
721 | mutex_unlock(&sysfs_workq_mutex); | 723 | mutex_unlock(&sysfs_workq_mutex); |
722 | 724 | ||
725 | if (sysfs_workqueue == NULL) { | ||
726 | sysfs_workqueue = create_workqueue("sysfsd"); | ||
727 | if (sysfs_workqueue == NULL) { | ||
728 | module_put(owner); | ||
729 | return -ENOMEM; | ||
730 | } | ||
731 | } | ||
732 | |||
723 | ss = kmalloc(sizeof(*ss), GFP_KERNEL); | 733 | ss = kmalloc(sizeof(*ss), GFP_KERNEL); |
724 | if (!ss) { | 734 | if (!ss) { |
725 | module_put(owner); | 735 | module_put(owner); |
@@ -735,7 +745,7 @@ int sysfs_schedule_callback(struct kobject *kobj, void (*func)(void *), | |||
735 | mutex_lock(&sysfs_workq_mutex); | 745 | mutex_lock(&sysfs_workq_mutex); |
736 | list_add_tail(&ss->workq_list, &sysfs_workq); | 746 | list_add_tail(&ss->workq_list, &sysfs_workq); |
737 | mutex_unlock(&sysfs_workq_mutex); | 747 | mutex_unlock(&sysfs_workq_mutex); |
738 | schedule_work(&ss->work); | 748 | queue_work(sysfs_workqueue, &ss->work); |
739 | return 0; | 749 | return 0; |
740 | } | 750 | } |
741 | EXPORT_SYMBOL_GPL(sysfs_schedule_callback); | 751 | EXPORT_SYMBOL_GPL(sysfs_schedule_callback); |
diff --git a/fs/xfs/linux-2.6/xfs_aops.c b/fs/xfs/linux-2.6/xfs_aops.c index c13f67300fe7..7ec89fc05b2b 100644 --- a/fs/xfs/linux-2.6/xfs_aops.c +++ b/fs/xfs/linux-2.6/xfs_aops.c | |||
@@ -153,23 +153,6 @@ xfs_find_bdev_for_inode( | |||
153 | } | 153 | } |
154 | 154 | ||
155 | /* | 155 | /* |
156 | * Schedule IO completion handling on a xfsdatad if this was | ||
157 | * the final hold on this ioend. If we are asked to wait, | ||
158 | * flush the workqueue. | ||
159 | */ | ||
160 | STATIC void | ||
161 | xfs_finish_ioend( | ||
162 | xfs_ioend_t *ioend, | ||
163 | int wait) | ||
164 | { | ||
165 | if (atomic_dec_and_test(&ioend->io_remaining)) { | ||
166 | queue_work(xfsdatad_workqueue, &ioend->io_work); | ||
167 | if (wait) | ||
168 | flush_workqueue(xfsdatad_workqueue); | ||
169 | } | ||
170 | } | ||
171 | |||
172 | /* | ||
173 | * We're now finished for good with this ioend structure. | 156 | * We're now finished for good with this ioend structure. |
174 | * Update the page state via the associated buffer_heads, | 157 | * Update the page state via the associated buffer_heads, |
175 | * release holds on the inode and bio, and finally free | 158 | * release holds on the inode and bio, and finally free |
@@ -310,6 +293,27 @@ xfs_end_bio_read( | |||
310 | } | 293 | } |
311 | 294 | ||
312 | /* | 295 | /* |
296 | * Schedule IO completion handling on a xfsdatad if this was | ||
297 | * the final hold on this ioend. If we are asked to wait, | ||
298 | * flush the workqueue. | ||
299 | */ | ||
300 | STATIC void | ||
301 | xfs_finish_ioend( | ||
302 | xfs_ioend_t *ioend, | ||
303 | int wait) | ||
304 | { | ||
305 | if (atomic_dec_and_test(&ioend->io_remaining)) { | ||
306 | struct workqueue_struct *wq = xfsdatad_workqueue; | ||
307 | if (ioend->io_work.func == xfs_end_bio_unwritten) | ||
308 | wq = xfsconvertd_workqueue; | ||
309 | |||
310 | queue_work(wq, &ioend->io_work); | ||
311 | if (wait) | ||
312 | flush_workqueue(wq); | ||
313 | } | ||
314 | } | ||
315 | |||
316 | /* | ||
313 | * Allocate and initialise an IO completion structure. | 317 | * Allocate and initialise an IO completion structure. |
314 | * We need to track unwritten extent write completion here initially. | 318 | * We need to track unwritten extent write completion here initially. |
315 | * We'll need to extend this for updating the ondisk inode size later | 319 | * We'll need to extend this for updating the ondisk inode size later |
diff --git a/fs/xfs/linux-2.6/xfs_aops.h b/fs/xfs/linux-2.6/xfs_aops.h index 1dd528849755..221b3e66ceef 100644 --- a/fs/xfs/linux-2.6/xfs_aops.h +++ b/fs/xfs/linux-2.6/xfs_aops.h | |||
@@ -19,6 +19,7 @@ | |||
19 | #define __XFS_AOPS_H__ | 19 | #define __XFS_AOPS_H__ |
20 | 20 | ||
21 | extern struct workqueue_struct *xfsdatad_workqueue; | 21 | extern struct workqueue_struct *xfsdatad_workqueue; |
22 | extern struct workqueue_struct *xfsconvertd_workqueue; | ||
22 | extern mempool_t *xfs_ioend_pool; | 23 | extern mempool_t *xfs_ioend_pool; |
23 | 24 | ||
24 | /* | 25 | /* |
diff --git a/fs/xfs/linux-2.6/xfs_buf.c b/fs/xfs/linux-2.6/xfs_buf.c index aa1016bb9134..e28800a9f2b5 100644 --- a/fs/xfs/linux-2.6/xfs_buf.c +++ b/fs/xfs/linux-2.6/xfs_buf.c | |||
@@ -51,6 +51,7 @@ static struct shrinker xfs_buf_shake = { | |||
51 | 51 | ||
52 | static struct workqueue_struct *xfslogd_workqueue; | 52 | static struct workqueue_struct *xfslogd_workqueue; |
53 | struct workqueue_struct *xfsdatad_workqueue; | 53 | struct workqueue_struct *xfsdatad_workqueue; |
54 | struct workqueue_struct *xfsconvertd_workqueue; | ||
54 | 55 | ||
55 | #ifdef XFS_BUF_TRACE | 56 | #ifdef XFS_BUF_TRACE |
56 | void | 57 | void |
@@ -1775,6 +1776,7 @@ xfs_flush_buftarg( | |||
1775 | xfs_buf_t *bp, *n; | 1776 | xfs_buf_t *bp, *n; |
1776 | int pincount = 0; | 1777 | int pincount = 0; |
1777 | 1778 | ||
1779 | xfs_buf_runall_queues(xfsconvertd_workqueue); | ||
1778 | xfs_buf_runall_queues(xfsdatad_workqueue); | 1780 | xfs_buf_runall_queues(xfsdatad_workqueue); |
1779 | xfs_buf_runall_queues(xfslogd_workqueue); | 1781 | xfs_buf_runall_queues(xfslogd_workqueue); |
1780 | 1782 | ||
@@ -1831,9 +1833,15 @@ xfs_buf_init(void) | |||
1831 | if (!xfsdatad_workqueue) | 1833 | if (!xfsdatad_workqueue) |
1832 | goto out_destroy_xfslogd_workqueue; | 1834 | goto out_destroy_xfslogd_workqueue; |
1833 | 1835 | ||
1836 | xfsconvertd_workqueue = create_workqueue("xfsconvertd"); | ||
1837 | if (!xfsconvertd_workqueue) | ||
1838 | goto out_destroy_xfsdatad_workqueue; | ||
1839 | |||
1834 | register_shrinker(&xfs_buf_shake); | 1840 | register_shrinker(&xfs_buf_shake); |
1835 | return 0; | 1841 | return 0; |
1836 | 1842 | ||
1843 | out_destroy_xfsdatad_workqueue: | ||
1844 | destroy_workqueue(xfsdatad_workqueue); | ||
1837 | out_destroy_xfslogd_workqueue: | 1845 | out_destroy_xfslogd_workqueue: |
1838 | destroy_workqueue(xfslogd_workqueue); | 1846 | destroy_workqueue(xfslogd_workqueue); |
1839 | out_free_buf_zone: | 1847 | out_free_buf_zone: |
@@ -1849,6 +1857,7 @@ void | |||
1849 | xfs_buf_terminate(void) | 1857 | xfs_buf_terminate(void) |
1850 | { | 1858 | { |
1851 | unregister_shrinker(&xfs_buf_shake); | 1859 | unregister_shrinker(&xfs_buf_shake); |
1860 | destroy_workqueue(xfsconvertd_workqueue); | ||
1852 | destroy_workqueue(xfsdatad_workqueue); | 1861 | destroy_workqueue(xfsdatad_workqueue); |
1853 | destroy_workqueue(xfslogd_workqueue); | 1862 | destroy_workqueue(xfslogd_workqueue); |
1854 | kmem_zone_destroy(xfs_buf_zone); | 1863 | kmem_zone_destroy(xfs_buf_zone); |
diff --git a/fs/xfs/linux-2.6/xfs_fs_subr.c b/fs/xfs/linux-2.6/xfs_fs_subr.c index 5aeb77776961..08be36d7326c 100644 --- a/fs/xfs/linux-2.6/xfs_fs_subr.c +++ b/fs/xfs/linux-2.6/xfs_fs_subr.c | |||
@@ -74,14 +74,14 @@ xfs_flush_pages( | |||
74 | 74 | ||
75 | if (mapping_tagged(mapping, PAGECACHE_TAG_DIRTY)) { | 75 | if (mapping_tagged(mapping, PAGECACHE_TAG_DIRTY)) { |
76 | xfs_iflags_clear(ip, XFS_ITRUNCATED); | 76 | xfs_iflags_clear(ip, XFS_ITRUNCATED); |
77 | ret = filemap_fdatawrite(mapping); | 77 | ret = -filemap_fdatawrite(mapping); |
78 | if (flags & XFS_B_ASYNC) | ||
79 | return -ret; | ||
80 | ret2 = filemap_fdatawait(mapping); | ||
81 | if (!ret) | ||
82 | ret = ret2; | ||
83 | } | 78 | } |
84 | return -ret; | 79 | if (flags & XFS_B_ASYNC) |
80 | return ret; | ||
81 | ret2 = xfs_wait_on_pages(ip, first, last); | ||
82 | if (!ret) | ||
83 | ret = ret2; | ||
84 | return ret; | ||
85 | } | 85 | } |
86 | 86 | ||
87 | int | 87 | int |
diff --git a/fs/xfs/linux-2.6/xfs_lrw.c b/fs/xfs/linux-2.6/xfs_lrw.c index 7e90daa0d1d1..9142192ccbe6 100644 --- a/fs/xfs/linux-2.6/xfs_lrw.c +++ b/fs/xfs/linux-2.6/xfs_lrw.c | |||
@@ -751,10 +751,26 @@ start: | |||
751 | goto relock; | 751 | goto relock; |
752 | } | 752 | } |
753 | } else { | 753 | } else { |
754 | int enospc = 0; | ||
755 | ssize_t ret2 = 0; | ||
756 | |||
757 | write_retry: | ||
754 | xfs_rw_enter_trace(XFS_WRITE_ENTER, xip, (void *)iovp, segs, | 758 | xfs_rw_enter_trace(XFS_WRITE_ENTER, xip, (void *)iovp, segs, |
755 | *offset, ioflags); | 759 | *offset, ioflags); |
756 | ret = generic_file_buffered_write(iocb, iovp, segs, | 760 | ret2 = generic_file_buffered_write(iocb, iovp, segs, |
757 | pos, offset, count, ret); | 761 | pos, offset, count, ret); |
762 | /* | ||
763 | * if we just got an ENOSPC, flush the inode now we | ||
764 | * aren't holding any page locks and retry *once* | ||
765 | */ | ||
766 | if (ret2 == -ENOSPC && !enospc) { | ||
767 | error = xfs_flush_pages(xip, 0, -1, 0, FI_NONE); | ||
768 | if (error) | ||
769 | goto out_unlock_internal; | ||
770 | enospc = 1; | ||
771 | goto write_retry; | ||
772 | } | ||
773 | ret = ret2; | ||
758 | } | 774 | } |
759 | 775 | ||
760 | current->backing_dev_info = NULL; | 776 | current->backing_dev_info = NULL; |
diff --git a/fs/xfs/linux-2.6/xfs_sync.c b/fs/xfs/linux-2.6/xfs_sync.c index a608e72fa405..f7ba76633c29 100644 --- a/fs/xfs/linux-2.6/xfs_sync.c +++ b/fs/xfs/linux-2.6/xfs_sync.c | |||
@@ -62,12 +62,6 @@ xfs_sync_inodes_ag( | |||
62 | uint32_t first_index = 0; | 62 | uint32_t first_index = 0; |
63 | int error = 0; | 63 | int error = 0; |
64 | int last_error = 0; | 64 | int last_error = 0; |
65 | int fflag = XFS_B_ASYNC; | ||
66 | |||
67 | if (flags & SYNC_DELWRI) | ||
68 | fflag = XFS_B_DELWRI; | ||
69 | if (flags & SYNC_WAIT) | ||
70 | fflag = 0; /* synchronous overrides all */ | ||
71 | 65 | ||
72 | do { | 66 | do { |
73 | struct inode *inode; | 67 | struct inode *inode; |
@@ -128,11 +122,23 @@ xfs_sync_inodes_ag( | |||
128 | * If we have to flush data or wait for I/O completion | 122 | * If we have to flush data or wait for I/O completion |
129 | * we need to hold the iolock. | 123 | * we need to hold the iolock. |
130 | */ | 124 | */ |
131 | if ((flags & SYNC_DELWRI) && VN_DIRTY(inode)) { | 125 | if (flags & SYNC_DELWRI) { |
132 | xfs_ilock(ip, XFS_IOLOCK_SHARED); | 126 | if (VN_DIRTY(inode)) { |
133 | lock_flags |= XFS_IOLOCK_SHARED; | 127 | if (flags & SYNC_TRYLOCK) { |
134 | error = xfs_flush_pages(ip, 0, -1, fflag, FI_NONE); | 128 | if (xfs_ilock_nowait(ip, XFS_IOLOCK_SHARED)) |
135 | if (flags & SYNC_IOWAIT) | 129 | lock_flags |= XFS_IOLOCK_SHARED; |
130 | } else { | ||
131 | xfs_ilock(ip, XFS_IOLOCK_SHARED); | ||
132 | lock_flags |= XFS_IOLOCK_SHARED; | ||
133 | } | ||
134 | if (lock_flags & XFS_IOLOCK_SHARED) { | ||
135 | error = xfs_flush_pages(ip, 0, -1, | ||
136 | (flags & SYNC_WAIT) ? 0 | ||
137 | : XFS_B_ASYNC, | ||
138 | FI_NONE); | ||
139 | } | ||
140 | } | ||
141 | if (VN_CACHED(inode) && (flags & SYNC_IOWAIT)) | ||
136 | xfs_ioend_wait(ip); | 142 | xfs_ioend_wait(ip); |
137 | } | 143 | } |
138 | xfs_ilock(ip, XFS_ILOCK_SHARED); | 144 | xfs_ilock(ip, XFS_ILOCK_SHARED); |
@@ -398,15 +404,17 @@ STATIC void | |||
398 | xfs_syncd_queue_work( | 404 | xfs_syncd_queue_work( |
399 | struct xfs_mount *mp, | 405 | struct xfs_mount *mp, |
400 | void *data, | 406 | void *data, |
401 | void (*syncer)(struct xfs_mount *, void *)) | 407 | void (*syncer)(struct xfs_mount *, void *), |
408 | struct completion *completion) | ||
402 | { | 409 | { |
403 | struct bhv_vfs_sync_work *work; | 410 | struct xfs_sync_work *work; |
404 | 411 | ||
405 | work = kmem_alloc(sizeof(struct bhv_vfs_sync_work), KM_SLEEP); | 412 | work = kmem_alloc(sizeof(struct xfs_sync_work), KM_SLEEP); |
406 | INIT_LIST_HEAD(&work->w_list); | 413 | INIT_LIST_HEAD(&work->w_list); |
407 | work->w_syncer = syncer; | 414 | work->w_syncer = syncer; |
408 | work->w_data = data; | 415 | work->w_data = data; |
409 | work->w_mount = mp; | 416 | work->w_mount = mp; |
417 | work->w_completion = completion; | ||
410 | spin_lock(&mp->m_sync_lock); | 418 | spin_lock(&mp->m_sync_lock); |
411 | list_add_tail(&work->w_list, &mp->m_sync_list); | 419 | list_add_tail(&work->w_list, &mp->m_sync_list); |
412 | spin_unlock(&mp->m_sync_lock); | 420 | spin_unlock(&mp->m_sync_lock); |
@@ -420,49 +428,26 @@ xfs_syncd_queue_work( | |||
420 | * heads, looking about for more room... | 428 | * heads, looking about for more room... |
421 | */ | 429 | */ |
422 | STATIC void | 430 | STATIC void |
423 | xfs_flush_inode_work( | 431 | xfs_flush_inodes_work( |
424 | struct xfs_mount *mp, | ||
425 | void *arg) | ||
426 | { | ||
427 | struct inode *inode = arg; | ||
428 | filemap_flush(inode->i_mapping); | ||
429 | iput(inode); | ||
430 | } | ||
431 | |||
432 | void | ||
433 | xfs_flush_inode( | ||
434 | xfs_inode_t *ip) | ||
435 | { | ||
436 | struct inode *inode = VFS_I(ip); | ||
437 | |||
438 | igrab(inode); | ||
439 | xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_inode_work); | ||
440 | delay(msecs_to_jiffies(500)); | ||
441 | } | ||
442 | |||
443 | /* | ||
444 | * This is the "bigger hammer" version of xfs_flush_inode_work... | ||
445 | * (IOW, "If at first you don't succeed, use a Bigger Hammer"). | ||
446 | */ | ||
447 | STATIC void | ||
448 | xfs_flush_device_work( | ||
449 | struct xfs_mount *mp, | 432 | struct xfs_mount *mp, |
450 | void *arg) | 433 | void *arg) |
451 | { | 434 | { |
452 | struct inode *inode = arg; | 435 | struct inode *inode = arg; |
453 | sync_blockdev(mp->m_super->s_bdev); | 436 | xfs_sync_inodes(mp, SYNC_DELWRI | SYNC_TRYLOCK); |
437 | xfs_sync_inodes(mp, SYNC_DELWRI | SYNC_TRYLOCK | SYNC_IOWAIT); | ||
454 | iput(inode); | 438 | iput(inode); |
455 | } | 439 | } |
456 | 440 | ||
457 | void | 441 | void |
458 | xfs_flush_device( | 442 | xfs_flush_inodes( |
459 | xfs_inode_t *ip) | 443 | xfs_inode_t *ip) |
460 | { | 444 | { |
461 | struct inode *inode = VFS_I(ip); | 445 | struct inode *inode = VFS_I(ip); |
446 | DECLARE_COMPLETION_ONSTACK(completion); | ||
462 | 447 | ||
463 | igrab(inode); | 448 | igrab(inode); |
464 | xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_device_work); | 449 | xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_inodes_work, &completion); |
465 | delay(msecs_to_jiffies(500)); | 450 | wait_for_completion(&completion); |
466 | xfs_log_force(ip->i_mount, (xfs_lsn_t)0, XFS_LOG_FORCE|XFS_LOG_SYNC); | 451 | xfs_log_force(ip->i_mount, (xfs_lsn_t)0, XFS_LOG_FORCE|XFS_LOG_SYNC); |
467 | } | 452 | } |
468 | 453 | ||
@@ -497,7 +482,7 @@ xfssyncd( | |||
497 | { | 482 | { |
498 | struct xfs_mount *mp = arg; | 483 | struct xfs_mount *mp = arg; |
499 | long timeleft; | 484 | long timeleft; |
500 | bhv_vfs_sync_work_t *work, *n; | 485 | xfs_sync_work_t *work, *n; |
501 | LIST_HEAD (tmp); | 486 | LIST_HEAD (tmp); |
502 | 487 | ||
503 | set_freezable(); | 488 | set_freezable(); |
@@ -532,6 +517,8 @@ xfssyncd( | |||
532 | list_del(&work->w_list); | 517 | list_del(&work->w_list); |
533 | if (work == &mp->m_sync_work) | 518 | if (work == &mp->m_sync_work) |
534 | continue; | 519 | continue; |
520 | if (work->w_completion) | ||
521 | complete(work->w_completion); | ||
535 | kmem_free(work); | 522 | kmem_free(work); |
536 | } | 523 | } |
537 | } | 524 | } |
@@ -545,6 +532,7 @@ xfs_syncd_init( | |||
545 | { | 532 | { |
546 | mp->m_sync_work.w_syncer = xfs_sync_worker; | 533 | mp->m_sync_work.w_syncer = xfs_sync_worker; |
547 | mp->m_sync_work.w_mount = mp; | 534 | mp->m_sync_work.w_mount = mp; |
535 | mp->m_sync_work.w_completion = NULL; | ||
548 | mp->m_sync_task = kthread_run(xfssyncd, mp, "xfssyncd"); | 536 | mp->m_sync_task = kthread_run(xfssyncd, mp, "xfssyncd"); |
549 | if (IS_ERR(mp->m_sync_task)) | 537 | if (IS_ERR(mp->m_sync_task)) |
550 | return -PTR_ERR(mp->m_sync_task); | 538 | return -PTR_ERR(mp->m_sync_task); |
diff --git a/fs/xfs/linux-2.6/xfs_sync.h b/fs/xfs/linux-2.6/xfs_sync.h index 04f058c848ae..308d5bf6dfbd 100644 --- a/fs/xfs/linux-2.6/xfs_sync.h +++ b/fs/xfs/linux-2.6/xfs_sync.h | |||
@@ -21,18 +21,20 @@ | |||
21 | struct xfs_mount; | 21 | struct xfs_mount; |
22 | struct xfs_perag; | 22 | struct xfs_perag; |
23 | 23 | ||
24 | typedef struct bhv_vfs_sync_work { | 24 | typedef struct xfs_sync_work { |
25 | struct list_head w_list; | 25 | struct list_head w_list; |
26 | struct xfs_mount *w_mount; | 26 | struct xfs_mount *w_mount; |
27 | void *w_data; /* syncer routine argument */ | 27 | void *w_data; /* syncer routine argument */ |
28 | void (*w_syncer)(struct xfs_mount *, void *); | 28 | void (*w_syncer)(struct xfs_mount *, void *); |
29 | } bhv_vfs_sync_work_t; | 29 | struct completion *w_completion; |
30 | } xfs_sync_work_t; | ||
30 | 31 | ||
31 | #define SYNC_ATTR 0x0001 /* sync attributes */ | 32 | #define SYNC_ATTR 0x0001 /* sync attributes */ |
32 | #define SYNC_DELWRI 0x0002 /* look at delayed writes */ | 33 | #define SYNC_DELWRI 0x0002 /* look at delayed writes */ |
33 | #define SYNC_WAIT 0x0004 /* wait for i/o to complete */ | 34 | #define SYNC_WAIT 0x0004 /* wait for i/o to complete */ |
34 | #define SYNC_BDFLUSH 0x0008 /* BDFLUSH is calling -- don't block */ | 35 | #define SYNC_BDFLUSH 0x0008 /* BDFLUSH is calling -- don't block */ |
35 | #define SYNC_IOWAIT 0x0010 /* wait for all I/O to complete */ | 36 | #define SYNC_IOWAIT 0x0010 /* wait for all I/O to complete */ |
37 | #define SYNC_TRYLOCK 0x0020 /* only try to lock inodes */ | ||
36 | 38 | ||
37 | int xfs_syncd_init(struct xfs_mount *mp); | 39 | int xfs_syncd_init(struct xfs_mount *mp); |
38 | void xfs_syncd_stop(struct xfs_mount *mp); | 40 | void xfs_syncd_stop(struct xfs_mount *mp); |
@@ -43,8 +45,7 @@ int xfs_sync_fsdata(struct xfs_mount *mp, int flags); | |||
43 | int xfs_quiesce_data(struct xfs_mount *mp); | 45 | int xfs_quiesce_data(struct xfs_mount *mp); |
44 | void xfs_quiesce_attr(struct xfs_mount *mp); | 46 | void xfs_quiesce_attr(struct xfs_mount *mp); |
45 | 47 | ||
46 | void xfs_flush_inode(struct xfs_inode *ip); | 48 | void xfs_flush_inodes(struct xfs_inode *ip); |
47 | void xfs_flush_device(struct xfs_inode *ip); | ||
48 | 49 | ||
49 | int xfs_reclaim_inode(struct xfs_inode *ip, int locked, int sync_mode); | 50 | int xfs_reclaim_inode(struct xfs_inode *ip, int locked, int sync_mode); |
50 | int xfs_reclaim_inodes(struct xfs_mount *mp, int noblock, int mode); | 51 | int xfs_reclaim_inodes(struct xfs_mount *mp, int noblock, int mode); |
diff --git a/fs/xfs/xfs_iget.c b/fs/xfs/xfs_iget.c index 478e587087fe..89b81eedce6a 100644 --- a/fs/xfs/xfs_iget.c +++ b/fs/xfs/xfs_iget.c | |||
@@ -69,15 +69,6 @@ xfs_inode_alloc( | |||
69 | ASSERT(!spin_is_locked(&ip->i_flags_lock)); | 69 | ASSERT(!spin_is_locked(&ip->i_flags_lock)); |
70 | ASSERT(completion_done(&ip->i_flush)); | 70 | ASSERT(completion_done(&ip->i_flush)); |
71 | 71 | ||
72 | /* | ||
73 | * initialise the VFS inode here to get failures | ||
74 | * out of the way early. | ||
75 | */ | ||
76 | if (!inode_init_always(mp->m_super, VFS_I(ip))) { | ||
77 | kmem_zone_free(xfs_inode_zone, ip); | ||
78 | return NULL; | ||
79 | } | ||
80 | |||
81 | /* initialise the xfs inode */ | 72 | /* initialise the xfs inode */ |
82 | ip->i_ino = ino; | 73 | ip->i_ino = ino; |
83 | ip->i_mount = mp; | 74 | ip->i_mount = mp; |
@@ -113,6 +104,20 @@ xfs_inode_alloc( | |||
113 | #ifdef XFS_DIR2_TRACE | 104 | #ifdef XFS_DIR2_TRACE |
114 | ip->i_dir_trace = ktrace_alloc(XFS_DIR2_KTRACE_SIZE, KM_NOFS); | 105 | ip->i_dir_trace = ktrace_alloc(XFS_DIR2_KTRACE_SIZE, KM_NOFS); |
115 | #endif | 106 | #endif |
107 | /* | ||
108 | * Now initialise the VFS inode. We do this after the xfs_inode | ||
109 | * initialisation as internal failures will result in ->destroy_inode | ||
110 | * being called and that will pass down through the reclaim path and | ||
111 | * free the XFS inode. This path requires the XFS inode to already be | ||
112 | * initialised. Hence if this call fails, the xfs_inode has already | ||
113 | * been freed and we should not reference it at all in the error | ||
114 | * handling. | ||
115 | */ | ||
116 | if (!inode_init_always(mp->m_super, VFS_I(ip))) | ||
117 | return NULL; | ||
118 | |||
119 | /* prevent anyone from using this yet */ | ||
120 | VFS_I(ip)->i_state = I_NEW|I_LOCK; | ||
116 | 121 | ||
117 | return ip; | 122 | return ip; |
118 | } | 123 | } |
diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index 08ce72316bfe..5aaa2d7ec155 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c | |||
@@ -338,38 +338,6 @@ xfs_iomap_eof_align_last_fsb( | |||
338 | } | 338 | } |
339 | 339 | ||
340 | STATIC int | 340 | STATIC int |
341 | xfs_flush_space( | ||
342 | xfs_inode_t *ip, | ||
343 | int *fsynced, | ||
344 | int *ioflags) | ||
345 | { | ||
346 | switch (*fsynced) { | ||
347 | case 0: | ||
348 | if (ip->i_delayed_blks) { | ||
349 | xfs_iunlock(ip, XFS_ILOCK_EXCL); | ||
350 | xfs_flush_inode(ip); | ||
351 | xfs_ilock(ip, XFS_ILOCK_EXCL); | ||
352 | *fsynced = 1; | ||
353 | } else { | ||
354 | *ioflags |= BMAPI_SYNC; | ||
355 | *fsynced = 2; | ||
356 | } | ||
357 | return 0; | ||
358 | case 1: | ||
359 | *fsynced = 2; | ||
360 | *ioflags |= BMAPI_SYNC; | ||
361 | return 0; | ||
362 | case 2: | ||
363 | xfs_iunlock(ip, XFS_ILOCK_EXCL); | ||
364 | xfs_flush_device(ip); | ||
365 | xfs_ilock(ip, XFS_ILOCK_EXCL); | ||
366 | *fsynced = 3; | ||
367 | return 0; | ||
368 | } | ||
369 | return 1; | ||
370 | } | ||
371 | |||
372 | STATIC int | ||
373 | xfs_cmn_err_fsblock_zero( | 341 | xfs_cmn_err_fsblock_zero( |
374 | xfs_inode_t *ip, | 342 | xfs_inode_t *ip, |
375 | xfs_bmbt_irec_t *imap) | 343 | xfs_bmbt_irec_t *imap) |
@@ -538,15 +506,9 @@ error_out: | |||
538 | } | 506 | } |
539 | 507 | ||
540 | /* | 508 | /* |
541 | * If the caller is doing a write at the end of the file, | 509 | * If the caller is doing a write at the end of the file, then extend the |
542 | * then extend the allocation out to the file system's write | 510 | * allocation out to the file system's write iosize. We clean up any extra |
543 | * iosize. We clean up any extra space left over when the | 511 | * space left over when the file is closed in xfs_inactive(). |
544 | * file is closed in xfs_inactive(). | ||
545 | * | ||
546 | * For sync writes, we are flushing delayed allocate space to | ||
547 | * try to make additional space available for allocation near | ||
548 | * the filesystem full boundary - preallocation hurts in that | ||
549 | * situation, of course. | ||
550 | */ | 512 | */ |
551 | STATIC int | 513 | STATIC int |
552 | xfs_iomap_eof_want_preallocate( | 514 | xfs_iomap_eof_want_preallocate( |
@@ -565,7 +527,7 @@ xfs_iomap_eof_want_preallocate( | |||
565 | int n, error, imaps; | 527 | int n, error, imaps; |
566 | 528 | ||
567 | *prealloc = 0; | 529 | *prealloc = 0; |
568 | if ((ioflag & BMAPI_SYNC) || (offset + count) <= ip->i_size) | 530 | if ((offset + count) <= ip->i_size) |
569 | return 0; | 531 | return 0; |
570 | 532 | ||
571 | /* | 533 | /* |
@@ -611,7 +573,7 @@ xfs_iomap_write_delay( | |||
611 | xfs_extlen_t extsz; | 573 | xfs_extlen_t extsz; |
612 | int nimaps; | 574 | int nimaps; |
613 | xfs_bmbt_irec_t imap[XFS_WRITE_IMAPS]; | 575 | xfs_bmbt_irec_t imap[XFS_WRITE_IMAPS]; |
614 | int prealloc, fsynced = 0; | 576 | int prealloc, flushed = 0; |
615 | int error; | 577 | int error; |
616 | 578 | ||
617 | ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); | 579 | ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); |
@@ -627,12 +589,12 @@ xfs_iomap_write_delay( | |||
627 | extsz = xfs_get_extsz_hint(ip); | 589 | extsz = xfs_get_extsz_hint(ip); |
628 | offset_fsb = XFS_B_TO_FSBT(mp, offset); | 590 | offset_fsb = XFS_B_TO_FSBT(mp, offset); |
629 | 591 | ||
630 | retry: | ||
631 | error = xfs_iomap_eof_want_preallocate(mp, ip, offset, count, | 592 | error = xfs_iomap_eof_want_preallocate(mp, ip, offset, count, |
632 | ioflag, imap, XFS_WRITE_IMAPS, &prealloc); | 593 | ioflag, imap, XFS_WRITE_IMAPS, &prealloc); |
633 | if (error) | 594 | if (error) |
634 | return error; | 595 | return error; |
635 | 596 | ||
597 | retry: | ||
636 | if (prealloc) { | 598 | if (prealloc) { |
637 | aligned_offset = XFS_WRITEIO_ALIGN(mp, (offset + count - 1)); | 599 | aligned_offset = XFS_WRITEIO_ALIGN(mp, (offset + count - 1)); |
638 | ioalign = XFS_B_TO_FSBT(mp, aligned_offset); | 600 | ioalign = XFS_B_TO_FSBT(mp, aligned_offset); |
@@ -659,15 +621,22 @@ retry: | |||
659 | 621 | ||
660 | /* | 622 | /* |
661 | * If bmapi returned us nothing, and if we didn't get back EDQUOT, | 623 | * If bmapi returned us nothing, and if we didn't get back EDQUOT, |
662 | * then we must have run out of space - flush delalloc, and retry.. | 624 | * then we must have run out of space - flush all other inodes with |
625 | * delalloc blocks and retry without EOF preallocation. | ||
663 | */ | 626 | */ |
664 | if (nimaps == 0) { | 627 | if (nimaps == 0) { |
665 | xfs_iomap_enter_trace(XFS_IOMAP_WRITE_NOSPACE, | 628 | xfs_iomap_enter_trace(XFS_IOMAP_WRITE_NOSPACE, |
666 | ip, offset, count); | 629 | ip, offset, count); |
667 | if (xfs_flush_space(ip, &fsynced, &ioflag)) | 630 | if (flushed) |
668 | return XFS_ERROR(ENOSPC); | 631 | return XFS_ERROR(ENOSPC); |
669 | 632 | ||
633 | xfs_iunlock(ip, XFS_ILOCK_EXCL); | ||
634 | xfs_flush_inodes(ip); | ||
635 | xfs_ilock(ip, XFS_ILOCK_EXCL); | ||
636 | |||
637 | flushed = 1; | ||
670 | error = 0; | 638 | error = 0; |
639 | prealloc = 0; | ||
671 | goto retry; | 640 | goto retry; |
672 | } | 641 | } |
673 | 642 | ||
diff --git a/fs/xfs/xfs_iomap.h b/fs/xfs/xfs_iomap.h index a1cc1322fc0f..fdcf7b82747f 100644 --- a/fs/xfs/xfs_iomap.h +++ b/fs/xfs/xfs_iomap.h | |||
@@ -40,8 +40,7 @@ typedef enum { | |||
40 | BMAPI_IGNSTATE = (1 << 4), /* ignore unwritten state on read */ | 40 | BMAPI_IGNSTATE = (1 << 4), /* ignore unwritten state on read */ |
41 | BMAPI_DIRECT = (1 << 5), /* direct instead of buffered write */ | 41 | BMAPI_DIRECT = (1 << 5), /* direct instead of buffered write */ |
42 | BMAPI_MMAP = (1 << 6), /* allocate for mmap write */ | 42 | BMAPI_MMAP = (1 << 6), /* allocate for mmap write */ |
43 | BMAPI_SYNC = (1 << 7), /* sync write to flush delalloc space */ | 43 | BMAPI_TRYLOCK = (1 << 7), /* non-blocking request */ |
44 | BMAPI_TRYLOCK = (1 << 8), /* non-blocking request */ | ||
45 | } bmapi_flags_t; | 44 | } bmapi_flags_t; |
46 | 45 | ||
47 | 46 | ||
diff --git a/fs/xfs/xfs_log.c b/fs/xfs/xfs_log.c index f76c6d7cea21..3750f04ede0b 100644 --- a/fs/xfs/xfs_log.c +++ b/fs/xfs/xfs_log.c | |||
@@ -562,9 +562,8 @@ xfs_log_mount( | |||
562 | } | 562 | } |
563 | 563 | ||
564 | mp->m_log = xlog_alloc_log(mp, log_target, blk_offset, num_bblks); | 564 | mp->m_log = xlog_alloc_log(mp, log_target, blk_offset, num_bblks); |
565 | if (!mp->m_log) { | 565 | if (IS_ERR(mp->m_log)) { |
566 | cmn_err(CE_WARN, "XFS: Log allocation failed: No memory!"); | 566 | error = -PTR_ERR(mp->m_log); |
567 | error = ENOMEM; | ||
568 | goto out; | 567 | goto out; |
569 | } | 568 | } |
570 | 569 | ||
@@ -1180,10 +1179,13 @@ xlog_alloc_log(xfs_mount_t *mp, | |||
1180 | xfs_buf_t *bp; | 1179 | xfs_buf_t *bp; |
1181 | int i; | 1180 | int i; |
1182 | int iclogsize; | 1181 | int iclogsize; |
1182 | int error = ENOMEM; | ||
1183 | 1183 | ||
1184 | log = kmem_zalloc(sizeof(xlog_t), KM_MAYFAIL); | 1184 | log = kmem_zalloc(sizeof(xlog_t), KM_MAYFAIL); |
1185 | if (!log) | 1185 | if (!log) { |
1186 | return NULL; | 1186 | xlog_warn("XFS: Log allocation failed: No memory!"); |
1187 | goto out; | ||
1188 | } | ||
1187 | 1189 | ||
1188 | log->l_mp = mp; | 1190 | log->l_mp = mp; |
1189 | log->l_targ = log_target; | 1191 | log->l_targ = log_target; |
@@ -1201,19 +1203,35 @@ xlog_alloc_log(xfs_mount_t *mp, | |||
1201 | log->l_grant_reserve_cycle = 1; | 1203 | log->l_grant_reserve_cycle = 1; |
1202 | log->l_grant_write_cycle = 1; | 1204 | log->l_grant_write_cycle = 1; |
1203 | 1205 | ||
1206 | error = EFSCORRUPTED; | ||
1204 | if (xfs_sb_version_hassector(&mp->m_sb)) { | 1207 | if (xfs_sb_version_hassector(&mp->m_sb)) { |
1205 | log->l_sectbb_log = mp->m_sb.sb_logsectlog - BBSHIFT; | 1208 | log->l_sectbb_log = mp->m_sb.sb_logsectlog - BBSHIFT; |
1206 | ASSERT(log->l_sectbb_log <= mp->m_sectbb_log); | 1209 | if (log->l_sectbb_log < 0 || |
1210 | log->l_sectbb_log > mp->m_sectbb_log) { | ||
1211 | xlog_warn("XFS: Log sector size (0x%x) out of range.", | ||
1212 | log->l_sectbb_log); | ||
1213 | goto out_free_log; | ||
1214 | } | ||
1215 | |||
1207 | /* for larger sector sizes, must have v2 or external log */ | 1216 | /* for larger sector sizes, must have v2 or external log */ |
1208 | ASSERT(log->l_sectbb_log == 0 || | 1217 | if (log->l_sectbb_log != 0 && |
1209 | log->l_logBBstart == 0 || | 1218 | (log->l_logBBstart != 0 && |
1210 | xfs_sb_version_haslogv2(&mp->m_sb)); | 1219 | !xfs_sb_version_haslogv2(&mp->m_sb))) { |
1211 | ASSERT(mp->m_sb.sb_logsectlog >= BBSHIFT); | 1220 | xlog_warn("XFS: log sector size (0x%x) invalid " |
1221 | "for configuration.", log->l_sectbb_log); | ||
1222 | goto out_free_log; | ||
1223 | } | ||
1224 | if (mp->m_sb.sb_logsectlog < BBSHIFT) { | ||
1225 | xlog_warn("XFS: Log sector log (0x%x) too small.", | ||
1226 | mp->m_sb.sb_logsectlog); | ||
1227 | goto out_free_log; | ||
1228 | } | ||
1212 | } | 1229 | } |
1213 | log->l_sectbb_mask = (1 << log->l_sectbb_log) - 1; | 1230 | log->l_sectbb_mask = (1 << log->l_sectbb_log) - 1; |
1214 | 1231 | ||
1215 | xlog_get_iclog_buffer_size(mp, log); | 1232 | xlog_get_iclog_buffer_size(mp, log); |
1216 | 1233 | ||
1234 | error = ENOMEM; | ||
1217 | bp = xfs_buf_get_empty(log->l_iclog_size, mp->m_logdev_targp); | 1235 | bp = xfs_buf_get_empty(log->l_iclog_size, mp->m_logdev_targp); |
1218 | if (!bp) | 1236 | if (!bp) |
1219 | goto out_free_log; | 1237 | goto out_free_log; |
@@ -1313,7 +1331,8 @@ out_free_iclog: | |||
1313 | xfs_buf_free(log->l_xbuf); | 1331 | xfs_buf_free(log->l_xbuf); |
1314 | out_free_log: | 1332 | out_free_log: |
1315 | kmem_free(log); | 1333 | kmem_free(log); |
1316 | return NULL; | 1334 | out: |
1335 | return ERR_PTR(-error); | ||
1317 | } /* xlog_alloc_log */ | 1336 | } /* xlog_alloc_log */ |
1318 | 1337 | ||
1319 | 1338 | ||
@@ -2541,18 +2560,19 @@ redo: | |||
2541 | xlog_ins_ticketq(&log->l_reserve_headq, tic); | 2560 | xlog_ins_ticketq(&log->l_reserve_headq, tic); |
2542 | xlog_trace_loggrant(log, tic, | 2561 | xlog_trace_loggrant(log, tic, |
2543 | "xlog_grant_log_space: sleep 2"); | 2562 | "xlog_grant_log_space: sleep 2"); |
2563 | spin_unlock(&log->l_grant_lock); | ||
2564 | xlog_grant_push_ail(log->l_mp, need_bytes); | ||
2565 | spin_lock(&log->l_grant_lock); | ||
2566 | |||
2544 | XFS_STATS_INC(xs_sleep_logspace); | 2567 | XFS_STATS_INC(xs_sleep_logspace); |
2545 | sv_wait(&tic->t_wait, PINOD|PLTWAIT, &log->l_grant_lock, s); | 2568 | sv_wait(&tic->t_wait, PINOD|PLTWAIT, &log->l_grant_lock, s); |
2546 | 2569 | ||
2547 | if (XLOG_FORCED_SHUTDOWN(log)) { | 2570 | spin_lock(&log->l_grant_lock); |
2548 | spin_lock(&log->l_grant_lock); | 2571 | if (XLOG_FORCED_SHUTDOWN(log)) |
2549 | goto error_return; | 2572 | goto error_return; |
2550 | } | ||
2551 | 2573 | ||
2552 | xlog_trace_loggrant(log, tic, | 2574 | xlog_trace_loggrant(log, tic, |
2553 | "xlog_grant_log_space: wake 2"); | 2575 | "xlog_grant_log_space: wake 2"); |
2554 | xlog_grant_push_ail(log->l_mp, need_bytes); | ||
2555 | spin_lock(&log->l_grant_lock); | ||
2556 | goto redo; | 2576 | goto redo; |
2557 | } else if (tic->t_flags & XLOG_TIC_IN_Q) | 2577 | } else if (tic->t_flags & XLOG_TIC_IN_Q) |
2558 | xlog_del_ticketq(&log->l_reserve_headq, tic); | 2578 | xlog_del_ticketq(&log->l_reserve_headq, tic); |
@@ -2631,7 +2651,7 @@ xlog_regrant_write_log_space(xlog_t *log, | |||
2631 | * for more free space, otherwise try to get some space for | 2651 | * for more free space, otherwise try to get some space for |
2632 | * this transaction. | 2652 | * this transaction. |
2633 | */ | 2653 | */ |
2634 | 2654 | need_bytes = tic->t_unit_res; | |
2635 | if ((ntic = log->l_write_headq)) { | 2655 | if ((ntic = log->l_write_headq)) { |
2636 | free_bytes = xlog_space_left(log, log->l_grant_write_cycle, | 2656 | free_bytes = xlog_space_left(log, log->l_grant_write_cycle, |
2637 | log->l_grant_write_bytes); | 2657 | log->l_grant_write_bytes); |
@@ -2651,26 +2671,25 @@ xlog_regrant_write_log_space(xlog_t *log, | |||
2651 | 2671 | ||
2652 | xlog_trace_loggrant(log, tic, | 2672 | xlog_trace_loggrant(log, tic, |
2653 | "xlog_regrant_write_log_space: sleep 1"); | 2673 | "xlog_regrant_write_log_space: sleep 1"); |
2674 | spin_unlock(&log->l_grant_lock); | ||
2675 | xlog_grant_push_ail(log->l_mp, need_bytes); | ||
2676 | spin_lock(&log->l_grant_lock); | ||
2677 | |||
2654 | XFS_STATS_INC(xs_sleep_logspace); | 2678 | XFS_STATS_INC(xs_sleep_logspace); |
2655 | sv_wait(&tic->t_wait, PINOD|PLTWAIT, | 2679 | sv_wait(&tic->t_wait, PINOD|PLTWAIT, |
2656 | &log->l_grant_lock, s); | 2680 | &log->l_grant_lock, s); |
2657 | 2681 | ||
2658 | /* If we're shutting down, this tic is already | 2682 | /* If we're shutting down, this tic is already |
2659 | * off the queue */ | 2683 | * off the queue */ |
2660 | if (XLOG_FORCED_SHUTDOWN(log)) { | 2684 | spin_lock(&log->l_grant_lock); |
2661 | spin_lock(&log->l_grant_lock); | 2685 | if (XLOG_FORCED_SHUTDOWN(log)) |
2662 | goto error_return; | 2686 | goto error_return; |
2663 | } | ||
2664 | 2687 | ||
2665 | xlog_trace_loggrant(log, tic, | 2688 | xlog_trace_loggrant(log, tic, |
2666 | "xlog_regrant_write_log_space: wake 1"); | 2689 | "xlog_regrant_write_log_space: wake 1"); |
2667 | xlog_grant_push_ail(log->l_mp, tic->t_unit_res); | ||
2668 | spin_lock(&log->l_grant_lock); | ||
2669 | } | 2690 | } |
2670 | } | 2691 | } |
2671 | 2692 | ||
2672 | need_bytes = tic->t_unit_res; | ||
2673 | |||
2674 | redo: | 2693 | redo: |
2675 | if (XLOG_FORCED_SHUTDOWN(log)) | 2694 | if (XLOG_FORCED_SHUTDOWN(log)) |
2676 | goto error_return; | 2695 | goto error_return; |
@@ -2680,19 +2699,20 @@ redo: | |||
2680 | if (free_bytes < need_bytes) { | 2699 | if (free_bytes < need_bytes) { |
2681 | if ((tic->t_flags & XLOG_TIC_IN_Q) == 0) | 2700 | if ((tic->t_flags & XLOG_TIC_IN_Q) == 0) |
2682 | xlog_ins_ticketq(&log->l_write_headq, tic); | 2701 | xlog_ins_ticketq(&log->l_write_headq, tic); |
2702 | spin_unlock(&log->l_grant_lock); | ||
2703 | xlog_grant_push_ail(log->l_mp, need_bytes); | ||
2704 | spin_lock(&log->l_grant_lock); | ||
2705 | |||
2683 | XFS_STATS_INC(xs_sleep_logspace); | 2706 | XFS_STATS_INC(xs_sleep_logspace); |
2684 | sv_wait(&tic->t_wait, PINOD|PLTWAIT, &log->l_grant_lock, s); | 2707 | sv_wait(&tic->t_wait, PINOD|PLTWAIT, &log->l_grant_lock, s); |
2685 | 2708 | ||
2686 | /* If we're shutting down, this tic is already off the queue */ | 2709 | /* If we're shutting down, this tic is already off the queue */ |
2687 | if (XLOG_FORCED_SHUTDOWN(log)) { | 2710 | spin_lock(&log->l_grant_lock); |
2688 | spin_lock(&log->l_grant_lock); | 2711 | if (XLOG_FORCED_SHUTDOWN(log)) |
2689 | goto error_return; | 2712 | goto error_return; |
2690 | } | ||
2691 | 2713 | ||
2692 | xlog_trace_loggrant(log, tic, | 2714 | xlog_trace_loggrant(log, tic, |
2693 | "xlog_regrant_write_log_space: wake 2"); | 2715 | "xlog_regrant_write_log_space: wake 2"); |
2694 | xlog_grant_push_ail(log->l_mp, need_bytes); | ||
2695 | spin_lock(&log->l_grant_lock); | ||
2696 | goto redo; | 2716 | goto redo; |
2697 | } else if (tic->t_flags & XLOG_TIC_IN_Q) | 2717 | } else if (tic->t_flags & XLOG_TIC_IN_Q) |
2698 | xlog_del_ticketq(&log->l_write_headq, tic); | 2718 | xlog_del_ticketq(&log->l_write_headq, tic); |
diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h index 7af44adffc8f..d6a64392f983 100644 --- a/fs/xfs/xfs_mount.h +++ b/fs/xfs/xfs_mount.h | |||
@@ -313,7 +313,7 @@ typedef struct xfs_mount { | |||
313 | #endif | 313 | #endif |
314 | struct xfs_mru_cache *m_filestream; /* per-mount filestream data */ | 314 | struct xfs_mru_cache *m_filestream; /* per-mount filestream data */ |
315 | struct task_struct *m_sync_task; /* generalised sync thread */ | 315 | struct task_struct *m_sync_task; /* generalised sync thread */ |
316 | bhv_vfs_sync_work_t m_sync_work; /* work item for VFS_SYNC */ | 316 | xfs_sync_work_t m_sync_work; /* work item for VFS_SYNC */ |
317 | struct list_head m_sync_list; /* sync thread work item list */ | 317 | struct list_head m_sync_list; /* sync thread work item list */ |
318 | spinlock_t m_sync_lock; /* work item list lock */ | 318 | spinlock_t m_sync_lock; /* work item list lock */ |
319 | int m_sync_seq; /* sync thread generation no. */ | 319 | int m_sync_seq; /* sync thread generation no. */ |
diff --git a/fs/xfs/xfs_vnodeops.c b/fs/xfs/xfs_vnodeops.c index 7394c7af5de5..19cf90a9c762 100644 --- a/fs/xfs/xfs_vnodeops.c +++ b/fs/xfs/xfs_vnodeops.c | |||
@@ -1457,6 +1457,13 @@ xfs_create( | |||
1457 | error = xfs_trans_reserve(tp, resblks, log_res, 0, | 1457 | error = xfs_trans_reserve(tp, resblks, log_res, 0, |
1458 | XFS_TRANS_PERM_LOG_RES, log_count); | 1458 | XFS_TRANS_PERM_LOG_RES, log_count); |
1459 | if (error == ENOSPC) { | 1459 | if (error == ENOSPC) { |
1460 | /* flush outstanding delalloc blocks and retry */ | ||
1461 | xfs_flush_inodes(dp); | ||
1462 | error = xfs_trans_reserve(tp, resblks, XFS_CREATE_LOG_RES(mp), 0, | ||
1463 | XFS_TRANS_PERM_LOG_RES, XFS_CREATE_LOG_COUNT); | ||
1464 | } | ||
1465 | if (error == ENOSPC) { | ||
1466 | /* No space at all so try a "no-allocation" reservation */ | ||
1460 | resblks = 0; | 1467 | resblks = 0; |
1461 | error = xfs_trans_reserve(tp, 0, log_res, 0, | 1468 | error = xfs_trans_reserve(tp, 0, log_res, 0, |
1462 | XFS_TRANS_PERM_LOG_RES, log_count); | 1469 | XFS_TRANS_PERM_LOG_RES, log_count); |