[OpenAFS-devel] nat mode

Jim Rees rees@umich.edu
Wed, 15 Feb 2006 08:58:34 -0500


Here is an old patch I did for adding "nat mode" to openafs.  I never put
this in cvs because

1) it's part of disconnected afs, and might not be the best way to do this
2) nat offends me, and increasing network traffic to compensate for lack of
   connectivity offends me

Index: src/afs/afs_daemons.c
===================================================================
RCS file: /cvs/openafs/src/afs/afs_daemons.c,v
retrieving revision 1.30
diff -u -r1.30 afs_daemons.c
--- src/afs/afs_daemons.c	1 Dec 2004 23:38:56 -0000	1.30
+++ src/afs/afs_daemons.c	18 Jan 2005 16:17:11 -0000
@@ -46,16 +46,36 @@
 afs_int32 afs_gcpags_procsize = 0;
 
 afs_int32 afs_CheckServerDaemonStarted = 0;
-#ifdef DEFAULT_PROBE_INTERVAL
-afs_int32 PROBE_INTERVAL = DEFAULT_PROBE_INTERVAL;	/* overridding during compile */
-#else
-afs_int32 PROBE_INTERVAL = 180;	/* default to 3 min */
+#ifndef DEFAULT_PROBE_INTERVAL
+#define DEFAULT_PROBE_INTERVAL 180	/* default to 3 min */
 #endif
+afs_int32 PROBE_INTERVAL = DEFAULT_PROBE_INTERVAL;
+afs_int32 probe_all_interval = 600;
+afs_int32 nat_probe_interval = 60;
 
 #define PROBE_WAIT() (1000 * (PROBE_INTERVAL - ((afs_random() & 0x7fffffff) \
 		      % (PROBE_INTERVAL/2))))
 
 void
+afs_SetCheckServerNATmode(int isnat)
+{
+    static afs_int32 old_intvl, old_all_intvl;
+    static int wasnat;
+
+    if (isnat && !wasnat) {
+	old_intvl = PROBE_INTERVAL;
+	old_all_intvl = probe_all_interval;
+	PROBE_INTERVAL = nat_probe_interval;
+	probe_all_interval = nat_probe_interval;
+	afs_osi_CancelWait(&AFS_CSWaitHandler);
+    } else if (!isnat && wasnat) {
+	PROBE_INTERVAL = old_intvl;
+	probe_all_interval = old_all_intvl;
+    }
+    wasnat = isnat;
+}
+
+void
 afs_CheckServerDaemon(void)
 {
     afs_int32 now, delay, lastCheck, last10MinCheck;
@@ -80,7 +100,7 @@
 	    lastCheck = now = osi_Time();
 	}
 
-	if (600 + last10MinCheck <= now) {
+	if (probe_all_interval + last10MinCheck <= now) {
 	    afs_Trace1(afs_iclSetp, CM_TRACE_PROBEUP, ICL_TYPE_INT32, 600);
 	    afs_CheckServers(0, NULL);
 	    last10MinCheck = now = osi_Time();
@@ -94,8 +114,8 @@
 
 	/* Compute time to next probe. */
 	delay = PROBE_INTERVAL + lastCheck;
-	if (delay > 600 + last10MinCheck)
-	    delay = 600 + last10MinCheck;
+	if (delay > probe_all_interval + last10MinCheck)
+	    delay = probe_all_interval + last10MinCheck;
 	delay -= now;
 	if (delay < 1)
 	    delay = 1;
@@ -175,9 +195,6 @@
 	    DFlush();		/* write out dir buffers */
 	    afs_WriteThroughDSlots();	/* write through cacheinfo entries */
 	    afs_FlushActiveVcaches(1);	/* keep flocks held & flush nfs writes */
-#ifdef AFS_DISCON_ENV
-	    afs_StoreDirtyVcaches();
-#endif
 	    afs_CheckRXEpoch();
 	    last1MinCheck = now;
 	}
Index: src/config/venus.h
===================================================================
RCS file: /cvs/openafs/src/config/venus.h,v
retrieving revision 1.10
diff -u -r1.10 venus.h
--- src/config/venus.h	2 Jun 2004 08:43:02 -0000	1.10
+++ src/config/venus.h	18 Jan 2005 16:17:11 -0000
@@ -180,5 +180,6 @@
 #define VIOC_NEWALIAS		_CVICEIOCTL(1)	/* create new cell alias */
 #define VIOC_GETALIAS		_CVICEIOCTL(2)	/* get alias info */
 #define VIOC_CBADDR		_CVICEIOCTL(3)	/* push callback addr */
+#define VIOC_DISCON             _CVICEIOCTL(5)	/* set/get discon mode */
 
 #endif /* AFS_VENUS_H */
Index: src/venus/fs.c
===================================================================
RCS file: /cvs/openafs/src/venus/fs.c,v
retrieving revision 1.26
diff -u -r1.26 fs.c
--- src/venus/fs.c	10 Oct 2004 01:38:57 -0000	1.26
+++ src/venus/fs.c	18 Jan 2005 16:17:12 -0000
@@ -3097,6 +3097,59 @@
     return 0;
 }
 
+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;
+}
+
 #include "AFS_component_version_number.c"
 
 int
@@ -3398,6 +3451,10 @@
     ts = cmd_CreateSyntax("setcbaddr", CallBackRxConnCmd, 0, "configure callback connection address");
     cmd_AddParm(ts, "-addr", CMD_SINGLE, CMD_OPTIONAL, "host name or address");
 
+    ts = cmd_CreateSyntax("discon", DisconCmd, 0,
+			  "disconnection mode");
+    cmd_AddParm(ts, "-mode", CMD_SINGLE, CMD_OPTIONAL, "nat | full");
+
     code = cmd_Dispatch(argc, argv);
     if (rxInitDone)
 	rx_Finalize();