2018-06-06 10:42:14 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2016-08-03 09:33:42 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Oracle. All Rights Reserved.
|
|
|
|
* Author: Darrick J. Wong <darrick.wong@oracle.com>
|
|
|
|
*/
|
|
|
|
#ifndef __XFS_RMAP_H__
|
|
|
|
#define __XFS_RMAP_H__
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
xfs_rmap_ino_bmbt_owner(
|
|
|
|
struct xfs_owner_info *oi,
|
|
|
|
xfs_ino_t ino,
|
|
|
|
int whichfork)
|
|
|
|
{
|
|
|
|
oi->oi_owner = ino;
|
|
|
|
oi->oi_offset = 0;
|
|
|
|
oi->oi_flags = XFS_OWNER_INFO_BMBT_BLOCK;
|
|
|
|
if (whichfork == XFS_ATTR_FORK)
|
|
|
|
oi->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
xfs_rmap_ino_owner(
|
|
|
|
struct xfs_owner_info *oi,
|
|
|
|
xfs_ino_t ino,
|
|
|
|
int whichfork,
|
|
|
|
xfs_fileoff_t offset)
|
|
|
|
{
|
|
|
|
oi->oi_owner = ino;
|
|
|
|
oi->oi_offset = offset;
|
|
|
|
oi->oi_flags = 0;
|
|
|
|
if (whichfork == XFS_ATTR_FORK)
|
|
|
|
oi->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
|
|
|
|
}
|
|
|
|
|
2017-12-08 11:07:27 +08:00
|
|
|
static inline bool
|
|
|
|
xfs_rmap_should_skip_owner_update(
|
2018-12-13 00:46:23 +08:00
|
|
|
const struct xfs_owner_info *oi)
|
2017-12-08 11:07:27 +08:00
|
|
|
{
|
|
|
|
return oi->oi_owner == XFS_RMAP_OWN_NULL;
|
|
|
|
}
|
|
|
|
|
2016-08-03 09:33:43 +08:00
|
|
|
/* Reverse mapping functions. */
|
|
|
|
|
|
|
|
struct xfs_buf;
|
|
|
|
|
2016-08-03 09:36:07 +08:00
|
|
|
static inline __u64
|
|
|
|
xfs_rmap_irec_offset_pack(
|
|
|
|
const struct xfs_rmap_irec *irec)
|
|
|
|
{
|
|
|
|
__u64 x;
|
|
|
|
|
|
|
|
x = XFS_RMAP_OFF(irec->rm_offset);
|
|
|
|
if (irec->rm_flags & XFS_RMAP_ATTR_FORK)
|
|
|
|
x |= XFS_RMAP_OFF_ATTR_FORK;
|
|
|
|
if (irec->rm_flags & XFS_RMAP_BMBT_BLOCK)
|
|
|
|
x |= XFS_RMAP_OFF_BMBT_BLOCK;
|
|
|
|
if (irec->rm_flags & XFS_RMAP_UNWRITTEN)
|
|
|
|
x |= XFS_RMAP_OFF_UNWRITTEN;
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
xfs_rmap_irec_offset_unpack(
|
|
|
|
__u64 offset,
|
|
|
|
struct xfs_rmap_irec *irec)
|
|
|
|
{
|
|
|
|
if (offset & ~(XFS_RMAP_OFF_MASK | XFS_RMAP_OFF_FLAGS))
|
|
|
|
return -EFSCORRUPTED;
|
|
|
|
irec->rm_offset = XFS_RMAP_OFF(offset);
|
|
|
|
if (offset & XFS_RMAP_OFF_ATTR_FORK)
|
|
|
|
irec->rm_flags |= XFS_RMAP_ATTR_FORK;
|
|
|
|
if (offset & XFS_RMAP_OFF_BMBT_BLOCK)
|
|
|
|
irec->rm_flags |= XFS_RMAP_BMBT_BLOCK;
|
|
|
|
if (offset & XFS_RMAP_OFF_UNWRITTEN)
|
|
|
|
irec->rm_flags |= XFS_RMAP_UNWRITTEN;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
xfs_owner_info_unpack(
|
2018-12-13 00:46:23 +08:00
|
|
|
const struct xfs_owner_info *oinfo,
|
|
|
|
uint64_t *owner,
|
|
|
|
uint64_t *offset,
|
|
|
|
unsigned int *flags)
|
2016-08-03 09:36:07 +08:00
|
|
|
{
|
2018-12-13 00:46:23 +08:00
|
|
|
unsigned int r = 0;
|
2016-08-03 09:36:07 +08:00
|
|
|
|
|
|
|
*owner = oinfo->oi_owner;
|
|
|
|
*offset = oinfo->oi_offset;
|
|
|
|
if (oinfo->oi_flags & XFS_OWNER_INFO_ATTR_FORK)
|
|
|
|
r |= XFS_RMAP_ATTR_FORK;
|
|
|
|
if (oinfo->oi_flags & XFS_OWNER_INFO_BMBT_BLOCK)
|
|
|
|
r |= XFS_RMAP_BMBT_BLOCK;
|
|
|
|
*flags = r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
xfs_owner_info_pack(
|
|
|
|
struct xfs_owner_info *oinfo,
|
|
|
|
uint64_t owner,
|
|
|
|
uint64_t offset,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
oinfo->oi_owner = owner;
|
|
|
|
oinfo->oi_offset = XFS_RMAP_OFF(offset);
|
|
|
|
oinfo->oi_flags = 0;
|
|
|
|
if (flags & XFS_RMAP_ATTR_FORK)
|
|
|
|
oinfo->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
|
|
|
|
if (flags & XFS_RMAP_BMBT_BLOCK)
|
|
|
|
oinfo->oi_flags |= XFS_OWNER_INFO_BMBT_BLOCK;
|
|
|
|
}
|
|
|
|
|
2016-08-03 09:33:43 +08:00
|
|
|
int xfs_rmap_alloc(struct xfs_trans *tp, struct xfs_buf *agbp,
|
|
|
|
xfs_agnumber_t agno, xfs_agblock_t bno, xfs_extlen_t len,
|
2018-12-13 00:46:23 +08:00
|
|
|
const struct xfs_owner_info *oinfo);
|
2016-08-03 09:33:43 +08:00
|
|
|
int xfs_rmap_free(struct xfs_trans *tp, struct xfs_buf *agbp,
|
|
|
|
xfs_agnumber_t agno, xfs_agblock_t bno, xfs_extlen_t len,
|
2018-12-13 00:46:23 +08:00
|
|
|
const struct xfs_owner_info *oinfo);
|
2016-08-03 09:33:43 +08:00
|
|
|
|
2016-08-03 09:39:05 +08:00
|
|
|
int xfs_rmap_lookup_le(struct xfs_btree_cur *cur, xfs_agblock_t bno,
|
|
|
|
xfs_extlen_t len, uint64_t owner, uint64_t offset,
|
|
|
|
unsigned int flags, int *stat);
|
|
|
|
int xfs_rmap_lookup_eq(struct xfs_btree_cur *cur, xfs_agblock_t bno,
|
|
|
|
xfs_extlen_t len, uint64_t owner, uint64_t offset,
|
|
|
|
unsigned int flags, int *stat);
|
2016-08-03 10:03:58 +08:00
|
|
|
int xfs_rmap_insert(struct xfs_btree_cur *rcur, xfs_agblock_t agbno,
|
|
|
|
xfs_extlen_t len, uint64_t owner, uint64_t offset,
|
|
|
|
unsigned int flags);
|
2016-08-03 09:39:05 +08:00
|
|
|
int xfs_rmap_get_rec(struct xfs_btree_cur *cur, struct xfs_rmap_irec *irec,
|
|
|
|
int *stat);
|
|
|
|
|
2016-08-03 09:42:39 +08:00
|
|
|
typedef int (*xfs_rmap_query_range_fn)(
|
|
|
|
struct xfs_btree_cur *cur,
|
|
|
|
struct xfs_rmap_irec *rec,
|
|
|
|
void *priv);
|
|
|
|
|
|
|
|
int xfs_rmap_query_range(struct xfs_btree_cur *cur,
|
|
|
|
struct xfs_rmap_irec *low_rec, struct xfs_rmap_irec *high_rec,
|
|
|
|
xfs_rmap_query_range_fn fn, void *priv);
|
2017-03-29 05:56:35 +08:00
|
|
|
int xfs_rmap_query_all(struct xfs_btree_cur *cur, xfs_rmap_query_range_fn fn,
|
|
|
|
void *priv);
|
2016-08-03 09:42:39 +08:00
|
|
|
|
2016-08-03 10:04:45 +08:00
|
|
|
enum xfs_rmap_intent_type {
|
|
|
|
XFS_RMAP_MAP,
|
|
|
|
XFS_RMAP_MAP_SHARED,
|
|
|
|
XFS_RMAP_UNMAP,
|
|
|
|
XFS_RMAP_UNMAP_SHARED,
|
|
|
|
XFS_RMAP_CONVERT,
|
|
|
|
XFS_RMAP_CONVERT_SHARED,
|
|
|
|
XFS_RMAP_ALLOC,
|
|
|
|
XFS_RMAP_FREE,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct xfs_rmap_intent {
|
|
|
|
struct list_head ri_list;
|
|
|
|
enum xfs_rmap_intent_type ri_type;
|
2017-06-17 02:00:05 +08:00
|
|
|
uint64_t ri_owner;
|
2016-08-03 10:04:45 +08:00
|
|
|
int ri_whichfork;
|
|
|
|
struct xfs_bmbt_irec ri_bmap;
|
|
|
|
};
|
|
|
|
|
xfs: propagate bmap updates to rmapbt
When we map, unmap, or convert an extent in a file's data or attr
fork, schedule a respective update in the rmapbt. Previous versions
of this patch required a 1:1 correspondence between bmap and rmap,
but this is no longer true as we now have ability to make interval
queries against the rmapbt.
We use the deferred operations code to handle redo operations
atomically and deadlock free. This plumbs in all five rmap actions
(map, unmap, convert extent, alloc, free); we'll use the first three
now for file data, and reflink will want the last two. We also add
an error injection site to test log recovery.
Finally, we need to fix the bmap shift extent code to adjust the
rmaps correctly.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-08-03 10:16:05 +08:00
|
|
|
/* functions for updating the rmapbt based on bmbt map/unmap operations */
|
2018-08-01 22:20:34 +08:00
|
|
|
int xfs_rmap_map_extent(struct xfs_trans *tp, struct xfs_inode *ip,
|
|
|
|
int whichfork, struct xfs_bmbt_irec *imap);
|
|
|
|
int xfs_rmap_unmap_extent(struct xfs_trans *tp, struct xfs_inode *ip,
|
|
|
|
int whichfork, struct xfs_bmbt_irec *imap);
|
|
|
|
int xfs_rmap_convert_extent(struct xfs_mount *mp, struct xfs_trans *tp,
|
xfs: propagate bmap updates to rmapbt
When we map, unmap, or convert an extent in a file's data or attr
fork, schedule a respective update in the rmapbt. Previous versions
of this patch required a 1:1 correspondence between bmap and rmap,
but this is no longer true as we now have ability to make interval
queries against the rmapbt.
We use the deferred operations code to handle redo operations
atomically and deadlock free. This plumbs in all five rmap actions
(map, unmap, convert extent, alloc, free); we'll use the first three
now for file data, and reflink will want the last two. We also add
an error injection site to test log recovery.
Finally, we need to fix the bmap shift extent code to adjust the
rmaps correctly.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-08-03 10:16:05 +08:00
|
|
|
struct xfs_inode *ip, int whichfork,
|
|
|
|
struct xfs_bmbt_irec *imap);
|
2018-08-01 22:20:34 +08:00
|
|
|
int xfs_rmap_alloc_extent(struct xfs_trans *tp, xfs_agnumber_t agno,
|
|
|
|
xfs_agblock_t bno, xfs_extlen_t len, uint64_t owner);
|
|
|
|
int xfs_rmap_free_extent(struct xfs_trans *tp, xfs_agnumber_t agno,
|
|
|
|
xfs_agblock_t bno, xfs_extlen_t len, uint64_t owner);
|
xfs: propagate bmap updates to rmapbt
When we map, unmap, or convert an extent in a file's data or attr
fork, schedule a respective update in the rmapbt. Previous versions
of this patch required a 1:1 correspondence between bmap and rmap,
but this is no longer true as we now have ability to make interval
queries against the rmapbt.
We use the deferred operations code to handle redo operations
atomically and deadlock free. This plumbs in all five rmap actions
(map, unmap, convert extent, alloc, free); we'll use the first three
now for file data, and reflink will want the last two. We also add
an error injection site to test log recovery.
Finally, we need to fix the bmap shift extent code to adjust the
rmaps correctly.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-08-03 10:16:05 +08:00
|
|
|
|
|
|
|
void xfs_rmap_finish_one_cleanup(struct xfs_trans *tp,
|
|
|
|
struct xfs_btree_cur *rcur, int error);
|
|
|
|
int xfs_rmap_finish_one(struct xfs_trans *tp, enum xfs_rmap_intent_type type,
|
2017-06-17 02:00:05 +08:00
|
|
|
uint64_t owner, int whichfork, xfs_fileoff_t startoff,
|
xfs: propagate bmap updates to rmapbt
When we map, unmap, or convert an extent in a file's data or attr
fork, schedule a respective update in the rmapbt. Previous versions
of this patch required a 1:1 correspondence between bmap and rmap,
but this is no longer true as we now have ability to make interval
queries against the rmapbt.
We use the deferred operations code to handle redo operations
atomically and deadlock free. This plumbs in all five rmap actions
(map, unmap, convert extent, alloc, free); we'll use the first three
now for file data, and reflink will want the last two. We also add
an error injection site to test log recovery.
Finally, we need to fix the bmap shift extent code to adjust the
rmaps correctly.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-08-03 10:16:05 +08:00
|
|
|
xfs_fsblock_t startblock, xfs_filblks_t blockcount,
|
|
|
|
xfs_exntst_t state, struct xfs_btree_cur **pcur);
|
|
|
|
|
2016-10-04 00:11:48 +08:00
|
|
|
int xfs_rmap_find_left_neighbor(struct xfs_btree_cur *cur, xfs_agblock_t bno,
|
|
|
|
uint64_t owner, uint64_t offset, unsigned int flags,
|
|
|
|
struct xfs_rmap_irec *irec, int *stat);
|
|
|
|
int xfs_rmap_lookup_le_range(struct xfs_btree_cur *cur, xfs_agblock_t bno,
|
|
|
|
uint64_t owner, uint64_t offset, unsigned int flags,
|
|
|
|
struct xfs_rmap_irec *irec, int *stat);
|
2017-03-29 05:56:37 +08:00
|
|
|
int xfs_rmap_compare(const struct xfs_rmap_irec *a,
|
|
|
|
const struct xfs_rmap_irec *b);
|
2017-06-17 02:00:07 +08:00
|
|
|
union xfs_btree_rec;
|
|
|
|
int xfs_rmap_btrec_to_irec(union xfs_btree_rec *rec,
|
|
|
|
struct xfs_rmap_irec *irec);
|
2018-01-17 10:52:13 +08:00
|
|
|
int xfs_rmap_has_record(struct xfs_btree_cur *cur, xfs_agblock_t bno,
|
|
|
|
xfs_extlen_t len, bool *exists);
|
|
|
|
int xfs_rmap_record_exists(struct xfs_btree_cur *cur, xfs_agblock_t bno,
|
2018-12-13 00:46:23 +08:00
|
|
|
xfs_extlen_t len, const struct xfs_owner_info *oinfo,
|
2018-01-17 10:52:13 +08:00
|
|
|
bool *has_rmap);
|
2018-05-10 01:02:02 +08:00
|
|
|
int xfs_rmap_has_other_keys(struct xfs_btree_cur *cur, xfs_agblock_t bno,
|
2018-12-13 00:46:23 +08:00
|
|
|
xfs_extlen_t len, const struct xfs_owner_info *oinfo,
|
2018-05-10 01:02:02 +08:00
|
|
|
bool *has_rmap);
|
|
|
|
int xfs_rmap_map_raw(struct xfs_btree_cur *cur, struct xfs_rmap_irec *rmap);
|
2016-10-04 00:11:48 +08:00
|
|
|
|
2018-12-13 00:46:23 +08:00
|
|
|
extern const struct xfs_owner_info XFS_RMAP_OINFO_SKIP_UPDATE;
|
|
|
|
extern const struct xfs_owner_info XFS_RMAP_OINFO_ANY_OWNER;
|
|
|
|
extern const struct xfs_owner_info XFS_RMAP_OINFO_FS;
|
|
|
|
extern const struct xfs_owner_info XFS_RMAP_OINFO_LOG;
|
|
|
|
extern const struct xfs_owner_info XFS_RMAP_OINFO_AG;
|
|
|
|
extern const struct xfs_owner_info XFS_RMAP_OINFO_INOBT;
|
|
|
|
extern const struct xfs_owner_info XFS_RMAP_OINFO_INODES;
|
|
|
|
extern const struct xfs_owner_info XFS_RMAP_OINFO_REFC;
|
|
|
|
extern const struct xfs_owner_info XFS_RMAP_OINFO_COW;
|
|
|
|
|
2016-08-03 09:33:42 +08:00
|
|
|
#endif /* __XFS_RMAP_H__ */
|