aboutsummaryrefslogtreecommitdiff
path: root/nfs/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'nfs/main.c')
-rw-r--r--nfs/main.c116
1 files changed, 74 insertions, 42 deletions
diff --git a/nfs/main.c b/nfs/main.c
index e709fc72..48852062 100644
--- a/nfs/main.c
+++ b/nfs/main.c
@@ -1,5 +1,5 @@
/*
- Copyright (C) 1996 Free Software Foundation, Inc.
+ Copyright (C) 1996, 1997, 2002 Free Software Foundation, Inc.
Written by Michael I. Bushnell, p/BSG.
This file is part of the GNU Hurd.
@@ -29,23 +29,34 @@
#include <maptime.h>
#include <argp.h>
#include <argz.h>
+#include <error.h>
+#include <version.h>
+
+char *netfs_server_name = "nfs";
+char *netfs_server_version = HURD_VERSION;
extern char *localhost ();
/* Default number of times to retry RPCs when mounted soft. */
-#define DEFAULT_SOFT_RETRIES 3
+#define DEFAULT_SOFT_RETRIES 3
/* Default number of seconds to timeout cached stat information. */
#define DEFAULT_STAT_TIMEOUT 3
/* Default number of seconds to timeout cached file contents. */
-#define DEFAULT_CACHE_TIMEOUT 3
+#define DEFAULT_CACHE_TIMEOUT 3
+
+/* Default number of seconds to timeout cache positive dir hits. */
+#define DEFAULT_NAME_CACHE_TIMEOUT 3
+
+/* Default number of seconds to timeout cache negative dir hits. */
+#define DEFAULT_NAME_CACHE_NEG_TIMEOUT 3
/* Default maximum number of bytes to read at once. */
-#define DEFAULT_READ_SIZE 8192
+#define DEFAULT_READ_SIZE 8192
/* Default maximum number of bytes to write at once. */
-#define DEFAULT_WRITE_SIZE 8192
+#define DEFAULT_WRITE_SIZE 8192
/* Number of seconds to timeout cached stat information. */
@@ -54,6 +65,12 @@ int stat_timeout = DEFAULT_STAT_TIMEOUT;
/* Number of seconds to timeout cached file contents. */
int cache_timeout = DEFAULT_CACHE_TIMEOUT;
+/* Number of seconds to timeout cached positive dir hits. */
+int name_cache_timeout = DEFAULT_NAME_CACHE_TIMEOUT;
+
+/* Number of seconds to timeout cached negative dir hits. */
+int name_cache_neg_timeout = DEFAULT_NAME_CACHE_NEG_TIMEOUT;
+
/* Number of seconds to wait for first retransmission of an RPC. */
int initial_transmit_timeout = 1;
@@ -74,8 +91,8 @@ int write_size = DEFAULT_WRITE_SIZE;
#define OPT_SOFT 's'
#define OPT_HARD 'h'
-#define OPT_RSIZE 'r'
-#define OPT_WSIZE 'w'
+#define OPT_RSIZE 'R'
+#define OPT_WSIZE 'W'
#define OPT_STAT_TO -2
#define OPT_CACHE_TO -3
#define OPT_INIT_TR_TO -4
@@ -88,19 +105,23 @@ int write_size = DEFAULT_WRITE_SIZE;
#define OPT_MNT_PROG -11
#define OPT_NFS_PROG -12
#define OPT_PMAP_PORT -13
+#define OPT_NCACHE_TO -14
+#define OPT_NCACHE_NEG_TO -15
/* Return a string corresponding to the printed rep of DEFAULT_what */
#define ___D(what) #what
#define __D(what) ___D(what)
#define _D(what) __D(DEFAULT_ ## what)
+const char *argp_program_version = STANDARD_HURD_VERSION (nfs);
+
/* Options usable both at startup and at runtime. */
static const struct argp_option common_options[] =
{
{0,0,0,0,0,1},
{"soft", OPT_SOFT, "RETRIES", OPTION_ARG_OPTIONAL,
- "File system requests will eventually fail, after RETRIES tries if"
- " specified, otherwise " _D(SOFT_RETRIES)},
+ "File system requests will eventually fail, after RETRIES tries"
+ " (default " _D(SOFT_RETRIES) ")" },
{"hard", OPT_HARD, 0, 0,
"Retry file systems requests until they succeed"},
@@ -117,6 +138,12 @@ static const struct argp_option common_options[] =
"Timeout for cached stat information (default " _D(STAT_TIMEOUT) ")"},
{"cache-timeout", OPT_CACHE_TO, "SEC", 0,
"Timeout for cached file data (default " _D(CACHE_TIMEOUT) ")"},
+ {"name-cache-timeout", OPT_NCACHE_TO, "SEC", 0,
+ "Timeout for positive directory cache entries (default "
+ _D(NAME_CACHE_TIMEOUT) ")"},
+ {"name-cache-neg-timeout", OPT_NCACHE_NEG_TO, "SEC", 0,
+ "Timeout for negative directory cache entires (default "
+ _D(NAME_CACHE_NEG_TIMEOUT) ")"},
{"init-transmit-timeout", OPT_INIT_TR_TO,"SEC", 0},
{"max-transmit-timeout", OPT_MAX_TR_TO, "SEC", 0},
@@ -144,6 +171,8 @@ parse_common_opt (int key, char *arg, struct argp_state *state)
case OPT_CACHE_TO: cache_timeout = atoi (arg); break;
case OPT_INIT_TR_TO: initial_transmit_timeout = atoi (arg); break;
case OPT_MAX_TR_TO: max_transmit_timeout = atoi (arg); break;
+ case OPT_NCACHE_TO: name_cache_timeout = atoi (arg); break;
+ case OPT_NCACHE_NEG_TO: name_cache_neg_timeout = atoi (arg); break;
default:
return ARGP_ERR_UNKNOWN;
@@ -172,29 +201,32 @@ static const struct argp_option startup_options[] = {
{ 0 }
};
static char *args_doc = "REMOTE_FS [HOST]";
-static char *doc = "If HOST is not specified, an attempt is made to extract"
-" it from REMOTE_FS, using either the `HOST:FS' or `FS@HOST' notations.";
+static char *doc = "Hurd nfs translator"
+"\vIf HOST is not specified, an attempt is made to extract"
+" it from REMOTE_FS using either the `HOST:FS' or `FS@HOST' notations.";
-static const struct argp *
-runtime_argp_parents[] = { &netfs_std_runtime_argp, 0 };
+static const struct argp_child
+runtime_argp_children[] = { {&netfs_std_runtime_argp}, {0} };
static struct argp
-runtime_argp = { common_options, parse_common_opt, 0, 0, runtime_argp_parents };
+runtime_argp = { common_options, parse_common_opt, 0, 0,
+ runtime_argp_children };
-/* Use by netfs_set_options to handle runtime option parsing. */
+/* Used by netfs_set_options to handle runtime option parsing. */
struct argp *netfs_runtime_argp = &runtime_argp;
+/* Where to find the remote filesystem. */
+static char *remote_fs; /* = 0; */
+static char *host; /* = 0; */
+
/* Return an argz string describing the current options. Fill *ARGZ
with a pointer to newly malloced storage holding the list and *LEN
to the length of that storage. */
error_t
-netfs_get_options (char **argz, size_t *argz_len)
+netfs_append_args (char **argz, size_t *argz_len)
{
char buf[80];
error_t err = 0;
- *argz = 0;
- *argz_len = 0;
-
#define FOPT(fmt, arg) \
do { \
if (! err) \
@@ -216,12 +248,23 @@ netfs_get_options (char **argz, size_t *argz_len)
FOPT ("--cache-timeout=%d", cache_timeout);
FOPT ("--init-transmit-timeout=%d", initial_transmit_timeout);
FOPT ("--max-transmit-timeout=%d", max_transmit_timeout);
+ FOPT ("--name-cache-timeout=%d", name_cache_timeout);
+ FOPT ("--name-cache-neg-timeout=%d", name_cache_neg_timeout);
if (! err)
err = netfs_append_std_options (argz, argz_len);
- if (err)
- free (argz);
+ if (! err)
+ {
+ char *fs;
+ if (asprintf (&fs, "%s:%s", host, remote_fs))
+ {
+ err = argz_add (argz, argz_len, fs);
+ free (fs);
+ }
+ else
+ err = ENOMEM;
+ }
return err;
}
@@ -235,6 +278,8 @@ extract_nfs_args (char *spec, char **remote_fs, char **host)
char *sep;
spec = strdup (spec); /* So we can trash it. */
+ if (! spec)
+ return NULL;
sep = index (spec, ':');
if (sep)
@@ -259,13 +304,6 @@ extract_nfs_args (char *spec, char **remote_fs, char **host)
return 0;
}
-/* Where to find the remote filesystem. */
-static char *remote_fs = 0;
-static char *host = 0;
-
-/* For debugging. */
-static volatile int hold = 0;
-
static error_t
parse_startup_opt (int key, char *arg, struct argp_state *state)
{
@@ -285,8 +323,6 @@ parse_startup_opt (int key, char *arg, struct argp_state *state)
nfs_port = atoi (arg);
break;
- case OPT_HOLD: hold = 1; break;
-
case ARGP_KEY_ARG:
if (state->arg_num == 0)
remote_fs = arg;
@@ -315,18 +351,17 @@ parse_startup_opt (int key, char *arg, struct argp_state *state)
int
main (int argc, char **argv)
{
+ error_t err;
struct argp common_argp = { common_options, parse_common_opt };
- const struct argp *argp_parents[] =
- { &common_argp, &netfs_std_startup_argp, 0 };
+ const struct argp_child argp_children[] =
+ { {&common_argp}, {&netfs_std_startup_argp}, {0} };
struct argp argp =
- { startup_options, parse_startup_opt, args_doc, doc, argp_parents };
+ { startup_options, parse_startup_opt, args_doc, doc, argp_children };
mach_port_t bootstrap;
struct sockaddr_in addr;
int ret;
argp_parse (&argp, argc, argv, 0, 0, 0);
-
- while (hold);
task_get_bootstrap_port (mach_task_self (), &bootstrap);
netfs_init ();
@@ -350,14 +385,11 @@ main (int argc, char **argv)
}
while ((ret == -1) && (errno == EADDRINUSE));
if (ret == -1)
- {
- perror ("binding main udp socket");
- exit (1);
- }
+ error (1, errno, "binding main udp socket");
- errno = maptime_map (0, 0, &mapped_time);
- if (errno)
- perror ("mapping time");
+ err = maptime_map (0, 0, &mapped_time);
+ if (err)
+ error (2, err, "mapping time");
cthread_detach (cthread_fork ((cthread_fn_t) timeout_service_thread, 0));
cthread_detach (cthread_fork ((cthread_fn_t) rpc_receive_thread, 0));