1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include "xfs.h"
19#include "xfs_fs.h"
20#include "xfs_types.h"
21#include "xfs_bit.h"
22#include "xfs_log.h"
23#include "xfs_inum.h"
24#include "xfs_trans.h"
25#include "xfs_buf_item.h"
26#include "xfs_sb.h"
27#include "xfs_ag.h"
28#include "xfs_dir2.h"
29#include "xfs_dmapi.h"
30#include "xfs_mount.h"
31#include "xfs_trans_priv.h"
32#include "xfs_bmap_btree.h"
33#include "xfs_alloc_btree.h"
34#include "xfs_ialloc_btree.h"
35#include "xfs_dir2_sf.h"
36#include "xfs_attr_sf.h"
37#include "xfs_dinode.h"
38#include "xfs_inode.h"
39#include "xfs_inode_item.h"
40#include "xfs_btree.h"
41#include "xfs_ialloc.h"
42#include "xfs_rw.h"
43
44
45kmem_zone_t *xfs_ili_zone;
46
47
48
49
50
51
52
53
54STATIC uint
55xfs_inode_item_size(
56 xfs_inode_log_item_t *iip)
57{
58 uint nvecs;
59 xfs_inode_t *ip;
60
61 ip = iip->ili_inode;
62 nvecs = 2;
63
64
65
66
67
68 iip->ili_format.ilf_fields |= XFS_ILOG_CORE;
69
70 switch (ip->i_d.di_format) {
71 case XFS_DINODE_FMT_EXTENTS:
72 iip->ili_format.ilf_fields &=
73 ~(XFS_ILOG_DDATA | XFS_ILOG_DBROOT |
74 XFS_ILOG_DEV | XFS_ILOG_UUID);
75 if ((iip->ili_format.ilf_fields & XFS_ILOG_DEXT) &&
76 (ip->i_d.di_nextents > 0) &&
77 (ip->i_df.if_bytes > 0)) {
78 ASSERT(ip->i_df.if_u1.if_extents != NULL);
79 nvecs++;
80 } else {
81 iip->ili_format.ilf_fields &= ~XFS_ILOG_DEXT;
82 }
83 break;
84
85 case XFS_DINODE_FMT_BTREE:
86 ASSERT(ip->i_df.if_ext_max ==
87 XFS_IFORK_DSIZE(ip) / (uint)sizeof(xfs_bmbt_rec_t));
88 iip->ili_format.ilf_fields &=
89 ~(XFS_ILOG_DDATA | XFS_ILOG_DEXT |
90 XFS_ILOG_DEV | XFS_ILOG_UUID);
91 if ((iip->ili_format.ilf_fields & XFS_ILOG_DBROOT) &&
92 (ip->i_df.if_broot_bytes > 0)) {
93 ASSERT(ip->i_df.if_broot != NULL);
94 nvecs++;
95 } else {
96 ASSERT(!(iip->ili_format.ilf_fields &
97 XFS_ILOG_DBROOT));
98#ifdef XFS_TRANS_DEBUG
99 if (iip->ili_root_size > 0) {
100 ASSERT(iip->ili_root_size ==
101 ip->i_df.if_broot_bytes);
102 ASSERT(memcmp(iip->ili_orig_root,
103 ip->i_df.if_broot,
104 iip->ili_root_size) == 0);
105 } else {
106 ASSERT(ip->i_df.if_broot_bytes == 0);
107 }
108#endif
109 iip->ili_format.ilf_fields &= ~XFS_ILOG_DBROOT;
110 }
111 break;
112
113 case XFS_DINODE_FMT_LOCAL:
114 iip->ili_format.ilf_fields &=
115 ~(XFS_ILOG_DEXT | XFS_ILOG_DBROOT |
116 XFS_ILOG_DEV | XFS_ILOG_UUID);
117 if ((iip->ili_format.ilf_fields & XFS_ILOG_DDATA) &&
118 (ip->i_df.if_bytes > 0)) {
119 ASSERT(ip->i_df.if_u1.if_data != NULL);
120 ASSERT(ip->i_d.di_size > 0);
121 nvecs++;
122 } else {
123 iip->ili_format.ilf_fields &= ~XFS_ILOG_DDATA;
124 }
125 break;
126
127 case XFS_DINODE_FMT_DEV:
128 iip->ili_format.ilf_fields &=
129 ~(XFS_ILOG_DDATA | XFS_ILOG_DBROOT |
130 XFS_ILOG_DEXT | XFS_ILOG_UUID);
131 break;
132
133 case XFS_DINODE_FMT_UUID:
134 iip->ili_format.ilf_fields &=
135 ~(XFS_ILOG_DDATA | XFS_ILOG_DBROOT |
136 XFS_ILOG_DEXT | XFS_ILOG_DEV);
137 break;
138
139 default:
140 ASSERT(0);
141 break;
142 }
143
144
145
146
147
148
149 if (!XFS_IFORK_Q(ip)) {
150 iip->ili_format.ilf_fields &=
151 ~(XFS_ILOG_ADATA | XFS_ILOG_ABROOT | XFS_ILOG_AEXT);
152 return nvecs;
153 }
154
155
156
157
158 switch (ip->i_d.di_aformat) {
159 case XFS_DINODE_FMT_EXTENTS:
160 iip->ili_format.ilf_fields &=
161 ~(XFS_ILOG_ADATA | XFS_ILOG_ABROOT);
162 if ((iip->ili_format.ilf_fields & XFS_ILOG_AEXT) &&
163 (ip->i_d.di_anextents > 0) &&
164 (ip->i_afp->if_bytes > 0)) {
165 ASSERT(ip->i_afp->if_u1.if_extents != NULL);
166 nvecs++;
167 } else {
168 iip->ili_format.ilf_fields &= ~XFS_ILOG_AEXT;
169 }
170 break;
171
172 case XFS_DINODE_FMT_BTREE:
173 iip->ili_format.ilf_fields &=
174 ~(XFS_ILOG_ADATA | XFS_ILOG_AEXT);
175 if ((iip->ili_format.ilf_fields & XFS_ILOG_ABROOT) &&
176 (ip->i_afp->if_broot_bytes > 0)) {
177 ASSERT(ip->i_afp->if_broot != NULL);
178 nvecs++;
179 } else {
180 iip->ili_format.ilf_fields &= ~XFS_ILOG_ABROOT;
181 }
182 break;
183
184 case XFS_DINODE_FMT_LOCAL:
185 iip->ili_format.ilf_fields &=
186 ~(XFS_ILOG_AEXT | XFS_ILOG_ABROOT);
187 if ((iip->ili_format.ilf_fields & XFS_ILOG_ADATA) &&
188 (ip->i_afp->if_bytes > 0)) {
189 ASSERT(ip->i_afp->if_u1.if_data != NULL);
190 nvecs++;
191 } else {
192 iip->ili_format.ilf_fields &= ~XFS_ILOG_ADATA;
193 }
194 break;
195
196 default:
197 ASSERT(0);
198 break;
199 }
200
201 return nvecs;
202}
203
204
205
206
207
208
209
210
211STATIC void
212xfs_inode_item_format(
213 xfs_inode_log_item_t *iip,
214 xfs_log_iovec_t *log_vector)
215{
216 uint nvecs;
217 xfs_log_iovec_t *vecp;
218 xfs_inode_t *ip;
219 size_t data_bytes;
220 xfs_bmbt_rec_t *ext_buffer;
221 int nrecs;
222 xfs_mount_t *mp;
223
224 ip = iip->ili_inode;
225 vecp = log_vector;
226
227 vecp->i_addr = (xfs_caddr_t)&iip->ili_format;
228 vecp->i_len = sizeof(xfs_inode_log_format_t);
229 XLOG_VEC_SET_TYPE(vecp, XLOG_REG_TYPE_IFORMAT);
230 vecp++;
231 nvecs = 1;
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259 if (ip->i_update_core) {
260 ip->i_update_core = 0;
261 SYNCHRONIZE();
262 }
263
264
265
266
267
268
269 if (ip->i_update_size)
270 ip->i_update_size = 0;
271
272
273
274
275 xfs_synchronize_atime(ip);
276
277 vecp->i_addr = (xfs_caddr_t)&ip->i_d;
278 vecp->i_len = sizeof(xfs_dinode_core_t);
279 XLOG_VEC_SET_TYPE(vecp, XLOG_REG_TYPE_ICORE);
280 vecp++;
281 nvecs++;
282 iip->ili_format.ilf_fields |= XFS_ILOG_CORE;
283
284
285
286
287
288
289
290
291
292 mp = ip->i_mount;
293 ASSERT(ip->i_d.di_version == XFS_DINODE_VERSION_1 ||
294 XFS_SB_VERSION_HASNLINK(&mp->m_sb));
295 if (ip->i_d.di_version == XFS_DINODE_VERSION_1) {
296 if (!XFS_SB_VERSION_HASNLINK(&mp->m_sb)) {
297
298
299
300 ASSERT(ip->i_d.di_nlink <= XFS_MAXLINK_1);
301 ip->i_d.di_onlink = ip->i_d.di_nlink;
302 } else {
303
304
305
306
307
308 ip->i_d.di_version = XFS_DINODE_VERSION_2;
309 ip->i_d.di_onlink = 0;
310 memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
311 }
312 }
313
314 switch (ip->i_d.di_format) {
315 case XFS_DINODE_FMT_EXTENTS:
316 ASSERT(!(iip->ili_format.ilf_fields &
317 (XFS_ILOG_DDATA | XFS_ILOG_DBROOT |
318 XFS_ILOG_DEV | XFS_ILOG_UUID)));
319 if (iip->ili_format.ilf_fields & XFS_ILOG_DEXT) {
320 ASSERT(ip->i_df.if_bytes > 0);
321 ASSERT(ip->i_df.if_u1.if_extents != NULL);
322 ASSERT(ip->i_d.di_nextents > 0);
323 ASSERT(iip->ili_extents_buf == NULL);
324 nrecs = ip->i_df.if_bytes /
325 (uint)sizeof(xfs_bmbt_rec_t);
326 ASSERT(nrecs > 0);
327#ifdef XFS_NATIVE_HOST
328 if (nrecs == ip->i_d.di_nextents) {
329
330
331
332
333
334 vecp->i_addr =
335 (char *)(ip->i_df.if_u1.if_extents);
336 vecp->i_len = ip->i_df.if_bytes;
337 XLOG_VEC_SET_TYPE(vecp, XLOG_REG_TYPE_IEXT);
338 } else
339#endif
340 {
341
342
343
344
345
346
347
348
349
350 ext_buffer = kmem_alloc(ip->i_df.if_bytes,
351 KM_SLEEP);
352 iip->ili_extents_buf = ext_buffer;
353 vecp->i_addr = (xfs_caddr_t)ext_buffer;
354 vecp->i_len = xfs_iextents_copy(ip, ext_buffer,
355 XFS_DATA_FORK);
356 XLOG_VEC_SET_TYPE(vecp, XLOG_REG_TYPE_IEXT);
357 }
358 ASSERT(vecp->i_len <= ip->i_df.if_bytes);
359 iip->ili_format.ilf_dsize = vecp->i_len;
360 vecp++;
361 nvecs++;
362 }
363 break;
364
365 case XFS_DINODE_FMT_BTREE:
366 ASSERT(!(iip->ili_format.ilf_fields &
367 (XFS_ILOG_DDATA | XFS_ILOG_DEXT |
368 XFS_ILOG_DEV | XFS_ILOG_UUID)));
369 if (iip->ili_format.ilf_fields & XFS_ILOG_DBROOT) {
370 ASSERT(ip->i_df.if_broot_bytes > 0);
371 ASSERT(ip->i_df.if_broot != NULL);
372 vecp->i_addr = (xfs_caddr_t)ip->i_df.if_broot;
373 vecp->i_len = ip->i_df.if_broot_bytes;
374 XLOG_VEC_SET_TYPE(vecp, XLOG_REG_TYPE_IBROOT);
375 vecp++;
376 nvecs++;
377 iip->ili_format.ilf_dsize = ip->i_df.if_broot_bytes;
378 }
379 break;
380
381 case XFS_DINODE_FMT_LOCAL:
382 ASSERT(!(iip->ili_format.ilf_fields &
383 (XFS_ILOG_DBROOT | XFS_ILOG_DEXT |
384 XFS_ILOG_DEV | XFS_ILOG_UUID)));
385 if (iip->ili_format.ilf_fields & XFS_ILOG_DDATA) {
386 ASSERT(ip->i_df.if_bytes > 0);
387 ASSERT(ip->i_df.if_u1.if_data != NULL);
388 ASSERT(ip->i_d.di_size > 0);
389
390 vecp->i_addr = (xfs_caddr_t)ip->i_df.if_u1.if_data;
391
392
393
394
395
396 data_bytes = roundup(ip->i_df.if_bytes, 4);
397 ASSERT((ip->i_df.if_real_bytes == 0) ||
398 (ip->i_df.if_real_bytes == data_bytes));
399 vecp->i_len = (int)data_bytes;
400 XLOG_VEC_SET_TYPE(vecp, XLOG_REG_TYPE_ILOCAL);
401 vecp++;
402 nvecs++;
403 iip->ili_format.ilf_dsize = (unsigned)data_bytes;
404 }
405 break;
406
407 case XFS_DINODE_FMT_DEV:
408 ASSERT(!(iip->ili_format.ilf_fields &
409 (XFS_ILOG_DBROOT | XFS_ILOG_DEXT |
410 XFS_ILOG_DDATA | XFS_ILOG_UUID)));
411 if (iip->ili_format.ilf_fields & XFS_ILOG_DEV) {
412 iip->ili_format.ilf_u.ilfu_rdev =
413 ip->i_df.if_u2.if_rdev;
414 }
415 break;
416
417 case XFS_DINODE_FMT_UUID:
418 ASSERT(!(iip->ili_format.ilf_fields &
419 (XFS_ILOG_DBROOT | XFS_ILOG_DEXT |
420 XFS_ILOG_DDATA | XFS_ILOG_DEV)));
421 if (iip->ili_format.ilf_fields & XFS_ILOG_UUID) {
422 iip->ili_format.ilf_u.ilfu_uuid =
423 ip->i_df.if_u2.if_uuid;
424 }
425 break;
426
427 default:
428 ASSERT(0);
429 break;
430 }
431
432
433
434
435
436
437 if (!XFS_IFORK_Q(ip)) {
438 ASSERT(nvecs == iip->ili_item.li_desc->lid_size);
439 iip->ili_format.ilf_size = nvecs;
440 ASSERT(!(iip->ili_format.ilf_fields &
441 (XFS_ILOG_ADATA | XFS_ILOG_ABROOT | XFS_ILOG_AEXT)));
442 return;
443 }
444
445 switch (ip->i_d.di_aformat) {
446 case XFS_DINODE_FMT_EXTENTS:
447 ASSERT(!(iip->ili_format.ilf_fields &
448 (XFS_ILOG_ADATA | XFS_ILOG_ABROOT)));
449 if (iip->ili_format.ilf_fields & XFS_ILOG_AEXT) {
450 ASSERT(ip->i_afp->if_bytes > 0);
451 ASSERT(ip->i_afp->if_u1.if_extents != NULL);
452 ASSERT(ip->i_d.di_anextents > 0);
453#ifdef DEBUG
454 nrecs = ip->i_afp->if_bytes /
455 (uint)sizeof(xfs_bmbt_rec_t);
456#endif
457 ASSERT(nrecs > 0);
458 ASSERT(nrecs == ip->i_d.di_anextents);
459#ifdef XFS_NATIVE_HOST
460
461
462
463
464 vecp->i_addr = (char *)(ip->i_afp->if_u1.if_extents);
465 vecp->i_len = ip->i_afp->if_bytes;
466#else
467 ASSERT(iip->ili_aextents_buf == NULL);
468
469
470
471 ext_buffer = kmem_alloc(ip->i_afp->if_bytes,
472 KM_SLEEP);
473 iip->ili_aextents_buf = ext_buffer;
474 vecp->i_addr = (xfs_caddr_t)ext_buffer;
475 vecp->i_len = xfs_iextents_copy(ip, ext_buffer,
476 XFS_ATTR_FORK);
477#endif
478 XLOG_VEC_SET_TYPE(vecp, XLOG_REG_TYPE_IATTR_EXT);
479 iip->ili_format.ilf_asize = vecp->i_len;
480 vecp++;
481 nvecs++;
482 }
483 break;
484
485 case XFS_DINODE_FMT_BTREE:
486 ASSERT(!(iip->ili_format.ilf_fields &
487 (XFS_ILOG_ADATA | XFS_ILOG_AEXT)));
488 if (iip->ili_format.ilf_fields & XFS_ILOG_ABROOT) {
489 ASSERT(ip->i_afp->if_broot_bytes > 0);
490 ASSERT(ip->i_afp->if_broot != NULL);
491 vecp->i_addr = (xfs_caddr_t)ip->i_afp->if_broot;
492 vecp->i_len = ip->i_afp->if_broot_bytes;
493 XLOG_VEC_SET_TYPE(vecp, XLOG_REG_TYPE_IATTR_BROOT);
494 vecp++;
495 nvecs++;
496 iip->ili_format.ilf_asize = ip->i_afp->if_broot_bytes;
497 }
498 break;
499
500 case XFS_DINODE_FMT_LOCAL:
501 ASSERT(!(iip->ili_format.ilf_fields &
502 (XFS_ILOG_ABROOT | XFS_ILOG_AEXT)));
503 if (iip->ili_format.ilf_fields & XFS_ILOG_ADATA) {
504 ASSERT(ip->i_afp->if_bytes > 0);
505 ASSERT(ip->i_afp->if_u1.if_data != NULL);
506
507 vecp->i_addr = (xfs_caddr_t)ip->i_afp->if_u1.if_data;
508
509
510
511
512
513 data_bytes = roundup(ip->i_afp->if_bytes, 4);
514 ASSERT((ip->i_afp->if_real_bytes == 0) ||
515 (ip->i_afp->if_real_bytes == data_bytes));
516 vecp->i_len = (int)data_bytes;
517 XLOG_VEC_SET_TYPE(vecp, XLOG_REG_TYPE_IATTR_LOCAL);
518 vecp++;
519 nvecs++;
520 iip->ili_format.ilf_asize = (unsigned)data_bytes;
521 }
522 break;
523
524 default:
525 ASSERT(0);
526 break;
527 }
528
529 ASSERT(nvecs == iip->ili_item.li_desc->lid_size);
530 iip->ili_format.ilf_size = nvecs;
531}
532
533
534
535
536
537
538
539
540STATIC void
541xfs_inode_item_pin(
542 xfs_inode_log_item_t *iip)
543{
544 ASSERT(ismrlocked(&(iip->ili_inode->i_lock), MR_UPDATE));
545 xfs_ipin(iip->ili_inode);
546}
547
548
549
550
551
552
553
554
555STATIC void
556xfs_inode_item_unpin(
557 xfs_inode_log_item_t *iip,
558 int stale)
559{
560 xfs_iunpin(iip->ili_inode);
561}
562
563
564STATIC void
565xfs_inode_item_unpin_remove(
566 xfs_inode_log_item_t *iip,
567 xfs_trans_t *tp)
568{
569 xfs_iunpin(iip->ili_inode);
570}
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585STATIC uint
586xfs_inode_item_trylock(
587 xfs_inode_log_item_t *iip)
588{
589 register xfs_inode_t *ip;
590
591 ip = iip->ili_inode;
592
593 if (xfs_ipincount(ip) > 0) {
594 return XFS_ITEM_PINNED;
595 }
596
597 if (!xfs_ilock_nowait(ip, XFS_ILOCK_SHARED)) {
598 return XFS_ITEM_LOCKED;
599 }
600
601 if (!xfs_iflock_nowait(ip)) {
602
603
604
605
606 if (iip->ili_pushbuf_flag == 0) {
607 iip->ili_pushbuf_flag = 1;
608#ifdef DEBUG
609 iip->ili_push_owner = current_pid();
610#endif
611
612
613
614
615 return XFS_ITEM_PUSHBUF;
616 } else {
617
618
619
620
621 xfs_iunlock(ip, XFS_ILOCK_SHARED|XFS_IUNLOCK_NONOTIFY);
622 return XFS_ITEM_FLUSHING;
623 }
624
625 }
626
627
628 if (ip->i_flags & XFS_ISTALE) {
629 xfs_ifunlock(ip);
630 xfs_iunlock(ip, XFS_ILOCK_SHARED|XFS_IUNLOCK_NONOTIFY);
631 return XFS_ITEM_PINNED;
632 }
633
634#ifdef DEBUG
635 if (!XFS_FORCED_SHUTDOWN(ip->i_mount)) {
636 ASSERT(iip->ili_format.ilf_fields != 0);
637 ASSERT(iip->ili_logged == 0);
638 ASSERT(iip->ili_item.li_flags & XFS_LI_IN_AIL);
639 }
640#endif
641 return XFS_ITEM_SUCCESS;
642}
643
644
645
646
647
648
649
650STATIC void
651xfs_inode_item_unlock(
652 xfs_inode_log_item_t *iip)
653{
654 uint hold;
655 uint iolocked;
656 uint lock_flags;
657 xfs_inode_t *ip;
658
659 ASSERT(iip != NULL);
660 ASSERT(iip->ili_inode->i_itemp != NULL);
661 ASSERT(ismrlocked(&(iip->ili_inode->i_lock), MR_UPDATE));
662 ASSERT((!(iip->ili_inode->i_itemp->ili_flags &
663 XFS_ILI_IOLOCKED_EXCL)) ||
664 ismrlocked(&(iip->ili_inode->i_iolock), MR_UPDATE));
665 ASSERT((!(iip->ili_inode->i_itemp->ili_flags &
666 XFS_ILI_IOLOCKED_SHARED)) ||
667 ismrlocked(&(iip->ili_inode->i_iolock), MR_ACCESS));
668
669
670
671 ip = iip->ili_inode;
672 ip->i_transp = NULL;
673
674
675
676
677
678 if (iip->ili_extents_buf != NULL) {
679 ASSERT(ip->i_d.di_format == XFS_DINODE_FMT_EXTENTS);
680 ASSERT(ip->i_d.di_nextents > 0);
681 ASSERT(iip->ili_format.ilf_fields & XFS_ILOG_DEXT);
682 ASSERT(ip->i_df.if_bytes > 0);
683 kmem_free(iip->ili_extents_buf, ip->i_df.if_bytes);
684 iip->ili_extents_buf = NULL;
685 }
686 if (iip->ili_aextents_buf != NULL) {
687 ASSERT(ip->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS);
688 ASSERT(ip->i_d.di_anextents > 0);
689 ASSERT(iip->ili_format.ilf_fields & XFS_ILOG_AEXT);
690 ASSERT(ip->i_afp->if_bytes > 0);
691 kmem_free(iip->ili_aextents_buf, ip->i_afp->if_bytes);
692 iip->ili_aextents_buf = NULL;
693 }
694
695
696
697
698 hold = iip->ili_flags & XFS_ILI_HOLD;
699
700
701
702
703
704 iolocked = iip->ili_flags & XFS_ILI_IOLOCKED_ANY;
705
706
707
708
709
710 iip->ili_ilock_recur = 0;
711 iip->ili_iolock_recur = 0;
712 iip->ili_flags = 0;
713
714
715
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
730
731
732
733
734
735
736
737STATIC xfs_lsn_t
738xfs_inode_item_committed(
739 xfs_inode_log_item_t *iip,
740 xfs_lsn_t lsn)
741{
742 return (lsn);
743}
744
745
746
747
748
749
750
751
752
753
754
755STATIC void
756xfs_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
766 ASSERT(ismrlocked(&(ip->i_lock), MR_ACCESS));
767
768
769
770
771
772 ASSERT(iip->ili_pushbuf_flag != 0);
773 ASSERT(iip->ili_push_owner == current_pid());
774
775
776
777
778
779
780 if (!issemalocked(&(ip->i_flock)) ||
781 ((iip->ili_item.li_flags & XFS_LI_IN_AIL) == 0)) {
782 iip->ili_pushbuf_flag = 0;
783 xfs_iunlock(ip, XFS_ILOCK_SHARED);
784 return;
785 }
786
787 mp = ip->i_mount;
788 bp = xfs_incore(mp->m_ddev_targp, iip->ili_format.ilf_blkno,
789 iip->ili_format.ilf_len, XFS_INCORE_TRYLOCK);
790
791 if (bp != NULL) {
792 if (XFS_BUF_ISDELAYWRITE(bp)) {
793
794
795
796
797
798
799
800
801 dopush = ((iip->ili_item.li_flags & XFS_LI_IN_AIL) &&
802 issemalocked(&(ip->i_flock)));
803 iip->ili_pushbuf_flag = 0;
804 xfs_iunlock(ip, XFS_ILOCK_SHARED);
805 xfs_buftrace("INODE ITEM PUSH", bp);
806 if (XFS_BUF_ISPINNED(bp)) {
807 xfs_log_force(mp, (xfs_lsn_t)0,
808 XFS_LOG_FORCE);
809 }
810 if (dopush) {
811 xfs_bawrite(mp, bp);
812 } else {
813 xfs_buf_relse(bp);
814 }
815 } else {
816 iip->ili_pushbuf_flag = 0;
817 xfs_iunlock(ip, XFS_ILOCK_SHARED);
818 xfs_buf_relse(bp);
819 }
820 return;
821 }
822
823
824
825
826
827
828
829
830 iip->ili_pushbuf_flag = 0;
831 xfs_iunlock(ip, XFS_ILOCK_SHARED);
832 return;
833}
834
835
836
837
838
839
840
841STATIC void
842xfs_inode_item_push(
843 xfs_inode_log_item_t *iip)
844{
845 xfs_inode_t *ip;
846
847 ip = iip->ili_inode;
848
849 ASSERT(ismrlocked(&(ip->i_lock), MR_ACCESS));
850 ASSERT(issemalocked(&(ip->i_flock)));
851
852
853
854
855
856
857
858
859
860 ASSERT(XFS_FORCED_SHUTDOWN(ip->i_mount) ||
861 iip->ili_format.ilf_fields != 0);
862
863
864
865
866
867 (void) xfs_iflush(ip, XFS_IFLUSH_ASYNC);
868 xfs_iunlock(ip, XFS_ILOCK_SHARED);
869
870 return;
871}
872
873
874
875
876
877
878STATIC void
879xfs_inode_item_committing(
880 xfs_inode_log_item_t *iip,
881 xfs_lsn_t lsn)
882{
883 iip->ili_last_lsn = lsn;
884 return;
885}
886
887
888
889
890static struct xfs_item_ops xfs_inode_item_ops = {
891 .iop_size = (uint(*)(xfs_log_item_t*))xfs_inode_item_size,
892 .iop_format = (void(*)(xfs_log_item_t*, xfs_log_iovec_t*))
893 xfs_inode_item_format,
894 .iop_pin = (void(*)(xfs_log_item_t*))xfs_inode_item_pin,
895 .iop_unpin = (void(*)(xfs_log_item_t*, int))xfs_inode_item_unpin,
896 .iop_unpin_remove = (void(*)(xfs_log_item_t*, xfs_trans_t*))
897 xfs_inode_item_unpin_remove,
898 .iop_trylock = (uint(*)(xfs_log_item_t*))xfs_inode_item_trylock,
899 .iop_unlock = (void(*)(xfs_log_item_t*))xfs_inode_item_unlock,
900 .iop_committed = (xfs_lsn_t(*)(xfs_log_item_t*, xfs_lsn_t))
901 xfs_inode_item_committed,
902 .iop_push = (void(*)(xfs_log_item_t*))xfs_inode_item_push,
903 .iop_pushbuf = (void(*)(xfs_log_item_t*))xfs_inode_item_pushbuf,
904 .iop_committing = (void(*)(xfs_log_item_t*, xfs_lsn_t))
905 xfs_inode_item_committing
906};
907
908
909
910
911
912void
913xfs_inode_item_init(
914 xfs_inode_t *ip,
915 xfs_mount_t *mp)
916{
917 xfs_inode_log_item_t *iip;
918
919 ASSERT(ip->i_itemp == NULL);
920 iip = ip->i_itemp = kmem_zone_zalloc(xfs_ili_zone, KM_SLEEP);
921
922 iip->ili_item.li_type = XFS_LI_INODE;
923 iip->ili_item.li_ops = &xfs_inode_item_ops;
924 iip->ili_item.li_mountp = mp;
925 iip->ili_inode = ip;
926
927
928
929
930
931
932
933 iip->ili_format.ilf_type = XFS_LI_INODE;
934 iip->ili_format.ilf_ino = ip->i_ino;
935 iip->ili_format.ilf_blkno = ip->i_blkno;
936 iip->ili_format.ilf_len = ip->i_len;
937 iip->ili_format.ilf_boffset = ip->i_boffset;
938}
939
940
941
942
943void
944xfs_inode_item_destroy(
945 xfs_inode_t *ip)
946{
947#ifdef XFS_TRANS_DEBUG
948 if (ip->i_itemp->ili_root_size != 0) {
949 kmem_free(ip->i_itemp->ili_orig_root,
950 ip->i_itemp->ili_root_size);
951 }
952#endif
953 kmem_zone_free(xfs_ili_zone, ip->i_itemp);
954}
955
956
957
958
959
960
961
962
963
964
965void
966xfs_iflush_done(
967 xfs_buf_t *bp,
968 xfs_inode_log_item_t *iip)
969{
970 xfs_inode_t *ip;
971 SPLDECL(s);
972
973 ip = iip->ili_inode;
974
975
976
977
978
979
980
981
982
983
984 if (iip->ili_logged &&
985 (iip->ili_item.li_lsn == iip->ili_flush_lsn)) {
986 AIL_LOCK(ip->i_mount, s);
987 if (iip->ili_item.li_lsn == iip->ili_flush_lsn) {
988
989
990
991 xfs_trans_delete_ail(ip->i_mount,
992 (xfs_log_item_t*)iip, s);
993 } else {
994 AIL_UNLOCK(ip->i_mount, s);
995 }
996 }
997
998 iip->ili_logged = 0;
999
1000
1001
1002
1003
1004 iip->ili_last_fields = 0;
1005
1006
1007
1008
1009 xfs_ifunlock(ip);
1010
1011 return;
1012}
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022void
1023xfs_iflush_abort(
1024 xfs_inode_t *ip)
1025{
1026 xfs_inode_log_item_t *iip;
1027 xfs_mount_t *mp;
1028 SPLDECL(s);
1029
1030 iip = ip->i_itemp;
1031 mp = ip->i_mount;
1032 if (iip) {
1033 if (iip->ili_item.li_flags & XFS_LI_IN_AIL) {
1034 AIL_LOCK(mp, s);
1035 if (iip->ili_item.li_flags & XFS_LI_IN_AIL) {
1036
1037
1038
1039 xfs_trans_delete_ail(mp, (xfs_log_item_t *)iip,
1040 s);
1041 } else
1042 AIL_UNLOCK(mp, s);
1043 }
1044 iip->ili_logged = 0;
1045
1046
1047
1048
1049 iip->ili_last_fields = 0;
1050
1051
1052
1053
1054 iip->ili_format.ilf_fields = 0;
1055 }
1056
1057
1058
1059 xfs_ifunlock(ip);
1060}
1061
1062void
1063xfs_istale_done(
1064 xfs_buf_t *bp,
1065 xfs_inode_log_item_t *iip)
1066{
1067 xfs_iflush_abort(iip->ili_inode);
1068}
1069
1070
1071
1072
1073
1074int
1075xfs_inode_item_format_convert(
1076 xfs_log_iovec_t *buf,
1077 xfs_inode_log_format_t *in_f)
1078{
1079 if (buf->i_len == sizeof(xfs_inode_log_format_32_t)) {
1080 xfs_inode_log_format_32_t *in_f32;
1081
1082 in_f32 = (xfs_inode_log_format_32_t *)buf->i_addr;
1083 in_f->ilf_type = in_f32->ilf_type;
1084 in_f->ilf_size = in_f32->ilf_size;
1085 in_f->ilf_fields = in_f32->ilf_fields;
1086 in_f->ilf_asize = in_f32->ilf_asize;
1087 in_f->ilf_dsize = in_f32->ilf_dsize;
1088 in_f->ilf_ino = in_f32->ilf_ino;
1089
1090 memcpy(in_f->ilf_u.ilfu_uuid.__u_bits,
1091 in_f32->ilf_u.ilfu_uuid.__u_bits,
1092 sizeof(uuid_t));
1093 in_f->ilf_blkno = in_f32->ilf_blkno;
1094 in_f->ilf_len = in_f32->ilf_len;
1095 in_f->ilf_boffset = in_f32->ilf_boffset;
1096 return 0;
1097 } else if (buf->i_len == sizeof(xfs_inode_log_format_64_t)){
1098 xfs_inode_log_format_64_t *in_f64;
1099
1100 in_f64 = (xfs_inode_log_format_64_t *)buf->i_addr;
1101 in_f->ilf_type = in_f64->ilf_type;
1102 in_f->ilf_size = in_f64->ilf_size;
1103 in_f->ilf_fields = in_f64->ilf_fields;
1104 in_f->ilf_asize = in_f64->ilf_asize;
1105 in_f->ilf_dsize = in_f64->ilf_dsize;
1106 in_f->ilf_ino = in_f64->ilf_ino;
1107
1108 memcpy(in_f->ilf_u.ilfu_uuid.__u_bits,
1109 in_f64->ilf_u.ilfu_uuid.__u_bits,
1110 sizeof(uuid_t));
1111 in_f->ilf_blkno = in_f64->ilf_blkno;
1112 in_f->ilf_len = in_f64->ilf_len;
1113 in_f->ilf_boffset = in_f64->ilf_boffset;
1114 return 0;
1115 }
1116 return EFSCORRUPTED;
1117}
1118