]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
7b718769 NS |
2 | * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc. |
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" |
a844f451 | 19 | #include "xfs_fs.h" |
1da177e4 | 20 | #include "xfs_types.h" |
a844f451 | 21 | #include "xfs_bit.h" |
1da177e4 | 22 | #include "xfs_log.h" |
a844f451 | 23 | #include "xfs_inum.h" |
1da177e4 LT |
24 | #include "xfs_trans.h" |
25 | #include "xfs_buf_item.h" | |
26 | #include "xfs_sb.h" | |
a844f451 | 27 | #include "xfs_ag.h" |
1da177e4 LT |
28 | #include "xfs_dir2.h" |
29 | #include "xfs_dmapi.h" | |
30 | #include "xfs_mount.h" | |
31 | #include "xfs_trans_priv.h" | |
1da177e4 | 32 | #include "xfs_bmap_btree.h" |
a844f451 | 33 | #include "xfs_alloc_btree.h" |
1da177e4 | 34 | #include "xfs_ialloc_btree.h" |
1da177e4 | 35 | #include "xfs_dir2_sf.h" |
a844f451 | 36 | #include "xfs_attr_sf.h" |
1da177e4 | 37 | #include "xfs_dinode.h" |
1da177e4 | 38 | #include "xfs_inode.h" |
a844f451 NS |
39 | #include "xfs_inode_item.h" |
40 | #include "xfs_btree.h" | |
41 | #include "xfs_ialloc.h" | |
1da177e4 | 42 | #include "xfs_rw.h" |
db7a19f2 | 43 | #include "xfs_error.h" |
0b1b213f | 44 | #include "xfs_trace.h" |
1da177e4 LT |
45 | |
46 | ||
47 | kmem_zone_t *xfs_ili_zone; /* inode log item zone */ | |
48 | ||
49 | /* | |
50 | * This returns the number of iovecs needed to log the given inode item. | |
51 | * | |
52 | * We need one iovec for the inode log format structure, one for the | |
53 | * inode core, and possibly one for the inode data/extents/b-tree root | |
54 | * and one for the inode attribute data/extents/b-tree root. | |
55 | */ | |
56 | STATIC uint | |
57 | xfs_inode_item_size( | |
58 | xfs_inode_log_item_t *iip) | |
59 | { | |
60 | uint nvecs; | |
61 | xfs_inode_t *ip; | |
62 | ||
63 | ip = iip->ili_inode; | |
64 | nvecs = 2; | |
65 | ||
66 | /* | |
67 | * Only log the data/extents/b-tree root if there is something | |
68 | * left to log. | |
69 | */ | |
70 | iip->ili_format.ilf_fields |= XFS_ILOG_CORE; | |
71 | ||
72 | switch (ip->i_d.di_format) { | |
73 | case XFS_DINODE_FMT_EXTENTS: | |
74 | iip->ili_format.ilf_fields &= | |
75 | ~(XFS_ILOG_DDATA | XFS_ILOG_DBROOT | | |
76 | XFS_ILOG_DEV | XFS_ILOG_UUID); | |
77 | if ((iip->ili_format.ilf_fields & XFS_ILOG_DEXT) && | |
78 | (ip->i_d.di_nextents > 0) && | |
79 | (ip->i_df.if_bytes > 0)) { | |
80 | ASSERT(ip->i_df.if_u1.if_extents != NULL); | |
81 | nvecs++; | |
82 | } else { | |
83 | iip->ili_format.ilf_fields &= ~XFS_ILOG_DEXT; | |
84 | } | |
85 | break; | |
86 | ||
87 | case XFS_DINODE_FMT_BTREE: | |
88 | ASSERT(ip->i_df.if_ext_max == | |
89 | XFS_IFORK_DSIZE(ip) / (uint)sizeof(xfs_bmbt_rec_t)); | |
90 | iip->ili_format.ilf_fields &= | |
91 | ~(XFS_ILOG_DDATA | XFS_ILOG_DEXT | | |
92 | XFS_ILOG_DEV | XFS_ILOG_UUID); | |
93 | if ((iip->ili_format.ilf_fields & XFS_ILOG_DBROOT) && | |
94 | (ip->i_df.if_broot_bytes > 0)) { | |
95 | ASSERT(ip->i_df.if_broot != NULL); | |
96 | nvecs++; | |
97 | } else { | |
98 | ASSERT(!(iip->ili_format.ilf_fields & | |
99 | XFS_ILOG_DBROOT)); | |
100 | #ifdef XFS_TRANS_DEBUG | |
101 | if (iip->ili_root_size > 0) { | |
102 | ASSERT(iip->ili_root_size == | |
103 | ip->i_df.if_broot_bytes); | |
104 | ASSERT(memcmp(iip->ili_orig_root, | |
105 | ip->i_df.if_broot, | |
106 | iip->ili_root_size) == 0); | |
107 | } else { | |
108 | ASSERT(ip->i_df.if_broot_bytes == 0); | |
109 | } | |
110 | #endif | |
111 | iip->ili_format.ilf_fields &= ~XFS_ILOG_DBROOT; | |
112 | } | |
113 | break; | |
114 | ||
115 | case XFS_DINODE_FMT_LOCAL: | |
116 | iip->ili_format.ilf_fields &= | |
117 | ~(XFS_ILOG_DEXT | XFS_ILOG_DBROOT | | |
118 | XFS_ILOG_DEV | XFS_ILOG_UUID); | |
119 | if ((iip->ili_format.ilf_fields & XFS_ILOG_DDATA) && | |
120 | (ip->i_df.if_bytes > 0)) { | |
121 | ASSERT(ip->i_df.if_u1.if_data != NULL); | |
122 | ASSERT(ip->i_d.di_size > 0); | |
123 | nvecs++; | |
124 | } else { | |
125 | iip->ili_format.ilf_fields &= ~XFS_ILOG_DDATA; | |
126 | } | |
127 | break; | |
128 | ||
129 | case XFS_DINODE_FMT_DEV: | |
130 | iip->ili_format.ilf_fields &= | |
131 | ~(XFS_ILOG_DDATA | XFS_ILOG_DBROOT | | |
132 | XFS_ILOG_DEXT | XFS_ILOG_UUID); | |
133 | break; | |
134 | ||
135 | case XFS_DINODE_FMT_UUID: | |
136 | iip->ili_format.ilf_fields &= | |
137 | ~(XFS_ILOG_DDATA | XFS_ILOG_DBROOT | | |
138 | XFS_ILOG_DEXT | XFS_ILOG_DEV); | |
139 | break; | |
140 | ||
141 | default: | |
142 | ASSERT(0); | |
143 | break; | |
144 | } | |
145 | ||
146 | /* | |
147 | * If there are no attributes associated with this file, | |
148 | * then there cannot be anything more to log. | |
149 | * Clear all attribute-related log flags. | |
150 | */ | |
151 | if (!XFS_IFORK_Q(ip)) { | |
152 | iip->ili_format.ilf_fields &= | |
153 | ~(XFS_ILOG_ADATA | XFS_ILOG_ABROOT | XFS_ILOG_AEXT); | |
154 | return nvecs; | |
155 | } | |
156 | ||
157 | /* | |
158 | * Log any necessary attribute data. | |
159 | */ | |
160 | switch (ip->i_d.di_aformat) { | |
161 | case XFS_DINODE_FMT_EXTENTS: | |
162 | iip->ili_format.ilf_fields &= | |
163 | ~(XFS_ILOG_ADATA | XFS_ILOG_ABROOT); | |
164 | if ((iip->ili_format.ilf_fields & XFS_ILOG_AEXT) && | |
165 | (ip->i_d.di_anextents > 0) && | |
166 | (ip->i_afp->if_bytes > 0)) { | |
167 | ASSERT(ip->i_afp->if_u1.if_extents != NULL); | |
168 | nvecs++; | |
169 | } else { | |
170 | iip->ili_format.ilf_fields &= ~XFS_ILOG_AEXT; | |
171 | } | |
172 | break; | |
173 | ||
174 | case XFS_DINODE_FMT_BTREE: | |
175 | iip->ili_format.ilf_fields &= | |
176 | ~(XFS_ILOG_ADATA | XFS_ILOG_AEXT); | |
177 | if ((iip->ili_format.ilf_fields & XFS_ILOG_ABROOT) && | |
178 | (ip->i_afp->if_broot_bytes > 0)) { | |
179 | ASSERT(ip->i_afp->if_broot != NULL); | |
180 | nvecs++; | |
181 | } else { | |
182 | iip->ili_format.ilf_fields &= ~XFS_ILOG_ABROOT; | |
183 | } | |
184 | break; | |
185 | ||
186 | case XFS_DINODE_FMT_LOCAL: | |
187 | iip->ili_format.ilf_fields &= | |
188 | ~(XFS_ILOG_AEXT | XFS_ILOG_ABROOT); | |
189 | if ((iip->ili_format.ilf_fields & XFS_ILOG_ADATA) && | |
190 | (ip->i_afp->if_bytes > 0)) { | |
191 | ASSERT(ip->i_afp->if_u1.if_data != NULL); | |
192 | nvecs++; | |
193 | } else { | |
194 | iip->ili_format.ilf_fields &= ~XFS_ILOG_ADATA; | |
195 | } | |
196 | break; | |
197 | ||
198 | default: | |
199 | ASSERT(0); | |
200 | break; | |
201 | } | |
202 | ||
203 | return nvecs; | |
204 | } | |
205 | ||
206 | /* | |
207 | * This is called to fill in the vector of log iovecs for the | |
208 | * given inode log item. It fills the first item with an inode | |
209 | * log format structure, the second with the on-disk inode structure, | |
210 | * and a possible third and/or fourth with the inode data/extents/b-tree | |
211 | * root and inode attributes data/extents/b-tree root. | |
212 | */ | |
213 | STATIC void | |
214 | xfs_inode_item_format( | |
215 | xfs_inode_log_item_t *iip, | |
216 | xfs_log_iovec_t *log_vector) | |
217 | { | |
218 | uint nvecs; | |
219 | xfs_log_iovec_t *vecp; | |
220 | xfs_inode_t *ip; | |
221 | size_t data_bytes; | |
222 | xfs_bmbt_rec_t *ext_buffer; | |
223 | int nrecs; | |
224 | xfs_mount_t *mp; | |
225 | ||
226 | ip = iip->ili_inode; | |
227 | vecp = log_vector; | |
228 | ||
229 | vecp->i_addr = (xfs_caddr_t)&iip->ili_format; | |
230 | vecp->i_len = sizeof(xfs_inode_log_format_t); | |
4139b3b3 | 231 | vecp->i_type = XLOG_REG_TYPE_IFORMAT; |
1da177e4 LT |
232 | vecp++; |
233 | nvecs = 1; | |
234 | ||
f9581b14 CH |
235 | /* |
236 | * Make sure the linux inode is dirty. We do this before | |
237 | * clearing i_update_core as the VFS will call back into | |
238 | * XFS here and set i_update_core, so we need to dirty the | |
239 | * inode first so that the ordering of i_update_core and | |
240 | * unlogged modifications still works as described below. | |
241 | */ | |
242 | xfs_mark_inode_dirty_sync(ip); | |
243 | ||
1da177e4 LT |
244 | /* |
245 | * Clear i_update_core if the timestamps (or any other | |
246 | * non-transactional modification) need flushing/logging | |
247 | * and we're about to log them with the rest of the core. | |
248 | * | |
249 | * This is the same logic as xfs_iflush() but this code can't | |
250 | * run at the same time as xfs_iflush because we're in commit | |
251 | * processing here and so we have the inode lock held in | |
252 | * exclusive mode. Although it doesn't really matter | |
253 | * for the timestamps if both routines were to grab the | |
254 | * timestamps or not. That would be ok. | |
255 | * | |
256 | * We clear i_update_core before copying out the data. | |
257 | * This is for coordination with our timestamp updates | |
258 | * that don't hold the inode lock. They will always | |
259 | * update the timestamps BEFORE setting i_update_core, | |
260 | * so if we clear i_update_core after they set it we | |
261 | * are guaranteed to see their updates to the timestamps | |
262 | * either here. Likewise, if they set it after we clear it | |
263 | * here, we'll see it either on the next commit of this | |
264 | * inode or the next time the inode gets flushed via | |
265 | * xfs_iflush(). This depends on strongly ordered memory | |
266 | * semantics, but we have that. We use the SYNCHRONIZE | |
267 | * macro to make sure that the compiler does not reorder | |
268 | * the i_update_core access below the data copy below. | |
269 | */ | |
270 | if (ip->i_update_core) { | |
271 | ip->i_update_core = 0; | |
272 | SYNCHRONIZE(); | |
273 | } | |
274 | ||
42fe2b1f | 275 | /* |
f9581b14 | 276 | * Make sure to get the latest timestamps from the Linux inode. |
42fe2b1f | 277 | */ |
f9581b14 | 278 | xfs_synchronize_times(ip); |
5d51eff4 | 279 | |
1da177e4 | 280 | vecp->i_addr = (xfs_caddr_t)&ip->i_d; |
81591fe2 | 281 | vecp->i_len = sizeof(struct xfs_icdinode); |
4139b3b3 | 282 | vecp->i_type = XLOG_REG_TYPE_ICORE; |
1da177e4 LT |
283 | vecp++; |
284 | nvecs++; | |
285 | iip->ili_format.ilf_fields |= XFS_ILOG_CORE; | |
286 | ||
287 | /* | |
288 | * If this is really an old format inode, then we need to | |
289 | * log it as such. This means that we have to copy the link | |
290 | * count from the new field to the old. We don't have to worry | |
291 | * about the new fields, because nothing trusts them as long as | |
292 | * the old inode version number is there. If the superblock already | |
293 | * has a new version number, then we don't bother converting back. | |
294 | */ | |
295 | mp = ip->i_mount; | |
51ce16d5 CH |
296 | ASSERT(ip->i_d.di_version == 1 || xfs_sb_version_hasnlink(&mp->m_sb)); |
297 | if (ip->i_d.di_version == 1) { | |
62118709 | 298 | if (!xfs_sb_version_hasnlink(&mp->m_sb)) { |
1da177e4 LT |
299 | /* |
300 | * Convert it back. | |
301 | */ | |
302 | ASSERT(ip->i_d.di_nlink <= XFS_MAXLINK_1); | |
303 | ip->i_d.di_onlink = ip->i_d.di_nlink; | |
304 | } else { | |
305 | /* | |
306 | * The superblock version has already been bumped, | |
307 | * so just make the conversion to the new inode | |
308 | * format permanent. | |
309 | */ | |
51ce16d5 | 310 | ip->i_d.di_version = 2; |
1da177e4 LT |
311 | ip->i_d.di_onlink = 0; |
312 | memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad)); | |
313 | } | |
314 | } | |
315 | ||
316 | switch (ip->i_d.di_format) { | |
317 | case XFS_DINODE_FMT_EXTENTS: | |
318 | ASSERT(!(iip->ili_format.ilf_fields & | |
319 | (XFS_ILOG_DDATA | XFS_ILOG_DBROOT | | |
320 | XFS_ILOG_DEV | XFS_ILOG_UUID))); | |
321 | if (iip->ili_format.ilf_fields & XFS_ILOG_DEXT) { | |
322 | ASSERT(ip->i_df.if_bytes > 0); | |
323 | ASSERT(ip->i_df.if_u1.if_extents != NULL); | |
324 | ASSERT(ip->i_d.di_nextents > 0); | |
325 | ASSERT(iip->ili_extents_buf == NULL); | |
326 | nrecs = ip->i_df.if_bytes / | |
327 | (uint)sizeof(xfs_bmbt_rec_t); | |
328 | ASSERT(nrecs > 0); | |
f016bad6 | 329 | #ifdef XFS_NATIVE_HOST |
1da177e4 LT |
330 | if (nrecs == ip->i_d.di_nextents) { |
331 | /* | |
332 | * There are no delayed allocation | |
333 | * extents, so just point to the | |
334 | * real extents array. | |
335 | */ | |
336 | vecp->i_addr = | |
337 | (char *)(ip->i_df.if_u1.if_extents); | |
338 | vecp->i_len = ip->i_df.if_bytes; | |
4139b3b3 | 339 | vecp->i_type = XLOG_REG_TYPE_IEXT; |
1da177e4 LT |
340 | } else |
341 | #endif | |
342 | { | |
343 | /* | |
344 | * There are delayed allocation extents | |
345 | * in the inode, or we need to convert | |
346 | * the extents to on disk format. | |
347 | * Use xfs_iextents_copy() | |
348 | * to copy only the real extents into | |
349 | * a separate buffer. We'll free the | |
350 | * buffer in the unlock routine. | |
351 | */ | |
352 | ext_buffer = kmem_alloc(ip->i_df.if_bytes, | |
353 | KM_SLEEP); | |
354 | iip->ili_extents_buf = ext_buffer; | |
355 | vecp->i_addr = (xfs_caddr_t)ext_buffer; | |
356 | vecp->i_len = xfs_iextents_copy(ip, ext_buffer, | |
357 | XFS_DATA_FORK); | |
4139b3b3 | 358 | vecp->i_type = XLOG_REG_TYPE_IEXT; |
1da177e4 LT |
359 | } |
360 | ASSERT(vecp->i_len <= ip->i_df.if_bytes); | |
361 | iip->ili_format.ilf_dsize = vecp->i_len; | |
362 | vecp++; | |
363 | nvecs++; | |
364 | } | |
365 | break; | |
366 | ||
367 | case XFS_DINODE_FMT_BTREE: | |
368 | ASSERT(!(iip->ili_format.ilf_fields & | |
369 | (XFS_ILOG_DDATA | XFS_ILOG_DEXT | | |
370 | XFS_ILOG_DEV | XFS_ILOG_UUID))); | |
371 | if (iip->ili_format.ilf_fields & XFS_ILOG_DBROOT) { | |
372 | ASSERT(ip->i_df.if_broot_bytes > 0); | |
373 | ASSERT(ip->i_df.if_broot != NULL); | |
374 | vecp->i_addr = (xfs_caddr_t)ip->i_df.if_broot; | |
375 | vecp->i_len = ip->i_df.if_broot_bytes; | |
4139b3b3 | 376 | vecp->i_type = XLOG_REG_TYPE_IBROOT; |
1da177e4 LT |
377 | vecp++; |
378 | nvecs++; | |
379 | iip->ili_format.ilf_dsize = ip->i_df.if_broot_bytes; | |
380 | } | |
381 | break; | |
382 | ||
383 | case XFS_DINODE_FMT_LOCAL: | |
384 | ASSERT(!(iip->ili_format.ilf_fields & | |
385 | (XFS_ILOG_DBROOT | XFS_ILOG_DEXT | | |
386 | XFS_ILOG_DEV | XFS_ILOG_UUID))); | |
387 | if (iip->ili_format.ilf_fields & XFS_ILOG_DDATA) { | |
388 | ASSERT(ip->i_df.if_bytes > 0); | |
389 | ASSERT(ip->i_df.if_u1.if_data != NULL); | |
390 | ASSERT(ip->i_d.di_size > 0); | |
391 | ||
392 | vecp->i_addr = (xfs_caddr_t)ip->i_df.if_u1.if_data; | |
393 | /* | |
394 | * Round i_bytes up to a word boundary. | |
395 | * The underlying memory is guaranteed to | |
396 | * to be there by xfs_idata_realloc(). | |
397 | */ | |
398 | data_bytes = roundup(ip->i_df.if_bytes, 4); | |
399 | ASSERT((ip->i_df.if_real_bytes == 0) || | |
400 | (ip->i_df.if_real_bytes == data_bytes)); | |
401 | vecp->i_len = (int)data_bytes; | |
4139b3b3 | 402 | vecp->i_type = XLOG_REG_TYPE_ILOCAL; |
1da177e4 LT |
403 | vecp++; |
404 | nvecs++; | |
405 | iip->ili_format.ilf_dsize = (unsigned)data_bytes; | |
406 | } | |
407 | break; | |
408 | ||
409 | case XFS_DINODE_FMT_DEV: | |
410 | ASSERT(!(iip->ili_format.ilf_fields & | |
411 | (XFS_ILOG_DBROOT | XFS_ILOG_DEXT | | |
412 | XFS_ILOG_DDATA | XFS_ILOG_UUID))); | |
413 | if (iip->ili_format.ilf_fields & XFS_ILOG_DEV) { | |
414 | iip->ili_format.ilf_u.ilfu_rdev = | |
415 | ip->i_df.if_u2.if_rdev; | |
416 | } | |
417 | break; | |
418 | ||
419 | case XFS_DINODE_FMT_UUID: | |
420 | ASSERT(!(iip->ili_format.ilf_fields & | |
421 | (XFS_ILOG_DBROOT | XFS_ILOG_DEXT | | |
422 | XFS_ILOG_DDATA | XFS_ILOG_DEV))); | |
423 | if (iip->ili_format.ilf_fields & XFS_ILOG_UUID) { | |
424 | iip->ili_format.ilf_u.ilfu_uuid = | |
425 | ip->i_df.if_u2.if_uuid; | |
426 | } | |
427 | break; | |
428 | ||
429 | default: | |
430 | ASSERT(0); | |
431 | break; | |
432 | } | |
433 | ||
434 | /* | |
435 | * If there are no attributes associated with the file, | |
436 | * then we're done. | |
437 | * Assert that no attribute-related log flags are set. | |
438 | */ | |
439 | if (!XFS_IFORK_Q(ip)) { | |
440 | ASSERT(nvecs == iip->ili_item.li_desc->lid_size); | |
441 | iip->ili_format.ilf_size = nvecs; | |
442 | ASSERT(!(iip->ili_format.ilf_fields & | |
443 | (XFS_ILOG_ADATA | XFS_ILOG_ABROOT | XFS_ILOG_AEXT))); | |
444 | return; | |
445 | } | |
446 | ||
447 | switch (ip->i_d.di_aformat) { | |
448 | case XFS_DINODE_FMT_EXTENTS: | |
449 | ASSERT(!(iip->ili_format.ilf_fields & | |
450 | (XFS_ILOG_ADATA | XFS_ILOG_ABROOT))); | |
451 | if (iip->ili_format.ilf_fields & XFS_ILOG_AEXT) { | |
452 | ASSERT(ip->i_afp->if_bytes > 0); | |
453 | ASSERT(ip->i_afp->if_u1.if_extents != NULL); | |
454 | ASSERT(ip->i_d.di_anextents > 0); | |
455 | #ifdef DEBUG | |
456 | nrecs = ip->i_afp->if_bytes / | |
457 | (uint)sizeof(xfs_bmbt_rec_t); | |
458 | #endif | |
459 | ASSERT(nrecs > 0); | |
460 | ASSERT(nrecs == ip->i_d.di_anextents); | |
f016bad6 | 461 | #ifdef XFS_NATIVE_HOST |
1da177e4 LT |
462 | /* |
463 | * There are not delayed allocation extents | |
464 | * for attributes, so just point at the array. | |
465 | */ | |
466 | vecp->i_addr = (char *)(ip->i_afp->if_u1.if_extents); | |
467 | vecp->i_len = ip->i_afp->if_bytes; | |
468 | #else | |
469 | ASSERT(iip->ili_aextents_buf == NULL); | |
470 | /* | |
471 | * Need to endian flip before logging | |
472 | */ | |
473 | ext_buffer = kmem_alloc(ip->i_afp->if_bytes, | |
474 | KM_SLEEP); | |
475 | iip->ili_aextents_buf = ext_buffer; | |
476 | vecp->i_addr = (xfs_caddr_t)ext_buffer; | |
477 | vecp->i_len = xfs_iextents_copy(ip, ext_buffer, | |
478 | XFS_ATTR_FORK); | |
479 | #endif | |
4139b3b3 | 480 | vecp->i_type = XLOG_REG_TYPE_IATTR_EXT; |
1da177e4 LT |
481 | iip->ili_format.ilf_asize = vecp->i_len; |
482 | vecp++; | |
483 | nvecs++; | |
484 | } | |
485 | break; | |
486 | ||
487 | case XFS_DINODE_FMT_BTREE: | |
488 | ASSERT(!(iip->ili_format.ilf_fields & | |
489 | (XFS_ILOG_ADATA | XFS_ILOG_AEXT))); | |
490 | if (iip->ili_format.ilf_fields & XFS_ILOG_ABROOT) { | |
491 | ASSERT(ip->i_afp->if_broot_bytes > 0); | |
492 | ASSERT(ip->i_afp->if_broot != NULL); | |
493 | vecp->i_addr = (xfs_caddr_t)ip->i_afp->if_broot; | |
494 | vecp->i_len = ip->i_afp->if_broot_bytes; | |
4139b3b3 | 495 | vecp->i_type = XLOG_REG_TYPE_IATTR_BROOT; |
1da177e4 LT |
496 | vecp++; |
497 | nvecs++; | |
498 | iip->ili_format.ilf_asize = ip->i_afp->if_broot_bytes; | |
499 | } | |
500 | break; | |
501 | ||
502 | case XFS_DINODE_FMT_LOCAL: | |
503 | ASSERT(!(iip->ili_format.ilf_fields & | |
504 | (XFS_ILOG_ABROOT | XFS_ILOG_AEXT))); | |
505 | if (iip->ili_format.ilf_fields & XFS_ILOG_ADATA) { | |
506 | ASSERT(ip->i_afp->if_bytes > 0); | |
507 | ASSERT(ip->i_afp->if_u1.if_data != NULL); | |
508 | ||
509 | vecp->i_addr = (xfs_caddr_t)ip->i_afp->if_u1.if_data; | |
510 | /* | |
511 | * Round i_bytes up to a word boundary. | |
512 | * The underlying memory is guaranteed to | |
513 | * to be there by xfs_idata_realloc(). | |
514 | */ | |
515 | data_bytes = roundup(ip->i_afp->if_bytes, 4); | |
516 | ASSERT((ip->i_afp->if_real_bytes == 0) || | |
517 | (ip->i_afp->if_real_bytes == data_bytes)); | |
518 | vecp->i_len = (int)data_bytes; | |
4139b3b3 | 519 | vecp->i_type = XLOG_REG_TYPE_IATTR_LOCAL; |
1da177e4 LT |
520 | vecp++; |
521 | nvecs++; | |
522 | iip->ili_format.ilf_asize = (unsigned)data_bytes; | |
523 | } | |
524 | break; | |
525 | ||
526 | default: | |
527 | ASSERT(0); | |
528 | break; | |
529 | } | |
530 | ||
531 | ASSERT(nvecs == iip->ili_item.li_desc->lid_size); | |
532 | iip->ili_format.ilf_size = nvecs; | |
533 | } | |
534 | ||
535 | ||
536 | /* | |
537 | * This is called to pin the inode associated with the inode log | |
538 | * item in memory so it cannot be written out. Do this by calling | |
539 | * xfs_ipin() to bump the pin count in the inode while holding the | |
540 | * inode pin lock. | |
541 | */ | |
542 | STATIC void | |
543 | xfs_inode_item_pin( | |
544 | xfs_inode_log_item_t *iip) | |
545 | { | |
579aa9ca | 546 | ASSERT(xfs_isilocked(iip->ili_inode, XFS_ILOCK_EXCL)); |
1da177e4 LT |
547 | xfs_ipin(iip->ili_inode); |
548 | } | |
549 | ||
550 | ||
551 | /* | |
552 | * This is called to unpin the inode associated with the inode log | |
553 | * item which was previously pinned with a call to xfs_inode_item_pin(). | |
554 | * Just call xfs_iunpin() on the inode to do this. | |
555 | */ | |
556 | /* ARGSUSED */ | |
557 | STATIC void | |
558 | xfs_inode_item_unpin( | |
559 | xfs_inode_log_item_t *iip, | |
560 | int stale) | |
561 | { | |
562 | xfs_iunpin(iip->ili_inode); | |
563 | } | |
564 | ||
565 | /* ARGSUSED */ | |
566 | STATIC void | |
567 | xfs_inode_item_unpin_remove( | |
568 | xfs_inode_log_item_t *iip, | |
569 | xfs_trans_t *tp) | |
570 | { | |
571 | xfs_iunpin(iip->ili_inode); | |
572 | } | |
573 | ||
574 | /* | |
575 | * This is called to attempt to lock the inode associated with this | |
576 | * inode log item, in preparation for the push routine which does the actual | |
577 | * iflush. Don't sleep on the inode lock or the flush lock. | |
578 | * | |
579 | * If the flush lock is already held, indicating that the inode has | |
580 | * been or is in the process of being flushed, then (ideally) we'd like to | |
581 | * see if the inode's buffer is still incore, and if so give it a nudge. | |
582 | * We delay doing so until the pushbuf routine, though, to avoid holding | |
c41564b5 | 583 | * the AIL lock across a call to the blackhole which is the buffer cache. |
1da177e4 LT |
584 | * Also we don't want to sleep in any device strategy routines, which can happen |
585 | * if we do the subsequent bawrite in here. | |
586 | */ | |
587 | STATIC uint | |
588 | xfs_inode_item_trylock( | |
589 | xfs_inode_log_item_t *iip) | |
590 | { | |
591 | register xfs_inode_t *ip; | |
592 | ||
593 | ip = iip->ili_inode; | |
594 | ||
595 | if (xfs_ipincount(ip) > 0) { | |
596 | return XFS_ITEM_PINNED; | |
597 | } | |
598 | ||
599 | if (!xfs_ilock_nowait(ip, XFS_ILOCK_SHARED)) { | |
600 | return XFS_ITEM_LOCKED; | |
601 | } | |
602 | ||
603 | if (!xfs_iflock_nowait(ip)) { | |
604 | /* | |
605 | * If someone else isn't already trying to push the inode | |
606 | * buffer, we get to do it. | |
607 | */ | |
608 | if (iip->ili_pushbuf_flag == 0) { | |
609 | iip->ili_pushbuf_flag = 1; | |
610 | #ifdef DEBUG | |
3762ec6b | 611 | iip->ili_push_owner = current_pid(); |
1da177e4 LT |
612 | #endif |
613 | /* | |
614 | * Inode is left locked in shared mode. | |
615 | * Pushbuf routine gets to unlock it. | |
616 | */ | |
617 | return XFS_ITEM_PUSHBUF; | |
618 | } else { | |
619 | /* | |
287f3dad | 620 | * We hold the AIL lock, so we must specify the |
1da177e4 LT |
621 | * NONOTIFY flag so that we won't double trip. |
622 | */ | |
623 | xfs_iunlock(ip, XFS_ILOCK_SHARED|XFS_IUNLOCK_NONOTIFY); | |
624 | return XFS_ITEM_FLUSHING; | |
625 | } | |
626 | /* NOTREACHED */ | |
627 | } | |
628 | ||
629 | /* Stale items should force out the iclog */ | |
630 | if (ip->i_flags & XFS_ISTALE) { | |
631 | xfs_ifunlock(ip); | |
632 | xfs_iunlock(ip, XFS_ILOCK_SHARED|XFS_IUNLOCK_NONOTIFY); | |
633 | return XFS_ITEM_PINNED; | |
634 | } | |
635 | ||
636 | #ifdef DEBUG | |
637 | if (!XFS_FORCED_SHUTDOWN(ip->i_mount)) { | |
638 | ASSERT(iip->ili_format.ilf_fields != 0); | |
639 | ASSERT(iip->ili_logged == 0); | |
640 | ASSERT(iip->ili_item.li_flags & XFS_LI_IN_AIL); | |
641 | } | |
642 | #endif | |
643 | return XFS_ITEM_SUCCESS; | |
644 | } | |
645 | ||
646 | /* | |
647 | * Unlock the inode associated with the inode log item. | |
648 | * Clear the fields of the inode and inode log item that | |
649 | * are specific to the current transaction. If the | |
650 | * hold flags is set, do not unlock the inode. | |
651 | */ | |
652 | STATIC void | |
653 | xfs_inode_item_unlock( | |
654 | xfs_inode_log_item_t *iip) | |
655 | { | |
656 | uint hold; | |
657 | uint iolocked; | |
658 | uint lock_flags; | |
659 | xfs_inode_t *ip; | |
660 | ||
661 | ASSERT(iip != NULL); | |
662 | ASSERT(iip->ili_inode->i_itemp != NULL); | |
579aa9ca | 663 | ASSERT(xfs_isilocked(iip->ili_inode, XFS_ILOCK_EXCL)); |
1da177e4 LT |
664 | ASSERT((!(iip->ili_inode->i_itemp->ili_flags & |
665 | XFS_ILI_IOLOCKED_EXCL)) || | |
579aa9ca | 666 | xfs_isilocked(iip->ili_inode, XFS_IOLOCK_EXCL)); |
1da177e4 LT |
667 | ASSERT((!(iip->ili_inode->i_itemp->ili_flags & |
668 | XFS_ILI_IOLOCKED_SHARED)) || | |
579aa9ca | 669 | xfs_isilocked(iip->ili_inode, XFS_IOLOCK_SHARED)); |
1da177e4 LT |
670 | /* |
671 | * Clear the transaction pointer in the inode. | |
672 | */ | |
673 | ip = iip->ili_inode; | |
674 | ip->i_transp = NULL; | |
675 | ||
676 | /* | |
677 | * If the inode needed a separate buffer with which to log | |
678 | * its extents, then free it now. | |
679 | */ | |
680 | if (iip->ili_extents_buf != NULL) { | |
681 | ASSERT(ip->i_d.di_format == XFS_DINODE_FMT_EXTENTS); | |
682 | ASSERT(ip->i_d.di_nextents > 0); | |
683 | ASSERT(iip->ili_format.ilf_fields & XFS_ILOG_DEXT); | |
684 | ASSERT(ip->i_df.if_bytes > 0); | |
f0e2d93c | 685 | kmem_free(iip->ili_extents_buf); |
1da177e4 LT |
686 | iip->ili_extents_buf = NULL; |
687 | } | |
688 | if (iip->ili_aextents_buf != NULL) { | |
689 | ASSERT(ip->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS); | |
690 | ASSERT(ip->i_d.di_anextents > 0); | |
691 | ASSERT(iip->ili_format.ilf_fields & XFS_ILOG_AEXT); | |
692 | ASSERT(ip->i_afp->if_bytes > 0); | |
f0e2d93c | 693 | kmem_free(iip->ili_aextents_buf); |
1da177e4 LT |
694 | iip->ili_aextents_buf = NULL; |
695 | } | |
696 | ||
697 | /* | |
698 | * Figure out if we should unlock the inode or not. | |
699 | */ | |
700 | hold = iip->ili_flags & XFS_ILI_HOLD; | |
701 | ||
702 | /* | |
703 | * Before clearing out the flags, remember whether we | |
704 | * are holding the inode's IO lock. | |
705 | */ | |
706 | iolocked = iip->ili_flags & XFS_ILI_IOLOCKED_ANY; | |
707 | ||
708 | /* | |
709 | * Clear out the fields of the inode log item particular | |
710 | * to the current transaction. | |
711 | */ | |
1da177e4 LT |
712 | iip->ili_flags = 0; |
713 | ||
714 | /* | |
715 | * Unlock the inode if XFS_ILI_HOLD was not set. | |
716 | */ | |
717 | if (!hold) { | |
718 | lock_flags = XFS_ILOCK_EXCL; | |
719 | if (iolocked & XFS_ILI_IOLOCKED_EXCL) { | |
720 | lock_flags |= XFS_IOLOCK_EXCL; | |
721 | } else if (iolocked & XFS_ILI_IOLOCKED_SHARED) { | |
722 | lock_flags |= XFS_IOLOCK_SHARED; | |
723 | } | |
724 | xfs_iput(iip->ili_inode, lock_flags); | |
725 | } | |
726 | } | |
727 | ||
728 | /* | |
729 | * This is called to find out where the oldest active copy of the | |
730 | * inode log item in the on disk log resides now that the last log | |
731 | * write of it completed at the given lsn. Since we always re-log | |
732 | * all dirty data in an inode, the latest copy in the on disk log | |
733 | * is the only one that matters. Therefore, simply return the | |
734 | * given lsn. | |
735 | */ | |
736 | /*ARGSUSED*/ | |
737 | STATIC xfs_lsn_t | |
738 | xfs_inode_item_committed( | |
739 | xfs_inode_log_item_t *iip, | |
740 | xfs_lsn_t lsn) | |
741 | { | |
742 | return (lsn); | |
743 | } | |
744 | ||
1da177e4 LT |
745 | /* |
746 | * This gets called by xfs_trans_push_ail(), when IOP_TRYLOCK | |
747 | * failed to get the inode flush lock but did get the inode locked SHARED. | |
748 | * Here we're trying to see if the inode buffer is incore, and if so whether it's | |
749 | * marked delayed write. If that's the case, we'll initiate a bawrite on that | |
750 | * buffer to expedite the process. | |
751 | * | |
287f3dad | 752 | * We aren't holding the AIL lock (or the flush lock) when this gets called, |
1da177e4 LT |
753 | * so it is inherently race-y. |
754 | */ | |
755 | STATIC void | |
756 | xfs_inode_item_pushbuf( | |
757 | xfs_inode_log_item_t *iip) | |
758 | { | |
759 | xfs_inode_t *ip; | |
760 | xfs_mount_t *mp; | |
761 | xfs_buf_t *bp; | |
762 | uint dopush; | |
763 | ||
764 | ip = iip->ili_inode; | |
765 | ||
579aa9ca | 766 | ASSERT(xfs_isilocked(ip, XFS_ILOCK_SHARED)); |
1da177e4 LT |
767 | |
768 | /* | |
769 | * The ili_pushbuf_flag keeps others from | |
770 | * trying to duplicate our effort. | |
771 | */ | |
772 | ASSERT(iip->ili_pushbuf_flag != 0); | |
3762ec6b | 773 | ASSERT(iip->ili_push_owner == current_pid()); |
1da177e4 LT |
774 | |
775 | /* | |
c63942d3 DC |
776 | * If a flush is not in progress anymore, chances are that the |
777 | * inode was taken off the AIL. So, just get out. | |
1da177e4 | 778 | */ |
c63942d3 | 779 | if (completion_done(&ip->i_flush) || |
1da177e4 LT |
780 | ((iip->ili_item.li_flags & XFS_LI_IN_AIL) == 0)) { |
781 | iip->ili_pushbuf_flag = 0; | |
782 | xfs_iunlock(ip, XFS_ILOCK_SHARED); | |
783 | return; | |
784 | } | |
785 | ||
786 | mp = ip->i_mount; | |
787 | bp = xfs_incore(mp->m_ddev_targp, iip->ili_format.ilf_blkno, | |
0cadda1c | 788 | iip->ili_format.ilf_len, XBF_TRYLOCK); |
1da177e4 LT |
789 | |
790 | if (bp != NULL) { | |
791 | if (XFS_BUF_ISDELAYWRITE(bp)) { | |
792 | /* | |
793 | * We were racing with iflush because we don't hold | |
287f3dad | 794 | * the AIL lock or the flush lock. However, at this point, |
1da177e4 LT |
795 | * we have the buffer, and we know that it's dirty. |
796 | * So, it's possible that iflush raced with us, and | |
797 | * this item is already taken off the AIL. | |
798 | * If not, we can flush it async. | |
799 | */ | |
800 | dopush = ((iip->ili_item.li_flags & XFS_LI_IN_AIL) && | |
c63942d3 | 801 | !completion_done(&ip->i_flush)); |
1da177e4 LT |
802 | iip->ili_pushbuf_flag = 0; |
803 | xfs_iunlock(ip, XFS_ILOCK_SHARED); | |
0b1b213f CH |
804 | |
805 | trace_xfs_inode_item_push(bp, _RET_IP_); | |
806 | ||
a14a348b CH |
807 | if (XFS_BUF_ISPINNED(bp)) |
808 | xfs_log_force(mp, 0); | |
809 | ||
1da177e4 | 810 | if (dopush) { |
db7a19f2 DC |
811 | int error; |
812 | error = xfs_bawrite(mp, bp); | |
813 | if (error) | |
814 | xfs_fs_cmn_err(CE_WARN, mp, | |
815 | "xfs_inode_item_pushbuf: pushbuf error %d on iip %p, bp %p", | |
816 | error, iip, bp); | |
1da177e4 LT |
817 | } else { |
818 | xfs_buf_relse(bp); | |
819 | } | |
820 | } else { | |
821 | iip->ili_pushbuf_flag = 0; | |
822 | xfs_iunlock(ip, XFS_ILOCK_SHARED); | |
823 | xfs_buf_relse(bp); | |
824 | } | |
825 | return; | |
826 | } | |
827 | /* | |
828 | * We have to be careful about resetting pushbuf flag too early (above). | |
829 | * Even though in theory we can do it as soon as we have the buflock, | |
830 | * we don't want others to be doing work needlessly. They'll come to | |
831 | * this function thinking that pushing the buffer is their | |
832 | * responsibility only to find that the buffer is still locked by | |
833 | * another doing the same thing | |
834 | */ | |
835 | iip->ili_pushbuf_flag = 0; | |
836 | xfs_iunlock(ip, XFS_ILOCK_SHARED); | |
837 | return; | |
838 | } | |
839 | ||
840 | ||
841 | /* | |
842 | * This is called to asynchronously write the inode associated with this | |
843 | * inode log item out to disk. The inode will already have been locked by | |
844 | * a successful call to xfs_inode_item_trylock(). | |
845 | */ | |
846 | STATIC void | |
847 | xfs_inode_item_push( | |
848 | xfs_inode_log_item_t *iip) | |
849 | { | |
850 | xfs_inode_t *ip; | |
851 | ||
852 | ip = iip->ili_inode; | |
853 | ||
579aa9ca | 854 | ASSERT(xfs_isilocked(ip, XFS_ILOCK_SHARED)); |
c63942d3 | 855 | ASSERT(!completion_done(&ip->i_flush)); |
1da177e4 LT |
856 | /* |
857 | * Since we were able to lock the inode's flush lock and | |
858 | * we found it on the AIL, the inode must be dirty. This | |
859 | * is because the inode is removed from the AIL while still | |
860 | * holding the flush lock in xfs_iflush_done(). Thus, if | |
861 | * we found it in the AIL and were able to obtain the flush | |
862 | * lock without sleeping, then there must not have been | |
863 | * anyone in the process of flushing the inode. | |
864 | */ | |
865 | ASSERT(XFS_FORCED_SHUTDOWN(ip->i_mount) || | |
866 | iip->ili_format.ilf_fields != 0); | |
867 | ||
868 | /* | |
869 | * Write out the inode. The completion routine ('iflush_done') will | |
870 | * pull it from the AIL, mark it clean, unlock the flush lock. | |
871 | */ | |
872 | (void) xfs_iflush(ip, XFS_IFLUSH_ASYNC); | |
873 | xfs_iunlock(ip, XFS_ILOCK_SHARED); | |
874 | ||
875 | return; | |
876 | } | |
877 | ||
878 | /* | |
879 | * XXX rcc - this one really has to do something. Probably needs | |
880 | * to stamp in a new field in the incore inode. | |
881 | */ | |
882 | /* ARGSUSED */ | |
883 | STATIC void | |
884 | xfs_inode_item_committing( | |
885 | xfs_inode_log_item_t *iip, | |
886 | xfs_lsn_t lsn) | |
887 | { | |
888 | iip->ili_last_lsn = lsn; | |
889 | return; | |
890 | } | |
891 | ||
892 | /* | |
893 | * This is the ops vector shared by all buf log items. | |
894 | */ | |
7989cb8e | 895 | static struct xfs_item_ops xfs_inode_item_ops = { |
1da177e4 LT |
896 | .iop_size = (uint(*)(xfs_log_item_t*))xfs_inode_item_size, |
897 | .iop_format = (void(*)(xfs_log_item_t*, xfs_log_iovec_t*)) | |
898 | xfs_inode_item_format, | |
899 | .iop_pin = (void(*)(xfs_log_item_t*))xfs_inode_item_pin, | |
900 | .iop_unpin = (void(*)(xfs_log_item_t*, int))xfs_inode_item_unpin, | |
901 | .iop_unpin_remove = (void(*)(xfs_log_item_t*, xfs_trans_t*)) | |
902 | xfs_inode_item_unpin_remove, | |
903 | .iop_trylock = (uint(*)(xfs_log_item_t*))xfs_inode_item_trylock, | |
904 | .iop_unlock = (void(*)(xfs_log_item_t*))xfs_inode_item_unlock, | |
905 | .iop_committed = (xfs_lsn_t(*)(xfs_log_item_t*, xfs_lsn_t)) | |
906 | xfs_inode_item_committed, | |
907 | .iop_push = (void(*)(xfs_log_item_t*))xfs_inode_item_push, | |
1da177e4 LT |
908 | .iop_pushbuf = (void(*)(xfs_log_item_t*))xfs_inode_item_pushbuf, |
909 | .iop_committing = (void(*)(xfs_log_item_t*, xfs_lsn_t)) | |
910 | xfs_inode_item_committing | |
911 | }; | |
912 | ||
913 | ||
914 | /* | |
915 | * Initialize the inode log item for a newly allocated (in-core) inode. | |
916 | */ | |
917 | void | |
918 | xfs_inode_item_init( | |
919 | xfs_inode_t *ip, | |
920 | xfs_mount_t *mp) | |
921 | { | |
922 | xfs_inode_log_item_t *iip; | |
923 | ||
924 | ASSERT(ip->i_itemp == NULL); | |
925 | iip = ip->i_itemp = kmem_zone_zalloc(xfs_ili_zone, KM_SLEEP); | |
926 | ||
927 | iip->ili_item.li_type = XFS_LI_INODE; | |
928 | iip->ili_item.li_ops = &xfs_inode_item_ops; | |
929 | iip->ili_item.li_mountp = mp; | |
fc1829f3 | 930 | iip->ili_item.li_ailp = mp->m_ail; |
1da177e4 LT |
931 | iip->ili_inode = ip; |
932 | ||
933 | /* | |
934 | We have zeroed memory. No need ... | |
935 | iip->ili_extents_buf = NULL; | |
936 | iip->ili_pushbuf_flag = 0; | |
937 | */ | |
938 | ||
939 | iip->ili_format.ilf_type = XFS_LI_INODE; | |
940 | iip->ili_format.ilf_ino = ip->i_ino; | |
92bfc6e7 CH |
941 | iip->ili_format.ilf_blkno = ip->i_imap.im_blkno; |
942 | iip->ili_format.ilf_len = ip->i_imap.im_len; | |
943 | iip->ili_format.ilf_boffset = ip->i_imap.im_boffset; | |
1da177e4 LT |
944 | } |
945 | ||
946 | /* | |
947 | * Free the inode log item and any memory hanging off of it. | |
948 | */ | |
949 | void | |
950 | xfs_inode_item_destroy( | |
951 | xfs_inode_t *ip) | |
952 | { | |
953 | #ifdef XFS_TRANS_DEBUG | |
954 | if (ip->i_itemp->ili_root_size != 0) { | |
f0e2d93c | 955 | kmem_free(ip->i_itemp->ili_orig_root); |
1da177e4 LT |
956 | } |
957 | #endif | |
958 | kmem_zone_free(xfs_ili_zone, ip->i_itemp); | |
959 | } | |
960 | ||
961 | ||
962 | /* | |
963 | * This is the inode flushing I/O completion routine. It is called | |
964 | * from interrupt level when the buffer containing the inode is | |
965 | * flushed to disk. It is responsible for removing the inode item | |
966 | * from the AIL if it has not been re-logged, and unlocking the inode's | |
967 | * flush lock. | |
968 | */ | |
969 | /*ARGSUSED*/ | |
970 | void | |
971 | xfs_iflush_done( | |
972 | xfs_buf_t *bp, | |
973 | xfs_inode_log_item_t *iip) | |
974 | { | |
783a2f65 DC |
975 | xfs_inode_t *ip = iip->ili_inode; |
976 | struct xfs_ail *ailp = iip->ili_item.li_ailp; | |
1da177e4 LT |
977 | |
978 | /* | |
979 | * We only want to pull the item from the AIL if it is | |
980 | * actually there and its location in the log has not | |
981 | * changed since we started the flush. Thus, we only bother | |
982 | * if the ili_logged flag is set and the inode's lsn has not | |
983 | * changed. First we check the lsn outside | |
984 | * the lock since it's cheaper, and then we recheck while | |
985 | * holding the lock before removing the inode from the AIL. | |
986 | */ | |
987 | if (iip->ili_logged && | |
988 | (iip->ili_item.li_lsn == iip->ili_flush_lsn)) { | |
783a2f65 | 989 | spin_lock(&ailp->xa_lock); |
1da177e4 | 990 | if (iip->ili_item.li_lsn == iip->ili_flush_lsn) { |
783a2f65 DC |
991 | /* xfs_trans_ail_delete() drops the AIL lock. */ |
992 | xfs_trans_ail_delete(ailp, (xfs_log_item_t*)iip); | |
1da177e4 | 993 | } else { |
783a2f65 | 994 | spin_unlock(&ailp->xa_lock); |
1da177e4 LT |
995 | } |
996 | } | |
997 | ||
998 | iip->ili_logged = 0; | |
999 | ||
1000 | /* | |
1001 | * Clear the ili_last_fields bits now that we know that the | |
1002 | * data corresponding to them is safely on disk. | |
1003 | */ | |
1004 | iip->ili_last_fields = 0; | |
1005 | ||
1006 | /* | |
1007 | * Release the inode's flush lock since we're done with it. | |
1008 | */ | |
1009 | xfs_ifunlock(ip); | |
1010 | ||
1011 | return; | |
1012 | } | |
1013 | ||
1014 | /* | |
1015 | * This is the inode flushing abort routine. It is called | |
1016 | * from xfs_iflush when the filesystem is shutting down to clean | |
1017 | * up the inode state. | |
1018 | * It is responsible for removing the inode item | |
1019 | * from the AIL if it has not been re-logged, and unlocking the inode's | |
1020 | * flush lock. | |
1021 | */ | |
1022 | void | |
1023 | xfs_iflush_abort( | |
1024 | xfs_inode_t *ip) | |
1025 | { | |
783a2f65 | 1026 | xfs_inode_log_item_t *iip = ip->i_itemp; |
1da177e4 | 1027 | xfs_mount_t *mp; |
1da177e4 LT |
1028 | |
1029 | iip = ip->i_itemp; | |
1030 | mp = ip->i_mount; | |
1031 | if (iip) { | |
783a2f65 | 1032 | struct xfs_ail *ailp = iip->ili_item.li_ailp; |
1da177e4 | 1033 | if (iip->ili_item.li_flags & XFS_LI_IN_AIL) { |
783a2f65 | 1034 | spin_lock(&ailp->xa_lock); |
1da177e4 | 1035 | if (iip->ili_item.li_flags & XFS_LI_IN_AIL) { |
783a2f65 DC |
1036 | /* xfs_trans_ail_delete() drops the AIL lock. */ |
1037 | xfs_trans_ail_delete(ailp, (xfs_log_item_t *)iip); | |
1da177e4 | 1038 | } else |
783a2f65 | 1039 | spin_unlock(&ailp->xa_lock); |
1da177e4 LT |
1040 | } |
1041 | iip->ili_logged = 0; | |
1042 | /* | |
1043 | * Clear the ili_last_fields bits now that we know that the | |
1044 | * data corresponding to them is safely on disk. | |
1045 | */ | |
1046 | iip->ili_last_fields = 0; | |
1047 | /* | |
1048 | * Clear the inode logging fields so no more flushes are | |
1049 | * attempted. | |
1050 | */ | |
1051 | iip->ili_format.ilf_fields = 0; | |
1052 | } | |
1053 | /* | |
1054 | * Release the inode's flush lock since we're done with it. | |
1055 | */ | |
1056 | xfs_ifunlock(ip); | |
1057 | } | |
1058 | ||
1059 | void | |
1060 | xfs_istale_done( | |
1061 | xfs_buf_t *bp, | |
1062 | xfs_inode_log_item_t *iip) | |
1063 | { | |
1064 | xfs_iflush_abort(iip->ili_inode); | |
1065 | } | |
6d192a9b TS |
1066 | |
1067 | /* | |
1068 | * convert an xfs_inode_log_format struct from either 32 or 64 bit versions | |
1069 | * (which can have different field alignments) to the native version | |
1070 | */ | |
1071 | int | |
1072 | xfs_inode_item_format_convert( | |
1073 | xfs_log_iovec_t *buf, | |
1074 | xfs_inode_log_format_t *in_f) | |
1075 | { | |
1076 | if (buf->i_len == sizeof(xfs_inode_log_format_32_t)) { | |
1077 | xfs_inode_log_format_32_t *in_f32; | |
1078 | ||
1079 | in_f32 = (xfs_inode_log_format_32_t *)buf->i_addr; | |
1080 | in_f->ilf_type = in_f32->ilf_type; | |
1081 | in_f->ilf_size = in_f32->ilf_size; | |
1082 | in_f->ilf_fields = in_f32->ilf_fields; | |
1083 | in_f->ilf_asize = in_f32->ilf_asize; | |
1084 | in_f->ilf_dsize = in_f32->ilf_dsize; | |
1085 | in_f->ilf_ino = in_f32->ilf_ino; | |
1086 | /* copy biggest field of ilf_u */ | |
1087 | memcpy(in_f->ilf_u.ilfu_uuid.__u_bits, | |
1088 | in_f32->ilf_u.ilfu_uuid.__u_bits, | |
1089 | sizeof(uuid_t)); | |
1090 | in_f->ilf_blkno = in_f32->ilf_blkno; | |
1091 | in_f->ilf_len = in_f32->ilf_len; | |
1092 | in_f->ilf_boffset = in_f32->ilf_boffset; | |
1093 | return 0; | |
1094 | } else if (buf->i_len == sizeof(xfs_inode_log_format_64_t)){ | |
1095 | xfs_inode_log_format_64_t *in_f64; | |
1096 | ||
1097 | in_f64 = (xfs_inode_log_format_64_t *)buf->i_addr; | |
1098 | in_f->ilf_type = in_f64->ilf_type; | |
1099 | in_f->ilf_size = in_f64->ilf_size; | |
1100 | in_f->ilf_fields = in_f64->ilf_fields; | |
1101 | in_f->ilf_asize = in_f64->ilf_asize; | |
1102 | in_f->ilf_dsize = in_f64->ilf_dsize; | |
1103 | in_f->ilf_ino = in_f64->ilf_ino; | |
1104 | /* copy biggest field of ilf_u */ | |
1105 | memcpy(in_f->ilf_u.ilfu_uuid.__u_bits, | |
1106 | in_f64->ilf_u.ilfu_uuid.__u_bits, | |
1107 | sizeof(uuid_t)); | |
1108 | in_f->ilf_blkno = in_f64->ilf_blkno; | |
1109 | in_f->ilf_len = in_f64->ilf_len; | |
1110 | in_f->ilf_boffset = in_f64->ilf_boffset; | |
1111 | return 0; | |
1112 | } | |
1113 | return EFSCORRUPTED; | |
1114 | } |