/*
* Copyright 2000, International Business Machines Corporation and others.
* All Rights Reserved.
- *
+ *
* This software has been released under the terms of the IBM Public
* License. For details, see the LICENSE file in the top-level source
* directory or online at http://www.openafs.org/dl/license10.html
#include <afsconfig.h>
#include <afs/param.h>
+#include <afs/procmgmt.h>
+#include <roken.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#endif /* ITIMER_REAL */
#endif
-#if defined(AFS_AIX_ENV) || defined(AFS_SUN4_ENV)
-#define WCOREDUMP(x) (x & 0200)
+#ifndef WCOREDUMP
+#define WCOREDUMP(x) ((x) & 0200)
#endif
#include <rx/xdr.h>
#include <afs/afsint.h>
-#include <afs/assert.h>
+#include <afs/afs_assert.h>
#if !defined(AFS_SGI_ENV) && !defined(AFS_NT40_ENV)
#if defined(AFS_VFSINCL_ENV)
#include <sys/vnode.h>
#ifdef AFS_OSF_ENV
#include <ufs/inode.h>
#else /* AFS_OSF_ENV */
-#if !defined(AFS_LINUX20_ENV) && !defined(AFS_XBSD_ENV)
+#if !defined(AFS_LINUX20_ENV) && !defined(AFS_XBSD_ENV) && !defined(AFS_ARM_DARWIN_ENV)
#include <sys/inode.h>
#endif
#endif
#include <afs/dir.h>
#include <afs/afsutil.h>
#include <afs/fileutil.h>
-#include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
#ifndef AFS_NT40_ENV
#include <syslog.h>
#endif
#include "viceinode.h"
#include "salvage.h"
#include "vol-salvage.h"
+#include "common.h"
#ifdef AFS_NT40_ENV
#include <pthread.h>
pthread_t main_thread;
#endif
-
static int get_salvage_lock = 0;
-
-/* Forward declarations */
-/*@printflike@*/ void Log(const char *format, ...);
-/*@printflike@*/ void Abort(const char *format, ...);
-
-
static int
handleit(struct cmd_syndesc *as, void *arock)
{
- register struct cmd_item *ti;
+ struct cmd_item *ti;
char pname[100], *temp;
- afs_int32 seenpart = 0, seenvol = 0, vid = 0;
-
+ afs_int32 seenpart = 0, seenvol = 0;
+ VolumeId vid = 0;
+ ProgramType pt;
+
#ifdef FAST_RESTART
afs_int32 seenany = 0;
#endif
-
+
+ VolumePackageOptions opts;
struct DiskPartition64 *partP;
#ifdef AFS_SGI_VNODE_GLUE
char *msg =
"Exiting immediately without salvage. Look into the FileLog to find volumes which really need to be salvaged!";
+#ifndef AFS_NT40_ENV
if (useSyslog)
Log(msg);
else
+#endif
printf("%s\n", msg);
Exit(0);
strncpy(pname, ti->data, 100);
}
if ((ti = as->parms[1].items)) { /* -volumeid */
+ char *end;
+ unsigned long vid_l;
if (!seenpart) {
printf
("You must also specify '-partition' option with the '-volumeid' option\n");
exit(-1);
}
seenvol = 1;
- vid = atoi(ti->data);
+ vid_l = strtoul(ti->data, &end, 10);
+ if (vid_l >= MAX_AFS_UINT32 || vid_l == ULONG_MAX || *end != '\0') {
+ Log("salvage: invalid volume id specified; salvage aborted\n");
+ Exit(1);
+ }
+ vid = (VolumeId)vid_l;
}
if (as->parms[2].items) /* -debug */
debug = 1;
Testing = 1;
if (as->parms[4].items) /* -inodes */
ListInodeOption = 1;
- if (as->parms[5].items) /* -force */
+ if (as->parms[5].items || as->parms[21].items) /* -force, -f */
ForceSalvage = 1;
if (as->parms[6].items) /* -oktozap */
OKToZap = 1;
char *msg =
"Exiting immediately without salvage. Look into the FileLog to find volumes which really need to be salvaged!";
+#ifndef AFS_NT40_ENV
if (useSyslog)
Log(msg);
else
+#endif
printf("%s\n", msg);
Exit(0);
}
-#elif defined(DEMAND_ATTACH_ENABLE)
- if (seenvol && !as->parms[19].items) {
- char * msg =
- "The standalone salvager cannot be run concurrently with a Demand Attach Fileserver. Please use 'salvageserver -client <partition> <volume id>' to manually schedule volume salvages with the salvageserver (new versions of 'bos salvage' automatically do this for you). Or, if you insist on using the standalone salvager, add the -forceDAFS flag to your salvager command line.";
-
- if (useSyslog)
- Log(msg);
- else
- printf("%s\n", msg);
- Exit(1);
- }
#endif
- if (get_salvage_lock) {
- ObtainSalvageLock();
- }
-
/* Note: if seenvol we initialize this as a standard volume utility: this has the
* implication that the file server may be running; negotations have to be made with
* the file server in this case to take the read write volume and associated read-only
}
}
#endif
- VInitVolumePackage(seenvol ? volumeUtility : salvager, 5, 5,
- DONT_CONNECT_FS, 0);
+
+ if (seenvol) {
+ pt = volumeSalvager;
+ } else {
+ pt = salvager;
+ }
+
+ VOptDefaults(pt, &opts);
+ if (VInitVolumePackage2(pt, &opts)) {
+ Log("errors encountered initializing volume package; salvage aborted\n");
+ Exit(1);
+ }
+
+ /* defer lock until we init volume package */
+ if (get_salvage_lock) {
+ if (seenvol && AskDAFS()) /* support forceDAFS */
+ ObtainSharedSalvageLock();
+ else
+ ObtainSalvageLock();
+ }
+
+ /*
+ * Ok to defer this as Exit will clean up and no real work is done
+ * init'ing volume package
+ */
+ if (seenvol) {
+ char *msg = NULL;
+#if defined(AFS_DEMAND_ATTACH_FS) || defined(AFS_DEMAND_ATTACH_UTIL)
+ if (!AskDAFS()) {
+ msg =
+ "The DAFS dasalvager cannot be run with a non-DAFS fileserver. Please use 'salvager'.";
+ }
+ if (!msg && !as->parms[20].items) {
+ msg =
+ "The standalone salvager cannot be run concurrently with a Demand Attach Fileserver. Please use 'salvageserver -client <partition> <volume id>' to manually schedule volume salvages with the salvageserver (new versions of 'bos salvage' automatically do this for you). Or, if you insist on using the standalone salvager, add the -forceDAFS flag to your salvager command line.";
+ }
+#else
+ if (AskDAFS()) {
+ msg =
+ "The non-DAFS salvager cannot be run with a Demand Attach Fileserver. Please use 'salvageserver -client <partition> <volume id>' to manually schedule volume salvages with the salvageserver (new versions of 'bos salvage' automatically do this for you). Or, if you insist on using the standalone salvager, run dasalvager with the -forceDAFS flag.";
+ }
+#endif
+
+ if (msg) {
+#ifndef AFS_NT40_ENV
+ if (useSyslog)
+ Log("%s", msg);
+ else
+#endif
+ printf("%s\n", msg);
+ Exit(1);
+ }
+ }
+
DInit(10);
#ifdef AFS_NT40_ENV
if (myjob.cj_number != NOT_CHILD) {
SalvageFileSys(partP, 0);
else {
/* Salvage individual volume */
- if (vid <= 0) {
- Log("salvage: invalid volume id specified; salvage aborted\n");
- Exit(1);
- }
SalvageFileSys(partP, vid);
}
}
{
struct cmd_syndesc *ts;
int err = 0;
- char commandLine[150];
- int i;
extern char cml_version_number[];
#ifdef AFS_AIX32_ENV
/*
- * The following signal action for AIX is necessary so that in case of a
- * crash (i.e. core is generated) we can include the user's data section
+ * The following signal action for AIX is necessary so that in case of a
+ * crash (i.e. core is generated) we can include the user's data section
* in the core dump. Unfortunately, by default, only a partial core is
* generated which, in many cases, isn't too useful.
*/
exit(2);
}
#ifdef AFS_NT40_ENV
+ /* Default to binary mode for fopen() */
+ _set_fmode(_O_BINARY);
+
main_thread = pthread_self();
if (spawnDatap && spawnDataLen) {
/* This is a child per partition salvager. Don't setup log or
exit(3);
} else {
#endif
- for (commandLine[0] = '\0', i = 0; i < argc; i++) {
- if (i > 0)
- strcat(commandLine, " ");
- strcat(commandLine, argv[i]);
- }
-
/* All entries to the log will be appended. Useful if there are
* multiple salvagers appending to the log.
*/
/* bad for normal help flag processing, but can do nada */
fprintf(logFile, "%s\n", cml_version_number);
- Log("STARTING AFS SALVAGER %s (%s)\n", SalvageVersion, commandLine);
+ LogCommandLine(argc, argv, "SALVAGER", SalvageVersion, "STARTING AFS",
+ Log);
/* Get and hold a lock for the duration of the salvage to make sure
* that no other salvage runs at the same time. The routine
- * VInitVolumePackage (called below) makes sure that a file server or
+ * VInitVolumePackage2 (called below) makes sure that a file server or
* other volume utilities don't interfere with the salvage.
*/
get_salvage_lock = 1;
#ifdef FAST_RESTART
cmd_AddParm(ts, "-DontSalvage", CMD_FLAG, CMD_OPTIONAL,
"Don't salvage. This my be set in BosConfig to let the fileserver restart immediately after a crash. Bad volumes will be taken offline");
-#elif defined(DEMAND_ATTACH_ENABLE)
+#elif defined(AFS_DEMAND_ATTACH_FS) || defined(AFS_DEMAND_ATTACH_UTIL)
+ cmd_Seek(ts, 20); /* skip DontSalvage */
cmd_AddParm(ts, "-forceDAFS", CMD_FLAG, CMD_OPTIONAL,
"For Demand Attach Fileserver, permit a manual volume salvage outside of the salvageserver");
#endif /* FAST_RESTART */
+ cmd_Seek(ts, 21); /* skip DontSalvage and forceDAFS if needed */
+ cmd_AddParm(ts, "-f", CMD_FLAG, CMD_OPTIONAL, "Alias for -force");
err = cmd_Dispatch(argc, argv);
Exit(err);
return 0; /* not reached */