1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2022 Oracle. All Rights Reserved.
4 * Author: Allison Henderson <allison.henderson@oracle.com>
9 #include "xfs_format.h"
10 #include "xfs_trans_resv.h"
11 #include "xfs_shared.h"
12 #include "xfs_mount.h"
13 #include "xfs_defer.h"
14 #include "xfs_log_format.h"
15 #include "xfs_trans.h"
16 #include "xfs_bmap_btree.h"
17 #include "xfs_trans_priv.h"
19 #include "xfs_inode.h"
20 #include "xfs_da_format.h"
21 #include "xfs_da_btree.h"
23 #include "xfs_attr_item.h"
24 #include "xfs_trace.h"
25 #include "xfs_trans_space.h"
26 #include "xfs_errortag.h"
27 #include "xfs_error.h"
28 #include "xfs_log_priv.h"
29 #include "xfs_log_recover.h"
31 struct kmem_cache
*xfs_attri_cache
;
32 struct kmem_cache
*xfs_attrd_cache
;
34 static const struct xfs_item_ops xfs_attri_item_ops
;
35 static const struct xfs_item_ops xfs_attrd_item_ops
;
36 static struct xfs_attrd_log_item
*xfs_trans_get_attrd(struct xfs_trans
*tp
,
37 struct xfs_attri_log_item
*attrip
);
39 static inline struct xfs_attri_log_item
*ATTRI_ITEM(struct xfs_log_item
*lip
)
41 return container_of(lip
, struct xfs_attri_log_item
, attri_item
);
45 * Shared xattr name/value buffers for logged extended attribute operations
47 * When logging updates to extended attributes, we can create quite a few
48 * attribute log intent items for a single xattr update. To avoid cycling the
49 * memory allocator and memcpy overhead, the name (and value, for setxattr)
50 * are kept in a refcounted object that is shared across all related log items
51 * and the upper-level deferred work state structure. The shared buffer has
52 * a control structure, followed by the name, and then the value.
55 static inline struct xfs_attri_log_nameval
*
56 xfs_attri_log_nameval_get(
57 struct xfs_attri_log_nameval
*nv
)
59 if (!refcount_inc_not_zero(&nv
->refcount
))
65 xfs_attri_log_nameval_put(
66 struct xfs_attri_log_nameval
*nv
)
70 if (refcount_dec_and_test(&nv
->refcount
))
74 static inline struct xfs_attri_log_nameval
*
75 xfs_attri_log_nameval_alloc(
77 unsigned int name_len
,
79 unsigned int value_len
)
81 struct xfs_attri_log_nameval
*nv
;
84 * This could be over 64kB in length, so we have to use kvmalloc() for
85 * this. But kvmalloc() utterly sucks, so we use our own version.
87 nv
= xlog_kvmalloc(sizeof(struct xfs_attri_log_nameval
) +
88 name_len
+ value_len
);
90 nv
->name
.i_addr
= nv
+ 1;
91 nv
->name
.i_len
= name_len
;
92 nv
->name
.i_type
= XLOG_REG_TYPE_ATTR_NAME
;
93 memcpy(nv
->name
.i_addr
, name
, name_len
);
96 nv
->value
.i_addr
= nv
->name
.i_addr
+ name_len
;
97 nv
->value
.i_len
= value_len
;
98 memcpy(nv
->value
.i_addr
, value
, value_len
);
100 nv
->value
.i_addr
= NULL
;
103 nv
->value
.i_type
= XLOG_REG_TYPE_ATTR_VALUE
;
105 refcount_set(&nv
->refcount
, 1);
111 struct xfs_attri_log_item
*attrip
)
113 kmem_free(attrip
->attri_item
.li_lv_shadow
);
114 xfs_attri_log_nameval_put(attrip
->attri_nameval
);
115 kmem_cache_free(xfs_attri_cache
, attrip
);
119 * Freeing the attrip requires that we remove it from the AIL if it has already
120 * been placed there. However, the ATTRI may not yet have been placed in the
121 * AIL when called by xfs_attri_release() from ATTRD processing due to the
122 * ordering of committed vs unpin operations in bulk insert operations. Hence
123 * the reference count to ensure only the last caller frees the ATTRI.
127 struct xfs_attri_log_item
*attrip
)
129 ASSERT(atomic_read(&attrip
->attri_refcount
) > 0);
130 if (!atomic_dec_and_test(&attrip
->attri_refcount
))
133 xfs_trans_ail_delete(&attrip
->attri_item
, 0);
134 xfs_attri_item_free(attrip
);
139 struct xfs_log_item
*lip
,
143 struct xfs_attri_log_item
*attrip
= ATTRI_ITEM(lip
);
144 struct xfs_attri_log_nameval
*nv
= attrip
->attri_nameval
;
147 *nbytes
+= sizeof(struct xfs_attri_log_format
) +
148 xlog_calc_iovec_len(nv
->name
.i_len
);
150 if (!nv
->value
.i_len
)
154 *nbytes
+= xlog_calc_iovec_len(nv
->value
.i_len
);
158 * This is called to fill in the log iovecs for the given attri log
159 * item. We use 1 iovec for the attri_format_item, 1 for the name, and
160 * another for the value if it is present
163 xfs_attri_item_format(
164 struct xfs_log_item
*lip
,
165 struct xfs_log_vec
*lv
)
167 struct xfs_attri_log_item
*attrip
= ATTRI_ITEM(lip
);
168 struct xfs_log_iovec
*vecp
= NULL
;
169 struct xfs_attri_log_nameval
*nv
= attrip
->attri_nameval
;
171 attrip
->attri_format
.alfi_type
= XFS_LI_ATTRI
;
172 attrip
->attri_format
.alfi_size
= 1;
175 * This size accounting must be done before copying the attrip into the
176 * iovec. If we do it after, the wrong size will be recorded to the log
177 * and we trip across assertion checks for bad region sizes later during
181 ASSERT(nv
->name
.i_len
> 0);
182 attrip
->attri_format
.alfi_size
++;
184 if (nv
->value
.i_len
> 0)
185 attrip
->attri_format
.alfi_size
++;
187 xlog_copy_iovec(lv
, &vecp
, XLOG_REG_TYPE_ATTRI_FORMAT
,
188 &attrip
->attri_format
,
189 sizeof(struct xfs_attri_log_format
));
190 xlog_copy_from_iovec(lv
, &vecp
, &nv
->name
);
191 if (nv
->value
.i_len
> 0)
192 xlog_copy_from_iovec(lv
, &vecp
, &nv
->value
);
196 * The unpin operation is the last place an ATTRI is manipulated in the log. It
197 * is either inserted in the AIL or aborted in the event of a log I/O error. In
198 * either case, the ATTRI transaction has been successfully committed to make
199 * it this far. Therefore, we expect whoever committed the ATTRI to either
200 * construct and commit the ATTRD or drop the ATTRD's reference in the event of
201 * error. Simply drop the log's ATTRI reference now that the log is done with
205 xfs_attri_item_unpin(
206 struct xfs_log_item
*lip
,
209 xfs_attri_release(ATTRI_ITEM(lip
));
214 xfs_attri_item_release(
215 struct xfs_log_item
*lip
)
217 xfs_attri_release(ATTRI_ITEM(lip
));
221 * Allocate and initialize an attri item. Caller may allocate an additional
222 * trailing buffer for name and value
224 STATIC
struct xfs_attri_log_item
*
226 struct xfs_mount
*mp
,
227 struct xfs_attri_log_nameval
*nv
)
229 struct xfs_attri_log_item
*attrip
;
231 attrip
= kmem_cache_zalloc(xfs_attri_cache
, GFP_NOFS
| __GFP_NOFAIL
);
234 * Grab an extra reference to the name/value buffer for this log item.
235 * The caller retains its own reference!
237 attrip
->attri_nameval
= xfs_attri_log_nameval_get(nv
);
238 ASSERT(attrip
->attri_nameval
);
240 xfs_log_item_init(mp
, &attrip
->attri_item
, XFS_LI_ATTRI
,
241 &xfs_attri_item_ops
);
242 attrip
->attri_format
.alfi_id
= (uintptr_t)(void *)attrip
;
243 atomic_set(&attrip
->attri_refcount
, 2);
248 static inline struct xfs_attrd_log_item
*ATTRD_ITEM(struct xfs_log_item
*lip
)
250 return container_of(lip
, struct xfs_attrd_log_item
, attrd_item
);
254 xfs_attrd_item_free(struct xfs_attrd_log_item
*attrdp
)
256 kmem_free(attrdp
->attrd_item
.li_lv_shadow
);
257 kmem_cache_free(xfs_attrd_cache
, attrdp
);
262 struct xfs_log_item
*lip
,
267 *nbytes
+= sizeof(struct xfs_attrd_log_format
);
271 * This is called to fill in the log iovecs for the given attrd log item. We use
272 * only 1 iovec for the attrd_format, and we point that at the attr_log_format
273 * structure embedded in the attrd item.
276 xfs_attrd_item_format(
277 struct xfs_log_item
*lip
,
278 struct xfs_log_vec
*lv
)
280 struct xfs_attrd_log_item
*attrdp
= ATTRD_ITEM(lip
);
281 struct xfs_log_iovec
*vecp
= NULL
;
283 attrdp
->attrd_format
.alfd_type
= XFS_LI_ATTRD
;
284 attrdp
->attrd_format
.alfd_size
= 1;
286 xlog_copy_iovec(lv
, &vecp
, XLOG_REG_TYPE_ATTRD_FORMAT
,
287 &attrdp
->attrd_format
,
288 sizeof(struct xfs_attrd_log_format
));
292 * The ATTRD is either committed or aborted if the transaction is canceled. If
293 * the transaction is canceled, drop our reference to the ATTRI and free the
297 xfs_attrd_item_release(
298 struct xfs_log_item
*lip
)
300 struct xfs_attrd_log_item
*attrdp
= ATTRD_ITEM(lip
);
302 xfs_attri_release(attrdp
->attrd_attrip
);
303 xfs_attrd_item_free(attrdp
);
306 static struct xfs_log_item
*
307 xfs_attrd_item_intent(
308 struct xfs_log_item
*lip
)
310 return &ATTRD_ITEM(lip
)->attrd_attrip
->attri_item
;
314 * Performs one step of an attribute update intent and marks the attrd item
315 * dirty.. An attr operation may be a set or a remove. Note that the
316 * transaction is marked dirty regardless of whether the operation succeeds or
317 * fails to support the ATTRI/ATTRD lifecycle rules.
320 xfs_xattri_finish_update(
321 struct xfs_attr_intent
*attr
,
322 struct xfs_attrd_log_item
*attrdp
)
324 struct xfs_da_args
*args
= attr
->xattri_da_args
;
327 if (XFS_TEST_ERROR(false, args
->dp
->i_mount
, XFS_ERRTAG_LARP
)) {
332 error
= xfs_attr_set_iter(attr
);
333 if (!error
&& attr
->xattri_dela_state
!= XFS_DAS_DONE
)
337 * Mark the transaction dirty, even on error. This ensures the
338 * transaction is aborted, which:
340 * 1.) releases the ATTRI and frees the ATTRD
341 * 2.) shuts down the filesystem
343 args
->trans
->t_flags
|= XFS_TRANS_DIRTY
| XFS_TRANS_HAS_INTENT_DONE
;
346 * attr intent/done items are null when logged attributes are disabled
349 set_bit(XFS_LI_DIRTY
, &attrdp
->attrd_item
.li_flags
);
354 /* Log an attr to the intent item. */
357 struct xfs_trans
*tp
,
358 struct xfs_attri_log_item
*attrip
,
359 const struct xfs_attr_intent
*attr
)
361 struct xfs_attri_log_format
*attrp
;
363 tp
->t_flags
|= XFS_TRANS_DIRTY
;
364 set_bit(XFS_LI_DIRTY
, &attrip
->attri_item
.li_flags
);
367 * At this point the xfs_attr_intent has been constructed, and we've
368 * created the log intent. Fill in the attri log item and log format
369 * structure with fields from this xfs_attr_intent
371 attrp
= &attrip
->attri_format
;
372 attrp
->alfi_ino
= attr
->xattri_da_args
->dp
->i_ino
;
373 ASSERT(!(attr
->xattri_op_flags
& ~XFS_ATTRI_OP_FLAGS_TYPE_MASK
));
374 attrp
->alfi_op_flags
= attr
->xattri_op_flags
;
375 attrp
->alfi_value_len
= attr
->xattri_nameval
->value
.i_len
;
376 attrp
->alfi_name_len
= attr
->xattri_nameval
->name
.i_len
;
377 ASSERT(!(attr
->xattri_da_args
->attr_filter
& ~XFS_ATTRI_FILTER_MASK
));
378 attrp
->alfi_attr_filter
= attr
->xattri_da_args
->attr_filter
;
382 static struct xfs_log_item
*
383 xfs_attr_create_intent(
384 struct xfs_trans
*tp
,
385 struct list_head
*items
,
389 struct xfs_mount
*mp
= tp
->t_mountp
;
390 struct xfs_attri_log_item
*attrip
;
391 struct xfs_attr_intent
*attr
;
392 struct xfs_da_args
*args
;
397 * Each attr item only performs one attribute operation at a time, so
398 * this is a list of one
400 attr
= list_first_entry_or_null(items
, struct xfs_attr_intent
,
402 args
= attr
->xattri_da_args
;
404 if (!(args
->op_flags
& XFS_DA_OP_LOGGED
))
408 * Create a buffer to store the attribute name and value. This buffer
409 * will be shared between the higher level deferred xattr work state
410 * and the lower level xattr log items.
412 if (!attr
->xattri_nameval
) {
414 * Transfer our reference to the name/value buffer to the
415 * deferred work state structure.
417 attr
->xattri_nameval
= xfs_attri_log_nameval_alloc(args
->name
,
418 args
->namelen
, args
->value
, args
->valuelen
);
421 attrip
= xfs_attri_init(mp
, attr
->xattri_nameval
);
422 xfs_trans_add_item(tp
, &attrip
->attri_item
);
423 xfs_attr_log_item(tp
, attrip
, attr
);
425 return &attrip
->attri_item
;
430 struct xfs_attr_intent
*attr
)
432 if (attr
->xattri_da_state
)
433 xfs_da_state_free(attr
->xattri_da_state
);
434 xfs_attri_log_nameval_put(attr
->xattri_nameval
);
435 if (attr
->xattri_da_args
->op_flags
& XFS_DA_OP_RECOVERY
)
438 kmem_cache_free(xfs_attr_intent_cache
, attr
);
441 /* Process an attr. */
443 xfs_attr_finish_item(
444 struct xfs_trans
*tp
,
445 struct xfs_log_item
*done
,
446 struct list_head
*item
,
447 struct xfs_btree_cur
**state
)
449 struct xfs_attr_intent
*attr
;
450 struct xfs_attrd_log_item
*done_item
= NULL
;
453 attr
= container_of(item
, struct xfs_attr_intent
, xattri_list
);
455 done_item
= ATTRD_ITEM(done
);
458 * Always reset trans after EAGAIN cycle
459 * since the transaction is new
461 attr
->xattri_da_args
->trans
= tp
;
463 error
= xfs_xattri_finish_update(attr
, done_item
);
464 if (error
!= -EAGAIN
)
465 xfs_attr_free_item(attr
);
470 /* Abort all pending ATTRs. */
472 xfs_attr_abort_intent(
473 struct xfs_log_item
*intent
)
475 xfs_attri_release(ATTRI_ITEM(intent
));
480 xfs_attr_cancel_item(
481 struct list_head
*item
)
483 struct xfs_attr_intent
*attr
;
485 attr
= container_of(item
, struct xfs_attr_intent
, xattri_list
);
486 xfs_attr_free_item(attr
);
490 xfs_attri_item_match(
491 struct xfs_log_item
*lip
,
494 return ATTRI_ITEM(lip
)->attri_format
.alfi_id
== intent_id
;
497 /* Is this recovered ATTRI format ok? */
500 struct xfs_mount
*mp
,
501 struct xfs_attri_log_format
*attrp
)
503 unsigned int op
= attrp
->alfi_op_flags
&
504 XFS_ATTRI_OP_FLAGS_TYPE_MASK
;
506 if (attrp
->__pad
!= 0)
509 if (attrp
->alfi_op_flags
& ~XFS_ATTRI_OP_FLAGS_TYPE_MASK
)
512 if (attrp
->alfi_attr_filter
& ~XFS_ATTRI_FILTER_MASK
)
515 /* alfi_op_flags should be either a set or remove */
517 case XFS_ATTRI_OP_FLAGS_SET
:
518 case XFS_ATTRI_OP_FLAGS_REPLACE
:
519 case XFS_ATTRI_OP_FLAGS_REMOVE
:
525 if (attrp
->alfi_value_len
> XATTR_SIZE_MAX
)
528 if ((attrp
->alfi_name_len
> XATTR_NAME_MAX
) ||
529 (attrp
->alfi_name_len
== 0))
532 return xfs_verify_ino(mp
, attrp
->alfi_ino
);
536 * Process an attr intent item that was recovered from the log. We need to
537 * delete the attr that it describes.
540 xfs_attri_item_recover(
541 struct xfs_log_item
*lip
,
542 struct list_head
*capture_list
)
544 struct xfs_attri_log_item
*attrip
= ATTRI_ITEM(lip
);
545 struct xfs_attr_intent
*attr
;
546 struct xfs_mount
*mp
= lip
->li_log
->l_mp
;
547 struct xfs_inode
*ip
;
548 struct xfs_da_args
*args
;
549 struct xfs_trans
*tp
;
550 struct xfs_trans_res resv
;
551 struct xfs_attri_log_format
*attrp
;
552 struct xfs_attri_log_nameval
*nv
= attrip
->attri_nameval
;
556 struct xfs_attrd_log_item
*done_item
= NULL
;
559 * First check the validity of the attr described by the ATTRI. If any
560 * are bad, then assume that all are bad and just toss the ATTRI.
562 attrp
= &attrip
->attri_format
;
563 if (!xfs_attri_validate(mp
, attrp
) ||
564 !xfs_attr_namecheck(nv
->name
.i_addr
, nv
->name
.i_len
))
565 return -EFSCORRUPTED
;
567 error
= xlog_recover_iget(mp
, attrp
->alfi_ino
, &ip
);
571 attr
= kmem_zalloc(sizeof(struct xfs_attr_intent
) +
572 sizeof(struct xfs_da_args
), KM_NOFS
);
573 args
= (struct xfs_da_args
*)(attr
+ 1);
575 attr
->xattri_da_args
= args
;
576 attr
->xattri_op_flags
= attrp
->alfi_op_flags
&
577 XFS_ATTRI_OP_FLAGS_TYPE_MASK
;
580 * We're reconstructing the deferred work state structure from the
581 * recovered log item. Grab a reference to the name/value buffer and
582 * attach it to the new work state.
584 attr
->xattri_nameval
= xfs_attri_log_nameval_get(nv
);
585 ASSERT(attr
->xattri_nameval
);
588 args
->geo
= mp
->m_attr_geo
;
589 args
->whichfork
= XFS_ATTR_FORK
;
590 args
->name
= nv
->name
.i_addr
;
591 args
->namelen
= nv
->name
.i_len
;
592 args
->hashval
= xfs_da_hashname(args
->name
, args
->namelen
);
593 args
->attr_filter
= attrp
->alfi_attr_filter
& XFS_ATTRI_FILTER_MASK
;
594 args
->op_flags
= XFS_DA_OP_RECOVERY
| XFS_DA_OP_OKNOENT
|
597 ASSERT(xfs_sb_version_haslogxattrs(&mp
->m_sb
));
599 switch (attr
->xattri_op_flags
) {
600 case XFS_ATTRI_OP_FLAGS_SET
:
601 case XFS_ATTRI_OP_FLAGS_REPLACE
:
602 args
->value
= nv
->value
.i_addr
;
603 args
->valuelen
= nv
->value
.i_len
;
604 args
->total
= xfs_attr_calc_size(args
, &local
);
605 if (xfs_inode_hasattr(args
->dp
))
606 attr
->xattri_dela_state
= xfs_attr_init_replace_state(args
);
608 attr
->xattri_dela_state
= xfs_attr_init_add_state(args
);
610 case XFS_ATTRI_OP_FLAGS_REMOVE
:
611 if (!xfs_inode_hasattr(args
->dp
))
613 attr
->xattri_dela_state
= xfs_attr_init_remove_state(args
);
617 error
= -EFSCORRUPTED
;
621 xfs_init_attr_trans(args
, &resv
, &total
);
622 resv
= xlog_recover_resv(&resv
);
623 error
= xfs_trans_alloc(mp
, &resv
, total
, 0, XFS_TRANS_RESERVE
, &tp
);
628 done_item
= xfs_trans_get_attrd(tp
, attrip
);
630 xfs_ilock(ip
, XFS_ILOCK_EXCL
);
631 xfs_trans_ijoin(tp
, ip
, 0);
633 error
= xfs_xattri_finish_update(attr
, done_item
);
634 if (error
== -EAGAIN
) {
636 * There's more work to do, so add the intent item to this
637 * transaction so that we can continue it later.
639 xfs_defer_add(tp
, XFS_DEFER_OPS_TYPE_ATTR
, &attr
->xattri_list
);
640 error
= xfs_defer_ops_capture_and_commit(tp
, capture_list
);
644 xfs_iunlock(ip
, XFS_ILOCK_EXCL
);
649 xfs_trans_cancel(tp
);
653 error
= xfs_defer_ops_capture_and_commit(tp
, capture_list
);
655 xfs_iunlock(ip
, XFS_ILOCK_EXCL
);
658 xfs_attr_free_item(attr
);
662 /* Re-log an intent item to push the log tail forward. */
663 static struct xfs_log_item
*
664 xfs_attri_item_relog(
665 struct xfs_log_item
*intent
,
666 struct xfs_trans
*tp
)
668 struct xfs_attrd_log_item
*attrdp
;
669 struct xfs_attri_log_item
*old_attrip
;
670 struct xfs_attri_log_item
*new_attrip
;
671 struct xfs_attri_log_format
*new_attrp
;
672 struct xfs_attri_log_format
*old_attrp
;
674 old_attrip
= ATTRI_ITEM(intent
);
675 old_attrp
= &old_attrip
->attri_format
;
677 tp
->t_flags
|= XFS_TRANS_DIRTY
;
678 attrdp
= xfs_trans_get_attrd(tp
, old_attrip
);
679 set_bit(XFS_LI_DIRTY
, &attrdp
->attrd_item
.li_flags
);
682 * Create a new log item that shares the same name/value buffer as the
685 new_attrip
= xfs_attri_init(tp
->t_mountp
, old_attrip
->attri_nameval
);
686 new_attrp
= &new_attrip
->attri_format
;
688 new_attrp
->alfi_ino
= old_attrp
->alfi_ino
;
689 new_attrp
->alfi_op_flags
= old_attrp
->alfi_op_flags
;
690 new_attrp
->alfi_value_len
= old_attrp
->alfi_value_len
;
691 new_attrp
->alfi_name_len
= old_attrp
->alfi_name_len
;
692 new_attrp
->alfi_attr_filter
= old_attrp
->alfi_attr_filter
;
694 xfs_trans_add_item(tp
, &new_attrip
->attri_item
);
695 set_bit(XFS_LI_DIRTY
, &new_attrip
->attri_item
.li_flags
);
697 return &new_attrip
->attri_item
;
701 xlog_recover_attri_commit_pass2(
703 struct list_head
*buffer_list
,
704 struct xlog_recover_item
*item
,
707 struct xfs_mount
*mp
= log
->l_mp
;
708 struct xfs_attri_log_item
*attrip
;
709 struct xfs_attri_log_format
*attri_formatp
;
710 struct xfs_attri_log_nameval
*nv
;
711 const void *attr_value
= NULL
;
712 const void *attr_name
;
715 attri_formatp
= item
->ri_buf
[0].i_addr
;
716 attr_name
= item
->ri_buf
[1].i_addr
;
718 /* Validate xfs_attri_log_format before the large memory allocation */
719 len
= sizeof(struct xfs_attri_log_format
);
720 if (item
->ri_buf
[0].i_len
!= len
) {
721 XFS_CORRUPTION_ERROR(__func__
, XFS_ERRLEVEL_LOW
, mp
,
722 item
->ri_buf
[0].i_addr
, item
->ri_buf
[0].i_len
);
723 return -EFSCORRUPTED
;
726 if (!xfs_attri_validate(mp
, attri_formatp
)) {
727 XFS_CORRUPTION_ERROR(__func__
, XFS_ERRLEVEL_LOW
, mp
,
728 item
->ri_buf
[0].i_addr
, item
->ri_buf
[0].i_len
);
729 return -EFSCORRUPTED
;
732 /* Validate the attr name */
733 if (item
->ri_buf
[1].i_len
!=
734 xlog_calc_iovec_len(attri_formatp
->alfi_name_len
)) {
735 XFS_CORRUPTION_ERROR(__func__
, XFS_ERRLEVEL_LOW
, mp
,
736 item
->ri_buf
[0].i_addr
, item
->ri_buf
[0].i_len
);
737 return -EFSCORRUPTED
;
740 if (!xfs_attr_namecheck(attr_name
, attri_formatp
->alfi_name_len
)) {
741 XFS_CORRUPTION_ERROR(__func__
, XFS_ERRLEVEL_LOW
, mp
,
742 item
->ri_buf
[1].i_addr
, item
->ri_buf
[1].i_len
);
743 return -EFSCORRUPTED
;
746 /* Validate the attr value, if present */
747 if (attri_formatp
->alfi_value_len
!= 0) {
748 if (item
->ri_buf
[2].i_len
!= xlog_calc_iovec_len(attri_formatp
->alfi_value_len
)) {
749 XFS_CORRUPTION_ERROR(__func__
, XFS_ERRLEVEL_LOW
, mp
,
750 item
->ri_buf
[0].i_addr
,
751 item
->ri_buf
[0].i_len
);
752 return -EFSCORRUPTED
;
755 attr_value
= item
->ri_buf
[2].i_addr
;
759 * Memory alloc failure will cause replay to abort. We attach the
760 * name/value buffer to the recovered incore log item and drop our
763 nv
= xfs_attri_log_nameval_alloc(attr_name
,
764 attri_formatp
->alfi_name_len
, attr_value
,
765 attri_formatp
->alfi_value_len
);
767 attrip
= xfs_attri_init(mp
, nv
);
768 memcpy(&attrip
->attri_format
, attri_formatp
, len
);
771 * The ATTRI has two references. One for the ATTRD and one for ATTRI to
772 * ensure it makes it into the AIL. Insert the ATTRI into the AIL
773 * directly and drop the ATTRI reference. Note that
774 * xfs_trans_ail_update() drops the AIL lock.
776 xfs_trans_ail_insert(log
->l_ailp
, &attrip
->attri_item
, lsn
);
777 xfs_attri_release(attrip
);
778 xfs_attri_log_nameval_put(nv
);
783 * This routine is called to allocate an "attr free done" log item.
785 static struct xfs_attrd_log_item
*
786 xfs_trans_get_attrd(struct xfs_trans
*tp
,
787 struct xfs_attri_log_item
*attrip
)
789 struct xfs_attrd_log_item
*attrdp
;
793 attrdp
= kmem_cache_zalloc(xfs_attrd_cache
, GFP_NOFS
| __GFP_NOFAIL
);
795 xfs_log_item_init(tp
->t_mountp
, &attrdp
->attrd_item
, XFS_LI_ATTRD
,
796 &xfs_attrd_item_ops
);
797 attrdp
->attrd_attrip
= attrip
;
798 attrdp
->attrd_format
.alfd_alf_id
= attrip
->attri_format
.alfi_id
;
800 xfs_trans_add_item(tp
, &attrdp
->attrd_item
);
804 /* Get an ATTRD so we can process all the attrs. */
805 static struct xfs_log_item
*
806 xfs_attr_create_done(
807 struct xfs_trans
*tp
,
808 struct xfs_log_item
*intent
,
814 return &xfs_trans_get_attrd(tp
, ATTRI_ITEM(intent
))->attrd_item
;
817 const struct xfs_defer_op_type xfs_attr_defer_type
= {
819 .create_intent
= xfs_attr_create_intent
,
820 .abort_intent
= xfs_attr_abort_intent
,
821 .create_done
= xfs_attr_create_done
,
822 .finish_item
= xfs_attr_finish_item
,
823 .cancel_item
= xfs_attr_cancel_item
,
827 * This routine is called when an ATTRD format structure is found in a committed
828 * transaction in the log. Its purpose is to cancel the corresponding ATTRI if
829 * it was still in the log. To do this it searches the AIL for the ATTRI with
830 * an id equal to that in the ATTRD format structure. If we find it we drop
831 * the ATTRD reference, which removes the ATTRI from the AIL and frees it.
834 xlog_recover_attrd_commit_pass2(
836 struct list_head
*buffer_list
,
837 struct xlog_recover_item
*item
,
840 struct xfs_attrd_log_format
*attrd_formatp
;
842 attrd_formatp
= item
->ri_buf
[0].i_addr
;
843 if (item
->ri_buf
[0].i_len
!= sizeof(struct xfs_attrd_log_format
)) {
844 XFS_CORRUPTION_ERROR(__func__
, XFS_ERRLEVEL_LOW
, log
->l_mp
,
845 item
->ri_buf
[0].i_addr
, item
->ri_buf
[0].i_len
);
846 return -EFSCORRUPTED
;
849 xlog_recover_release_intent(log
, XFS_LI_ATTRI
,
850 attrd_formatp
->alfd_alf_id
);
854 static const struct xfs_item_ops xfs_attri_item_ops
= {
855 .flags
= XFS_ITEM_INTENT
,
856 .iop_size
= xfs_attri_item_size
,
857 .iop_format
= xfs_attri_item_format
,
858 .iop_unpin
= xfs_attri_item_unpin
,
859 .iop_release
= xfs_attri_item_release
,
860 .iop_recover
= xfs_attri_item_recover
,
861 .iop_match
= xfs_attri_item_match
,
862 .iop_relog
= xfs_attri_item_relog
,
865 const struct xlog_recover_item_ops xlog_attri_item_ops
= {
866 .item_type
= XFS_LI_ATTRI
,
867 .commit_pass2
= xlog_recover_attri_commit_pass2
,
870 static const struct xfs_item_ops xfs_attrd_item_ops
= {
871 .flags
= XFS_ITEM_RELEASE_WHEN_COMMITTED
|
872 XFS_ITEM_INTENT_DONE
,
873 .iop_size
= xfs_attrd_item_size
,
874 .iop_format
= xfs_attrd_item_format
,
875 .iop_release
= xfs_attrd_item_release
,
876 .iop_intent
= xfs_attrd_item_intent
,
879 const struct xlog_recover_item_ops xlog_attrd_item_ops
= {
880 .item_type
= XFS_LI_ATTRD
,
881 .commit_pass2
= xlog_recover_attrd_commit_pass2
,