blob: a01990dbb945e046d12df12d0da634735d07d1ad [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include "xfs.h"
Nathan Scotta844f452005-11-02 14:38:42 +110019#include "xfs_fs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include "xfs_types.h"
Nathan Scotta844f452005-11-02 14:38:42 +110021#include "xfs_bit.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include "xfs_log.h"
Nathan Scotta844f452005-11-02 14:38:42 +110023#include "xfs_inum.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include "xfs_trans.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include "xfs_sb.h"
Nathan Scotta844f452005-11-02 14:38:42 +110026#include "xfs_ag.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include "xfs_mount.h"
28#include "xfs_trans_priv.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include "xfs_bmap_btree.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include "xfs_dinode.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include "xfs_inode.h"
Nathan Scotta844f452005-11-02 14:38:42 +110032#include "xfs_inode_item.h"
David Chinnerdb7a19f2008-04-10 12:22:24 +100033#include "xfs_error.h"
Christoph Hellwig0b1b2132009-12-14 23:14:59 +000034#include "xfs_trace.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36
37kmem_zone_t *xfs_ili_zone; /* inode log item zone */
38
39/*
40 * This returns the number of iovecs needed to log the given inode item.
41 *
42 * We need one iovec for the inode log format structure, one for the
43 * inode core, and possibly one for the inode data/extents/b-tree root
44 * and one for the inode attribute data/extents/b-tree root.
45 */
46STATIC uint
47xfs_inode_item_size(
48 xfs_inode_log_item_t *iip)
49{
50 uint nvecs;
51 xfs_inode_t *ip;
52
53 ip = iip->ili_inode;
54 nvecs = 2;
55
56 /*
57 * Only log the data/extents/b-tree root if there is something
58 * left to log.
59 */
60 iip->ili_format.ilf_fields |= XFS_ILOG_CORE;
61
62 switch (ip->i_d.di_format) {
63 case XFS_DINODE_FMT_EXTENTS:
64 iip->ili_format.ilf_fields &=
65 ~(XFS_ILOG_DDATA | XFS_ILOG_DBROOT |
66 XFS_ILOG_DEV | XFS_ILOG_UUID);
67 if ((iip->ili_format.ilf_fields & XFS_ILOG_DEXT) &&
68 (ip->i_d.di_nextents > 0) &&
69 (ip->i_df.if_bytes > 0)) {
70 ASSERT(ip->i_df.if_u1.if_extents != NULL);
71 nvecs++;
72 } else {
73 iip->ili_format.ilf_fields &= ~XFS_ILOG_DEXT;
74 }
75 break;
76
77 case XFS_DINODE_FMT_BTREE:
78 ASSERT(ip->i_df.if_ext_max ==
79 XFS_IFORK_DSIZE(ip) / (uint)sizeof(xfs_bmbt_rec_t));
80 iip->ili_format.ilf_fields &=
81 ~(XFS_ILOG_DDATA | XFS_ILOG_DEXT |
82 XFS_ILOG_DEV | XFS_ILOG_UUID);
83 if ((iip->ili_format.ilf_fields & XFS_ILOG_DBROOT) &&
84 (ip->i_df.if_broot_bytes > 0)) {
85 ASSERT(ip->i_df.if_broot != NULL);
86 nvecs++;
87 } else {
88 ASSERT(!(iip->ili_format.ilf_fields &
89 XFS_ILOG_DBROOT));
90#ifdef XFS_TRANS_DEBUG
91 if (iip->ili_root_size > 0) {
92 ASSERT(iip->ili_root_size ==
93 ip->i_df.if_broot_bytes);
94 ASSERT(memcmp(iip->ili_orig_root,
95 ip->i_df.if_broot,
96 iip->ili_root_size) == 0);
97 } else {
98 ASSERT(ip->i_df.if_broot_bytes == 0);
99 }
100#endif
101 iip->ili_format.ilf_fields &= ~XFS_ILOG_DBROOT;
102 }
103 break;
104
105 case XFS_DINODE_FMT_LOCAL:
106 iip->ili_format.ilf_fields &=
107 ~(XFS_ILOG_DEXT | XFS_ILOG_DBROOT |
108 XFS_ILOG_DEV | XFS_ILOG_UUID);
109 if ((iip->ili_format.ilf_fields & XFS_ILOG_DDATA) &&
110 (ip->i_df.if_bytes > 0)) {
111 ASSERT(ip->i_df.if_u1.if_data != NULL);
112 ASSERT(ip->i_d.di_size > 0);
113 nvecs++;
114 } else {
115 iip->ili_format.ilf_fields &= ~XFS_ILOG_DDATA;
116 }
117 break;
118
119 case XFS_DINODE_FMT_DEV:
120 iip->ili_format.ilf_fields &=
121 ~(XFS_ILOG_DDATA | XFS_ILOG_DBROOT |
122 XFS_ILOG_DEXT | XFS_ILOG_UUID);
123 break;
124
125 case XFS_DINODE_FMT_UUID:
126 iip->ili_format.ilf_fields &=
127 ~(XFS_ILOG_DDATA | XFS_ILOG_DBROOT |
128 XFS_ILOG_DEXT | XFS_ILOG_DEV);
129 break;
130
131 default:
132 ASSERT(0);
133 break;
134 }
135
136 /*
137 * If there are no attributes associated with this file,
138 * then there cannot be anything more to log.
139 * Clear all attribute-related log flags.
140 */
141 if (!XFS_IFORK_Q(ip)) {
142 iip->ili_format.ilf_fields &=
143 ~(XFS_ILOG_ADATA | XFS_ILOG_ABROOT | XFS_ILOG_AEXT);
144 return nvecs;
145 }
146
147 /*
148 * Log any necessary attribute data.
149 */
150 switch (ip->i_d.di_aformat) {
151 case XFS_DINODE_FMT_EXTENTS:
152 iip->ili_format.ilf_fields &=
153 ~(XFS_ILOG_ADATA | XFS_ILOG_ABROOT);
154 if ((iip->ili_format.ilf_fields & XFS_ILOG_AEXT) &&
155 (ip->i_d.di_anextents > 0) &&
156 (ip->i_afp->if_bytes > 0)) {
157 ASSERT(ip->i_afp->if_u1.if_extents != NULL);
158 nvecs++;
159 } else {
160 iip->ili_format.ilf_fields &= ~XFS_ILOG_AEXT;
161 }
162 break;
163
164 case XFS_DINODE_FMT_BTREE:
165 iip->ili_format.ilf_fields &=
166 ~(XFS_ILOG_ADATA | XFS_ILOG_AEXT);
167 if ((iip->ili_format.ilf_fields & XFS_ILOG_ABROOT) &&
168 (ip->i_afp->if_broot_bytes > 0)) {
169 ASSERT(ip->i_afp->if_broot != NULL);
170 nvecs++;
171 } else {
172 iip->ili_format.ilf_fields &= ~XFS_ILOG_ABROOT;
173 }
174 break;
175
176 case XFS_DINODE_FMT_LOCAL:
177 iip->ili_format.ilf_fields &=
178 ~(XFS_ILOG_AEXT | XFS_ILOG_ABROOT);
179 if ((iip->ili_format.ilf_fields & XFS_ILOG_ADATA) &&
180 (ip->i_afp->if_bytes > 0)) {
181 ASSERT(ip->i_afp->if_u1.if_data != NULL);
182 nvecs++;
183 } else {
184 iip->ili_format.ilf_fields &= ~XFS_ILOG_ADATA;
185 }
186 break;
187
188 default:
189 ASSERT(0);
190 break;
191 }
192
193 return nvecs;
194}
195
196/*
197 * This is called to fill in the vector of log iovecs for the
198 * given inode log item. It fills the first item with an inode
199 * log format structure, the second with the on-disk inode structure,
200 * and a possible third and/or fourth with the inode data/extents/b-tree
201 * root and inode attributes data/extents/b-tree root.
202 */
203STATIC void
204xfs_inode_item_format(
205 xfs_inode_log_item_t *iip,
206 xfs_log_iovec_t *log_vector)
207{
208 uint nvecs;
209 xfs_log_iovec_t *vecp;
210 xfs_inode_t *ip;
211 size_t data_bytes;
212 xfs_bmbt_rec_t *ext_buffer;
213 int nrecs;
214 xfs_mount_t *mp;
215
216 ip = iip->ili_inode;
217 vecp = log_vector;
218
219 vecp->i_addr = (xfs_caddr_t)&iip->ili_format;
220 vecp->i_len = sizeof(xfs_inode_log_format_t);
Christoph Hellwig4139b3b2010-01-19 09:56:45 +0000221 vecp->i_type = XLOG_REG_TYPE_IFORMAT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 vecp++;
223 nvecs = 1;
224
225 /*
Christoph Hellwigf9581b12009-10-06 20:29:26 +0000226 * Make sure the linux inode is dirty. We do this before
227 * clearing i_update_core as the VFS will call back into
228 * XFS here and set i_update_core, so we need to dirty the
229 * inode first so that the ordering of i_update_core and
230 * unlogged modifications still works as described below.
231 */
232 xfs_mark_inode_dirty_sync(ip);
233
234 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 * Clear i_update_core if the timestamps (or any other
236 * non-transactional modification) need flushing/logging
237 * and we're about to log them with the rest of the core.
238 *
239 * This is the same logic as xfs_iflush() but this code can't
240 * run at the same time as xfs_iflush because we're in commit
241 * processing here and so we have the inode lock held in
242 * exclusive mode. Although it doesn't really matter
243 * for the timestamps if both routines were to grab the
244 * timestamps or not. That would be ok.
245 *
246 * We clear i_update_core before copying out the data.
247 * This is for coordination with our timestamp updates
248 * that don't hold the inode lock. They will always
249 * update the timestamps BEFORE setting i_update_core,
250 * so if we clear i_update_core after they set it we
251 * are guaranteed to see their updates to the timestamps
252 * either here. Likewise, if they set it after we clear it
253 * here, we'll see it either on the next commit of this
254 * inode or the next time the inode gets flushed via
255 * xfs_iflush(). This depends on strongly ordered memory
256 * semantics, but we have that. We use the SYNCHRONIZE
257 * macro to make sure that the compiler does not reorder
258 * the i_update_core access below the data copy below.
259 */
260 if (ip->i_update_core) {
261 ip->i_update_core = 0;
262 SYNCHRONIZE();
263 }
264
265 /*
Christoph Hellwigf9581b12009-10-06 20:29:26 +0000266 * Make sure to get the latest timestamps from the Linux inode.
Christoph Hellwig42fe2b12006-01-11 15:35:17 +1100267 */
Christoph Hellwigf9581b12009-10-06 20:29:26 +0000268 xfs_synchronize_times(ip);
David Chinner5d51eff2007-11-23 16:29:18 +1100269
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 vecp->i_addr = (xfs_caddr_t)&ip->i_d;
Christoph Hellwig81591fe2008-11-28 14:23:39 +1100271 vecp->i_len = sizeof(struct xfs_icdinode);
Christoph Hellwig4139b3b2010-01-19 09:56:45 +0000272 vecp->i_type = XLOG_REG_TYPE_ICORE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 vecp++;
274 nvecs++;
275 iip->ili_format.ilf_fields |= XFS_ILOG_CORE;
276
277 /*
278 * If this is really an old format inode, then we need to
279 * log it as such. This means that we have to copy the link
280 * count from the new field to the old. We don't have to worry
281 * about the new fields, because nothing trusts them as long as
282 * the old inode version number is there. If the superblock already
283 * has a new version number, then we don't bother converting back.
284 */
285 mp = ip->i_mount;
Christoph Hellwig51ce16d2008-11-28 14:23:39 +1100286 ASSERT(ip->i_d.di_version == 1 || xfs_sb_version_hasnlink(&mp->m_sb));
287 if (ip->i_d.di_version == 1) {
Eric Sandeen62118702008-03-06 13:44:28 +1100288 if (!xfs_sb_version_hasnlink(&mp->m_sb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 /*
290 * Convert it back.
291 */
292 ASSERT(ip->i_d.di_nlink <= XFS_MAXLINK_1);
293 ip->i_d.di_onlink = ip->i_d.di_nlink;
294 } else {
295 /*
296 * The superblock version has already been bumped,
297 * so just make the conversion to the new inode
298 * format permanent.
299 */
Christoph Hellwig51ce16d2008-11-28 14:23:39 +1100300 ip->i_d.di_version = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 ip->i_d.di_onlink = 0;
302 memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
303 }
304 }
305
306 switch (ip->i_d.di_format) {
307 case XFS_DINODE_FMT_EXTENTS:
308 ASSERT(!(iip->ili_format.ilf_fields &
309 (XFS_ILOG_DDATA | XFS_ILOG_DBROOT |
310 XFS_ILOG_DEV | XFS_ILOG_UUID)));
311 if (iip->ili_format.ilf_fields & XFS_ILOG_DEXT) {
312 ASSERT(ip->i_df.if_bytes > 0);
313 ASSERT(ip->i_df.if_u1.if_extents != NULL);
314 ASSERT(ip->i_d.di_nextents > 0);
315 ASSERT(iip->ili_extents_buf == NULL);
316 nrecs = ip->i_df.if_bytes /
317 (uint)sizeof(xfs_bmbt_rec_t);
318 ASSERT(nrecs > 0);
Nathan Scottf016bad2005-09-08 15:30:05 +1000319#ifdef XFS_NATIVE_HOST
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 if (nrecs == ip->i_d.di_nextents) {
321 /*
322 * There are no delayed allocation
323 * extents, so just point to the
324 * real extents array.
325 */
326 vecp->i_addr =
327 (char *)(ip->i_df.if_u1.if_extents);
328 vecp->i_len = ip->i_df.if_bytes;
Christoph Hellwig4139b3b2010-01-19 09:56:45 +0000329 vecp->i_type = XLOG_REG_TYPE_IEXT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 } else
331#endif
332 {
333 /*
334 * There are delayed allocation extents
335 * in the inode, or we need to convert
336 * the extents to on disk format.
337 * Use xfs_iextents_copy()
338 * to copy only the real extents into
339 * a separate buffer. We'll free the
340 * buffer in the unlock routine.
341 */
342 ext_buffer = kmem_alloc(ip->i_df.if_bytes,
343 KM_SLEEP);
344 iip->ili_extents_buf = ext_buffer;
345 vecp->i_addr = (xfs_caddr_t)ext_buffer;
346 vecp->i_len = xfs_iextents_copy(ip, ext_buffer,
347 XFS_DATA_FORK);
Christoph Hellwig4139b3b2010-01-19 09:56:45 +0000348 vecp->i_type = XLOG_REG_TYPE_IEXT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 }
350 ASSERT(vecp->i_len <= ip->i_df.if_bytes);
351 iip->ili_format.ilf_dsize = vecp->i_len;
352 vecp++;
353 nvecs++;
354 }
355 break;
356
357 case XFS_DINODE_FMT_BTREE:
358 ASSERT(!(iip->ili_format.ilf_fields &
359 (XFS_ILOG_DDATA | XFS_ILOG_DEXT |
360 XFS_ILOG_DEV | XFS_ILOG_UUID)));
361 if (iip->ili_format.ilf_fields & XFS_ILOG_DBROOT) {
362 ASSERT(ip->i_df.if_broot_bytes > 0);
363 ASSERT(ip->i_df.if_broot != NULL);
364 vecp->i_addr = (xfs_caddr_t)ip->i_df.if_broot;
365 vecp->i_len = ip->i_df.if_broot_bytes;
Christoph Hellwig4139b3b2010-01-19 09:56:45 +0000366 vecp->i_type = XLOG_REG_TYPE_IBROOT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 vecp++;
368 nvecs++;
369 iip->ili_format.ilf_dsize = ip->i_df.if_broot_bytes;
370 }
371 break;
372
373 case XFS_DINODE_FMT_LOCAL:
374 ASSERT(!(iip->ili_format.ilf_fields &
375 (XFS_ILOG_DBROOT | XFS_ILOG_DEXT |
376 XFS_ILOG_DEV | XFS_ILOG_UUID)));
377 if (iip->ili_format.ilf_fields & XFS_ILOG_DDATA) {
378 ASSERT(ip->i_df.if_bytes > 0);
379 ASSERT(ip->i_df.if_u1.if_data != NULL);
380 ASSERT(ip->i_d.di_size > 0);
381
382 vecp->i_addr = (xfs_caddr_t)ip->i_df.if_u1.if_data;
383 /*
384 * Round i_bytes up to a word boundary.
385 * The underlying memory is guaranteed to
386 * to be there by xfs_idata_realloc().
387 */
388 data_bytes = roundup(ip->i_df.if_bytes, 4);
389 ASSERT((ip->i_df.if_real_bytes == 0) ||
390 (ip->i_df.if_real_bytes == data_bytes));
391 vecp->i_len = (int)data_bytes;
Christoph Hellwig4139b3b2010-01-19 09:56:45 +0000392 vecp->i_type = XLOG_REG_TYPE_ILOCAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 vecp++;
394 nvecs++;
395 iip->ili_format.ilf_dsize = (unsigned)data_bytes;
396 }
397 break;
398
399 case XFS_DINODE_FMT_DEV:
400 ASSERT(!(iip->ili_format.ilf_fields &
401 (XFS_ILOG_DBROOT | XFS_ILOG_DEXT |
402 XFS_ILOG_DDATA | XFS_ILOG_UUID)));
403 if (iip->ili_format.ilf_fields & XFS_ILOG_DEV) {
404 iip->ili_format.ilf_u.ilfu_rdev =
405 ip->i_df.if_u2.if_rdev;
406 }
407 break;
408
409 case XFS_DINODE_FMT_UUID:
410 ASSERT(!(iip->ili_format.ilf_fields &
411 (XFS_ILOG_DBROOT | XFS_ILOG_DEXT |
412 XFS_ILOG_DDATA | XFS_ILOG_DEV)));
413 if (iip->ili_format.ilf_fields & XFS_ILOG_UUID) {
414 iip->ili_format.ilf_u.ilfu_uuid =
415 ip->i_df.if_u2.if_uuid;
416 }
417 break;
418
419 default:
420 ASSERT(0);
421 break;
422 }
423
424 /*
425 * If there are no attributes associated with the file,
426 * then we're done.
427 * Assert that no attribute-related log flags are set.
428 */
429 if (!XFS_IFORK_Q(ip)) {
430 ASSERT(nvecs == iip->ili_item.li_desc->lid_size);
431 iip->ili_format.ilf_size = nvecs;
432 ASSERT(!(iip->ili_format.ilf_fields &
433 (XFS_ILOG_ADATA | XFS_ILOG_ABROOT | XFS_ILOG_AEXT)));
434 return;
435 }
436
437 switch (ip->i_d.di_aformat) {
438 case XFS_DINODE_FMT_EXTENTS:
439 ASSERT(!(iip->ili_format.ilf_fields &
440 (XFS_ILOG_ADATA | XFS_ILOG_ABROOT)));
441 if (iip->ili_format.ilf_fields & XFS_ILOG_AEXT) {
442 ASSERT(ip->i_afp->if_bytes > 0);
443 ASSERT(ip->i_afp->if_u1.if_extents != NULL);
444 ASSERT(ip->i_d.di_anextents > 0);
445#ifdef DEBUG
446 nrecs = ip->i_afp->if_bytes /
447 (uint)sizeof(xfs_bmbt_rec_t);
448#endif
449 ASSERT(nrecs > 0);
450 ASSERT(nrecs == ip->i_d.di_anextents);
Nathan Scottf016bad2005-09-08 15:30:05 +1000451#ifdef XFS_NATIVE_HOST
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 /*
453 * There are not delayed allocation extents
454 * for attributes, so just point at the array.
455 */
456 vecp->i_addr = (char *)(ip->i_afp->if_u1.if_extents);
457 vecp->i_len = ip->i_afp->if_bytes;
458#else
459 ASSERT(iip->ili_aextents_buf == NULL);
460 /*
461 * Need to endian flip before logging
462 */
463 ext_buffer = kmem_alloc(ip->i_afp->if_bytes,
464 KM_SLEEP);
465 iip->ili_aextents_buf = ext_buffer;
466 vecp->i_addr = (xfs_caddr_t)ext_buffer;
467 vecp->i_len = xfs_iextents_copy(ip, ext_buffer,
468 XFS_ATTR_FORK);
469#endif
Christoph Hellwig4139b3b2010-01-19 09:56:45 +0000470 vecp->i_type = XLOG_REG_TYPE_IATTR_EXT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 iip->ili_format.ilf_asize = vecp->i_len;
472 vecp++;
473 nvecs++;
474 }
475 break;
476
477 case XFS_DINODE_FMT_BTREE:
478 ASSERT(!(iip->ili_format.ilf_fields &
479 (XFS_ILOG_ADATA | XFS_ILOG_AEXT)));
480 if (iip->ili_format.ilf_fields & XFS_ILOG_ABROOT) {
481 ASSERT(ip->i_afp->if_broot_bytes > 0);
482 ASSERT(ip->i_afp->if_broot != NULL);
483 vecp->i_addr = (xfs_caddr_t)ip->i_afp->if_broot;
484 vecp->i_len = ip->i_afp->if_broot_bytes;
Christoph Hellwig4139b3b2010-01-19 09:56:45 +0000485 vecp->i_type = XLOG_REG_TYPE_IATTR_BROOT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 vecp++;
487 nvecs++;
488 iip->ili_format.ilf_asize = ip->i_afp->if_broot_bytes;
489 }
490 break;
491
492 case XFS_DINODE_FMT_LOCAL:
493 ASSERT(!(iip->ili_format.ilf_fields &
494 (XFS_ILOG_ABROOT | XFS_ILOG_AEXT)));
495 if (iip->ili_format.ilf_fields & XFS_ILOG_ADATA) {
496 ASSERT(ip->i_afp->if_bytes > 0);
497 ASSERT(ip->i_afp->if_u1.if_data != NULL);
498
499 vecp->i_addr = (xfs_caddr_t)ip->i_afp->if_u1.if_data;
500 /*
501 * Round i_bytes up to a word boundary.
502 * The underlying memory is guaranteed to
503 * to be there by xfs_idata_realloc().
504 */
505 data_bytes = roundup(ip->i_afp->if_bytes, 4);
506 ASSERT((ip->i_afp->if_real_bytes == 0) ||
507 (ip->i_afp->if_real_bytes == data_bytes));
508 vecp->i_len = (int)data_bytes;
Christoph Hellwig4139b3b2010-01-19 09:56:45 +0000509 vecp->i_type = XLOG_REG_TYPE_IATTR_LOCAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 vecp++;
511 nvecs++;
512 iip->ili_format.ilf_asize = (unsigned)data_bytes;
513 }
514 break;
515
516 default:
517 ASSERT(0);
518 break;
519 }
520
521 ASSERT(nvecs == iip->ili_item.li_desc->lid_size);
522 iip->ili_format.ilf_size = nvecs;
523}
524
525
526/*
527 * This is called to pin the inode associated with the inode log
Christoph Hellwiga14a5ab2010-02-18 12:43:22 +0000528 * item in memory so it cannot be written out.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 */
530STATIC void
531xfs_inode_item_pin(
532 xfs_inode_log_item_t *iip)
533{
Christoph Hellwig579aa9c2008-04-22 17:34:00 +1000534 ASSERT(xfs_isilocked(iip->ili_inode, XFS_ILOCK_EXCL));
Christoph Hellwiga14a5ab2010-02-18 12:43:22 +0000535
Dave Chinner4aaf15d2010-03-08 11:24:07 +1100536 trace_xfs_inode_pin(iip->ili_inode, _RET_IP_);
Christoph Hellwiga14a5ab2010-02-18 12:43:22 +0000537 atomic_inc(&iip->ili_inode->i_pincount);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538}
539
540
541/*
542 * This is called to unpin the inode associated with the inode log
543 * item which was previously pinned with a call to xfs_inode_item_pin().
Christoph Hellwiga14a5ab2010-02-18 12:43:22 +0000544 *
545 * Also wake up anyone in xfs_iunpin_wait() if the count goes to 0.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547STATIC void
548xfs_inode_item_unpin(
Christoph Hellwig9412e312010-06-23 18:11:15 +1000549 xfs_inode_log_item_t *iip,
550 int remove)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551{
Christoph Hellwiga14a5ab2010-02-18 12:43:22 +0000552 struct xfs_inode *ip = iip->ili_inode;
553
Dave Chinner4aaf15d2010-03-08 11:24:07 +1100554 trace_xfs_inode_unpin(ip, _RET_IP_);
Christoph Hellwiga14a5ab2010-02-18 12:43:22 +0000555 ASSERT(atomic_read(&ip->i_pincount) > 0);
556 if (atomic_dec_and_test(&ip->i_pincount))
557 wake_up(&ip->i_ipin_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558}
559
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560/*
561 * This is called to attempt to lock the inode associated with this
562 * inode log item, in preparation for the push routine which does the actual
563 * iflush. Don't sleep on the inode lock or the flush lock.
564 *
565 * If the flush lock is already held, indicating that the inode has
566 * been or is in the process of being flushed, then (ideally) we'd like to
567 * see if the inode's buffer is still incore, and if so give it a nudge.
568 * We delay doing so until the pushbuf routine, though, to avoid holding
Nathan Scottc41564b2006-03-29 08:55:14 +1000569 * the AIL lock across a call to the blackhole which is the buffer cache.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 * Also we don't want to sleep in any device strategy routines, which can happen
571 * if we do the subsequent bawrite in here.
572 */
573STATIC uint
574xfs_inode_item_trylock(
575 xfs_inode_log_item_t *iip)
576{
577 register xfs_inode_t *ip;
578
579 ip = iip->ili_inode;
580
581 if (xfs_ipincount(ip) > 0) {
582 return XFS_ITEM_PINNED;
583 }
584
585 if (!xfs_ilock_nowait(ip, XFS_ILOCK_SHARED)) {
586 return XFS_ITEM_LOCKED;
587 }
588
589 if (!xfs_iflock_nowait(ip)) {
590 /*
Dave Chinnerd808f612010-02-02 10:13:42 +1100591 * inode has already been flushed to the backing buffer,
592 * leave it locked in shared mode, pushbuf routine will
593 * unlock it.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 */
Dave Chinnerd808f612010-02-02 10:13:42 +1100595 return XFS_ITEM_PUSHBUF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 }
597
598 /* Stale items should force out the iclog */
599 if (ip->i_flags & XFS_ISTALE) {
600 xfs_ifunlock(ip);
Dave Chinnerd808f612010-02-02 10:13:42 +1100601 /*
602 * we hold the AIL lock - notify the unlock routine of this
603 * so it doesn't try to get the lock again.
604 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 xfs_iunlock(ip, XFS_ILOCK_SHARED|XFS_IUNLOCK_NONOTIFY);
606 return XFS_ITEM_PINNED;
607 }
608
609#ifdef DEBUG
610 if (!XFS_FORCED_SHUTDOWN(ip->i_mount)) {
611 ASSERT(iip->ili_format.ilf_fields != 0);
612 ASSERT(iip->ili_logged == 0);
613 ASSERT(iip->ili_item.li_flags & XFS_LI_IN_AIL);
614 }
615#endif
616 return XFS_ITEM_SUCCESS;
617}
618
619/*
620 * Unlock the inode associated with the inode log item.
621 * Clear the fields of the inode and inode log item that
622 * are specific to the current transaction. If the
623 * hold flags is set, do not unlock the inode.
624 */
625STATIC void
626xfs_inode_item_unlock(
627 xfs_inode_log_item_t *iip)
628{
629 uint hold;
630 uint iolocked;
631 uint lock_flags;
632 xfs_inode_t *ip;
633
634 ASSERT(iip != NULL);
635 ASSERT(iip->ili_inode->i_itemp != NULL);
Christoph Hellwig579aa9c2008-04-22 17:34:00 +1000636 ASSERT(xfs_isilocked(iip->ili_inode, XFS_ILOCK_EXCL));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 ASSERT((!(iip->ili_inode->i_itemp->ili_flags &
638 XFS_ILI_IOLOCKED_EXCL)) ||
Christoph Hellwig579aa9c2008-04-22 17:34:00 +1000639 xfs_isilocked(iip->ili_inode, XFS_IOLOCK_EXCL));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 ASSERT((!(iip->ili_inode->i_itemp->ili_flags &
641 XFS_ILI_IOLOCKED_SHARED)) ||
Christoph Hellwig579aa9c2008-04-22 17:34:00 +1000642 xfs_isilocked(iip->ili_inode, XFS_IOLOCK_SHARED));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 /*
644 * Clear the transaction pointer in the inode.
645 */
646 ip = iip->ili_inode;
647 ip->i_transp = NULL;
648
649 /*
650 * If the inode needed a separate buffer with which to log
651 * its extents, then free it now.
652 */
653 if (iip->ili_extents_buf != NULL) {
654 ASSERT(ip->i_d.di_format == XFS_DINODE_FMT_EXTENTS);
655 ASSERT(ip->i_d.di_nextents > 0);
656 ASSERT(iip->ili_format.ilf_fields & XFS_ILOG_DEXT);
657 ASSERT(ip->i_df.if_bytes > 0);
Denys Vlasenkof0e2d932008-05-19 16:31:57 +1000658 kmem_free(iip->ili_extents_buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 iip->ili_extents_buf = NULL;
660 }
661 if (iip->ili_aextents_buf != NULL) {
662 ASSERT(ip->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS);
663 ASSERT(ip->i_d.di_anextents > 0);
664 ASSERT(iip->ili_format.ilf_fields & XFS_ILOG_AEXT);
665 ASSERT(ip->i_afp->if_bytes > 0);
Denys Vlasenkof0e2d932008-05-19 16:31:57 +1000666 kmem_free(iip->ili_aextents_buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 iip->ili_aextents_buf = NULL;
668 }
669
670 /*
671 * Figure out if we should unlock the inode or not.
672 */
673 hold = iip->ili_flags & XFS_ILI_HOLD;
674
675 /*
676 * Before clearing out the flags, remember whether we
677 * are holding the inode's IO lock.
678 */
679 iolocked = iip->ili_flags & XFS_ILI_IOLOCKED_ANY;
680
681 /*
682 * Clear out the fields of the inode log item particular
683 * to the current transaction.
684 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 iip->ili_flags = 0;
686
687 /*
688 * Unlock the inode if XFS_ILI_HOLD was not set.
689 */
690 if (!hold) {
691 lock_flags = XFS_ILOCK_EXCL;
692 if (iolocked & XFS_ILI_IOLOCKED_EXCL) {
693 lock_flags |= XFS_IOLOCK_EXCL;
694 } else if (iolocked & XFS_ILI_IOLOCKED_SHARED) {
695 lock_flags |= XFS_IOLOCK_SHARED;
696 }
697 xfs_iput(iip->ili_inode, lock_flags);
698 }
699}
700
701/*
702 * This is called to find out where the oldest active copy of the
703 * inode log item in the on disk log resides now that the last log
704 * write of it completed at the given lsn. Since we always re-log
705 * all dirty data in an inode, the latest copy in the on disk log
706 * is the only one that matters. Therefore, simply return the
707 * given lsn.
708 */
709/*ARGSUSED*/
710STATIC xfs_lsn_t
711xfs_inode_item_committed(
712 xfs_inode_log_item_t *iip,
713 xfs_lsn_t lsn)
714{
715 return (lsn);
716}
717
718/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 * This gets called by xfs_trans_push_ail(), when IOP_TRYLOCK
720 * failed to get the inode flush lock but did get the inode locked SHARED.
721 * Here we're trying to see if the inode buffer is incore, and if so whether it's
Dave Chinnerd808f612010-02-02 10:13:42 +1100722 * marked delayed write. If that's the case, we'll promote it and that will
723 * allow the caller to write the buffer by triggering the xfsbufd to run.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 */
725STATIC void
726xfs_inode_item_pushbuf(
727 xfs_inode_log_item_t *iip)
728{
729 xfs_inode_t *ip;
730 xfs_mount_t *mp;
731 xfs_buf_t *bp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
733 ip = iip->ili_inode;
Christoph Hellwig579aa9c2008-04-22 17:34:00 +1000734 ASSERT(xfs_isilocked(ip, XFS_ILOCK_SHARED));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
736 /*
David Chinnerc63942d2008-08-13 16:41:16 +1000737 * If a flush is not in progress anymore, chances are that the
738 * inode was taken off the AIL. So, just get out.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 */
David Chinnerc63942d2008-08-13 16:41:16 +1000740 if (completion_done(&ip->i_flush) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 ((iip->ili_item.li_flags & XFS_LI_IN_AIL) == 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 xfs_iunlock(ip, XFS_ILOCK_SHARED);
743 return;
744 }
745
746 mp = ip->i_mount;
747 bp = xfs_incore(mp->m_ddev_targp, iip->ili_format.ilf_blkno,
Christoph Hellwig0cadda12010-01-19 09:56:44 +0000748 iip->ili_format.ilf_len, XBF_TRYLOCK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 xfs_iunlock(ip, XFS_ILOCK_SHARED);
Dave Chinnerd808f612010-02-02 10:13:42 +1100751 if (!bp)
752 return;
753 if (XFS_BUF_ISDELAYWRITE(bp))
754 xfs_buf_delwri_promote(bp);
755 xfs_buf_relse(bp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 return;
757}
758
759
760/*
761 * This is called to asynchronously write the inode associated with this
762 * inode log item out to disk. The inode will already have been locked by
763 * a successful call to xfs_inode_item_trylock().
764 */
765STATIC void
766xfs_inode_item_push(
767 xfs_inode_log_item_t *iip)
768{
769 xfs_inode_t *ip;
770
771 ip = iip->ili_inode;
772
Christoph Hellwig579aa9c2008-04-22 17:34:00 +1000773 ASSERT(xfs_isilocked(ip, XFS_ILOCK_SHARED));
David Chinnerc63942d2008-08-13 16:41:16 +1000774 ASSERT(!completion_done(&ip->i_flush));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 /*
776 * Since we were able to lock the inode's flush lock and
777 * we found it on the AIL, the inode must be dirty. This
778 * is because the inode is removed from the AIL while still
779 * holding the flush lock in xfs_iflush_done(). Thus, if
780 * we found it in the AIL and were able to obtain the flush
781 * lock without sleeping, then there must not have been
782 * anyone in the process of flushing the inode.
783 */
784 ASSERT(XFS_FORCED_SHUTDOWN(ip->i_mount) ||
785 iip->ili_format.ilf_fields != 0);
786
787 /*
Dave Chinnerc8543632010-02-06 12:39:36 +1100788 * Push the inode to it's backing buffer. This will not remove the
789 * inode from the AIL - a further push will be required to trigger a
790 * buffer push. However, this allows all the dirty inodes to be pushed
791 * to the buffer before it is pushed to disk. THe buffer IO completion
792 * will pull th einode from the AIL, mark it clean and unlock the flush
793 * lock.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 */
Dave Chinnerc8543632010-02-06 12:39:36 +1100795 (void) xfs_iflush(ip, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 xfs_iunlock(ip, XFS_ILOCK_SHARED);
797
798 return;
799}
800
801/*
802 * XXX rcc - this one really has to do something. Probably needs
803 * to stamp in a new field in the incore inode.
804 */
805/* ARGSUSED */
806STATIC void
807xfs_inode_item_committing(
808 xfs_inode_log_item_t *iip,
809 xfs_lsn_t lsn)
810{
811 iip->ili_last_lsn = lsn;
812 return;
813}
814
815/*
816 * This is the ops vector shared by all buf log items.
817 */
David Chinner7989cb82007-02-10 18:34:56 +1100818static struct xfs_item_ops xfs_inode_item_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 .iop_size = (uint(*)(xfs_log_item_t*))xfs_inode_item_size,
820 .iop_format = (void(*)(xfs_log_item_t*, xfs_log_iovec_t*))
821 xfs_inode_item_format,
822 .iop_pin = (void(*)(xfs_log_item_t*))xfs_inode_item_pin,
Christoph Hellwig9412e312010-06-23 18:11:15 +1000823 .iop_unpin = (void(*)(xfs_log_item_t*, int))xfs_inode_item_unpin,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 .iop_trylock = (uint(*)(xfs_log_item_t*))xfs_inode_item_trylock,
825 .iop_unlock = (void(*)(xfs_log_item_t*))xfs_inode_item_unlock,
826 .iop_committed = (xfs_lsn_t(*)(xfs_log_item_t*, xfs_lsn_t))
827 xfs_inode_item_committed,
828 .iop_push = (void(*)(xfs_log_item_t*))xfs_inode_item_push,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 .iop_pushbuf = (void(*)(xfs_log_item_t*))xfs_inode_item_pushbuf,
830 .iop_committing = (void(*)(xfs_log_item_t*, xfs_lsn_t))
831 xfs_inode_item_committing
832};
833
834
835/*
836 * Initialize the inode log item for a newly allocated (in-core) inode.
837 */
838void
839xfs_inode_item_init(
840 xfs_inode_t *ip,
841 xfs_mount_t *mp)
842{
843 xfs_inode_log_item_t *iip;
844
845 ASSERT(ip->i_itemp == NULL);
846 iip = ip->i_itemp = kmem_zone_zalloc(xfs_ili_zone, KM_SLEEP);
847
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 iip->ili_inode = ip;
Dave Chinner43f5efc2010-03-23 10:10:00 +1100849 xfs_log_item_init(mp, &iip->ili_item, XFS_LI_INODE,
850 &xfs_inode_item_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 iip->ili_format.ilf_type = XFS_LI_INODE;
852 iip->ili_format.ilf_ino = ip->i_ino;
Christoph Hellwig92bfc6e2008-11-28 14:23:41 +1100853 iip->ili_format.ilf_blkno = ip->i_imap.im_blkno;
854 iip->ili_format.ilf_len = ip->i_imap.im_len;
855 iip->ili_format.ilf_boffset = ip->i_imap.im_boffset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856}
857
858/*
859 * Free the inode log item and any memory hanging off of it.
860 */
861void
862xfs_inode_item_destroy(
863 xfs_inode_t *ip)
864{
865#ifdef XFS_TRANS_DEBUG
866 if (ip->i_itemp->ili_root_size != 0) {
Denys Vlasenkof0e2d932008-05-19 16:31:57 +1000867 kmem_free(ip->i_itemp->ili_orig_root);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 }
869#endif
870 kmem_zone_free(xfs_ili_zone, ip->i_itemp);
871}
872
873
874/*
875 * This is the inode flushing I/O completion routine. It is called
876 * from interrupt level when the buffer containing the inode is
877 * flushed to disk. It is responsible for removing the inode item
878 * from the AIL if it has not been re-logged, and unlocking the inode's
879 * flush lock.
880 */
881/*ARGSUSED*/
882void
883xfs_iflush_done(
884 xfs_buf_t *bp,
885 xfs_inode_log_item_t *iip)
886{
David Chinner783a2f62008-10-30 17:39:58 +1100887 xfs_inode_t *ip = iip->ili_inode;
888 struct xfs_ail *ailp = iip->ili_item.li_ailp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
890 /*
891 * We only want to pull the item from the AIL if it is
892 * actually there and its location in the log has not
893 * changed since we started the flush. Thus, we only bother
894 * if the ili_logged flag is set and the inode's lsn has not
895 * changed. First we check the lsn outside
896 * the lock since it's cheaper, and then we recheck while
897 * holding the lock before removing the inode from the AIL.
898 */
899 if (iip->ili_logged &&
900 (iip->ili_item.li_lsn == iip->ili_flush_lsn)) {
David Chinner783a2f62008-10-30 17:39:58 +1100901 spin_lock(&ailp->xa_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 if (iip->ili_item.li_lsn == iip->ili_flush_lsn) {
David Chinner783a2f62008-10-30 17:39:58 +1100903 /* xfs_trans_ail_delete() drops the AIL lock. */
904 xfs_trans_ail_delete(ailp, (xfs_log_item_t*)iip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 } else {
David Chinner783a2f62008-10-30 17:39:58 +1100906 spin_unlock(&ailp->xa_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 }
908 }
909
910 iip->ili_logged = 0;
911
912 /*
913 * Clear the ili_last_fields bits now that we know that the
914 * data corresponding to them is safely on disk.
915 */
916 iip->ili_last_fields = 0;
917
918 /*
919 * Release the inode's flush lock since we're done with it.
920 */
921 xfs_ifunlock(ip);
922
923 return;
924}
925
926/*
927 * This is the inode flushing abort routine. It is called
928 * from xfs_iflush when the filesystem is shutting down to clean
929 * up the inode state.
930 * It is responsible for removing the inode item
931 * from the AIL if it has not been re-logged, and unlocking the inode's
932 * flush lock.
933 */
934void
935xfs_iflush_abort(
936 xfs_inode_t *ip)
937{
David Chinner783a2f62008-10-30 17:39:58 +1100938 xfs_inode_log_item_t *iip = ip->i_itemp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 xfs_mount_t *mp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
941 iip = ip->i_itemp;
942 mp = ip->i_mount;
943 if (iip) {
David Chinner783a2f62008-10-30 17:39:58 +1100944 struct xfs_ail *ailp = iip->ili_item.li_ailp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 if (iip->ili_item.li_flags & XFS_LI_IN_AIL) {
David Chinner783a2f62008-10-30 17:39:58 +1100946 spin_lock(&ailp->xa_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 if (iip->ili_item.li_flags & XFS_LI_IN_AIL) {
David Chinner783a2f62008-10-30 17:39:58 +1100948 /* xfs_trans_ail_delete() drops the AIL lock. */
949 xfs_trans_ail_delete(ailp, (xfs_log_item_t *)iip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 } else
David Chinner783a2f62008-10-30 17:39:58 +1100951 spin_unlock(&ailp->xa_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 }
953 iip->ili_logged = 0;
954 /*
955 * Clear the ili_last_fields bits now that we know that the
956 * data corresponding to them is safely on disk.
957 */
958 iip->ili_last_fields = 0;
959 /*
960 * Clear the inode logging fields so no more flushes are
961 * attempted.
962 */
963 iip->ili_format.ilf_fields = 0;
964 }
965 /*
966 * Release the inode's flush lock since we're done with it.
967 */
968 xfs_ifunlock(ip);
969}
970
971void
972xfs_istale_done(
973 xfs_buf_t *bp,
974 xfs_inode_log_item_t *iip)
975{
976 xfs_iflush_abort(iip->ili_inode);
977}
Tim Shimmin6d192a92006-06-09 14:55:38 +1000978
979/*
980 * convert an xfs_inode_log_format struct from either 32 or 64 bit versions
981 * (which can have different field alignments) to the native version
982 */
983int
984xfs_inode_item_format_convert(
985 xfs_log_iovec_t *buf,
986 xfs_inode_log_format_t *in_f)
987{
988 if (buf->i_len == sizeof(xfs_inode_log_format_32_t)) {
989 xfs_inode_log_format_32_t *in_f32;
990
991 in_f32 = (xfs_inode_log_format_32_t *)buf->i_addr;
992 in_f->ilf_type = in_f32->ilf_type;
993 in_f->ilf_size = in_f32->ilf_size;
994 in_f->ilf_fields = in_f32->ilf_fields;
995 in_f->ilf_asize = in_f32->ilf_asize;
996 in_f->ilf_dsize = in_f32->ilf_dsize;
997 in_f->ilf_ino = in_f32->ilf_ino;
998 /* copy biggest field of ilf_u */
999 memcpy(in_f->ilf_u.ilfu_uuid.__u_bits,
1000 in_f32->ilf_u.ilfu_uuid.__u_bits,
1001 sizeof(uuid_t));
1002 in_f->ilf_blkno = in_f32->ilf_blkno;
1003 in_f->ilf_len = in_f32->ilf_len;
1004 in_f->ilf_boffset = in_f32->ilf_boffset;
1005 return 0;
1006 } else if (buf->i_len == sizeof(xfs_inode_log_format_64_t)){
1007 xfs_inode_log_format_64_t *in_f64;
1008
1009 in_f64 = (xfs_inode_log_format_64_t *)buf->i_addr;
1010 in_f->ilf_type = in_f64->ilf_type;
1011 in_f->ilf_size = in_f64->ilf_size;
1012 in_f->ilf_fields = in_f64->ilf_fields;
1013 in_f->ilf_asize = in_f64->ilf_asize;
1014 in_f->ilf_dsize = in_f64->ilf_dsize;
1015 in_f->ilf_ino = in_f64->ilf_ino;
1016 /* copy biggest field of ilf_u */
1017 memcpy(in_f->ilf_u.ilfu_uuid.__u_bits,
1018 in_f64->ilf_u.ilfu_uuid.__u_bits,
1019 sizeof(uuid_t));
1020 in_f->ilf_blkno = in_f64->ilf_blkno;
1021 in_f->ilf_len = in_f64->ilf_len;
1022 in_f->ilf_boffset = in_f64->ilf_boffset;
1023 return 0;
1024 }
1025 return EFSCORRUPTED;
1026}