afsd: Remove unused definitions
[openafs.git] / src / afsd / afsd.c
index bda6053..4c9cdd7 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * 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
   *    -rxmaxmtu   Set the max mtu to help with VPN issues.
   *    -verbose     Be chatty.
   *    -disable-dynamic-vcaches     Disable the use of -stat value as the starting size of
-  *                          the size of the vcache/stat cache pool, 
+  *                          the size of the vcache/stat cache pool,
   *                          but increase that pool dynamically as needed.
   *    -debug     Print out additional debugging info.
   *    -kerndev    [OBSOLETE] The kernel device for AFS.
   *    -dontfork   [OBSOLETE] Don't fork off as a new process.
   *    -daemons   The number of background daemons to start (Default: 2).
   *    -rmtsys    Also fires up an afs remote sys call (e.g. pioctl, setpag)
-  *                support daemon 
+  *                support daemon
   *     -chunksize [n]   2^n is the chunksize to be used.  0 is default.
   *     -dcache    The number of data cache entries.
   *     -biods     Number of bkg I/O daemons (AIX3.1 only)
@@ -68,8 +68,7 @@
 
 #include "afsd.h"
 
-#include <assert.h>
-#include <potpourri.h>
+#include <afs/afs_assert.h>
 #include <afs/afsutil.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <sys/fs_types.h>
 #endif
 
-#ifdef HAVE_SYS_MOUNT_H
+#if defined(HAVE_SYS_MOUNT_H) && !defined(AFS_ARM_DARWIN_ENV)
 #include <sys/mount.h>
 #endif
 
@@ -167,22 +166,20 @@ void set_staticaddrs(void);
 #include <sys/ioctl.h>
 #include <sys/xattr.h>
 #endif
-#include <mach/mach.h>
-#include <mach/mach_port.h>
-#include <mach/mach_interface.h>
-#include <mach/mach_init.h>
-
 #include <CoreFoundation/CoreFoundation.h>
 
 #include <SystemConfiguration/SystemConfiguration.h>
 #include <SystemConfiguration/SCDynamicStore.h>
 
+#ifndef AFS_ARM_DARWIN_ENV
 #include <IOKit/pwr_mgt/IOPMLib.h>
 #include <IOKit/IOMessage.h>
 
 static io_connect_t root_port;
 static IONotificationPortRef notify;
 static io_object_t iterator;
+#endif
+
 static CFRunLoopSourceRef source;
 
 static int event_pid;
@@ -231,11 +228,6 @@ struct in_addr_42 {
        } S_un_w;
        afs_uint32 S_addr;
     } S_un;
-#define        s_host  S_un.S_un_b.s_b2        /* host on imp */
-#define        s_net   S_un.S_un_b.s_b1        /* network */
-#define        s_imp   S_un.S_un_w.s_w2        /* imp */
-#define        s_impno S_un.S_un_b.s_b4        /* imp # */
-#define        s_lh    S_un.S_un_b.s_b3        /* logical host */
 };
 
 #define        mPrintIPAddr(ipaddr)  printf("[%d.%d.%d.%d] ",          \
@@ -272,7 +264,7 @@ static int sawBiod = 0;
 static int sawCacheStatEntries = 0;
 char afsd_cacheMountDir[1024]; /*Mount directory for AFS */
 static char rootVolume[64] = "root.afs";       /*AFS root volume name */
-static afs_int32 cacheSetTime = FALSE; /*Keep checking time to avoid drift? */
+static afs_int32 cacheSetTime = 0;     /*Keep checking time to avoid drift? */
 #ifdef AFS_XBSD_ENV
 static int createAndTrunc = O_RDWR | O_CREAT | O_TRUNC;        /*Create & truncate on open */
 #else
@@ -327,7 +319,7 @@ int *dir_for_V = NULL;              /* Array: dir of each cache file.
                                 * -2: file exists in top-level
                                 * >=0: file exists in Dxxx
                                 */
-#if !defined(AFS_CACHE_VNODE_PATH) && !defined(LINUX_USE_FH)
+#if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX26_ENV)
 AFSD_INO_T *inode_for_V;       /* Array of inodes for desired
                                 * cache files */
 #endif
@@ -347,40 +339,40 @@ static void fork_rx_syscall();
 #endif
 static void fork_syscall();
 
-#ifdef AFS_DARWIN_ENV
+#if defined(AFS_DARWIN_ENV) && !defined(AFS_ARM_DARWIN_ENV)
 static void
-afsd_sleep_callback(void * refCon, io_service_t service, 
+afsd_sleep_callback(void * refCon, io_service_t service,
                    natural_t messageType, void * messageArgument )
 {
     switch (messageType) {
     case kIOMessageCanSystemSleep:
-       /* Idle sleep is about to kick in; can 
-          prevent sleep by calling IOCancelPowerChange, otherwise 
+       /* Idle sleep is about to kick in; can
+          prevent sleep by calling IOCancelPowerChange, otherwise
           if we don't ack in 30s the system sleeps anyway */
-       
+
        /* allow it */
        IOAllowPowerChange(root_port, (long)messageArgument);
        break;
-       
+
     case kIOMessageSystemWillSleep:
        /* The system WILL go to sleep. Ack or suffer delay */
-       
+
        IOAllowPowerChange(root_port, (long)messageArgument);
        break;
-       
+
     case kIOMessageSystemWillRestart:
        /* The system WILL restart. Ack or suffer delay */
-       
+
        IOAllowPowerChange(root_port, (long)messageArgument);
        break;
-       
+
     case kIOMessageSystemWillPowerOn:
     case kIOMessageSystemHasPoweredOn:
        /* coming back from sleep */
-       
+
        IOAllowPowerChange(root_port, (long)messageArgument);
        break;
-       
+
     default:
        IOAllowPowerChange(root_port, (long)messageArgument);
        break;
@@ -408,6 +400,10 @@ afsd_update_addresses(CFRunLoopTimerRef timer, void *info)
     } else
        printf("ADVISEADDR: Error in specifying interface addresses:%s\n",
               reason);
+
+    /* Since it's likely this means our DNS server changed, reinit now */
+    if (enable_afsdb)
+       res_init();
 }
 
 /* This function is called when the system's ip addresses may have changed. */
@@ -423,15 +419,16 @@ afsd_ipaddr_callback (SCDynamicStoreRef store, CFArrayRef changed_keys, void *in
       CFRelease (timer);
 }
 
-static void 
+static void
 afsd_event_cleanup(int signo) {
 
     CFRunLoopRemoveSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode);
     CFRelease (source);
+#ifndef AFS_ARM_DARWIN_ENV
     IODeregisterForSystemPower(&iterator);
     IOServiceClose(root_port);
     IONotificationPortDestroy(notify);
-
+#endif
     exit(0);
 }
 
@@ -442,58 +439,60 @@ afsd_install_events(void)
     SCDynamicStoreContext ctx = {0};
     SCDynamicStoreRef store;
 
+#ifndef AFS_ARM_DARWIN_ENV
     root_port = IORegisterForSystemPower(0,&notify,afsd_sleep_callback,&iterator);
-    
+
     if (root_port) {
        CFRunLoopAddSource(CFRunLoopGetCurrent(),
                           IONotificationPortGetRunLoopSource(notify),
                           kCFRunLoopDefaultMode);
     }
-    
-    
+
+
     store = SCDynamicStoreCreate (NULL,
                                  CFSTR ("AddIPAddressListChangeCallbackSCF"),
                                  afsd_ipaddr_callback, &ctx);
-    
+
     if (store) {
        const void *keys[1];
-       
+
        /* Request IPV4 address change notification */
        keys[0] = (SCDynamicStoreKeyCreateNetworkServiceEntity
                   (NULL, kSCDynamicStoreDomainState,
                    kSCCompAnyRegex, kSCEntNetIPv4));
-       
+
 #if 0
        /* This should tell us when the hostname(s) change. do we care? */
        keys[N] = SCDynamicStoreKeyCreateHostNames (NULL);
 #endif
-       
+
        if (keys[0] != NULL) {
            CFArrayRef pattern_array;
-           
+
            pattern_array = CFArrayCreate (NULL, keys, 1,
                                           &kCFTypeArrayCallBacks);
-           
+
            if (pattern_array != NULL)
            {
                SCDynamicStoreSetNotificationKeys (store, NULL, pattern_array);
                source = SCDynamicStoreCreateRunLoopSource (NULL, store, 0);
-               
+
                CFRelease (pattern_array);
            }
-           
+
            if (keys[0] != NULL)
                CFRelease (keys[0]);
        }
-       
-       CFRelease (store); 
+
+       CFRelease (store);
     }
-    
+#endif
+
     if (source != NULL) {
        CFRunLoopAddSource (CFRunLoopGetCurrent(),
                            source, kCFRunLoopDefaultMode);
     }
-    
+
     signal(SIGTERM, afsd_event_cleanup);
 
     CFRunLoopRun();
@@ -596,8 +595,8 @@ ParseCacheInfoFile(void)
 }
 
 /*
- * All failures to open the partition are ignored. Also if the cache dir 
- * isn't a mounted partition it's also ignored since we can't guarantee 
+ * All failures to open the partition are ignored. Also if the cache dir
+ * isn't a mounted partition it's also ignored since we can't guarantee
  * what will be stored afterwards. Too many if's. This is now purely
  * advisory. ODS with over 2G partition also gives warning message.
  *
@@ -808,7 +807,7 @@ SetNoBackupAttr(char *fullpn)
 }
 
 static int
-MoveCacheFile(char *basename, int fromDir, int toDir, int cacheFile, 
+MoveCacheFile(char *basename, int fromDir, int toDir, int cacheFile,
              int maxDir)
 {
     static char rn[] = "MoveCacheFile";
@@ -940,7 +939,7 @@ UnlinkUnwantedFile(char *rn, char *fullpn_FileToDelete, char *fileToDelete)
 
 
 static int
-doSweepAFSCache(int *vFilesFound, 
+doSweepAFSCache(int *vFilesFound,
                char *directory,        /* /path/to/cache/directory */
                int dirNum,             /* current directory number */
                int maxDir)             /* maximum directory number */
@@ -993,7 +992,7 @@ doSweepAFSCache(int *vFilesFound,
 #if defined(AFS_SGI62_ENV) || defined(AFS_DARWIN90_ENV)
            printf("\tinode=%" AFS_INT64_FMT ", reclen=%d, name='%s'\n", currp->d_ino,
                   currp->d_reclen, currp->d_name);
-#elif defined(AFS_DFBSD_ENV)
+#elif defined(AFS_DFBSD_ENV) || defined(AFS_USR_DFBSD_ENV)
            printf("\tinode=%ld, name='%s'\n", (long)currp->d_ino, currp->d_name);
 #else
            printf("\tinode=%ld, reclen=%d, name='%s'\n", (long)currp->d_ino,
@@ -1016,7 +1015,7 @@ doSweepAFSCache(int *vFilesFound,
             * file's inode, directory, and bump the number of files found
             * total and in this directory.
             */
-#if !defined(AFS_CACHE_VNODE_PATH) && !defined(LINUX_USE_FH)
+#if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX26_ENV)
            inode_for_V[vFileNum] = currp->d_ino;
 #endif
            dir_for_V[vFileNum] = dirNum;       /* remember this directory */
@@ -1158,7 +1157,7 @@ doSweepAFSCache(int *vFilesFound,
                           vFileNum);
                else {
                    struct stat statb;
-#if !defined(AFS_CACHE_VNODE_PATH) && !defined(LINUX_USE_FH)
+#if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX26_ENV)
                    assert(inode_for_V[vFileNum] == (AFSD_INO_T) 0);
 #endif
                    sprintf(vFilePtr, "D%d/V%d", thisDir, vFileNum);
@@ -1171,7 +1170,7 @@ doSweepAFSCache(int *vFilesFound,
                    if (CreateCacheFile(fullpn_VFile, &statb))
                        printf("%s: Can't create '%s'\n", rn, fullpn_VFile);
                    else {
-#if !defined(AFS_CACHE_VNODE_PATH) && !defined(LINUX_USE_FH)
+#if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX26_ENV)
                        inode_for_V[vFileNum] = statb.st_ino;
 #endif
                        dir_for_V[vFileNum] = thisDir;
@@ -1274,7 +1273,7 @@ CheckCacheBaseDir(char *dir)
        if (res != 0) {
            return "unable to statfs cache base directory";
        }
-#if !defined(LINUX_USE_FH)
+#if !defined(AFS_LINUX26_ENV)
        if (statfsbuf.f_type == 0x52654973) {   /* REISERFS_SUPER_MAGIC */
            return "cannot use reiserfs as cache partition";
        } else if (statfsbuf.f_type == 0x58465342) {    /* XFS_SUPER_MAGIC */
@@ -1413,9 +1412,11 @@ ConfigCell(struct afsconf_cell *aci, void *arock, struct afsconf_dir *adir)
 
     /* figure out if this is the home cell */
     isHomeCell = (strcmp(aci->name, LclCellName) == 0);
-    if (!isHomeCell)
+    if (!isHomeCell) {
        cellFlags = 2;          /* not home, suid is forbidden */
-
+       if (enable_dynroot == 2)
+           cellFlags |= 8; /* don't display foreign cells until looked up */
+    }
     /* build address list */
     for (i = 0; i < MAXHOSTSPERCELL; i++)
        memcpy(&hosts[i], &aci->hostAddr[i].sin_addr, sizeof(afs_int32));
@@ -1719,7 +1720,7 @@ mainproc(struct cmd_syndesc *as, void *arock)
     }
     if (as->parms[8].items) {
        /* -nosettime */
-       cacheSetTime = FALSE;
+       cacheSetTime = 0;
     }
     if (as->parms[9].items) {
        /* -verbose */
@@ -1787,7 +1788,7 @@ mainproc(struct cmd_syndesc *as, void *arock)
     if (as->parms[20].items) {
        /* -shutdown */
        afs_shutdown = 1;
-       /* 
+       /*
         * Cold shutdown is the default
         */
        printf("afsd: Shutting down all afs processes and afs state\n");
@@ -1851,7 +1852,7 @@ mainproc(struct cmd_syndesc *as, void *arock)
     }
     if (as->parms[32].items) {
        /* -settime */
-       cacheSetTime = TRUE;
+       cacheSetTime = 1;
     }
 
     /* set rx_extraPackets */
@@ -1884,7 +1885,7 @@ mainproc(struct cmd_syndesc *as, void *arock)
     if (as->parms[35].items) {
 #ifdef AFS_MAXVCOUNT_ENV
        /* -disable-dynamic-vcaches */
-       afsd_dynamic_vcaches = FALSE;
+       afsd_dynamic_vcaches = 0;
 #else
        printf("afsd: Error toggling flag, dynamically allocated vcaches not supported on your platform\n");
        exit(1);
@@ -1893,7 +1894,7 @@ mainproc(struct cmd_syndesc *as, void *arock)
 #ifdef AFS_MAXVCOUNT_ENV
     else {
        /* -dynamic-vcaches */
-       afsd_dynamic_vcaches = TRUE;
+       afsd_dynamic_vcaches = 1;
     }
 
     if (afsd_verbose)
@@ -1905,6 +1906,10 @@ mainproc(struct cmd_syndesc *as, void *arock)
         /* -rxmaxmtu */
         rxmaxmtu = atoi(as->parms[36].items->data);
     }
+    if (as->parms[37].items) {
+       /* -dynroot-sparse */
+       enable_dynroot = 2;
+    }
     return 0;
 }
 
@@ -1921,7 +1926,7 @@ afsd_run(void)
     int vFilesFound;           /*How many data cache files were found in sweep */
     int currVFile;             /*Current AFS cache file number passed in */
 
-    /*
+       /*
      * Pull out all the configuration info for the workstation's AFS cache and
      * the cellular community we're willing to let our users see.
      */
@@ -2005,7 +2010,7 @@ afsd_run(void)
        /* Disk cache:
         * Compute the number of cache files based on cache size,
         * but only if -files isn't given on the command line.
-        * Don't let # files be so small as to prevent full utilization 
+        * Don't let # files be so small as to prevent full utilization
         * of the cache unless user has explicitly asked for it.
         */
        if (chunkSize == 0) {
@@ -2023,7 +2028,7 @@ afsd_run(void)
 
            cacheFiles = max(cacheFiles, 1000);
 
-           /* Always allow more files than chunks.  Presume average V-file 
+           /* Always allow more files than chunks.  Presume average V-file
             * is ~67% of a chunk...  (another guess, perhaps Honeyman will
             * have a grad student write a paper).  i is KILOBYTES.
             */
@@ -2061,7 +2066,7 @@ afsd_run(void)
        /* This actually needs to
           1) use powers of 2
           2) not second-guess when a chunksize comes from the command line
-          3) be less, um, small. 2^2?? 
+          3) be less, um, small. 2^2??
        */
        /* Sanity check chunkSize */
        i = max(cacheBlocks / 1000, cacheBlocks / cacheFiles);
@@ -2096,7 +2101,7 @@ afsd_run(void)
                   cacheStatEntries);
     }
 
-#if !defined(AFS_CACHE_VNODE_PATH) && !defined(LINUX_USE_FH)
+#if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX26_ENV)
     /*
      * Create and zero the inode table for the desired cache files.
      */
@@ -2159,7 +2164,7 @@ afsd_run(void)
        if (code > 0) {
            if (enable_rxbind)
                code = code | 0x80000000;
-           afsd_call_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf);
+               afsd_call_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf);
        } else
            printf("ADVISEADDR: Error in specifying interface addresses:%s\n",
                   reason);
@@ -2211,7 +2216,6 @@ afsd_run(void)
            printf("%s: Forking AFSDB lookup handler.\n", rn);
        afsd_fork(0, afsdb_thread, NULL);
     }
-
     code = afsd_call_syscall(AFSOP_BASIC_INIT, 1);
     if (code) {
        printf("%s: Error %d in basic initialization.\n", rn, code);
@@ -2236,7 +2240,7 @@ afsd_run(void)
     cparams.setTimeFlag = cacheSetTime;
     cparams.memCacheFlag = cacheFlags;
     cparams.dynamic_vcaches = afsd_dynamic_vcaches;
-    afsd_call_syscall(AFSOP_CACHEINIT, &cparams);
+       afsd_call_syscall(AFSOP_CACHEINIT, &cparams);
 
     /* do it before we init the cache inodes */
     if (enable_splitcache) {
@@ -2278,7 +2282,7 @@ afsd_run(void)
        printf("%s: Using memory cache, not swept\n", rn);
 
     /*
-     * Pass the kernel the name of the workstation cache file holding the 
+     * Pass the kernel the name of the workstation cache file holding the
      * dcache entries.
      */
     if (afsd_debug)
@@ -2295,7 +2299,7 @@ afsd_run(void)
     if (afsd_debug)
        printf("%s: Calling AFSOP_CELLINFO: cell info file is '%s'\n", rn,
               fullpn_CellInfoFile);
-    afsd_call_syscall(AFSOP_CELLINFO, fullpn_CellInfoFile);
+       afsd_call_syscall(AFSOP_CELLINFO, fullpn_CellInfoFile);
 
     if (rxmaxmtu) {
        if (afsd_verbose)
@@ -2307,7 +2311,8 @@ afsd_run(void)
 
     if (enable_dynroot) {
        if (afsd_verbose)
-           printf("%s: Enabling dynroot support in kernel.\n", rn);
+           printf("%s: Enabling dynroot support in kernel%s.\n", rn,
+                  (enable_dynroot==2)?", not showing cells.":"");
        code = afsd_call_syscall(AFSOP_SET_DYNROOT, 1);
        if (code)
            printf("%s: Error enabling dynroot support.\n", rn);
@@ -2315,7 +2320,9 @@ afsd_run(void)
 
     if (enable_fakestat) {
        if (afsd_verbose)
-           printf("%s: Enabling fakestat support in kernel.\n", rn);
+           printf("%s: Enabling fakestat support in kernel%s.\n", rn,
+                  (enable_fakestat==2)?" for all mountpoints."
+                  :" for crosscell mountpoints");
        code = afsd_call_syscall(AFSOP_SET_FAKESTAT, enable_fakestat);
        if (code)
            printf("%s: Error enabling fakestat support.\n", rn);
@@ -2423,7 +2430,7 @@ afsd_run(void)
            afsd_call_syscall(AFSOP_CACHEINODE,
                         (afs_uint32) (inode_for_V[currVFile] >> 32),
                         (afs_uint32) (inode_for_V[currVFile] & 0xffffffff));
-#elif !(defined(LINUX_USE_FH) || defined(AFS_CACHE_VNODE_PATH))
+#elif !(defined(AFS_LINUX26_ENV) || defined(AFS_CACHE_VNODE_PATH))
            afsd_call_syscall(AFSOP_CACHEINODE, inode_for_V[currVFile]);
 #else
            printf
@@ -2441,10 +2448,10 @@ afsd_run(void)
     if (afsd_debug)
        printf("%s: Calling AFSOP_GO with cacheSetTime = %d\n", rn,
               cacheSetTime);
-    afsd_call_syscall(AFSOP_GO, cacheSetTime);
+       afsd_call_syscall(AFSOP_GO, cacheSetTime);
 
     /*
-     * At this point, we have finished passing the kernel all the info 
+     * At this point, we have finished passing the kernel all the info
      * it needs to set up the AFS.  Mount the AFS root.
      */
     printf("%s: All AFS daemons started.\n", rn);
@@ -2548,9 +2555,11 @@ afsd_init(void)
                "set rx_extraPackets to this value");
     cmd_AddParm(ts, "-splitcache", CMD_SINGLE, CMD_OPTIONAL,
                "Percentage RW versus RO in cache (specify as 60/40)");
-    cmd_AddParm(ts, "-disable-dynamic-vcaches", CMD_FLAG, CMD_OPTIONAL, 
+    cmd_AddParm(ts, "-disable-dynamic-vcaches", CMD_FLAG, CMD_OPTIONAL,
                "disable stat/vcache cache growing as needed");
     cmd_AddParm(ts, "-rxmaxmtu", CMD_SINGLE, CMD_OPTIONAL, "set rx max MTU to use");
+    cmd_AddParm(ts, "-dynroot-sparse", CMD_FLAG, CMD_OPTIONAL,
+               "Enable dynroot support with minimal cell list");
 }
 
 int