Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 14 Jul 2001 21:17:15 -0500
From:      Alfred Perlstein <bright@sneakerz.org>
To:        Seigo Tanimura <tanimura@r.dl.itc.u-tokyo.ac.jp>
Cc:        jake@FreeBSD.org, jhb@FreeBSD.org, current@FreeBSD.org
Subject:   Re: Lock of struct filedesc, file, pgrp, session and sigio
Message-ID:  <20010714211715.E15299@sneakerz.org>
In-Reply-To: <200107131200.f6DC0Pt05497@rina.r.dl.itc.u-tokyo.ac.jp>; from tanimura@r.dl.itc.u-tokyo.ac.jp on Fri, Jul 13, 2001 at 09:00:25PM %2B0900
References:  <200107020812.f628CfK44241@rina.r.dl.itc.u-tokyo.ac.jp> <20010707164249.C88962@sneakerz.org> <20010709032044.B1894@sneakerz.org> <200107100845.f6A8jqt99404@rina.r.dl.itc.u-tokyo.ac.jp> <20010710035347.Q1894@sneakerz.org> <200107100903.f6A93et02367@rina.r.dl.itc.u-tokyo.ac.jp> <200107111137.f6BBbQt22812@rina.r.dl.itc.u-tokyo.ac.jp> <20010713042504.O6664@sneakerz.org> <200107131049.f6DAnPt95755@rina.r.dl.itc.u-tokyo.ac.jp> <200107131200.f6DC0Pt05497@rina.r.dl.itc.u-tokyo.ac.jp>

next in thread | previous in thread | raw e-mail | index | archive | help
* Seigo Tanimura <tanimura@r.dl.itc.u-tokyo.ac.jp> [010713 07:00] wrote:
> On Fri, 13 Jul 2001 19:49:25 +0900,
>   Seigo Tanimura <tanimura> said:
> 
> Alfred> Certain operations, such as:
> Alfred> kq = (struct kqueue *)fp->f_data;
> Alfred> should not really require that the file be locked, it's implicitly frozen
> Alfred> at creation time (i think)
> 
> Seigo> Yes.
> 
> Only one exception beats off everything. union_dircheck() in
> fs/unionfs/union_subr.c may replace f_data with a new vnode.

That code really scared me, but on careful inspection, the f_data
is actually protected by the vnode exclusive lock from concurrant
getdirentries() calls.  (getdirentries() calls union_dircheck())

The code is still troublesome for mixing read() and getdirentries()
at the same time, but since union mounts are rare we should leave
it along and possibly revisit this later.

My opinion is that you never need a lock for an assignment, unless
that assignment spans multiple dependant operations or is dependant
on some pre-condition, cases:

/* no lock */
foo->a = 5;   

/* needs lock */
if (foo->b)
   foo->a = 5;

/* might need lock to protect agianst inconsistant view */
foo->a = 5;
foo->b = c;

-- 
-Alfred Perlstein [alfred@freebsd.org]
Ok, who wrote this damn function called '??'?
And why do my programs keep crashing in it?

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010714211715.E15299>