Commit 97eeb4d9 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'xfs-5.5-merge-16' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux

Pull XFS updates from Darrick Wong:
 "For this release, we changed quite a few things.

  Highlights:

   - Fixed some long tail latency problems in the block allocator

   - Removed some long deprecated (and for the past several years no-op)
     mount options and ioctls

   - Strengthened the extended attribute and directory verifiers

   - Audited and fixed all the places where we could return EFSCORRUPTED
     without logging anything

   - Refactored the old SGI space allocation ioctls to make the
     equivalent fallocate calls

   - Fixed a race between fallocate and directio

   - Fixed an integer overflow when files have more than a few
     billion(!) extents

   - Fixed a longstanding bug where quota accounting could be incorrect
     when performing unwritten extent conversion on a freshly mounted fs

   - Fixed various complaints in scrub about soft lockups and
     unresponsiveness to signals

   - De-vtable'd the directory handling code, which should make it
     faster

   - Converted to the new mount api, for better or for worse

   - Cleaned up some memory leaks

  and quite a lot of other smaller fixes and cleanups.

  A more detailed summary:

   - Fill out the build string

   - Prevent inode fork extent count overflows

   - Refactor the allocator to reduce long tail latency

   - Rework incore log locking a little to reduce spinning

   - Break up the xfs_iomap_begin functions into smaller more cohesive
     parts

   - Fix allocation alignment being dropped too early when the
     allocation request is for more blocks than an AG is large

   - Other small cleanups

   - Clean up file buftarg retrieval helpers

   - Hoist the resvsp and unresvsp ioctls to the vfs

   - Remove the undocumented biosize mount option, since it has never
     been mentioned as existing or supported on linux

   - Clean up some of the mount option printing and parsing

   - Enhance attr leaf verifier to check block structure

   - Check dirent and attr names for invalid characters before passing
     them to the vfs

   - Refactor open-coded bmbt walking

   - Fix a few places where we return EIO instead of EFSCORRUPTED after
     failing metadata sanity checks

   - Fix a synchronization problem between fallocate and aio dio
     corrupting the file length

   - Clean up various loose ends in the iomap and bmap code

   - Convert to the new mount api

   - Make sure we always log something when returning EFSCORRUPTED

   - Fix some problems where long running scrub loops could trigger soft
     lockup warnings and/or fail to exit due to fatal signals pending

   - Fix various Coverity complaints

   - Remove most of the function pointers from the directory code to
     reduce indirection penalties

   - Ensure that dquots are attached to the inode when performing
     unwritten extent conversion after io

   - Deuglify incore projid and crtime types

   - Fix another AGI/AGF locking order deadlock when renaming

   - Clean up some quota typedefs

   - Remove the FSSETDM ioctls which haven't done anything in 20 years

   - Fix some memory leaks when mounting the log fails

   - Fix an underflow when updating an xattr leaf freemap

   - Remove some trivial wrappers

   - Report metadata corruption as an error, not a (potentially) fatal
     assertion

   - Clean up the dir/attr buffer mapping code

   - Allow fatal signals to kill scrub during parent pointer checks"

* tag 'xfs-5.5-merge-16' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux: (198 commits)
  xfs: allow parent directory scans to be interrupted with fatal signals
  xfs: remove the mappedbno argument to xfs_da_get_buf
  xfs: remove the mappedbno argument to xfs_da_read_buf
  xfs: split xfs_da3_node_read
  xfs: remove the mappedbno argument to xfs_dir3_leafn_read
  xfs: remove the mappedbno argument to xfs_dir3_leaf_read
  xfs: remove the mappedbno argument to xfs_attr3_leaf_read
  xfs: remove the mappedbno argument to xfs_da_reada_buf
  xfs: improve the xfs_dabuf_map calling conventions
  xfs: refactor xfs_dabuf_map
  xfs: simplify mappedbno handling in xfs_da_{get,read}_buf
  xfs: report corruption only as a regular error
  xfs: Remove kmem_zone_free() wrapper
  xfs: Remove kmem_zone_destroy() wrapper
  xfs: Remove slab init wrappers
  xfs: fix attr leaf header freemap.size underflow
  xfs: fix some memory leaks in log recovery
  xfs: fix another missing include
  xfs: remove XFS_IOC_FSSETDM and XFS_IOC_FSSETDM_BY_HANDLE
  xfs: remove duplicated include from xfs_dir2_data.c
  ...
parents 9b326948 8feb4732
...@@ -185,15 +185,27 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, ...@@ -185,15 +185,27 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
/* handled by some ->ioctl(); always a pointer to int */ /* handled by some ->ioctl(); always a pointer to int */
case FIONREAD: case FIONREAD:
goto found_handler; goto found_handler;
/* these two get messy on amd64 due to alignment differences */ /* these get messy on amd64 due to alignment differences */
#if defined(CONFIG_X86_64) #if defined(CONFIG_X86_64)
case FS_IOC_RESVSP_32: case FS_IOC_RESVSP_32:
case FS_IOC_RESVSP64_32: case FS_IOC_RESVSP64_32:
error = compat_ioctl_preallocate(f.file, compat_ptr(arg)); error = compat_ioctl_preallocate(f.file, 0, compat_ptr(arg));
goto out_fput;
case FS_IOC_UNRESVSP_32:
case FS_IOC_UNRESVSP64_32:
error = compat_ioctl_preallocate(f.file, FALLOC_FL_PUNCH_HOLE,
compat_ptr(arg));
goto out_fput;
case FS_IOC_ZERO_RANGE_32:
error = compat_ioctl_preallocate(f.file, FALLOC_FL_ZERO_RANGE,
compat_ptr(arg));
goto out_fput; goto out_fput;
#else #else
case FS_IOC_RESVSP: case FS_IOC_RESVSP:
case FS_IOC_RESVSP64: case FS_IOC_RESVSP64:
case FS_IOC_UNRESVSP:
case FS_IOC_UNRESVSP64:
case FS_IOC_ZERO_RANGE:
goto found_handler; goto found_handler;
#endif #endif
......
...@@ -467,7 +467,7 @@ EXPORT_SYMBOL(generic_block_fiemap); ...@@ -467,7 +467,7 @@ EXPORT_SYMBOL(generic_block_fiemap);
* Only the l_start, l_len and l_whence fields of the 'struct space_resv' * Only the l_start, l_len and l_whence fields of the 'struct space_resv'
* are used here, rest are ignored. * are used here, rest are ignored.
*/ */
int ioctl_preallocate(struct file *filp, void __user *argp) int ioctl_preallocate(struct file *filp, int mode, void __user *argp)
{ {
struct inode *inode = file_inode(filp); struct inode *inode = file_inode(filp);
struct space_resv sr; struct space_resv sr;
...@@ -488,13 +488,14 @@ int ioctl_preallocate(struct file *filp, void __user *argp) ...@@ -488,13 +488,14 @@ int ioctl_preallocate(struct file *filp, void __user *argp)
return -EINVAL; return -EINVAL;
} }
return vfs_fallocate(filp, FALLOC_FL_KEEP_SIZE, sr.l_start, sr.l_len); return vfs_fallocate(filp, mode | FALLOC_FL_KEEP_SIZE, sr.l_start,
sr.l_len);
} }
/* on ia32 l_start is on a 32-bit boundary */ /* on ia32 l_start is on a 32-bit boundary */
#if defined CONFIG_COMPAT && defined(CONFIG_X86_64) #if defined CONFIG_COMPAT && defined(CONFIG_X86_64)
/* just account for different alignment */ /* just account for different alignment */
int compat_ioctl_preallocate(struct file *file, int compat_ioctl_preallocate(struct file *file, int mode,
struct space_resv_32 __user *argp) struct space_resv_32 __user *argp)
{ {
struct inode *inode = file_inode(file); struct inode *inode = file_inode(file);
...@@ -516,7 +517,7 @@ int compat_ioctl_preallocate(struct file *file, ...@@ -516,7 +517,7 @@ int compat_ioctl_preallocate(struct file *file,
return -EINVAL; return -EINVAL;
} }
return vfs_fallocate(file, FALLOC_FL_KEEP_SIZE, sr.l_start, sr.l_len); return vfs_fallocate(file, mode | FALLOC_FL_KEEP_SIZE, sr.l_start, sr.l_len);
} }
#endif #endif
...@@ -533,7 +534,12 @@ static int file_ioctl(struct file *filp, unsigned int cmd, ...@@ -533,7 +534,12 @@ static int file_ioctl(struct file *filp, unsigned int cmd,
return put_user(i_size_read(inode) - filp->f_pos, p); return put_user(i_size_read(inode) - filp->f_pos, p);
case FS_IOC_RESVSP: case FS_IOC_RESVSP:
case FS_IOC_RESVSP64: case FS_IOC_RESVSP64:
return ioctl_preallocate(filp, p); return ioctl_preallocate(filp, 0, p);
case FS_IOC_UNRESVSP:
case FS_IOC_UNRESVSP64:
return ioctl_preallocate(filp, FALLOC_FL_PUNCH_HOLE, p);
case FS_IOC_ZERO_RANGE:
return ioctl_preallocate(filp, FALLOC_FL_ZERO_RANGE, p);
} }
return vfs_ioctl(filp, cmd, arg); return vfs_ioctl(filp, cmd, arg);
......
...@@ -27,7 +27,6 @@ xfs-y += $(addprefix libxfs/, \ ...@@ -27,7 +27,6 @@ xfs-y += $(addprefix libxfs/, \
xfs_bmap_btree.o \ xfs_bmap_btree.o \
xfs_btree.o \ xfs_btree.o \
xfs_da_btree.o \ xfs_da_btree.o \
xfs_da_format.o \
xfs_defer.o \ xfs_defer.o \
xfs_dir2.o \ xfs_dir2.o \
xfs_dir2_block.o \ xfs_dir2_block.o \
......
...@@ -32,7 +32,7 @@ kmem_alloc(size_t size, xfs_km_flags_t flags) ...@@ -32,7 +32,7 @@ kmem_alloc(size_t size, xfs_km_flags_t flags)
/* /*
* __vmalloc() will allocate data pages and auxillary structures (e.g. * __vmalloc() will allocate data pages and auxiliary structures (e.g.
* pagetables) with GFP_KERNEL, yet we may be under GFP_NOFS context here. Hence * pagetables) with GFP_KERNEL, yet we may be under GFP_NOFS context here. Hence
* we need to tell memory reclaim that we are in such a context via * we need to tell memory reclaim that we are in such a context via
* PF_MEMALLOC_NOFS to prevent memory reclaim re-entering the filesystem here * PF_MEMALLOC_NOFS to prevent memory reclaim re-entering the filesystem here
......
...@@ -78,39 +78,9 @@ kmem_zalloc_large(size_t size, xfs_km_flags_t flags) ...@@ -78,39 +78,9 @@ kmem_zalloc_large(size_t size, xfs_km_flags_t flags)
* Zone interfaces * Zone interfaces
*/ */
#define KM_ZONE_HWALIGN SLAB_HWCACHE_ALIGN
#define KM_ZONE_RECLAIM SLAB_RECLAIM_ACCOUNT
#define KM_ZONE_SPREAD SLAB_MEM_SPREAD
#define KM_ZONE_ACCOUNT SLAB_ACCOUNT
#define kmem_zone kmem_cache #define kmem_zone kmem_cache
#define kmem_zone_t struct kmem_cache #define kmem_zone_t struct kmem_cache
static inline kmem_zone_t *
kmem_zone_init(int size, char *zone_name)
{
return kmem_cache_create(zone_name, size, 0, 0, NULL);
}
static inline kmem_zone_t *
kmem_zone_init_flags(int size, char *zone_name, slab_flags_t flags,
void (*construct)(void *))
{
return kmem_cache_create(zone_name, size, 0, flags, construct);
}
static inline void
kmem_zone_free(kmem_zone_t *zone, void *ptr)
{
kmem_cache_free(zone, ptr);
}
static inline void
kmem_zone_destroy(kmem_zone_t *zone)
{
kmem_cache_destroy(zone);
}
extern void *kmem_zone_alloc(kmem_zone_t *, xfs_km_flags_t); extern void *kmem_zone_alloc(kmem_zone_t *, xfs_km_flags_t);
static inline void * static inline void *
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#include "xfs_btree.h" #include "xfs_btree.h"
#include "xfs_refcount_btree.h" #include "xfs_refcount_btree.h"
#include "xfs_ialloc_btree.h" #include "xfs_ialloc_btree.h"
#include "xfs_sb.h"
#include "xfs_ag_resv.h"
/* /*
* Per-AG Block Reservations * Per-AG Block Reservations
......
This diff is collapsed.
...@@ -54,7 +54,6 @@ typedef struct xfs_alloc_arg { ...@@ -54,7 +54,6 @@ typedef struct xfs_alloc_arg {
struct xfs_mount *mp; /* file system mount point */ struct xfs_mount *mp; /* file system mount point */
struct xfs_buf *agbp; /* buffer for a.g. freelist header */ struct xfs_buf *agbp; /* buffer for a.g. freelist header */
struct xfs_perag *pag; /* per-ag struct for this agno */ struct xfs_perag *pag; /* per-ag struct for this agno */
struct xfs_inode *ip; /* for userdata zeroing method */
xfs_fsblock_t fsbno; /* file system block number */ xfs_fsblock_t fsbno; /* file system block number */
xfs_agnumber_t agno; /* allocation group number */ xfs_agnumber_t agno; /* allocation group number */
xfs_agblock_t agbno; /* allocation group-relative block # */ xfs_agblock_t agbno; /* allocation group-relative block # */
...@@ -83,20 +82,7 @@ typedef struct xfs_alloc_arg { ...@@ -83,20 +82,7 @@ typedef struct xfs_alloc_arg {
*/ */
#define XFS_ALLOC_USERDATA (1 << 0)/* allocation is for user data*/ #define XFS_ALLOC_USERDATA (1 << 0)/* allocation is for user data*/
#define XFS_ALLOC_INITIAL_USER_DATA (1 << 1)/* special case start of file */ #define XFS_ALLOC_INITIAL_USER_DATA (1 << 1)/* special case start of file */
#define XFS_ALLOC_USERDATA_ZERO (1 << 2)/* zero extent on allocation */ #define XFS_ALLOC_NOBUSY (1 << 2)/* Busy extents not allowed */
#define XFS_ALLOC_NOBUSY (1 << 3)/* Busy extents not allowed */
static inline bool
xfs_alloc_is_userdata(int datatype)
{
return (datatype & ~XFS_ALLOC_NOBUSY) != 0;
}
static inline bool
xfs_alloc_allow_busy_reuse(int datatype)
{
return (datatype & XFS_ALLOC_NOBUSY) == 0;
}
/* freespace limit calculations */ /* freespace limit calculations */
#define XFS_ALLOC_AGFL_RESERVE 4 #define XFS_ALLOC_AGFL_RESERVE 4
......
...@@ -507,6 +507,7 @@ xfs_allocbt_init_cursor( ...@@ -507,6 +507,7 @@ xfs_allocbt_init_cursor(
cur->bc_private.a.agbp = agbp; cur->bc_private.a.agbp = agbp;
cur->bc_private.a.agno = agno; cur->bc_private.a.agno = agno;
cur->bc_private.a.priv.abt.active = false;
if (xfs_sb_version_hascrc(&mp->m_sb)) if (xfs_sb_version_hascrc(&mp->m_sb))
cur->bc_flags |= XFS_BTREE_CRC_BLOCKS; cur->bc_flags |= XFS_BTREE_CRC_BLOCKS;
......
...@@ -589,7 +589,7 @@ xfs_attr_leaf_addname( ...@@ -589,7 +589,7 @@ xfs_attr_leaf_addname(
*/ */
dp = args->dp; dp = args->dp;
args->blkno = 0; args->blkno = 0;
error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, -1, &bp); error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, &bp);
if (error) if (error)
return error; return error;
...@@ -715,7 +715,7 @@ xfs_attr_leaf_addname( ...@@ -715,7 +715,7 @@ xfs_attr_leaf_addname(
* remove the "old" attr from that block (neat, huh!) * remove the "old" attr from that block (neat, huh!)
*/ */
error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno,
-1, &bp); &bp);
if (error) if (error)
return error; return error;
...@@ -769,7 +769,7 @@ xfs_attr_leaf_removename( ...@@ -769,7 +769,7 @@ xfs_attr_leaf_removename(
*/ */
dp = args->dp; dp = args->dp;
args->blkno = 0; args->blkno = 0;
error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, -1, &bp); error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, &bp);
if (error) if (error)
return error; return error;
...@@ -813,7 +813,7 @@ xfs_attr_leaf_get(xfs_da_args_t *args) ...@@ -813,7 +813,7 @@ xfs_attr_leaf_get(xfs_da_args_t *args)
trace_xfs_attr_leaf_get(args); trace_xfs_attr_leaf_get(args);
args->blkno = 0; args->blkno = 0;
error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, -1, &bp); error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, &bp);
if (error) if (error)
return error; return error;
...@@ -1173,7 +1173,7 @@ xfs_attr_node_removename( ...@@ -1173,7 +1173,7 @@ xfs_attr_node_removename(
ASSERT(state->path.blk[0].bp); ASSERT(state->path.blk[0].bp);
state->path.blk[0].bp = NULL; state->path.blk[0].bp = NULL;
error = xfs_attr3_leaf_read(args->trans, args->dp, 0, -1, &bp); error = xfs_attr3_leaf_read(args->trans, args->dp, 0, &bp);
if (error) if (error)
goto out; goto out;
...@@ -1266,10 +1266,9 @@ xfs_attr_refillstate(xfs_da_state_t *state) ...@@ -1266,10 +1266,9 @@ xfs_attr_refillstate(xfs_da_state_t *state)
ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH)); ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
for (blk = path->blk, level = 0; level < path->active; blk++, level++) { for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
if (blk->disk_blkno) { if (blk->disk_blkno) {
error = xfs_da3_node_read(state->args->trans, error = xfs_da3_node_read_mapped(state->args->trans,
state->args->dp, state->args->dp, blk->disk_blkno,
blk->blkno, blk->disk_blkno, &blk->bp, XFS_ATTR_FORK);
&blk->bp, XFS_ATTR_FORK);
if (error) if (error)
return error; return error;
} else { } else {
...@@ -1285,10 +1284,9 @@ xfs_attr_refillstate(xfs_da_state_t *state) ...@@ -1285,10 +1284,9 @@ xfs_attr_refillstate(xfs_da_state_t *state)
ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH)); ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
for (blk = path->blk, level = 0; level < path->active; blk++, level++) { for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
if (blk->disk_blkno) { if (blk->disk_blkno) {
error = xfs_da3_node_read(state->args->trans, error = xfs_da3_node_read_mapped(state->args->trans,
state->args->dp, state->args->dp, blk->disk_blkno,
blk->blkno, blk->disk_blkno, &blk->bp, XFS_ATTR_FORK);
&blk->bp, XFS_ATTR_FORK);
if (error) if (error)
return error; return error;
} else { } else {
......
...@@ -232,6 +232,61 @@ xfs_attr3_leaf_hdr_to_disk( ...@@ -232,6 +232,61 @@ xfs_attr3_leaf_hdr_to_disk(
} }
} }
static xfs_failaddr_t
xfs_attr3_leaf_verify_entry(
struct xfs_mount *mp,
char *buf_end,
struct xfs_attr_leafblock *leaf,
struct xfs_attr3_icleaf_hdr *leafhdr,
struct xfs_attr_leaf_entry *ent,
int idx,
__u32 *last_hashval)
{
struct xfs_attr_leaf_name_local *lentry;
struct xfs_attr_leaf_name_remote *rentry;
char *name_end;
unsigned int nameidx;
unsigned int namesize;
__u32 hashval;
/* hash order check */
hashval = be32_to_cpu(ent->hashval);
if (hashval < *last_hashval)
return __this_address;
*last_hashval = hashval;
nameidx = be16_to_cpu(ent->nameidx);
if (nameidx < leafhdr->firstused || nameidx >= mp->m_attr_geo->blksize)
return __this_address;
/*
* Check the name information. The namelen fields are u8 so we can't
* possibly exceed the maximum name length of 255 bytes.
*/
if (ent->flags & XFS_ATTR_LOCAL) {
lentry = xfs_attr3_leaf_name_local(leaf, idx);
namesize = xfs_attr_leaf_entsize_local(lentry->namelen,
be16_to_cpu(lentry->valuelen));
name_end = (char *)lentry + namesize;
if (lentry->namelen == 0)
return __this_address;
} else {
rentry = xfs_attr3_leaf_name_remote(leaf, idx);
namesize = xfs_attr_leaf_entsize_remote(rentry->namelen);
name_end = (char *)rentry + namesize;
if (rentry->namelen == 0)
return __this_address;
if (!(ent->flags & XFS_ATTR_INCOMPLETE) &&
rentry->valueblk == 0)
return __this_address;
}
if (name_end > buf_end)
return __this_address;
return NULL;
}
static xfs_failaddr_t static xfs_failaddr_t
xfs_attr3_leaf_verify( xfs_attr3_leaf_verify(
struct xfs_buf *bp) struct xfs_buf *bp)
...@@ -240,7 +295,10 @@ xfs_attr3_leaf_verify( ...@@ -240,7 +295,10 @@ xfs_attr3_leaf_verify(
struct xfs_mount *mp = bp->b_mount; struct xfs_mount *mp = bp->b_mount;
struct xfs_attr_leafblock *leaf = bp->b_addr; struct xfs_attr_leafblock *leaf = bp->b_addr;
struct xfs_attr_leaf_entry *entries; struct xfs_attr_leaf_entry *entries;
struct xfs_attr_leaf_entry *ent;
char *buf_end;
uint32_t end; /* must be 32bit - see below */ uint32_t end; /* must be 32bit - see below */
__u32 last_hashval = 0;
int i; int i;
xfs_failaddr_t fa; xfs_failaddr_t fa;
...@@ -273,8 +331,13 @@ xfs_attr3_leaf_verify( ...@@ -273,8 +331,13 @@ xfs_attr3_leaf_verify(
(char *)bp->b_addr + ichdr.firstused) (char *)bp->b_addr + ichdr.firstused)
return __this_address; return __this_address;
/* XXX: need to range check rest of attr header values */ buf_end = (char *)bp->b_addr + mp->m_attr_geo->blksize;
/* XXX: hash order check? */ for (i = 0, ent = entries; i < ichdr.count; ent++, i++) {
fa = xfs_attr3_leaf_verify_entry(mp, buf_end, leaf, &ichdr,
ent, i, &last_hashval);
if (fa)
return fa;
}
/* /*
* Quickly check the freemap information. Attribute data has to be * Quickly check the freemap information. Attribute data has to be
...@@ -367,13 +430,12 @@ xfs_attr3_leaf_read( ...@@ -367,13 +430,12 @@ xfs_attr3_leaf_read(
struct xfs_trans *tp, struct xfs_trans *tp,
struct xfs_inode *dp, struct xfs_inode *dp,
xfs_dablk_t bno, xfs_dablk_t bno,
xfs_daddr_t mappedbno,
struct xfs_buf **bpp) struct xfs_buf **bpp)
{ {
int err; int err;
err = xfs_da_read_buf(tp, dp, bno, mappedbno, bpp, err = xfs_da_read_buf(tp, dp, bno, 0, bpp, XFS_ATTR_FORK,
XFS_ATTR_FORK, &xfs_attr3_leaf_buf_ops); &xfs_attr3_leaf_buf_ops);
if (!err && tp && *bpp) if (!err && tp && *bpp)
xfs_trans_buf_set_type(tp, *bpp, XFS_BLFT_ATTR_LEAF_BUF); xfs_trans_buf_set_type(tp, *bpp, XFS_BLFT_ATTR_LEAF_BUF);
return err; return err;
...@@ -453,13 +515,15 @@ xfs_attr_copy_value( ...@@ -453,13 +515,15 @@ xfs_attr_copy_value(
* special case for dev/uuid inodes, they have fixed size data forks. * special case for dev/uuid inodes, they have fixed size data forks.
*/ */
int int
xfs_attr_shortform_bytesfit(xfs_inode_t *dp, int bytes) xfs_attr_shortform_bytesfit(
struct xfs_inode *dp,
int bytes)
{ {
int offset; struct xfs_mount *mp = dp->i_mount;
int minforkoff; /* lower limit on valid forkoff locations */ int64_t dsize;
int maxforkoff; /* upper limit on valid forkoff locations */ int minforkoff;
int dsize; int maxforkoff;
xfs_mount_t *mp = dp->i_mount; int offset;
/* rounded down */ /* rounded down */
offset = (XFS_LITINO(mp, dp->i_d.di_version) - bytes) >> 3; offset = (XFS_LITINO(mp, dp->i_d.di_version) - bytes) >> 3;
...@@ -525,7 +589,7 @@ xfs_attr_shortform_bytesfit(xfs_inode_t *dp, int bytes) ...@@ -525,7 +589,7 @@ xfs_attr_shortform_bytesfit(xfs_inode_t *dp, int bytes)
* A data fork btree root must have space for at least * A data fork btree root must have space for at least
* MINDBTPTRS key/ptr pairs if the data fork is small or empty. * MINDBTPTRS key/ptr pairs if the data fork is small or empty.
*/ */
minforkoff = max(dsize, XFS_BMDR_SPACE_CALC(MINDBTPTRS)); minforkoff = max_t(int64_t, dsize, XFS_BMDR_SPACE_CALC(MINDBTPTRS));
minforkoff = roundup(minforkoff, 8) >> 3; minforkoff = roundup(minforkoff, 8) >> 3;
/* attr fork btree root can have at least this many key/ptr pairs */ /* attr fork btree root can have at least this many key/ptr pairs */
...@@ -764,7 +828,7 @@ xfs_attr_shortform_lookup(xfs_da_args_t *args) ...@@ -764,7 +828,7 @@ xfs_attr_shortform_lookup(xfs_da_args_t *args)
} }
/* /*
* Retreive the attribute value and length. * Retrieve the attribute value and length.
* *
* If ATTR_KERNOVAL is specified, only the length needs to be returned. * If ATTR_KERNOVAL is specified, only the length needs to be returned.
* Unlike a lookup, we only return an error if the attribute does not * Unlike a lookup, we only return an error if the attribute does not
...@@ -924,7 +988,7 @@ xfs_attr_shortform_verify( ...@@ -924,7 +988,7 @@ xfs_attr_shortform_verify(
char *endp; char *endp;
struct xfs_ifork *ifp; struct xfs_ifork *ifp;
int i; int i;
int size; int64_t size;
ASSERT(ip->i_d.di_aformat == XFS_DINODE_FMT_LOCAL); ASSERT(ip->i_d.di_aformat == XFS_DINODE_FMT_LOCAL);
ifp = XFS_IFORK_PTR(ip, XFS_ATTR_FORK); ifp = XFS_IFORK_PTR(ip, XFS_ATTR_FORK);
...@@ -1080,7 +1144,6 @@ xfs_attr3_leaf_to_node( ...@@ -1080,7 +1144,6 @@ xfs_attr3_leaf_to_node(
struct xfs_attr_leafblock *leaf; struct xfs_attr_leafblock *leaf;
struct xfs_attr3_icleaf_hdr icleafhdr; struct xfs_attr3_icleaf_hdr icleafhdr;
struct xfs_attr_leaf_entry *entries; struct xfs_attr_leaf_entry *entries;
struct xfs_da_node_entry *btree;
struct xfs_da3_icnode_hdr icnodehdr; struct xfs_da3_icnode_hdr icnodehdr;
struct xfs_da_intnode *node; struct xfs_da_intnode *node;
struct xfs_inode *dp = args->dp; struct xfs_inode *dp = args->dp;
...@@ -1095,11 +1158,11 @@ xfs_attr3_leaf_to_node( ...@@ -1095,11 +1158,11 @@ xfs_attr3_leaf_to_node(
error = xfs_da_grow_inode(args, &blkno); error = xfs_da_grow_inode(args, &blkno);
if (error) if (error)
goto out; goto out;
error = xfs_attr3_leaf_read(args->trans, dp, 0, -1, &bp1); error = xfs_attr3_leaf_read(args->trans, dp, 0, &bp1);
if (error) if (error)
goto out; goto out;
error = xfs_da_get_buf(args->trans, dp, blkno, -1, &bp2, XFS_ATTR_FORK); error = xfs_da_get_buf(args->trans, dp, blkno, &bp2, XFS_ATTR_FORK);
if (error) if (error)
goto out; goto out;
...@@ -1120,18 +1183,17 @@ xfs_attr3_leaf_to_node( ...@@ -1120,18 +1183,17 @@ xfs_attr3_leaf_to_node(
if (error) if (error)
goto out; goto out;
node = bp1->b_addr; node = bp1->b_addr;
dp->d_ops->node_hdr_from_disk(&icnodehdr, node); xfs_da3_node_hdr_from_disk(mp, &icnodehdr, node);
btree = dp->d_ops->node_tree_p(node);
leaf = bp2->b_addr; leaf = bp2->b_addr;
xfs_attr3_leaf_hdr_from_disk(args->geo, &icleafhdr, leaf); xfs_attr3_leaf_hdr_from_disk(args->geo, &icleafhdr, leaf);
entries = xfs_attr3_leaf_entryp(leaf); entries = xfs_attr3_leaf_entryp(leaf);
/* both on-disk, don't endian-flip twice */ /* both on-disk, don't endian-flip twice */
btree[0].hashval = entries[icleafhdr.count - 1].hashval; icnodehdr.btree[0].hashval = entries[icleafhdr.count - 1].hashval;
btree[0].before = cpu_to_be32(blkno); icnodehdr.btree[0].before = cpu_to_be32(blkno);
icnodehdr.count = 1; icnodehdr.count = 1;
dp->d_ops->node_hdr_to_disk(node, &icnodehdr); xfs_da3_node_hdr_to_disk(dp->i_mount, node, &icnodehdr);
xfs_trans_log_buf(args->trans, bp1, 0, args->geo->blksize - 1); xfs_trans_log_buf(args->trans, bp1, 0, args->geo->blksize - 1);
error = 0; error = 0;
out: out:
...@@ -1161,7 +1223,7 @@ xfs_attr3_leaf_create( ...@@ -1161,7 +1223,7 @@ xfs_attr3_leaf_create(
trace_xfs_attr_leaf_create(args); trace_xfs_attr_leaf_create(args);
error = xfs_da_get_buf(args->trans, args->dp, blkno, -1, &bp, error = xfs_da_get_buf(args->trans, args->dp, blkno, &bp,
XFS_ATTR_FORK); XFS_ATTR_FORK);
if (error) if (error)
return error; return error;
...@@ -1447,7 +1509,9 @@ xfs_attr3_leaf_add_work( ...@@ -1447,7 +1509,9 @@ xfs_attr3_leaf_add_work(
for (i = 0; i < XFS_ATTR_LEAF_MAPSIZE; i++) { for (i = 0; i < XFS_ATTR_LEAF_MAPSIZE; i++) {
if (ichdr->freemap[i].base == tmp) { if (ichdr->freemap[i].base == tmp) {
ichdr->freemap[i].base += sizeof(xfs_attr_leaf_entry_t); ichdr->freemap[i].base += sizeof(xfs_attr_leaf_entry_t);
ichdr->freemap[i].size -= sizeof(xfs_attr_leaf_entry_t); ichdr->freemap[i].size -=
min_t(uint16_t, ichdr->freemap[i].size,
sizeof(xfs_attr_leaf_entry_t));
} }
} }
ichdr->usedbytes += xfs_attr_leaf_entsize(leaf, args->index); ichdr->usedbytes += xfs_attr_leaf_entsize(leaf, args->index);
...@@ -1931,7 +1995,7 @@ xfs_attr3_leaf_toosmall( ...@@ -1931,7 +1995,7 @@ xfs_attr3_leaf_toosmall(
if (blkno == 0) if (blkno == 0)
continue; continue;
error = xfs_attr3_leaf_read(state->args->trans, state->args->dp, error = xfs_attr3_leaf_read(state->args->trans, state->args->dp,
blkno, -1, &bp); blkno, &bp);
if (error) if (error)
return error; return error;
...@@ -2281,8 +2345,10 @@ xfs_attr3_leaf_lookup_int( ...@@ -2281,8 +2345,10 @@ xfs_attr3_leaf_lookup_int(
leaf = bp->b_addr; leaf = bp->b_addr;
xfs_attr3_leaf_hdr_from_disk(args->geo, &ichdr, leaf); xfs_attr3_leaf_hdr_from_disk(args->geo, &ichdr, leaf);
entries = xfs_attr3_leaf_entryp(leaf); entries = xfs_attr3_leaf_entryp(leaf);
if (ichdr.count >= args->geo->blksize / 8) if (ichdr.count >= args->geo->blksize / 8) {
xfs_buf_corruption_error(bp);
return -EFSCORRUPTED; return -EFSCORRUPTED;
}
/* /*
* Binary search. (note: small blocks will skip this loop) * Binary search. (note: small blocks will skip this loop)
...@@ -2298,10 +2364,14 @@ xfs_attr3_leaf_lookup_int( ...@@ -2298,10 +2364,14 @@ xfs_attr3_leaf_lookup_int(
else else
break; break;
} }
if (!(probe >= 0 && (!ichdr.count || probe < ichdr.count))) if (!(probe >= 0 && (!ichdr.count || probe < ichdr.count))) {
xfs_buf_corruption_error(bp);
return -EFSCORRUPTED; return -EFSCORRUPTED;
if (!(span <= 4 || be32_to_cpu(entry->hashval) == hashval)) }
if (!(span <= 4 || be32_to_cpu(entry->hashval) == hashval)) {
xfs_buf_corruption_error(bp);
return -EFSCORRUPTED; return -EFSCORRUPTED;
}
/* /*
* Since we may have duplicate hashval's, find the first matching * Since we may have duplicate hashval's, find the first matching
...@@ -2661,7 +2731,7 @@ xfs_attr3_leaf_clearflag( ...@@ -2661,7 +2731,7 @@ xfs_attr3_leaf_clearflag(
/* /*
* Set up the operation. * Set up the operation.
*/ */
error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, -1, &bp); error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, &bp);
if (error) if (error)
return error; return error;
...@@ -2728,7 +2798,7 @@ xfs_attr3_leaf_setflag( ...@@ -2728,7 +2798,7 @@ xfs_attr3_leaf_setflag(
/* /*
* Set up the operation. * Set up the operation.
*/ */
error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, -1, &bp); error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, &bp);
if (error) if (error)
return error; return error;
...@@ -2790,7 +2860,7 @@ xfs_attr3_leaf_flipflags( ...@@ -2790,7 +2860,7 @@ xfs_attr3_leaf_flipflags(
/* /*
* Read the block containing the "old" attr * Read the block containing the "old" attr
*/ */
error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, -1, &bp1); error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, &bp1);
if (error) if (error)
return error; return error;
...@@ -2799,7 +2869,7 @@ xfs_attr3_leaf_flipflags( ...@@ -2799,7 +2869,7 @@ xfs_attr3_leaf_flipflags(
*/ */
if (args->blkno2 != args->blkno) { if (args->blkno2 != args->blkno) {
error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno2, error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno2,
-1, &bp2); &bp2);
if (error) if (error)
return error; return error;
} else { } else {
......
...@@ -16,6 +16,29 @@ struct xfs_da_state_blk; ...@@ -16,6 +16,29 @@ struct xfs_da_state_blk;
struct xfs_inode; struct xfs_inode;
struct xfs_trans; struct xfs_trans;
/*
* Incore version of the attribute leaf header.
*/
struct xfs_attr3_icleaf_hdr {
uint32_t forw;
uint32_t back;
uint16_t magic;
uint16_t count;
uint16_t usedbytes;
/*
* Firstused is 32-bit here instead of 16-bit like the on-disk variant
* to support maximum fsb size of 64k without overflow issues throughout
* the attr code. Instead, the overflow condition is handled on
* conversion to/from disk.
*/
uint32_t firstused;
__u8 holes;
struct {
uint16_t base;
uint16_t size;
} freemap[XFS_ATTR_LEAF_MAPSIZE];
};
/* /*
* Used to keep a list of "remote value" extents when unlinking an inode. * Used to keep a list of "remote value" extents when unlinking an inode.
*/ */
...@@ -67,8 +90,8 @@ int xfs_attr3_leaf_add(struct xfs_buf *leaf_buffer, ...@@ -67,8 +90,8 @@ int xfs_attr3_leaf_add(struct xfs_buf *leaf_buffer,
struct xfs_da_args *args); struct xfs_da_args *args);
int xfs_attr3_leaf_remove(struct xfs_buf *leaf_buffer, int xfs_attr3_leaf_remove(struct xfs_buf *leaf_buffer,
struct xfs_da_args *args); struct xfs_da_args *args);
void xfs_attr3_leaf_list_int(struct xfs_buf *bp, int xfs_attr3_leaf_list_int(struct xfs_buf *bp,
struct xfs_attr_list_context *context); struct xfs_attr_list_context *context);
/* /*
* Routines used for shrinking the Btree. * Routines used for shrinking the Btree.
...@@ -85,8 +108,7 @@ int xfs_attr_leaf_order(struct xfs_buf *leaf1_bp, ...@@ -85,8 +108,7 @@ int xfs_attr_leaf_order(struct xfs_buf *leaf1_bp,
struct xfs_buf *leaf2_bp); struct xfs_buf *leaf2_bp);
int xfs_attr_leaf_newentsize(struct xfs_da_args *args, int *local); int xfs_attr_leaf_newentsize(struct xfs_da_args *args, int *local);
int xfs_attr3_leaf_read(struct xfs_trans *tp, struct xfs_inode *dp, int xfs_attr3_leaf_read(struct xfs_trans *tp, struct xfs_inode *dp,
xfs_dablk_t bno, xfs_daddr_t mappedbno, xfs_dablk_t bno, struct xfs_buf **bpp);
struct xfs_buf **bpp);
void xfs_attr3_leaf_hdr_from_disk(struct xfs_da_geometry *geo, void xfs_attr3_leaf_hdr_from_disk(struct xfs_da_geometry *geo,
struct xfs_attr3_icleaf_hdr *to, struct xfs_attr3_icleaf_hdr *to,
struct xfs_attr_leafblock *from); struct xfs_attr_leafblock *from);
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "xfs_trans.h" #include "xfs_trans.h"
#include "xfs_bmap.h" #include "xfs_bmap.h"
#include "xfs_attr.h" #include "xfs_attr.h"
#include "xfs_attr_remote.h"
#include "xfs_trace.h" #include "xfs_trace.h"
#include "xfs_error.h" #include "xfs_error.h"
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
*/ */
#include "xfs.h" #include "xfs.h"
#include "xfs_log_format.h" #include "xfs_log_format.h"
#include "xfs_bit.h"
/* /*
* XFS bit manipulation routines, used in non-realtime code. * XFS bit manipulation routines, used in non-realtime code.
......
This diff is collapsed.
...@@ -105,11 +105,10 @@ xfs_btree_check_lblock( ...@@ -105,11 +105,10 @@ xfs_btree_check_lblock(
xfs_failaddr_t fa; xfs_failaddr_t fa;
fa = __xfs_btree_check_lblock(cur, block, level, bp); fa = __xfs_btree_check_lblock(cur, block, level, bp);
if (unlikely(XFS_TEST_ERROR(fa != NULL, mp, if (XFS_IS_CORRUPT(mp, fa != NULL) ||
XFS_ERRTAG_BTREE_CHECK_LBLOCK))) { XFS_TEST_ERROR(false, mp, XFS_ERRTAG_BTREE_CHECK_LBLOCK)) {
if (bp) if (bp)
trace_xfs_btree_corrupt(bp, _RET_IP_); trace_xfs_btree_corrupt(bp, _RET_IP_);
XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, mp);
return -EFSCORRUPTED; return -EFSCORRUPTED;
} }
return 0; return 0;
...@@ -169,11 +168,10 @@ xfs_btree_check_sblock( ...@@ -169,11 +168,10 @@ xfs_btree_check_sblock(
xfs_failaddr_t fa; xfs_failaddr_t fa;
fa = __xfs_btree_check_sblock(cur, block, level, bp); fa = __xfs_btree_check_sblock(cur, block, level, bp);
if (unlikely(XFS_TEST_ERROR(fa != NULL, mp, if (XFS_IS_CORRUPT(mp, fa != NULL) ||
XFS_ERRTAG_BTREE_CHECK_SBLOCK))) { XFS_TEST_ERROR(false, mp, XFS_ERRTAG_BTREE_CHECK_SBLOCK)) {
if (bp) if (bp)
trace_xfs_btree_corrupt(bp, _RET_IP_); trace_xfs_btree_corrupt(bp, _RET_IP_);
XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, mp);
return -EFSCORRUPTED; return -EFSCORRUPTED;
} }
return 0; return 0;
...@@ -384,7 +382,7 @@ xfs_btree_del_cursor( ...@@ -384,7 +382,7 @@ xfs_btree_del_cursor(
/* /*
* Free the cursor. * Free the cursor.
*/ */
kmem_zone_free(xfs_btree_cur_zone, cur); kmem_cache_free(xfs_btree_cur_zone, cur);
} }
/* /*
...@@ -716,25 +714,6 @@ xfs_btree_get_bufs( ...@@ -716,25 +714,6 @@ xfs_btree_get_bufs(
return xfs_trans_get_buf(tp, mp->m_ddev_targp, d, mp->m_bsize, 0); return xfs_trans_get_buf(tp, mp->m_ddev_targp, d, mp->m_bsize, 0);
} }
/*
* Check for the cursor referring to the last block at the given level.
*/
int /* 1=is last block, 0=not last block */
xfs_btree_islastblock(
xfs_btree_cur_t *cur, /* btree cursor */
int level) /* level to check */
{
struct xfs_btree_block *block; /* generic btree block pointer */
xfs_buf_t *bp; /* buffer containing block */
block = xfs_btree_get_block(cur, level, &bp);
xfs_btree_check_block(cur, block, level, bp);
if (cur->bc_flags & XFS_BTREE_LONG_PTRS)
return block->bb_u.l.bb_rightsib == cpu_to_be64(NULLFSBLOCK);
else
return block->bb_u.s.bb_rightsib == cpu_to_be32(NULLAGBLOCK);
}
/* /*
* Change the cursor to point to the first record at the given level. * Change the cursor to point to the first record at the given level.
* Other levels are unaffected. * Other levels are unaffected.
...@@ -1820,6 +1799,7 @@ xfs_btree_lookup_get_block( ...@@ -1820,6 +1799,7 @@ xfs_btree_lookup_get_block(
out_bad: out_bad:
*blkp = NULL; *blkp = NULL;
xfs_buf_corruption_error(bp);
xfs_trans_brelse(cur->bc_tp, bp); xfs_trans_brelse(cur->bc_tp, bp);
return -EFSCORRUPTED; return -EFSCORRUPTED;
} }
...@@ -1867,7 +1847,7 @@ xfs_btree_lookup( ...@@ -1867,7 +1847,7 @@ xfs_btree_lookup(
XFS_BTREE_STATS_INC(cur, lookup); XFS_BTREE_STATS_INC(cur, lookup);
/* No such thing as a zero-level tree. */ /* No such thing as a zero-level tree. */
if (cur->bc_nlevels == 0) if (XFS_IS_CORRUPT(cur->bc_mp, cur->bc_nlevels == 0))
return -EFSCORRUPTED; return -EFSCORRUPTED;
block = NULL; block = NULL;
...@@ -1987,7 +1967,8 @@ xfs_btree_lookup( ...@@ -1987,7 +1967,8 @@ xfs_btree_lookup(
error = xfs_btree_increment(cur, 0, &i); error = xfs_btree_increment(cur, 0, &i);
if (error) if (error)
goto error0; goto error0;
XFS_WANT_CORRUPTED_RETURN(cur->bc_mp, i == 1); if (XFS_IS_CORRUPT(cur->bc_mp, i != 1))
return -EFSCORRUPTED;
*stat = 1; *stat = 1;
return 0; return 0;
} }
...@@ -2442,7 +2423,10 @@ xfs_btree_lshift( ...@@ -2442,7 +2423,10 @@ xfs_btree_lshift(
if (error) if (error)
goto error0; goto error0;
i = xfs_btree_firstrec(tcur, level); i = xfs_btree_firstrec(tcur, level);
XFS_WANT_CORRUPTED_GOTO(tcur->bc_mp, i == 1, error0); if (XFS_IS_CORRUPT(tcur->bc_mp, i != 1)) {
error = -EFSCORRUPTED;
goto error0;
}
error = xfs_btree_decrement(tcur, level, &i); error = xfs_btree_decrement(tcur, level, &i);
if (error) if (error)
...@@ -2609,7 +2593,10 @@ xfs_btree_rshift( ...@@ -2609,7 +2593,10 @@ xfs_btree_rshift(
if (error) if (error)
goto error0; goto error0;
i = xfs_btree_lastrec(tcur, level); i = xfs_btree_lastrec(tcur, level);
XFS_WANT_CORRUPTED_GOTO(tcur->bc_mp, i == 1, error0); if (XFS_IS_CORRUPT(tcur->bc_mp, i != 1)) {
error = -EFSCORRUPTED;
goto error0;
}
error = xfs_btree_increment(tcur, level, &i); error = xfs_btree_increment(tcur, level, &i);
if (error) if (error)
...@@ -3463,7 +3450,10 @@ xfs_btree_insert( ...@@ -3463,7 +3450,10 @@ xfs_btree_insert(
goto error0; goto error0;
} }
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, i == 1, error0); if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) {
error = -EFSCORRUPTED;
goto error0;
}
level++; level++;
/* /*
...@@ -3867,15 +3857,24 @@ xfs_btree_delrec( ...@@ -3867,15 +3857,24 @@ xfs_btree_delrec(
* Actually any entry but the first would suffice. * Actually any entry but the first would suffice.
*/ */
i = xfs_btree_lastrec(tcur, level); i = xfs_btree_lastrec(tcur, level);
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, i == 1, error0); if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) {
error = -EFSCORRUPTED;
goto error0;
}
error = xfs_btree_increment(tcur, level, &i); error = xfs_btree_increment(tcur, level, &i);
if (error) if (error)
goto error0; goto error0;
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, i == 1, error0); if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) {
error = -EFSCORRUPTED;
goto error0;
}
i = xfs_btree_lastrec(tcur, level); i = xfs_btree_lastrec(tcur, level);
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, i == 1, error0); if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) {
error = -EFSCORRUPTED;
goto error0;
}
/* Grab a pointer to the block. */ /* Grab a pointer to the block. */
right = xfs_btree_get_block(tcur, level, &rbp); right = xfs_btree_get_block(tcur, level, &rbp);
...@@ -3919,12 +3918,18 @@ xfs_btree_delrec( ...@@ -3919,12 +3918,18 @@ xfs_btree_delrec(
rrecs = xfs_btree_get_numrecs(right); rrecs = xfs_btree_get_numrecs(right);
if (!xfs_btree_ptr_is_null(cur, &lptr)) { if (!xfs_btree_ptr_is_null(cur, &lptr)) {
i = xfs_btree_firstrec(tcur, level); i = xfs_btree_firstrec(tcur, level);
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, i == 1, error0); if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) {
error = -EFSCORRUPTED;
goto error0;
}
error = xfs_btree_decrement(tcur, level, &i); error = xfs_btree_decrement(tcur, level, &i);
if (error) if (error)
goto error0; goto error0;
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, i == 1, error0); if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) {
error = -EFSCORRUPTED;
goto error0;
}
} }
} }
...@@ -3938,13 +3943,19 @@ xfs_btree_delrec( ...@@ -3938,13 +3943,19 @@ xfs_btree_delrec(
* previous block. * previous block.
*/ */
i = xfs_btree_firstrec(tcur, level); i = xfs_btree_firstrec(tcur, level);
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, i == 1, error0); if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) {
error = -EFSCORRUPTED;
goto error0;
}
error = xfs_btree_decrement(tcur, level, &i); error = xfs_btree_decrement(tcur, level, &i);
if (error) if (error)
goto error0; goto error0;
i = xfs_btree_firstrec(tcur, level); i = xfs_btree_firstrec(tcur, level);
XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, i == 1, error0); if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) {
error = -EFSCORRUPTED;
goto error0;
}
/* Grab a pointer to the block. */ /* Grab a pointer to the block. */
left = xfs_btree_get_block(tcur, level, &lbp); left = xfs_btree_get_block(tcur, level, &lbp);
...@@ -4286,6 +4297,7 @@ int ...@@ -4286,6 +4297,7 @@ int
xfs_btree_visit_blocks( xfs_btree_visit_blocks(
struct xfs_btree_cur *cur, struct xfs_btree_cur *cur,
xfs_btree_visit_blocks_fn fn, xfs_btree_visit_blocks_fn fn,
unsigned int flags,
void *data) void *data)
{ {
union xfs_btree_ptr lptr; union xfs_btree_ptr lptr;
...@@ -4311,6 +4323,11 @@ xfs_btree_visit_blocks( ...@@ -4311,6 +4323,11 @@ xfs_btree_visit_blocks(
/* save for the next iteration of the loop */ /* save for the next iteration of the loop */
xfs_btree_copy_ptrs(cur, &lptr, ptr, 1); xfs_btree_copy_ptrs(cur, &lptr, ptr, 1);
if (!(flags & XFS_BTREE_VISIT_LEAVES))
continue;
} else if (!(flags & XFS_BTREE_VISIT_RECORDS)) {
continue;
} }
/* for each buffer in the level */ /* for each buffer in the level */
...@@ -4413,7 +4430,7 @@ xfs_btree_change_owner( ...@@ -4413,7 +4430,7 @@ xfs_btree_change_owner(
bbcoi.buffer_list = buffer_list; bbcoi.buffer_list = buffer_list;
return xfs_btree_visit_blocks(cur, xfs_btree_block_change_owner, return xfs_btree_visit_blocks(cur, xfs_btree_block_change_owner,
&bbcoi); XFS_BTREE_VISIT_ALL, &bbcoi);
} }
/* Verify the v5 fields of a long-format btree block. */ /* Verify the v5 fields of a long-format btree block. */
...@@ -4865,7 +4882,7 @@ xfs_btree_count_blocks( ...@@ -4865,7 +4882,7 @@ xfs_btree_count_blocks(
{ {
*blocks = 0; *blocks = 0;
return xfs_btree_visit_blocks(cur, xfs_btree_count_blocks_helper, return xfs_btree_visit_blocks(cur, xfs_btree_count_blocks_helper,
blocks); XFS_BTREE_VISIT_ALL, blocks);
} }
/* Compare two btree pointers. */ /* Compare two btree pointers. */
......
...@@ -183,6 +183,9 @@ union xfs_btree_cur_private { ...@@ -183,6 +183,9 @@ union xfs_btree_cur_private {
unsigned long nr_ops; /* # record updates */ unsigned long nr_ops; /* # record updates */
int shape_changes; /* # of extent splits */ int shape_changes; /* # of extent splits */
} refc; } refc;
struct {
bool active; /* allocation cursor state */
} abt;
}; };
/* /*
...@@ -314,14 +317,6 @@ xfs_btree_get_bufs( ...@@ -314,14 +317,6 @@ xfs_btree_get_bufs(
xfs_agnumber_t agno, /* allocation group number */ xfs_agnumber_t agno, /* allocation group number */
xfs_agblock_t agbno); /* allocation group block number */ xfs_agblock_t agbno); /* allocation group block number */
/*
* Check for the cursor referring to the last block at the given level.
*/
int /* 1=is last block, 0=not last block */
xfs_btree_islastblock(
xfs_btree_cur_t *cur, /* btree cursor */
int level); /* level to check */
/* /*
* Compute first and last byte offsets for the fields given. * Compute first and last byte offsets for the fields given.
* Interprets the offsets table, which contains struct field offsets. * Interprets the offsets table, which contains struct field offsets.
...@@ -482,8 +477,15 @@ int xfs_btree_query_all(struct xfs_btree_cur *cur, xfs_btree_query_range_fn fn, ...@@ -482,8 +477,15 @@ int xfs_btree_query_all(struct xfs_btree_cur *cur, xfs_btree_query_range_fn fn,
typedef int (*xfs_btree_visit_blocks_fn)(struct xfs_btree_cur *cur, int level, typedef int (*xfs_btree_visit_blocks_fn)(struct xfs_btree_cur *cur, int level,
void *data); void *data);
/* Visit record blocks. */
#define XFS_BTREE_VISIT_RECORDS (1 << 0)
/* Visit leaf blocks. */
#define XFS_BTREE_VISIT_LEAVES (1 << 1)
/* Visit all blocks. */
#define XFS_BTREE_VISIT_ALL (XFS_BTREE_VISIT_RECORDS | \
XFS_BTREE_VISIT_LEAVES)
int xfs_btree_visit_blocks(struct xfs_btree_cur *cur, int xfs_btree_visit_blocks(struct xfs_btree_cur *cur,
xfs_btree_visit_blocks_fn fn, void *data); xfs_btree_visit_blocks_fn fn, unsigned int flags, void *data);
int xfs_btree_count_blocks(struct xfs_btree_cur *cur, xfs_extlen_t *blocks); int xfs_btree_count_blocks(struct xfs_btree_cur *cur, xfs_extlen_t *blocks);
...@@ -514,4 +516,21 @@ int xfs_btree_has_record(struct xfs_btree_cur *cur, union xfs_btree_irec *low, ...@@ -514,4 +516,21 @@ int xfs_btree_has_record(struct xfs_btree_cur *cur, union xfs_btree_irec *low,
union xfs_btree_irec *high, bool *exists); union xfs_btree_irec *high, bool *exists);
bool xfs_btree_has_more_records(struct xfs_btree_cur *cur); bool xfs_btree_has_more_records(struct xfs_btree_cur *cur);
/* Does this cursor point to the last block in the given level? */
static inline bool
xfs_btree_islastblock(
xfs_btree_cur_t *cur,
int level)
{
struct xfs_btree_block *block;
struct xfs_buf *bp;
block = xfs_btree_get_block(cur, level, &bp);
ASSERT(block && xfs_btree_check_block(cur, block, level, bp) == 0);
if (cur->bc_flags & XFS_BTREE_LONG_PTRS)
return block->bb_u.l.bb_rightsib == cpu_to_be64(NULLFSBLOCK);
return block->bb_u.s.bb_rightsib == cpu_to_be32(NULLAGBLOCK);
}
#endif /* __XFS_BTREE_H__ */ #endif /* __XFS_BTREE_H__ */
This diff is collapsed.
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
struct xfs_inode; struct xfs_inode;
struct xfs_trans; struct xfs_trans;
struct zone; struct zone;
struct xfs_dir_ops;
/* /*
* Directory/attribute geometry information. There will be one of these for each * Directory/attribute geometry information. There will be one of these for each
...@@ -18,15 +17,23 @@ struct xfs_dir_ops; ...@@ -18,15 +17,23 @@ struct xfs_dir_ops;
* structures will be attached to the xfs_mount. * structures will be attached to the xfs_mount.
*/ */
struct xfs_da_geometry { struct xfs_da_geometry {
int blksize; /* da block size in bytes */ unsigned int blksize; /* da block size in bytes */
int fsbcount; /* da block size in filesystem blocks */ unsigned int fsbcount; /* da block size in filesystem blocks */
uint8_t fsblog; /* log2 of _filesystem_ block size */ uint8_t fsblog; /* log2 of _filesystem_ block size */
uint8_t blklog; /* log2 of da block size */ uint8_t blklog; /* log2 of da block size */
uint node_ents; /* # of entries in a danode */ unsigned int node_hdr_size; /* danode header size in bytes */
int magicpct; /* 37% of block size in bytes */ unsigned int node_ents; /* # of entries in a danode */
unsigned int magicpct; /* 37% of block size in bytes */
xfs_dablk_t datablk; /* blockno of dir data v2 */ xfs_dablk_t datablk; /* blockno of dir data v2 */
unsigned int leaf_hdr_size; /* dir2 leaf header size */
unsigned int leaf_max_ents; /* # of entries in dir2 leaf */
xfs_dablk_t leafblk; /* blockno of leaf data v2 */ xfs_dablk_t leafblk; /* blockno of leaf data v2 */
unsigned int free_hdr_size; /* dir2 free header size */
unsigned int free_max_bests; /* # of bests entries in dir2 free */
xfs_dablk_t freeblk; /* blockno of free data v2 */ xfs_dablk_t freeblk; /* blockno of free data v2 */
xfs_dir2_data_aoff_t data_first_offset;
size_t data_entry_offset;
}; };
/*======================================================================== /*========================================================================
...@@ -124,6 +131,25 @@ typedef struct xfs_da_state { ...@@ -124,6 +131,25 @@ typedef struct xfs_da_state {
/* for dirv2 extrablk is data */ /* for dirv2 extrablk is data */
} xfs_da_state_t; } xfs_da_state_t;
/*
* In-core version of the node header to abstract the differences in the v2 and
* v3 disk format of the headers. Callers need to convert to/from disk format as
* appropriate.
*/
struct xfs_da3_icnode_hdr {
uint32_t forw;
uint32_t back;
uint16_t magic;
uint16_t count;
uint16_t level;
/*
* Pointer to the on-disk format entries, which are behind the
* variable size (v4 vs v5) header in the on-disk block.
*/
struct xfs_da_node_entry *btree;
};
/* /*
* Utility macros to aid in logging changed structure fields. * Utility macros to aid in logging changed structure fields.
*/ */
...@@ -132,16 +158,6 @@ typedef struct xfs_da_state { ...@@ -132,16 +158,6 @@ typedef struct xfs_da_state {
(uint)(XFS_DA_LOGOFF(BASE, ADDR)), \ (uint)(XFS_DA_LOGOFF(BASE, ADDR)), \
(uint)(XFS_DA_LOGOFF(BASE, ADDR)+(SIZE)-1) (uint)(XFS_DA_LOGOFF(BASE, ADDR)+(SIZE)-1)
/*
* Name ops for directory and/or attr name operations
*/
struct xfs_nameops {
xfs_dahash_t (*hashname)(struct xfs_name *);
enum xfs_dacmp (*compname)(struct xfs_da_args *,
const unsigned char *, int);
};
/*======================================================================== /*========================================================================
* Function prototypes. * Function prototypes.
*========================================================================*/ *========================================================================*/
...@@ -172,25 +188,28 @@ int xfs_da3_path_shift(xfs_da_state_t *state, xfs_da_state_path_t *path, ...@@ -172,25 +188,28 @@ int xfs_da3_path_shift(xfs_da_state_t *state, xfs_da_state_path_t *path,
int xfs_da3_blk_link(xfs_da_state_t *state, xfs_da_state_blk_t *old_blk, int xfs_da3_blk_link(xfs_da_state_t *state, xfs_da_state_blk_t *old_blk,
xfs_da_state_blk_t *new_blk); xfs_da_state_blk_t *new_blk);
int xfs_da3_node_read(struct xfs_trans *tp, struct xfs_inode *dp, int xfs_da3_node_read(struct xfs_trans *tp, struct xfs_inode *dp,
xfs_dablk_t bno, xfs_daddr_t mappedbno, xfs_dablk_t bno, struct xfs_buf **bpp, int whichfork);
struct xfs_buf **bpp, int which_fork); int xfs_da3_node_read_mapped(struct xfs_trans *tp, struct xfs_inode *dp,
xfs_daddr_t mappedbno, struct xfs_buf **bpp,
int whichfork);
/* /*
* Utility routines. * Utility routines.
*/ */
#define XFS_DABUF_MAP_HOLE_OK (1 << 0)
int xfs_da_grow_inode(xfs_da_args_t *args, xfs_dablk_t *new_blkno); int xfs_da_grow_inode(xfs_da_args_t *args, xfs_dablk_t *new_blkno);
int xfs_da_grow_inode_int(struct xfs_da_args *args, xfs_fileoff_t *bno, int xfs_da_grow_inode_int(struct xfs_da_args *args, xfs_fileoff_t *bno,
int count); int count);
int xfs_da_get_buf(struct xfs_trans *trans, struct xfs_inode *dp, int xfs_da_get_buf(struct xfs_trans *trans, struct xfs_inode *dp,
xfs_dablk_t bno, xfs_daddr_t mappedbno, xfs_dablk_t bno, struct xfs_buf **bp, int whichfork);
struct xfs_buf **bp, int whichfork);
int xfs_da_read_buf(struct xfs_trans *trans, struct xfs_inode *dp, int xfs_da_read_buf(struct xfs_trans *trans, struct xfs_inode *dp,
xfs_dablk_t bno, xfs_daddr_t mappedbno, xfs_dablk_t bno, unsigned int flags, struct xfs_buf **bpp,
struct xfs_buf **bpp, int whichfork, int whichfork, const struct xfs_buf_ops *ops);
const struct xfs_buf_ops *ops);
int xfs_da_reada_buf(struct xfs_inode *dp, xfs_dablk_t bno, int xfs_da_reada_buf(struct xfs_inode *dp, xfs_dablk_t bno,
xfs_daddr_t mapped_bno, int whichfork, unsigned int flags, int whichfork,
const struct xfs_buf_ops *ops); const struct xfs_buf_ops *ops);
int xfs_da_shrink_inode(xfs_da_args_t *args, xfs_dablk_t dead_blkno, int xfs_da_shrink_inode(xfs_da_args_t *args, xfs_dablk_t dead_blkno,
struct xfs_buf *dead_buf); struct xfs_buf *dead_buf);
...@@ -202,7 +221,11 @@ enum xfs_dacmp xfs_da_compname(struct xfs_da_args *args, ...@@ -202,7 +221,11 @@ enum xfs_dacmp xfs_da_compname(struct xfs_da_args *args,
xfs_da_state_t *xfs_da_state_alloc(void); xfs_da_state_t *xfs_da_state_alloc(void);
void xfs_da_state_free(xfs_da_state_t *state); void xfs_da_state_free(xfs_da_state_t *state);
void xfs_da3_node_hdr_from_disk(struct xfs_mount *mp,
struct xfs_da3_icnode_hdr *to, struct xfs_da_intnode *from);
void xfs_da3_node_hdr_to_disk(struct xfs_mount *mp,
struct xfs_da_intnode *to, struct xfs_da3_icnode_hdr *from);
extern struct kmem_zone *xfs_da_state_zone; extern struct kmem_zone *xfs_da_state_zone;
extern const struct xfs_nameops xfs_default_nameops;
#endif /* __XFS_DA_BTREE_H__ */ #endif /* __XFS_DA_BTREE_H__ */
This diff is collapsed.
...@@ -93,19 +93,6 @@ struct xfs_da3_intnode { ...@@ -93,19 +93,6 @@ struct xfs_da3_intnode {
struct xfs_da_node_entry __btree[]; struct xfs_da_node_entry __btree[];
}; };
/*
* In-core version of the node header to abstract the differences in the v2 and
* v3 disk format of the headers. Callers need to convert to/from disk format as
* appropriate.
*/
struct xfs_da3_icnode_hdr {
uint32_t forw;
uint32_t back;
uint16_t magic;
uint16_t count;
uint16_t level;
};
/* /*
* Directory version 2. * Directory version 2.
* *
...@@ -434,14 +421,6 @@ struct xfs_dir3_leaf_hdr { ...@@ -434,14 +421,6 @@ struct xfs_dir3_leaf_hdr {
__be32 pad; /* 64 bit alignment */ __be32 pad; /* 64 bit alignment */
}; };
struct xfs_dir3_icleaf_hdr {
uint32_t forw;
uint32_t back;
uint16_t magic;
uint16_t count;
uint16_t stale;
};
/* /*
* Leaf block entry. * Leaf block entry.
*/ */
...@@ -482,7 +461,7 @@ xfs_dir2_leaf_bests_p(struct xfs_dir2_leaf_tail *ltp) ...@@ -482,7 +461,7 @@ xfs_dir2_leaf_bests_p(struct xfs_dir2_leaf_tail *ltp)
} }
/* /*
* Free space block defintions for the node format. * Free space block definitions for the node format.
*/ */
/* /*
...@@ -520,19 +499,6 @@ struct xfs_dir3_free { ...@@ -520,19 +499,6 @@ struct xfs_dir3_free {
#define XFS_DIR3_FREE_CRC_OFF offsetof(struct xfs_dir3_free, hdr.hdr.crc) #define XFS_DIR3_FREE_CRC_OFF offsetof(struct xfs_dir3_free, hdr.hdr.crc)
/*
* In core version of the free block header, abstracted away from on-disk format
* differences. Use this in the code, and convert to/from the disk version using
* xfs_dir3_free_hdr_from_disk/xfs_dir3_free_hdr_to_disk.
*/
struct xfs_dir3_icfree_hdr {
uint32_t magic;
uint32_t firstdb;
uint32_t nvalid;
uint32_t nused;
};
/* /*
* Single block format. * Single block format.
* *
...@@ -709,29 +675,6 @@ struct xfs_attr3_leafblock { ...@@ -709,29 +675,6 @@ struct xfs_attr3_leafblock {
*/ */
}; };
/*
* incore, neutral version of the attribute leaf header
*/
struct xfs_attr3_icleaf_hdr {
uint32_t forw;
uint32_t back;
uint16_t magic;
uint16_t count;
uint16_t usedbytes;
/*
* firstused is 32-bit here instead of 16-bit like the on-disk variant
* to support maximum fsb size of 64k without overflow issues throughout
* the attr code. Instead, the overflow condition is handled on
* conversion to/from disk.
*/
uint32_t firstused;
__u8 holes;
struct {
uint16_t base;
uint16_t size;
} freemap[XFS_ATTR_LEAF_MAPSIZE];
};
/* /*
* Special value to represent fs block size in the leaf header firstused field. * Special value to represent fs block size in the leaf header firstused field.
* Only used when block size overflows the 2-bytes available on disk. * Only used when block size overflows the 2-bytes available on disk.
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment