afsd missing close brace
[openafs.git] / src / afsd / afsd.c
index 5fbdf8d..87f1615 100644 (file)
   *     -dcache    The number of data cache entries.
   *     -biods     Number of bkg I/O daemons (AIX3.1 only)
   *    -prealloc  Number of preallocated "small" memory blocks
-  *     -pininodes Number of inodes which can be spared from inode[] for 
-  *                pointing at Vfiles.  If this is set too high, you may have
-  *                system problems, which can only be ameliorated by changing
-  *                NINODE (or equivalent) and rebuilding the kernel.
-  *               This option is now disabled.
   *    -logfile   [OBSOLETE] Place where to put the logfile (default in
   *                <cache>/etc/AFSLog.
   *    -waitclose make close calls always synchronous (slows em down, tho)
@@ -61,6 +56,9 @@
 #include <afsconfig.h>
 #include <afs/param.h>
 
+#ifdef IGNORE_SOME_GCC_WARNINGS
+# pragma GCC diagnostic warning "-Wdeprecated-declarations"
+#endif
 
 #define VFS 1
 
@@ -160,6 +158,7 @@ void set_staticaddrs(void);
 #ifdef AFS_DARWIN_ENV
 #ifdef AFS_DARWIN80_ENV
 #include <sys/ioctl.h>
+#include <sys/xattr.h>
 #endif
 #include <mach/mach.h>
 #ifndef AFS_DARWIN100_ENV
@@ -313,17 +312,12 @@ static int nBiods = 5;            /* AIX3.1 only */
 static int preallocs = 400;    /* Def # of allocated memory blocks */
 static int enable_peer_stats = 0;      /* enable rx stats */
 static int enable_process_stats = 0;   /* enable rx stats */
-#ifdef AFS_AFSDB_ENV
 static int enable_afsdb = 0;   /* enable AFSDB support */
-#endif
 static int enable_dynroot = 0; /* enable dynroot support */
 static int enable_fakestat = 0;        /* enable fakestat support */
 static int enable_backuptree = 0;      /* enable backup tree support */
 static int enable_nomount = 0; /* do not mount */
 static int enable_splitcache = 0;
-#ifdef notdef
-static int inodes = 60;                /* VERY conservative, but has to be */
-#endif
 int afsd_dynamic_vcaches = 0;  /* Enable dynamic-vcache support */
 int afsd_verbose = 0;          /*Are we being chatty? */
 int afsd_debug = 0;            /*Are we printing debugging info? */
@@ -801,6 +795,24 @@ CreateCacheSubDir(char *basename, int dirNum)
     return (0);
 }
 
+static void
+SetNoBackupAttr(char *fullpn)
+{
+#ifdef AFS_DARWIN80_ENV
+    int ret;
+
+    ret = setxattr(fullpn, "com.apple.metadata:com_apple_backup_excludeItem",
+                  "com.apple.backupd", strlen("com.apple.backupd"), 0,
+                  XATTR_CREATE);
+    if(ret < 0)
+    {
+       if(errno != EEXIST)
+           fprintf(stderr, "afsd: Warning: failed to set attribute to preclude cache backup: %s\n", strerror(errno));
+    }
+#endif
+    return;
+}
+
 static int
 MoveCacheFile(char *basename, int fromDir, int toDir, int cacheFile, 
              int maxDir)
@@ -834,6 +846,7 @@ MoveCacheFile(char *basename, int fromDir, int toDir, int cacheFile,
               from, to, ret, errno);
        return -1;
     }
+    SetNoBackupAttr(to);
 
     /* Reset directory pointer; fix file counts */
     dir_for_V[cacheFile] = toDir;
@@ -1079,16 +1092,19 @@ doSweepAFSCache(int *vFilesFound,
             * Found the file holding the dcache entries.
             */
            missing_DCacheFile = 0;
+           SetNoBackupAttr(fullpn_DCacheFile);
        } else if (dirNum < 0 && strcmp(currp->d_name, VOLINFOFILE) == 0) {
            /*
             * Found the file holding the volume info.
             */
            missing_VolInfoFile = 0;
+           SetNoBackupAttr(fullpn_VolInfoFile);
        } else if (dirNum < 0 && strcmp(currp->d_name, CELLINFOFILE) == 0) {
            /*
             * Found the file holding the cell info.
             */
            missing_CellInfoFile = 0;
+           SetNoBackupAttr(fullpn_CellInfoFile);
        } else if ((strcmp(currp->d_name, ".") == 0)
                   || (strcmp(currp->d_name, "..") == 0) ||
 #ifdef AFS_DECOSF_ENV
@@ -1168,6 +1184,7 @@ doSweepAFSCache(int *vFilesFound,
                        cache_dir_list[thisDir]++;
                        (*vFilesFound)++;
                    }
+                   SetNoBackupAttr(fullpn_VFile);
                }
 
            } else if (dir_for_V[vFileNum] >= maxDir
@@ -1432,7 +1449,6 @@ ConfigCellAlias(struct afsconf_cellalias *aca,
     return 0;
 }
 
-#ifdef AFS_AFSDB_ENV
 static void
 AfsdbLookupHandler(void)
 {
@@ -1490,7 +1506,6 @@ AfsdbLookupHandler(void)
 #endif
     exit(1);
 }
-#endif
 
 #ifdef mac2
 #include <sys/ioctl.h>
@@ -1524,9 +1539,7 @@ mainproc(struct cmd_syndesc *as, void *arock)
     static char rn[] = "afsd"; /*Name of this routine */
     afs_int32 code;            /*Result of fork() */
     int i;
-#ifndef AFS_CACHE_VNODE_PATH
     int currVFile;             /*Current AFS cache file number passed in */
-#endif
     int mountFlags;            /*Flags passed to mount() */
     int lookupResult;          /*Result of GetLocalCellName() */
     int cacheIteration;                /*How many times through cache verification */
@@ -1637,12 +1650,6 @@ mainproc(struct cmd_syndesc *as, void *arock)
        /* -prealloc */
        preallocs = atoi(as->parms[16].items->data);
     }
-#ifdef notdef
-    if (as->parms[17].items) {
-       /* -pininodes */
-       inodes = atoi(as->parms[17].items->data);
-    }
-#endif
     strcpy(confDir, AFSDIR_CLIENT_ETC_DIRPATH);
     if (as->parms[17].items) {
        /* -confdir */
@@ -1681,15 +1688,11 @@ mainproc(struct cmd_syndesc *as, void *arock)
     }
     if (as->parms[23].items) {
        /* -mem_alloc_sleep */
-       cacheFlags |= AFSCALL_INIT_MEMCACHE_SLEEP;
+       printf("afsd: -mem_alloc_sleep is deprecated -- ignored\n");
     }
     if (as->parms[24].items) {
        /* -afsdb */
-#ifdef AFS_AFSDB_ENV
        enable_afsdb = 1;
-#else
-       printf("afsd: No AFSDB support; ignoring -afsdb");
-#endif
     }
     if (as->parms[25].items) {
        /* -files_per_subdir */
@@ -1778,9 +1781,9 @@ mainproc(struct cmd_syndesc *as, void *arock)
 #endif
 
     /* set -rxmaxmtu */
-    if (as->parms[35].items) {
+    if (as->parms[36].items) {
         /* -rxmaxmtu */
-        rxmaxmtu = atoi(as->parms[35].items->data);
+        rxmaxmtu = atoi(as->parms[36].items->data);
     }
 
     /*
@@ -2078,7 +2081,6 @@ mainproc(struct cmd_syndesc *as, void *arock)
     }
 #endif
 
-#ifdef AFS_AFSDB_ENV
     if (enable_afsdb) {
        if (afsd_verbose)
            printf("%s: Forking AFSDB lookup handler.\n", rn);
@@ -2096,7 +2098,6 @@ mainproc(struct cmd_syndesc *as, void *arock)
            exit(1);
        }
     }
-#endif
 
     code = call_syscall(AFSOP_BASIC_INIT, 1);
     if (code) {
@@ -2122,9 +2123,6 @@ mainproc(struct cmd_syndesc *as, void *arock)
     cparams.setTimeFlag = cacheSetTime;
     cparams.memCacheFlag = cacheFlags;
     cparams.dynamic_vcaches = afsd_dynamic_vcaches;
-#ifdef notdef
-    cparams.inodes = inodes;
-#endif
     call_syscall(AFSOP_CACHEINIT, &cparams);
 
     /* do it before we init the cache inodes */
@@ -2163,23 +2161,6 @@ mainproc(struct cmd_syndesc *as, void *arock)
                     rn, vFilesFound, cacheFiles, cacheIteration);
        } while ((vFilesFound < cacheFiles)
                 && (cacheIteration < MAX_CACHE_LOOPS));
-#ifdef AFS_CACHE_VNODE_PATH
-       if (afsd_debug)
-           printf
-               ("%s: Calling AFSOP_CACHEBASEDIR with '%s'\n",
-                rn, cacheBaseDir);
-       call_syscall(AFSOP_CACHEBASEDIR, cacheBaseDir);
-       if (afsd_debug)
-           printf
-               ("%s: Calling AFSOP_CACHEDIRS with %d dirs\n",
-                rn, nFilesPerDir);
-       call_syscall(AFSOP_CACHEDIRS, nFilesPerDir);
-       if (afsd_debug)
-           printf
-               ("%s: Calling AFSOP_CACHEFILES with %d files\n",
-                rn, cacheFiles);
-       call_syscall(AFSOP_CACHEFILES, cacheFiles);
-#endif
     } else if (afsd_verbose)
        printf("%s: Using memory cache, not swept\n", rn);
 
@@ -2204,11 +2185,11 @@ mainproc(struct cmd_syndesc *as, void *arock)
     call_syscall(AFSOP_CELLINFO, fullpn_CellInfoFile);
 
     if (rxmaxmtu) {
-    if (afsd_verbose)
-        printf("%s: Setting rxmaxmtu in kernel = %d\n", rn, rxmaxmtu);
-    code = call_syscall(AFSOP_SET_RXMAXMTU, rxmaxmtu);
-    if (code)
-        printf("%s: Error seting rxmaxmtu\n", rn);
+       if (afsd_verbose)
+            printf("%s: Setting rxmaxmtu in kernel = %d\n", rn, rxmaxmtu);
+       code = call_syscall(AFSOP_SET_RXMAXMTU, rxmaxmtu);
+        if (code)
+            printf("%s: Error seting rxmaxmtu\n", rn);
     }
 
     if (enable_dynroot) {
@@ -2322,32 +2303,53 @@ mainproc(struct cmd_syndesc *as, void *arock)
     if (!(cacheFlags & AFSCALL_INIT_MEMCACHE))
        call_syscall(AFSOP_VOLUMEINFO, fullpn_VolInfoFile);
 
-#ifndef AFS_CACHE_VNODE_PATH
     /*
      * Give the kernel the names of the AFS files cached on the workstation's
      * disk.
      */
     if (afsd_debug)
        printf
-           ("%s: Calling AFSOP_CACHEINODE for each of the %d files in '%s'\n",
+           ("%s: Calling AFSOP_CACHEFILE for each of the %d files in '%s'\n",
             rn, cacheFiles, cacheBaseDir);
-    if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) /* ... and again ... */
+    if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
+       /* ... and again ... */
+       int nocachefile = 0;
        for (currVFile = 0; currVFile < cacheFiles; currVFile++) {
+           if (!nocachefile) {
+               sprintf(fullpn_VFile, "%s/D%d/V%d", cacheBaseDir, dir_for_V[currVFile], currVFile);
+               code = call_syscall(AFSOP_CACHEFILE, fullpn_VFile);
+               if (code) {
+                   if (currVFile == 0) {
+                       if (afsd_debug)
+                           printf
+                               ("%s: Calling AFSOP_CACHEINODE for each of the %d files in '%s'\n",
+                                rn, cacheFiles, cacheBaseDir);
+                       nocachefile = 1;
+                   } else {
+                       printf
+                           ("%s: Error calling AFSOP_CACHEFILE for '%s'\n",
+                            rn, fullpn_VFile);
+                       exit(1);
+                   }
+               } else {
+                   continue;
+               }
+               /* fall through to setup-by-inode */
+           }
 #ifdef AFS_SGI62_ENV
            call_syscall(AFSOP_CACHEINODE,
                         (afs_uint32) (inode_for_V[currVFile] >> 32),
                         (afs_uint32) (inode_for_V[currVFile] & 0xffffffff));
-#else
-#if defined(LINUX_USE_FH)
-           sprintf(fullpn_VFile, "%s/D%d/V%d", cacheBaseDir, dir_for_V[currVFile], currVFile);
-           call_syscall(AFSOP_CACHEFILE, fullpn_VFile);
-#else
+#elif !(defined(LINUX_USE_FH) || defined(AFS_CACHE_VNODE_PATH))
            call_syscall(AFSOP_CACHEINODE, inode_for_V[currVFile]);
-#endif
+#else
+           printf
+               ("%s: Error calling AFSOP_CACHEINODE: not configured\n",
+                rn);
+           exit(1);
 #endif
        }
-#endif
-
+    }
     /*end for */
     /*
      * All the necessary info has been passed into the kernel to run an AFS
@@ -2446,6 +2448,8 @@ main(int argc, char **argv)
     struct cmd_syndesc *ts;
 
     ts = cmd_CreateSyntax(NULL, mainproc, NULL, "start AFS");
+
+    /* 0 - 10 */
     cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL,
                "1024 byte blocks in cache");
     cmd_AddParm(ts, "-files", CMD_SINGLE, CMD_OPTIONAL, "files in cache");
@@ -2464,6 +2468,8 @@ main(int argc, char **argv)
                "display lots of information");
     cmd_AddParm(ts, "-rmtsys", CMD_FLAG, CMD_OPTIONAL,
                "start NFS rmtsysd program");
+
+    /* 11 - 20 */
     cmd_AddParm(ts, "-debug", CMD_FLAG, CMD_OPTIONAL, "display debug info");
     cmd_AddParm(ts, "-chunksize", CMD_SINGLE, CMD_OPTIONAL,
                "log(2) of chunk size");
@@ -2473,13 +2479,8 @@ main(int argc, char **argv)
                "number of volume entries");
     cmd_AddParm(ts, "-biods", CMD_SINGLE, CMD_OPTIONAL,
                "number of bkg I/O daemons (aix vm)");
-
     cmd_AddParm(ts, "-prealloc", CMD_SINGLE, CMD_OPTIONAL,
                "number of 'small' preallocated blocks");
-#ifdef notdef
-    cmd_AddParm(ts, "-pininodes", CMD_SINGLE, CMD_OPTIONAL,
-               "number of inodes to hog");
-#endif
     cmd_AddParm(ts, "-confdir", CMD_SINGLE, CMD_OPTIONAL,
                "configuration directory");
     cmd_AddParm(ts, "-logfile", CMD_SINGLE, CMD_OPTIONAL,
@@ -2488,6 +2489,7 @@ main(int argc, char **argv)
                "make close calls synchronous");
     cmd_AddParm(ts, "-shutdown", CMD_FLAG, CMD_OPTIONAL,
                "Shutdown all afs state");
+    /* 21 - 30 */
     cmd_AddParm(ts, "-enable_peer_stats", CMD_FLAG, CMD_OPTIONAL | CMD_HIDE,
                "Collect rpc statistics by peer");
     cmd_AddParm(ts, "-enable_process_stats", CMD_FLAG,
@@ -2495,11 +2497,8 @@ main(int argc, char **argv)
                "Collect rpc statistics for this process");
     cmd_AddParm(ts, "-mem_alloc_sleep", CMD_FLAG, (CMD_OPTIONAL | CMD_HIDE),
                "Allow sleeps when allocating memory cache");
-    cmd_AddParm(ts, "-afsdb", CMD_FLAG, (CMD_OPTIONAL
-#ifndef AFS_AFSDB_ENV
-                                        | CMD_HIDE
-#endif
-               ), "Enable AFSDB support");
+    cmd_AddParm(ts, "-afsdb", CMD_FLAG, (CMD_OPTIONAL),
+               "Enable AFSDB support");
     cmd_AddParm(ts, "-files_per_subdir", CMD_SINGLE, CMD_OPTIONAL,
                "log(2) of the number of cache files per cache subdirectory");
     cmd_AddParm(ts, "-dynroot", CMD_FLAG, CMD_OPTIONAL,
@@ -2511,6 +2510,7 @@ main(int argc, char **argv)
     cmd_AddParm(ts, "-nomount", CMD_FLAG, CMD_OPTIONAL, "Do not mount AFS");
     cmd_AddParm(ts, "-backuptree", CMD_FLAG, CMD_OPTIONAL,
                "Prefer backup volumes for mointpoints in backup volumes");
+    /* 31 - 40 */
     cmd_AddParm(ts, "-rxbind", CMD_FLAG, CMD_OPTIONAL,
                "Bind the Rx socket (one interface only)");
     cmd_AddParm(ts, "-settime", CMD_FLAG, CMD_OPTIONAL, "set the time");