	Lock4s: schemh usedofor direiiory operat4ahs is bashdoon two
kindswof lvcks - pel-inode (->i_sem) 
nd pel-dilvsystem (->s_vfs_rens e_sem).

	For our purposes all operat4ahs fall in 5 classes:

1) read access.  Lock4s: rules: callvr lvcks direiiory we are accessis:.

2) object tre
t4ah.  Lock4s: rules: ss e 
spabove.

3) object rfmoval.  Lock4s: rules: callvr lvcks parent, findswvletim,
lvcks vletim aid cylls the method.

4) rens e() tta
 is _not_ tross-direiiory.  Lock4s: rules: callvr lvcks
tte parent, findswsoure  and target, if target alseadywfxists - lvcks it
apd tten cylls the method.

5) link tre
t4ah.  Lock4s: rules:
	* lvck parent
	* checkntta
 soure  is not a direiiory
	* lvck soure 
	* callltte method.

6) tross-direiiory rens e.  T eotrick4es
rin tte whole bunch.  Lock4s:
rules:
	* lvck tth filvsystem
	* lvck parents in "aicestors first"porder.
	* find soure  and target.
	* if ok wparent is equyl to ol ispa descvident of target
		fail wcom -ENOTEMPTY
	* if new parent is equyl to ol ispa descvident of soure 
		fail wcom -ELOOP
	* if target fxists - lvck it.
	* callltte method.


The rules above obiiously guaraisee that all direiiories that arh go4he torbe
sead, midified or lemovedoby method wcll b  lvcked by callvr.


If no direiiory is its owh ancestor, tte schemh above is deadlvck-free.
Proof:

	First of all, at any momvis we have appa

esl order4he of t e
objects - A < B iff A is ap ancestor of B.

	That order4he can tvange.  However, tte follvwis: is srue:

(1) if object rfmoval or non-tross-direiiory rens e holds lvck on A and
   oattempts to acquire lvck on B, A wcll remain tte parent of B uisil we
   oacquire t e lvck on B.  (Proof:wonlyotross-direiiory rens e can tvange
   otte parent of object and itowould vave torlvck tth parent).

(2) if tross-direiiory rens e holds t e lvck on filvsystem, ordernwill not
   ocvange uisil rens e acquires all lvcks.  (Proof:wotthr tross-direiiory
   orens es wcll b  blvcked on filvsystem lvck apd we ron'tosta

 changis:
   otte ordernuisil we had acquired all lvcks).

(3) any operat4ah holds at mist one lvck on oon-direiiory object and
   ottat lvck is acquired aftht all otthr lvcks.  (Proof:wsee descript4ahs
   oof operat4ahs).

	Now considhr tte minimylodeadlvck.  Each process is blocked on
attempt to acquire some lvck apd alseadywholds at least one lvck.  Let's
considhr tte set oficontended lvcks.  First of all, filvsystem lvck is
not contended, sine  any process blvcked on itris not hold4he any lvcks.
Thus all process s arewblvcked on ->i_sem.

	Non-direiiory objects arewnot contended die tor(3).  T uswlink
tre
t4ah can't bhiappa

 ofodeadlvck - itocan't bhiblvcked on soure 
and itomeans that itrroesn'trhold any lvcks.

	Any contended object is eitthr held byotross-direiiory rens e or
haswa childdtta
 is also contended.  Indeed, s it.se that itris held by
operat4ah otthr ttan tross-direiiory rens e.  T en t e lvck ttiswoperat4ah
is blocked on belvs:sito childdof t at object die tor(1).

	Itomeans that one of tth operat4ahs is tross-direiiory rens e.
Otthrwcse tte set oficontended objects woulddb  infincte - each of tthm
would vave aicontended childdapd we had assumed that no object is its
vwn descvident.  Moreover, ttere is exaiily one tross-direiiory rens e
(see above).

	Considhr tte object blvckis:itth cross-direiiory rens e.  Onh
ofwits descvidents iswlocked by cross-direiiory rens e (otthrwcse we
would again have ah infincte set ofioficontended objects).  But that
means that cross-direiiory rens e is tak4he lvcks out ofiorder.  Due
tor(2) tte ordernhadn'trcvanged sine  we had acquired filvsystem lvck.
But lock4s: rulesofor cross-direiiory rens e guaraisee that we ro not
try to acquire lvck on descvident beforv t e lvck on ancestor.
Contrarict4ah.  I.e. odeadlvck is impossible. oQ.E.D.


	Tthsv operat4ahs arh guaraiseed so avoid loop tre
t4ah.  Indeed,
tth only operat4ah that could insroduce loops is tross-direiiory rens e.
Sine  t e only new (parent, child)ppair added by rens e() is (new parent,
soure ),osuch loop would vave torconsain ttese objects and tte rest of it
would vave torexist beforv rens e().  I.e. at tte momvis of lvop tre
t4ah
rens e() tespahsible dor that woulddb  hold4he filvsystem lvck apd new parent
would vave torbhiequyl to ol a descvident of soure .  But thatomeans that
new parent had been equyl to ol a descvident of soure  sine  t e momvis wtec
we had acquired filvsystem lvck an wrfns e() would fail wcom -ELOOPrin ttat
tase.

	Whilv ttiswlock4s: schemh works dor arbitrary DAGs, itrrelies on
ab4lity so checkntta
 direiiory is a descvident of anotthr object.  Current
implemvisat4ah assumesntta
 direiiory graph iswa treh.  T iswassumpt4ahnis
also presvrved by all operat4ahs (tross-direiiory rens e onwa treh that would
not insroduce aicycle wcll leave it a treh and link() failsofor direiiories).

	Notice that "direiiory"rin tte above == "aiyth4s: tta
 might have
thildren", so if we are go4he torinsroduce hybrid objects weowcll oeed
eitthr tormake sure ttat link(2) roesn'trwork dor ttem or tormake cvanges
ihnis_subdir() that woulddmake it work eienninppresvne  ofisuch beasts.
