vol-fix-nuke-iteration-and-nuke-globals-20040928

allInodes global dies; don't use ti as an iterator right after freeing it.
This commit is contained in:
Derrick Brashear 2004-10-02 16:54:28 +00:00
parent 9592e1b10c
commit 3f2e943d43
7 changed files with 63 additions and 54 deletions

View File

@ -35,7 +35,7 @@ RCSID
int
ListViceInodes(char *devname, char *mountedOn, char *resultFile,
int (*judgeInode) (), int judgeParam, int *forcep, int forceR,
char *wpath)
char *wpath, void *rock)
{
Log("ListViceInodes not implemented for this platform!\n");
return -1;
@ -167,7 +167,7 @@ struct dinode *ginode();
int
ListViceInodes(char *devname, char *mountedOn, char *resultFile,
int (*judgeInode) (), int judgeParam, int *forcep, int forceR,
char *wpath)
char *wpath, void *rock)
{
FILE *inodeFile = NULL;
char dev[50], rdev[51];
@ -301,7 +301,7 @@ ListViceInodes(char *devname, char *mountedOn, char *resultFile,
info.u.param[2] = p->di_vicep3;
info.u.param[3] = p->di_vicep4;
if (judgeInode && (*judgeInode) (&info, judgeParam) == 0)
if (judgeInode && (*judgeInode) (&info, judgeParam, rock) == 0)
continue;
if (fwrite(&info, sizeof info, 1, inodeFile) != 1) {
@ -469,7 +469,7 @@ afs_efs_figet(EFS_MOUNT * mp, struct efs_dinode *dinodeBuf, int *last_cgno,
int
efs_ListViceInodes(char *devname, char *mountedOn, char *resultFile,
int (*judgeInode) (), int judgeParam, int *forcep,
int forceR, char *wpath)
int forceR, char *wpath, void *rock)
{
FILE *inodeFile = NULL;
char dev[50], rdev[51];
@ -570,7 +570,7 @@ efs_ListViceInodes(char *devname, char *mountedOn, char *resultFile,
p->di_nlink, info.u.param[0], info.u.param[1], info.u.param[2],
info.u.param[3]);
#endif
if (judgeInode && (*judgeInode) (&info, judgeParam) == 0)
if (judgeInode && (*judgeInode) (&info, judgeParam, rock) == 0)
continue;
if (fwrite(&info, sizeof info, 1, inodeFile) != 1) {
@ -823,7 +823,7 @@ xfs_RenameFiles(char *dir, xfs_Rename_t * renames, int n_renames)
int
xfs_ListViceInodes(char *devname, char *mountedOn, char *resultFile,
int (*judgeInode) (), int judgeParam, int *forcep,
int forceR, char *wpath)
int forceR, char *wpath, void *rock)
{
FILE *inodeFile = NULL;
i_list_inode_t info;
@ -931,7 +931,7 @@ xfs_ListViceInodes(char *devname, char *mountedOn, char *resultFile,
goto err1_exit;
}
if (judgeInode && (*judgeInode) (&info.ili_info, judgeParam) == 0)
if (judgeInode && (*judgeInode) (&info.ili_info, judgeParam, rock) == 0)
continue;
rename = 0;
@ -1039,7 +1039,7 @@ xfs_ListViceInodes(char *devname, char *mountedOn, char *resultFile,
int
ListViceInodes(char *devname, char *mountedOn, char *resultFile,
int (*judgeInode) (), int judgeParam, int *forcep, int forceR,
char *wpath)
char *wpath, void *rock)
{
FILE *inodeFile = NULL;
char dev[50], rdev[51];
@ -1070,13 +1070,13 @@ ListViceInodes(char *devname, char *mountedOn, char *resultFile,
#ifdef AFS_SGI_XFS_IOPS_ENV
if (!strcmp("xfs", root_inode.st_fstype)) {
return xfs_ListViceInodes(devname, mountedOn, resultFile, judgeInode,
judgeParam, forcep, forceR, wpath);
judgeParam, forcep, forceR, wpath, rock);
} else
#endif
#ifdef AFS_SGI_EFS_IOPS_ENV
if (root_inode.st_ino == EFS_ROOTINO) {
return efs_ListViceInodes(devname, mountedOn, resultFile, judgeInode,
judgeParam, forcep, forceR, wpath);
judgeParam, forcep, forceR, wpath, rock);
} else
#endif
{
@ -1114,7 +1114,7 @@ extern char *afs_rawname();
int
ListViceInodes(char *devname, char *mountedOn, char *resultFile,
int (*judgeInode) (), int judgeParam, int *forcep, int forceR,
char *wpath)
char *wpath, void *rock)
{
union {
#ifdef AFS_AIX_ENV
@ -1212,7 +1212,7 @@ ListViceInodes(char *devname, char *mountedOn, char *resultFile,
info.u.param[1] = auxp->aux_param2;
info.u.param[2] = auxp->aux_param3;
info.u.param[3] = auxp->aux_param4;
if (judgeInode && (*judgeInode) (&info, judgeParam) == 0)
if (judgeInode && (*judgeInode) (&info, judgeParam, rock) == 0)
continue;
if (fwrite(&info, sizeof info, 1, inodeFile) != 1) {
Log("Error writing inode file for partition %s\n", partition);
@ -1421,7 +1421,7 @@ ListViceInodes(char *devname, char *mountedOn, char *resultFile,
info.inodeNumber = i;
info.byteCount = p->di_size;
info.linkCount = p->di_nlink;
if (judgeInode && (*judgeInode) (&info, judgeParam) == 0)
if (judgeInode && (*judgeInode) (&info, judgeParam, rock) == 0)
continue;
if (fwrite(&info, sizeof info, 1, inodeFile) != 1) {
Log("Error writing inode file for partition %s\n",

View File

@ -1041,8 +1041,8 @@ static int namei_ListAFSSubDirs(IHandle_t * dirIH,
struct ViceInodeInfo *,
char *, char *), FILE * fp,
int (*judgeFun) (struct ViceInodeInfo *,
int vid),
int singleVolumeNumber);
int vid, void *),
int singleVolumeNumber, void *rock);
/* WriteInodeInfo
@ -1093,8 +1093,9 @@ VerifyDirPerms(char *path)
*/
int
ListViceInodes(char *devname, char *mountedOn, char *resultFile,
int (*judgeInode) (struct ViceInodeInfo * info, int vid),
int singleVolumeNumber, int *forcep, int forceR, char *wpath)
int (*judgeInode) (struct ViceInodeInfo * info, int vid, void *rock),
int singleVolumeNumber, int *forcep, int forceR, char *wpath,
void *rock)
{
FILE *fp = (FILE *) - 1;
int ninodes;
@ -1114,7 +1115,7 @@ ListViceInodes(char *devname, char *mountedOn, char *resultFile,
ninodes =
namei_ListAFSFiles(mountedOn, WriteInodeInfo, fp, judgeInode,
singleVolumeNumber);
singleVolumeNumber, rock);
if (!resultFile)
return ninodes;
@ -1167,8 +1168,8 @@ int
namei_ListAFSFiles(char *dev,
int (*writeFun) (FILE *, struct ViceInodeInfo *, char *,
char *), FILE * fp,
int (*judgeFun) (struct ViceInodeInfo *, int),
int singleVolumeNumber)
int (*judgeFun) (struct ViceInodeInfo *, int, void *),
int singleVolumeNumber, void *rock)
{
IHandle_t ih;
namei_t name;
@ -1188,7 +1189,7 @@ namei_ListAFSFiles(char *dev,
namei_HandleToVolDir(&name, &ih);
ninodes =
namei_ListAFSSubDirs(&ih, writeFun, fp, judgeFun,
singleVolumeNumber);
singleVolumeNumber, rock);
if (ninodes < 0)
return ninodes;
} else {
@ -1212,7 +1213,7 @@ namei_ListAFSFiles(char *dev,
if (!DecodeVolumeName(dp2->d_name, &ih.ih_vid)) {
ninodes +=
namei_ListAFSSubDirs(&ih, writeFun, fp, judgeFun,
0);
0, rock);
}
}
closedir(dirp2);
@ -1239,8 +1240,8 @@ static int
namei_ListAFSSubDirs(IHandle_t * dirIH,
int (*writeFun) (FILE *, struct ViceInodeInfo *, char *,
char *), FILE * fp,
int (*judgeFun) (struct ViceInodeInfo *, int),
int singleVolumeNumber)
int (*judgeFun) (struct ViceInodeInfo *, int, void *),
int singleVolumeNumber, void *rock)
{
IHandle_t myIH = *dirIH;
namei_t name;
@ -1283,7 +1284,7 @@ namei_ListAFSSubDirs(IHandle_t * dirIH,
info.linkCount =
namei_GetLinkCount(&linkHandle, (Inode) 0, 0);
}
if (judgeFun && !(*judgeFun) (&info, singleVolumeNumber))
if (judgeFun && !(*judgeFun) (&info, singleVolumeNumber, rock))
continue;
if ((*writeFun) (fp, &info, path1, dp1->d_name) < 0) {
@ -1345,7 +1346,7 @@ namei_ListAFSSubDirs(IHandle_t * dirIH,
continue;
}
if (judgeFun
&& !(*judgeFun) (&info, singleVolumeNumber))
&& !(*judgeFun) (&info, singleVolumeNumber, rock))
continue;
if ((*writeFun) (fp, &info, path3, dp3->d_name) <

View File

@ -50,11 +50,13 @@ int namei_ListAFSFiles(char *dev,
struct ViceInodeInfo * info,
char *dir, char *file), FILE * fp,
int (*judge_fun) (struct ViceInodeInfo * info,
int vid), int singleVolumeNumber);
int vid, void *rock),
int singleVolumeNumber, void *rock);
int ListViceInodes(char *devname, char *mountedOn, char *resultFile,
int (*judgeInode) (struct ViceInodeInfo * info, int vid),
int (*judgeInode) (struct ViceInodeInfo * info, int vid,
void *rock),
int singleVolumeNumber, int *forcep, int forceR,
char *wpath);
char *wpath, void *rock);
#define NAMEI_LCOMP_LEN 32

View File

@ -935,8 +935,8 @@ static int nt_ListAFSSubDirs(IHandle_t * dirIH,
int (*write_fun) (FILE *, struct ViceInodeInfo *,
char *, char *), FILE * fp,
int (*judgeFun) (struct ViceInodeInfo *,
int vid),
int singleVolumeNumber);
int vid, void *rock),
int singleVolumeNumber, void *rock);
/* WriteInodeInfo
@ -972,8 +972,9 @@ WriteInodeInfo(FILE * fp, struct ViceInodeInfo *info, char *dir, char *name)
*/
int
ListViceInodes(char *devname, char *mountedOn, char *resultFile,
int (*judgeInode) (struct ViceInodeInfo * info, int vid),
int singleVolumeNumber, int *forcep, int forceR, char *wpath)
int (*judgeInode) (struct ViceInodeInfo * info, int vid, void *rock),
int singleVolumeNumber, int *forcep, int forceR, char *wpath,
void *rock)
{
FILE *fp = (FILE *) - 1;
int ninodes;
@ -988,7 +989,7 @@ ListViceInodes(char *devname, char *mountedOn, char *resultFile,
}
ninodes =
nt_ListAFSFiles(wpath, WriteInodeInfo, fp, judgeInode,
singleVolumeNumber);
singleVolumeNumber, rock);
if (!resultFile)
return ninodes;
@ -1041,8 +1042,8 @@ int
nt_ListAFSFiles(char *dev,
int (*writeFun) (FILE *, struct ViceInodeInfo *, char *,
char *), FILE * fp,
int (*judgeFun) (struct ViceInodeInfo *, int),
int singleVolumeNumber)
int (*judgeFun) (struct ViceInodeInfo *, int, void *),
int singleVolumeNumber, void *rock)
{
IHandle_t h;
char name[MAX_PATH];
@ -1059,7 +1060,7 @@ nt_ListAFSFiles(char *dev,
if (!nt_HandleToVolDir(name, &h))
return -1;
ninodes =
nt_ListAFSSubDirs(&h, writeFun, fp, judgeFun, singleVolumeNumber);
nt_ListAFSSubDirs(&h, writeFun, fp, judgeFun, singleVolumeNumber, rock);
if (ninodes < 0)
return ninodes;
} else {
@ -1072,7 +1073,7 @@ nt_ListAFSFiles(char *dev,
return -1;
while (dp = readdir(dirp)) {
if (!DecodeVolumeName(dp->d_name, &h.ih_vid)) {
ninodes += nt_ListAFSSubDirs(&h, writeFun, fp, judgeFun, 0);
ninodes += nt_ListAFSSubDirs(&h, writeFun, fp, judgeFun, 0, rock);
}
}
}
@ -1094,8 +1095,8 @@ static int
nt_ListAFSSubDirs(IHandle_t * dirIH,
int (*writeFun) (FILE *, struct ViceInodeInfo *, char *,
char *), FILE * fp,
int (*judgeFun) (struct ViceInodeInfo *, int),
int singleVolumeNumber)
int (*judgeFun) (struct ViceInodeInfo *, int, void *),
int singleVolumeNumber, void *rock)
{
int i;
IHandle_t myIH = *dirIH;
@ -1179,7 +1180,7 @@ nt_ListAFSSubDirs(IHandle_t * dirIH,
info.u.param[2] = data.ftCreationTime.dwHighDateTime;
info.u.param[3] = data.ftCreationTime.dwLowDateTime;
}
if (judgeFun && !(*judgeFun) (&info, singleVolumeNumber))
if (judgeFun && !(*judgeFun) (&info, singleVolumeNumber, rock))
goto next_file;
if ((*writeFun) (fp, &info, path, data.cFileName) < 0) {
nt_close(linkHandle.fd_fd);

View File

@ -49,12 +49,12 @@ extern int nt_GetLinkCount(FdHandle_t * h, Inode ino, int lockit);
int nt_ListAFSFiles(char *dev,
int (*write_fun) (FILE * fp, struct ViceInodeInfo *,
char *dir, char *file), FILE * fp,
int (*judge_fun) (struct ViceInodeInfo *, int vid),
int singleVolumeNumber);
int (*judge_fun) (struct ViceInodeInfo *, int vid, void *rock),
int singleVolumeNumber, void *rock);
int ListViceInodes(char *devname, char *mountedOn, char *resultFile,
int (*judgeInode) (struct ViceInodeInfo * info, int vid),
int (*judgeInode) (struct ViceInodeInfo * info, int vid, void *rock),
int singleVolumeNumber, int *forcep, int forceR,
char *wpath);
char *wpath, void *rock);
int nt_HandleToName(char *name, IHandle_t * h);

View File

@ -65,14 +65,14 @@ struct ilist {
afs_int32 freePtr; /* first free index in this table */
Inode inode[MAXATONCE]; /* inode # */
afs_int32 count[MAXATONCE]; /* link count */
} *allInodes = 0;
};
/* called with a structure specifying info about the inode, and our rock (which
* is the volume ID. Returns true if we should keep this inode, otherwise false.
* Note that ainfo->u.param[0] is always the volume ID, for any vice inode.
*/
static int
NukeProc(struct ViceInodeInfo *ainfo, afs_int32 avolid)
NukeProc(struct ViceInodeInfo *ainfo, afs_int32 avolid, struct ilist *allInodes)
{
struct ilist *ti;
register afs_int32 i;
@ -113,7 +113,7 @@ nuke(char *aname, afs_int32 avolid)
{
/* first process the partition containing this junk */
struct afs_stat tstat;
struct ilist *ti, *ni;
struct ilist *ti, *ni, *li=NULL;
register afs_int32 code;
int i, forceSal;
char devName[64], wpath[100];
@ -127,6 +127,7 @@ nuke(char *aname, afs_int32 avolid)
#endif
#endif /* AFS_NAMEI_ENV */
IHandle_t *fileH;
struct ilist *allInodes = 0;
if (avolid == 0)
return EINVAL;
@ -169,11 +170,11 @@ nuke(char *aname, afs_int32 avolid)
#ifdef AFS_NAMEI_ENV
code =
ListViceInodes(lastDevComp, aname, NULL, NukeProc, avolid, &forceSal,
0, wpath);
0, wpath, allInodes);
#else
code =
ListViceInodes(lastDevComp, aname, "/tmp/vNukeXX", NukeProc, avolid,
&forceSal, 0, wpath);
&forceSal, 0, wpath, allInodes);
unlink("/tmp/vNukeXX"); /* clean it up now */
#endif
if (code == 0) {
@ -211,8 +212,10 @@ nuke(char *aname, afs_int32 avolid)
#endif /* AFS_NAMEI_ENV */
}
ni = ti->next;
free(ti);
if (li) free(li);
li = ti;
}
if (li) free(li);
code = 0; /* we really don't care about it except for debugging */
allInodes = NULL;
@ -236,8 +239,10 @@ nuke(char *aname, afs_int32 avolid)
/* just free things */
for (ti = allInodes; ti; ti = ni) {
ni = ti->next;
free(ti);
if (li) free(li);
li = ti;
}
if (li) free(li);
allInodes = NULL;
}
ReleaseWriteLock(&localLock);

View File

@ -1520,7 +1520,7 @@ CountVolumeInodes(register struct ViceInodeInfo *ip, int maxInodes,
}
int
OnlyOneVolume(struct ViceInodeInfo *inodeinfo, VolumeId singleVolumeNumber)
OnlyOneVolume(struct ViceInodeInfo *inodeinfo, VolumeId singleVolumeNumber, void *rock)
{
if (inodeinfo->u.vnode.vnodeNumber == INODESPECIAL)
return (inodeinfo->u.special.parentId == singleVolumeNumber);
@ -1556,7 +1556,7 @@ GetInodeSummary(char *path, VolumeId singleVolumeNumber)
if ((err =
ListViceInodes(dev, fileSysPath, path,
singleVolumeNumber ? OnlyOneVolume : 0,
singleVolumeNumber, &forceSal, forceR, wpath)) < 0) {
singleVolumeNumber, &forceSal, forceR, wpath, NULL)) < 0) {
if (err == -2) {
Log("*** I/O error %d when writing a tmp inode file %s; Not salvaged %s ***\nIncrease space on partition or use '-tmpdir'\n", errno, path, dev);
return -1;