#endif /* __XFS_LOG_FORMAT_H__ */
diff --git a/fs/xfs/libxfs/xfs_types.h b/fs/xfs/libxfs/xfs_types.h
index 0220159..5372063 100644
--- a/fs/xfs/libxfs/xfs_types.h
+++ b/fs/xfs/libxfs/xfs_types.h
@@ -23,6 +23,7 @@ typedef uint32_t prid_t; /* project ID */
typedef uint32_t xfs_agblock_t; /* blockno in alloc. group */
typedef uint32_t xfs_agino_t; /* inode # within allocation grp */
typedef uint32_t xfs_extlen_t; /* extent length in blocks */
+typedef uint32_t xfs_attrlen_t; /* attr length */
typedef uint32_t xfs_agnumber_t; /* allocation group number */
typedef int32_t xfs_extnum_t; /* # of extents in a file */
typedef int16_t xfs_aextnum_t; /* # extents in an attribute fork */
diff --git a/fs/xfs/xfs_attr.h b/fs/xfs/xfs_attr.h
index 8542606..3ef3c77 100644
--- a/fs/xfs/xfs_attr.h
+++ b/fs/xfs/xfs_attr.h
@@ -18,6 +18,8 @@
#ifndef __XFS_ATTR_H__
#define __XFS_ATTR_H__
+#include "libxfs/xfs_defer.h"
+
struct xfs_inode;
struct xfs_da_args;
struct xfs_attr_list_context;
@@ -87,6 +89,22 @@ typedef struct attrlist_ent { /* data from attr_list() */
} attrlist_ent_t;
/*
+ * List of attrs to commit later.
+ */
+struct xfs_attr_item {
+ struct xfs_inode *xattri_ip;
+ uint32_t xattri_op_flags;
+ uint32_t xattri_value_len; /* length of name and val */
+ uint32_t xattri_name_len; /* length of name */
+ uint32_t xattri_flags; /* attr flags */
+ struct list_head xattri_list;
+ char xattri_name_value[0];
+};
+
+#define XFS_ATTR_ITEM_SIZEOF(namelen, valuelen) \
+ (sizeof(struct xfs_attr_item) + (namelen) + (valuelen))
+
+/*
* Given a pointer to the (char*) buffer containing the attr_list() result,
* and an index, return a pointer to the indicated attribute in the buffer.
*/
@@ -154,6 +172,8 @@ int xfs_attr_remove(struct xfs_inode *dp, const unsigned char *name, int flags);
int xfs_attr_remove_args(struct xfs_da_args *args, int flags);
int xfs_attr_list(struct xfs_inode *dp, char *buffer, int bufsize,
int flags, struct attrlist_cursor_kern *cursor);
-
+int xfs_attr_args_init(struct xfs_da_args *args, struct xfs_inode *dp,
+ const unsigned char *name, int flags);
+int xfs_attr_calc_size(struct xfs_da_args *args, int *local);
#endif /* __XFS_ATTR_H__ */
diff --git a/fs/xfs/xfs_attr_item.c b/fs/xfs/xfs_attr_item.c
new file mode 100644
index 0000000..0ba2a54
--- /dev/null
+++ b/fs/xfs/xfs_attr_item.c
@@ -0,0 +1,513 @@
+/*
+ * Copyright (c) 2017 Oracle, Inc.
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation Inc.
+ */
+#include "xfs.h"
+#include "xfs_fs.h"
+#include "xfs_format.h"
+#include "xfs_log_format.h"
+#include "xfs_trans_resv.h"
+#include "xfs_bit.h"
+#include "xfs_mount.h"
+#include "xfs_trans.h"
+#include "xfs_trans_priv.h"
+#include "xfs_buf_item.h"
+#include "xfs_attr_item.h"
+#include "xfs_log.h"
+#include "xfs_btree.h"
+#include "xfs_rmap.h"
+#include "xfs_inode.h"
+#include "xfs_icache.h"
+
+static inline struct xfs_attri_log_item *ATTRI_ITEM(struct xfs_log_item *lip)
+{
+ return container_of(lip, struct xfs_attri_log_item, item);
+}
+
+void
+xfs_attri_item_free(
+ struct xfs_attri_log_item *attrip)
+{
+ kmem_free(attrip->item.li_lv_shadow);
+ kmem_free(attrip);
+}
+
+/*
+ * This returns the number of iovecs needed to log the given attri item.
+ * We only need 1 iovec for an attri item. It just logs the attr_log_format
+ * structure.
+ */
+static inline int
+xfs_attri_item_sizeof(
+ struct xfs_attri_log_item *attrip)
+{
+ return sizeof(struct xfs_attr_log_format);
+}
+
+STATIC void
+xfs_attri_item_size(
+ struct xfs_log_item *lip,
+ int *nvecs,
+ int *nbytes)
+{
+ struct xfs_attri_log_item *attrip = ATTRI_ITEM(lip);
+
+ *nvecs += 1;
+ *nbytes += xfs_attri_item_sizeof(attrip);
+
+ if (attrip->name_len > 0) {
+ *nvecs += 1;
+ nbytes += ATTR_NVEC_SIZE(attrip->name_len);
+ }
+
+ if (attrip->value_len > 0) {
+ *nvecs += 1;
+ nbytes += ATTR_NVEC_SIZE(attrip->value_len);
+ }
+}
+
+/*
+ * This is called to fill in the vector of log iovecs for the
+ * given attri log item. We use only 1 iovec, and we point that
+ * at the attri_log_format structure embedded in the attri item.
+ * It is at this point that we assert that all of the attr
+ * slots in the attri item have been filled.
+ */
+STATIC void
+xfs_attri_item_format(
+ struct xfs_log_item *lip,
+ struct xfs_log_vec *lv)
+{
+ struct xfs_attri_log_item *attrip = ATTRI_ITEM(lip);
+ struct xfs_log_iovec *vecp = NULL;
+
+ attrip->format.alf_type = XFS_LI_ATTRI;
+ attrip->format.alf_size = 1;
+
+ xlog_copy_iovec(lv, &vecp, XLOG_REG_TYPE_ATTRI_FORMAT,
+ &attrip->format,
+ xfs_attri_item_sizeof(attrip));
+ if (attrip->name_len > 0)
+ xlog_copy_iovec(lv, &vecp, XLOG_REG_TYPE_ATTR_NAME,
+ attrip->name, ATTR_NVEC_SIZE(attrip->name_len));
+
+ if (attrip->value_len > 0)
+ xlog_copy_iovec(lv, &vecp, XLOG_REG_TYPE_ATTR_VALUE,
+ attrip->value,
+ ATTR_NVEC_SIZE(attrip->value_len));
+}
+
+
+/*
+ * Pinning has no meaning for an attri item, so just return.
+ */
+STATIC void
+xfs_attri_item_pin(
+ struct xfs_log_item *lip)
+{
+}
+
+/*
+ * The unpin operation is the last place an ATTRI is manipulated in the log. It
+ * is either inserted in the AIL or aborted in the event of a log I/O error. In
+ * either case, the ATTRI transaction has been successfully committed to make it
+ * this far. Therefore, we expect whoever committed the ATTRI to either
+ * construct and commit the ATTRD or drop the ATTRD's reference in the event of
+ * error. Simply drop the log's ATTRI reference now that the log is done with
+ * it.
+ */
+STATIC void
+xfs_attri_item_unpin(
+ struct xfs_log_item *lip,
+ int remove)
+{
+ struct xfs_attri_log_item *attrip = ATTRI_ITEM(lip);
+
+ xfs_attri_release(attrip);
+}
+
+/*
+ * attri items have no locking or pushing. However, since ATTRIs are pulled
+ * from the AIL when their corresponding ATTRDs are committed to disk, their
+ * situation is very similar to being pinned. Return XFS_ITEM_PINNED so that
+ * the caller will eventually flush the log. This should help in getting the
+ * ATTRI out of the AIL.
+ */
+STATIC uint
+xfs_attri_item_push(
+ struct xfs_log_item *lip,
+ struct list_head *buffer_list)
+{
+ return XFS_ITEM_PINNED;
+}
+
+/*
+ * The ATTRI has been either committed or aborted if the transaction has been
+ * cancelled. If the transaction was cancelled, an ATTRD isn't going to be
+ * constructed and thus we free the ATTRI here directly.
+ */
+STATIC void
+xfs_attri_item_unlock(
+ struct xfs_log_item *lip)
+{
+ if (lip->li_flags & XFS_LI_ABORTED)
+ xfs_attri_item_free(ATTRI_ITEM(lip));
+}
+
+/*
+ * The ATTRI is logged only once and cannot be moved in the log, so simply
+ * return the lsn at which it's been logged.
+ */
+STATIC xfs_lsn_t
+xfs_attri_item_committed(
+ struct xfs_log_item *lip,
+ xfs_lsn_t lsn)
+{
+ return lsn;
+}
+
+STATIC void
+xfs_attri_item_committing(
+ struct xfs_log_item *lip,
+ xfs_lsn_t lsn)
+{
+}
+
+/*
+ * This is the ops vector shared by all attri log items.
+ */
+static const struct xfs_item_ops xfs_attri_item_ops = {
+ .iop_size = xfs_attri_item_size,
+ .iop_format = xfs_attri_item_format,
+ .iop_pin = xfs_attri_item_pin,
+ .iop_unpin = xfs_attri_item_unpin,
+ .iop_unlock = xfs_attri_item_unlock,
+ .iop_committed = xfs_attri_item_committed,
+ .iop_push = xfs_attri_item_push,
+ .iop_committing = xfs_attri_item_committing
+};
+
+
+/*
+ * Allocate and initialize an attri item
+ */
+struct xfs_attri_log_item *
+xfs_attri_init(
+ struct xfs_mount *mp)
+
+{
+ struct xfs_attri_log_item *attrip;
+ uint size;
+
+ size = (uint)(sizeof(struct xfs_attri_log_item));
+ attrip = kmem_zalloc(size, KM_SLEEP);
+
+ xfs_log_item_init(mp, &(attrip->item), XFS_LI_ATTRI,
+ &xfs_attri_item_ops);
+ attrip->format.alf_id = (uintptr_t)(void *)attrip;
+ atomic_set(&attrip->refcount, 2);
+
+ return attrip;
+}
+
+/*
+ * Copy an attr format buffer from the given buf, and into the destination
+ * attr format structure.
+ */
+int
+xfs_attr_copy_format(struct xfs_log_iovec *buf,
+ struct xfs_attr_log_format *dst_attr_fmt)
+{
+ struct xfs_attr_log_format *src_attr_fmt = buf->i_addr;
+ uint len = sizeof(struct xfs_attr_log_format);
+
+ if (buf->i_len == len) {
+ memcpy((char *)dst_attr_fmt, (char *)src_attr_fmt, len);
+ return 0;
+ }
+ return -EFSCORRUPTED;
+}
+
+/*
+ * Freeing the attri requires that we remove it from the AIL if it has already
+ * been placed there. However, the ATTRI may not yet have been placed in the
+ * AIL when called by xfs_attri_release() from ATTRD processing due to the
+ * ordering of committed vs unpin operations in bulk insert operations. Hence
+ * the reference count to ensure only the last caller frees the ATTRI.
+ */
+void
+xfs_attri_release(
+ struct xfs_attri_log_item *attrip)
+{
+ ASSERT(atomic_read(&attrip->refcount) > 0);
+ if (atomic_dec_and_test(&attrip->refcount)) {
+ xfs_trans_ail_remove(&attrip->item,
+ SHUTDOWN_LOG_IO_ERROR);
+ xfs_attri_item_free(attrip);
+ }
+}
+
+static inline struct xfs_attrd_log_item *ATTRD_ITEM(struct xfs_log_item *lip)
+{
+ return container_of(lip, struct xfs_attrd_log_item, item);
+}
+
+STATIC void
+xfs_attrd_item_free(struct xfs_attrd_log_item *attrdp)
+{
+ kmem_free(attrdp->item.li_lv_shadow);
+ kmem_free(attrdp);
+}
+
+/*
+ * This returns the number of iovecs needed to log the given attrd item.
+ * We only need 1 iovec for an attrd item. It just logs the attr_log_format
+ * structure.
+ */
+static inline int
+xfs_attrd_item_sizeof(
+ struct xfs_attrd_log_item *attrdp)
+{
+ return sizeof(struct xfs_attr_log_format);
+}
+
+STATIC void
+xfs_attrd_item_size(
+ struct xfs_log_item *lip,
+ int *nvecs,
+ int *nbytes)
+{
+ struct xfs_attrd_log_item *attrdp = ATTRD_ITEM(lip);
+ *nvecs += 1;
+ *nbytes += xfs_attrd_item_sizeof(attrdp);
+
+ if (attrdp->name_len > 0) {
+ *nvecs += 1;
+ nbytes += attrdp->name_len;
+ }
+
+ if (attrdp->value_len > 0) {
+ *nvecs += 1;
+ nbytes += attrdp->value_len;
+ }
+}
+
+/*
+ * This is called to fill in the vector of log iovecs for the
+ * given attrd log item. We use only 1 iovec, and we point that
+ * at the attr_log_format structure embedded in the attrd item.
+ * It is at this point that we assert that all of the attr
+ * slots in the attrd item have been filled.
+ */
+STATIC void
+xfs_attrd_item_format(
+ struct xfs_log_item *lip,
+ struct xfs_log_vec *lv)
+{
+ struct xfs_attrd_log_item *attrdp = ATTRD_ITEM(lip);
+ struct xfs_log_iovec *vecp = NULL;
+
+ attrdp->format.alf_type = XFS_LI_ATTRD;
+ attrdp->format.alf_size = 1;
+
+ xlog_copy_iovec(lv, &vecp, XLOG_REG_TYPE_ATTRD_FORMAT,
+ &attrdp->format,
+ xfs_attrd_item_sizeof(attrdp));
+}
+
+/*
+ * Pinning has no meaning for an attrd item, so just return.
+ */
+STATIC void
+xfs_attrd_item_pin(
+ struct xfs_log_item *lip)
+{
+}
+
+/*
+ * Since pinning has no meaning for an attrd item, unpinning does
+ * not either.
+ */
+STATIC void
+xfs_attrd_item_unpin(
+ struct xfs_log_item *lip,
+ int remove)
+{
+}
+
+/*
+ * There isn't much you can do to push on an attrd item. It is simply stuck
+ * waiting for the log to be flushed to disk.
+ */
+STATIC uint
+xfs_attrd_item_push(
+ struct xfs_log_item *lip,
+ struct list_head *buffer_list)
+{
+ return XFS_ITEM_PINNED;
+}
+
+/*
+ * The ATTRD is either committed or aborted if the transaction is cancelled. If
+ * the transaction is cancelled, drop our reference to the ATTRI and free the
+ * ATTRD.
+ */
+STATIC void
+xfs_attrd_item_unlock(
+ struct xfs_log_item *lip)
+{
+ struct xfs_attrd_log_item *attrdp = ATTRD_ITEM(lip);
+
+ if (lip->li_flags & XFS_LI_ABORTED) {
+ xfs_attri_release(attrdp->attrip);
+ xfs_attrd_item_free(attrdp);
+ }
+}
+
+/*
+ * When the attrd item is committed to disk, all we need to do is delete our
+ * reference to our partner attri item and then free ourselves. Since we're
+ * freeing ourselves we must return -1 to keep the transaction code from
+ * further referencing this item.
+ */
+STATIC xfs_lsn_t
+xfs_attrd_item_committed(
+ struct xfs_log_item *lip,
+ xfs_lsn_t lsn)
+{
+ struct xfs_attrd_log_item *attrdp = ATTRD_ITEM(lip);
+
+ /*
+ * Drop the ATTRI reference regardless of whether the ATTRD has been
+ * aborted. Once the ATTRD transaction is constructed, it is the sole
+ * responsibility of the ATTRD to release the ATTRI (even if the ATTRI
+ * is aborted due to log I/O error).
+ */
+ xfs_attri_release(attrdp->attrip);
+ xfs_attrd_item_free(attrdp);
+
+ return (xfs_lsn_t)-1;
+}
+
+STATIC void
+xfs_attrd_item_committing(
+ struct xfs_log_item *lip,
+ xfs_lsn_t lsn)
+{
+}
+
+/*
+ * This is the ops vector shared by all attrd log items.
+ */
+static const struct xfs_item_ops xfs_attrd_item_ops = {
+ .iop_size = xfs_attrd_item_size,
+ .iop_format = xfs_attrd_item_format,
+ .iop_pin = xfs_attrd_item_pin,
+ .iop_unpin = xfs_attrd_item_unpin,
+ .iop_unlock = xfs_attrd_item_unlock,
+ .iop_committed = xfs_attrd_item_committed,
+ .iop_push = xfs_attrd_item_push,
+ .iop_committing = xfs_attrd_item_committing
+};
+
+/*
+ * Allocate and initialize an attrd item
+ */
+struct xfs_attrd_log_item *
+xfs_attrd_init(
+ struct xfs_mount *mp,
+ struct xfs_attri_log_item *attrip)
+
+{
+ struct xfs_attrd_log_item *attrdp;
+ uint size;
+
+ size = (uint)(sizeof(struct xfs_attrd_log_item));
+ attrdp = kmem_zalloc(size, KM_SLEEP);
+
+ xfs_log_item_init(mp, &attrdp->item, XFS_LI_ATTRD,
+ &xfs_attrd_item_ops);
+ attrdp->attrip = attrip;
+ attrdp->format.alf_id = attrip->format.alf_id;
+
+ return attrdp;
+}
+
+/*
+ * Process an attr intent item that was recovered from
+ * the log. We need to delete the attr that it describes.
+ */
+int
+xfs_attri_recover(
+ struct xfs_mount *mp,
+ struct xfs_attri_log_item *attrip)
+{
+ struct xfs_inode *ip;
+ struct xfs_attrd_log_item *attrdp;
+ struct xfs_trans *tp;
+ int error = 0;
+ struct xfs_attr_log_format *attrp;
+
+ ASSERT(!test_bit(XFS_ATTRI_RECOVERED, &attrip->flags));
+
+ /*
+ * First check the validity of the attr described by the
+ * ATTRI. If any are bad, then assume that all are bad and
+ * just toss the ATTRI. A valid attr must have a name length,
+ * a value length, and either a "set" or "remove" op flag
+ */
+ attrp = &attrip->format;
+ if (attrp->alf_value_len == 0 ||
+ attrp->alf_name_len == 0 ||
+ !(attrp->alf_op_flags == XFS_ATTR_OP_FLAGS_SET ||
+ attrp->alf_op_flags == XFS_ATTR_OP_FLAGS_REMOVE) ) {
+ /*
+ * This will pull the ATTRI from the AIL and
+ * free the memory associated with it.
+ */
+ set_bit(XFS_ATTRI_RECOVERED, &attrip->flags);
+ xfs_attri_release(attrip);
+ return -EIO;
+ }
+
+ error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp);
+ if (error)
+ return error;
+ attrdp = xfs_trans_get_attrd(tp, attrip);
+ attrp = &attrip->format;
+
+ error = xfs_iget(mp, tp, attrp->alf_ino, 0, 0, &ip);
+ if (error)
+ return error;
+
+ error = xfs_trans_attr(tp, attrdp, ip,
+ attrp->alf_op_flags,
+ attrp->alf_attr_flags,
+ attrp->alf_name_len,
+ attrp->alf_value_len,
+ attrip->name,
+ attrip->value);
+ if (error)
+ goto abort_error;
+
+
+ set_bit(XFS_ATTRI_RECOVERED, &attrip->flags);
+ error = xfs_trans_commit(tp);
+ return error;
+
+abort_error:
+ xfs_trans_cancel(tp);
+ return error;
+}
diff --git a/fs/xfs/xfs_attr_item.h b/fs/xfs/xfs_attr_item.h
new file mode 100644
index 0000000..774b56e
--- /dev/null
+++ b/fs/xfs/xfs_attr_item.h
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2017 Oracle, Inc.
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation Inc.
+ */
+#ifndef __XFS_ATTR_ITEM_H__
+#define __XFS_ATTR_ITEM_H__
+
+/* kernel only ATTRI/ATTRD definitions */
+
+struct xfs_mount;
+struct kmem_zone;
+
+/*
+ * Max number of attrs in fast allocation path.
+ */
+#define XFS_ATTRI_MAX_FAST_ATTRS 1
+
+
+/*
+ * Define ATTR flag bits. Manipulated by set/clear/test_bit operators.
+ */
+#define XFS_ATTRI_RECOVERED 1
+
+
+/* nvecs must be in multiples of 4 */
+#define ATTR_NVEC_SIZE(size) (size == sizeof(int32_t) ? sizeof(int32_t) : \
+ size + sizeof(int32_t) - \
+ (size % sizeof(int32_t)))
+
+/*
+ * This is the "attr intention" log item. It is used to log the fact
+ * that some attrs need to be processed. It is used in conjunction with the
+ * "attr done" log item described below.
+ *
+ * The ATTRI is reference counted so that it is not freed prior to both the
+ * ATTRI and ATTRD being committed and unpinned. This ensures the ATTRI is
+ * inserted into the AIL even in the event of out of order ATTRI/ATTRD
+ * processing. In other words, an ATTRI is born with two references:
+ *
+ * 1.) an ATTRI held reference to track ATTRI AIL insertion
+ * 2.) an ATTRD held reference to track ATTRD commit
+ *
+ * On allocation, both references are the responsibility of the caller. Once
+ * the ATTRI is added to and dirtied in a transaction, ownership of reference
+ * one transfers to the transaction. The reference is dropped once the ATTRI is
+ * inserted to the AIL or in the event of failure along the way (e.g., commit
+ * failure, log I/O error, etc.). Note that the caller remains responsible for
+ * the ATTRD reference under all circumstances to this point. The caller has no
+ * means to detect failure once the transaction is committed, however.
+ * Therefore, an ATTRD is required after this point, even in the event of
+ * unrelated failure.
+ *
+ * Once an ATTRD is allocated and dirtied in a transaction, reference two
+ * transfers to the transaction. The ATTRD reference is dropped once it reaches
+ * the unpin handler. Similar to the ATTRI, the reference also drops in the
+ * event of commit failure or log I/O errors. Note that the ATTRD is not
+ * inserted in the AIL, so at this point both the ATTI and ATTRD are freed.
+ */
+struct xfs_attri_log_item {
+ xfs_log_item_t item;
+ atomic_t refcount;
+ unsigned long flags; /* misc flags */
+ int name_len;
+ void *name;
+ int value_len;
+ void *value;
+ struct xfs_attr_log_format format;
+};
+
+/*
+ * This is the "attr done" log item. It is used to log
+ * the fact that some attrs earlier mentioned in an attri item
+ * have been freed.
+ */
+struct xfs_attrd_log_item {
+ struct xfs_log_item item;
+ struct xfs_attri_log_item *attrip;
+ uint next_attr;
+ int name_len;
+ void *name;
+ int value_len;
+ void *value;
+ struct xfs_attr_log_format format;
+};
+
+/*
+ * Max number of attrs in fast allocation path.
+ */
+#define XFS_ATTRD_MAX_FAST_ATTRS 1
+
+extern struct kmem_zone *xfs_attri_zone;
+extern struct kmem_zone *xfs_attrd_zone;
+
+struct xfs_attri_log_item *xfs_attri_init(struct xfs_mount *mp);
+struct xfs_attrd_log_item *xfs_attrd_init(struct xfs_mount *mp,
+ struct xfs_attri_log_item *attrip);
+int xfs_attr_copy_format(struct xfs_log_iovec *buf,
+ struct xfs_attr_log_format *dst_attri_fmt);
+void xfs_attri_item_free(struct xfs_attri_log_item *attrip);
+void xfs_attri_release(struct xfs_attri_log_item *attrip);
+
+int xfs_attri_recover(struct xfs_mount *mp,
+ struct xfs_attri_log_item *attrip);
+
+#endif /* __XFS_ATTR_ITEM_H__ */
diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c
index ee34899..fd0e052 100644
--- a/fs/xfs/xfs_log_recover.c
+++ b/fs/xfs/xfs_log_recover.c
@@ -33,6 +33,7 @@
#include "xfs_log_recover.h"
#include "xfs_inode_item.h"
#include "xfs_extfree_item.h"
+#include "xfs_attr_item.h"
#include "xfs_trans_priv.h"
#include "xfs_alloc.h"
#include "xfs_ialloc.h"
@@ -1956,6 +1957,8 @@ xlog_recover_reorder_trans(
case XFS_LI_CUD:
case XFS_LI_BUI:
case XFS_LI_BUD:
+ case XFS_LI_ATTRI:
+ case XFS_LI_ATTRD:
trace_xfs_log_recover_item_reorder_tail(log,
trans, item, pass);
list_move_tail(&item->ri_list, &inode_list);
@@ -3489,6 +3492,92 @@ xlog_recover_efd_pass2(
return 0;
}
+STATIC int
+xlog_recover_attri_pass2(
+ struct xlog *log,
+ struct xlog_recover_item *item,
+ xfs_lsn_t lsn)
+{
+ int error;
+ struct xfs_mount *mp = log->l_mp;
+ struct xfs_attri_log_item *attrip;
+ struct xfs_attr_log_format *attri_formatp;
+
+ attri_formatp = item->ri_buf[0].i_addr;
+
+ attrip = xfs_attri_init(mp);
+ error = xfs_attr_copy_format(&item->ri_buf[0], &attrip->format);
+ if (error) {
+ xfs_attri_item_free(attrip);
+ return error;
+ }
+
+ spin_lock(&log->l_ailp->xa_lock);
+ /*
+ * The ATTRI has two references. One for the ATTRD and one for ATTRI to
+ * ensure it makes it into the AIL. Insert the ATTRI into the AIL
+ * directly and drop the ATTRI reference. Note that
+ * xfs_trans_ail_update() drops the AIL lock.
+ */
+ xfs_trans_ail_update(log->l_ailp, &attrip->item, lsn);
+ xfs_attri_release(attrip);
+ return 0;
+}
+
+
+/*
+ * This routine is called when an ATTRD format structure is found in a committed
+ * transaction in the log. Its purpose is to cancel the corresponding ATTRI if
+ * it was still in the log. To do this it searches the AIL for the ATTRI with
+ * an id equal to that in the ATTRD format structure. If we find it we drop
+ * the ATTRD reference, which removes the ATTRI from the AIL and frees it.
+ */
+STATIC int
+xlog_recover_attrd_pass2(
+ struct xlog *log,
+ struct xlog_recover_item *item)
+{
+ struct xfs_attr_log_format *attrd_formatp;
+ struct xfs_attri_log_item *attrip = NULL;
+ struct xfs_log_item *lip;
+ uint64_t attri_id;
+ struct xfs_ail_cursor cur;
+ struct xfs_ail *ailp = log->l_ailp;