fs-uuid-20071016
[openafs.git] / src / venus / fs.c
index 83ef0c2..60709b5 100644 (file)
@@ -25,6 +25,7 @@ RCSID
 #include <afs/stds.h>
 #include <afs/vice.h>
 #include <afs/venus.h>
+#include <afs/com_err.h>
 #ifdef AFS_AIX32_ENV
 #include <signal.h>
 #endif
@@ -41,7 +42,6 @@ RCSID
 #undef VICE
 #include "afs/prs_fs.h"
 #include <afs/afsint.h>
-#include <afs/auth.h>
 #include <afs/cellconfig.h>
 #include <ubik.h>
 #include <rx/rxkad.h>
@@ -69,7 +69,7 @@ static char tspace[1024];
 static struct ubik_client *uclient;
 
 static int GetClientAddrsCmd(), SetClientAddrsCmd(), FlushMountCmd();
-static int RxStatProcCmd(), RxStatPeerCmd(), GetFidCmd();
+static int RxStatProcCmd(), RxStatPeerCmd(), GetFidCmd(), UuidCmd();
 
 extern char *hostutil_GetNameByINet();
 extern struct hostent *hostutil_GetHostByName();
@@ -1208,7 +1208,7 @@ GetCallerAccess(struct cmd_syndesc *as, char *arock)
         struct vcxstat2 stat;
         blob.out_size = sizeof(struct vcxstat2);
         blob.in_size = 0;
-        blob.out = &stat;
+        blob.out = (void *)&stat;
         code = pioctl(ti->data, VIOC_GETVCXSTATUS2, &blob, 1);
         if (code) {
             Die(errno, ti->data);
@@ -1244,6 +1244,43 @@ FlushVolumeCmd(struct cmd_syndesc *as, char *arock)
     return error;
 }
 
+/* 
+ * The Windows version of UuidCmd displays the UUID.
+ * When the UNIX version is updated to do the same
+ * be sure to replace the CMD_REQUIRED flag with
+ * CMD_OPTIONAL in the cmd_AddParam(-generate) call 
+ */
+static int
+UuidCmd(struct cmd_syndesc *as, char *arock)
+{
+    afs_int32 code;
+    struct ViceIoctl blob;
+
+    blob.in_size = 0;
+    blob.out_size = 0;
+    
+    if (as->parms[0].items) {
+        if (geteuid()) {
+            fprintf (stderr, "Permission denied: requires root access.\n");
+            return EACCES;
+        }
+
+        /* generate new UUID */
+        code = pioctl(0, VIOC_NEWUUID, &blob, 1);
+
+        if (code) {
+            Die(errno, 0);
+            return 1;
+        }
+
+        printf("New uuid generated.\n");
+    } else {
+        /* This will never execute */
+        printf("Please add the '-generate' option to generate a new UUID.\n");
+    }
+    return 0;
+}
+
 static int
 FlushCmd(struct cmd_syndesc *as, char *arock)
 {
@@ -1714,7 +1751,7 @@ defect #3069
        if (code == 0) {
            /* make the check.  Don't complain if there are problems with init */
            code =
-               ubik_Call(VL_GetEntryByNameO, uclient, 0, volName,
+               ubik_VL_GetEntryByNameO(uclient, 0, volName,
                          &vldbEntry);
            if (code == VL_NOENT) {
                fprintf(stderr,
@@ -2006,13 +2043,28 @@ SetCacheSizeCmd(struct cmd_syndesc *as, char *arock)
 static int
 GetCacheParmsCmd(struct cmd_syndesc *as, char *arock)
 {
-    afs_int32 code;
+    afs_int32 code, filesUsed;
     struct ViceIoctl blob;
     afs_int32 parms[MAXGCSIZE];
+    double percentFiles, percentBlocks;
+    afs_int32 flags = 0;
+
+    if (as->parms[0].items){ /* -files */
+       flags = 1;
+    } else if (as->parms[1].items){ /* -excessive */
+       flags = 2;
+    } else {
+       flags = 0;
+    }
 
     memset(parms, '\0', sizeof parms); /* avoid Purify UMR error */
-    blob.in = NULL;
-    blob.in_size = 0;
+    if (flags){
+       blob.in = (char *)&flags;
+       blob.in_size = sizeof(afs_int32);
+    } else {   /* be backward compatible */
+       blob.in = NULL;
+       blob.in_size = 0;
+    }
     blob.out_size = sizeof(parms);
     blob.out = (char *)parms;
     code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1);
@@ -2020,11 +2072,48 @@ GetCacheParmsCmd(struct cmd_syndesc *as, char *arock)
        Die(errno, NULL);
        return 1;
     }
-    printf("AFS using %d of the cache's available %d 1K byte blocks.\n",
-          parms[1], parms[0]);
-    if (parms[1] > parms[0])
-       printf
-           ("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
+
+    if (!flags){
+       printf("AFS using %d of the cache's available %d 1K byte blocks.\n",
+               parms[1], parms[0]);
+       if (parms[1] > parms[0])
+               printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
+       return 0;
+    }
+
+    percentBlocks = ((double)parms[1]/parms[0]) * 100;
+    printf("AFS using %5.0f%% of cache blocks (%d of %d 1k blocks)\n",
+          percentBlocks, parms[1], parms[0]);
+
+    if (parms[2] == 0)
+       return 0;
+
+    filesUsed = parms[2] - parms[3];
+    percentFiles = ((double)filesUsed/parms[2]) * 100;
+    printf("          %5.0f%% of the cache files (%d of %d files)\n",
+           percentFiles, filesUsed, parms[2]);
+    if (flags == 2){
+       printf("        afs_cacheFiles: %10d\n", parms[2]);
+       printf("        IFFree:         %10d\n", parms[3]); 
+       printf("        IFEverUsed:     %10d\n", parms[4]); 
+       printf("        IFDataMod:      %10d\n", parms[5]); 
+       printf("        IFDirtyPages:   %10d\n", parms[6]);
+       printf("        IFAnyPages:     %10d\n", parms[7]); 
+       printf("        IFDiscarded:    %10d\n", parms[8]);
+       printf("        DCentries:  %10d\n", parms[9]);
+       printf("          0k-   4K: %10d\n", parms[10]); 
+       printf("          4k-  16k: %10d\n", parms[11]); 
+       printf("         16k-  64k: %10d\n", parms[12]); 
+       printf("         64k- 256k: %10d\n", parms[13]); 
+       printf("        256k-   1M: %10d\n", parms[14]); 
+       printf("              >=1M: %10d\n", parms[15]); 
+    }
+
+    if (percentBlocks > 90)
+       printf("[cache size usage over 90%, consider increasing cache size]\n");
+    if (percentFiles > 90)
+       printf("[cache file usage over 90%, consider increasing '-files' argument to afsd]\n");
+        
     return 0;
 }
 
@@ -2149,6 +2238,37 @@ CallBackRxConnCmd(struct cmd_syndesc *as, char *arock)
 }
 
 static int
+NukeNFSCredsCmd(struct cmd_syndesc *as, char *arock)
+{
+    afs_int32 code;
+    struct ViceIoctl blob;
+    struct cmd_item *ti;
+    afs_int32 hostAddr;
+    struct hostent *thp;
+    
+    ti = as->parms[0].items;
+    thp = hostutil_GetHostByName(ti->data);
+    if (!thp) {
+       fprintf(stderr, "host %s not found in host table.\n", ti->data);
+       return 1;
+    }
+    else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
+    
+    /* now do operation */
+    blob.in_size = sizeof(afs_int32);
+    blob.out_size = sizeof(afs_int32);
+    blob.in = (char *) &hostAddr;
+    blob.out = (char *) &hostAddr;
+    
+    code = pioctl(0, VIOC_NFS_NUKE_CREDS, &blob, 1);
+    if (code < 0) {
+       Die(errno, 0);
+       return 1;
+    }
+    return 0;
+}
+
+static int
 NewCellCmd(struct cmd_syndesc *as, char *arock)
 {
     afs_int32 code, linkedstate = 0, size = 0, *lp;
@@ -2472,7 +2592,7 @@ ExportAfsCmd(struct cmd_syndesc *as, char *arock)
     struct ViceIoctl blob;
     struct cmd_item *ti;
     int export = 0, type = 0, mode = 0, exp = 0, exportcall, pwsync =
-       0, smounts = 0;
+       0, smounts = 0, clipags = 0, pagcb = 0;
 
     ti = as->parms[0].items;
     if (strcmp(ti->data, "nfs") == 0)
@@ -2525,8 +2645,29 @@ ExportAfsCmd(struct cmd_syndesc *as, char *arock)
            return 1;
        }
     }
+    if (ti = as->parms[5].items) {     /* -clipags */
+       if (strcmp(ti->data, "on") == 0)
+           clipags = 3;
+       else if (strcmp(ti->data, "off") == 0)
+           clipags = 2;
+       else {
+           fprintf(stderr, "Illegal argument %s\n", ti->data);
+           return 1;
+       }
+    }
+    if (ti = as->parms[6].items) {     /* -pagcb */
+       if (strcmp(ti->data, "on") == 0)
+           pagcb = 3;
+       else if (strcmp(ti->data, "off") == 0)
+           pagcb = 2;
+       else {
+           fprintf(stderr, "Illegal argument %s\n", ti->data);
+           return 1;
+       }
+    }
     exportcall =
-       (type << 24) | (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
+       (type << 24) | (pagcb << 10) | (clipags << 8) |
+       (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
     type &= ~0x70;
     /* make the call */
     blob.in = (char *)&exportcall;
@@ -2557,6 +2698,13 @@ ExportAfsCmd(struct cmd_syndesc *as, char *arock)
        printf("\t%s\n",
               (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" :
                "Only mounts to /afs allowed"));
+       printf("\t%s\n",
+              (exportcall & 16 ? "Client-assigned PAG's are used" :
+               "Client-assigned PAG's are not used"));
+       printf("\t%s\n",
+              (exportcall & 32 ?
+               "Callbacks are made to get creds from new clients" :
+               "Callbacks are not made to get creds from new clients"));
     } else {
        printf("'%s' translator is disabled\n", exported_types[type]);
     }
@@ -3131,6 +3279,61 @@ GetCryptCmd(struct cmd_syndesc *as, char *arock)
     return 0;
 }
 
+#ifdef AFS_DISCON_ENV
+static char *modenames[] = {
+    "discon",
+    "fetchonly",
+    "partial",
+    "nat",
+    "full",
+    NULL
+};
+
+static afs_int32
+DisconCmd(struct cmd_syndesc *as, char *arock)
+{
+    struct cmd_item *ti;
+    char *modename;
+    int modelen;
+    afs_int32 mode, code;
+    struct ViceIoctl blob;
+
+    blob.in = NULL;
+    blob.in_size = 0;
+
+    ti = as->parms[0].items;
+    if (ti) {
+       modename = ti->data;
+       modelen = strlen(modename);
+       for (mode = 0; modenames[mode] != NULL; mode++)
+           if (!strncasecmp(modename, modenames[mode], modelen))
+               break;
+       if (modenames[mode] == NULL)
+           printf("Unknown discon mode \"%s\"\n", modename);
+       else {
+           memcpy(space, &mode, sizeof mode);
+           blob.in = space;
+           blob.in_size = sizeof mode;
+       }
+    }
+
+    blob.out_size = sizeof(mode);
+    blob.out = space;
+    code = pioctl(0, VIOC_DISCON, &blob, 1);
+    if (code)
+       Die(errno, NULL);
+    else {
+       memcpy(&mode, space, sizeof mode);
+       if (mode < sizeof modenames / sizeof (char *))
+           printf("Discon mode is now \"%s\"\n", modenames[mode]);
+       else
+           printf("Unknown discon mode %d\n", mode);
+    }
+
+    return 0;
+}
+#endif
+
 #include "AFS_component_version_number.c"
 
 int
@@ -3317,6 +3520,8 @@ defect 3069
 
     ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, 0,
                          "get cache usage info");
+    cmd_AddParm(ts, "-files", CMD_FLAG, CMD_OPTIONAL, "Show cach files used as well");
+    cmd_AddParm(ts, "-excessive", CMD_FLAG, CMD_OPTIONAL, "excessively verbose cache stats");
 
     ts = cmd_CreateSyntax("listcells", ListCellsCmd, 0,
                          "list configured cells");
@@ -3403,6 +3608,10 @@ defect 3069
                "run on strict 'uid check' mode (on | off)");
     cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL,
                "allow nfs mounts to subdirs of /afs/.. (on  | off)");
+    cmd_AddParm(ts, "-clipags", CMD_SINGLE, CMD_OPTIONAL,
+               "enable use of client-assigned PAG's (on  | off)");
+    cmd_AddParm(ts, "-pagcb", CMD_SINGLE, CMD_OPTIONAL,
+               "enable callbacks to get creds from new clients (on  | off)");
 
 
     ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, 0,
@@ -3442,6 +3651,18 @@ defect 3069
                          "get fid for file(s)");
     cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
 
+#ifdef AFS_DISCON_ENV
+    ts = cmd_CreateSyntax("discon", DisconCmd, 0,
+                         "disconnection mode");
+    cmd_AddParm(ts, "-mode", CMD_SINGLE, CMD_OPTIONAL, "nat | full");
+#endif
+
+    ts = cmd_CreateSyntax("nukenfscreds", NukeNFSCredsCmd, 0, "nuke credentials for NFS client");
+    cmd_AddParm(ts, "-addr", CMD_SINGLE, 0, "host name or address");
+
+    ts = cmd_CreateSyntax("uuid", UuidCmd, 0, "manage the UUID for the cache manager");
+    cmd_AddParm(ts, "-generate", CMD_FLAG, CMD_REQUIRED, "generate a new UUID");
+
     code = cmd_Dispatch(argc, argv);
     if (rxInitDone)
        rx_Finalize();
@@ -3487,7 +3708,7 @@ Die(int errnum, char *filename)
            fprintf(stderr, "%s:'%s'", pn, filename);
        else
            fprintf(stderr, "%s", pn);
-       fprintf(stderr, ": %s\n", error_message(errnum));
+       fprintf(stderr, ": %s\n", afs_error_message(errnum));
        break;
     }
 }