From: Allison Henderson <allison.henderson@oracle.com>
To: linux-xfs@vger.kernel.org
Subject: [PATCH v3 19/30] xfsprogs: parent pointer attribute creation
Date: Wed, 26 Sep 2018 03:23:22 -0700 [thread overview]
Message-ID: <1537957413-10630-20-git-send-email-allison.henderson@oracle.com> (raw)
In-Reply-To: <1537957413-10630-1-git-send-email-allison.henderson@oracle.com>
Add parent pointer attribute during xfs_create, and
subroutines to initialize attributes
Kernel create routines take advantage of deferred attributes,
where as libxfs routines will add parent pointers directly.
[bfoster: rebase, use VFS inode generation]
[achender: rebased, changed __unint32_t to xfs_dir2_dataptr_t,
fixed some null pointer bugs,
merged error handling patch,
added subroutines to handle attribute initialization,
remove unnecessary ENOSPC handling in xfs_attr_set_first_parent]
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Allison Henderson <allison.henderson@oracle.com>
---
libxfs/Makefile | 2 +
libxfs/xfs_parent.c | 197 ++++++++++++++++++++++++++++++++++++++++++++++++++++
libxfs/xfs_parent.h | 35 ++++++++++
3 files changed, 234 insertions(+)
diff --git a/libxfs/Makefile b/libxfs/Makefile
index 51ba9d6..9d37e2b 100644
--- a/libxfs/Makefile
+++ b/libxfs/Makefile
@@ -37,6 +37,7 @@ HFILES = \
xfs_ialloc_btree.h \
xfs_inode_buf.h \
xfs_inode_fork.h \
+ xfs_parent.h \
xfs_quota_defs.h \
xfs_refcount.h \
xfs_refcount_btree.h \
@@ -87,6 +88,7 @@ CFILES = cache.c \
xfs_inode_fork.c \
xfs_ialloc_btree.c \
xfs_log_rlimit.c \
+ xfs_parent.c \
xfs_refcount.c \
xfs_refcount_btree.c \
xfs_rmap.c \
diff --git a/libxfs/xfs_parent.c b/libxfs/xfs_parent.c
new file mode 100644
index 0000000..f83815f
--- /dev/null
+++ b/libxfs/xfs_parent.c
@@ -0,0 +1,197 @@
+/*
+ * Copyright (c) 2015 Red Hat, 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
+ */
+#include "xfs.h"
+#include "xfs_fs.h"
+#include "platform_defs.h"
+#include "xfs_arch.h"
+#include "xfs_format.h"
+#include "xfs_da_format.h"
+#include "xfs_log_format.h"
+#include "list.h"
+#include "xfs_shared.h"
+#include "xfs_trans_resv.h"
+#include "radix-tree.h"
+#include "atomic.h"
+#include "xfs_mount.h"
+#include "xfs_da_format.h"
+#include "xfs_bmap_btree.h"
+#include "cache.h"
+#include "xfs_cksum.h"
+#include "libxfs_io.h"
+#include "xfs_inode.h"
+#include "xfs_trace.h"
+#include "xfs_trans.h"
+#include "xfs_da_btree.h"
+#include "xfs_attr.h"
+#include "xfs_da_btree.h"
+#include "xfs_attr_sf.h"
+#include "libxfs_api_defs.h"
+#include "kmem.h"
+#include "xfs_bmap.h"
+
+/*
+ * Parent pointer attribute handling.
+ *
+ * Because the attribute value is a filename component, it will never be longer
+ * than 255 bytes. This means the attribute will always be a local format
+ * attribute as it is xfs_attr_leaf_entsize_local_max() for v5 filesystems will
+ * always be larger than this (max is 75% of block size).
+ *
+ * Creating a new parent attribute will always create a new attribute - there
+ * should never, ever be an existing attribute in the tree for a new inode.
+ * ENOSPC behaviour is problematic - creating the inode without the parent
+ * pointer is effectively a corruption, so we allow parent attribute creation
+ * to dip into the reserve block pool to avoid unexpected ENOSPC errors from
+ * occurring.
+ */
+
+
+/* Initializes a xfs_parent_name_rec to be stored as an attribute name */
+void
+xfs_init_parent_name_rec(
+ struct xfs_parent_name_rec *rec,
+ struct xfs_inode *ip,
+ uint32_t p_diroffset)
+{
+ xfs_ino_t p_ino = ip->i_ino;
+ uint32_t p_gen = VFS_I(ip)->i_generation;
+
+ rec->p_ino = cpu_to_be64(p_ino);
+ rec->p_gen = cpu_to_be32(p_gen);
+ rec->p_diroffset = cpu_to_be32(p_diroffset);
+}
+
+/* Initializes a xfs_parent_name_irec from an xfs_parent_name_rec */
+void
+xfs_init_parent_name_irec(
+ struct xfs_parent_name_irec *irec,
+ struct xfs_parent_name_rec *rec)
+{
+ irec->p_ino = be64_to_cpu(rec->p_ino);
+ irec->p_gen = be32_to_cpu(rec->p_gen);
+ irec->p_diroffset = be32_to_cpu(rec->p_diroffset);
+}
+
+/*
+ * Directly add a parent pointer instead of as a deferred operation
+ * Currently only used during protofile creation
+ */
+int
+xfs_parent_add(
+ struct xfs_inode *parent,
+ struct xfs_inode *child,
+ struct xfs_name *child_name,
+ uint32_t diroffset)
+{
+ struct xfs_parent_name_rec rec;
+ int error, err2;
+ struct xfs_da_args args;
+ int local = 0;
+ int rsvd = 0;
+ struct xfs_buf *leaf_bp = NULL;
+ struct xfs_trans_res tres;
+ struct xfs_mount *mp = child->i_mount;
+ xfs_attr_state_t state = 0;
+ int flags = ATTR_PARENT;
+
+ xfs_init_parent_name_rec(&rec, parent, diroffset);
+
+ error = xfs_attr_args_init(&args, child, (const unsigned char *)&rec,
+ sizeof(rec), flags);
+ if (error)
+ return error;
+
+ args.hashval = xfs_da_hashname(args.name, args.namelen);
+ args.flags = flags;
+ args.value = (uint8_t *)child_name->name;
+ args.valuelen = child_name->len;
+ args.op_flags = XFS_DA_OP_OKNOENT | XFS_DA_OP_ADDNAME;
+ args.total = xfs_attr_calc_size(&args, &local);
+
+ tres.tr_logres = M_RES(mp)->tr_attrsetm.tr_logres +
+ M_RES(mp)->tr_attrsetrt.tr_logres * args.total;
+ tres.tr_logcount = XFS_ATTRSET_LOG_COUNT;
+ tres.tr_logflags = XFS_TRANS_PERM_LOG_RES;
+
+ /*
+ * Root fork attributes can use reserved data blocks for this
+ * operation if necessary
+ */
+ error = xfs_trans_alloc(mp, &tres, args.total, 0,
+ rsvd ? XFS_TRANS_RESERVE : 0, &args.trans);
+ if (error)
+ goto out;
+
+ /*
+ * If the inode doesn't have an attribute fork, add one.
+ * (inode must not be locked when we call this routine)
+ */
+ if (XFS_IFORK_Q(child) == 0) {
+ int sf_size = sizeof(xfs_attr_sf_hdr_t) +
+ XFS_ATTR_SF_ENTSIZE_BYNAME(args.namelen,
+ args.valuelen);
+
+ error = xfs_bmap_add_attrfork(child, sf_size, rsvd);
+ if (error)
+ return error;
+ }
+
+ xfs_trans_ijoin(args.trans, child, 0);
+
+ do {
+ leaf_bp = NULL;
+
+ error = xfs_attr_set_args(&args, &leaf_bp,
+ &state);
+ if (error && error != -EAGAIN)
+ goto out;
+
+ xfs_trans_log_inode(args.trans, child,
+ XFS_ILOG_CORE | XFS_ILOG_ADATA);
+
+ err2 = xfs_trans_commit(args.trans);
+ if (err2) {
+ error = err2;
+ goto out;
+ }
+
+ if (error == -EAGAIN) {
+ err2 = xfs_trans_alloc(mp, &tres, args.total, 0,
+ XFS_TRANS_PERM_LOG_RES, &args.trans);
+ if (err2) {
+ error = err2;
+ goto out;
+ }
+ xfs_trans_ijoin(args.trans, child, 0);
+ }
+ } while (error == -EAGAIN);
+
+ if (leaf_bp)
+ xfs_trans_brelse(args.trans, leaf_bp);
+
+ xfs_trans_log_inode(args.trans, child, XFS_ILOG_CORE);
+
+ return error;
+
+out:
+ if (args.trans)
+ xfs_trans_cancel(args.trans);
+
+ return error;
+}
+
+
diff --git a/libxfs/xfs_parent.h b/libxfs/xfs_parent.h
new file mode 100644
index 0000000..60f1172
--- /dev/null
+++ b/libxfs/xfs_parent.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2018 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_PARENT_H__
+#define __XFS_PARENT_H__
+
+#include "xfs_da_format.h"
+#include "xfs_format.h"
+
+/*
+ * Parent pointer attribute prototypes
+ */
+void xfs_init_parent_name_rec(struct xfs_parent_name_rec *rec,
+ struct xfs_inode *ip,
+ uint32_t p_diroffset);
+void xfs_init_parent_name_irec(struct xfs_parent_name_irec *irec,
+ struct xfs_parent_name_rec *rec);
+
+int xfs_parent_add(struct xfs_inode *parent,
+ struct xfs_inode *child, struct xfs_name *child_name,
+ uint32_t diroffset);
+#endif /* __XFS_PARENT_H__ */
--
2.7.4
next prev parent reply other threads:[~2018-09-26 16:38 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-26 10:23 [PATCH v3 00/30] xfsprogs: parent pointers v2 Allison Henderson
2018-09-26 10:23 ` [PATCH v3 01/30] xfsprogs: Move xfs_attr.h to libxfs Allison Henderson
2018-09-26 10:23 ` [PATCH v3 02/30] xfsprogs: Add helper function xfs_attr_try_sf_addname Allison Henderson
2018-09-26 10:23 ` [PATCH v3 03/30] xfsprogs: Add attibute set and helper functions Allison Henderson
2018-09-26 10:23 ` [PATCH v3 04/30] xfsprogs: Add attibute remove " Allison Henderson
2018-09-26 10:23 ` [PATCH v3 05/30] xfsprogs: Add trans toggle to attr routines Allison Henderson
2018-09-26 10:23 ` [PATCH v3 06/30] xfsprogs: Set up infastructure for deferred attribute operations Allison Henderson
2018-09-26 10:23 ` [PATCH v3 07/30] xfsprogs: Add xfs_attr_set_deferred and xfs_attr_remove_deferred Allison Henderson
2018-09-26 10:23 ` [PATCH v3 08/30] xfsprogs: Add xfs_has_attr and subroutines Allison Henderson
2018-09-26 10:23 ` [PATCH v3 09/30] xfsprogs: Add attr context to log item Allison Henderson
2018-09-26 10:23 ` [PATCH v3 10/30] xfsprogs: Roll delayed attr operations by returning EAGAIN Allison Henderson
2018-09-26 10:23 ` [PATCH v3 11/30] xfsprogs: Remove roll_trans boolean Allison Henderson
2018-09-26 10:23 ` [PATCH v3 12/30] xfsprogs: Remove all strlen calls in all xfs_attr_* functions for attr names Allison Henderson
2018-09-26 10:23 ` [PATCH v3 13/30] xfsprogs: get directory offset when adding directory name Allison Henderson
2018-09-26 10:23 ` [PATCH v3 14/30] xfsprogs: get directory offset when removing " Allison Henderson
2018-09-26 10:23 ` [PATCH v3 15/30] xfsprogs: get directory offset when replacing a " Allison Henderson
2018-09-26 10:23 ` [PATCH v3 16/30] xfsprogs: add parent pointer support to attribute code Allison Henderson
2018-09-26 10:23 ` [PATCH v3 17/30] xfsprogs: define parent pointer xattr format Allison Henderson
2018-09-26 10:23 ` [PATCH v3 18/30] xfsprogs: extent transaction reservations for parent attributes Allison Henderson
2018-09-26 10:23 ` Allison Henderson [this message]
2018-09-26 10:23 ` [PATCH v3 20/30] xfsprogs: Add the parent pointer support to the superblock version 5 Allison Henderson
2018-09-26 10:23 ` [PATCH v3 21/30] xfsprogs: Add helper function xfs_attr_list_context_init Allison Henderson
2018-09-26 10:23 ` [PATCH v3 22/30] xfsprogs: Add parent pointer ioctl Allison Henderson
2018-09-26 10:23 ` [PATCH v3 23/30] xfs_io: Add delayed attributes error tag Allison Henderson
2018-09-26 10:23 ` [PATCH v3 24/30] xfsprogs: Add parent pointer flag to cmd Allison Henderson
2018-09-26 10:23 ` [PATCH v3 25/30] xfsprogs: Add log item printing for ATTRI and ATTRD Allison Henderson
2018-09-26 10:23 ` [PATCH v3 26/30] xfsprogs: Add xfs_verify_pptr Allison Henderson
2018-09-26 10:23 ` [PATCH v3 27/30] xfsprogs: Add parent pointers to recreated inodes Allison Henderson
2018-09-26 10:23 ` [PATCH v3 28/30] xfsprogs: Add parent pointers during protofile creation Allison Henderson
2018-09-26 10:23 ` [PATCH v3 29/30] xfsprogs: implement the upper half of parent pointers Allison Henderson
2018-09-26 10:23 ` [PATCH v3 30/30] xfsprogs: Add i, n and f flags to parent command Allison Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1537957413-10630-20-git-send-email-allison.henderson@oracle.com \
--to=allison.henderson@oracle.com \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).