xfs: sync libxfs with 5.14
cover xfs: sync libxfs with 5.14
Hi all,
This patchset backports all the libxfs changes from kernel 5.14, as well as all the related for_each_perag and fallthrough; cleanups that went with it. I've prepared this series and pull request per Eric's request.
If you're going to start using this mess, you probably ought to just pull from my git trees, which are linked below.
This is an extraordinary way to destroy everything. Enjoy! Comments and questions are, as always, welcome.
--D
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=libxfs-5.14-sync
--- db/fsmap.c | 17 - db/info.c | 18 - db/type.c | 2 growfs/xfs_growfs.c | 6 include/atomic.h | 1 include/libxfs.h | 3 include/linux.h | 17 + include/xfs_mount.h | 65 --- include/xfs_multidisk.h | 5 libfrog/Makefile | 3 libfrog/mockups.h | 43 ++ libfrog/radix-tree.h | 3 libxfs/Makefile | 10 libxfs/init.c | 147 +++---- libxfs/libxfs_api_defs.h | 2 libxfs/libxfs_priv.h | 18 + libxfs/topology.c | 5 libxfs/topology.h | 6 libxfs/util.c | 12 - libxfs/xfs_ag.c | 287 +++++++++++++ libxfs/xfs_ag.h | 136 ++++++ libxfs/xfs_ag_resv.c | 15 - libxfs/xfs_ag_resv.h | 15 + libxfs/xfs_alloc.c | 113 +++-- libxfs/xfs_alloc.h | 2 libxfs/xfs_alloc_btree.c | 31 + libxfs/xfs_alloc_btree.h | 9 libxfs/xfs_attr.c | 956 ++++++++++++++++++++++++++----------------- libxfs/xfs_attr.h | 403 ++++++++++++++++++ libxfs/xfs_attr_leaf.c | 5 libxfs/xfs_attr_leaf.h | 2 libxfs/xfs_attr_remote.c | 167 +++----- libxfs/xfs_attr_remote.h | 8 libxfs/xfs_bmap.c | 3 libxfs/xfs_bmap.h | 1 libxfs/xfs_btree.c | 15 - libxfs/xfs_btree.h | 12 - libxfs/xfs_da_btree.c | 2 libxfs/xfs_ialloc.c | 696 ++++++++++++++++--------------- libxfs/xfs_ialloc.h | 43 -- libxfs/xfs_ialloc_btree.c | 46 +- libxfs/xfs_ialloc_btree.h | 13 - libxfs/xfs_inode_buf.c | 30 + libxfs/xfs_log_format.h | 14 - libxfs/xfs_refcount.c | 122 +++-- libxfs/xfs_refcount.h | 9 libxfs/xfs_refcount_btree.c | 39 +- libxfs/xfs_refcount_btree.h | 7 libxfs/xfs_rmap.c | 147 +++---- libxfs/xfs_rmap.h | 6 libxfs/xfs_rmap_btree.c | 46 +- libxfs/xfs_rmap_btree.h | 8 libxfs/xfs_sb.c | 145 ------- libxfs/xfs_sb.h | 9 libxfs/xfs_shared.h | 20 - libxfs/xfs_trans_inode.c | 10 libxfs/xfs_types.c | 4 libxfs/xfs_types.h | 1 mkfs/proto.c | 1 mkfs/proto.h | 13 + mkfs/xfs_mkfs.c | 11 repair/agbtree.c | 28 + repair/agbtree.h | 8 repair/dinode.c | 18 - repair/phase4.c | 4 repair/phase5.c | 16 - repair/rmap.c | 43 +- repair/sb.c | 1 repair/scan.c | 4 scrub/inodes.c | 2 scrub/repair.c | 2 scrub/scrub.c | 8 72 files changed, 2520 insertions(+), 1619 deletions(-) create mode 100644 libfrog/mockups.h rename libfrog/topology.c => libxfs/topology.c (99%) rename libfrog/topology.h => libxfs/topology.h (88%) create mode 100644 mkfs/proto.h
PATCH 1/61 mkfs: move mkfs/proto.c declarations to mkfs/proto.h
From: Darrick J. Wong <[email protected]>
These functions are only used by mkfs, so move them to a separate header file that isn't in an internal library.
--- include/xfs_multidisk.h | 5 ----- mkfs/proto.c | 1 + mkfs/proto.h | 13 +++++++++++++ mkfs/xfs_mkfs.c | 1 + 4 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 mkfs/proto.h
include/xfs_multidisk.h +0 -5
@@ -42,9 +42,4 @@#define XFS_NOMULTIDISK_AGLOG 2/* 4 AGs */ #define XFS_MULTIDISK_AGCOUNT (1 << XFS_MULTIDISK_AGLOG) -/* proto.c */ -extern char *setup_proto (char *fname); -extern void parse_proto (xfs_mount_t *mp,struct fsxattr *fsx,char **pp); -extern void res_failed (int err); -#endif /* __XFS_MULTIDISK_H__ */
mkfs/proto.c +1 -0
@@ -7,6 +7,7 @@#include "libxfs.h" #include <sys/stat.h> #include "libfrog/convert.h" +#include "proto.h" /* * Prototypes for internal functions.
mkfs/proto.h new file +13 -0
@@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2000-2001,2004-2005 Silicon Graphics, Inc. +* All Rights Reserved. +*/ +#ifndef MKFS_PROTO_H_ +#define MKFS_PROTO_H_ + +extern char *setup_proto (char *fname); +extern void parse_proto (xfs_mount_t *mp,struct fsxattr *fsx,char **pp); +extern void res_failed (int err); + +#endif /* MKFS_PROTO_H_ */
mkfs/xfs_mkfs.c +1 -0
@@ -11,6 +11,7 @@#include "libfrog/fsgeom.h" #include "libfrog/topology.h" #include "libfrog/convert.h" +#include "proto.h" #include <ini.h> #define TERABYTES (count, blog) ((uint64_t)(count) << (40 - (blog)))
Re: [PATCH 01/61] mkfs: move mkfs/proto.c declarations to mkfs/proto.h
mkfs/proto.h line 11
Quoted 3 lines
mkfs/proto.h new file +3
-0+extern char *setup_proto (char *fname); +extern void parse_proto (xfs_mount_t *mp,struct fsxattr *fsx,char **pp); +extern void res_failed (int err);
It might be worth to drop the externs, the spaces before the opening braces and the xfs_mount_t typedef usage while you're at it.
Otherwise looks good:
PATCH 2/61 libfrog: move topology.[ch] to libxfs
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
The topology code depends on a few libxfs structures and is only needed by mkfs and xfs_repair. Move this code to libxfs to reduce the size of libfrog and to avoid build failures caused by "xfs: move perag structure and setup to libxfs/xfs_ag.[ch]".
--- include/libxfs.h | 1 + libfrog/Makefile | 2 -- libxfs/Makefile | 10 ++++++---- libxfs/topology.c | 5 ++--- libxfs/topology.h | 6 +++--- mkfs/xfs_mkfs.c | 1 - repair/sb.c | 1 - 7 files changed, 12 insertions(+), 14 deletions(-) rename libfrog/topology.c => libxfs/topology.c (99%) rename libfrog/topology.h => libxfs/topology.h (88%)
include/libxfs.h +1 -0
@@ -213,5 +213,6 @@ int libxfs_rtfree_extent(struct xfs_trans *, xfs_rtblock_t, xfs_extlen_t);bool libxfs_verify_rtbno (struct xfs_mount *mp,xfs_rtblock_t rtbno);#include "xfs_attr.h" +#include "topology.h" #endif /* __LIBXFS_H__ */
libfrog/Makefile +0 -2
@@ -27,7 +27,6 @@ projects.c \ ptvar.c \ radix-tree.c \ scrub.c \ -topology.c \ util.c \ workqueue.c
@@ -47,7 +46,6 @@ projects.h \ ptvar.h \ radix-tree.h \ scrub.h \ -topology.h \ workqueue.h LSRCFILES += gen_crc32table.c
libxfs/Makefile +6 -4
@@ -20,6 +20,11 @@ PKGHFILES = xfs_fs.h \ xfs_log_format.h HFILES = \ + libxfs_io.h \ + libxfs_api_defs.h \ + init.h \ + libxfs_priv.h \ + topology.h \ xfs_ag_resv.h \ xfs_alloc.h \ xfs_alloc_btree.h \
@@ -48,10 +53,6 @@ HFILES = \ xfs_shared.h \ xfs_trans_resv.h \ xfs_trans_space.h \ - libxfs_io.h \ - libxfs_api_defs.h \ - init.h \ - libxfs_priv.h \ xfs_dir2_priv.h CFILES = cache.c \
@@ -60,6 +61,7 @@ CFILES = cache.c \ kmem.c \ logitem.c \ rdwr.c \ + topology.c \ trans.c \ util.c \ xfs_ag.c \
libxfs/topology.c renamed from libfrog/topology.c +2 -3
@@ -4,14 +4,13 @@* All Rights Reserved. */ -#include "libxfs.h" +#include "libxfs_priv.h" #include "libxcmd.h" #ifdef ENABLE_BLKID # include <blkid/blkid.h> #endif /* ENABLE_BLKID */ #include "xfs_multidisk.h" -#include "topology.h" -#include "platform.h" +#include "libfrog/platform.h" #define TERABYTES (count, blog) ((uint64_t)(count) << (40 - (blog)))#define GIGABYTES (count, blog) ((uint64_t)(count) << (30 - (blog)))
libxfs/topology.h renamed from libfrog/topology.h +3 -3
@@ -4,8 +4,8 @@* All Rights Reserved. */ -#ifndef __LIBFROG_TOPOLOGY_H__ -#define __LIBFROG_TOPOLOGY_H__ +#ifndef __LIBXFS_TOPOLOGY_H__ +#define __LIBXFS_TOPOLOGY_H__/* * Device topology information.
@@ -36,4 +36,4 @@ extern intcheck_overwrite ( const char *device); -#endif /* __LIBFROG_TOPOLOGY_H__ */ +#endif /* __LIBXFS_TOPOLOGY_H__ */
mkfs/xfs_mkfs.c +0 -1
@@ -9,7 +9,6 @@#include "xfs_multidisk.h" #include "libxcmd.h" #include "libfrog/fsgeom.h" -#include "libfrog/topology.h" #include "libfrog/convert.h" #include "proto.h" #include <ini.h>
repair/sb.c +0 -1
@@ -12,7 +12,6 @@#include "protos.h" #include "err_protos.h" #include "xfs_multidisk.h" -#include "libfrog/topology.h" #define BSIZE (1024 * 1024)
Re: [PATCH 02/61] libfrog: move topology.[ch] to libxfs
Quoted 8 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
The topology code depends on a few libxfs structures and is only needed by mkfs and
xfs_repair. Move this code to libxfs to reduce the size of libfrog and to avoid build failures caused by "xfs: move perag structure and setup to libxfs/xfs_ag.[ch]".Signed-off-by Darrick J. Wong <[email protected]>
Looks good,
PATCH 3/61 libfrog: create header file for mocked-up kernel data structures
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Create a mockups.h for mocked-up versions of kernel data structures to ease porting of libxfs code.
--- include/libxfs.h | 1 + libfrog/Makefile | 1 + libfrog/mockups.h | 19 +++++++++++++++++++ libxfs/libxfs_priv.h | 4 +--- 4 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 libfrog/mockups.h
include/libxfs.h +1 -0
@@ -17,6 +17,7 @@#include "bitops.h" #include "kmem.h" #include "libfrog/radix-tree.h" +#include "libfrog/mockups.h" #include "atomic.h" #include "xfs_types.h"
libfrog/Makefile +1 -0
@@ -41,6 +41,7 @@ crc32defs.h \ crc32table.h \ fsgeom.h \ logging.h \ +mockups.h \ paths.h \ projects.h \ ptvar.h \
libfrog/mockups.h new file +19 -0
@@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2000-2005 Silicon Graphics, Inc. +* All Rights Reserved. +*/ +#ifndef __LIBFROG_MOCKUPS_H__ +#define __LIBFROG_MOCKUPS_H__ + +/* Mockups of kernel data structures. */ + +typedef struct spinlock { +}spinlock_t ; + +#define spin_lock_init (lock) ((void) 0) + +#define spin_lock (a) ((void) 0) +#define spin_unlock (a) ((void) 0) + +#endif /* __LIBFROG_MOCKUPS_H__ */
libxfs/libxfs_priv.h +1 -3
@@ -47,6 +47,7 @@#include "bitops.h" #include "kmem.h" #include "libfrog/radix-tree.h" +#include "libfrog/mockups.h" #include "atomic.h" #include "xfs_types.h"
@@ -205,9 +206,6 @@ enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC };#endif /* miscellaneous kernel routines not in user space */ -#define spin_lock_init (a) ((void) 0) -#define spin_lock (a) ((void) 0) -#define spin_unlock (a) ((void) 0)#define likely (x) (x)#define unlikely (x) (x)#define rcu_read_lock () ((void) 0)
Re: [PATCH 03/61] libfrog: create header file for mocked-up kernel data structures
Quoted 5 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Create a
mockups.hfor mocked-up versions of kernel data structures to ease porting of libxfs code.
Quoted 7 lines
Signed-off-by Darrick J. Wong <[email protected]>--- include/libxfs.h | 1 + libfrog/Makefile | 1 + libfrog/mockups.h | 19 +++++++++++++++++++ libxfs/libxfs_priv.h | 4 +--- 4 files changed, 22 insertions(+), 3 deletions(-)
I don't really like moving this stuff to libfrog. The whole point of libxfs/libxfs_priv.h is to define the kernel wrapper stuff that libxfs needs to compile and should never be seen by anything outside libxfs/...
Indeed, we -cannot- use spinlocks in userspace code, so I really don't see why we'd want to make them more widely visible to the userspace xfsprogs code...
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 03/61] libfrog: create header file for mocked-up kernel data structures
Quoted 14 lines · Dave Chinner
Quoted 5 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Create a
mockups.hfor mocked-up versions of kernel data structures to ease porting of libxfs code.Quoted 7 lines
Signed-off-by Darrick J. Wong <[email protected]>--- include/libxfs.h | 1 + libfrog/Makefile | 1 + libfrog/mockups.h | 19 +++++++++++++++++++ libxfs/libxfs_priv.h | 4 +--- 4 files changed, 22 insertions(+), 3 deletions(-)
Quoted 4 lines
I don't really like moving this stuff to libfrog. The whole point of
libxfs/libxfs_priv.his to define the kernel wrapper stuff that libxfs needs to compile and should never be seen by anything outside libxfs/...
How did you handle this in your xfsprogs port? I /think/ the only reason we need the mockups is to handle the perag structure in xfs_ag.h? In that case, I guess one could simply omit the stuff below the "kernel only structures below this line" line?
In that case, can you (or anyone, really) fix libxfs-compare to be smart enough to filter out the "#ifdef __KERNEL__" parts of libxfs from the diff?
--D
Quoted 10 lines
Indeed, we -cannot- use spinlocks in userspace code, so I really don't see why we'd want to make them more widely visible to the userspace xfsprogs code...
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 03/61] libfrog: create header file for mocked-up kernel data structures
Quoted 20 lines · Darrick J. Wong
Quoted 14 lines · Dave Chinner
Quoted 5 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Create a
mockups.hfor mocked-up versions of kernel data structures to ease porting of libxfs code.Quoted 7 lines
Signed-off-by Darrick J. Wong <[email protected]>--- include/libxfs.h | 1 + libfrog/Makefile | 1 + libfrog/mockups.h | 19 +++++++++++++++++++ libxfs/libxfs_priv.h | 4 +--- 4 files changed, 22 insertions(+), 3 deletions(-)Quoted 4 lines
I don't really like moving this stuff to libfrog. The whole point of
libxfs/libxfs_priv.his to define the kernel wrapper stuff that libxfs needs to compile and should never be seen by anything outside libxfs/...
Quoted 4 lines
How did you handle this in your xfsprogs port? I /think/ the only reason we need the mockups is to handle the perag structure in
xfs_ag.h? In that case, I guess one could simply omit the stuff below the "kernel only structures below this line" line?
I just put an #ifdef __KERNEL__ in the userspace code, like we have in userspace libxfs/xfs_btree.c for the btree split hand-off code.
Quoted 3 lines
In that case, can you (or anyone, really) fix libxfs-compare to be smart enough to filter out the "#ifdef
__KERNEL__" parts of libxfs from the diff?
You mean tools/libxfs-diff? I'm not sure that's a simple thing to do because of the #else cases that go along with define in xfs_btree.c. Is there really enough noise from libxfs-diff at the moment that this is actually a problem?
As it is, my longer term plan it to actually properly support things like spinlocks, atomics, rcu, etc in xfsprogs via pthread and liburcu wrappers defined in include/<foo.h> that are xfsprogs wide. At that point, the wrappers in libxfs/libxfs_priv.h then simply disappear.
I'd prefer we move towards proper support for these primitives rather than just rearranging how we mock them up...
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 03/61] libfrog: create header file for mocked-up kernel data structures
Quoted 8 lines · Dave Chinner
As it is, my longer term plan it to actually properly support things like spinlocks, atomics, rcu, etc in xfsprogs via pthread and liburcu wrappers defined in include/<foo.h> that are xfsprogs wide. At that point, the wrappers in
libxfs/libxfs_priv.hthen simply disappear.I'd prefer we move towards proper support for these primitives rather than just rearranging how we mock them up...
Just dug some patches out of a series (not up to date so probably won't apply, but...) so you can see what I'm suggesting. I'll post them as a reply here...
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
cover xfsprogs: generic serialisation primitives
Hi Darrick,
This is where I think we should be going with spinlocks, atomics, and other primitives that the shared libxfs code depends on in the kernel...
-Dave.
PATCH 1/5 xfsprogs: introduce liburcu support
From: Dave Chinner <[email protected]>
The upcoming buffer cache rework/kerenl sync-up requires atomic variables. I could use C++11 atomics build into GCC, but they are a pain to work with and shoe-horn into the kernel atomic variable API.
Much easier is to introduce a dependency on liburcu - the userspace RCU library. This provides atomic variables that very closely match the kernel atomic variable API, and it provides a very similar memory model and memory barrier support to the kernel. And we get RCU support that has an identical interface to the kernel and works the same way.
Hence kernel code written with RCU algorithms and atomic variables will just slot straight into the userspace xfsprogs code without us having to think about whether the lockless algorithms will work in userspace or not. This reduces glue and hoop jumping, and gets us a step closer to having the entire userspace libxfs code MT safe.
--- configure.ac | 3 +++ copy/Makefile | 3 ++- copy/xfs_copy.c | 3 +++ db/Makefile | 3 ++- debian/control | 2 +- growfs/Makefile | 3 ++- include/builddefs.in | 4 +++- include/platform_defs.h.in | 1 + libfrog/workqueue.c | 3 +++ libxfs/init.c | 3 +++ libxfs/libxfs_priv.h | 3 +-- logprint/Makefile | 3 ++- m4/Makefile | 1 + mdrestore/Makefile | 3 ++- mkfs/Makefile | 2 +- repair/Makefile | 2 +- repair/prefetch.c | 9 +++++++-- repair/progress.c | 4 +++- scrub/Makefile | 3 ++- scrub/progress.c | 2 ++ 20 files changed, 45 insertions(+), 15 deletions(-)
configure.ac +3 -0
@@ -154,6 +154,9 @@ AC_PACKAGE_NEED_UUIDCOMPARE AC_PACKAGE_NEED_PTHREAD_H AC_PACKAGE_NEED_PTHREADMUTEXINIT +AC_PACKAGE_NEED_URCU_H +AC_PACKAGE_NEED_RCU_INIT + AC_HAVE_FADVISE AC_HAVE_MADVISE AC_HAVE_MINCORE
copy/Makefile +2 -1
@@ -9,7 +9,8 @@ LTCOMMAND = xfs_copy CFILES = xfs_copy.c HFILES = xfs_copy.h -LLDLIBS = $(LIBXFS) $(LIBXLOG) $(LIBFROG) $(LIBUUID) $(LIBPTHREAD) $(LIBRT) +LLDLIBS = $(LIBXFS) $(LIBXLOG) $(LIBFROG) $(LIBUUID) $(LIBPTHREAD) $(LIBRT) \ + $(LIBURCU) LTDEPENDENCIES = $(LIBXFS) $(LIBXLOG) $(LIBFROG) LLDFLAGS = -static-libtool-libs
copy/xfs_copy.c +3 -0
@@ -110,6 +110,7 @@ do_message(int flags, int code, const char *fmt, ...)fprintf (stderr,_ ("Aborting XFS copy -- logfile error -- reason: %s\n" ),strerror (errno)); +rcu_unregister_thread ();pthread_exit (NULL ); } }
@@ -224,6 +225,7 @@ begin_reader(void *arg) {thread_args *args = arg; +rcu_register_thread ();for (;;) {pthread_mutex_lock (&args->wait);if (do_write (args,NULL ))
@@ -243,6 +245,7 @@ handle_error:if (--glob_masks.num_working ==0 )pthread_mutex_unlock (&mainwait);pthread_mutex_unlock (&glob_masks.mutex); +rcu_unregister_thread ();pthread_exit (NULL );return NULL ; }
db/Makefile +2 -1
@@ -18,7 +18,8 @@ CFILES = $(HFILES:.h=.c) btdump.c btheight.c convert.c info.c namei.c \ timelimit.c LSRCFILES = xfs_admin.sh xfs_ncheck.sh xfs_metadump.sh -LLDLIBS = $(LIBXFS) $(LIBXLOG) $(LIBFROG) $(LIBUUID) $(LIBRT) $(LIBPTHREAD) +LLDLIBS = $(LIBXFS) $(LIBXLOG) $(LIBFROG) $(LIBUUID) $(LIBRT) $(LIBPTHREAD) \ + $(LIBURCU) LTDEPENDENCIES = $(LIBXFS) $(LIBXLOG) $(LIBFROG) LLDFLAGS += -static-libtool-libs
debian/control +1 -1
@@ -3,7 +3,7 @@ Section: admin Priority: optional Maintainer: XFS Development Team <[email protected]> Uploaders: Nathan Scott <[email protected]>, Anibal Monsalve Salazar <[email protected]>, Bastian Germann <[email protected]> -Build-Depends: libinih-dev (>= 53), uuid-dev, dh-autoreconf, debhelper (>= 5), gettext, libtool, libedit-dev, libblkid-dev (>= 2.17), linux-libc-dev, libdevmapper-dev, libattr1-dev, libicu-dev, pkg-config +Build-Depends: libinih-dev (>= 53), uuid-dev, dh-autoreconf, debhelper (>= 5), gettext, libtool, libedit-dev, libblkid-dev (>= 2.17), linux-libc-dev, libdevmapper-dev, libattr1-dev, libicu-dev, pkg-config, liburcu-dev Standards-Version: 4.0.0 Homepage: https://xfs.wiki.kernel.org/
growfs/Makefile +2 -1
@@ -9,7 +9,8 @@ LTCOMMAND = xfs_growfs CFILES = xfs_growfs.c -LLDLIBS = $(LIBXFS) $(LIBXCMD) $(LIBFROG) $(LIBUUID) $(LIBRT) $(LIBPTHREAD) +LLDLIBS = $(LIBXFS) $(LIBXCMD) $(LIBFROG) $(LIBUUID) $(LIBRT) $(LIBPTHREAD) \ + $(LIBURCU) ifeq ($(ENABLE_EDITLINE),yes) LLDLIBS += $(LIBEDITLINE) $(LIBTERMCAP)
include/builddefs.in +3 -1
@@ -22,6 +22,7 @@ LDFLAGS = LIBRT = @librt@ LIBUUID = @libuuid@ +LIBURCU = @liburcu@ LIBPTHREAD = @libpthread@ LIBTERMCAP = @libtermcap@ LIBEDITLINE = @libeditline@
@@ -125,7 +126,8 @@ CROND_DIR = @crond_dir@ GCCFLAGS = -funsigned-char -fno-strict-aliasing -Wall # -Wbitwise -Wno-transparent-union -Wno-old-initializer -Wno-decl -PCFLAGS = -D_GNU_SOURCE $(GCCFLAGS) +# _LGPL_SOURCE is for liburcu to work correctly with GPL/LGPL programs +PCFLAGS = -D_LGPL_SOURCE -D_GNU_SOURCE $(GCCFLAGS) ifeq ($(HAVE_UMODE_T),yes) PCFLAGS += -DHAVE_UMODE_T endif
include/platform_defs.h.in +1 -0
@@ -23,6 +23,7 @@ #include <limits.h> #include <stdbool.h> #include <libgen.h> +#include <urcu.h> typedef struct filldir filldir_t;
libfrog/workqueue.c +3 -0
@@ -11,6 +11,7 @@#include <stdbool.h> #include <errno.h> #include <assert.h> +#include <urcu.h> #include "workqueue.h" /* Main processing thread */
@@ -24,6 +25,7 @@ workqueue_thread(void *arg)* Loop pulling work from the passed in work queue. * Check for notification to exit after every chunk of work. */ +rcu_register_thread ();while (1 ) {pthread_mutex_lock (&wq->lock);
@@ -60,6 +62,7 @@ workqueue_thread(void *arg) (wi->function)(wi->queue, wi->index, wi->arg);free (wi); } +rcu_unregister_thread ();return NULL ; }
libxfs/init.c +3 -0
@@ -310,6 +310,8 @@ libxfs_init(libxfs_init_t *a) fd =-1 ; flags = (a->isreadonly | a->isdirect); +rcu_init (); +rcu_register_thread ();radix_tree_init ();if (a->volname) {
@@ -1023,6 +1025,7 @@ libxfs_destroy(libxfs_bcache_free ();cache_destroy (libxfs_bcache); leaked =destroy_zones (); +rcu_unregister_thread ();if (getenv ("LIBXFS_LEAK_CHECK" ) && leaked)exit (1 ); }
libxfs/libxfs_priv.h +1 -2
@@ -210,8 +210,7 @@ enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC };#define spin_unlock (a) ((void) 0)#define likely (x) (x)#define unlikely (x) (x) -#define rcu_read_lock () ((void) 0) -#define rcu_read_unlock () ((void) 0) +/* Need to be able to handle this bare or in control flow */ static inline bool WARN_ON (bool expr) {return (expr);
logprint/Makefile +2 -1
@@ -12,7 +12,8 @@ CFILES = logprint.c \ log_copy.c log_dump.c log_misc.c \ log_print_all.c log_print_trans.c log_redo.c -LLDLIBS = $(LIBXFS) $(LIBXLOG) $(LIBFROG) $(LIBUUID) $(LIBRT) $(LIBPTHREAD) +LLDLIBS = $(LIBXFS) $(LIBXLOG) $(LIBFROG) $(LIBUUID) $(LIBRT) $(LIBPTHREAD) \ + $(LIBURCU) LTDEPENDENCIES = $(LIBXFS) $(LIBXLOG) $(LIBFROG) LLDFLAGS = -static-libtool-libs
m4/Makefile +1 -0
@@ -24,6 +24,7 @@ LSRCFILES = \ package_services.m4 \ package_types.m4 \ package_icu.m4 \ + package_urcu.m4 \ package_utilies.m4 \ package_uuiddev.m4 \ multilib.m4 \
mdrestore/Makefile +2 -1
@@ -8,7 +8,8 @@ include $(TOPDIR)/include/builddefs LTCOMMAND = xfs_mdrestore CFILES = xfs_mdrestore.c -LLDLIBS = $(LIBXFS) $(LIBFROG) $(LIBRT) $(LIBPTHREAD) $(LIBUUID) +LLDLIBS = $(LIBXFS) $(LIBFROG) $(LIBRT) $(LIBPTHREAD) $(LIBUUID) \ + $(LIBURCU) LTDEPENDENCIES = $(LIBXFS) $(LIBFROG) LLDFLAGS = -static
mkfs/Makefile +1 -1
@@ -11,7 +11,7 @@ HFILES = CFILES = proto.c xfs_mkfs.c LLDLIBS += $(LIBXFS) $(LIBXCMD) $(LIBFROG) $(LIBRT) $(LIBPTHREAD) $(LIBBLKID) \ - $(LIBUUID) $(LIBINIH) + $(LIBUUID) $(LIBINIH) $(LIBURCU) LTDEPENDENCIES += $(LIBXFS) $(LIBXCMD) $(LIBFROG) LLDFLAGS = -static-libtool-libs
repair/Makefile +1 -1
@@ -72,7 +72,7 @@ CFILES = \ xfs_repair.c LLDLIBS = $(LIBXFS) $(LIBXLOG) $(LIBXCMD) $(LIBFROG) $(LIBUUID) $(LIBRT) \ - $(LIBPTHREAD) $(LIBBLKID) + $(LIBPTHREAD) $(LIBBLKID) $(LIBURCU) LTDEPENDENCIES = $(LIBXFS) $(LIBXLOG) $(LIBXCMD) $(LIBFROG) LLDFLAGS = -static-libtool-libs
repair/prefetch.c +7 -2
@@ -660,6 +660,7 @@ pf_io_worker(if (buf ==NULL )return NULL ; +rcu_register_thread ();pthread_mutex_lock (&args->lock);while (!args->queuing_done || !btree_is_empty (args->io_queue)) {pftrace ("waiting to start prefetch I/O for AG %d" , args->agno);
@@ -682,6 +683,7 @@ pf_io_worker(free (buf);pftrace ("finished prefetch I/O for AG %d" , args->agno); +rcu_unregister_thread ();return NULL ; }
@@ -726,6 +728,8 @@ pf_queuing_worker(struct xfs_ino_geometry *igeo =M_IGEO (mp);unsigned long long cluster_mask; +rcu_register_thread (); + cluster_mask = (1ULL << igeo->inodes_per_cluster) -1 ;for (i =0 ; i <PF_THREAD_COUNT ; i++) {
@@ -739,7 +743,7 @@ pf_queuing_worker( args->io_threads[i] =0 ;if (i ==0 ) {pf_skip_prefetch_thread (args); -return NULL ; + goto out; }/* * since we have at least one I/O thread, use them for
@@ -779,7 +783,6 @@ pf_queuing_worker(* Start processing as well, in case everything so * far was already prefetched and the queue is empty. */ -pf_start_io_workers (args);pf_start_processing (args);sem_wait (&args->ra_count);
@@ -841,6 +844,8 @@ pf_queuing_worker(if (next_args)pf_create_prefetch_thread (next_args); +out: +rcu_unregister_thread ();return NULL ; }
repair/progress.c +3 -1
@@ -182,6 +182,7 @@ progress_rpt_thread (void *p)do_error (_ ("progress_rpt: cannot malloc progress msg buffer\n" )); running =1 ; +rcu_register_thread ();/* * Specify a repeating timer that fires each MSG_INTERVAL seconds.
@@ -286,7 +287,8 @@ progress_rpt_thread (void *p)do_warn (_ ("cannot delete timer\n" ));free (msgbuf); -return (NULL ); +rcu_unregister_thread (); +return NULL ; }int
scrub/Makefile +2 -1
@@ -71,7 +71,8 @@ spacemap.c \ vfs.c \ xfs_scrub.c -LLDLIBS += $(LIBHANDLE) $(LIBFROG) $(LIBPTHREAD) $(LIBICU_LIBS) $(LIBRT) +LLDLIBS += $(LIBHANDLE) $(LIBFROG) $(LIBPTHREAD) $(LIBICU_LIBS) $(LIBRT) \ + $(LIBURCU) LTDEPENDENCIES += $(LIBHANDLE) $(LIBFROG) LLDFLAGS = -static
scrub/progress.c +2 -0
@@ -116,6 +116,7 @@ progress_report_thread(void *arg)struct timespec abstime;int ret; +rcu_register_thread ();pthread_mutex_lock (&pt.lock);while (1 ) {uint64_t progress_val;
@@ -139,6 +140,7 @@ progress_report_thread(void *arg)progress_report (progress_val); }pthread_mutex_unlock (&pt.lock); +rcu_unregister_thread ();return NULL ; }
Signature · 1 line
2.33.0
Re: [PATCH 1/5] xfsprogs: introduce liburcu support
Quoted 1 line · Dave Chinner
From: Dave Chinner <[email protected]>
..
Quoted 7 lines
Hence kernel code written with RCU algorithms and atomic variables will just slot straight into the userspace xfsprogs code without us having to think about whether the lockless algorithms will work in userspace or not. This reduces glue and hoop jumping, and gets us a step closer to having the entire userspace libxfs code MT safe.
Signed-off-by Dave Chinner <[email protected]>
...
m4/Makefile LSRCFILES = \ · line 27
Quoted 9 lines
m4/Makefile +1
-0@@ -24,6 +24,7 @@ LSRCFILES = \ package_services.m4 \ package_types.m4 \ package_icu.m4 \ + package_urcu.m4 \
This new m4 file is missing from the patchset, I think?
Thanks,
-Eric
Re: [PATCH 1/5] xfsprogs: introduce liburcu support
Quoted 13 lines · Eric Sandeen
Quoted 1 line · Dave Chinner
From: Dave Chinner <[email protected]>
..
Quoted 6 lines
Hence kernel code written with RCU algorithms and atomic variables will just slot straight into the userspace xfsprogs code without us having to think about whether the lockless algorithms will work in userspace or not. This reduces glue and hoop jumping, and gets us a step closer to having the entire userspace libxfs code MT safe.
Signed-off-by Dave Chinner <[email protected]>...
Quoted 12 lines
m4/Makefile LSRCFILES = \ · line 27
Quoted 9 lines
m4/Makefile +1
-0@@ -24,6 +24,7 @@ LSRCFILES = \ package_services.m4 \ package_types.m4 \ package_icu.m4 \ + package_urcu.m4 \This new m4 file is missing from the patchset, I think?
urcu.h maps rcu_init()/rcu_[un]register_thread() to one of the userspace variants e.g. rcu_init() may be mapped to urcu_mb_init(). The configure script generated by autoconf does not include urcu.h in the code snippet it generates to detect availability of rcu_init(). Hence the linker complains about not finding rcu_init() causing configure script to declare that liburcu is not present on the system.
After finding the root cause, I searched through configure.ac scripts of Knot DNS (https://www.knot-dns.cz/) and found that the project was using rcu_set_pointer_sym() as the function in their m4 macros.
The changes can be obtained from
https://github.com/chandanr/xfsprogs-dev/commit/d227e8aac894ffe1d688c6c658b445ca56a173fb
Signature · 1 line
chandan
PATCH 2/5 libxfs: add spinlock_t wrapper
In reply to Dave ChinnerFrom: Dave Chinner <[email protected]>
These provide the kernel spinlock_t interface, but are *not* spinlocks. Spinlocks cannot be used by general purpose userspace processes due to the fact they cannot control task preemption and scheduling reliability. Hence these are implemented as a pthread_mutex_t, similar to the way the kernel RT build implements spinlock_t as a kernel mutex.
Because the current libxfs spinlock "implementation" just makes spinlocks go away, we have to also add initialisation to spinlocks that libxfs uses that are missing from the userspace implementation.
--- include/Makefile | 1 + include/libxfs.h | 1 + include/spinlock.h | 25 +++++++++++++++++++++++++ include/xfs_inode.h | 1 + include/xfs_mount.h | 2 ++ include/xfs_trans.h | 1 + libxfs/init.c | 4 +++- libxfs/libxfs_priv.h | 4 +--- libxfs/rdwr.c | 2 ++ 9 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 include/spinlock.h
include/Makefile +1 -0
@@ -16,6 +16,7 @@ LIBHFILES = libxfs.h \ kmem.h \ list.h \ parent.h \ + spinlock.h \ xfs_inode.h \ xfs_log_recover.h \ xfs_metadump.h \
include/libxfs.h +1 -0
@@ -18,6 +18,7 @@#include "kmem.h" #include "libfrog/radix-tree.h" #include "atomic.h" +#include "spinlock.h" #include "xfs_types.h" #include "xfs_fs.h"
include/spinlock.h new file +25 -0
@@ -0,0 +1,25 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2019-20 RedHat, Inc. +* All Rights Reserved. +*/ +#ifndef __LIBXFS_SPINLOCK_H__ +#define __LIBXFS_SPINLOCK_H__ + +/* +* This implements kernel compatible spinlock exclusion semantics. These, +* however, are not spinlocks, as spinlocks cannot be reliably implemented in +* userspace without using realtime scheduling task contexts. Hence this +* interface is implemented with pthread mutexes and so can block, but this is +* no different to the kernel RT build which replaces spinlocks with mutexes. +* Hence we know it works. +*/ + +typedef pthread_mutex_t spinlock_t ; + +#define spin_lock_init (l) pthread_mutex_init(l, NULL) +#define spin_lock (l) pthread_mutex_lock(l) +#define spin_trylock (l) (pthread_mutex_trylock(l) != EBUSY) +#define spin_unlock (l) pthread_mutex_unlock(l) + +#endif /* __LIBXFS_SPINLOCK_H__ */
include/xfs_inode.h +1 -0
@@ -43,6 +43,7 @@ struct inode {struct timespec64 i_atime;struct timespec64 i_mtime;struct timespec64 i_ctime; +spinlock_t i_lock; };static inline uint32_t i_uid_read (struct inode *inode)
include/xfs_mount.h +2 -0
@@ -22,6 +22,7 @@ typedef struct xfs_mount {#define m_icount m_sb.sb_icount#define m_ifree m_sb.sb_ifree#define m_fdblocks m_sb.sb_fdblocks +spinlock_t m_sb_lock;/* * Bitsets of per-fs metadata that have been checked and/or are sick.
@@ -32,6 +33,7 @@ typedef struct xfs_mount {char *m_fsname;/* filesystem name */ int m_bsize;/* fs logical block size */ +spinlock_t m_agirotor_lock;xfs_agnumber_t m_agfrotor;/* last ag where space found */ xfs_agnumber_t m_agirotor;/* last ag dir inode alloced */ xfs_agnumber_t m_maxagi;/* highest inode alloc group */
include/xfs_trans.h +1 -0
@@ -35,6 +35,7 @@ struct xfs_inode_log_item {unsigned int ili_last_fields;/* fields when flushed*/ unsigned int ili_fields;/* fields to be logged */ unsigned int ili_fsync_fields;/* ignored by userspace */ +spinlock_t ili_lock; }; typedef struct xfs_buf_log_item {
libxfs/init.c +3 -1
@@ -743,7 +743,9 @@ libxfs_mount( mp->m_flags = (LIBXFS_MOUNT_32BITINODES |LIBXFS_MOUNT_32BITINOOPT ); mp->m_sb = *sb;INIT_RADIX_TREE (&mp->m_perag_tree,GFP_KERNEL ); - sbp = &(mp->m_sb); + sbp = &mp->m_sb; +spin_lock_init (&mp->m_sb_lock); +spin_lock_init (&mp->m_agirotor_lock);xfs_sb_mount_common (mp, sb);
libxfs/libxfs_priv.h +1 -3
@@ -48,6 +48,7 @@#include "kmem.h" #include "libfrog/radix-tree.h" #include "atomic.h" +#include "spinlock.h" #include "xfs_types.h" #include "xfs_arch.h"
@@ -205,9 +206,6 @@ enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC };#endif /* miscellaneous kernel routines not in user space */ -#define spin_lock_init (a) ((void) 0) -#define spin_lock (a) ((void) 0) -#define spin_unlock (a) ((void) 0)#define likely (x) (x)#define unlikely (x) (x)
libxfs/rdwr.c +2 -0
@@ -1070,6 +1070,8 @@ libxfs_iget(VFS_I (ip)->i_count =1 ; ip->i_ino = ino; ip->i_mount = mp; +spin_lock_init (&VFS_I (ip)->i_lock); + error =xfs_imap (mp, tp, ip->i_ino, &ip->i_imap,0 );if (error) goto out_destroy;
Signature · 1 line
2.33.0
PATCH 3/5 atomic: convert to uatomic
In reply to Dave ChinnerFrom: Dave Chinner <[email protected]>
Now we have liburcu, we can make use of it's atomic variable implementation. It is almost identical to the kernel API - it's just got a "uatomic" prefix. liburcu also provides all the same aomtic variable memory barriers as the kernel, so if we pull memory barrier dependent kernel code across, it will just work with the right barrier wrappers.
This is preparation the addition of more extensive atomic operations the that kernel buffer cache requires to function correctly.
--- include/atomic.h | 65 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 11 deletions(-)
include/atomic.h +54 -11
@@ -7,21 +7,64 @@#define __ATOMIC_H__/* -* Warning: These are not really atomic at all. They are wrappers around the -* kernel atomic variable interface. If we do need these variables to be atomic -* (due to multithreading of the code that uses them) we need to add some -* pthreads magic here. +* Atomics are provided by liburcu. +* +* API and guidelines for which operations provide memory barriers is here: +* +* https://github.com/urcu/userspace-rcu/blob/master/doc/uatomic-api.md +* +* Unlike the kernel, the same interface supports 32 and 64 bit atomic integers. */ +#include <urcu/uatomic.h> +#include "spinlock.h" +typedef int32_t atomic_t ;typedef int64_t atomic64_t ; -#define atomic_inc_return (x) (++(*(x))) -#define atomic_dec_return (x) (--(*(x))) +#define atomic_read (a) uatomic_read(a) +#define atomic_set (a, v) uatomic_set(a, v) +#define atomic_add (a, v) uatomic_add(a, v) +#define atomic_sub (a, v) uatomic_sub(a, v) +#define atomic_inc (a) uatomic_inc(a) +#define atomic_dec (a) uatomic_dec(a) +#define atomic_inc_return (a) uatomic_add_return(a, 1) +#define atomic_dec_return (a) uatomic_sub_return(a, 1) +#define atomic_dec_and_test (a) (atomic_dec_return(a) == 0) +#define cmpxchg (a, o, n) uatomic_cmpxchg(a, o, n); + +static inline bool atomic_add_unless (atomic_t *a,int v,int u) +{ +int r =atomic_read (a); +int n, o; + +do { + o = r; +if (o == u) +break ; + n = o + v; + r =uatomic_cmpxchg (a, o, n); + }while (r != o); + +return o != u; +} + +static inline bool atomic_dec_and_lock (atomic_t *a,spinlock_t *lock) +{ +if (atomic_add_unless (a,-1 ,1 )) +return 0 ; + +spin_lock (lock); +if (atomic_dec_and_test (a)) +return 1 ; +spin_unlock (lock); +return 0 ; +} -#define atomic64_read (x) *(x) -#define atomic64_set (x, v) (*(x) = v) -#define atomic64_add (v, x) (*(x) += v) -#define atomic64_inc (x) ((*(x))++) -#define atomic64_dec (x) ((*(x))--) +#define atomic64_read (x) uatomic_read(x) +#define atomic64_set (x, v) uatomic_set(x, v) +#define atomic64_add (a, v) uatomic_add(a, v) +#define atomic64_sub (a, v) uatomic_sub(a, v) +#define atomic64_inc (a) uatomic_inc(a) +#define atomic64_dec (a) uatomic_dec(a)#endif /* __ATOMIC_H__ */
Signature · 1 line
2.33.0
PATCH 4/5 libxfs: add kernel-compatible completion API
In reply to Dave ChinnerFrom: Dave Chinner <[email protected]>
This is needed for the kernel buffer cache conversion to be able to wait on IO synchrnously. It is implemented with pthread mutexes and conditional variables.
--- include/Makefile | 1 + include/completion.h | 61 ++++++++++++++++++++++++++++++++++++++++++++ include/libxfs.h | 1 + libxfs/libxfs_priv.h | 1 + 4 files changed, 64 insertions(+) create mode 100644 include/completion.h
include/Makefile +1 -0
@@ -12,6 +12,7 @@ LIBHFILES = libxfs.h \ atomic.h \ bitops.h \ cache.h \ + completion.h \ hlist.h \ kmem.h \ list.h \
include/completion.h new file +61 -0
61 lines not on this page · raw message
include/libxfs.h +1 -0
@@ -19,6 +19,7 @@#include "libfrog/radix-tree.h" #include "atomic.h" #include "spinlock.h" +#include "completion.h" #include "xfs_types.h" #include "xfs_fs.h"
libxfs/libxfs_priv.h +1 -0
@@ -49,6 +49,7 @@#include "libfrog/radix-tree.h" #include "atomic.h" #include "spinlock.h" +#include "completion.h" #include "xfs_types.h" #include "xfs_arch.h"
Signature · 1 line
2.33.0
PATCH 5/5 libxfs: add wrappers for kernel semaphores
In reply to Dave ChinnerFrom: Dave Chinner <[email protected]>
Implemented via pthread mutexes.
On Linux, fast pthread mutexes don't actaully check which thread owns the lock on unlock, so can be used in situations where the unlock occurs in a different thread to the lock. This is non-portable behaviour, so if other platforms are supported, this may need to be converted to posix semaphores.
--- include/Makefile | 1 + include/libxfs.h | 1 + include/sema.h | 35 +++++++++++++++++++++++++++++++++++ libxfs/libxfs_priv.h | 1 + 4 files changed, 38 insertions(+) create mode 100644 include/sema.h
include/Makefile +1 -0
@@ -17,6 +17,7 @@ LIBHFILES = libxfs.h \ kmem.h \ list.h \ parent.h \ + sema.h \ spinlock.h \ xfs_inode.h \ xfs_log_recover.h \
include/libxfs.h +1 -0
@@ -20,6 +20,7 @@#include "atomic.h" #include "spinlock.h" #include "completion.h" +#include "sema.h" #include "xfs_types.h" #include "xfs_fs.h"
include/sema.h new file +35 -0
@@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2019-20 RedHat, Inc. +* All Rights Reserved. +*/ +#ifndef __LIBXFS_SEMA_H__ +#define __LIBXFS_SEMA_H__ + +/* +* This implements kernel compatible semaphore _exclusion_ semantics. It does +* not implement counting semaphore behaviour. +* +* This makes use of the fact that fast pthread mutexes on Linux don't check +* that the unlocker is the same thread that locked the mutex, and hence can be +* unlocked in a different thread safely. +* +* If this needs to be portable or we require counting semaphore behaviour in +* libxfs code, this requires re-implementation based on posix semaphores. +*/ +struct semaphore { +pthread_mutex_t lock; +}; + +#define sema_init (l, nolock) \ +do { \ + pthread_mutex_init(&(l)->lock, NULL); \ + if (!nolock) \ + pthread_mutex_lock(&(l)->lock); \ +} while (0) + +#define down (l) pthread_mutex_lock(&(l)->lock) +#define down_trylock (l) pthread_mutex_trylock(&(l)->lock) +#define up (l) pthread_mutex_unlock(&(l)->lock) + +#endif /* __LIBXFS_SEMA_H__ */
libxfs/libxfs_priv.h +1 -0
@@ -50,6 +50,7 @@#include "atomic.h" #include "spinlock.h" #include "completion.h" +#include "sema.h" #include "xfs_types.h" #include "xfs_arch.h"
Signature · 1 line
2.33.0
Re: [PATCH 0/5] xfsprogs: generic serialisation primitives
In reply to Dave ChinnerQuoted 7 lines · Dave Chinner
Hi Darrick,
This is where I think we should be going with spinlocks, atomics, and other primitives that the shared libxfs code depends on in the kernel...
-Dave.
So is the proposal that we aim to merge this prior to the 5.14 resync?
Or is this just a demonstration of future things to come ;)
I'm ok with pulling it in now, especially if it helps future work and avoids pointless mockup reshuffling ...
-Eric
Re: [External] : [PATCH 0/5] xfsprogs: generic serialisation primitives
In reply to Dave ChinnerQuoted 7 lines · Dave Chinner
Hi Darrick,
This is where I think we should be going with spinlocks, atomics, and other primitives that the shared libxfs code depends on in the kernel...
-Dave.
I will work on getting this cleanly applied on top of current xfsprogs code base.
Signature · 1 line
chandan
Re: [PATCH 03/61] libfrog: create header file for mocked-up kernel data structures
In reply to Dave ChinnerQuoted 14 lines · Dave Chinner
Quoted 5 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Create a
mockups.hfor mocked-up versions of kernel data structures to ease porting of libxfs code.Quoted 7 lines
Signed-off-by Darrick J. Wong <[email protected]>--- include/libxfs.h | 1 + libfrog/Makefile | 1 + libfrog/mockups.h | 19 +++++++++++++++++++ libxfs/libxfs_priv.h | 4 +--- 4 files changed, 22 insertions(+), 3 deletions(-)
Quoted 4 lines
I don't really like moving this stuff to libfrog. The whole point of
libxfs/libxfs_priv.his to define the kernel wrapper stuff that libxfs needs to compile and should never be seen by anything outside libxfs/...
I had the same reaction to seeing these in libfrog/ TBH.
IIRC adding this all to libxfs_priv.h caused me problems, though I don't remember exactly why. I had more luck creating a new header file in include/mockups.h, and then I had to include /that/ in both libxfs.h and libxfs_priv.h. I don't remember how I ended up like that... but without the libxfs.h include, I ended up with:
In file included from ../include/libxfs.h:73:0,
from topology.c:7:../libxfs/xfs_ag.h:75:2: error: unknown type name 'spinlock_t'
spinlock_t pag_state_lock;
^
I do think that more functionally-named, separate header files might be good, rather than just "dump more stuff in libxfs_priv.h" because it's getting to be quite the junk drawer. ;)
But I see Dave may have a grander plan than that ;)
-Eric
Quoted 8 lines
Indeed, we -cannot- use spinlocks in userspace code, so I really don't see why we'd want to make them more widely visible to the userspace xfsprogs code...
Cheers,
Dave.
PATCH 4/61 libxfs: port xfs_set_inode_alloc from the kernel
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
To prepare to perag initialization code move to libxfs, port the xfs_set_inode_alloc function from the kernel and make libxfs_initialize_perag use it. The code isn't 1:1 identical, but AFAICT it behaves the same way. In a future kernel release we'll move the function into xfs_ag.c and update xfsprogs.
--- libxfs/init.c | 142 ++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 89 insertions(+), 53 deletions(-)
libxfs/init.c +89 -53
@@ -482,18 +482,102 @@ rtmount_init(return 0 ; } +/* +* Set parameters for inode allocation heuristics, taking into account +* filesystem size and inode32/inode64 mount options; i.e. specifically +* whether or not XFS_MOUNT_SMALL_INUMS is set. +* +* Inode allocation patterns are altered only if inode32 is requested +* (XFS_MOUNT_SMALL_INUMS), and the filesystem is sufficiently large. +* If altered, XFS_MOUNT_32BITINODES is set as well. +* +* An agcount independent of that in the mount structure is provided +* because in the growfs case, mp->m_sb.sb_agcount is not yet updated +* to the potentially higher ag count. +* +* Returns the maximum AG index which may contain inodes. +*/ +xfs_agnumber_t +xfs_set_inode_alloc ( +struct xfs_mount *mp, +xfs_agnumber_t agcount) +{ +xfs_agnumber_t index; +xfs_agnumber_t maxagi =0 ; +xfs_sb_t *sbp = &mp->m_sb; +xfs_agnumber_t max_metadata; +xfs_agino_t agino; +xfs_ino_t ino; + +/* +* Calculate how much should be reserved for inodes to meet +* the max inode percentage. Used only for inode32. +*/ +if (M_IGEO (mp)->maxicount) { +uint64_t icount; + + icount = sbp->sb_dblocks * sbp->sb_imax_pct; +do_div (icount,100 ); + icount += sbp->sb_agblocks -1 ; +do_div (icount, sbp->sb_agblocks); + max_metadata = icount; + }else { + max_metadata = agcount; + } + +/* Get the last possible inode in the filesystem */ + agino =XFS_AGB_TO_AGINO (mp, sbp->sb_agblocks -1 ); + ino =XFS_AGINO_TO_INO (mp, agcount -1 , agino); + +/* +* If user asked for no more than 32-bit inodes, and the fs is +* sufficiently large, set XFS_MOUNT_32BITINODES if we must alter +* the allocator to accommodate the request. +*/ +if ((mp->m_flags &XFS_MOUNT_SMALL_INUMS ) && ino >XFS_MAXINUMBER_32 ) + mp->m_flags |=XFS_MOUNT_32BITINODES ; +else + mp->m_flags &= ~XFS_MOUNT_32BITINODES ; + +for (index =0 ; index < agcount; index++) { +struct xfs_perag *pag; + + ino =XFS_AGINO_TO_INO (mp, index, agino); + + pag =xfs_perag_get (mp, index); + +if (mp->m_flags &XFS_MOUNT_32BITINODES ) { +if (ino >XFS_MAXINUMBER_32 ) { + pag->pagi_inodeok =0 ; + pag->pagf_metadata =0 ; + }else { + pag->pagi_inodeok =1 ; + maxagi++; +if (index < max_metadata) + pag->pagf_metadata =1 ; +else + pag->pagf_metadata =0 ; + } + }else { + pag->pagi_inodeok =1 ; + pag->pagf_metadata =0 ; + } + +xfs_perag_put (pag); + } + +return (mp->m_flags &XFS_MOUNT_32BITINODES ) ? maxagi : agcount; +} +static int libxfs_initialize_perag (xfs_mount_t *mp,xfs_agnumber_t agcount,xfs_agnumber_t *maxagi) { -xfs_agnumber_t index, max_metadata; +xfs_agnumber_t index;xfs_agnumber_t first_initialised =0 ;xfs_perag_t *pag; -xfs_agino_t agino; -xfs_ino_t ino; -xfs_sb_t *sbp = &mp->m_sb;int error = -ENOMEM ;/*
@@ -522,55 +606,7 @@ libxfs_initialize_perag( } } -/* -* If we mount with the inode64 option, or no inode overflows -* the legacy 32-bit address space clear the inode32 option. -*/ - agino =XFS_AGB_TO_AGINO (mp, sbp->sb_agblocks -1 ); - ino =XFS_AGINO_TO_INO (mp, agcount -1 , agino); - -if ((mp->m_flags &XFS_MOUNT_SMALL_INUMS ) && ino >XFS_MAXINUMBER_32 ) - mp->m_flags |=XFS_MOUNT_32BITINODES ; -else - mp->m_flags &= ~XFS_MOUNT_32BITINODES ; - -if (mp->m_flags &XFS_MOUNT_32BITINODES ) { -/* -* Calculate how much should be reserved for inodes to meet -* the max inode percentage. -*/ -if (M_IGEO (mp)->maxicount) { -uint64_t icount; - - icount = sbp->sb_dblocks * sbp->sb_imax_pct; -do_div (icount,100 ); - icount += sbp->sb_agblocks -1 ; -do_div (icount, sbp->sb_agblocks); - max_metadata = icount; - }else { - max_metadata = agcount; - } - -for (index =0 ; index < agcount; index++) { - ino =XFS_AGINO_TO_INO (mp, index, agino); -if (ino >XFS_MAXINUMBER_32 ) { - index++; -break ; - } - - pag =xfs_perag_get (mp, index); - pag->pagi_inodeok =1 ; -if (index < max_metadata) - pag->pagf_metadata =1 ; -xfs_perag_put (pag); - } - }else { -for (index =0 ; index < agcount; index++) { - pag =xfs_perag_get (mp, index); - pag->pagi_inodeok =1 ; -xfs_perag_put (pag); - } - } + index =xfs_set_inode_alloc (mp, agcount);if (maxagi) *maxagi = index;
Re: [PATCH 04/61] libxfs: port xfs_set_inode_alloc from the kernel
Quoted 9 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
To prepare to perag initialization code move to libxfs, port the
xfs_set_inode_allocfunction from the kernel and makelibxfs_initialize_peraguse it. The code isn't 1:1 identical, but AFAICT it behaves the same way. In a future kernel release we'll move the function intoxfs_ag.cand update xfsprogs.Signed-off-by Darrick J. Wong <[email protected]>
Ok, so this is in effect syncing up:
commit 2d2194f61fddab3a9731b6e7a7ae3a4a19dd810c
Author: Carlos Maiolino <[email protected]> Date: Thu Sep 20 10:32:38 2012 -0300
xfs: reduce code duplication handling inode32/64 options
and a few others up to about this change:
commit 12c3f05c7b592ae3bf2219392f1cbf252645cd79
Author: Eric Sandeen <[email protected]> Date: Wed Mar 2 09:58:09 2016 +1100
xfs: fix up inode32/64 (re)mount handling
from the kernel. The pitfalls of having copied kernel code that's not in libxfs. :(
The change looks legit and works fine here.
Thanks,
-Eric
Quoted 174 lines
--- libxfs/init.c | 142 ++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 89 insertions(+), 53 deletions(-)libxfs/init.c +89
-53@@ -482,18 +482,102 @@ rtmount_init(return 0 ; } +/* +* Set parameters for inode allocation heuristics, taking into account +* filesystem size and inode32/inode64 mount options; i.e. specifically +* whether or not XFS_MOUNT_SMALL_INUMS is set. +* +* Inode allocation patterns are altered only if inode32 is requested +* (XFS_MOUNT_SMALL_INUMS), and the filesystem is sufficiently large. +* If altered, XFS_MOUNT_32BITINODES is set as well. +* +* An agcount independent of that in the mount structure is provided +* because in the growfs case, mp->m_sb.sb_agcount is not yet updated +* to the potentially higher ag count. +* +* Returns the maximum AG index which may contain inodes. +*/ +xfs_agnumber_t +xfs_set_inode_alloc ( +struct xfs_mount *mp, +xfs_agnumber_t agcount) +{ +xfs_agnumber_t index; +xfs_agnumber_t maxagi =0 ; +xfs_sb_t *sbp = &mp->m_sb; +xfs_agnumber_t max_metadata; +xfs_agino_t agino; +xfs_ino_t ino; + +/* +* Calculate how much should be reserved for inodes to meet +* the max inode percentage. Used only for inode32. +*/ +if (M_IGEO (mp)->maxicount) { +uint64_t icount; + + icount = sbp->sb_dblocks * sbp->sb_imax_pct; +do_div (icount,100 ); + icount += sbp->sb_agblocks -1 ; +do_div (icount, sbp->sb_agblocks); + max_metadata = icount; + }else { + max_metadata = agcount; + } + +/* Get the last possible inode in the filesystem */ + agino =XFS_AGB_TO_AGINO (mp, sbp->sb_agblocks -1 ); + ino =XFS_AGINO_TO_INO (mp, agcount -1 , agino); + +/* +* If user asked for no more than 32-bit inodes, and the fs is +* sufficiently large, set XFS_MOUNT_32BITINODES if we must alter +* the allocator to accommodate the request. +*/ +if ((mp->m_flags &XFS_MOUNT_SMALL_INUMS ) && ino >XFS_MAXINUMBER_32 ) + mp->m_flags |=XFS_MOUNT_32BITINODES ; +else + mp->m_flags &= ~XFS_MOUNT_32BITINODES ; + +for (index =0 ; index < agcount; index++) { +struct xfs_perag *pag; + + ino =XFS_AGINO_TO_INO (mp, index, agino); + + pag =xfs_perag_get (mp, index); + +if (mp->m_flags &XFS_MOUNT_32BITINODES ) { +if (ino >XFS_MAXINUMBER_32 ) { + pag->pagi_inodeok =0 ; + pag->pagf_metadata =0 ; + }else { + pag->pagi_inodeok =1 ; + maxagi++; +if (index < max_metadata) + pag->pagf_metadata =1 ; +else + pag->pagf_metadata =0 ; + } + }else { + pag->pagi_inodeok =1 ; + pag->pagf_metadata =0 ; + } + +xfs_perag_put (pag); + } + +return (mp->m_flags &XFS_MOUNT_32BITINODES ) ? maxagi : agcount; +} +static int libxfs_initialize_perag (xfs_mount_t *mp,xfs_agnumber_t agcount,xfs_agnumber_t *maxagi) { -xfs_agnumber_t index, max_metadata; +xfs_agnumber_t index;xfs_agnumber_t first_initialised =0 ;xfs_perag_t *pag; -xfs_agino_t agino; -xfs_ino_t ino; -xfs_sb_t *sbp = &mp->m_sb;int error = -ENOMEM ;/* @@ -522,55 +606,7 @@ libxfs_initialize_perag( } } -/* -* If we mount with the inode64 option, or no inode overflows -* the legacy 32-bit address space clear the inode32 option. -*/ - agino =XFS_AGB_TO_AGINO (mp, sbp->sb_agblocks -1 ); - ino =XFS_AGINO_TO_INO (mp, agcount -1 , agino); - -if ((mp->m_flags &XFS_MOUNT_SMALL_INUMS ) && ino >XFS_MAXINUMBER_32 ) - mp->m_flags |=XFS_MOUNT_32BITINODES ; -else - mp->m_flags &= ~XFS_MOUNT_32BITINODES ; - -if (mp->m_flags &XFS_MOUNT_32BITINODES ) { -/* -* Calculate how much should be reserved for inodes to meet -* the max inode percentage. -*/ -if (M_IGEO (mp)->maxicount) { -uint64_t icount; - - icount = sbp->sb_dblocks * sbp->sb_imax_pct; -do_div (icount,100 ); - icount += sbp->sb_agblocks -1 ; -do_div (icount, sbp->sb_agblocks); - max_metadata = icount; - }else { - max_metadata = agcount; - } - -for (index =0 ; index < agcount; index++) { - ino =XFS_AGINO_TO_INO (mp, index, agino); -if (ino >XFS_MAXINUMBER_32 ) { - index++; -break ; - } - - pag =xfs_perag_get (mp, index); - pag->pagi_inodeok =1 ; -if (index < max_metadata) - pag->pagf_metadata =1 ; -xfs_perag_put (pag); - } - }else { -for (index =0 ; index < agcount; index++) { - pag =xfs_perag_get (mp, index); - pag->pagi_inodeok =1 ; -xfs_perag_put (pag); - } - } + index =xfs_set_inode_alloc (mp, agcount);if (maxagi) *maxagi = index;
PATCH 5/61 libxfs: fix whitespace inconsistencies with kernel
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Fix a few places where the whitespace isn't an exact match for the kernel.
--- libxfs/xfs_btree.h | 2 +- libxfs/xfs_rmap_btree.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
libxfs/xfs_btree.h +1 -1
@@ -88,7 +88,7 @@ uint32_t xfs_btree_magic(int crc, xfs_btnum_t btnum);*/ #define XFS_BTREE_STATS_INC (cur, stat) \ XFS_STATS_INC_OFF((cur)->bc_mp, (cur)->bc_statoff + __XBTS_ ## stat) -#define XFS_BTREE_STATS_ADD (cur, stat, val) \ +#define XFS_BTREE_STATS_ADD (cur, stat, val) \ XFS_STATS_ADD_OFF((cur)->bc_mp, (cur)->bc_statoff + __XBTS_ ## stat, val)#define XFS_BTREE_MAXLEVELS 9/* max of all btrees */
libxfs/xfs_rmap_btree.h +1 -1
@@ -4,7 +4,7 @@* All Rights Reserved. */ #ifndef __XFS_RMAP_BTREE_H__ -#define __XFS_RMAP_BTREE_H__ +#define __XFS_RMAP_BTREE_H__struct xfs_buf ;struct xfs_btree_cur ;
Re: [PATCH 05/61] libxfs: fix whitespace inconsistencies with kernel
Quoted 6 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Fix a few places where the whitespace isn't an exact match for the kernel.
Signed-off-by Darrick J. Wong <[email protected]>
PATCH 6/61 xfs: Fix fall-through warnings for Clang
In reply to Darrick J. WongFrom: Gustavo A. R. Silva <[email protected]>
Source kernel commit: 53004ee78d6273c994534ccf79d993098ac89769
In preparation to enable -Wimplicit-fallthrough for Clang, fix the following warnings by replacing /* fall through */ comments, and its variants, with the new pseudo-keyword macro fallthrough:
fs/xfs/libxfs/xfs_alloc.c:3167:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough] fs/xfs/libxfs/xfs_da_btree.c:286:3: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough] fs/xfs/libxfs/xfs_ag_resv.c:346:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough] fs/xfs/libxfs/xfs_ag_resv.c:388:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough] fs/xfs/xfs_bmap_util.c:246:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough] fs/xfs/xfs_export.c:88:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough] fs/xfs/xfs_export.c:96:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough] fs/xfs/xfs_file.c:867:3: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough] fs/xfs/xfs_ioctl.c:562:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough] fs/xfs/xfs_ioctl.c:1548:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough] fs/xfs/xfs_iomap.c:1040:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough] fs/xfs/xfs_inode.c:852:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough] fs/xfs/xfs_log.c:2627:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough] fs/xfs/xfs_trans_buf.c:298:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough] fs/xfs/scrub/bmap.c:275:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough] fs/xfs/scrub/btree.c:48:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough] fs/xfs/scrub/common.c:85:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough] fs/xfs/scrub/common.c:138:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough] fs/xfs/scrub/common.c:698:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough] fs/xfs/scrub/dabtree.c:51:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough] fs/xfs/scrub/repair.c:951:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough] fs/xfs/scrub/agheader.c:89:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
Notice that Clang doesn't recognize /* fall through */ comments as implicit fall-through markings, so in order to globally enable -Wimplicit-fallthrough for Clang, these comments need to be replaced with fallthrough; in the whole codebase.
--- include/linux.h | 17 +++++++++++++++++ libxfs/xfs_ag_resv.c | 4 ++-- libxfs/xfs_alloc.c | 2 +- libxfs/xfs_da_btree.c | 2 +- 4 files changed, 21 insertions(+), 4 deletions(-)
include/linux.h +17 -0
@@ -359,4 +359,21 @@ fsmap_advance(#include <asm-generic/mman-common.h> #endif /* HAVE_MAP_SYNC */ +/* +* Add the pseudo keyword 'fallthrough' so case statement blocks +* must end with any of these keywords: +* break; +* fallthrough; +* continue; +* goto <label>; +* return [expression]; +* +* gcc: https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html#Statement-Attributes +*/ +#if __has_attribute (__fallthrough__) +# define fallthrough __attribute__((__fallthrough__)) +#else +# define fallthrough do {} while (0)/* fallthrough */ +#endif +#endif /* __XFS_LINUX_H__ */
libxfs/xfs_ag_resv.c +2 -2
@@ -365,7 +365,7 @@ xfs_ag_resv_alloc_extent(break ;default :ASSERT (0 ); -/* fall through */ + fallthrough;case XFS_AG_RESV_NONE : field = args->wasdel ?XFS_TRANS_SB_RES_FDBLOCKS :XFS_TRANS_SB_FDBLOCKS ;
@@ -407,7 +407,7 @@ xfs_ag_resv_free_extent(break ;default :ASSERT (0 ); -/* fall through */ + fallthrough;case XFS_AG_RESV_NONE :xfs_trans_mod_sb (tp,XFS_TRANS_SB_FDBLOCKS , (int64_t )len);return ;
libxfs/xfs_alloc.c +1 -1
@@ -3170,7 +3170,7 @@ xfs_alloc_vextent( } args->agbno =XFS_FSB_TO_AGBNO (mp, args->fsbno); args->type =XFS_ALLOCTYPE_NEAR_BNO ; -/* FALLTHROUGH */ + fallthrough;case XFS_ALLOCTYPE_FIRST_AG :/* * Rotate through the allocation groups looking for a winner.
libxfs/xfs_da_btree.c +1 -1
@@ -279,7 +279,7 @@ xfs_da3_node_read_verify( __this_address);break ; } -/* fall through */ + fallthrough;case XFS_DA_NODE_MAGIC : fa =xfs_da3_node_verify (bp);if (fa)
Re: [PATCH 06/61] xfs: Fix fall-through warnings for Clang
On 9/15/21 6:07 PM, Darrick J. Wong wrote:
I'd like to wrap this in
#ifdef __has_attribute
(with another else to define it away) so we don't have any gcc version surprises. Ok? (yes, yes, old gcc yuck but would rather not break it if we don't have to)
#if defined __has_attribute
# if __has_attribute(__fallthrough__)
# define fallthrough __attribute__((__fallthrough__))
# else
# define fallthrough do {} while (0) /* fallthrough */
# endif
#else
# define fallthrough do {} while (0) /* fallthrough */
#endif
Unless there's objection I'll do that before I merge it.
(note, can't do #if defined __has_attribute && __has_attribute(), as shown at
https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005fattribute.html)
Thanks,
-Eric
Quoted 5 lines
include/linux.h +5
-0+#if __has_attribute (__fallthrough__) +# define fallthrough __attribute__((__fallthrough__)) +#else +# define fallthrough do {} while (0)/* fallthrough */ +#endif
PATCH 7/61 misc: convert utilities to use "fallthrough;"
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Now that we have a macro to virtualize switch statement fallthroughs for lazy compiler linters, we might as well spread it elsewhere.
--- db/type.c | 2 +- growfs/xfs_growfs.c | 6 +++--- repair/dinode.c | 18 +++++++++--------- repair/phase4.c | 4 ++-- repair/scan.c | 4 ++-- scrub/inodes.c | 2 +- scrub/repair.c | 2 +- scrub/scrub.c | 8 ++++---- 8 files changed, 23 insertions(+), 23 deletions(-)
db/type.c +1 -1
@@ -307,7 +307,7 @@ handle_text( {switch (action) {case DB_FUZZ : -/* fall through */ + fallthrough;case DB_WRITE :dbprintf (_ ("text writing/fuzzing not supported.\n" ));break ;
growfs/xfs_growfs.c +3 -3
@@ -78,7 +78,7 @@ main(int argc, char **argv)switch (c) {case 'D' : dsize =strtoll (optarg,NULL ,10 ); -/* fall through */ + fallthrough;case 'd' : dflag =1 ;break ;
@@ -91,7 +91,7 @@ main(int argc, char **argv)break ;case 'L' : lsize =strtoll (optarg,NULL ,10 ); -/* fall through */ + fallthrough;case 'l' : lflag =1 ;break ;
@@ -107,7 +107,7 @@ main(int argc, char **argv)break ;case 'R' : rsize =strtoll (optarg,NULL ,10 ); -/* fall through */ + fallthrough;case 'r' : rflag =1 ;break ;
repair/dinode.c +9 -9
@@ -531,7 +531,7 @@ _("Fatal error: inode %" PRIu64 " - blkmap_set_ext(): %s\n"do_warn (_ ("%s fork in ino %" PRIu64" claims free block %" PRIu64"\n" ), forkname, ino, (uint64_t ) b); -/* fall through ... */ + fallthrough;case XR_E_INUSE1 :/* seen by rmap */ case XR_E_UNKNOWN :break ;
@@ -543,7 +543,7 @@ _("%s fork in ino %" PRIu64 " claims free block %" PRIu64 "\n"),case XR_E_INO1 :case XR_E_INUSE_FS1 :do_warn (_ ("rmap claims metadata use!\n" )); -/* fall through */ + fallthrough;case XR_E_FS_MAP :case XR_E_INO :case XR_E_INUSE_FS :
@@ -1674,9 +1674,9 @@ _("directory inode %" PRIu64 " has bad size %" PRId64 "\n"), }break ; -case XR_INO_CHRDEV :/* fall through to FIFO case ... */ -case XR_INO_BLKDEV :/* fall through to FIFO case ... */ -case XR_INO_SOCK :/* fall through to FIFO case ... */ +case XR_INO_CHRDEV : +case XR_INO_BLKDEV : +case XR_INO_SOCK :case XR_INO_FIFO :if (process_misc_ino_types (mp, dino, lino, type))return 1 ;
@@ -1751,8 +1751,8 @@ _("bad attr fork offset %d in dev inode %" PRIu64 ", should be %d\n"),return 1 ; }break ; -case XFS_DINODE_FMT_LOCAL :/* fall through ... */ -case XFS_DINODE_FMT_EXTENTS :/* fall through ... */ +case XFS_DINODE_FMT_LOCAL : +case XFS_DINODE_FMT_EXTENTS :case XFS_DINODE_FMT_BTREE :if (dino->di_forkoff >= (XFS_LITINO (mp) >>3 )) { do_warn(
@@ -1908,7 +1908,7 @@ process_inode_data_fork( totblocks, nextents, dblkmap,XFS_DATA_FORK , check_dups);break ; -case XFS_DINODE_FMT_DEV :/* fall through */ +case XFS_DINODE_FMT_DEV : err =0 ;break ;default :
@@ -1946,7 +1946,7 @@ process_inode_data_fork( dirty, totblocks, nextents, dblkmap, XFS_DATA_FORK, 0);break ; -case XFS_DINODE_FMT_DEV :/* fall through */ +case XFS_DINODE_FMT_DEV : err =0 ;break ;default :
repair/phase4.c +2 -2
@@ -317,7 +317,7 @@ phase4(xfs_mount_t *mp)do_warn (_ ("unknown block state, ag %d, blocks %u-%u\n" ), i, j, j + blen -1 ); -/* fall through .. */ + fallthrough;case XR_E_UNKNOWN :case XR_E_FREE :case XR_E_INUSE :
@@ -349,7 +349,7 @@ phase4(xfs_mount_t *mp)do_warn (_ ("unknown rt extent state, extent %" PRIu64"\n" ), bno); -/* fall through .. */ + fallthrough;case XR_E_UNKNOWN :case XR_E_FREE1 :case XR_E_FREE :
repair/scan.c +2 -2
@@ -732,7 +732,7 @@ _("%s freespace btree block claimed (state %d), agno %d, bno %d, suspect %d\n"), XR_E_FREE);break ; } -/* fall through */ + fallthrough;default : do_warn( _("block (%d,%d-%d) multiply claimed by %s space tree, state - %d\n"),
@@ -911,7 +911,7 @@ _("in use block (%d,%d-%d) mismatch in %s tree, state - %d,%" PRIx64 "\n"),if (xfs_sb_version_hasreflink (&mp->m_sb) && !XFS_RMAP_NON_INODE_OWNER (owner))break ; -/* fall through */ + fallthrough;default : do_warn( _("unknown block (%d,%d-%d) mismatch on %s tree, state - %d,%" PRIx64 "\n"),
scrub/inodes.c +1 -1
@@ -204,7 +204,7 @@ _("Changed too many times during scan; giving up.")); }case ECANCELED : error =0 ; -/* fall thru */ + fallthrough;default : goto err; }
scrub/repair.c +1 -1
@@ -133,7 +133,7 @@ action_list_find_mustfix( alist->nr--;list_move_tail (&aitem->list, &immediate_alist->list); immediate_alist->nr++; -/* fall through */ + fallthrough;case XFS_SCRUB_TYPE_BNOBT :case XFS_SCRUB_TYPE_CNTBT :case XFS_SCRUB_TYPE_REFCNTBT :
scrub/scrub.c +4 -4
@@ -164,7 +164,7 @@ _("Filesystem is shut down, aborting."));* and the other two should be reported via sm_flags. */ str_liberror (ctx, error,_ ("Kernel bug" )); -/* fall through */ + fallthrough;default :/* Operational error. */ str_errno (ctx,descr_render (&dsc));
@@ -316,7 +316,7 @@ scrub_meta_type( ret =scrub_save_repair (ctx, alist, &meta);if (ret)return ret; -/* fall through */ + fallthrough;case CHECK_DONE :return 0 ;default :
@@ -741,7 +741,7 @@ _("Filesystem is shut down, aborting."));if (is_unoptimized (&oldm) ||debug_tweak_on ("XFS_SCRUB_FORCE_REPAIR" ))return CHECK_DONE ; -/* fall through */ + fallthrough;case EINVAL :/* Kernel doesn't know how to repair this? */ str_corrupt(ctx, descr_render(&dsc),
@@ -761,7 +761,7 @@ _("Read-only filesystem; cannot make changes."));/* Don't care if preen fails due to low resources. */ if (is_unoptimized (&oldm) && !needs_repair (&oldm))return CHECK_DONE ; -/* fall through */ + fallthrough;default :/* * Operational error. If the caller doesn't want us
Re: [PATCH 07/61] misc: convert utilities to use "fallthrough;"
Quoted 6 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Now that we have a macro to virtualize switch statement fallthroughs for lazy compiler linters, we might as well spread it elsewhere.
Signed-off-by Darrick J. Wong <[email protected]>
PATCH 8/61 xfs: use xfs_buf_alloc_pages for uncached buffers
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: 07b5c5add42a0afccf79401b12d78043ed6b8240
Use the newly factored out page allocation code. This adds automatic buffer zeroing for non-read uncached buffers.
This also allows us to greatly simply the error handling in xfs_buf_get_uncached(). Because xfs_buf_alloc_pages() cleans up partial allocation failure, we can just call xfs_buf_free() in all error cases now to clean up after failures.
--- libxfs/xfs_ag.c | 1 - 1 file changed, 1 deletion(-)
libxfs/xfs_ag.c +0 -1
@@ -42,7 +42,6 @@ xfs_get_aghdr_buf(if (error)return error; -xfs_buf_zero (bp,0 ,BBTOB (bp->b_length)); bp->b_bn = blkno; bp->b_maps[0 ].bm_bn = blkno; bp->b_ops = ops;
PATCH 9/61 xfs: Reverse apply 72b97ea40d
In reply to Darrick J. WongFrom: Allison Henderson <[email protected]>
Source kernel commit: 4126c06e25b38842a254b2de6ffc3019a7b2f0ca
Originally we added this patch to help modularize the attr code in preparation for delayed attributes and the state machine it requires. However, later reviews found that this slightly alters the transaction handling as the helper function is ambiguous as to whether the transaction is diry or clean. This may cause a dirty transaction to be included in the next roll, where previously it had not. To preserve the existing code flow, we reverse apply this commit.
--- libxfs/xfs_attr.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-)
libxfs/xfs_attr.c +9 -19
@@ -1214,24 +1214,6 @@ int xfs_attr_node_removename_setup(return 0 ; } -STATIC int -xfs_attr_node_remove_rmt ( -struct xfs_da_args *args, -struct xfs_da_state *state) -{ -int error =0 ; - - error =xfs_attr_rmtval_remove (args); -if (error) -return error; - -/* -* Refill the state structure with buffers, the prior calls released our -* buffers. -*/ -return xfs_attr_refillstate (state); -} -/* * Remove a name from a B-tree attribute list. *
@@ -1260,7 +1242,15 @@ xfs_attr_node_removename(* overflow the maximum size of a transaction and/or hit a deadlock. */ if (args->rmtblkno >0 ) { - error =xfs_attr_node_remove_rmt (args, state); + error =xfs_attr_rmtval_remove (args); +if (error) + goto out; + +/* +* Refill the state structure with buffers, the prior calls +* released our buffers. +*/ + error =xfs_attr_refillstate (state);if (error) goto out; }
PATCH 10/61 xfs: Add xfs_attr_node_remove_name
In reply to Darrick J. WongFrom: Allison Henderson <[email protected]>
Source kernel commit: a8490f699f6ec88843879b92cbb21953dab379ee
This patch pulls a new helper function xfs_attr_node_remove_name out of xfs_attr_node_remove_step. This helps to modularize xfs_attr_node_remove_step which will help make the delayed attribute code easier to follow
--- libxfs/xfs_attr.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-)
libxfs/xfs_attr.c +20 -9
@@ -1214,6 +1214,25 @@ int xfs_attr_node_removename_setup(return 0 ; } +STATIC int +xfs_attr_node_remove_name ( +struct xfs_da_args *args, +struct xfs_da_state *state) +{ +struct xfs_da_state_blk *blk; +int retval; + +/* +* Remove the name and update the hashvals in the tree. +*/ + blk = &state->path.blk[state->path.active-1 ]; +ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); + retval =xfs_attr3_leaf_remove (blk->bp, args); +xfs_da3_fixhashpath (state, &state->path); + +return retval; +} +/* * Remove a name from a B-tree attribute list. *
@@ -1226,7 +1245,6 @@ xfs_attr_node_removename( struct xfs_da_args *args) {struct xfs_da_state *state; -struct xfs_da_state_blk *blk;int retval, error;struct xfs_inode *dp = args->dp;
@@ -1254,14 +1272,7 @@ xfs_attr_node_removename(if (error) goto out; } - -/* -* Remove the name and update the hashvals in the tree. -*/ - blk = &state->path.blk[ state->path.active-1 ]; -ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); - retval =xfs_attr3_leaf_remove (blk->bp, args); -xfs_da3_fixhashpath (state, &state->path); + retval =xfs_attr_node_remove_name (args, state);/* * Check to see if the tree needs to be collapsed.
PATCH 11/61 xfs: Refactor xfs_attr_set_shortform
In reply to Darrick J. WongFrom: Allison Henderson <[email protected]>
Source kernel commit: 6286514b63e12d7bedc67e46aa1aeff9ed8378ce
This patch is actually the combination of patches from the previous version (v18). Initially patch 3 hoisted xfs_attr_set_shortform, and the next added the helper xfs_attr_set_fmt. xfs_attr_set_fmt is similar the old xfs_attr_set_shortform. It returns 0 when the attr has been set and no further action is needed. It returns -EAGAIN when shortform has been transformed to leaf, and the calling function should proceed the set the attr in leaf form.
--- libxfs/xfs_attr.c | 42 ++++++++++++++---------------------------- 1 file changed, 14 insertions(+), 28 deletions(-)
libxfs/xfs_attr.c +14 -28
@@ -236,16 +236,11 @@ xfs_attr_is_shortform( ip->i_afp->if_nextents == 0); } -/* -* Attempts to set an attr in shortform, or converts short form to leaf form if -* there is not enough room. If the attr is set, the transaction is committed -* and set to NULL. -*/ STATIC int -xfs_attr_set_shortform ( -struct xfs_da_args *args, -struct xfs_buf **leaf_bp) +xfs_attr_set_fmt ( +struct xfs_da_args *args) { +struct xfs_buf *leaf_bp =NULL ;struct xfs_inode *dp = args->dp;int error, error2 =0 ;
@@ -258,29 +253,29 @@ xfs_attr_set_shortform( args->trans =NULL ;return error ? error : error2; } +/* * It won't fit in the shortform, transform to a leaf block. GROT: * another possible req'mt for a double-split btree op. */ - error =xfs_attr_shortform_to_leaf (args, leaf_bp); + error =xfs_attr_shortform_to_leaf (args, &leaf_bp);if (error)return error;/* * Prevent the leaf buffer from being unlocked so that a concurrent AIL * push cannot grab the half-baked leaf buffer and run into problems -* with the write verifier. Once we're done rolling the transaction we -* can release the hold and add the attr to the leaf. +* with the write verifier. */ -xfs_trans_bhold (args->trans, *leaf_bp); +xfs_trans_bhold (args->trans, leaf_bp); error =xfs_defer_finish (&args->trans); -xfs_trans_bhold_release (args->trans, *leaf_bp); +xfs_trans_bhold_release (args->trans, leaf_bp);if (error) { -xfs_trans_brelse (args->trans, *leaf_bp); +xfs_trans_brelse (args->trans, leaf_bp);return error; } -return 0 ; +return -EAGAIN ; }/*
@@ -291,8 +286,7 @@ xfs_attr_set_args( struct xfs_da_args *args) {struct xfs_inode *dp = args->dp; -struct xfs_buf *leaf_bp =NULL ; -int error =0 ; +int error;/* * If the attribute list is already in leaf format, jump straight to
@@ -301,15 +295,8 @@ xfs_attr_set_args(* again. */ if (xfs_attr_is_shortform (dp)) { - -/* -* If the attr was successfully set in shortform, the -* transaction is committed and set to NULL. Otherwise, is it -* converted from shortform to leaf, and the transaction is -* retained. -*/ - error =xfs_attr_set_shortform (args, &leaf_bp); -if (error || !args->trans) + error =xfs_attr_set_fmt (args); +if (error != -EAGAIN )return error; }
@@ -344,8 +331,7 @@ xfs_attr_set_args(return error; } - error =xfs_attr_node_addname (args); -return error; +return xfs_attr_node_addname (args); }/*
PATCH 12/61 xfs: Separate xfs_attr_node_addname and xfs_attr_node_addname_clear_incomplete
In reply to Darrick J. WongFrom: Allison Henderson <[email protected]>
Source kernel commit: f0f7c502c728d0c6947219739631bad101f8737b
This patch separate xfs_attr_node_addname into two functions. This will help to make it easier to hoist parts of xfs_attr_node_addname that need state management
--- libxfs/xfs_attr.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
libxfs/xfs_attr.c +23 -0
@@ -54,6 +54,7 @@ STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp); STATIC int xfs_attr_node_get(xfs_da_args_t *args); STATIC int xfs_attr_node_addname(xfs_da_args_t *args); STATIC int xfs_attr_node_removename(xfs_da_args_t *args); +STATIC int xfs_attr_node_addname_clear_incomplete(struct xfs_da_args *args); STATIC int xfs_attr_node_hasname(xfs_da_args_t *args,struct xfs_da_state **state); STATIC int xfs_attr_fillstate(xfs_da_state_t *state);
@@ -1073,6 +1074,28 @@ xfs_attr_node_addname(return error; } + error =xfs_attr_node_addname_clear_incomplete (args); +if (error) + goto out; + retval =0 ; +out: +if (state) +xfs_da_state_free (state); +if (error) +return error; +return retval; +} + + +STATIC int +xfs_attr_node_addname_clear_incomplete ( +struct xfs_da_args *args) +{ +struct xfs_da_state *state =NULL ; +struct xfs_da_state_blk *blk; +int retval =0 ; +int error =0 ; +/* * Re-find the "old" attribute entry after any split ops. The INCOMPLETE * flag means that we will find the "old" attr, not the "new" one.
PATCH 13/61 xfs: Add helper xfs_attr_node_addname_find_attr
In reply to Darrick J. WongFrom: Allison Henderson <[email protected]>
Source kernel commit: 6ca5a4a1f52952790a40099b79b5631d91163ba4
This patch separates the first half of xfs_attr_node_addname into a helper function xfs_attr_node_addname_find_attr. It also replaces the restart goto with an EAGAIN return code driven by a loop in the calling function. This looks odd now, but will clean up nicly once we introduce the state machine. It will also enable hoisting the last state out of xfs_attr_node_addname with out having to plumb in a "done" parameter to know if we need to move to the next state or not.
--- libxfs/xfs_attr.c | 101 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 61 insertions(+), 40 deletions(-)
libxfs/xfs_attr.c +61 -40
@@ -52,7 +52,10 @@ STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);* Internal routines when attribute list is more than one block. */ STATIC int xfs_attr_node_get(xfs_da_args_t *args); -STATIC int xfs_attr_node_addname(xfs_da_args_t *args); +STATIC int xfs_attr_node_addname(struct xfs_da_args *args, +struct xfs_da_state *state); +STATIC int xfs_attr_node_addname_find_attr(struct xfs_da_args *args, +struct xfs_da_state **state); STATIC int xfs_attr_node_removename(xfs_da_args_t *args); STATIC int xfs_attr_node_addname_clear_incomplete(struct xfs_da_args *args); STATIC int xfs_attr_node_hasname(xfs_da_args_t *args,
@@ -287,6 +290,7 @@ xfs_attr_set_args( struct xfs_da_args *args) {struct xfs_inode *dp = args->dp; +struct xfs_da_state *state;int error;/*
@@ -332,7 +336,14 @@ xfs_attr_set_args(return error; } -return xfs_attr_node_addname (args); +do { + error =xfs_attr_node_addname_find_attr (args, &state); +if (error) +return error; + error =xfs_attr_node_addname (args, state); + }while (error == -EAGAIN ); + +return error; }/*
@@ -896,6 +907,50 @@ xfs_attr_node_hasname(* External routines when attribute list size > geo->blksize *========================================================================*/ +STATIC int +xfs_attr_node_addname_find_attr ( +struct xfs_da_args *args, +struct xfs_da_state **state) +{ +int retval; + +/* +* Search to see if name already exists, and get back a pointer +* to where it should go. +*/ + retval =xfs_attr_node_hasname (args, state); +if (retval != -ENOATTR && retval != -EEXIST ) + goto error; + +if (retval == -ENOATTR && (args->attr_flags &XATTR_REPLACE )) + goto error; +if (retval == -EEXIST ) { +if (args->attr_flags &XATTR_CREATE ) + goto error; + +trace_xfs_attr_node_replace (args); + +/* save the attribute state for later removal*/ + args->op_flags |=XFS_DA_OP_RENAME ;/* atomic rename op */ +xfs_attr_save_rmt_blk (args); + +/* +* clear the remote attr state now that it is saved so that the +* values reflect the state of the attribute we are about to +* add, not the attribute we just found and will remove later. +*/ + args->rmtblkno =0 ; + args->rmtblkcnt =0 ; + args->rmtvaluelen =0 ; + } + +return 0 ; +error: +if (*state) +xfs_da_state_free (*state); +return retval; +} +/* * Add a name to a Btree-format attribute list. *
@@ -908,52 +963,18 @@ xfs_attr_node_hasname(*/ STATIC intxfs_attr_node_addname ( -struct xfs_da_args *args) +struct xfs_da_args *args, +struct xfs_da_state *state) { -struct xfs_da_state *state;struct xfs_da_state_blk *blk;struct xfs_inode *dp;int retval, error;trace_xfs_attr_node_addname (args); -/* -* Fill in bucket of arguments/results/context to carry around. -*/ dp = args->dp; -restart: -/* -* Search to see if name already exists, and get back a pointer -* to where it should go. -*/ - error =0 ; - retval =xfs_attr_node_hasname (args, &state); -if (retval != -ENOATTR && retval != -EEXIST ) - goto out; - - blk = &state->path.blk[ state->path.active-1 ]; + blk = &state->path.blk[state->path.active-1 ];ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); -if (retval == -ENOATTR && (args->attr_flags &XATTR_REPLACE )) - goto out; -if (retval == -EEXIST ) { -if (args->attr_flags &XATTR_CREATE ) - goto out; - -trace_xfs_attr_node_replace (args); - -/* save the attribute state for later removal*/ - args->op_flags |=XFS_DA_OP_RENAME ;/* atomic rename op */ -xfs_attr_save_rmt_blk (args); - -/* -* clear the remote attr state now that it is saved so that the -* values reflect the state of the attribute we are about to -* add, not the attribute we just found and will remove later. -*/ - args->rmtblkno =0 ; - args->rmtblkcnt =0 ; - args->rmtvaluelen =0 ; - } retval =xfs_attr3_leaf_add (blk->bp, state->args);if (retval == -ENOSPC ) {
@@ -980,7 +1001,7 @@ xfs_attr_node_addname(if (error) goto out; - goto restart; +return -EAGAIN ; }/*
PATCH 14/61 xfs: Hoist xfs_attr_node_addname
In reply to Darrick J. WongFrom: Allison Henderson <[email protected]>
Source kernel commit: 5d954cc09f6baed80458ea02ec092031608ea3fe
This patch hoists the later half of xfs_attr_node_addname into the calling function. We do this because it is this area that will need the most state management, and we want to keep such code in the same scope as much as possible
--- libxfs/xfs_attr.c | 159 +++++++++++++++++++++++++---------------------------- 1 file changed, 75 insertions(+), 84 deletions(-)
libxfs/xfs_attr.c +75 -84
@@ -52,6 +52,7 @@ STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);* Internal routines when attribute list is more than one block. */ STATIC int xfs_attr_node_get(xfs_da_args_t *args); +STATIC void xfs_attr_restore_rmt_blk(struct xfs_da_args *args); STATIC int xfs_attr_node_addname(struct xfs_da_args *args,struct xfs_da_state *state); STATIC int xfs_attr_node_addname_find_attr(struct xfs_da_args *args,
@@ -290,8 +291,8 @@ xfs_attr_set_args( struct xfs_da_args *args) {struct xfs_inode *dp = args->dp; -struct xfs_da_state *state; -int error; +struct xfs_da_state *state =NULL ; +int error =0 ;/* * If the attribute list is already in leaf format, jump straight to
@@ -342,7 +343,75 @@ xfs_attr_set_args(return error; error =xfs_attr_node_addname (args, state); }while (error == -EAGAIN ); +if (error) +return error; +/* +* Commit the leaf addition or btree split and start the next +* trans in the chain. +*/ + error =xfs_trans_roll_inode (&args->trans, dp); +if (error) + goto out; + +/* +* If there was an out-of-line value, allocate the blocks we +* identified for its storage and copy the value. This is done +* after we create the attribute so that we don't overflow the +* maximum size of a transaction and/or hit a deadlock. +*/ +if (args->rmtblkno >0 ) { + error =xfs_attr_rmtval_set (args); +if (error) +return error; + } + +if (!(args->op_flags &XFS_DA_OP_RENAME )) { +/* +* Added a "remote" value, just clear the incomplete flag. +*/ +if (args->rmtblkno >0 ) + error =xfs_attr3_leaf_clearflag (args); + goto out; + } + +/* +* If this is an atomic rename operation, we must "flip" the incomplete +* flags on the "new" and "old" attribute/value pairs so that one +* disappears and one appears atomically. Then we must remove the "old" +* attribute/value pair. +* +* In a separate transaction, set the incomplete flag on the "old" attr +* and clear the incomplete flag on the "new" attr. +*/ + error =xfs_attr3_leaf_flipflags (args); +if (error) + goto out; +/* +* Commit the flag value change and start the next trans in series +*/ + error =xfs_trans_roll_inode (&args->trans, args->dp); +if (error) + goto out; + +/* +* Dismantle the "old" attribute/value pair by removing a "remote" value +* (if it exists). +*/ +xfs_attr_restore_rmt_blk (args); + +if (args->rmtblkno) { + error =xfs_attr_rmtval_invalidate (args); +if (error) +return error; + + error =xfs_attr_rmtval_remove (args); +if (error) +return error; + } + + error =xfs_attr_node_addname_clear_incomplete (args); +out:return error; }
@@ -968,7 +1037,7 @@ xfs_attr_node_addname( {struct xfs_da_state_blk *blk;struct xfs_inode *dp; -int retval, error; +int error;trace_xfs_attr_node_addname (args);
@@ -976,8 +1045,8 @@ xfs_attr_node_addname( blk = &state->path.blk[state->path.active-1 ];ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); - retval =xfs_attr3_leaf_add (blk->bp, state->args); -if (retval == -ENOSPC ) { + error =xfs_attr3_leaf_add (blk->bp, state->args); +if (error == -ENOSPC ) {if (state->path.active ==1 ) {/* * Its really a single leaf node, but it had
@@ -1023,88 +1092,10 @@ xfs_attr_node_addname(xfs_da3_fixhashpath (state, &state->path); } -/* -* Kill the state structure, we're done with it and need to -* allow the buffers to come back later. -*/ -xfs_da_state_free (state); - state =NULL ; - -/* -* Commit the leaf addition or btree split and start the next -* trans in the chain. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; - -/* -* If there was an out-of-line value, allocate the blocks we -* identified for its storage and copy the value. This is done -* after we create the attribute so that we don't overflow the -* maximum size of a transaction and/or hit a deadlock. -*/ -if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_set (args); -if (error) -return error; - } - -if (!(args->op_flags &XFS_DA_OP_RENAME )) { -/* -* Added a "remote" value, just clear the incomplete flag. -*/ -if (args->rmtblkno >0 ) - error =xfs_attr3_leaf_clearflag (args); - retval = error; - goto out; - } - -/* -* If this is an atomic rename operation, we must "flip" the incomplete -* flags on the "new" and "old" attribute/value pairs so that one -* disappears and one appears atomically. Then we must remove the "old" -* attribute/value pair. -* -* In a separate transaction, set the incomplete flag on the "old" attr -* and clear the incomplete flag on the "new" attr. -*/ - error =xfs_attr3_leaf_flipflags (args); -if (error) - goto out; -/* -* Commit the flag value change and start the next trans in series -*/ - error =xfs_trans_roll_inode (&args->trans, args->dp); -if (error) - goto out; - -/* -* Dismantle the "old" attribute/value pair by removing a "remote" value -* (if it exists). -*/ -xfs_attr_restore_rmt_blk (args); - -if (args->rmtblkno) { - error =xfs_attr_rmtval_invalidate (args); -if (error) -return error; - - error =xfs_attr_rmtval_remove (args); -if (error) -return error; - } - - error =xfs_attr_node_addname_clear_incomplete (args); -if (error) - goto out; - retval =0 ; out:if (state)xfs_da_state_free (state); -if (error) -return error; -return retval; +return error; }
PATCH 15/61 xfs: Hoist xfs_attr_leaf_addname
In reply to Darrick J. WongFrom: Allison Henderson <[email protected]>
Source kernel commit: 83c6e70789ff371c4eebc54f2c8d979305a1bae8
This patch hoists xfs_attr_leaf_addname into the calling function. The goal being to get all the code that will require state management into the same scope. This isn't particularly aesthetic right away, but it is a preliminary step to merging in the state machine code.
--- libxfs/xfs_attr.c | 209 ++++++++++++++++++++++++----------------------------- 1 file changed, 96 insertions(+), 113 deletions(-)
libxfs/xfs_attr.c +96 -113
@@ -44,9 +44,9 @@ STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);* Internal routines when attribute list is one block. */ STATIC int xfs_attr_leaf_get(xfs_da_args_t *args); -STATIC int xfs_attr_leaf_addname(xfs_da_args_t *args); STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args); STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp); +STATIC int xfs_attr_leaf_try_add(struct xfs_da_args *args, struct xfs_buf *bp);/* * Internal routines when attribute list is more than one block.
@@ -291,8 +291,9 @@ xfs_attr_set_args( struct xfs_da_args *args) {struct xfs_inode *dp = args->dp; +struct xfs_buf *bp =NULL ;struct xfs_da_state *state =NULL ; -int error =0 ; +int forkoff, error =0 ;/* * If the attribute list is already in leaf format, jump straight to
@@ -307,10 +308,101 @@ xfs_attr_set_args( }if (xfs_attr_is_leaf (dp)) { - error =xfs_attr_leaf_addname (args); -if (error != -ENOSPC ) + error =xfs_attr_leaf_try_add (args, bp); +if (error == -ENOSPC ) + goto node; +else if (error)return error; +/* +* Commit the transaction that added the attr name so that +* later routines can manage their own transactions. +*/ + error =xfs_trans_roll_inode (&args->trans, dp); +if (error) +return error; + +/* +* If there was an out-of-line value, allocate the blocks we +* identified for its storage and copy the value. This is done +* after we create the attribute so that we don't overflow the +* maximum size of a transaction and/or hit a deadlock. +*/ +if (args->rmtblkno >0 ) { + error =xfs_attr_rmtval_set (args); +if (error) +return error; + } + +if (!(args->op_flags &XFS_DA_OP_RENAME )) { +/* +* Added a "remote" value, just clear the incomplete +*flag. +*/ +if (args->rmtblkno >0 ) + error =xfs_attr3_leaf_clearflag (args); + +return error; + } + +/* +* If this is an atomic rename operation, we must "flip" the +* incomplete flags on the "new" and "old" attribute/value pairs +* so that one disappears and one appears atomically. Then we +* must remove the "old" attribute/value pair. +* +* In a separate transaction, set the incomplete flag on the +* "old" attr and clear the incomplete flag on the "new" attr. +*/ + + error =xfs_attr3_leaf_flipflags (args); +if (error) +return error; +/* +* Commit the flag value change and start the next trans in +* series. +*/ + error =xfs_trans_roll_inode (&args->trans, args->dp); +if (error) +return error; + +/* +* Dismantle the "old" attribute/value pair by removing a +* "remote" value (if it exists). +*/ +xfs_attr_restore_rmt_blk (args); + +if (args->rmtblkno) { + error =xfs_attr_rmtval_invalidate (args); +if (error) +return error; + + error =xfs_attr_rmtval_remove (args); +if (error) +return error; + } + +/* +* Read in the block containing the "old" attr, then remove the +* "old" attr from that block (neat, huh!) +*/ + error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno, + &bp); +if (error) +return error; + +xfs_attr3_leaf_remove (bp, args); + +/* +* If the result is small enough, shrink it all into the inode. +*/ + forkoff =xfs_attr_shortform_allfit (bp, dp); +if (forkoff) + error =xfs_attr3_leaf_to_shortform (bp, args, forkoff); +/* bp is gone due to xfs_da_shrink_inode */ + +return error; +node:/* * Promote the attribute list to the Btree format. */
@@ -737,115 +829,6 @@ xfs_attr_leaf_try_add(return retval; } - -/* -* Add a name to the leaf attribute list structure -* -* This leaf block cannot have a "remote" value, we only call this routine -* if bmap_one_block() says there is only one block (ie: no remote blks). -*/ -STATIC int -xfs_attr_leaf_addname ( -struct xfs_da_args *args) -{ -int error, forkoff; -struct xfs_buf *bp =NULL ; -struct xfs_inode *dp = args->dp; - -trace_xfs_attr_leaf_addname (args); - - error =xfs_attr_leaf_try_add (args, bp); -if (error) -return error; - -/* -* Commit the transaction that added the attr name so that -* later routines can manage their own transactions. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; - -/* -* If there was an out-of-line value, allocate the blocks we -* identified for its storage and copy the value. This is done -* after we create the attribute so that we don't overflow the -* maximum size of a transaction and/or hit a deadlock. -*/ -if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_set (args); -if (error) -return error; - } - -if (!(args->op_flags &XFS_DA_OP_RENAME )) { -/* -* Added a "remote" value, just clear the incomplete flag. -*/ -if (args->rmtblkno >0 ) - error =xfs_attr3_leaf_clearflag (args); - -return error; - } - -/* -* If this is an atomic rename operation, we must "flip" the incomplete -* flags on the "new" and "old" attribute/value pairs so that one -* disappears and one appears atomically. Then we must remove the "old" -* attribute/value pair. -* -* In a separate transaction, set the incomplete flag on the "old" attr -* and clear the incomplete flag on the "new" attr. -*/ - - error =xfs_attr3_leaf_flipflags (args); -if (error) -return error; -/* -* Commit the flag value change and start the next trans in series. -*/ - error =xfs_trans_roll_inode (&args->trans, args->dp); -if (error) -return error; - -/* -* Dismantle the "old" attribute/value pair by removing a "remote" value -* (if it exists). -*/ -xfs_attr_restore_rmt_blk (args); - -if (args->rmtblkno) { - error =xfs_attr_rmtval_invalidate (args); -if (error) -return error; - - error =xfs_attr_rmtval_remove (args); -if (error) -return error; - } - -/* -* Read in the block containing the "old" attr, then remove the "old" -* attr from that block (neat, huh!) -*/ - error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno, - &bp); -if (error) -return error; - -xfs_attr3_leaf_remove (bp, args); - -/* -* If the result is small enough, shrink it all into the inode. -*/ - forkoff =xfs_attr_shortform_allfit (bp, dp); -if (forkoff) - error =xfs_attr3_leaf_to_shortform (bp, args, forkoff); -/* bp is gone due to xfs_da_shrink_inode */ - -return error; -} -/* * Return EEXIST if attr is found, or ENOATTR if not */
PATCH 16/61 xfs: Hoist node transaction handling
In reply to Darrick J. WongFrom: Allison Henderson <[email protected]>
Source kernel commit: 3f562d092bb1edd39bfc0e6808d7108d47f8aa3a
This patch basically hoists the node transaction handling around the leaf code we just hoisted. This will helps setup this area for the state machine since the goto is easily replaced with a state since it ends with a transaction roll.
--- libxfs/xfs_attr.c | 55 ++++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 26 deletions(-)
libxfs/xfs_attr.c +29 -26
@@ -309,10 +309,36 @@ xfs_attr_set_args(if (xfs_attr_is_leaf (dp)) { error =xfs_attr_leaf_try_add (args, bp); -if (error == -ENOSPC ) +if (error == -ENOSPC ) { +/* +* Promote the attribute list to the Btree format. +*/ + error =xfs_attr3_leaf_to_node (args); +if (error) +return error; + +/* +* Finish any deferred work items and roll the transaction once +* more. The goal here is to call node_addname with the inode +* and transaction in the same state (inode locked and joined, +* transaction clean) no matter how we got to this step. +*/ + error =xfs_defer_finish (&args->trans); +if (error) +return error; + +/* +* Commit the current trans (including the inode) and +* start a new one. +*/ + error =xfs_trans_roll_inode (&args->trans, dp); +if (error) +return error; + goto node; -else if (error) + }else if (error) {return error; + }/* * Commit the transaction that added the attr name so that
@@ -402,32 +428,9 @@ xfs_attr_set_args(/* bp is gone due to xfs_da_shrink_inode */ return error; + } node: -/* -* Promote the attribute list to the Btree format. -*/ - error =xfs_attr3_leaf_to_node (args); -if (error) -return error; -/* -* Finish any deferred work items and roll the transaction once -* more. The goal here is to call node_addname with the inode -* and transaction in the same state (inode locked and joined, -* transaction clean) no matter how we got to this step. -*/ - error =xfs_defer_finish (&args->trans); -if (error) -return error; - -/* -* Commit the current trans (including the inode) and -* start a new one. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; - } do { error = xfs_attr_node_addname_find_attr(args, &state);
PATCH 17/61 xfs: Add delay ready attr remove routines
In reply to Darrick J. WongFrom: Allison Henderson <[email protected]>
Source kernel commit: 2b74b03c13c444cb5af56804cc975534e2058d06
This patch modifies the attr remove routines to be delay ready. This means they no longer roll or commit transactions, but instead return -EAGAIN to have the calling routine roll and refresh the transaction. In this series, xfs_attr_remove_args is merged with xfs_attr_node_removename become a new function, xfs_attr_remove_iter. This new version uses a sort of state machine like switch to keep track of where it was when EAGAIN was returned. A new version of xfs_attr_remove_args consists of a simple loop to refresh the transaction until the operation is completed. A new XFS_DAC_DEFER_FINISH flag is used to finish the transaction where ever the existing code used to.
Calls to xfs_attr_rmtval_remove are replaced with the delay ready version __xfs_attr_rmtval_remove. We will rename __xfs_attr_rmtval_remove back to xfs_attr_rmtval_remove when we are done.
xfs_attr_rmtval_remove itself is still in use by the set routines (used during a rename). For reasons of preserving existing function, we modify xfs_attr_rmtval_remove to call xfs_defer_finish when the flag is set. Similar to how xfs_attr_remove_args does here. Once we transition the set routines to be delay ready, xfs_attr_rmtval_remove is no longer used and will be removed.
This patch also adds a new struct xfs_delattr_context, which we will use to keep track of the current state of an attribute operation. The new xfs_delattr_state enum is used to track various operations that are in progress so that we know not to repeat them, and resume where we left off before EAGAIN was returned to cycle out the transaction. Other members take the place of local variables that need to retain their values across multiple function calls. See xfs_attr.h for a more detailed diagram of the states.
--- include/libxfs.h | 1 libxfs/xfs_attr.c | 239 +++++++++++++++++++++++++++++++++------------- libxfs/xfs_attr.h | 131 +++++++++++++++++++++++++ libxfs/xfs_attr_leaf.c | 2 libxfs/xfs_attr_remote.c | 53 ++++++---- libxfs/xfs_attr_remote.h | 2 6 files changed, 335 insertions(+), 93 deletions(-)
include/libxfs.h +1 -0
@@ -62,6 +62,7 @@ struct iomap;#include "xfs_bmap_btree.h" #include "xfs_alloc_btree.h" #include "xfs_ialloc_btree.h" +#include "xfs_attr.h" #include "xfs_attr_sf.h" #include "xfs_inode_fork.h" #include "xfs_inode_buf.h"
libxfs/xfs_attr.c +170 -69
295 lines not on this page · raw message
libxfs/xfs_attr.h +131 -0
143 lines not on this page · raw message
libxfs/xfs_attr_leaf.c +1 -1
@@ -19,8 +19,8 @@#include "xfs_bmap_btree.h" #include "xfs_bmap.h" #include "xfs_attr_sf.h" -#include "xfs_attr_remote.h" #include "xfs_attr.h" +#include "xfs_attr_remote.h" #include "xfs_attr_leaf.h" #include "xfs_trace.h" #include "xfs_dir2.h"
libxfs/xfs_attr_remote.c +31 -22
84 lines not on this page · raw message
libxfs/xfs_attr_remote.h +1 -1
@@ -14,5 +14,5 @@ int xfs_attr_rmtval_remove(struct xfs_da_args *args);int xfs_attr_rmtval_stale (struct xfs_inode *ip,struct xfs_bmbt_irec *map,xfs_buf_flags_t incore_flags);int xfs_attr_rmtval_invalidate (struct xfs_da_args *args); -int __xfs_attr_rmtval_remove (struct xfs_da_args *args); +int __xfs_attr_rmtval_remove (struct xfs_delattr_context *dac);#endif /* __XFS_ATTR_REMOTE_H__ */
PATCH 18/61 xfs: Add delay ready attr set routines
In reply to Darrick J. WongFrom: Allison Henderson <[email protected]>
Source kernel commit: 8f502a4009822a6972772ae65b34078645b3ba16
This patch modifies the attr set routines to be delay ready. This means they no longer roll or commit transactions, but instead return -EAGAIN to have the calling routine roll and refresh the transaction. In this series, xfs_attr_set_args has become xfs_attr_set_iter, which uses a state machine like switch to keep track of where it was when EAGAIN was returned. See xfs_attr.h for a more detailed diagram of the states.
Two new helper functions have been added: xfs_attr_rmtval_find_space and xfs_attr_rmtval_set_blk. They provide a subset of logic similar to xfs_attr_rmtval_set, but they store the current block in the delay attr context to allow the caller to roll the transaction between allocations. This helps to simplify and consolidate code used by xfs_attr_leaf_addname and xfs_attr_node_addname. xfs_attr_set_args has now become a simple loop to refresh the transaction until the operation is completed. Lastly, xfs_attr_rmtval_remove is no longer used, and is removed.
--- libxfs/xfs_attr.c | 466 +++++++++++++++++++++++++++------------------- libxfs/xfs_attr.h | 274 +++++++++++++++++++++++++++ libxfs/xfs_attr_remote.c | 100 +++++++--- libxfs/xfs_attr_remote.h | 5 4 files changed, 618 insertions(+), 227 deletions(-)
libxfs/xfs_attr.c +275 -191
@@ -53,15 +53,16 @@ STATIC int xfs_attr_leaf_try_add(struct xfs_da_args *args, struct xfs_buf *bp);*/ STATIC int xfs_attr_node_get(xfs_da_args_t *args); STATIC void xfs_attr_restore_rmt_blk(struct xfs_da_args *args); -STATIC int xfs_attr_node_addname(struct xfs_da_args *args, -struct xfs_da_state *state); -STATIC int xfs_attr_node_addname_find_attr(struct xfs_da_args *args, -struct xfs_da_state **state); -STATIC int xfs_attr_node_addname_clear_incomplete(struct xfs_da_args *args); +STATIC int xfs_attr_node_addname(struct xfs_delattr_context *dac); +STATIC int xfs_attr_node_addname_find_attr(struct xfs_delattr_context *dac); +STATIC int xfs_attr_node_addname_clear_incomplete( +struct xfs_delattr_context *dac); STATIC int xfs_attr_node_hasname(xfs_da_args_t *args,struct xfs_da_state **state); STATIC int xfs_attr_fillstate(xfs_da_state_t *state); STATIC int xfs_attr_refillstate(xfs_da_state_t *state); +STATIC int xfs_attr_set_iter(struct xfs_delattr_context *dac, +struct xfs_buf **leaf_bp);int xfs_inode_hasattr(
@@ -244,7 +245,7 @@ xfs_attr_is_shortform(* Checks to see if a delayed attribute transaction should be rolled. If so, * transaction is finished or rolled as needed. */ -int +STATIC intxfs_attr_trans_roll (struct xfs_delattr_context *dac) {
@@ -265,29 +266,58 @@ xfs_attr_trans_roll(return error; } +/* +* Set the attribute specified in @args. +*/ +int +xfs_attr_set_args ( +struct xfs_da_args *args) +{ +struct xfs_buf *leaf_bp =NULL ; +int error =0 ; +struct xfs_delattr_context dac = { + .da_args = args, + }; + +do { + error =xfs_attr_set_iter (&dac, &leaf_bp); +if (error != -EAGAIN ) +break ; + + error =xfs_attr_trans_roll (&dac); +if (error) { +if (leaf_bp) +xfs_trans_brelse (args->trans, leaf_bp); +return error; + } + }while (true); + +return error; +} + STATIC intxfs_attr_set_fmt ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac, +struct xfs_buf **leaf_bp) { -struct xfs_buf *leaf_bp =NULL ; -struct xfs_inode *dp = args->dp; -int error, error2 =0 ; +struct xfs_da_args *args = dac->da_args; +struct xfs_inode *dp = args->dp; +int error =0 ;/* * Try to add the attr to the attribute list in the inode. */ error =xfs_attr_try_sf_addname (dp, args); -if (error != -ENOSPC ) { - error2 =xfs_trans_commit (args->trans); - args->trans =NULL ; -return error ? error : error2; - } + +/* Should only be 0, -EEXIST or -ENOSPC */ +if (error != -ENOSPC ) +return error;/* * It won't fit in the shortform, transform to a leaf block. GROT: * another possible req'mt for a double-split btree op. */ - error =xfs_attr_shortform_to_leaf (args, &leaf_bp); + error =xfs_attr_shortform_to_leaf (args, leaf_bp);if (error)return error;
@@ -296,102 +326,130 @@ xfs_attr_set_fmt(* push cannot grab the half-baked leaf buffer and run into problems * with the write verifier. */ -xfs_trans_bhold (args->trans, leaf_bp); - error =xfs_defer_finish (&args->trans); -xfs_trans_bhold_release (args->trans, leaf_bp); -if (error) { -xfs_trans_brelse (args->trans, leaf_bp); -return error; - } +xfs_trans_bhold (args->trans, *leaf_bp); +/* +* We're still in XFS_DAS_UNINIT state here. We've converted +* the attr fork to leaf format and will restart with the leaf +* add. +*/ + dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ; }/* * Set the attribute specified in @args. +* This routine is meant to function as a delayed operation, and may return +* -EAGAIN when the transaction needs to be rolled. Calling functions will need +* to handle this, and recall the function until a successful error code is +* returned. */ int -xfs_attr_set_args ( -struct xfs_da_args *args) +xfs_attr_set_iter ( +struct xfs_delattr_context *dac, +struct xfs_buf **leaf_bp) { -struct xfs_inode *dp = args->dp; -struct xfs_buf *bp =NULL ; -struct xfs_da_state *state =NULL ; -int forkoff, error =0 ; - -/* -* If the attribute list is already in leaf format, jump straight to -* leaf handling. Otherwise, try to add the attribute to the shortform -* list; if there's no room then convert the list to leaf format and try -* again. -*/ -if (xfs_attr_is_shortform (dp)) { - error =xfs_attr_set_fmt (args); -if (error != -EAGAIN ) -return error; - } - -if (xfs_attr_is_leaf (dp)) { - error =xfs_attr_leaf_try_add (args, bp); -if (error == -ENOSPC ) { -/* -* Promote the attribute list to the Btree format. -*/ - error =xfs_attr3_leaf_to_node (args); -if (error) -return error; - -/* -* Finish any deferred work items and roll the transaction once -* more. The goal here is to call node_addname with the inode -* and transaction in the same state (inode locked and joined, -* transaction clean) no matter how we got to this step. -*/ - error =xfs_defer_finish (&args->trans); -if (error) -return error; - -/* -* Commit the current trans (including the inode) and -* start a new one. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; - - goto node; - }else if (error) { -return error; - } - +struct xfs_da_args *args = dac->da_args; +struct xfs_inode *dp = args->dp; +struct xfs_buf *bp =NULL ; +int forkoff, error =0 ; + +/* State machine switch */ +switch (dac->dela_state) { +case XFS_DAS_UNINIT :/* -* Commit the transaction that added the attr name so that -* later routines can manage their own transactions. +* If the fork is shortform, attempt to add the attr. If there +* is no space, this converts to leaf format and returns +* -EAGAIN with the leaf buffer held across the roll. The caller +* will deal with a transaction roll error, but otherwise +* release the hold once we return with a clean transaction. */ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; +if (xfs_attr_is_shortform (dp)) +return xfs_attr_set_fmt (dac, leaf_bp); +if (*leaf_bp !=NULL ) { +xfs_trans_bhold_release (args->trans, *leaf_bp); + *leaf_bp =NULL ; + } +if (xfs_attr_is_leaf (dp)) { + error =xfs_attr_leaf_try_add (args, *leaf_bp); +if (error == -ENOSPC ) { + error =xfs_attr3_leaf_to_node (args); +if (error) +return error; + +/* +* Finish any deferred work items and roll the +* transaction once more. The goal here is to +* call node_addname with the inode and +* transaction in the same state (inode locked +* and joined, transaction clean) no matter how +* we got to this step. +* +* At this point, we are still in +* XFS_DAS_UNINIT, but when we come back, we'll +* be a node, so we'll fall down into the node +* handling code below +*/ + dac->flags |=XFS_DAC_DEFER_FINISH ; +return -EAGAIN ; + }else if (error) { +return error; + } + + dac->dela_state =XFS_DAS_FOUND_LBLK ; + }else { + error =xfs_attr_node_addname_find_attr (dac); +if (error) +return error; + + error =xfs_attr_node_addname (dac); +if (error) +return error; + + dac->dela_state =XFS_DAS_FOUND_NBLK ; + } +return -EAGAIN ; +case XFS_DAS_FOUND_LBLK :/* * If there was an out-of-line value, allocate the blocks we * identified for its storage and copy the value. This is done * after we create the attribute so that we don't overflow the * maximum size of a transaction and/or hit a deadlock. */ -if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_set (args); + +/* Open coded xfs_attr_rmtval_set without trans handling */ +if ((dac->flags &XFS_DAC_LEAF_ADDNAME_INIT ) ==0 ) { + dac->flags |=XFS_DAC_LEAF_ADDNAME_INIT ; +if (args->rmtblkno >0 ) { + error =xfs_attr_rmtval_find_space (dac); +if (error) +return error; + } + } + +/* +* Repeat allocating remote blocks for the attr value until +* blkcnt drops to zero. +*/ +if (dac->blkcnt >0 ) { + error =xfs_attr_rmtval_set_blk (dac);if (error)return error; +return -EAGAIN ; } + error =xfs_attr_rmtval_set_value (args); +if (error) +return error; + +/* +* If this is not a rename, clear the incomplete flag and we're +* done. +*/ if (!(args->op_flags &XFS_DA_OP_RENAME )) { -/* -* Added a "remote" value, just clear the incomplete -*flag. -*/ if (args->rmtblkno >0 ) error =xfs_attr3_leaf_clearflag (args); -return error; }
@@ -404,7 +462,6 @@ xfs_attr_set_args(* In a separate transaction, set the incomplete flag on the * "old" attr and clear the incomplete flag on the "new" attr. */ - error =xfs_attr3_leaf_flipflags (args);if (error)return error;
@@ -412,29 +469,37 @@ xfs_attr_set_args(* Commit the flag value change and start the next trans in * series. */ - error =xfs_trans_roll_inode (&args->trans, args->dp); -if (error) -return error; - + dac->dela_state =XFS_DAS_FLIP_LFLAG ; +return -EAGAIN ; +case XFS_DAS_FLIP_LFLAG :/* * Dismantle the "old" attribute/value pair by removing a * "remote" value (if it exists). */ xfs_attr_restore_rmt_blk (args); + error =xfs_attr_rmtval_invalidate (args); +if (error) +return error; +/* fallthrough */ +case XFS_DAS_RM_LBLK : +/* Set state in case xfs_attr_rmtval_remove returns -EAGAIN */ + dac->dela_state =XFS_DAS_RM_LBLK ;if (args->rmtblkno) { - error =xfs_attr_rmtval_invalidate (args); + error =__xfs_attr_rmtval_remove (dac);if (error)return error; - error =xfs_attr_rmtval_remove (args); -if (error) -return error; + dac->dela_state =XFS_DAS_RD_LEAF ; +return -EAGAIN ; } +/* fallthrough */ +case XFS_DAS_RD_LEAF :/* -* Read in the block containing the "old" attr, then remove the -* "old" attr from that block (neat, huh!) +* This is the last step for leaf format. Read the block with +* the old attr, remove the old attr, check for shortform +* conversion and return. */ error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno, &bp);
@@ -443,97 +508,116 @@ xfs_attr_set_args(xfs_attr3_leaf_remove (bp, args); -/* -* If the result is small enough, shrink it all into the inode. -*/ forkoff =xfs_attr_shortform_allfit (bp, dp);if (forkoff) error =xfs_attr3_leaf_to_shortform (bp, args, forkoff);/* bp is gone due to xfs_da_shrink_inode */ return error; - } -node: +case XFS_DAS_FOUND_NBLK : +/* +* Find space for remote blocks and fall into the allocation +* state. +*/ +if (args->rmtblkno >0 ) { + error =xfs_attr_rmtval_find_space (dac); +if (error) +return error; + } -do { - error =xfs_attr_node_addname_find_attr (args, &state); -if (error) -return error; - error =xfs_attr_node_addname (args, state); - }while (error == -EAGAIN ); -if (error) -return error; - -/* -* Commit the leaf addition or btree split and start the next -* trans in the chain. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; +/* fallthrough */ +case XFS_DAS_ALLOC_NODE : +/* +* If there was an out-of-line value, allocate the blocks we +* identified for its storage and copy the value. This is done +* after we create the attribute so that we don't overflow the +* maximum size of a transaction and/or hit a deadlock. +*/ + dac->dela_state =XFS_DAS_ALLOC_NODE ; +if (args->rmtblkno >0 ) { +if (dac->blkcnt >0 ) { + error =xfs_attr_rmtval_set_blk (dac); +if (error) +return error; +return -EAGAIN ; + } -/* -* If there was an out-of-line value, allocate the blocks we -* identified for its storage and copy the value. This is done -* after we create the attribute so that we don't overflow the -* maximum size of a transaction and/or hit a deadlock. -*/ -if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_set (args); -if (error) -return error; - } + error =xfs_attr_rmtval_set_value (args); +if (error) +return error; + } -if (!(args->op_flags &XFS_DA_OP_RENAME )) {/* -* Added a "remote" value, just clear the incomplete flag. +* If this was not a rename, clear the incomplete flag and we're +* done. */ -if (args->rmtblkno >0 ) - error =xfs_attr3_leaf_clearflag (args); - goto out; - } +if (!(args->op_flags &XFS_DA_OP_RENAME )) { +if (args->rmtblkno >0 ) + error =xfs_attr3_leaf_clearflag (args); + goto out; + } -/* -* If this is an atomic rename operation, we must "flip" the incomplete -* flags on the "new" and "old" attribute/value pairs so that one -* disappears and one appears atomically. Then we must remove the "old" -* attribute/value pair. -* -* In a separate transaction, set the incomplete flag on the "old" attr -* and clear the incomplete flag on the "new" attr. -*/ - error =xfs_attr3_leaf_flipflags (args); -if (error) - goto out; -/* -* Commit the flag value change and start the next trans in series -*/ - error =xfs_trans_roll_inode (&args->trans, args->dp); -if (error) - goto out; +/* +* If this is an atomic rename operation, we must "flip" the +* incomplete flags on the "new" and "old" attribute/value pairs +* so that one disappears and one appears atomically. Then we +* must remove the "old" attribute/value pair. +* +* In a separate transaction, set the incomplete flag on the +* "old" attr and clear the incomplete flag on the "new" attr. +*/ + error =xfs_attr3_leaf_flipflags (args); +if (error) + goto out; +/* +* Commit the flag value change and start the next trans in +* series +*/ + dac->dela_state =XFS_DAS_FLIP_NFLAG ; +return -EAGAIN ; -/* -* Dismantle the "old" attribute/value pair by removing a "remote" value -* (if it exists). -*/ -xfs_attr_restore_rmt_blk (args); +case XFS_DAS_FLIP_NFLAG : +/* +* Dismantle the "old" attribute/value pair by removing a +* "remote" value (if it exists). +*/ +xfs_attr_restore_rmt_blk (args); -if (args->rmtblkno) { error =xfs_attr_rmtval_invalidate (args);if (error)return error; - error =xfs_attr_rmtval_remove (args); -if (error) -return error; +/* fallthrough */ +case XFS_DAS_RM_NBLK : +/* Set state in case xfs_attr_rmtval_remove returns -EAGAIN */ + dac->dela_state =XFS_DAS_RM_NBLK ; +if (args->rmtblkno) { + error =__xfs_attr_rmtval_remove (dac); +if (error) +return error; + + dac->dela_state =XFS_DAS_CLR_FLAG ; +return -EAGAIN ; + } + +/* fallthrough */ +case XFS_DAS_CLR_FLAG : +/* +* The last state for node format. Look up the old attr and +* remove it. +*/ + error =xfs_attr_node_addname_clear_incomplete (dac); +break ; +default : +ASSERT (dac->dela_state !=XFS_DAS_RM_SHRINK ); +break ; } - - error =xfs_attr_node_addname_clear_incomplete (args); out:return error; } +/* * Return EEXIST if attr is found, or ENOATTR if not */
@@ -997,18 +1081,18 @@ xfs_attr_node_hasname( STATIC intxfs_attr_node_addname_find_attr ( -struct xfs_da_args *args, -struct xfs_da_state **state) +struct xfs_delattr_context *dac) { -int retval; +struct xfs_da_args *args = dac->da_args; +int retval;/* * Search to see if name already exists, and get back a pointer * to where it should go. */ - retval =xfs_attr_node_hasname (args, state); + retval =xfs_attr_node_hasname (args, &dac->da_state);if (retval != -ENOATTR && retval != -EEXIST ) - goto error; +return retval;if (retval == -ENOATTR && (args->attr_flags &XATTR_REPLACE )) goto error;
@@ -1034,8 +1118,8 @@ xfs_attr_node_addname_find_attr(return 0 ; error: -if (*state) -xfs_da_state_free (*state); +if (dac->da_state) +xfs_da_state_free (dac->da_state);return retval; }
@@ -1048,19 +1132,23 @@ xfs_attr_node_addname_find_attr(* * "Remote" attribute values confuse the issue and atomic rename operations * add a whole extra layer of confusion on top of that. +* +* This routine is meant to function as a delayed operation, and may return +* -EAGAIN when the transaction needs to be rolled. Calling functions will need +* to handle this, and recall the function until a successful error code is +*returned. */ STATIC intxfs_attr_node_addname ( -struct xfs_da_args *args, -struct xfs_da_state *state) +struct xfs_delattr_context *dac) { -struct xfs_da_state_blk *blk; -struct xfs_inode *dp; -int error; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state = dac->da_state; +struct xfs_da_state_blk *blk; +int error;trace_xfs_attr_node_addname (args); - dp = args->dp; blk = &state->path.blk[state->path.active-1 ];ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC );
@@ -1075,20 +1163,17 @@ xfs_attr_node_addname(xfs_da_state_free (state); state =NULL ; error =xfs_attr3_leaf_to_node (args); -if (error) - goto out; - error =xfs_defer_finish (&args->trans);if (error) goto out;/* -* Commit the node conversion and start the next -* trans in the chain. +* Now that we have converted the leaf to a node, we can +* roll the transaction, and try xfs_attr3_leaf_add +* again on re-entry. No need to set dela_state to do +* this. dela_state is still unset by this function at +* this point. */ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; - + dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ; }
@@ -1101,9 +1186,7 @@ xfs_attr_node_addname( error =xfs_da3_split (state);if (error) goto out; - error =xfs_defer_finish (&args->trans); -if (error) - goto out; + dac->flags |=XFS_DAC_DEFER_FINISH ; }else {/* * Addition succeeded, update Btree hashvals.
@@ -1120,8 +1203,9 @@ xfs_attr_node_addname( STATIC intxfs_attr_node_addname_clear_incomplete ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac) { +struct xfs_da_args *args = dac->da_args;struct xfs_da_state *state =NULL ;struct xfs_da_state_blk *blk;int retval =0 ;
libxfs/xfs_attr.h +273 -1
304 lines not on this page · raw message
libxfs/xfs_attr_remote.c +66 -34
125 lines not on this page · raw message
libxfs/xfs_attr_remote.h +4 -1
@@ -10,9 +10,12 @@ int xfs_attr3_rmt_blocks(struct xfs_mount *mp, int attrlen);int xfs_attr_rmtval_get (struct xfs_da_args *args);int xfs_attr_rmtval_set (struct xfs_da_args *args); -int xfs_attr_rmtval_remove (struct xfs_da_args *args);int xfs_attr_rmtval_stale (struct xfs_inode *ip,struct xfs_bmbt_irec *map,xfs_buf_flags_t incore_flags);int xfs_attr_rmtval_invalidate (struct xfs_da_args *args);int __xfs_attr_rmtval_remove (struct xfs_delattr_context *dac); +int xfs_attr_rmt_find_hole (struct xfs_da_args *args); +int xfs_attr_rmtval_set_value (struct xfs_da_args *args); +int xfs_attr_rmtval_set_blk (struct xfs_delattr_context *dac); +int xfs_attr_rmtval_find_space (struct xfs_delattr_context *dac);#endif /* __XFS_ATTR_REMOTE_H__ */
PATCH 19/61 xfs: Remove xfs_attr_rmtval_set
In reply to Darrick J. WongFrom: Allison Henderson <[email protected]>
Source kernel commit: 0e6acf29db6f463027d1ff7cea86a641da89f0d4
This function is no longer used, so it is safe to remove
--- libxfs/xfs_attr_remote.c | 66 ---------------------------------------------- libxfs/xfs_attr_remote.h | 1 - 2 files changed, 67 deletions(-)
libxfs/xfs_attr_remote.c +0 -66
@@ -560,72 +560,6 @@ xfs_attr_rmtval_stale(return 0 ; } -/* -* Write the value associated with an attribute into the out-of-line buffer -* that we have defined for it. -*/ -int -xfs_attr_rmtval_set ( -struct xfs_da_args *args) -{ -struct xfs_inode *dp = args->dp; -struct xfs_bmbt_irec map; -xfs_dablk_t lblkno; -int blkcnt; -int nmap; -int error; - -trace_xfs_attr_rmtval_set (args); - - error =xfs_attr_rmt_find_hole (args); -if (error) -return error; - - blkcnt = args->rmtblkcnt; - lblkno = (xfs_dablk_t )args->rmtblkno; -/* -* Roll through the "value", allocating blocks on disk as required. -*/ -while (blkcnt >0 ) { -/* -* Allocate a single extent, up to the size of the value. -* -* Note that we have to consider this a data allocation as we -* write the remote attribute without logging the contents. -* Hence we must ensure that we aren't using blocks that are on -* the busy list so that we don't overwrite blocks which have -* recently been freed but their transactions are not yet -* committed to disk. If we overwrite the contents of a busy -* extent and then crash then the block may not contain the -* correct metadata after log recovery occurs. -*/ - nmap =1 ; - error =xfs_bmapi_write (args->trans, dp, (xfs_fileoff_t )lblkno, - blkcnt,XFS_BMAPI_ATTRFORK , args->total, &map, - &nmap); -if (error) -return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; - -ASSERT (nmap ==1 ); -ASSERT ((map.br_startblock !=DELAYSTARTBLOCK ) && - (map.br_startblock !=HOLESTARTBLOCK )); - lblkno += map.br_blockcount; - blkcnt -= map.br_blockcount; - -/* -* Start the next trans in the chain. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; - } - -return xfs_attr_rmtval_set_value (args); -} -/* * Find a hole for the attr and store it in the delayed attr context. This * initializes the context to roll through allocating an attr extent for a
libxfs/xfs_attr_remote.h +0 -1
@@ -9,7 +9,6 @@int xfs_attr3_rmt_blocks (struct xfs_mount *mp,int attrlen);int xfs_attr_rmtval_get (struct xfs_da_args *args); -int xfs_attr_rmtval_set (struct xfs_da_args *args);int xfs_attr_rmtval_stale (struct xfs_inode *ip,struct xfs_bmbt_irec *map,xfs_buf_flags_t incore_flags);int xfs_attr_rmtval_invalidate (struct xfs_da_args *args);
PATCH 20/61 xfs: Clean up xfs_attr_node_addname_clear_incomplete
In reply to Darrick J. WongFrom: Allison Henderson <[email protected]>
Source kernel commit: 4fd084dbbd05402bb6e24782b8e9f9ea3e8ab3d6
We can use the helper function xfs_attr_node_remove_name to reduce duplicate code in this function
--- libxfs/xfs_attr.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
libxfs/xfs_attr.c +3 -8
@@ -63,6 +63,8 @@ STATIC int xfs_attr_fillstate(xfs_da_state_t *state); STATIC int xfs_attr_refillstate(xfs_da_state_t *state); STATIC int xfs_attr_set_iter(struct xfs_delattr_context *dac,struct xfs_buf **leaf_bp); +STATIC int xfs_attr_node_remove_name(struct xfs_da_args *args, +struct xfs_da_state *state);int xfs_inode_hasattr(
@@ -1207,7 +1209,6 @@ xfs_attr_node_addname_clear_incomplete( {struct xfs_da_args *args = dac->da_args;struct xfs_da_state *state =NULL ; -struct xfs_da_state_blk *blk;int retval =0 ;int error =0 ;
@@ -1222,13 +1223,7 @@ xfs_attr_node_addname_clear_incomplete(if (error) goto out; -/* -* Remove the name and update the hashvals in the tree. -*/ - blk = &state->path.blk[state->path.active-1 ]; -ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); - error =xfs_attr3_leaf_remove (blk->bp, args); -xfs_da3_fixhashpath (state, &state->path); + error =xfs_attr_node_remove_name (args, state);/* * Check to see if the tree needs to be collapsed.
PATCH 21/61 xfs: clean up open-coded fs block unit conversions
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: a7bcb147fef39054fe324a1a988470f5da127196
Replace some open-coded fs block unit conversions with the standard conversion macro.
--- libxfs/xfs_inode_buf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libxfs/xfs_inode_buf.c +1 -1
@@ -609,7 +609,7 @@ xfs_inode_validate_extsize(*/ if (rt_flag) - blocksize_bytes = mp->m_sb.sb_rextsize << mp->m_sb.sb_blocklog; + blocksize_bytes =XFS_FSB_TO_B (mp, mp->m_sb.sb_rextsize);else blocksize_bytes = mp->m_sb.sb_blocksize;
PATCH 22/61 xfs: move xfs_perag_get/put to xfs_ag.[ch]
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: 9bbafc71919adfdf83fafd2ce909853b493e7d86
They are AG functions, not superblock functions, so move them to the appropriate location.
--- libxfs/xfs_ag.c | 135 +++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_ag.h | 10 +++ libxfs/xfs_ag_resv.c | 2 - libxfs/xfs_alloc.c | 2 - libxfs/xfs_alloc_btree.c | 2 - libxfs/xfs_attr_leaf.c | 1 libxfs/xfs_bmap.c | 1 libxfs/xfs_ialloc.c | 2 - libxfs/xfs_refcount_btree.c | 2 - libxfs/xfs_rmap.c | 1 libxfs/xfs_rmap_btree.c | 2 - libxfs/xfs_sb.c | 133 ------------------------------------------ libxfs/xfs_sb.h | 9 --- 13 files changed, 154 insertions(+), 148 deletions(-)
libxfs/xfs_ag.c +135 -0
@@ -26,6 +26,141 @@#include "xfs_defer.h" #include "xfs_log_format.h" #include "xfs_trans.h" +#include "xfs_trace.h" + +/* +* Passive reference counting access wrappers to the perag structures. If the +* per-ag structure is to be freed, the freeing code is responsible for cleaning +* up objects with passive references before freeing the structure. This is +* things like cached buffers. +*/ +struct xfs_perag * +xfs_perag_get ( +struct xfs_mount *mp, +xfs_agnumber_t agno) +{ +struct xfs_perag *pag; +int ref =0 ; + +rcu_read_lock (); + pag =radix_tree_lookup (&mp->m_perag_tree, agno); +if (pag) { +ASSERT (atomic_read (&pag->pag_ref) >=0 ); + ref =atomic_inc_return (&pag->pag_ref); + } +rcu_read_unlock (); +trace_xfs_perag_get (mp, agno, ref, _RET_IP_); +return pag; +} + +/* +* search from @first to find the next perag with the given tag set. +*/ +struct xfs_perag * +xfs_perag_get_tag ( +struct xfs_mount *mp, +xfs_agnumber_t first, +int tag) +{ +struct xfs_perag *pag; +int found; +int ref; + +rcu_read_lock (); + found =radix_tree_gang_lookup_tag (&mp->m_perag_tree, + (void **)&pag, first,1 , tag); +if (found <=0 ) { +rcu_read_unlock (); +return NULL ; + } + ref =atomic_inc_return (&pag->pag_ref); +rcu_read_unlock (); +trace_xfs_perag_get_tag (mp, pag->pag_agno, ref, _RET_IP_); +return pag; +} + +void +xfs_perag_put ( +struct xfs_perag *pag) +{ +int ref; + +ASSERT (atomic_read (&pag->pag_ref) >0 ); + ref =atomic_dec_return (&pag->pag_ref); +trace_xfs_perag_put (pag->pag_mount, pag->pag_agno, ref, _RET_IP_); +} + +/* +* xfs_initialize_perag_data +* +* Read in each per-ag structure so we can count up the number of +* allocated inodes, free inodes and used filesystem blocks as this +* information is no longer persistent in the superblock. Once we have +* this information, write it into the in-core superblock structure. +*/ +int +xfs_initialize_perag_data ( +struct xfs_mount *mp, +xfs_agnumber_t agcount) +{ +xfs_agnumber_t index; +xfs_perag_t *pag; +xfs_sb_t *sbp = &mp->m_sb; +uint64_t ifree =0 ; +uint64_t ialloc =0 ; +uint64_t bfree =0 ; +uint64_t bfreelst =0 ; +uint64_t btree =0 ; +uint64_t fdblocks; +int error =0 ; + +for (index =0 ; index < agcount; index++) { +/* +* read the agf, then the agi. This gets us +* all the information we need and populates the +* per-ag structures for us. +*/ + error =xfs_alloc_pagf_init (mp,NULL , index,0 ); +if (error) +return error; + + error =xfs_ialloc_pagi_init (mp,NULL , index); +if (error) +return error; + pag =xfs_perag_get (mp, index); + ifree += pag->pagi_freecount; + ialloc += pag->pagi_count; + bfree += pag->pagf_freeblks; + bfreelst += pag->pagf_flcount; + btree += pag->pagf_btreeblks; +xfs_perag_put (pag); + } + fdblocks = bfree + bfreelst + btree; + +/* +* If the new summary counts are obviously incorrect, fail the +* mount operation because that implies the AGFs are also corrupt. +* Clear FS_COUNTERS so that we don't unmount with a dirty log, which +* will prevent xfs_repair from fixing anything. +*/ +if (fdblocks > sbp->sb_dblocks || ifree > ialloc) { +xfs_alert (mp,"AGF corruption. Please run xfs_repair." ); + error = -EFSCORRUPTED ; + goto out; + } + +/* Overwrite incore superblock counters with just-read data */ +spin_lock (&mp->m_sb_lock); + sbp->sb_ifree = ifree; + sbp->sb_icount = ialloc; + sbp->sb_fdblocks = fdblocks; +spin_unlock (&mp->m_sb_lock); + +xfs_reinit_percpu_counters (mp); +out: +xfs_fs_mark_healthy (mp,XFS_SICK_FS_COUNTERS ); +return error; +}static int xfs_get_aghdr_buf(
libxfs/xfs_ag.h +10 -0
@@ -9,6 +9,16 @@struct xfs_mount ;struct xfs_trans ; +struct xfs_perag ; + +/* +* perag get/put wrappers for ref counting +*/ +int xfs_initialize_perag_data (struct xfs_mount *,xfs_agnumber_t ); +struct xfs_perag *xfs_perag_get (struct xfs_mount *,xfs_agnumber_t ); +struct xfs_perag *xfs_perag_get_tag (struct xfs_mount *,xfs_agnumber_t , +int tag); +void xfs_perag_put (struct xfs_perag *pag);struct aghdr_init_data {/* per ag data */
libxfs/xfs_ag_resv.c +1 -1
@@ -18,7 +18,7 @@#include "xfs_btree.h" #include "xfs_refcount_btree.h" #include "xfs_ialloc_btree.h" -#include "xfs_sb.h" +#include "xfs_ag.h" #include "xfs_ag_resv.h" /*
libxfs/xfs_alloc.c +1 -1
@@ -10,7 +10,6 @@#include "xfs_shared.h" #include "xfs_trans_resv.h" #include "xfs_bit.h" -#include "xfs_sb.h" #include "xfs_mount.h" #include "xfs_defer.h" #include "xfs_btree.h"
@@ -20,6 +19,7 @@#include "xfs_errortag.h" #include "xfs_trace.h" #include "xfs_trans.h" +#include "xfs_ag.h" #include "xfs_ag_resv.h" #include "xfs_bmap.h"
libxfs/xfs_alloc_btree.c +1 -1
@@ -9,7 +9,6 @@#include "xfs_format.h" #include "xfs_log_format.h" #include "xfs_trans_resv.h" -#include "xfs_sb.h" #include "xfs_mount.h" #include "xfs_btree.h" #include "xfs_btree_staging.h"
@@ -17,6 +16,7 @@#include "xfs_alloc.h" #include "xfs_trace.h" #include "xfs_trans.h" +#include "xfs_ag.h" STATIC struct xfs_btree_cur *
libxfs/xfs_attr_leaf.c +1 -0
@@ -24,6 +24,7 @@#include "xfs_attr_leaf.h" #include "xfs_trace.h" #include "xfs_dir2.h" +#include "xfs_ag.h" /*
libxfs/xfs_bmap.c +1 -0
@@ -26,6 +26,7 @@#include "xfs_attr_leaf.h" #include "xfs_quota_defs.h" #include "xfs_rmap.h" +#include "xfs_ag.h" #include "xfs_ag_resv.h" #include "xfs_refcount.h"
libxfs/xfs_ialloc.c +1 -1
@@ -10,7 +10,6 @@#include "xfs_log_format.h" #include "xfs_trans_resv.h" #include "xfs_bit.h" -#include "xfs_sb.h" #include "xfs_mount.h" #include "xfs_inode.h" #include "xfs_btree.h"
@@ -22,6 +21,7 @@#include "xfs_trans.h" #include "xfs_trace.h" #include "xfs_rmap.h" +#include "xfs_ag.h" /* * Lookup a record by ino in the btree given by cur.
libxfs/xfs_refcount_btree.c +1 -1
@@ -9,7 +9,6 @@#include "xfs_format.h" #include "xfs_log_format.h" #include "xfs_trans_resv.h" -#include "xfs_sb.h" #include "xfs_mount.h" #include "xfs_btree.h" #include "xfs_btree_staging.h"
@@ -19,6 +18,7 @@#include "xfs_trans.h" #include "xfs_bit.h" #include "xfs_rmap.h" +#include "xfs_ag.h" static struct xfs_btree_cur * xfs_refcountbt_dup_cursor(
libxfs/xfs_rmap.c +1 -0
@@ -20,6 +20,7 @@#include "xfs_trace.h" #include "xfs_errortag.h" #include "xfs_inode.h" +#include "xfs_ag.h" /* * Lookup the first record less than or equal to [bno, len, owner, offset]
libxfs/xfs_rmap_btree.c +1 -1
@@ -9,7 +9,6 @@#include "xfs_format.h" #include "xfs_log_format.h" #include "xfs_trans_resv.h" -#include "xfs_sb.h" #include "xfs_mount.h" #include "xfs_trans.h" #include "xfs_alloc.h"
@@ -18,6 +17,7 @@#include "xfs_rmap.h" #include "xfs_rmap_btree.h" #include "xfs_trace.h" +#include "xfs_ag.h" #include "xfs_ag_resv.h" /*
libxfs/xfs_sb.c +0 -133
145 lines not on this page · raw message
libxfs/xfs_sb.h +0 -9
@@ -13,15 +13,6 @@ struct xfs_trans;struct xfs_fsop_geom ;struct xfs_perag ; -/* -* perag get/put wrappers for ref counting -*/ -extern struct xfs_perag *xfs_perag_get (struct xfs_mount *,xfs_agnumber_t ); -extern struct xfs_perag *xfs_perag_get_tag (struct xfs_mount *,xfs_agnumber_t , -int tag); -extern void xfs_perag_put (struct xfs_perag *pag); -extern int xfs_initialize_perag_data (struct xfs_mount *,xfs_agnumber_t ); -extern void xfs_log_sb (struct xfs_trans *tp);extern int xfs_sync_sb (struct xfs_mount *mp,bool wait);extern int xfs_sync_sb_buf (struct xfs_mount *mp);
PATCH 23/61 xfs: move perag structure and setup to libxfs/xfs_ag.[ch]
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: 07b6403a6873045344b0c18cbb4a4360854f6d76
Move the xfs_perag infrastructure to the libxfs files that contain all the per AG infrastructure. This helps set up for passing perags around all the code instead of bare agnos with minimal extra includes for existing files.
--- include/xfs_mount.h | 65 ---------------------- libfrog/mockups.h | 24 ++++++++ libfrog/radix-tree.h | 3 + libxfs/init.c | 61 --------------------- libxfs/libxfs_api_defs.h | 2 + libxfs/libxfs_priv.h | 10 +++ libxfs/xfs_ag.c | 134 ++++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_ag.h | 98 +++++++++++++++++++++++++++++++++- libxfs/xfs_ag_resv.h | 15 +++++ libxfs/xfs_btree.c | 1 10 files changed, 285 insertions(+), 128 deletions(-)
include/xfs_mount.h +0 -65
@@ -117,71 +117,6 @@ typedef struct xfs_mount {#define M_IGEO (mp) (&(mp)->m_ino_geo) -struct xfs_ag_resv { -/* number of blocks originally reserved here */ -xfs_extlen_t ar_orig_reserved; -/* number of blocks reserved here */ -xfs_extlen_t ar_reserved; -/* number of blocks originally asked for */ -xfs_extlen_t ar_asked; -}; - -/* -* Per-ag incore structure, copies of information in agf and agi, -* to improve the performance of allocation group selection. -*/ -typedef struct xfs_perag { -struct xfs_mount *pag_mount;/* owner filesystem */ -xfs_agnumber_t pag_agno;/* AG this structure belongs to */ -atomic_t pag_ref;/* perag reference count */ -char pagf_init;/* this agf's entry is initialized */ -char pagi_init;/* this agi's entry is initialized */ -char pagf_metadata;/* the agf is preferred to be metadata */ -char pagi_inodeok;/* The agi is ok for inodes */ -uint8_t pagf_levels[XFS_BTNUM_AGF ]; -/* # of levels in bno & cnt btree */ -bool pagf_agflreset;/* agfl requires reset before use */ -uint32_t pagf_flcount;/* count of blocks in freelist */ -xfs_extlen_t pagf_freeblks;/* total free blocks */ -xfs_extlen_t pagf_longest;/* longest free space */ -uint32_t pagf_btreeblks;/* # of blocks held in AGF btrees */ -xfs_agino_t pagi_freecount;/* number of free inodes */ -xfs_agino_t pagi_count;/* number of allocated inodes */ - -/* -* Inode allocation search lookup optimisation. -* If the pagino matches, the search for new inodes -* doesn't need to search the near ones again straight away -*/ -xfs_agino_t pagl_pagino; -xfs_agino_t pagl_leftrec; -xfs_agino_t pagl_rightrec; -int pagb_count;/* pagb slots in use */ - -/* Blocks reserved for all kinds of metadata. */ -struct xfs_ag_resv pag_meta_resv; -/* Blocks reserved for just AGFL-based metadata. */ -struct xfs_ag_resv pag_rmapbt_resv; - -/* reference count */ -uint8_t pagf_refcount_level; -}xfs_perag_t ; - -static inline struct xfs_ag_resv * -xfs_perag_resv ( -struct xfs_perag *pag, -enum xfs_ag_resv_type type) -{ -switch (type) { -case XFS_AG_RESV_METADATA : -return &pag->pag_meta_resv; -case XFS_AG_RESV_RMAPBT : -return &pag->pag_rmapbt_resv; -default : -return NULL ; - } -} -#define LIBXFS_MOUNT_DEBUGGER 0x0001#define LIBXFS_MOUNT_32BITINODES 0x0002#define LIBXFS_MOUNT_32BITINOOPT 0x0004
libfrog/mockups.h +24 -0
@@ -16,4 +16,28 @@ typedef struct spinlock {#define spin_lock (a) ((void) 0)#define spin_unlock (a) ((void) 0) +struct rb_root { +}; + +#define RB_ROOT (struct rb_root) { } + +typedef struct wait_queue_head { +}wait_queue_head_t ; + +#define init_waitqueue_head (wqh) do { } while(0) + +struct rhashtable { +}; + +struct rcu_head { +}; + +#define call_rcu (arg, func) (func(arg)) + +struct delayed_work { +}; + +#define INIT_DELAYED_WORK (work, func) do { } while(0) +#define cancel_delayed_work_sync (work) do { } while(0) +#endif /* __LIBFROG_MOCKUPS_H__ */
libfrog/radix-tree.h +3 -0
@@ -60,4 +60,7 @@ radix_tree_gang_lookup_tag(struct radix_tree_root *root, void **results,int radix_tree_tagged (struct radix_tree_root *root,unsigned int tag);#endif +static inline int radix_tree_preload (int gfp_mask) {return 0 ; } +static inline void radix_tree_preload_end (void ) { } +#endif /* __LIBFROG_RADIX_TREE_H__ */
libxfs/init.c +1 -60
79 lines not on this page · raw message
libxfs/libxfs_api_defs.h +2 -0
@@ -104,6 +104,7 @@#define xfs_finobt_calc_reserves libxfs_finobt_calc_reserves#define xfs_free_extent libxfs_free_extent +#define xfs_free_perag libxfs_free_perag#define xfs_fs_geometry libxfs_fs_geometry#define xfs_highbit32 libxfs_highbit32#define xfs_highbit64 libxfs_highbit64
@@ -111,6 +112,7 @@#define xfs_idata_realloc libxfs_idata_realloc#define xfs_idestroy_fork libxfs_idestroy_fork#define xfs_iext_lookup_extent libxfs_iext_lookup_extent +#define xfs_initialize_perag libxfs_initialize_perag#define xfs_initialize_perag_data libxfs_initialize_perag_data#define xfs_init_local_fork libxfs_init_local_fork
libxfs/libxfs_priv.h +9 -1
@@ -547,7 +547,6 @@ int xfs_attr_rmtval_get(struct xfs_da_args *);void xfs_bmap_del_free (struct xfs_bmap_free *,struct xfs_bmap_free_item *);/* xfs_mount.c */ -int xfs_initialize_perag_data (struct xfs_mount *,xfs_agnumber_t );void xfs_mount_common (struct xfs_mount *,struct xfs_sb *);/*
@@ -666,6 +665,15 @@ static inline int test_and_set_bit(int nr, volatile unsigned long *addr)return 0 ; } +static inline int xfs_buf_hash_init (struct xfs_perag *pag) {return 0 ; } +static inline void xfs_buf_hash_destroy (struct xfs_perag *pag) { } + +static inline int xfs_iunlink_init (struct xfs_perag *pag) {return 0 ; } +static inline void xfs_iunlink_destroy (struct xfs_perag *pag) { } + +xfs_agnumber_t xfs_set_inode_alloc (struct xfs_mount *mp, +xfs_agnumber_t agcount); +/* Keep static checkers quiet about nonstatic functions by exporting */ int xfs_rtbuf_get (struct xfs_mount *mp,struct xfs_trans *tp,xfs_rtblock_t block,int issum,struct xfs_buf **bpp);
libxfs/xfs_ag.c +134 -0
146 lines not on this page · raw message
libxfs/xfs_ag.h +96 -2
105 lines not on this page · raw message
libxfs/xfs_ag_resv.h +15 -0
@@ -18,6 +18,21 @@ void xfs_ag_resv_alloc_extent(struct xfs_perag *pag, enum xfs_ag_resv_type type,void xfs_ag_resv_free_extent (struct xfs_perag *pag,enum xfs_ag_resv_type type,struct xfs_trans *tp,xfs_extlen_t len); +static inline struct xfs_ag_resv * +xfs_perag_resv ( +struct xfs_perag *pag, +enum xfs_ag_resv_type type) +{ +switch (type) { +case XFS_AG_RESV_METADATA : +return &pag->pag_meta_resv; +case XFS_AG_RESV_RMAPBT : +return &pag->pag_rmapbt_resv; +default : +return NULL ; + } +} +/* * RMAPBT reservation accounting wrappers. Since rmapbt blocks are sourced from * the AGFL, they are allocated one at a time and the reservation updates don't
libxfs/xfs_btree.c +1 -0
@@ -18,6 +18,7 @@#include "xfs_trace.h" #include "xfs_alloc.h" #include "xfs_btree_staging.h" +#include "xfs_ag.h" /* * Cursor allocation zone.
PATCH 24/61 xfs: make for_each_perag... a first class citizen
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: f250eedcf7621b9a56d563912b4eeacd524422c7
for_each_perag_tag() is defined in xfs_icache.c for local use. Promote this to xfs_ag.h and define equivalent iteration functions so that we can use them to iterate AGs instead to replace open coded perag walks and perag lookups.
We also convert as many of the straight forward open coded AG walks to use these iterators as possible. Anything that is not a direct conversion to an iterator is ignored and will be updated in future
--- libxfs/xfs_ag.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
libxfs/xfs_ag.h +17 -0
@@ -114,6 +114,23 @@ struct xfs_perag *xfs_perag_get_tag(struct xfs_mount *, xfs_agnumber_t, int tag);void xfs_perag_put (struct xfs_perag *pag); +/* +* Perag iteration APIs +*/ +#define for_each_perag (mp, next_agno, pag) \ + for ((next_agno) = 0, (pag) = xfs_perag_get((mp), 0); \ + (pag) != NULL; \ + (next_agno) = (pag)->pag_agno + 1, \ + xfs_perag_put(pag), \ + (pag) = xfs_perag_get((mp), (next_agno))) + +#define for_each_perag_tag (mp, next_agno, pag, tag) \ + for ((next_agno) = 0, (pag) = xfs_perag_get_tag((mp), 0, (tag)); \ + (pag) != NULL; \ + (next_agno) = (pag)->pag_agno + 1, \ + xfs_perag_put(pag), \ + (pag) = xfs_perag_get_tag((mp), (next_agno), (tag))) +struct aghdr_init_data {/* per ag data */ xfs_agblock_t agno;/* ag to init */
PATCH 25/61 xfs: convert raw ag walks to use for_each_perag
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: 934933c3eec9e4a5826d3d7a47aca0742337fded
Convert the raw walks to an iterator, pulling the current AG out of pag->pag_agno instead of the loop iterator variable.
--- libxfs/xfs_types.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
libxfs/xfs_types.c +3 -1
@@ -11,6 +11,7 @@#include "xfs_trans_resv.h" #include "xfs_bit.h" #include "xfs_mount.h" +#include "xfs_ag.h" /* Find the size of the AG, in blocks. */ inline xfs_agblock_t
@@ -222,12 +223,13 @@ xfs_icount_range( unsigned long long *max) {unsigned long long nr_inos =0 ; +struct xfs_perag *pag;xfs_agnumber_t agno;/* root, rtbitmap, rtsum all live in the first chunk */ *min =XFS_INODES_PER_CHUNK ; -for (agno =0 ; agno < mp->m_sb.sb_agcount; agno++) { +for_each_perag (mp, agno, pag) {xfs_agino_t first, last;xfs_agino_range (mp, agno, &first, &last);
PATCH 26/61 xfs: convert xfs_iwalk to use perag references
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: 6f4118fc6482b1989cdcb19a1a0ab53b2dca7ab9
Rather than manually walking the ags and passing agnunbers around, pass the perag for the AG we are currently working on around in the iwalk structure.
--- libxfs/xfs_ag.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
libxfs/xfs_ag.h +10 -6
@@ -117,19 +117,23 @@ void xfs_perag_put(struct xfs_perag *pag);/* * Perag iteration APIs */ -#define for_each_perag (mp, next_agno, pag) \ - for ((next_agno) = 0, (pag) = xfs_perag_get((mp), 0); \ +#define for_each_perag_from (mp, next_agno, pag) \ + for ((pag) = xfs_perag_get((mp), (next_agno)); \ (pag) != NULL; \ (next_agno) = (pag)->pag_agno + 1, \ xfs_perag_put(pag), \ (pag) = xfs_perag_get((mp), (next_agno))) -#define for_each_perag_tag (mp, next_agno, pag, tag) \ - for ((next_agno) = 0, (pag) = xfs_perag_get_tag((mp), 0, (tag)); \ +#define for_each_perag (mp, agno, pag) \ + (agno) = 0; \ + for_each_perag_from((mp), (agno), (pag)) + +#define for_each_perag_tag (mp, agno, pag, tag) \ + for ((agno) = 0, (pag) = xfs_perag_get_tag((mp), 0, (tag)); \ (pag) != NULL; \ - (next_agno) = (pag)->pag_agno + 1, \ + (agno) = (pag)->pag_agno + 1, \ xfs_perag_put(pag), \ - (pag) = xfs_perag_get_tag((mp), (next_agno), (tag))) + (pag) = xfs_perag_get_tag((mp), (agno), (tag)))struct aghdr_init_data {/* per ag data */
PATCH 27/61 xfs: convert secondary superblock walk to use perags
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: 7f8d3b3ca6fe9269b3c5deee0dcea38499288e06
Clean up the last external manual AG walk.
--- libxfs/xfs_sb.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
libxfs/xfs_sb.c +7 -5
@@ -22,6 +22,7 @@#include "xfs_refcount_btree.h" #include "xfs_da_format.h" #include "xfs_health.h" +#include "xfs_ag.h" /* * Physical superblock buffer manipulations. Shared with libxfs in userspace.
@@ -853,17 +854,18 @@ intxfs_update_secondary_sbs ( struct xfs_mount *mp) { -xfs_agnumber_t agno; +struct xfs_perag *pag; +xfs_agnumber_t agno =1 ;int saved_error =0 ;int error =0 ;LIST_HEAD (buffer_list);/* update secondary superblocks. */ -for (agno =1 ; agno < mp->m_sb.sb_agcount; agno++) { +for_each_perag_from (mp, agno, pag) {struct xfs_buf *bp; error =xfs_buf_get (mp->m_ddev_targp, -XFS_AG_DADDR (mp, agno,XFS_SB_DADDR ), +XFS_AG_DADDR (mp, pag->pag_agno,XFS_SB_DADDR ),XFS_FSS_TO_BB (mp,1 ), &bp);/* * If we get an error reading or writing alternate superblocks,
@@ -875,7 +877,7 @@ xfs_update_secondary_sbs(if (error) {xfs_warn (mp,"error allocating secondary superblock for ag %d" , - agno); + pag->pag_agno);if (!saved_error) saved_error = error;continue ;
@@ -896,7 +898,7 @@ xfs_update_secondary_sbs(if (error) {xfs_warn (mp,"write error %d updating a secondary superblock near ag %d" , - error, agno); + error, pag->pag_agno);if (!saved_error) saved_error = error;continue ;
PATCH 28/61 xfs: pass perags through to the busy extent code
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: 45d0662117565e6100f9e0cf356cd873542c95b1
All of the callers of the busy extent API either have perag references available to use so we can pass a perag to the busy extent functions rather than having them have to do unnecessary lookups.
--- libxfs/libxfs_priv.h | 4 ++-- libxfs/xfs_alloc.c | 37 +++++++++++++++++++------------------ libxfs/xfs_alloc.h | 2 +- libxfs/xfs_alloc_btree.c | 5 ++--- libxfs/xfs_rmap.c | 32 +++++++++++++++++++------------- libxfs/xfs_rmap_btree.c | 9 ++++----- 6 files changed, 47 insertions(+), 42 deletions(-)
libxfs/libxfs_priv.h +2 -2
@@ -486,8 +486,8 @@ void __xfs_buf_mark_corrupt(struct xfs_buf *bp, xfs_failaddr_t fa);#define xfs_extent_busy_reuse (mp,ag,bno,len,user) ((void) 0)/* avoid unused variable warning */ -#define xfs_extent_busy_insert(tp,ag,bno,len,flags)({ \ - xfs_agnumber_t __foo = ag; \ +#define xfs_extent_busy_insert(tp,pag,bno,len,flags)({ \ + struct xfs_perag *__foo = pag; \ __foo = __foo; /* no set-but-unused warning */ \ })#define xfs_extent_busy_trim (args,bno,len,busy_gen) ({ \
libxfs/xfs_alloc.c +19 -18
@@ -1059,7 +1059,7 @@ xfs_alloc_ag_vextent_small(if (fbno ==NULLAGBLOCK ) goto out; -xfs_extent_busy_reuse (args->mp, args->agno, fbno,1 , +xfs_extent_busy_reuse (args->mp, args->pag, fbno,1 , (args->datatype &XFS_ALLOC_NOBUSY ));if (args->datatype &XFS_ALLOC_USERDATA ) {
@@ -1174,7 +1174,7 @@ xfs_alloc_ag_vextent(if (error)return error; -ASSERT (!xfs_extent_busy_search (args->mp, args->agno, +ASSERT (!xfs_extent_busy_search (args->mp, args->pag, args->agbno, args->len)); }
@@ -3288,7 +3288,7 @@ xfs_alloc_vextent(int xfs_free_extent_fix_freelist (struct xfs_trans *tp, -xfs_agnumber_t agno, +struct xfs_perag *pag,struct xfs_buf **agbp) {struct xfs_alloc_arg args;
@@ -3297,7 +3297,8 @@ xfs_free_extent_fix_freelist(memset (&args,0 ,sizeof (struct xfs_alloc_arg )); args.tp = tp; args.mp = tp->t_mountp; - args.agno = agno; + args.agno = pag->pag_agno; + args.pag = pag;/* * validate that the block number is legal - the enables us to detect
@@ -3306,17 +3307,12 @@ xfs_free_extent_fix_freelist(if (args.agno >= args.mp->m_sb.sb_agcount)return -EFSCORRUPTED ; - args.pag =xfs_perag_get (args.mp, args.agno); -ASSERT (args.pag); - error =xfs_alloc_fix_freelist (&args,XFS_ALLOC_FLAG_FREEING );if (error) - goto out; +return error; *agbp = args.agbp; -out: -xfs_perag_put (args.pag); -return error; +return 0 ; }/*
@@ -3340,6 +3336,7 @@ __xfs_free_extent(struct xfs_agf *agf;int error;unsigned int busy_flags =0 ; +struct xfs_perag *pag;ASSERT (len !=0 );ASSERT (type !=XFS_AG_RESV_AGFL );
@@ -3348,33 +3345,37 @@ __xfs_free_extent( XFS_ERRTAG_FREE_EXTENT))return -EIO ; - error =xfs_free_extent_fix_freelist (tp, agno, &agbp); + pag =xfs_perag_get (mp, agno); + error =xfs_free_extent_fix_freelist (tp, pag, &agbp);if (error) -return error; + goto err; agf = agbp->b_addr;if (XFS_IS_CORRUPT (mp, agbno >= mp->m_sb.sb_agblocks)) { error = -EFSCORRUPTED ; - goto err; + goto err_release; }/* validate the extent size is legal now we have the agf locked */ if (XFS_IS_CORRUPT (mp, agbno + len >be32_to_cpu (agf->agf_length))) { error = -EFSCORRUPTED ; - goto err; + goto err_release; } error =xfs_free_ag_extent (tp, agbp, agno, agbno, len, oinfo, type);if (error) - goto err; + goto err_release;if (skip_discard) busy_flags |=XFS_EXTENT_BUSY_SKIP_DISCARD ; -xfs_extent_busy_insert (tp, agno, agbno, len, busy_flags); +xfs_extent_busy_insert (tp, pag, agbno, len, busy_flags); +xfs_perag_put (pag);return 0 ; -err: +err_release:xfs_trans_brelse (tp, agbp); +err: +xfs_perag_put (pag);return error; }
libxfs/xfs_alloc.h +1 -1
@@ -214,7 +214,7 @@ int xfs_alloc_read_agfl(struct xfs_mount *mp, struct xfs_trans *tp,int xfs_free_agfl_block (struct xfs_trans *,xfs_agnumber_t ,xfs_agblock_t ,struct xfs_buf *,struct xfs_owner_info *);int xfs_alloc_fix_freelist (struct xfs_alloc_arg *args,int flags); -int xfs_free_extent_fix_freelist (struct xfs_trans *tp,xfs_agnumber_t agno, +int xfs_free_extent_fix_freelist (struct xfs_trans *tp,struct xfs_perag *pag,struct xfs_buf **agbp);xfs_extlen_t xfs_prealloc_blocks (struct xfs_mount *mp);
libxfs/xfs_alloc_btree.c +2 -3
@@ -70,7 +70,7 @@ xfs_allocbt_alloc_block( }atomic64_inc (&cur->bc_mp->m_allocbt_blks); -xfs_extent_busy_reuse (cur->bc_mp, cur->bc_ag.agno, bno,1 , false); +xfs_extent_busy_reuse (cur->bc_mp, cur->bc_ag.agbp->b_pag, bno,1 , false); new->s =cpu_to_be32 (bno);
@@ -84,7 +84,6 @@ xfs_allocbt_free_block( struct xfs_buf *bp) {struct xfs_buf *agbp = cur->bc_ag.agbp; -struct xfs_agf *agf = agbp->b_addr;xfs_agblock_t bno;int error;
@@ -94,7 +93,7 @@ xfs_allocbt_free_block(return error;atomic64_dec (&cur->bc_mp->m_allocbt_blks); -xfs_extent_busy_insert (cur->bc_tp,be32_to_cpu (agf->agf_seqno), bno,1 , +xfs_extent_busy_insert (cur->bc_tp, agbp->b_pag, bno,1 ,XFS_EXTENT_BUSY_SKIP_DISCARD );return 0 ; }
libxfs/xfs_rmap.c +19 -13
@@ -11,6 +11,7 @@#include "xfs_trans_resv.h" #include "xfs_bit.h" #include "xfs_mount.h" +#include "xfs_sb.h" #include "xfs_defer.h" #include "xfs_btree.h" #include "xfs_trans.h"
@@ -2362,31 +2363,32 @@ xfs_rmap_finish_one( struct xfs_btree_cur **pcur) {struct xfs_mount *mp = tp->t_mountp; +struct xfs_perag *pag;struct xfs_btree_cur *rcur;struct xfs_buf *agbp =NULL ;int error =0 ; -xfs_agnumber_t agno;struct xfs_owner_info oinfo;xfs_agblock_t bno;bool unwritten; - agno =XFS_FSB_TO_AGNO (mp, startblock); -ASSERT (agno !=NULLAGNUMBER ); + pag =xfs_perag_get (mp,XFS_FSB_TO_AGNO (mp, startblock)); bno =XFS_FSB_TO_AGBNO (mp, startblock); -trace_xfs_rmap_deferred (mp, agno, type, bno, owner, whichfork, +trace_xfs_rmap_deferred (mp, pag->pag_agno, type, bno, owner, whichfork, startoff, blockcount, state); -if (XFS_TEST_ERROR (false, mp, -XFS_ERRTAG_RMAP_FINISH_ONE )) -return -EIO ; +if (XFS_TEST_ERROR (false, mp,XFS_ERRTAG_RMAP_FINISH_ONE )) { + error = -EIO ; + goto out_drop; + } +/* * If we haven't gotten a cursor or the cursor AG doesn't match * the startblock, get one now. */ rcur = *pcur; -if (rcur !=NULL && rcur->bc_ag.agno != agno) { +if (rcur !=NULL && rcur->bc_ag.agno != pag->pag_agno) {xfs_rmap_finish_one_cleanup (tp, rcur,0 ); rcur =NULL ; *pcur =NULL ;
@@ -2397,13 +2399,15 @@ xfs_rmap_finish_one(* rmapbt, because a shape change could cause us to * allocate blocks. */ - error =xfs_free_extent_fix_freelist (tp, agno, &agbp); + error =xfs_free_extent_fix_freelist (tp, pag, &agbp);if (error) -return error; -if (XFS_IS_CORRUPT (tp->t_mountp, !agbp)) -return -EFSCORRUPTED ; + goto out_drop; +if (XFS_IS_CORRUPT (tp->t_mountp, !agbp)) { + error = -EFSCORRUPTED ; + goto out_drop; + } - rcur =xfs_rmapbt_init_cursor (mp, tp, agbp, agno); + rcur =xfs_rmapbt_init_cursor (mp, tp, agbp, pag->pag_agno); } *pcur = rcur;
@@ -2441,6 +2445,8 @@ xfs_rmap_finish_one(ASSERT (0 ); error = -EFSCORRUPTED ; } +out_drop: +xfs_perag_put (pag);return error; }
libxfs/xfs_rmap_btree.c +4 -5
@@ -98,8 +98,7 @@ xfs_rmapbt_alloc_block(return 0 ; } -xfs_extent_busy_reuse (cur->bc_mp, cur->bc_ag.agno, bno,1 , - false); +xfs_extent_busy_reuse (cur->bc_mp, agbp->b_pag, bno,1 , false); new->s =cpu_to_be32 (bno);be32_add_cpu (&agf->agf_rmap_blocks,1 );
@@ -131,10 +130,10 @@ xfs_rmapbt_free_block(if (error)return error; -xfs_extent_busy_insert (cur->bc_tp,be32_to_cpu (agf->agf_seqno), bno,1 , -XFS_EXTENT_BUSY_SKIP_DISCARD ); - pag = cur->bc_ag.agbp->b_pag; +xfs_extent_busy_insert (cur->bc_tp, pag, bno,1 , +XFS_EXTENT_BUSY_SKIP_DISCARD ); +xfs_ag_resv_free_extent (pag,XFS_AG_RESV_RMAPBT ,NULL ,1 );return 0 ; }
PATCH 29/61 xfs: push perags through the ag reservation callouts
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: 30933120ad79f4549d6e364df7eda474cc0d9c65
We currently pass an agno from the AG reservation functions to the individual feature accounting functions, which in future may have to do perag lookups to access per-AG state. Instead, pre-emptively plumb the perag through from the highest AG reservation layer to the feature callouts so they won't have to look it up again.
--- db/info.c | 8 +++++--- libxfs/xfs_ag_resv.c | 9 ++++----- libxfs/xfs_ialloc_btree.c | 17 +++++++++-------- libxfs/xfs_ialloc_btree.h | 2 +- libxfs/xfs_refcount_btree.c | 7 +++---- libxfs/xfs_refcount_btree.h | 3 ++- libxfs/xfs_rmap_btree.c | 6 +++--- libxfs/xfs_rmap_btree.h | 2 +- 8 files changed, 28 insertions(+), 26 deletions(-)
db/info.c +5 -3
@@ -66,19 +66,20 @@ print_agresv_info( {struct xfs_buf *bp;struct xfs_agf *agf; +struct xfs_perag *pag =xfs_perag_get (mp, agno);xfs_extlen_t ask =0 ;xfs_extlen_t used =0 ;xfs_extlen_t free =0 ;xfs_extlen_t length =0 ;int error; - error = -libxfs_refcountbt_calc_reserves (mp,NULL , agno, &ask, &used); + error = -libxfs_refcountbt_calc_reserves (mp,NULL , pag, &ask, &used);if (error)xfrog_perror (error,"refcountbt" ); - error = -libxfs_finobt_calc_reserves (mp,NULL , agno, &ask, &used); + error = -libxfs_finobt_calc_reserves (mp,NULL , pag, &ask, &used);if (error)xfrog_perror (error,"finobt" ); - error = -libxfs_rmapbt_calc_reserves (mp,NULL , agno, &ask, &used); + error = -libxfs_rmapbt_calc_reserves (mp,NULL , pag, &ask, &used);if (error)xfrog_perror (error,"rmapbt" );
@@ -96,6 +97,7 @@ print_agresv_info(if (ask - used > free)printf (" <not enough space>" );printf ("\n" ); +xfs_perag_put (pag); } static int
libxfs/xfs_ag_resv.c +4 -5
@@ -249,7 +249,6 @@ xfs_ag_resv_init( struct xfs_trans *tp) {struct xfs_mount *mp = pag->pag_mount; -xfs_agnumber_t agno = pag->pag_agno;xfs_extlen_t ask;xfs_extlen_t used;int error =0 , error2;
@@ -259,11 +258,11 @@ xfs_ag_resv_init(if (pag->pag_meta_resv.ar_asked ==0 ) { ask = used =0 ; - error =xfs_refcountbt_calc_reserves (mp, tp, agno, &ask, &used); + error =xfs_refcountbt_calc_reserves (mp, tp, pag, &ask, &used);if (error) goto out; - error =xfs_finobt_calc_reserves (mp, tp, agno, &ask, &used); + error =xfs_finobt_calc_reserves (mp, tp, pag, &ask, &used);if (error) goto out;
@@ -281,7 +280,7 @@ xfs_ag_resv_init( mp->m_finobt_nores = true; - error =xfs_refcountbt_calc_reserves (mp, tp, agno, &ask, + error =xfs_refcountbt_calc_reserves (mp, tp, pag, &ask, &used);if (error) goto out;
@@ -299,7 +298,7 @@ xfs_ag_resv_init(if (pag->pag_rmapbt_resv.ar_asked ==0 ) { ask = used =0 ; - error =xfs_rmapbt_calc_reserves (mp, tp, agno, &ask, &used); + error =xfs_rmapbt_calc_reserves (mp, tp, pag, &ask, &used);if (error) goto out;
libxfs/xfs_ialloc_btree.c +9 -8
@@ -19,6 +19,7 @@#include "xfs_trace.h" #include "xfs_trans.h" #include "xfs_rmap.h" +#include "xfs_ag.h" STATIC int xfs_inobt_get_minrecs(
@@ -679,7 +680,7 @@ static intxfs_inobt_count_blocks ( struct xfs_mount *mp, struct xfs_trans *tp, - xfs_agnumber_t agno, + struct xfs_perag *pag, xfs_btnum_t btnum, xfs_extlen_t *tree_blocks) {
@@ -687,7 +688,7 @@ xfs_inobt_count_blocks(struct xfs_btree_cur *cur =NULL ;int error; - error =xfs_inobt_cur (mp, tp, agno, btnum, &cur, &agbp); + error =xfs_inobt_cur (mp, tp, pag->pag_agno, btnum, &cur, &agbp);if (error)return error;
@@ -703,14 +704,14 @@ static intxfs_finobt_read_blocks ( struct xfs_mount *mp, struct xfs_trans *tp, - xfs_agnumber_t agno, + struct xfs_perag *pag, xfs_extlen_t *tree_blocks) { struct xfs_buf *agbp;struct xfs_agi *agi;int error; - error =xfs_ialloc_read_agi (mp, tp, agno, &agbp); + error =xfs_ialloc_read_agi (mp, tp, pag->pag_agno, &agbp);if (error)return error;
@@ -727,7 +728,7 @@ intxfs_finobt_calc_reserves ( struct xfs_mount *mp, struct xfs_trans *tp, - xfs_agnumber_t agno, + struct xfs_perag *pag, xfs_extlen_t *ask, xfs_extlen_t *used) {
@@ -738,14 +739,14 @@ xfs_finobt_calc_reserves(return 0 ;if (xfs_sb_version_hasinobtcounts (&mp->m_sb)) - error =xfs_finobt_read_blocks (mp, tp, agno, &tree_len); + error =xfs_finobt_read_blocks (mp, tp, pag, &tree_len);else - error =xfs_inobt_count_blocks (mp, tp, agno,XFS_BTNUM_FINO , + error =xfs_inobt_count_blocks (mp, tp, pag,XFS_BTNUM_FINO , &tree_len);if (error)return error; - *ask +=xfs_inobt_max_size (mp, agno); + *ask +=xfs_inobt_max_size (mp, pag->pag_agno); *used += tree_len;return 0 ; }
libxfs/xfs_ialloc_btree.h +1 -1
@@ -64,7 +64,7 @@ int xfs_inobt_rec_check_count(struct xfs_mount *,#endif /* DEBUG */ int xfs_finobt_calc_reserves (struct xfs_mount *mp,struct xfs_trans *tp, -xfs_agnumber_t agno,xfs_extlen_t *ask,xfs_extlen_t *used); +struct xfs_perag *pag,xfs_extlen_t *ask,xfs_extlen_t *used);extern xfs_extlen_t xfs_iallocbt_calc_size (struct xfs_mount *mp,unsigned long long len); int xfs_inobt_cur(struct xfs_mount *mp, struct xfs_trans *tp,
libxfs/xfs_refcount_btree.c +3 -4
@@ -449,7 +449,7 @@ intxfs_refcountbt_calc_reserves ( struct xfs_mount *mp, struct xfs_trans *tp, - xfs_agnumber_t agno, + struct xfs_perag *pag, xfs_extlen_t *ask, xfs_extlen_t *used) {
@@ -462,8 +462,7 @@ xfs_refcountbt_calc_reserves(if (!xfs_sb_version_hasreflink (&mp->m_sb))return 0 ; - - error =xfs_alloc_read_agf (mp, tp, agno,0 , &agbp); + error =xfs_alloc_read_agf (mp, tp, pag->pag_agno,0 , &agbp);if (error)return error;
@@ -478,7 +477,7 @@ xfs_refcountbt_calc_reserves(* expansion. We therefore can pretend the space isn't there. */ if (mp->m_sb.sb_logstart && -XFS_FSB_TO_AGNO (mp, mp->m_sb.sb_logstart) == agno) +XFS_FSB_TO_AGNO (mp, mp->m_sb.sb_logstart) == pag->pag_agno) agblocks -= mp->m_sb.sb_logblocks; *ask +=xfs_refcountbt_max_size (mp, agblocks);
libxfs/xfs_refcount_btree.h +2 -1
@@ -13,6 +13,7 @@struct xfs_buf ;struct xfs_btree_cur ;struct xfs_mount ; +struct xfs_perag ;struct xbtree_afakeroot ;/*
@@ -58,7 +59,7 @@ extern xfs_extlen_t xfs_refcountbt_max_size(struct xfs_mount *mp, xfs_agblock_t agblocks);extern int xfs_refcountbt_calc_reserves (struct xfs_mount *mp, -struct xfs_trans *tp,xfs_agnumber_t agno,xfs_extlen_t *ask, +struct xfs_trans *tp,struct xfs_perag *pag,xfs_extlen_t *ask,xfs_extlen_t *used); void xfs_refcountbt_commit_staged_btree(struct xfs_btree_cur *cur,
libxfs/xfs_rmap_btree.c +3 -3
@@ -593,7 +593,7 @@ intxfs_rmapbt_calc_reserves ( struct xfs_mount *mp, struct xfs_trans *tp, - xfs_agnumber_t agno, + struct xfs_perag *pag, xfs_extlen_t *ask, xfs_extlen_t *used) {
@@ -606,7 +606,7 @@ xfs_rmapbt_calc_reserves(if (!xfs_sb_version_hasrmapbt (&mp->m_sb))return 0 ; - error =xfs_alloc_read_agf (mp, tp, agno,0 , &agbp); + error =xfs_alloc_read_agf (mp, tp, pag->pag_agno,0 , &agbp);if (error)return error;
@@ -621,7 +621,7 @@ xfs_rmapbt_calc_reserves(* expansion. We therefore can pretend the space isn't there. */ if (mp->m_sb.sb_logstart && -XFS_FSB_TO_AGNO (mp, mp->m_sb.sb_logstart) == agno) +XFS_FSB_TO_AGNO (mp, mp->m_sb.sb_logstart) == pag->pag_agno) agblocks -= mp->m_sb.sb_logblocks;/* Reserve 1% of the AG or enough for 1 block per record. */
libxfs/xfs_rmap_btree.h +1 -1
@@ -57,6 +57,6 @@ extern xfs_extlen_t xfs_rmapbt_max_size(struct xfs_mount *mp, xfs_agblock_t agblocks);extern int xfs_rmapbt_calc_reserves (struct xfs_mount *mp,struct xfs_trans *tp, -xfs_agnumber_t agno,xfs_extlen_t *ask,xfs_extlen_t *used); +struct xfs_perag *pag,xfs_extlen_t *ask,xfs_extlen_t *used);#endif /* __XFS_RMAP_BTREE_H__ */
PATCH 30/61 xfs: pass perags around in fsmap data dev functions
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: 58d43a7e3263766ade4974c86118e6b5737ea259
Needs a [from, to] ranged AG walk, and the perag to be stuffed into the info structure for callouts to use.
--- libxfs/xfs_ag.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
libxfs/xfs_ag.h +13 -2
@@ -116,14 +116,25 @@ void xfs_perag_put(struct xfs_perag *pag);/* * Perag iteration APIs +* +* XXX: for_each_perag_range() usage really needs an iterator to clean up when +* we terminate at end_agno because we may have taken a reference to the perag +* beyond end_agno. Right now callers have to be careful to catch and clean that +* up themselves. This is not necessary for the callers of for_each_perag() and +* for_each_perag_from() because they terminate at sb_agcount where there are +* no perag structures in tree beyond end_agno. */ -#define for_each_perag_from (mp, next_agno, pag) \ +#define for_each_perag_range (mp, next_agno, end_agno, pag) \ for ((pag) = xfs_perag_get((mp), (next_agno)); \ - (pag) != NULL; \ + (pag) != NULL && (next_agno) <= (end_agno); \ (next_agno) = (pag)->pag_agno + 1, \ xfs_perag_put(pag), \ (pag) = xfs_perag_get((mp), (next_agno))) +#define for_each_perag_from (mp, next_agno, pag) \ + for_each_perag_range((mp), (next_agno), (mp)->m_sb.sb_agcount, (pag)) + +#define for_each_perag (mp, agno, pag) \ (agno) = 0; \ for_each_perag_from((mp), (agno), (pag))
PATCH 31/61 xfs: add a perag to the btree cursor
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: be9fb17d88f08af648a89784d30dbac83d893154
Which will eventually completely replace the agno in it.
--- db/fsmap.c | 18 +++++++++++------- db/info.c | 4 ++-- include/atomic.h | 1 + libxfs/xfs_alloc.c | 25 +++++++++++++++---------- libxfs/xfs_alloc_btree.c | 13 ++++++++++--- libxfs/xfs_alloc_btree.h | 3 ++- libxfs/xfs_btree.c | 2 ++ libxfs/xfs_btree.h | 11 ++++++++++- libxfs/xfs_ialloc.c | 16 ++++++++-------- libxfs/xfs_ialloc_btree.c | 15 +++++++++++---- libxfs/xfs_ialloc_btree.h | 7 ++++--- libxfs/xfs_refcount.c | 4 ++-- libxfs/xfs_refcount_btree.c | 17 ++++++++++++----- libxfs/xfs_refcount_btree.h | 2 +- libxfs/xfs_rmap.c | 6 +++--- libxfs/xfs_rmap_btree.c | 17 ++++++++++++----- libxfs/xfs_rmap_btree.h | 2 +- repair/rmap.c | 38 ++++++++++++++++++++------------------ 18 files changed, 127 insertions(+), 74 deletions(-)
db/fsmap.c +11 -7
@@ -41,12 +41,12 @@ fsmap(struct fsmap_info info;xfs_agnumber_t start_ag;xfs_agnumber_t end_ag; -xfs_agnumber_t agno;xfs_daddr_t eofs;struct xfs_rmap_irec low = {0 };struct xfs_rmap_irec high = {0 };struct xfs_btree_cur *bt_cur;struct xfs_buf *agbp; +struct xfs_perag *pag;int error; eofs =XFS_FSB_TO_BB (mp, mp->m_sb.sb_dblocks);
@@ -63,29 +63,33 @@ fsmap( end_ag =XFS_FSB_TO_AGNO (mp, end_fsb); info.nr =0 ; -for (agno = start_ag; agno <= end_ag; agno++) { -if (agno == end_ag) +for_each_perag_range (mp, start_ag, end_ag, pag) { +if (pag->pag_agno == end_ag) high.rm_startblock =XFS_FSB_TO_AGBNO (mp, end_fsb); - error = -libxfs_alloc_read_agf (mp,NULL , agno,0 , &agbp); + error = -libxfs_alloc_read_agf (mp,NULL , pag->pag_agno,0 , &agbp);if (error) { +libxfs_perag_put (pag);dbprintf (_ ("Error %d while reading AGF.\n" ), error);return ; } - bt_cur =libxfs_rmapbt_init_cursor (mp,NULL , agbp, agno); + bt_cur =libxfs_rmapbt_init_cursor (mp,NULL , agbp, + pag->pag_agno, pag);if (!bt_cur) {libxfs_buf_relse (agbp); +libxfs_perag_put (pag);dbprintf (_ ("Not enough memory.\n" ));return ; } - info.agno = agno; + info.agno = pag->pag_agno; error = -libxfs_rmap_query_range (bt_cur, &low, &high, fsmap_fn, &info);if (error) {libxfs_btree_del_cursor (bt_cur,XFS_BTREE_ERROR );libxfs_buf_relse (agbp); +libxfs_perag_put (pag);dbprintf (_ ("Error %d while querying fsmap btree.\n" ), error);return ;
@@ -94,7 +98,7 @@ fsmap(libxfs_btree_del_cursor (bt_cur,XFS_BTREE_NOERROR );libxfs_buf_relse (agbp); -if (agno == start_ag) +if (pag->pag_agno == start_ag) low.rm_startblock =0 ; } }
db/info.c +2 -2
@@ -66,7 +66,7 @@ print_agresv_info( {struct xfs_buf *bp;struct xfs_agf *agf; -struct xfs_perag *pag =xfs_perag_get (mp, agno); +struct xfs_perag *pag =libxfs_perag_get (mp, agno);xfs_extlen_t ask =0 ;xfs_extlen_t used =0 ;xfs_extlen_t free =0 ;
@@ -97,7 +97,7 @@ print_agresv_info(if (ask - used > free)printf (" <not enough space>" );printf ("\n" ); -xfs_perag_put (pag); +libxfs_perag_put (pag); } static int
include/atomic.h +1 -0
@@ -15,6 +15,7 @@typedef int32_t atomic_t ;typedef int64_t atomic64_t ; +#define atomic_inc (x) ((*(x))++)#define atomic_inc_return (x) (++(*(x)))#define atomic_dec_return (x) (--(*(x)))
libxfs/xfs_alloc.c +15 -10
@@ -772,7 +772,8 @@ xfs_alloc_cur_setup(*/ if (!acur->cnt) acur->cnt =xfs_allocbt_init_cursor (args->mp, args->tp, - args->agbp, args->agno,XFS_BTNUM_CNT ); + args->agbp, args->agno, + args->pag,XFS_BTNUM_CNT ); error =xfs_alloc_lookup_ge (acur->cnt,0 , args->maxlen, &i);if (error)return error;
@@ -782,10 +783,12 @@ xfs_alloc_cur_setup(*/ if (!acur->bnolt) acur->bnolt =xfs_allocbt_init_cursor (args->mp, args->tp, - args->agbp, args->agno,XFS_BTNUM_BNO ); + args->agbp, args->agno, + args->pag,XFS_BTNUM_BNO );if (!acur->bnogt) acur->bnogt =xfs_allocbt_init_cursor (args->mp, args->tp, - args->agbp, args->agno,XFS_BTNUM_BNO ); + args->agbp, args->agno, + args->pag,XFS_BTNUM_BNO );return i ==1 ?0 : -ENOSPC ; }
@@ -1213,7 +1216,7 @@ xfs_alloc_ag_vextent_exact(* Allocate/initialize a cursor for the by-number freespace btree. */ bno_cur =xfs_allocbt_init_cursor (args->mp, args->tp, args->agbp, - args->agno,XFS_BTNUM_BNO ); + args->agno, args->pag,XFS_BTNUM_BNO );/* * Lookup bno and minlen in the btree (minlen is irrelevant, really).
@@ -1273,7 +1276,7 @@ xfs_alloc_ag_vextent_exact(* Allocate/initialize a cursor for the by-size btree. */ cnt_cur =xfs_allocbt_init_cursor (args->mp, args->tp, args->agbp, - args->agno,XFS_BTNUM_CNT ); + args->agno, args->pag,XFS_BTNUM_CNT );ASSERT (args->agbno + args->len <=be32_to_cpu (agf->agf_length)); error =xfs_alloc_fixup_trees (cnt_cur, bno_cur, fbno, flen, args->agbno, args->len,XFSA_FIXUP_BNO_OK );
@@ -1670,7 +1673,7 @@ xfs_alloc_ag_vextent_size(* Allocate and initialize a cursor for the by-size btree. */ cnt_cur =xfs_allocbt_init_cursor (args->mp, args->tp, args->agbp, - args->agno,XFS_BTNUM_CNT ); + args->agno, args->pag,XFS_BTNUM_CNT ); bno_cur =NULL ; busy = false;
@@ -1833,7 +1836,7 @@ xfs_alloc_ag_vextent_size(* Allocate and initialize a cursor for the by-block tree. */ bno_cur =xfs_allocbt_init_cursor (args->mp, args->tp, args->agbp, - args->agno,XFS_BTNUM_BNO ); + args->agno, args->pag,XFS_BTNUM_BNO );if ((error =xfs_alloc_fixup_trees (cnt_cur, bno_cur, fbno, flen, rbno, rlen,XFSA_FIXUP_CNT_OK ))) goto error0;
@@ -1905,7 +1908,8 @@ xfs_free_ag_extent(/* * Allocate and initialize a cursor for the by-block btree. */ - bno_cur =xfs_allocbt_init_cursor (mp, tp, agbp, agno,XFS_BTNUM_BNO ); + bno_cur =xfs_allocbt_init_cursor (mp, tp, agbp, agno, +NULL ,XFS_BTNUM_BNO );/* * Look for a neighboring block on the left (lower block numbers) * that is contiguous with this space.
@@ -1975,7 +1979,8 @@ xfs_free_ag_extent(/* * Now allocate and initialize a cursor for the by-size tree. */ - cnt_cur =xfs_allocbt_init_cursor (mp, tp, agbp, agno,XFS_BTNUM_CNT ); + cnt_cur =xfs_allocbt_init_cursor (mp, tp, agbp, agno, +NULL ,XFS_BTNUM_CNT );/* * Have both left and right contiguous neighbors. * Merge all three into a single free block.
@@ -2486,7 +2491,7 @@ xfs_exact_minlen_extent_available(int error =0 ; cnt_cur =xfs_allocbt_init_cursor (args->mp, args->tp, agbp, - args->agno,XFS_BTNUM_CNT ); + args->agno, args->pag,XFS_BTNUM_CNT ); error =xfs_alloc_lookup_ge (cnt_cur,0 , args->minlen, stat);if (error) goto out;
libxfs/xfs_alloc_btree.c +10 -3
@@ -25,7 +25,7 @@ xfs_allocbt_dup_cursor( {return xfs_allocbt_init_cursor (cur->bc_mp, cur->bc_tp, cur->bc_ag.agbp, cur->bc_ag.agno, - cur->bc_btnum); + cur->bc_ag.pag, cur->bc_btnum); }STATIC void
@@ -471,6 +471,7 @@ xfs_allocbt_init_common(struct xfs_mount *mp, struct xfs_trans *tp, xfs_agnumber_t agno, + struct xfs_perag *pag, xfs_btnum_t btnum) { struct xfs_btree_cur *cur;
@@ -495,6 +496,11 @@ xfs_allocbt_init_common( cur->bc_ag.agno = agno; cur->bc_ag.abt.active = false; +if (pag) { +/* take a reference for the cursor */ +atomic_inc (&pag->pag_ref); + } + cur->bc_ag.pag = pag;if (xfs_sb_version_hascrc (&mp->m_sb)) cur->bc_flags |=XFS_BTREE_CRC_BLOCKS ;
@@ -511,12 +517,13 @@ xfs_allocbt_init_cursor(struct xfs_trans *tp,/* transaction pointer */ struct xfs_buf *agbp, /* buffer for agf structure */ xfs_agnumber_t agno, /* allocation group number */ + struct xfs_perag *pag, xfs_btnum_t btnum) /* btree identifier */ { struct xfs_agf *agf = agbp->b_addr;struct xfs_btree_cur *cur; - cur =xfs_allocbt_init_common (mp, tp, agno, btnum); + cur =xfs_allocbt_init_common (mp, tp, agno, pag, btnum);if (btnum ==XFS_BTNUM_CNT ) cur->bc_nlevels =be32_to_cpu (agf->agf_levels[XFS_BTNUM_CNT ]);else
@@ -537,7 +544,7 @@ xfs_allocbt_stage_cursor( {struct xfs_btree_cur *cur; - cur =xfs_allocbt_init_common (mp,NULL , agno, btnum); + cur =xfs_allocbt_init_common (mp,NULL , agno,NULL , btnum);xfs_btree_stage_afakeroot (cur, afake);return cur; }
libxfs/xfs_alloc_btree.h +2 -1
@@ -13,6 +13,7 @@struct xfs_buf ;struct xfs_btree_cur ;struct xfs_mount ; +struct xfs_perag ;struct xbtree_afakeroot ;/*
@@ -48,7 +49,7 @@ struct xbtree_afakeroot;extern struct xfs_btree_cur *xfs_allocbt_init_cursor (struct xfs_mount *,struct xfs_trans *,struct xfs_buf *, -xfs_agnumber_t ,xfs_btnum_t ); +xfs_agnumber_t ,struct xfs_perag *pag,xfs_btnum_t );struct xfs_btree_cur *xfs_allocbt_stage_cursor (struct xfs_mount *mp,struct xbtree_afakeroot *afake,xfs_agnumber_t agno,xfs_btnum_t btnum);
libxfs/xfs_btree.c +2 -0
@@ -374,6 +374,8 @@ xfs_btree_del_cursor( XFS_FORCED_SHUTDOWN(cur->bc_mp));if (unlikely (cur->bc_flags &XFS_BTREE_STAGING ))kmem_free (cur->bc_ops); +if (!(cur->bc_flags &XFS_BTREE_LONG_PTRS ) && cur->bc_ag.pag) +xfs_perag_put (cur->bc_ag.pag);kmem_cache_free (xfs_btree_cur_zone, cur); }
libxfs/xfs_btree.h +10 -1
@@ -11,6 +11,7 @@ struct xfs_inode;struct xfs_mount ;struct xfs_trans ;struct xfs_ifork ; +struct xfs_perag ;extern kmem_zone_t *xfs_btree_cur_zone;
@@ -180,11 +181,12 @@ union xfs_btree_irec {/* Per-AG btree information. */ struct xfs_btree_cur_ag { + xfs_agnumber_t agno; + struct xfs_perag *pag; union { struct xfs_buf *agbp; struct xbtree_afakeroot *afake; /* for staging cursor */ }; - xfs_agnumber_t agno; union { struct { unsigned long nr_ops; /* # record updates */
@@ -231,6 +233,13 @@ typedef struct xfs_btree_curuint8_t bc_blocklog;/* log2(blocksize) of btree blocks */ xfs_btnum_t bc_btnum;/* identifies which btree type */ int bc_statoff;/* offset of btre stats array */ + +/* +* Short btree pointers need an agno to be able to turn the pointers +* into physical addresses for IO, so the btree cursor switches between +* bc_ino and bc_ag based on whether XFS_BTREE_LONG_PTRS is set for the +* cursor. +*/ union {struct xfs_btree_cur_ag bc_ag;struct xfs_btree_cur_ino bc_ino;
libxfs/xfs_ialloc.c +8 -8
@@ -178,7 +178,7 @@ xfs_inobt_insert(int i;int error; - cur =xfs_inobt_init_cursor (mp, tp, agbp, agno, btnum); + cur =xfs_inobt_init_cursor (mp, tp, agbp, agno,NULL , btnum); for (thisino = newino; thisino < newino + newlen;
@@ -526,7 +526,7 @@ xfs_inobt_insert_sprec(int i;struct xfs_inobt_rec_incore rec; - cur =xfs_inobt_init_cursor (mp, tp, agbp, agno, btnum); + cur =xfs_inobt_init_cursor (mp, tp, agbp, agno,NULL , btnum);/* the new record is pre-aligned so we know where to look */ error =xfs_inobt_lookup (cur, nrec->ir_startino,XFS_LOOKUP_EQ , &i);
@@ -1140,7 +1140,7 @@ xfs_dialloc_ag_inobt(ASSERT (pag->pagi_freecount >0 ); restart_pagno: - cur =xfs_inobt_init_cursor (mp, tp, agbp, agno,XFS_BTNUM_INO ); + cur =xfs_inobt_init_cursor (mp, tp, agbp, agno,NULL ,XFS_BTNUM_INO );/* * If pagino is 0 (this is the root inode allocation) use newino. * This must work because we've just allocated some.
@@ -1593,7 +1593,7 @@ xfs_dialloc_ag(if (!pagino) pagino =be32_to_cpu (agi->agi_newino); - cur =xfs_inobt_init_cursor (mp, tp, agbp, agno,XFS_BTNUM_FINO ); + cur =xfs_inobt_init_cursor (mp, tp, agbp, agno,NULL ,XFS_BTNUM_FINO ); error =xfs_check_agi_freecount (cur, agi);if (error)
@@ -1636,7 +1636,7 @@ xfs_dialloc_ag(* the original freecount. If all is well, make the equivalent update to * the inobt using the finobt record and offset information. */ - icur =xfs_inobt_init_cursor (mp, tp, agbp, agno,XFS_BTNUM_INO ); + icur =xfs_inobt_init_cursor (mp, tp, agbp, agno,NULL ,XFS_BTNUM_INO ); error =xfs_check_agi_freecount (icur, agi);if (error)
@@ -1949,7 +1949,7 @@ xfs_difree_inobt(/* * Initialize the cursor. */ - cur =xfs_inobt_init_cursor (mp, tp, agbp, agno,XFS_BTNUM_INO ); + cur =xfs_inobt_init_cursor (mp, tp, agbp, agno,NULL ,XFS_BTNUM_INO ); error =xfs_check_agi_freecount (cur, agi);if (error)
@@ -2075,7 +2075,7 @@ xfs_difree_finobt(int error;int i; - cur =xfs_inobt_init_cursor (mp, tp, agbp, agno,XFS_BTNUM_FINO ); + cur =xfs_inobt_init_cursor (mp, tp, agbp, agno,NULL ,XFS_BTNUM_FINO ); error =xfs_inobt_lookup (cur, ibtrec->ir_startino,XFS_LOOKUP_EQ , &i);if (error)
@@ -2276,7 +2276,7 @@ xfs_imap_lookup(* we have a record, we need to ensure it contains the inode number * we are looking up. */ - cur =xfs_inobt_init_cursor (mp, tp, agbp, agno,XFS_BTNUM_INO ); + cur =xfs_inobt_init_cursor (mp, tp, agbp, agno,NULL ,XFS_BTNUM_INO ); error =xfs_inobt_lookup (cur, agino,XFS_LOOKUP_LE , &i);if (!error) {if (i)
libxfs/xfs_ialloc_btree.c +11 -4
@@ -35,7 +35,7 @@ xfs_inobt_dup_cursor( {return xfs_inobt_init_cursor (cur->bc_mp, cur->bc_tp, cur->bc_ag.agbp, cur->bc_ag.agno, - cur->bc_btnum); + cur->bc_ag.pag, cur->bc_btnum); }STATIC void
@@ -428,6 +428,7 @@ xfs_inobt_init_common(struct xfs_mount *mp,/* file system mount point */ struct xfs_trans *tp, /* transaction pointer */ xfs_agnumber_t agno, /* allocation group number */ + struct xfs_perag *pag, xfs_btnum_t btnum) /* ialloc or free ino btree */ { struct xfs_btree_cur *cur;
@@ -450,6 +451,11 @@ xfs_inobt_init_common( cur->bc_flags |=XFS_BTREE_CRC_BLOCKS ; cur->bc_ag.agno = agno; +if (pag) { +/* take a reference for the cursor */ +atomic_inc (&pag->pag_ref); + } + cur->bc_ag.pag = pag;return cur; }
@@ -460,12 +466,13 @@ xfs_inobt_init_cursor(struct xfs_trans *tp, struct xfs_buf *agbp, xfs_agnumber_t agno, + struct xfs_perag *pag, xfs_btnum_t btnum) { struct xfs_btree_cur *cur;struct xfs_agi *agi = agbp->b_addr; - cur =xfs_inobt_init_common (mp, tp, agno, btnum); + cur =xfs_inobt_init_common (mp, tp, agno, pag, btnum);if (btnum ==XFS_BTNUM_INO ) cur->bc_nlevels =be32_to_cpu (agi->agi_level);else
@@ -484,7 +491,7 @@ xfs_inobt_stage_cursor( {struct xfs_btree_cur *cur; - cur =xfs_inobt_init_common (mp,NULL , agno, btnum); + cur =xfs_inobt_init_common (mp,NULL , agno,NULL , btnum);xfs_btree_stage_afakeroot (cur, afake);return cur; }
@@ -671,7 +678,7 @@ xfs_inobt_cur(if (error)return error; - cur =xfs_inobt_init_cursor (mp, tp, *agi_bpp, agno, which); + cur =xfs_inobt_init_cursor (mp, tp, *agi_bpp, agno,NULL , which); *curpp = cur;return 0 ; }
libxfs/xfs_ialloc_btree.h +4 -3
@@ -13,6 +13,7 @@struct xfs_buf ;struct xfs_btree_cur ;struct xfs_mount ; +struct xfs_perag ;/* * Btree block header size depends on a superblock flag.
@@ -45,9 +46,9 @@ struct xfs_mount; (maxrecs) * sizeof(xfs_inobt_key_t) + \ ((index) - 1) * sizeof(xfs_inobt_ptr_t))) -extern struct xfs_btree_cur *xfs_inobt_init_cursor (struct xfs_mount *, -struct xfs_trans *,struct xfs_buf *,xfs_agnumber_t , -xfs_btnum_t ); +extern struct xfs_btree_cur *xfs_inobt_init_cursor (struct xfs_mount *mp, +struct xfs_trans *tp,struct xfs_buf *agbp,xfs_agnumber_t agno, +struct xfs_perag *pag,xfs_btnum_t btnum);struct xfs_btree_cur *xfs_inobt_stage_cursor (struct xfs_mount *mp,struct xbtree_afakeroot *afake,xfs_agnumber_t agno,xfs_btnum_t btnum);
libxfs/xfs_refcount.c +2 -2
@@ -1177,7 +1177,7 @@ xfs_refcount_finish_one(if (error)return error; - rcur =xfs_refcountbt_init_cursor (mp, tp, agbp, agno); + rcur =xfs_refcountbt_init_cursor (mp, tp, agbp, agno,NULL ); rcur->bc_ag.refc.nr_ops = nr_ops; rcur->bc_ag.refc.shape_changes = shape_changes; }
@@ -1706,7 +1706,7 @@ xfs_refcount_recover_cow_leftovers( error =xfs_alloc_read_agf (mp, tp, agno,0 , &agbp);if (error) goto out_trans; - cur =xfs_refcountbt_init_cursor (mp, tp, agbp, agno); + cur =xfs_refcountbt_init_cursor (mp, tp, agbp, agno,NULL );/* Find all the leftover CoW staging extents. */ memset (&low,0 ,sizeof (low));
libxfs/xfs_refcount_btree.c +12 -5
@@ -25,7 +25,7 @@ xfs_refcountbt_dup_cursor( struct xfs_btree_cur *cur) {return xfs_refcountbt_init_cursor (cur->bc_mp, cur->bc_tp, - cur->bc_ag.agbp, cur->bc_ag.agno); + cur->bc_ag.agbp, cur->bc_ag.agno, cur->bc_ag.pag); }STATIC void
@@ -315,7 +315,8 @@ static struct xfs_btree_cur *xfs_refcountbt_init_common ( struct xfs_mount *mp, struct xfs_trans *tp, - xfs_agnumber_t agno) + xfs_agnumber_t agno, + struct xfs_perag *pag) { struct xfs_btree_cur *cur;
@@ -331,6 +332,11 @@ xfs_refcountbt_init_common( cur->bc_ag.agno = agno; cur->bc_flags |=XFS_BTREE_CRC_BLOCKS ; +if (pag) { +/* take a reference for the cursor */ +atomic_inc (&pag->pag_ref); + } + cur->bc_ag.pag = pag; cur->bc_ag.refc.nr_ops =0 ; cur->bc_ag.refc.shape_changes =0 ;
@@ -344,12 +350,13 @@ xfs_refcountbt_init_cursor(struct xfs_mount *mp, struct xfs_trans *tp, struct xfs_buf *agbp, - xfs_agnumber_t agno) + xfs_agnumber_t agno, + struct xfs_perag *pag) { struct xfs_agf *agf = agbp->b_addr;struct xfs_btree_cur *cur; - cur =xfs_refcountbt_init_common (mp, tp, agno); + cur =xfs_refcountbt_init_common (mp, tp, agno, pag); cur->bc_nlevels =be32_to_cpu (agf->agf_refcount_level); cur->bc_ag.agbp = agbp;return cur;
@@ -364,7 +371,7 @@ xfs_refcountbt_stage_cursor( {struct xfs_btree_cur *cur; - cur =xfs_refcountbt_init_common (mp,NULL , agno); + cur =xfs_refcountbt_init_common (mp,NULL , agno,NULL );xfs_btree_stage_afakeroot (cur, afake);return cur; }
libxfs/xfs_refcount_btree.h +1 -1
@@ -47,7 +47,7 @@ struct xbtree_afakeroot;extern struct xfs_btree_cur *xfs_refcountbt_init_cursor (struct xfs_mount *mp,struct xfs_trans *tp,struct xfs_buf *agbp, -xfs_agnumber_t agno); +xfs_agnumber_t agno,struct xfs_perag *pag);struct xfs_btree_cur *xfs_refcountbt_stage_cursor (struct xfs_mount *mp,struct xbtree_afakeroot *afake,xfs_agnumber_t agno);extern int xfs_refcountbt_maxrecs (int blocklen,bool leaf);
libxfs/xfs_rmap.c +3 -3
@@ -707,7 +707,7 @@ xfs_rmap_free(if (!xfs_sb_version_hasrmapbt (&mp->m_sb))return 0 ; - cur =xfs_rmapbt_init_cursor (mp, tp, agbp, agno); + cur =xfs_rmapbt_init_cursor (mp, tp, agbp, agno,NULL ); error =xfs_rmap_unmap (cur, bno, len, false, oinfo);
@@ -961,7 +961,7 @@ xfs_rmap_alloc(if (!xfs_sb_version_hasrmapbt (&mp->m_sb))return 0 ; - cur =xfs_rmapbt_init_cursor (mp, tp, agbp, agno); + cur =xfs_rmapbt_init_cursor (mp, tp, agbp, agno,NULL ); error =xfs_rmap_map (cur, bno, len, false, oinfo);xfs_btree_del_cursor (cur, error);
@@ -2407,7 +2407,7 @@ xfs_rmap_finish_one( goto out_drop; } - rcur =xfs_rmapbt_init_cursor (mp, tp, agbp, pag->pag_agno); + rcur =xfs_rmapbt_init_cursor (mp, tp, agbp, pag->pag_agno, pag); } *pcur = rcur;
libxfs/xfs_rmap_btree.c +12 -5
@@ -50,7 +50,7 @@ xfs_rmapbt_dup_cursor( struct xfs_btree_cur *cur) {return xfs_rmapbt_init_cursor (cur->bc_mp, cur->bc_tp, - cur->bc_ag.agbp, cur->bc_ag.agno); + cur->bc_ag.agbp, cur->bc_ag.agno, cur->bc_ag.pag); }STATIC void
@@ -447,7 +447,8 @@ static struct xfs_btree_cur *xfs_rmapbt_init_common ( struct xfs_mount *mp, struct xfs_trans *tp, - xfs_agnumber_t agno) + xfs_agnumber_t agno, + struct xfs_perag *pag) { struct xfs_btree_cur *cur;
@@ -461,6 +462,11 @@ xfs_rmapbt_init_common( cur->bc_statoff =XFS_STATS_CALC_INDEX (xs_rmap_2); cur->bc_ag.agno = agno; cur->bc_ops = &xfs_rmapbt_ops; +if (pag) { +/* take a reference for the cursor */ +atomic_inc (&pag->pag_ref); + } + cur->bc_ag.pag = pag;return cur; }
@@ -471,12 +477,13 @@ xfs_rmapbt_init_cursor(struct xfs_mount *mp, struct xfs_trans *tp, struct xfs_buf *agbp, - xfs_agnumber_t agno) + xfs_agnumber_t agno, + struct xfs_perag *pag) { struct xfs_agf *agf = agbp->b_addr;struct xfs_btree_cur *cur; - cur =xfs_rmapbt_init_common (mp, tp, agno); + cur =xfs_rmapbt_init_common (mp, tp, agno, pag); cur->bc_nlevels =be32_to_cpu (agf->agf_levels[XFS_BTNUM_RMAP ]); cur->bc_ag.agbp = agbp;return cur;
@@ -491,7 +498,7 @@ xfs_rmapbt_stage_cursor( {struct xfs_btree_cur *cur; - cur =xfs_rmapbt_init_common (mp,NULL , agno); + cur =xfs_rmapbt_init_common (mp,NULL , agno,NULL );xfs_btree_stage_afakeroot (cur, afake);return cur; }
libxfs/xfs_rmap_btree.h +1 -1
@@ -43,7 +43,7 @@ struct xbtree_afakeroot;struct xfs_btree_cur *xfs_rmapbt_init_cursor (struct xfs_mount *mp,struct xfs_trans *tp,struct xfs_buf *bp, -xfs_agnumber_t agno); +xfs_agnumber_t agno,struct xfs_perag *pag);struct xfs_btree_cur *xfs_rmapbt_stage_cursor (struct xfs_mount *mp,struct xbtree_afakeroot *afake,xfs_agnumber_t agno); void xfs_rmapbt_commit_staged_btree(struct xfs_btree_cur *cur,
repair/rmap.c +20 -18
@@ -976,14 +976,14 @@ rmaps_verify_btree( struct xfs_mount *mp, xfs_agnumber_t agno) { +struct xfs_rmap_irec tmp;struct xfs_slab_cursor *rm_cur;struct xfs_btree_cur *bt_cur =NULL ; -int error; -int have;struct xfs_buf *agbp =NULL ;struct xfs_rmap_irec *rm_rec; -struct xfs_rmap_irec tmp; -struct xfs_perag *pag;/* per allocation group data */ +struct xfs_perag *pag =NULL ; +int have; +int error;if (!xfs_sb_version_hasrmapbt (&mp->m_sb))return 0 ;
@@ -1005,9 +1005,8 @@ rmaps_verify_btree(/* Leave the per-ag data "uninitialized" since we rewrite it later */ pag =libxfs_perag_get (mp, agno); pag->pagf_init =0 ; -libxfs_perag_put (pag); - bt_cur =libxfs_rmapbt_init_cursor (mp,NULL , agbp, agno); + bt_cur =libxfs_rmapbt_init_cursor (mp,NULL , agbp, agno, pag);if (!bt_cur) { error = -ENOMEM ; goto err;
@@ -1081,6 +1080,8 @@ _("Incorrect reverse-mapping: saw (%u/%u) %slen %u owner %"PRId64" %s%soff \ err:if (bt_cur)libxfs_btree_del_cursor (bt_cur,XFS_BTREE_NOERROR ); +if (pag) +libxfs_perag_put (pag);if (agbp)libxfs_buf_relse (agbp);free_slab_cursor (&rm_cur);
@@ -1333,18 +1334,18 @@ refcount_avoid_check(void)*/ int check_refcounts ( -struct xfs_mount *mp, -xfs_agnumber_t agno) +struct xfs_mount *mp, +xfs_agnumber_t agno) { -struct xfs_slab_cursor *rl_cur; -struct xfs_btree_cur *bt_cur =NULL ; -int error; -int have; -int i; -struct xfs_buf *agbp =NULL ; -struct xfs_refcount_irec *rl_rec;struct xfs_refcount_irec tmp; -struct xfs_perag *pag;/* per allocation group data */ +struct xfs_slab_cursor *rl_cur; +struct xfs_btree_cur *bt_cur =NULL ; +struct xfs_buf *agbp =NULL ; +struct xfs_perag *pag =NULL ; +struct xfs_refcount_irec *rl_rec; +int have; +int i; +int error;if (!xfs_sb_version_hasreflink (&mp->m_sb))return 0 ;
@@ -1366,9 +1367,8 @@ check_refcounts(/* Leave the per-ag data "uninitialized" since we rewrite it later */ pag =libxfs_perag_get (mp, agno); pag->pagf_init =0 ; -libxfs_perag_put (pag); - bt_cur =libxfs_refcountbt_init_cursor (mp,NULL , agbp, agno); + bt_cur =libxfs_refcountbt_init_cursor (mp,NULL , agbp, agno, pag);if (!bt_cur) { error = -ENOMEM ; goto err;
@@ -1417,6 +1417,8 @@ _("Incorrect reference count: saw (%u/%u) len %u nlinks %u; should be (%u/%u) leif (bt_cur)libxfs_btree_del_cursor (bt_cur, error ?XFS_BTREE_ERROR :XFS_BTREE_NOERROR ); +if (pag) +libxfs_perag_put (pag);if (agbp)libxfs_buf_relse (agbp);free_slab_cursor (&rl_cur);
PATCH 32/61 xfs: convert rmap btree cursor to using a perag
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: fa9c3c197329fdab0efc48a8944d2c4a21c6a74f
--- db/fsmap.c | 3 +-- libxfs/xfs_ag.c | 2 +- libxfs/xfs_alloc.c | 7 ++++--- libxfs/xfs_rmap.c | 10 +++++----- libxfs/xfs_rmap.h | 6 ++++-- libxfs/xfs_rmap_btree.c | 37 ++++++++++++++++--------------------- libxfs/xfs_rmap_btree.h | 4 ++-- repair/agbtree.c | 5 +++-- repair/agbtree.h | 2 +- repair/phase5.c | 10 ++++++---- repair/rmap.c | 7 +++++-- 11 files changed, 48 insertions(+), 45 deletions(-)
db/fsmap.c +1 -2
@@ -74,8 +74,7 @@ fsmap(return ; } - bt_cur =libxfs_rmapbt_init_cursor (mp,NULL , agbp, - pag->pag_agno, pag); + bt_cur =libxfs_rmapbt_init_cursor (mp,NULL , agbp, pag);if (!bt_cur) {libxfs_buf_relse (agbp);libxfs_perag_put (pag);
libxfs/xfs_ag.c +1 -1
@@ -913,7 +913,7 @@ xfs_ag_extend_space(* XFS_RMAP_OINFO_SKIP_UPDATE is used here to tell the rmap btree that * this doesn't actually exist in the rmap btree. */ - error =xfs_rmap_free (tp, bp, id->agno, + error =xfs_rmap_free (tp, bp, bp->b_pag,be32_to_cpu (agf->agf_length) - len, len, &XFS_RMAP_OINFO_SKIP_UPDATE );if (error)
libxfs/xfs_alloc.c +4 -3
@@ -1088,7 +1088,7 @@ xfs_alloc_ag_vextent_small(* If we're feeding an AGFL block to something that doesn't live in the * free space, we need to clear out the OWN_AG rmap. */ - error =xfs_rmap_free (args->tp, args->agbp, args->agno, fbno,1 , + error =xfs_rmap_free (args->tp, args->agbp, args->pag, fbno,1 , &XFS_RMAP_OINFO_AG );if (error) goto error;
@@ -1165,7 +1165,7 @@ xfs_alloc_ag_vextent(/* if not file data, insert new block into the reverse map btree */ if (!xfs_rmap_should_skip_owner_update (&args->oinfo)) { - error =xfs_rmap_alloc (args->tp, args->agbp, args->agno, + error =xfs_rmap_alloc (args->tp, args->agbp, args->pag, args->agbno, args->len, &args->oinfo);if (error)return error;
@@ -1895,12 +1895,13 @@ xfs_free_ag_extent(int haveright;/* have a right neighbor */ int i;int error; +struct xfs_perag *pag = agbp->b_pag; bno_cur = cnt_cur =NULL ; mp = tp->t_mountp;if (!xfs_rmap_should_skip_owner_update (oinfo)) { - error =xfs_rmap_free (tp, agbp, agno, bno, len, oinfo); + error =xfs_rmap_free (tp, agbp, pag, bno, len, oinfo);if (error) goto error0; }
libxfs/xfs_rmap.c +5 -5
@@ -695,7 +695,7 @@ intxfs_rmap_free ( struct xfs_trans *tp, struct xfs_buf *agbp, - xfs_agnumber_t agno, + struct xfs_perag *pag, xfs_agblock_t bno, xfs_extlen_t len, const struct xfs_owner_info *oinfo)
@@ -707,7 +707,7 @@ xfs_rmap_free(if (!xfs_sb_version_hasrmapbt (&mp->m_sb))return 0 ; - cur =xfs_rmapbt_init_cursor (mp, tp, agbp, agno,NULL ); + cur =xfs_rmapbt_init_cursor (mp, tp, agbp, pag); error =xfs_rmap_unmap (cur, bno, len, false, oinfo);
@@ -949,7 +949,7 @@ intxfs_rmap_alloc ( struct xfs_trans *tp, struct xfs_buf *agbp, - xfs_agnumber_t agno, + struct xfs_perag *pag, xfs_agblock_t bno, xfs_extlen_t len, const struct xfs_owner_info *oinfo)
@@ -961,7 +961,7 @@ xfs_rmap_alloc(if (!xfs_sb_version_hasrmapbt (&mp->m_sb))return 0 ; - cur =xfs_rmapbt_init_cursor (mp, tp, agbp, agno,NULL ); + cur =xfs_rmapbt_init_cursor (mp, tp, agbp, pag); error =xfs_rmap_map (cur, bno, len, false, oinfo);xfs_btree_del_cursor (cur, error);
@@ -2407,7 +2407,7 @@ xfs_rmap_finish_one( goto out_drop; } - rcur =xfs_rmapbt_init_cursor (mp, tp, agbp, pag->pag_agno, pag); + rcur =xfs_rmapbt_init_cursor (mp, tp, agbp, pag); } *pcur = rcur;
libxfs/xfs_rmap.h +4 -2
@@ -6,6 +6,8 @@#ifndef __XFS_RMAP_H__#define __XFS_RMAP_H__ +struct xfs_perag ; + static inline void xfs_rmap_ino_bmbt_owner( struct xfs_owner_info *oi,
@@ -113,10 +115,10 @@ xfs_owner_info_pack( }int xfs_rmap_alloc (struct xfs_trans *tp,struct xfs_buf *agbp, -xfs_agnumber_t agno,xfs_agblock_t bno,xfs_extlen_t len, +struct xfs_perag *pag,xfs_agblock_t bno,xfs_extlen_t len,const struct xfs_owner_info *oinfo);int xfs_rmap_free (struct xfs_trans *tp,struct xfs_buf *agbp, -xfs_agnumber_t agno,xfs_agblock_t bno,xfs_extlen_t len, +struct xfs_perag *pag,xfs_agblock_t bno,xfs_extlen_t len,const struct xfs_owner_info *oinfo); int xfs_rmap_lookup_le(struct xfs_btree_cur *cur, xfs_agblock_t bno,
libxfs/xfs_rmap_btree.c +16 -21
@@ -50,7 +50,7 @@ xfs_rmapbt_dup_cursor( struct xfs_btree_cur *cur) {return xfs_rmapbt_init_cursor (cur->bc_mp, cur->bc_tp, - cur->bc_ag.agbp, cur->bc_ag.agno, cur->bc_ag.pag); + cur->bc_ag.agbp, cur->bc_ag.pag); }STATIC void
@@ -62,13 +62,12 @@ xfs_rmapbt_set_root(struct xfs_buf *agbp = cur->bc_ag.agbp;struct xfs_agf *agf = agbp->b_addr;int btnum = cur->bc_btnum; -struct xfs_perag *pag = agbp->b_pag;ASSERT (ptr->s !=0 ); agf->agf_roots[btnum] = ptr->s;be32_add_cpu (&agf->agf_levels[btnum], inc); - pag->pagf_levels[btnum] += inc; + cur->bc_ag.pag->pagf_levels[btnum] += inc;xfs_alloc_log_agf (cur->bc_tp, agbp,XFS_AGF_ROOTS |XFS_AGF_LEVELS ); }
@@ -82,6 +81,7 @@ xfs_rmapbt_alloc_block( {struct xfs_buf *agbp = cur->bc_ag.agbp;struct xfs_agf *agf = agbp->b_addr; +struct xfs_perag *pag = cur->bc_ag.pag;int error;xfs_agblock_t bno;
@@ -91,20 +91,19 @@ xfs_rmapbt_alloc_block(if (error)return error; -trace_xfs_rmapbt_alloc_block (cur->bc_mp, cur->bc_ag.agno, - bno,1 ); +trace_xfs_rmapbt_alloc_block (cur->bc_mp, pag->pag_agno, bno,1 );if (bno ==NULLAGBLOCK ) { *stat =0 ;return 0 ; } -xfs_extent_busy_reuse (cur->bc_mp, agbp->b_pag, bno,1 , false); +xfs_extent_busy_reuse (cur->bc_mp, pag, bno,1 , false); new->s =cpu_to_be32 (bno);be32_add_cpu (&agf->agf_rmap_blocks,1 );xfs_alloc_log_agf (cur->bc_tp, agbp,XFS_AGF_RMAP_BLOCKS ); -xfs_ag_resv_rmapbt_alloc (cur->bc_mp, cur->bc_ag.agno); +xfs_ag_resv_rmapbt_alloc (cur->bc_mp, pag->pag_agno); *stat =1 ;return 0 ;
@@ -117,12 +116,12 @@ xfs_rmapbt_free_block( {struct xfs_buf *agbp = cur->bc_ag.agbp;struct xfs_agf *agf = agbp->b_addr; -struct xfs_perag *pag; +struct xfs_perag *pag = cur->bc_ag.pag;xfs_agblock_t bno;int error; bno =xfs_daddr_to_agbno (cur->bc_mp,XFS_BUF_ADDR (bp)); -trace_xfs_rmapbt_free_block (cur->bc_mp, cur->bc_ag.agno, +trace_xfs_rmapbt_free_block (cur->bc_mp, pag->pag_agno, bno,1 );be32_add_cpu (&agf->agf_rmap_blocks,-1 );xfs_alloc_log_agf (cur->bc_tp, agbp,XFS_AGF_RMAP_BLOCKS );
@@ -130,7 +129,6 @@ xfs_rmapbt_free_block(if (error)return error; - pag = cur->bc_ag.agbp->b_pag;xfs_extent_busy_insert (cur->bc_tp, pag, bno,1 ,XFS_EXTENT_BUSY_SKIP_DISCARD );
@@ -212,7 +210,7 @@ xfs_rmapbt_init_ptr_from_cur( {struct xfs_agf *agf = cur->bc_ag.agbp->b_addr; -ASSERT (cur->bc_ag.agno ==be32_to_cpu (agf->agf_seqno)); +ASSERT (cur->bc_ag.pag->pag_agno ==be32_to_cpu (agf->agf_seqno)); ptr->s = agf->agf_roots[cur->bc_btnum]; }
@@ -447,7 +445,6 @@ static struct xfs_btree_cur *xfs_rmapbt_init_common ( struct xfs_mount *mp, struct xfs_trans *tp, - xfs_agnumber_t agno, struct xfs_perag *pag) { struct xfs_btree_cur *cur;
@@ -460,13 +457,12 @@ xfs_rmapbt_init_common( cur->bc_flags =XFS_BTREE_CRC_BLOCKS |XFS_BTREE_OVERLAPPING ; cur->bc_blocklog = mp->m_sb.sb_blocklog; cur->bc_statoff =XFS_STATS_CALC_INDEX (xs_rmap_2); - cur->bc_ag.agno = agno; cur->bc_ops = &xfs_rmapbt_ops; -if (pag) { -/* take a reference for the cursor */ -atomic_inc (&pag->pag_ref); - } + +/* take a reference for the cursor */ +atomic_inc (&pag->pag_ref); cur->bc_ag.pag = pag; + cur->bc_ag.agno = pag->pag_agno;return cur; }
@@ -477,13 +473,12 @@ xfs_rmapbt_init_cursor(struct xfs_mount *mp, struct xfs_trans *tp, struct xfs_buf *agbp, - xfs_agnumber_t agno, struct xfs_perag *pag) { struct xfs_agf *agf = agbp->b_addr;struct xfs_btree_cur *cur; - cur =xfs_rmapbt_init_common (mp, tp, agno, pag); + cur =xfs_rmapbt_init_common (mp, tp, pag); cur->bc_nlevels =be32_to_cpu (agf->agf_levels[XFS_BTNUM_RMAP ]); cur->bc_ag.agbp = agbp;return cur;
@@ -494,11 +489,11 @@ struct xfs_btree_cur *xfs_rmapbt_stage_cursor ( struct xfs_mount *mp, struct xbtree_afakeroot *afake, - xfs_agnumber_t agno) + struct xfs_perag *pag) { struct xfs_btree_cur *cur; - cur =xfs_rmapbt_init_common (mp,NULL , agno,NULL ); + cur =xfs_rmapbt_init_common (mp,NULL , pag);xfs_btree_stage_afakeroot (cur, afake);return cur; }
libxfs/xfs_rmap_btree.h +2 -2
@@ -43,9 +43,9 @@ struct xbtree_afakeroot;struct xfs_btree_cur *xfs_rmapbt_init_cursor (struct xfs_mount *mp,struct xfs_trans *tp,struct xfs_buf *bp, -xfs_agnumber_t agno,struct xfs_perag *pag); +struct xfs_perag *pag);struct xfs_btree_cur *xfs_rmapbt_stage_cursor (struct xfs_mount *mp, -struct xbtree_afakeroot *afake,xfs_agnumber_t agno); +struct xbtree_afakeroot *afake,struct xfs_perag *pag);void xfs_rmapbt_commit_staged_btree (struct xfs_btree_cur *cur,struct xfs_trans *tp,struct xfs_buf *agbp);int xfs_rmapbt_maxrecs (int blocklen,int leaf);
repair/agbtree.c +3 -2
@@ -574,17 +574,18 @@ get_rmapbt_record(void init_rmapbt_cursor (struct repair_ctx *sc, -xfs_agnumber_t agno, +struct xfs_perag *pag,unsigned int free_space,struct bt_rebuild *btr) { +xfs_agnumber_t agno = pag->pag_agno;int error;if (!xfs_sb_version_hasrmapbt (&sc->mp->m_sb))return ;init_rebuild (sc, &XFS_RMAP_OINFO_AG , free_space, btr); - btr->cur =libxfs_rmapbt_stage_cursor (sc->mp, &btr->newbt.afake, agno); + btr->cur =libxfs_rmapbt_stage_cursor (sc->mp, &btr->newbt.afake, pag); btr->bload.get_record = get_rmapbt_record; btr->bload.claim_block = rebuild_claim_block;
repair/agbtree.h +1 -1
@@ -49,7 +49,7 @@ void init_ino_cursors(struct repair_ctx *sc, xfs_agnumber_t agno,void build_inode_btrees (struct repair_ctx *sc,xfs_agnumber_t agno,struct bt_rebuild *btr_ino,struct bt_rebuild *btr_fino); -void init_rmapbt_cursor (struct repair_ctx *sc,xfs_agnumber_t agno, +void init_rmapbt_cursor (struct repair_ctx *sc,struct xfs_perag *pag,unsigned int free_space,struct bt_rebuild *btr);void build_rmap_tree (struct repair_ctx *sc,xfs_agnumber_t agno,struct bt_rebuild *btr);
repair/phase5.c +6 -4
@@ -433,7 +433,7 @@ keep_fsinos(xfs_mount_t *mp)static void phase5_func (struct xfs_mount *mp, -xfs_agnumber_t agno, +struct xfs_perag *pag,struct bitmap *lost_blocks) {struct repair_ctx sc = { .mp = mp, };
@@ -443,6 +443,7 @@ phase5_func(struct bt_rebuild btr_fino;struct bt_rebuild btr_rmap;struct bt_rebuild btr_refc; +xfs_agnumber_t agno = pag->pag_agno;int extra_blocks =0 ;uint num_freeblocks;xfs_agblock_t num_extents;
@@ -476,7 +477,7 @@ _("unable to rebuild AG %u. Not enough free space in on-disk AG.\n"),init_ino_cursors (&sc, agno, num_freeblocks, &sb_icount_ag[agno], &sb_ifree_ag[agno], &btr_ino, &btr_fino); -init_rmapbt_cursor (&sc, agno, num_freeblocks, &btr_rmap); +init_rmapbt_cursor (&sc, pag, num_freeblocks, &btr_rmap);init_refc_cursor (&sc, agno, num_freeblocks, &btr_refc);
@@ -605,6 +606,7 @@ void phase5(xfs_mount_t *mp) {struct bitmap *lost_blocks =NULL ; +struct xfs_perag *pag;xfs_agnumber_t agno;int error;
@@ -651,8 +653,8 @@ phase5(xfs_mount_t *mp)if (error)do_error (_ ("cannot alloc lost block bitmap\n" )); -for (agno =0 ; agno < mp->m_sb.sb_agcount; agno++) -phase5_func (mp, agno, lost_blocks); +for_each_perag (mp, agno, pag) +phase5_func (mp, pag, lost_blocks);print_final_rpt ();
repair/rmap.c +5 -2
@@ -545,6 +545,7 @@ rmap_store_ag_btree_rec( rm_rec =pop_slab_cursor (rm_cur);while (rm_rec) {struct xfs_owner_info oinfo = {}; +struct xfs_perag *pag; error = -libxfs_trans_alloc_rollable (mp,16 , &tp);if (error)
@@ -556,8 +557,10 @@ rmap_store_ag_btree_rec(ASSERT (XFS_RMAP_NON_INODE_OWNER (rm_rec->rm_owner)); oinfo.oi_owner = rm_rec->rm_owner; - error = -libxfs_rmap_alloc (tp, agbp, agno, rm_rec->rm_startblock, + pag =libxfs_perag_get (mp, agno); + error = -libxfs_rmap_alloc (tp, agbp, pag, rm_rec->rm_startblock, rm_rec->rm_blockcount, &oinfo); +libxfs_perag_put (pag);if (error) goto err_trans;
@@ -1006,7 +1009,7 @@ rmaps_verify_btree( pag =libxfs_perag_get (mp, agno); pag->pagf_init =0 ; - bt_cur =libxfs_rmapbt_init_cursor (mp,NULL , agbp, agno, pag); + bt_cur =libxfs_rmapbt_init_cursor (mp,NULL , agbp, pag);if (!bt_cur) { error = -ENOMEM ; goto err;
PATCH 33/61 xfs: convert refcount btree cursor to use perags
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: a81a06211fb43d80ee746e7a40a32ed812002f8e
--- libxfs/xfs_refcount.c | 40 ++++++++++++++++++++++------------------ libxfs/xfs_refcount.h | 9 ++++++++- libxfs/xfs_refcount_btree.c | 22 +++++++++------------- libxfs/xfs_refcount_btree.h | 4 ++-- repair/agbtree.c | 5 +++-- repair/agbtree.h | 2 +- repair/phase5.c | 2 +- repair/rmap.c | 2 +- 8 files changed, 47 insertions(+), 39 deletions(-)
libxfs/xfs_refcount.c +22 -18
@@ -21,6 +21,7 @@#include "xfs_bit.h" #include "xfs_refcount.h" #include "xfs_rmap.h" +#include "xfs_ag.h" /* Allowable refcount adjustment amounts. */ enum xfs_refc_adjust_op {
@@ -1141,30 +1142,30 @@ xfs_refcount_finish_one(struct xfs_btree_cur *rcur;struct xfs_buf *agbp =NULL ;int error =0 ; -xfs_agnumber_t agno;xfs_agblock_t bno;xfs_agblock_t new_agbno;unsigned long nr_ops =0 ;int shape_changes =0 ; +struct xfs_perag *pag; - agno =XFS_FSB_TO_AGNO (mp, startblock); -ASSERT (agno !=NULLAGNUMBER ); + pag =xfs_perag_get (mp,XFS_FSB_TO_AGNO (mp, startblock)); bno =XFS_FSB_TO_AGBNO (mp, startblock);trace_xfs_refcount_deferred (mp,XFS_FSB_TO_AGNO (mp, startblock), type,XFS_FSB_TO_AGBNO (mp, startblock), blockcount); -if (XFS_TEST_ERROR (false, mp, -XFS_ERRTAG_REFCOUNT_FINISH_ONE )) -return -EIO ; +if (XFS_TEST_ERROR (false, mp,XFS_ERRTAG_REFCOUNT_FINISH_ONE )) { + error = -EIO ; + goto out_drop; + }/* * If we haven't gotten a cursor or the cursor AG doesn't match * the startblock, get one now. */ rcur = *pcur; -if (rcur !=NULL && rcur->bc_ag.agno != agno) { +if (rcur !=NULL && rcur->bc_ag.pag != pag) { nr_ops = rcur->bc_ag.refc.nr_ops; shape_changes = rcur->bc_ag.refc.shape_changes;xfs_refcount_finish_one_cleanup (tp, rcur,0 );
@@ -1172,12 +1173,12 @@ xfs_refcount_finish_one( *pcur =NULL ; }if (rcur ==NULL ) { - error =xfs_alloc_read_agf (tp->t_mountp, tp, agno, + error =xfs_alloc_read_agf (tp->t_mountp, tp, pag->pag_agno,XFS_ALLOC_FLAG_FREEING , &agbp);if (error) -return error; + goto out_drop; - rcur =xfs_refcountbt_init_cursor (mp, tp, agbp, agno,NULL ); + rcur =xfs_refcountbt_init_cursor (mp, tp, agbp, pag); rcur->bc_ag.refc.nr_ops = nr_ops; rcur->bc_ag.refc.shape_changes = shape_changes; }
@@ -1187,12 +1188,12 @@ xfs_refcount_finish_one(case XFS_REFCOUNT_INCREASE : error =xfs_refcount_adjust (rcur, bno, blockcount, &new_agbno, new_len,XFS_REFCOUNT_ADJUST_INCREASE ,NULL ); - *new_fsb =XFS_AGB_TO_FSB (mp, agno, new_agbno); + *new_fsb =XFS_AGB_TO_FSB (mp, pag->pag_agno, new_agbno);break ;case XFS_REFCOUNT_DECREASE : error =xfs_refcount_adjust (rcur, bno, blockcount, &new_agbno, new_len,XFS_REFCOUNT_ADJUST_DECREASE ,NULL ); - *new_fsb =XFS_AGB_TO_FSB (mp, agno, new_agbno); + *new_fsb =XFS_AGB_TO_FSB (mp, pag->pag_agno, new_agbno);break ;case XFS_REFCOUNT_ALLOC_COW : *new_fsb = startblock + blockcount;
@@ -1209,8 +1210,10 @@ xfs_refcount_finish_one( error = -EFSCORRUPTED ; }if (!error && *new_len >0 ) -trace_xfs_refcount_finish_one_leftover (mp, agno, type, +trace_xfs_refcount_finish_one_leftover (mp, pag->pag_agno, type, bno, blockcount, new_agbno, *new_len); +out_drop: +xfs_perag_put (pag);return error; }
@@ -1671,7 +1674,7 @@ xfs_refcount_recover_extent(int xfs_refcount_recover_cow_leftovers (struct xfs_mount *mp, -xfs_agnumber_t agno) +struct xfs_perag *pag) {struct xfs_trans *tp;struct xfs_btree_cur *cur;
@@ -1703,10 +1706,10 @@ xfs_refcount_recover_cow_leftovers(if (error)return error; - error =xfs_alloc_read_agf (mp, tp, agno,0 , &agbp); + error =xfs_alloc_read_agf (mp, tp, pag->pag_agno,0 , &agbp);if (error) goto out_trans; - cur =xfs_refcountbt_init_cursor (mp, tp, agbp, agno,NULL ); + cur =xfs_refcountbt_init_cursor (mp, tp, agbp, pag);/* Find all the leftover CoW staging extents. */ memset (&low,0 ,sizeof (low));
@@ -1728,11 +1731,12 @@ xfs_refcount_recover_cow_leftovers(if (error) goto out_free; -trace_xfs_refcount_recover_extent (mp, agno, &rr->rr_rrec); +trace_xfs_refcount_recover_extent (mp, pag->pag_agno, + &rr->rr_rrec);/* Free the orphan record */ agbno = rr->rr_rrec.rc_startblock -XFS_REFC_COW_START ; - fsb =XFS_AGB_TO_FSB (mp, agno, agbno); + fsb =XFS_AGB_TO_FSB (mp, pag->pag_agno, agbno);xfs_refcount_free_cow_extent (tp, fsb, rr->rr_rrec.rc_blockcount);
libxfs/xfs_refcount.h +8 -1
@@ -6,6 +6,13 @@#ifndef __XFS_REFCOUNT_H__#define __XFS_REFCOUNT_H__ +struct xfs_trans ; +struct xfs_mount ; +struct xfs_perag ; +struct xfs_btree_cur ; +struct xfs_bmbt_irec ; +struct xfs_refcount_irec ; +extern int xfs_refcount_lookup_le (struct xfs_btree_cur *cur,xfs_agblock_t bno,int *stat); extern int xfs_refcount_lookup_ge(struct xfs_btree_cur *cur,
@@ -50,7 +57,7 @@ void xfs_refcount_alloc_cow_extent(struct xfs_trans *tp, xfs_fsblock_t fsb,void xfs_refcount_free_cow_extent (struct xfs_trans *tp,xfs_fsblock_t fsb,xfs_extlen_t len);extern int xfs_refcount_recover_cow_leftovers (struct xfs_mount *mp, -xfs_agnumber_t agno); +struct xfs_perag *pag);/* * While we're adjusting the refcounts records of an extent, we have
libxfs/xfs_refcount_btree.c +9 -13
@@ -25,7 +25,7 @@ xfs_refcountbt_dup_cursor( struct xfs_btree_cur *cur) {return xfs_refcountbt_init_cursor (cur->bc_mp, cur->bc_tp, - cur->bc_ag.agbp, cur->bc_ag.agno, cur->bc_ag.pag); + cur->bc_ag.agbp, cur->bc_ag.pag); }STATIC void
@@ -315,13 +315,11 @@ static struct xfs_btree_cur *xfs_refcountbt_init_common ( struct xfs_mount *mp, struct xfs_trans *tp, - xfs_agnumber_t agno, struct xfs_perag *pag) { struct xfs_btree_cur *cur; -ASSERT (agno !=NULLAGNUMBER ); -ASSERT (agno < mp->m_sb.sb_agcount); +ASSERT (pag->pag_agno < mp->m_sb.sb_agcount); cur =kmem_cache_zalloc (xfs_btree_cur_zone,GFP_NOFS | __GFP_NOFAIL); cur->bc_tp = tp;
@@ -330,13 +328,12 @@ xfs_refcountbt_init_common( cur->bc_blocklog = mp->m_sb.sb_blocklog; cur->bc_statoff =XFS_STATS_CALC_INDEX (xs_refcbt_2); - cur->bc_ag.agno = agno; cur->bc_flags |=XFS_BTREE_CRC_BLOCKS ; -if (pag) { -/* take a reference for the cursor */ -atomic_inc (&pag->pag_ref); - } + +/* take a reference for the cursor */ +atomic_inc (&pag->pag_ref); cur->bc_ag.pag = pag; + cur->bc_ag.agno = pag->pag_agno; cur->bc_ag.refc.nr_ops =0 ; cur->bc_ag.refc.shape_changes =0 ;
@@ -350,13 +347,12 @@ xfs_refcountbt_init_cursor(struct xfs_mount *mp, struct xfs_trans *tp, struct xfs_buf *agbp, - xfs_agnumber_t agno, struct xfs_perag *pag) { struct xfs_agf *agf = agbp->b_addr;struct xfs_btree_cur *cur; - cur =xfs_refcountbt_init_common (mp, tp, agno, pag); + cur =xfs_refcountbt_init_common (mp, tp, pag); cur->bc_nlevels =be32_to_cpu (agf->agf_refcount_level); cur->bc_ag.agbp = agbp;return cur;
@@ -367,11 +363,11 @@ struct xfs_btree_cur *xfs_refcountbt_stage_cursor ( struct xfs_mount *mp, struct xbtree_afakeroot *afake, - xfs_agnumber_t agno) + struct xfs_perag *pag) { struct xfs_btree_cur *cur; - cur =xfs_refcountbt_init_common (mp,NULL , agno,NULL ); + cur =xfs_refcountbt_init_common (mp,NULL , pag);xfs_btree_stage_afakeroot (cur, afake);return cur; }
libxfs/xfs_refcount_btree.h +2 -2
@@ -47,9 +47,9 @@ struct xbtree_afakeroot;extern struct xfs_btree_cur *xfs_refcountbt_init_cursor (struct xfs_mount *mp,struct xfs_trans *tp,struct xfs_buf *agbp, -xfs_agnumber_t agno,struct xfs_perag *pag); +struct xfs_perag *pag);struct xfs_btree_cur *xfs_refcountbt_stage_cursor (struct xfs_mount *mp, -struct xbtree_afakeroot *afake,xfs_agnumber_t agno); +struct xbtree_afakeroot *afake,struct xfs_perag *pag);extern int xfs_refcountbt_maxrecs (int blocklen,bool leaf);extern void xfs_refcountbt_compute_maxlevels (struct xfs_mount *mp);
repair/agbtree.c +3 -2
@@ -645,10 +645,11 @@ get_refcountbt_record(void init_refc_cursor (struct repair_ctx *sc, -xfs_agnumber_t agno, +struct xfs_perag *pag,unsigned int free_space,struct bt_rebuild *btr) { +xfs_agnumber_t agno = pag->pag_agno;int error;if (!xfs_sb_version_hasreflink (&sc->mp->m_sb))
@@ -656,7 +657,7 @@ init_refc_cursor(init_rebuild (sc, &XFS_RMAP_OINFO_REFC , free_space, btr); btr->cur =libxfs_refcountbt_stage_cursor (sc->mp, &btr->newbt.afake, - agno); + pag); btr->bload.get_record = get_refcountbt_record; btr->bload.claim_block = rebuild_claim_block;
repair/agbtree.h +1 -1
@@ -54,7 +54,7 @@ void init_rmapbt_cursor(struct repair_ctx *sc, struct xfs_perag *pag,void build_rmap_tree (struct repair_ctx *sc,xfs_agnumber_t agno,struct bt_rebuild *btr); -void init_refc_cursor (struct repair_ctx *sc,xfs_agnumber_t agno, +void init_refc_cursor (struct repair_ctx *sc,struct xfs_perag *pag,unsigned int free_space,struct bt_rebuild *btr);void build_refcount_tree (struct repair_ctx *sc,xfs_agnumber_t agno,struct bt_rebuild *btr);
repair/phase5.c +1 -1
@@ -479,7 +479,7 @@ _("unable to rebuild AG %u. Not enough free space in on-disk AG.\n"),init_rmapbt_cursor (&sc, pag, num_freeblocks, &btr_rmap); -init_refc_cursor (&sc, agno, num_freeblocks, &btr_refc); +init_refc_cursor (&sc, pag, num_freeblocks, &btr_refc); num_extents =count_bno_extents_blocks (agno, &num_freeblocks);/*
repair/rmap.c +1 -1
@@ -1371,7 +1371,7 @@ check_refcounts( pag =libxfs_perag_get (mp, agno); pag->pagf_init =0 ; - bt_cur =libxfs_refcountbt_init_cursor (mp,NULL , agbp, agno, pag); + bt_cur =libxfs_refcountbt_init_cursor (mp,NULL , agbp, pag);if (!bt_cur) { error = -ENOMEM ; goto err;
PATCH 34/61 xfs: convert allocbt cursors to use perags
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: 289d38d22cd88960cb648dc480c50de5102519bb
--- libxfs/xfs_alloc.c | 25 ++++++++++--------------- libxfs/xfs_alloc_btree.c | 26 ++++++++++---------------- libxfs/xfs_alloc_btree.h | 8 ++++---- repair/agbtree.c | 7 ++++--- repair/agbtree.h | 2 +- repair/phase5.c | 2 +- 6 files changed, 30 insertions(+), 40 deletions(-)
libxfs/xfs_alloc.c +10 -15
@@ -772,8 +772,7 @@ xfs_alloc_cur_setup(*/ if (!acur->cnt) acur->cnt =xfs_allocbt_init_cursor (args->mp, args->tp, - args->agbp, args->agno, - args->pag,XFS_BTNUM_CNT ); + args->agbp, args->pag,XFS_BTNUM_CNT ); error =xfs_alloc_lookup_ge (acur->cnt,0 , args->maxlen, &i);if (error)return error;
@@ -783,12 +782,10 @@ xfs_alloc_cur_setup(*/ if (!acur->bnolt) acur->bnolt =xfs_allocbt_init_cursor (args->mp, args->tp, - args->agbp, args->agno, - args->pag,XFS_BTNUM_BNO ); + args->agbp, args->pag,XFS_BTNUM_BNO );if (!acur->bnogt) acur->bnogt =xfs_allocbt_init_cursor (args->mp, args->tp, - args->agbp, args->agno, - args->pag,XFS_BTNUM_BNO ); + args->agbp, args->pag,XFS_BTNUM_BNO );return i ==1 ?0 : -ENOSPC ; }
@@ -1216,7 +1213,7 @@ xfs_alloc_ag_vextent_exact(* Allocate/initialize a cursor for the by-number freespace btree. */ bno_cur =xfs_allocbt_init_cursor (args->mp, args->tp, args->agbp, - args->agno, args->pag,XFS_BTNUM_BNO ); + args->pag,XFS_BTNUM_BNO );/* * Lookup bno and minlen in the btree (minlen is irrelevant, really).
@@ -1276,7 +1273,7 @@ xfs_alloc_ag_vextent_exact(* Allocate/initialize a cursor for the by-size btree. */ cnt_cur =xfs_allocbt_init_cursor (args->mp, args->tp, args->agbp, - args->agno, args->pag,XFS_BTNUM_CNT ); + args->pag,XFS_BTNUM_CNT );ASSERT (args->agbno + args->len <=be32_to_cpu (agf->agf_length)); error =xfs_alloc_fixup_trees (cnt_cur, bno_cur, fbno, flen, args->agbno, args->len,XFSA_FIXUP_BNO_OK );
@@ -1673,7 +1670,7 @@ xfs_alloc_ag_vextent_size(* Allocate and initialize a cursor for the by-size btree. */ cnt_cur =xfs_allocbt_init_cursor (args->mp, args->tp, args->agbp, - args->agno, args->pag,XFS_BTNUM_CNT ); + args->pag,XFS_BTNUM_CNT ); bno_cur =NULL ; busy = false;
@@ -1836,7 +1833,7 @@ xfs_alloc_ag_vextent_size(* Allocate and initialize a cursor for the by-block tree. */ bno_cur =xfs_allocbt_init_cursor (args->mp, args->tp, args->agbp, - args->agno, args->pag,XFS_BTNUM_BNO ); + args->pag,XFS_BTNUM_BNO );if ((error =xfs_alloc_fixup_trees (cnt_cur, bno_cur, fbno, flen, rbno, rlen,XFSA_FIXUP_CNT_OK ))) goto error0;
@@ -1909,8 +1906,7 @@ xfs_free_ag_extent(/* * Allocate and initialize a cursor for the by-block btree. */ - bno_cur =xfs_allocbt_init_cursor (mp, tp, agbp, agno, -NULL ,XFS_BTNUM_BNO ); + bno_cur =xfs_allocbt_init_cursor (mp, tp, agbp, pag,XFS_BTNUM_BNO );/* * Look for a neighboring block on the left (lower block numbers) * that is contiguous with this space.
@@ -1980,8 +1976,7 @@ xfs_free_ag_extent(/* * Now allocate and initialize a cursor for the by-size tree. */ - cnt_cur =xfs_allocbt_init_cursor (mp, tp, agbp, agno, -NULL ,XFS_BTNUM_CNT ); + cnt_cur =xfs_allocbt_init_cursor (mp, tp, agbp, pag,XFS_BTNUM_CNT );/* * Have both left and right contiguous neighbors. * Merge all three into a single free block.
@@ -2492,7 +2487,7 @@ xfs_exact_minlen_extent_available(int error =0 ; cnt_cur =xfs_allocbt_init_cursor (args->mp, args->tp, agbp, - args->agno, args->pag,XFS_BTNUM_CNT ); + args->pag,XFS_BTNUM_CNT ); error =xfs_alloc_lookup_ge (cnt_cur,0 , args->minlen, stat);if (error) goto out;
libxfs/xfs_alloc_btree.c +10 -16
@@ -24,8 +24,7 @@ xfs_allocbt_dup_cursor( struct xfs_btree_cur *cur) {return xfs_allocbt_init_cursor (cur->bc_mp, cur->bc_tp, - cur->bc_ag.agbp, cur->bc_ag.agno, - cur->bc_ag.pag, cur->bc_btnum); + cur->bc_ag.agbp, cur->bc_ag.pag, cur->bc_btnum); }STATIC void
@@ -37,13 +36,12 @@ xfs_allocbt_set_root(struct xfs_buf *agbp = cur->bc_ag.agbp;struct xfs_agf *agf = agbp->b_addr;int btnum = cur->bc_btnum; -struct xfs_perag *pag = agbp->b_pag;ASSERT (ptr->s !=0 ); agf->agf_roots[btnum] = ptr->s;be32_add_cpu (&agf->agf_levels[btnum], inc); - pag->pagf_levels[btnum] += inc; + cur->bc_ag.pag->pagf_levels[btnum] += inc;xfs_alloc_log_agf (cur->bc_tp, agbp,XFS_AGF_ROOTS |XFS_AGF_LEVELS ); }
@@ -222,7 +220,7 @@ xfs_allocbt_init_ptr_from_cur( {struct xfs_agf *agf = cur->bc_ag.agbp->b_addr; -ASSERT (cur->bc_ag.agno ==be32_to_cpu (agf->agf_seqno)); +ASSERT (cur->bc_ag.pag->pag_agno ==be32_to_cpu (agf->agf_seqno)); ptr->s = agf->agf_roots[cur->bc_btnum]; }
@@ -470,7 +468,6 @@ STATIC struct xfs_btree_cur *xfs_allocbt_init_common ( struct xfs_mount *mp, struct xfs_trans *tp, - xfs_agnumber_t agno, struct xfs_perag *pag, xfs_btnum_t btnum) {
@@ -484,6 +481,7 @@ xfs_allocbt_init_common( cur->bc_mp = mp; cur->bc_btnum = btnum; cur->bc_blocklog = mp->m_sb.sb_blocklog; + cur->bc_ag.abt.active = false;if (btnum ==XFS_BTNUM_CNT ) { cur->bc_ops = &xfs_cntbt_ops;
@@ -494,13 +492,10 @@ xfs_allocbt_init_common( cur->bc_statoff =XFS_STATS_CALC_INDEX (xs_abtb_2); } - cur->bc_ag.agno = agno; - cur->bc_ag.abt.active = false; -if (pag) { -/* take a reference for the cursor */ -atomic_inc (&pag->pag_ref); - } +/* take a reference for the cursor */ +atomic_inc (&pag->pag_ref); cur->bc_ag.pag = pag; + cur->bc_ag.agno = pag->pag_agno;if (xfs_sb_version_hascrc (&mp->m_sb)) cur->bc_flags |=XFS_BTREE_CRC_BLOCKS ;
@@ -516,14 +511,13 @@ xfs_allocbt_init_cursor(struct xfs_mount *mp,/* file system mount point */ struct xfs_trans *tp, /* transaction pointer */ struct xfs_buf *agbp, /* buffer for agf structure */ - xfs_agnumber_t agno, /* allocation group number */ struct xfs_perag *pag, xfs_btnum_t btnum) /* btree identifier */ { struct xfs_agf *agf = agbp->b_addr;struct xfs_btree_cur *cur; - cur =xfs_allocbt_init_common (mp, tp, agno, pag, btnum); + cur =xfs_allocbt_init_common (mp, tp, pag, btnum);if (btnum ==XFS_BTNUM_CNT ) cur->bc_nlevels =be32_to_cpu (agf->agf_levels[XFS_BTNUM_CNT ]);else
@@ -539,12 +533,12 @@ struct xfs_btree_cur *xfs_allocbt_stage_cursor ( struct xfs_mount *mp, struct xbtree_afakeroot *afake, - xfs_agnumber_t agno, + struct xfs_perag *pag, xfs_btnum_t btnum) { struct xfs_btree_cur *cur; - cur =xfs_allocbt_init_common (mp,NULL , agno,NULL , btnum); + cur =xfs_allocbt_init_common (mp,NULL , pag, btnum);xfs_btree_stage_afakeroot (cur, afake);return cur; }
libxfs/xfs_alloc_btree.h +4 -4
@@ -47,11 +47,11 @@ struct xbtree_afakeroot; (maxrecs) * sizeof(xfs_alloc_key_t) + \ ((index) - 1) * sizeof(xfs_alloc_ptr_t))) -extern struct xfs_btree_cur *xfs_allocbt_init_cursor (struct xfs_mount *, -struct xfs_trans *,struct xfs_buf *, -xfs_agnumber_t ,struct xfs_perag *pag,xfs_btnum_t ); +extern struct xfs_btree_cur *xfs_allocbt_init_cursor (struct xfs_mount *mp, +struct xfs_trans *tp,struct xfs_buf *bp, +struct xfs_perag *pag,xfs_btnum_t btnum);struct xfs_btree_cur *xfs_allocbt_stage_cursor (struct xfs_mount *mp, -struct xbtree_afakeroot *afake,xfs_agnumber_t agno, +struct xbtree_afakeroot *afake,struct xfs_perag *pag,xfs_btnum_t btnum);extern int xfs_allocbt_maxrecs (struct xfs_mount *,int ,int ); extern xfs_extlen_t xfs_allocbt_calc_size(struct xfs_mount *mp,
repair/agbtree.c +4 -3
@@ -226,13 +226,14 @@ get_bnobt_record(void init_freespace_cursors (struct repair_ctx *sc, -xfs_agnumber_t agno, +struct xfs_perag *pag,unsigned int free_space,unsigned int *nr_extents,int *extra_blocks,struct bt_rebuild *btr_bno,struct bt_rebuild *btr_cnt) { +xfs_agnumber_t agno = pag->pag_agno;unsigned int agfl_goal;int error;
@@ -242,9 +243,9 @@ init_freespace_cursors(init_rebuild (sc, &XFS_RMAP_OINFO_AG , free_space, btr_cnt); btr_bno->cur =libxfs_allocbt_stage_cursor (sc->mp, - &btr_bno->newbt.afake, agno,XFS_BTNUM_BNO ); + &btr_bno->newbt.afake, pag,XFS_BTNUM_BNO ); btr_cnt->cur =libxfs_allocbt_stage_cursor (sc->mp, - &btr_cnt->newbt.afake, agno,XFS_BTNUM_CNT ); + &btr_cnt->newbt.afake, pag,XFS_BTNUM_CNT ); btr_bno->bload.get_record = get_bnobt_record; btr_bno->bload.claim_block = rebuild_claim_block;
repair/agbtree.h +1 -1
@@ -35,7 +35,7 @@ struct bt_rebuild {void finish_rebuild (struct xfs_mount *mp,struct bt_rebuild *btr,struct bitmap *lost_blocks); -void init_freespace_cursors (struct repair_ctx *sc,xfs_agnumber_t agno, +void init_freespace_cursors (struct repair_ctx *sc,struct xfs_perag *pag,unsigned int free_space,unsigned int *nr_extents,int *extra_blocks,struct bt_rebuild *btr_bno,struct bt_rebuild *btr_cnt);
repair/phase5.c +1 -1
@@ -507,7 +507,7 @@ _("unable to rebuild AG %u. Not enough free space in on-disk AG.\n"),/* * track blocks that we might really lose */ -init_freespace_cursors (&sc, agno, num_freeblocks, &num_extents, +init_freespace_cursors (&sc, pag, num_freeblocks, &num_extents, &extra_blocks, &btr_bno, &btr_cnt);/*
PATCH 35/61 xfs: use perag for ialloc btree cursors
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: 7b13c515518264df0cb90d84fdab907a627c0fa9
--- libxfs/xfs_ialloc.c | 177 +++++++++++++++++++++++---------------------- libxfs/xfs_ialloc_btree.c | 27 +++---- libxfs/xfs_ialloc_btree.h | 6 +- repair/agbtree.c | 7 +- repair/agbtree.h | 2 - repair/phase5.c | 2 - 6 files changed, 109 insertions(+), 112 deletions(-)
libxfs/xfs_ialloc.c +89 -88
@@ -167,18 +167,17 @@ xfs_inobt_insert(struct xfs_mount *mp, struct xfs_trans *tp, struct xfs_buf *agbp, + struct xfs_perag *pag, xfs_agino_t newino, xfs_agino_t newlen, xfs_btnum_t btnum) { struct xfs_btree_cur *cur; -struct xfs_agi *agi = agbp->b_addr; -xfs_agnumber_t agno =be32_to_cpu (agi->agi_seqno);xfs_agino_t thisino;int i;int error; - cur =xfs_inobt_init_cursor (mp, tp, agbp, agno,NULL , btnum); + cur =xfs_inobt_init_cursor (mp, tp, agbp, pag, btnum); for (thisino = newino; thisino < newino + newlen;
@@ -515,18 +514,17 @@ xfs_inobt_insert_sprec(struct xfs_mount *mp, struct xfs_trans *tp, struct xfs_buf *agbp, + struct xfs_perag *pag, int btnum, struct xfs_inobt_rec_incore *nrec, /* in/out: new/merged rec. */ bool merge) /* merge or replace */ { struct xfs_btree_cur *cur; -struct xfs_agi *agi = agbp->b_addr; -xfs_agnumber_t agno =be32_to_cpu (agi->agi_seqno);int error;int i;struct xfs_inobt_rec_incore rec; - cur =xfs_inobt_init_cursor (mp, tp, agbp, agno,NULL , btnum); + cur =xfs_inobt_init_cursor (mp, tp, agbp, pag, btnum);/* the new record is pre-aligned so we know where to look */ error =xfs_inobt_lookup (cur, nrec->ir_startino,XFS_LOOKUP_EQ , &i);
@@ -573,14 +571,14 @@ xfs_inobt_insert_sprec( goto error; } -trace_xfs_irec_merge_pre (mp, agno, rec.ir_startino, +trace_xfs_irec_merge_pre (mp, pag->pag_agno, rec.ir_startino, rec.ir_holemask, nrec->ir_startino, nrec->ir_holemask);/* merge to nrec to output the updated record */ __xfs_inobt_rec_merge (nrec, &rec); -trace_xfs_irec_merge_post (mp, agno, nrec->ir_startino, +trace_xfs_irec_merge_post (mp, pag->pag_agno, nrec->ir_startino, nrec->ir_holemask); error =xfs_inobt_rec_check_count (mp, nrec);
@@ -608,21 +606,20 @@ xfs_inobt_insert_sprec( STATIC intxfs_ialloc_ag_alloc (struct xfs_trans *tp, -struct xfs_buf *agbp) +struct xfs_buf *agbp, +struct xfs_perag *pag) {struct xfs_agi *agi;struct xfs_alloc_arg args; -xfs_agnumber_t agno;int error;xfs_agino_t newino;/* new first inode's number */ xfs_agino_t newlen;/* new number of inodes */ int isaligned =0 ;/* inode allocation at stripe */ /* unit boundary */ /* init. to full chunk */ -uint16_t allocmask = (uint16_t )-1 ;struct xfs_inobt_rec_incore rec; -struct xfs_perag *pag;struct xfs_ino_geometry *igeo =M_IGEO (tp->t_mountp); +uint16_t allocmask = (uint16_t )-1 ;int do_sparse =0 ;memset (&args,0 ,sizeof (args));
@@ -655,14 +652,13 @@ xfs_ialloc_ag_alloc(*/ agi = agbp->b_addr; newino =be32_to_cpu (agi->agi_newino); - agno =be32_to_cpu (agi->agi_seqno); args.agbno =XFS_AGINO_TO_AGBNO (args.mp, newino) + igeo->ialloc_blks;if (do_sparse) goto sparse_alloc;if (likely (newino !=NULLAGINO && (args.agbno <be32_to_cpu (agi->agi_length)))) { - args.fsbno =XFS_AGB_TO_FSB (args.mp, agno, args.agbno); + args.fsbno =XFS_AGB_TO_FSB (args.mp, pag->pag_agno, args.agbno); args.type =XFS_ALLOCTYPE_THIS_BNO ; args.prod =1 ;
@@ -722,7 +718,7 @@ xfs_ialloc_ag_alloc(* For now, just allocate blocks up front. */ args.agbno =be32_to_cpu (agi->agi_root); - args.fsbno =XFS_AGB_TO_FSB (args.mp, agno, args.agbno); + args.fsbno =XFS_AGB_TO_FSB (args.mp, pag->pag_agno, args.agbno);/* * Allocate a fixed-size extent of inodes. */
@@ -743,7 +739,7 @@ xfs_ialloc_ag_alloc(if (isaligned && args.fsbno ==NULLFSBLOCK ) { args.type =XFS_ALLOCTYPE_NEAR_BNO ; args.agbno =be32_to_cpu (agi->agi_root); - args.fsbno =XFS_AGB_TO_FSB (args.mp, agno, args.agbno); + args.fsbno =XFS_AGB_TO_FSB (args.mp, pag->pag_agno, args.agbno); args.alignment = igeo->cluster_align;if ((error =xfs_alloc_vextent (&args)))return error;
@@ -759,7 +755,7 @@ xfs_ialloc_ag_alloc( sparse_alloc: args.type =XFS_ALLOCTYPE_NEAR_BNO ; args.agbno =be32_to_cpu (agi->agi_root); - args.fsbno =XFS_AGB_TO_FSB (args.mp, agno, args.agbno); + args.fsbno =XFS_AGB_TO_FSB (args.mp, pag->pag_agno, args.agbno); args.alignment = args.mp->m_sb.sb_spino_align; args.prod =1 ;
@@ -804,7 +800,7 @@ xfs_ialloc_ag_alloc(* rather than a linear progression to prevent the next generation * number from being easily guessable. */ - error =xfs_ialloc_inode_init (args.mp, tp,NULL , newlen, agno, + error =xfs_ialloc_inode_init (args.mp, tp,NULL , newlen, pag->pag_agno, args.agbno, args.len,prandom_u32 ());if (error)
@@ -831,12 +827,12 @@ xfs_ialloc_ag_alloc(* if necessary. If a merge does occur, rec is updated to the * merged record. */ - error =xfs_inobt_insert_sprec (args.mp, tp, agbp,XFS_BTNUM_INO , - &rec, true); + error =xfs_inobt_insert_sprec (args.mp, tp, agbp, pag, +XFS_BTNUM_INO , &rec, true);if (error == -EFSCORRUPTED ) {xfs_alert (args.mp,"invalid sparse inode record: ino 0x%llx holemask 0x%x count %u" , -XFS_AGINO_TO_INO (args.mp, agno, +XFS_AGINO_TO_INO (args.mp, pag->pag_agno, rec.ir_startino), rec.ir_holemask, rec.ir_count);xfs_force_shutdown (args.mp,SHUTDOWN_CORRUPT_INCORE );
@@ -856,21 +852,20 @@ xfs_ialloc_ag_alloc(* existing record with this one. */ if (xfs_sb_version_hasfinobt (&args.mp->m_sb)) { - error =xfs_inobt_insert_sprec (args.mp, tp, agbp, -XFS_BTNUM_FINO , &rec, - false); + error =xfs_inobt_insert_sprec (args.mp, tp, agbp, pag, +XFS_BTNUM_FINO , &rec, false);if (error)return error; } }else {/* full chunk - insert new records to both btrees */ - error =xfs_inobt_insert (args.mp, tp, agbp, newino, newlen, + error =xfs_inobt_insert (args.mp, tp, agbp, pag, newino, newlen,XFS_BTNUM_INO );if (error)return error;if (xfs_sb_version_hasfinobt (&args.mp->m_sb)) { - error =xfs_inobt_insert (args.mp, tp, agbp, newino, + error =xfs_inobt_insert (args.mp, tp, agbp, pag, newino, newlen,XFS_BTNUM_FINO );if (error)return error;
@@ -882,7 +877,6 @@ xfs_ialloc_ag_alloc(*/ be32_add_cpu (&agi->agi_count, newlen);be32_add_cpu (&agi->agi_freecount, newlen); - pag = agbp->b_pag; pag->pagi_freecount += newlen; pag->pagi_count += newlen; agi->agi_newino =cpu_to_be32 (newino);
@@ -1118,15 +1112,14 @@ STATIC intxfs_dialloc_ag_inobt ( struct xfs_trans *tp, struct xfs_buf *agbp, + struct xfs_perag *pag, xfs_ino_t parent, xfs_ino_t *inop) { struct xfs_mount *mp = tp->t_mountp;struct xfs_agi *agi = agbp->b_addr; -xfs_agnumber_t agno =be32_to_cpu (agi->agi_seqno);xfs_agnumber_t pagno =XFS_INO_TO_AGNO (mp, parent);xfs_agino_t pagino =XFS_INO_TO_AGINO (mp, parent); -struct xfs_perag *pag = agbp->b_pag;struct xfs_btree_cur *cur, *tcur;struct xfs_inobt_rec_incore rec, trec;xfs_ino_t ino;
@@ -1140,7 +1133,7 @@ xfs_dialloc_ag_inobt(ASSERT (pag->pagi_freecount >0 ); restart_pagno: - cur =xfs_inobt_init_cursor (mp, tp, agbp, agno,NULL ,XFS_BTNUM_INO ); + cur =xfs_inobt_init_cursor (mp, tp, agbp, pag,XFS_BTNUM_INO );/* * If pagino is 0 (this is the root inode allocation) use newino. * This must work because we've just allocated some.
@@ -1155,7 +1148,7 @@ xfs_dialloc_ag_inobt(/* * If in the same AG as the parent, try to get near the parent. */ -if (pagno == agno) { +if (pagno == pag->pag_agno) {int doneleft;/* done, to the left */ int doneright;/* done, to the right */
@@ -1358,7 +1351,7 @@ xfs_dialloc_ag_inobt(ASSERT (offset <XFS_INODES_PER_CHUNK );ASSERT ((XFS_AGINO_TO_OFFSET (mp, rec.ir_startino) %XFS_INODES_PER_CHUNK ) ==0 ); - ino =XFS_AGINO_TO_INO (mp, agno, rec.ir_startino + offset); + ino =XFS_AGINO_TO_INO (mp, pag->pag_agno, rec.ir_startino + offset); rec.ir_free &= ~XFS_INOBT_MASK (offset); rec.ir_freecount--; error =xfs_inobt_update (cur, &rec);
@@ -1572,7 +1565,6 @@ xfs_dialloc_ag( {struct xfs_mount *mp = tp->t_mountp;struct xfs_agi *agi = agbp->b_addr; -xfs_agnumber_t agno =be32_to_cpu (agi->agi_seqno);xfs_agnumber_t pagno =XFS_INO_TO_AGNO (mp, parent);xfs_agino_t pagino =XFS_INO_TO_AGINO (mp, parent);struct xfs_btree_cur *cur;/* finobt cursor */
@@ -1582,9 +1574,10 @@ xfs_dialloc_ag(int error;int offset;int i; +struct xfs_perag *pag = agbp->b_pag;if (!xfs_sb_version_hasfinobt (&mp->m_sb)) -return xfs_dialloc_ag_inobt (tp, agbp, parent, inop); +return xfs_dialloc_ag_inobt (tp, agbp, pag, parent, inop);/* * If pagino is 0 (this is the root inode allocation) use newino.
@@ -1593,7 +1586,7 @@ xfs_dialloc_ag(if (!pagino) pagino =be32_to_cpu (agi->agi_newino); - cur =xfs_inobt_init_cursor (mp, tp, agbp, agno,NULL ,XFS_BTNUM_FINO ); + cur =xfs_inobt_init_cursor (mp, tp, agbp, pag,XFS_BTNUM_FINO ); error =xfs_check_agi_freecount (cur, agi);if (error)
@@ -1604,7 +1597,7 @@ xfs_dialloc_ag(* parent. If so, find the closest available inode to the parent. If * not, consider the agi hint or find the first free inode in the AG. */ -if (agno == pagno) +if (pag->pag_agno == pagno) error =xfs_dialloc_ag_finobt_near (pagino, &cur, &rec);else error =xfs_dialloc_ag_finobt_newino (agi, cur, &rec);
@@ -1616,7 +1609,7 @@ xfs_dialloc_ag(ASSERT (offset <XFS_INODES_PER_CHUNK );ASSERT ((XFS_AGINO_TO_OFFSET (mp, rec.ir_startino) %XFS_INODES_PER_CHUNK ) ==0 ); - ino =XFS_AGINO_TO_INO (mp, agno, rec.ir_startino + offset); + ino =XFS_AGINO_TO_INO (mp, pag->pag_agno, rec.ir_startino + offset);/* * Modify or remove the finobt record.
@@ -1636,7 +1629,7 @@ xfs_dialloc_ag(* the original freecount. If all is well, make the equivalent update to * the inobt using the finobt record and offset information. */ - icur =xfs_inobt_init_cursor (mp, tp, agbp, agno,NULL ,XFS_BTNUM_INO ); + icur =xfs_inobt_init_cursor (mp, tp, agbp, pag,XFS_BTNUM_INO ); error =xfs_check_agi_freecount (icur, agi);if (error)
@@ -1652,7 +1645,7 @@ xfs_dialloc_ag(*/ be32_add_cpu (&agi->agi_freecount,-1 );xfs_ialloc_log_agi (tp, agbp,XFS_AGI_FREECOUNT ); - agbp->b_pag->pagi_freecount--; + pag->pagi_freecount--;xfs_trans_mod_sb (tp,XFS_TRANS_SB_IFREE ,-1 );
@@ -1804,7 +1797,7 @@ xfs_dialloc_select_ag(if (!okalloc) goto nextag_relse_buffer; - error =xfs_ialloc_ag_alloc (*tpp, agbp); + error =xfs_ialloc_ag_alloc (*tpp, agbp, pag);if (error <0 ) {xfs_trans_brelse (*tpp, agbp);
@@ -1930,12 +1923,12 @@ xfs_difree_inobt(struct xfs_mount *mp, struct xfs_trans *tp, struct xfs_buf *agbp, + struct xfs_perag *pag, xfs_agino_t agino, struct xfs_icluster *xic, struct xfs_inobt_rec_incore *orec) { struct xfs_agi *agi = agbp->b_addr; -xfs_agnumber_t agno =be32_to_cpu (agi->agi_seqno);struct xfs_btree_cur *cur;struct xfs_inobt_rec_incore rec;int ilen;
@@ -1949,7 +1942,7 @@ xfs_difree_inobt(/* * Initialize the cursor. */ - cur =xfs_inobt_init_cursor (mp, tp, agbp, agno,NULL ,XFS_BTNUM_INO ); + cur =xfs_inobt_init_cursor (mp, tp, agbp, pag,XFS_BTNUM_INO ); error =xfs_check_agi_freecount (cur, agi);if (error)
@@ -2000,7 +1993,8 @@ xfs_difree_inobt(struct xfs_perag *pag = agbp->b_pag; xic->deleted = true; - xic->first_ino =XFS_AGINO_TO_INO (mp, agno, rec.ir_startino); + xic->first_ino =XFS_AGINO_TO_INO (mp, pag->pag_agno, + rec.ir_startino); xic->alloc =xfs_inobt_irec_to_allocmask (&rec);/*
@@ -2023,7 +2017,7 @@ xfs_difree_inobt( goto error0; } -xfs_difree_inode_chunk (tp, agno, &rec); +xfs_difree_inode_chunk (tp, pag->pag_agno, &rec); }else { xic->deleted = false;
@@ -2039,7 +2033,7 @@ xfs_difree_inobt(*/ be32_add_cpu (&agi->agi_freecount,1 );xfs_ialloc_log_agi (tp, agbp,XFS_AGI_FREECOUNT ); - agbp->b_pag->pagi_freecount++; + pag->pagi_freecount++;xfs_trans_mod_sb (tp,XFS_TRANS_SB_IFREE ,1 ); }
@@ -2064,18 +2058,18 @@ xfs_difree_finobt(struct xfs_mount *mp, struct xfs_trans *tp, struct xfs_buf *agbp, + struct xfs_perag *pag, xfs_agino_t agino, struct xfs_inobt_rec_incore *ibtrec) /* inobt record */ { struct xfs_agi *agi = agbp->b_addr; -xfs_agnumber_t agno =be32_to_cpu (agi->agi_seqno);struct xfs_btree_cur *cur;struct xfs_inobt_rec_incore rec;int offset = agino - ibtrec->ir_startino;int error;int i; - cur =xfs_inobt_init_cursor (mp, tp, agbp, agno,NULL ,XFS_BTNUM_FINO ); + cur =xfs_inobt_init_cursor (mp, tp, agbp, pag,XFS_BTNUM_FINO ); error =xfs_inobt_lookup (cur, ibtrec->ir_startino,XFS_LOOKUP_EQ , &i);if (error)
@@ -2183,16 +2177,15 @@ xfs_difree(xfs_agino_t agino;/* allocation group inode number */ xfs_agnumber_t agno;/* allocation group number */ int error;/* error return value */ -struct xfs_mount *mp;/* mount structure for filesystem */ +struct xfs_mount *mp = tp->t_mountp;struct xfs_inobt_rec_incore rec;/* btree record */ - - mp = tp->t_mountp; +struct xfs_perag *pag;/* * Break up inode number into its components. */ agno =XFS_INO_TO_AGNO (mp, inode); -if (agno >= mp->m_sb.sb_agcount) { +if (agno >= mp->m_sb.sb_agcount) {xfs_warn (mp,"%s: agno >= mp->m_sb.sb_agcount (%d >= %d)." , __func__, agno, mp->m_sb.sb_agcount);ASSERT (0 );
@@ -2226,7 +2219,8 @@ xfs_difree(/* * Fix up the inode allocation btree. */ - error =xfs_difree_inobt (mp, tp, agbp, agino, xic, &rec); + pag = agbp->b_pag; + error =xfs_difree_inobt (mp, tp, agbp, pag, agino, xic, &rec);if (error) goto error0;
@@ -2234,7 +2228,7 @@ xfs_difree(* Fix up the free inode btree. */ if (xfs_sb_version_hasfinobt (&mp->m_sb)) { - error =xfs_difree_finobt (mp, tp, agbp, agino, &rec); + error =xfs_difree_finobt (mp, tp, agbp, pag, agino, &rec);if (error) goto error0; }
@@ -2249,7 +2243,7 @@ STATIC intxfs_imap_lookup ( struct xfs_mount *mp, struct xfs_trans *tp, - xfs_agnumber_t agno, + struct xfs_perag *pag, xfs_agino_t agino, xfs_agblock_t agbno, xfs_agblock_t *chunk_agbno,
@@ -2262,11 +2256,11 @@ xfs_imap_lookup(int error;int i; - error =xfs_ialloc_read_agi (mp, tp, agno, &agbp); + error =xfs_ialloc_read_agi (mp, tp, pag->pag_agno, &agbp);if (error) {xfs_alert (mp,"%s: xfs_ialloc_read_agi() returned error %d, agno %d" , - __func__, error, agno); + __func__, error, pag->pag_agno);return error; }
@@ -2276,7 +2270,7 @@ xfs_imap_lookup(* we have a record, we need to ensure it contains the inode number * we are looking up. */ - cur =xfs_inobt_init_cursor (mp, tp, agbp, agno,NULL ,XFS_BTNUM_INO ); + cur =xfs_inobt_init_cursor (mp, tp, agbp, pag,XFS_BTNUM_INO ); error =xfs_inobt_lookup (cur, agino,XFS_LOOKUP_LE , &i);if (!error) {if (i)
@@ -2310,42 +2304,44 @@ xfs_imap_lookup(*/ int xfs_imap ( -xfs_mount_t *mp,/* file system mount structure */ -xfs_trans_t *tp,/* transaction pointer */ -xfs_ino_t ino,/* inode to locate */ -struct xfs_imap *imap,/* location map structure */ -uint flags)/* flags for inode btree lookup */ +struct xfs_mount *mp,/* file system mount structure */ +struct xfs_trans *tp,/* transaction pointer */ +xfs_ino_t ino,/* inode to locate */ +struct xfs_imap *imap,/* location map structure */ +uint flags)/* flags for inode btree lookup */ { -xfs_agblock_t agbno;/* block number of inode in the alloc group */ -xfs_agino_t agino;/* inode number within alloc group */ -xfs_agnumber_t agno;/* allocation group number */ -xfs_agblock_t chunk_agbno;/* first block in inode chunk */ -xfs_agblock_t cluster_agbno;/* first block in inode cluster */ -int error;/* error code */ -int offset;/* index of inode in its buffer */ -xfs_agblock_t offset_agbno;/* blks from chunk start to inode */ +xfs_agblock_t agbno;/* block number of inode in the alloc group */ +xfs_agino_t agino;/* inode number within alloc group */ +xfs_agblock_t chunk_agbno;/* first block in inode chunk */ +xfs_agblock_t cluster_agbno;/* first block in inode cluster */ +int error;/* error code */ +int offset;/* index of inode in its buffer */ +xfs_agblock_t offset_agbno;/* blks from chunk start to inode */ +struct xfs_perag *pag;ASSERT (ino !=NULLFSINO );/* * Split up the inode number into its parts. */ - agno =XFS_INO_TO_AGNO (mp, ino); + pag =xfs_perag_get (mp,XFS_INO_TO_AGNO (mp, ino)); agino =XFS_INO_TO_AGINO (mp, ino); agbno =XFS_AGINO_TO_AGBNO (mp, agino); -if (agno >= mp->m_sb.sb_agcount || agbno >= mp->m_sb.sb_agblocks || - ino !=XFS_AGINO_TO_INO (mp, agno, agino)) { +if (!pag || agbno >= mp->m_sb.sb_agblocks || + ino !=XFS_AGINO_TO_INO (mp, pag->pag_agno, agino)) { + error = -EINVAL ;#ifdef DEBUG /* * Don't output diagnostic information for untrusted inodes * as they can be invalid without implying corruption. */ if (flags &XFS_IGET_UNTRUSTED ) -return -EINVAL ; -if (agno >= mp->m_sb.sb_agcount) { + goto out_drop; +if (!pag) {xfs_alert (mp,"%s: agno (%d) >= mp->m_sb.sb_agcount (%d)" , - __func__, agno, mp->m_sb.sb_agcount); + __func__,XFS_INO_TO_AGNO (mp, ino), + mp->m_sb.sb_agcount); }if (agbno >= mp->m_sb.sb_agblocks) { xfs_alert(mp,
@@ -2353,15 +2349,15 @@ xfs_imap( __func__, (unsigned long long )agbno, (unsigned long)mp->m_sb.sb_agblocks); } -if (ino !=XFS_AGINO_TO_INO (mp, agno, agino)) { +if (pag && ino !=XFS_AGINO_TO_INO (mp, pag->pag_agno, agino)) {xfs_alert (mp,"%s: ino (0x%llx) != XFS_AGINO_TO_INO() (0x%llx)" , __func__, ino, -XFS_AGINO_TO_INO (mp, agno, agino)); +XFS_AGINO_TO_INO (mp, pag->pag_agno, agino)); }xfs_stack_trace ();#endif /* DEBUG */ -return -EINVAL ; + goto out_drop; }/*
@@ -2372,10 +2368,10 @@ xfs_imap(* in all cases where an untrusted inode number is passed. */ if (flags &XFS_IGET_UNTRUSTED ) { - error =xfs_imap_lookup (mp, tp, agno, agino, agbno, + error =xfs_imap_lookup (mp, tp, pag, agino, agbno, &chunk_agbno, &offset_agbno, flags);if (error) -return error; + goto out_drop; goto out_map; }
@@ -2387,11 +2383,12 @@ xfs_imap( offset =XFS_INO_TO_OFFSET (mp, ino);ASSERT (offset < mp->m_sb.sb_inopblock); - imap->im_blkno =XFS_AGB_TO_DADDR (mp, agno, agbno); + imap->im_blkno =XFS_AGB_TO_DADDR (mp, pag->pag_agno, agbno); imap->im_len =XFS_FSB_TO_BB (mp,1 ); imap->im_boffset = (unsigned short )(offset << mp->m_sb.sb_inodelog); -return 0 ; + error =0 ; + goto out_drop; }/*
@@ -2403,10 +2400,10 @@ xfs_imap( offset_agbno = agbno &M_IGEO (mp)->inoalign_mask; chunk_agbno = agbno - offset_agbno; }else { - error =xfs_imap_lookup (mp, tp, agno, agino, agbno, + error =xfs_imap_lookup (mp, tp, pag, agino, agbno, &chunk_agbno, &offset_agbno, flags);if (error) -return error; + goto out_drop; } out_map:
@@ -2417,7 +2414,7 @@ xfs_imap( offset = ((agbno - cluster_agbno) * mp->m_sb.sb_inopblock) +XFS_INO_TO_OFFSET (mp, ino); - imap->im_blkno =XFS_AGB_TO_DADDR (mp, agno, cluster_agbno); + imap->im_blkno =XFS_AGB_TO_DADDR (mp, pag->pag_agno, cluster_agbno); imap->im_len =XFS_FSB_TO_BB (mp,M_IGEO (mp)->blocks_per_cluster); imap->im_boffset = (unsigned short )(offset << mp->m_sb.sb_inodelog);
@@ -2434,9 +2431,13 @@ xfs_imap( __func__, (unsigned long long ) imap->im_blkno, (unsigned long long ) imap->im_len, XFS_FSB_TO_BB(mp, mp->m_sb.sb_dblocks)); -return -EINVAL ; + error = -EINVAL ; + goto out_drop; } -return 0 ; + error =0 ; +out_drop: +xfs_perag_put (pag); +return error; }/*
libxfs/xfs_ialloc_btree.c +11 -16
@@ -34,8 +34,7 @@ xfs_inobt_dup_cursor( struct xfs_btree_cur *cur) {return xfs_inobt_init_cursor (cur->bc_mp, cur->bc_tp, - cur->bc_ag.agbp, cur->bc_ag.agno, - cur->bc_ag.pag, cur->bc_btnum); + cur->bc_ag.agbp, cur->bc_ag.pag, cur->bc_btnum); }STATIC void
@@ -427,7 +426,6 @@ static struct xfs_btree_cur *xfs_inobt_init_common ( struct xfs_mount *mp, /* file system mount point */ struct xfs_trans *tp, /* transaction pointer */ - xfs_agnumber_t agno, /* allocation group number */ struct xfs_perag *pag, xfs_btnum_t btnum) /* ialloc or free ino btree */ {
@@ -450,12 +448,10 @@ xfs_inobt_init_common(if (xfs_sb_version_hascrc (&mp->m_sb)) cur->bc_flags |=XFS_BTREE_CRC_BLOCKS ; - cur->bc_ag.agno = agno; -if (pag) { -/* take a reference for the cursor */ -atomic_inc (&pag->pag_ref); - } +/* take a reference for the cursor */ +atomic_inc (&pag->pag_ref); cur->bc_ag.pag = pag; + cur->bc_ag.agno = pag->pag_agno;return cur; }
@@ -465,14 +461,13 @@ xfs_inobt_init_cursor(struct xfs_mount *mp, struct xfs_trans *tp, struct xfs_buf *agbp, - xfs_agnumber_t agno, struct xfs_perag *pag, xfs_btnum_t btnum) { struct xfs_btree_cur *cur;struct xfs_agi *agi = agbp->b_addr; - cur =xfs_inobt_init_common (mp, tp, agno, pag, btnum); + cur =xfs_inobt_init_common (mp, tp, pag, btnum);if (btnum ==XFS_BTNUM_INO ) cur->bc_nlevels =be32_to_cpu (agi->agi_level);else
@@ -486,12 +481,12 @@ struct xfs_btree_cur *xfs_inobt_stage_cursor ( struct xfs_mount *mp, struct xbtree_afakeroot *afake, - xfs_agnumber_t agno, + struct xfs_perag *pag, xfs_btnum_t btnum) { struct xfs_btree_cur *cur; - cur =xfs_inobt_init_common (mp,NULL , agno,NULL , btnum); + cur =xfs_inobt_init_common (mp,NULL , pag, btnum);xfs_btree_stage_afakeroot (cur, afake);return cur; }
@@ -663,7 +658,7 @@ intxfs_inobt_cur ( struct xfs_mount *mp, struct xfs_trans *tp, - xfs_agnumber_t agno, + struct xfs_perag *pag, xfs_btnum_t which, struct xfs_btree_cur **curpp, struct xfs_buf **agi_bpp)
@@ -674,11 +669,11 @@ xfs_inobt_cur(ASSERT (*agi_bpp ==NULL );ASSERT (*curpp ==NULL ); - error =xfs_ialloc_read_agi (mp, tp, agno, agi_bpp); + error =xfs_ialloc_read_agi (mp, tp, pag->pag_agno, agi_bpp);if (error)return error; - cur =xfs_inobt_init_cursor (mp, tp, *agi_bpp, agno,NULL , which); + cur =xfs_inobt_init_cursor (mp, tp, *agi_bpp, pag, which); *curpp = cur;return 0 ; }
@@ -695,7 +690,7 @@ xfs_inobt_count_blocks(struct xfs_btree_cur *cur =NULL ;int error; - error =xfs_inobt_cur (mp, tp, pag->pag_agno, btnum, &cur, &agbp); + error =xfs_inobt_cur (mp, tp, pag, btnum, &cur, &agbp);if (error)return error;
libxfs/xfs_ialloc_btree.h +3 -3
@@ -47,10 +47,10 @@ struct xfs_perag; ((index) - 1) * sizeof(xfs_inobt_ptr_t)))extern struct xfs_btree_cur *xfs_inobt_init_cursor (struct xfs_mount *mp, -struct xfs_trans *tp,struct xfs_buf *agbp,xfs_agnumber_t agno, +struct xfs_trans *tp,struct xfs_buf *agbp,struct xfs_perag *pag,xfs_btnum_t btnum);struct xfs_btree_cur *xfs_inobt_stage_cursor (struct xfs_mount *mp, -struct xbtree_afakeroot *afake,xfs_agnumber_t agno, +struct xbtree_afakeroot *afake,struct xfs_perag *pag,xfs_btnum_t btnum);extern int xfs_inobt_maxrecs (struct xfs_mount *,int ,int );
@@ -69,7 +69,7 @@ int xfs_finobt_calc_reserves(struct xfs_mount *mp, struct xfs_trans *tp,extern xfs_extlen_t xfs_iallocbt_calc_size (struct xfs_mount *mp,unsigned long long len);int xfs_inobt_cur (struct xfs_mount *mp,struct xfs_trans *tp, -xfs_agnumber_t agno,xfs_btnum_t btnum, +struct xfs_perag *pag,xfs_btnum_t btnum,struct xfs_btree_cur **curpp,struct xfs_buf **agi_bpp); void xfs_inobt_commit_staged_btree(struct xfs_btree_cur *cur,
repair/agbtree.c +4 -3
@@ -438,7 +438,7 @@ get_inobt_record( void init_ino_cursors( struct repair_ctx *sc, - xfs_agnumber_t agno, + struct xfs_perag *pag, unsigned int free_space, uint64_t *num_inos, uint64_t *num_free_inos,
@@ -446,6 +446,7 @@ init_ino_cursors( struct bt_rebuild *btr_fino) {struct ino_tree_node *ino_rec; +xfs_agnumber_t agno = pag->pag_agno;unsigned int ino_recs =0 ;unsigned int fino_recs =0 ;bool finobt;
@@ -487,7 +488,7 @@ init_ino_cursors( } btr_ino->cur =libxfs_inobt_stage_cursor (sc->mp, &btr_ino->newbt.afake, - agno,XFS_BTNUM_INO ); + pag,XFS_BTNUM_INO ); btr_ino->bload.get_record = get_inobt_record; btr_ino->bload.claim_block = rebuild_claim_block;
@@ -507,7 +508,7 @@ _("Unable to compute inode btree geometry, error %d.\n"), error);init_rebuild (sc, &XFS_RMAP_OINFO_INOBT , free_space, btr_fino); btr_fino->cur =libxfs_inobt_stage_cursor (sc->mp, - &btr_fino->newbt.afake, agno,XFS_BTNUM_FINO ); + &btr_fino->newbt.afake, pag,XFS_BTNUM_FINO ); btr_fino->bload.get_record = get_inobt_record; btr_fino->bload.claim_block = rebuild_claim_block;
repair/agbtree.h +1 -1
@@ -42,7 +42,7 @@ void init_freespace_cursors(struct repair_ctx *sc, struct xfs_perag *pag,void build_freespace_btrees (struct repair_ctx *sc,xfs_agnumber_t agno,struct bt_rebuild *btr_bno,struct bt_rebuild *btr_cnt); -void init_ino_cursors (struct repair_ctx *sc,xfs_agnumber_t agno, +void init_ino_cursors (struct repair_ctx *sc,struct xfs_perag *pag,unsigned int free_space,uint64_t *num_inos,uint64_t *num_free_inos,struct bt_rebuild *btr_ino,struct bt_rebuild *btr_fino);
repair/phase5.c +1 -1
@@ -474,7 +474,7 @@ _("unable to rebuild AG %u. Not enough free space in on-disk AG.\n"), agno); } -init_ino_cursors (&sc, agno, num_freeblocks, &sb_icount_ag[agno], +init_ino_cursors (&sc, pag, num_freeblocks, &sb_icount_ag[agno], &sb_ifree_ag[agno], &btr_ino, &btr_fino);init_rmapbt_cursor (&sc, pag, num_freeblocks, &btr_rmap);
PATCH 36/61 xfs: remove agno from btree cursor
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: 50f02fe3338d3fee6b298a1b262a4c562e7d84e0
Now that everything passes a perag, the agno is not needed anymore. Convert all the users to use pag->pag_agno instead and remove the agno from the cursor. This was largely done as an automated search and replace.
--- libxfs/xfs_alloc.c | 2 - libxfs/xfs_alloc_btree.c | 1 libxfs/xfs_btree.c | 12 ++--- libxfs/xfs_btree.h | 1 libxfs/xfs_ialloc.c | 2 - libxfs/xfs_ialloc_btree.c | 7 +-- libxfs/xfs_refcount.c | 82 ++++++++++++++++----------------- libxfs/xfs_refcount_btree.c | 11 ++-- libxfs/xfs_rmap.c | 108 ++++++++++++++++++++++--------------------- libxfs/xfs_rmap_btree.c | 1 repair/agbtree.c | 4 +- 11 files changed, 113 insertions(+), 118 deletions(-)
libxfs/xfs_alloc.c +1 -1
@@ -226,7 +226,7 @@ xfs_alloc_get_rec( int *stat) /* output: success/failure */ {struct xfs_mount *mp = cur->bc_mp; -xfs_agnumber_t agno = cur->bc_ag.agno; +xfs_agnumber_t agno = cur->bc_ag.pag->pag_agno;union xfs_btree_rec *rec;int error;
libxfs/xfs_alloc_btree.c +0 -1
@@ -495,7 +495,6 @@ xfs_allocbt_init_common(/* take a reference for the cursor */ atomic_inc (&pag->pag_ref); cur->bc_ag.pag = pag; - cur->bc_ag.agno = pag->pag_agno;if (xfs_sb_version_hascrc (&mp->m_sb)) cur->bc_flags |=XFS_BTREE_CRC_BLOCKS ;
libxfs/xfs_btree.c +6 -6
@@ -213,7 +213,7 @@ xfs_btree_check_sptr( {if (level <=0 )return false; -return xfs_verify_agbno (cur->bc_mp, cur->bc_ag.agno, agbno); +return xfs_verify_agbno (cur->bc_mp, cur->bc_ag.pag->pag_agno, agbno); }/*
@@ -242,7 +242,7 @@ xfs_btree_check_ptr(return 0 ;xfs_err (cur->bc_mp,"AG %u: Corrupt btree %d pointer at level %d index %d." , - cur->bc_ag.agno, cur->bc_btnum, + cur->bc_ag.pag->pag_agno, cur->bc_btnum, level, index); }
@@ -885,13 +885,13 @@ xfs_btree_readahead_sblock(if ((lr &XFS_BTCUR_LEFTRA ) && left !=NULLAGBLOCK ) { -xfs_btree_reada_bufs (cur->bc_mp, cur->bc_ag.agno, +xfs_btree_reada_bufs (cur->bc_mp, cur->bc_ag.pag->pag_agno, left,1 , cur->bc_ops->buf_ops); rval++; }if ((lr &XFS_BTCUR_RIGHTRA ) && right !=NULLAGBLOCK ) { -xfs_btree_reada_bufs (cur->bc_mp, cur->bc_ag.agno, +xfs_btree_reada_bufs (cur->bc_mp, cur->bc_ag.pag->pag_agno, right,1 , cur->bc_ops->buf_ops); rval++; }
@@ -949,7 +949,7 @@ xfs_btree_ptr_to_daddr( *daddr =XFS_FSB_TO_DADDR (cur->bc_mp, fsbno); }else { agbno =be32_to_cpu (ptr->s); - *daddr =XFS_AGB_TO_DADDR (cur->bc_mp, cur->bc_ag.agno, + *daddr =XFS_AGB_TO_DADDR (cur->bc_mp, cur->bc_ag.pag->pag_agno, agbno); }
@@ -1150,7 +1150,7 @@ xfs_btree_init_block_cur(if (cur->bc_flags &XFS_BTREE_LONG_PTRS ) owner = cur->bc_ino.ip->i_ino;else - owner = cur->bc_ag.agno; + owner = cur->bc_ag.pag->pag_agno; xfs_btree_init_block_int(cur->bc_mp, XFS_BUF_TO_BLOCK(bp), bp->b_bn, cur->bc_btnum, level, numrecs,
libxfs/xfs_btree.h +0 -1
@@ -181,7 +181,6 @@ union xfs_btree_irec {/* Per-AG btree information. */ struct xfs_btree_cur_ag { -xfs_agnumber_t agno;struct xfs_perag *pag;union {struct xfs_buf *agbp;
libxfs/xfs_ialloc.c +1 -1
@@ -100,7 +100,7 @@ xfs_inobt_get_rec( int *stat) {struct xfs_mount *mp = cur->bc_mp; -xfs_agnumber_t agno = cur->bc_ag.agno; +xfs_agnumber_t agno = cur->bc_ag.pag->pag_agno;union xfs_btree_rec *rec;int error;uint64_t realfree;
libxfs/xfs_ialloc_btree.c +3 -4
@@ -101,7 +101,7 @@ __xfs_inobt_alloc_block( args.tp = cur->bc_tp; args.mp = cur->bc_mp; args.oinfo =XFS_RMAP_OINFO_INOBT ; - args.fsbno =XFS_AGB_TO_FSB (args.mp, cur->bc_ag.agno, sbno); + args.fsbno =XFS_AGB_TO_FSB (args.mp, cur->bc_ag.pag->pag_agno, sbno); args.minlen =1 ; args.maxlen =1 ; args.prod =1 ;
@@ -234,7 +234,7 @@ xfs_inobt_init_ptr_from_cur( {struct xfs_agi *agi = cur->bc_ag.agbp->b_addr; -ASSERT (cur->bc_ag.agno ==be32_to_cpu (agi->agi_seqno)); +ASSERT (cur->bc_ag.pag->pag_agno ==be32_to_cpu (agi->agi_seqno)); ptr->s = agi->agi_root; }
@@ -246,7 +246,7 @@ xfs_finobt_init_ptr_from_cur( {struct xfs_agi *agi = cur->bc_ag.agbp->b_addr; -ASSERT (cur->bc_ag.agno ==be32_to_cpu (agi->agi_seqno)); +ASSERT (cur->bc_ag.pag->pag_agno ==be32_to_cpu (agi->agi_seqno)); ptr->s = agi->agi_free_root; }
@@ -451,7 +451,6 @@ xfs_inobt_init_common(/* take a reference for the cursor */ atomic_inc (&pag->pag_ref); cur->bc_ag.pag = pag; - cur->bc_ag.agno = pag->pag_agno;return cur; }
libxfs/xfs_refcount.c +41 -41
320 lines not on this page · raw message
libxfs/xfs_refcount_btree.c +5 -6
@@ -64,7 +64,7 @@ xfs_refcountbt_alloc_block( args.tp = cur->bc_tp; args.mp = cur->bc_mp; args.type =XFS_ALLOCTYPE_NEAR_BNO ; - args.fsbno =XFS_AGB_TO_FSB (cur->bc_mp, cur->bc_ag.agno, + args.fsbno =XFS_AGB_TO_FSB (cur->bc_mp, cur->bc_ag.pag->pag_agno,xfs_refc_block (args.mp)); args.oinfo =XFS_RMAP_OINFO_REFC ; args.minlen = args.maxlen = args.prod =1 ;
@@ -73,13 +73,13 @@ xfs_refcountbt_alloc_block( error =xfs_alloc_vextent (&args);if (error) goto out_error; -trace_xfs_refcountbt_alloc_block (cur->bc_mp, cur->bc_ag.agno, +trace_xfs_refcountbt_alloc_block (cur->bc_mp, cur->bc_ag.pag->pag_agno, args.agbno,1 );if (args.fsbno ==NULLFSBLOCK ) { *stat =0 ;return 0 ; } -ASSERT (args.agno == cur->bc_ag.agno); +ASSERT (args.agno == cur->bc_ag.pag->pag_agno);ASSERT (args.len ==1 ); new->s =cpu_to_be32 (args.agbno);
@@ -104,7 +104,7 @@ xfs_refcountbt_free_block(xfs_fsblock_t fsbno =XFS_DADDR_TO_FSB (mp,XFS_BUF_ADDR (bp));int error; -trace_xfs_refcountbt_free_block (cur->bc_mp, cur->bc_ag.agno, +trace_xfs_refcountbt_free_block (cur->bc_mp, cur->bc_ag.pag->pag_agno,XFS_FSB_TO_AGBNO (cur->bc_mp, fsbno),1 );be32_add_cpu (&agf->agf_refcount_blocks,-1 );xfs_alloc_log_agf (cur->bc_tp, agbp,XFS_AGF_REFCOUNT_BLOCKS );
@@ -169,7 +169,7 @@ xfs_refcountbt_init_ptr_from_cur( {struct xfs_agf *agf = cur->bc_ag.agbp->b_addr; -ASSERT (cur->bc_ag.agno ==be32_to_cpu (agf->agf_seqno)); +ASSERT (cur->bc_ag.pag->pag_agno ==be32_to_cpu (agf->agf_seqno)); ptr->s = agf->agf_refcount_root; }
@@ -333,7 +333,6 @@ xfs_refcountbt_init_common(/* take a reference for the cursor */ atomic_inc (&pag->pag_ref); cur->bc_ag.pag = pag; - cur->bc_ag.agno = pag->pag_agno; cur->bc_ag.refc.nr_ops =0 ; cur->bc_ag.refc.shape_changes =0 ;
libxfs/xfs_rmap.c +54 -54
418 lines not on this page · raw message
libxfs/xfs_rmap_btree.c +0 -1
@@ -462,7 +462,6 @@ xfs_rmapbt_init_common(/* take a reference for the cursor */ atomic_inc (&pag->pag_ref); cur->bc_ag.pag = pag; - cur->bc_ag.agno = pag->pag_agno;return cur; }
repair/agbtree.c +2 -2
@@ -193,7 +193,7 @@ get_bno_rec(struct xfs_btree_cur *cur, struct extent_tree_node *prev_value) { - xfs_agnumber_t agno = cur->bc_ag.agno; + xfs_agnumber_t agno = cur->bc_ag.pag->pag_agno;if (cur->bc_btnum ==XFS_BTNUM_BNO ) {if (!prev_value)
@@ -355,7 +355,7 @@ get_ino_rec(struct xfs_btree_cur *cur, struct ino_tree_node *prev_value) { - xfs_agnumber_t agno = cur->bc_ag.agno; + xfs_agnumber_t agno = cur->bc_ag.pag->pag_agno;if (cur->bc_btnum ==XFS_BTNUM_INO ) {if (!prev_value)
PATCH 37/61 xfs: simplify xfs_dialloc_select_ag() return values
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: 4268547305c91b35ae7871374078de788a822ed1
The only caller of xfs_dialloc_select_ag() will always return -ENOSPC to it's caller if the agbp returned from xfs_dialloc_select_ag() is NULL. IOWs, failure to find a candidate AGI we can allocate inodes from is always an ENOSPC condition, so move this logic up into xfs_dialloc_select_ag() so we can simplify the return logic in this function.
xfs_dialloc_select_ag() now only ever returns 0 with a locked agbp, or an error with no agbp.
--- libxfs/xfs_ialloc.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-)
libxfs/xfs_ialloc.c +8 -15
@@ -1712,7 +1712,7 @@ xfs_dialloc_roll(* This function will ensure that the selected AG has free inodes available to * allocate from. The selected AGI will be returned locked to the caller, and it * will allocate more free inodes if required. If no free inodes are found or -* can be allocated, no AGI will be returned. +* can be allocated, -ENOSPC be returned. */ int xfs_dialloc_select_ag(
@@ -1725,7 +1725,6 @@ xfs_dialloc_select_ag(struct xfs_buf *agbp;xfs_agnumber_t agno;int error; -bool noroom = false;xfs_agnumber_t start_agno;struct xfs_perag *pag;struct xfs_ino_geometry *igeo =M_IGEO (mp);
@@ -1739,7 +1738,7 @@ xfs_dialloc_select_ag(*/ start_agno =xfs_ialloc_ag_select (*tpp, parent, mode);if (start_agno ==NULLAGNUMBER ) -return 0 ; +return -ENOSPC ;/* * If we have already hit the ceiling of inode blocks then clear
@@ -1752,7 +1751,6 @@ xfs_dialloc_select_ag(if (igeo->maxicount &&percpu_counter_read_positive (&mp->m_icount) + igeo->ialloc_inos > igeo->maxicount) { - noroom = true; okalloc = false; }
@@ -1789,10 +1787,8 @@ xfs_dialloc_select_ag(if (error)break ; -if (pag->pagi_freecount) { -xfs_perag_put (pag); +if (pag->pagi_freecount) goto found_ag; - }if (!okalloc) goto nextag_relse_buffer;
@@ -1800,9 +1796,6 @@ xfs_dialloc_select_ag( error =xfs_ialloc_ag_alloc (*tpp, agbp, pag);if (error <0 ) {xfs_trans_brelse (*tpp, agbp); - -if (error == -ENOSPC ) - error =0 ;break ; }
@@ -1813,12 +1806,11 @@ xfs_dialloc_select_ag(* allocate one of the new inodes. */ ASSERT (pag->pagi_freecount >0 ); -xfs_perag_put (pag); error =xfs_dialloc_roll (tpp, agbp);if (error) {xfs_buf_relse (agbp); -return error; +break ; } goto found_ag; }
@@ -1826,16 +1818,17 @@ xfs_dialloc_select_ag( nextag_relse_buffer:xfs_trans_brelse (*tpp, agbp); nextag: -xfs_perag_put (pag);if (++agno == mp->m_sb.sb_agcount) agno =0 ;if (agno == start_agno) -return noroom ? -ENOSPC :0 ; +break ; +xfs_perag_put (pag); }xfs_perag_put (pag); -return error; +return error ? error : -ENOSPC ; found_ag: +xfs_perag_put (pag); *IO_agbp = agbp;return 0 ; }
PATCH 38/61 xfs: collapse AG selection for inode allocation
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: 89b1f55a2951bb89b7ae9f8cb3fd11513ff3f219
xfs_dialloc_select_ag() does a lot of repetitive work. It first calls xfs_ialloc_ag_select() to select the AG to start allocation attempts in, which can do up to two entire loops across the perags that inodes can be allocated in. This is simply checking if there is spce available to allocate inodes in an AG, and it returns when it finds the first candidate AG.
xfs_dialloc_select_ag() then does it's own iterative walk across all the perags locking the AGIs and trying to allocate inodes from the locked AG. It also doesn't limit the search to mp->m_maxagi, so it will walk all AGs whether they can allocate inodes or not.
Hence if we are really low on inodes, we could do almost 3 entire walks across the whole perag range before we find an allocation group we can allocate inodes in or report ENOSPC.
Because xfs_ialloc_ag_select() returns on the first candidate AG it finds, we can simply do these checks directly in xfs_dialloc_select_ag() before we lock and try to allocate inodes. This reduces the inode allocation pass down to 2 perag sweeps at most - one for aligned inode cluster allocation and if we can't allocate full, aligned inode clusters anywhere we'll do another pass trying to do sparse inode cluster allocation.
This also removes a big chunk of duplicate code.
--- libxfs/xfs_ialloc.c | 225 ++++++++++++++++++--------------------------------- 1 file changed, 78 insertions(+), 147 deletions(-)
libxfs/xfs_ialloc.c +78 -147
@@ -894,139 +894,6 @@ xfs_ialloc_ag_alloc(return 0 ; } -STATIC xfs_agnumber_t -xfs_ialloc_next_ag ( -xfs_mount_t *mp) -{ -xfs_agnumber_t agno; - -spin_lock (&mp->m_agirotor_lock); - agno = mp->m_agirotor; -if (++mp->m_agirotor >= mp->m_maxagi) - mp->m_agirotor =0 ; -spin_unlock (&mp->m_agirotor_lock); - -return agno; -} - -/* -* Select an allocation group to look for a free inode in, based on the parent -* inode and the mode. Return the allocation group buffer. -*/ -STATIC xfs_agnumber_t -xfs_ialloc_ag_select ( -xfs_trans_t *tp,/* transaction pointer */ -xfs_ino_t parent,/* parent directory inode number */ -umode_t mode)/* bits set to indicate file type */ -{ -xfs_agnumber_t agcount;/* number of ag's in the filesystem */ -xfs_agnumber_t agno;/* current ag number */ -int flags;/* alloc buffer locking flags */ -xfs_extlen_t ineed;/* blocks needed for inode allocation */ -xfs_extlen_t longest =0 ;/* longest extent available */ -xfs_mount_t *mp;/* mount point structure */ -int needspace;/* file mode implies space allocated */ -xfs_perag_t *pag;/* per allocation group data */ -xfs_agnumber_t pagno;/* parent (starting) ag number */ -int error; - -/* -* Files of these types need at least one block if length > 0 -* (and they won't fit in the inode, but that's hard to figure out). -*/ - needspace =S_ISDIR (mode) ||S_ISREG (mode) ||S_ISLNK (mode); - mp = tp->t_mountp; - agcount = mp->m_maxagi; -if (S_ISDIR (mode)) - pagno =xfs_ialloc_next_ag (mp); -else { - pagno =XFS_INO_TO_AGNO (mp, parent); -if (pagno >= agcount) - pagno =0 ; - } - -ASSERT (pagno < agcount); - -/* -* Loop through allocation groups, looking for one with a little -* free space in it. Note we don't look for free inodes, exactly. -* Instead, we include whether there is a need to allocate inodes -* to mean that blocks must be allocated for them, -* if none are currently free. -*/ - agno = pagno; - flags =XFS_ALLOC_FLAG_TRYLOCK ; -for (;;) { - pag =xfs_perag_get (mp, agno); -if (!pag->pagi_inodeok) { -xfs_ialloc_next_ag (mp); - goto nextag; - } - -if (!pag->pagi_init) { - error =xfs_ialloc_pagi_init (mp, tp, agno); -if (error) - goto nextag; - } - -if (pag->pagi_freecount) { -xfs_perag_put (pag); -return agno; - } - -if (!pag->pagf_init) { - error =xfs_alloc_pagf_init (mp, tp, agno, flags); -if (error) - goto nextag; - } - -/* -* Check that there is enough free space for the file plus a -* chunk of inodes if we need to allocate some. If this is the -* first pass across the AGs, take into account the potential -* space needed for alignment of inode chunks when checking the -* longest contiguous free space in the AG - this prevents us -* from getting ENOSPC because we have free space larger than -* ialloc_blks but alignment constraints prevent us from using -* it. -* -* If we can't find an AG with space for full alignment slack to -* be taken into account, we must be near ENOSPC in all AGs. -* Hence we don't include alignment for the second pass and so -* if we fail allocation due to alignment issues then it is most -* likely a real ENOSPC condition. -*/ - ineed =M_IGEO (mp)->ialloc_min_blks; -if (flags && ineed >1 ) - ineed +=M_IGEO (mp)->cluster_align; - longest = pag->pagf_longest; -if (!longest) - longest = pag->pagf_flcount >0 ; - -if (pag->pagf_freeblks >= needspace + ineed && - longest >= ineed) { -xfs_perag_put (pag); -return agno; - } -nextag: -xfs_perag_put (pag); -/* -* No point in iterating over the rest, if we're shutting -* down. -*/ -if (XFS_FORCED_SHUTDOWN (mp)) -return NULLAGNUMBER ; - agno++; -if (agno >= agcount) - agno =0 ; -if (agno == pagno) { -if (flags ==0 ) -return NULLAGNUMBER ; - flags =0 ; - } - } -} -/* * Try to retrieve the next record to the left/right from the current one. */
@@ -1703,6 +1570,21 @@ xfs_dialloc_roll(return 0 ; } +STATIC xfs_agnumber_t +xfs_ialloc_next_ag ( +xfs_mount_t *mp) +{ +xfs_agnumber_t agno; + +spin_lock (&mp->m_agirotor_lock); + agno = mp->m_agirotor; +if (++mp->m_agirotor >= mp->m_maxagi) + mp->m_agirotor =0 ; +spin_unlock (&mp->m_agirotor_lock); + +return agno; +} +/* * Select and prepare an AG for inode allocation. *
@@ -1729,16 +1611,24 @@ xfs_dialloc_select_ag(struct xfs_perag *pag;struct xfs_ino_geometry *igeo =M_IGEO (mp);bool okalloc = true; +int needspace; +int flags; *IO_agbp =NULL ;/* -* We do not have an agbp, so select an initial allocation -* group for inode allocation. +* Directories, symlinks, and regular files frequently allocate at least +* one block, so factor that potential expansion when we examine whether +* an AG has enough space for file creation. */ - start_agno =xfs_ialloc_ag_select (*tpp, parent, mode); -if (start_agno ==NULLAGNUMBER ) -return -ENOSPC ; + needspace =S_ISDIR (mode) ||S_ISREG (mode) ||S_ISLNK (mode); +if (S_ISDIR (mode)) + start_agno =xfs_ialloc_next_ag (mp); +else { + start_agno =XFS_INO_TO_AGNO (mp, parent); +if (start_agno >= mp->m_maxagi) + start_agno =0 ; + }/* * If we have already hit the ceiling of inode blocks then clear
@@ -1760,12 +1650,14 @@ xfs_dialloc_select_ag(* allocation groups upward, wrapping at the end. */ agno = start_agno; + flags =XFS_ALLOC_FLAG_TRYLOCK ;for (;;) { +xfs_extlen_t ineed; +xfs_extlen_t longest =0 ; + pag =xfs_perag_get (mp, agno); -if (!pag->pagi_inodeok) { -xfs_ialloc_next_ag (mp); +if (!pag->pagi_inodeok) goto nextag; - }if (!pag->pagi_init) { error =xfs_ialloc_pagi_init (mp, *tpp, agno);
@@ -1773,12 +1665,44 @@ xfs_dialloc_select_ag(break ; } -/* -* Do a first racy fast path check if this AG is usable. -*/ if (!pag->pagi_freecount && !okalloc) goto nextag; +if (!pag->pagf_init) { + error =xfs_alloc_pagf_init (mp, *tpp, agno, flags); +if (error) + goto nextag; + } + +/* +* Check that there is enough free space for the file plus a +* chunk of inodes if we need to allocate some. If this is the +* first pass across the AGs, take into account the potential +* space needed for alignment of inode chunks when checking the +* longest contiguous free space in the AG - this prevents us +* from getting ENOSPC because we have free space larger than +* ialloc_blks but alignment constraints prevent us from using +* it. +* +* If we can't find an AG with space for full alignment slack to +* be taken into account, we must be near ENOSPC in all AGs. +* Hence we don't include alignment for the second pass and so +* if we fail allocation due to alignment issues then it is most +* likely a real ENOSPC condition. +*/ +if (!pag->pagi_freecount) { + ineed =M_IGEO (mp)->ialloc_min_blks; +if (flags && ineed >1 ) + ineed +=M_IGEO (mp)->cluster_align; + longest = pag->pagf_longest; +if (!longest) + longest = pag->pagf_flcount >0 ; + +if (pag->pagf_freeblks < needspace + ineed || + longest < ineed) + goto nextag; + } +/* * Then read in the AGI buffer and recheck with the AGI buffer * lock held.
@@ -1818,10 +1742,17 @@ xfs_dialloc_select_ag( nextag_relse_buffer:xfs_trans_brelse (*tpp, agbp); nextag: -if (++agno == mp->m_sb.sb_agcount) - agno =0 ; -if (agno == start_agno) +if (XFS_FORCED_SHUTDOWN (mp)) { + error = -EFSCORRUPTED ;break ; + } +if (++agno == mp->m_maxagi) + agno =0 ; +if (agno == start_agno) { +if (!flags) +break ; + flags =0 ; + }xfs_perag_put (pag); }
PATCH 39/61 xfs: get rid of xfs_dir_ialloc()
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: b652afd937033911944d7f681f2031b006961f1d
This is just a simple wrapper around the per-ag inode allocation that doesn't need to exist. The internal mechanism to select and allocate within an AG does not need to be exposed outside xfs_ialloc.c, and it being exposed simply makes it harder to follow the code and simplify it.
This is simplified by internalising xf_dialloc_select_ag() and xfs_dialloc_ag() into a single xfs_dialloc() function and then xfs_dir_ialloc() can go away.
--- libxfs/util.c | 12 +----------- libxfs/xfs_ialloc.c | 17 ++++++++++------- libxfs/xfs_ialloc.h | 27 ++++----------------------- 3 files changed, 15 insertions(+), 41 deletions(-)
libxfs/util.c +1 -11
@@ -514,7 +514,6 @@ libxfs_dir_ialloc(struct fsxattr *fsx, struct xfs_inode **ipp) { - struct xfs_buf *agibp; xfs_ino_t parent_ino = dp ? dp->i_ino : 0;xfs_ino_t ino;int error;
@@ -523,19 +522,10 @@ libxfs_dir_ialloc(* Call the space management code to pick the on-disk inode to be * allocated. */ - error =xfs_dialloc_select_ag (tpp, parent_ino, mode, &agibp); + error =xfs_dialloc (tpp, parent_ino, mode, &ino);if (error)return error; -if (!agibp) -return -ENOSPC ; - -/* Allocate an inode from the selected AG */ - error =xfs_dialloc_ag (*tpp, agibp, parent_ino, &ino); -if (error) -return error; -ASSERT (ino !=NULLFSINO ); -return libxfs_init_new_inode (*tpp, dp, ino, mode, nlink, rdev, cr, fsx, ipp); }
libxfs/xfs_ialloc.c +10 -7
@@ -1423,7 +1423,7 @@ xfs_dialloc_ag_update_inobt(* The caller selected an AG for us, and made sure that free inodes are * available. */ -int +static int xfs_dialloc_ag( struct xfs_trans *tp, struct xfs_buf *agbp,
@@ -1597,24 +1597,23 @@ xfs_ialloc_next_ag(* can be allocated, -ENOSPC be returned. */ int -xfs_dialloc_select_ag ( +xfs_dialloc (struct xfs_trans **tpp,xfs_ino_t parent,umode_t mode, -struct xfs_buf **IO_agbp) +xfs_ino_t *new_ino) {struct xfs_mount *mp = (*tpp)->t_mountp;struct xfs_buf *agbp;xfs_agnumber_t agno; -int error; +int error =0 ;xfs_agnumber_t start_agno;struct xfs_perag *pag;struct xfs_ino_geometry *igeo =M_IGEO (mp);bool okalloc = true;int needspace;int flags; - - *IO_agbp =NULL ; +xfs_ino_t ino;/* * Directories, symlinks, and regular files frequently allocate at least
@@ -1760,7 +1759,11 @@ xfs_dialloc_select_ag(return error ? error : -ENOSPC ; found_ag:xfs_perag_put (pag); - *IO_agbp = agbp; +/* Allocate an inode in the found AG */ + error =xfs_dialloc_ag (*tpp, agbp, parent, &ino); +if (error) +return error; + *new_ino = ino;return 0 ; }
libxfs/xfs_ialloc.h +4 -23
@@ -33,30 +33,11 @@ xfs_make_iptr(struct xfs_mount *mp, struct xfs_buf *b, int o) }/* -* Allocate an inode on disk. -* Mode is used to tell whether the new inode will need space, and whether -* it is a directory. -* -* There are two phases to inode allocation: selecting an AG and ensuring -* that it contains free inodes, followed by allocating one of the free -* inodes. xfs_dialloc_select_ag() does the former and returns a locked AGI -* to the caller, ensuring that followup call to xfs_dialloc_ag() will -* have free inodes to allocate from. xfs_dialloc_ag() will return the inode -* number of the free inode we allocated. +* Allocate an inode on disk. Mode is used to tell whether the new inode will +* need space, and whether it is a directory. */ -int /* error */ -xfs_dialloc_select_ag ( -struct xfs_trans **tpp,/* double pointer of transaction */ -xfs_ino_t parent,/* parent inode (directory) */ -umode_t mode,/* mode bits for new inode */ -struct xfs_buf **IO_agbp); - -int -xfs_dialloc_ag ( -struct xfs_trans *tp, -struct xfs_buf *agbp, -xfs_ino_t parent, -xfs_ino_t *inop); +int xfs_dialloc (struct xfs_trans **tpp,xfs_ino_t parent,umode_t mode, +xfs_ino_t *new_ino);/* * Free disk inode. Carefully avoids touching the incore inode, all
PATCH 40/61 xfs: inode allocation can use a single perag instance
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: 309161f6603ce1a53b76a42817cde2a9bcd17e82
Now that we've internalised the two-phase inode allocation, we can now easily make the AG selection and allocation atomic from the perspective of a single perag context. This will ensure AGs going offline/away cannot occur between the selection and allocation steps.
--- libxfs/xfs_ialloc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
libxfs/xfs_ialloc.c +3 -3
@@ -1427,6 +1427,7 @@ static intxfs_dialloc_ag ( struct xfs_trans *tp, struct xfs_buf *agbp, + struct xfs_perag *pag, xfs_ino_t parent, xfs_ino_t *inop) {
@@ -1441,7 +1442,6 @@ xfs_dialloc_ag(int error;int offset;int i; -struct xfs_perag *pag = agbp->b_pag;if (!xfs_sb_version_hasfinobt (&mp->m_sb))return xfs_dialloc_ag_inobt (tp, agbp, pag, parent, inop);
@@ -1758,9 +1758,9 @@ xfs_dialloc(xfs_perag_put (pag);return error ? error : -ENOSPC ; found_ag: -xfs_perag_put (pag);/* Allocate an inode in the found AG */ - error =xfs_dialloc_ag (*tpp, agbp, parent, &ino); + error =xfs_dialloc_ag (*tpp, agbp, pag, parent, &ino); +xfs_perag_put (pag);if (error)return error; *new_ino = ino;
PATCH 41/61 xfs: clean up and simplify xfs_dialloc()
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: 8237fbf53d6fd2a3a248fc2a8608e047ef22316c
Because it's a mess.
--- libxfs/xfs_ialloc.c | 271 +++++++++++++++++++++++++++++---------------------- 1 file changed, 153 insertions(+), 118 deletions(-)
libxfs/xfs_ialloc.c +153 -118
@@ -599,9 +599,10 @@ xfs_inobt_insert_sprec( }/* -* Allocate new inodes in the allocation group specified by agbp. -* Returns 0 if inodes were allocated in this AG; 1 if there was no space -* in this AG; or the usual negative error code. +* Allocate new inodes in the allocation group specified by agbp. Returns 0 if +* inodes were allocated in this AG; -EAGAIN if there was no space in this AG so +* the caller knows it can try another AG, a hard -ENOSPC when over the maximum +* inode count threshold, or the usual negative error code for other errors. */ STATIC int xfs_ialloc_ag_alloc(
@@ -787,7 +788,7 @@ xfs_ialloc_ag_alloc( }if (args.fsbno ==NULLFSBLOCK ) -return 1 ; +return -EAGAIN ;ASSERT (args.len == args.minlen);
@@ -1563,14 +1564,17 @@ xfs_dialloc_roll(/* Re-attach the quota info that we detached from prev trx. */ tp->t_dqinfo = dqinfo; - *tpp = tp; -if (error) -return error; +/* +* Join the buffer even on commit error so that the buffer is released +* when the caller cancels the transaction and doesn't have to handle +* this error case specially. +*/ xfs_trans_bjoin (tp, agibp); -return 0 ; + *tpp = tp; +return error; } -STATIC xfs_agnumber_t +static xfs_agnumber_t xfs_ialloc_next_ag (xfs_mount_t *mp) {
@@ -1585,16 +1589,136 @@ xfs_ialloc_next_ag(return agno; } +static bool +xfs_dialloc_good_ag ( +struct xfs_trans *tp, +struct xfs_perag *pag, +umode_t mode, +int flags, +bool ok_alloc) +{ +struct xfs_mount *mp = tp->t_mountp; +xfs_extlen_t ineed; +xfs_extlen_t longest =0 ; +int needspace; +int error; + +if (!pag->pagi_inodeok) +return false; + +if (!pag->pagi_init) { + error =xfs_ialloc_pagi_init (mp, tp, pag->pag_agno); +if (error) +return false; + } + +if (pag->pagi_freecount) +return true; +if (!ok_alloc) +return false; + +if (!pag->pagf_init) { + error =xfs_alloc_pagf_init (mp, tp, pag->pag_agno, flags); +if (error) +return false; + } + +/* +* Check that there is enough free space for the file plus a chunk of +* inodes if we need to allocate some. If this is the first pass across +* the AGs, take into account the potential space needed for alignment +* of inode chunks when checking the longest contiguous free space in +* the AG - this prevents us from getting ENOSPC because we have free +* space larger than ialloc_blks but alignment constraints prevent us +* from using it. +* +* If we can't find an AG with space for full alignment slack to be +* taken into account, we must be near ENOSPC in all AGs. Hence we +* don't include alignment for the second pass and so if we fail +* allocation due to alignment issues then it is most likely a real +* ENOSPC condition. +* +* XXX(dgc): this calculation is now bogus thanks to the per-ag +* reservations that xfs_alloc_fix_freelist() now does via +* xfs_alloc_space_available(). When the AG fills up, pagf_freeblks will +* be more than large enough for the check below to succeed, but +* xfs_alloc_space_available() will fail because of the non-zero +* metadata reservation and hence we won't actually be able to allocate +* more inodes in this AG. We do soooo much unnecessary work near ENOSPC +* because of this. +*/ + ineed =M_IGEO (mp)->ialloc_min_blks; +if (flags && ineed >1 ) + ineed +=M_IGEO (mp)->cluster_align; + longest = pag->pagf_longest; +if (!longest) + longest = pag->pagf_flcount >0 ; + needspace =S_ISDIR (mode) ||S_ISREG (mode) ||S_ISLNK (mode); + +if (pag->pagf_freeblks < needspace + ineed || longest < ineed) +return false; +return true; +} + +static int +xfs_dialloc_try_ag ( +struct xfs_trans **tpp, +struct xfs_perag *pag, +xfs_ino_t parent, +xfs_ino_t *new_ino, +bool ok_alloc) +{ +struct xfs_buf *agbp; +xfs_ino_t ino; +int error; + +/* +* Then read in the AGI buffer and recheck with the AGI buffer +* lock held. +*/ + error =xfs_ialloc_read_agi (pag->pag_mount, *tpp, pag->pag_agno, &agbp); +if (error) +return error; + +if (!pag->pagi_freecount) { +if (!ok_alloc) { + error = -EAGAIN ; + goto out_release; + } + + error =xfs_ialloc_ag_alloc (*tpp, agbp, pag); +if (error <0 ) + goto out_release; + +/* +* We successfully allocated space for an inode cluster in this +* AG. Roll the transaction so that we can allocate one of the +* new inodes. +*/ +ASSERT (pag->pagi_freecount >0 ); + error =xfs_dialloc_roll (tpp, agbp); +if (error) + goto out_release; + } + +/* Allocate an inode in the found AG */ + error =xfs_dialloc_ag (*tpp, agbp, pag, parent, &ino); +if (!error) + *new_ino = ino; +return error; + +out_release: +xfs_trans_brelse (*tpp, agbp); +return error; +} +/* -* Select and prepare an AG for inode allocation. +* Allocate an on-disk inode. * * Mode is used to tell whether the new inode is a directory and hence where to -* locate it. -* -* This function will ensure that the selected AG has free inodes available to -* allocate from. The selected AGI will be returned locked to the caller, and it -* will allocate more free inodes if required. If no free inodes are found or -* can be allocated, -ENOSPC be returned. +* locate it. The on-disk inode that is allocated will be returned in @new_ino +* on success, otherwise an error will be set to indicate the failure (e.g. +* -ENOSPC). */ int xfs_dialloc(
@@ -1604,14 +1728,12 @@ xfs_dialloc( xfs_ino_t *new_ino) {struct xfs_mount *mp = (*tpp)->t_mountp; -struct xfs_buf *agbp;xfs_agnumber_t agno;int error =0 ;xfs_agnumber_t start_agno;struct xfs_perag *pag;struct xfs_ino_geometry *igeo =M_IGEO (mp); -bool okalloc = true; -int needspace; +bool ok_alloc = true;int flags;xfs_ino_t ino;
@@ -1620,7 +1742,6 @@ xfs_dialloc(* one block, so factor that potential expansion when we examine whether * an AG has enough space for file creation. */ - needspace =S_ISDIR (mode) ||S_ISREG (mode) ||S_ISLNK (mode);if (S_ISDIR (mode)) start_agno =xfs_ialloc_next_ag (mp);else {
@@ -1631,7 +1752,7 @@ xfs_dialloc(/* * If we have already hit the ceiling of inode blocks then clear -* okalloc so we scan all available agi structures for a free +* ok_alloc so we scan all available agi structures for a free * inode. * * Read rough value of mp->m_icount by percpu_counter_read_positive,
@@ -1640,7 +1761,7 @@ xfs_dialloc(if (igeo->maxicount &&percpu_counter_read_positive (&mp->m_icount) + igeo->ialloc_inos > igeo->maxicount) { - okalloc = false; + ok_alloc = false; }/*
@@ -1651,96 +1772,14 @@ xfs_dialloc( agno = start_agno; flags =XFS_ALLOC_FLAG_TRYLOCK ;for (;;) { -xfs_extlen_t ineed; -xfs_extlen_t longest =0 ; - pag =xfs_perag_get (mp, agno); -if (!pag->pagi_inodeok) - goto nextag; - -if (!pag->pagi_init) { - error =xfs_ialloc_pagi_init (mp, *tpp, agno); -if (error) -break ; - } - -if (!pag->pagi_freecount && !okalloc) - goto nextag; - -if (!pag->pagf_init) { - error =xfs_alloc_pagf_init (mp, *tpp, agno, flags); -if (error) - goto nextag; - } - -/* -* Check that there is enough free space for the file plus a -* chunk of inodes if we need to allocate some. If this is the -* first pass across the AGs, take into account the potential -* space needed for alignment of inode chunks when checking the -* longest contiguous free space in the AG - this prevents us -* from getting ENOSPC because we have free space larger than -* ialloc_blks but alignment constraints prevent us from using -* it. -* -* If we can't find an AG with space for full alignment slack to -* be taken into account, we must be near ENOSPC in all AGs. -* Hence we don't include alignment for the second pass and so -* if we fail allocation due to alignment issues then it is most -* likely a real ENOSPC condition. -*/ -if (!pag->pagi_freecount) { - ineed =M_IGEO (mp)->ialloc_min_blks; -if (flags && ineed >1 ) - ineed +=M_IGEO (mp)->cluster_align; - longest = pag->pagf_longest; -if (!longest) - longest = pag->pagf_flcount >0 ; - -if (pag->pagf_freeblks < needspace + ineed || - longest < ineed) - goto nextag; - } - -/* -* Then read in the AGI buffer and recheck with the AGI buffer -* lock held. -*/ - error =xfs_ialloc_read_agi (mp, *tpp, agno, &agbp); -if (error) -break ; - -if (pag->pagi_freecount) - goto found_ag; - -if (!okalloc) - goto nextag_relse_buffer; - - error =xfs_ialloc_ag_alloc (*tpp, agbp, pag); -if (error <0 ) { -xfs_trans_brelse (*tpp, agbp); -break ; - } - -if (error ==0 ) { -/* -* We successfully allocated space for an inode cluster -* in this AG. Roll the transaction so that we can -* allocate one of the new inodes. -*/ -ASSERT (pag->pagi_freecount >0 ); - - error =xfs_dialloc_roll (tpp, agbp); -if (error) { -xfs_buf_relse (agbp); +if (xfs_dialloc_good_ag (*tpp, pag, mode, flags, ok_alloc)) { + error =xfs_dialloc_try_ag (tpp, pag, parent, + &ino, ok_alloc); +if (error != -EAGAIN )break ; - } - goto found_ag; } -nextag_relse_buffer: -xfs_trans_brelse (*tpp, agbp); -nextag:if (XFS_FORCED_SHUTDOWN (mp)) { error = -EFSCORRUPTED ;break ;
@@ -1748,23 +1787,19 @@ xfs_dialloc(if (++agno == mp->m_maxagi) agno =0 ;if (agno == start_agno) { -if (!flags) +if (!flags) { + error = -ENOSPC ;break ; + } flags =0 ; }xfs_perag_put (pag); } +if (!error) + *new_ino = ino;xfs_perag_put (pag); -return error ? error : -ENOSPC ; -found_ag: -/* Allocate an inode in the found AG */ - error =xfs_dialloc_ag (*tpp, agbp, pag, parent, &ino); -xfs_perag_put (pag); -if (error) -return error; - *new_ino = ino; -return 0 ; +return error; }/*
PATCH 42/61 xfs: use perag through unlink processing
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: f40aadb2bb64fe0a3d9b59957e70796d629cdee2
Unlinked lists are held in the perag, and freeing of inodes needs to be passed a perag, too, so look up the perag early in the unlink processing and use it throughout.
--- libxfs/xfs_ialloc.c | 23 ++++++++++------------- libxfs/xfs_ialloc.h | 13 ++----------- 2 files changed, 12 insertions(+), 24 deletions(-)
libxfs/xfs_ialloc.c +10 -13
@@ -2129,35 +2129,33 @@ xfs_difree_finobt(*/ int xfs_difree ( -struct xfs_trans *tp,/* transaction pointer */ -xfs_ino_t inode,/* inode to be freed */ -struct xfs_icluster *xic)/* cluster info if deleted */ +struct xfs_trans *tp, +struct xfs_perag *pag, +xfs_ino_t inode, +struct xfs_icluster *xic) {/* REFERENCED */ xfs_agblock_t agbno;/* block number containing inode */ struct xfs_buf *agbp;/* buffer for allocation group header */ xfs_agino_t agino;/* allocation group inode number */ -xfs_agnumber_t agno;/* allocation group number */ int error;/* error return value */ struct xfs_mount *mp = tp->t_mountp;struct xfs_inobt_rec_incore rec;/* btree record */ -struct xfs_perag *pag;/* * Break up inode number into its components. */ - agno =XFS_INO_TO_AGNO (mp, inode); -if (agno >= mp->m_sb.sb_agcount) { -xfs_warn (mp,"%s: agno >= mp->m_sb.sb_agcount (%d >= %d)." , - __func__, agno, mp->m_sb.sb_agcount); +if (pag->pag_agno !=XFS_INO_TO_AGNO (mp, inode)) { +xfs_warn (mp,"%s: agno != pag->pag_agno (%d != %d)." , + __func__,XFS_INO_TO_AGNO (mp, inode), pag->pag_agno);ASSERT (0 );return -EINVAL ; } agino =XFS_INO_TO_AGINO (mp, inode); -if (inode !=XFS_AGINO_TO_INO (mp, agno, agino)) { +if (inode !=XFS_AGINO_TO_INO (mp, pag->pag_agno, agino)) {xfs_warn (mp,"%s: inode != XFS_AGINO_TO_INO() (%llu != %llu)." , __func__, (unsigned long long )inode, - (unsigned long long )XFS_AGINO_TO_INO (mp, agno, agino)); + (unsigned long long )XFS_AGINO_TO_INO (mp, pag->pag_agno, agino));ASSERT (0 );return -EINVAL ; }
@@ -2171,7 +2169,7 @@ xfs_difree(/* * Get the allocation group header. */ - error =xfs_ialloc_read_agi (mp, tp, agno, &agbp); + error =xfs_ialloc_read_agi (mp, tp, pag->pag_agno, &agbp);if (error) {xfs_warn (mp,"%s: xfs_ialloc_read_agi() returned error %d." , __func__, error);
@@ -2181,7 +2179,6 @@ xfs_difree(/* * Fix up the inode allocation btree. */ - pag = agbp->b_pag; error =xfs_difree_inobt (mp, tp, agbp, pag, agino, xic, &rec);if (error) goto error0;
libxfs/xfs_ialloc.h +2 -11
@@ -39,17 +39,8 @@ xfs_make_iptr(struct xfs_mount *mp, struct xfs_buf *b, int o)int xfs_dialloc (struct xfs_trans **tpp,xfs_ino_t parent,umode_t mode,xfs_ino_t *new_ino); -/* -* Free disk inode. Carefully avoids touching the incore inode, all -* manipulations incore are the caller's responsibility. -* The on-disk inode is not changed by this operation, only the -* btree (free inode mask) is changed. -*/ -int /* error */ -xfs_difree ( -struct xfs_trans *tp,/* transaction pointer */ -xfs_ino_t inode,/* inode to be freed */ -struct xfs_icluster *ifree);/* cluster info if deleted */ +int xfs_difree (struct xfs_trans *tp,struct xfs_perag *pag, +xfs_ino_t ino,struct xfs_icluster *ifree);/* * Return the location of the inode in imap, for mapping it into a buffer.
PATCH 43/61 xfs: remove xfs_perag_t
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: 509201163fca3d4d906bd50a5320115d42818748
Almost unused, gets rid of another typedef.
--- libxfs/xfs_ag.c | 24 ++++++++++++------------ libxfs/xfs_ag.h | 4 ++-- libxfs/xfs_alloc.c | 42 +++++++++++++++++++++--------------------- 3 files changed, 35 insertions(+), 35 deletions(-)
libxfs/xfs_ag.c +12 -12
@@ -102,19 +102,19 @@ xfs_perag_put(*/ int xfs_initialize_perag_data ( -struct xfs_mount *mp, -xfs_agnumber_t agcount) +struct xfs_mount *mp, +xfs_agnumber_t agcount) { -xfs_agnumber_t index; -xfs_perag_t *pag; -xfs_sb_t *sbp = &mp->m_sb; -uint64_t ifree =0 ; -uint64_t ialloc =0 ; -uint64_t bfree =0 ; -uint64_t bfreelst =0 ; -uint64_t btree =0 ; -uint64_t fdblocks; -int error =0 ; +xfs_agnumber_t index; +struct xfs_perag *pag; +struct xfs_sb *sbp = &mp->m_sb; +uint64_t ifree =0 ; +uint64_t ialloc =0 ; +uint64_t bfree =0 ; +uint64_t bfreelst =0 ; +uint64_t btree =0 ; +uint64_t fdblocks; +int error =0 ;for (index =0 ; index < agcount; index++) {/*
libxfs/xfs_ag.h +2 -2
@@ -29,7 +29,7 @@ struct xfs_ag_resv {* Per-ag incore structure, copies of information in agf and agi, to improve the * performance of allocation group selection. */ -typedef struct xfs_perag { +struct xfs_perag {struct xfs_mount *pag_mount;/* owner filesystem */ xfs_agnumber_t pag_agno;/* AG this structure belongs to */ atomic_t pag_ref;/* perag reference count */
@@ -102,7 +102,7 @@ typedef struct xfs_perag {* or have some other means to control concurrency. */ struct rhashtable pagi_unlinked_hash; -} xfs_perag_t; +};int xfs_initialize_perag (struct xfs_mount *mp,xfs_agnumber_t agcount,xfs_agnumber_t *maxagi);
libxfs/xfs_alloc.c +21 -21
62 lines not on this page · raw message
PATCH 44/61 xfs: sort variable alphabetically to avoid repeated declaration
In reply to Darrick J. WongFrom: Shaokun Zhang <[email protected]>
Source kernel commit: 5f7fd75086203a8a4dd3e518976e52bcf24e8b22
Variable 'xfs_agf_buf_ops', 'xfs_agi_buf_ops', 'xfs_dquot_buf_ops' and 'xfs_symlink_buf_ops' are declared twice, so sort these variables alphabetically and remove the repeated declaration.
--- libxfs/xfs_shared.h | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)
libxfs/xfs_shared.h +8 -12
@@ -22,30 +22,26 @@ struct xfs_inode;* Buffer verifier operations are widely used, including userspace tools */ extern const struct xfs_buf_ops xfs_agf_buf_ops; -extern const struct xfs_buf_ops xfs_agi_buf_ops; -extern const struct xfs_buf_ops xfs_agf_buf_ops;extern const struct xfs_buf_ops xfs_agfl_buf_ops; -extern const struct xfs_buf_ops xfs_bnobt_buf_ops; -extern const struct xfs_buf_ops xfs_cntbt_buf_ops; -extern const struct xfs_buf_ops xfs_rmapbt_buf_ops; -extern const struct xfs_buf_ops xfs_refcountbt_buf_ops; +extern const struct xfs_buf_ops xfs_agi_buf_ops;extern const struct xfs_buf_ops xfs_attr3_leaf_buf_ops;extern const struct xfs_buf_ops xfs_attr3_rmt_buf_ops;extern const struct xfs_buf_ops xfs_bmbt_buf_ops; +extern const struct xfs_buf_ops xfs_bnobt_buf_ops; +extern const struct xfs_buf_ops xfs_cntbt_buf_ops;extern const struct xfs_buf_ops xfs_da3_node_buf_ops;extern const struct xfs_buf_ops xfs_dquot_buf_ops; -extern const struct xfs_buf_ops xfs_symlink_buf_ops; -extern const struct xfs_buf_ops xfs_agi_buf_ops; -extern const struct xfs_buf_ops xfs_inobt_buf_ops; +extern const struct xfs_buf_ops xfs_dquot_buf_ra_ops;extern const struct xfs_buf_ops xfs_finobt_buf_ops; +extern const struct xfs_buf_ops xfs_inobt_buf_ops;extern const struct xfs_buf_ops xfs_inode_buf_ops;extern const struct xfs_buf_ops xfs_inode_buf_ra_ops; -extern const struct xfs_buf_ops xfs_dquot_buf_ops; -extern const struct xfs_buf_ops xfs_dquot_buf_ra_ops; +extern const struct xfs_buf_ops xfs_refcountbt_buf_ops; +extern const struct xfs_buf_ops xfs_rmapbt_buf_ops; +extern const struct xfs_buf_ops xfs_rtbuf_ops;extern const struct xfs_buf_ops xfs_sb_buf_ops;extern const struct xfs_buf_ops xfs_sb_quiet_buf_ops;extern const struct xfs_buf_ops xfs_symlink_buf_ops; -extern const struct xfs_buf_ops xfs_rtbuf_ops;/* log size calculation functions */ int xfs_log_calc_unit_res (struct xfs_mount *mp,int unit_bytes);
PATCH 45/61 xfs: Remove redundant assignment to busy
In reply to Darrick J. WongFrom: Jiapeng Chong <[email protected]>
Source kernel commit: 9673261c32dc2f30863b803374b726a72d16b07c
Variable busy is set to false, but this value is never read as it is overwritten or not used later on, hence it is a redundant assignment and can be removed.
Clean up the following clang-analyzer warning:
fs/xfs/libxfs/xfs_alloc.c:1679:2: warning: Value stored to 'busy' is never read [clang-analyzer-deadcode.DeadStores].
--- libxfs/xfs_alloc.c | 1 - 1 file changed, 1 deletion(-)
libxfs/xfs_alloc.c +0 -1
@@ -1672,7 +1672,6 @@ xfs_alloc_ag_vextent_size( cnt_cur =xfs_allocbt_init_cursor (args->mp, args->tp, args->agbp, args->pag,XFS_BTNUM_CNT ); bno_cur =NULL ; - busy = false;/* * Look for an entry >= maxlen+alignment-1 blocks.
PATCH 46/61 xfs: mark xfs_bmap_set_attrforkoff static
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Source kernel commit: 5a981e4ea8ff8062e7c7ea8fc4a1565e4820a08b
xfs_bmap_set_attrforkoff is only used inside of xfs_bmap.c, so mark it static.
--- libxfs/xfs_bmap.c | 2 +- libxfs/xfs_bmap.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-)
libxfs/xfs_bmap.c +1 -1
@@ -1022,7 +1022,7 @@ xfs_bmap_add_attrfork_local(/* * Set an inode attr fork offset based on the format of the data fork. */ -int +static int xfs_bmap_set_attrforkoff( struct xfs_inode *ip, int size,
libxfs/xfs_bmap.h +0 -1
@@ -187,7 +187,6 @@ void xfs_trim_extent(struct xfs_bmbt_irec *irec, xfs_fileoff_t bno, xfs_filblks_t len);unsigned int xfs_bmap_compute_attr_offset (struct xfs_mount *mp);int xfs_bmap_add_attrfork (struct xfs_inode *ip,int size,int rsvd); -int xfs_bmap_set_attrforkoff (struct xfs_inode *ip,int size,int *version);void xfs_bmap_local_to_extents_empty (struct xfs_trans *tp,struct xfs_inode *ip,int whichfork); void __xfs_bmap_add_free(struct xfs_trans *tp, xfs_fsblock_t bno,
PATCH 47/61 xfs: fix radix tree tag signs
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 919a4ddb68413056ecb7c71d9d5465bb54c8032b
Radix tree tags are supposed to be unsigned ints, so fix the callers.
--- libxfs/xfs_ag.c | 2 +- libxfs/xfs_ag.h | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-)
libxfs/xfs_ag.c +1 -1
@@ -62,7 +62,7 @@ struct xfs_perag *xfs_perag_get_tag ( struct xfs_mount *mp, xfs_agnumber_t first, - int tag) + unsigned int tag) { struct xfs_perag *pag;int found;
libxfs/xfs_ag.h +4 -4
@@ -109,10 +109,10 @@ int xfs_initialize_perag(struct xfs_mount *mp, xfs_agnumber_t agcount,int xfs_initialize_perag_data (struct xfs_mount *mp,xfs_agnumber_t agno);void xfs_free_perag (struct xfs_mount *mp); -struct xfs_perag *xfs_perag_get (struct xfs_mount *,xfs_agnumber_t ); -struct xfs_perag *xfs_perag_get_tag (struct xfs_mount *,xfs_agnumber_t , -int tag); -void xfs_perag_put (struct xfs_perag *pag); +struct xfs_perag *xfs_perag_get (struct xfs_mount *mp,xfs_agnumber_t agno); +struct xfs_perag *xfs_perag_get_tag (struct xfs_mount *mp,xfs_agnumber_t agno, +unsigned int tag); +void xfs_perag_put (struct xfs_perag *pag);/* * Perag iteration APIs
PATCH 48/61 xfs: drop the AGI being passed to xfs_check_agi_freecount
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: 9ba0889e2272294bfbb5589b1b180ad2e782b2a4
From: Dave Chinner <[email protected]>
Stephen Rothwell reported this compiler warning from linux-next:
fs/xfs/libxfs/xfs_ialloc.c: In function 'xfs_difree_finobt':fs/xfs/libxfs/xfs_ialloc.c:2032:20: warning: unused variable 'agi' [-Wunused-variable]
2032 | struct xfs_agi *agi = agbp->b_addr;
Which is fallout from agno -> perag conversions that were done in this function. xfs_check_agi_freecount() is the only user of "agi" in xfs_difree_finobt() now, and it only uses the agi to get the current free inode count. We hold that in the perag structure, so there's not need to directly reference the raw AGI to get this information.
The btree cursor being passed to xfs_check_agi_freecount() has a reference to the perag being operated on, so use that directly in xfs_check_agi_freecount() rather than passing an AGI.
--- libxfs/xfs_ialloc.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-)
libxfs/xfs_ialloc.c +13 -15
@@ -209,10 +209,9 @@ xfs_inobt_insert(* Verify that the number of free inodes in the AGI is correct. */ #ifdef DEBUG -STATIC int +static int xfs_check_agi_freecount ( -struct xfs_btree_cur *cur, -struct xfs_agi *agi) +struct xfs_btree_cur *cur) {if (cur->bc_nlevels ==1 ) {xfs_inobt_rec_incore_t rec;
@@ -238,12 +237,12 @@ xfs_check_agi_freecount( } while (i == 1);if (!XFS_FORCED_SHUTDOWN (cur->bc_mp)) -ASSERT (freecount ==be32_to_cpu (agi->agi_freecount)); +ASSERT (freecount == cur->bc_ag.pag->pagi_freecount); }return 0 ; }#else -#define xfs_check_agi_freecount (cur, agi) 0 +#define xfs_check_agi_freecount (cur) 0#endif /*
@@ -1009,7 +1008,7 @@ xfs_dialloc_ag_inobt(if (!pagino) pagino =be32_to_cpu (agi->agi_newino); - error =xfs_check_agi_freecount (cur, agi); + error =xfs_check_agi_freecount (cur);if (error) goto error0;
@@ -1229,7 +1228,7 @@ xfs_dialloc_ag_inobt(xfs_ialloc_log_agi (tp, agbp,XFS_AGI_FREECOUNT ); pag->pagi_freecount--; - error =xfs_check_agi_freecount (cur, agi); + error =xfs_check_agi_freecount (cur);if (error) goto error0;
@@ -1456,7 +1455,7 @@ xfs_dialloc_ag( cur =xfs_inobt_init_cursor (mp, tp, agbp, pag,XFS_BTNUM_FINO ); - error =xfs_check_agi_freecount (cur, agi); + error =xfs_check_agi_freecount (cur);if (error) goto error_cur;
@@ -1499,7 +1498,7 @@ xfs_dialloc_ag(*/ icur =xfs_inobt_init_cursor (mp, tp, agbp, pag,XFS_BTNUM_INO ); - error =xfs_check_agi_freecount (icur, agi); + error =xfs_check_agi_freecount (icur);if (error) goto error_icur;
@@ -1517,10 +1516,10 @@ xfs_dialloc_ag(xfs_trans_mod_sb (tp,XFS_TRANS_SB_IFREE ,-1 ); - error =xfs_check_agi_freecount (icur, agi); + error =xfs_check_agi_freecount (icur);if (error) goto error_icur; - error =xfs_check_agi_freecount (cur, agi); + error =xfs_check_agi_freecount (cur);if (error) goto error_icur;
@@ -1906,7 +1905,7 @@ xfs_difree_inobt(*/ cur =xfs_inobt_init_cursor (mp, tp, agbp, pag,XFS_BTNUM_INO ); - error =xfs_check_agi_freecount (cur, agi); + error =xfs_check_agi_freecount (cur);if (error) goto error0;
@@ -1999,7 +1998,7 @@ xfs_difree_inobt(xfs_trans_mod_sb (tp,XFS_TRANS_SB_IFREE ,1 ); } - error =xfs_check_agi_freecount (cur, agi); + error =xfs_check_agi_freecount (cur);if (error) goto error0;
@@ -2024,7 +2023,6 @@ xfs_difree_finobt(xfs_agino_t agino, struct xfs_inobt_rec_incore *ibtrec) /* inobt record */ { - struct xfs_agi *agi = agbp->b_addr; struct xfs_btree_cur *cur;struct xfs_inobt_rec_incore rec;int offset = agino - ibtrec->ir_startino;
@@ -2109,7 +2107,7 @@ xfs_difree_finobt( } out: - error =xfs_check_agi_freecount (cur, agi); + error =xfs_check_agi_freecount (cur);if (error) goto error;
PATCH 49/61 xfs: Fix default ASSERT in xfs_attr_set_iter
In reply to Darrick J. WongFrom: Allison Henderson <[email protected]>
Source kernel commit: 4a4957c16dc674d1306a3b43d6b07ed93a7b7a14
This ASSERT checks for the state value of RM_SHRINK in the set path which should never happen. Change to ASSERT(0);
--- libxfs/xfs_attr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libxfs/xfs_attr.c +1 -1
@@ -612,7 +612,7 @@ xfs_attr_set_iter( error =xfs_attr_node_addname_clear_incomplete (dac);break ;default : -ASSERT (dac->dela_state !=XFS_DAS_RM_SHRINK ); +ASSERT (0 );break ; } out:
PATCH 50/61 xfs: Make attr name schemes consistent
In reply to Darrick J. WongFrom: Allison Henderson <[email protected]>
Source kernel commit: 816c8e39b7ea0875640312c9ed3be0d5a68d7183
This patch renames the following functions to make the nameing scheme more consistent:xfs_attr_shortform_remove -> xfs_attr_sf_removename xfs_attr_node_remove_name -> xfs_attr_node_removenamexfs_attr_set_fmt -> xfs_attr_sf_addname
--- libxfs/xfs_attr.c | 18 +++++++++--------- libxfs/xfs_attr_leaf.c | 2 +- libxfs/xfs_attr_leaf.h | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-)
libxfs/xfs_attr.c +9 -9
@@ -63,8 +63,8 @@ STATIC int xfs_attr_fillstate(xfs_da_state_t *state); STATIC int xfs_attr_refillstate(xfs_da_state_t *state); STATIC int xfs_attr_set_iter(struct xfs_delattr_context *dac,struct xfs_buf **leaf_bp); -STATIC int xfs_attr_node_remove_name(struct xfs_da_args *args, -struct xfs_da_state *state); +STATIC int xfs_attr_node_removename(struct xfs_da_args *args, +struct xfs_da_state *state);int xfs_inode_hasattr(
@@ -298,7 +298,7 @@ xfs_attr_set_args( } STATIC int -xfs_attr_set_fmt ( +xfs_attr_sf_addname (struct xfs_delattr_context *dac,struct xfs_buf **leaf_bp) {
@@ -367,7 +367,7 @@ xfs_attr_set_iter(* release the hold once we return with a clean transaction. */ if (xfs_attr_is_shortform (dp)) -return xfs_attr_set_fmt (dac, leaf_bp); +return xfs_attr_sf_addname (dac, leaf_bp);if (*leaf_bp !=NULL ) {xfs_trans_bhold_release (args->trans, *leaf_bp); *leaf_bp =NULL ;
@@ -840,7 +840,7 @@ xfs_attr_shortform_addname(xfs_da_args_t *args)if (retval == -EEXIST ) {if (args->attr_flags &XATTR_CREATE )return retval; - retval =xfs_attr_shortform_remove (args); + retval =xfs_attr_sf_removename (args);if (retval)return retval;/*
@@ -1223,7 +1223,7 @@ xfs_attr_node_addname_clear_incomplete(if (error) goto out; - error =xfs_attr_node_remove_name (args, state); + error =xfs_attr_node_removename (args, state);/* * Check to see if the tree needs to be collapsed.
@@ -1339,7 +1339,7 @@ int xfs_attr_node_removename_setup( } STATIC int -xfs_attr_node_remove_name ( +xfs_attr_node_removename (struct xfs_da_args *args,struct xfs_da_state *state) {
@@ -1390,7 +1390,7 @@ xfs_attr_remove_iter(* thus state transitions. Call the right helper and return. */ if (dp->i_afp->if_format ==XFS_DINODE_FMT_LOCAL ) -return xfs_attr_shortform_remove (args); +return xfs_attr_sf_removename (args);if (xfs_attr_is_leaf (dp))return xfs_attr_leaf_removename (args);
@@ -1453,7 +1453,7 @@ xfs_attr_remove_iter( goto out; } - retval =xfs_attr_node_remove_name (args, state); + retval =xfs_attr_node_removename (args, state);/* * Check to see if the tree needs to be collapsed. If so, roll
libxfs/xfs_attr_leaf.c +1 -1
@@ -771,7 +771,7 @@ xfs_attr_fork_remove(* Remove an attribute from the shortform attribute list structure. */ int -xfs_attr_shortform_remove ( +xfs_attr_sf_removename (struct xfs_da_args *args) {struct xfs_attr_shortform *sf;
libxfs/xfs_attr_leaf.h +1 -1
@@ -51,7 +51,7 @@ int xfs_attr_shortform_lookup(struct xfs_da_args *args);int xfs_attr_shortform_getvalue (struct xfs_da_args *args);int xfs_attr_shortform_to_leaf (struct xfs_da_args *args,struct xfs_buf **leaf_bp); -int xfs_attr_shortform_remove (struct xfs_da_args *args); +int xfs_attr_sf_removename (struct xfs_da_args *args);int xfs_attr_sf_findname (struct xfs_da_args *args,struct xfs_attr_sf_entry **sfep,unsigned int *basep);
PATCH 51/61 xfs: perag may be null in xfs_imap()
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: 90e2c1c20ac672756a2835b5a92a606dd48a4aa3
Dan Carpenter's static checker reported:
The patch 7b13c5155182: "xfs: use perag for ialloc btree cursors" from Jun 2, 2021, leads to the following Smatch complaint:
fs/xfs/libxfs/xfs_ialloc.c:2403 xfs_imap()
error: we previously assumed 'pag' could be null (see line 2294)
And it's right. Fix it.
--- libxfs/xfs_ialloc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
libxfs/xfs_ialloc.c +2 -1
@@ -2393,7 +2393,8 @@ xfs_imap( } error =0 ; out_drop: -xfs_perag_put (pag); +if (pag) +xfs_perag_put (pag);return error; }
PATCH 52/61 xfs: log stripe roundoff is a property of the log
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: a6a65fef5ef8d0a6a0ce514eb66b2f3dfa777b48
We don't need to look at the xfs_mount and superblock every time we need to do an iclog roundoff calculation. The property is fixed for the life of the log, so store the roundoff in the log at mount time and use that everywhere.
On a debug build:
$ size fs/xfs/xfs_log.o.* text data bss dec hex filename 27360 560 8 27928 6d18 fs/xfs/xfs_log.o.orig 27219 560 8 27787 6c8b fs/xfs/xfs_log.o.patched
--- libxfs/xfs_log_format.h | 3 --- 1 file changed, 3 deletions(-)
libxfs/xfs_log_format.h +0 -3
@@ -34,9 +34,6 @@ typedef uint32_t xlog_tid_t;#define XLOG_MIN_RECORD_BSHIFT 14/* 16384 == 1 << 14 */ #define XLOG_BIG_RECORD_BSHIFT 15/* 32k == 1 << 15 */ #define XLOG_MAX_RECORD_BSHIFT 18/* 256k == 1 << 18 */ -#define XLOG_BTOLSUNIT (log, b) (((b)+(log)->l_mp->m_sb.sb_logsunit-1) / \ - (log)->l_mp->m_sb.sb_logsunit) -#define XLOG_LSUNITTOB (log, su) ((su) * (log)->l_mp->m_sb.sb_logsunit)#define XLOG_HEADER_SIZE 512
PATCH 53/61 xfs: xfs_log_force_lsn isn't passed a LSN
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: 5f9b4b0de8dc2fb8eb655463b438001c111570fe
In doing an investigation into AIL push stalls, I was looking at the log force code to see if an async CIL push could be done instead. This lead me to xfs_log_force_lsn() and looking at how it works.
xfs_log_force_lsn() is only called from inode synchronisation contexts such as fsync(), and it takes the ip->i_itemp->ili_last_lsn value as the LSN to sync the log to. This gets passed to xlog_cil_force_lsn() via xfs_log_force_lsn() to flush the CIL to the journal, and then used by xfs_log_force_lsn() to flush the iclogs to the journal.
The problem is that ip->i_itemp->ili_last_lsn does not store a log sequence number. What it stores is passed to it from the ->iop_committing method, which is called by xfs_log_commit_cil(). The value this passes to the iop_committing method is the CIL context sequence number that the item was committed to.
As it turns out, xlog_cil_force_lsn() converts the sequence to an actual commit LSN for the related context and returns that to xfs_log_force_lsn(). xfs_log_force_lsn() overwrites it's "lsn" variable that contained a sequence with an actual LSN and then uses that to sync the iclogs.
This caused me some confusion for a while, even though I originally wrote all this code a decade ago. ->iop_committing is only used by a couple of log item types, and only inode items use the sequence number it is passed.
Let's clean up the API, CIL structures and inode log item to call it a sequence number, and make it clear that the high level code is using CIL sequence numbers and not on-disk LSNs for integrity synchronisation purposes.
--- libxfs/xfs_types.h | 1 + 1 file changed, 1 insertion(+)
libxfs/xfs_types.h +1 -0
@@ -21,6 +21,7 @@ typedef int32_t xfs_suminfo_t; /* type of bitmap summary info */typedef uint32_t xfs_rtword_t ;/* word type for bitmap manipulations */ typedef int64_t xfs_lsn_t ;/* log sequence number */ +typedef int64_t xfs_csn_t ;/* CIL sequence number */ typedef uint32_t xfs_dablk_t ;/* dir/attr block number (in file) */ typedef uint32_t xfs_dahash_t ;/* dir/attr hash value */
PATCH 54/61 xfs: fix endianness issue in xfs_ag_shrink_space
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: a8f3522c9a1f4a31e93b17f2b5310a2b615f5581
The AGI buffer is in big-endian format, so we must convert the endianness to CPU format to do any comparisons.
--- libxfs/xfs_ag.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
libxfs/xfs_ag.c +4 -3
@@ -777,6 +777,7 @@ xfs_ag_shrink_space(struct xfs_buf *agibp, *agfbp;struct xfs_agi *agi;struct xfs_agf *agf; +xfs_agblock_t aglen;int error, err2;ASSERT (agno == mp->m_sb.sb_agcount -1 );
@@ -791,14 +792,14 @@ xfs_ag_shrink_space(return error; agf = agfbp->b_addr; + aglen =be32_to_cpu (agi->agi_length);/* some extra paranoid checks before we shrink the ag */ if (XFS_IS_CORRUPT (mp, agf->agf_length != agi->agi_length))return -EFSCORRUPTED ; -if (delta >= agi->agi_length) +if (delta >= aglen)return -EINVAL ; - args.fsbno =XFS_AGB_TO_FSB (mp, agno, -be32_to_cpu (agi->agi_length) - delta); + args.fsbno =XFS_AGB_TO_FSB (mp, agno, aglen - delta);/* * Disable perag reservations so it doesn't cause the allocation request
PATCH 55/61 xfs: Initialize error in xfs_attr_remove_iter
In reply to Darrick J. WongFrom: Allison Henderson <[email protected]>
Source kernel commit: d3a3340b6af28ab79a66687973fb0287d976d490
A recent bug report generated a warning that a code path in xfs_attr_remove_iter could potentially return error uninitialized in the case of XFS_DAS_RM_SHRINK state. Fix this by initializing error.
--- libxfs/xfs_attr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libxfs/xfs_attr.c +1 -1
@@ -1375,7 +1375,7 @@ xfs_attr_remove_iter( {struct xfs_da_args *args = dac->da_args;struct xfs_da_state *state = dac->da_state; -int retval, error; +int retval, error =0 ;struct xfs_inode *dp = args->dp;trace_xfs_attr_node_removename (args);
PATCH 56/61 xfs: Fix multiple fall-through warnings for Clang
In reply to Darrick J. WongFrom: Gustavo A. R. Silva <[email protected]>
Source kernel commit: 5937e00017f1d1dd4551e723ebfa306671f27843
In preparation to enable -Wimplicit-fallthrough for Clang, fix the following warnings by replacing /* fallthrough */ comments, and its variants, with the new pseudo-keyword macro fallthrough:
fs/xfs/libxfs/xfs_attr.c:487:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough] fs/xfs/libxfs/xfs_attr.c:500:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough] fs/xfs/libxfs/xfs_attr.c:532:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough] fs/xfs/libxfs/xfs_attr.c:594:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough] fs/xfs/libxfs/xfs_attr.c:607:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough] fs/xfs/libxfs/xfs_attr.c:1410:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough] fs/xfs/libxfs/xfs_attr.c:1445:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough] fs/xfs/libxfs/xfs_attr.c:1473:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
Notice that Clang doesn't recognize /* fallthrough */ comments as implicit fall-through markings, so in order to globally enable -Wimplicit-fallthrough for Clang, these comments need to be replaced with fallthrough; in the whole codebase.
--- libxfs/xfs_attr.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
libxfs/xfs_attr.c +8 -8
@@ -483,7 +483,7 @@ xfs_attr_set_iter(if (error)return error; -/* fallthrough */ + fallthrough;case XFS_DAS_RM_LBLK :/* Set state in case xfs_attr_rmtval_remove returns -EAGAIN */ dac->dela_state =XFS_DAS_RM_LBLK ;
@@ -496,7 +496,7 @@ xfs_attr_set_iter(return -EAGAIN ; } -/* fallthrough */ + fallthrough;case XFS_DAS_RD_LEAF :/* * This is the last step for leaf format. Read the block with
@@ -528,7 +528,7 @@ xfs_attr_set_iter(return error; } -/* fallthrough */ + fallthrough;case XFS_DAS_ALLOC_NODE :/* * If there was an out-of-line value, allocate the blocks we
@@ -590,7 +590,7 @@ xfs_attr_set_iter(if (error)return error; -/* fallthrough */ + fallthrough;case XFS_DAS_RM_NBLK :/* Set state in case xfs_attr_rmtval_remove returns -EAGAIN */ dac->dela_state =XFS_DAS_RM_NBLK ;
@@ -603,7 +603,7 @@ xfs_attr_set_iter(return -EAGAIN ; } -/* fallthrough */ + fallthrough;case XFS_DAS_CLR_FLAG :/* * The last state for node format. Look up the old attr and
@@ -1406,7 +1406,7 @@ xfs_attr_remove_iter( state = dac->da_state; } -/* fallthrough */ + fallthrough;case XFS_DAS_RMTBLK : dac->dela_state =XFS_DAS_RMTBLK ;
@@ -1441,7 +1441,7 @@ xfs_attr_remove_iter(return -EAGAIN ; } -/* fallthrough */ + fallthrough;case XFS_DAS_RM_NAME :/* * If we came here fresh from a transaction roll, reattach all
@@ -1469,7 +1469,7 @@ xfs_attr_remove_iter(return -EAGAIN ; } -/* fallthrough */ + fallthrough;case XFS_DAS_RM_SHRINK :/* * If the result is small enough, push it all into the inode.
PATCH 57/61 xfs: check for sparse inode clusters that cross new EOAG when shrinking
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: da062d16a897c0759ae907e786bc0bea950c0c9d
While running xfs/168, I noticed occasional write verifier shutdowns involving inodes at the very end of the filesystem. Existing inode btree validation code checks that all inode clusters are fully contained within the filesystem.
However, due to inadequate checking in the fs shrink code, it's possible that there could be a sparse inode cluster at the end of the filesystem where the upper inodes of the cluster are marked as holes and the corresponding blocks are free. In this case, the last blocks in the AG are listed in the bnobt. This enables the shrink to proceed but results in a filesystem that trips the inode verifiers. Fix this by disallowing the shrink.
--- libxfs/xfs_ag.c | 8 +++++++ libxfs/xfs_ialloc.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_ialloc.h | 3 +++ 3 files changed, 66 insertions(+)
libxfs/xfs_ag.c +8 -0
@@ -801,6 +801,14 @@ xfs_ag_shrink_space( args.fsbno =XFS_AGB_TO_FSB (mp, agno, aglen - delta); +/* +* Make sure that the last inode cluster cannot overlap with the new +* end of the AG, even if it's sparse. +*/ + error =xfs_ialloc_check_shrink (*tpp, agno, agibp, aglen - delta); +if (error) +return error; +/* * Disable perag reservations so it doesn't cause the allocation request * to fail. We'll reestablish reservation before we return.
libxfs/xfs_ialloc.c +55 -0
58 lines not on this page · raw message
libxfs/xfs_ialloc.h +3 -0
@@ -122,4 +122,7 @@ int xfs_ialloc_cluster_alignment(struct xfs_mount *mp);void xfs_ialloc_setup_geometry (struct xfs_mount *mp);xfs_ino_t xfs_ialloc_calc_rootino (struct xfs_mount *mp,int sunit); +int xfs_ialloc_check_shrink (struct xfs_trans *tp,xfs_agnumber_t agno, +struct xfs_buf *agibp,xfs_agblock_t new_length); +#endif /* __XFS_IALLOC_H__ */
PATCH 58/61 xfs: correct the narrative around misaligned rtinherit/extszinherit dirs
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Source kernel commit: 83193e5ebb0164d612aa620ceab7d3746e80e2a4
While auditing the realtime growfs code, I realized that the GROWFSRT ioctl (and by extension xfs_growfs) has always allowed sysadmins to change the realtime extent size when adding a realtime section to the filesystem. Since we also have always allowed sysadmins to set RTINHERIT and EXTSZINHERIT on directories even if there is no realtime device, this invalidates the premise laid out in the comments added in
In other words, this is not a case of inadequate metadata validation. This is a case of nearly forgotten (and apparently untested) but supported functionality. Update the comments to reflect what we've learned, and remove the log message about correcting the misalignment.
--- libxfs/xfs_inode_buf.c | 28 ++++++++++++++++------------ libxfs/xfs_trans_inode.c | 10 ++++------ 2 files changed, 20 insertions(+), 18 deletions(-)
libxfs/xfs_inode_buf.c +16 -12
@@ -589,23 +589,27 @@ xfs_inode_validate_extsize(/* * This comment describes a historic gap in this verifier function. * -* On older kernels, the extent size hint verifier doesn't check that -* the extent size hint is an integer multiple of the realtime extent -* size on a directory with both RTINHERIT and EXTSZINHERIT flags set. -* The verifier has always enforced the alignment rule for regular -* files with the REALTIME flag set. +* For a directory with both RTINHERIT and EXTSZINHERIT flags set, this +* function has never checked that the extent size hint is an integer +* multiple of the realtime extent size. Since we allow users to set +* this combination on non-rt filesystems /and/ to change the rt +* extent size when adding a rt device to a filesystem, the net effect +* is that users can configure a filesystem anticipating one rt +* geometry and change their minds later. Directories do not use the +* extent size hint, so this is harmless for them. * * If a directory with a misaligned extent size hint is allowed to * propagate that hint into a new regular realtime file, the result * is that the inode cluster buffer verifier will trigger a corruption -* shutdown the next time it is run. +* shutdown the next time it is run, because the verifier has always +* enforced the alignment rule for regular files. * -* Unfortunately, there could be filesystems with these misconfigured -* directories in the wild, so we cannot add a check to this verifier -* at this time because that will result a new source of directory -* corruption errors when reading an existing filesystem. Instead, we -* permit the misconfiguration to pass through the verifiers so that -* callers of this function can correct and mitigate externally. +* Because we allow administrators to set a new rt extent size when +* adding a rt section, we cannot add a check to this verifier because +* that will result a new source of directory corruption errors when +* reading an existing filesystem. Instead, we rely on callers to +* decide when alignment checks are appropriate, and fix things up as +* needed. */ if (rt_flag)
libxfs/xfs_trans_inode.c +4 -6
@@ -140,16 +140,14 @@ xfs_trans_log_inode( }/* -* Inode verifiers on older kernels don't check that the extent size -* hint is an integer multiple of the rt extent size on a directory -* with both rtinherit and extszinherit flags set. If we're logging a -* directory that is misconfigured in this way, clear the hint. +* Inode verifiers do not check that the extent size hint is an integer +* multiple of the rt extent size on a directory with both rtinherit +* and extszinherit flags set. If we're logging a directory that is +* misconfigured in this way, clear the hint. */ if ((ip->i_diflags &XFS_DIFLAG_RTINHERIT ) && (ip->i_diflags &XFS_DIFLAG_EXTSZINHERIT ) && (ip->i_extsize % ip->i_mount->m_sb.sb_rextsize) >0 ) { -xfs_info_once (ip->i_mount, -"Correcting misaligned extent size hint in inode 0x%llx." , ip->i_ino); ip->i_diflags &= ~(XFS_DIFLAG_EXTSIZE |XFS_DIFLAG_EXTSZINHERIT ); ip->i_extsize =0 ;
PATCH 59/61 xfs: logging the on disk inode LSN can make it go backwards
In reply to Darrick J. WongFrom: Dave Chinner <[email protected]>
Source kernel commit: 32baa63d82ee3f5ab3bd51bae6bf7d1c15aed8c7
When we log an inode, we format the "log inode" core and set an LSN in that inode core. We do that via xfs_inode_item_format_core(), which calls:
xfs_inode_to_log_dinode(ip, dic, ip->i_itemp->ili_item.li_lsn);
to format the log inode. It writes the LSN from the inode item into the log inode, and if recovery decides the inode item needs to be replayed, it recovers the log inode LSN field and writes it into the on disk inode LSN field.
Now this might seem like a reasonable thing to do, but it is wrong on multiple levels. Firstly, if the item is not yet in the AIL, item->li_lsn is zero. i.e. the first time the inode it is logged and formatted, the LSN we write into the log inode will be zero. If we only log it once, recovery will run and can write this zero LSN into the inode.
This means that the next time the inode is logged and log recovery runs, it will *always* replay changes to the inode regardless of whether the inode is newer on disk than the version in the log and that violates the entire purpose of recording the LSN in the inode at writeback time (i.e. to stop it going backwards in time on disk during recovery).
Secondly, if we commit the CIL to the journal so the inode item moves to the AIL, and then relog the inode, the LSN that gets stamped into the log inode will be the LSN of the inode's current location in the AIL, not it's age on disk. And it's not the LSN that will be associated with the current change. That means when log recovery replays this inode item, the LSN that ends up on disk is the LSN for the previous changes in the log, not the current changes being replayed. IOWs, after recovery the LSN on disk is not in sync with the LSN of the modifications that were replayed into the inode. This, again, violates the recovery ordering semantics that on-disk writeback LSNs provide.
Hence the inode LSN in the log dinode is -always- invalid.
Thirdly, recovery actually has the LSN of the log transaction it is replaying right at hand - it uses it to determine if it should replay the inode by comparing it to the on-disk inode's LSN. But it doesn't use that LSN to stamp the LSN into the inode which will be written back when the transaction is fully replayed. It uses the one in the log dinode, which we know is always going to be incorrect.
Looking back at the change history, the inode logging was broken by back in 2016 by a stupid idiot who thought he knew how this code worked. i.e. me. That commit replaced an in memory di_lsn field that was updated only at inode writeback time from the inode item.li_lsn value - and hence always contained the same LSN that appeared in the on-disk inode - with a read of the inode item LSN at inode format time. CLearly these are not the same thing.
Before 93f958f9c41f, the log recovery behaviour was irrelevant, because the LSN in the log inode always matched the on-disk LSN at the time the inode was logged, hence recovery of the transaction would never make the on-disk LSN in the inode go backwards or get out of sync.
A symptom of the problem is this, caught from a failure of generic/482. Before log recovery, the inode has been allocated but never used:
xfs_db> inode 393388xfs_db> p
core.magic = 0x494e
core.mode = 0
....
v3.crc = 0x99126961 (correct)
v3.change_count = 0
v3.lsn = 0
v3.flags2 = 0
v3.cowextsize = 0
v3.crtime.sec = Thu Jan 1 10:00:00 1970
v3.crtime.nsec = 0
After log recovery:
xfs_db> p
core.magic = 0x494e
core.mode = 020444
....
v3.crc = 0x23e68f23 (correct)
v3.change_count = 2
v3.lsn = 0
v3.flags2 = 0
v3.cowextsize = 0
v3.crtime.sec = Thu Jul 22 17:03:03 2021
v3.crtime.nsec = 751000000
...
You can see that the LSN of the on-disk inode is 0, even though it clearly has been written to disk. I point out this inode, because the generic/482 failure occurred because several adjacent inodes in this specific inode cluster were not replayed correctly and still appeared to be zero on disk when all the other metadata (inobt, finobt, directories, etc) indicated they should be allocated and written back.
The fix for this is two-fold. The first is that we need to either revert the LSN changes in 93f958f9c41f or stop logging the inode LSN altogether. If we do the former, log recovery does not need to change but we add 8 bytes of memory per inode to store what is largely a write-only inode field. If we do the latter, log recovery needs to stamp the on-disk inode in the same manner that inode writeback does.
I prefer the latter, because we shouldn't really be trying to log and replay changes to the on disk LSN as the on-disk value is the canonical source of the on-disk version of the inode. It also matches the way we recover buffer items - we create a buf_log_item that carries the current recovery transaction LSN that gets stamped into the buffer by the write verifier when it gets written back when the transaction is fully recovered.
However, this might break log recovery on older kernels even more, so I'm going to simply ignore the logged value in recovery and stamp the on-disk inode with the LSN of the transaction being recovered that will trigger writeback on transaction recovery completion. This will ensure that the on-disk inode LSN always reflects the LSN of the last change that was written to disk, regardless of whether it comes from log recovery or runtime writeback.
--- libxfs/xfs_log_format.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
libxfs/xfs_log_format.h +10 -1
@@ -411,7 +411,16 @@ struct xfs_log_dinode {/* start of the extended dinode, writable fields */ uint32_t di_crc;/* CRC of the inode */ uint64_t di_changecount;/* number of attribute changes */ -xfs_lsn_t di_lsn;/* flush sequence */ + +/* +* The LSN we write to this field during formatting is not a reflection +* of the current on-disk LSN. It should never be used for recovery +* sequencing, nor should it be recovered into the on-disk inode at all. +* See xlog_recover_inode_commit_pass2() and xfs_log_dinode_to_disk() +* for details. +*/ +xfs_lsn_t di_lsn; +uint64_t di_flags2;/* more random flags */ uint32_t di_cowextsize;/* basic cow extent size for file */ uint8_t di_pad2[12 ];/* more padding for future expansion */
PATCH 60/61 xfs_db: convert the agresv command to use for_each_perag
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Convert the AG iteration loop for this debugger command to use for_each_perag, since it's the only place in userspace that obvious wants it.
--- db/info.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
db/info.c +8 -6
@@ -62,11 +62,11 @@ agresv_help(void)static void print_agresv_info ( -xfs_agnumber_t agno) +struct xfs_perag *pag) {struct xfs_buf *bp;struct xfs_agf *agf; -struct xfs_perag *pag =libxfs_perag_get (mp, agno); +xfs_agnumber_t agno = pag->pag_agno;xfs_extlen_t ask =0 ;xfs_extlen_t used =0 ;xfs_extlen_t free =0 ;
@@ -97,7 +97,6 @@ print_agresv_info(if (ask - used > free)printf (" <not enough space>" );printf ("\n" ); -libxfs_perag_put (pag); } static int
@@ -105,6 +104,7 @@ agresv_f(int argc, char **argv) { + struct xfs_perag *pag;xfs_agnumber_t agno;int i;
@@ -127,13 +127,15 @@ agresv_f(continue ; } -print_agresv_info (a); + pag =libxfs_perag_get (mp, a); +print_agresv_info (pag); +libxfs_perag_put (pag); }return 0 ; } -for (agno =0 ; agno < mp->m_sb.sb_agcount; agno++) -print_agresv_info (agno); +for_each_perag (mp, agno, pag) +print_agresv_info (pag);return 0 ; }
Re: [PATCH 60/61] xfs_db: convert the agresv command to use for_each_perag
Quoted 7 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Convert the AG iteration loop for this debugger command to use
for_each_perag, since it's the only place in userspace that obvious wants it.Signed-off-by Darrick J. Wong <[email protected]>
Looks good,
PATCH 61/61 mkfs: warn about V4 deprecation when creating new V4 filesystems
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
The V4 filesystem format is deprecated in the upstream Linux kernel. In September 2025 it will be turned off by default in the kernel and five years after that, support will be removed entirely. Warn people formatting new filesystems with the old format, particularly since V4 is not the default.
--- mkfs/xfs_mkfs.c | 9 +++++++++ 1 file changed, 9 insertions(+)
mkfs/xfs_mkfs.c +9 -0
@@ -2103,6 +2103,15 @@ _("Directory ftype field always enabled on CRC enabled filesystems\n")); } }else {/* !crcs_enabled */ +/* +* The V4 filesystem format is deprecated in the upstream Linux +* kernel. In September 2025 it will be turned off by default +* in the kernel and in September 2030 support will be removed +* entirely. +*/ +fprintf (stdout, +_ ("V4 filesystems are deprecated and will not be supported by future versions.\n" )); +/* * The kernel doesn't support crc=0,finobt=1 filesystems. * If crcs are not enabled and the user has not explicitly
Re: [PATCH 61/61] mkfs: warn about V4 deprecation when creating new V4 filesystems
Quoted 10 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
The V4 filesystem format is deprecated in the upstream Linux kernel. In September 2025 it will be turned off by default in the kernel and five years after that, support will be removed entirely. Warn people formatting new filesystems with the old format, particularly since V4 is not the default.
Signed-off-by Darrick J. Wong <[email protected]>Reviewed-by Dave Chinner <[email protected]>
Looks good,
(assuming you're already dealing with the xfstests fallout)
Re: [PATCH 61/61] mkfs: warn about V4 deprecation when creating new V4 filesystems
Quoted 9 lines · Christoph Hellwig
Quoted 8 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
The V4 filesystem format is deprecated in the upstream Linux kernel. In September 2025 it will be turned off by default in the kernel and five years after that, support will be removed entirely. Warn people formatting new filesystems with the old format, particularly since V4 is not the default.
Quoted 6 lines
Quoted 2 lines
Signed-off-by Darrick J. Wong <[email protected]>Reviewed-by Dave Chinner <[email protected]>Looks good,
(assuming you're already dealing with the xfstests fallout)
Already merged to fstests two weeks ago. ;)
(Was there supposed to be a RVB tag here?)
--D
Christoph Hellwig
Reviewed-byRe: [PATCH 61/61] mkfs: warn about V4 deprecation when creating new V4 filesystems
Quoted 13 lines · Darrick J. Wong
Quoted 12 lines · Christoph Hellwig
Quoted 10 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
The V4 filesystem format is deprecated in the upstream Linux kernel. In September 2025 it will be turned off by default in the kernel and five years after that, support will be removed entirely. Warn people formatting new filesystems with the old format, particularly since V4 is not the default.
Signed-off-by Darrick J. Wong <[email protected]>Reviewed-by Dave Chinner <[email protected]>
Quoted 7 lines
Quoted 3 lines
Looks good,
(assuming you're already dealing with the xfstests fallout)
Already merged to fstests two weeks ago. ;)
(Was there supposed to be a RVB tag here?)
Re: [PATCH 61/61] mkfs: warn about V4 deprecation when creating new V4 filesystems
In reply to Darrick J. WongQuoted 7 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
The V4 filesystem format is deprecated in the upstream Linux kernel. In September 2025 it will be turned off by default in the kernel and five years after that, support will be removed entirely. Warn people formatting new filesystems with the old format, particularly since V4 is not the default.
Friendly ping? I don't see this in for-next, but OTOH there hasn't been a release either... ;)
--D
Quoted 28 lines
Signed-off-by Darrick J. Wong <[email protected]>Reviewed-by Dave Chinner <[email protected]>--- mkfs/xfs_mkfs.c | 9 +++++++++ 1 file changed, 9 insertions(+)mkfs/xfs_mkfs.c +9
-0@@ -2103,6 +2103,15 @@ _("Directory ftype field always enabled on CRC enabled filesystems\n")); } }else {/* !crcs_enabled */ +/* +* The V4 filesystem format is deprecated in the upstream Linux +* kernel. In September 2025 it will be turned off by default +* in the kernel and in September 2030 support will be removed +* entirely. +*/ +fprintf (stdout, +_ ("V4 filesystems are deprecated and will not be supported by future versions.\n" )); +/* * The kernel doesn't support crc=0,finobt=1 filesystems. * If crcs are not enabled and the user has not explicitly
Re: [PATCH 61/61] mkfs: warn about V4 deprecation when creating new V4 filesystems
Quoted 11 lines · Darrick J. Wong
Quoted 7 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
The V4 filesystem format is deprecated in the upstream Linux kernel. In September 2025 it will be turned off by default in the kernel and five years after that, support will be removed entirely. Warn people formatting new filesystems with the old format, particularly since V4 is not the default.
Friendly ping? I don't see this in for-next, but OTOH there hasn't been a release either... ;)
Not forgotten - I'm just very behind. Ran it through regression tests and just wanted to fix up the dumb header file mistake before pushing out -rc1.
-Eric
Quoted 31 lines
--D
Quoted 28 lines
Signed-off-by Darrick J. Wong <[email protected]>Reviewed-by Dave Chinner <[email protected]>--- mkfs/xfs_mkfs.c | 9 +++++++++ 1 file changed, 9 insertions(+)mkfs/xfs_mkfs.c +9
-0@@ -2103,6 +2103,15 @@ _("Directory ftype field always enabled on CRC enabled filesystems\n")); } }else {/* !crcs_enabled */ +/* +* The V4 filesystem format is deprecated in the upstream Linux +* kernel. In September 2025 it will be turned off by default +* in the kernel and in September 2030 support will be removed +* entirely. +*/ +fprintf (stdout, +_ ("V4 filesystems are deprecated and will not be supported by future versions.\n" )); +/* * The kernel doesn't support crc=0,finobt=1 filesystems. * If crcs are not enabled and the user has not explicitly
Quoted 5 lines · Darrick J. Wong
Hi all,
This patchset backports all the libxfs changes from kernel 5.14, as well as all the related
for_each_peragand fallthrough; cleanups that went with it. I've prepared this series and pull request per Eric's request.
...and if anyone else really wants to go through this, the only patches that need formal reviews are patches 1-5, 7, and 60-61. Sorry for the overbroad cc list, I forgot that my maintainer scripts do that automatically. :/
--D
Quoted 89 lines
If you're going to start using this mess, you probably ought to just pull from my git trees, which are linked below.
This is an extraordinary way to destroy everything. Enjoy! Comments and questions are, as always, welcome.
--D
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=libxfs-5.14-sync--- db/fsmap.c | 17 - db/info.c | 18 - db/type.c | 2 growfs/xfs_growfs.c | 6 include/atomic.h | 1 include/libxfs.h | 3 include/linux.h | 17 + include/xfs_mount.h | 65 --- include/xfs_multidisk.h | 5 libfrog/Makefile | 3 libfrog/mockups.h | 43 ++ libfrog/radix-tree.h | 3 libxfs/Makefile | 10 libxfs/init.c | 147 +++---- libxfs/libxfs_api_defs.h | 2 libxfs/libxfs_priv.h | 18 + libxfs/topology.c | 5 libxfs/topology.h | 6 libxfs/util.c | 12 - libxfs/xfs_ag.c | 287 +++++++++++++ libxfs/xfs_ag.h | 136 ++++++ libxfs/xfs_ag_resv.c | 15 - libxfs/xfs_ag_resv.h | 15 + libxfs/xfs_alloc.c | 113 +++-- libxfs/xfs_alloc.h | 2 libxfs/xfs_alloc_btree.c | 31 + libxfs/xfs_alloc_btree.h | 9 libxfs/xfs_attr.c | 956 ++++++++++++++++++++++++++----------------- libxfs/xfs_attr.h | 403 ++++++++++++++++++ libxfs/xfs_attr_leaf.c | 5 libxfs/xfs_attr_leaf.h | 2 libxfs/xfs_attr_remote.c | 167 +++----- libxfs/xfs_attr_remote.h | 8 libxfs/xfs_bmap.c | 3 libxfs/xfs_bmap.h | 1 libxfs/xfs_btree.c | 15 - libxfs/xfs_btree.h | 12 - libxfs/xfs_da_btree.c | 2 libxfs/xfs_ialloc.c | 696 ++++++++++++++++--------------- libxfs/xfs_ialloc.h | 43 -- libxfs/xfs_ialloc_btree.c | 46 +- libxfs/xfs_ialloc_btree.h | 13 - libxfs/xfs_inode_buf.c | 30 + libxfs/xfs_log_format.h | 14 - libxfs/xfs_refcount.c | 122 +++-- libxfs/xfs_refcount.h | 9 libxfs/xfs_refcount_btree.c | 39 +- libxfs/xfs_refcount_btree.h | 7 libxfs/xfs_rmap.c | 147 +++---- libxfs/xfs_rmap.h | 6 libxfs/xfs_rmap_btree.c | 46 +- libxfs/xfs_rmap_btree.h | 8 libxfs/xfs_sb.c | 145 ------- libxfs/xfs_sb.h | 9 libxfs/xfs_shared.h | 20 - libxfs/xfs_trans_inode.c | 10 libxfs/xfs_types.c | 4 libxfs/xfs_types.h | 1 mkfs/proto.c | 1 mkfs/proto.h | 13 + mkfs/xfs_mkfs.c | 11 repair/agbtree.c | 28 + repair/agbtree.h | 8 repair/dinode.c | 18 - repair/phase4.c | 4 repair/phase5.c | 16 - repair/rmap.c | 43 +- repair/sb.c | 1 repair/scan.c | 4 scrub/inodes.c | 2 scrub/repair.c | 2 scrub/scrub.c | 8 72 files changed, 2520 insertions(+), 1619 deletions(-) create mode 100644 libfrog/mockups.h rename libfrog/topology.c => libxfs/topology.c (99%) rename libfrog/topology.h => libxfs/topology.h (88%) create mode 100644 mkfs/proto.h