Commit 5902f53e authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Refactor code a bit

parent c1e9a3ad
...@@ -285,6 +285,25 @@ vsm_delset(struct vsm_set **p) ...@@ -285,6 +285,25 @@ vsm_delset(struct vsm_set **p)
FREE_OBJ(vs); FREE_OBJ(vs);
} }
static void
vsm_wash_set(struct vsm_set *vs, int all)
{
struct vsm_seg *vg, *vg2;
VTAILQ_FOREACH_SAFE(vg, &vs->segs, list, vg2) {
if (all || (vg->flags & VSM_FLAG_MARKSCAN) == 0) {
VTAILQ_REMOVE(&vs->segs, vg, list);
if (vg->refs) {
vg->flags |= VSM_FLAG_STALE;
VTAILQ_INSERT_TAIL(&vs->stale, vg, list);
} else {
VAV_Free(vg->av);
FREE_OBJ(vg);
}
}
}
}
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
struct vsm * struct vsm *
...@@ -393,8 +412,6 @@ VSM_ResetError(struct vsm *vd) ...@@ -393,8 +412,6 @@ VSM_ResetError(struct vsm *vd)
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
*/ */
#define VSM_NUKE_ALL (1U << 16)
static int static int
vsm_cmp_av(char * const *a1, char * const *a2) vsm_cmp_av(char * const *a1, char * const *a2)
{ {
...@@ -563,7 +580,7 @@ vsm_vlu_func(void *priv, const char *line) ...@@ -563,7 +580,7 @@ vsm_vlu_func(void *priv, const char *line)
} }
static unsigned static unsigned
vsm_refresh_set2(struct vsm *vd, struct vsm_set *vs) vsm_refresh_set(struct vsm *vd, struct vsm_set *vs)
{ {
struct stat st; struct stat st;
int i; int i;
...@@ -576,7 +593,8 @@ vsm_refresh_set2(struct vsm *vd, struct vsm_set *vs) ...@@ -576,7 +593,8 @@ vsm_refresh_set2(struct vsm *vd, struct vsm_set *vs)
if (fstatat(vd->dfd, vs->dname, &st, AT_SYMLINK_NOFOLLOW)) { if (fstatat(vd->dfd, vs->dname, &st, AT_SYMLINK_NOFOLLOW)) {
closefd(&vs->dfd); closefd(&vs->dfd);
vs->id1 = vs->id2 = 0; vs->id1 = vs->id2 = 0;
return (VSM_MGT_RESTARTED|VSM_NUKE_ALL); vsm_wash_set(vs, 1);
return (VSM_MGT_RESTARTED|VSM_MGT_CHANGED);
} }
if (st.st_ino != vs->dst.st_ino || if (st.st_ino != vs->dst.st_ino ||
st.st_dev != vs->dst.st_dev || st.st_dev != vs->dst.st_dev ||
...@@ -593,7 +611,8 @@ vsm_refresh_set2(struct vsm *vd, struct vsm_set *vs) ...@@ -593,7 +611,8 @@ vsm_refresh_set2(struct vsm *vd, struct vsm_set *vs)
vs->retval |= VSM_MGT_RESTARTED; vs->retval |= VSM_MGT_RESTARTED;
if (vs->dfd < 0) { if (vs->dfd < 0) {
vs->id1 = vs->id2 = 0; vs->id1 = vs->id2 = 0;
return (vs->retval|VSM_NUKE_ALL); vsm_wash_set(vs, 1);
return (vs->retval|VSM_MGT_CHANGED);
} }
AZ(fstat(vs->dfd, &vs->dst)); AZ(fstat(vs->dfd, &vs->dst));
} }
...@@ -631,34 +650,10 @@ vsm_refresh_set2(struct vsm *vd, struct vsm_set *vs) ...@@ -631,34 +650,10 @@ vsm_refresh_set2(struct vsm *vd, struct vsm_set *vs)
} while (!i); } while (!i);
assert(i == -2); assert(i == -2);
VLU_Destroy(&vlu); VLU_Destroy(&vlu);
vsm_wash_set(vs, 0);
return (vs->retval); return (vs->retval);
} }
static unsigned
vsm_refresh_set(struct vsm *vd, struct vsm_set *vs)
{
unsigned retval;
struct vsm_seg *vg, *vg2;
retval = vsm_refresh_set2(vd, vs);
if (retval & VSM_NUKE_ALL)
retval |= VSM_MGT_CHANGED;
VTAILQ_FOREACH_SAFE(vg, &vs->segs, list, vg2) {
if ((vg->flags & VSM_FLAG_MARKSCAN) == 0 ||
(retval & VSM_NUKE_ALL)) {
VTAILQ_REMOVE(&vs->segs, vg, list);
if (vg->refs) {
vg->flags |= VSM_FLAG_STALE;
VTAILQ_INSERT_TAIL(&vs->stale, vg, list);
} else {
VAV_Free(vg->av);
FREE_OBJ(vg);
}
}
}
return (retval & ~VSM_NUKE_ALL);
}
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
unsigned unsigned
......
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