Skip to content

Commit

Permalink
xfs: Set up infastructure for deferred attribute operations
Browse files Browse the repository at this point in the history
Currently attributes are modified directly across one or more
transactions.  But they are not logged or replayed in the event of
an error. The goal of delayed attributes is to enable logging and
replaying of attribute operations using the existing delayed
operations infrastructure.  This will later enable the attributes
to become part of larger multi part operations that also must first
be recorded to the log.  This is mostly of interest in the scheme of
parent pointers which would need to maintain an attribute containing
parent inode information any time an inode is moved, created, or
removed.  Parent pointers would then be of interest to any feature
that would need to quickly derive an inode path from the mount
point.  Online scrub, nfs lookups and fs grow or shrink operations
are all features that could take advantage of this.

This patch adds two new log item types for setting or removing
attributes as deferred operations.  The xfs_attri_log_item logs an
intent to set or remove an attribute.  The corresponding
xfs_attrd_log_item holds a reference to the xfs_attri_log_item and
is freed once the transaction is done.  Both log items use a generic
xfs_attr_log_format structure that contains the attribute name,
value, flags, inode, and an op_flag that indicates if the operations
is a set or remove.

Signed-off-by: Allison Collins <allison.henderson@oracle.com>
  • Loading branch information
allisonhenderson committed Jan 18, 2020
1 parent 5a5159a commit 7d5b739
Show file tree
Hide file tree
Showing 14 changed files with 1,109 additions and 7 deletions.
2 changes: 1 addition & 1 deletion fs/xfs/Makefile
Expand Up @@ -101,14 +101,14 @@ xfs-y += xfs_log.o \
xfs_bmap_item.o \
xfs_buf_item.o \
xfs_extfree_item.o \
xfs_attr_item.o \
xfs_icreate_item.o \
xfs_inode_item.o \
xfs_refcount_item.o \
xfs_rmap_item.o \
xfs_log_recover.o \
xfs_trans_ail.o \
xfs_trans_buf.o

# optional features
xfs-$(CONFIG_XFS_QUOTA) += xfs_dquot.o \
xfs_dquot_item.o \
Expand Down
6 changes: 3 additions & 3 deletions fs/xfs/libxfs/xfs_attr.c
Expand Up @@ -24,6 +24,7 @@
#include "xfs_quota.h"
#include "xfs_trans_space.h"
#include "xfs_trace.h"
#include "xfs_attr_item.h"

/*
* xfs_attr.c
Expand Down Expand Up @@ -60,8 +61,7 @@ STATIC int xfs_attr_fillstate(xfs_da_state_t *state);
STATIC int xfs_attr_refillstate(xfs_da_state_t *state);
STATIC int xfs_attr_leaf_try_add(struct xfs_da_args *args, struct xfs_buf *bp);


STATIC int
int
xfs_attr_args_init(
struct xfs_da_args *args,
struct xfs_inode *dp,
Expand Down Expand Up @@ -189,7 +189,7 @@ xfs_attr_get(
/*
* Calculate how many blocks we need for the new attribute,
*/
STATIC int
int
xfs_attr_calc_size(
struct xfs_da_args *args,
int *local)
Expand Down
33 changes: 33 additions & 0 deletions fs/xfs/libxfs/xfs_attr.h
Expand Up @@ -82,6 +82,36 @@ typedef struct attrlist_ent { /* data from attr_list() */
char a_name[1]; /* attr name (NULL terminated) */
} attrlist_ent_t;

/*
* List of attrs to commit later.
*/
struct xfs_attr_item {
struct xfs_inode *xattri_ip;
void *xattri_value; /* attr value */
void *xattri_name; /* attr name */
uint32_t xattri_op_flags; /* attr op set or rm */
uint32_t xattri_value_len; /* length of value */
uint32_t xattri_name_len; /* length of name */
uint32_t xattri_flags; /* attr flags */

/* used to log this item to an intent */
struct list_head xattri_list;

/*
* xfs_da_args needs to remain instantiated across transaction rolls
* during the defer finish, so store it here
*/
struct xfs_da_args xattri_args;

/*
* A byte array follows the header containing the file name and
* attribute value.
*/
};

#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.
Expand Down Expand Up @@ -160,5 +190,8 @@ int xfs_attr_remove_iter(struct xfs_da_args *args);
int xfs_attr_list(struct xfs_inode *dp, char *buffer, int bufsize,
int flags, struct attrlist_cursor_kern *cursor);
bool xfs_attr_namecheck(const void *name, size_t length);
int xfs_attr_args_init(struct xfs_da_args *args, struct xfs_inode *dp,
struct xfs_name *name, int flags);
int xfs_attr_calc_size(struct xfs_da_args *args, int *local);

#endif /* __XFS_ATTR_H__ */
1 change: 1 addition & 0 deletions fs/xfs/libxfs/xfs_da_btree.h
Expand Up @@ -63,6 +63,7 @@ enum xfs_delattr_state {
XFS_DAS_FLIP_LFLAG = 8, /* Flipped leaf INCOMPLETE attr flag */
XFS_DAS_ALLOC_NODE = 9, /* We are allocating node blocks */
XFS_DAS_FLIP_NFLAG = 10,/* Flipped node INCOMPLETE attr flag */
XFS_DAS_INIT = 11,/* Context has been initialized */
};

/*
Expand Down
1 change: 1 addition & 0 deletions fs/xfs/libxfs/xfs_defer.c
Expand Up @@ -176,6 +176,7 @@ static const struct xfs_defer_op_type *defer_op_types[] = {
[XFS_DEFER_OPS_TYPE_RMAP] = &xfs_rmap_update_defer_type,
[XFS_DEFER_OPS_TYPE_FREE] = &xfs_extent_free_defer_type,
[XFS_DEFER_OPS_TYPE_AGFL_FREE] = &xfs_agfl_free_defer_type,
[XFS_DEFER_OPS_TYPE_ATTR] = &xfs_attr_defer_type,
};

/*
Expand Down
3 changes: 3 additions & 0 deletions fs/xfs/libxfs/xfs_defer.h
Expand Up @@ -17,6 +17,7 @@ enum xfs_defer_ops_type {
XFS_DEFER_OPS_TYPE_RMAP,
XFS_DEFER_OPS_TYPE_FREE,
XFS_DEFER_OPS_TYPE_AGFL_FREE,
XFS_DEFER_OPS_TYPE_ATTR,
XFS_DEFER_OPS_TYPE_MAX,
};

Expand Down Expand Up @@ -60,5 +61,7 @@ extern const struct xfs_defer_op_type xfs_refcount_update_defer_type;
extern const struct xfs_defer_op_type xfs_rmap_update_defer_type;
extern const struct xfs_defer_op_type xfs_extent_free_defer_type;
extern const struct xfs_defer_op_type xfs_agfl_free_defer_type;
extern const struct xfs_defer_op_type xfs_attr_defer_type;


#endif /* __XFS_DEFER_H__ */
44 changes: 42 additions & 2 deletions fs/xfs/libxfs/xfs_log_format.h
Expand Up @@ -117,7 +117,12 @@ struct xfs_unmount_log_format {
#define XLOG_REG_TYPE_CUD_FORMAT 24
#define XLOG_REG_TYPE_BUI_FORMAT 25
#define XLOG_REG_TYPE_BUD_FORMAT 26
#define XLOG_REG_TYPE_MAX 26
#define XLOG_REG_TYPE_ATTRI_FORMAT 27
#define XLOG_REG_TYPE_ATTRD_FORMAT 28
#define XLOG_REG_TYPE_ATTR_NAME 29
#define XLOG_REG_TYPE_ATTR_VALUE 30
#define XLOG_REG_TYPE_MAX 30


/*
* Flags to log operation header
Expand Down Expand Up @@ -240,6 +245,8 @@ typedef struct xfs_trans_header {
#define XFS_LI_CUD 0x1243
#define XFS_LI_BUI 0x1244 /* bmbt update intent */
#define XFS_LI_BUD 0x1245
#define XFS_LI_ATTRI 0x1246 /* attr set/remove intent*/
#define XFS_LI_ATTRD 0x1247 /* attr set/remove done */

#define XFS_LI_TYPE_DESC \
{ XFS_LI_EFI, "XFS_LI_EFI" }, \
Expand All @@ -255,7 +262,9 @@ typedef struct xfs_trans_header {
{ XFS_LI_CUI, "XFS_LI_CUI" }, \
{ XFS_LI_CUD, "XFS_LI_CUD" }, \
{ XFS_LI_BUI, "XFS_LI_BUI" }, \
{ XFS_LI_BUD, "XFS_LI_BUD" }
{ XFS_LI_BUD, "XFS_LI_BUD" }, \
{ XFS_LI_ATTRI, "XFS_LI_ATTRI" }, \
{ XFS_LI_ATTRD, "XFS_LI_ATTRD" }

/*
* Inode Log Item Format definitions.
Expand Down Expand Up @@ -853,4 +862,35 @@ struct xfs_icreate_log {
__be32 icl_gen; /* inode generation number to use */
};

/*
* Flags for deferred attribute operations.
* Upper bits are flags, lower byte is type code
*/
#define XFS_ATTR_OP_FLAGS_SET 1 /* Set the attribute */
#define XFS_ATTR_OP_FLAGS_REMOVE 2 /* Remove the attribute */
#define XFS_ATTR_OP_FLAGS_TYPE_MASK 0x0FF /* Flags type mask */

/*
* This is the structure used to lay out an attr log item in the
* log.
*/
struct xfs_attri_log_format {
uint16_t alfi_type; /* attri log item type */
uint16_t alfi_size; /* size of this item */
uint32_t __pad; /* pad to 64 bit aligned */
uint64_t alfi_id; /* attri identifier */
xfs_ino_t alfi_ino; /* the inode for this attr operation */
uint32_t alfi_op_flags; /* marks the op as a set or remove */
uint32_t alfi_name_len; /* attr name length */
uint32_t alfi_value_len; /* attr value length */
uint32_t alfi_attr_flags;/* attr flags */
};

struct xfs_attrd_log_format {
uint16_t alfd_type; /* attrd log item type */
uint16_t alfd_size; /* size of this item */
uint32_t __pad; /* pad to 64 bit aligned */
uint64_t alfd_alf_id; /* id of corresponding attrd */
};

#endif /* __XFS_LOG_FORMAT_H__ */
1 change: 1 addition & 0 deletions fs/xfs/libxfs/xfs_types.h
Expand Up @@ -11,6 +11,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 */
Expand Down

0 comments on commit 7d5b739

Please sign in to comment.