2002-11-07 09:43:42

by Hirokazu Takahashi

[permalink] [raw]
Subject: [BUG][PATCH] lockd won't work 248 days after booting.

Hello,

I think lockd has jiffies wraparound problems.
It's wrong that lockd set some timers to zero in hope that
it'll exipre soon. But time_before() and time_after() won't
work 248 days after booting.

We should initialize them to jiffies instead of zero.

The following patch can be applied against 2.5.46 and 2.4.19.

Thank you,
Hirokazu Takahashi.


--- fs/lockd/host.c.JIF Tue Nov 5 16:49:38 2030
+++ fs/lockd/host.c Tue Nov 5 17:04:41 2030
@@ -128,7 +128,7 @@ nlm_lookup_host(int server, struct socka
nlm_hosts[hash] = host;

if (++nrhosts > NLM_HOST_MAX)
- next_gc = 0;
+ next_gc = jiffies;

nohost:
up(&nlm_host_sema);
@@ -276,7 +276,7 @@ nlm_shutdown_hosts(void)
dprintk("lockd: nuking all hosts...\n");
for (i = 0; i < NLM_HOST_NRHASH; i++) {
for (host = nlm_hosts[i]; host; host = host->h_next)
- host->h_expires = 0;
+ host->h_expires = jiffies;
}

/* Then, perform a garbage collection pass */
--- fs/lockd/svcsubs.c.JIF Tue Nov 5 16:50:03 2030
+++ fs/lockd/svcsubs.c Tue Nov 5 16:57:43 2030
@@ -302,7 +302,7 @@ nlmsvc_invalidate_all(void)
struct nlm_host *host;
while ((host = nlm_find_client()) != NULL) {
nlmsvc_free_host_resources(host);
- host->h_expires = 0;
+ host->h_expires = jiffies;
host->h_killed = 1;
nlm_release_host(host);
}
--- fs/lockd/clntlock.c.JIF Thu Nov 7 13:01:38 2030
+++ fs/lockd/clntlock.c Thu Nov 7 13:02:07 2030
@@ -167,7 +167,7 @@ void nlmclnt_prepare_reclaim(struct nlm_
host->h_monitored = 0;
host->h_nsmstate = newstate;
host->h_state++;
- host->h_nextrebind = 0;
+ host->h_nextrebind = jiffies;
nlm_rebind_host(host);
nlmclnt_mark_reclaim(host);
dprintk("NLM: reclaiming locks for host %s", host->h_name);


-------------------------------------------------------
This sf.net email is sponsored by: See the NEW Palm
Tungsten T handheld. Power & Color in a compact size!
http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0001en
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs


2002-11-07 09:50:39

by Hirokazu Takahashi

[permalink] [raw]
Subject: Re: [BUG][PATCH] lockd won't work 248 days after booting.

Hello,

> I think lockd has jiffies wraparound problems.
> It's wrong that lockd set some timers to zero in hope that
> it'll exipre soon. But time_before() and time_after() won't
> work 248 days after booting.


We can check jiffies wraparound problems with a following patch.



--- kernel/timer.c.JIF Tue Nov 5 17:13:00 2030
+++ kernel/timer.c Tue Nov 5 21:27:58 2030
@@ -1094,6 +1094,7 @@ static void __devinit init_timers_cpu(in
{
int j;
tvec_base_t *base;
+ unsigned long jif = jiffies;

base = &per_cpu(tvec_bases, cpu);
spin_lock_init(&base->lock);
@@ -1105,6 +1106,18 @@ static void __devinit init_timers_cpu(in
}
for (j = 0; j < TVR_SIZE; j++)
INIT_LIST_HEAD(base->tv1.vec + j);
+
+ base->timer_jiffies = jif;
+ base->tv1.index = jif & TVR_MASK;
+ jif >>= TVR_BITS;
+ base->tv2.index = jif & TVN_MASK;
+ jif >>= TVN_BITS;
+ base->tv3.index = jif & TVN_MASK;
+ jif >>= TVN_BITS;
+ base->tv4.index = jif & TVN_MASK;
+ jif >>= TVN_BITS;
+ base->tv5.index = jif & TVN_MASK;
+
tasklet_init(&per_cpu(timer_tasklet, cpu), run_timer_tasklet, 0UL);
}

@@ -1126,9 +1139,22 @@ static struct notifier_block __devinitda
.notifier_call = timer_cpu_notify,
};

+static int __init
+jiffies_setup(char *str)
+{
+ char *cur = str;
+ jiffies = simple_strtoul(cur, &cur, 0);
+ printk(KERN_INFO "jiffies is initialized to 0x%lx\n", jiffies);
+ return 1;
+}
+
+__setup("jiffies=", jiffies_setup);

void __init init_timers(void)
{
+ jiffies_64 = jiffies;
+ wall_jiffies = jiffies;
+
timer_cpu_notify(&timers_nb, (unsigned long)CPU_UP_PREPARE,
(void *)(long)smp_processor_id());
register_cpu_notifier(&timers_nb);


-------------------------------------------------------
This sf.net email is sponsored by: See the NEW Palm
Tungsten T handheld. Power & Color in a compact size!
http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0001en
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs