2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
12 * Module: vol-salvage.c
13 * Institution: The Information Technology Center, Carnegie-Mellon University
17 Correct handling of bad "." and ".." entries.
18 Message if volume has "destroyMe" flag set--but doesn't delete yet.
19 Link count bug fixed--bug was that vnodeEssence link count was unsigned
20 14 bits. Needs to be signed.
23 Change to DirHandle stuff to make sure that cache entries are reused at the
24 right time (this parallels the file server change, but is not identical).
26 Added calls to directory salvager routines; doesn't salvage dir unless debug=1.
29 Fixed bug which was causing inode link counts to go bad (thus leaking
31 Vnodes with 0 inode pointers in RW volumes are now deleted.
32 An inode with a matching inode number to the vnode is preferred to an
33 inode with a higer data version.
34 Bug is probably fixed that was causing data version to remain wrong,
35 despite assurances from the salvager to the contrary.
38 Added limited salvaging: unless ForceSalvage is on, then the volume will
39 not be salvaged if the dontSalvage flag is set in the Volume Header.
40 The ForceSalvage flag is turned on if an individual volume is salvaged or
41 if the file FORCESALVAGE exists in the partition header of the file system
42 being salvaged. This isn't used for anything but could be set by vfsck.
43 A -f flag was also added to force salvage.
46 It now deletes obsolete volume inodes without complaining
49 Repairs rw volume headers (again).
52 Correlates volume headers & inodes correctly, thus preventing occasional deletion
53 of read-only volumes...
54 No longer forces a directory salvage for volume 144 (which may be a good volume
56 Some of the messages are cleaned up or made more explicit. One or two added.
58 A bug was fixed which forced salvage of read-only volumes without a corresponding
62 When a volume header is recreated, the new name will be "bogus.volume#"
65 Directory salvaging turned on!!!
68 Prints warning messages for setuid programs.
71 Logs missing inode numbers.
74 Increments directory version number by 200 (rather than by 1) when it is salvaged, in order to prevent problems due to the fact that a version number can be promised to a workstation before it is written to disk. If the server crashes, it may have an older version. Salvaging it could bring the version number up to the same version the workstation believed it already had a call back on.
77 Locks the file /vice/vol/salvage.lock before starting. Aborts if it can't acquire the lock.
78 Time stamps on log entries.
79 Fcntl on stdout to cause all entries to be appended.
80 Problems writing to temporary files are now all detected.
81 Inode summary files are now dynamically named (so that multiple salvagers wouldn't conflict).
82 Some cleanup of error messages.
86 #include <afsconfig.h>
87 #include <afs/param.h>
91 #include <sys/param.h>
95 #endif /* ITIMER_REAL */
101 #include <sys/stat.h>
106 #include <WINNT/afsevent.h>
109 #define WCOREDUMP(x) ((x) & 0200)
112 #include <afs/afsint.h>
113 #include <afs/assert.h>
114 #if !defined(AFS_SGI_ENV) && !defined(AFS_NT40_ENV)
115 #if defined(AFS_VFSINCL_ENV)
116 #include <sys/vnode.h>
118 #include <sys/fs/ufs_inode.h>
120 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
121 #include <ufs/ufs/dinode.h>
122 #include <ufs/ffs/fs.h>
124 #include <ufs/inode.h>
127 #else /* AFS_VFSINCL_ENV */
129 #include <ufs/inode.h>
130 #else /* AFS_OSF_ENV */
131 #if !defined(AFS_LINUX20_ENV) && !defined(AFS_XBSD_ENV)
132 #include <sys/inode.h>
135 #endif /* AFS_VFSINCL_ENV */
136 #endif /* AFS_SGI_ENV */
139 #include <sys/lockf.h>
143 #include <checklist.h>
145 #if defined(AFS_SGI_ENV)
150 #if defined(AFS_SUN_ENV) || defined(AFS_SUN5_ENV)
153 #include <sys/mnttab.h>
154 #include <sys/mntent.h>
159 #endif /* AFS_SGI_ENV */
160 #endif /* AFS_HPUX_ENV */
165 #include <afs/osi_inode.h>
169 #include <afs/afsutil.h>
170 #include <afs/fileutil.h>
171 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
179 #include <afs/afssyscalls.h>
183 #include "partition.h"
184 #include "daemon_com.h"
186 #include "volume_inline.h"
187 #include "salvsync.h"
188 #include "viceinode.h"
190 #include "volinodes.h" /* header magic number, etc. stuff */
191 #include "vol-salvage.h"
193 #include "vol_internal.h"
195 #include <afs/prs_fs.h>
197 #ifdef FSSYNC_BUILD_CLIENT
198 #include "vg_cache.h"
205 /*@+fcnmacros +macrofcndecl@*/
208 extern off64_t afs_lseek(int FD, off64_t O, int F);
209 #endif /*S_SPLINT_S */
210 #define afs_lseek(FD, O, F) lseek64(FD, (off64_t) (O), F)
211 #define afs_stat stat64
212 #define afs_fstat fstat64
213 #define afs_open open64
214 #define afs_fopen fopen64
215 #else /* !O_LARGEFILE */
217 extern off_t afs_lseek(int FD, off_t O, int F);
218 #endif /*S_SPLINT_S */
219 #define afs_lseek(FD, O, F) lseek(FD, (off_t) (O), F)
220 #define afs_stat stat
221 #define afs_fstat fstat
222 #define afs_open open
223 #define afs_fopen fopen
224 #endif /* !O_LARGEFILE */
225 /*@=fcnmacros =macrofcndecl@*/
228 extern void *calloc();
230 static char *TimeStamp(time_t clock, int precision);
233 int debug; /* -d flag */
234 extern int Testing; /* -n flag */
235 int ListInodeOption; /* -i flag */
236 int ShowRootFiles; /* -r flag */
237 int RebuildDirs; /* -sal flag */
238 int Parallel = 4; /* -para X flag */
239 int PartsPerDisk = 8; /* Salvage up to 8 partitions on same disk sequentially */
240 int forceR = 0; /* -b flag */
241 int ShowLog = 0; /* -showlog flag */
242 int ShowSuid = 0; /* -showsuid flag */
243 int ShowMounts = 0; /* -showmounts flag */
244 int orphans = ORPH_IGNORE; /* -orphans option */
249 int useSyslog = 0; /* -syslog flag */
250 int useSyslogFacility = LOG_DAEMON; /* -syslogfacility option */
259 #define MAXPARALLEL 32
261 int OKToZap; /* -o flag */
262 int ForceSalvage; /* If salvage should occur despite the DONT_SALVAGE flag
263 * in the volume header */
265 FILE *logFile = 0; /* one of {/usr/afs/logs,/vice/file}/SalvageLog */
267 #define ROOTINODE 2 /* Root inode of a 4.2 Unix file system
269 Device fileSysDevice; /* The device number of the current
270 * partition being salvaged */
274 char *fileSysPath; /* The path of the mounted partition currently
275 * being salvaged, i.e. the directory
276 * containing the volume headers */
278 char *fileSysPathName; /* NT needs this to make name pretty in log. */
279 IHandle_t *VGLinkH; /* Link handle for current volume group. */
280 int VGLinkH_cnt; /* # of references to lnk handle. */
281 struct DiskPartition64 *fileSysPartition; /* Partition being salvaged */
283 char *fileSysDeviceName; /* The block device where the file system
284 * being salvaged was mounted */
285 char *filesysfulldev;
287 int VolumeChanged; /* Set by any routine which would change the volume in
288 * a way which would require callback is to be broken if the
289 * volume was put back on line by an active file server */
291 VolumeDiskData VolInfo; /* A copy of the last good or salvaged volume header dealt with */
293 int nVolumesInInodeFile; /* Number of read-write volumes summarized */
294 int inodeFd; /* File descriptor for inode file */
297 struct VnodeInfo vnodeInfo[nVNODECLASSES];
300 struct VolumeSummary *volumeSummaryp = NULL; /* Holds all the volumes in a part */
301 int nVolumes; /* Number of volumes (read-write and read-only)
302 * in volume summary */
308 /* Forward declarations */
309 static int IsVnodeOrphaned(VnodeId vnode);
310 static int AskVolumeSummary(VolumeId singleVolumeNumber);
312 #ifdef AFS_DEMAND_ATTACH_FS
313 static int LockVolume(VolumeId volumeId);
314 #endif /* AFS_DEMAND_ATTACH_FS */
316 /* Uniquifier stored in the Inode */
321 return (u & 0x3fffff);
323 #if defined(AFS_SGI_EXMAG)
324 return (u & SGI_UNIQMASK);
327 #endif /* AFS_SGI_EXMAG */
332 BadError(register int aerror)
334 if (aerror == EPERM || aerror == ENXIO || aerror == ENOENT)
336 return 0; /* otherwise may be transient, e.g. EMFILE */
341 char *save_args[MAX_ARGS];
343 extern pthread_t main_thread;
344 childJob_t myjob = { SALVAGER_MAGIC, NOT_CHILD, "" };
348 * Get the salvage lock if not already held. Hold until process exits.
350 * @param[in] locktype READ_LOCK or WRITE_LOCK
353 _ObtainSalvageLock(int locktype)
355 struct VLockFile salvageLock;
360 VLockFileInit(&salvageLock, AFSDIR_SERVER_SLVGLOCK_FILEPATH);
362 code = VLockFileLock(&salvageLock, offset, locktype, nonblock);
365 "salvager: There appears to be another salvager running! "
370 "salvager: Error %d trying to acquire salvage lock! "
376 ObtainSalvageLock(void)
378 _ObtainSalvageLock(WRITE_LOCK);
381 ObtainSharedSalvageLock(void)
383 _ObtainSalvageLock(READ_LOCK);
387 #ifdef AFS_SGI_XFS_IOPS_ENV
388 /* Check if the given partition is mounted. For XFS, the root inode is not a
389 * constant. So we check the hard way.
392 IsPartitionMounted(char *part)
395 struct mntent *mntent;
397 assert(mntfp = setmntent(MOUNTED, "r"));
398 while (mntent = getmntent(mntfp)) {
399 if (!strcmp(part, mntent->mnt_dir))
404 return mntent ? 1 : 1;
407 /* Check if the given inode is the root of the filesystem. */
408 #ifndef AFS_SGI_XFS_IOPS_ENV
410 IsRootInode(struct afs_stat *status)
413 * The root inode is not a fixed value in XFS partitions. So we need to
414 * see if the partition is in the list of mounted partitions. This only
415 * affects the SalvageFileSys path, so we check there.
417 return (status->st_ino == ROOTINODE);
422 #ifndef AFS_NAMEI_ENV
423 /* We don't want to salvage big files filesystems, since we can't put volumes on
427 CheckIfBigFilesFS(char *mountPoint, char *devName)
429 struct superblock fs;
432 if (strncmp(devName, "/dev/", 5)) {
433 (void)sprintf(name, "/dev/%s", devName);
435 (void)strcpy(name, devName);
438 if (ReadSuper(&fs, name) < 0) {
439 Log("Unable to read superblock. Not salvaging partition %s.\n",
443 if (IsBigFilesFileSystem(&fs)) {
444 Log("Partition %s is a big files filesystem, not salvaging.\n",
454 #define HDSTR "\\Device\\Harddisk"
455 #define HDLEN (sizeof(HDSTR)-1) /* Length of "\Device\Harddisk" */
457 SameDisk(struct DiskPartition64 *p1, struct DiskPartition64 *p2)
462 static int dowarn = 1;
464 if (!QueryDosDevice(p1->devName, res, RES_LEN - 1))
466 if (strncmp(res, HDSTR, HDLEN)) {
469 Log("WARNING: QueryDosDevice is returning %s, not %s for %s\n",
470 res, HDSTR, p1->devName);
474 d1 = atoi(&res[HDLEN]);
476 if (!QueryDosDevice(p2->devName, res, RES_LEN - 1))
478 if (strncmp(res, HDSTR, HDLEN)) {
481 Log("WARNING: QueryDosDevice is returning %s, not %s for %s\n",
482 res, HDSTR, p2->devName);
486 d2 = atoi(&res[HDLEN]);
491 #define SameDisk(P1, P2) ((P1)->device/PartsPerDisk == (P2)->device/PartsPerDisk)
494 /* This assumes that two partitions with the same device number divided by
495 * PartsPerDisk are on the same disk.
498 SalvageFileSysParallel(struct DiskPartition64 *partP)
501 struct DiskPartition64 *partP;
502 int pid; /* Pid for this job */
503 int jobnumb; /* Log file job number */
504 struct job *nextjob; /* Next partition on disk to salvage */
506 static struct job *jobs[MAXPARALLEL] = { 0 }; /* Need to zero this */
507 struct job *thisjob = 0;
508 static int numjobs = 0;
509 static int jobcount = 0;
515 char logFileName[256];
519 /* We have a partition to salvage. Copy it into thisjob */
520 thisjob = (struct job *)malloc(sizeof(struct job));
522 Log("Can't salvage '%s'. Not enough memory\n", partP->name);
525 memset(thisjob, 0, sizeof(struct job));
526 thisjob->partP = partP;
527 thisjob->jobnumb = jobcount;
529 } else if (jobcount == 0) {
530 /* We are asking to wait for all jobs (partp == 0), yet we never
533 Log("No file system partitions named %s* found; not salvaged\n",
534 VICE_PARTITION_PREFIX);
538 if (debug || Parallel == 1) {
540 SalvageFileSys(thisjob->partP, 0);
547 /* Check to see if thisjob is for a disk that we are already
548 * salvaging. If it is, link it in as the next job to do. The
549 * jobs array has 1 entry per disk being salvages. numjobs is
550 * the total number of disks currently being salvaged. In
551 * order to keep thejobs array compact, when a disk is
552 * completed, the hightest element in the jobs array is moved
553 * down to now open slot.
555 for (j = 0; j < numjobs; j++) {
556 if (SameDisk(jobs[j]->partP, thisjob->partP)) {
557 /* On same disk, add it to this list and return */
558 thisjob->nextjob = jobs[j]->nextjob;
559 jobs[j]->nextjob = thisjob;
566 /* Loop until we start thisjob or until all existing jobs are finished */
567 while (thisjob || (!partP && (numjobs > 0))) {
568 startjob = -1; /* No new job to start */
570 if ((numjobs >= Parallel) || (!partP && (numjobs > 0))) {
571 /* Either the max jobs are running or we have to wait for all
572 * the jobs to finish. In either case, we wait for at least one
573 * job to finish. When it's done, clean up after it.
575 pid = wait(&wstatus);
577 for (j = 0; j < numjobs; j++) { /* Find which job it is */
578 if (pid == jobs[j]->pid)
582 if (WCOREDUMP(wstatus)) { /* Say if the job core dumped */
583 Log("Salvage of %s core dumped!\n", jobs[j]->partP->name);
586 numjobs--; /* job no longer running */
587 oldjob = jobs[j]; /* remember */
588 jobs[j] = jobs[j]->nextjob; /* Step to next part on same disk */
589 free(oldjob); /* free the old job */
591 /* If there is another partition on the disk to salvage, then
592 * say we will start it (startjob). If not, then put thisjob there
593 * and say we will start it.
595 if (jobs[j]) { /* Another partitions to salvage */
596 startjob = j; /* Will start it */
597 } else { /* There is not another partition to salvage */
599 jobs[j] = thisjob; /* Add thisjob */
601 startjob = j; /* Will start it */
603 jobs[j] = jobs[numjobs]; /* Move last job up to this slot */
604 startjob = -1; /* Don't start it - already running */
608 /* We don't have to wait for a job to complete */
610 jobs[numjobs] = thisjob; /* Add this job */
612 startjob = numjobs; /* Will start it */
616 /* Start up a new salvage job on a partition in job slot "startjob" */
617 if (startjob != -1) {
619 Log("Starting salvage of file system partition %s\n",
620 jobs[startjob]->partP->name);
622 /* For NT, we not only fork, but re-exec the salvager. Pass in the
623 * commands and pass the child job number via the data path.
626 nt_SalvagePartition(jobs[startjob]->partP->name,
627 jobs[startjob]->jobnumb);
628 jobs[startjob]->pid = pid;
633 jobs[startjob]->pid = pid;
639 for (fd = 0; fd < 16; fd++)
646 openlog("salvager", LOG_PID, useSyslogFacility);
650 (void)afs_snprintf(logFileName, sizeof logFileName,
652 AFSDIR_SERVER_SLVGLOG_FILEPATH,
653 jobs[startjob]->jobnumb);
654 logFile = afs_fopen(logFileName, "w");
659 SalvageFileSys1(jobs[startjob]->partP, 0);
664 } /* while ( thisjob || (!partP && numjobs > 0) ) */
666 /* If waited for all jobs to complete, now collect log files and return */
668 if (!useSyslog) /* if syslogging - no need to collect */
671 for (i = 0; i < jobcount; i++) {
672 (void)afs_snprintf(logFileName, sizeof logFileName, "%s.%d",
673 AFSDIR_SERVER_SLVGLOG_FILEPATH, i);
674 if ((passLog = afs_fopen(logFileName, "r"))) {
675 while (fgets(buf, sizeof(buf), passLog)) {
680 (void)unlink(logFileName);
689 SalvageFileSys(struct DiskPartition64 *partP, VolumeId singleVolumeNumber)
691 if (!canfork || debug || Fork() == 0) {
692 SalvageFileSys1(partP, singleVolumeNumber);
693 if (canfork && !debug) {
698 Wait("SalvageFileSys");
702 get_DevName(char *pbuffer, char *wpath)
704 char pbuf[128], *ptr;
705 strcpy(pbuf, pbuffer);
706 ptr = (char *)strrchr(pbuf, '/');
712 ptr = (char *)strrchr(pbuffer, '/');
714 strcpy(pbuffer, ptr + 1);
721 SalvageFileSys1(struct DiskPartition64 *partP, VolumeId singleVolumeNumber)
724 char inodeListPath[256];
725 FILE *inodeFile = NULL;
726 static char tmpDevName[100];
727 static char wpath[100];
728 struct VolumeSummary *vsp, *esp;
739 if (tries > VOL_MAX_CHECKOUT_RETRIES) {
740 Abort("Raced too many times with fileserver restarts while trying to "
741 "checkout/lock volumes; Aborted\n");
743 #ifdef AFS_DEMAND_ATTACH_FS
745 /* unlock all previous volume locks, since we're about to lock them
747 VLockFileReinit(&partP->volLockFile);
749 #endif /* AFS_DEMAND_ATTACH_FS */
751 fileSysPartition = partP;
752 fileSysDevice = fileSysPartition->device;
753 fileSysPathName = VPartitionPath(fileSysPartition);
756 /* Opendir can fail on "C:" but not on "C:\" if C is empty! */
757 (void)sprintf(fileSysPath, "%s\\", fileSysPathName);
758 name = partP->devName;
760 fileSysPath = fileSysPathName;
761 strcpy(tmpDevName, partP->devName);
762 name = get_DevName(tmpDevName, wpath);
763 fileSysDeviceName = name;
764 filesysfulldev = wpath;
767 if (singleVolumeNumber) {
768 #ifndef AFS_DEMAND_ATTACH_FS
769 /* only non-DAFS locks the partition when salvaging a single volume;
770 * DAFS will lock the individual volumes in the VG */
771 VLockPartition(partP->name);
772 #endif /* !AFS_DEMAND_ATTACH_FS */
776 /* salvageserver already setup fssync conn for us */
777 if ((programType != salvageServer) && !VConnectFS()) {
778 Abort("Couldn't connect to file server\n");
781 AskOffline(singleVolumeNumber, partP->name);
782 #ifdef AFS_DEMAND_ATTACH_FS
783 if (LockVolume(singleVolumeNumber)) {
786 #endif /* AFS_DEMAND_ATTACH_FS */
789 VLockPartition(partP->name);
793 ForceSalvage = UseTheForceLuke(fileSysPath);
796 Log("SALVAGING FILE SYSTEM PARTITION %s (device=%s%s)\n",
797 partP->name, name, (Testing ? "(READONLY mode)" : ""));
799 Log("***Forced salvage of all volumes on this partition***\n");
804 * Remove any leftover /vicepa/salvage.inodes.* or /vicepa/salvage.temp.*
811 assert((dirp = opendir(fileSysPath)) != NULL);
812 while ((dp = readdir(dirp))) {
813 if (!strncmp(dp->d_name, "salvage.inodes.", 15)
814 || !strncmp(dp->d_name, "salvage.temp.", 13)) {
816 Log("Removing old salvager temp files %s\n", dp->d_name);
817 strcpy(npath, fileSysPath);
819 strcat(npath, dp->d_name);
825 tdir = (tmpdir ? tmpdir : fileSysPath);
827 (void)_putenv("TMP="); /* If "TMP" is set, then that overrides tdir. */
828 (void)strncpy(inodeListPath, _tempnam(tdir, "salvage.inodes."), 255);
830 snprintf(inodeListPath, 255, "%s/salvage.inodes.%s.%d", tdir, name,
834 inodeFile = fopen(inodeListPath, "w+b");
836 Abort("Error %d when creating inode description file %s; not salvaged\n", errno, inodeListPath);
839 /* Using nt_unlink here since we're really using the delete on close
840 * semantics of unlink. In most places in the salvager, we really do
841 * mean to unlink the file at that point. Those places have been
842 * modified to actually do that so that the NT crt can be used there.
844 code = nt_unlink(inodeListPath);
846 code = unlink(inodeListPath);
849 Log("Error %d when trying to unlink %s\n", errno, inodeListPath);
852 if (GetInodeSummary(inodeFile, singleVolumeNumber) < 0) {
856 inodeFd = fileno(inodeFile);
858 Abort("Temporary file %s is missing...\n", inodeListPath);
859 afs_lseek(inodeFd, 0L, SEEK_SET);
860 if (ListInodeOption) {
864 /* enumerate volumes in the partition.
865 * figure out sets of read-only + rw volumes.
866 * salvage each set, read-only volumes first, then read-write.
867 * Fix up inodes on last volume in set (whether it is read-write
870 if (GetVolumeSummary(singleVolumeNumber)) {
874 for (i = j = 0, vsp = volumeSummaryp, esp = vsp + nVolumes;
875 i < nVolumesInInodeFile; i = j) {
876 VolumeId rwvid = inodeSummary[i].RWvolumeId;
878 j < nVolumesInInodeFile && inodeSummary[j].RWvolumeId == rwvid;
880 VolumeId vid = inodeSummary[j].volumeId;
881 struct VolumeSummary *tsp;
882 /* Scan volume list (from partition root directory) looking for the
883 * current rw volume number in the volume list from the inode scan.
884 * If there is one here that is not in the inode volume list,
886 for (; vsp < esp && (vsp->header.parent < rwvid); vsp++) {
888 DeleteExtraVolumeHeaderFile(vsp);
890 /* Now match up the volume summary info from the root directory with the
891 * entry in the volume list obtained from scanning inodes */
892 inodeSummary[j].volSummary = NULL;
893 for (tsp = vsp; tsp < esp && (tsp->header.parent == rwvid); tsp++) {
894 if (tsp->header.id == vid) {
895 inodeSummary[j].volSummary = tsp;
901 /* Salvage the group of volumes (several read-only + 1 read/write)
902 * starting with the current read-only volume we're looking at.
904 SalvageVolumeGroup(&inodeSummary[i], j - i);
907 /* Delete any additional volumes that were listed in the partition but which didn't have any corresponding inodes */
908 for (; vsp < esp; vsp++) {
910 DeleteExtraVolumeHeaderFile(vsp);
913 if (!singleVolumeNumber) /* Remove the FORCESALVAGE file */
914 RemoveTheForce(fileSysPath);
916 if (!Testing && singleVolumeNumber) {
917 #ifdef AFS_DEMAND_ATTACH_FS
918 /* unlock vol headers so the fs can attach them when we AskOnline */
919 VLockFileReinit(&fileSysPartition->volLockFile);
920 #endif /* AFS_DEMAND_ATTACH_FS */
922 AskOnline(singleVolumeNumber, fileSysPartition->name);
924 /* Step through the volumeSummary list and set all volumes on-line.
925 * The volumes were taken off-line in GetVolumeSummary.
927 for (j = 0; j < nVolumes; j++) {
928 AskOnline(volumeSummaryp[j].header.id, fileSysPartition->name);
932 Log("SALVAGING OF PARTITION %s%s COMPLETED\n",
933 fileSysPartition->name, (Testing ? " (READONLY mode)" : ""));
936 fclose(inodeFile); /* SalvageVolumeGroup was the last which needed it. */
940 DeleteExtraVolumeHeaderFile(register struct VolumeSummary *vsp)
943 sprintf(path, "%s/%s", fileSysPath, vsp->fileName);
946 Log("The volume header file %s is not associated with any actual data (%sdeleted)\n", path, (Testing ? "would have been " : ""));
949 code = VDestroyVolumeDiskHeader(fileSysPartition, vsp->header.id, vsp->header.parent);
951 Log("Error %ld destroying volume disk header for volume %lu\n",
952 afs_printable_int32_ld(code),
953 afs_printable_uint32_lu(vsp->header.id));
956 /* make sure we actually delete the fileName file; ENOENT
957 * is fine, since VDestroyVolumeDiskHeader probably already
959 if (unlink(path) && errno != ENOENT) {
960 Log("Unable to unlink %s (errno = %d)\n", path, errno);
967 CompareInodes(const void *_p1, const void *_p2)
969 register const struct ViceInodeInfo *p1 = _p1;
970 register const struct ViceInodeInfo *p2 = _p2;
971 if (p1->u.vnode.vnodeNumber == INODESPECIAL
972 || p2->u.vnode.vnodeNumber == INODESPECIAL) {
973 VolumeId p1rwid, p2rwid;
975 (p1->u.vnode.vnodeNumber ==
976 INODESPECIAL ? p1->u.special.parentId : p1->u.vnode.volumeId);
978 (p2->u.vnode.vnodeNumber ==
979 INODESPECIAL ? p2->u.special.parentId : p2->u.vnode.volumeId);
984 if (p1->u.vnode.vnodeNumber == INODESPECIAL
985 && p2->u.vnode.vnodeNumber == INODESPECIAL) {
986 if (p1->u.vnode.volumeId == p2->u.vnode.volumeId)
987 return (p1->u.special.type < p2->u.special.type ? -1 : 1);
988 if (p1->u.vnode.volumeId == p1rwid)
990 if (p2->u.vnode.volumeId == p2rwid)
992 return (p1->u.vnode.volumeId < p2->u.vnode.volumeId ? -1 : 1);
994 if (p1->u.vnode.vnodeNumber != INODESPECIAL)
995 return (p2->u.vnode.volumeId == p2rwid ? 1 : -1);
996 return (p1->u.vnode.volumeId == p1rwid ? -1 : 1);
998 if (p1->u.vnode.volumeId < p2->u.vnode.volumeId)
1000 if (p1->u.vnode.volumeId > p2->u.vnode.volumeId)
1002 if (p1->u.vnode.vnodeNumber < p2->u.vnode.vnodeNumber)
1004 if (p1->u.vnode.vnodeNumber > p2->u.vnode.vnodeNumber)
1006 /* The following tests are reversed, so that the most desirable
1007 * of several similar inodes comes first */
1008 if (p1->u.vnode.vnodeUniquifier > p2->u.vnode.vnodeUniquifier) {
1009 #ifdef AFS_3DISPARES
1010 if (p1->u.vnode.vnodeUniquifier > 3775414 /* 90% of 4.2M */ &&
1011 p2->u.vnode.vnodeUniquifier < 419490 /* 10% of 4.2M */ )
1014 #ifdef AFS_SGI_EXMAG
1015 if (p1->u.vnode.vnodeUniquifier > 15099494 /* 90% of 16M */ &&
1016 p2->u.vnode.vnodeUniquifier < 1677721 /* 10% of 16M */ )
1021 if (p1->u.vnode.vnodeUniquifier < p2->u.vnode.vnodeUniquifier) {
1022 #ifdef AFS_3DISPARES
1023 if (p2->u.vnode.vnodeUniquifier > 3775414 /* 90% of 4.2M */ &&
1024 p1->u.vnode.vnodeUniquifier < 419490 /* 10% of 4.2M */ )
1027 #ifdef AFS_SGI_EXMAG
1028 if (p2->u.vnode.vnodeUniquifier > 15099494 /* 90% of 16M */ &&
1029 p1->u.vnode.vnodeUniquifier < 1677721 /* 10% of 16M */ )
1034 if (p1->u.vnode.inodeDataVersion > p2->u.vnode.inodeDataVersion) {
1035 #ifdef AFS_3DISPARES
1036 if (p1->u.vnode.inodeDataVersion > 1887437 /* 90% of 2.1M */ &&
1037 p2->u.vnode.inodeDataVersion < 209716 /* 10% of 2.1M */ )
1040 #ifdef AFS_SGI_EXMAG
1041 if (p1->u.vnode.inodeDataVersion > 15099494 /* 90% of 16M */ &&
1042 p2->u.vnode.inodeDataVersion < 1677721 /* 10% of 16M */ )
1047 if (p1->u.vnode.inodeDataVersion < p2->u.vnode.inodeDataVersion) {
1048 #ifdef AFS_3DISPARES
1049 if (p2->u.vnode.inodeDataVersion > 1887437 /* 90% of 2.1M */ &&
1050 p1->u.vnode.inodeDataVersion < 209716 /* 10% of 2.1M */ )
1053 #ifdef AFS_SGI_EXMAG
1054 if (p2->u.vnode.inodeDataVersion > 15099494 /* 90% of 16M */ &&
1055 p1->u.vnode.inodeDataVersion < 1677721 /* 10% of 16M */ )
1064 CountVolumeInodes(register struct ViceInodeInfo *ip, int maxInodes,
1065 register struct InodeSummary *summary)
1067 VolumeId volume = ip->u.vnode.volumeId;
1068 VolumeId rwvolume = volume;
1069 register int n, nSpecial;
1070 register Unique maxunique;
1073 while (maxInodes-- && volume == ip->u.vnode.volumeId) {
1075 if (ip->u.vnode.vnodeNumber == INODESPECIAL) {
1077 rwvolume = ip->u.special.parentId;
1078 /* This isn't quite right, as there could (in error) be different
1079 * parent inodes in different special vnodes */
1081 if (maxunique < ip->u.vnode.vnodeUniquifier)
1082 maxunique = ip->u.vnode.vnodeUniquifier;
1086 summary->volumeId = volume;
1087 summary->RWvolumeId = rwvolume;
1088 summary->nInodes = n;
1089 summary->nSpecialInodes = nSpecial;
1090 summary->maxUniquifier = maxunique;
1094 OnlyOneVolume(struct ViceInodeInfo *inodeinfo, afs_uint32 singleVolumeNumber, void *rock)
1096 if (inodeinfo->u.vnode.vnodeNumber == INODESPECIAL)
1097 return (inodeinfo->u.special.parentId == singleVolumeNumber);
1098 return (inodeinfo->u.vnode.volumeId == singleVolumeNumber);
1103 * Collect list of inodes in file named by path. If a truly fatal error,
1104 * unlink the file and abort. For lessor errors, return -1. The file will
1105 * be unlinked by the caller.
1108 GetInodeSummary(FILE *inodeFile, VolumeId singleVolumeNumber)
1110 struct afs_stat status;
1113 struct ViceInodeInfo *ip, *ip_save;
1114 struct InodeSummary summary;
1115 char summaryFileName[50];
1118 char *dev = fileSysPath;
1119 char *wpath = fileSysPath;
1121 char *dev = fileSysDeviceName;
1122 char *wpath = filesysfulldev;
1124 char *part = fileSysPath;
1127 /* This file used to come from vfsck; cobble it up ourselves now... */
1129 ListViceInodes(dev, fileSysPath, inodeFile,
1130 singleVolumeNumber ? OnlyOneVolume : 0,
1131 singleVolumeNumber, &forceSal, forceR, wpath, NULL)) < 0) {
1133 Log("*** I/O error %d when writing a tmp inode file; Not salvaged %s ***\nIncrease space on partition or use '-tmpdir'\n", errno, dev);
1136 Abort("Unable to get inodes for \"%s\"; not salvaged\n", dev);
1138 if (forceSal && !ForceSalvage) {
1139 Log("***Forced salvage of all volumes on this partition***\n");
1142 fseek(inodeFile, 0L, SEEK_SET);
1143 inodeFd = fileno(inodeFile);
1144 if (inodeFd == -1 || afs_fstat(inodeFd, &status) == -1) {
1145 Abort("No inode description file for \"%s\"; not salvaged\n", dev);
1147 tdir = (tmpdir ? tmpdir : part);
1149 (void)_putenv("TMP="); /* If "TMP" is set, then that overrides tdir. */
1150 (void)strcpy(summaryFileName, _tempnam(tdir, "salvage.temp"));
1152 (void)afs_snprintf(summaryFileName, sizeof summaryFileName,
1153 "%s/salvage.temp.%d", tdir, getpid());
1155 summaryFile = afs_fopen(summaryFileName, "a+");
1156 if (summaryFile == NULL) {
1157 Abort("Unable to create inode summary file\n");
1161 /* Using nt_unlink here since we're really using the delete on close
1162 * semantics of unlink. In most places in the salvager, we really do
1163 * mean to unlink the file at that point. Those places have been
1164 * modified to actually do that so that the NT crt can be used there.
1166 code = nt_unlink(summaryFileName);
1168 code = unlink(summaryFileName);
1171 Log("Error %d when trying to unlink %s\n", errno, summaryFileName);
1174 if (!canfork || debug || Fork() == 0) {
1176 unsigned long st_size=(unsigned long) status.st_size;
1177 nInodes = st_size / sizeof(struct ViceInodeInfo);
1179 fclose(summaryFile);
1180 if (!singleVolumeNumber) /* Remove the FORCESALVAGE file */
1181 RemoveTheForce(fileSysPath);
1183 struct VolumeSummary *vsp;
1186 GetVolumeSummary(singleVolumeNumber);
1188 for (i = 0, vsp = volumeSummaryp; i < nVolumes; i++) {
1190 DeleteExtraVolumeHeaderFile(vsp);
1193 Log("%s vice inodes on %s; not salvaged\n",
1194 singleVolumeNumber ? "No applicable" : "No", dev);
1197 ip = (struct ViceInodeInfo *)malloc(nInodes*sizeof(struct ViceInodeInfo));
1199 fclose(summaryFile);
1201 ("Unable to allocate enough space to read inode table; %s not salvaged\n",
1204 if (read(inodeFd, ip, st_size) != st_size) {
1205 fclose(summaryFile);
1206 Abort("Unable to read inode table; %s not salvaged\n", dev);
1208 qsort(ip, nInodes, sizeof(struct ViceInodeInfo), CompareInodes);
1209 if (afs_lseek(inodeFd, 0, SEEK_SET) == -1
1210 || write(inodeFd, ip, st_size) != st_size) {
1211 fclose(summaryFile);
1212 Abort("Unable to rewrite inode table; %s not salvaged\n", dev);
1217 CountVolumeInodes(ip, nInodes, &summary);
1218 if (fwrite(&summary, sizeof(summary), 1, summaryFile) != 1) {
1219 Log("Difficulty writing summary file (errno = %d); %s not salvaged\n", errno, dev);
1220 fclose(summaryFile);
1223 summary.index += (summary.nInodes);
1224 nInodes -= summary.nInodes;
1225 ip += summary.nInodes;
1228 ip = ip_save = NULL;
1229 /* Following fflush is not fclose, because if it was debug mode would not work */
1230 if (fflush(summaryFile) == EOF || fsync(fileno(summaryFile)) == -1) {
1231 Log("Unable to write summary file (errno = %d); %s not salvaged\n", errno, dev);
1232 fclose(summaryFile);
1235 if (canfork && !debug) {
1240 if (Wait("Inode summary") == -1) {
1241 fclose(summaryFile);
1242 Exit(1); /* salvage of this partition aborted */
1245 assert(afs_fstat(fileno(summaryFile), &status) != -1);
1246 if (status.st_size != 0) {
1248 unsigned long st_status=(unsigned long)status.st_size;
1249 inodeSummary = (struct InodeSummary *)malloc(st_status);
1250 assert(inodeSummary != NULL);
1251 /* For GNU we need to do lseek to get the file pointer moved. */
1252 assert(afs_lseek(fileno(summaryFile), 0, SEEK_SET) == 0);
1253 ret = read(fileno(summaryFile), inodeSummary, st_status);
1254 assert(ret == st_status);
1256 nVolumesInInodeFile =(unsigned long)(status.st_size) / sizeof(struct InodeSummary);
1257 Log("%d nVolumesInInodeFile %lu \n",nVolumesInInodeFile,(unsigned long)(status.st_size));
1258 fclose(summaryFile);
1262 /* Comparison routine for volume sort.
1263 This is setup so that a read-write volume comes immediately before
1264 any read-only clones of that volume */
1266 CompareVolumes(const void *_p1, const void *_p2)
1268 register const struct VolumeSummary *p1 = _p1;
1269 register const struct VolumeSummary *p2 = _p2;
1270 if (p1->header.parent != p2->header.parent)
1271 return p1->header.parent < p2->header.parent ? -1 : 1;
1272 if (p1->header.id == p1->header.parent) /* p1 is rw volume */
1274 if (p2->header.id == p2->header.parent) /* p2 is rw volume */
1276 return p1->header.id < p2->header.id ? -1 : 1; /* Both read-only */
1280 * Gleans volumeSummary information by asking the fileserver
1282 * @param[in] singleVolumeNumber the volume we're salvaging. 0 if we're
1283 * salvaging a whole partition
1285 * @return whether we obtained the volume summary information or not
1286 * @retval 0 success; we obtained the volume summary information
1287 * @retval -1 we raced with a fileserver restart; volume locks and checkout
1289 * @retval 1 we did not get the volume summary information; either the
1290 * fileserver responded with an error, or we are not supposed to
1291 * ask the fileserver for the information (e.g. we are salvaging
1292 * the entire partition or we are not the salvageserver)
1294 * @note for non-DAFS, always returns 1
1297 AskVolumeSummary(VolumeId singleVolumeNumber)
1300 #if defined(FSSYNC_BUILD_CLIENT) && defined(AFS_DEMAND_ATTACH_FS)
1301 if (programType == salvageServer) {
1302 if (singleVolumeNumber) {
1303 FSSYNC_VGQry_response_t q_res;
1305 struct VolumeSummary *vsp;
1307 struct VolumeDiskHeader diskHdr;
1309 memset(&res, 0, sizeof(res));
1311 code = FSYNC_VGCQuery(fileSysPartition->name, singleVolumeNumber, &q_res, &res);
1314 * We must wait for the partition to finish scanning before
1315 * can continue, since we will not know if we got the entire
1316 * VG membership unless the partition is fully scanned.
1317 * We could, in theory, just scan the partition ourselves if
1318 * the VG cache is not ready, but we would be doing the exact
1319 * same scan the fileserver is doing; it will almost always
1320 * be faster to wait for the fileserver. The only exceptions
1321 * are if the partition does not take very long to scan, and
1322 * in that case it's fast either way, so who cares?
1324 if (code == SYNC_FAILED && res.hdr.reason == FSYNC_PART_SCANNING) {
1325 Log("waiting for fileserver to finish scanning partition %s...\n",
1326 fileSysPartition->name);
1328 for (i = 1; code == SYNC_FAILED && res.hdr.reason == FSYNC_PART_SCANNING; i++) {
1329 /* linearly ramp up from 1 to 10 seconds; nothing fancy,
1330 * just so small partitions don't need to wait over 10
1331 * seconds every time, and large partitions are generally
1332 * polled only once every ten seconds. */
1333 sleep((i > 10) ? (i = 10) : i);
1335 code = FSYNC_VGCQuery(fileSysPartition->name, singleVolumeNumber, &q_res, &res);
1339 if (code == SYNC_FAILED && res.hdr.reason == FSYNC_UNKNOWN_VOLID) {
1340 /* This can happen if there's no header for the volume
1341 * we're salvaging, or no headers exist for the VG (if
1342 * we're salvaging an RW). Act as if we got a response
1343 * with no VG members. The headers may be created during
1344 * salvaging, if there are inodes in this VG. */
1346 memset(&q_res, 0, sizeof(q_res));
1347 q_res.rw = singleVolumeNumber;
1351 Log("fileserver refused VGCQuery request for volume %lu on "
1352 "partition %s, code %ld reason %ld\n",
1353 afs_printable_uint32_lu(singleVolumeNumber),
1354 fileSysPartition->name,
1355 afs_printable_int32_ld(code),
1356 afs_printable_int32_ld(res.hdr.reason));
1360 if (q_res.rw != singleVolumeNumber) {
1361 Log("fileserver requested salvage of clone %lu; scheduling salvage of volume group %lu...\n",
1362 afs_printable_uint32_lu(singleVolumeNumber),
1363 afs_printable_uint32_lu(q_res.rw));
1364 #ifdef SALVSYNC_BUILD_CLIENT
1365 if (SALVSYNC_LinkVolume(q_res.rw,
1367 fileSysPartition->name,
1369 Log("schedule request failed\n");
1371 #endif /* SALVSYNC_BUILD_CLIENT */
1372 Exit(SALSRV_EXIT_VOLGROUP_LINK);
1375 volumeSummaryp = malloc(VOL_VG_MAX_VOLS * sizeof(struct VolumeSummary));
1376 assert(volumeSummaryp != NULL);
1379 vsp = volumeSummaryp;
1381 for (i = 0; i < VOL_VG_MAX_VOLS; i++) {
1382 char name[VMAXPATHLEN];
1384 if (!q_res.children[i]) {
1388 /* AskOffline for singleVolumeNumber was called much earlier */
1389 if (q_res.children[i] != singleVolumeNumber) {
1390 AskOffline(q_res.children[i], fileSysPartition->name);
1391 if (LockVolume(q_res.children[i])) {
1397 code = VReadVolumeDiskHeader(q_res.children[i], fileSysPartition, &diskHdr);
1399 Log("Cannot read header for %lu; trying to salvage group anyway\n",
1400 afs_printable_uint32_lu(q_res.children[i]));
1405 DiskToVolumeHeader(&vsp->header, &diskHdr);
1406 VolumeExternalName_r(q_res.children[i], name, sizeof(name));
1407 vsp->fileName = ToString(name);
1412 qsort(volumeSummaryp, nVolumes, sizeof(struct VolumeSummary),
1417 Log("Cannot get volume summary from fileserver; falling back to scanning "
1418 "entire partition\n");
1421 #endif /* FSSYNC_BUILD_CLIENT && AFS_DEMAND_ATTACH_FS */
1426 * count how many volume headers are found by VWalkVolumeHeaders.
1428 * @param[in] dp the disk partition (unused)
1429 * @param[in] name full path to the .vol header (unused)
1430 * @param[in] hdr the header data (unused)
1431 * @param[in] last whether this is the last try or not (unused)
1432 * @param[in] rock actually an afs_int32*; the running count of how many
1433 * volumes we have found
1438 CountHeader(struct DiskPartition64 *dp, const char *name,
1439 struct VolumeDiskHeader *hdr, int last, void *rock)
1441 afs_int32 *nvols = (afs_int32 *)rock;
1447 * parameters to pass to the VWalkVolumeHeaders callbacks when recording volume
1450 struct SalvageScanParams {
1451 VolumeId singleVolumeNumber; /**< 0 for a partition-salvage, otherwise the
1452 * vol id of the VG we're salvaging */
1453 struct VolumeSummary *vsp; /**< ptr to the current volume summary object
1454 * we're filling in */
1455 afs_int32 nVolumes; /**< # of vols we've encountered */
1456 afs_int32 totalVolumes; /**< max # of vols we should encounter (the
1457 * # of vols we've alloc'd memory for) */
1458 int retry; /**< do we need to retry vol lock/checkout? */
1462 * records volume summary info found from VWalkVolumeHeaders.
1464 * Found volumes are also taken offline if they are in the specific volume
1465 * group we are looking for.
1467 * @param[in] dp the disk partition
1468 * @param[in] name full path to the .vol header
1469 * @param[in] hdr the header data
1470 * @param[in] last 1 if this is the last try to read the header, 0 otherwise
1471 * @param[in] rock actually a struct SalvageScanParams*, containing the
1472 * information needed to record the volume summary data
1474 * @return operation status
1476 * @retval -1 volume locking raced with fileserver restart; checking out
1477 * and locking volumes needs to be retried
1478 * @retval 1 volume header is mis-named and should be deleted
1481 RecordHeader(struct DiskPartition64 *dp, const char *name,
1482 struct VolumeDiskHeader *hdr, int last, void *rock)
1484 char nameShouldBe[64];
1485 struct SalvageScanParams *params;
1486 struct VolumeSummary summary;
1487 VolumeId singleVolumeNumber;
1489 params = (struct SalvageScanParams *)rock;
1491 singleVolumeNumber = params->singleVolumeNumber;
1493 DiskToVolumeHeader(&summary.header, hdr);
1495 if (singleVolumeNumber && summary.header.id == singleVolumeNumber
1496 && summary.header.parent != singleVolumeNumber) {
1498 if (programType == salvageServer) {
1499 #ifdef SALVSYNC_BUILD_CLIENT
1500 Log("fileserver requested salvage of clone %u; scheduling salvage of volume group %u...\n",
1501 summary.header.id, summary.header.parent);
1502 if (SALVSYNC_LinkVolume(summary.header.parent,
1506 Log("schedule request failed\n");
1509 Exit(SALSRV_EXIT_VOLGROUP_LINK);
1512 Log("%u is a read-only volume; not salvaged\n",
1513 singleVolumeNumber);
1518 if (!singleVolumeNumber || summary.header.id == singleVolumeNumber
1519 || summary.header.parent == singleVolumeNumber) {
1521 /* check if the header file is incorrectly named */
1523 const char *base = strrchr(name, '/');
1530 (void)afs_snprintf(nameShouldBe, sizeof nameShouldBe,
1531 VFORMAT, afs_printable_uint32_lu(summary.header.id));
1534 if (strcmp(nameShouldBe, base)) {
1535 /* .vol file has wrong name; retry/delete */
1539 if (!badname || last) {
1540 /* only offline the volume if the header is good, or if this is
1541 * the last try looking at it; avoid AskOffline'ing the same vol
1544 if (singleVolumeNumber
1545 && summary.header.id != singleVolumeNumber) {
1546 /* don't offline singleVolumeNumber; we already did that
1549 AskOffline(summary.header.id, fileSysPartition->name);
1551 #ifdef AFS_DEMAND_ATTACH_FS
1553 /* don't lock the volume if the header is bad, since we're
1554 * about to delete it anyway. */
1555 if (LockVolume(summary.header.id)) {
1560 #endif /* AFS_DEMAND_ATTACH_FS */
1564 if (last && !Showmode) {
1565 Log("Volume header file %s is incorrectly named (should be %s "
1566 "not %s); %sdeleted (it will be recreated later, if "
1567 "necessary)\n", name, nameShouldBe, base,
1568 (Testing ? "it would have been " : ""));
1573 summary.fileName = ToString(base);
1576 if (params->nVolumes > params->totalVolumes) {
1577 /* We found more volumes than we found on the first partition walk;
1578 * apparently something created a volume while we were
1579 * partition-salvaging, or we found more than 20 vols when salvaging a
1580 * particular volume. Abort if we detect this, since other programs
1581 * supposed to not touch the partition while it is partition-salvaging,
1582 * and we shouldn't find more than 20 vols in a VG.
1584 Abort("Found %ld vol headers, but should have found at most %ld! "
1585 "Make sure the volserver/fileserver are not running at the "
1586 "same time as a partition salvage\n",
1587 afs_printable_int32_ld(params->nVolumes),
1588 afs_printable_int32_ld(params->totalVolumes));
1591 memcpy(params->vsp, &summary, sizeof(summary));
1599 * possibly unlinks bad volume headers found from VWalkVolumeHeaders.
1601 * If the header could not be read in at all, the header is always unlinked.
1602 * If instead RecordHeader said the header was bad (that is, the header file
1603 * is mis-named), we only unlink if we are doing a partition salvage, as
1604 * opposed to salvaging a specific volume group.
1606 * @param[in] dp the disk partition
1607 * @param[in] name full path to the .vol header
1608 * @param[in] hdr header data, or NULL if the header could not be read
1609 * @param[in] rock actually a struct SalvageScanParams*, with some information
1613 UnlinkHeader(struct DiskPartition64 *dp, const char *name,
1614 struct VolumeDiskHeader *hdr, void *rock)
1616 struct SalvageScanParams *params;
1619 params = (struct SalvageScanParams *)rock;
1622 /* no header; header is too bogus to read in at all */
1624 Log("%s is not a legitimate volume header file; %sdeleted\n", name, (Testing ? "it would have been " : ""));
1630 } else if (!params->singleVolumeNumber) {
1631 /* We were able to read in a header, but RecordHeader said something
1632 * was wrong with it. We only unlink those if we are doing a partition
1639 if (dounlink && unlink(name)) {
1640 Log("Error %d while trying to unlink %s\n", errno, name);
1645 * Populates volumeSummaryp with volume summary information, either by asking
1646 * the fileserver for VG information, or by scanning the /vicepX partition.
1648 * @param[in] singleVolumeNumber the volume ID of the single volume group we
1649 * are salvaging, or 0 if this is a partition
1652 * @return operation status
1654 * @retval -1 we raced with a fileserver restart; checking out and locking
1655 * volumes must be retried
1658 GetVolumeSummary(VolumeId singleVolumeNumber)
1660 afs_int32 nvols = 0;
1661 struct SalvageScanParams params;
1664 code = AskVolumeSummary(singleVolumeNumber);
1666 /* we successfully got the vol information from the fileserver; no
1667 * need to scan the partition */
1671 /* we need to retry volume checkout */
1675 if (!singleVolumeNumber) {
1676 /* Count how many volumes we have in /vicepX */
1677 code = VWalkVolumeHeaders(fileSysPartition, fileSysPath, CountHeader,
1680 Abort("Can't read directory %s; not salvaged\n", fileSysPath);
1685 nvols = VOL_VG_MAX_VOLS;
1688 volumeSummaryp = malloc(nvols * sizeof(struct VolumeSummary));
1689 assert(volumeSummaryp != NULL);
1691 params.singleVolumeNumber = singleVolumeNumber;
1692 params.vsp = volumeSummaryp;
1693 params.nVolumes = 0;
1694 params.totalVolumes = nvols;
1697 /* walk the partition directory of volume headers and record the info
1698 * about them; unlinking invalid headers */
1699 code = VWalkVolumeHeaders(fileSysPartition, fileSysPath, RecordHeader,
1700 UnlinkHeader, ¶ms);
1702 /* we apparently need to retry checking-out/locking volumes */
1706 Abort("Failed to get volume header summary\n");
1708 nVolumes = params.nVolumes;
1710 qsort(volumeSummaryp, nVolumes, sizeof(struct VolumeSummary),
1716 /* Find the link table. This should be associated with the RW volume or, if
1717 * a RO only site, then the RO volume. For now, be cautious and hunt carefully.
1720 FindLinkHandle(register struct InodeSummary *isp, int nVols,
1721 struct ViceInodeInfo *allInodes)
1724 struct ViceInodeInfo *ip;
1726 for (i = 0; i < nVols; i++) {
1727 ip = allInodes + isp[i].index;
1728 for (j = 0; j < isp[i].nSpecialInodes; j++) {
1729 if (ip[j].u.special.type == VI_LINKTABLE)
1730 return ip[j].inodeNumber;
1737 CreateLinkTable(register struct InodeSummary *isp, Inode ino)
1739 struct versionStamp version;
1742 if (!VALID_INO(ino))
1744 IH_CREATE(NULL, fileSysDevice, fileSysPath, 0, isp->volumeId,
1745 INODESPECIAL, VI_LINKTABLE, isp->RWvolumeId);
1746 if (!VALID_INO(ino))
1748 ("Unable to allocate link table inode for volume %u (error = %d)\n",
1749 isp->RWvolumeId, errno);
1750 IH_INIT(VGLinkH, fileSysDevice, isp->RWvolumeId, ino);
1751 fdP = IH_OPEN(VGLinkH);
1753 Abort("Can't open link table for volume %u (error = %d)\n",
1754 isp->RWvolumeId, errno);
1756 if (FDH_TRUNC(fdP, sizeof(version) + sizeof(short)) < 0)
1757 Abort("Can't truncate link table for volume %u (error = %d)\n",
1758 isp->RWvolumeId, errno);
1760 version.magic = LINKTABLEMAGIC;
1761 version.version = LINKTABLEVERSION;
1763 if (FDH_WRITE(fdP, (char *)&version, sizeof(version))
1765 Abort("Can't truncate link table for volume %u (error = %d)\n",
1766 isp->RWvolumeId, errno);
1768 FDH_REALLYCLOSE(fdP);
1770 /* If the volume summary exits (i.e., the V*.vol header file exists),
1771 * then set this inode there as well.
1773 if (isp->volSummary)
1774 isp->volSummary->header.linkTable = ino;
1783 SVGParms_t *parms = (SVGParms_t *) arg;
1784 DoSalvageVolumeGroup(parms->svgp_inodeSummaryp, parms->svgp_count);
1789 SalvageVolumeGroup(register struct InodeSummary *isp, int nVols)
1792 pthread_attr_t tattr;
1796 /* Initialize per volume global variables, even if later code does so */
1800 memset(&VolInfo, 0, sizeof(VolInfo));
1802 parms.svgp_inodeSummaryp = isp;
1803 parms.svgp_count = nVols;
1804 code = pthread_attr_init(&tattr);
1806 Log("Failed to salvage volume group %u: pthread_attr_init()\n",
1810 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_JOINABLE);
1812 Log("Failed to salvage volume group %u: pthread_attr_setdetachstate()\n", isp->RWvolumeId);
1815 code = pthread_create(&tid, &tattr, nt_SVG, &parms);
1817 Log("Failed to create thread to salvage volume group %u\n",
1821 (void)pthread_join(tid, NULL);
1823 #endif /* AFS_NT40_ENV */
1826 DoSalvageVolumeGroup(register struct InodeSummary *isp, int nVols)
1828 struct ViceInodeInfo *inodes, *allInodes, *ip;
1829 int i, totalInodes, size, salvageTo;
1833 int dec_VGLinkH = 0;
1835 FdHandle_t *fdP = NULL;
1838 haveRWvolume = (isp->volumeId == isp->RWvolumeId
1839 && isp->nSpecialInodes > 0);
1840 if ((!ShowMounts) || (ShowMounts && !haveRWvolume)) {
1841 if (!ForceSalvage && QuickCheck(isp, nVols))
1844 if (ShowMounts && !haveRWvolume)
1846 if (canfork && !debug && Fork() != 0) {
1847 (void)Wait("Salvage volume group");
1850 for (i = 0, totalInodes = 0; i < nVols; i++)
1851 totalInodes += isp[i].nInodes;
1852 size = totalInodes * sizeof(struct ViceInodeInfo);
1853 inodes = (struct ViceInodeInfo *)malloc(size);
1854 allInodes = inodes - isp->index; /* this would the base of all the inodes
1855 * for the partition, if all the inodes
1856 * had been read into memory */
1858 (inodeFd, isp->index * sizeof(struct ViceInodeInfo),
1860 assert(read(inodeFd, inodes, size) == size);
1862 /* Don't try to salvage a read write volume if there isn't one on this
1864 salvageTo = haveRWvolume ? 0 : 1;
1866 #ifdef AFS_NAMEI_ENV
1867 ino = FindLinkHandle(isp, nVols, allInodes);
1868 if (VALID_INO(ino)) {
1869 IH_INIT(VGLinkH, fileSysDevice, isp->RWvolumeId, ino);
1870 fdP = IH_OPEN(VGLinkH);
1872 if (!VALID_INO(ino) || fdP == NULL) {
1873 Log("%s link table for volume %u.\n",
1874 Testing ? "Would have recreated" : "Recreating", isp->RWvolumeId);
1876 IH_INIT(VGLinkH, fileSysDevice, -1, -1);
1879 struct ViceInodeInfo *ip;
1880 CreateLinkTable(isp, ino);
1881 fdP = IH_OPEN(VGLinkH);
1882 /* Sync fake 1 link counts to the link table, now that it exists */
1884 for (i = 0; i < nVols; i++) {
1885 ip = allInodes + isp[i].index;
1886 for (j = isp[i].nSpecialInodes; j < isp[i].nInodes; j++) {
1888 nt_SetLinkCount(fdP, ip[j].inodeNumber, 1, 1);
1890 namei_SetLinkCount(fdP, ip[j].inodeNumber, 1, 1);
1898 FDH_REALLYCLOSE(fdP);
1900 IH_INIT(VGLinkH, fileSysDevice, -1, -1);
1903 /* Salvage in reverse order--read/write volume last; this way any
1904 * Inodes not referenced by the time we salvage the read/write volume
1905 * can be picked up by the read/write volume */
1906 /* ACTUALLY, that's not done right now--the inodes just vanish */
1907 for (i = nVols - 1; i >= salvageTo; i--) {
1909 struct InodeSummary *lisp = &isp[i];
1910 #ifdef AFS_NAMEI_ENV
1911 /* If only the RO is present on this partition, the link table
1912 * shows up as a RW volume special file. Need to make sure the
1913 * salvager doesn't try to salvage the non-existent RW.
1915 if (rw && nVols > 1 && isp[i].nSpecialInodes == 1) {
1916 /* If this only special inode is the link table, continue */
1917 if (inodes->u.special.type == VI_LINKTABLE) {
1924 Log("%s VOLUME %u%s.\n", rw ? "SALVAGING" : "CHECKING CLONED",
1925 lisp->volumeId, (Testing ? "(READONLY mode)" : ""));
1926 /* Check inodes twice. The second time do things seriously. This
1927 * way the whole RO volume can be deleted, below, if anything goes wrong */
1928 for (check = 1; check >= 0; check--) {
1930 if (SalvageVolumeHeaderFile(lisp, allInodes, rw, check, &deleteMe)
1932 MaybeZapVolume(lisp, "Volume header", deleteMe, check);
1933 if (rw && deleteMe) {
1934 haveRWvolume = 0; /* This will cause its inodes to be deleted--since salvage
1935 * volume won't be called */
1941 if (rw && check == 1)
1943 if (SalvageVnodes(isp, lisp, allInodes, check) == -1) {
1944 MaybeZapVolume(lisp, "Vnode index", 0, check);
1950 /* Fix actual inode counts */
1952 Log("totalInodes %d\n",totalInodes);
1953 for (ip = inodes; totalInodes; ip++, totalInodes--) {
1954 static int TraceBadLinkCounts = 0;
1955 #ifdef AFS_NAMEI_ENV
1956 if (VGLinkH->ih_ino == ip->inodeNumber) {
1957 dec_VGLinkH = ip->linkCount - VGLinkH_cnt;
1958 VGLinkH_p1 = ip->u.param[0];
1959 continue; /* Deal with this last. */
1962 if (ip->linkCount != 0 && TraceBadLinkCounts) {
1963 TraceBadLinkCounts--; /* Limit reports, per volume */
1964 Log("#### DEBUG #### Link count incorrect by %d; inode %s, size %llu, p=(%u,%u,%u,%u)\n", ip->linkCount, PrintInode(NULL, ip->inodeNumber), (afs_uintmax_t) ip->byteCount, ip->u.param[0], ip->u.param[1], ip->u.param[2], ip->u.param[3]);
1966 while (ip->linkCount > 0) {
1967 /* below used to assert, not break */
1969 if (IH_DEC(VGLinkH, ip->inodeNumber, ip->u.param[0])) {
1970 Log("idec failed. inode %s errno %d\n",
1971 PrintInode(NULL, ip->inodeNumber), errno);
1977 while (ip->linkCount < 0) {
1978 /* these used to be asserts */
1980 if (IH_INC(VGLinkH, ip->inodeNumber, ip->u.param[0])) {
1981 Log("iinc failed. inode %s errno %d\n",
1982 PrintInode(NULL, ip->inodeNumber), errno);
1989 #ifdef AFS_NAMEI_ENV
1990 while (dec_VGLinkH > 0) {
1991 if (IH_DEC(VGLinkH, VGLinkH->ih_ino, VGLinkH_p1) < 0) {
1992 Log("idec failed on link table, errno = %d\n", errno);
1996 while (dec_VGLinkH < 0) {
1997 if (IH_INC(VGLinkH, VGLinkH->ih_ino, VGLinkH_p1) < 0) {
1998 Log("iinc failed on link table, errno = %d\n", errno);
2005 /* Directory consistency checks on the rw volume */
2007 SalvageVolume(isp, VGLinkH);
2008 IH_RELEASE(VGLinkH);
2010 if (canfork && !debug) {
2017 QuickCheck(register struct InodeSummary *isp, int nVols)
2019 /* Check headers BEFORE forking */
2023 for (i = 0; i < nVols; i++) {
2024 struct VolumeSummary *vs = isp[i].volSummary;
2025 VolumeDiskData volHeader;
2027 /* Don't salvage just because phantom rw volume is there... */
2028 /* (If a read-only volume exists, read/write inodes must also exist) */
2029 if (i == 0 && isp->nSpecialInodes == 0 && nVols > 1)
2033 IH_INIT(h, fileSysDevice, vs->header.parent, vs->header.volumeInfo);
2034 if (IH_IREAD(h, 0, (char *)&volHeader, sizeof(volHeader))
2035 == sizeof(volHeader)
2036 && volHeader.stamp.magic == VOLUMEINFOMAGIC
2037 && volHeader.dontSalvage == DONT_SALVAGE
2038 && volHeader.needsSalvaged == 0 && volHeader.destroyMe == 0) {
2039 if (volHeader.inUse != 0) {
2040 volHeader.inUse = 0;
2041 volHeader.inService = 1;
2043 if (IH_IWRITE(h, 0, (char *)&volHeader, sizeof(volHeader))
2044 != sizeof(volHeader)) {
2060 /* SalvageVolumeHeaderFile
2062 * Salvage the top level V*.vol header file. Make sure the special files
2063 * exist and that there are no duplicates.
2065 * Calls SalvageHeader for each possible type of volume special file.
2069 SalvageVolumeHeaderFile(register struct InodeSummary *isp,
2070 register struct ViceInodeInfo *inodes, int RW,
2071 int check, int *deleteMe)
2074 register struct ViceInodeInfo *ip;
2075 int allinodesobsolete = 1;
2076 struct VolumeDiskHeader diskHeader;
2077 afs_int32 (*writefunc)(VolumeDiskHeader_t *, struct DiskPartition64 *) = NULL;
2080 /* keeps track of special inodes that are probably 'good'; they are
2081 * referenced in the vol header, and are included in the given inodes
2086 } goodspecial[MAXINODETYPE];
2091 memset(goodspecial, 0, sizeof(goodspecial));
2093 skip = malloc(isp->nSpecialInodes * sizeof(*skip));
2095 memset(skip, 0, isp->nSpecialInodes * sizeof(*skip));
2097 Log("cannot allocate memory for inode skip array when salvaging "
2098 "volume %lu; not performing duplicate special inode recovery\n",
2099 afs_printable_uint32_lu(isp->volumeId));
2100 /* still try to perform the salvage; the skip array only does anything
2101 * if we detect duplicate special inodes */
2105 * First, look at the special inodes and see if any are referenced by
2106 * the existing volume header. If we find duplicate special inodes, we
2107 * can use this information to use the referenced inode (it's more
2108 * likely to be the 'good' one), and throw away the duplicates.
2110 if (isp->volSummary && skip) {
2111 /* use tempHeader, so we can use the stuff[] array to easily index
2112 * into the isp->volSummary special inodes */
2113 memcpy(&tempHeader, &isp->volSummary->header, sizeof(struct VolumeHeader));
2115 for (i = 0; i < isp->nSpecialInodes; i++) {
2116 ip = &inodes[isp->index + i];
2117 if (ip->u.special.type <= 0 || ip->u.special.type > MAXINODETYPE) {
2118 /* will get taken care of in a later loop */
2121 if (ip->inodeNumber == *(stuff[ip->u.special.type - 1].inode)) {
2122 goodspecial[ip->u.special.type-1].valid = 1;
2123 goodspecial[ip->u.special.type-1].inode = ip->inodeNumber;
2128 memset(&tempHeader, 0, sizeof(tempHeader));
2129 tempHeader.stamp.magic = VOLUMEHEADERMAGIC;
2130 tempHeader.stamp.version = VOLUMEHEADERVERSION;
2131 tempHeader.id = isp->volumeId;
2132 tempHeader.parent = isp->RWvolumeId;
2134 /* Check for duplicates (inodes are sorted by type field) */
2135 for (i = 0; i < isp->nSpecialInodes - 1; i++) {
2136 ip = &inodes[isp->index + i];
2137 if (ip->u.special.type == (ip + 1)->u.special.type) {
2138 afs_ino_str_t stmp1, stmp2;
2140 if (ip->u.special.type <= 0 || ip->u.special.type > MAXINODETYPE) {
2141 /* Will be caught in the loop below */
2145 Log("Duplicate special %d inodes for volume %u found (%s, %s);\n",
2146 ip->u.special.type, isp->volumeId,
2147 PrintInode(stmp1, ip->inodeNumber),
2148 PrintInode(stmp2, (ip+1)->inodeNumber));
2150 if (skip && goodspecial[ip->u.special.type-1].valid) {
2151 Inode gi = goodspecial[ip->u.special.type-1].inode;
2154 Log("using special inode referenced by vol header (%s)\n",
2155 PrintInode(stmp1, gi));
2158 /* the volume header references some special inode of
2159 * this type in the inodes array; are we it? */
2160 if (ip->inodeNumber != gi) {
2162 } else if ((ip+1)->inodeNumber != gi) {
2163 /* in case this is the last iteration; we need to
2164 * make sure we check ip+1, too */
2169 Log("cannot determine which is correct; salvage of volume %u aborted\n", isp->volumeId);
2177 for (i = 0; i < isp->nSpecialInodes; i++) {
2178 ip = &inodes[isp->index + i];
2179 if (ip->u.special.type <= 0 || ip->u.special.type > MAXINODETYPE) {
2181 Log("Rubbish header inode %s of type %d\n",
2182 PrintInode(NULL, ip->inodeNumber),
2183 ip->u.special.type);
2189 Log("Rubbish header inode %s of type %d; deleted\n",
2190 PrintInode(NULL, ip->inodeNumber),
2191 ip->u.special.type);
2192 } else if (!stuff[ip->u.special.type - 1].obsolete) {
2193 if (skip && skip[i]) {
2194 if (orphans == ORPH_REMOVE) {
2195 Log("Removing orphan special inode %s of type %d\n",
2196 PrintInode(NULL, ip->inodeNumber), ip->u.special.type);
2199 Log("Ignoring orphan special inode %s of type %d\n",
2200 PrintInode(NULL, ip->inodeNumber), ip->u.special.type);
2201 /* fall through to the ip->linkCount--; line below */
2204 *(stuff[ip->u.special.type - 1].inode) = ip->inodeNumber;
2205 allinodesobsolete = 0;
2207 if (!check && ip->u.special.type != VI_LINKTABLE)
2208 ip->linkCount--; /* Keep the inode around */
2216 if (allinodesobsolete) {
2223 VGLinkH_cnt++; /* one for every header. */
2225 if (!RW && !check && isp->volSummary) {
2226 ClearROInUseBit(isp->volSummary);
2230 for (i = 0; i < MAXINODETYPE; i++) {
2231 if (stuff[i].inodeType == VI_LINKTABLE) {
2232 /* Gross hack: SalvageHeader does a bcmp on the volume header.
2233 * And we may have recreated the link table earlier, so set the
2234 * RW header as well.
2236 if (VALID_INO(VGLinkH->ih_ino)) {
2237 *stuff[i].inode = VGLinkH->ih_ino;
2241 if (SalvageHeader(&stuff[i], isp, check, deleteMe) == -1 && check)
2245 if (isp->volSummary == NULL) {
2247 char headerName[64];
2248 (void)afs_snprintf(headerName, sizeof headerName, VFORMAT, afs_printable_uint32_lu(isp->volumeId));
2249 (void)afs_snprintf(path, sizeof path, "%s/%s", fileSysPath, headerName);
2251 Log("No header file for volume %u\n", isp->volumeId);
2255 Log("No header file for volume %u; %screating %s\n",
2256 isp->volumeId, (Testing ? "it would have been " : ""),
2258 isp->volSummary = (struct VolumeSummary *)
2259 malloc(sizeof(struct VolumeSummary));
2260 isp->volSummary->fileName = ToString(headerName);
2262 writefunc = VCreateVolumeDiskHeader;
2265 char headerName[64];
2266 /* hack: these two fields are obsolete... */
2267 isp->volSummary->header.volumeAcl = 0;
2268 isp->volSummary->header.volumeMountTable = 0;
2271 (&isp->volSummary->header, &tempHeader,
2272 sizeof(struct VolumeHeader))) {
2273 /* We often remove the name before calling us, so we make a fake one up */
2274 if (isp->volSummary->fileName) {
2275 strcpy(headerName, isp->volSummary->fileName);
2277 (void)afs_snprintf(headerName, sizeof headerName, VFORMAT, afs_printable_uint32_lu(isp->volumeId));
2278 isp->volSummary->fileName = ToString(headerName);
2280 (void)afs_snprintf(path, sizeof path, "%s/%s", fileSysPath, headerName);
2282 Log("Header file %s is damaged or no longer valid%s\n", path,
2283 (check ? "" : "; repairing"));
2287 writefunc = VWriteVolumeDiskHeader;
2291 memcpy(&isp->volSummary->header, &tempHeader,
2292 sizeof(struct VolumeHeader));
2295 Log("It would have written a new header file for volume %u\n",
2299 VolumeHeaderToDisk(&diskHeader, &tempHeader);
2300 code = (*writefunc)(&diskHeader, fileSysPartition);
2302 Log("Error %ld writing volume header file for volume %lu\n",
2303 afs_printable_int32_ld(code),
2304 afs_printable_uint32_lu(diskHeader.id));
2309 IH_INIT(isp->volSummary->volumeInfoHandle, fileSysDevice, isp->RWvolumeId,
2310 isp->volSummary->header.volumeInfo);
2315 SalvageHeader(register struct stuff *sp, struct InodeSummary *isp, int check,
2319 VolumeDiskData volumeInfo;
2320 struct versionStamp fileHeader;
2329 #ifndef AFS_NAMEI_ENV
2330 if (sp->inodeType == VI_LINKTABLE)
2333 if (*(sp->inode) == 0) {
2335 Log("Missing inode in volume header (%s)\n", sp->description);
2339 Log("Missing inode in volume header (%s); %s\n", sp->description,
2340 (Testing ? "it would have recreated it" : "recreating"));
2343 IH_CREATE(NULL, fileSysDevice, fileSysPath, 0, isp->volumeId,
2344 INODESPECIAL, sp->inodeType, isp->RWvolumeId);
2345 if (!VALID_INO(*(sp->inode)))
2347 ("Unable to allocate inode (%s) for volume header (error = %d)\n",
2348 sp->description, errno);
2353 IH_INIT(specH, fileSysDevice, isp->RWvolumeId, *(sp->inode));
2354 fdP = IH_OPEN(specH);
2355 if (OKToZap && (fdP == NULL) && BadError(errno)) {
2356 /* bail out early and destroy the volume */
2358 Log("Still can't open volume header inode (%s), destroying volume\n", sp->description);
2365 Abort("Unable to open inode (%s) of volume header (error = %d)\n",
2366 sp->description, errno);
2369 && (FDH_READ(fdP, (char *)&header, sp->size) != sp->size
2370 || header.fileHeader.magic != sp->stamp.magic)) {
2372 Log("Part of the header (%s) is corrupted\n", sp->description);
2373 FDH_REALLYCLOSE(fdP);
2377 Log("Part of the header (%s) is corrupted; recreating\n",
2381 if (sp->inodeType == VI_VOLINFO
2382 && header.volumeInfo.destroyMe == DESTROY_ME) {
2385 FDH_REALLYCLOSE(fdP);
2389 if (recreate && !Testing) {
2392 ("Internal error: recreating volume header (%s) in check mode\n",
2394 nBytes = FDH_TRUNC(fdP, 0);
2396 Abort("Unable to truncate volume header file (%s) (error = %d)\n",
2397 sp->description, errno);
2399 /* The following code should be moved into vutil.c */
2400 if (sp->inodeType == VI_VOLINFO) {
2402 memset(&header.volumeInfo, 0, sizeof(header.volumeInfo));
2403 header.volumeInfo.stamp = sp->stamp;
2404 header.volumeInfo.id = isp->volumeId;
2405 header.volumeInfo.parentId = isp->RWvolumeId;
2406 sprintf(header.volumeInfo.name, "bogus.%u", isp->volumeId);
2407 Log("Warning: the name of volume %u is now \"bogus.%u\"\n",
2408 isp->volumeId, isp->volumeId);
2409 header.volumeInfo.inService = 0;
2410 header.volumeInfo.blessed = 0;
2411 /* The + 1000 is a hack in case there are any files out in venus caches */
2412 header.volumeInfo.uniquifier = (isp->maxUniquifier + 1) + 1000;
2413 header.volumeInfo.type = (isp->volumeId == isp->RWvolumeId ? readwriteVolume : readonlyVolume); /* XXXX */
2414 header.volumeInfo.needsCallback = 0;
2415 gettimeofday(&tp, 0);
2416 header.volumeInfo.creationDate = tp.tv_sec;
2417 if (FDH_SEEK(fdP, 0, SEEK_SET) < 0) {
2419 ("Unable to seek to beginning of volume header file (%s) (errno = %d)\n",
2420 sp->description, errno);
2423 FDH_WRITE(fdP, (char *)&header.volumeInfo,
2424 sizeof(header.volumeInfo));
2425 if (nBytes != sizeof(header.volumeInfo)) {
2428 ("Unable to write volume header file (%s) (errno = %d)\n",
2429 sp->description, errno);
2430 Abort("Unable to write entire volume header file (%s)\n",
2434 if (FDH_SEEK(fdP, 0, SEEK_SET) < 0) {
2436 ("Unable to seek to beginning of volume header file (%s) (errno = %d)\n",
2437 sp->description, errno);
2439 nBytes = FDH_WRITE(fdP, (char *)&sp->stamp, sizeof(sp->stamp));
2440 if (nBytes != sizeof(sp->stamp)) {
2443 ("Unable to write version stamp in volume header file (%s) (errno = %d)\n",
2444 sp->description, errno);
2446 ("Unable to write entire version stamp in volume header file (%s)\n",
2451 FDH_REALLYCLOSE(fdP);
2453 if (sp->inodeType == VI_VOLINFO) {
2454 VolInfo = header.volumeInfo;
2457 if (VolInfo.updateDate) {
2458 strcpy(update, TimeStamp(VolInfo.updateDate, 0));
2460 Log("%s (%u) %supdated %s\n", VolInfo.name, VolInfo.id,
2461 (Testing ? "it would have been " : ""), update);
2463 strcpy(update, TimeStamp(VolInfo.creationDate, 0));
2465 Log("%s (%u) not updated (created %s)\n", VolInfo.name,
2466 VolInfo.id, update);
2476 SalvageVnodes(register struct InodeSummary *rwIsp,
2477 register struct InodeSummary *thisIsp,
2478 register struct ViceInodeInfo *inodes, int check)
2480 int ilarge, ismall, ioffset, RW, nInodes;
2481 ioffset = rwIsp->index + rwIsp->nSpecialInodes; /* first inode */
2484 RW = (rwIsp == thisIsp);
2485 nInodes = (rwIsp->nInodes - rwIsp->nSpecialInodes);
2487 SalvageIndex(thisIsp->volSummary->header.smallVnodeIndex, vSmall, RW,
2488 &inodes[ioffset], nInodes, thisIsp->volSummary, check);
2489 if (check && ismall == -1)
2492 SalvageIndex(thisIsp->volSummary->header.largeVnodeIndex, vLarge, RW,
2493 &inodes[ioffset], nInodes, thisIsp->volSummary, check);
2494 return (ilarge == 0 && ismall == 0 ? 0 : -1);
2498 SalvageIndex(Inode ino, VnodeClass class, int RW,
2499 register struct ViceInodeInfo *ip, int nInodes,
2500 struct VolumeSummary *volSummary, int check)
2502 VolumeId volumeNumber;
2503 char buf[SIZEOF_LARGEDISKVNODE];
2504 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
2506 StreamHandle_t *file;
2507 struct VnodeClassInfo *vcp;
2509 afs_sfsize_t nVnodes;
2510 afs_fsize_t vnodeLength;
2512 afs_ino_str_t stmp1, stmp2;
2516 volumeNumber = volSummary->header.id;
2517 IH_INIT(handle, fileSysDevice, volSummary->header.parent, ino);
2518 fdP = IH_OPEN(handle);
2519 assert(fdP != NULL);
2520 file = FDH_FDOPEN(fdP, "r+");
2521 assert(file != NULL);
2522 vcp = &VnodeClassInfo[class];
2523 size = OS_SIZE(fdP->fd_fd);
2525 nVnodes = (size / vcp->diskSize) - 1;
2527 assert((nVnodes + 1) * vcp->diskSize == size);
2528 assert(STREAM_SEEK(file, vcp->diskSize, 0) == 0);
2532 for (vnodeIndex = 0;
2533 nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1;
2534 nVnodes--, vnodeIndex++) {
2535 if (vnode->type != vNull) {
2536 int vnodeChanged = 0;
2537 int vnodeNumber = bitNumberToVnodeNumber(vnodeIndex, class);
2538 /* Log programs that belong to root (potentially suid root);
2539 * don't bother for read-only or backup volumes */
2540 #ifdef notdef /* This is done elsewhere */
2541 if (ShowRootFiles && RW && vnode->owner == 0 && vnodeNumber != 1)
2542 Log("OWNER IS ROOT %s %u dir %u vnode %u author %u owner %u mode %o\n", VolInfo.name, volumeNumber, vnode->parent, vnodeNumber, vnode->author, vnode->owner, vnode->modeBits);
2544 if (VNDISK_GET_INO(vnode) == 0) {
2546 /* Log("### DEBUG ### Deleted Vnode with 0 inode (vnode %d)\n", vnodeNumber); */
2547 memset(vnode, 0, vcp->diskSize);
2551 if (vcp->magic != vnode->vnodeMagic) {
2552 /* bad magic #, probably partially created vnode */
2553 Log("Partially allocated vnode %d deleted.\n",
2555 memset(vnode, 0, vcp->diskSize);
2559 /* ****** Should do a bit more salvage here: e.g. make sure
2560 * vnode type matches what it should be given the index */
2561 while (nInodes && ip->u.vnode.vnodeNumber < vnodeNumber) {
2562 /* if (vnodeIdToClass(ip->u.vnode.vnodeNumber) == class && RW) {
2563 * Log("Inode %d: says it belongs to non-existing vnode %d\n",
2564 * ip->inodeNumber, ip->u.vnode.vnodeNumber);
2571 while (nInodes && ip->u.vnode.vnodeNumber == vnodeNumber) {
2572 /* The following doesn't work, because the version number
2573 * is not maintained correctly by the file server */
2574 /*if (vnode->uniquifier == ip->u.vnode.vnodeUniquifier &&
2575 * vnode->dataVersion == ip->u.vnode.inodeDataVersion)
2577 if (VNDISK_GET_INO(vnode) == ip->inodeNumber)
2583 /* For RW volume, look for vnode with matching inode number;
2584 * if no such match, take the first determined by our sort
2586 register struct ViceInodeInfo *lip = ip;
2587 register int lnInodes = nInodes;
2589 && lip->u.vnode.vnodeNumber == vnodeNumber) {
2590 if (VNDISK_GET_INO(vnode) == lip->inodeNumber) {
2599 if (nInodes && ip->u.vnode.vnodeNumber == vnodeNumber) {
2600 /* "Matching" inode */
2604 vu = vnode->uniquifier;
2605 iu = ip->u.vnode.vnodeUniquifier;
2606 vd = vnode->dataVersion;
2607 id = ip->u.vnode.inodeDataVersion;
2609 * Because of the possibility of the uniquifier overflows (> 4M)
2610 * we compare them modulo the low 22-bits; we shouldn't worry
2611 * about mismatching since they shouldn't to many old
2612 * uniquifiers of the same vnode...
2614 if (IUnique(vu) != IUnique(iu)) {
2616 Log("Vnode %u: vnode.unique, %u, does not match inode unique, %u; fixed, but status will be wrong\n", vnodeNumber, IUnique(vu), IUnique(iu));
2619 vnode->uniquifier = iu;
2620 #ifdef AFS_3DISPARES
2621 vnode->dataVersion = (id >= vd ?
2624 1887437 ? vd : id) :
2627 1887437 ? id : vd));
2629 #if defined(AFS_SGI_EXMAG)
2630 vnode->dataVersion = (id >= vd ?
2633 15099494 ? vd : id) :
2636 15099494 ? id : vd));
2638 vnode->dataVersion = (id > vd ? id : vd);
2639 #endif /* AFS_SGI_EXMAG */
2640 #endif /* AFS_3DISPARES */
2643 /* don't bother checking for vd > id any more, since
2644 * partial file transfers always result in this state,
2645 * and you can't do much else anyway (you've already
2646 * found the best data you can) */
2647 #ifdef AFS_3DISPARES
2648 if (!vnodeIsDirectory(vnodeNumber)
2649 && ((vd < id && (id - vd) < 1887437)
2650 || ((vd > id && (vd - id) > 1887437)))) {
2652 #if defined(AFS_SGI_EXMAG)
2653 if (!vnodeIsDirectory(vnodeNumber)
2654 && ((vd < id && (id - vd) < 15099494)
2655 || ((vd > id && (vd - id) > 15099494)))) {
2657 if (!vnodeIsDirectory(vnodeNumber) && vd < id) {
2658 #endif /* AFS_SGI_EXMAG */
2661 Log("Vnode %d: version < inode version; fixed (old status)\n", vnodeNumber);
2662 vnode->dataVersion = id;
2667 if (ip->inodeNumber != VNDISK_GET_INO(vnode)) {
2670 Log("Vnode %d: inode number incorrect (is %s should be %s). FileSize=%llu\n", vnodeNumber, PrintInode(stmp1, VNDISK_GET_INO(vnode)), PrintInode(stmp2, ip->inodeNumber), (afs_uintmax_t) ip->byteCount);
2672 VNDISK_SET_INO(vnode, ip->inodeNumber);
2677 Log("Vnode %d: inode number incorrect; changed from %s to %s. FileSize=%llu\n", vnodeNumber, PrintInode(stmp1, VNDISK_GET_INO(vnode)), PrintInode(stmp2, ip->inodeNumber), (afs_uintmax_t) ip->byteCount);
2679 VNDISK_SET_INO(vnode, ip->inodeNumber);
2682 VNDISK_GET_LEN(vnodeLength, vnode);
2683 if (ip->byteCount != vnodeLength) {
2686 Log("Vnode %d: length incorrect; (is %llu should be %llu)\n", vnodeNumber, (afs_uintmax_t) vnodeLength, (afs_uintmax_t) ip->byteCount);
2691 Log("Vnode %d: length incorrect; changed from %llu to %llu\n", vnodeNumber, (afs_uintmax_t) vnodeLength, (afs_uintmax_t) ip->byteCount);
2692 VNDISK_SET_LEN(vnode, ip->byteCount);
2696 ip->linkCount--; /* Keep the inode around */
2699 } else { /* no matching inode */
2700 if (VNDISK_GET_INO(vnode) != 0
2701 || vnode->type == vDirectory) {
2702 /* No matching inode--get rid of the vnode */
2704 if (VNDISK_GET_INO(vnode)) {
2706 Log("Vnode %d (unique %u): corresponding inode %s is missing\n", vnodeNumber, vnode->uniquifier, PrintInode(NULL, VNDISK_GET_INO(vnode)));
2710 Log("Vnode %d (unique %u): bad directory vnode (no inode number listed)\n", vnodeNumber, vnode->uniquifier);
2715 if (VNDISK_GET_INO(vnode)) {
2717 time_t serverModifyTime = vnode->serverModifyTime;
2718 Log("Vnode %d (unique %u): corresponding inode %s is missing; vnode deleted, vnode mod time=%s", vnodeNumber, vnode->uniquifier, PrintInode(NULL, VNDISK_GET_INO(vnode)), ctime(&serverModifyTime));
2722 time_t serverModifyTime = vnode->serverModifyTime;
2723 Log("Vnode %d (unique %u): bad directory vnode (no inode number listed); vnode deleted, vnode mod time=%s", vnodeNumber, vnode->uniquifier, ctime(&serverModifyTime));
2726 memset(vnode, 0, vcp->diskSize);
2729 /* Should not reach here becuase we checked for
2730 * (inodeNumber == 0) above. And where we zero the vnode,
2731 * we also goto vnodeDone.
2735 while (nInodes && ip->u.vnode.vnodeNumber == vnodeNumber) {
2739 } /* VNDISK_GET_INO(vnode) != 0 */
2741 assert(!(vnodeChanged && check));
2742 if (vnodeChanged && !Testing) {
2744 (handle, vnodeIndexOffset(vcp, vnodeNumber),
2745 (char *)vnode, vcp->diskSize)
2747 VolumeChanged = 1; /* For break call back */
2758 struct VnodeEssence *
2759 CheckVnodeNumber(VnodeId vnodeNumber)
2762 struct VnodeInfo *vip;
2765 class = vnodeIdToClass(vnodeNumber);
2766 vip = &vnodeInfo[class];
2767 offset = vnodeIdToBitNumber(vnodeNumber);
2768 return (offset >= vip->nVnodes ? NULL : &vip->vnodes[offset]);
2772 CopyOnWrite(register struct DirSummary *dir)
2774 /* Copy the directory unconditionally if we are going to change it:
2775 * not just if was cloned.
2777 struct VnodeDiskObject vnode;
2778 struct VnodeClassInfo *vcp = &VnodeClassInfo[vLarge];
2779 Inode oldinode, newinode;
2782 if (dir->copied || Testing)
2784 DFlush(); /* Well justified paranoia... */
2787 IH_IREAD(vnodeInfo[vLarge].handle,
2788 vnodeIndexOffset(vcp, dir->vnodeNumber), (char *)&vnode,
2790 assert(code == sizeof(vnode));
2791 oldinode = VNDISK_GET_INO(&vnode);
2792 /* Increment the version number by a whole lot to avoid problems with
2793 * clients that were promised new version numbers--but the file server
2794 * crashed before the versions were written to disk.
2797 IH_CREATE(dir->ds_linkH, fileSysDevice, fileSysPath, 0, dir->rwVid,
2798 dir->vnodeNumber, vnode.uniquifier, vnode.dataVersion +=
2800 assert(VALID_INO(newinode));
2801 assert(CopyInode(fileSysDevice, oldinode, newinode, dir->rwVid) == 0);
2803 VNDISK_SET_INO(&vnode, newinode);
2805 IH_IWRITE(vnodeInfo[vLarge].handle,
2806 vnodeIndexOffset(vcp, dir->vnodeNumber), (char *)&vnode,
2808 assert(code == sizeof(vnode));
2810 SetSalvageDirHandle(&dir->dirHandle, dir->dirHandle.dirh_handle->ih_vid,
2811 fileSysDevice, newinode);
2812 /* Don't delete the original inode right away, because the directory is
2813 * still being scanned.
2819 * This function should either successfully create a new dir, or give up
2820 * and leave things the way they were. In particular, if it fails to write
2821 * the new dir properly, it should return w/o changing the reference to the
2825 CopyAndSalvage(register struct DirSummary *dir)
2827 struct VnodeDiskObject vnode;
2828 struct VnodeClassInfo *vcp = &VnodeClassInfo[vLarge];
2829 Inode oldinode, newinode;
2834 afs_int32 parentUnique = 1;
2835 struct VnodeEssence *vnodeEssence;
2840 Log("Salvaging directory %u...\n", dir->vnodeNumber);
2842 IH_IREAD(vnodeInfo[vLarge].handle,
2843 vnodeIndexOffset(vcp, dir->vnodeNumber), (char *)&vnode,
2845 assert(lcode == sizeof(vnode));
2846 oldinode = VNDISK_GET_INO(&vnode);
2847 /* Increment the version number by a whole lot to avoid problems with
2848 * clients that were promised new version numbers--but the file server
2849 * crashed before the versions were written to disk.
2852 IH_CREATE(dir->ds_linkH, fileSysDevice, fileSysPath, 0, dir->rwVid,
2853 dir->vnodeNumber, vnode.uniquifier, vnode.dataVersion +=
2855 assert(VALID_INO(newinode));
2856 SetSalvageDirHandle(&newdir, dir->rwVid, fileSysDevice, newinode);
2858 /* Assign . and .. vnode numbers from dir and vnode.parent.
2859 * The uniquifier for . is in the vnode.
2860 * The uniquifier for .. might be set to a bogus value of 1 and
2861 * the salvager will later clean it up.
2863 if (vnode.parent && (vnodeEssence = CheckVnodeNumber(vnode.parent))) {
2864 parentUnique = (vnodeEssence->unique ? vnodeEssence->unique : 1);
2867 DirSalvage(&dir->dirHandle, &newdir, dir->vnodeNumber,
2869 (vnode.parent ? vnode.parent : dir->vnodeNumber),
2874 /* didn't really build the new directory properly, let's just give up. */
2875 code = IH_DEC(dir->ds_linkH, newinode, dir->rwVid);
2876 Log("Directory salvage returned code %d, continuing.\n", code);
2878 Log("also failed to decrement link count on new inode");
2882 Log("Checking the results of the directory salvage...\n");
2883 if (!DirOK(&newdir)) {
2884 Log("Directory salvage failed!!!; restoring old version of the directory.\n");
2885 code = IH_DEC(dir->ds_linkH, newinode, dir->rwVid);
2890 VNDISK_SET_INO(&vnode, newinode);
2891 length = Length(&newdir);
2892 VNDISK_SET_LEN(&vnode, length);
2894 IH_IWRITE(vnodeInfo[vLarge].handle,
2895 vnodeIndexOffset(vcp, dir->vnodeNumber), (char *)&vnode,
2897 assert(lcode == sizeof(vnode));
2900 nt_sync(fileSysDevice);
2902 sync(); /* this is slow, but hopefully rarely called. We don't have
2903 * an open FD on the file itself to fsync.
2907 vnodeInfo[vLarge].handle->ih_synced = 1;
2909 /* make sure old directory file is really closed */
2910 fdP = IH_OPEN(dir->dirHandle.dirh_handle);
2911 FDH_REALLYCLOSE(fdP);
2913 code = IH_DEC(dir->ds_linkH, oldinode, dir->rwVid);
2915 dir->dirHandle = newdir;
2919 JudgeEntry(void *dirVal, char *name, afs_int32 vnodeNumber,
2922 struct DirSummary *dir = (struct DirSummary *)dirVal;
2923 struct VnodeEssence *vnodeEssence;
2924 afs_int32 dirOrphaned, todelete;
2926 dirOrphaned = IsVnodeOrphaned(dir->vnodeNumber);
2928 vnodeEssence = CheckVnodeNumber(vnodeNumber);
2929 if (vnodeEssence == NULL) {
2931 Log("dir vnode %u: invalid entry deleted: %s/%s (vnode %u, unique %u)\n", dir->vnodeNumber, dir->name ? dir->name : "??", name, vnodeNumber, unique);
2935 assert(Delete(&dir->dirHandle, name) == 0);
2940 #ifndef AFS_NAMEI_ENV
2941 /* On AIX machines, don't allow entries to point to inode 0. That is a special
2942 * mount inode for the partition. If this inode were deleted, it would crash
2945 if (vnodeEssence->InodeNumber == 0) {
2946 Log("dir vnode %d: invalid entry: %s/%s has no inode (vnode %d, unique %d)%s\n", dir->vnodeNumber, (dir->name ? dir->name : "??"), name, vnodeNumber, unique, (Testing ? "-- would have deleted" : " -- deleted"));
2949 assert(Delete(&dir->dirHandle, name) == 0);
2956 if (!(vnodeNumber & 1) && !Showmode
2957 && !(vnodeEssence->count || vnodeEssence->unique
2958 || vnodeEssence->modeBits)) {
2959 Log("dir vnode %u: invalid entry: %s/%s (vnode %u, unique %u)%s\n",
2960 dir->vnodeNumber, (dir->name ? dir->name : "??"), name,
2961 vnodeNumber, unique,
2962 ((!unique) ? (Testing ? "-- would have deleted" : " -- deleted") :
2967 assert(Delete(&dir->dirHandle, name) == 0);
2973 /* Check if the Uniquifiers match. If not, change the directory entry
2974 * so its unique matches the vnode unique. Delete if the unique is zero
2975 * or if the directory is orphaned.
2977 if (!vnodeEssence->unique || (vnodeEssence->unique) != unique) {
2978 if (!vnodeEssence->unique
2979 && ((strcmp(name, "..") == 0) || (strcmp(name, ".") == 0))) {
2980 /* This is an orphaned directory. Don't delete the . or ..
2981 * entry. Otherwise, it will get created in the next
2982 * salvage and deleted again here. So Just skip it.
2987 todelete = ((!vnodeEssence->unique || dirOrphaned) ? 1 : 0);
2990 Log("dir vnode %u: %s/%s (vnode %u): unique changed from %u to %u %s\n", dir->vnodeNumber, (dir->name ? dir->name : "??"), name, vnodeNumber, unique, vnodeEssence->unique, (!todelete ? "" : (Testing ? "-- would have deleted" : "-- deleted")));
2994 fid.Vnode = vnodeNumber;
2995 fid.Unique = vnodeEssence->unique;
2997 assert(Delete(&dir->dirHandle, name) == 0);
2999 assert(Create(&dir->dirHandle, name, &fid) == 0);
3002 return 0; /* no need to continue */
3005 if (strcmp(name, ".") == 0) {
3006 if (dir->vnodeNumber != vnodeNumber || (dir->unique != unique)) {
3009 Log("directory vnode %u.%u: bad '.' entry (was %u.%u); fixed\n", dir->vnodeNumber, dir->unique, vnodeNumber, unique);
3012 assert(Delete(&dir->dirHandle, ".") == 0);
3013 fid.Vnode = dir->vnodeNumber;
3014 fid.Unique = dir->unique;
3015 assert(Create(&dir->dirHandle, ".", &fid) == 0);
3018 vnodeNumber = fid.Vnode; /* Get the new Essence */
3019 unique = fid.Unique;
3020 vnodeEssence = CheckVnodeNumber(vnodeNumber);
3023 } else if (strcmp(name, "..") == 0) {
3026 struct VnodeEssence *dotdot;
3027 pa.Vnode = dir->parent;
3028 dotdot = CheckVnodeNumber(pa.Vnode);
3029 assert(dotdot != NULL); /* XXX Should not be assert */
3030 pa.Unique = dotdot->unique;
3032 pa.Vnode = dir->vnodeNumber;
3033 pa.Unique = dir->unique;
3035 if ((pa.Vnode != vnodeNumber) || (pa.Unique != unique)) {
3037 Log("directory vnode %u.%u: bad '..' entry (was %u.%u); fixed\n", dir->vnodeNumber, dir->unique, vnodeNumber, unique);
3040 assert(Delete(&dir->dirHandle, "..") == 0);
3041 assert(Create(&dir->dirHandle, "..", &pa) == 0);
3044 vnodeNumber = pa.Vnode; /* Get the new Essence */
3046 vnodeEssence = CheckVnodeNumber(vnodeNumber);
3048 dir->haveDotDot = 1;
3049 } else if (strncmp(name, ".__afs", 6) == 0) {
3051 Log("dir vnode %u: special old unlink-while-referenced file %s %s deleted (vnode %u)\n", dir->vnodeNumber, name, (Testing ? "would have been" : "is"), vnodeNumber);
3055 assert(Delete(&dir->dirHandle, name) == 0);
3057 vnodeEssence->claimed = 0; /* Not claimed: Orphaned */
3058 vnodeEssence->todelete = 1; /* Will later delete vnode and decr inode */
3061 if (ShowSuid && (vnodeEssence->modeBits & 06000))
3062 Log("FOUND suid/sgid file: %s/%s (%u.%u %05o) author %u (vnode %u dir %u)\n", dir->name ? dir->name : "??", name, vnodeEssence->owner, vnodeEssence->group, vnodeEssence->modeBits, vnodeEssence->author, vnodeNumber, dir->vnodeNumber);
3063 if (/* ShowMounts && */ (vnodeEssence->type == vSymlink)
3064 && !(vnodeEssence->modeBits & 0111)) {
3071 IH_INIT(ihP, fileSysDevice, dir->dirHandle.dirh_handle->ih_vid,
3072 vnodeEssence->InodeNumber);
3075 Log("ERROR %s could not open mount point vnode %u\n", dir->vname, vnodeNumber);
3079 size = FDH_SIZE(fdP);
3081 Log("ERROR %s mount point has invalid size %d, vnode %u\n", dir->vname, (int)size, vnodeNumber);
3082 FDH_REALLYCLOSE(fdP);
3089 nBytes = FDH_READ(fdP, buf, size);
3090 if (nBytes == size) {
3092 if ( (*buf != '#' && *buf != '%') || buf[strlen(buf)-1] != '.' ) {
3093 Log("Volume %u (%s) mount point %s/%s to '%s' invalid, %s to symbolic link\n",
3094 dir->dirHandle.dirh_handle->ih_vid, dir->vname, dir->name ? dir->name : "??", name, buf,
3095 Testing ? "would convert" : "converted");
3096 vnodeEssence->modeBits |= 0111;
3097 vnodeEssence->changed = 1;
3098 } else if (ShowMounts) Log("In volume %u (%s) found mountpoint %s/%s to '%s'\n",
3099 dir->dirHandle.dirh_handle->ih_vid, dir->vname,
3100 dir->name ? dir->name : "??", name, buf);
3102 Log("Volume %s cound not read mount point vnode %u size %d code %d\n",
3103 dir->vname, vnodeNumber, (int)size, (int)nBytes);
3105 FDH_REALLYCLOSE(fdP);
3108 if (ShowRootFiles && vnodeEssence->owner == 0 && vnodeNumber != 1)
3109 Log("FOUND root file: %s/%s (%u.%u %05o) author %u (vnode %u dir %u)\n", dir->name ? dir->name : "??", name, vnodeEssence->owner, vnodeEssence->group, vnodeEssence->modeBits, vnodeEssence->author, vnodeNumber, dir->vnodeNumber);
3110 if (vnodeIdToClass(vnodeNumber) == vLarge
3111 && vnodeEssence->name == NULL) {
3113 if ((n = (char *)malloc(strlen(name) + 1)))
3115 vnodeEssence->name = n;
3118 /* The directory entry points to the vnode. Check to see if the
3119 * vnode points back to the directory. If not, then let the
3120 * directory claim it (else it might end up orphaned). Vnodes
3121 * already claimed by another directory are deleted from this
3122 * directory: hardlinks to the same vnode are not allowed
3123 * from different directories.
3125 if (vnodeEssence->parent != dir->vnodeNumber) {
3126 if (!vnodeEssence->claimed && !dirOrphaned && vnodeNumber != 1) {
3127 /* Vnode does not point back to this directory.
3128 * Orphaned dirs cannot claim a file (it may belong to
3129 * another non-orphaned dir).
3132 Log("dir vnode %u: %s/%s (vnode %u, unique %u) -- parent vnode %schanged from %u to %u\n", dir->vnodeNumber, (dir->name ? dir->name : "??"), name, vnodeNumber, unique, (Testing ? "would have been " : ""), vnodeEssence->parent, dir->vnodeNumber);
3134 vnodeEssence->parent = dir->vnodeNumber;
3135 vnodeEssence->changed = 1;
3137 /* Vnode was claimed by another directory */
3140 Log("dir vnode %u: %s/%s parent vnode is %u (vnode %u, unique %u) -- %sdeleted\n", dir->vnodeNumber, (dir->name ? dir->name : "??"), name, vnodeEssence->parent, vnodeNumber, unique, (Testing ? "would have been " : ""));
3141 } else if (vnodeNumber == 1) {
3142 Log("dir vnode %d: %s/%s is invalid (vnode %d, unique %d) -- %sdeleted\n", dir->vnodeNumber, (dir->name ? dir->name : "??"), name, vnodeNumber, unique, (Testing ? "would have been " : ""));
3144 Log("dir vnode %u: %s/%s already claimed by directory vnode %u (vnode %u, unique %u) -- %sdeleted\n", dir->vnodeNumber, (dir->name ? dir->name : "??"), name, vnodeEssence->parent, vnodeNumber, unique, (Testing ? "would have been " : ""));
3149 assert(Delete(&dir->dirHandle, name) == 0);
3154 /* This directory claims the vnode */
3155 vnodeEssence->claimed = 1;
3157 vnodeEssence->count--;
3162 DistilVnodeEssence(VolumeId rwVId, VnodeClass class, Inode ino, Unique * maxu)
3164 register struct VnodeInfo *vip = &vnodeInfo[class];
3165 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
3166 char buf[SIZEOF_LARGEDISKVNODE];
3167 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
3169 StreamHandle_t *file;
3174 IH_INIT(vip->handle, fileSysDevice, rwVId, ino);
3175 fdP = IH_OPEN(vip->handle);
3176 assert(fdP != NULL);
3177 file = FDH_FDOPEN(fdP, "r+");
3178 assert(file != NULL);
3179 size = OS_SIZE(fdP->fd_fd);
3181 vip->nVnodes = (size / vcp->diskSize) - 1;
3182 if (vip->nVnodes > 0) {
3183 assert((vip->nVnodes + 1) * vcp->diskSize == size);
3184 assert(STREAM_SEEK(file, vcp->diskSize, 0) == 0);
3185 assert((vip->vnodes = (struct VnodeEssence *)
3186 calloc(vip->nVnodes, sizeof(struct VnodeEssence))) != NULL);
3187 if (class == vLarge) {
3188 assert((vip->inodes = (Inode *)
3189 calloc(vip->nVnodes, sizeof(Inode))) != NULL);
3198 vip->volumeBlockCount = vip->nAllocatedVnodes = 0;
3199 for (vnodeIndex = 0, nVnodes = vip->nVnodes;
3200 nVnodes && STREAM_READ(vnode, vcp->diskSize, 1, file) == 1;
3201 nVnodes--, vnodeIndex++) {
3202 if (vnode->type != vNull) {
3203 register struct VnodeEssence *vep = &vip->vnodes[vnodeIndex];
3204 afs_fsize_t vnodeLength;
3205 vip->nAllocatedVnodes++;
3206 vep->count = vnode->linkCount;
3207 VNDISK_GET_LEN(vnodeLength, vnode);
3208 vep->blockCount = nBlocks(vnodeLength);
3209 vip->volumeBlockCount += vep->blockCount;
3210 vep->parent = vnode->parent;
3211 vep->unique = vnode->uniquifier;
3212 if (*maxu < vnode->uniquifier)
3213 *maxu = vnode->uniquifier;
3214 vep->modeBits = vnode->modeBits;
3215 vep->InodeNumber = VNDISK_GET_INO(vnode);
3216 vep->type = vnode->type;
3217 vep->author = vnode->author;
3218 vep->owner = vnode->owner;
3219 vep->group = vnode->group;
3220 if (vnode->type == vDirectory) {
3221 if (class != vLarge) {
3222 VnodeId vnodeNumber = bitNumberToVnodeNumber(vnodeIndex, class);
3223 vip->nAllocatedVnodes--;
3224 memset(vnode, 0, sizeof(vnode));
3225 IH_IWRITE(vnodeInfo[vSmall].handle,
3226 vnodeIndexOffset(vcp, vnodeNumber),
3227 (char *)&vnode, sizeof(vnode));
3230 vip->inodes[vnodeIndex] = VNDISK_GET_INO(vnode);
3239 GetDirName(VnodeId vnode, struct VnodeEssence *vp, char *path)
3241 struct VnodeEssence *parentvp;
3247 if (vp->parent && vp->name && (parentvp = CheckVnodeNumber(vp->parent))
3248 && GetDirName(vp->parent, parentvp, path)) {
3250 strcat(path, vp->name);
3256 /* To determine if a vnode is orhpaned or not, the vnode and all its parent
3257 * vnodes must be "claimed". The vep->claimed flag is set in JudgeEntry().
3260 IsVnodeOrphaned(VnodeId vnode)
3262 struct VnodeEssence *vep;
3265 return (1); /* Vnode zero does not exist */
3267 return (0); /* The root dir vnode is always claimed */
3268 vep = CheckVnodeNumber(vnode); /* Get the vnode essence */
3269 if (!vep || !vep->claimed)
3270 return (1); /* Vnode is not claimed - it is orphaned */
3272 return (IsVnodeOrphaned(vep->parent));
3276 SalvageDir(char *name, VolumeId rwVid, struct VnodeInfo *dirVnodeInfo,
3277 IHandle_t * alinkH, int i, struct DirSummary *rootdir,
3280 static struct DirSummary dir;
3281 static struct DirHandle dirHandle;
3282 struct VnodeEssence *parent;
3283 static char path[MAXPATHLEN];
3286 if (dirVnodeInfo->vnodes[i].salvaged)
3287 return; /* already salvaged */
3290 dirVnodeInfo->vnodes[i].salvaged = 1;
3292 if (dirVnodeInfo->inodes[i] == 0)
3293 return; /* Not allocated to a directory */
3295 if (bitNumberToVnodeNumber(i, vLarge) == 1) {
3296 if (dirVnodeInfo->vnodes[i].parent) {
3297 Log("Bad parent, vnode 1; %s...\n",
3298 (Testing ? "skipping" : "salvaging"));
3299 dirVnodeInfo->vnodes[i].parent = 0;
3300 dirVnodeInfo->vnodes[i].changed = 1;
3303 parent = CheckVnodeNumber(dirVnodeInfo->vnodes[i].parent);
3304 if (parent && parent->salvaged == 0)
3305 SalvageDir(name, rwVid, dirVnodeInfo, alinkH,
3306 vnodeIdToBitNumber(dirVnodeInfo->vnodes[i].parent),
3307 rootdir, rootdirfound);
3310 dir.vnodeNumber = bitNumberToVnodeNumber(i, vLarge);
3311 dir.unique = dirVnodeInfo->vnodes[i].unique;
3314 dir.parent = dirVnodeInfo->vnodes[i].parent;
3315 dir.haveDot = dir.haveDotDot = 0;
3316 dir.ds_linkH = alinkH;
3317 SetSalvageDirHandle(&dir.dirHandle, dir.rwVid, fileSysDevice,
3318 dirVnodeInfo->inodes[i]);
3320 dirok = ((RebuildDirs && !Testing) ? 0 : DirOK(&dir.dirHandle));
3323 Log("Directory bad, vnode %u; %s...\n", dir.vnodeNumber,
3324 (Testing ? "skipping" : "salvaging"));
3327 CopyAndSalvage(&dir);
3331 dirHandle = dir.dirHandle;
3334 GetDirName(bitNumberToVnodeNumber(i, vLarge),
3335 &dirVnodeInfo->vnodes[i], path);
3338 /* If enumeration failed for random reasons, we will probably delete
3339 * too much stuff, so we guard against this instead.
3341 assert(EnumerateDir(&dirHandle, JudgeEntry, &dir) == 0);
3344 /* Delete the old directory if it was copied in order to salvage.
3345 * CopyOnWrite has written the new inode # to the disk, but we still
3346 * have the old one in our local structure here. Thus, we idec the
3350 if (dir.copied && !Testing) {
3351 code = IH_DEC(dir.ds_linkH, dirHandle.dirh_handle->ih_ino, rwVid);
3353 dirVnodeInfo->inodes[i] = dir.dirHandle.dirh_inode;
3356 /* Remember rootdir DirSummary _after_ it has been judged */
3357 if (dir.vnodeNumber == 1 && dir.unique == 1) {
3358 memcpy(rootdir, &dir, sizeof(struct DirSummary));
3366 * Get a new FID that can be used to create a new file.
3368 * @param[in] volHeader vol header for the volume
3369 * @param[in] class what type of vnode we'll be creating (vLarge or vSmall)
3370 * @param[out] afid the FID that we can use (only Vnode and Unique are set)
3371 * @param[inout] maxunique max uniquifier for all vnodes in the volume;
3372 * updated to the new max unique if we create a new
3376 GetNewFID(VolumeDiskData *volHeader, VnodeClass class, AFSFid *afid,
3380 for (i = 0; i < vnodeInfo[class].nVnodes; i++) {
3381 if (vnodeInfo[class].vnodes[i].type == vNull) {
3385 if (i == vnodeInfo[class].nVnodes) {
3386 /* no free vnodes; make a new one */
3387 vnodeInfo[class].nVnodes++;
3388 vnodeInfo[class].vnodes = realloc(vnodeInfo[class].vnodes,
3389 sizeof(struct VnodeEssence) * (i+1));
3390 vnodeInfo[class].vnodes[i].type = vNull;
3393 afid->Vnode = bitNumberToVnodeNumber(i, class);
3395 if (volHeader->uniquifier < (*maxunique + 1)) {
3396 /* header uniq is bad; it will get bumped by 2000 later */
3397 afid->Unique = *maxunique + 1 + 2000;
3400 /* header uniq seems okay; just use that */
3401 afid->Unique = *maxunique = volHeader->uniquifier++;
3406 * Create a vnode for a README file explaining not to use a recreated-root vol.
3408 * @param[in] volHeader vol header for the volume
3409 * @param[in] alinkH ihandle for i/o for the volume
3410 * @param[in] vid volume id
3411 * @param[inout] maxunique max uniquifier for all vnodes in the volume;
3412 * updated to the new max unique if we create a new
3414 * @param[out] afid FID for the new readme vnode
3415 * @param[out] ainode the inode for the new readme file
3417 * @return operation status
3422 CreateReadme(VolumeDiskData *volHeader, IHandle_t *alinkH,
3423 VolumeId vid, Unique *maxunique, AFSFid *afid, Inode *ainode)
3426 struct VnodeDiskObject *rvnode = NULL;
3428 IHandle_t *readmeH = NULL;
3429 struct VnodeEssence *vep;
3431 time_t now = time(NULL);
3433 /* Try to make the note brief, but informative. Only administrators should
3434 * be able to read this file at first, so we can hopefully assume they
3435 * know what AFS is, what a volume is, etc. */
3437 "This volume has been salvaged, but has lost its original root directory.\n"
3438 "The root directory that exists now has been recreated from orphan files\n"
3439 "from the rest of the volume. This recreated root directory may interfere\n"
3440 "with old cached data on clients, and there is no way the salvager can\n"
3441 "reasonably prevent that. So, it is recommended that you do not continue to\n"
3442 "use this volume, but only copy the salvaged data to a new volume.\n"
3443 "Continuing to use this volume as it exists now may cause some clients to\n"
3444 "behave oddly when accessing this volume.\n"
3445 "\n\t -- Your friendly neighborhood OpenAFS salvager\n";
3446 /* ^ the person reading this probably just lost some data, so they could
3447 * use some cheering up. */
3449 /* -1 for the trailing NUL */
3450 length = sizeof(readme) - 1;
3452 GetNewFID(volHeader, vSmall, afid, maxunique);
3454 vep = &vnodeInfo[vSmall].vnodes[vnodeIdToBitNumber(afid->Vnode)];
3456 /* create the inode and write the contents */
3457 readmeinode = IH_CREATE(alinkH, fileSysDevice, fileSysPath, 0, vid,
3458 afid->Vnode, afid->Unique, 1);
3459 if (!VALID_INO(readmeinode)) {
3460 Log("CreateReadme: readme IH_CREATE failed\n");
3464 IH_INIT(readmeH, fileSysDevice, vid, readmeinode);
3465 bytes = IH_IWRITE(readmeH, 0, readme, length);
3466 IH_RELEASE(readmeH);
3468 if (bytes != length) {
3469 Log("CreateReadme: IWRITE failed (%d/%d)\n", (int)bytes,
3470 (int)sizeof(readme));
3474 /* create the vnode and write it out */
3475 rvnode = malloc(SIZEOF_SMALLDISKVNODE);
3477 Log("CreateRootDir: error alloc'ing memory\n");
3481 rvnode->type = vFile;
3483 rvnode->modeBits = 0777;
3484 rvnode->linkCount = 1;
3485 VNDISK_SET_LEN(rvnode, length);
3486 rvnode->uniquifier = afid->Unique;
3487 rvnode->dataVersion = 1;
3488 VNDISK_SET_INO(rvnode, readmeinode);
3489 rvnode->unixModifyTime = rvnode->serverModifyTime = now;
3494 rvnode->vnodeMagic = VnodeClassInfo[vSmall].magic;
3496 bytes = IH_IWRITE(vnodeInfo[vSmall].handle,
3497 vnodeIndexOffset(&VnodeClassInfo[vSmall], afid->Vnode),
3498 (char*)rvnode, SIZEOF_SMALLDISKVNODE);
3500 if (bytes != SIZEOF_SMALLDISKVNODE) {
3501 Log("CreateReadme: IH_IWRITE failed (%d/%d)\n", (int)bytes,
3502 (int)SIZEOF_SMALLDISKVNODE);
3506 /* update VnodeEssence for new readme vnode */
3507 vnodeInfo[vSmall].nAllocatedVnodes++;
3509 vep->blockCount = nBlocks(length);
3510 vnodeInfo[vSmall].volumeBlockCount += vep->blockCount;
3511 vep->parent = rvnode->parent;
3512 vep->unique = rvnode->uniquifier;
3513 vep->modeBits = rvnode->modeBits;
3514 vep->InodeNumber = VNDISK_GET_INO(rvnode);
3515 vep->type = rvnode->type;
3516 vep->author = rvnode->author;
3517 vep->owner = rvnode->owner;
3518 vep->group = rvnode->group;
3528 *ainode = readmeinode;
3533 if (IH_DEC(alinkH, readmeinode, vid)) {
3534 Log("CreateReadme (recovery): IH_DEC failed\n");
3546 * create a root dir for a volume that lacks one.
3548 * @param[in] volHeader vol header for the volume
3549 * @param[in] alinkH ihandle for disk access for this volume group
3550 * @param[in] vid volume id we're dealing with
3551 * @param[out] rootdir populated with info about the new root dir
3552 * @param[inout] maxunique max uniquifier for all vnodes in the volume;
3553 * updated to the new max unique if we create a new
3556 * @return operation status
3561 CreateRootDir(VolumeDiskData *volHeader, IHandle_t *alinkH, VolumeId vid,
3562 struct DirSummary *rootdir, Unique *maxunique)
3565 int decroot = 0, decreadme = 0;
3566 AFSFid did, readmeid;
3569 struct VnodeDiskObject *rootvnode = NULL;
3570 struct acl_accessList *ACL;
3573 struct VnodeEssence *vep;
3575 time_t now = time(NULL);
3577 if (!vnodeInfo[vLarge].vnodes && !vnodeInfo[vSmall].vnodes) {
3578 Log("Not creating new root dir; volume appears to lack any vnodes\n");
3582 if (!vnodeInfo[vLarge].vnodes) {
3583 /* We don't have any large vnodes in the volume; allocate room
3584 * for one so we can recreate the root dir */
3585 vnodeInfo[vLarge].nVnodes = 1;
3586 vnodeInfo[vLarge].vnodes = calloc(1, sizeof(struct VnodeEssence));
3587 vnodeInfo[vLarge].inodes = calloc(1, sizeof(Inode));
3589 assert(vnodeInfo[vLarge].vnodes);
3590 assert(vnodeInfo[vLarge].inodes);
3593 vep = &vnodeInfo[vLarge].vnodes[vnodeIdToBitNumber(1)];
3594 ip = &vnodeInfo[vLarge].inodes[vnodeIdToBitNumber(1)];
3595 if (vep->type != vNull) {
3596 Log("Not creating new root dir; existing vnode 1 is non-null\n");
3600 if (CreateReadme(volHeader, alinkH, vid, maxunique, &readmeid, &readmeinode)) {
3605 /* set the DV to a very high number, so it is unlikely that we collide
3606 * with a cached DV */
3609 rootinode = IH_CREATE(alinkH, fileSysDevice, fileSysPath, 0, vid, 1, 1, dv);
3610 if (!VALID_INO(rootinode)) {
3611 Log("CreateRootDir: IH_CREATE failed\n");
3616 SetSalvageDirHandle(&rootdir->dirHandle, vid, fileSysDevice, rootinode);
3620 if (MakeDir(&rootdir->dirHandle, (afs_int32*)&did, (afs_int32*)&did)) {
3621 Log("CreateRootDir: MakeDir failed\n");
3624 if (Create(&rootdir->dirHandle, "README.ROOTDIR", &readmeid)) {
3625 Log("CreateRootDir: Create failed\n");
3629 length = Length(&rootdir->dirHandle);
3630 DZap((void *)&rootdir->dirHandle);
3632 /* create the new root dir vnode */
3633 rootvnode = malloc(SIZEOF_LARGEDISKVNODE);
3635 Log("CreateRootDir: malloc failed\n");
3639 /* only give 'rl' permissions to 'system:administrators'. We do this to
3640 * try to catch the attention of an administrator, that they should not
3641 * be writing to this directory or continue to use it. */
3642 ACL = VVnodeDiskACL(rootvnode);
3643 ACL->size = sizeof(struct acl_accessList);
3644 ACL->version = ACL_ACLVERSION;
3648 ACL->entries[0].id = -204; /* system:administrators */
3649 ACL->entries[0].rights = PRSFS_READ | PRSFS_LOOKUP;
3651 rootvnode->type = vDirectory;
3652 rootvnode->cloned = 0;
3653 rootvnode->modeBits = 0777;
3654 rootvnode->linkCount = 2;
3655 VNDISK_SET_LEN(rootvnode, length);
3656 rootvnode->uniquifier = 1;
3657 rootvnode->dataVersion = dv;
3658 VNDISK_SET_INO(rootvnode, rootinode);
3659 rootvnode->unixModifyTime = rootvnode->serverModifyTime = now;
3660 rootvnode->author = 0;
3661 rootvnode->owner = 0;
3662 rootvnode->parent = 0;
3663 rootvnode->group = 0;
3664 rootvnode->vnodeMagic = VnodeClassInfo[vLarge].magic;
3666 /* write it out to disk */
3667 bytes = IH_IWRITE(vnodeInfo[vLarge].handle,
3668 vnodeIndexOffset(&VnodeClassInfo[vLarge], 1),
3669 (char*)rootvnode, SIZEOF_LARGEDISKVNODE);
3671 if (bytes != SIZEOF_LARGEDISKVNODE) {
3672 /* just cast to int and don't worry about printing real 64-bit ints;
3673 * a large disk vnode isn't anywhere near the 32-bit limit */
3674 Log("CreateRootDir: IH_IWRITE failed (%d/%d)\n", (int)bytes,
3675 (int)SIZEOF_LARGEDISKVNODE);
3679 /* update VnodeEssence for the new root vnode */
3680 vnodeInfo[vLarge].nAllocatedVnodes++;
3682 vep->blockCount = nBlocks(length);
3683 vnodeInfo[vLarge].volumeBlockCount += vep->blockCount;
3684 vep->parent = rootvnode->parent;
3685 vep->unique = rootvnode->uniquifier;
3686 vep->modeBits = rootvnode->modeBits;
3687 vep->InodeNumber = VNDISK_GET_INO(rootvnode);
3688 vep->type = rootvnode->type;
3689 vep->author = rootvnode->author;
3690 vep->owner = rootvnode->owner;
3691 vep->group = rootvnode->group;
3701 /* update DirSummary for the new root vnode */
3702 rootdir->vnodeNumber = 1;
3703 rootdir->unique = 1;
3704 rootdir->haveDot = 1;
3705 rootdir->haveDotDot = 1;
3706 rootdir->rwVid = vid;
3707 rootdir->copied = 0;
3708 rootdir->parent = 0;
3709 rootdir->name = strdup(".");
3710 rootdir->vname = volHeader->name;
3711 rootdir->ds_linkH = alinkH;
3718 if (decroot && IH_DEC(alinkH, rootinode, vid)) {
3719 Log("CreateRootDir (recovery): IH_DEC (root) failed\n");
3721 if (decreadme && IH_DEC(alinkH, readmeinode, vid)) {
3722 Log("CreateRootDir (recovery): IH_DEC (readme) failed\n");
3732 SalvageVolume(register struct InodeSummary *rwIsp, IHandle_t * alinkH)
3734 /* This routine, for now, will only be called for read-write volumes */
3736 int BlocksInVolume = 0, FilesInVolume = 0;
3737 register VnodeClass class;
3738 struct DirSummary rootdir, oldrootdir;
3739 struct VnodeInfo *dirVnodeInfo;
3740 struct VnodeDiskObject vnode;
3741 VolumeDiskData volHeader;
3743 int orphaned, rootdirfound = 0;
3744 Unique maxunique = 0; /* the maxUniquifier from the vnodes */
3745 afs_int32 ofiles = 0, oblocks = 0; /* Number of orphaned files/blocks */
3746 struct VnodeEssence *vep;
3749 afs_sfsize_t nBytes;
3751 VnodeId LFVnode, ThisVnode;
3752 Unique LFUnique, ThisUnique;
3756 vid = rwIsp->volSummary->header.id;
3757 IH_INIT(h, fileSysDevice, vid, rwIsp->volSummary->header.volumeInfo);
3758 nBytes = IH_IREAD(h, 0, (char *)&volHeader, sizeof(volHeader));
3759 assert(nBytes == sizeof(volHeader));
3760 assert(volHeader.stamp.magic == VOLUMEINFOMAGIC);
3761 assert(volHeader.destroyMe != DESTROY_ME);
3762 /* (should not have gotten this far with DESTROY_ME flag still set!) */
3764 DistilVnodeEssence(vid, vLarge, rwIsp->volSummary->header.largeVnodeIndex,
3766 DistilVnodeEssence(vid, vSmall, rwIsp->volSummary->header.smallVnodeIndex,
3769 dirVnodeInfo = &vnodeInfo[vLarge];
3770 for (i = 0; i < dirVnodeInfo->nVnodes; i++) {
3771 SalvageDir(volHeader.name, vid, dirVnodeInfo, alinkH, i, &rootdir,
3775 nt_sync(fileSysDevice);
3777 sync(); /* This used to be done lower level, for every dir */
3784 if (!rootdirfound && (orphans == ORPH_ATTACH) && !Testing) {
3786 Log("Cannot find root directory for volume %lu; attempting to create "
3787 "a new one\n", afs_printable_uint32_lu(vid));
3789 code = CreateRootDir(&volHeader, alinkH, vid, &rootdir, &maxunique);
3797 /* Parse each vnode looking for orphaned vnodes and
3798 * connect them to the tree as orphaned (if requested).
3800 oldrootdir = rootdir;
3801 for (class = 0; class < nVNODECLASSES; class++) {
3802 for (v = 0; v < vnodeInfo[class].nVnodes; v++) {
3803 vep = &(vnodeInfo[class].vnodes[v]);
3804 ThisVnode = bitNumberToVnodeNumber(v, class);
3805 ThisUnique = vep->unique;
3807 if ((vep->type == 0) || vep->claimed || ThisVnode == 1)
3808 continue; /* Ignore unused, claimed, and root vnodes */
3810 /* This vnode is orphaned. If it is a directory vnode, then the '..'
3811 * entry in this vnode had incremented the parent link count (In
3812 * JudgeEntry()). We need to go to the parent and decrement that
3813 * link count. But if the parent's unique is zero, then the parent
3814 * link count was not incremented in JudgeEntry().
3816 if (class == vLarge) { /* directory vnode */
3817 pv = vnodeIdToBitNumber(vep->parent);
3818 if (vnodeInfo[vLarge].vnodes[pv].unique != 0) {
3819 if (vep->parent == 1 && newrootdir) {
3820 /* this vnode's parent was the volume root, and
3821 * we just created the volume root. So, the parent
3822 * dir didn't exist during JudgeEntry, so the link
3823 * count was not inc'd there, so don't dec it here.
3829 vnodeInfo[vLarge].vnodes[pv].count++;
3835 continue; /* If no rootdir, can't attach orphaned files */
3837 /* Here we attach orphaned files and directories into the
3838 * root directory, LVVnode, making sure link counts stay correct.
3840 if ((orphans == ORPH_ATTACH) && !vep->todelete && !Testing) {
3841 LFVnode = rootdir.vnodeNumber; /* Lost+Found vnode number */
3842 LFUnique = rootdir.unique; /* Lost+Found uniquifier */
3844 /* Update this orphaned vnode's info. Its parent info and
3845 * link count (do for orphaned directories and files).
3847 vep->parent = LFVnode; /* Parent is the root dir */
3848 vep->unique = LFUnique;
3851 vep->count--; /* Inc link count (root dir will pt to it) */
3853 /* If this orphaned vnode is a directory, change '..'.
3854 * The name of the orphaned dir/file is unknown, so we
3855 * build a unique name. No need to CopyOnWrite the directory
3856 * since it is not connected to tree in BK or RO volume and
3857 * won't be visible there.
3859 if (class == vLarge) {
3863 /* Remove and recreate the ".." entry in this orphaned directory */
3864 SetSalvageDirHandle(&dh, vid, fileSysDevice,
3865 vnodeInfo[class].inodes[v]);
3867 pa.Unique = LFUnique;
3868 assert(Delete(&dh, "..") == 0);
3869 assert(Create(&dh, "..", &pa) == 0);
3871 /* The original parent's link count was decremented above.
3872 * Here we increment the new parent's link count.
3874 pv = vnodeIdToBitNumber(LFVnode);
3875 vnodeInfo[vLarge].vnodes[pv].count--;
3879 /* Go to the root dir and add this entry. The link count of the
3880 * root dir was incremented when ".." was created. Try 10 times.
3882 for (j = 0; j < 10; j++) {
3883 pa.Vnode = ThisVnode;
3884 pa.Unique = ThisUnique;
3886 (void)afs_snprintf(npath, sizeof npath, "%s.%u.%u",
3888 vLarge) ? "__ORPHANDIR__" :
3889 "__ORPHANFILE__"), ThisVnode,
3892 CopyOnWrite(&rootdir);
3893 code = Create(&rootdir.dirHandle, npath, &pa);
3897 ThisUnique += 50; /* Try creating a different file */
3900 Log("Attaching orphaned %s to volume's root dir as %s\n",
3901 ((class == vLarge) ? "directory" : "file"), npath);
3903 } /* for each vnode in the class */
3904 } /* for each class of vnode */
3906 /* Delete the old rootinode directory if the rootdir was CopyOnWrite */
3908 if (!oldrootdir.copied && rootdir.copied) {
3910 IH_DEC(oldrootdir.ds_linkH, oldrootdir.dirHandle.dirh_inode,
3913 /* dirVnodeInfo->inodes[?] is not updated with new inode number */
3916 DFlush(); /* Flush the changes */
3917 if (!rootdirfound && (orphans == ORPH_ATTACH)) {
3918 Log("Cannot attach orphaned files and directories: Root directory not found\n");
3919 orphans = ORPH_IGNORE;
3922 /* Write out all changed vnodes. Orphaned files and directories
3923 * will get removed here also (if requested).
3925 for (class = 0; class < nVNODECLASSES; class++) {
3926 int nVnodes = vnodeInfo[class].nVnodes;
3927 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
3928 struct VnodeEssence *vnodes = vnodeInfo[class].vnodes;
3929 FilesInVolume += vnodeInfo[class].nAllocatedVnodes;
3930 BlocksInVolume += vnodeInfo[class].volumeBlockCount;
3931 for (i = 0; i < nVnodes; i++) {
3932 register struct VnodeEssence *vnp = &vnodes[i];
3933 VnodeId vnodeNumber = bitNumberToVnodeNumber(i, class);
3935 /* If the vnode is good but is unclaimed (not listed in
3936 * any directory entries), then it is orphaned.
3939 if ((vnp->type != 0) && (orphaned = IsVnodeOrphaned(vnodeNumber))) {
3940 vnp->claimed = 0; /* Makes IsVnodeOrphaned calls faster */
3944 if (vnp->changed || vnp->count) {
3948 IH_IREAD(vnodeInfo[class].handle,
3949 vnodeIndexOffset(vcp, vnodeNumber),
3950 (char *)&vnode, sizeof(vnode));
3951 assert(nBytes == sizeof(vnode));
3953 vnode.parent = vnp->parent;
3954 oldCount = vnode.linkCount;
3955 vnode.linkCount = vnode.linkCount - vnp->count;
3958 orphaned = IsVnodeOrphaned(vnodeNumber);
3960 if (!vnp->todelete) {
3961 /* Orphans should have already been attached (if requested) */
3962 assert(orphans != ORPH_ATTACH);
3963 oblocks += vnp->blockCount;
3966 if (((orphans == ORPH_REMOVE) || vnp->todelete)
3968 BlocksInVolume -= vnp->blockCount;
3970 if (VNDISK_GET_INO(&vnode)) {
3972 IH_DEC(alinkH, VNDISK_GET_INO(&vnode), vid);
3975 memset(&vnode, 0, sizeof(vnode));
3977 } else if (vnp->count) {
3979 Log("Vnode %u: link count incorrect (was %d, %s %d)\n", vnodeNumber, oldCount, (Testing ? "would have changed to" : "now"), vnode.linkCount);
3982 vnode.modeBits = vnp->modeBits;
3985 vnode.dataVersion++;
3988 IH_IWRITE(vnodeInfo[class].handle,
3989 vnodeIndexOffset(vcp, vnodeNumber),
3990 (char *)&vnode, sizeof(vnode));
3991 assert(nBytes == sizeof(vnode));
3997 if (!Showmode && ofiles) {
3998 Log("%s %d orphaned files and directories (approx. %u KB)\n",
4000 && (orphans == ORPH_REMOVE)) ? "Removed" : "Found", ofiles,
4004 for (class = 0; class < nVNODECLASSES; class++) {
4005 register struct VnodeInfo *vip = &vnodeInfo[class];
4006 for (i = 0; i < vip->nVnodes; i++)
4007 if (vip->vnodes[i].name)
4008 free(vip->vnodes[i].name);
4015 /* Set correct resource utilization statistics */
4016 volHeader.filecount = FilesInVolume;
4017 volHeader.diskused = BlocksInVolume;
4019 /* Make sure the uniquifer is big enough: maxunique is the real maxUniquifier */
4020 if (volHeader.uniquifier < (maxunique + 1)) {
4022 Log("Volume uniquifier is too low; fixed\n");
4023 /* Plus 2,000 in case there are workstations out there with
4024 * cached vnodes that have since been deleted
4026 volHeader.uniquifier = (maxunique + 1 + 2000);
4030 Log("*** WARNING: Root directory recreated, but volume is fragile! "
4031 "Only use this salvaged volume to copy data to another volume; "
4032 "do not continue to use this volume (%lu) as-is.\n",
4033 afs_printable_uint32_lu(vid));
4036 #ifdef FSSYNC_BUILD_CLIENT
4037 if (!Testing && VolumeChanged) {
4038 afs_int32 fsync_code;
4040 fsync_code = FSYNC_VolOp(vid, NULL, FSYNC_VOL_BREAKCBKS, FSYNC_SALVAGE, NULL);
4042 Log("Error trying to tell the fileserver to break callbacks for "
4043 "changed volume %lu; error code %ld\n",
4044 afs_printable_uint32_lu(vid),
4045 afs_printable_int32_ld(fsync_code));
4050 #endif /* FSSYNC_BUILD_CLIENT */
4052 /* Turn off the inUse bit; the volume's been salvaged! */
4053 volHeader.inUse = 0; /* clear flag indicating inUse@last crash */
4054 volHeader.needsSalvaged = 0; /* clear 'damaged' flag */
4055 volHeader.inService = 1; /* allow service again */
4056 volHeader.needsCallback = (VolumeChanged != 0);
4057 volHeader.dontSalvage = DONT_SALVAGE;
4060 nBytes = IH_IWRITE(h, 0, (char *)&volHeader, sizeof(volHeader));
4061 assert(nBytes == sizeof(volHeader));
4064 Log("%sSalvaged %s (%u): %d files, %d blocks\n",
4065 (Testing ? "It would have " : ""), volHeader.name, volHeader.id,
4066 FilesInVolume, BlocksInVolume);
4068 IH_RELEASE(vnodeInfo[vSmall].handle);
4069 IH_RELEASE(vnodeInfo[vLarge].handle);
4075 ClearROInUseBit(struct VolumeSummary *summary)
4077 IHandle_t *h = summary->volumeInfoHandle;
4078 afs_sfsize_t nBytes;
4080 VolumeDiskData volHeader;
4082 nBytes = IH_IREAD(h, 0, (char *)&volHeader, sizeof(volHeader));
4083 assert(nBytes == sizeof(volHeader));
4084 assert(volHeader.stamp.magic == VOLUMEINFOMAGIC);
4085 volHeader.inUse = 0;
4086 volHeader.needsSalvaged = 0;
4087 volHeader.inService = 1;
4088 volHeader.dontSalvage = DONT_SALVAGE;
4090 nBytes = IH_IWRITE(h, 0, (char *)&volHeader, sizeof(volHeader));
4091 assert(nBytes == sizeof(volHeader));
4096 * Possible delete the volume.
4098 * deleteMe - Always do so, only a partial volume.
4101 MaybeZapVolume(register struct InodeSummary *isp, char *message, int deleteMe,
4104 if (readOnly(isp) || deleteMe) {
4105 if (isp->volSummary && isp->volSummary->fileName) {
4108 Log("Volume %u (is only a partial volume--probably an attempt was made to move/restore it when a machine crash occured.\n", isp->volumeId);
4110 Log("It will be deleted on this server (you may find it elsewhere)\n");
4113 Log("Volume %u needs to be salvaged. Since it is read-only, however,\n", isp->volumeId);
4115 Log("it will be deleted instead. It should be recloned.\n");
4120 sprintf(path, "%s/%s", fileSysPath, isp->volSummary->fileName);
4122 code = VDestroyVolumeDiskHeader(fileSysPartition, isp->volumeId, isp->RWvolumeId);
4124 Log("Error %ld destroying volume disk header for volume %lu\n",
4125 afs_printable_int32_ld(code),
4126 afs_printable_uint32_lu(isp->volumeId));
4129 /* make sure we actually delete the fileName file; ENOENT
4130 * is fine, since VDestroyVolumeDiskHeader probably already
4132 if (unlink(path) && errno != ENOENT) {
4133 Log("Unable to unlink %s (errno = %d)\n", path, errno);
4137 } else if (!check) {
4138 Log("%s salvage was unsuccessful: read-write volume %u\n", message,
4140 Abort("Salvage of volume %u aborted\n", isp->volumeId);
4144 #ifdef AFS_DEMAND_ATTACH_FS
4146 * Locks a volume on disk for salvaging.
4148 * @param[in] volumeId volume ID to lock
4150 * @return operation status
4152 * @retval -1 volume lock raced with a fileserver restart; all volumes must
4153 * checked out and locked again
4158 LockVolume(VolumeId volumeId)
4163 /* should always be WRITE_LOCK, but keep the lock-type logic all
4164 * in one place, in VVolLockType. Params will be ignored, but
4165 * try to provide what we're logically doing. */
4166 locktype = VVolLockType(V_VOLUPD, 1);
4168 code = VLockVolumeByIdNB(volumeId, fileSysPartition, locktype);
4170 if (code == EBUSY) {
4171 Abort("Someone else appears to be using volume %lu; Aborted\n",
4172 afs_printable_uint32_lu(volumeId));
4174 Abort("Error %ld trying to lock volume %lu; Aborted\n",
4175 afs_printable_int32_ld(code),
4176 afs_printable_uint32_lu(volumeId));
4179 code = FSYNC_VerifyCheckout(volumeId, fileSysPathName, FSYNC_VOL_OFF, FSYNC_SALVAGE);
4180 if (code == SYNC_DENIED) {
4181 /* need to retry checking out volumes */
4184 if (code != SYNC_OK) {
4185 Abort("FSYNC_VerifyCheckout failed for volume %lu with code %ld\n",
4186 afs_printable_uint32_lu(volumeId), afs_printable_int32_ld(code));
4189 /* set inUse = programType in the volume header to ensure that nobody
4190 * tries to use this volume again without salvaging, if we somehow crash
4191 * or otherwise exit before finishing the salvage.
4195 struct VolumeHeader header;
4196 struct VolumeDiskHeader diskHeader;
4197 struct VolumeDiskData volHeader;
4199 code = VReadVolumeDiskHeader(volumeId, fileSysPartition, &diskHeader);
4204 DiskToVolumeHeader(&header, &diskHeader);
4206 IH_INIT(h, fileSysDevice, header.parent, header.volumeInfo);
4207 if (IH_IREAD(h, 0, (char*)&volHeader, sizeof(volHeader)) != sizeof(volHeader) ||
4208 volHeader.stamp.magic != VOLUMEINFOMAGIC) {
4214 volHeader.inUse = programType;
4216 /* If we can't re-write the header, bail out and error. We don't
4217 * assert when reading the header, since it's possible the
4218 * header isn't really there (when there's no data associated
4219 * with the volume; we just delete the vol header file in that
4220 * case). But if it's there enough that we can read it, but
4221 * somehow we cannot write to it to signify we're salvaging it,
4222 * we've got a big problem and we cannot continue. */
4223 assert(IH_IWRITE(h, 0, (char*)&volHeader, sizeof(volHeader)) == sizeof(volHeader));
4230 #endif /* AFS_DEMAND_ATTACH_FS */
4233 AskOffline(VolumeId volumeId, char * partition)
4238 memset(&res, 0, sizeof(res));
4240 for (i = 0; i < 3; i++) {
4241 code = FSYNC_VolOp(volumeId, partition, FSYNC_VOL_OFF, FSYNC_SALVAGE, &res);
4243 if (code == SYNC_OK) {
4245 } else if (code == SYNC_DENIED) {
4246 #ifdef DEMAND_ATTACH_ENABLE
4247 Log("AskOffline: file server denied offline request; a general salvage may be required.\n");
4249 Log("AskOffline: file server denied offline request; a general salvage is required.\n");
4251 Abort("Salvage aborted\n");
4252 } else if (code == SYNC_BAD_COMMAND) {
4253 Log("AskOffline: fssync protocol mismatch (bad command word '%d'); salvage aborting.\n",
4255 #ifdef DEMAND_ATTACH_ENABLE
4256 Log("AskOffline: please make sure fileserver, volserver, salvageserver and salvager binaries are same version.\n");
4258 Log("AskOffline: please make sure fileserver, volserver and salvager binaries are same version.\n");
4260 Abort("Salvage aborted\n");
4263 Log("AskOffline: request for fileserver to take volume offline failed; trying again...\n");
4264 FSYNC_clientFinis();
4268 if (code != SYNC_OK) {
4269 Log("AskOffline: request for fileserver to take volume offline failed; salvage aborting.\n");
4270 Abort("Salvage aborted\n");
4275 AskOnline(VolumeId volumeId, char *partition)
4279 for (i = 0; i < 3; i++) {
4280 code = FSYNC_VolOp(volumeId, partition, FSYNC_VOL_ON, FSYNC_WHATEVER, NULL);
4282 if (code == SYNC_OK) {
4284 } else if (code == SYNC_DENIED) {
4285 Log("AskOnline: file server denied online request to volume %u partition %s; trying again...\n", volumeId, partition);
4286 } else if (code == SYNC_BAD_COMMAND) {
4287 Log("AskOnline: fssync protocol mismatch (bad command word '%d')\n",
4289 #ifdef DEMAND_ATTACH_ENABLE
4290 Log("AskOnline: please make sure fileserver, volserver, salvageserver and salvager binaries are same version.\n");
4292 Log("AskOnline: please make sure fileserver, volserver and salvager binaries are same version.\n");
4297 Log("AskOnline: request for fileserver to take volume offline failed; trying again...\n");
4298 FSYNC_clientFinis();
4305 CopyInode(Device device, Inode inode1, Inode inode2, int rwvolume)
4307 /* Volume parameter is passed in case iopen is upgraded in future to
4308 * require a volume Id to be passed
4311 IHandle_t *srcH, *destH;
4312 FdHandle_t *srcFdP, *destFdP;
4315 IH_INIT(srcH, device, rwvolume, inode1);
4316 srcFdP = IH_OPEN(srcH);
4317 assert(srcFdP != NULL);
4318 IH_INIT(destH, device, rwvolume, inode2);
4319 destFdP = IH_OPEN(destH);
4320 while ((nBytes = FDH_READ(srcFdP, buf, sizeof(buf))) > 0)
4321 assert(FDH_WRITE(destFdP, buf, nBytes) == nBytes);
4322 assert(nBytes == 0);
4323 FDH_REALLYCLOSE(srcFdP);
4324 FDH_REALLYCLOSE(destFdP);
4331 PrintInodeList(void)
4333 register struct ViceInodeInfo *ip;
4334 struct ViceInodeInfo *buf;
4335 struct afs_stat status;
4336 register int nInodes;
4338 assert(afs_fstat(inodeFd, &status) == 0);
4339 buf = (struct ViceInodeInfo *)malloc(status.st_size);
4340 assert(buf != NULL);
4341 nInodes = status.st_size / sizeof(struct ViceInodeInfo);
4342 assert(read(inodeFd, buf, status.st_size) == status.st_size);
4343 for (ip = buf; nInodes--; ip++) {
4344 Log("Inode:%s, linkCount=%d, size=%#llx, p=(%u,%u,%u,%u)\n",
4345 PrintInode(NULL, ip->inodeNumber), ip->linkCount,
4346 (afs_uintmax_t) ip->byteCount, ip->u.param[0], ip->u.param[1],
4347 ip->u.param[2], ip->u.param[3]);
4353 PrintInodeSummary(void)
4356 struct InodeSummary *isp;
4358 for (i = 0; i < nVolumesInInodeFile; i++) {
4359 isp = &inodeSummary[i];
4360 Log("VID:%u, RW:%u, index:%d, nInodes:%d, nSpecialInodes:%d, maxUniquifier:%u, volSummary\n", isp->volumeId, isp->RWvolumeId, isp->index, isp->nInodes, isp->nSpecialInodes, isp->maxUniquifier);
4365 PrintVolumeSummary(void)
4368 struct VolumeSummary *vsp;
4370 for (i = 0, vsp = volumeSummaryp; i < nVolumes; vsp++, i++) {
4371 Log("fileName:%s, header, wouldNeedCallback\n", vsp->fileName);
4381 assert(0); /* Fork is never executed in the NT code path */
4385 #ifdef AFS_DEMAND_ATTACH_FS
4386 if ((f == 0) && (programType == salvageServer)) {
4387 /* we are a salvageserver child */
4388 #ifdef FSSYNC_BUILD_CLIENT
4389 VChildProcReconnectFS_r();
4391 #ifdef SALVSYNC_BUILD_CLIENT
4395 #endif /* AFS_DEMAND_ATTACH_FS */
4396 #endif /* !AFS_NT40_ENV */
4406 #ifdef AFS_DEMAND_ATTACH_FS
4407 if (programType == salvageServer) {
4408 #ifdef SALVSYNC_BUILD_CLIENT
4411 #ifdef FSSYNC_BUILD_CLIENT
4415 #endif /* AFS_DEMAND_ATTACH_FS */
4418 if (main_thread != pthread_self())
4419 pthread_exit((void *)code);
4432 pid = wait(&status);
4434 if (WCOREDUMP(status))
4435 Log("\"%s\" core dumped!\n", prog);
4436 if (WIFSIGNALED(status) != 0 || WEXITSTATUS(status) != 0)
4442 TimeStamp(time_t clock, int precision)
4445 static char timestamp[20];
4446 lt = localtime(&clock);
4448 (void)strftime(timestamp, 20, "%m/%d/%Y %H:%M:%S", lt);
4450 (void)strftime(timestamp, 20, "%m/%d/%Y %H:%M", lt);
4455 CheckLogFile(char * log_path)
4457 char oldSlvgLog[AFSDIR_PATH_MAX];
4459 #ifndef AFS_NT40_ENV
4466 strcpy(oldSlvgLog, log_path);
4467 strcat(oldSlvgLog, ".old");
4469 renamefile(log_path, oldSlvgLog);
4470 logFile = afs_fopen(log_path, "a");
4472 if (!logFile) { /* still nothing, use stdout */
4476 #ifndef AFS_NAMEI_ENV
4477 AFS_DEBUG_IOPS_LOG(logFile);
4482 #ifndef AFS_NT40_ENV
4484 TimeStampLogFile(char * log_path)
4486 char stampSlvgLog[AFSDIR_PATH_MAX];
4491 lt = localtime(&now);
4492 (void)afs_snprintf(stampSlvgLog, sizeof stampSlvgLog,
4493 "%s.%04d-%02d-%02d.%02d:%02d:%02d",
4494 log_path, lt->tm_year + 1900,
4495 lt->tm_mon + 1, lt->tm_mday, lt->tm_hour, lt->tm_min,
4498 /* try to link the logfile to a timestamped filename */
4499 /* if it fails, oh well, nothing we can do */
4500 link(log_path, stampSlvgLog);
4509 #ifndef AFS_NT40_ENV
4511 printf("Can't show log since using syslog.\n");
4522 logFile = afs_fopen(AFSDIR_SERVER_SLVGLOG_FILEPATH, "r");
4525 printf("Can't read %s, exiting\n", AFSDIR_SERVER_SLVGLOG_FILEPATH);
4528 while (fgets(line, sizeof(line), logFile))
4535 Log(const char *format, ...)
4541 va_start(args, format);
4542 (void)afs_vsnprintf(tmp, sizeof tmp, format, args);
4544 #ifndef AFS_NT40_ENV
4546 syslog(LOG_INFO, "%s", tmp);
4550 gettimeofday(&now, 0);
4551 fprintf(logFile, "%s %s", TimeStamp(now.tv_sec, 1), tmp);
4557 Abort(const char *format, ...)
4562 va_start(args, format);
4563 (void)afs_vsnprintf(tmp, sizeof tmp, format, args);
4565 #ifndef AFS_NT40_ENV
4567 syslog(LOG_INFO, "%s", tmp);
4571 fprintf(logFile, "%s", tmp);
4583 ToString(const char *s)
4586 p = (char *)malloc(strlen(s) + 1);
4592 /* Remove the FORCESALVAGE file */
4594 RemoveTheForce(char *path)
4597 struct afs_stat force; /* so we can use afs_stat to find it */
4598 strcpy(target,path);
4599 strcat(target,"/FORCESALVAGE");
4600 if (!Testing && ForceSalvage) {
4601 if (afs_stat(target,&force) == 0) unlink(target);
4605 #ifndef AFS_AIX32_ENV
4607 * UseTheForceLuke - see if we can use the force
4610 UseTheForceLuke(char *path)
4612 struct afs_stat force;
4614 strcpy(target,path);
4615 strcat(target,"/FORCESALVAGE");
4617 return (afs_stat(target, &force) == 0);
4621 * UseTheForceLuke - see if we can use the force
4624 * The VRMIX fsck will not muck with the filesystem it is supposedly
4625 * fixing and create a "FORCESALVAGE" file (by design). Instead, we
4626 * muck directly with the root inode, which is within the normal
4628 * ListViceInodes() has a side effect of setting ForceSalvage if
4629 * it detects a need, based on root inode examination.
4632 UseTheForceLuke(char *path)
4635 return 0; /* sorry OB1 */
4640 /* NT support routines */
4642 static char execpathname[MAX_PATH];
4644 nt_SalvagePartition(char *partName, int jobn)
4649 if (!*execpathname) {
4650 n = GetModuleFileName(NULL, execpathname, MAX_PATH - 1);
4651 if (!n || n == 1023)
4654 job.cj_magic = SALVAGER_MAGIC;
4655 job.cj_number = jobn;
4656 (void)strcpy(job.cj_part, partName);
4657 pid = (int)spawnprocveb(execpathname, save_args, NULL, &job, sizeof(job));
4662 nt_SetupPartitionSalvage(void *datap, int len)
4664 childJob_t *jobp = (childJob_t *) datap;
4665 char logname[AFSDIR_PATH_MAX];
4667 if (len != sizeof(childJob_t))
4669 if (jobp->cj_magic != SALVAGER_MAGIC)
4674 (void)sprintf(logname, "%s.%d", AFSDIR_SERVER_SLVGLOG_FILEPATH,
4676 logFile = afs_fopen(logname, "w");
4684 #endif /* AFS_NT40_ENV */