mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-11 12:28:41 +08:00
xfs: implement live updates for parent pointer repairs
While we're scanning the filesystem for dirents that we can turn into parent pointers, we cannot hold the IOLOCK or ILOCK of the file being repaired. Therefore, we need to set up a dirent hook so that we can keep the temporary file's parent pionters up to date with the rest of the filesystem. Hence we add the ability to *remove* pptrs from the temporary file. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de>
This commit is contained in:
parent
b334f7fab5
commit
65a1fb7a11
@ -70,6 +70,12 @@
|
|||||||
* disrupt attrmulti cursors.
|
* disrupt attrmulti cursors.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* Create a parent pointer in the tempfile. */
|
||||||
|
#define XREP_PPTR_ADD (1)
|
||||||
|
|
||||||
|
/* Remove a parent pointer from the tempfile. */
|
||||||
|
#define XREP_PPTR_REMOVE (2)
|
||||||
|
|
||||||
/* A stashed parent pointer update. */
|
/* A stashed parent pointer update. */
|
||||||
struct xrep_pptr {
|
struct xrep_pptr {
|
||||||
/* Cookie for retrieval of the pptr name. */
|
/* Cookie for retrieval of the pptr name. */
|
||||||
@ -80,6 +86,9 @@ struct xrep_pptr {
|
|||||||
|
|
||||||
/* Length of the pptr name. */
|
/* Length of the pptr name. */
|
||||||
uint8_t namelen;
|
uint8_t namelen;
|
||||||
|
|
||||||
|
/* XREP_PPTR_{ADD,REMOVE} */
|
||||||
|
uint8_t action;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -225,11 +234,25 @@ xrep_parent_replay_update(
|
|||||||
{
|
{
|
||||||
struct xfs_scrub *sc = rp->sc;
|
struct xfs_scrub *sc = rp->sc;
|
||||||
|
|
||||||
/* Create parent pointer. */
|
switch (pptr->action) {
|
||||||
trace_xrep_parent_replay_parentadd(sc->tempip, xname, &pptr->pptr_rec);
|
case XREP_PPTR_ADD:
|
||||||
|
/* Create parent pointer. */
|
||||||
|
trace_xrep_parent_replay_parentadd(sc->tempip, xname,
|
||||||
|
&pptr->pptr_rec);
|
||||||
|
|
||||||
return xfs_parent_set(sc->tempip, sc->ip->i_ino, xname,
|
return xfs_parent_set(sc->tempip, sc->ip->i_ino, xname,
|
||||||
&pptr->pptr_rec, &rp->pptr_args);
|
&pptr->pptr_rec, &rp->pptr_args);
|
||||||
|
case XREP_PPTR_REMOVE:
|
||||||
|
/* Remove parent pointer. */
|
||||||
|
trace_xrep_parent_replay_parentremove(sc->tempip, xname,
|
||||||
|
&pptr->pptr_rec);
|
||||||
|
|
||||||
|
return xfs_parent_unset(sc->tempip, sc->ip->i_ino, xname,
|
||||||
|
&pptr->pptr_rec, &rp->pptr_args);
|
||||||
|
}
|
||||||
|
|
||||||
|
ASSERT(0);
|
||||||
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -290,6 +313,7 @@ xrep_parent_stash_parentadd(
|
|||||||
const struct xfs_inode *dp)
|
const struct xfs_inode *dp)
|
||||||
{
|
{
|
||||||
struct xrep_pptr pptr = {
|
struct xrep_pptr pptr = {
|
||||||
|
.action = XREP_PPTR_ADD,
|
||||||
.namelen = name->len,
|
.namelen = name->len,
|
||||||
};
|
};
|
||||||
int error;
|
int error;
|
||||||
@ -304,6 +328,32 @@ xrep_parent_stash_parentadd(
|
|||||||
return xfarray_append(rp->pptr_recs, &pptr);
|
return xfarray_append(rp->pptr_recs, &pptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Remember that we want to remove a parent pointer from the tempfile. These
|
||||||
|
* stashed actions will be replayed later.
|
||||||
|
*/
|
||||||
|
STATIC int
|
||||||
|
xrep_parent_stash_parentremove(
|
||||||
|
struct xrep_parent *rp,
|
||||||
|
const struct xfs_name *name,
|
||||||
|
const struct xfs_inode *dp)
|
||||||
|
{
|
||||||
|
struct xrep_pptr pptr = {
|
||||||
|
.action = XREP_PPTR_REMOVE,
|
||||||
|
.namelen = name->len,
|
||||||
|
};
|
||||||
|
int error;
|
||||||
|
|
||||||
|
trace_xrep_parent_stash_parentremove(rp->sc->tempip, dp, name);
|
||||||
|
|
||||||
|
xfs_inode_to_parent_rec(&pptr.pptr_rec, dp);
|
||||||
|
error = xfblob_storename(rp->pptr_names, &pptr.name_cookie, name);
|
||||||
|
if (error)
|
||||||
|
return error;
|
||||||
|
|
||||||
|
return xfarray_append(rp->pptr_recs, &pptr);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Examine an entry of a directory. If this dirent leads us back to the file
|
* Examine an entry of a directory. If this dirent leads us back to the file
|
||||||
* whose parent pointers we're rebuilding, add a pptr to the temporary
|
* whose parent pointers we're rebuilding, add a pptr to the temporary
|
||||||
@ -513,6 +563,48 @@ xrep_parent_scan_dirtree(
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Capture dirent updates being made by other threads which are relevant to the
|
||||||
|
* file being repaired.
|
||||||
|
*/
|
||||||
|
STATIC int
|
||||||
|
xrep_parent_live_update(
|
||||||
|
struct notifier_block *nb,
|
||||||
|
unsigned long action,
|
||||||
|
void *data)
|
||||||
|
{
|
||||||
|
struct xfs_dir_update_params *p = data;
|
||||||
|
struct xrep_parent *rp;
|
||||||
|
struct xfs_scrub *sc;
|
||||||
|
int error;
|
||||||
|
|
||||||
|
rp = container_of(nb, struct xrep_parent, pscan.dhook.dirent_hook.nb);
|
||||||
|
sc = rp->sc;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This thread updated a dirent that points to the file that we're
|
||||||
|
* repairing, so stash the update for replay against the temporary
|
||||||
|
* file.
|
||||||
|
*/
|
||||||
|
if (p->ip->i_ino == sc->ip->i_ino &&
|
||||||
|
xchk_iscan_want_live_update(&rp->pscan.iscan, p->dp->i_ino)) {
|
||||||
|
mutex_lock(&rp->pscan.lock);
|
||||||
|
if (p->delta > 0)
|
||||||
|
error = xrep_parent_stash_parentadd(rp, p->name, p->dp);
|
||||||
|
else
|
||||||
|
error = xrep_parent_stash_parentremove(rp, p->name,
|
||||||
|
p->dp);
|
||||||
|
mutex_unlock(&rp->pscan.lock);
|
||||||
|
if (error)
|
||||||
|
goto out_abort;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NOTIFY_DONE;
|
||||||
|
out_abort:
|
||||||
|
xchk_iscan_abort(&rp->pscan.iscan);
|
||||||
|
return NOTIFY_DONE;
|
||||||
|
}
|
||||||
|
|
||||||
/* Reset a directory's dotdot entry, if needed. */
|
/* Reset a directory's dotdot entry, if needed. */
|
||||||
STATIC int
|
STATIC int
|
||||||
xrep_parent_reset_dotdot(
|
xrep_parent_reset_dotdot(
|
||||||
@ -684,7 +776,8 @@ xrep_parent_setup_scan(
|
|||||||
if (error)
|
if (error)
|
||||||
goto out_recs;
|
goto out_recs;
|
||||||
|
|
||||||
error = xrep_findparent_scan_start(sc, &rp->pscan);
|
error = __xrep_findparent_scan_start(sc, &rp->pscan,
|
||||||
|
xrep_parent_live_update);
|
||||||
if (error)
|
if (error)
|
||||||
goto out_names;
|
goto out_names;
|
||||||
|
|
||||||
|
@ -2821,6 +2821,7 @@ DEFINE_EVENT(xrep_pptr_class, name, \
|
|||||||
DEFINE_XREP_PPTR_EVENT(xrep_xattr_replay_parentadd);
|
DEFINE_XREP_PPTR_EVENT(xrep_xattr_replay_parentadd);
|
||||||
DEFINE_XREP_PPTR_EVENT(xrep_xattr_replay_parentremove);
|
DEFINE_XREP_PPTR_EVENT(xrep_xattr_replay_parentremove);
|
||||||
DEFINE_XREP_PPTR_EVENT(xrep_parent_replay_parentadd);
|
DEFINE_XREP_PPTR_EVENT(xrep_parent_replay_parentadd);
|
||||||
|
DEFINE_XREP_PPTR_EVENT(xrep_parent_replay_parentremove);
|
||||||
|
|
||||||
DECLARE_EVENT_CLASS(xrep_pptr_scan_class,
|
DECLARE_EVENT_CLASS(xrep_pptr_scan_class,
|
||||||
TP_PROTO(struct xfs_inode *ip, const struct xfs_inode *dp,
|
TP_PROTO(struct xfs_inode *ip, const struct xfs_inode *dp,
|
||||||
@ -2856,6 +2857,7 @@ DEFINE_EVENT(xrep_pptr_scan_class, name, \
|
|||||||
const struct xfs_name *name), \
|
const struct xfs_name *name), \
|
||||||
TP_ARGS(ip, dp, name))
|
TP_ARGS(ip, dp, name))
|
||||||
DEFINE_XREP_PPTR_SCAN_EVENT(xrep_parent_stash_parentadd);
|
DEFINE_XREP_PPTR_SCAN_EVENT(xrep_parent_stash_parentadd);
|
||||||
|
DEFINE_XREP_PPTR_SCAN_EVENT(xrep_parent_stash_parentremove);
|
||||||
|
|
||||||
TRACE_EVENT(xrep_nlinks_set_record,
|
TRACE_EVENT(xrep_nlinks_set_record,
|
||||||
TP_PROTO(struct xfs_mount *mp, xfs_ino_t ino,
|
TP_PROTO(struct xfs_mount *mp, xfs_ino_t ino,
|
||||||
|
Loading…
Reference in New Issue
Block a user