2005-04-16 22:20:36 +00:00
|
|
|
/*
|
2005-11-02 03:58:39 +00:00
|
|
|
* Copyright (c) 2000,2002-2005 Silicon Graphics, Inc.
|
|
|
|
* All Rights Reserved.
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
2005-11-02 03:58:39 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
2005-04-16 22:20:36 +00:00
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
2005-11-02 03:58:39 +00:00
|
|
|
* This program is distributed in the hope that it would be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
2005-11-02 03:58:39 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
#ifndef __XFS_BMAP_BTREE_H__
|
|
|
|
#define __XFS_BMAP_BTREE_H__
|
|
|
|
|
|
|
|
struct xfs_btree_cur;
|
2008-10-30 06:11:40 +00:00
|
|
|
struct xfs_btree_block;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct xfs_mount;
|
|
|
|
struct xfs_inode;
|
2008-10-30 05:53:59 +00:00
|
|
|
struct xfs_trans;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Extent state and extent format macros.
|
|
|
|
*/
|
2005-11-02 03:38:42 +00:00
|
|
|
#define XFS_EXTFMT_INODE(x) \
|
2008-03-06 02:44:28 +00:00
|
|
|
(xfs_sb_version_hasextflgbit(&((x)->i_mount->m_sb)) ? \
|
2005-11-02 03:38:42 +00:00
|
|
|
XFS_EXTFMT_HASSTATE : XFS_EXTFMT_NOSTATE)
|
2005-04-16 22:20:36 +00:00
|
|
|
#define ISUNWRITTEN(x) ((x)->br_state == XFS_EXT_UNWRITTEN)
|
|
|
|
|
2008-10-30 06:14:34 +00:00
|
|
|
/*
|
|
|
|
* Btree block header size depends on a superblock flag.
|
|
|
|
*/
|
2013-04-21 19:53:46 +00:00
|
|
|
#define XFS_BMBT_BLOCK_LEN(mp) \
|
|
|
|
(xfs_sb_version_hascrc(&((mp)->m_sb)) ? \
|
|
|
|
XFS_BTREE_LBLOCK_CRC_LEN : XFS_BTREE_LBLOCK_LEN)
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-10-30 06:11:40 +00:00
|
|
|
#define XFS_BMBT_REC_ADDR(mp, block, index) \
|
|
|
|
((xfs_bmbt_rec_t *) \
|
|
|
|
((char *)(block) + \
|
2008-10-30 06:14:34 +00:00
|
|
|
XFS_BMBT_BLOCK_LEN(mp) + \
|
2008-10-30 06:11:40 +00:00
|
|
|
((index) - 1) * sizeof(xfs_bmbt_rec_t)))
|
|
|
|
|
|
|
|
#define XFS_BMBT_KEY_ADDR(mp, block, index) \
|
|
|
|
((xfs_bmbt_key_t *) \
|
|
|
|
((char *)(block) + \
|
2008-10-30 06:14:34 +00:00
|
|
|
XFS_BMBT_BLOCK_LEN(mp) + \
|
2008-10-30 06:11:40 +00:00
|
|
|
((index) - 1) * sizeof(xfs_bmbt_key_t)))
|
|
|
|
|
|
|
|
#define XFS_BMBT_PTR_ADDR(mp, block, index, maxrecs) \
|
|
|
|
((xfs_bmbt_ptr_t *) \
|
|
|
|
((char *)(block) + \
|
2008-10-30 06:14:34 +00:00
|
|
|
XFS_BMBT_BLOCK_LEN(mp) + \
|
2008-10-30 06:11:40 +00:00
|
|
|
(maxrecs) * sizeof(xfs_bmbt_key_t) + \
|
|
|
|
((index) - 1) * sizeof(xfs_bmbt_ptr_t)))
|
|
|
|
|
|
|
|
#define XFS_BMDR_REC_ADDR(block, index) \
|
|
|
|
((xfs_bmdr_rec_t *) \
|
|
|
|
((char *)(block) + \
|
|
|
|
sizeof(struct xfs_bmdr_block) + \
|
|
|
|
((index) - 1) * sizeof(xfs_bmdr_rec_t)))
|
|
|
|
|
|
|
|
#define XFS_BMDR_KEY_ADDR(block, index) \
|
|
|
|
((xfs_bmdr_key_t *) \
|
|
|
|
((char *)(block) + \
|
|
|
|
sizeof(struct xfs_bmdr_block) + \
|
|
|
|
((index) - 1) * sizeof(xfs_bmdr_key_t)))
|
|
|
|
|
|
|
|
#define XFS_BMDR_PTR_ADDR(block, index, maxrecs) \
|
|
|
|
((xfs_bmdr_ptr_t *) \
|
|
|
|
((char *)(block) + \
|
|
|
|
sizeof(struct xfs_bmdr_block) + \
|
|
|
|
(maxrecs) * sizeof(xfs_bmdr_key_t) + \
|
|
|
|
((index) - 1) * sizeof(xfs_bmdr_ptr_t)))
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* These are to be used when we know the size of the block and
|
|
|
|
* we don't have a cursor.
|
|
|
|
*/
|
2008-10-30 06:11:40 +00:00
|
|
|
#define XFS_BMAP_BROOT_PTR_ADDR(mp, bb, i, sz) \
|
|
|
|
XFS_BMBT_PTR_ADDR(mp, bb, i, xfs_bmbt_maxrecs(mp, sz, 0))
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2013-04-21 19:53:46 +00:00
|
|
|
#define XFS_BMAP_BROOT_SPACE_CALC(mp, nrecs) \
|
|
|
|
(int)(XFS_BMBT_BLOCK_LEN(mp) + \
|
2005-11-02 03:38:42 +00:00
|
|
|
((nrecs) * (sizeof(xfs_bmbt_key_t) + sizeof(xfs_bmbt_ptr_t))))
|
|
|
|
|
2013-04-21 19:53:46 +00:00
|
|
|
#define XFS_BMAP_BROOT_SPACE(mp, bb) \
|
|
|
|
(XFS_BMAP_BROOT_SPACE_CALC(mp, be16_to_cpu((bb)->bb_numrecs)))
|
2005-11-02 03:38:42 +00:00
|
|
|
#define XFS_BMDR_SPACE_CALC(nrecs) \
|
|
|
|
(int)(sizeof(xfs_bmdr_block_t) + \
|
|
|
|
((nrecs) * (sizeof(xfs_bmbt_key_t) + sizeof(xfs_bmbt_ptr_t))))
|
2012-03-27 20:40:26 +00:00
|
|
|
#define XFS_BMAP_BMDR_SPACE(bb) \
|
|
|
|
(XFS_BMDR_SPACE_CALC(be16_to_cpu((bb)->bb_numrecs)))
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Maximum number of bmap btree levels.
|
|
|
|
*/
|
2005-11-02 03:38:42 +00:00
|
|
|
#define XFS_BM_MAXLEVELS(mp,w) ((mp)->m_bm_maxlevels[(w)])
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Prototypes for xfs_bmap.c to call.
|
|
|
|
*/
|
2013-04-21 19:53:46 +00:00
|
|
|
extern void xfs_bmdr_to_bmbt(struct xfs_inode *, xfs_bmdr_block_t *, int,
|
2008-10-30 06:14:34 +00:00
|
|
|
struct xfs_btree_block *, int);
|
2007-08-16 06:23:40 +00:00
|
|
|
extern void xfs_bmbt_get_all(xfs_bmbt_rec_host_t *r, xfs_bmbt_irec_t *s);
|
|
|
|
extern xfs_filblks_t xfs_bmbt_get_blockcount(xfs_bmbt_rec_host_t *r);
|
|
|
|
extern xfs_fsblock_t xfs_bmbt_get_startblock(xfs_bmbt_rec_host_t *r);
|
|
|
|
extern xfs_fileoff_t xfs_bmbt_get_startoff(xfs_bmbt_rec_host_t *r);
|
|
|
|
extern xfs_exntst_t xfs_bmbt_get_state(xfs_bmbt_rec_host_t *r);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-11-02 03:38:42 +00:00
|
|
|
extern xfs_filblks_t xfs_bmbt_disk_get_blockcount(xfs_bmbt_rec_t *r);
|
|
|
|
extern xfs_fileoff_t xfs_bmbt_disk_get_startoff(xfs_bmbt_rec_t *r);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-08-16 06:23:40 +00:00
|
|
|
extern void xfs_bmbt_set_all(xfs_bmbt_rec_host_t *r, xfs_bmbt_irec_t *s);
|
|
|
|
extern void xfs_bmbt_set_allf(xfs_bmbt_rec_host_t *r, xfs_fileoff_t o,
|
2005-11-02 03:38:42 +00:00
|
|
|
xfs_fsblock_t b, xfs_filblks_t c, xfs_exntst_t v);
|
2007-08-16 06:23:40 +00:00
|
|
|
extern void xfs_bmbt_set_blockcount(xfs_bmbt_rec_host_t *r, xfs_filblks_t v);
|
|
|
|
extern void xfs_bmbt_set_startblock(xfs_bmbt_rec_host_t *r, xfs_fsblock_t v);
|
|
|
|
extern void xfs_bmbt_set_startoff(xfs_bmbt_rec_host_t *r, xfs_fileoff_t v);
|
|
|
|
extern void xfs_bmbt_set_state(xfs_bmbt_rec_host_t *r, xfs_exntst_t v);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-11-02 03:38:42 +00:00
|
|
|
extern void xfs_bmbt_disk_set_allf(xfs_bmbt_rec_t *r, xfs_fileoff_t o,
|
|
|
|
xfs_fsblock_t b, xfs_filblks_t c, xfs_exntst_t v);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-10-30 06:14:34 +00:00
|
|
|
extern void xfs_bmbt_to_bmdr(struct xfs_mount *, struct xfs_btree_block *, int,
|
2008-10-30 06:11:19 +00:00
|
|
|
xfs_bmdr_block_t *, int);
|
|
|
|
|
|
|
|
extern int xfs_bmbt_get_maxrecs(struct xfs_btree_cur *, int level);
|
2014-04-14 08:58:51 +00:00
|
|
|
extern int xfs_bmdr_maxrecs(int blocklen, int leaf);
|
2008-10-30 06:11:19 +00:00
|
|
|
extern int xfs_bmbt_maxrecs(struct xfs_mount *, int blocklen, int leaf);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2013-08-30 00:23:44 +00:00
|
|
|
extern int xfs_bmbt_change_owner(struct xfs_trans *tp, struct xfs_inode *ip,
|
xfs: recovery of swap extents operations for CRC filesystems
This is the recovery side of the btree block owner change operation
performed by swapext on CRC enabled filesystems. We detect that an
owner change is needed by the flag that has been placed on the inode
log format flag field. Because the inode recovery is being replayed
after the buffers that make up the BMBT in the given checkpoint, we
can walk all the buffers and directly modify them when we see the
flag set on an inode.
Because the inode can be relogged and hence present in multiple
chekpoints with the "change owner" flag set, we could do multiple
passes across the inode to do this change. While this isn't optimal,
we can't directly ignore the flag as there may be multiple
independent swap extent operations being replayed on the same inode
in different checkpoints so we can't ignore them.
Further, because the owner change operation uses ordered buffers, we
might have buffers that are newer on disk than the current
checkpoint and so already have the owner changed in them. Hence we
cannot just peek at a buffer in the tree and check that it has the
correct owner and assume that the change was completed.
So, for the moment just brute force the owner change every time we
see an inode with the flag set. Note that we have to be careful here
because the owner of the buffers may point to either the old owner
or the new owner. Currently the verifier can't verify the owner
directly, so there is no failure case here right now. If we verify
the owner exactly in future, then we'll have to take this into
account.
This was tested in terms of normal operation via xfstests - all of
the fsr tests now pass without failure. however, we really need to
modify xfs/227 to stress v3 inodes correctly to ensure we fully
cover this case for v5 filesystems.
In terms of recovery testing, I used a hacked version of xfs_fsr
that held the temp inode open for a few seconds before exiting so
that the filesystem could be shut down with an open owner change
recovery flags set on at least the temp inode. fsr leaves the temp
inode unlinked and in btree format, so this was necessary for the
owner change to be reliably replayed.
logprint confirmed the tmp inode in the log had the correct flag set:
INO: cnt:3 total:3 a:0x69e9e0 len:56 a:0x69ea20 len:176 a:0x69eae0 len:88
INODE: #regs:3 ino:0x44 flags:0x209 dsize:88
^^^^^
0x200 is set, indicating a data fork owner change needed to be
replayed on inode 0x44. A printk in the revoery code confirmed that
the inode change was recovered:
XFS (vdc): Mounting Filesystem
XFS (vdc): Starting recovery (logdev: internal)
recovering owner change ino 0x44
XFS (vdc): Version 5 superblock detected. This kernel L support enabled!
Use of these features in this kernel is at your own risk!
XFS (vdc): Ending recovery (logdev: internal)
The script used to test this was:
$ cat ./recovery-fsr.sh
#!/bin/bash
dev=/dev/vdc
mntpt=/mnt/scratch
testfile=$mntpt/testfile
umount $mntpt
mkfs.xfs -f -m crc=1 $dev
mount $dev $mntpt
chmod 777 $mntpt
for i in `seq 10000 -1 0`; do
xfs_io -f -d -c "pwrite $(($i * 4096)) 4096" $testfile > /dev/null 2>&1
done
xfs_bmap -vp $testfile |head -20
xfs_fsr -d -v $testfile &
sleep 10
/home/dave/src/xfstests-dev/src/godown -f $mntpt
wait
umount $mntpt
xfs_logprint -t $dev |tail -20
time mount $dev $mntpt
xfs_bmap -vp $testfile
umount $mntpt
$
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2013-08-30 00:23:45 +00:00
|
|
|
int whichfork, xfs_ino_t new_owner,
|
|
|
|
struct list_head *buffer_list);
|
2013-08-30 00:23:44 +00:00
|
|
|
|
2008-10-30 05:53:59 +00:00
|
|
|
extern struct xfs_btree_cur *xfs_bmbt_init_cursor(struct xfs_mount *,
|
|
|
|
struct xfs_trans *, struct xfs_inode *, int);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif /* __XFS_BMAP_BTREE_H__ */
|