From: Allison Henderson <allison.henderson@oracle.com>
To: linux-xfs@vger.kernel.org
Subject: [PATCH v8 20/28] xfs: parent pointer attribute creation
Date: Tue, 28 Aug 2018 12:22:33 -0700 [thread overview]
Message-ID: <1535484161-11059-21-git-send-email-allison.henderson@oracle.com> (raw)
In-Reply-To: <1535484161-11059-1-git-send-email-allison.henderson@oracle.com>
From: Dave Chinner <dchinner@redhat.com>
Add parent pointer attribute during xfs_create, and
subroutines to initialize attributes
[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>
---
fs/xfs/Makefile | 2 +
fs/xfs/libxfs/xfs_parent.c | 101 +++++++++++++++++++++++++++++++++++++++++++++
fs/xfs/libxfs/xfs_parent.h | 35 ++++++++++++++++
fs/xfs/xfs_inode.c | 17 +++++++-
fs/xfs/xfs_parent_utils.c | 52 +++++++++++++++++++++++
fs/xfs/xfs_parent_utils.h | 26 ++++++++++++
6 files changed, 231 insertions(+), 2 deletions(-)
diff --git a/fs/xfs/Makefile b/fs/xfs/Makefile
index 022e0b4..45a3360 100644
--- a/fs/xfs/Makefile
+++ b/fs/xfs/Makefile
@@ -42,6 +42,7 @@ xfs-y += $(addprefix libxfs/, \
xfs_inode_fork.o \
xfs_inode_buf.o \
xfs_log_rlimit.o \
+ xfs_parent.o \
xfs_ag_resv.o \
xfs_rmap.o \
xfs_rmap_btree.o \
@@ -82,6 +83,7 @@ xfs-y += xfs_aops.o \
xfs_message.o \
xfs_mount.o \
xfs_mru_cache.o \
+ xfs_parent_utils.o \
xfs_reflink.o \
xfs_stats.o \
xfs_super.o \
diff --git a/fs/xfs/libxfs/xfs_parent.c b/fs/xfs/libxfs/xfs_parent.c
new file mode 100644
index 0000000..5045f65
--- /dev/null
+++ b/fs/xfs/libxfs/xfs_parent.c
@@ -0,0 +1,101 @@
+/*
+ * 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 "xfs_format.h"
+#include "xfs_da_format.h"
+#include "xfs_log_format.h"
+#include "xfs_shared.h"
+#include "xfs_trans_resv.h"
+#include "xfs_mount.h"
+#include "xfs_bmap_btree.h"
+#include "xfs_inode.h"
+#include "xfs_error.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 "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;
+ int flags = ATTR_PARENT;
+
+ xfs_init_parent_name_rec(&rec, parent, diroffset);
+
+ error = xfs_attr_set(child, (const unsigned char *)&rec, sizeof(rec),
+ (char *)child_name->name, child_name->len, flags);
+
+ return error;
+}
+
diff --git a/fs/xfs/libxfs/xfs_parent.h b/fs/xfs/libxfs/xfs_parent.h
new file mode 100644
index 0000000..60f1172
--- /dev/null
+++ b/fs/xfs/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__ */
diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
index d7e06c2..3f722e6 100644
--- a/fs/xfs/xfs_inode.c
+++ b/fs/xfs/xfs_inode.c
@@ -41,6 +41,7 @@
#include "xfs_bmap_btree.h"
#include "xfs_reflink.h"
#include "xfs_dir2_priv.h"
+#include "xfs_parent_utils.h"
kmem_zone_t *xfs_inode_zone;
@@ -1151,6 +1152,7 @@ xfs_create(
struct xfs_dquot *pdqp = NULL;
struct xfs_trans_res *tres;
uint resblks;
+ xfs_dir2_dataptr_t diroffset;
trace_xfs_create(dp, name);
@@ -1219,13 +1221,13 @@ xfs_create(
* the transaction cancel unlocking dp so don't do it explicitly in the
* error path.
*/
- xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL);
+ xfs_trans_ijoin(tp, dp, 0);
unlock_dp_on_error = false;
error = xfs_dir_createname(tp, dp, name, ip->i_ino,
resblks ?
resblks - XFS_IALLOC_SPACE_RES(mp) : 0,
- NULL);
+ &diroffset);
if (error) {
ASSERT(error != -ENOSPC);
goto out_trans_cancel;
@@ -1244,6 +1246,16 @@ xfs_create(
}
/*
+ * If we have parent pointers, we need to add the attribute containing
+ * the parent information now.
+ */
+ if (xfs_sb_version_hasparent(&mp->m_sb)) {
+ error = xfs_parent_add_deferred(dp, tp, ip, name, diroffset);
+ if (error)
+ goto out_trans_cancel;
+ }
+
+ /*
* If this is a synchronous mount, make sure that the
* create transaction goes to disk before returning to
* the user.
@@ -1268,6 +1280,7 @@ xfs_create(
*ipp = ip;
xfs_iunlock(ip, XFS_ILOCK_EXCL);
+ xfs_iunlock(dp, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
return 0;
out_trans_cancel:
diff --git a/fs/xfs/xfs_parent_utils.c b/fs/xfs/xfs_parent_utils.c
new file mode 100644
index 0000000..f84a4fd
--- /dev/null
+++ b/fs/xfs/xfs_parent_utils.c
@@ -0,0 +1,52 @@
+/*
+ * 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 "xfs_format.h"
+#include "xfs_log_format.h"
+#include "xfs_shared.h"
+#include "xfs_trans_resv.h"
+#include "xfs_mount.h"
+#include "xfs_bmap_btree.h"
+#include "xfs_inode.h"
+#include "xfs_error.h"
+#include "xfs_trace.h"
+#include "xfs_trans.h"
+#include "xfs_da_format.h"
+#include "xfs_da_btree.h"
+#include "xfs_attr.h"
+#include "xfs_parent.h"
+
+/*
+ * Add a parent record to an inode with existing parent records.
+ */
+int
+xfs_parent_add_deferred(
+ struct xfs_inode *parent,
+ struct xfs_trans *tp,
+ struct xfs_inode *child,
+ struct xfs_name *child_name,
+ uint32_t diroffset)
+{
+ struct xfs_parent_name_rec rec;
+
+ xfs_init_parent_name_rec(&rec, parent, diroffset);
+
+ return xfs_attr_set_deferred(child, tp, &rec, sizeof(rec),
+ (void *)child_name->name, child_name->len, ATTR_PARENT);
+}
+
diff --git a/fs/xfs/xfs_parent_utils.h b/fs/xfs/xfs_parent_utils.h
new file mode 100644
index 0000000..82453d2
--- /dev/null
+++ b/fs/xfs/xfs_parent_utils.h
@@ -0,0 +1,26 @@
+/*
+ * 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_PARENT_UTILS_H__
+#define __XFS_PARENT_UTILS_H__
+
+/*
+ * Parent pointer attribute prototypes
+ */
+int xfs_parent_add_deferred(struct xfs_inode *parent, struct xfs_trans *tp,
+ struct xfs_inode *child, struct xfs_name *child_name,
+ uint32_t diroffset);
+#endif /* __XFS_PARENT_UTILS_H__ */
--
2.7.4
next prev parent reply other threads:[~2018-08-28 23:18 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-28 19:22 [PATCH v8 00/28] Parent Pointers v8 Allison Henderson
2018-08-28 19:22 ` [PATCH v8 01/28] xfs: Move fs/xfs/xfs_attr.h to fs/xfs/libxfs/xfs_attr.h Allison Henderson
2018-08-28 19:22 ` [PATCH v8 02/28] xfs: Add helper function xfs_attr_try_sf_addname Allison Henderson
2018-08-28 19:22 ` [PATCH v8 03/28] xfs: Add attibute set and helper functions Allison Henderson
2018-08-28 19:22 ` [PATCH v8 04/28] xfs: Add attibute remove " Allison Henderson
2018-08-28 19:22 ` [PATCH v8 05/28] xfs: Hold inode locks in xfs_ialloc Allison Henderson
2018-08-28 19:22 ` [PATCH v8 06/28] xfs: Add trans toggle to attr routines Allison Henderson
2018-08-28 19:22 ` [PATCH v8 07/28] xfs: Set up infastructure for deferred attribute operations Allison Henderson
2018-08-28 19:22 ` [PATCH v8 08/28] xfs: Add xfs_attr_set_deferred and xfs_attr_remove_deferred Allison Henderson
2018-08-28 19:22 ` [PATCH v8 09/28] xfs: Add xfs_has_attr and subroutines Allison Henderson
2018-08-28 19:22 ` [PATCH v8 10/28] xfs: Add attr context to log item Allison Henderson
2018-08-28 19:22 ` [PATCH v8 11/28] xfs: Roll delayed attr operations by returning EAGAIN Allison Henderson
2018-08-28 19:22 ` [PATCH v8 12/28] xfs: Remove roll_trans boolean Allison Henderson
2018-08-28 19:22 ` [PATCH v8 13/28] xfs: Remove all strlen calls in all xfs_attr_* functions for attr names Allison Henderson
2018-08-28 19:22 ` [PATCH v8 14/28] xfs: get directory offset when adding directory name Allison Henderson
2018-08-28 19:22 ` [PATCH v8 15/28] xfs: get directory offset when removing " Allison Henderson
2018-08-28 19:22 ` [PATCH v8 16/28] xfs: get directory offset when replacing a " Allison Henderson
2018-08-28 19:22 ` [PATCH v8 17/28] xfs: add parent pointer support to attribute code Allison Henderson
2018-08-28 19:22 ` [PATCH v8 18/28] xfs: define parent pointer xattr format Allison Henderson
2018-08-28 19:22 ` [PATCH v8 19/28] xfs: extent transaction reservations for parent attributes Allison Henderson
2018-08-28 19:22 ` Allison Henderson [this message]
2018-08-28 19:22 ` [PATCH v8 21/28] xfs: add parent attributes to link Allison Henderson
2018-08-28 19:22 ` [PATCH v8 22/28] xfs: remove parent pointers in unlink Allison Henderson
2018-08-28 19:22 ` [PATCH v8 23/28] xfs: Add parent pointers to rename Allison Henderson
2018-09-03 3:20 ` Dave Chinner
2018-09-03 5:28 ` Amir Goldstein
2018-09-04 18:31 ` Allison Henderson
2018-09-04 18:31 ` Allison Henderson
2018-08-28 19:22 ` [PATCH v8 24/28] xfs: Add the parent pointer support to the superblock version 5 Allison Henderson
2018-08-28 19:22 ` [PATCH v8 25/28] xfs: Add helper function xfs_attr_list_context_init Allison Henderson
2018-08-28 19:22 ` [PATCH v8 26/28] xfs: Increase XFS_DEFER_OPS_NR_INODES to 4 Allison Henderson
2018-08-28 19:22 ` [PATCH v8 27/28] xfs: Add parent pointer ioctl Allison Henderson
2018-08-28 19:22 ` [PATCH v8 28/28] xfs: Add delayed attributes error tag Allison Henderson
2018-09-03 1:20 ` [PATCH v8 00/28] Parent Pointers v8 Dave Chinner
2018-09-03 1:40 ` Dave Chinner
2018-09-04 18:31 ` Allison Henderson
2018-09-03 5:41 ` Dave Chinner
2018-09-04 18:32 ` 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=1535484161-11059-21-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).