Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
3e57ecf6 | 2 | * Copyright (c) 2000-2006 Silicon Graphics, Inc. |
7b718769 | 3 | * All Rights Reserved. |
1da177e4 | 4 | * |
7b718769 NS |
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 | |
1da177e4 LT |
7 | * published by the Free Software Foundation. |
8 | * | |
7b718769 NS |
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. | |
1da177e4 | 13 | * |
7b718769 NS |
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 | |
1da177e4 | 17 | */ |
1da177e4 | 18 | #include "xfs.h" |
1da177e4 | 19 | #include "xfs_fs.h" |
a844f451 | 20 | #include "xfs_bit.h" |
1da177e4 | 21 | #include "xfs_log.h" |
a844f451 | 22 | #include "xfs_inum.h" |
1da177e4 LT |
23 | #include "xfs_trans.h" |
24 | #include "xfs_sb.h" | |
25 | #include "xfs_ag.h" | |
26 | #include "xfs_dir.h" | |
27 | #include "xfs_dir2.h" | |
28 | #include "xfs_alloc.h" | |
29 | #include "xfs_dmapi.h" | |
30 | #include "xfs_quota.h" | |
31 | #include "xfs_mount.h" | |
1da177e4 | 32 | #include "xfs_bmap_btree.h" |
a844f451 | 33 | #include "xfs_alloc_btree.h" |
1da177e4 | 34 | #include "xfs_ialloc_btree.h" |
1da177e4 LT |
35 | #include "xfs_dir_sf.h" |
36 | #include "xfs_dir2_sf.h" | |
a844f451 | 37 | #include "xfs_attr_sf.h" |
1da177e4 LT |
38 | #include "xfs_dinode.h" |
39 | #include "xfs_inode.h" | |
a844f451 NS |
40 | #include "xfs_ialloc.h" |
41 | #include "xfs_btree.h" | |
1da177e4 | 42 | #include "xfs_bmap.h" |
1da177e4 LT |
43 | #include "xfs_rtalloc.h" |
44 | #include "xfs_error.h" | |
45 | #include "xfs_itable.h" | |
46 | #include "xfs_rw.h" | |
47 | #include "xfs_acl.h" | |
48 | #include "xfs_cap.h" | |
49 | #include "xfs_mac.h" | |
50 | #include "xfs_attr.h" | |
51 | #include "xfs_buf_item.h" | |
52 | #include "xfs_trans_space.h" | |
53 | #include "xfs_utils.h" | |
54 | #include "xfs_iomap.h" | |
55 | ||
56 | #if defined(XFS_RW_TRACE) | |
57 | void | |
58 | xfs_iomap_enter_trace( | |
59 | int tag, | |
60 | xfs_iocore_t *io, | |
61 | xfs_off_t offset, | |
62 | ssize_t count) | |
63 | { | |
64 | xfs_inode_t *ip = XFS_IO_INODE(io); | |
65 | ||
66 | if (!ip->i_rwtrace) | |
67 | return; | |
68 | ||
69 | ktrace_enter(ip->i_rwtrace, | |
70 | (void *)((unsigned long)tag), | |
71 | (void *)ip, | |
72 | (void *)((unsigned long)((ip->i_d.di_size >> 32) & 0xffffffff)), | |
73 | (void *)((unsigned long)(ip->i_d.di_size & 0xffffffff)), | |
74 | (void *)((unsigned long)((offset >> 32) & 0xffffffff)), | |
75 | (void *)((unsigned long)(offset & 0xffffffff)), | |
76 | (void *)((unsigned long)count), | |
77 | (void *)((unsigned long)((io->io_new_size >> 32) & 0xffffffff)), | |
78 | (void *)((unsigned long)(io->io_new_size & 0xffffffff)), | |
f1fdc848 | 79 | (void *)((unsigned long)current_pid()), |
1da177e4 LT |
80 | (void *)NULL, |
81 | (void *)NULL, | |
82 | (void *)NULL, | |
83 | (void *)NULL, | |
84 | (void *)NULL, | |
85 | (void *)NULL); | |
86 | } | |
87 | ||
88 | void | |
89 | xfs_iomap_map_trace( | |
90 | int tag, | |
91 | xfs_iocore_t *io, | |
92 | xfs_off_t offset, | |
93 | ssize_t count, | |
94 | xfs_iomap_t *iomapp, | |
95 | xfs_bmbt_irec_t *imapp, | |
96 | int flags) | |
97 | { | |
98 | xfs_inode_t *ip = XFS_IO_INODE(io); | |
99 | ||
100 | if (!ip->i_rwtrace) | |
101 | return; | |
102 | ||
103 | ktrace_enter(ip->i_rwtrace, | |
104 | (void *)((unsigned long)tag), | |
105 | (void *)ip, | |
106 | (void *)((unsigned long)((ip->i_d.di_size >> 32) & 0xffffffff)), | |
107 | (void *)((unsigned long)(ip->i_d.di_size & 0xffffffff)), | |
108 | (void *)((unsigned long)((offset >> 32) & 0xffffffff)), | |
109 | (void *)((unsigned long)(offset & 0xffffffff)), | |
110 | (void *)((unsigned long)count), | |
111 | (void *)((unsigned long)flags), | |
112 | (void *)((unsigned long)((iomapp->iomap_offset >> 32) & 0xffffffff)), | |
113 | (void *)((unsigned long)(iomapp->iomap_offset & 0xffffffff)), | |
114 | (void *)((unsigned long)(iomapp->iomap_delta)), | |
115 | (void *)((unsigned long)(iomapp->iomap_bsize)), | |
116 | (void *)((unsigned long)(iomapp->iomap_bn)), | |
117 | (void *)(__psint_t)(imapp->br_startoff), | |
118 | (void *)((unsigned long)(imapp->br_blockcount)), | |
119 | (void *)(__psint_t)(imapp->br_startblock)); | |
120 | } | |
121 | #else | |
122 | #define xfs_iomap_enter_trace(tag, io, offset, count) | |
123 | #define xfs_iomap_map_trace(tag, io, offset, count, iomapp, imapp, flags) | |
124 | #endif | |
125 | ||
126 | #define XFS_WRITEIO_ALIGN(mp,off) (((off) >> mp->m_writeio_log) \ | |
127 | << mp->m_writeio_log) | |
128 | #define XFS_STRAT_WRITE_IMAPS 2 | |
129 | #define XFS_WRITE_IMAPS XFS_BMAP_MAX_NMAP | |
130 | ||
131 | STATIC int | |
132 | xfs_imap_to_bmap( | |
133 | xfs_iocore_t *io, | |
134 | xfs_off_t offset, | |
135 | xfs_bmbt_irec_t *imap, | |
136 | xfs_iomap_t *iomapp, | |
137 | int imaps, /* Number of imap entries */ | |
138 | int iomaps, /* Number of iomap entries */ | |
139 | int flags) | |
140 | { | |
141 | xfs_mount_t *mp; | |
142 | xfs_fsize_t nisize; | |
143 | int pbm; | |
144 | xfs_fsblock_t start_block; | |
145 | ||
146 | mp = io->io_mount; | |
147 | nisize = XFS_SIZE(mp, io); | |
148 | if (io->io_new_size > nisize) | |
149 | nisize = io->io_new_size; | |
150 | ||
151 | for (pbm = 0; imaps && pbm < iomaps; imaps--, iomapp++, imap++, pbm++) { | |
152 | iomapp->iomap_offset = XFS_FSB_TO_B(mp, imap->br_startoff); | |
153 | iomapp->iomap_delta = offset - iomapp->iomap_offset; | |
154 | iomapp->iomap_bsize = XFS_FSB_TO_B(mp, imap->br_blockcount); | |
155 | iomapp->iomap_flags = flags; | |
156 | ||
157 | if (io->io_flags & XFS_IOCORE_RT) { | |
158 | iomapp->iomap_flags |= IOMAP_REALTIME; | |
159 | iomapp->iomap_target = mp->m_rtdev_targp; | |
160 | } else { | |
161 | iomapp->iomap_target = mp->m_ddev_targp; | |
162 | } | |
163 | start_block = imap->br_startblock; | |
164 | if (start_block == HOLESTARTBLOCK) { | |
165 | iomapp->iomap_bn = IOMAP_DADDR_NULL; | |
166 | iomapp->iomap_flags |= IOMAP_HOLE; | |
167 | } else if (start_block == DELAYSTARTBLOCK) { | |
168 | iomapp->iomap_bn = IOMAP_DADDR_NULL; | |
169 | iomapp->iomap_flags |= IOMAP_DELAY; | |
170 | } else { | |
171 | iomapp->iomap_bn = XFS_FSB_TO_DB_IO(io, start_block); | |
172 | if (ISUNWRITTEN(imap)) | |
173 | iomapp->iomap_flags |= IOMAP_UNWRITTEN; | |
174 | } | |
175 | ||
176 | if ((iomapp->iomap_offset + iomapp->iomap_bsize) >= nisize) { | |
177 | iomapp->iomap_flags |= IOMAP_EOF; | |
178 | } | |
179 | ||
180 | offset += iomapp->iomap_bsize - iomapp->iomap_delta; | |
181 | } | |
182 | return pbm; /* Return the number filled */ | |
183 | } | |
184 | ||
185 | int | |
186 | xfs_iomap( | |
187 | xfs_iocore_t *io, | |
188 | xfs_off_t offset, | |
189 | ssize_t count, | |
190 | int flags, | |
191 | xfs_iomap_t *iomapp, | |
192 | int *niomaps) | |
193 | { | |
194 | xfs_mount_t *mp = io->io_mount; | |
195 | xfs_fileoff_t offset_fsb, end_fsb; | |
196 | int error = 0; | |
197 | int lockmode = 0; | |
198 | xfs_bmbt_irec_t imap; | |
199 | int nimaps = 1; | |
200 | int bmapi_flags = 0; | |
201 | int iomap_flags = 0; | |
202 | ||
203 | if (XFS_FORCED_SHUTDOWN(mp)) | |
204 | return XFS_ERROR(EIO); | |
205 | ||
206 | switch (flags & | |
207 | (BMAPI_READ | BMAPI_WRITE | BMAPI_ALLOCATE | | |
208 | BMAPI_UNWRITTEN | BMAPI_DEVICE)) { | |
209 | case BMAPI_READ: | |
210 | xfs_iomap_enter_trace(XFS_IOMAP_READ_ENTER, io, offset, count); | |
211 | lockmode = XFS_LCK_MAP_SHARED(mp, io); | |
212 | bmapi_flags = XFS_BMAPI_ENTIRE; | |
1da177e4 LT |
213 | break; |
214 | case BMAPI_WRITE: | |
215 | xfs_iomap_enter_trace(XFS_IOMAP_WRITE_ENTER, io, offset, count); | |
216 | lockmode = XFS_ILOCK_EXCL|XFS_EXTSIZE_WR; | |
c31e8878 NS |
217 | if (flags & BMAPI_IGNSTATE) |
218 | bmapi_flags |= XFS_BMAPI_IGSTATE|XFS_BMAPI_ENTIRE; | |
1da177e4 LT |
219 | XFS_ILOCK(mp, io, lockmode); |
220 | break; | |
221 | case BMAPI_ALLOCATE: | |
222 | xfs_iomap_enter_trace(XFS_IOMAP_ALLOC_ENTER, io, offset, count); | |
223 | lockmode = XFS_ILOCK_SHARED|XFS_EXTSIZE_RD; | |
224 | bmapi_flags = XFS_BMAPI_ENTIRE; | |
225 | /* Attempt non-blocking lock */ | |
226 | if (flags & BMAPI_TRYLOCK) { | |
227 | if (!XFS_ILOCK_NOWAIT(mp, io, lockmode)) | |
228 | return XFS_ERROR(EAGAIN); | |
229 | } else { | |
230 | XFS_ILOCK(mp, io, lockmode); | |
231 | } | |
232 | break; | |
233 | case BMAPI_UNWRITTEN: | |
234 | goto phase2; | |
235 | case BMAPI_DEVICE: | |
236 | lockmode = XFS_LCK_MAP_SHARED(mp, io); | |
237 | iomapp->iomap_target = io->io_flags & XFS_IOCORE_RT ? | |
238 | mp->m_rtdev_targp : mp->m_ddev_targp; | |
239 | error = 0; | |
240 | *niomaps = 1; | |
241 | goto out; | |
242 | default: | |
243 | BUG(); | |
244 | } | |
245 | ||
246 | ASSERT(offset <= mp->m_maxioffset); | |
247 | if ((xfs_fsize_t)offset + count > mp->m_maxioffset) | |
248 | count = mp->m_maxioffset - offset; | |
249 | end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)offset + count); | |
250 | offset_fsb = XFS_B_TO_FSBT(mp, offset); | |
251 | ||
252 | error = XFS_BMAPI(mp, NULL, io, offset_fsb, | |
253 | (xfs_filblks_t)(end_fsb - offset_fsb), | |
254 | bmapi_flags, NULL, 0, &imap, | |
3e57ecf6 | 255 | &nimaps, NULL, NULL); |
1da177e4 LT |
256 | |
257 | if (error) | |
258 | goto out; | |
259 | ||
260 | phase2: | |
261 | switch (flags & (BMAPI_WRITE|BMAPI_ALLOCATE|BMAPI_UNWRITTEN)) { | |
262 | case BMAPI_WRITE: | |
263 | /* If we found an extent, return it */ | |
68d1498c | 264 | if (nimaps && |
dd9f438e | 265 | (imap.br_startblock != HOLESTARTBLOCK) && |
68d1498c | 266 | (imap.br_startblock != DELAYSTARTBLOCK)) { |
1da177e4 LT |
267 | xfs_iomap_map_trace(XFS_IOMAP_WRITE_MAP, io, |
268 | offset, count, iomapp, &imap, flags); | |
269 | break; | |
270 | } | |
271 | ||
272 | if (flags & (BMAPI_DIRECT|BMAPI_MMAP)) { | |
273 | error = XFS_IOMAP_WRITE_DIRECT(mp, io, offset, | |
274 | count, flags, &imap, &nimaps, nimaps); | |
275 | } else { | |
276 | error = XFS_IOMAP_WRITE_DELAY(mp, io, offset, count, | |
277 | flags, &imap, &nimaps); | |
278 | } | |
279 | if (!error) { | |
280 | xfs_iomap_map_trace(XFS_IOMAP_ALLOC_MAP, io, | |
281 | offset, count, iomapp, &imap, flags); | |
282 | } | |
283 | iomap_flags = IOMAP_NEW; | |
284 | break; | |
285 | case BMAPI_ALLOCATE: | |
286 | /* If we found an extent, return it */ | |
287 | XFS_IUNLOCK(mp, io, lockmode); | |
288 | lockmode = 0; | |
289 | ||
290 | if (nimaps && !ISNULLSTARTBLOCK(imap.br_startblock)) { | |
291 | xfs_iomap_map_trace(XFS_IOMAP_WRITE_MAP, io, | |
292 | offset, count, iomapp, &imap, flags); | |
293 | break; | |
294 | } | |
295 | ||
24e17b5f NS |
296 | error = XFS_IOMAP_WRITE_ALLOCATE(mp, io, offset, count, |
297 | &imap, &nimaps); | |
1da177e4 LT |
298 | break; |
299 | case BMAPI_UNWRITTEN: | |
300 | lockmode = 0; | |
301 | error = XFS_IOMAP_WRITE_UNWRITTEN(mp, io, offset, count); | |
302 | nimaps = 0; | |
303 | break; | |
304 | } | |
305 | ||
306 | if (nimaps) { | |
307 | *niomaps = xfs_imap_to_bmap(io, offset, &imap, | |
308 | iomapp, nimaps, *niomaps, iomap_flags); | |
309 | } else if (niomaps) { | |
310 | *niomaps = 0; | |
311 | } | |
312 | ||
313 | out: | |
314 | if (lockmode) | |
315 | XFS_IUNLOCK(mp, io, lockmode); | |
316 | return XFS_ERROR(error); | |
317 | } | |
318 | ||
dd9f438e NS |
319 | STATIC int |
320 | xfs_iomap_eof_align_last_fsb( | |
321 | xfs_mount_t *mp, | |
322 | xfs_iocore_t *io, | |
323 | xfs_fsize_t isize, | |
324 | xfs_extlen_t extsize, | |
325 | xfs_fileoff_t *last_fsb) | |
326 | { | |
327 | xfs_fileoff_t new_last_fsb = 0; | |
328 | xfs_extlen_t align; | |
329 | int eof, error; | |
330 | ||
331 | if (io->io_flags & XFS_IOCORE_RT) | |
332 | ; | |
333 | /* | |
334 | * If mounted with the "-o swalloc" option, roundup the allocation | |
335 | * request to a stripe width boundary if the file size is >= | |
336 | * stripe width and we are allocating past the allocation eof. | |
337 | */ | |
338 | else if (mp->m_swidth && (mp->m_flags & XFS_MOUNT_SWALLOC) && | |
339 | (isize >= XFS_FSB_TO_B(mp, mp->m_swidth))) | |
340 | new_last_fsb = roundup_64(*last_fsb, mp->m_swidth); | |
341 | /* | |
342 | * Roundup the allocation request to a stripe unit (m_dalign) boundary | |
343 | * if the file size is >= stripe unit size, and we are allocating past | |
344 | * the allocation eof. | |
345 | */ | |
346 | else if (mp->m_dalign && (isize >= XFS_FSB_TO_B(mp, mp->m_dalign))) | |
347 | new_last_fsb = roundup_64(*last_fsb, mp->m_dalign); | |
348 | ||
349 | /* | |
350 | * Always round up the allocation request to an extent boundary | |
351 | * (when file on a real-time subvolume or has di_extsize hint). | |
352 | */ | |
353 | if (extsize) { | |
354 | if (new_last_fsb) | |
355 | align = roundup_64(new_last_fsb, extsize); | |
356 | else | |
357 | align = extsize; | |
358 | new_last_fsb = roundup_64(*last_fsb, align); | |
359 | } | |
360 | ||
361 | if (new_last_fsb) { | |
362 | error = XFS_BMAP_EOF(mp, io, new_last_fsb, XFS_DATA_FORK, &eof); | |
363 | if (error) | |
364 | return error; | |
365 | if (eof) | |
366 | *last_fsb = new_last_fsb; | |
367 | } | |
368 | return 0; | |
369 | } | |
370 | ||
1da177e4 LT |
371 | STATIC int |
372 | xfs_flush_space( | |
373 | xfs_inode_t *ip, | |
374 | int *fsynced, | |
375 | int *ioflags) | |
376 | { | |
377 | switch (*fsynced) { | |
378 | case 0: | |
379 | if (ip->i_delayed_blks) { | |
380 | xfs_iunlock(ip, XFS_ILOCK_EXCL); | |
381 | xfs_flush_inode(ip); | |
382 | xfs_ilock(ip, XFS_ILOCK_EXCL); | |
383 | *fsynced = 1; | |
384 | } else { | |
385 | *ioflags |= BMAPI_SYNC; | |
386 | *fsynced = 2; | |
387 | } | |
388 | return 0; | |
389 | case 1: | |
390 | *fsynced = 2; | |
391 | *ioflags |= BMAPI_SYNC; | |
392 | return 0; | |
393 | case 2: | |
394 | xfs_iunlock(ip, XFS_ILOCK_EXCL); | |
395 | xfs_flush_device(ip); | |
396 | xfs_ilock(ip, XFS_ILOCK_EXCL); | |
397 | *fsynced = 3; | |
398 | return 0; | |
399 | } | |
400 | return 1; | |
401 | } | |
402 | ||
403 | int | |
404 | xfs_iomap_write_direct( | |
405 | xfs_inode_t *ip, | |
f403b7f4 | 406 | xfs_off_t offset, |
1da177e4 LT |
407 | size_t count, |
408 | int flags, | |
409 | xfs_bmbt_irec_t *ret_imap, | |
410 | int *nmaps, | |
411 | int found) | |
412 | { | |
413 | xfs_mount_t *mp = ip->i_mount; | |
414 | xfs_iocore_t *io = &ip->i_iocore; | |
415 | xfs_fileoff_t offset_fsb; | |
416 | xfs_fileoff_t last_fsb; | |
dd9f438e | 417 | xfs_filblks_t count_fsb, resaligned; |
1da177e4 | 418 | xfs_fsblock_t firstfsb; |
dd9f438e NS |
419 | xfs_extlen_t extsz, temp; |
420 | xfs_fsize_t isize; | |
0116d935 | 421 | int nimaps; |
1da177e4 | 422 | int bmapi_flag; |
06d10dd9 | 423 | int quota_flag; |
1da177e4 LT |
424 | int rt; |
425 | xfs_trans_t *tp; | |
0116d935 | 426 | xfs_bmbt_irec_t imap; |
1da177e4 | 427 | xfs_bmap_free_t free_list; |
dd9f438e | 428 | uint qblocks, resblks, resrtextents; |
1da177e4 | 429 | int committed; |
dd9f438e | 430 | int error; |
1da177e4 LT |
431 | |
432 | /* | |
433 | * Make sure that the dquots are there. This doesn't hold | |
434 | * the ilock across a disk read. | |
435 | */ | |
436 | error = XFS_QM_DQATTACH(ip->i_mount, ip, XFS_QMOPT_ILOCKED); | |
437 | if (error) | |
438 | return XFS_ERROR(error); | |
439 | ||
dd9f438e NS |
440 | rt = XFS_IS_REALTIME_INODE(ip); |
441 | if (unlikely(rt)) { | |
442 | if (!(extsz = ip->i_d.di_extsize)) | |
443 | extsz = mp->m_sb.sb_rextsize; | |
444 | } else { | |
445 | extsz = ip->i_d.di_extsize; | |
1da177e4 LT |
446 | } |
447 | ||
dd9f438e NS |
448 | isize = ip->i_d.di_size; |
449 | if (io->io_new_size > isize) | |
450 | isize = io->io_new_size; | |
1da177e4 | 451 | |
dd9f438e NS |
452 | offset_fsb = XFS_B_TO_FSBT(mp, offset); |
453 | last_fsb = XFS_B_TO_FSB(mp, ((xfs_ufsize_t)(offset + count))); | |
454 | if ((offset + count) > isize) { | |
455 | error = xfs_iomap_eof_align_last_fsb(mp, io, isize, extsz, | |
456 | &last_fsb); | |
457 | if (error) | |
458 | goto error_out; | |
1da177e4 | 459 | } else { |
dd9f438e NS |
460 | if (found && (ret_imap->br_startblock == HOLESTARTBLOCK)) |
461 | last_fsb = MIN(last_fsb, (xfs_fileoff_t) | |
462 | ret_imap->br_blockcount + | |
463 | ret_imap->br_startoff); | |
1da177e4 | 464 | } |
dd9f438e NS |
465 | count_fsb = last_fsb - offset_fsb; |
466 | ASSERT(count_fsb > 0); | |
467 | ||
468 | resaligned = count_fsb; | |
469 | if (unlikely(extsz)) { | |
470 | if ((temp = do_mod(offset_fsb, extsz))) | |
471 | resaligned += temp; | |
472 | if ((temp = do_mod(resaligned, extsz))) | |
473 | resaligned += extsz - temp; | |
474 | } | |
475 | ||
476 | if (unlikely(rt)) { | |
477 | resrtextents = qblocks = resaligned; | |
478 | resrtextents /= mp->m_sb.sb_rextsize; | |
479 | resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0); | |
480 | quota_flag = XFS_QMOPT_RES_RTBLKS; | |
481 | } else { | |
482 | resrtextents = 0; | |
483 | resblks = qblocks = XFS_DIOSTRAT_SPACE_RES(mp, resaligned); | |
484 | quota_flag = XFS_QMOPT_RES_REGBLKS; | |
485 | } | |
1da177e4 LT |
486 | |
487 | /* | |
06d10dd9 | 488 | * Allocate and setup the transaction |
1da177e4 LT |
489 | */ |
490 | xfs_iunlock(ip, XFS_ILOCK_EXCL); | |
491 | tp = xfs_trans_alloc(mp, XFS_TRANS_DIOSTRAT); | |
1da177e4 | 492 | error = xfs_trans_reserve(tp, resblks, |
d52b44d0 | 493 | XFS_WRITE_LOG_RES(mp), resrtextents, |
1da177e4 LT |
494 | XFS_TRANS_PERM_LOG_RES, |
495 | XFS_WRITE_LOG_COUNT); | |
1da177e4 | 496 | /* |
06d10dd9 | 497 | * Check for running out of space, note: need lock to return |
1da177e4 LT |
498 | */ |
499 | if (error) | |
1da177e4 | 500 | xfs_trans_cancel(tp, 0); |
1da177e4 | 501 | xfs_ilock(ip, XFS_ILOCK_EXCL); |
1da177e4 | 502 | if (error) |
06d10dd9 | 503 | goto error_out; |
1da177e4 | 504 | |
dd9f438e NS |
505 | error = XFS_TRANS_RESERVE_QUOTA_NBLKS(mp, tp, ip, |
506 | qblocks, 0, quota_flag); | |
507 | if (error) | |
1da177e4 | 508 | goto error1; |
1da177e4 | 509 | |
1da177e4 LT |
510 | xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); |
511 | xfs_trans_ihold(tp, ip); | |
512 | ||
dd9f438e NS |
513 | bmapi_flag = XFS_BMAPI_WRITE; |
514 | if ((flags & BMAPI_DIRECT) && (offset < ip->i_d.di_size || extsz)) | |
1da177e4 LT |
515 | bmapi_flag |= XFS_BMAPI_PREALLOC; |
516 | ||
517 | /* | |
dd9f438e | 518 | * Issue the xfs_bmapi() call to allocate the blocks |
1da177e4 LT |
519 | */ |
520 | XFS_BMAP_INIT(&free_list, &firstfsb); | |
06d10dd9 | 521 | nimaps = 1; |
3e57ecf6 OW |
522 | error = XFS_BMAPI(mp, tp, io, offset_fsb, count_fsb, bmapi_flag, |
523 | &firstfsb, 0, &imap, &nimaps, &free_list, NULL); | |
06d10dd9 | 524 | if (error) |
1da177e4 | 525 | goto error0; |
1da177e4 LT |
526 | |
527 | /* | |
06d10dd9 | 528 | * Complete the transaction |
1da177e4 | 529 | */ |
1da177e4 | 530 | error = xfs_bmap_finish(&tp, &free_list, firstfsb, &committed); |
06d10dd9 | 531 | if (error) |
1da177e4 | 532 | goto error0; |
1da177e4 | 533 | error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES, NULL); |
06d10dd9 | 534 | if (error) |
1da177e4 | 535 | goto error_out; |
1da177e4 | 536 | |
06d10dd9 NS |
537 | /* |
538 | * Copy any maps to caller's array and return any error. | |
539 | */ | |
1da177e4 LT |
540 | if (nimaps == 0) { |
541 | error = (ENOSPC); | |
542 | goto error_out; | |
543 | } | |
544 | ||
0116d935 | 545 | *ret_imap = imap; |
1da177e4 LT |
546 | *nmaps = 1; |
547 | if ( !(io->io_flags & XFS_IOCORE_RT) && !ret_imap->br_startblock) { | |
548 | cmn_err(CE_PANIC,"Access to block zero: fs <%s> inode: %lld " | |
549 | "start_block : %llx start_off : %llx blkcnt : %llx " | |
550 | "extent-state : %x \n", | |
551 | (ip->i_mount)->m_fsname, | |
552 | (long long)ip->i_ino, | |
6ab65429 NS |
553 | (unsigned long long)ret_imap->br_startblock, |
554 | (unsigned long long)ret_imap->br_startoff, | |
555 | (unsigned long long)ret_imap->br_blockcount, | |
556 | ret_imap->br_state); | |
1da177e4 LT |
557 | } |
558 | return 0; | |
559 | ||
06d10dd9 | 560 | error0: /* Cancel bmap, unlock inode, unreserve quota blocks, cancel trans */ |
1da177e4 | 561 | xfs_bmap_cancel(&free_list); |
06d10dd9 | 562 | XFS_TRANS_UNRESERVE_QUOTA_NBLKS(mp, tp, ip, qblocks, 0, quota_flag); |
1da177e4 | 563 | |
06d10dd9 | 564 | error1: /* Just cancel transaction */ |
1da177e4 LT |
565 | xfs_trans_cancel(tp, XFS_TRANS_RELEASE_LOG_RES | XFS_TRANS_ABORT); |
566 | *nmaps = 0; /* nothing set-up here */ | |
567 | ||
568 | error_out: | |
569 | return XFS_ERROR(error); | |
570 | } | |
571 | ||
dd9f438e NS |
572 | /* |
573 | * If the caller is doing a write at the end of the file, | |
574 | * then extend the allocation out to the file system's write | |
575 | * iosize. We clean up any extra space left over when the | |
576 | * file is closed in xfs_inactive(). | |
577 | * | |
578 | * For sync writes, we are flushing delayed allocate space to | |
579 | * try to make additional space available for allocation near | |
580 | * the filesystem full boundary - preallocation hurts in that | |
581 | * situation, of course. | |
582 | */ | |
583 | STATIC int | |
584 | xfs_iomap_eof_want_preallocate( | |
585 | xfs_mount_t *mp, | |
586 | xfs_iocore_t *io, | |
587 | xfs_fsize_t isize, | |
588 | xfs_off_t offset, | |
589 | size_t count, | |
590 | int ioflag, | |
591 | xfs_bmbt_irec_t *imap, | |
592 | int nimaps, | |
593 | int *prealloc) | |
594 | { | |
595 | xfs_fileoff_t start_fsb; | |
596 | xfs_filblks_t count_fsb; | |
597 | xfs_fsblock_t firstblock; | |
598 | int n, error, imaps; | |
599 | ||
600 | *prealloc = 0; | |
601 | if ((ioflag & BMAPI_SYNC) || (offset + count) <= isize) | |
602 | return 0; | |
603 | ||
604 | /* | |
605 | * If there are any real blocks past eof, then don't | |
606 | * do any speculative allocation. | |
607 | */ | |
608 | start_fsb = XFS_B_TO_FSBT(mp, ((xfs_ufsize_t)(offset + count - 1))); | |
609 | count_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)XFS_MAXIOFFSET(mp)); | |
610 | while (count_fsb > 0) { | |
611 | imaps = nimaps; | |
3ddb8fa9 | 612 | firstblock = NULLFSBLOCK; |
3e57ecf6 OW |
613 | error = XFS_BMAPI(mp, NULL, io, start_fsb, count_fsb, 0, |
614 | &firstblock, 0, imap, &imaps, NULL, NULL); | |
dd9f438e NS |
615 | if (error) |
616 | return error; | |
617 | for (n = 0; n < imaps; n++) { | |
618 | if ((imap[n].br_startblock != HOLESTARTBLOCK) && | |
619 | (imap[n].br_startblock != DELAYSTARTBLOCK)) | |
620 | return 0; | |
621 | start_fsb += imap[n].br_blockcount; | |
622 | count_fsb -= imap[n].br_blockcount; | |
623 | } | |
624 | } | |
625 | *prealloc = 1; | |
626 | return 0; | |
627 | } | |
628 | ||
1da177e4 LT |
629 | int |
630 | xfs_iomap_write_delay( | |
631 | xfs_inode_t *ip, | |
f403b7f4 | 632 | xfs_off_t offset, |
1da177e4 LT |
633 | size_t count, |
634 | int ioflag, | |
635 | xfs_bmbt_irec_t *ret_imap, | |
636 | int *nmaps) | |
637 | { | |
638 | xfs_mount_t *mp = ip->i_mount; | |
639 | xfs_iocore_t *io = &ip->i_iocore; | |
640 | xfs_fileoff_t offset_fsb; | |
641 | xfs_fileoff_t last_fsb; | |
dd9f438e NS |
642 | xfs_off_t aligned_offset; |
643 | xfs_fileoff_t ioalign; | |
1da177e4 | 644 | xfs_fsblock_t firstblock; |
dd9f438e NS |
645 | xfs_extlen_t extsz; |
646 | xfs_fsize_t isize; | |
1da177e4 | 647 | int nimaps; |
1da177e4 | 648 | xfs_bmbt_irec_t imap[XFS_WRITE_IMAPS]; |
dd9f438e NS |
649 | int prealloc, fsynced = 0; |
650 | int error; | |
1da177e4 LT |
651 | |
652 | ASSERT(ismrlocked(&ip->i_lock, MR_UPDATE) != 0); | |
653 | ||
654 | /* | |
655 | * Make sure that the dquots are there. This doesn't hold | |
656 | * the ilock across a disk read. | |
657 | */ | |
1da177e4 LT |
658 | error = XFS_QM_DQATTACH(mp, ip, XFS_QMOPT_ILOCKED); |
659 | if (error) | |
660 | return XFS_ERROR(error); | |
661 | ||
dd9f438e NS |
662 | if (XFS_IS_REALTIME_INODE(ip)) { |
663 | if (!(extsz = ip->i_d.di_extsize)) | |
664 | extsz = mp->m_sb.sb_rextsize; | |
665 | } else { | |
666 | extsz = ip->i_d.di_extsize; | |
667 | } | |
668 | ||
669 | offset_fsb = XFS_B_TO_FSBT(mp, offset); | |
670 | ||
1da177e4 LT |
671 | retry: |
672 | isize = ip->i_d.di_size; | |
dd9f438e | 673 | if (io->io_new_size > isize) |
1da177e4 | 674 | isize = io->io_new_size; |
1da177e4 | 675 | |
dd9f438e NS |
676 | error = xfs_iomap_eof_want_preallocate(mp, io, isize, offset, count, |
677 | ioflag, imap, XFS_WRITE_IMAPS, &prealloc); | |
678 | if (error) | |
679 | return error; | |
1da177e4 | 680 | |
dd9f438e | 681 | if (prealloc) { |
1da177e4 LT |
682 | aligned_offset = XFS_WRITEIO_ALIGN(mp, (offset + count - 1)); |
683 | ioalign = XFS_B_TO_FSBT(mp, aligned_offset); | |
dd9f438e NS |
684 | last_fsb = ioalign + mp->m_writeio_blocks; |
685 | } else { | |
686 | last_fsb = XFS_B_TO_FSB(mp, ((xfs_ufsize_t)(offset + count))); | |
1da177e4 | 687 | } |
1da177e4 | 688 | |
dd9f438e NS |
689 | if (prealloc || extsz) { |
690 | error = xfs_iomap_eof_align_last_fsb(mp, io, isize, extsz, | |
691 | &last_fsb); | |
692 | if (error) | |
1da177e4 | 693 | return error; |
1da177e4 | 694 | } |
dd9f438e NS |
695 | |
696 | nimaps = XFS_WRITE_IMAPS; | |
697 | firstblock = NULLFSBLOCK; | |
3e57ecf6 | 698 | error = XFS_BMAPI(mp, NULL, io, offset_fsb, |
1da177e4 LT |
699 | (xfs_filblks_t)(last_fsb - offset_fsb), |
700 | XFS_BMAPI_DELAY | XFS_BMAPI_WRITE | | |
701 | XFS_BMAPI_ENTIRE, &firstblock, 1, imap, | |
3e57ecf6 | 702 | &nimaps, NULL, NULL); |
dd9f438e | 703 | if (error && (error != ENOSPC)) |
1da177e4 | 704 | return XFS_ERROR(error); |
dd9f438e | 705 | |
1da177e4 LT |
706 | /* |
707 | * If bmapi returned us nothing, and if we didn't get back EDQUOT, | |
dd9f438e | 708 | * then we must have run out of space - flush delalloc, and retry.. |
1da177e4 LT |
709 | */ |
710 | if (nimaps == 0) { | |
711 | xfs_iomap_enter_trace(XFS_IOMAP_WRITE_NOSPACE, | |
712 | io, offset, count); | |
713 | if (xfs_flush_space(ip, &fsynced, &ioflag)) | |
714 | return XFS_ERROR(ENOSPC); | |
715 | ||
716 | error = 0; | |
717 | goto retry; | |
718 | } | |
719 | ||
dd9f438e | 720 | if (!(io->io_flags & XFS_IOCORE_RT) && !ret_imap->br_startblock) { |
1da177e4 LT |
721 | cmn_err(CE_PANIC,"Access to block zero: fs <%s> inode: %lld " |
722 | "start_block : %llx start_off : %llx blkcnt : %llx " | |
723 | "extent-state : %x \n", | |
724 | (ip->i_mount)->m_fsname, | |
725 | (long long)ip->i_ino, | |
6ab65429 NS |
726 | (unsigned long long)ret_imap->br_startblock, |
727 | (unsigned long long)ret_imap->br_startoff, | |
728 | (unsigned long long)ret_imap->br_blockcount, | |
729 | ret_imap->br_state); | |
1da177e4 | 730 | } |
dd9f438e NS |
731 | |
732 | *ret_imap = imap[0]; | |
733 | *nmaps = 1; | |
734 | ||
1da177e4 LT |
735 | return 0; |
736 | } | |
737 | ||
738 | /* | |
739 | * Pass in a delayed allocate extent, convert it to real extents; | |
740 | * return to the caller the extent we create which maps on top of | |
741 | * the originating callers request. | |
742 | * | |
743 | * Called without a lock on the inode. | |
744 | */ | |
745 | int | |
746 | xfs_iomap_write_allocate( | |
747 | xfs_inode_t *ip, | |
f403b7f4 | 748 | xfs_off_t offset, |
24e17b5f | 749 | size_t count, |
1da177e4 LT |
750 | xfs_bmbt_irec_t *map, |
751 | int *retmap) | |
752 | { | |
753 | xfs_mount_t *mp = ip->i_mount; | |
754 | xfs_iocore_t *io = &ip->i_iocore; | |
755 | xfs_fileoff_t offset_fsb, last_block; | |
756 | xfs_fileoff_t end_fsb, map_start_fsb; | |
757 | xfs_fsblock_t first_block; | |
758 | xfs_bmap_free_t free_list; | |
759 | xfs_filblks_t count_fsb; | |
760 | xfs_bmbt_irec_t imap[XFS_STRAT_WRITE_IMAPS]; | |
761 | xfs_trans_t *tp; | |
762 | int i, nimaps, committed; | |
763 | int error = 0; | |
764 | int nres; | |
765 | ||
766 | *retmap = 0; | |
767 | ||
768 | /* | |
769 | * Make sure that the dquots are there. | |
770 | */ | |
771 | if ((error = XFS_QM_DQATTACH(mp, ip, 0))) | |
772 | return XFS_ERROR(error); | |
773 | ||
24e17b5f | 774 | offset_fsb = XFS_B_TO_FSBT(mp, offset); |
1da177e4 | 775 | count_fsb = map->br_blockcount; |
24e17b5f | 776 | map_start_fsb = map->br_startoff; |
1da177e4 LT |
777 | |
778 | XFS_STATS_ADD(xs_xstrat_bytes, XFS_FSB_TO_B(mp, count_fsb)); | |
779 | ||
780 | while (count_fsb != 0) { | |
781 | /* | |
782 | * Set up a transaction with which to allocate the | |
783 | * backing store for the file. Do allocations in a | |
784 | * loop until we get some space in the range we are | |
785 | * interested in. The other space that might be allocated | |
786 | * is in the delayed allocation extent on which we sit | |
787 | * but before our buffer starts. | |
788 | */ | |
789 | ||
790 | nimaps = 0; | |
791 | while (nimaps == 0) { | |
792 | tp = xfs_trans_alloc(mp, XFS_TRANS_STRAT_WRITE); | |
793 | nres = XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK); | |
794 | error = xfs_trans_reserve(tp, nres, | |
795 | XFS_WRITE_LOG_RES(mp), | |
796 | 0, XFS_TRANS_PERM_LOG_RES, | |
797 | XFS_WRITE_LOG_COUNT); | |
798 | if (error == ENOSPC) { | |
799 | error = xfs_trans_reserve(tp, 0, | |
800 | XFS_WRITE_LOG_RES(mp), | |
801 | 0, | |
802 | XFS_TRANS_PERM_LOG_RES, | |
803 | XFS_WRITE_LOG_COUNT); | |
804 | } | |
805 | if (error) { | |
806 | xfs_trans_cancel(tp, 0); | |
807 | return XFS_ERROR(error); | |
808 | } | |
809 | xfs_ilock(ip, XFS_ILOCK_EXCL); | |
810 | xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); | |
811 | xfs_trans_ihold(tp, ip); | |
812 | ||
813 | XFS_BMAP_INIT(&free_list, &first_block); | |
814 | ||
815 | nimaps = XFS_STRAT_WRITE_IMAPS; | |
816 | /* | |
817 | * Ensure we don't go beyond eof - it is possible | |
818 | * the extents changed since we did the read call, | |
819 | * we dropped the ilock in the interim. | |
820 | */ | |
821 | ||
822 | end_fsb = XFS_B_TO_FSB(mp, ip->i_d.di_size); | |
823 | xfs_bmap_last_offset(NULL, ip, &last_block, | |
824 | XFS_DATA_FORK); | |
825 | last_block = XFS_FILEOFF_MAX(last_block, end_fsb); | |
826 | if ((map_start_fsb + count_fsb) > last_block) { | |
827 | count_fsb = last_block - map_start_fsb; | |
828 | if (count_fsb == 0) { | |
829 | error = EAGAIN; | |
830 | goto trans_cancel; | |
831 | } | |
832 | } | |
833 | ||
834 | /* Go get the actual blocks */ | |
3e57ecf6 | 835 | error = XFS_BMAPI(mp, tp, io, map_start_fsb, count_fsb, |
1da177e4 | 836 | XFS_BMAPI_WRITE, &first_block, 1, |
3e57ecf6 | 837 | imap, &nimaps, &free_list, NULL); |
1da177e4 LT |
838 | if (error) |
839 | goto trans_cancel; | |
840 | ||
841 | error = xfs_bmap_finish(&tp, &free_list, | |
842 | first_block, &committed); | |
843 | if (error) | |
844 | goto trans_cancel; | |
845 | ||
846 | error = xfs_trans_commit(tp, | |
847 | XFS_TRANS_RELEASE_LOG_RES, NULL); | |
848 | if (error) | |
849 | goto error0; | |
850 | ||
851 | xfs_iunlock(ip, XFS_ILOCK_EXCL); | |
852 | } | |
853 | ||
854 | /* | |
855 | * See if we were able to allocate an extent that | |
856 | * covers at least part of the callers request | |
857 | */ | |
858 | ||
859 | for (i = 0; i < nimaps; i++) { | |
6ab65429 NS |
860 | if (!(io->io_flags & XFS_IOCORE_RT) && |
861 | !imap[i].br_startblock) { | |
1da177e4 LT |
862 | cmn_err(CE_PANIC,"Access to block zero: " |
863 | "fs <%s> inode: %lld " | |
6ab65429 | 864 | "start_block : %llx start_off : %llx " |
1da177e4 LT |
865 | "blkcnt : %llx extent-state : %x \n", |
866 | (ip->i_mount)->m_fsname, | |
867 | (long long)ip->i_ino, | |
6ab65429 NS |
868 | (unsigned long long) |
869 | imap[i].br_startblock, | |
870 | (unsigned long long) | |
871 | imap[i].br_startoff, | |
872 | (unsigned long long) | |
873 | imap[i].br_blockcount, | |
874 | imap[i].br_state); | |
1da177e4 | 875 | } |
24e17b5f NS |
876 | if ((offset_fsb >= imap[i].br_startoff) && |
877 | (offset_fsb < (imap[i].br_startoff + | |
878 | imap[i].br_blockcount))) { | |
1da177e4 LT |
879 | *map = imap[i]; |
880 | *retmap = 1; | |
881 | XFS_STATS_INC(xs_xstrat_quick); | |
882 | return 0; | |
883 | } | |
884 | count_fsb -= imap[i].br_blockcount; | |
885 | } | |
886 | ||
887 | /* So far we have not mapped the requested part of the | |
888 | * file, just surrounding data, try again. | |
889 | */ | |
890 | nimaps--; | |
24e17b5f NS |
891 | map_start_fsb = imap[nimaps].br_startoff + |
892 | imap[nimaps].br_blockcount; | |
1da177e4 LT |
893 | } |
894 | ||
895 | trans_cancel: | |
896 | xfs_bmap_cancel(&free_list); | |
897 | xfs_trans_cancel(tp, XFS_TRANS_RELEASE_LOG_RES | XFS_TRANS_ABORT); | |
898 | error0: | |
899 | xfs_iunlock(ip, XFS_ILOCK_EXCL); | |
900 | return XFS_ERROR(error); | |
901 | } | |
902 | ||
903 | int | |
904 | xfs_iomap_write_unwritten( | |
905 | xfs_inode_t *ip, | |
f403b7f4 | 906 | xfs_off_t offset, |
1da177e4 LT |
907 | size_t count) |
908 | { | |
909 | xfs_mount_t *mp = ip->i_mount; | |
910 | xfs_iocore_t *io = &ip->i_iocore; | |
1da177e4 LT |
911 | xfs_fileoff_t offset_fsb; |
912 | xfs_filblks_t count_fsb; | |
913 | xfs_filblks_t numblks_fsb; | |
dd9f438e NS |
914 | xfs_fsblock_t firstfsb; |
915 | int nimaps; | |
916 | xfs_trans_t *tp; | |
917 | xfs_bmbt_irec_t imap; | |
918 | xfs_bmap_free_t free_list; | |
919 | uint resblks; | |
1da177e4 LT |
920 | int committed; |
921 | int error; | |
1da177e4 LT |
922 | |
923 | xfs_iomap_enter_trace(XFS_IOMAP_UNWRITTEN, | |
924 | &ip->i_iocore, offset, count); | |
925 | ||
926 | offset_fsb = XFS_B_TO_FSBT(mp, offset); | |
927 | count_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)offset + count); | |
928 | count_fsb = (xfs_filblks_t)(count_fsb - offset_fsb); | |
929 | ||
dd9f438e | 930 | resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0) << 1; |
1da177e4 | 931 | |
dd9f438e | 932 | do { |
1da177e4 LT |
933 | /* |
934 | * set up a transaction to convert the range of extents | |
935 | * from unwritten to real. Do allocations in a loop until | |
936 | * we have covered the range passed in. | |
937 | */ | |
938 | ||
939 | tp = xfs_trans_alloc(mp, XFS_TRANS_STRAT_WRITE); | |
dd9f438e | 940 | error = xfs_trans_reserve(tp, resblks, |
1da177e4 LT |
941 | XFS_WRITE_LOG_RES(mp), 0, |
942 | XFS_TRANS_PERM_LOG_RES, | |
943 | XFS_WRITE_LOG_COUNT); | |
944 | if (error) { | |
945 | xfs_trans_cancel(tp, 0); | |
946 | goto error0; | |
947 | } | |
948 | ||
949 | xfs_ilock(ip, XFS_ILOCK_EXCL); | |
950 | xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); | |
951 | xfs_trans_ihold(tp, ip); | |
952 | ||
953 | /* | |
954 | * Modify the unwritten extent state of the buffer. | |
955 | */ | |
956 | XFS_BMAP_INIT(&free_list, &firstfsb); | |
957 | nimaps = 1; | |
3e57ecf6 | 958 | error = XFS_BMAPI(mp, tp, io, offset_fsb, count_fsb, |
dd9f438e | 959 | XFS_BMAPI_WRITE|XFS_BMAPI_CONVERT, &firstfsb, |
3e57ecf6 | 960 | 1, &imap, &nimaps, &free_list, NULL); |
1da177e4 LT |
961 | if (error) |
962 | goto error_on_bmapi_transaction; | |
963 | ||
964 | error = xfs_bmap_finish(&(tp), &(free_list), | |
965 | firstfsb, &committed); | |
966 | if (error) | |
967 | goto error_on_bmapi_transaction; | |
968 | ||
969 | error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES, NULL); | |
970 | xfs_iunlock(ip, XFS_ILOCK_EXCL); | |
971 | if (error) | |
972 | goto error0; | |
dd9f438e | 973 | |
1da177e4 LT |
974 | if ( !(io->io_flags & XFS_IOCORE_RT) && !imap.br_startblock) { |
975 | cmn_err(CE_PANIC,"Access to block zero: fs <%s> " | |
976 | "inode: %lld start_block : %llx start_off : " | |
977 | "%llx blkcnt : %llx extent-state : %x \n", | |
978 | (ip->i_mount)->m_fsname, | |
979 | (long long)ip->i_ino, | |
6ab65429 NS |
980 | (unsigned long long)imap.br_startblock, |
981 | (unsigned long long)imap.br_startoff, | |
982 | (unsigned long long)imap.br_blockcount, | |
983 | imap.br_state); | |
1da177e4 LT |
984 | } |
985 | ||
986 | if ((numblks_fsb = imap.br_blockcount) == 0) { | |
987 | /* | |
988 | * The numblks_fsb value should always get | |
989 | * smaller, otherwise the loop is stuck. | |
990 | */ | |
991 | ASSERT(imap.br_blockcount); | |
992 | break; | |
993 | } | |
994 | offset_fsb += numblks_fsb; | |
995 | count_fsb -= numblks_fsb; | |
996 | } while (count_fsb > 0); | |
997 | ||
998 | return 0; | |
999 | ||
1000 | error_on_bmapi_transaction: | |
1001 | xfs_bmap_cancel(&free_list); | |
1002 | xfs_trans_cancel(tp, (XFS_TRANS_RELEASE_LOG_RES | XFS_TRANS_ABORT)); | |
1003 | xfs_iunlock(ip, XFS_ILOCK_EXCL); | |
1004 | error0: | |
1005 | return XFS_ERROR(error); | |
1006 | } |