]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
afsd-check-for-bad-partition-type-20030602
authorNathan Neulinger <nneul@umr.edu>
Tue, 3 Jun 2003 05:31:08 +0000 (05:31 +0000)
committerDerrick Brashear <shadow@dementia.org>
Tue, 3 Jun 2003 05:31:08 +0000 (05:31 +0000)
FIXES 1455

disallow cache directory of types we know cause problems

====================
This delta was composed from multiple commits as part of the CVS->Git migration.
The checkin message with each commit was inconsistent.
The following are the additional commit messages.
====================
FIXES 1542

typo

acinclude.m4
src/afsd/afsd.c

index be836393e07c35e852712de55feaf842777aa897..de72cac9c0bec8e7280a006f5101d1ec5aada652 100644 (file)
@@ -752,7 +752,7 @@ AC_HEADER_SYS_WAIT
 AC_HEADER_DIRENT
 AC_CHECK_HEADERS(stdlib.h string.h unistd.h fcntl.h sys/time.h sys/file.h)
 AC_CHECK_HEADERS(netinet/in.h netdb.h sys/fcntl.h sys/mnttab.h sys/mntent.h)
-AC_CHECK_HEADERS(mntent.h sys/vfs.h sys/param.h sys/fs_types.h)
+AC_CHECK_HEADERS(mntent.h sys/vfs.h sys/param.h sys/fs_types.h sys/fstyp.h)
 AC_CHECK_HEADERS(sys/mount.h strings.h termios.h signal.h)
 AC_CHECK_HEADERS(windows.h malloc.h winsock2.h direct.h io.h)
 AC_CHECK_HEADERS(security/pam_modules.h siad.h usersec.h ucontext.h)
index 85ae976d77520a4f4dc021bdd3c4275e0f2af757..af5773b49002f0cd9063fa841af6cffc0fab0b3a 100644 (file)
@@ -113,6 +113,10 @@ RCSID("$Header$");
 #include <sys/vfs.h>
 #endif
 
+#ifdef HAVE_SYS_FSTYP_H
+#include <sys/fstyp.h>
+#endif
+
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
@@ -993,6 +997,95 @@ static int doSweepAFSCache(vFilesFound,directory,dirNum,maxDir)
     return(0);
 }
 
+char *CheckCacheBaseDir(char *dir)
+{
+       struct stat statbuf;
+
+       if ( !dir ) { return "cache base dir not specified"; }
+       if ( stat(dir, &statbuf) != 0 ) {
+               return "unable to stat cache base directory";
+       }
+
+       /* might want to check here for anything else goofy, like cache pointed at a non-dedicated directory, etc */
+
+#ifdef AFS_LINUX24_ENV
+       {
+               int res;
+               struct statfs statfsbuf;
+
+               res = statfs(dir, &statfsbuf);
+               if ( res != 0 ) {
+                       return "unable to statfs cache base directory";
+               }
+               if ( statfsbuf.f_type == 0x52654973 ) /* REISERFS_SUPER_MAGIC */
+               {
+                       return "cannot use reiserfs as cache partition";
+               }
+       }
+#endif
+
+#ifdef AFS_HPUX_ENV
+       {
+               int res;
+               struct statfs statfsbuf;
+               char name[FSTYPSZ];
+
+               res = statfs(dir, &statfsbuf);
+               if ( res != 0 )
+               {
+                       return "unable to statfs cache base directory";
+               }
+
+               if (sysfs(GETFSTYP, statfsbuf.f_fsid, name) != 0 )
+               {
+                       return "unable to determine filesystem type for cache base dir";
+               }
+
+               if ( strcmp(name, "hfs") )
+               {
+                       return "can only use hfs filesystem for cache partition on hpux";
+               }
+       }
+#endif
+
+#ifdef AFS_SUN5_ENV
+       {
+               FILE *vfstab;
+               struct mnttab mnt;
+               struct stat statmnt, statci;
+
+               if ((stat(dir, &statci) == 0) &&
+                       ((vfstab = fopen(MNTTAB, "r")) != NULL))
+               {
+                       while (getmntent(vfstab, &mnt) == 0) {
+                       if (strcmp(dir, mnt.mnt_mountp) != 0)
+                       {
+                               char *cp;
+                               int rdev = 0;
+
+                               if (cp = hasmntopt(&mnt, "dev="))
+                                       rdev=(int)strtol(cp+strlen("dev="), (char **)NULL, 16);
+
+                               if ((rdev == 0) && (stat(mnt.mnt_mountp, &statmnt) == 0))
+                                       rdev=statmnt.st_dev;
+
+                               if ((rdev == statci.st_dev) &&
+                                       (hasmntopt (&mnt, "logging") != NULL)) {
+
+                                       fclose(vfstab);
+                                       return "mounting a multi-use partition which contains the AFS cache with the\n\"logging\" option may deadlock your system.\n\n";
+                               }
+                       }
+                       }
+
+               fclose(vfstab);
+               }
+       }
+#endif
+
+       return NULL;
+}
+
 int SweepAFSCache(vFilesFound)
     int *vFilesFound;
 {
@@ -1176,6 +1269,7 @@ mainproc(as, arock)
     int        vFilesFound;                /*How many data cache files were found in sweep*/
     struct afsconf_dir *cdir;      /* config dir */
     FILE *logfd;
+    char *fsTypeMsg = NULL;
 #ifdef AFS_SUN5_ENV
     struct stat st;
 #endif
@@ -1497,36 +1591,9 @@ mainproc(as, arock)
     sprintf(fullpn_VFile,       "%s/",  cacheBaseDir);
     vFilePtr = fullpn_VFile + strlen(fullpn_VFile);
 
-#ifdef AFS_SUN5_ENV
-    {
-       FILE *vfstab;
-       struct mnttab mnt;
-       struct stat statmnt, statci;
-
-       if ((stat(cacheBaseDir, &statci) == 0) &&
-           ((vfstab = fopen(MNTTAB, "r")) != NULL)) {
-           while (getmntent(vfstab, &mnt) == 0) {
-               if (strcmp(cacheBaseDir, mnt.mnt_mountp) != 0) {
-                   char *cp;
-                   int rdev = 0;
-
-                   if (cp = hasmntopt(&mnt, "dev="))
-                       rdev=(int)strtol(cp+strlen("dev="), (char **)NULL, 16);
-
-                   if ((rdev == 0) && (stat(mnt.mnt_mountp, &statmnt) == 0))
-                       rdev=statmnt.st_dev;
-
-                   if ((rdev == statci.st_dev) &&
-                       (hasmntopt (&mnt, "logging") != NULL)) {
-                       printf("WARNING: Mounting a multi-use partition which contains the AFS cache with the\n\"logging\" option may deadlock your system.\n\n");
-                       fflush(stdout);
-                   }
-               }
-           }
-           fclose(vfstab);
-       }
+    if ((fsTypeMsg = CheckCacheBaseDir(cacheBaseDir))) {
+        printf("%s: WARNING: Cache dir check failed (%s)\n", rn, fsTypeMsg);
     }
-#endif
 
 #if 0
     fputs(AFS_GOVERNMENT_MESSAGE, stdout);