User-selectable idmapping cache lifetime
authorneilbrown <neilbrown>
Tue, 28 Mar 2006 00:33:55 +0000 (00:33 +0000)
committerneilbrown <neilbrown>
Tue, 28 Mar 2006 00:33:55 +0000 (00:33 +0000)
Read and process new configuration option, Cache-Expiration, and use
the value to determine how long idmapping entries are cached.
(Really this time)

ChangeLog
utils/idmapd/idmapd.c

index eb21171..ebccf8b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2006-03-28 Kevin Coffman <kwc@citi.umich.edu>
+       User-selectable idmapping cache lifetime
+       
+       Read and process new configuration option, Cache-Expiration, and use
+       the value to determine how long idmapping entries are cached.
+       (Really this time)
+       
 2006-03-27 NeilBrown <neilb@suse.de>
        1.0.8-rc3
 
index ca52c2c..5712edb 100644 (file)
 #define NFSD_DIR  "/proc/net/rpc"
 #endif
 
+#ifndef CLIENT_CACHE_TIMEOUT_FILE
+#define CLIENT_CACHE_TIMEOUT_FILE "/proc/sys/fs/nfs/idmap_cache_timeout"
+#endif
+
 #ifndef NFS4NOBODY_USER
 #define NFS4NOBODY_USER "nobody"
 #endif
@@ -144,6 +148,8 @@ void    mydaemon(int, int);
 void    release_parent();
 
 static int verbose = 0;
+#define DEFAULT_IDMAP_CACHE_EXPIRY 600 /* seconds */
+static int cache_entry_expiration = 0;
 static char pipefsdir[PATH_MAX];
 static char *nobodyuser, *nobodygroup;
 static uid_t nobodyuid;
@@ -291,6 +297,8 @@ main(int argc, char **argv)
        } else {
                conf_init();
                verbose = conf_get_num("General", "Verbosity", 0);
+               cache_entry_expiration = conf_get_num("General",
+                               "Cache-Expiration", DEFAULT_IDMAP_CACHE_EXPIRY);
                CONF_SAVE(xpipefsdir, conf_get_str("General", "Pipefs-Directory"));
                if (xpipefsdir != NULL)
                        strlcpy(pipefsdir, xpipefsdir, sizeof(pipefsdir));
@@ -348,6 +356,9 @@ main(int argc, char **argv)
 
        event_init();
 
+       if (verbose > 0)
+               idmapd_warnx("Expiration time is %d seconds.",
+                            cache_entry_expiration);
        if (serverstart) {
                nfsdret = nfsdopen();
                if (nfsdret == 0) {
@@ -364,6 +375,29 @@ main(int argc, char **argv)
                        .tv_usec = 0,
                };
 
+               if (cache_entry_expiration != DEFAULT_IDMAP_CACHE_EXPIRY) {
+                       int timeout_fd, len;
+                       char timeout_buf[12];
+                       if ((timeout_fd = open(CLIENT_CACHE_TIMEOUT_FILE,
+                                              O_RDWR)) == -1) {
+                               idmapd_warnx("Unable to open '%s' to set "
+                                            "client cache expiration time "
+                                            "to %d seconds\n",
+                                            CLIENT_CACHE_TIMEOUT_FILE,
+                                            cache_entry_expiration);
+                       } else {
+                               len = snprintf(timeout_buf, sizeof(timeout_buf),
+                                              "%d", cache_entry_expiration);
+                               if ((write(timeout_fd, timeout_buf, len)) != len)
+                                       idmapd_warnx("Error writing '%s' to "
+                                                    "'%s' to set client "
+                                                    "cache expiration time\n",
+                                                    timeout_buf,
+                                                    CLIENT_CACHE_TIMEOUT_FILE);
+                               close(timeout_fd);
+                       }
+               }
+
                if ((fd = open(pipefsdir, O_RDONLY)) == -1)
                        idmapd_err(1, "main: open(%s)", pipefsdir);
 
@@ -584,9 +618,9 @@ nfsdcb(int fd, short which, void *data)
                addfield(&bp, &bsiz, p);
                /* Name */
                addfield(&bp, &bsiz, im.im_name);
-#define NFSD_EXPIRY 300 /* seconds */
                /* expiry */
-               snprintf(buf1, sizeof(buf1), "%lu", time(NULL) + NFSD_EXPIRY);
+               snprintf(buf1, sizeof(buf1), "%lu",
+                        time(NULL) + cache_entry_expiration);
                addfield(&bp, &bsiz, buf1);
                /* ID */
                snprintf(buf1, sizeof(buf1), "%u", im.im_id);
@@ -605,7 +639,8 @@ nfsdcb(int fd, short which, void *data)
                snprintf(buf1, sizeof(buf1), "%u", im.im_id);
                addfield(&bp, &bsiz, buf1);
                /* expiry */
-               snprintf(buf1, sizeof(buf1), "%lu", time(NULL) + NFSD_EXPIRY);
+               snprintf(buf1, sizeof(buf1), "%lu",
+                        time(NULL) + cache_entry_expiration);
                addfield(&bp, &bsiz, buf1);
                /* Name */
                addfield(&bp, &bsiz, im.im_name);