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
13 * Institution: The Information Technology Center, Carnegie-Mellon University
17 /* Main program file. Define globals. */
20 #include <afsconfig.h>
21 #include <afs/param.h>
33 #include <WINNT/afsevent.h>
35 #include <sys/param.h>
39 #endif /* ITIMER_REAL */
42 #define WCOREDUMP(x) ((x) & 0200)
45 #include <afs/afsint.h>
46 #include <afs/assert.h>
47 #if !defined(AFS_SGI_ENV) && !defined(AFS_NT40_ENV)
48 #if defined(AFS_VFSINCL_ENV)
49 #include <sys/vnode.h>
51 #include <sys/fs/ufs_inode.h>
53 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
54 #include <ufs/ufs/dinode.h>
55 #include <ufs/ffs/fs.h>
57 #include <ufs/inode.h>
60 #else /* AFS_VFSINCL_ENV */
62 #include <ufs/inode.h>
63 #else /* AFS_OSF_ENV */
64 #if !defined(AFS_LINUX20_ENV) && !defined(AFS_XBSD_ENV)
65 #include <sys/inode.h>
68 #endif /* AFS_VFSINCL_ENV */
69 #endif /* AFS_SGI_ENV */
72 #include <sys/lockf.h>
76 #include <checklist.h>
78 #if defined(AFS_SGI_ENV)
83 #if defined(AFS_SUN_ENV) || defined(AFS_SUN5_ENV)
86 #include <sys/mnttab.h>
87 #include <sys/mntent.h>
92 #endif /* AFS_SGI_ENV */
93 #endif /* AFS_HPUX_ENV */
98 #include <afs/osi_inode.h>
102 #include <afs/afsutil.h>
103 #include <afs/fileutil.h>
104 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
112 #include <afs/afssyscalls.h>
116 #include "partition.h"
117 #include "daemon_com.h"
119 #include "salvsync.h"
120 #include "viceinode.h"
122 #include "vol-salvage.h"
126 pthread_t main_thread;
129 static int get_salvage_lock = 0;
132 handleit(struct cmd_syndesc *as, void *arock)
135 char pname[100], *temp;
136 afs_int32 seenpart = 0, seenvol = 0, vid = 0;
140 afs_int32 seenany = 0;
143 VolumePackageOptions opts;
144 struct DiskPartition64 *partP;
146 #ifdef AFS_SGI_VNODE_GLUE
147 if (afs_init_kernel_config(-1) < 0) {
149 ("Can't determine NUMA configuration, not starting salvager.\n");
157 for (i = 0; i < CMD_MAXPARMS; i++) {
158 if (as->parms[i].items) {
166 "Exiting immediately without salvage. Look into the FileLog to find volumes which really need to be salvaged!";
175 #endif /* FAST_RESTART */
176 if ((ti = as->parms[0].items)) { /* -partition */
178 strncpy(pname, ti->data, 100);
180 if ((ti = as->parms[1].items)) { /* -volumeid */
183 ("You must also specify '-partition' option with the '-volumeid' option\n");
187 vid = atoi(ti->data);
189 if (as->parms[2].items) /* -debug */
191 if (as->parms[3].items) /* -nowrite */
193 if (as->parms[4].items) /* -inodes */
195 if (as->parms[5].items || as->parms[20].items) /* -force, -f */
197 if (as->parms[6].items) /* -oktozap */
199 if (as->parms[7].items) /* -rootinodes */
201 if (as->parms[8].items) /* -RebuildDirs */
203 if (as->parms[9].items) /* -ForceReads */
205 if ((ti = as->parms[10].items)) { /* -Parallel # */
207 if (strncmp(temp, "all", 3) == 0) {
211 if (strlen(temp) != 0) {
212 Parallel = atoi(temp);
215 if (Parallel > MAXPARALLEL) {
216 printf("Setting parallel salvages to maximum of %d \n",
218 Parallel = MAXPARALLEL;
222 if ((ti = as->parms[11].items)) { /* -tmpdir */
226 dirp = opendir(tmpdir);
229 ("Can't open temporary placeholder dir %s; using current partition \n",
235 if ((ti = as->parms[12].items)) /* -showlog */
237 if ((ti = as->parms[13].items)) { /* -log */
242 if ((ti = as->parms[14].items)) { /* -showmounts */
247 if ((ti = as->parms[15].items)) { /* -orphans */
249 orphans = ORPH_IGNORE;
250 else if (strcmp(ti->data, "remove") == 0
251 || strcmp(ti->data, "r") == 0)
252 orphans = ORPH_REMOVE;
253 else if (strcmp(ti->data, "attach") == 0
254 || strcmp(ti->data, "a") == 0)
255 orphans = ORPH_ATTACH;
257 #ifndef AFS_NT40_ENV /* ignore options on NT */
258 if ((ti = as->parms[16].items)) { /* -syslog */
262 if ((ti = as->parms[17].items)) { /* -syslogfacility */
263 useSyslogFacility = atoi(ti->data);
266 if ((ti = as->parms[18].items)) { /* -datelogs */
267 TimeStampLogFile((char *)AFSDIR_SERVER_SLVGLOG_FILEPATH);
272 if (ti = as->parms[19].items) { /* -DontSalvage */
274 "Exiting immediately without salvage. Look into the FileLog to find volumes which really need to be salvaged!";
282 #elif defined(DEMAND_ATTACH_ENABLE)
283 if (seenvol && !as->parms[19].items) {
285 "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.";
295 if (get_salvage_lock) {
299 /* Note: if seenvol we initialize this as a standard volume utility: this has the
300 * implication that the file server may be running; negotations have to be made with
301 * the file server in this case to take the read write volume and associated read-only
302 * volumes off line before salvaging */
305 if (afs_winsockInit() < 0) {
306 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0,
307 AFSDIR_SALVAGER_FILE, 0);
308 Log("Failed to initailize winsock, exiting.\n");
320 VOptDefaults(pt, &opts);
321 if (VInitVolumePackage2(pt, &opts)) {
322 Log("errors encountered initializing volume package; salvage aborted\n");
327 if (myjob.cj_number != NOT_CHILD) {
330 (void)strcpy(pname, myjob.cj_part);
335 for (partP = DiskPartitionList; partP; partP = partP->next) {
336 SalvageFileSysParallel(partP);
338 SalvageFileSysParallel(0);
340 partP = VGetPartition(pname, 0);
342 Log("salvage: Unknown or unmounted partition %s; salvage aborted\n", pname);
346 SalvageFileSys(partP, 0);
348 /* Salvage individual volume */
350 Log("salvage: invalid volume id specified; salvage aborted\n");
353 SalvageFileSys(partP, vid);
361 #include "AFS_component_version_number.c"
365 main(int argc, char **argv)
367 struct cmd_syndesc *ts;
370 extern char cml_version_number[];
374 * The following signal action for AIX is necessary so that in case of a
375 * crash (i.e. core is generated) we can include the user's data section
376 * in the core dump. Unfortunately, by default, only a partial core is
377 * generated which, in many cases, isn't too useful.
379 struct sigaction nsa;
381 sigemptyset(&nsa.sa_mask);
382 nsa.sa_handler = SIG_DFL;
383 nsa.sa_flags = SA_FULLDUMP;
384 sigaction(SIGABRT, &nsa, NULL);
385 sigaction(SIGSEGV, &nsa, NULL);
388 /* Initialize directory paths */
389 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
391 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
393 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
398 main_thread = pthread_self();
399 if (spawnDatap && spawnDataLen) {
400 /* This is a child per partition salvager. Don't setup log or
401 * try to lock the salvager lock.
403 if (nt_SetupPartitionSalvage(spawnDatap, spawnDataLen) < 0)
407 /* All entries to the log will be appended. Useful if there are
408 * multiple salvagers appending to the log.
411 CheckLogFile((char *)AFSDIR_SERVER_SLVGLOG_FILEPATH);
413 #ifdef AFS_LINUX20_ENV
414 fcntl(fileno(logFile), F_SETFL, O_APPEND); /* Isn't this redundant? */
416 fcntl(fileno(logFile), F_SETFL, FAPPEND); /* Isn't this redundant? */
422 if (geteuid() != 0) {
423 printf("Salvager must be run as root.\n");
429 /* bad for normal help flag processing, but can do nada */
431 fprintf(logFile, "%s\n", cml_version_number);
432 LogCommandLine(argc, argv, "SALVAGER", SalvageVersion, "STARTING AFS",
435 /* Get and hold a lock for the duration of the salvage to make sure
436 * that no other salvage runs at the same time. The routine
437 * VInitVolumePackage2 (called below) makes sure that a file server or
438 * other volume utilities don't interfere with the salvage.
440 get_salvage_lock = 1;
445 ts = cmd_CreateSyntax("initcmd", handleit, NULL, "initialize the program");
446 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL,
447 "Name of partition to salvage");
448 cmd_AddParm(ts, "-volumeid", CMD_SINGLE, CMD_OPTIONAL,
449 "Volume Id to salvage");
450 cmd_AddParm(ts, "-debug", CMD_FLAG, CMD_OPTIONAL,
451 "Run in Debugging mode");
452 cmd_AddParm(ts, "-nowrite", CMD_FLAG, CMD_OPTIONAL,
453 "Run readonly/test mode");
454 cmd_AddParm(ts, "-inodes", CMD_FLAG, CMD_OPTIONAL,
455 "Just list affected afs inodes - debugging flag");
456 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "Force full salvaging");
457 cmd_AddParm(ts, "-oktozap", CMD_FLAG, CMD_OPTIONAL,
458 "Give permission to destroy bogus inodes/volumes - debugging flag");
459 cmd_AddParm(ts, "-rootinodes", CMD_FLAG, CMD_OPTIONAL,
460 "Show inodes owned by root - debugging flag");
461 cmd_AddParm(ts, "-salvagedirs", CMD_FLAG, CMD_OPTIONAL,
462 "Force rebuild/salvage of all directories");
463 cmd_AddParm(ts, "-blockreads", CMD_FLAG, CMD_OPTIONAL,
464 "Read smaller blocks to handle IO/bad blocks");
465 cmd_AddParm(ts, "-parallel", CMD_SINGLE, CMD_OPTIONAL,
466 "# of max parallel partition salvaging");
467 cmd_AddParm(ts, "-tmpdir", CMD_SINGLE, CMD_OPTIONAL,
468 "Name of dir to place tmp files ");
469 cmd_AddParm(ts, "-showlog", CMD_FLAG, CMD_OPTIONAL,
470 "Show log file upon completion");
471 cmd_AddParm(ts, "-showsuid", CMD_FLAG, CMD_OPTIONAL,
472 "Report on suid/sgid files");
473 cmd_AddParm(ts, "-showmounts", CMD_FLAG, CMD_OPTIONAL,
474 "Report on mountpoints");
475 cmd_AddParm(ts, "-orphans", CMD_SINGLE, CMD_OPTIONAL,
476 "ignore | remove | attach");
478 /* note - syslog isn't avail on NT, but if we make it conditional, have
479 * to deal with screwy offsets for cmd params */
480 cmd_AddParm(ts, "-syslog", CMD_FLAG, CMD_OPTIONAL,
481 "Write salvage log to syslogs");
482 cmd_AddParm(ts, "-syslogfacility", CMD_SINGLE, CMD_OPTIONAL,
483 "Syslog facility number to use");
484 cmd_AddParm(ts, "-datelogs", CMD_FLAG, CMD_OPTIONAL,
485 "Include timestamp in logfile filename");
487 cmd_AddParm(ts, "-DontSalvage", CMD_FLAG, CMD_OPTIONAL,
488 "Don't salvage. This my be set in BosConfig to let the fileserver restart immediately after a crash. Bad volumes will be taken offline");
489 #elif defined(DEMAND_ATTACH_ENABLE)
490 cmd_AddParm(ts, "-forceDAFS", CMD_FLAG, CMD_OPTIONAL,
491 "For Demand Attach Fileserver, permit a manual volume salvage outside of the salvageserver");
492 #endif /* FAST_RESTART */
494 cmd_AddParm(ts, "-f", CMD_FLAG, CMD_OPTIONAL, "Alias for -force");
495 err = cmd_Dispatch(argc, argv);
497 return 0; /* not reached */