diff options
author | Jiri Kosina <jkosina@suse.cz> | 2011-02-15 04:24:31 -0500 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2011-02-15 04:24:31 -0500 |
commit | 0a9d59a2461477bd9ed143c01af9df3f8f00fa81 (patch) | |
tree | df997d1cfb0786427a0df1fbd6f0640fa4248cf4 /fs/xfs | |
parent | a23ce6da9677d245aa0aadc99f4197030350ab54 (diff) | |
parent | 795abaf1e4e188c4171e3cd3dbb11a9fcacaf505 (diff) |
Merge branch 'master' into for-next
Diffstat (limited to 'fs/xfs')
30 files changed, 935 insertions, 608 deletions
diff --git a/fs/xfs/Makefile b/fs/xfs/Makefile index 0dce969d6cad..faca44997099 100644 --- a/fs/xfs/Makefile +++ b/fs/xfs/Makefile | |||
@@ -98,6 +98,7 @@ xfs-y += $(addprefix $(XFS_LINUX)/, \ | |||
98 | kmem.o \ | 98 | kmem.o \ |
99 | xfs_aops.o \ | 99 | xfs_aops.o \ |
100 | xfs_buf.o \ | 100 | xfs_buf.o \ |
101 | xfs_discard.o \ | ||
101 | xfs_export.o \ | 102 | xfs_export.o \ |
102 | xfs_file.o \ | 103 | xfs_file.o \ |
103 | xfs_fs_subr.o \ | 104 | xfs_fs_subr.o \ |
diff --git a/fs/xfs/linux-2.6/xfs_buf.c b/fs/xfs/linux-2.6/xfs_buf.c index 92f1f2acc6ab..ac1c7e8378dd 100644 --- a/fs/xfs/linux-2.6/xfs_buf.c +++ b/fs/xfs/linux-2.6/xfs_buf.c | |||
@@ -896,7 +896,6 @@ xfs_buf_rele( | |||
896 | trace_xfs_buf_rele(bp, _RET_IP_); | 896 | trace_xfs_buf_rele(bp, _RET_IP_); |
897 | 897 | ||
898 | if (!pag) { | 898 | if (!pag) { |
899 | ASSERT(!bp->b_relse); | ||
900 | ASSERT(list_empty(&bp->b_lru)); | 899 | ASSERT(list_empty(&bp->b_lru)); |
901 | ASSERT(RB_EMPTY_NODE(&bp->b_rbnode)); | 900 | ASSERT(RB_EMPTY_NODE(&bp->b_rbnode)); |
902 | if (atomic_dec_and_test(&bp->b_hold)) | 901 | if (atomic_dec_and_test(&bp->b_hold)) |
@@ -908,11 +907,7 @@ xfs_buf_rele( | |||
908 | 907 | ||
909 | ASSERT(atomic_read(&bp->b_hold) > 0); | 908 | ASSERT(atomic_read(&bp->b_hold) > 0); |
910 | if (atomic_dec_and_lock(&bp->b_hold, &pag->pag_buf_lock)) { | 909 | if (atomic_dec_and_lock(&bp->b_hold, &pag->pag_buf_lock)) { |
911 | if (bp->b_relse) { | 910 | if (!(bp->b_flags & XBF_STALE) && |
912 | atomic_inc(&bp->b_hold); | ||
913 | spin_unlock(&pag->pag_buf_lock); | ||
914 | bp->b_relse(bp); | ||
915 | } else if (!(bp->b_flags & XBF_STALE) && | ||
916 | atomic_read(&bp->b_lru_ref)) { | 911 | atomic_read(&bp->b_lru_ref)) { |
917 | xfs_buf_lru_add(bp); | 912 | xfs_buf_lru_add(bp); |
918 | spin_unlock(&pag->pag_buf_lock); | 913 | spin_unlock(&pag->pag_buf_lock); |
diff --git a/fs/xfs/linux-2.6/xfs_buf.h b/fs/xfs/linux-2.6/xfs_buf.h index a76c2428faff..cbe65950e524 100644 --- a/fs/xfs/linux-2.6/xfs_buf.h +++ b/fs/xfs/linux-2.6/xfs_buf.h | |||
@@ -152,8 +152,6 @@ typedef struct xfs_buftarg { | |||
152 | 152 | ||
153 | struct xfs_buf; | 153 | struct xfs_buf; |
154 | typedef void (*xfs_buf_iodone_t)(struct xfs_buf *); | 154 | typedef void (*xfs_buf_iodone_t)(struct xfs_buf *); |
155 | typedef void (*xfs_buf_relse_t)(struct xfs_buf *); | ||
156 | typedef int (*xfs_buf_bdstrat_t)(struct xfs_buf *); | ||
157 | 155 | ||
158 | #define XB_PAGES 2 | 156 | #define XB_PAGES 2 |
159 | 157 | ||
@@ -183,7 +181,6 @@ typedef struct xfs_buf { | |||
183 | void *b_addr; /* virtual address of buffer */ | 181 | void *b_addr; /* virtual address of buffer */ |
184 | struct work_struct b_iodone_work; | 182 | struct work_struct b_iodone_work; |
185 | xfs_buf_iodone_t b_iodone; /* I/O completion function */ | 183 | xfs_buf_iodone_t b_iodone; /* I/O completion function */ |
186 | xfs_buf_relse_t b_relse; /* releasing function */ | ||
187 | struct completion b_iowait; /* queue for I/O waiters */ | 184 | struct completion b_iowait; /* queue for I/O waiters */ |
188 | void *b_fspriv; | 185 | void *b_fspriv; |
189 | void *b_fspriv2; | 186 | void *b_fspriv2; |
@@ -323,7 +320,6 @@ void xfs_buf_stale(struct xfs_buf *bp); | |||
323 | #define XFS_BUF_FSPRIVATE2(bp, type) ((type)(bp)->b_fspriv2) | 320 | #define XFS_BUF_FSPRIVATE2(bp, type) ((type)(bp)->b_fspriv2) |
324 | #define XFS_BUF_SET_FSPRIVATE2(bp, val) ((bp)->b_fspriv2 = (void*)(val)) | 321 | #define XFS_BUF_SET_FSPRIVATE2(bp, val) ((bp)->b_fspriv2 = (void*)(val)) |
325 | #define XFS_BUF_SET_START(bp) do { } while (0) | 322 | #define XFS_BUF_SET_START(bp) do { } while (0) |
326 | #define XFS_BUF_SET_BRELSE_FUNC(bp, func) ((bp)->b_relse = (func)) | ||
327 | 323 | ||
328 | #define XFS_BUF_PTR(bp) (xfs_caddr_t)((bp)->b_addr) | 324 | #define XFS_BUF_PTR(bp) (xfs_caddr_t)((bp)->b_addr) |
329 | #define XFS_BUF_SET_PTR(bp, val, cnt) xfs_buf_associate_memory(bp, val, cnt) | 325 | #define XFS_BUF_SET_PTR(bp, val, cnt) xfs_buf_associate_memory(bp, val, cnt) |
@@ -360,8 +356,7 @@ xfs_buf_set_ref( | |||
360 | 356 | ||
361 | static inline void xfs_buf_relse(xfs_buf_t *bp) | 357 | static inline void xfs_buf_relse(xfs_buf_t *bp) |
362 | { | 358 | { |
363 | if (!bp->b_relse) | 359 | xfs_buf_unlock(bp); |
364 | xfs_buf_unlock(bp); | ||
365 | xfs_buf_rele(bp); | 360 | xfs_buf_rele(bp); |
366 | } | 361 | } |
367 | 362 | ||
diff --git a/fs/xfs/linux-2.6/xfs_discard.c b/fs/xfs/linux-2.6/xfs_discard.c new file mode 100644 index 000000000000..05201ae719e5 --- /dev/null +++ b/fs/xfs/linux-2.6/xfs_discard.c | |||
@@ -0,0 +1,191 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2010 Red Hat, Inc. | ||
3 | * All Rights Reserved. | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or | ||
6 | * modify it under the terms of the GNU General Public License as | ||
7 | * published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope that it would be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write the Free Software Foundation, | ||
16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
17 | */ | ||
18 | #include "xfs.h" | ||
19 | #include "xfs_sb.h" | ||
20 | #include "xfs_inum.h" | ||
21 | #include "xfs_log.h" | ||
22 | #include "xfs_ag.h" | ||
23 | #include "xfs_mount.h" | ||
24 | #include "xfs_quota.h" | ||
25 | #include "xfs_trans.h" | ||
26 | #include "xfs_alloc_btree.h" | ||
27 | #include "xfs_bmap_btree.h" | ||
28 | #include "xfs_ialloc_btree.h" | ||
29 | #include "xfs_btree.h" | ||
30 | #include "xfs_inode.h" | ||
31 | #include "xfs_alloc.h" | ||
32 | #include "xfs_error.h" | ||
33 | #include "xfs_discard.h" | ||
34 | #include "xfs_trace.h" | ||
35 | |||
36 | STATIC int | ||
37 | xfs_trim_extents( | ||
38 | struct xfs_mount *mp, | ||
39 | xfs_agnumber_t agno, | ||
40 | xfs_fsblock_t start, | ||
41 | xfs_fsblock_t len, | ||
42 | xfs_fsblock_t minlen, | ||
43 | __uint64_t *blocks_trimmed) | ||
44 | { | ||
45 | struct block_device *bdev = mp->m_ddev_targp->bt_bdev; | ||
46 | struct xfs_btree_cur *cur; | ||
47 | struct xfs_buf *agbp; | ||
48 | struct xfs_perag *pag; | ||
49 | int error; | ||
50 | int i; | ||
51 | |||
52 | pag = xfs_perag_get(mp, agno); | ||
53 | |||
54 | error = xfs_alloc_read_agf(mp, NULL, agno, 0, &agbp); | ||
55 | if (error || !agbp) | ||
56 | goto out_put_perag; | ||
57 | |||
58 | cur = xfs_allocbt_init_cursor(mp, NULL, agbp, agno, XFS_BTNUM_CNT); | ||
59 | |||
60 | /* | ||
61 | * Force out the log. This means any transactions that might have freed | ||
62 | * space before we took the AGF buffer lock are now on disk, and the | ||
63 | * volatile disk cache is flushed. | ||
64 | */ | ||
65 | xfs_log_force(mp, XFS_LOG_SYNC); | ||
66 | |||
67 | /* | ||
68 | * Look up the longest btree in the AGF and start with it. | ||
69 | */ | ||
70 | error = xfs_alloc_lookup_le(cur, 0, | ||
71 | XFS_BUF_TO_AGF(agbp)->agf_longest, &i); | ||
72 | if (error) | ||
73 | goto out_del_cursor; | ||
74 | |||
75 | /* | ||
76 | * Loop until we are done with all extents that are large | ||
77 | * enough to be worth discarding. | ||
78 | */ | ||
79 | while (i) { | ||
80 | xfs_agblock_t fbno; | ||
81 | xfs_extlen_t flen; | ||
82 | |||
83 | error = xfs_alloc_get_rec(cur, &fbno, &flen, &i); | ||
84 | if (error) | ||
85 | goto out_del_cursor; | ||
86 | XFS_WANT_CORRUPTED_GOTO(i == 1, out_del_cursor); | ||
87 | ASSERT(flen <= XFS_BUF_TO_AGF(agbp)->agf_longest); | ||
88 | |||
89 | /* | ||
90 | * Too small? Give up. | ||
91 | */ | ||
92 | if (flen < minlen) { | ||
93 | trace_xfs_discard_toosmall(mp, agno, fbno, flen); | ||
94 | goto out_del_cursor; | ||
95 | } | ||
96 | |||
97 | /* | ||
98 | * If the extent is entirely outside of the range we are | ||
99 | * supposed to discard skip it. Do not bother to trim | ||
100 | * down partially overlapping ranges for now. | ||
101 | */ | ||
102 | if (XFS_AGB_TO_FSB(mp, agno, fbno) + flen < start || | ||
103 | XFS_AGB_TO_FSB(mp, agno, fbno) >= start + len) { | ||
104 | trace_xfs_discard_exclude(mp, agno, fbno, flen); | ||
105 | goto next_extent; | ||
106 | } | ||
107 | |||
108 | /* | ||
109 | * If any blocks in the range are still busy, skip the | ||
110 | * discard and try again the next time. | ||
111 | */ | ||
112 | if (xfs_alloc_busy_search(mp, agno, fbno, flen)) { | ||
113 | trace_xfs_discard_busy(mp, agno, fbno, flen); | ||
114 | goto next_extent; | ||
115 | } | ||
116 | |||
117 | trace_xfs_discard_extent(mp, agno, fbno, flen); | ||
118 | error = -blkdev_issue_discard(bdev, | ||
119 | XFS_AGB_TO_DADDR(mp, agno, fbno), | ||
120 | XFS_FSB_TO_BB(mp, flen), | ||
121 | GFP_NOFS, 0); | ||
122 | if (error) | ||
123 | goto out_del_cursor; | ||
124 | *blocks_trimmed += flen; | ||
125 | |||
126 | next_extent: | ||
127 | error = xfs_btree_decrement(cur, 0, &i); | ||
128 | if (error) | ||
129 | goto out_del_cursor; | ||
130 | } | ||
131 | |||
132 | out_del_cursor: | ||
133 | xfs_btree_del_cursor(cur, error ? XFS_BTREE_ERROR : XFS_BTREE_NOERROR); | ||
134 | xfs_buf_relse(agbp); | ||
135 | out_put_perag: | ||
136 | xfs_perag_put(pag); | ||
137 | return error; | ||
138 | } | ||
139 | |||
140 | int | ||
141 | xfs_ioc_trim( | ||
142 | struct xfs_mount *mp, | ||
143 | struct fstrim_range __user *urange) | ||
144 | { | ||
145 | struct request_queue *q = mp->m_ddev_targp->bt_bdev->bd_disk->queue; | ||
146 | unsigned int granularity = q->limits.discard_granularity; | ||
147 | struct fstrim_range range; | ||
148 | xfs_fsblock_t start, len, minlen; | ||
149 | xfs_agnumber_t start_agno, end_agno, agno; | ||
150 | __uint64_t blocks_trimmed = 0; | ||
151 | int error, last_error = 0; | ||
152 | |||
153 | if (!capable(CAP_SYS_ADMIN)) | ||
154 | return -XFS_ERROR(EPERM); | ||
155 | if (copy_from_user(&range, urange, sizeof(range))) | ||
156 | return -XFS_ERROR(EFAULT); | ||
157 | |||
158 | /* | ||
159 | * Truncating down the len isn't actually quite correct, but using | ||
160 | * XFS_B_TO_FSB would mean we trivially get overflows for values | ||
161 | * of ULLONG_MAX or slightly lower. And ULLONG_MAX is the default | ||
162 | * used by the fstrim application. In the end it really doesn't | ||
163 | * matter as trimming blocks is an advisory interface. | ||
164 | */ | ||
165 | start = XFS_B_TO_FSBT(mp, range.start); | ||
166 | len = XFS_B_TO_FSBT(mp, range.len); | ||
167 | minlen = XFS_B_TO_FSB(mp, max_t(u64, granularity, range.minlen)); | ||
168 | |||
169 | start_agno = XFS_FSB_TO_AGNO(mp, start); | ||
170 | if (start_agno >= mp->m_sb.sb_agcount) | ||
171 | return -XFS_ERROR(EINVAL); | ||
172 | |||
173 | end_agno = XFS_FSB_TO_AGNO(mp, start + len); | ||
174 | if (end_agno >= mp->m_sb.sb_agcount) | ||
175 | end_agno = mp->m_sb.sb_agcount - 1; | ||
176 | |||
177 | for (agno = start_agno; agno <= end_agno; agno++) { | ||
178 | error = -xfs_trim_extents(mp, agno, start, len, minlen, | ||
179 | &blocks_trimmed); | ||
180 | if (error) | ||
181 | last_error = error; | ||
182 | } | ||
183 | |||
184 | if (last_error) | ||
185 | return last_error; | ||
186 | |||
187 | range.len = XFS_FSB_TO_B(mp, blocks_trimmed); | ||
188 | if (copy_to_user(urange, &range, sizeof(range))) | ||
189 | return -XFS_ERROR(EFAULT); | ||
190 | return 0; | ||
191 | } | ||
diff --git a/fs/xfs/linux-2.6/xfs_discard.h b/fs/xfs/linux-2.6/xfs_discard.h new file mode 100644 index 000000000000..e82b6dd3e127 --- /dev/null +++ b/fs/xfs/linux-2.6/xfs_discard.h | |||
@@ -0,0 +1,8 @@ | |||
1 | #ifndef XFS_DISCARD_H | ||
2 | #define XFS_DISCARD_H 1 | ||
3 | |||
4 | struct fstrim_range; | ||
5 | |||
6 | extern int xfs_ioc_trim(struct xfs_mount *, struct fstrim_range __user *); | ||
7 | |||
8 | #endif /* XFS_DISCARD_H */ | ||
diff --git a/fs/xfs/linux-2.6/xfs_file.c b/fs/xfs/linux-2.6/xfs_file.c index ba8ad422a165..a55c1b46b219 100644 --- a/fs/xfs/linux-2.6/xfs_file.c +++ b/fs/xfs/linux-2.6/xfs_file.c | |||
@@ -37,10 +37,45 @@ | |||
37 | #include "xfs_trace.h" | 37 | #include "xfs_trace.h" |
38 | 38 | ||
39 | #include <linux/dcache.h> | 39 | #include <linux/dcache.h> |
40 | #include <linux/falloc.h> | ||
40 | 41 | ||
41 | static const struct vm_operations_struct xfs_file_vm_ops; | 42 | static const struct vm_operations_struct xfs_file_vm_ops; |
42 | 43 | ||
43 | /* | 44 | /* |
45 | * Locking primitives for read and write IO paths to ensure we consistently use | ||
46 | * and order the inode->i_mutex, ip->i_lock and ip->i_iolock. | ||
47 | */ | ||
48 | static inline void | ||
49 | xfs_rw_ilock( | ||
50 | struct xfs_inode *ip, | ||
51 | int type) | ||
52 | { | ||
53 | if (type & XFS_IOLOCK_EXCL) | ||
54 | mutex_lock(&VFS_I(ip)->i_mutex); | ||
55 | xfs_ilock(ip, type); | ||
56 | } | ||
57 | |||
58 | static inline void | ||
59 | xfs_rw_iunlock( | ||
60 | struct xfs_inode *ip, | ||
61 | int type) | ||
62 | { | ||
63 | xfs_iunlock(ip, type); | ||
64 | if (type & XFS_IOLOCK_EXCL) | ||
65 | mutex_unlock(&VFS_I(ip)->i_mutex); | ||
66 | } | ||
67 | |||
68 | static inline void | ||
69 | xfs_rw_ilock_demote( | ||
70 | struct xfs_inode *ip, | ||
71 | int type) | ||
72 | { | ||
73 | xfs_ilock_demote(ip, type); | ||
74 | if (type & XFS_IOLOCK_EXCL) | ||
75 | mutex_unlock(&VFS_I(ip)->i_mutex); | ||
76 | } | ||
77 | |||
78 | /* | ||
44 | * xfs_iozero | 79 | * xfs_iozero |
45 | * | 80 | * |
46 | * xfs_iozero clears the specified range of buffer supplied, | 81 | * xfs_iozero clears the specified range of buffer supplied, |
@@ -262,22 +297,21 @@ xfs_file_aio_read( | |||
262 | if (XFS_FORCED_SHUTDOWN(mp)) | 297 | if (XFS_FORCED_SHUTDOWN(mp)) |
263 | return -EIO; | 298 | return -EIO; |
264 | 299 | ||
265 | if (unlikely(ioflags & IO_ISDIRECT)) | ||
266 | mutex_lock(&inode->i_mutex); | ||
267 | xfs_ilock(ip, XFS_IOLOCK_SHARED); | ||
268 | |||
269 | if (unlikely(ioflags & IO_ISDIRECT)) { | 300 | if (unlikely(ioflags & IO_ISDIRECT)) { |
301 | xfs_rw_ilock(ip, XFS_IOLOCK_EXCL); | ||
302 | |||
270 | if (inode->i_mapping->nrpages) { | 303 | if (inode->i_mapping->nrpages) { |
271 | ret = -xfs_flushinval_pages(ip, | 304 | ret = -xfs_flushinval_pages(ip, |
272 | (iocb->ki_pos & PAGE_CACHE_MASK), | 305 | (iocb->ki_pos & PAGE_CACHE_MASK), |
273 | -1, FI_REMAPF_LOCKED); | 306 | -1, FI_REMAPF_LOCKED); |
307 | if (ret) { | ||
308 | xfs_rw_iunlock(ip, XFS_IOLOCK_EXCL); | ||
309 | return ret; | ||
310 | } | ||
274 | } | 311 | } |
275 | mutex_unlock(&inode->i_mutex); | 312 | xfs_rw_ilock_demote(ip, XFS_IOLOCK_EXCL); |
276 | if (ret) { | 313 | } else |
277 | xfs_iunlock(ip, XFS_IOLOCK_SHARED); | 314 | xfs_rw_ilock(ip, XFS_IOLOCK_SHARED); |
278 | return ret; | ||
279 | } | ||
280 | } | ||
281 | 315 | ||
282 | trace_xfs_file_read(ip, size, iocb->ki_pos, ioflags); | 316 | trace_xfs_file_read(ip, size, iocb->ki_pos, ioflags); |
283 | 317 | ||
@@ -285,7 +319,7 @@ xfs_file_aio_read( | |||
285 | if (ret > 0) | 319 | if (ret > 0) |
286 | XFS_STATS_ADD(xs_read_bytes, ret); | 320 | XFS_STATS_ADD(xs_read_bytes, ret); |
287 | 321 | ||
288 | xfs_iunlock(ip, XFS_IOLOCK_SHARED); | 322 | xfs_rw_iunlock(ip, XFS_IOLOCK_SHARED); |
289 | return ret; | 323 | return ret; |
290 | } | 324 | } |
291 | 325 | ||
@@ -309,7 +343,7 @@ xfs_file_splice_read( | |||
309 | if (XFS_FORCED_SHUTDOWN(ip->i_mount)) | 343 | if (XFS_FORCED_SHUTDOWN(ip->i_mount)) |
310 | return -EIO; | 344 | return -EIO; |
311 | 345 | ||
312 | xfs_ilock(ip, XFS_IOLOCK_SHARED); | 346 | xfs_rw_ilock(ip, XFS_IOLOCK_SHARED); |
313 | 347 | ||
314 | trace_xfs_file_splice_read(ip, count, *ppos, ioflags); | 348 | trace_xfs_file_splice_read(ip, count, *ppos, ioflags); |
315 | 349 | ||
@@ -317,10 +351,61 @@ xfs_file_splice_read( | |||
317 | if (ret > 0) | 351 | if (ret > 0) |
318 | XFS_STATS_ADD(xs_read_bytes, ret); | 352 | XFS_STATS_ADD(xs_read_bytes, ret); |
319 | 353 | ||
320 | xfs_iunlock(ip, XFS_IOLOCK_SHARED); | 354 | xfs_rw_iunlock(ip, XFS_IOLOCK_SHARED); |
321 | return ret; | 355 | return ret; |
322 | } | 356 | } |
323 | 357 | ||
358 | STATIC void | ||
359 | xfs_aio_write_isize_update( | ||
360 | struct inode *inode, | ||
361 | loff_t *ppos, | ||
362 | ssize_t bytes_written) | ||
363 | { | ||
364 | struct xfs_inode *ip = XFS_I(inode); | ||
365 | xfs_fsize_t isize = i_size_read(inode); | ||
366 | |||
367 | if (bytes_written > 0) | ||
368 | XFS_STATS_ADD(xs_write_bytes, bytes_written); | ||
369 | |||
370 | if (unlikely(bytes_written < 0 && bytes_written != -EFAULT && | ||
371 | *ppos > isize)) | ||
372 | *ppos = isize; | ||
373 | |||
374 | if (*ppos > ip->i_size) { | ||
375 | xfs_rw_ilock(ip, XFS_ILOCK_EXCL); | ||
376 | if (*ppos > ip->i_size) | ||
377 | ip->i_size = *ppos; | ||
378 | xfs_rw_iunlock(ip, XFS_ILOCK_EXCL); | ||
379 | } | ||
380 | } | ||
381 | |||
382 | /* | ||
383 | * If this was a direct or synchronous I/O that failed (such as ENOSPC) then | ||
384 | * part of the I/O may have been written to disk before the error occured. In | ||
385 | * this case the on-disk file size may have been adjusted beyond the in-memory | ||
386 | * file size and now needs to be truncated back. | ||
387 | */ | ||
388 | STATIC void | ||
389 | xfs_aio_write_newsize_update( | ||
390 | struct xfs_inode *ip) | ||
391 | { | ||
392 | if (ip->i_new_size) { | ||
393 | xfs_rw_ilock(ip, XFS_ILOCK_EXCL); | ||
394 | ip->i_new_size = 0; | ||
395 | if (ip->i_d.di_size > ip->i_size) | ||
396 | ip->i_d.di_size = ip->i_size; | ||
397 | xfs_rw_iunlock(ip, XFS_ILOCK_EXCL); | ||
398 | } | ||
399 | } | ||
400 | |||
401 | /* | ||
402 | * xfs_file_splice_write() does not use xfs_rw_ilock() because | ||
403 | * generic_file_splice_write() takes the i_mutex itself. This, in theory, | ||
404 | * couuld cause lock inversions between the aio_write path and the splice path | ||
405 | * if someone is doing concurrent splice(2) based writes and write(2) based | ||
406 | * writes to the same inode. The only real way to fix this is to re-implement | ||
407 | * the generic code here with correct locking orders. | ||
408 | */ | ||
324 | STATIC ssize_t | 409 | STATIC ssize_t |
325 | xfs_file_splice_write( | 410 | xfs_file_splice_write( |
326 | struct pipe_inode_info *pipe, | 411 | struct pipe_inode_info *pipe, |
@@ -331,7 +416,7 @@ xfs_file_splice_write( | |||
331 | { | 416 | { |
332 | struct inode *inode = outfilp->f_mapping->host; | 417 | struct inode *inode = outfilp->f_mapping->host; |
333 | struct xfs_inode *ip = XFS_I(inode); | 418 | struct xfs_inode *ip = XFS_I(inode); |
334 | xfs_fsize_t isize, new_size; | 419 | xfs_fsize_t new_size; |
335 | int ioflags = 0; | 420 | int ioflags = 0; |
336 | ssize_t ret; | 421 | ssize_t ret; |
337 | 422 | ||
@@ -355,27 +440,9 @@ xfs_file_splice_write( | |||
355 | trace_xfs_file_splice_write(ip, count, *ppos, ioflags); | 440 | trace_xfs_file_splice_write(ip, count, *ppos, ioflags); |
356 | 441 | ||
357 | ret = generic_file_splice_write(pipe, outfilp, ppos, count, flags); | 442 | ret = generic_file_splice_write(pipe, outfilp, ppos, count, flags); |
358 | if (ret > 0) | ||
359 | XFS_STATS_ADD(xs_write_bytes, ret); | ||
360 | |||
361 | isize = i_size_read(inode); | ||
362 | if (unlikely(ret < 0 && ret != -EFAULT && *ppos > isize)) | ||
363 | *ppos = isize; | ||
364 | |||
365 | if (*ppos > ip->i_size) { | ||
366 | xfs_ilock(ip, XFS_ILOCK_EXCL); | ||
367 | if (*ppos > ip->i_size) | ||
368 | ip->i_size = *ppos; | ||
369 | xfs_iunlock(ip, XFS_ILOCK_EXCL); | ||
370 | } | ||
371 | 443 | ||
372 | if (ip->i_new_size) { | 444 | xfs_aio_write_isize_update(inode, ppos, ret); |
373 | xfs_ilock(ip, XFS_ILOCK_EXCL); | 445 | xfs_aio_write_newsize_update(ip); |
374 | ip->i_new_size = 0; | ||
375 | if (ip->i_d.di_size > ip->i_size) | ||
376 | ip->i_d.di_size = ip->i_size; | ||
377 | xfs_iunlock(ip, XFS_ILOCK_EXCL); | ||
378 | } | ||
379 | xfs_iunlock(ip, XFS_IOLOCK_EXCL); | 446 | xfs_iunlock(ip, XFS_IOLOCK_EXCL); |
380 | return ret; | 447 | return ret; |
381 | } | 448 | } |
@@ -562,247 +629,314 @@ out_lock: | |||
562 | return error; | 629 | return error; |
563 | } | 630 | } |
564 | 631 | ||
632 | /* | ||
633 | * Common pre-write limit and setup checks. | ||
634 | * | ||
635 | * Returns with iolock held according to @iolock. | ||
636 | */ | ||
565 | STATIC ssize_t | 637 | STATIC ssize_t |
566 | xfs_file_aio_write( | 638 | xfs_file_aio_write_checks( |
567 | struct kiocb *iocb, | 639 | struct file *file, |
568 | const struct iovec *iovp, | 640 | loff_t *pos, |
569 | unsigned long nr_segs, | 641 | size_t *count, |
570 | loff_t pos) | 642 | int *iolock) |
571 | { | 643 | { |
572 | struct file *file = iocb->ki_filp; | 644 | struct inode *inode = file->f_mapping->host; |
573 | struct address_space *mapping = file->f_mapping; | ||
574 | struct inode *inode = mapping->host; | ||
575 | struct xfs_inode *ip = XFS_I(inode); | 645 | struct xfs_inode *ip = XFS_I(inode); |
576 | struct xfs_mount *mp = ip->i_mount; | 646 | xfs_fsize_t new_size; |
577 | ssize_t ret = 0, error = 0; | 647 | int error = 0; |
578 | int ioflags = 0; | ||
579 | xfs_fsize_t isize, new_size; | ||
580 | int iolock; | ||
581 | size_t ocount = 0, count; | ||
582 | int need_i_mutex; | ||
583 | 648 | ||
584 | XFS_STATS_INC(xs_write_calls); | 649 | error = generic_write_checks(file, pos, count, S_ISBLK(inode->i_mode)); |
650 | if (error) { | ||
651 | xfs_rw_iunlock(ip, XFS_ILOCK_EXCL | *iolock); | ||
652 | *iolock = 0; | ||
653 | return error; | ||
654 | } | ||
585 | 655 | ||
586 | BUG_ON(iocb->ki_pos != pos); | 656 | new_size = *pos + *count; |
657 | if (new_size > ip->i_size) | ||
658 | ip->i_new_size = new_size; | ||
587 | 659 | ||
588 | if (unlikely(file->f_flags & O_DIRECT)) | 660 | if (likely(!(file->f_mode & FMODE_NOCMTIME))) |
589 | ioflags |= IO_ISDIRECT; | 661 | file_update_time(file); |
590 | if (file->f_mode & FMODE_NOCMTIME) | 662 | |
591 | ioflags |= IO_INVIS; | 663 | /* |
664 | * If the offset is beyond the size of the file, we need to zero any | ||
665 | * blocks that fall between the existing EOF and the start of this | ||
666 | * write. | ||
667 | */ | ||
668 | if (*pos > ip->i_size) | ||
669 | error = -xfs_zero_eof(ip, *pos, ip->i_size); | ||
592 | 670 | ||
593 | error = generic_segment_checks(iovp, &nr_segs, &ocount, VERIFY_READ); | 671 | xfs_rw_iunlock(ip, XFS_ILOCK_EXCL); |
594 | if (error) | 672 | if (error) |
595 | return error; | 673 | return error; |
596 | 674 | ||
597 | count = ocount; | 675 | /* |
598 | if (count == 0) | 676 | * If we're writing the file then make sure to clear the setuid and |
599 | return 0; | 677 | * setgid bits if the process is not being run by root. This keeps |
600 | 678 | * people from modifying setuid and setgid binaries. | |
601 | xfs_wait_for_freeze(mp, SB_FREEZE_WRITE); | 679 | */ |
680 | return file_remove_suid(file); | ||
602 | 681 | ||
603 | if (XFS_FORCED_SHUTDOWN(mp)) | 682 | } |
604 | return -EIO; | ||
605 | 683 | ||
606 | relock: | 684 | /* |
607 | if (ioflags & IO_ISDIRECT) { | 685 | * xfs_file_dio_aio_write - handle direct IO writes |
608 | iolock = XFS_IOLOCK_SHARED; | 686 | * |
609 | need_i_mutex = 0; | 687 | * Lock the inode appropriately to prepare for and issue a direct IO write. |
610 | } else { | 688 | * By separating it from the buffered write path we remove all the tricky to |
611 | iolock = XFS_IOLOCK_EXCL; | 689 | * follow locking changes and looping. |
612 | need_i_mutex = 1; | 690 | * |
613 | mutex_lock(&inode->i_mutex); | 691 | * If there are cached pages or we're extending the file, we need IOLOCK_EXCL |
692 | * until we're sure the bytes at the new EOF have been zeroed and/or the cached | ||
693 | * pages are flushed out. | ||
694 | * | ||
695 | * In most cases the direct IO writes will be done holding IOLOCK_SHARED | ||
696 | * allowing them to be done in parallel with reads and other direct IO writes. | ||
697 | * However, if the IO is not aligned to filesystem blocks, the direct IO layer | ||
698 | * needs to do sub-block zeroing and that requires serialisation against other | ||
699 | * direct IOs to the same block. In this case we need to serialise the | ||
700 | * submission of the unaligned IOs so that we don't get racing block zeroing in | ||
701 | * the dio layer. To avoid the problem with aio, we also need to wait for | ||
702 | * outstanding IOs to complete so that unwritten extent conversion is completed | ||
703 | * before we try to map the overlapping block. This is currently implemented by | ||
704 | * hitting it with a big hammer (i.e. xfs_ioend_wait()). | ||
705 | * | ||
706 | * Returns with locks held indicated by @iolock and errors indicated by | ||
707 | * negative return values. | ||
708 | */ | ||
709 | STATIC ssize_t | ||
710 | xfs_file_dio_aio_write( | ||
711 | struct kiocb *iocb, | ||
712 | const struct iovec *iovp, | ||
713 | unsigned long nr_segs, | ||
714 | loff_t pos, | ||
715 | size_t ocount, | ||
716 | int *iolock) | ||
717 | { | ||
718 | struct file *file = iocb->ki_filp; | ||
719 | struct address_space *mapping = file->f_mapping; | ||
720 | struct inode *inode = mapping->host; | ||
721 | struct xfs_inode *ip = XFS_I(inode); | ||
722 | struct xfs_mount *mp = ip->i_mount; | ||
723 | ssize_t ret = 0; | ||
724 | size_t count = ocount; | ||
725 | int unaligned_io = 0; | ||
726 | struct xfs_buftarg *target = XFS_IS_REALTIME_INODE(ip) ? | ||
727 | mp->m_rtdev_targp : mp->m_ddev_targp; | ||
728 | |||
729 | *iolock = 0; | ||
730 | if ((pos & target->bt_smask) || (count & target->bt_smask)) | ||
731 | return -XFS_ERROR(EINVAL); | ||
732 | |||
733 | if ((pos & mp->m_blockmask) || ((pos + count) & mp->m_blockmask)) | ||
734 | unaligned_io = 1; | ||
735 | |||
736 | if (unaligned_io || mapping->nrpages || pos > ip->i_size) | ||
737 | *iolock = XFS_IOLOCK_EXCL; | ||
738 | else | ||
739 | *iolock = XFS_IOLOCK_SHARED; | ||
740 | xfs_rw_ilock(ip, XFS_ILOCK_EXCL | *iolock); | ||
741 | |||
742 | ret = xfs_file_aio_write_checks(file, &pos, &count, iolock); | ||
743 | if (ret) | ||
744 | return ret; | ||
745 | |||
746 | if (mapping->nrpages) { | ||
747 | WARN_ON(*iolock != XFS_IOLOCK_EXCL); | ||
748 | ret = -xfs_flushinval_pages(ip, (pos & PAGE_CACHE_MASK), -1, | ||
749 | FI_REMAPF_LOCKED); | ||
750 | if (ret) | ||
751 | return ret; | ||
614 | } | 752 | } |
615 | 753 | ||
616 | xfs_ilock(ip, XFS_ILOCK_EXCL|iolock); | 754 | /* |
617 | 755 | * If we are doing unaligned IO, wait for all other IO to drain, | |
618 | start: | 756 | * otherwise demote the lock if we had to flush cached pages |
619 | error = -generic_write_checks(file, &pos, &count, | 757 | */ |
620 | S_ISBLK(inode->i_mode)); | 758 | if (unaligned_io) |
621 | if (error) { | 759 | xfs_ioend_wait(ip); |
622 | xfs_iunlock(ip, XFS_ILOCK_EXCL|iolock); | 760 | else if (*iolock == XFS_IOLOCK_EXCL) { |
623 | goto out_unlock_mutex; | 761 | xfs_rw_ilock_demote(ip, XFS_IOLOCK_EXCL); |
762 | *iolock = XFS_IOLOCK_SHARED; | ||
624 | } | 763 | } |
625 | 764 | ||
626 | if (ioflags & IO_ISDIRECT) { | 765 | trace_xfs_file_direct_write(ip, count, iocb->ki_pos, 0); |
627 | xfs_buftarg_t *target = | 766 | ret = generic_file_direct_write(iocb, iovp, |
628 | XFS_IS_REALTIME_INODE(ip) ? | 767 | &nr_segs, pos, &iocb->ki_pos, count, ocount); |
629 | mp->m_rtdev_targp : mp->m_ddev_targp; | ||
630 | 768 | ||
631 | if ((pos & target->bt_smask) || (count & target->bt_smask)) { | 769 | /* No fallback to buffered IO on errors for XFS. */ |
632 | xfs_iunlock(ip, XFS_ILOCK_EXCL|iolock); | 770 | ASSERT(ret < 0 || ret == count); |
633 | return XFS_ERROR(-EINVAL); | 771 | return ret; |
634 | } | 772 | } |
635 | 773 | ||
636 | if (!need_i_mutex && (mapping->nrpages || pos > ip->i_size)) { | 774 | STATIC ssize_t |
637 | xfs_iunlock(ip, XFS_ILOCK_EXCL|iolock); | 775 | xfs_file_buffered_aio_write( |
638 | iolock = XFS_IOLOCK_EXCL; | 776 | struct kiocb *iocb, |
639 | need_i_mutex = 1; | 777 | const struct iovec *iovp, |
640 | mutex_lock(&inode->i_mutex); | 778 | unsigned long nr_segs, |
641 | xfs_ilock(ip, XFS_ILOCK_EXCL|iolock); | 779 | loff_t pos, |
642 | goto start; | 780 | size_t ocount, |
643 | } | 781 | int *iolock) |
644 | } | 782 | { |
783 | struct file *file = iocb->ki_filp; | ||
784 | struct address_space *mapping = file->f_mapping; | ||
785 | struct inode *inode = mapping->host; | ||
786 | struct xfs_inode *ip = XFS_I(inode); | ||
787 | ssize_t ret; | ||
788 | int enospc = 0; | ||
789 | size_t count = ocount; | ||
645 | 790 | ||
646 | new_size = pos + count; | 791 | *iolock = XFS_IOLOCK_EXCL; |
647 | if (new_size > ip->i_size) | 792 | xfs_rw_ilock(ip, XFS_ILOCK_EXCL | *iolock); |
648 | ip->i_new_size = new_size; | ||
649 | 793 | ||
650 | if (likely(!(ioflags & IO_INVIS))) | 794 | ret = xfs_file_aio_write_checks(file, &pos, &count, iolock); |
651 | file_update_time(file); | 795 | if (ret) |
796 | return ret; | ||
652 | 797 | ||
798 | /* We can write back this queue in page reclaim */ | ||
799 | current->backing_dev_info = mapping->backing_dev_info; | ||
800 | |||
801 | write_retry: | ||
802 | trace_xfs_file_buffered_write(ip, count, iocb->ki_pos, 0); | ||
803 | ret = generic_file_buffered_write(iocb, iovp, nr_segs, | ||
804 | pos, &iocb->ki_pos, count, ret); | ||
653 | /* | 805 | /* |
654 | * If the offset is beyond the size of the file, we have a couple | 806 | * if we just got an ENOSPC, flush the inode now we aren't holding any |
655 | * of things to do. First, if there is already space allocated | 807 | * page locks and retry *once* |
656 | * we need to either create holes or zero the disk or ... | ||
657 | * | ||
658 | * If there is a page where the previous size lands, we need | ||
659 | * to zero it out up to the new size. | ||
660 | */ | 808 | */ |
661 | 809 | if (ret == -ENOSPC && !enospc) { | |
662 | if (pos > ip->i_size) { | 810 | ret = -xfs_flush_pages(ip, 0, -1, 0, FI_NONE); |
663 | error = xfs_zero_eof(ip, pos, ip->i_size); | 811 | if (ret) |
664 | if (error) { | 812 | return ret; |
665 | xfs_iunlock(ip, XFS_ILOCK_EXCL); | 813 | enospc = 1; |
666 | goto out_unlock_internal; | 814 | goto write_retry; |
667 | } | ||
668 | } | 815 | } |
669 | xfs_iunlock(ip, XFS_ILOCK_EXCL); | 816 | current->backing_dev_info = NULL; |
817 | return ret; | ||
818 | } | ||
670 | 819 | ||
671 | /* | 820 | STATIC ssize_t |
672 | * If we're writing the file then make sure to clear the | 821 | xfs_file_aio_write( |
673 | * setuid and setgid bits if the process is not being run | 822 | struct kiocb *iocb, |
674 | * by root. This keeps people from modifying setuid and | 823 | const struct iovec *iovp, |
675 | * setgid binaries. | 824 | unsigned long nr_segs, |
676 | */ | 825 | loff_t pos) |
677 | error = -file_remove_suid(file); | 826 | { |
678 | if (unlikely(error)) | 827 | struct file *file = iocb->ki_filp; |
679 | goto out_unlock_internal; | 828 | struct address_space *mapping = file->f_mapping; |
829 | struct inode *inode = mapping->host; | ||
830 | struct xfs_inode *ip = XFS_I(inode); | ||
831 | ssize_t ret; | ||
832 | int iolock; | ||
833 | size_t ocount = 0; | ||
680 | 834 | ||
681 | /* We can write back this queue in page reclaim */ | 835 | XFS_STATS_INC(xs_write_calls); |
682 | current->backing_dev_info = mapping->backing_dev_info; | ||
683 | 836 | ||
684 | if ((ioflags & IO_ISDIRECT)) { | 837 | BUG_ON(iocb->ki_pos != pos); |
685 | if (mapping->nrpages) { | ||
686 | WARN_ON(need_i_mutex == 0); | ||
687 | error = xfs_flushinval_pages(ip, | ||
688 | (pos & PAGE_CACHE_MASK), | ||
689 | -1, FI_REMAPF_LOCKED); | ||
690 | if (error) | ||
691 | goto out_unlock_internal; | ||
692 | } | ||
693 | 838 | ||
694 | if (need_i_mutex) { | 839 | ret = generic_segment_checks(iovp, &nr_segs, &ocount, VERIFY_READ); |
695 | /* demote the lock now the cached pages are gone */ | 840 | if (ret) |
696 | xfs_ilock_demote(ip, XFS_IOLOCK_EXCL); | 841 | return ret; |
697 | mutex_unlock(&inode->i_mutex); | ||
698 | 842 | ||
699 | iolock = XFS_IOLOCK_SHARED; | 843 | if (ocount == 0) |
700 | need_i_mutex = 0; | 844 | return 0; |
701 | } | ||
702 | 845 | ||
703 | trace_xfs_file_direct_write(ip, count, iocb->ki_pos, ioflags); | 846 | xfs_wait_for_freeze(ip->i_mount, SB_FREEZE_WRITE); |
704 | ret = generic_file_direct_write(iocb, iovp, | ||
705 | &nr_segs, pos, &iocb->ki_pos, count, ocount); | ||
706 | 847 | ||
707 | /* | 848 | if (XFS_FORCED_SHUTDOWN(ip->i_mount)) |
708 | * direct-io write to a hole: fall through to buffered I/O | 849 | return -EIO; |
709 | * for completing the rest of the request. | ||
710 | */ | ||
711 | if (ret >= 0 && ret != count) { | ||
712 | XFS_STATS_ADD(xs_write_bytes, ret); | ||
713 | 850 | ||
714 | pos += ret; | 851 | if (unlikely(file->f_flags & O_DIRECT)) |
715 | count -= ret; | 852 | ret = xfs_file_dio_aio_write(iocb, iovp, nr_segs, pos, |
853 | ocount, &iolock); | ||
854 | else | ||
855 | ret = xfs_file_buffered_aio_write(iocb, iovp, nr_segs, pos, | ||
856 | ocount, &iolock); | ||
716 | 857 | ||
717 | ioflags &= ~IO_ISDIRECT; | 858 | xfs_aio_write_isize_update(inode, &iocb->ki_pos, ret); |
718 | xfs_iunlock(ip, iolock); | ||
719 | goto relock; | ||
720 | } | ||
721 | } else { | ||
722 | int enospc = 0; | ||
723 | ssize_t ret2 = 0; | ||
724 | 859 | ||
725 | write_retry: | 860 | if (ret <= 0) |
726 | trace_xfs_file_buffered_write(ip, count, iocb->ki_pos, ioflags); | 861 | goto out_unlock; |
727 | ret2 = generic_file_buffered_write(iocb, iovp, nr_segs, | ||
728 | pos, &iocb->ki_pos, count, ret); | ||
729 | /* | ||
730 | * if we just got an ENOSPC, flush the inode now we | ||
731 | * aren't holding any page locks and retry *once* | ||
732 | */ | ||
733 | if (ret2 == -ENOSPC && !enospc) { | ||
734 | error = xfs_flush_pages(ip, 0, -1, 0, FI_NONE); | ||
735 | if (error) | ||
736 | goto out_unlock_internal; | ||
737 | enospc = 1; | ||
738 | goto write_retry; | ||
739 | } | ||
740 | ret = ret2; | ||
741 | } | ||
742 | 862 | ||
743 | current->backing_dev_info = NULL; | 863 | /* Handle various SYNC-type writes */ |
864 | if ((file->f_flags & O_DSYNC) || IS_SYNC(inode)) { | ||
865 | loff_t end = pos + ret - 1; | ||
866 | int error, error2; | ||
744 | 867 | ||
745 | isize = i_size_read(inode); | 868 | xfs_rw_iunlock(ip, iolock); |
746 | if (unlikely(ret < 0 && ret != -EFAULT && iocb->ki_pos > isize)) | 869 | error = filemap_write_and_wait_range(mapping, pos, end); |
747 | iocb->ki_pos = isize; | 870 | xfs_rw_ilock(ip, iolock); |
748 | 871 | ||
749 | if (iocb->ki_pos > ip->i_size) { | 872 | error2 = -xfs_file_fsync(file, |
750 | xfs_ilock(ip, XFS_ILOCK_EXCL); | 873 | (file->f_flags & __O_SYNC) ? 0 : 1); |
751 | if (iocb->ki_pos > ip->i_size) | 874 | if (error) |
752 | ip->i_size = iocb->ki_pos; | 875 | ret = error; |
753 | xfs_iunlock(ip, XFS_ILOCK_EXCL); | 876 | else if (error2) |
877 | ret = error2; | ||
754 | } | 878 | } |
755 | 879 | ||
756 | error = -ret; | 880 | out_unlock: |
757 | if (ret <= 0) | 881 | xfs_aio_write_newsize_update(ip); |
758 | goto out_unlock_internal; | 882 | xfs_rw_iunlock(ip, iolock); |
883 | return ret; | ||
884 | } | ||
759 | 885 | ||
760 | XFS_STATS_ADD(xs_write_bytes, ret); | 886 | STATIC long |
887 | xfs_file_fallocate( | ||
888 | struct file *file, | ||
889 | int mode, | ||
890 | loff_t offset, | ||
891 | loff_t len) | ||
892 | { | ||
893 | struct inode *inode = file->f_path.dentry->d_inode; | ||
894 | long error; | ||
895 | loff_t new_size = 0; | ||
896 | xfs_flock64_t bf; | ||
897 | xfs_inode_t *ip = XFS_I(inode); | ||
898 | int cmd = XFS_IOC_RESVSP; | ||
761 | 899 | ||
762 | /* Handle various SYNC-type writes */ | 900 | if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE)) |
763 | if ((file->f_flags & O_DSYNC) || IS_SYNC(inode)) { | 901 | return -EOPNOTSUPP; |
764 | loff_t end = pos + ret - 1; | ||
765 | int error2; | ||
766 | 902 | ||
767 | xfs_iunlock(ip, iolock); | 903 | bf.l_whence = 0; |
768 | if (need_i_mutex) | 904 | bf.l_start = offset; |
769 | mutex_unlock(&inode->i_mutex); | 905 | bf.l_len = len; |
770 | 906 | ||
771 | error2 = filemap_write_and_wait_range(mapping, pos, end); | 907 | xfs_ilock(ip, XFS_IOLOCK_EXCL); |
772 | if (!error) | ||
773 | error = error2; | ||
774 | if (need_i_mutex) | ||
775 | mutex_lock(&inode->i_mutex); | ||
776 | xfs_ilock(ip, iolock); | ||
777 | 908 | ||
778 | error2 = -xfs_file_fsync(file, | 909 | if (mode & FALLOC_FL_PUNCH_HOLE) |
779 | (file->f_flags & __O_SYNC) ? 0 : 1); | 910 | cmd = XFS_IOC_UNRESVSP; |
780 | if (!error) | 911 | |
781 | error = error2; | 912 | /* check the new inode size is valid before allocating */ |
913 | if (!(mode & FALLOC_FL_KEEP_SIZE) && | ||
914 | offset + len > i_size_read(inode)) { | ||
915 | new_size = offset + len; | ||
916 | error = inode_newsize_ok(inode, new_size); | ||
917 | if (error) | ||
918 | goto out_unlock; | ||
782 | } | 919 | } |
783 | 920 | ||
784 | out_unlock_internal: | 921 | error = -xfs_change_file_space(ip, cmd, &bf, 0, XFS_ATTR_NOLOCK); |
785 | if (ip->i_new_size) { | 922 | if (error) |
786 | xfs_ilock(ip, XFS_ILOCK_EXCL); | 923 | goto out_unlock; |
787 | ip->i_new_size = 0; | 924 | |
788 | /* | 925 | /* Change file size if needed */ |
789 | * If this was a direct or synchronous I/O that failed (such | 926 | if (new_size) { |
790 | * as ENOSPC) then part of the I/O may have been written to | 927 | struct iattr iattr; |
791 | * disk before the error occured. In this case the on-disk | 928 | |
792 | * file size may have been adjusted beyond the in-memory file | 929 | iattr.ia_valid = ATTR_SIZE; |
793 | * size and now needs to be truncated back. | 930 | iattr.ia_size = new_size; |
794 | */ | 931 | error = -xfs_setattr(ip, &iattr, XFS_ATTR_NOLOCK); |
795 | if (ip->i_d.di_size > ip->i_size) | ||
796 | ip->i_d.di_size = ip->i_size; | ||
797 | xfs_iunlock(ip, XFS_ILOCK_EXCL); | ||
798 | } | 932 | } |
799 | xfs_iunlock(ip, iolock); | 933 | |
800 | out_unlock_mutex: | 934 | out_unlock: |
801 | if (need_i_mutex) | 935 | xfs_iunlock(ip, XFS_IOLOCK_EXCL); |
802 | mutex_unlock(&inode->i_mutex); | 936 | return error; |
803 | return -error; | ||
804 | } | 937 | } |
805 | 938 | ||
939 | |||
806 | STATIC int | 940 | STATIC int |
807 | xfs_file_open( | 941 | xfs_file_open( |
808 | struct inode *inode, | 942 | struct inode *inode, |
@@ -921,6 +1055,7 @@ const struct file_operations xfs_file_operations = { | |||
921 | .open = xfs_file_open, | 1055 | .open = xfs_file_open, |
922 | .release = xfs_file_release, | 1056 | .release = xfs_file_release, |
923 | .fsync = xfs_file_fsync, | 1057 | .fsync = xfs_file_fsync, |
1058 | .fallocate = xfs_file_fallocate, | ||
924 | }; | 1059 | }; |
925 | 1060 | ||
926 | const struct file_operations xfs_dir_file_operations = { | 1061 | const struct file_operations xfs_dir_file_operations = { |
diff --git a/fs/xfs/linux-2.6/xfs_ioctl.c b/fs/xfs/linux-2.6/xfs_ioctl.c index ad442d9e392e..f5e2a19e0f8e 100644 --- a/fs/xfs/linux-2.6/xfs_ioctl.c +++ b/fs/xfs/linux-2.6/xfs_ioctl.c | |||
@@ -39,6 +39,7 @@ | |||
39 | #include "xfs_dfrag.h" | 39 | #include "xfs_dfrag.h" |
40 | #include "xfs_fsops.h" | 40 | #include "xfs_fsops.h" |
41 | #include "xfs_vnodeops.h" | 41 | #include "xfs_vnodeops.h" |
42 | #include "xfs_discard.h" | ||
42 | #include "xfs_quota.h" | 43 | #include "xfs_quota.h" |
43 | #include "xfs_inode_item.h" | 44 | #include "xfs_inode_item.h" |
44 | #include "xfs_export.h" | 45 | #include "xfs_export.h" |
@@ -984,10 +985,22 @@ xfs_ioctl_setattr( | |||
984 | 985 | ||
985 | /* | 986 | /* |
986 | * Extent size must be a multiple of the appropriate block | 987 | * Extent size must be a multiple of the appropriate block |
987 | * size, if set at all. | 988 | * size, if set at all. It must also be smaller than the |
989 | * maximum extent size supported by the filesystem. | ||
990 | * | ||
991 | * Also, for non-realtime files, limit the extent size hint to | ||
992 | * half the size of the AGs in the filesystem so alignment | ||
993 | * doesn't result in extents larger than an AG. | ||
988 | */ | 994 | */ |
989 | if (fa->fsx_extsize != 0) { | 995 | if (fa->fsx_extsize != 0) { |
990 | xfs_extlen_t size; | 996 | xfs_extlen_t size; |
997 | xfs_fsblock_t extsize_fsb; | ||
998 | |||
999 | extsize_fsb = XFS_B_TO_FSB(mp, fa->fsx_extsize); | ||
1000 | if (extsize_fsb > MAXEXTLEN) { | ||
1001 | code = XFS_ERROR(EINVAL); | ||
1002 | goto error_return; | ||
1003 | } | ||
991 | 1004 | ||
992 | if (XFS_IS_REALTIME_INODE(ip) || | 1005 | if (XFS_IS_REALTIME_INODE(ip) || |
993 | ((mask & FSX_XFLAGS) && | 1006 | ((mask & FSX_XFLAGS) && |
@@ -996,6 +1009,10 @@ xfs_ioctl_setattr( | |||
996 | mp->m_sb.sb_blocklog; | 1009 | mp->m_sb.sb_blocklog; |
997 | } else { | 1010 | } else { |
998 | size = mp->m_sb.sb_blocksize; | 1011 | size = mp->m_sb.sb_blocksize; |
1012 | if (extsize_fsb > mp->m_sb.sb_agblocks / 2) { | ||
1013 | code = XFS_ERROR(EINVAL); | ||
1014 | goto error_return; | ||
1015 | } | ||
999 | } | 1016 | } |
1000 | 1017 | ||
1001 | if (fa->fsx_extsize % size) { | 1018 | if (fa->fsx_extsize % size) { |
@@ -1294,6 +1311,8 @@ xfs_file_ioctl( | |||
1294 | trace_xfs_file_ioctl(ip); | 1311 | trace_xfs_file_ioctl(ip); |
1295 | 1312 | ||
1296 | switch (cmd) { | 1313 | switch (cmd) { |
1314 | case FITRIM: | ||
1315 | return xfs_ioc_trim(mp, arg); | ||
1297 | case XFS_IOC_ALLOCSP: | 1316 | case XFS_IOC_ALLOCSP: |
1298 | case XFS_IOC_FREESP: | 1317 | case XFS_IOC_FREESP: |
1299 | case XFS_IOC_RESVSP: | 1318 | case XFS_IOC_RESVSP: |
diff --git a/fs/xfs/linux-2.6/xfs_iops.c b/fs/xfs/linux-2.6/xfs_iops.c index da54403633b6..bd5727852fd6 100644 --- a/fs/xfs/linux-2.6/xfs_iops.c +++ b/fs/xfs/linux-2.6/xfs_iops.c | |||
@@ -46,7 +46,6 @@ | |||
46 | #include <linux/namei.h> | 46 | #include <linux/namei.h> |
47 | #include <linux/posix_acl.h> | 47 | #include <linux/posix_acl.h> |
48 | #include <linux/security.h> | 48 | #include <linux/security.h> |
49 | #include <linux/falloc.h> | ||
50 | #include <linux/fiemap.h> | 49 | #include <linux/fiemap.h> |
51 | #include <linux/slab.h> | 50 | #include <linux/slab.h> |
52 | 51 | ||
@@ -505,61 +504,6 @@ xfs_vn_setattr( | |||
505 | return -xfs_setattr(XFS_I(dentry->d_inode), iattr, 0); | 504 | return -xfs_setattr(XFS_I(dentry->d_inode), iattr, 0); |
506 | } | 505 | } |
507 | 506 | ||
508 | STATIC long | ||
509 | xfs_vn_fallocate( | ||
510 | struct inode *inode, | ||
511 | int mode, | ||
512 | loff_t offset, | ||
513 | loff_t len) | ||
514 | { | ||
515 | long error; | ||
516 | loff_t new_size = 0; | ||
517 | xfs_flock64_t bf; | ||
518 | xfs_inode_t *ip = XFS_I(inode); | ||
519 | int cmd = XFS_IOC_RESVSP; | ||
520 | |||
521 | /* preallocation on directories not yet supported */ | ||
522 | error = -ENODEV; | ||
523 | if (S_ISDIR(inode->i_mode)) | ||
524 | goto out_error; | ||
525 | |||
526 | bf.l_whence = 0; | ||
527 | bf.l_start = offset; | ||
528 | bf.l_len = len; | ||
529 | |||
530 | xfs_ilock(ip, XFS_IOLOCK_EXCL); | ||
531 | |||
532 | if (mode & FALLOC_FL_PUNCH_HOLE) | ||
533 | cmd = XFS_IOC_UNRESVSP; | ||
534 | |||
535 | /* check the new inode size is valid before allocating */ | ||
536 | if (!(mode & FALLOC_FL_KEEP_SIZE) && | ||
537 | offset + len > i_size_read(inode)) { | ||
538 | new_size = offset + len; | ||
539 | error = inode_newsize_ok(inode, new_size); | ||
540 | if (error) | ||
541 | goto out_unlock; | ||
542 | } | ||
543 | |||
544 | error = -xfs_change_file_space(ip, cmd, &bf, 0, XFS_ATTR_NOLOCK); | ||
545 | if (error) | ||
546 | goto out_unlock; | ||
547 | |||
548 | /* Change file size if needed */ | ||
549 | if (new_size) { | ||
550 | struct iattr iattr; | ||
551 | |||
552 | iattr.ia_valid = ATTR_SIZE; | ||
553 | iattr.ia_size = new_size; | ||
554 | error = -xfs_setattr(ip, &iattr, XFS_ATTR_NOLOCK); | ||
555 | } | ||
556 | |||
557 | out_unlock: | ||
558 | xfs_iunlock(ip, XFS_IOLOCK_EXCL); | ||
559 | out_error: | ||
560 | return error; | ||
561 | } | ||
562 | |||
563 | #define XFS_FIEMAP_FLAGS (FIEMAP_FLAG_SYNC|FIEMAP_FLAG_XATTR) | 507 | #define XFS_FIEMAP_FLAGS (FIEMAP_FLAG_SYNC|FIEMAP_FLAG_XATTR) |
564 | 508 | ||
565 | /* | 509 | /* |
@@ -653,7 +597,6 @@ static const struct inode_operations xfs_inode_operations = { | |||
653 | .getxattr = generic_getxattr, | 597 | .getxattr = generic_getxattr, |
654 | .removexattr = generic_removexattr, | 598 | .removexattr = generic_removexattr, |
655 | .listxattr = xfs_vn_listxattr, | 599 | .listxattr = xfs_vn_listxattr, |
656 | .fallocate = xfs_vn_fallocate, | ||
657 | .fiemap = xfs_vn_fiemap, | 600 | .fiemap = xfs_vn_fiemap, |
658 | }; | 601 | }; |
659 | 602 | ||
diff --git a/fs/xfs/linux-2.6/xfs_super.c b/fs/xfs/linux-2.6/xfs_super.c index bd07f7339366..9731898083ae 100644 --- a/fs/xfs/linux-2.6/xfs_super.c +++ b/fs/xfs/linux-2.6/xfs_super.c | |||
@@ -1414,7 +1414,7 @@ xfs_fs_freeze( | |||
1414 | 1414 | ||
1415 | xfs_save_resvblks(mp); | 1415 | xfs_save_resvblks(mp); |
1416 | xfs_quiesce_attr(mp); | 1416 | xfs_quiesce_attr(mp); |
1417 | return -xfs_fs_log_dummy(mp, SYNC_WAIT); | 1417 | return -xfs_fs_log_dummy(mp); |
1418 | } | 1418 | } |
1419 | 1419 | ||
1420 | STATIC int | 1420 | STATIC int |
diff --git a/fs/xfs/linux-2.6/xfs_sync.c b/fs/xfs/linux-2.6/xfs_sync.c index a02480de9759..e22f0057d21f 100644 --- a/fs/xfs/linux-2.6/xfs_sync.c +++ b/fs/xfs/linux-2.6/xfs_sync.c | |||
@@ -362,7 +362,7 @@ xfs_quiesce_data( | |||
362 | 362 | ||
363 | /* mark the log as covered if needed */ | 363 | /* mark the log as covered if needed */ |
364 | if (xfs_log_need_covered(mp)) | 364 | if (xfs_log_need_covered(mp)) |
365 | error2 = xfs_fs_log_dummy(mp, SYNC_WAIT); | 365 | error2 = xfs_fs_log_dummy(mp); |
366 | 366 | ||
367 | /* flush data-only devices */ | 367 | /* flush data-only devices */ |
368 | if (mp->m_rtdev_targp) | 368 | if (mp->m_rtdev_targp) |
@@ -503,13 +503,14 @@ xfs_sync_worker( | |||
503 | int error; | 503 | int error; |
504 | 504 | ||
505 | if (!(mp->m_flags & XFS_MOUNT_RDONLY)) { | 505 | if (!(mp->m_flags & XFS_MOUNT_RDONLY)) { |
506 | xfs_log_force(mp, 0); | ||
507 | xfs_reclaim_inodes(mp, 0); | ||
508 | /* dgc: errors ignored here */ | 506 | /* dgc: errors ignored here */ |
509 | error = xfs_qm_sync(mp, SYNC_TRYLOCK); | ||
510 | if (mp->m_super->s_frozen == SB_UNFROZEN && | 507 | if (mp->m_super->s_frozen == SB_UNFROZEN && |
511 | xfs_log_need_covered(mp)) | 508 | xfs_log_need_covered(mp)) |
512 | error = xfs_fs_log_dummy(mp, 0); | 509 | error = xfs_fs_log_dummy(mp); |
510 | else | ||
511 | xfs_log_force(mp, 0); | ||
512 | xfs_reclaim_inodes(mp, 0); | ||
513 | error = xfs_qm_sync(mp, SYNC_TRYLOCK); | ||
513 | } | 514 | } |
514 | mp->m_sync_seq++; | 515 | mp->m_sync_seq++; |
515 | wake_up(&mp->m_wait_single_sync_task); | 516 | wake_up(&mp->m_wait_single_sync_task); |
diff --git a/fs/xfs/linux-2.6/xfs_sysctl.c b/fs/xfs/linux-2.6/xfs_sysctl.c index 7bb5092d6ae4..ee3cee097e7e 100644 --- a/fs/xfs/linux-2.6/xfs_sysctl.c +++ b/fs/xfs/linux-2.6/xfs_sysctl.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include "xfs.h" | 18 | #include "xfs.h" |
19 | #include <linux/sysctl.h> | 19 | #include <linux/sysctl.h> |
20 | #include <linux/proc_fs.h> | 20 | #include <linux/proc_fs.h> |
21 | #include "xfs_error.h" | ||
21 | 22 | ||
22 | static struct ctl_table_header *xfs_table_header; | 23 | static struct ctl_table_header *xfs_table_header; |
23 | 24 | ||
@@ -51,6 +52,26 @@ xfs_stats_clear_proc_handler( | |||
51 | 52 | ||
52 | return ret; | 53 | return ret; |
53 | } | 54 | } |
55 | |||
56 | STATIC int | ||
57 | xfs_panic_mask_proc_handler( | ||
58 | ctl_table *ctl, | ||
59 | int write, | ||
60 | void __user *buffer, | ||
61 | size_t *lenp, | ||
62 | loff_t *ppos) | ||
63 | { | ||
64 | int ret, *valp = ctl->data; | ||
65 | |||
66 | ret = proc_dointvec_minmax(ctl, write, buffer, lenp, ppos); | ||
67 | if (!ret && write) { | ||
68 | xfs_panic_mask = *valp; | ||
69 | #ifdef DEBUG | ||
70 | xfs_panic_mask |= (XFS_PTAG_SHUTDOWN_CORRUPT | XFS_PTAG_LOGRES); | ||
71 | #endif | ||
72 | } | ||
73 | return ret; | ||
74 | } | ||
54 | #endif /* CONFIG_PROC_FS */ | 75 | #endif /* CONFIG_PROC_FS */ |
55 | 76 | ||
56 | static ctl_table xfs_table[] = { | 77 | static ctl_table xfs_table[] = { |
@@ -77,7 +98,7 @@ static ctl_table xfs_table[] = { | |||
77 | .data = &xfs_params.panic_mask.val, | 98 | .data = &xfs_params.panic_mask.val, |
78 | .maxlen = sizeof(int), | 99 | .maxlen = sizeof(int), |
79 | .mode = 0644, | 100 | .mode = 0644, |
80 | .proc_handler = proc_dointvec_minmax, | 101 | .proc_handler = xfs_panic_mask_proc_handler, |
81 | .extra1 = &xfs_params.panic_mask.min, | 102 | .extra1 = &xfs_params.panic_mask.min, |
82 | .extra2 = &xfs_params.panic_mask.max | 103 | .extra2 = &xfs_params.panic_mask.max |
83 | }, | 104 | }, |
diff --git a/fs/xfs/linux-2.6/xfs_trace.h b/fs/xfs/linux-2.6/xfs_trace.h index 647af2a2e7aa..2d0bcb479075 100644 --- a/fs/xfs/linux-2.6/xfs_trace.h +++ b/fs/xfs/linux-2.6/xfs_trace.h | |||
@@ -1759,6 +1759,39 @@ DEFINE_LOG_RECOVER_INO_ITEM(xfs_log_recover_inode_recover); | |||
1759 | DEFINE_LOG_RECOVER_INO_ITEM(xfs_log_recover_inode_cancel); | 1759 | DEFINE_LOG_RECOVER_INO_ITEM(xfs_log_recover_inode_cancel); |
1760 | DEFINE_LOG_RECOVER_INO_ITEM(xfs_log_recover_inode_skip); | 1760 | DEFINE_LOG_RECOVER_INO_ITEM(xfs_log_recover_inode_skip); |
1761 | 1761 | ||
1762 | DECLARE_EVENT_CLASS(xfs_discard_class, | ||
1763 | TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno, | ||
1764 | xfs_agblock_t agbno, xfs_extlen_t len), | ||
1765 | TP_ARGS(mp, agno, agbno, len), | ||
1766 | TP_STRUCT__entry( | ||
1767 | __field(dev_t, dev) | ||
1768 | __field(xfs_agnumber_t, agno) | ||
1769 | __field(xfs_agblock_t, agbno) | ||
1770 | __field(xfs_extlen_t, len) | ||
1771 | ), | ||
1772 | TP_fast_assign( | ||
1773 | __entry->dev = mp->m_super->s_dev; | ||
1774 | __entry->agno = agno; | ||
1775 | __entry->agbno = agbno; | ||
1776 | __entry->len = len; | ||
1777 | ), | ||
1778 | TP_printk("dev %d:%d agno %u agbno %u len %u\n", | ||
1779 | MAJOR(__entry->dev), MINOR(__entry->dev), | ||
1780 | __entry->agno, | ||
1781 | __entry->agbno, | ||
1782 | __entry->len) | ||
1783 | ) | ||
1784 | |||
1785 | #define DEFINE_DISCARD_EVENT(name) \ | ||
1786 | DEFINE_EVENT(xfs_discard_class, name, \ | ||
1787 | TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno, \ | ||
1788 | xfs_agblock_t agbno, xfs_extlen_t len), \ | ||
1789 | TP_ARGS(mp, agno, agbno, len)) | ||
1790 | DEFINE_DISCARD_EVENT(xfs_discard_extent); | ||
1791 | DEFINE_DISCARD_EVENT(xfs_discard_toosmall); | ||
1792 | DEFINE_DISCARD_EVENT(xfs_discard_exclude); | ||
1793 | DEFINE_DISCARD_EVENT(xfs_discard_busy); | ||
1794 | |||
1762 | #endif /* _TRACE_XFS_H */ | 1795 | #endif /* _TRACE_XFS_H */ |
1763 | 1796 | ||
1764 | #undef TRACE_INCLUDE_PATH | 1797 | #undef TRACE_INCLUDE_PATH |
diff --git a/fs/xfs/quota/xfs_qm.c b/fs/xfs/quota/xfs_qm.c index f8e854b4fde8..206a2815ced6 100644 --- a/fs/xfs/quota/xfs_qm.c +++ b/fs/xfs/quota/xfs_qm.c | |||
@@ -1863,12 +1863,14 @@ xfs_qm_dqreclaim_one(void) | |||
1863 | xfs_dquot_t *dqpout; | 1863 | xfs_dquot_t *dqpout; |
1864 | xfs_dquot_t *dqp; | 1864 | xfs_dquot_t *dqp; |
1865 | int restarts; | 1865 | int restarts; |
1866 | int startagain; | ||
1866 | 1867 | ||
1867 | restarts = 0; | 1868 | restarts = 0; |
1868 | dqpout = NULL; | 1869 | dqpout = NULL; |
1869 | 1870 | ||
1870 | /* lockorder: hashchainlock, freelistlock, mplistlock, dqlock, dqflock */ | 1871 | /* lockorder: hashchainlock, freelistlock, mplistlock, dqlock, dqflock */ |
1871 | startagain: | 1872 | again: |
1873 | startagain = 0; | ||
1872 | mutex_lock(&xfs_Gqm->qm_dqfrlist_lock); | 1874 | mutex_lock(&xfs_Gqm->qm_dqfrlist_lock); |
1873 | 1875 | ||
1874 | list_for_each_entry(dqp, &xfs_Gqm->qm_dqfrlist, q_freelist) { | 1876 | list_for_each_entry(dqp, &xfs_Gqm->qm_dqfrlist, q_freelist) { |
@@ -1885,13 +1887,10 @@ startagain: | |||
1885 | ASSERT(! (dqp->dq_flags & XFS_DQ_INACTIVE)); | 1887 | ASSERT(! (dqp->dq_flags & XFS_DQ_INACTIVE)); |
1886 | 1888 | ||
1887 | trace_xfs_dqreclaim_want(dqp); | 1889 | trace_xfs_dqreclaim_want(dqp); |
1888 | |||
1889 | xfs_dqunlock(dqp); | ||
1890 | mutex_unlock(&xfs_Gqm->qm_dqfrlist_lock); | ||
1891 | if (++restarts >= XFS_QM_RECLAIM_MAX_RESTARTS) | ||
1892 | return NULL; | ||
1893 | XQM_STATS_INC(xqmstats.xs_qm_dqwants); | 1890 | XQM_STATS_INC(xqmstats.xs_qm_dqwants); |
1894 | goto startagain; | 1891 | restarts++; |
1892 | startagain = 1; | ||
1893 | goto dqunlock; | ||
1895 | } | 1894 | } |
1896 | 1895 | ||
1897 | /* | 1896 | /* |
@@ -1906,23 +1905,20 @@ startagain: | |||
1906 | ASSERT(list_empty(&dqp->q_mplist)); | 1905 | ASSERT(list_empty(&dqp->q_mplist)); |
1907 | list_del_init(&dqp->q_freelist); | 1906 | list_del_init(&dqp->q_freelist); |
1908 | xfs_Gqm->qm_dqfrlist_cnt--; | 1907 | xfs_Gqm->qm_dqfrlist_cnt--; |
1909 | xfs_dqunlock(dqp); | ||
1910 | dqpout = dqp; | 1908 | dqpout = dqp; |
1911 | XQM_STATS_INC(xqmstats.xs_qm_dqinact_reclaims); | 1909 | XQM_STATS_INC(xqmstats.xs_qm_dqinact_reclaims); |
1912 | break; | 1910 | goto dqunlock; |
1913 | } | 1911 | } |
1914 | 1912 | ||
1915 | ASSERT(dqp->q_hash); | 1913 | ASSERT(dqp->q_hash); |
1916 | ASSERT(!list_empty(&dqp->q_mplist)); | 1914 | ASSERT(!list_empty(&dqp->q_mplist)); |
1917 | 1915 | ||
1918 | /* | 1916 | /* |
1919 | * Try to grab the flush lock. If this dquot is in the process of | 1917 | * Try to grab the flush lock. If this dquot is in the process |
1920 | * getting flushed to disk, we don't want to reclaim it. | 1918 | * of getting flushed to disk, we don't want to reclaim it. |
1921 | */ | 1919 | */ |
1922 | if (!xfs_dqflock_nowait(dqp)) { | 1920 | if (!xfs_dqflock_nowait(dqp)) |
1923 | xfs_dqunlock(dqp); | 1921 | goto dqunlock; |
1924 | continue; | ||
1925 | } | ||
1926 | 1922 | ||
1927 | /* | 1923 | /* |
1928 | * We have the flush lock so we know that this is not in the | 1924 | * We have the flush lock so we know that this is not in the |
@@ -1944,8 +1940,7 @@ startagain: | |||
1944 | xfs_fs_cmn_err(CE_WARN, mp, | 1940 | xfs_fs_cmn_err(CE_WARN, mp, |
1945 | "xfs_qm_dqreclaim: dquot %p flush failed", dqp); | 1941 | "xfs_qm_dqreclaim: dquot %p flush failed", dqp); |
1946 | } | 1942 | } |
1947 | xfs_dqunlock(dqp); /* dqflush unlocks dqflock */ | 1943 | goto dqunlock; |
1948 | continue; | ||
1949 | } | 1944 | } |
1950 | 1945 | ||
1951 | /* | 1946 | /* |
@@ -1967,13 +1962,8 @@ startagain: | |||
1967 | */ | 1962 | */ |
1968 | if (!mutex_trylock(&mp->m_quotainfo->qi_dqlist_lock)) { | 1963 | if (!mutex_trylock(&mp->m_quotainfo->qi_dqlist_lock)) { |
1969 | restarts++; | 1964 | restarts++; |
1970 | mutex_unlock(&dqp->q_hash->qh_lock); | 1965 | startagain = 1; |
1971 | xfs_dqfunlock(dqp); | 1966 | goto qhunlock; |
1972 | xfs_dqunlock(dqp); | ||
1973 | mutex_unlock(&xfs_Gqm->qm_dqfrlist_lock); | ||
1974 | if (restarts++ >= XFS_QM_RECLAIM_MAX_RESTARTS) | ||
1975 | return NULL; | ||
1976 | goto startagain; | ||
1977 | } | 1967 | } |
1978 | 1968 | ||
1979 | ASSERT(dqp->q_nrefs == 0); | 1969 | ASSERT(dqp->q_nrefs == 0); |
@@ -1986,14 +1976,20 @@ startagain: | |||
1986 | xfs_Gqm->qm_dqfrlist_cnt--; | 1976 | xfs_Gqm->qm_dqfrlist_cnt--; |
1987 | dqpout = dqp; | 1977 | dqpout = dqp; |
1988 | mutex_unlock(&mp->m_quotainfo->qi_dqlist_lock); | 1978 | mutex_unlock(&mp->m_quotainfo->qi_dqlist_lock); |
1979 | qhunlock: | ||
1989 | mutex_unlock(&dqp->q_hash->qh_lock); | 1980 | mutex_unlock(&dqp->q_hash->qh_lock); |
1990 | dqfunlock: | 1981 | dqfunlock: |
1991 | xfs_dqfunlock(dqp); | 1982 | xfs_dqfunlock(dqp); |
1983 | dqunlock: | ||
1992 | xfs_dqunlock(dqp); | 1984 | xfs_dqunlock(dqp); |
1993 | if (dqpout) | 1985 | if (dqpout) |
1994 | break; | 1986 | break; |
1995 | if (restarts >= XFS_QM_RECLAIM_MAX_RESTARTS) | 1987 | if (restarts >= XFS_QM_RECLAIM_MAX_RESTARTS) |
1996 | return NULL; | 1988 | break; |
1989 | if (startagain) { | ||
1990 | mutex_unlock(&xfs_Gqm->qm_dqfrlist_lock); | ||
1991 | goto again; | ||
1992 | } | ||
1997 | } | 1993 | } |
1998 | mutex_unlock(&xfs_Gqm->qm_dqfrlist_lock); | 1994 | mutex_unlock(&xfs_Gqm->qm_dqfrlist_lock); |
1999 | return dqpout; | 1995 | return dqpout; |
diff --git a/fs/xfs/support/debug.c b/fs/xfs/support/debug.c index 975aa10e1a47..0df88897ef84 100644 --- a/fs/xfs/support/debug.c +++ b/fs/xfs/support/debug.c | |||
@@ -25,86 +25,78 @@ | |||
25 | #include "xfs_mount.h" | 25 | #include "xfs_mount.h" |
26 | #include "xfs_error.h" | 26 | #include "xfs_error.h" |
27 | 27 | ||
28 | static char message[1024]; /* keep it off the stack */ | ||
29 | static DEFINE_SPINLOCK(xfs_err_lock); | ||
30 | |||
31 | /* Translate from CE_FOO to KERN_FOO, err_level(CE_FOO) == KERN_FOO */ | ||
32 | #define XFS_MAX_ERR_LEVEL 7 | ||
33 | #define XFS_ERR_MASK ((1 << 3) - 1) | ||
34 | static const char * const err_level[XFS_MAX_ERR_LEVEL+1] = | ||
35 | {KERN_EMERG, KERN_ALERT, KERN_CRIT, | ||
36 | KERN_ERR, KERN_WARNING, KERN_NOTICE, | ||
37 | KERN_INFO, KERN_DEBUG}; | ||
38 | |||
39 | void | 28 | void |
40 | cmn_err(register int level, char *fmt, ...) | 29 | cmn_err( |
30 | const char *lvl, | ||
31 | const char *fmt, | ||
32 | ...) | ||
41 | { | 33 | { |
42 | char *fp = fmt; | 34 | struct va_format vaf; |
43 | int len; | 35 | va_list args; |
44 | ulong flags; | 36 | |
45 | va_list ap; | 37 | va_start(args, fmt); |
46 | 38 | vaf.fmt = fmt; | |
47 | level &= XFS_ERR_MASK; | 39 | vaf.va = &args; |
48 | if (level > XFS_MAX_ERR_LEVEL) | 40 | |
49 | level = XFS_MAX_ERR_LEVEL; | 41 | printk("%s%pV", lvl, &vaf); |
50 | spin_lock_irqsave(&xfs_err_lock,flags); | 42 | va_end(args); |
51 | va_start(ap, fmt); | 43 | |
52 | if (*fmt == '!') fp++; | 44 | BUG_ON(strncmp(lvl, KERN_EMERG, strlen(KERN_EMERG)) == 0); |
53 | len = vsnprintf(message, sizeof(message), fp, ap); | ||
54 | if (len >= sizeof(message)) | ||
55 | len = sizeof(message) - 1; | ||
56 | if (message[len-1] == '\n') | ||
57 | message[len-1] = 0; | ||
58 | printk("%s%s\n", err_level[level], message); | ||
59 | va_end(ap); | ||
60 | spin_unlock_irqrestore(&xfs_err_lock,flags); | ||
61 | BUG_ON(level == CE_PANIC); | ||
62 | } | 45 | } |
63 | 46 | ||
64 | void | 47 | void |
65 | xfs_fs_vcmn_err( | 48 | xfs_fs_cmn_err( |
66 | int level, | 49 | const char *lvl, |
67 | struct xfs_mount *mp, | 50 | struct xfs_mount *mp, |
68 | char *fmt, | 51 | const char *fmt, |
69 | va_list ap) | 52 | ...) |
70 | { | 53 | { |
71 | unsigned long flags; | 54 | struct va_format vaf; |
72 | int len = 0; | 55 | va_list args; |
73 | 56 | ||
74 | level &= XFS_ERR_MASK; | 57 | va_start(args, fmt); |
75 | if (level > XFS_MAX_ERR_LEVEL) | 58 | vaf.fmt = fmt; |
76 | level = XFS_MAX_ERR_LEVEL; | 59 | vaf.va = &args; |
77 | 60 | ||
78 | spin_lock_irqsave(&xfs_err_lock,flags); | 61 | printk("%sFilesystem %s: %pV", lvl, mp->m_fsname, &vaf); |
62 | va_end(args); | ||
79 | 63 | ||
80 | if (mp) { | 64 | BUG_ON(strncmp(lvl, KERN_EMERG, strlen(KERN_EMERG)) == 0); |
81 | len = sprintf(message, "Filesystem \"%s\": ", mp->m_fsname); | 65 | } |
66 | |||
67 | /* All callers to xfs_cmn_err use CE_ALERT, so don't bother testing lvl */ | ||
68 | void | ||
69 | xfs_cmn_err( | ||
70 | int panic_tag, | ||
71 | const char *lvl, | ||
72 | struct xfs_mount *mp, | ||
73 | const char *fmt, | ||
74 | ...) | ||
75 | { | ||
76 | struct va_format vaf; | ||
77 | va_list args; | ||
78 | int do_panic = 0; | ||
82 | 79 | ||
83 | /* | 80 | if (xfs_panic_mask && (xfs_panic_mask & panic_tag)) { |
84 | * Skip the printk if we can't print anything useful | 81 | printk(KERN_ALERT "XFS: Transforming an alert into a BUG."); |
85 | * due to an over-long device name. | 82 | do_panic = 1; |
86 | */ | ||
87 | if (len >= sizeof(message)) | ||
88 | goto out; | ||
89 | } | 83 | } |
90 | 84 | ||
91 | len = vsnprintf(message + len, sizeof(message) - len, fmt, ap); | 85 | va_start(args, fmt); |
92 | if (len >= sizeof(message)) | 86 | vaf.fmt = fmt; |
93 | len = sizeof(message) - 1; | 87 | vaf.va = &args; |
94 | if (message[len-1] == '\n') | ||
95 | message[len-1] = 0; | ||
96 | 88 | ||
97 | printk("%s%s\n", err_level[level], message); | 89 | printk(KERN_ALERT "Filesystem %s: %pV", mp->m_fsname, &vaf); |
98 | out: | 90 | va_end(args); |
99 | spin_unlock_irqrestore(&xfs_err_lock,flags); | ||
100 | 91 | ||
101 | BUG_ON(level == CE_PANIC); | 92 | BUG_ON(do_panic); |
102 | } | 93 | } |
103 | 94 | ||
104 | void | 95 | void |
105 | assfail(char *expr, char *file, int line) | 96 | assfail(char *expr, char *file, int line) |
106 | { | 97 | { |
107 | printk("Assertion failed: %s, file: %s, line: %d\n", expr, file, line); | 98 | printk(KERN_CRIT "Assertion failed: %s, file: %s, line: %d\n", expr, |
99 | file, line); | ||
108 | BUG(); | 100 | BUG(); |
109 | } | 101 | } |
110 | 102 | ||
diff --git a/fs/xfs/support/debug.h b/fs/xfs/support/debug.h index d2d20462fd4f..05699f67d475 100644 --- a/fs/xfs/support/debug.h +++ b/fs/xfs/support/debug.h | |||
@@ -20,15 +20,22 @@ | |||
20 | 20 | ||
21 | #include <stdarg.h> | 21 | #include <stdarg.h> |
22 | 22 | ||
23 | #define CE_DEBUG 7 /* debug */ | 23 | struct xfs_mount; |
24 | #define CE_CONT 6 /* continuation */ | 24 | |
25 | #define CE_NOTE 5 /* notice */ | 25 | #define CE_DEBUG KERN_DEBUG |
26 | #define CE_WARN 4 /* warning */ | 26 | #define CE_CONT KERN_INFO |
27 | #define CE_ALERT 1 /* alert */ | 27 | #define CE_NOTE KERN_NOTICE |
28 | #define CE_PANIC 0 /* panic */ | 28 | #define CE_WARN KERN_WARNING |
29 | 29 | #define CE_ALERT KERN_ALERT | |
30 | extern void cmn_err(int, char *, ...) | 30 | #define CE_PANIC KERN_EMERG |
31 | __attribute__ ((format (printf, 2, 3))); | 31 | |
32 | void cmn_err(const char *lvl, const char *fmt, ...) | ||
33 | __attribute__ ((format (printf, 2, 3))); | ||
34 | void xfs_fs_cmn_err( const char *lvl, struct xfs_mount *mp, | ||
35 | const char *fmt, ...) __attribute__ ((format (printf, 3, 4))); | ||
36 | void xfs_cmn_err( int panic_tag, const char *lvl, struct xfs_mount *mp, | ||
37 | const char *fmt, ...) __attribute__ ((format (printf, 4, 5))); | ||
38 | |||
32 | extern void assfail(char *expr, char *f, int l); | 39 | extern void assfail(char *expr, char *f, int l); |
33 | 40 | ||
34 | #define ASSERT_ALWAYS(expr) \ | 41 | #define ASSERT_ALWAYS(expr) \ |
diff --git a/fs/xfs/xfs_alloc.c b/fs/xfs/xfs_alloc.c index fa8723f5870a..f3227984a9bf 100644 --- a/fs/xfs/xfs_alloc.c +++ b/fs/xfs/xfs_alloc.c | |||
@@ -41,10 +41,6 @@ | |||
41 | #define XFSA_FIXUP_BNO_OK 1 | 41 | #define XFSA_FIXUP_BNO_OK 1 |
42 | #define XFSA_FIXUP_CNT_OK 2 | 42 | #define XFSA_FIXUP_CNT_OK 2 |
43 | 43 | ||
44 | static int | ||
45 | xfs_alloc_busy_search(struct xfs_mount *mp, xfs_agnumber_t agno, | ||
46 | xfs_agblock_t bno, xfs_extlen_t len); | ||
47 | |||
48 | /* | 44 | /* |
49 | * Prototypes for per-ag allocation routines | 45 | * Prototypes for per-ag allocation routines |
50 | */ | 46 | */ |
@@ -94,7 +90,7 @@ xfs_alloc_lookup_ge( | |||
94 | * Lookup the first record less than or equal to [bno, len] | 90 | * Lookup the first record less than or equal to [bno, len] |
95 | * in the btree given by cur. | 91 | * in the btree given by cur. |
96 | */ | 92 | */ |
97 | STATIC int /* error */ | 93 | int /* error */ |
98 | xfs_alloc_lookup_le( | 94 | xfs_alloc_lookup_le( |
99 | struct xfs_btree_cur *cur, /* btree cursor */ | 95 | struct xfs_btree_cur *cur, /* btree cursor */ |
100 | xfs_agblock_t bno, /* starting block of extent */ | 96 | xfs_agblock_t bno, /* starting block of extent */ |
@@ -127,7 +123,7 @@ xfs_alloc_update( | |||
127 | /* | 123 | /* |
128 | * Get the data from the pointed-to record. | 124 | * Get the data from the pointed-to record. |
129 | */ | 125 | */ |
130 | STATIC int /* error */ | 126 | int /* error */ |
131 | xfs_alloc_get_rec( | 127 | xfs_alloc_get_rec( |
132 | struct xfs_btree_cur *cur, /* btree cursor */ | 128 | struct xfs_btree_cur *cur, /* btree cursor */ |
133 | xfs_agblock_t *bno, /* output: starting block of extent */ | 129 | xfs_agblock_t *bno, /* output: starting block of extent */ |
@@ -2615,7 +2611,7 @@ restart: | |||
2615 | * will require a synchronous transaction, but it can still be | 2611 | * will require a synchronous transaction, but it can still be |
2616 | * used to distinguish between a partial or exact match. | 2612 | * used to distinguish between a partial or exact match. |
2617 | */ | 2613 | */ |
2618 | static int | 2614 | int |
2619 | xfs_alloc_busy_search( | 2615 | xfs_alloc_busy_search( |
2620 | struct xfs_mount *mp, | 2616 | struct xfs_mount *mp, |
2621 | xfs_agnumber_t agno, | 2617 | xfs_agnumber_t agno, |
diff --git a/fs/xfs/xfs_alloc.h b/fs/xfs/xfs_alloc.h index 895009a97271..d0b3bc72005b 100644 --- a/fs/xfs/xfs_alloc.h +++ b/fs/xfs/xfs_alloc.h | |||
@@ -19,6 +19,7 @@ | |||
19 | #define __XFS_ALLOC_H__ | 19 | #define __XFS_ALLOC_H__ |
20 | 20 | ||
21 | struct xfs_buf; | 21 | struct xfs_buf; |
22 | struct xfs_btree_cur; | ||
22 | struct xfs_mount; | 23 | struct xfs_mount; |
23 | struct xfs_perag; | 24 | struct xfs_perag; |
24 | struct xfs_trans; | 25 | struct xfs_trans; |
@@ -74,6 +75,22 @@ typedef unsigned int xfs_alloctype_t; | |||
74 | #define XFS_ALLOC_SET_ASIDE(mp) (4 + ((mp)->m_sb.sb_agcount * 4)) | 75 | #define XFS_ALLOC_SET_ASIDE(mp) (4 + ((mp)->m_sb.sb_agcount * 4)) |
75 | 76 | ||
76 | /* | 77 | /* |
78 | * When deciding how much space to allocate out of an AG, we limit the | ||
79 | * allocation maximum size to the size the AG. However, we cannot use all the | ||
80 | * blocks in the AG - some are permanently used by metadata. These | ||
81 | * blocks are generally: | ||
82 | * - the AG superblock, AGF, AGI and AGFL | ||
83 | * - the AGF (bno and cnt) and AGI btree root blocks | ||
84 | * - 4 blocks on the AGFL according to XFS_ALLOC_SET_ASIDE() limits | ||
85 | * | ||
86 | * The AG headers are sector sized, so the amount of space they take up is | ||
87 | * dependent on filesystem geometry. The others are all single blocks. | ||
88 | */ | ||
89 | #define XFS_ALLOC_AG_MAX_USABLE(mp) \ | ||
90 | ((mp)->m_sb.sb_agblocks - XFS_BB_TO_FSB(mp, XFS_FSS_TO_BB(mp, 4)) - 7) | ||
91 | |||
92 | |||
93 | /* | ||
77 | * Argument structure for xfs_alloc routines. | 94 | * Argument structure for xfs_alloc routines. |
78 | * This is turned into a structure to avoid having 20 arguments passed | 95 | * This is turned into a structure to avoid having 20 arguments passed |
79 | * down several levels of the stack. | 96 | * down several levels of the stack. |
@@ -118,16 +135,16 @@ xfs_alloc_longest_free_extent(struct xfs_mount *mp, | |||
118 | struct xfs_perag *pag); | 135 | struct xfs_perag *pag); |
119 | 136 | ||
120 | #ifdef __KERNEL__ | 137 | #ifdef __KERNEL__ |
121 | |||
122 | void | 138 | void |
123 | xfs_alloc_busy_insert(xfs_trans_t *tp, | 139 | xfs_alloc_busy_insert(struct xfs_trans *tp, xfs_agnumber_t agno, |
124 | xfs_agnumber_t agno, | 140 | xfs_agblock_t bno, xfs_extlen_t len); |
125 | xfs_agblock_t bno, | ||
126 | xfs_extlen_t len); | ||
127 | 141 | ||
128 | void | 142 | void |
129 | xfs_alloc_busy_clear(struct xfs_mount *mp, struct xfs_busy_extent *busyp); | 143 | xfs_alloc_busy_clear(struct xfs_mount *mp, struct xfs_busy_extent *busyp); |
130 | 144 | ||
145 | int | ||
146 | xfs_alloc_busy_search(struct xfs_mount *mp, xfs_agnumber_t agno, | ||
147 | xfs_agblock_t bno, xfs_extlen_t len); | ||
131 | #endif /* __KERNEL__ */ | 148 | #endif /* __KERNEL__ */ |
132 | 149 | ||
133 | /* | 150 | /* |
@@ -205,4 +222,18 @@ xfs_free_extent( | |||
205 | xfs_fsblock_t bno, /* starting block number of extent */ | 222 | xfs_fsblock_t bno, /* starting block number of extent */ |
206 | xfs_extlen_t len); /* length of extent */ | 223 | xfs_extlen_t len); /* length of extent */ |
207 | 224 | ||
225 | int /* error */ | ||
226 | xfs_alloc_lookup_le( | ||
227 | struct xfs_btree_cur *cur, /* btree cursor */ | ||
228 | xfs_agblock_t bno, /* starting block of extent */ | ||
229 | xfs_extlen_t len, /* length of extent */ | ||
230 | int *stat); /* success/failure */ | ||
231 | |||
232 | int /* error */ | ||
233 | xfs_alloc_get_rec( | ||
234 | struct xfs_btree_cur *cur, /* btree cursor */ | ||
235 | xfs_agblock_t *bno, /* output: starting block of extent */ | ||
236 | xfs_extlen_t *len, /* output: length of extent */ | ||
237 | int *stat); /* output: success/failure */ | ||
238 | |||
208 | #endif /* __XFS_ALLOC_H__ */ | 239 | #endif /* __XFS_ALLOC_H__ */ |
diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c index 4111cd3966c7..dc3afd7739ff 100644 --- a/fs/xfs/xfs_bmap.c +++ b/fs/xfs/xfs_bmap.c | |||
@@ -1038,17 +1038,34 @@ xfs_bmap_add_extent_delay_real( | |||
1038 | * Filling in the middle part of a previous delayed allocation. | 1038 | * Filling in the middle part of a previous delayed allocation. |
1039 | * Contiguity is impossible here. | 1039 | * Contiguity is impossible here. |
1040 | * This case is avoided almost all the time. | 1040 | * This case is avoided almost all the time. |
1041 | * | ||
1042 | * We start with a delayed allocation: | ||
1043 | * | ||
1044 | * +ddddddddddddddddddddddddddddddddddddddddddddddddddddddd+ | ||
1045 | * PREV @ idx | ||
1046 | * | ||
1047 | * and we are allocating: | ||
1048 | * +rrrrrrrrrrrrrrrrr+ | ||
1049 | * new | ||
1050 | * | ||
1051 | * and we set it up for insertion as: | ||
1052 | * +ddddddddddddddddddd+rrrrrrrrrrrrrrrrr+ddddddddddddddddd+ | ||
1053 | * new | ||
1054 | * PREV @ idx LEFT RIGHT | ||
1055 | * inserted at idx + 1 | ||
1041 | */ | 1056 | */ |
1042 | temp = new->br_startoff - PREV.br_startoff; | 1057 | temp = new->br_startoff - PREV.br_startoff; |
1043 | trace_xfs_bmap_pre_update(ip, idx, 0, _THIS_IP_); | ||
1044 | xfs_bmbt_set_blockcount(ep, temp); | ||
1045 | r[0] = *new; | ||
1046 | r[1].br_state = PREV.br_state; | ||
1047 | r[1].br_startblock = 0; | ||
1048 | r[1].br_startoff = new_endoff; | ||
1049 | temp2 = PREV.br_startoff + PREV.br_blockcount - new_endoff; | 1058 | temp2 = PREV.br_startoff + PREV.br_blockcount - new_endoff; |
1050 | r[1].br_blockcount = temp2; | 1059 | trace_xfs_bmap_pre_update(ip, idx, 0, _THIS_IP_); |
1051 | xfs_iext_insert(ip, idx + 1, 2, &r[0], state); | 1060 | xfs_bmbt_set_blockcount(ep, temp); /* truncate PREV */ |
1061 | LEFT = *new; | ||
1062 | RIGHT.br_state = PREV.br_state; | ||
1063 | RIGHT.br_startblock = nullstartblock( | ||
1064 | (int)xfs_bmap_worst_indlen(ip, temp2)); | ||
1065 | RIGHT.br_startoff = new_endoff; | ||
1066 | RIGHT.br_blockcount = temp2; | ||
1067 | /* insert LEFT (r[0]) and RIGHT (r[1]) at the same time */ | ||
1068 | xfs_iext_insert(ip, idx + 1, 2, &LEFT, state); | ||
1052 | ip->i_df.if_lastex = idx + 1; | 1069 | ip->i_df.if_lastex = idx + 1; |
1053 | ip->i_d.di_nextents++; | 1070 | ip->i_d.di_nextents++; |
1054 | if (cur == NULL) | 1071 | if (cur == NULL) |
@@ -2430,7 +2447,7 @@ xfs_bmap_btalloc_nullfb( | |||
2430 | startag = ag = 0; | 2447 | startag = ag = 0; |
2431 | 2448 | ||
2432 | pag = xfs_perag_get(mp, ag); | 2449 | pag = xfs_perag_get(mp, ag); |
2433 | while (*blen < ap->alen) { | 2450 | while (*blen < args->maxlen) { |
2434 | if (!pag->pagf_init) { | 2451 | if (!pag->pagf_init) { |
2435 | error = xfs_alloc_pagf_init(mp, args->tp, ag, | 2452 | error = xfs_alloc_pagf_init(mp, args->tp, ag, |
2436 | XFS_ALLOC_FLAG_TRYLOCK); | 2453 | XFS_ALLOC_FLAG_TRYLOCK); |
@@ -2452,7 +2469,7 @@ xfs_bmap_btalloc_nullfb( | |||
2452 | notinit = 1; | 2469 | notinit = 1; |
2453 | 2470 | ||
2454 | if (xfs_inode_is_filestream(ap->ip)) { | 2471 | if (xfs_inode_is_filestream(ap->ip)) { |
2455 | if (*blen >= ap->alen) | 2472 | if (*blen >= args->maxlen) |
2456 | break; | 2473 | break; |
2457 | 2474 | ||
2458 | if (ap->userdata) { | 2475 | if (ap->userdata) { |
@@ -2498,14 +2515,14 @@ xfs_bmap_btalloc_nullfb( | |||
2498 | * If the best seen length is less than the request | 2515 | * If the best seen length is less than the request |
2499 | * length, use the best as the minimum. | 2516 | * length, use the best as the minimum. |
2500 | */ | 2517 | */ |
2501 | else if (*blen < ap->alen) | 2518 | else if (*blen < args->maxlen) |
2502 | args->minlen = *blen; | 2519 | args->minlen = *blen; |
2503 | /* | 2520 | /* |
2504 | * Otherwise we've seen an extent as big as alen, | 2521 | * Otherwise we've seen an extent as big as maxlen, |
2505 | * use that as the minimum. | 2522 | * use that as the minimum. |
2506 | */ | 2523 | */ |
2507 | else | 2524 | else |
2508 | args->minlen = ap->alen; | 2525 | args->minlen = args->maxlen; |
2509 | 2526 | ||
2510 | /* | 2527 | /* |
2511 | * set the failure fallback case to look in the selected | 2528 | * set the failure fallback case to look in the selected |
@@ -2573,7 +2590,9 @@ xfs_bmap_btalloc( | |||
2573 | args.tp = ap->tp; | 2590 | args.tp = ap->tp; |
2574 | args.mp = mp; | 2591 | args.mp = mp; |
2575 | args.fsbno = ap->rval; | 2592 | args.fsbno = ap->rval; |
2576 | args.maxlen = MIN(ap->alen, mp->m_sb.sb_agblocks); | 2593 | |
2594 | /* Trim the allocation back to the maximum an AG can fit. */ | ||
2595 | args.maxlen = MIN(ap->alen, XFS_ALLOC_AG_MAX_USABLE(mp)); | ||
2577 | args.firstblock = ap->firstblock; | 2596 | args.firstblock = ap->firstblock; |
2578 | blen = 0; | 2597 | blen = 0; |
2579 | if (nullfb) { | 2598 | if (nullfb) { |
@@ -2621,7 +2640,7 @@ xfs_bmap_btalloc( | |||
2621 | /* | 2640 | /* |
2622 | * Adjust for alignment | 2641 | * Adjust for alignment |
2623 | */ | 2642 | */ |
2624 | if (blen > args.alignment && blen <= ap->alen) | 2643 | if (blen > args.alignment && blen <= args.maxlen) |
2625 | args.minlen = blen - args.alignment; | 2644 | args.minlen = blen - args.alignment; |
2626 | args.minalignslop = 0; | 2645 | args.minalignslop = 0; |
2627 | } else { | 2646 | } else { |
@@ -2640,7 +2659,7 @@ xfs_bmap_btalloc( | |||
2640 | * of minlen+alignment+slop doesn't go up | 2659 | * of minlen+alignment+slop doesn't go up |
2641 | * between the calls. | 2660 | * between the calls. |
2642 | */ | 2661 | */ |
2643 | if (blen > mp->m_dalign && blen <= ap->alen) | 2662 | if (blen > mp->m_dalign && blen <= args.maxlen) |
2644 | nextminlen = blen - mp->m_dalign; | 2663 | nextminlen = blen - mp->m_dalign; |
2645 | else | 2664 | else |
2646 | nextminlen = args.minlen; | 2665 | nextminlen = args.minlen; |
@@ -4485,6 +4504,16 @@ xfs_bmapi( | |||
4485 | /* Figure out the extent size, adjust alen */ | 4504 | /* Figure out the extent size, adjust alen */ |
4486 | extsz = xfs_get_extsz_hint(ip); | 4505 | extsz = xfs_get_extsz_hint(ip); |
4487 | if (extsz) { | 4506 | if (extsz) { |
4507 | /* | ||
4508 | * make sure we don't exceed a single | ||
4509 | * extent length when we align the | ||
4510 | * extent by reducing length we are | ||
4511 | * going to allocate by the maximum | ||
4512 | * amount extent size aligment may | ||
4513 | * require. | ||
4514 | */ | ||
4515 | alen = XFS_FILBLKS_MIN(len, | ||
4516 | MAXEXTLEN - (2 * extsz - 1)); | ||
4488 | error = xfs_bmap_extsize_align(mp, | 4517 | error = xfs_bmap_extsize_align(mp, |
4489 | &got, &prev, extsz, | 4518 | &got, &prev, extsz, |
4490 | rt, eof, | 4519 | rt, eof, |
diff --git a/fs/xfs/xfs_buf_item.c b/fs/xfs/xfs_buf_item.c index ed2b65f3f8b9..6f8c21ce0d6d 100644 --- a/fs/xfs/xfs_buf_item.c +++ b/fs/xfs/xfs_buf_item.c | |||
@@ -141,7 +141,6 @@ xfs_buf_item_log_check( | |||
141 | #define xfs_buf_item_log_check(x) | 141 | #define xfs_buf_item_log_check(x) |
142 | #endif | 142 | #endif |
143 | 143 | ||
144 | STATIC void xfs_buf_error_relse(xfs_buf_t *bp); | ||
145 | STATIC void xfs_buf_do_callbacks(struct xfs_buf *bp); | 144 | STATIC void xfs_buf_do_callbacks(struct xfs_buf *bp); |
146 | 145 | ||
147 | /* | 146 | /* |
@@ -428,13 +427,15 @@ xfs_buf_item_unpin( | |||
428 | 427 | ||
429 | if (remove) { | 428 | if (remove) { |
430 | /* | 429 | /* |
431 | * We have to remove the log item from the transaction | 430 | * If we are in a transaction context, we have to |
432 | * as we are about to release our reference to the | 431 | * remove the log item from the transaction as we are |
433 | * buffer. If we don't, the unlock that occurs later | 432 | * about to release our reference to the buffer. If we |
434 | * in xfs_trans_uncommit() will ry to reference the | 433 | * don't, the unlock that occurs later in |
434 | * xfs_trans_uncommit() will try to reference the | ||
435 | * buffer which we no longer have a hold on. | 435 | * buffer which we no longer have a hold on. |
436 | */ | 436 | */ |
437 | xfs_trans_del_item(lip); | 437 | if (lip->li_desc) |
438 | xfs_trans_del_item(lip); | ||
438 | 439 | ||
439 | /* | 440 | /* |
440 | * Since the transaction no longer refers to the buffer, | 441 | * Since the transaction no longer refers to the buffer, |
@@ -959,128 +960,76 @@ xfs_buf_do_callbacks( | |||
959 | */ | 960 | */ |
960 | void | 961 | void |
961 | xfs_buf_iodone_callbacks( | 962 | xfs_buf_iodone_callbacks( |
962 | xfs_buf_t *bp) | 963 | struct xfs_buf *bp) |
963 | { | 964 | { |
964 | xfs_log_item_t *lip; | 965 | struct xfs_log_item *lip = bp->b_fspriv; |
965 | static ulong lasttime; | 966 | struct xfs_mount *mp = lip->li_mountp; |
966 | static xfs_buftarg_t *lasttarg; | 967 | static ulong lasttime; |
967 | xfs_mount_t *mp; | 968 | static xfs_buftarg_t *lasttarg; |
968 | 969 | ||
969 | ASSERT(XFS_BUF_FSPRIVATE(bp, void *) != NULL); | 970 | if (likely(!XFS_BUF_GETERROR(bp))) |
970 | lip = XFS_BUF_FSPRIVATE(bp, xfs_log_item_t *); | 971 | goto do_callbacks; |
971 | 972 | ||
972 | if (XFS_BUF_GETERROR(bp) != 0) { | 973 | /* |
973 | /* | 974 | * If we've already decided to shutdown the filesystem because of |
974 | * If we've already decided to shutdown the filesystem | 975 | * I/O errors, there's no point in giving this a retry. |
975 | * because of IO errors, there's no point in giving this | 976 | */ |
976 | * a retry. | 977 | if (XFS_FORCED_SHUTDOWN(mp)) { |
977 | */ | 978 | XFS_BUF_SUPER_STALE(bp); |
978 | mp = lip->li_mountp; | 979 | trace_xfs_buf_item_iodone(bp, _RET_IP_); |
979 | if (XFS_FORCED_SHUTDOWN(mp)) { | 980 | goto do_callbacks; |
980 | ASSERT(XFS_BUF_TARGET(bp) == mp->m_ddev_targp); | 981 | } |
981 | XFS_BUF_SUPER_STALE(bp); | ||
982 | trace_xfs_buf_item_iodone(bp, _RET_IP_); | ||
983 | xfs_buf_do_callbacks(bp); | ||
984 | XFS_BUF_SET_FSPRIVATE(bp, NULL); | ||
985 | XFS_BUF_CLR_IODONE_FUNC(bp); | ||
986 | xfs_buf_ioend(bp, 0); | ||
987 | return; | ||
988 | } | ||
989 | 982 | ||
990 | if ((XFS_BUF_TARGET(bp) != lasttarg) || | 983 | if (XFS_BUF_TARGET(bp) != lasttarg || |
991 | (time_after(jiffies, (lasttime + 5*HZ)))) { | 984 | time_after(jiffies, (lasttime + 5*HZ))) { |
992 | lasttime = jiffies; | 985 | lasttime = jiffies; |
993 | cmn_err(CE_ALERT, "Device %s, XFS metadata write error" | 986 | cmn_err(CE_ALERT, "Device %s, XFS metadata write error" |
994 | " block 0x%llx in %s", | 987 | " block 0x%llx in %s", |
995 | XFS_BUFTARG_NAME(XFS_BUF_TARGET(bp)), | 988 | XFS_BUFTARG_NAME(XFS_BUF_TARGET(bp)), |
996 | (__uint64_t)XFS_BUF_ADDR(bp), mp->m_fsname); | 989 | (__uint64_t)XFS_BUF_ADDR(bp), mp->m_fsname); |
997 | } | 990 | } |
998 | lasttarg = XFS_BUF_TARGET(bp); | 991 | lasttarg = XFS_BUF_TARGET(bp); |
999 | 992 | ||
1000 | if (XFS_BUF_ISASYNC(bp)) { | 993 | /* |
1001 | /* | 994 | * If the write was asynchronous then noone will be looking for the |
1002 | * If the write was asynchronous then noone will be | 995 | * error. Clear the error state and write the buffer out again. |
1003 | * looking for the error. Clear the error state | 996 | * |
1004 | * and write the buffer out again delayed write. | 997 | * During sync or umount we'll write all pending buffers again |
1005 | * | 998 | * synchronous, which will catch these errors if they keep hanging |
1006 | * XXXsup This is OK, so long as we catch these | 999 | * around. |
1007 | * before we start the umount; we don't want these | 1000 | */ |
1008 | * DELWRI metadata bufs to be hanging around. | 1001 | if (XFS_BUF_ISASYNC(bp)) { |
1009 | */ | 1002 | XFS_BUF_ERROR(bp, 0); /* errno of 0 unsets the flag */ |
1010 | XFS_BUF_ERROR(bp,0); /* errno of 0 unsets the flag */ | 1003 | |
1011 | 1004 | if (!XFS_BUF_ISSTALE(bp)) { | |
1012 | if (!(XFS_BUF_ISSTALE(bp))) { | 1005 | XFS_BUF_DELAYWRITE(bp); |
1013 | XFS_BUF_DELAYWRITE(bp); | ||
1014 | XFS_BUF_DONE(bp); | ||
1015 | XFS_BUF_SET_START(bp); | ||
1016 | } | ||
1017 | ASSERT(XFS_BUF_IODONE_FUNC(bp)); | ||
1018 | trace_xfs_buf_item_iodone_async(bp, _RET_IP_); | ||
1019 | xfs_buf_relse(bp); | ||
1020 | } else { | ||
1021 | /* | ||
1022 | * If the write of the buffer was not asynchronous, | ||
1023 | * then we want to make sure to return the error | ||
1024 | * to the caller of bwrite(). Because of this we | ||
1025 | * cannot clear the B_ERROR state at this point. | ||
1026 | * Instead we install a callback function that | ||
1027 | * will be called when the buffer is released, and | ||
1028 | * that routine will clear the error state and | ||
1029 | * set the buffer to be written out again after | ||
1030 | * some delay. | ||
1031 | */ | ||
1032 | /* We actually overwrite the existing b-relse | ||
1033 | function at times, but we're gonna be shutting down | ||
1034 | anyway. */ | ||
1035 | XFS_BUF_SET_BRELSE_FUNC(bp,xfs_buf_error_relse); | ||
1036 | XFS_BUF_DONE(bp); | 1006 | XFS_BUF_DONE(bp); |
1037 | XFS_BUF_FINISH_IOWAIT(bp); | 1007 | XFS_BUF_SET_START(bp); |
1038 | } | 1008 | } |
1009 | ASSERT(XFS_BUF_IODONE_FUNC(bp)); | ||
1010 | trace_xfs_buf_item_iodone_async(bp, _RET_IP_); | ||
1011 | xfs_buf_relse(bp); | ||
1039 | return; | 1012 | return; |
1040 | } | 1013 | } |
1041 | 1014 | ||
1042 | xfs_buf_do_callbacks(bp); | 1015 | /* |
1043 | XFS_BUF_SET_FSPRIVATE(bp, NULL); | 1016 | * If the write of the buffer was synchronous, we want to make |
1044 | XFS_BUF_CLR_IODONE_FUNC(bp); | 1017 | * sure to return the error to the caller of xfs_bwrite(). |
1045 | xfs_buf_ioend(bp, 0); | 1018 | */ |
1046 | } | ||
1047 | |||
1048 | /* | ||
1049 | * This is a callback routine attached to a buffer which gets an error | ||
1050 | * when being written out synchronously. | ||
1051 | */ | ||
1052 | STATIC void | ||
1053 | xfs_buf_error_relse( | ||
1054 | xfs_buf_t *bp) | ||
1055 | { | ||
1056 | xfs_log_item_t *lip; | ||
1057 | xfs_mount_t *mp; | ||
1058 | |||
1059 | lip = XFS_BUF_FSPRIVATE(bp, xfs_log_item_t *); | ||
1060 | mp = (xfs_mount_t *)lip->li_mountp; | ||
1061 | ASSERT(XFS_BUF_TARGET(bp) == mp->m_ddev_targp); | ||
1062 | |||
1063 | XFS_BUF_STALE(bp); | 1019 | XFS_BUF_STALE(bp); |
1064 | XFS_BUF_DONE(bp); | 1020 | XFS_BUF_DONE(bp); |
1065 | XFS_BUF_UNDELAYWRITE(bp); | 1021 | XFS_BUF_UNDELAYWRITE(bp); |
1066 | XFS_BUF_ERROR(bp,0); | ||
1067 | 1022 | ||
1068 | trace_xfs_buf_error_relse(bp, _RET_IP_); | 1023 | trace_xfs_buf_error_relse(bp, _RET_IP_); |
1024 | xfs_force_shutdown(mp, SHUTDOWN_META_IO_ERROR); | ||
1069 | 1025 | ||
1070 | if (! XFS_FORCED_SHUTDOWN(mp)) | 1026 | do_callbacks: |
1071 | xfs_force_shutdown(mp, SHUTDOWN_META_IO_ERROR); | ||
1072 | /* | ||
1073 | * We have to unpin the pinned buffers so do the | ||
1074 | * callbacks. | ||
1075 | */ | ||
1076 | xfs_buf_do_callbacks(bp); | 1027 | xfs_buf_do_callbacks(bp); |
1077 | XFS_BUF_SET_FSPRIVATE(bp, NULL); | 1028 | XFS_BUF_SET_FSPRIVATE(bp, NULL); |
1078 | XFS_BUF_CLR_IODONE_FUNC(bp); | 1029 | XFS_BUF_CLR_IODONE_FUNC(bp); |
1079 | XFS_BUF_SET_BRELSE_FUNC(bp,NULL); | 1030 | xfs_buf_ioend(bp, 0); |
1080 | xfs_buf_relse(bp); | ||
1081 | } | 1031 | } |
1082 | 1032 | ||
1083 | |||
1084 | /* | 1033 | /* |
1085 | * This is the iodone() function for buffers which have been | 1034 | * This is the iodone() function for buffers which have been |
1086 | * logged. It is called when they are eventually flushed out. | 1035 | * logged. It is called when they are eventually flushed out. |
diff --git a/fs/xfs/xfs_error.c b/fs/xfs/xfs_error.c index c78cc6a3d87c..4c7db74a05f7 100644 --- a/fs/xfs/xfs_error.c +++ b/fs/xfs/xfs_error.c | |||
@@ -152,37 +152,6 @@ xfs_errortag_clearall(xfs_mount_t *mp, int loud) | |||
152 | } | 152 | } |
153 | #endif /* DEBUG */ | 153 | #endif /* DEBUG */ |
154 | 154 | ||
155 | |||
156 | void | ||
157 | xfs_fs_cmn_err(int level, xfs_mount_t *mp, char *fmt, ...) | ||
158 | { | ||
159 | va_list ap; | ||
160 | |||
161 | va_start(ap, fmt); | ||
162 | xfs_fs_vcmn_err(level, mp, fmt, ap); | ||
163 | va_end(ap); | ||
164 | } | ||
165 | |||
166 | void | ||
167 | xfs_cmn_err(int panic_tag, int level, xfs_mount_t *mp, char *fmt, ...) | ||
168 | { | ||
169 | va_list ap; | ||
170 | |||
171 | #ifdef DEBUG | ||
172 | xfs_panic_mask |= (XFS_PTAG_SHUTDOWN_CORRUPT | XFS_PTAG_LOGRES); | ||
173 | #endif | ||
174 | |||
175 | if (xfs_panic_mask && (xfs_panic_mask & panic_tag) | ||
176 | && (level & CE_ALERT)) { | ||
177 | level &= ~CE_ALERT; | ||
178 | level |= CE_PANIC; | ||
179 | cmn_err(CE_ALERT, "XFS: Transforming an alert into a BUG."); | ||
180 | } | ||
181 | va_start(ap, fmt); | ||
182 | xfs_fs_vcmn_err(level, mp, fmt, ap); | ||
183 | va_end(ap); | ||
184 | } | ||
185 | |||
186 | void | 155 | void |
187 | xfs_error_report( | 156 | xfs_error_report( |
188 | const char *tag, | 157 | const char *tag, |
diff --git a/fs/xfs/xfs_error.h b/fs/xfs/xfs_error.h index f338847f80b8..10dce5475f02 100644 --- a/fs/xfs/xfs_error.h +++ b/fs/xfs/xfs_error.h | |||
@@ -136,8 +136,8 @@ extern int xfs_error_test(int, int *, char *, int, char *, unsigned long); | |||
136 | xfs_error_test((tag), (mp)->m_fixedfsid, "expr", __LINE__, __FILE__, \ | 136 | xfs_error_test((tag), (mp)->m_fixedfsid, "expr", __LINE__, __FILE__, \ |
137 | (rf)))) | 137 | (rf)))) |
138 | 138 | ||
139 | extern int xfs_errortag_add(int error_tag, xfs_mount_t *mp); | 139 | extern int xfs_errortag_add(int error_tag, struct xfs_mount *mp); |
140 | extern int xfs_errortag_clearall(xfs_mount_t *mp, int loud); | 140 | extern int xfs_errortag_clearall(struct xfs_mount *mp, int loud); |
141 | #else | 141 | #else |
142 | #define XFS_TEST_ERROR(expr, mp, tag, rf) (expr) | 142 | #define XFS_TEST_ERROR(expr, mp, tag, rf) (expr) |
143 | #define xfs_errortag_add(tag, mp) (ENOSYS) | 143 | #define xfs_errortag_add(tag, mp) (ENOSYS) |
@@ -162,21 +162,15 @@ extern int xfs_errortag_clearall(xfs_mount_t *mp, int loud); | |||
162 | 162 | ||
163 | struct xfs_mount; | 163 | struct xfs_mount; |
164 | 164 | ||
165 | extern void xfs_fs_vcmn_err(int level, struct xfs_mount *mp, | ||
166 | char *fmt, va_list ap) | ||
167 | __attribute__ ((format (printf, 3, 0))); | ||
168 | extern void xfs_cmn_err(int panic_tag, int level, struct xfs_mount *mp, | ||
169 | char *fmt, ...) | ||
170 | __attribute__ ((format (printf, 4, 5))); | ||
171 | extern void xfs_fs_cmn_err(int level, struct xfs_mount *mp, char *fmt, ...) | ||
172 | __attribute__ ((format (printf, 3, 4))); | ||
173 | |||
174 | extern void xfs_hex_dump(void *p, int length); | 165 | extern void xfs_hex_dump(void *p, int length); |
175 | 166 | ||
176 | #define xfs_fs_repair_cmn_err(level, mp, fmt, args...) \ | 167 | #define xfs_fs_repair_cmn_err(level, mp, fmt, args...) \ |
177 | xfs_fs_cmn_err(level, mp, fmt " Unmount and run xfs_repair.", ## args) | 168 | xfs_fs_cmn_err(level, mp, fmt " Unmount and run xfs_repair.", ## args) |
178 | 169 | ||
179 | #define xfs_fs_mount_cmn_err(f, fmt, args...) \ | 170 | #define xfs_fs_mount_cmn_err(f, fmt, args...) \ |
180 | ((f & XFS_MFSI_QUIET)? (void)0 : cmn_err(CE_WARN, "XFS: " fmt, ## args)) | 171 | do { \ |
172 | if (!(f & XFS_MFSI_QUIET)) \ | ||
173 | cmn_err(CE_WARN, "XFS: " fmt, ## args); \ | ||
174 | } while (0) | ||
181 | 175 | ||
182 | #endif /* __XFS_ERROR_H__ */ | 176 | #endif /* __XFS_ERROR_H__ */ |
diff --git a/fs/xfs/xfs_extfree_item.c b/fs/xfs/xfs_extfree_item.c index 75f2ef60e579..d22e62623437 100644 --- a/fs/xfs/xfs_extfree_item.c +++ b/fs/xfs/xfs_extfree_item.c | |||
@@ -138,7 +138,8 @@ xfs_efi_item_unpin( | |||
138 | 138 | ||
139 | if (remove) { | 139 | if (remove) { |
140 | ASSERT(!(lip->li_flags & XFS_LI_IN_AIL)); | 140 | ASSERT(!(lip->li_flags & XFS_LI_IN_AIL)); |
141 | xfs_trans_del_item(lip); | 141 | if (lip->li_desc) |
142 | xfs_trans_del_item(lip); | ||
142 | xfs_efi_item_free(efip); | 143 | xfs_efi_item_free(efip); |
143 | return; | 144 | return; |
144 | } | 145 | } |
diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c index f56d30e8040c..cec89dd5d7d2 100644 --- a/fs/xfs/xfs_fsops.c +++ b/fs/xfs/xfs_fsops.c | |||
@@ -612,12 +612,13 @@ out: | |||
612 | * | 612 | * |
613 | * We cannot use an inode here for this - that will push dirty state back up | 613 | * We cannot use an inode here for this - that will push dirty state back up |
614 | * into the VFS and then periodic inode flushing will prevent log covering from | 614 | * into the VFS and then periodic inode flushing will prevent log covering from |
615 | * making progress. Hence we log a field in the superblock instead. | 615 | * making progress. Hence we log a field in the superblock instead and use a |
616 | * synchronous transaction to ensure the superblock is immediately unpinned | ||
617 | * and can be written back. | ||
616 | */ | 618 | */ |
617 | int | 619 | int |
618 | xfs_fs_log_dummy( | 620 | xfs_fs_log_dummy( |
619 | xfs_mount_t *mp, | 621 | xfs_mount_t *mp) |
620 | int flags) | ||
621 | { | 622 | { |
622 | xfs_trans_t *tp; | 623 | xfs_trans_t *tp; |
623 | int error; | 624 | int error; |
@@ -632,8 +633,7 @@ xfs_fs_log_dummy( | |||
632 | 633 | ||
633 | /* log the UUID because it is an unchanging field */ | 634 | /* log the UUID because it is an unchanging field */ |
634 | xfs_mod_sb(tp, XFS_SB_UUID); | 635 | xfs_mod_sb(tp, XFS_SB_UUID); |
635 | if (flags & SYNC_WAIT) | 636 | xfs_trans_set_sync(tp); |
636 | xfs_trans_set_sync(tp); | ||
637 | return xfs_trans_commit(tp, 0); | 637 | return xfs_trans_commit(tp, 0); |
638 | } | 638 | } |
639 | 639 | ||
diff --git a/fs/xfs/xfs_fsops.h b/fs/xfs/xfs_fsops.h index a786c5212c1e..1b6a98b66886 100644 --- a/fs/xfs/xfs_fsops.h +++ b/fs/xfs/xfs_fsops.h | |||
@@ -25,6 +25,6 @@ extern int xfs_fs_counts(xfs_mount_t *mp, xfs_fsop_counts_t *cnt); | |||
25 | extern int xfs_reserve_blocks(xfs_mount_t *mp, __uint64_t *inval, | 25 | extern int xfs_reserve_blocks(xfs_mount_t *mp, __uint64_t *inval, |
26 | xfs_fsop_resblks_t *outval); | 26 | xfs_fsop_resblks_t *outval); |
27 | extern int xfs_fs_goingdown(xfs_mount_t *mp, __uint32_t inflags); | 27 | extern int xfs_fs_goingdown(xfs_mount_t *mp, __uint32_t inflags); |
28 | extern int xfs_fs_log_dummy(xfs_mount_t *mp, int flags); | 28 | extern int xfs_fs_log_dummy(struct xfs_mount *mp); |
29 | 29 | ||
30 | #endif /* __XFS_FSOPS_H__ */ | 30 | #endif /* __XFS_FSOPS_H__ */ |
diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index 55582bd66659..8a0f044750c3 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c | |||
@@ -337,7 +337,12 @@ xfs_iomap_prealloc_size( | |||
337 | int shift = 0; | 337 | int shift = 0; |
338 | int64_t freesp; | 338 | int64_t freesp; |
339 | 339 | ||
340 | alloc_blocks = XFS_B_TO_FSB(mp, ip->i_size); | 340 | /* |
341 | * rounddown_pow_of_two() returns an undefined result | ||
342 | * if we pass in alloc_blocks = 0. Hence the "+ 1" to | ||
343 | * ensure we always pass in a non-zero value. | ||
344 | */ | ||
345 | alloc_blocks = XFS_B_TO_FSB(mp, ip->i_size) + 1; | ||
341 | alloc_blocks = XFS_FILEOFF_MIN(MAXEXTLEN, | 346 | alloc_blocks = XFS_FILEOFF_MIN(MAXEXTLEN, |
342 | rounddown_pow_of_two(alloc_blocks)); | 347 | rounddown_pow_of_two(alloc_blocks)); |
343 | 348 | ||
diff --git a/fs/xfs/xfs_log.c b/fs/xfs/xfs_log.c index 0bf24b11d0c4..ae6fef1ff563 100644 --- a/fs/xfs/xfs_log.c +++ b/fs/xfs/xfs_log.c | |||
@@ -377,7 +377,7 @@ xfs_log_mount( | |||
377 | cmn_err(CE_NOTE, "XFS mounting filesystem %s", mp->m_fsname); | 377 | cmn_err(CE_NOTE, "XFS mounting filesystem %s", mp->m_fsname); |
378 | else { | 378 | else { |
379 | cmn_err(CE_NOTE, | 379 | cmn_err(CE_NOTE, |
380 | "!Mounting filesystem \"%s\" in no-recovery mode. Filesystem will be inconsistent.", | 380 | "Mounting filesystem \"%s\" in no-recovery mode. Filesystem will be inconsistent.", |
381 | mp->m_fsname); | 381 | mp->m_fsname); |
382 | ASSERT(mp->m_flags & XFS_MOUNT_RDONLY); | 382 | ASSERT(mp->m_flags & XFS_MOUNT_RDONLY); |
383 | } | 383 | } |
diff --git a/fs/xfs/xfs_log.h b/fs/xfs/xfs_log.h index 916eb7db14d9..3bd3291ef8d2 100644 --- a/fs/xfs/xfs_log.h +++ b/fs/xfs/xfs_log.h | |||
@@ -191,7 +191,7 @@ void xfs_log_ticket_put(struct xlog_ticket *ticket); | |||
191 | 191 | ||
192 | xlog_tid_t xfs_log_get_trans_ident(struct xfs_trans *tp); | 192 | xlog_tid_t xfs_log_get_trans_ident(struct xfs_trans *tp); |
193 | 193 | ||
194 | int xfs_log_commit_cil(struct xfs_mount *mp, struct xfs_trans *tp, | 194 | void xfs_log_commit_cil(struct xfs_mount *mp, struct xfs_trans *tp, |
195 | struct xfs_log_vec *log_vector, | 195 | struct xfs_log_vec *log_vector, |
196 | xfs_lsn_t *commit_lsn, int flags); | 196 | xfs_lsn_t *commit_lsn, int flags); |
197 | bool xfs_log_item_in_current_chkpt(struct xfs_log_item *lip); | 197 | bool xfs_log_item_in_current_chkpt(struct xfs_log_item *lip); |
diff --git a/fs/xfs/xfs_log_cil.c b/fs/xfs/xfs_log_cil.c index 9dc8125d04e5..9ca59be08977 100644 --- a/fs/xfs/xfs_log_cil.c +++ b/fs/xfs/xfs_log_cil.c | |||
@@ -543,7 +543,7 @@ xlog_cil_push( | |||
543 | 543 | ||
544 | error = xlog_write(log, &lvhdr, tic, &ctx->start_lsn, NULL, 0); | 544 | error = xlog_write(log, &lvhdr, tic, &ctx->start_lsn, NULL, 0); |
545 | if (error) | 545 | if (error) |
546 | goto out_abort; | 546 | goto out_abort_free_ticket; |
547 | 547 | ||
548 | /* | 548 | /* |
549 | * now that we've written the checkpoint into the log, strictly | 549 | * now that we've written the checkpoint into the log, strictly |
@@ -569,8 +569,9 @@ restart: | |||
569 | } | 569 | } |
570 | spin_unlock(&cil->xc_cil_lock); | 570 | spin_unlock(&cil->xc_cil_lock); |
571 | 571 | ||
572 | /* xfs_log_done always frees the ticket on error. */ | ||
572 | commit_lsn = xfs_log_done(log->l_mp, tic, &commit_iclog, 0); | 573 | commit_lsn = xfs_log_done(log->l_mp, tic, &commit_iclog, 0); |
573 | if (error || commit_lsn == -1) | 574 | if (commit_lsn == -1) |
574 | goto out_abort; | 575 | goto out_abort; |
575 | 576 | ||
576 | /* attach all the transactions w/ busy extents to iclog */ | 577 | /* attach all the transactions w/ busy extents to iclog */ |
@@ -600,6 +601,8 @@ out_free_ticket: | |||
600 | kmem_free(new_ctx); | 601 | kmem_free(new_ctx); |
601 | return 0; | 602 | return 0; |
602 | 603 | ||
604 | out_abort_free_ticket: | ||
605 | xfs_log_ticket_put(tic); | ||
603 | out_abort: | 606 | out_abort: |
604 | xlog_cil_committed(ctx, XFS_LI_ABORTED); | 607 | xlog_cil_committed(ctx, XFS_LI_ABORTED); |
605 | return XFS_ERROR(EIO); | 608 | return XFS_ERROR(EIO); |
@@ -622,7 +625,7 @@ out_abort: | |||
622 | * background commit, returns without it held once background commits are | 625 | * background commit, returns without it held once background commits are |
623 | * allowed again. | 626 | * allowed again. |
624 | */ | 627 | */ |
625 | int | 628 | void |
626 | xfs_log_commit_cil( | 629 | xfs_log_commit_cil( |
627 | struct xfs_mount *mp, | 630 | struct xfs_mount *mp, |
628 | struct xfs_trans *tp, | 631 | struct xfs_trans *tp, |
@@ -637,11 +640,6 @@ xfs_log_commit_cil( | |||
637 | if (flags & XFS_TRANS_RELEASE_LOG_RES) | 640 | if (flags & XFS_TRANS_RELEASE_LOG_RES) |
638 | log_flags = XFS_LOG_REL_PERM_RESERV; | 641 | log_flags = XFS_LOG_REL_PERM_RESERV; |
639 | 642 | ||
640 | if (XLOG_FORCED_SHUTDOWN(log)) { | ||
641 | xlog_cil_free_logvec(log_vector); | ||
642 | return XFS_ERROR(EIO); | ||
643 | } | ||
644 | |||
645 | /* | 643 | /* |
646 | * do all the hard work of formatting items (including memory | 644 | * do all the hard work of formatting items (including memory |
647 | * allocation) outside the CIL context lock. This prevents stalling CIL | 645 | * allocation) outside the CIL context lock. This prevents stalling CIL |
@@ -701,7 +699,6 @@ xfs_log_commit_cil( | |||
701 | */ | 699 | */ |
702 | if (push) | 700 | if (push) |
703 | xlog_cil_push(log, 0); | 701 | xlog_cil_push(log, 0); |
704 | return 0; | ||
705 | } | 702 | } |
706 | 703 | ||
707 | /* | 704 | /* |
diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c index 204d8e5fa7fa..aa0ebb776903 100644 --- a/fs/xfs/xfs_log_recover.c +++ b/fs/xfs/xfs_log_recover.c | |||
@@ -3800,7 +3800,7 @@ xlog_recover_finish( | |||
3800 | log->l_flags &= ~XLOG_RECOVERY_NEEDED; | 3800 | log->l_flags &= ~XLOG_RECOVERY_NEEDED; |
3801 | } else { | 3801 | } else { |
3802 | cmn_err(CE_DEBUG, | 3802 | cmn_err(CE_DEBUG, |
3803 | "!Ending clean XFS mount for filesystem: %s\n", | 3803 | "Ending clean XFS mount for filesystem: %s\n", |
3804 | log->l_mp->m_fsname); | 3804 | log->l_mp->m_fsname); |
3805 | } | 3805 | } |
3806 | return 0; | 3806 | return 0; |
diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c index f80a067a4658..76922793f64f 100644 --- a/fs/xfs/xfs_trans.c +++ b/fs/xfs/xfs_trans.c | |||
@@ -1137,7 +1137,7 @@ out_undo_fdblocks: | |||
1137 | if (blkdelta) | 1137 | if (blkdelta) |
1138 | xfs_icsb_modify_counters(mp, XFS_SBS_FDBLOCKS, -blkdelta, rsvd); | 1138 | xfs_icsb_modify_counters(mp, XFS_SBS_FDBLOCKS, -blkdelta, rsvd); |
1139 | out: | 1139 | out: |
1140 | ASSERT(error = 0); | 1140 | ASSERT(error == 0); |
1141 | return; | 1141 | return; |
1142 | } | 1142 | } |
1143 | 1143 | ||
@@ -1446,6 +1446,14 @@ xfs_log_item_batch_insert( | |||
1446 | * Bulk operation version of xfs_trans_committed that takes a log vector of | 1446 | * Bulk operation version of xfs_trans_committed that takes a log vector of |
1447 | * items to insert into the AIL. This uses bulk AIL insertion techniques to | 1447 | * items to insert into the AIL. This uses bulk AIL insertion techniques to |
1448 | * minimise lock traffic. | 1448 | * minimise lock traffic. |
1449 | * | ||
1450 | * If we are called with the aborted flag set, it is because a log write during | ||
1451 | * a CIL checkpoint commit has failed. In this case, all the items in the | ||
1452 | * checkpoint have already gone through IOP_COMMITED and IOP_UNLOCK, which | ||
1453 | * means that checkpoint commit abort handling is treated exactly the same | ||
1454 | * as an iclog write error even though we haven't started any IO yet. Hence in | ||
1455 | * this case all we need to do is IOP_COMMITTED processing, followed by an | ||
1456 | * IOP_UNPIN(aborted) call. | ||
1449 | */ | 1457 | */ |
1450 | void | 1458 | void |
1451 | xfs_trans_committed_bulk( | 1459 | xfs_trans_committed_bulk( |
@@ -1472,6 +1480,16 @@ xfs_trans_committed_bulk( | |||
1472 | if (XFS_LSN_CMP(item_lsn, (xfs_lsn_t)-1) == 0) | 1480 | if (XFS_LSN_CMP(item_lsn, (xfs_lsn_t)-1) == 0) |
1473 | continue; | 1481 | continue; |
1474 | 1482 | ||
1483 | /* | ||
1484 | * if we are aborting the operation, no point in inserting the | ||
1485 | * object into the AIL as we are in a shutdown situation. | ||
1486 | */ | ||
1487 | if (aborted) { | ||
1488 | ASSERT(XFS_FORCED_SHUTDOWN(ailp->xa_mount)); | ||
1489 | IOP_UNPIN(lip, 1); | ||
1490 | continue; | ||
1491 | } | ||
1492 | |||
1475 | if (item_lsn != commit_lsn) { | 1493 | if (item_lsn != commit_lsn) { |
1476 | 1494 | ||
1477 | /* | 1495 | /* |
@@ -1503,20 +1521,24 @@ xfs_trans_committed_bulk( | |||
1503 | } | 1521 | } |
1504 | 1522 | ||
1505 | /* | 1523 | /* |
1506 | * Called from the trans_commit code when we notice that | 1524 | * Called from the trans_commit code when we notice that the filesystem is in |
1507 | * the filesystem is in the middle of a forced shutdown. | 1525 | * the middle of a forced shutdown. |
1526 | * | ||
1527 | * When we are called here, we have already pinned all the items in the | ||
1528 | * transaction. However, neither IOP_COMMITTING or IOP_UNLOCK has been called | ||
1529 | * so we can simply walk the items in the transaction, unpin them with an abort | ||
1530 | * flag and then free the items. Note that unpinning the items can result in | ||
1531 | * them being freed immediately, so we need to use a safe list traversal method | ||
1532 | * here. | ||
1508 | */ | 1533 | */ |
1509 | STATIC void | 1534 | STATIC void |
1510 | xfs_trans_uncommit( | 1535 | xfs_trans_uncommit( |
1511 | struct xfs_trans *tp, | 1536 | struct xfs_trans *tp, |
1512 | uint flags) | 1537 | uint flags) |
1513 | { | 1538 | { |
1514 | struct xfs_log_item_desc *lidp; | 1539 | struct xfs_log_item_desc *lidp, *n; |
1515 | 1540 | ||
1516 | list_for_each_entry(lidp, &tp->t_items, lid_trans) { | 1541 | list_for_each_entry_safe(lidp, n, &tp->t_items, lid_trans) { |
1517 | /* | ||
1518 | * Unpin all but those that aren't dirty. | ||
1519 | */ | ||
1520 | if (lidp->lid_flags & XFS_LID_DIRTY) | 1542 | if (lidp->lid_flags & XFS_LID_DIRTY) |
1521 | IOP_UNPIN(lidp->lid_item, 1); | 1543 | IOP_UNPIN(lidp->lid_item, 1); |
1522 | } | 1544 | } |
@@ -1733,7 +1755,6 @@ xfs_trans_commit_cil( | |||
1733 | int flags) | 1755 | int flags) |
1734 | { | 1756 | { |
1735 | struct xfs_log_vec *log_vector; | 1757 | struct xfs_log_vec *log_vector; |
1736 | int error; | ||
1737 | 1758 | ||
1738 | /* | 1759 | /* |
1739 | * Get each log item to allocate a vector structure for | 1760 | * Get each log item to allocate a vector structure for |
@@ -1744,9 +1765,7 @@ xfs_trans_commit_cil( | |||
1744 | if (!log_vector) | 1765 | if (!log_vector) |
1745 | return ENOMEM; | 1766 | return ENOMEM; |
1746 | 1767 | ||
1747 | error = xfs_log_commit_cil(mp, tp, log_vector, commit_lsn, flags); | 1768 | xfs_log_commit_cil(mp, tp, log_vector, commit_lsn, flags); |
1748 | if (error) | ||
1749 | return error; | ||
1750 | 1769 | ||
1751 | current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS); | 1770 | current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS); |
1752 | xfs_trans_free(tp); | 1771 | xfs_trans_free(tp); |