提交 c2066e26 编写于 作者: C Christoph Hellwig

xfs: avoid usage of struct xfs_dir2_data

In most places we can simply pass around and use the struct xfs_dir2_data_hdr,
which is the first and most important member of struct xfs_dir2_data instead
of the full structure.
Signed-off-by: NChristoph Hellwig <hch@lst.de>
Reviewed-by: NAlex Elder <aelder@sgi.com>
Reviewed-by: NDave Chinner <dchinner@redhat.com>
上级 a64b0417
......@@ -2079,16 +2079,13 @@ xfs_da_do_buf(
* For read_buf, check the magic number.
*/
if (caller == 1) {
xfs_dir2_data_t *data;
xfs_dir2_free_t *free;
xfs_da_blkinfo_t *info;
xfs_dir2_data_hdr_t *hdr = rbp->data;
xfs_dir2_free_t *free = rbp->data;
xfs_da_blkinfo_t *info = rbp->data;
uint magic, magic1;
info = rbp->data;
data = rbp->data;
free = rbp->data;
magic = be16_to_cpu(info->magic);
magic1 = be32_to_cpu(data->hdr.magic);
magic1 = be32_to_cpu(hdr->magic);
if (unlikely(
XFS_TEST_ERROR((magic != XFS_DA_NODE_MAGIC) &&
(magic != XFS_ATTR_LEAF_MAGIC) &&
......
......@@ -282,7 +282,7 @@ xfs_dir2_block_addname(
* This needs to happen before the next call to use_free.
*/
if (needscan) {
xfs_dir2_data_freescan(mp, (xfs_dir2_data_t *)hdr, &needlog);
xfs_dir2_data_freescan(mp, hdr, &needlog);
needscan = 0;
}
}
......@@ -331,8 +331,7 @@ xfs_dir2_block_addname(
* This needs to happen before the next call to use_free.
*/
if (needscan) {
xfs_dir2_data_freescan(mp, (xfs_dir2_data_t *)hdr,
&needlog);
xfs_dir2_data_freescan(mp, hdr, &needlog);
needscan = 0;
}
/*
......@@ -417,7 +416,7 @@ xfs_dir2_block_addname(
* Clean up the bestfree array and log the header, tail, and entry.
*/
if (needscan)
xfs_dir2_data_freescan(mp, (xfs_dir2_data_t *)hdr, &needlog);
xfs_dir2_data_freescan(mp, hdr, &needlog);
if (needlog)
xfs_dir2_data_log_header(tp, bp);
xfs_dir2_block_log_tail(tp, bp);
......@@ -783,7 +782,7 @@ xfs_dir2_block_removename(
* Fix up bestfree, log the header if necessary.
*/
if (needscan)
xfs_dir2_data_freescan(mp, (xfs_dir2_data_t *)hdr, &needlog);
xfs_dir2_data_freescan(mp, hdr, &needlog);
if (needlog)
xfs_dir2_data_log_header(tp, bp);
xfs_dir2_data_check(dp, bp);
......@@ -982,7 +981,7 @@ xfs_dir2_leaf_to_block(
* Scan the bestfree if we need it and log the data block header.
*/
if (needscan)
xfs_dir2_data_freescan(mp, (xfs_dir2_data_t *)hdr, &needlog);
xfs_dir2_data_freescan(mp, hdr, &needlog);
if (needlog)
xfs_dir2_data_log_header(tp, dbp);
/*
......@@ -1177,8 +1176,7 @@ xfs_dir2_sf_to_block(
*xfs_dir2_data_unused_tag_p(dup) = cpu_to_be16(
((char *)dup - (char *)hdr));
xfs_dir2_data_log_unused(tp, bp, dup);
(void)xfs_dir2_data_freeinsert((xfs_dir2_data_t *)hdr,
dup, &dummy);
xfs_dir2_data_freeinsert(hdr, dup, &dummy);
offset += be16_to_cpu(dup->length);
continue;
}
......
此差异已折叠。
......@@ -157,12 +157,10 @@ extern void xfs_dir2_data_check(struct xfs_inode *dp, struct xfs_dabuf *bp);
#else
#define xfs_dir2_data_check(dp,bp)
#endif
extern xfs_dir2_data_free_t *xfs_dir2_data_freefind(xfs_dir2_data_t *d,
xfs_dir2_data_unused_t *dup);
extern xfs_dir2_data_free_t *xfs_dir2_data_freeinsert(xfs_dir2_data_t *d,
extern xfs_dir2_data_free_t *xfs_dir2_data_freeinsert(xfs_dir2_data_hdr_t *hdr,
xfs_dir2_data_unused_t *dup, int *loghead);
extern void xfs_dir2_data_freescan(struct xfs_mount *mp, xfs_dir2_data_t *d,
int *loghead);
extern void xfs_dir2_data_freescan(struct xfs_mount *mp,
xfs_dir2_data_hdr_t *hdr, int *loghead);
extern int xfs_dir2_data_init(struct xfs_da_args *args, xfs_dir2_db_t blkno,
struct xfs_dabuf **bpp);
extern void xfs_dir2_data_log_entry(struct xfs_trans *tp, struct xfs_dabuf *bp,
......
......@@ -132,7 +132,7 @@ xfs_dir2_block_to_leaf(
*/
hdr->magic = cpu_to_be32(XFS_DIR2_DATA_MAGIC);
if (needscan)
xfs_dir2_data_freescan(mp, (xfs_dir2_data_t *)hdr, &needlog);
xfs_dir2_data_freescan(mp, hdr, &needlog);
/*
* Set up leaf tail and bests table.
*/
......@@ -278,7 +278,7 @@ xfs_dir2_leaf_addname(
{
__be16 *bestsp; /* freespace table in leaf */
int compact; /* need to compact leaves */
xfs_dir2_data_t *data; /* data block structure */
xfs_dir2_data_hdr_t *hdr; /* data block header */
xfs_dabuf_t *dbp; /* data block buffer */
xfs_dir2_data_entry_t *dep; /* data block entry */
xfs_inode_t *dp; /* incore directory inode */
......@@ -486,8 +486,8 @@ xfs_dir2_leaf_addname(
*/
else
xfs_dir2_leaf_log_bests(tp, lbp, use_block, use_block);
data = dbp->data;
bestsp[use_block] = data->hdr.bestfree[0].length;
hdr = dbp->data;
bestsp[use_block] = hdr->bestfree[0].length;
grown = 1;
}
/*
......@@ -501,7 +501,7 @@ xfs_dir2_leaf_addname(
xfs_da_brelse(tp, lbp);
return error;
}
data = dbp->data;
hdr = dbp->data;
grown = 0;
}
xfs_dir2_data_check(dp, dbp);
......@@ -509,14 +509,14 @@ xfs_dir2_leaf_addname(
* Point to the biggest freespace in our data block.
*/
dup = (xfs_dir2_data_unused_t *)
((char *)data + be16_to_cpu(data->hdr.bestfree[0].offset));
((char *)hdr + be16_to_cpu(hdr->bestfree[0].offset));
ASSERT(be16_to_cpu(dup->length) >= length);
needscan = needlog = 0;
/*
* Mark the initial part of our freespace in use for the new entry.
*/
xfs_dir2_data_use_free(tp, dbp, dup,
(xfs_dir2_data_aoff_t)((char *)dup - (char *)data), length,
(xfs_dir2_data_aoff_t)((char *)dup - (char *)hdr), length,
&needlog, &needscan);
/*
* Initialize our new entry (at last).
......@@ -526,12 +526,12 @@ xfs_dir2_leaf_addname(
dep->namelen = args->namelen;
memcpy(dep->name, args->name, dep->namelen);
tagp = xfs_dir2_data_entry_tag_p(dep);
*tagp = cpu_to_be16((char *)dep - (char *)data);
*tagp = cpu_to_be16((char *)dep - (char *)hdr);
/*
* Need to scan fix up the bestfree table.
*/
if (needscan)
xfs_dir2_data_freescan(mp, data, &needlog);
xfs_dir2_data_freescan(mp, hdr, &needlog);
/*
* Need to log the data block's header.
*/
......@@ -542,8 +542,8 @@ xfs_dir2_leaf_addname(
* If the bests table needs to be changed, do it.
* Log the change unless we've already done that.
*/
if (be16_to_cpu(bestsp[use_block]) != be16_to_cpu(data->hdr.bestfree[0].length)) {
bestsp[use_block] = data->hdr.bestfree[0].length;
if (be16_to_cpu(bestsp[use_block]) != be16_to_cpu(hdr->bestfree[0].length)) {
bestsp[use_block] = hdr->bestfree[0].length;
if (!grown)
xfs_dir2_leaf_log_bests(tp, lbp, use_block, use_block);
}
......@@ -786,6 +786,7 @@ xfs_dir2_leaf_getdents(
xfs_dir2_db_t curdb; /* db for current block */
xfs_dir2_off_t curoff; /* current overall offset */
xfs_dir2_data_t *data; /* data block structure */
xfs_dir2_data_hdr_t *hdr; /* data block header */
xfs_dir2_data_entry_t *dep; /* data entry */
xfs_dir2_data_unused_t *dup; /* unused entry */
int error = 0; /* error return value */
......@@ -1044,6 +1045,7 @@ xfs_dir2_leaf_getdents(
ASSERT(xfs_dir2_byte_to_db(mp, curoff) ==
curdb);
data = bp->data;
hdr = &data->hdr;
xfs_dir2_data_check(dp, bp);
/*
* Find our position in the block.
......@@ -1054,12 +1056,12 @@ xfs_dir2_leaf_getdents(
* Skip past the header.
*/
if (byteoff == 0)
curoff += (uint)sizeof(data->hdr);
curoff += (uint)sizeof(*hdr);
/*
* Skip past entries until we reach our offset.
*/
else {
while ((char *)ptr - (char *)data < byteoff) {
while ((char *)ptr - (char *)hdr < byteoff) {
dup = (xfs_dir2_data_unused_t *)ptr;
if (be16_to_cpu(dup->freetag)
......@@ -1080,8 +1082,8 @@ xfs_dir2_leaf_getdents(
curoff =
xfs_dir2_db_off_to_byte(mp,
xfs_dir2_byte_to_db(mp, curoff),
(char *)ptr - (char *)data);
if (ptr >= (char *)data + mp->m_dirblksize) {
(char *)ptr - (char *)hdr);
if (ptr >= (char *)hdr + mp->m_dirblksize) {
continue;
}
}
......@@ -1462,7 +1464,7 @@ xfs_dir2_leaf_removename(
xfs_da_args_t *args) /* operation arguments */
{
__be16 *bestsp; /* leaf block best freespace */
xfs_dir2_data_t *data; /* data block structure */
xfs_dir2_data_hdr_t *hdr; /* data block header */
xfs_dir2_db_t db; /* data block number */
xfs_dabuf_t *dbp; /* data block buffer */
xfs_dir2_data_entry_t *dep; /* data entry structure */
......@@ -1492,7 +1494,7 @@ xfs_dir2_leaf_removename(
tp = args->trans;
mp = dp->i_mount;
leaf = lbp->data;
data = dbp->data;
hdr = dbp->data;
xfs_dir2_data_check(dp, dbp);
/*
* Point to the leaf entry, use that to point to the data entry.
......@@ -1500,9 +1502,9 @@ xfs_dir2_leaf_removename(
lep = &leaf->ents[index];
db = xfs_dir2_dataptr_to_db(mp, be32_to_cpu(lep->address));
dep = (xfs_dir2_data_entry_t *)
((char *)data + xfs_dir2_dataptr_to_off(mp, be32_to_cpu(lep->address)));
((char *)hdr + xfs_dir2_dataptr_to_off(mp, be32_to_cpu(lep->address)));
needscan = needlog = 0;
oldbest = be16_to_cpu(data->hdr.bestfree[0].length);
oldbest = be16_to_cpu(hdr->bestfree[0].length);
ltp = xfs_dir2_leaf_tail_p(mp, leaf);
bestsp = xfs_dir2_leaf_bests_p(ltp);
ASSERT(be16_to_cpu(bestsp[db]) == oldbest);
......@@ -1510,7 +1512,7 @@ xfs_dir2_leaf_removename(
* Mark the former data entry unused.
*/
xfs_dir2_data_make_free(tp, dbp,
(xfs_dir2_data_aoff_t)((char *)dep - (char *)data),
(xfs_dir2_data_aoff_t)((char *)dep - (char *)hdr),
xfs_dir2_data_entsize(dep->namelen), &needlog, &needscan);
/*
* We just mark the leaf entry stale by putting a null in it.
......@@ -1524,23 +1526,23 @@ xfs_dir2_leaf_removename(
* log the data block header if necessary.
*/
if (needscan)
xfs_dir2_data_freescan(mp, data, &needlog);
xfs_dir2_data_freescan(mp, hdr, &needlog);
if (needlog)
xfs_dir2_data_log_header(tp, dbp);
/*
* If the longest freespace in the data block has changed,
* put the new value in the bests table and log that.
*/
if (be16_to_cpu(data->hdr.bestfree[0].length) != oldbest) {
bestsp[db] = data->hdr.bestfree[0].length;
if (be16_to_cpu(hdr->bestfree[0].length) != oldbest) {
bestsp[db] = hdr->bestfree[0].length;
xfs_dir2_leaf_log_bests(tp, lbp, db, db);
}
xfs_dir2_data_check(dp, dbp);
/*
* If the data block is now empty then get rid of the data block.
*/
if (be16_to_cpu(data->hdr.bestfree[0].length) ==
mp->m_dirblksize - (uint)sizeof(data->hdr)) {
if (be16_to_cpu(hdr->bestfree[0].length) ==
mp->m_dirblksize - (uint)sizeof(*hdr)) {
ASSERT(db != mp->m_dirdatablk);
if ((error = xfs_dir2_shrink_inode(args, db, dbp))) {
/*
......@@ -1711,9 +1713,6 @@ xfs_dir2_leaf_trim_data(
xfs_dir2_db_t db) /* data block number */
{
__be16 *bestsp; /* leaf bests table */
#ifdef DEBUG
xfs_dir2_data_t *data; /* data block structure */
#endif
xfs_dabuf_t *dbp; /* data block buffer */
xfs_inode_t *dp; /* incore directory inode */
int error; /* error return value */
......@@ -1732,20 +1731,21 @@ xfs_dir2_leaf_trim_data(
XFS_DATA_FORK))) {
return error;
}
#ifdef DEBUG
data = dbp->data;
ASSERT(be32_to_cpu(data->hdr.magic) == XFS_DIR2_DATA_MAGIC);
#endif
/* this seems to be an error
* data is only valid if DEBUG is defined?
* RMC 09/08/1999
*/
leaf = lbp->data;
ltp = xfs_dir2_leaf_tail_p(mp, leaf);
ASSERT(be16_to_cpu(data->hdr.bestfree[0].length) ==
mp->m_dirblksize - (uint)sizeof(data->hdr));
#ifdef DEBUG
{
struct xfs_dir2_data_hdr *hdr = dbp->data;
ASSERT(be32_to_cpu(hdr->magic) == XFS_DIR2_DATA_MAGIC);
ASSERT(be16_to_cpu(hdr->bestfree[0].length) ==
mp->m_dirblksize - (uint)sizeof(*hdr));
ASSERT(db == be32_to_cpu(ltp->bestcount) - 1);
}
#endif
/*
* Get rid of the data block.
*/
......
......@@ -842,7 +842,7 @@ xfs_dir2_leafn_remove(
xfs_da_state_blk_t *dblk, /* data block */
int *rval) /* resulting block needs join */
{
xfs_dir2_data_t *data; /* data block structure */
xfs_dir2_data_hdr_t *hdr; /* data block header */
xfs_dir2_db_t db; /* data block number */
xfs_dabuf_t *dbp; /* data block buffer */
xfs_dir2_data_entry_t *dep; /* data block entry */
......@@ -887,9 +887,9 @@ xfs_dir2_leafn_remove(
* in the data block in case it changes.
*/
dbp = dblk->bp;
data = dbp->data;
dep = (xfs_dir2_data_entry_t *)((char *)data + off);
longest = be16_to_cpu(data->hdr.bestfree[0].length);
hdr = dbp->data;
dep = (xfs_dir2_data_entry_t *)((char *)hdr + off);
longest = be16_to_cpu(hdr->bestfree[0].length);
needlog = needscan = 0;
xfs_dir2_data_make_free(tp, dbp, off,
xfs_dir2_data_entsize(dep->namelen), &needlog, &needscan);
......@@ -898,7 +898,7 @@ xfs_dir2_leafn_remove(
* Log the data block header if needed.
*/
if (needscan)
xfs_dir2_data_freescan(mp, data, &needlog);
xfs_dir2_data_freescan(mp, hdr, &needlog);
if (needlog)
xfs_dir2_data_log_header(tp, dbp);
xfs_dir2_data_check(dp, dbp);
......@@ -906,7 +906,7 @@ xfs_dir2_leafn_remove(
* If the longest data block freespace changes, need to update
* the corresponding freeblock entry.
*/
if (longest < be16_to_cpu(data->hdr.bestfree[0].length)) {
if (longest < be16_to_cpu(hdr->bestfree[0].length)) {
int error; /* error return value */
xfs_dabuf_t *fbp; /* freeblock buffer */
xfs_dir2_db_t fdb; /* freeblock block number */
......@@ -932,19 +932,19 @@ xfs_dir2_leafn_remove(
* Calculate which entry we need to fix.
*/
findex = xfs_dir2_db_to_fdindex(mp, db);
longest = be16_to_cpu(data->hdr.bestfree[0].length);
longest = be16_to_cpu(hdr->bestfree[0].length);
/*
* If the data block is now empty we can get rid of it
* (usually).
*/
if (longest == mp->m_dirblksize - (uint)sizeof(data->hdr)) {
if (longest == mp->m_dirblksize - (uint)sizeof(*hdr)) {
/*
* Try to punch out the data block.
*/
error = xfs_dir2_shrink_inode(args, db, dbp);
if (error == 0) {
dblk->bp = NULL;
data = NULL;
hdr = NULL;
}
/*
* We can get ENOSPC if there's no space reservation.
......@@ -960,7 +960,7 @@ xfs_dir2_leafn_remove(
* If we got rid of the data block, we can eliminate that entry
* in the free block.
*/
if (data == NULL) {
if (hdr == NULL) {
/*
* One less used entry in the free table.
*/
......@@ -1356,7 +1356,7 @@ xfs_dir2_node_addname_int(
xfs_da_args_t *args, /* operation arguments */
xfs_da_state_blk_t *fblk) /* optional freespace block */
{
xfs_dir2_data_t *data; /* data block structure */
xfs_dir2_data_hdr_t *hdr; /* data block header */
xfs_dir2_db_t dbno; /* data block number */
xfs_dabuf_t *dbp; /* data block buffer */
xfs_dir2_data_entry_t *dep; /* data entry pointer */
......@@ -1641,8 +1641,8 @@ xfs_dir2_node_addname_int(
* We haven't allocated the data entry yet so this will
* change again.
*/
data = dbp->data;
free->bests[findex] = data->hdr.bestfree[0].length;
hdr = dbp->data;
free->bests[findex] = hdr->bestfree[0].length;
logfree = 1;
}
/*
......@@ -1667,21 +1667,21 @@ xfs_dir2_node_addname_int(
xfs_da_buf_done(fbp);
return error;
}
data = dbp->data;
hdr = dbp->data;
logfree = 0;
}
ASSERT(be16_to_cpu(data->hdr.bestfree[0].length) >= length);
ASSERT(be16_to_cpu(hdr->bestfree[0].length) >= length);
/*
* Point to the existing unused space.
*/
dup = (xfs_dir2_data_unused_t *)
((char *)data + be16_to_cpu(data->hdr.bestfree[0].offset));
((char *)hdr + be16_to_cpu(hdr->bestfree[0].offset));
needscan = needlog = 0;
/*
* Mark the first part of the unused space, inuse for us.
*/
xfs_dir2_data_use_free(tp, dbp, dup,
(xfs_dir2_data_aoff_t)((char *)dup - (char *)data), length,
(xfs_dir2_data_aoff_t)((char *)dup - (char *)hdr), length,
&needlog, &needscan);
/*
* Fill in the new entry and log it.
......@@ -1691,13 +1691,13 @@ xfs_dir2_node_addname_int(
dep->namelen = args->namelen;
memcpy(dep->name, args->name, dep->namelen);
tagp = xfs_dir2_data_entry_tag_p(dep);
*tagp = cpu_to_be16((char *)dep - (char *)data);
*tagp = cpu_to_be16((char *)dep - (char *)hdr);
xfs_dir2_data_log_entry(tp, dbp, dep);
/*
* Rescan the block for bestfree if needed.
*/
if (needscan)
xfs_dir2_data_freescan(mp, data, &needlog);
xfs_dir2_data_freescan(mp, hdr, &needlog);
/*
* Log the data block header if needed.
*/
......@@ -1706,8 +1706,8 @@ xfs_dir2_node_addname_int(
/*
* If the freespace entry is now wrong, update it.
*/
if (be16_to_cpu(free->bests[findex]) != be16_to_cpu(data->hdr.bestfree[0].length)) {
free->bests[findex] = data->hdr.bestfree[0].length;
if (be16_to_cpu(free->bests[findex]) != be16_to_cpu(hdr->bestfree[0].length)) {
free->bests[findex] = hdr->bestfree[0].length;
logfree = 1;
}
/*
......@@ -1857,7 +1857,7 @@ xfs_dir2_node_replace(
xfs_da_args_t *args) /* operation arguments */
{
xfs_da_state_blk_t *blk; /* leaf block */
xfs_dir2_data_t *data; /* data block structure */
xfs_dir2_data_hdr_t *hdr; /* data block header */
xfs_dir2_data_entry_t *dep; /* data entry changed */
int error; /* error return value */
int i; /* btree level */
......@@ -1901,10 +1901,10 @@ xfs_dir2_node_replace(
/*
* Point to the data entry.
*/
data = state->extrablk.bp->data;
ASSERT(be32_to_cpu(data->hdr.magic) == XFS_DIR2_DATA_MAGIC);
hdr = state->extrablk.bp->data;
ASSERT(be32_to_cpu(hdr->magic) == XFS_DIR2_DATA_MAGIC);
dep = (xfs_dir2_data_entry_t *)
((char *)data +
((char *)hdr +
xfs_dir2_dataptr_to_off(state->mp, be32_to_cpu(lep->address)));
ASSERT(inum != be64_to_cpu(dep->inumber));
/*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册