Line data Source code
1 : // SPDX-License-Identifier: GPL-2.0-or-later
2 : /*
3 : * Copyright (C) 2022 Oracle. All Rights Reserved.
4 : * Author: Allison Henderson <allison.henderson@oracle.com>
5 : */
6 :
7 : #include "xfs.h"
8 : #include "xfs_fs.h"
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"
18 : #include "xfs_log.h"
19 : #include "xfs_inode.h"
20 : #include "xfs_da_format.h"
21 : #include "xfs_da_btree.h"
22 : #include "xfs_attr.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"
30 : #include "xfs_parent.h"
31 :
32 : struct kmem_cache *xfs_attri_cache;
33 : struct kmem_cache *xfs_attrd_cache;
34 :
35 : static const struct xfs_item_ops xfs_attri_item_ops;
36 : static const struct xfs_item_ops xfs_attrd_item_ops;
37 : static struct xfs_attrd_log_item *xfs_trans_get_attrd(struct xfs_trans *tp,
38 : struct xfs_attri_log_item *attrip);
39 :
40 : static inline struct xfs_attri_log_item *ATTRI_ITEM(struct xfs_log_item *lip)
41 : {
42 : return container_of(lip, struct xfs_attri_log_item, attri_item);
43 : }
44 :
45 : /*
46 : * Shared xattr name/value buffers for logged extended attribute operations
47 : *
48 : * When logging updates to extended attributes, we can create quite a few
49 : * attribute log intent items for a single xattr update. To avoid cycling the
50 : * memory allocator and memcpy overhead, the name (and value, for setxattr)
51 : * are kept in a refcounted object that is shared across all related log items
52 : * and the upper-level deferred work state structure. The shared buffer has
53 : * a control structure, followed by the name, and then the value.
54 : */
55 :
56 : static inline struct xfs_attri_log_nameval *
57 285358922 : xfs_attri_log_nameval_get(
58 : struct xfs_attri_log_nameval *nv)
59 : {
60 285358922 : if (!refcount_inc_not_zero(&nv->refcount))
61 0 : return NULL;
62 : return nv;
63 : }
64 :
65 : static inline void
66 656089949 : xfs_attri_log_nameval_put(
67 : struct xfs_attri_log_nameval *nv)
68 : {
69 656089949 : if (!nv)
70 : return;
71 512745946 : if (refcount_dec_and_test(&nv->refcount))
72 227431086 : kvfree(nv);
73 : }
74 :
75 : static inline struct xfs_attri_log_nameval *
76 227057413 : xfs_attri_log_nameval_alloc(
77 : const void *name,
78 : unsigned int name_len,
79 : const void *new_name,
80 : unsigned int new_name_len,
81 : const void *value,
82 : unsigned int value_len,
83 : const void *new_value,
84 : unsigned int new_value_len)
85 : {
86 227057413 : struct xfs_attri_log_nameval *nv;
87 :
88 : /*
89 : * This could be over 64kB in length, so we have to use kvmalloc() for
90 : * this. But kvmalloc() utterly sucks, so we use our own version.
91 : */
92 227057413 : nv = xlog_kvmalloc(sizeof(struct xfs_attri_log_nameval) +
93 227057413 : name_len + new_name_len + value_len +
94 : new_value_len);
95 :
96 226989854 : nv->name.i_addr = nv + 1;
97 226989854 : nv->name.i_len = name_len;
98 226989854 : nv->name.i_type = XLOG_REG_TYPE_ATTR_NAME;
99 453979708 : memcpy(nv->name.i_addr, name, name_len);
100 :
101 226989854 : if (new_name_len) {
102 57240849 : nv->new_name.i_addr = nv->name.i_addr + name_len;
103 57240849 : nv->new_name.i_len = new_name_len;
104 114481698 : memcpy(nv->new_name.i_addr, new_name, new_name_len);
105 : } else {
106 169749005 : nv->new_name.i_addr = NULL;
107 169749005 : nv->new_name.i_len = 0;
108 : }
109 226989854 : nv->new_name.i_type = XLOG_REG_TYPE_ATTR_NEWNAME;
110 :
111 226989854 : if (value_len) {
112 226478605 : nv->value.i_addr = nv->name.i_addr + name_len + new_name_len;
113 226478605 : nv->value.i_len = value_len;
114 452957210 : memcpy(nv->value.i_addr, value, value_len);
115 : } else {
116 595096 : nv->value.i_addr = NULL;
117 595096 : nv->value.i_len = 0;
118 : }
119 226989854 : nv->value.i_type = XLOG_REG_TYPE_ATTR_VALUE;
120 :
121 226989854 : if (new_value_len) {
122 57240826 : nv->new_value.i_addr = nv->name.i_addr + name_len +
123 57240826 : new_name_len + value_len;
124 57240826 : nv->new_value.i_len = new_value_len;
125 114481652 : memcpy(nv->new_value.i_addr, new_value, new_value_len);
126 : } else {
127 169749028 : nv->new_value.i_addr = NULL;
128 169749028 : nv->new_value.i_len = 0;
129 : }
130 226989854 : nv->new_value.i_type = XLOG_REG_TYPE_ATTR_NEWVALUE;
131 :
132 226989854 : refcount_set(&nv->refcount, 1);
133 226989854 : return nv;
134 : }
135 :
136 : STATIC void
137 285525448 : xfs_attri_item_free(
138 : struct xfs_attri_log_item *attrip)
139 : {
140 285525448 : kmem_free(attrip->attri_item.li_lv_shadow);
141 285526301 : xfs_attri_log_nameval_put(attrip->attri_nameval);
142 285519834 : kmem_cache_free(xfs_attri_cache, attrip);
143 285522067 : }
144 :
145 : /*
146 : * Freeing the attrip requires that we remove it from the AIL if it has already
147 : * been placed there. However, the ATTRI may not yet have been placed in the
148 : * AIL when called by xfs_attri_release() from ATTRD processing due to the
149 : * ordering of committed vs unpin operations in bulk insert operations. Hence
150 : * the reference count to ensure only the last caller frees the ATTRI.
151 : */
152 : STATIC void
153 570909589 : xfs_attri_release(
154 : struct xfs_attri_log_item *attrip)
155 : {
156 570909589 : ASSERT(atomic_read(&attrip->attri_refcount) > 0);
157 570909589 : if (!atomic_dec_and_test(&attrip->attri_refcount))
158 : return;
159 :
160 285521952 : xfs_trans_ail_delete(&attrip->attri_item, 0);
161 285526638 : xfs_attri_item_free(attrip);
162 : }
163 :
164 : STATIC void
165 285486303 : xfs_attri_item_size(
166 : struct xfs_log_item *lip,
167 : int *nvecs,
168 : int *nbytes)
169 : {
170 285486303 : struct xfs_attri_log_item *attrip = ATTRI_ITEM(lip);
171 285486303 : struct xfs_attri_log_nameval *nv = attrip->attri_nameval;
172 :
173 285486303 : *nvecs += 2;
174 285486303 : *nbytes += sizeof(struct xfs_attri_log_format) +
175 285486303 : xlog_calc_iovec_len(nv->name.i_len);
176 :
177 285486303 : if (nv->new_name.i_len) {
178 114673469 : *nvecs += 1;
179 114673469 : *nbytes += xlog_calc_iovec_len(nv->new_name.i_len);
180 : }
181 :
182 285486303 : if (nv->value.i_len) {
183 284859579 : *nvecs += 1;
184 284859579 : *nbytes += xlog_calc_iovec_len(nv->value.i_len);
185 : }
186 :
187 285486303 : if (nv->new_value.i_len) {
188 114673547 : *nvecs += 1;
189 114673547 : *nbytes += xlog_calc_iovec_len(nv->new_value.i_len);
190 : }
191 285486303 : }
192 :
193 : /*
194 : * This is called to fill in the log iovecs for the given attri log
195 : * item. We use 1 iovec for the attri_format_item, 1 for the name, and
196 : * another for the value if it is present
197 : */
198 : STATIC void
199 285491129 : xfs_attri_item_format(
200 : struct xfs_log_item *lip,
201 : struct xfs_log_vec *lv)
202 : {
203 285491129 : struct xfs_attri_log_item *attrip = ATTRI_ITEM(lip);
204 285491129 : struct xfs_log_iovec *vecp = NULL;
205 285491129 : struct xfs_attri_log_nameval *nv = attrip->attri_nameval;
206 :
207 285491129 : attrip->attri_format.alfi_type = XFS_LI_ATTRI;
208 285491129 : attrip->attri_format.alfi_size = 1;
209 :
210 : /*
211 : * This size accounting must be done before copying the attrip into the
212 : * iovec. If we do it after, the wrong size will be recorded to the log
213 : * and we trip across assertion checks for bad region sizes later during
214 : * the log recovery.
215 : */
216 :
217 285491129 : ASSERT(nv->name.i_len > 0);
218 285491129 : attrip->attri_format.alfi_size++;
219 :
220 285491129 : if (nv->new_name.i_len > 0)
221 114673628 : attrip->attri_format.alfi_size++;
222 :
223 285491129 : if (nv->value.i_len > 0)
224 284857358 : attrip->attri_format.alfi_size++;
225 :
226 285491129 : if (nv->new_value.i_len > 0)
227 114673541 : attrip->attri_format.alfi_size++;
228 :
229 285491129 : xlog_copy_iovec(lv, &vecp, XLOG_REG_TYPE_ATTRI_FORMAT,
230 285491129 : &attrip->attri_format,
231 : sizeof(struct xfs_attri_log_format));
232 285366608 : xlog_copy_from_iovec(lv, &vecp, &nv->name);
233 :
234 285411050 : if (nv->new_name.i_len > 0)
235 114673378 : xlog_copy_from_iovec(lv, &vecp, &nv->new_name);
236 :
237 285411078 : if (nv->value.i_len > 0)
238 284815987 : xlog_copy_from_iovec(lv, &vecp, &nv->value);
239 :
240 285357881 : if (nv->new_value.i_len > 0)
241 114673386 : xlog_copy_from_iovec(lv, &vecp, &nv->new_value);
242 285357951 : }
243 :
244 : /*
245 : * The unpin operation is the last place an ATTRI is manipulated in the log. It
246 : * is either inserted in the AIL or aborted in the event of a log I/O error. In
247 : * either case, the ATTRI transaction has been successfully committed to make
248 : * it this far. Therefore, we expect whoever committed the ATTRI to either
249 : * construct and commit the ATTRD or drop the ATTRD's reference in the event of
250 : * error. Simply drop the log's ATTRI reference now that the log is done with
251 : * it.
252 : */
253 : STATIC void
254 285506734 : xfs_attri_item_unpin(
255 : struct xfs_log_item *lip,
256 : int remove)
257 : {
258 285506734 : xfs_attri_release(ATTRI_ITEM(lip));
259 285517005 : }
260 :
261 :
262 : STATIC void
263 2120 : xfs_attri_item_release(
264 : struct xfs_log_item *lip)
265 : {
266 2120 : xfs_attri_release(ATTRI_ITEM(lip));
267 2120 : }
268 :
269 : /*
270 : * Allocate and initialize an attri item. Caller may allocate an additional
271 : * trailing buffer for name and value
272 : */
273 : STATIC struct xfs_attri_log_item *
274 285202861 : xfs_attri_init(
275 : struct xfs_mount *mp,
276 : struct xfs_attri_log_nameval *nv)
277 : {
278 285202861 : struct xfs_attri_log_item *attrip;
279 :
280 285202861 : attrip = kmem_cache_zalloc(xfs_attri_cache, GFP_NOFS | __GFP_NOFAIL);
281 :
282 : /*
283 : * Grab an extra reference to the name/value buffer for this log item.
284 : * The caller retains its own reference!
285 : */
286 285355326 : attrip->attri_nameval = xfs_attri_log_nameval_get(nv);
287 285435881 : ASSERT(attrip->attri_nameval);
288 :
289 285435881 : xfs_log_item_init(mp, &attrip->attri_item, XFS_LI_ATTRI,
290 : &xfs_attri_item_ops);
291 285342755 : attrip->attri_format.alfi_id = (uintptr_t)(void *)attrip;
292 285342755 : atomic_set(&attrip->attri_refcount, 2);
293 :
294 285342755 : return attrip;
295 : }
296 :
297 : static inline struct xfs_attrd_log_item *ATTRD_ITEM(struct xfs_log_item *lip)
298 : {
299 : return container_of(lip, struct xfs_attrd_log_item, attrd_item);
300 : }
301 :
302 : STATIC void
303 285483746 : xfs_attrd_item_free(struct xfs_attrd_log_item *attrdp)
304 : {
305 285483746 : kmem_free(attrdp->attrd_item.li_lv_shadow);
306 285439708 : kmem_cache_free(xfs_attrd_cache, attrdp);
307 285428853 : }
308 :
309 : STATIC void
310 285418401 : xfs_attrd_item_size(
311 : struct xfs_log_item *lip,
312 : int *nvecs,
313 : int *nbytes)
314 : {
315 285418401 : *nvecs += 1;
316 285418401 : *nbytes += sizeof(struct xfs_attrd_log_format);
317 285418401 : }
318 :
319 : /*
320 : * This is called to fill in the log iovecs for the given attrd log item. We use
321 : * only 1 iovec for the attrd_format, and we point that at the attr_log_format
322 : * structure embedded in the attrd item.
323 : */
324 : STATIC void
325 66998 : xfs_attrd_item_format(
326 : struct xfs_log_item *lip,
327 : struct xfs_log_vec *lv)
328 : {
329 66998 : struct xfs_attrd_log_item *attrdp = ATTRD_ITEM(lip);
330 66998 : struct xfs_log_iovec *vecp = NULL;
331 :
332 66998 : attrdp->attrd_format.alfd_type = XFS_LI_ATTRD;
333 66998 : attrdp->attrd_format.alfd_size = 1;
334 :
335 66998 : xlog_copy_iovec(lv, &vecp, XLOG_REG_TYPE_ATTRD_FORMAT,
336 66998 : &attrdp->attrd_format,
337 : sizeof(struct xfs_attrd_log_format));
338 66994 : }
339 :
340 : /*
341 : * The ATTRD is either committed or aborted if the transaction is canceled. If
342 : * the transaction is canceled, drop our reference to the ATTRI and free the
343 : * ATTRD.
344 : */
345 : STATIC void
346 285447300 : xfs_attrd_item_release(
347 : struct xfs_log_item *lip)
348 : {
349 285447300 : struct xfs_attrd_log_item *attrdp = ATTRD_ITEM(lip);
350 :
351 285447300 : xfs_attri_release(attrdp->attrd_attrip);
352 285494107 : xfs_attrd_item_free(attrdp);
353 285452760 : }
354 :
355 : static struct xfs_log_item *
356 285405799 : xfs_attrd_item_intent(
357 : struct xfs_log_item *lip)
358 : {
359 285405799 : return &ATTRD_ITEM(lip)->attrd_attrip->attri_item;
360 : }
361 :
362 : /*
363 : * Performs one step of an attribute update intent and marks the attrd item
364 : * dirty.. An attr operation may be a set or a remove. Note that the
365 : * transaction is marked dirty regardless of whether the operation succeeds or
366 : * fails to support the ATTRI/ATTRD lifecycle rules.
367 : */
368 : STATIC int
369 469307023 : xfs_xattri_finish_update(
370 : struct xfs_attr_intent *attr,
371 : struct xfs_attrd_log_item *attrdp)
372 : {
373 469307023 : struct xfs_da_args *args = attr->xattri_da_args;
374 469307023 : int error;
375 :
376 469307023 : if (XFS_TEST_ERROR(false, args->dp->i_mount, XFS_ERRTAG_LARP)) {
377 308 : error = -EIO;
378 308 : goto out;
379 : }
380 :
381 469347298 : error = xfs_attr_set_iter(attr);
382 469505409 : if (!error && attr->xattri_dela_state != XFS_DAS_DONE)
383 98902656 : error = -EAGAIN;
384 370602753 : out:
385 : /*
386 : * Mark the transaction dirty, even on error. This ensures the
387 : * transaction is aborted, which:
388 : *
389 : * 1.) releases the ATTRI and frees the ATTRD
390 : * 2.) shuts down the filesystem
391 : */
392 469505717 : args->trans->t_flags |= XFS_TRANS_DIRTY | XFS_TRANS_HAS_INTENT_DONE;
393 :
394 : /*
395 : * attr intent/done items are null when logged attributes are disabled
396 : */
397 469505717 : if (attrdp)
398 285361824 : set_bit(XFS_LI_DIRTY, &attrdp->attrd_item.li_flags);
399 :
400 469623603 : return error;
401 : }
402 :
403 : static inline unsigned int
404 : xfs_attr_log_item_op(const struct xfs_attri_log_format *attrp)
405 : {
406 285437023 : return attrp->alfi_op_flags & XFS_ATTRI_OP_FLAGS_TYPE_MASK;
407 : }
408 :
409 : /* Log an attr to the intent item. */
410 : STATIC void
411 285277876 : xfs_attr_log_item(
412 : struct xfs_trans *tp,
413 : struct xfs_attri_log_item *attrip,
414 : const struct xfs_attr_intent *attr)
415 : {
416 285277876 : struct xfs_attri_log_format *attrp;
417 :
418 285277876 : tp->t_flags |= XFS_TRANS_DIRTY;
419 285277876 : set_bit(XFS_LI_DIRTY, &attrip->attri_item.li_flags);
420 :
421 : /*
422 : * At this point the xfs_attr_intent has been constructed, and we've
423 : * created the log intent. Fill in the attri log item and log format
424 : * structure with fields from this xfs_attr_intent
425 : */
426 285430254 : attrp = &attrip->attri_format;
427 285430254 : attrp->alfi_ino = attr->xattri_da_args->dp->i_ino;
428 285430254 : ASSERT(!(attr->xattri_op_flags & ~XFS_ATTRI_OP_FLAGS_TYPE_MASK));
429 285430254 : attrp->alfi_op_flags = attr->xattri_op_flags;
430 285430254 : attrp->alfi_value_len = attr->xattri_nameval->value.i_len;
431 :
432 285430254 : if (xfs_attr_log_item_op(attrp) == XFS_ATTRI_OP_FLAGS_NVREPLACE) {
433 114673555 : attrp->alfi_old_name_len = attr->xattri_nameval->name.i_len;
434 114673555 : attrp->alfi_new_name_len = attr->xattri_nameval->new_name.i_len;
435 114673555 : attrp->alfi_new_value_len = attr->xattri_nameval->new_value.i_len;
436 : } else {
437 170756699 : attrp->alfi_name_len = attr->xattri_nameval->name.i_len;
438 : }
439 :
440 285430254 : ASSERT(!(attr->xattri_da_args->attr_filter & ~XFS_ATTRI_FILTER_MASK));
441 285430254 : attrp->alfi_attr_filter = attr->xattri_da_args->attr_filter;
442 285430254 : }
443 :
444 : /* Get an ATTRI. */
445 : static struct xfs_log_item *
446 469286354 : xfs_attr_create_intent(
447 : struct xfs_trans *tp,
448 : struct list_head *items,
449 : unsigned int count,
450 : bool sort)
451 : {
452 469286354 : struct xfs_mount *mp = tp->t_mountp;
453 469286354 : struct xfs_attri_log_item *attrip;
454 469286354 : struct xfs_attr_intent *attr;
455 469286354 : struct xfs_da_args *args;
456 :
457 469286354 : ASSERT(count == 1);
458 :
459 : /*
460 : * Each attr item only performs one attribute operation at a time, so
461 : * this is a list of one
462 : */
463 469286354 : attr = list_first_entry_or_null(items, struct xfs_attr_intent,
464 : xattri_list);
465 469286354 : args = attr->xattri_da_args;
466 :
467 469286354 : if (!(args->op_flags & XFS_DA_OP_LOGGED))
468 : return NULL;
469 :
470 : /*
471 : * Create a buffer to store the attribute name and value. This buffer
472 : * will be shared between the higher level deferred xattr work state
473 : * and the lower level xattr log items.
474 : */
475 285108024 : if (!attr->xattri_nameval) {
476 : /*
477 : * Transfer our reference to the name/value buffer to the
478 : * deferred work state structure.
479 : */
480 226894907 : attr->xattri_nameval = xfs_attri_log_nameval_alloc(
481 226944270 : args->name, args->namelen,
482 226944270 : args->new_name, args->new_namelen,
483 226944270 : args->value, args->valuelen,
484 226944270 : args->new_value, args->new_valuelen);
485 : }
486 :
487 285058661 : attrip = xfs_attri_init(mp, attr->xattri_nameval);
488 285387772 : xfs_trans_add_item(tp, &attrip->attri_item);
489 285322992 : xfs_attr_log_item(tp, attrip, attr);
490 :
491 285322992 : return &attrip->attri_item;
492 : }
493 :
494 : static inline void
495 370651460 : xfs_attr_free_item(
496 : struct xfs_attr_intent *attr)
497 : {
498 370651460 : if (attr->xattri_da_state)
499 682748 : xfs_da_state_free(attr->xattri_da_state);
500 370651458 : xfs_attri_log_nameval_put(attr->xattri_nameval);
501 370637948 : if (attr->xattri_da_args->op_flags & XFS_DA_OP_RECOVERY)
502 386 : kmem_free(attr);
503 : else
504 370637562 : kmem_cache_free(xfs_attr_intent_cache, attr);
505 370629815 : }
506 :
507 : /* Process an attr. */
508 : STATIC int
509 469396780 : xfs_attr_finish_item(
510 : struct xfs_trans *tp,
511 : struct xfs_log_item *done,
512 : struct list_head *item,
513 : struct xfs_btree_cur **state)
514 : {
515 469396780 : struct xfs_attr_intent *attr;
516 469396780 : struct xfs_attrd_log_item *done_item = NULL;
517 469396780 : int error;
518 :
519 469396780 : attr = container_of(item, struct xfs_attr_intent, xattri_list);
520 469396780 : if (done)
521 285332157 : done_item = ATTRD_ITEM(done);
522 :
523 : /*
524 : * Always reset trans after EAGAIN cycle
525 : * since the transaction is new
526 : */
527 469396780 : attr->xattri_da_args->trans = tp;
528 :
529 469396780 : error = xfs_xattri_finish_update(attr, done_item);
530 469637371 : if (error != -EAGAIN)
531 370777865 : xfs_attr_free_item(attr);
532 :
533 469484060 : return error;
534 : }
535 :
536 : /* Abort all pending ATTRs. */
537 : STATIC void
538 41 : xfs_attr_abort_intent(
539 : struct xfs_log_item *intent)
540 : {
541 41 : xfs_attri_release(ATTRI_ITEM(intent));
542 41 : }
543 :
544 : /* Cancel an attr */
545 : STATIC void
546 279 : xfs_attr_cancel_item(
547 : struct list_head *item)
548 : {
549 279 : struct xfs_attr_intent *attr;
550 :
551 279 : attr = container_of(item, struct xfs_attr_intent, xattri_list);
552 279 : xfs_attr_free_item(attr);
553 279 : }
554 :
555 : STATIC bool
556 2288 : xfs_attri_item_match(
557 : struct xfs_log_item *lip,
558 : uint64_t intent_id)
559 : {
560 2288 : return ATTRI_ITEM(lip)->attri_format.alfi_id == intent_id;
561 : }
562 :
563 : /* Is this recovered ATTRI format ok? */
564 : static inline bool
565 2881 : xfs_attri_validate(
566 : struct xfs_mount *mp,
567 : struct xfs_attri_log_format *attrp)
568 : {
569 2881 : unsigned int op = xfs_attr_log_item_op(attrp);
570 :
571 2881 : if (attrp->alfi_op_flags & ~XFS_ATTRI_OP_FLAGS_TYPE_MASK)
572 : return false;
573 :
574 2881 : if (attrp->alfi_attr_filter & ~XFS_ATTRI_FILTER_MASK)
575 : return false;
576 :
577 : /* alfi_op_flags should be either a set or remove */
578 2881 : switch (op) {
579 264 : case XFS_ATTRI_OP_FLAGS_REMOVE:
580 264 : if (attrp->alfi_value_len != 0)
581 : return false;
582 264 : if (attrp->alfi_name_len == 0 ||
583 : attrp->alfi_name_len > XATTR_NAME_MAX)
584 : return false;
585 264 : if (attrp->alfi_new_value_len != 0)
586 : return false;
587 : break;
588 1398 : case XFS_ATTRI_OP_FLAGS_SET:
589 : case XFS_ATTRI_OP_FLAGS_REPLACE:
590 : case XFS_ATTRI_OP_FLAGS_NVREMOVE:
591 : case XFS_ATTRI_OP_FLAGS_NVSET:
592 1398 : if (attrp->alfi_name_len == 0 ||
593 : attrp->alfi_name_len > XATTR_NAME_MAX)
594 : return false;
595 1398 : if (attrp->alfi_value_len > XATTR_SIZE_MAX)
596 : return false;
597 1398 : if (attrp->alfi_new_value_len != 0)
598 : return false;
599 : break;
600 1219 : case XFS_ATTRI_OP_FLAGS_NVREPLACE:
601 1219 : if (attrp->alfi_old_name_len == 0 ||
602 : attrp->alfi_old_name_len > XATTR_NAME_MAX)
603 : return false;
604 1219 : if (attrp->alfi_new_name_len == 0 ||
605 : attrp->alfi_new_name_len > XATTR_NAME_MAX)
606 : return false;
607 1219 : if (attrp->alfi_value_len > XATTR_SIZE_MAX)
608 : return false;
609 1219 : if (attrp->alfi_new_value_len > XATTR_SIZE_MAX)
610 : return false;
611 : break;
612 : default:
613 : return false;
614 : }
615 :
616 2881 : return xfs_verify_ino(mp, attrp->alfi_ino);
617 : }
618 :
619 : /*
620 : * Process an attr intent item that was recovered from the log. We need to
621 : * delete the attr that it describes.
622 : */
623 : STATIC int
624 386 : xfs_attri_item_recover(
625 : struct xfs_log_item *lip,
626 : struct list_head *capture_list)
627 : {
628 386 : struct xfs_attri_log_item *attrip = ATTRI_ITEM(lip);
629 386 : struct xfs_attr_intent *attr;
630 386 : struct xfs_mount *mp = lip->li_log->l_mp;
631 386 : struct xfs_inode *ip;
632 386 : struct xfs_da_args *args;
633 386 : struct xfs_trans *tp;
634 386 : struct xfs_trans_res tres;
635 386 : struct xfs_attri_log_format *attrp;
636 386 : struct xfs_attri_log_nameval *nv = attrip->attri_nameval;
637 386 : int error;
638 386 : int total;
639 386 : int local;
640 386 : struct xfs_attrd_log_item *done_item = NULL;
641 :
642 : /*
643 : * First check the validity of the attr described by the ATTRI. If any
644 : * are bad, then assume that all are bad and just toss the ATTRI.
645 : */
646 386 : attrp = &attrip->attri_format;
647 772 : if (!xfs_attri_validate(mp, attrp) ||
648 386 : !xfs_attr_namecheck(mp, nv->name.i_addr, nv->name.i_len,
649 : attrp->alfi_attr_filter))
650 0 : return -EFSCORRUPTED;
651 :
652 386 : error = xlog_recover_iget(mp, attrp->alfi_ino, &ip);
653 386 : if (error)
654 : return error;
655 :
656 386 : attr = kmem_zalloc(sizeof(struct xfs_attr_intent) +
657 : sizeof(struct xfs_da_args), KM_NOFS);
658 386 : args = (struct xfs_da_args *)(attr + 1);
659 :
660 386 : attr->xattri_da_args = args;
661 386 : attr->xattri_op_flags = xfs_attr_log_item_op(attrp);
662 :
663 : /*
664 : * We're reconstructing the deferred work state structure from the
665 : * recovered log item. Grab a reference to the name/value buffer and
666 : * attach it to the new work state.
667 : */
668 386 : attr->xattri_nameval = xfs_attri_log_nameval_get(nv);
669 386 : ASSERT(attr->xattri_nameval);
670 :
671 386 : args->dp = ip;
672 386 : args->geo = mp->m_attr_geo;
673 386 : args->whichfork = XFS_ATTR_FORK;
674 386 : args->name = nv->name.i_addr;
675 386 : args->namelen = nv->name.i_len;
676 386 : args->new_name = nv->new_name.i_addr;
677 386 : args->new_namelen = nv->new_name.i_len;
678 386 : args->hashval = xfs_da_hashname(args->name, args->namelen);
679 386 : args->value = nv->value.i_addr;
680 386 : args->valuelen = nv->value.i_len;
681 386 : args->new_value = nv->new_value.i_addr;
682 386 : args->new_valuelen = nv->new_value.i_len;
683 386 : args->attr_filter = attrp->alfi_attr_filter & XFS_ATTRI_FILTER_MASK;
684 386 : args->op_flags = XFS_DA_OP_RECOVERY | XFS_DA_OP_OKNOENT |
685 : XFS_DA_OP_LOGGED;
686 386 : args->owner = ip->i_ino;
687 :
688 772 : ASSERT(xfs_sb_version_haslogxattrs(&mp->m_sb));
689 :
690 386 : switch (xfs_attr_intent_op(attr)) {
691 56 : case XFS_ATTRI_OP_FLAGS_NVREPLACE:
692 : case XFS_ATTRI_OP_FLAGS_NVSET:
693 56 : args->op_flags |= XFS_DA_OP_NVLOOKUP;
694 243 : fallthrough;
695 243 : case XFS_ATTRI_OP_FLAGS_SET:
696 : case XFS_ATTRI_OP_FLAGS_REPLACE:
697 243 : args->total = xfs_attr_calc_size(args, &local);
698 243 : if (xfs_inode_hasattr(args->dp))
699 173 : attr->xattri_dela_state = xfs_attr_init_replace_state(args);
700 : else
701 70 : attr->xattri_dela_state = xfs_attr_init_add_state(args);
702 : break;
703 11 : case XFS_ATTRI_OP_FLAGS_NVREMOVE:
704 11 : args->op_flags |= XFS_DA_OP_NVLOOKUP;
705 143 : fallthrough;
706 143 : case XFS_ATTRI_OP_FLAGS_REMOVE:
707 143 : if (!xfs_inode_hasattr(args->dp))
708 0 : goto out;
709 143 : attr->xattri_dela_state = xfs_attr_init_remove_state(args);
710 143 : break;
711 0 : default:
712 0 : ASSERT(0);
713 0 : error = -EFSCORRUPTED;
714 0 : goto out;
715 : }
716 :
717 386 : xfs_init_attr_trans(args, &tres, &total);
718 386 : error = xfs_trans_alloc(mp, &tres, total, 0, XFS_TRANS_RESERVE, &tp);
719 386 : if (error)
720 0 : goto out;
721 :
722 386 : args->trans = tp;
723 386 : done_item = xfs_trans_get_attrd(tp, attrip);
724 :
725 386 : xfs_ilock(ip, XFS_ILOCK_EXCL);
726 386 : xfs_trans_ijoin(tp, ip, 0);
727 :
728 386 : error = xfs_xattri_finish_update(attr, done_item);
729 386 : if (error == -EAGAIN) {
730 : /*
731 : * There's more work to do, so add the intent item to this
732 : * transaction so that we can continue it later.
733 : */
734 272 : xfs_defer_add(tp, XFS_DEFER_OPS_TYPE_ATTR, &attr->xattri_list);
735 272 : error = xfs_defer_ops_capture_and_commit(tp, capture_list);
736 272 : if (error)
737 0 : goto out_unlock;
738 :
739 272 : xfs_iunlock(ip, XFS_ILOCK_EXCL);
740 272 : xfs_irele(ip);
741 272 : return 0;
742 : }
743 114 : if (error) {
744 0 : xfs_trans_cancel(tp);
745 0 : goto out_unlock;
746 : }
747 :
748 114 : error = xfs_defer_ops_capture_and_commit(tp, capture_list);
749 114 : out_unlock:
750 114 : xfs_iunlock(ip, XFS_ILOCK_EXCL);
751 114 : xfs_irele(ip);
752 114 : out:
753 114 : xfs_attr_free_item(attr);
754 114 : return error;
755 : }
756 :
757 : /* Re-log an intent item to push the log tail forward. */
758 : static struct xfs_log_item *
759 1007 : xfs_attri_item_relog(
760 : struct xfs_log_item *intent,
761 : struct xfs_trans *tp)
762 : {
763 1007 : struct xfs_attrd_log_item *attrdp;
764 1007 : struct xfs_attri_log_item *old_attrip;
765 1007 : struct xfs_attri_log_item *new_attrip;
766 1007 : struct xfs_attri_log_format *new_attrp;
767 1007 : struct xfs_attri_log_format *old_attrp;
768 :
769 1007 : old_attrip = ATTRI_ITEM(intent);
770 1007 : old_attrp = &old_attrip->attri_format;
771 :
772 1007 : tp->t_flags |= XFS_TRANS_DIRTY;
773 1007 : attrdp = xfs_trans_get_attrd(tp, old_attrip);
774 1007 : set_bit(XFS_LI_DIRTY, &attrdp->attrd_item.li_flags);
775 :
776 : /*
777 : * Create a new log item that shares the same name/value buffer as the
778 : * old log item.
779 : */
780 1007 : new_attrip = xfs_attri_init(tp->t_mountp, old_attrip->attri_nameval);
781 1007 : new_attrp = &new_attrip->attri_format;
782 :
783 1007 : new_attrp->alfi_ino = old_attrp->alfi_ino;
784 1007 : new_attrp->alfi_op_flags = old_attrp->alfi_op_flags;
785 1007 : new_attrp->alfi_value_len = old_attrp->alfi_value_len;
786 :
787 1007 : if (xfs_attr_log_item_op(old_attrp) == XFS_ATTRI_OP_FLAGS_NVREPLACE) {
788 93 : new_attrp->alfi_new_name_len = old_attrp->alfi_new_name_len;
789 93 : new_attrp->alfi_old_name_len = old_attrp->alfi_old_name_len;
790 93 : new_attrp->alfi_new_value_len = old_attrp->alfi_new_value_len;
791 : } else {
792 914 : new_attrp->alfi_name_len = old_attrp->alfi_name_len;
793 : }
794 :
795 1007 : new_attrp->alfi_attr_filter = old_attrp->alfi_attr_filter;
796 :
797 1007 : xfs_trans_add_item(tp, &new_attrip->attri_item);
798 1007 : set_bit(XFS_LI_DIRTY, &new_attrip->attri_item.li_flags);
799 :
800 1007 : return &new_attrip->attri_item;
801 : }
802 :
803 : STATIC int
804 2495 : xlog_recover_attri_commit_pass2(
805 : struct xlog *log,
806 : struct list_head *buffer_list,
807 : struct xlog_recover_item *item,
808 : xfs_lsn_t lsn)
809 : {
810 2495 : struct xfs_mount *mp = log->l_mp;
811 2495 : struct xfs_attri_log_item *attrip;
812 2495 : struct xfs_attri_log_format *attri_formatp;
813 2495 : struct xfs_attri_log_nameval *nv;
814 2495 : const void *attr_name;
815 2495 : const void *attr_value = NULL;
816 2495 : const void *attr_new_name = NULL;
817 2495 : const void *attr_new_value = NULL;
818 2495 : size_t len;
819 2495 : unsigned int name_len = 0;
820 2495 : unsigned int value_len = 0;
821 2495 : unsigned int new_name_len = 0;
822 2495 : unsigned int new_value_len = 0;
823 2495 : unsigned int op, i = 0;
824 :
825 : /* Validate xfs_attri_log_format before the large memory allocation */
826 2495 : len = sizeof(struct xfs_attri_log_format);
827 2495 : if (item->ri_buf[i].i_len != len) {
828 0 : XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
829 : item->ri_buf[0].i_addr, item->ri_buf[0].i_len);
830 0 : return -EFSCORRUPTED;
831 : }
832 :
833 2495 : attri_formatp = item->ri_buf[i].i_addr;
834 2495 : if (!xfs_attri_validate(mp, attri_formatp)) {
835 0 : XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
836 : attri_formatp, len);
837 0 : return -EFSCORRUPTED;
838 : }
839 :
840 : /* Check the number of log iovecs makes sense for the op code. */
841 2495 : op = xfs_attr_log_item_op(attri_formatp);
842 2495 : switch (op) {
843 996 : case XFS_ATTRI_OP_FLAGS_NVSET:
844 : case XFS_ATTRI_OP_FLAGS_NVREMOVE:
845 : /* Log item, attr name, optional attr value */
846 996 : if (item->ri_total != 3 && item->ri_total != 2) {
847 0 : XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
848 : attri_formatp, len);
849 0 : return -EFSCORRUPTED;
850 : }
851 996 : name_len = attri_formatp->alfi_name_len;
852 996 : value_len = attri_formatp->alfi_value_len;
853 996 : break;
854 188 : case XFS_ATTRI_OP_FLAGS_SET:
855 : case XFS_ATTRI_OP_FLAGS_REPLACE:
856 : /* Log item, attr name, attr value */
857 188 : if (item->ri_total != 3) {
858 0 : XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
859 : attri_formatp, len);
860 0 : return -EFSCORRUPTED;
861 : }
862 188 : name_len = attri_formatp->alfi_name_len;
863 188 : value_len = attri_formatp->alfi_value_len;
864 188 : break;
865 132 : case XFS_ATTRI_OP_FLAGS_REMOVE:
866 : /* Log item, attr name */
867 132 : if (item->ri_total != 2) {
868 0 : XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
869 : attri_formatp, len);
870 0 : return -EFSCORRUPTED;
871 : }
872 132 : name_len = attri_formatp->alfi_name_len;
873 132 : break;
874 1179 : case XFS_ATTRI_OP_FLAGS_NVREPLACE:
875 : /*
876 : * Log item, attr name, new attr name, optional attr value,
877 : * optional new attr value
878 : */
879 1179 : if (item->ri_total < 3 || item->ri_total > 5) {
880 0 : XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
881 : attri_formatp, len);
882 0 : return -EFSCORRUPTED;
883 : }
884 1179 : name_len = attri_formatp->alfi_old_name_len;
885 1179 : new_name_len = attri_formatp->alfi_new_name_len;
886 1179 : value_len = attri_formatp->alfi_value_len;
887 1179 : new_value_len = attri_formatp->alfi_new_value_len;
888 1179 : break;
889 0 : default:
890 0 : XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
891 : attri_formatp, len);
892 0 : return -EFSCORRUPTED;
893 : }
894 2495 : i++;
895 :
896 : /* Validate the attr name */
897 2495 : if (item->ri_buf[i].i_len != xlog_calc_iovec_len(name_len)) {
898 0 : XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
899 : attri_formatp, len);
900 0 : return -EFSCORRUPTED;
901 : }
902 :
903 2495 : attr_name = item->ri_buf[i].i_addr;
904 2495 : if (!xfs_attr_namecheck(mp, attr_name, name_len,
905 : attri_formatp->alfi_attr_filter)) {
906 0 : XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
907 : attri_formatp, len);
908 0 : return -EFSCORRUPTED;
909 : }
910 2495 : i++;
911 :
912 : /* Validate the new attr name */
913 2495 : if (new_name_len > 0) {
914 1179 : if (item->ri_buf[i].i_len != xlog_calc_iovec_len(new_name_len)) {
915 0 : XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
916 : item->ri_buf[i].i_addr,
917 : item->ri_buf[i].i_len);
918 0 : return -EFSCORRUPTED;
919 : }
920 :
921 1179 : attr_new_name = item->ri_buf[i].i_addr;
922 1179 : if (!xfs_attr_namecheck(mp, attr_new_name, new_name_len,
923 : attri_formatp->alfi_attr_filter)) {
924 0 : XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
925 : item->ri_buf[i].i_addr,
926 : item->ri_buf[i].i_len);
927 0 : return -EFSCORRUPTED;
928 : }
929 : i++;
930 : }
931 :
932 : /* Validate the attr value, if present */
933 2495 : if (value_len != 0) {
934 2363 : if (item->ri_buf[i].i_len != xlog_calc_iovec_len(value_len)) {
935 0 : XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
936 : attri_formatp, len);
937 0 : return -EFSCORRUPTED;
938 : }
939 :
940 2363 : attr_value = item->ri_buf[i].i_addr;
941 4538 : if ((attri_formatp->alfi_attr_filter & XFS_ATTR_PARENT) &&
942 2175 : !xfs_parent_valuecheck(mp, attr_value, value_len)) {
943 0 : XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
944 : item->ri_buf[i].i_addr,
945 : item->ri_buf[i].i_len);
946 0 : return -EFSCORRUPTED;
947 : }
948 2363 : i++;
949 : }
950 :
951 : /* Validate the new attr value, if present */
952 2495 : if (new_value_len != 0) {
953 1179 : if (item->ri_buf[i].i_len != xlog_calc_iovec_len(new_value_len)) {
954 0 : XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
955 : attri_formatp, len);
956 0 : return -EFSCORRUPTED;
957 : }
958 :
959 1179 : attr_new_value = item->ri_buf[i].i_addr;
960 2358 : if ((attri_formatp->alfi_attr_filter & XFS_ATTR_PARENT) &&
961 1179 : !xfs_parent_valuecheck(mp, attr_new_value, new_value_len)) {
962 0 : XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
963 : item->ri_buf[i].i_addr,
964 : item->ri_buf[i].i_len);
965 0 : return -EFSCORRUPTED;
966 : }
967 1179 : i++;
968 : }
969 :
970 : /*
971 : * Make sure we got the correct number of buffers for the operation
972 : * that we just loaded.
973 : */
974 2495 : if (i != item->ri_total) {
975 0 : XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
976 : attri_formatp, len);
977 0 : return -EFSCORRUPTED;
978 : }
979 :
980 2495 : switch (op) {
981 132 : case XFS_ATTRI_OP_FLAGS_REMOVE:
982 : /* Regular remove operations operate only on names. */
983 132 : if (attr_value != NULL || value_len != 0) {
984 0 : XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
985 : attri_formatp, len);
986 0 : return -EFSCORRUPTED;
987 : }
988 1316 : fallthrough;
989 : case XFS_ATTRI_OP_FLAGS_NVSET:
990 : case XFS_ATTRI_OP_FLAGS_NVREMOVE:
991 : case XFS_ATTRI_OP_FLAGS_SET:
992 : case XFS_ATTRI_OP_FLAGS_REPLACE:
993 : /*
994 : * Regular xattr set/remove/replace operations require a name
995 : * and do not take a newname. Values are optional for set and
996 : * replace.
997 : *
998 : * Name-value set/remove operations must have a name, do not
999 : * take a newname, and can take a value.
1000 : */
1001 1316 : if (attr_name == NULL || name_len == 0) {
1002 0 : XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
1003 : attri_formatp, len);
1004 0 : return -EFSCORRUPTED;
1005 : }
1006 : break;
1007 1179 : case XFS_ATTRI_OP_FLAGS_NVREPLACE:
1008 : /*
1009 : * Name-value replace operations require the caller to
1010 : * specify the old and new names and values explicitly.
1011 : * Values are optional.
1012 : */
1013 1179 : if (attr_name == NULL || name_len == 0) {
1014 0 : XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
1015 : attri_formatp, len);
1016 0 : return -EFSCORRUPTED;
1017 : }
1018 1179 : if (attr_new_name == NULL || new_name_len == 0) {
1019 0 : XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
1020 : attri_formatp, len);
1021 0 : return -EFSCORRUPTED;
1022 : }
1023 : break;
1024 : }
1025 :
1026 : /*
1027 : * Memory alloc failure will cause replay to abort. We attach the
1028 : * name/value buffer to the recovered incore log item and drop our
1029 : * reference.
1030 : */
1031 2495 : nv = xfs_attri_log_nameval_alloc(attr_name, name_len,
1032 : attr_new_name, new_name_len,
1033 : attr_value, value_len,
1034 : attr_new_value, new_value_len);
1035 :
1036 2495 : attrip = xfs_attri_init(mp, nv);
1037 4990 : memcpy(&attrip->attri_format, attri_formatp, len);
1038 :
1039 : /*
1040 : * The ATTRI has two references. One for the ATTRD and one for ATTRI to
1041 : * ensure it makes it into the AIL. Insert the ATTRI into the AIL
1042 : * directly and drop the ATTRI reference. Note that
1043 : * xfs_trans_ail_update() drops the AIL lock.
1044 : */
1045 2495 : xfs_trans_ail_insert(log->l_ailp, &attrip->attri_item, lsn);
1046 2495 : xfs_attri_release(attrip);
1047 2495 : xfs_attri_log_nameval_put(nv);
1048 2495 : return 0;
1049 : }
1050 :
1051 : /*
1052 : * This routine is called to allocate an "attr free done" log item.
1053 : */
1054 : static struct xfs_attrd_log_item *
1055 285277503 : xfs_trans_get_attrd(struct xfs_trans *tp,
1056 : struct xfs_attri_log_item *attrip)
1057 : {
1058 285277503 : struct xfs_attrd_log_item *attrdp;
1059 :
1060 285277503 : ASSERT(tp != NULL);
1061 :
1062 285277503 : attrdp = kmem_cache_zalloc(xfs_attrd_cache, GFP_NOFS | __GFP_NOFAIL);
1063 :
1064 285392959 : xfs_log_item_init(tp->t_mountp, &attrdp->attrd_item, XFS_LI_ATTRD,
1065 : &xfs_attrd_item_ops);
1066 285294177 : attrdp->attrd_attrip = attrip;
1067 285294177 : attrdp->attrd_format.alfd_alf_id = attrip->attri_format.alfi_id;
1068 :
1069 285294177 : xfs_trans_add_item(tp, &attrdp->attrd_item);
1070 285374446 : return attrdp;
1071 : }
1072 :
1073 : /* Get an ATTRD so we can process all the attrs. */
1074 : static struct xfs_log_item *
1075 469421470 : xfs_attr_create_done(
1076 : struct xfs_trans *tp,
1077 : struct xfs_log_item *intent,
1078 : unsigned int count)
1079 : {
1080 469421470 : if (!intent)
1081 : return NULL;
1082 :
1083 285329119 : return &xfs_trans_get_attrd(tp, ATTRI_ITEM(intent))->attrd_item;
1084 : }
1085 :
1086 : const struct xfs_defer_op_type xfs_attr_defer_type = {
1087 : .max_items = 1,
1088 : .create_intent = xfs_attr_create_intent,
1089 : .abort_intent = xfs_attr_abort_intent,
1090 : .create_done = xfs_attr_create_done,
1091 : .finish_item = xfs_attr_finish_item,
1092 : .cancel_item = xfs_attr_cancel_item,
1093 : };
1094 :
1095 : /*
1096 : * This routine is called when an ATTRD format structure is found in a committed
1097 : * transaction in the log. Its purpose is to cancel the corresponding ATTRI if
1098 : * it was still in the log. To do this it searches the AIL for the ATTRI with
1099 : * an id equal to that in the ATTRD format structure. If we find it we drop
1100 : * the ATTRD reference, which removes the ATTRI from the AIL and frees it.
1101 : */
1102 : STATIC int
1103 2113 : xlog_recover_attrd_commit_pass2(
1104 : struct xlog *log,
1105 : struct list_head *buffer_list,
1106 : struct xlog_recover_item *item,
1107 : xfs_lsn_t lsn)
1108 : {
1109 2113 : struct xfs_attrd_log_format *attrd_formatp;
1110 :
1111 2113 : attrd_formatp = item->ri_buf[0].i_addr;
1112 2113 : if (item->ri_buf[0].i_len != sizeof(struct xfs_attrd_log_format)) {
1113 0 : XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, log->l_mp,
1114 : item->ri_buf[0].i_addr, item->ri_buf[0].i_len);
1115 0 : return -EFSCORRUPTED;
1116 : }
1117 :
1118 2113 : xlog_recover_release_intent(log, XFS_LI_ATTRI,
1119 : attrd_formatp->alfd_alf_id);
1120 2113 : return 0;
1121 : }
1122 :
1123 : static const struct xfs_item_ops xfs_attri_item_ops = {
1124 : .flags = XFS_ITEM_INTENT,
1125 : .iop_size = xfs_attri_item_size,
1126 : .iop_format = xfs_attri_item_format,
1127 : .iop_unpin = xfs_attri_item_unpin,
1128 : .iop_release = xfs_attri_item_release,
1129 : .iop_recover = xfs_attri_item_recover,
1130 : .iop_match = xfs_attri_item_match,
1131 : .iop_relog = xfs_attri_item_relog,
1132 : };
1133 :
1134 : const struct xlog_recover_item_ops xlog_attri_item_ops = {
1135 : .item_type = XFS_LI_ATTRI,
1136 : .commit_pass2 = xlog_recover_attri_commit_pass2,
1137 : };
1138 :
1139 : static const struct xfs_item_ops xfs_attrd_item_ops = {
1140 : .flags = XFS_ITEM_RELEASE_WHEN_COMMITTED |
1141 : XFS_ITEM_INTENT_DONE,
1142 : .iop_size = xfs_attrd_item_size,
1143 : .iop_format = xfs_attrd_item_format,
1144 : .iop_release = xfs_attrd_item_release,
1145 : .iop_intent = xfs_attrd_item_intent,
1146 : };
1147 :
1148 : const struct xlog_recover_item_ops xlog_attrd_item_ops = {
1149 : .item_type = XFS_LI_ATTRD,
1150 : .commit_pass2 = xlog_recover_attrd_commit_pass2,
1151 : };
|