From 9eafd545537e39677f62f8cb40c96b419533a747 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Sun, 14 Apr 2024 06:09:33 +0200 Subject: [PATCH] FOLD: xfs: merge xfs_imeta_utils.[ch] into xfs_imeta.[ch] --- include/libxfs.h | 1 - include/xfs_inode.h | 4 + include/xfs_trans.h | 4 +- libxfs/Makefile | 2 - libxfs/imeta_utils.c | 320 ------------------------------------------- libxfs/imeta_utils.h | 27 ---- libxfs/trans.c | 6 +- 7 files changed, 10 insertions(+), 354 deletions(-) delete mode 100644 libxfs/imeta_utils.c delete mode 100644 libxfs/imeta_utils.h diff --git a/include/libxfs.h b/include/libxfs.h index a862104cd..34a93f3e2 100644 --- a/include/libxfs.h +++ b/include/libxfs.h @@ -95,7 +95,6 @@ struct iomap; #include "xfs_ag_resv.h" #include "xfs_parent.h" #include "xfs_imeta.h" -#include "imeta_utils.h" #include "xfs_rtbitmap.h" #include "xfs_rtgroup.h" #include "xfs_rtrmap_btree.h" diff --git a/include/xfs_inode.h b/include/xfs_inode.h index 0f4ba3284..10d4edc05 100644 --- a/include/xfs_inode.h +++ b/include/xfs_inode.h @@ -458,4 +458,8 @@ extern void libxfs_irele(struct xfs_inode *ip); int libxfs_ifree_cluster(struct xfs_trans *tp, struct xfs_perag *pag, struct xfs_inode *free_ip, struct xfs_icluster *xic); +static inline void xfs_finish_inode_setup(struct xfs_inode *ip) +{ +} + #endif /* __XFS_INODE_H__ */ diff --git a/include/xfs_trans.h b/include/xfs_trans.h index 630bc85ce..b35506d07 100644 --- a/include/xfs_trans.h +++ b/include/xfs_trans.h @@ -94,8 +94,8 @@ int libxfs_trans_alloc_inode(struct xfs_inode *ip, struct xfs_trans_res *resv, unsigned int dblocks, unsigned int rblocks, bool force, struct xfs_trans **tpp); int libxfs_trans_alloc_dir(struct xfs_inode *dp, struct xfs_trans_res *resv, - struct xfs_inode *ip, unsigned int dblocks, - struct xfs_trans **tpp); + struct xfs_inode *ip, unsigned int *dblocks, + struct xfs_trans **tpp, int *nospace_error); int libxfs_trans_alloc_rollable(struct xfs_mount *mp, uint blocks, struct xfs_trans **tpp); int libxfs_trans_alloc_empty(struct xfs_mount *mp, struct xfs_trans **tpp); diff --git a/libxfs/Makefile b/libxfs/Makefile index ac3484efe..fc31711cc 100644 --- a/libxfs/Makefile +++ b/libxfs/Makefile @@ -23,7 +23,6 @@ HFILES = \ defer_item.h \ libxfs_io.h \ libxfs_api_defs.h \ - imeta_utils.h \ init.h \ iunlink.h \ libxfs_priv.h \ @@ -74,7 +73,6 @@ HFILES = \ CFILES = buf_mem.c \ cache.c \ defer_item.c \ - imeta_utils.c \ init.c \ inode.c \ iunlink.c \ diff --git a/libxfs/imeta_utils.c b/libxfs/imeta_utils.c deleted file mode 100644 index 3b6e891d2..000000000 --- a/libxfs/imeta_utils.c +++ /dev/null @@ -1,320 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * Copyright (c) 2018-2024 Oracle. All Rights Reserved. - * Author: Darrick J. Wong - */ -#include "libxfs_priv.h" -#include "xfs_fs.h" -#include "xfs_shared.h" -#include "xfs_format.h" -#include "xfs_log_format.h" -#include "xfs_da_format.h" -#include "xfs_trans_resv.h" -#include "xfs_trans_space.h" -#include "xfs_mount.h" -#include "xfs_trans.h" -#include "xfs_inode.h" -#include "xfs_da_btree.h" -#include "xfs_bmap_btree.h" -#include "xfs_bit.h" -#include "xfs_sb.h" -#include "xfs_imeta.h" -#include "xfs_trace.h" -#include "xfs_parent.h" -#include "xfs_health.h" -#include "imeta_utils.h" - -/* Initialize a metadata update structure. */ -static inline int -xfs_imeta_init( - struct xfs_mount *mp, - const struct xfs_imeta_path *path, - struct xfs_imeta_update *upd) -{ - struct xfs_trans *tp; - int error; - - memset(upd, 0, sizeof(struct xfs_imeta_update)); - upd->mp = mp; - upd->path = path; - - if (!xfs_has_metadir(mp)) - return 0; - - /* - * Find the parent of the last path component. If the parent path does - * not exist, we consider this corruption because paths are supposed - * to exist. For example, if the path is /quota/user, we require that - * /quota already exists. - */ - error = xfs_trans_alloc_empty(mp, &tp); - if (error) - return error; - error = xfs_imeta_dir_parent(tp, upd->path, &upd->dp); - xfs_trans_cancel(tp); - if (error == -ENOENT) { - xfs_fs_mark_sick(mp, XFS_SICK_FS_METADIR); - return -EFSCORRUPTED; - } - if (error) - return error; - - return xfs_parent_start(mp, &upd->ppargs); -} - -/* - * Unlock and release resources after committing (or cancelling) a metadata - * directory tree operation. The caller retains its reference to @upd->ip - * and must release it explicitly. - */ -static inline void -xfs_imeta_teardown( - struct xfs_imeta_update *upd, - int error) -{ - trace_xfs_imeta_teardown(upd, error); - - if (upd->ppargs) { - xfs_parent_finish(upd->mp, upd->ppargs); - upd->ppargs = NULL; - } - - if (upd->ip) { - if (upd->ip_locked) - xfs_iunlock(upd->ip, XFS_ILOCK_EXCL); - upd->ip_locked = false; - } - - if (upd->dp) { - if (upd->dp_locked) - xfs_iunlock(upd->dp, XFS_ILOCK_EXCL); - upd->dp_locked = false; - - xfs_imeta_irele(upd->dp); - upd->dp = NULL; - } -} - -/* - * Begin the process of creating a metadata file by allocating transactions - * and taking whatever resources we're going to need. - */ -int -xfs_imeta_start_create( - struct xfs_mount *mp, - const struct xfs_imeta_path *path, - struct xfs_imeta_update *upd) -{ - int error; - - error = xfs_imeta_init(mp, path, upd); - if (error) - return error; - - error = xfs_trans_alloc(mp, &M_RES(mp)->tr_imeta_create, - xfs_create_space_res(mp, MAXNAMELEN), 0, 0, &upd->tp); - if (error) - goto out_teardown; - - /* - * Lock the parent directory if there is one. We can't ijoin it to - * the transaction until after the child file has been created. - */ - if (upd->dp) { - xfs_ilock(upd->dp, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT); - upd->dp_locked = true; - } - - trace_xfs_imeta_start_create(upd); - return 0; -out_teardown: - xfs_imeta_teardown(upd, error); - return error; -} - -/* - * Begin the process of linking a metadata file by allocating transactions - * and locking whatever resources we're going to need. - */ -static inline int -xfs_imeta_start_dir_update( - struct xfs_mount *mp, - const struct xfs_imeta_path *path, - struct xfs_inode *ip, - struct xfs_trans_res *tr_resv, - unsigned int resblks, - struct xfs_imeta_update *upd) -{ - int error; - - error = xfs_imeta_init(mp, path, upd); - if (error) - return error; - - upd->ip = ip; - - if (upd->dp) { - error = xfs_trans_alloc_dir(upd->dp, tr_resv, upd->ip, - resblks, &upd->tp); - if (error) - goto out_teardown; - - upd->dp_locked = true; - } else { - error = xfs_trans_alloc_inode(upd->ip, tr_resv, resblks, 0, - false, &upd->tp); - if (error) - goto out_teardown; - } - - upd->ip_locked = true; - return 0; -out_teardown: - xfs_imeta_teardown(upd, error); - return error; -} - -/* - * Begin the process of linking a metadata file by allocating transactions - * and locking whatever resources we're going to need. - */ -int -xfs_imeta_start_link( - struct xfs_mount *mp, - const struct xfs_imeta_path *path, - struct xfs_inode *ip, - struct xfs_imeta_update *upd) -{ - int error; - - error = xfs_imeta_start_dir_update(mp, path, ip, - &M_RES(mp)->tr_imeta_link, - xfs_link_space_res(mp, MAXNAMELEN), upd); - if (error) - return error; - - trace_xfs_imeta_start_link(upd); - return 0; -} - -/* - * Begin the process of unlinking a metadata file by allocating transactions - * and locking whatever resources we're going to need. - */ -int -xfs_imeta_start_unlink( - struct xfs_mount *mp, - const struct xfs_imeta_path *path, - struct xfs_inode *ip, - struct xfs_imeta_update *upd) -{ - int error; - - error = xfs_imeta_start_dir_update(mp, path, ip, - &M_RES(mp)->tr_imeta_unlink, - xfs_remove_space_res(mp, MAXNAMELEN), upd); - if (error) - return error; - - trace_xfs_imeta_start_unlink(upd); - return 0; -} - -/* Commit a metadir update and unlock/drop all resources. */ -int -xfs_imeta_commit_update( - struct xfs_imeta_update *upd) -{ - int error; - - trace_xfs_imeta_update_commit(upd); - - error = xfs_trans_commit(upd->tp); - upd->tp = NULL; - - xfs_imeta_teardown(upd, error); - return error; -} - -/* Cancel a metadir update and unlock/drop all resources. */ -void -xfs_imeta_cancel_update( - struct xfs_imeta_update *upd, - int error) -{ - trace_xfs_imeta_update_cancel(upd); - - xfs_trans_cancel(upd->tp); - upd->tp = NULL; - - xfs_imeta_teardown(upd, error); -} - -/* Create a metadata for the last component of the path. */ -STATIC int -xfs_imeta_mkdir( - struct xfs_mount *mp, - const struct xfs_imeta_path *path) -{ - struct xfs_imeta_update upd; - struct xfs_inode *ip = NULL; - int error; - - if (xfs_is_shutdown(mp)) - return -EIO; - - /* Allocate a transaction to create the last directory. */ - error = xfs_imeta_start_create(mp, path, &upd); - if (error) - return error; - - /* Create the subdirectory and take our reference. */ - error = xfs_imeta_create(&upd, S_IFDIR, &ip); - if (error) - goto out_cancel; - - error = xfs_imeta_commit_update(&upd); - - /* - * We don't pass the directory we just created to the caller, so finish - * setting up the inode, then release the dir and the dquots. - */ - goto out_irele; - -out_cancel: - xfs_imeta_cancel_update(&upd, error); -out_irele: - /* Have to finish setting up the inode to ensure it's deleted. */ - if (ip) - xfs_irele(ip); - return error; -} - -/* - * Make sure that every metadata directory path component exists and is a - * directory. - */ -int -xfs_imeta_ensure_dirpath( - struct xfs_mount *mp, - const struct xfs_imeta_path *path) -{ - struct xfs_imeta_path temp_path = { - .im_path = path->im_path, - .im_depth = 1, - .im_ftype = XFS_DIR3_FT_DIR, - }; - unsigned int i; - int error = 0; - - if (!xfs_has_metadir(mp)) - return 0; - - for (i = 0; i < path->im_depth - 1; i++, temp_path.im_depth++) { - error = xfs_imeta_mkdir(mp, &temp_path); - if (error && error != -EEXIST) - return error; - } - - return 0; -} diff --git a/libxfs/imeta_utils.h b/libxfs/imeta_utils.h deleted file mode 100644 index f1bd66999..000000000 --- a/libxfs/imeta_utils.h +++ /dev/null @@ -1,27 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* - * Copyright (c) 2018-2024 Oracle. All Rights Reserved. - * Author: Darrick J. Wong - */ -#ifndef __XFS_IMETA_UTILS_H__ -#define __XFS_IMETA_UTILS_H__ - -int xfs_imeta_start_create(struct xfs_mount *mp, - const struct xfs_imeta_path *path, - struct xfs_imeta_update *upd); - -int xfs_imeta_start_link(struct xfs_mount *mp, - const struct xfs_imeta_path *path, - struct xfs_inode *ip, struct xfs_imeta_update *upd); - -int xfs_imeta_start_unlink(struct xfs_mount *mp, - const struct xfs_imeta_path *path, - struct xfs_inode *ip, struct xfs_imeta_update *upd); - -int xfs_imeta_ensure_dirpath(struct xfs_mount *mp, - const struct xfs_imeta_path *path); - -int xfs_imeta_commit_update(struct xfs_imeta_update *upd); -void xfs_imeta_cancel_update(struct xfs_imeta_update *upd, int error); - -#endif /* __XFS_IMETA_UTILS_H__ */ diff --git a/libxfs/trans.c b/libxfs/trans.c index 3c5d6383e..5eecb009a 100644 --- a/libxfs/trans.c +++ b/libxfs/trans.c @@ -1227,11 +1227,13 @@ libxfs_trans_alloc_dir( struct xfs_inode *dp, struct xfs_trans_res *resv, struct xfs_inode *ip, - unsigned int resblks, - struct xfs_trans **tpp) + unsigned int *dblocks, + struct xfs_trans **tpp, + int *nospace_error) { struct xfs_trans *tp; struct xfs_mount *mp = ip->i_mount; + unsigned int resblks = *dblocks; int error; error = xfs_trans_alloc(mp, resv, resblks, 0, 0, &tp); -- 2.50.1