@@ -78,6 +78,7 @@ struct iomap;
#include "xfs_refcount_btree.h"
#include "xfs_refcount.h"
#include "xfs_btree_staging.h"
+#include "xfs_parent.h"
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
@@ -175,6 +175,12 @@ static inline struct inode *VFS_I(struct xfs_inode *ip)
return &ip->i_vnode;
}
+/* convert from const xfs inode to const vfs inode */
+static inline const struct inode *VFS_IC(const struct xfs_inode *ip)
+{
+ return &ip->i_vnode;
+}
+
/* We only have i_size in the xfs inode in userspace */
static inline loff_t i_size_read(struct inode *inode)
{
@@ -258,6 +258,8 @@ init_caches(void)
"xfs_extfree_item");
xfs_trans_cache = kmem_cache_init(
sizeof(struct xfs_trans), "xfs_trans");
+ xfs_parent_intent_cache = kmem_cache_init(
+ sizeof(struct xfs_parent_defer), "xfs_parent_defer");
}
static int
@@ -275,6 +277,7 @@ destroy_caches(void)
xfs_btree_destroy_cur_caches();
leaked += kmem_cache_destroy(xfs_extfree_item_cache);
leaked += kmem_cache_destroy(xfs_trans_cache);
+ leaked += kmem_cache_destroy(xfs_parent_intent_cache);
return leaked;
}
@@ -616,7 +616,8 @@ int libxfs_zero_extent(struct xfs_inode *ip, xfs_fsblock_t start_fsb,
/* xfs_log.c */
bool xfs_log_check_lsn(struct xfs_mount *, xfs_lsn_t);
void xfs_log_item_init(struct xfs_mount *, struct xfs_log_item *, int);
-#define xfs_attr_use_log_assist(mp) (0)
+#define xfs_attr_grab_log_assist(mp) (0)
+#define xfs_attr_rele_log_assist(mp) ((void) 0)
#define xlog_drop_incompat_feat(log) do { } while (0)
#define xfs_log_in_recovery(mp) (false)
@@ -893,7 +893,7 @@ xfs_attr_lookup(
return error;
}
-static int
+int
xfs_attr_intent_init(
struct xfs_da_args *args,
unsigned int op_flags, /* op flag (set or remove) */
@@ -911,7 +911,7 @@ xfs_attr_intent_init(
}
/* Sets an attribute for an inode as a deferred operation */
-static int
+int
xfs_attr_defer_add(
struct xfs_da_args *args)
{
@@ -549,6 +549,7 @@ int xfs_inode_hasattr(struct xfs_inode *ip);
bool xfs_attr_is_leaf(struct xfs_inode *ip);
int xfs_attr_get_ilocked(struct xfs_da_args *args);
int xfs_attr_get(struct xfs_da_args *args);
+int xfs_attr_defer_add(struct xfs_da_args *args);
int xfs_attr_set(struct xfs_da_args *args);
int xfs_attr_set_iter(struct xfs_attr_intent *attr);
int xfs_attr_remove_iter(struct xfs_attr_intent *attr);
@@ -557,7 +558,8 @@ bool xfs_attr_namecheck(struct xfs_mount *mp, const void *name, size_t length,
int xfs_attr_calc_size(struct xfs_da_args *args, int *local);
void xfs_init_attr_trans(struct xfs_da_args *args, struct xfs_trans_res *tres,
unsigned int *total);
-
+int xfs_attr_intent_init(struct xfs_da_args *args, unsigned int op_flags,
+ struct xfs_attr_intent **attr);
/*
* Check to see if the attr should be upgraded from non-existent or shortform to
* single-leaf-block attribute list.
@@ -21,6 +21,7 @@
#include "xfs_da_btree.h"
#include "xfs_attr.h"
#include "xfs_dir2.h"
+#include "xfs_dir2_priv.h"
#include "xfs_attr_sf.h"
#include "xfs_bmap.h"
#include "xfs_parent.h"
@@ -28,6 +29,8 @@
#include "xfs_format.h"
#include "xfs_trans_space.h"
+struct kmem_cache *xfs_parent_intent_cache;
+
/*
* Parent pointer attribute handling.
*
@@ -90,3 +93,116 @@ xfs_parent_valuecheck(
return true;
}
+
+/* Initializes a xfs_parent_name_rec to be stored as an attribute name. */
+static inline void
+xfs_init_parent_name_rec(
+ struct xfs_parent_name_rec *rec,
+ const struct xfs_inode *dp,
+ const struct xfs_name *name,
+ struct xfs_inode *ip)
+{
+ rec->p_ino = cpu_to_be64(dp->i_ino);
+ rec->p_gen = cpu_to_be32(VFS_IC(dp)->i_generation);
+ rec->p_namehash = cpu_to_be32(xfs_dir2_hashname(dp->i_mount, name));
+}
+
+/* Point the da args value fields at the non-key parts of a parent pointer. */
+static inline void
+xfs_init_parent_davalue(
+ struct xfs_da_args *args,
+ const struct xfs_name *name)
+{
+ args->valuelen = name->len;
+ args->value = (void *)name->name;
+}
+
+/*
+ * Allocate memory to control a logged parent pointer update as part of a
+ * dirent operation.
+ */
+int
+__xfs_parent_init(
+ struct xfs_mount *mp,
+ struct xfs_parent_defer **parentp)
+{
+ struct xfs_parent_defer *parent;
+ int error;
+
+ error = xfs_attr_grab_log_assist(mp);
+ if (error)
+ return error;
+
+ parent = kmem_cache_zalloc(xfs_parent_intent_cache, GFP_KERNEL);
+ if (!parent) {
+ xfs_attr_rele_log_assist(mp);
+ return -ENOMEM;
+ }
+
+ /* init parent da_args */
+ parent->args.geo = mp->m_attr_geo;
+ parent->args.whichfork = XFS_ATTR_FORK;
+ parent->args.attr_filter = XFS_ATTR_PARENT;
+ parent->args.op_flags = XFS_DA_OP_OKNOENT | XFS_DA_OP_LOGGED |
+ XFS_DA_OP_NVLOOKUP;
+ parent->args.name = (const uint8_t *)&parent->rec;
+ parent->args.namelen = sizeof(struct xfs_parent_name_rec);
+
+ *parentp = parent;
+ return 0;
+}
+
+static inline xfs_dahash_t
+xfs_parent_hashname(
+ struct xfs_inode *ip,
+ const struct xfs_parent_defer *parent)
+{
+ return xfs_da_hashname((const void *)&parent->rec,
+ sizeof(struct xfs_parent_name_rec));
+}
+
+/* Add a parent pointer to reflect a dirent addition. */
+int
+xfs_parent_add(
+ struct xfs_trans *tp,
+ struct xfs_parent_defer *parent,
+ struct xfs_inode *dp,
+ const struct xfs_name *parent_name,
+ struct xfs_inode *child)
+{
+ struct xfs_da_args *args = &parent->args;
+
+ xfs_init_parent_name_rec(&parent->rec, dp, parent_name, child);
+ args->hashval = xfs_parent_hashname(dp, parent);
+
+ args->trans = tp;
+ args->dp = child;
+
+ xfs_init_parent_davalue(&parent->args, parent_name);
+
+ return xfs_attr_defer_add(args);
+}
+
+/* Cancel a parent pointer operation. */
+void
+__xfs_parent_cancel(
+ struct xfs_mount *mp,
+ struct xfs_parent_defer *parent)
+{
+ xlog_drop_incompat_feat(mp->m_log);
+ kmem_cache_free(xfs_parent_intent_cache, parent);
+}
+
+/* Calculate the disk space required to add a parent pointer. */
+unsigned int
+xfs_parent_calc_space_res(
+ struct xfs_mount *mp,
+ unsigned int namelen)
+{
+ /*
+ * Parent pointers are always the first attr in an attr tree, and never
+ * larger than a block
+ */
+ return XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK) +
+ XFS_NEXTENTADD_SPACE_RES(mp, namelen, XFS_ATTR_FORK);
+}
@@ -13,4 +13,46 @@ bool xfs_parent_namecheck(struct xfs_mount *mp,
bool xfs_parent_valuecheck(struct xfs_mount *mp, const void *value,
size_t valuelen);
-#endif /* __XFS_PARENT_H__ */
+extern struct kmem_cache *xfs_parent_intent_cache;
+
+/*
+ * Dynamically allocd structure used to wrap the needed data to pass around
+ * the defer ops machinery
+ */
+struct xfs_parent_defer {
+ struct xfs_parent_name_rec rec;
+ struct xfs_da_args args;
+};
+
+int __xfs_parent_init(struct xfs_mount *mp, struct xfs_parent_defer **parentp);
+
+static inline int
+xfs_parent_start(
+ struct xfs_mount *mp,
+ struct xfs_parent_defer **pp)
+{
+ *pp = NULL;
+
+ if (xfs_has_parent(mp))
+ return __xfs_parent_init(mp, pp);
+ return 0;
+}
+
+int xfs_parent_add(struct xfs_trans *tp, struct xfs_parent_defer *parent,
+ struct xfs_inode *dp, const struct xfs_name *parent_name,
+ struct xfs_inode *child);
+void __xfs_parent_cancel(struct xfs_mount *mp, struct xfs_parent_defer *parent);
+
+static inline void
+xfs_parent_finish(
+ struct xfs_mount *mp,
+ struct xfs_parent_defer *p)
+{
+ if (p)
+ __xfs_parent_cancel(mp, p);
+}
+
+unsigned int xfs_parent_calc_space_res(struct xfs_mount *mp,
+ unsigned int namelen);
+
+#endif /* __XFS_PARENT_H__ */