int debug; /* -d flag */
-int Testing = 0; /* -n flag */
+extern int Testing; /* -n flag */
int ListInodeOption; /* -i flag */
int ShowRootFiles; /* -r flag */
int RebuildDirs; /* -sal flag */
int orphans = ORPH_IGNORE; /* -orphans option */
int Showmode = 0;
+
#ifndef AFS_NT40_ENV
int useSyslog = 0; /* -syslog flag */
int useSyslogFacility = LOG_DAEMON; /* -syslogfacility option */
#endif
+#ifdef AFS_NT40_ENV
+int canfork = 0;
+#else
+int canfork = 1;
+#endif
+
#define MAXPARALLEL 32
int OKToZap; /* -o flag */
char *fileSysPathName; /* NT needs this to make name pretty in log. */
IHandle_t *VGLinkH; /* Link handle for current volume group. */
int VGLinkH_cnt; /* # of references to lnk handle. */
-struct DiskPartition *fileSysPartition; /* Partition being salvaged */
+struct DiskPartition64 *fileSysPartition; /* Partition being salvaged */
#ifndef AFS_NT40_ENV
char *fileSysDeviceName; /* The block device where the file system
* being salvaged was mounted */
return 0; /* otherwise may be transient, e.g. EMFILE */
}
-
#define MAX_ARGS 128
#ifdef AFS_NT40_ENV
char *save_args[MAX_ARGS];
int n_save_args = 0;
-pthread_t main_thread;
+extern pthread_t main_thread;
+childJob_t myjob = { SALVAGER_MAGIC, NOT_CHILD, "" };
#endif
-
/* Get the salvage lock if not already held. Hold until process exits. */
void
ObtainSalvageLock(void)
#define HDSTR "\\Device\\Harddisk"
#define HDLEN (sizeof(HDSTR)-1) /* Length of "\Device\Harddisk" */
int
-SameDisk(struct DiskPartition *p1, struct DiskPartition *p2)
+SameDisk(struct DiskPartition64 *p1, struct DiskPartition64 *p2)
{
#define RES_LEN 256
char res[RES_LEN];
* PartsPerDisk are on the same disk.
*/
void
-SalvageFileSysParallel(struct DiskPartition *partP)
+SalvageFileSysParallel(struct DiskPartition64 *partP)
{
struct job {
- struct DiskPartition *partP;
+ struct DiskPartition64 *partP;
int pid; /* Pid for this job */
int jobnumb; /* Log file job number */
struct job *nextjob; /* Next partition on disk to salvage */
void
-SalvageFileSys(struct DiskPartition *partP, VolumeId singleVolumeNumber)
+SalvageFileSys(struct DiskPartition64 *partP, VolumeId singleVolumeNumber)
{
if (!canfork || debug || Fork() == 0) {
SalvageFileSys1(partP, singleVolumeNumber);
}
void
-SalvageFileSys1(struct DiskPartition *partP, VolumeId singleVolumeNumber)
+SalvageFileSys1(struct DiskPartition64 *partP, VolumeId singleVolumeNumber)
{
char *name, *tdir;
char inodeListPath[256];
DiskToVolumeHeader(&vsp->header, &diskHeader);
if (singleVolumeNumber && vsp->header.id == singleVolumeNumber
&& vsp->header.parent != singleVolumeNumber) {
- Log("%u is a read-only volume; not salvaged\n",
- singleVolumeNumber);
- Exit(1);
+ if (programType == salvageServer) {
+#ifdef SALVSYNC_BUILD_CLIENT
+ Log("fileserver requested salvage of clone %u; scheduling salvage of volume group %u...\n",
+ vsp->header.id, vsp->header.parent);
+ if (SALVSYNC_LinkVolume(vsp->header.parent,
+ vsp->header.id,
+ fileSysPartition->name,
+ NULL) != SYNC_OK) {
+ Log("schedule request failed\n");
+ }
+#endif
+ Exit(SALSRV_EXIT_VOLGROUP_LINK);
+ } else {
+ Log("%u is a read-only volume; not salvaged\n",
+ singleVolumeNumber);
+ Exit(1);
+ }
}
if (!singleVolumeNumber
|| (vsp->header.id == singleVolumeNumber
Abort("Can't open link table for volume %u (error = %d)\n",
isp->RWvolumeId, errno);
- if (FDH_TRUNC(fdP, 0) < 0)
+ if (FDH_TRUNC(fdP, sizeof(version) + sizeof(short)) < 0)
Abort("Can't truncate link table for volume %u (error = %d)\n",
isp->RWvolumeId, errno);
if (Testing) {
IH_INIT(VGLinkH, fileSysDevice, -1, -1);
} else {
+ int i, j;
+ struct ViceInodeInfo *ip;
CreateLinkTable(isp, ino);
+ fdP = IH_OPEN(VGLinkH);
+ /* Sync fake 1 link counts to the link table, now that it exists */
+ if (fdP) {
+ for (i = 0; i < nVols; i++) {
+ ip = allInodes + isp[i].index;
+ for (j = isp[i].nSpecialInodes; j < isp[i].nInodes; j++) {
+#ifdef AFS_NT40_ENV
+ nt_SetLinkCount(fdP, ip[j].inodeNumber, 1, 1);
+#else
+ namei_SetLinkCount(fdP, ip[j].inodeNumber, 1, 1);
+#endif
+ }
+ }
+ }
}
}
if (fdP)
&& volHeader.stamp.magic == VOLUMEINFOMAGIC
&& volHeader.dontSalvage == DONT_SALVAGE
&& volHeader.needsSalvaged == 0 && volHeader.destroyMe == 0) {
- if (volHeader.inUse == 1) {
+ if (volHeader.inUse != 0) {
volHeader.inUse = 0;
volHeader.inService = 1;
if (!Testing) {
vnodeIndexOffset(vcp, dir->vnodeNumber), (char *)&vnode,
sizeof(vnode));
assert(lcode == sizeof(vnode));
+#if 0
#ifdef AFS_NT40_ENV
nt_sync(fileSysDevice);
#else
* an open FD on the file itself to fsync.
*/
#endif
+#else
+ vnodeInfo[vLarge].handle->ih_synced = 1;
+#endif
code = IH_DEC(dir->ds_linkH, oldinode, dir->rwVid);
assert(code == 0);
dir->dirHandle = newdir;
SalvageDir(volHeader.name, vid, dirVnodeInfo, alinkH, i, &rootdir,
&rootdirfound);
}
+#ifdef AFS_NT40_ENV
+ nt_sync(fileSysDevice);
+#else
+ sync(); /* This used to be done lower level, for every dir */
+#endif
if (Showmode) {
IH_RELEASE(h);
return 0;
#else
f = fork();
assert(f >= 0);
+#ifdef AFS_DEMAND_ATTACH_FS
+ if ((f == 0) && (programType == salvageServer)) {
+ /* we are a salvageserver child */
+#ifdef FSSYNC_BUILD_CLIENT
+ VChildProcReconnectFS_r();
#endif
+#ifdef SALVSYNC_BUILD_CLIENT
+ VReconnectSALV_r();
+#endif
+ }
+#endif /* AFS_DEMAND_ATTACH_FS */
+#endif /* !AFS_NT40_ENV */
return f;
}
{
if (ShowLog)
showlog();
+
+#ifdef AFS_DEMAND_ATTACH_FS
+ if (programType == salvageServer) {
+#ifdef SALVSYNC_BUILD_CLIENT
+ VDisconnectSALV();
+#endif
+#ifdef FSSYNC_BUILD_CLIENT
+ VDisconnectFS();
+#endif
+ }
+#endif /* AFS_DEMAND_ATTACH_FS */
+
#ifdef AFS_NT40_ENV
if (main_thread != pthread_self())
pthread_exit((void *)code);
syslog(LOG_INFO, "%s", tmp);
} else
#endif
- {
- gettimeofday(&now, 0);
- fprintf(logFile, "%s %s", TimeStamp(now.tv_sec, 1), tmp);
- fflush(logFile);
- }
+ if (logFile) {
+ gettimeofday(&now, 0);
+ fprintf(logFile, "%s %s", TimeStamp(now.tv_sec, 1), tmp);
+ fflush(logFile);
+ }
}
void
syslog(LOG_INFO, "%s", tmp);
} else
#endif
- {
- fprintf(logFile, "%s", tmp);
- fflush(logFile);
- if (ShowLog)
- showlog();
- }
+ if (logFile) {
+ fprintf(logFile, "%s", tmp);
+ fflush(logFile);
+ if (ShowLog)
+ showlog();
+ }
if (debug)
abort();