blob: 4b97d7754b83f540e4f2aab4a96f452ba566afd7 [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 */
547/* ARGSUSED */
548STATIC void
549xfs_inode_item_unpin(
Dave Chinner8e123852010-03-08 11:26:03 +1100550 xfs_inode_log_item_t *iip)
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
560/* ARGSUSED */
561STATIC void
562xfs_inode_item_unpin_remove(
563 xfs_inode_log_item_t *iip,
564 xfs_trans_t *tp)
565{
Dave Chinner8e123852010-03-08 11:26:03 +1100566 xfs_inode_item_unpin(iip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567}
568
569/*
570 * This is called to attempt to lock the inode associated with this
571 * inode log item, in preparation for the push routine which does the actual
572 * iflush. Don't sleep on the inode lock or the flush lock.
573 *
574 * If the flush lock is already held, indicating that the inode has
575 * been or is in the process of being flushed, then (ideally) we'd like to
576 * see if the inode's buffer is still incore, and if so give it a nudge.
577 * We delay doing so until the pushbuf routine, though, to avoid holding
Nathan Scottc41564b2006-03-29 08:55:14 +1000578 * the AIL lock across a call to the blackhole which is the buffer cache.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 * Also we don't want to sleep in any device strategy routines, which can happen
580 * if we do the subsequent bawrite in here.
581 */
582STATIC uint
583xfs_inode_item_trylock(
584 xfs_inode_log_item_t *iip)
585{
586 register xfs_inode_t *ip;
587
588 ip = iip->ili_inode;
589
590 if (xfs_ipincount(ip) > 0) {
591 return XFS_ITEM_PINNED;
592 }
593
594 if (!xfs_ilock_nowait(ip, XFS_ILOCK_SHARED)) {
595 return XFS_ITEM_LOCKED;
596 }
597
598 if (!xfs_iflock_nowait(ip)) {
599 /*
Dave Chinnerd808f612010-02-02 10:13:42 +1100600 * inode has already been flushed to the backing buffer,
601 * leave it locked in shared mode, pushbuf routine will
602 * unlock it.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 */
Dave Chinnerd808f612010-02-02 10:13:42 +1100604 return XFS_ITEM_PUSHBUF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 }
606
607 /* Stale items should force out the iclog */
608 if (ip->i_flags & XFS_ISTALE) {
609 xfs_ifunlock(ip);
Dave Chinnerd808f612010-02-02 10:13:42 +1100610 /*
611 * we hold the AIL lock - notify the unlock routine of this
612 * so it doesn't try to get the lock again.
613 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 xfs_iunlock(ip, XFS_ILOCK_SHARED|XFS_IUNLOCK_NONOTIFY);
615 return XFS_ITEM_PINNED;
616 }
617
618#ifdef DEBUG
619 if (!XFS_FORCED_SHUTDOWN(ip->i_mount)) {
620 ASSERT(iip->ili_format.ilf_fields != 0);
621 ASSERT(iip->ili_logged == 0);
622 ASSERT(iip->ili_item.li_flags & XFS_LI_IN_AIL);
623 }
624#endif
625 return XFS_ITEM_SUCCESS;
626}
627
628/*
629 * Unlock the inode associated with the inode log item.
630 * Clear the fields of the inode and inode log item that
631 * are specific to the current transaction. If the
632 * hold flags is set, do not unlock the inode.
633 */
634STATIC void
635xfs_inode_item_unlock(
636 xfs_inode_log_item_t *iip)
637{
638 uint hold;
639 uint iolocked;
640 uint lock_flags;
641 xfs_inode_t *ip;
642
643 ASSERT(iip != NULL);
644 ASSERT(iip->ili_inode->i_itemp != NULL);
Christoph Hellwig579aa9c2008-04-22 17:34:00 +1000645 ASSERT(xfs_isilocked(iip->ili_inode, XFS_ILOCK_EXCL));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 ASSERT((!(iip->ili_inode->i_itemp->ili_flags &
647 XFS_ILI_IOLOCKED_EXCL)) ||
Christoph Hellwig579aa9c2008-04-22 17:34:00 +1000648 xfs_isilocked(iip->ili_inode, XFS_IOLOCK_EXCL));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 ASSERT((!(iip->ili_inode->i_itemp->ili_flags &
650 XFS_ILI_IOLOCKED_SHARED)) ||
Christoph Hellwig579aa9c2008-04-22 17:34:00 +1000651 xfs_isilocked(iip->ili_inode, XFS_IOLOCK_SHARED));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 /*
653 * Clear the transaction pointer in the inode.
654 */
655 ip = iip->ili_inode;
656 ip->i_transp = NULL;
657
658 /*
659 * If the inode needed a separate buffer with which to log
660 * its extents, then free it now.
661 */
662 if (iip->ili_extents_buf != NULL) {
663 ASSERT(ip->i_d.di_format == XFS_DINODE_FMT_EXTENTS);
664 ASSERT(ip->i_d.di_nextents > 0);
665 ASSERT(iip->ili_format.ilf_fields & XFS_ILOG_DEXT);
666 ASSERT(ip->i_df.if_bytes > 0);
Denys Vlasenkof0e2d932008-05-19 16:31:57 +1000667 kmem_free(iip->ili_extents_buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 iip->ili_extents_buf = NULL;
669 }
670 if (iip->ili_aextents_buf != NULL) {
671 ASSERT(ip->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS);
672 ASSERT(ip->i_d.di_anextents > 0);
673 ASSERT(iip->ili_format.ilf_fields & XFS_ILOG_AEXT);
674 ASSERT(ip->i_afp->if_bytes > 0);
Denys Vlasenkof0e2d932008-05-19 16:31:57 +1000675 kmem_free(iip->ili_aextents_buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 iip->ili_aextents_buf = NULL;
677 }
678
679 /*
680 * Figure out if we should unlock the inode or not.
681 */
682 hold = iip->ili_flags & XFS_ILI_HOLD;
683
684 /*
685 * Before clearing out the flags, remember whether we
686 * are holding the inode's IO lock.
687 */
688 iolocked = iip->ili_flags & XFS_ILI_IOLOCKED_ANY;
689
690 /*
691 * Clear out the fields of the inode log item particular
692 * to the current transaction.
693 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 iip->ili_flags = 0;
695
696 /*
697 * Unlock the inode if XFS_ILI_HOLD was not set.
698 */
699 if (!hold) {
700 lock_flags = XFS_ILOCK_EXCL;
701 if (iolocked & XFS_ILI_IOLOCKED_EXCL) {
702 lock_flags |= XFS_IOLOCK_EXCL;
703 } else if (iolocked & XFS_ILI_IOLOCKED_SHARED) {
704 lock_flags |= XFS_IOLOCK_SHARED;
705 }
706 xfs_iput(iip->ili_inode, lock_flags);
707 }
708}
709
710/*
711 * This is called to find out where the oldest active copy of the
712 * inode log item in the on disk log resides now that the last log
713 * write of it completed at the given lsn. Since we always re-log
714 * all dirty data in an inode, the latest copy in the on disk log
715 * is the only one that matters. Therefore, simply return the
716 * given lsn.
717 */
718/*ARGSUSED*/
719STATIC xfs_lsn_t
720xfs_inode_item_committed(
721 xfs_inode_log_item_t *iip,
722 xfs_lsn_t lsn)
723{
724 return (lsn);
725}
726
727/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 * This gets called by xfs_trans_push_ail(), when IOP_TRYLOCK
729 * failed to get the inode flush lock but did get the inode locked SHARED.
730 * 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 +1100731 * marked delayed write. If that's the case, we'll promote it and that will
732 * allow the caller to write the buffer by triggering the xfsbufd to run.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 */
734STATIC void
735xfs_inode_item_pushbuf(
736 xfs_inode_log_item_t *iip)
737{
738 xfs_inode_t *ip;
739 xfs_mount_t *mp;
740 xfs_buf_t *bp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
742 ip = iip->ili_inode;
Christoph Hellwig579aa9c2008-04-22 17:34:00 +1000743 ASSERT(xfs_isilocked(ip, XFS_ILOCK_SHARED));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
745 /*
David Chinnerc63942d2008-08-13 16:41:16 +1000746 * If a flush is not in progress anymore, chances are that the
747 * inode was taken off the AIL. So, just get out.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 */
David Chinnerc63942d2008-08-13 16:41:16 +1000749 if (completion_done(&ip->i_flush) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 ((iip->ili_item.li_flags & XFS_LI_IN_AIL) == 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 xfs_iunlock(ip, XFS_ILOCK_SHARED);
752 return;
753 }
754
755 mp = ip->i_mount;
756 bp = xfs_incore(mp->m_ddev_targp, iip->ili_format.ilf_blkno,
Christoph Hellwig0cadda12010-01-19 09:56:44 +0000757 iip->ili_format.ilf_len, XBF_TRYLOCK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 xfs_iunlock(ip, XFS_ILOCK_SHARED);
Dave Chinnerd808f612010-02-02 10:13:42 +1100760 if (!bp)
761 return;
762 if (XFS_BUF_ISDELAYWRITE(bp))
763 xfs_buf_delwri_promote(bp);
764 xfs_buf_relse(bp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 return;
766}
767
768
769/*
770 * This is called to asynchronously write the inode associated with this
771 * inode log item out to disk. The inode will already have been locked by
772 * a successful call to xfs_inode_item_trylock().
773 */
774STATIC void
775xfs_inode_item_push(
776 xfs_inode_log_item_t *iip)
777{
778 xfs_inode_t *ip;
779
780 ip = iip->ili_inode;
781
Christoph Hellwig579aa9c2008-04-22 17:34:00 +1000782 ASSERT(xfs_isilocked(ip, XFS_ILOCK_SHARED));
David Chinnerc63942d2008-08-13 16:41:16 +1000783 ASSERT(!completion_done(&ip->i_flush));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 /*
785 * Since we were able to lock the inode's flush lock and
786 * we found it on the AIL, the inode must be dirty. This
787 * is because the inode is removed from the AIL while still
788 * holding the flush lock in xfs_iflush_done(). Thus, if
789 * we found it in the AIL and were able to obtain the flush
790 * lock without sleeping, then there must not have been
791 * anyone in the process of flushing the inode.
792 */
793 ASSERT(XFS_FORCED_SHUTDOWN(ip->i_mount) ||
794 iip->ili_format.ilf_fields != 0);
795
796 /*
Dave Chinnerc8543632010-02-06 12:39:36 +1100797 * Push the inode to it's backing buffer. This will not remove the
798 * inode from the AIL - a further push will be required to trigger a
799 * buffer push. However, this allows all the dirty inodes to be pushed
800 * to the buffer before it is pushed to disk. THe buffer IO completion
801 * will pull th einode from the AIL, mark it clean and unlock the flush
802 * lock.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 */
Dave Chinnerc8543632010-02-06 12:39:36 +1100804 (void) xfs_iflush(ip, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 xfs_iunlock(ip, XFS_ILOCK_SHARED);
806
807 return;
808}
809
810/*
811 * XXX rcc - this one really has to do something. Probably needs
812 * to stamp in a new field in the incore inode.
813 */
814/* ARGSUSED */
815STATIC void
816xfs_inode_item_committing(
817 xfs_inode_log_item_t *iip,
818 xfs_lsn_t lsn)
819{
820 iip->ili_last_lsn = lsn;
821 return;
822}
823
824/*
825 * This is the ops vector shared by all buf log items.
826 */
David Chinner7989cb82007-02-10 18:34:56 +1100827static struct xfs_item_ops xfs_inode_item_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 .iop_size = (uint(*)(xfs_log_item_t*))xfs_inode_item_size,
829 .iop_format = (void(*)(xfs_log_item_t*, xfs_log_iovec_t*))
830 xfs_inode_item_format,
831 .iop_pin = (void(*)(xfs_log_item_t*))xfs_inode_item_pin,
Dave Chinner8e123852010-03-08 11:26:03 +1100832 .iop_unpin = (void(*)(xfs_log_item_t*))xfs_inode_item_unpin,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 .iop_unpin_remove = (void(*)(xfs_log_item_t*, xfs_trans_t*))
834 xfs_inode_item_unpin_remove,
835 .iop_trylock = (uint(*)(xfs_log_item_t*))xfs_inode_item_trylock,
836 .iop_unlock = (void(*)(xfs_log_item_t*))xfs_inode_item_unlock,
837 .iop_committed = (xfs_lsn_t(*)(xfs_log_item_t*, xfs_lsn_t))
838 xfs_inode_item_committed,
839 .iop_push = (void(*)(xfs_log_item_t*))xfs_inode_item_push,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 .iop_pushbuf = (void(*)(xfs_log_item_t*))xfs_inode_item_pushbuf,
841 .iop_committing = (void(*)(xfs_log_item_t*, xfs_lsn_t))
842 xfs_inode_item_committing
843};
844
845
846/*
847 * Initialize the inode log item for a newly allocated (in-core) inode.
848 */
849void
850xfs_inode_item_init(
851 xfs_inode_t *ip,
852 xfs_mount_t *mp)
853{
854 xfs_inode_log_item_t *iip;
855
856 ASSERT(ip->i_itemp == NULL);
857 iip = ip->i_itemp = kmem_zone_zalloc(xfs_ili_zone, KM_SLEEP);
858
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 iip->ili_inode = ip;
Dave Chinner43f5efc2010-03-23 10:10:00 +1100860 xfs_log_item_init(mp, &iip->ili_item, XFS_LI_INODE,
861 &xfs_inode_item_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 iip->ili_format.ilf_type = XFS_LI_INODE;
863 iip->ili_format.ilf_ino = ip->i_ino;
Christoph Hellwig92bfc6e2008-11-28 14:23:41 +1100864 iip->ili_format.ilf_blkno = ip->i_imap.im_blkno;
865 iip->ili_format.ilf_len = ip->i_imap.im_len;
866 iip->ili_format.ilf_boffset = ip->i_imap.im_boffset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867}
868
869/*
870 * Free the inode log item and any memory hanging off of it.
871 */
872void
873xfs_inode_item_destroy(
874 xfs_inode_t *ip)
875{
876#ifdef XFS_TRANS_DEBUG
877 if (ip->i_itemp->ili_root_size != 0) {
Denys Vlasenkof0e2d932008-05-19 16:31:57 +1000878 kmem_free(ip->i_itemp->ili_orig_root);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 }
880#endif
881 kmem_zone_free(xfs_ili_zone, ip->i_itemp);
882}
883
884
885/*
886 * This is the inode flushing I/O completion routine. It is called
887 * from interrupt level when the buffer containing the inode is
888 * flushed to disk. It is responsible for removing the inode item
889 * from the AIL if it has not been re-logged, and unlocking the inode's
890 * flush lock.
891 */
892/*ARGSUSED*/
893void
894xfs_iflush_done(
895 xfs_buf_t *bp,
896 xfs_inode_log_item_t *iip)
897{
David Chinner783a2f62008-10-30 17:39:58 +1100898 xfs_inode_t *ip = iip->ili_inode;
899 struct xfs_ail *ailp = iip->ili_item.li_ailp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900
901 /*
902 * We only want to pull the item from the AIL if it is
903 * actually there and its location in the log has not
904 * changed since we started the flush. Thus, we only bother
905 * if the ili_logged flag is set and the inode's lsn has not
906 * changed. First we check the lsn outside
907 * the lock since it's cheaper, and then we recheck while
908 * holding the lock before removing the inode from the AIL.
909 */
910 if (iip->ili_logged &&
911 (iip->ili_item.li_lsn == iip->ili_flush_lsn)) {
David Chinner783a2f62008-10-30 17:39:58 +1100912 spin_lock(&ailp->xa_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 if (iip->ili_item.li_lsn == iip->ili_flush_lsn) {
David Chinner783a2f62008-10-30 17:39:58 +1100914 /* xfs_trans_ail_delete() drops the AIL lock. */
915 xfs_trans_ail_delete(ailp, (xfs_log_item_t*)iip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 } else {
David Chinner783a2f62008-10-30 17:39:58 +1100917 spin_unlock(&ailp->xa_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 }
919 }
920
921 iip->ili_logged = 0;
922
923 /*
924 * Clear the ili_last_fields bits now that we know that the
925 * data corresponding to them is safely on disk.
926 */
927 iip->ili_last_fields = 0;
928
929 /*
930 * Release the inode's flush lock since we're done with it.
931 */
932 xfs_ifunlock(ip);
933
934 return;
935}
936
937/*
938 * This is the inode flushing abort routine. It is called
939 * from xfs_iflush when the filesystem is shutting down to clean
940 * up the inode state.
941 * It is responsible for removing the inode item
942 * from the AIL if it has not been re-logged, and unlocking the inode's
943 * flush lock.
944 */
945void
946xfs_iflush_abort(
947 xfs_inode_t *ip)
948{
David Chinner783a2f62008-10-30 17:39:58 +1100949 xfs_inode_log_item_t *iip = ip->i_itemp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 xfs_mount_t *mp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
952 iip = ip->i_itemp;
953 mp = ip->i_mount;
954 if (iip) {
David Chinner783a2f62008-10-30 17:39:58 +1100955 struct xfs_ail *ailp = iip->ili_item.li_ailp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 if (iip->ili_item.li_flags & XFS_LI_IN_AIL) {
David Chinner783a2f62008-10-30 17:39:58 +1100957 spin_lock(&ailp->xa_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 if (iip->ili_item.li_flags & XFS_LI_IN_AIL) {
David Chinner783a2f62008-10-30 17:39:58 +1100959 /* xfs_trans_ail_delete() drops the AIL lock. */
960 xfs_trans_ail_delete(ailp, (xfs_log_item_t *)iip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 } else
David Chinner783a2f62008-10-30 17:39:58 +1100962 spin_unlock(&ailp->xa_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 }
964 iip->ili_logged = 0;
965 /*
966 * Clear the ili_last_fields bits now that we know that the
967 * data corresponding to them is safely on disk.
968 */
969 iip->ili_last_fields = 0;
970 /*
971 * Clear the inode logging fields so no more flushes are
972 * attempted.
973 */
974 iip->ili_format.ilf_fields = 0;
975 }
976 /*
977 * Release the inode's flush lock since we're done with it.
978 */
979 xfs_ifunlock(ip);
980}
981
982void
983xfs_istale_done(
984 xfs_buf_t *bp,
985 xfs_inode_log_item_t *iip)
986{
987 xfs_iflush_abort(iip->ili_inode);
988}
Tim Shimmin6d192a92006-06-09 14:55:38 +1000989
990/*
991 * convert an xfs_inode_log_format struct from either 32 or 64 bit versions
992 * (which can have different field alignments) to the native version
993 */
994int
995xfs_inode_item_format_convert(
996 xfs_log_iovec_t *buf,
997 xfs_inode_log_format_t *in_f)
998{
999 if (buf->i_len == sizeof(xfs_inode_log_format_32_t)) {
1000 xfs_inode_log_format_32_t *in_f32;
1001
1002 in_f32 = (xfs_inode_log_format_32_t *)buf->i_addr;
1003 in_f->ilf_type = in_f32->ilf_type;
1004 in_f->ilf_size = in_f32->ilf_size;
1005 in_f->ilf_fields = in_f32->ilf_fields;
1006 in_f->ilf_asize = in_f32->ilf_asize;
1007 in_f->ilf_dsize = in_f32->ilf_dsize;
1008 in_f->ilf_ino = in_f32->ilf_ino;
1009 /* copy biggest field of ilf_u */
1010 memcpy(in_f->ilf_u.ilfu_uuid.__u_bits,
1011 in_f32->ilf_u.ilfu_uuid.__u_bits,
1012 sizeof(uuid_t));
1013 in_f->ilf_blkno = in_f32->ilf_blkno;
1014 in_f->ilf_len = in_f32->ilf_len;
1015 in_f->ilf_boffset = in_f32->ilf_boffset;
1016 return 0;
1017 } else if (buf->i_len == sizeof(xfs_inode_log_format_64_t)){
1018 xfs_inode_log_format_64_t *in_f64;
1019
1020 in_f64 = (xfs_inode_log_format_64_t *)buf->i_addr;
1021 in_f->ilf_type = in_f64->ilf_type;
1022 in_f->ilf_size = in_f64->ilf_size;
1023 in_f->ilf_fields = in_f64->ilf_fields;
1024 in_f->ilf_asize = in_f64->ilf_asize;
1025 in_f->ilf_dsize = in_f64->ilf_dsize;
1026 in_f->ilf_ino = in_f64->ilf_ino;
1027 /* copy biggest field of ilf_u */
1028 memcpy(in_f->ilf_u.ilfu_uuid.__u_bits,
1029 in_f64->ilf_u.ilfu_uuid.__u_bits,
1030 sizeof(uuid_t));
1031 in_f->ilf_blkno = in_f64->ilf_blkno;
1032 in_f->ilf_len = in_f64->ilf_len;
1033 in_f->ilf_boffset = in_f64->ilf_boffset;
1034 return 0;
1035 }
1036 return EFSCORRUPTED;
1037}