Address lock-order-inversion

There was a possible lock inversion scenario that could happen when
attempting to shutdown BIND if three or more threads are involved.

To demonstrate the problem in question lets consider the case detected
in TSAN tests, we have three threads, T1, T2 and T3, we also have three
mutexes involved, M1, M2 and M3.

M1 = adb->namelocks[some_bucket]
M2 = some_view->lock (View's lock)
M3 = some_zone->lock (Zone's lock)

T1 acquires M1 dns_adb_createfind -> find_name_and_lock
T2 acquires M2 view_flushanddetach
T3 acquires M3 zone_shutdown

T1 attempts to acquire M2, but it is locked by T2:
	#1 dns_view_find lib/dns/view.c:1040
	#2 dbfind_name lib/dns/adb.c:3833
	#3 dns_adb_createfind lib/dns/adb.c:3198

T2 attempts to acquire M3, but it is locked by T3:
	#1 dns_zone_flush lib/dns/zone.c:11441
    #2 flush lib/dns/zt.c:215
    #3 dns_zt_apply lib/dns/zt.c:537
    #4 zt_destroy lib/dns/zt.c:221
    #5 zt_flushanddetach lib/dns/zt.c:243
    #6 dns_zt_flushanddetach lib/dns/zt.c:249
    #7 view_flushanddetach lib/dns/view.c:645

T3 attemtps to acquire M1, but it is locked by T1:
	#1 violate_locking_hierarchy lib/dns/adb.c:1279
    #2 dns_adb_cancelfind lib/dns/adb.c:3457
    #3 notify_cancel lib/dns/zone.c:11796
    #4 zone_shutdown lib/dns/zone.c:14532

To fix the problem, we addressed the function zone_shutdown, before we
attempt to acquire the zone's lock (M3) we now acquire the view's lock
(M2) associated with that zone, this way we ensure that either T2 or T3
will complete its job. If T3 runs first it will relase M1, so T1 could
run to completion, if T2 runs first, it will release M3 allowing T3 to
run to completion.
Status Job ID Name Coverage
  Precheck
passed #1629755
linux amd64
autoreconf

00:00:17

passed #1629757
linux amd64
clang-format

00:00:17

passed #1629758
linux amd64
coccinelle

00:03:39

failed #1629759
linux amd64
danger

00:00:15

passed #1629756
linux amd64
misc

00:00:13

 
  Build
passed #1629772
linux amd64
clang:asan

00:03:57

passed #1629776
linux amd64
clang:buster:amd64

00:01:47

passed #1629779
amd64 libvirt
clang:freebsd11:amd64

00:01:55

passed #1629780
amd64 libvirt
clang:freebsd12:amd64

00:01:43

passed #1629781
amd64 libvirt
clang:openbsd:amd64

00:03:44

passed #1629774
linux amd64
clang:tsan

00:02:02

passed #1629760
linux amd64
gcc:alpine3.13:amd64

00:01:46

passed #1629771
linux amd64
gcc:asan

00:03:23

passed #1629764
linux amd64
gcc:buster:amd64

00:01:15

passed #1629761
linux amd64
gcc:centos7:amd64

00:01:22

passed #1629762
linux amd64
gcc:centos8:amd64

00:01:28

passed #1629770
linux amd64
gcc:focal:amd64

00:01:36

passed #1629775
linux amd64
gcc:mutexatomics

00:01:29

passed #1629766
linux amd64
gcc:out-of-tree

00:01:21

passed #1629765
linux amd64
gcc:sid:amd64

00:02:02

passed #1629767
linux i386
gcc:sid:i386

00:01:35

passed #1629777
linux amd64
gcc:softhsm2.4

00:01:29

passed #1629778
linux amd64
gcc:softhsm2.6

00:01:35

passed #1629763
linux amd64
gcc:stretch:amd64

00:01:45

passed #1629773
linux amd64
gcc:tsan

00:01:43

passed #1629768
linux amd64
gcc:tumbleweed:amd64

00:01:26

passed #1629769
linux amd64
gcc:xenial:amd64

00:01:43

passed #1629783
amd64 windows
msvc:windows:amd64

00:01:11

passed #1629782
linux amd64
nolibtool:sid:amd64

00:02:00

 
  Unit
passed #1629795
linux amd64
unit:clang:asan

00:01:09

passed #1629799
linux amd64
unit:clang:buster:amd64

00:00:37

passed #1629802
amd64 libvirt
unit:clang:freebsd11:amd64

00:01:08

passed #1629803
amd64 libvirt
unit:clang:freebsd12:amd64

00:01:02

passed #1629797
linux amd64
unit:clang:tsan

00:01:29

passed #1629784
linux amd64
unit:gcc:alpine3.13:amd64

00:00:40

passed #1629794
linux amd64
unit:gcc:asan

00:01:09

passed #1629788
linux amd64
unit:gcc:buster:amd64

00:00:55

passed #1629785
linux amd64
unit:gcc:centos7:amd64

00:00:38

passed #1629786
linux amd64
unit:gcc:centos8:amd64

00:00:39

passed #1629793
linux amd64
unit:gcc:focal:amd64

00:00:36

passed #1629798
linux amd64
unit:gcc:mutexatomics

00:00:36

passed #1629789
linux amd64
unit:gcc:sid:amd64

00:00:38

passed #1629790
linux i386
unit:gcc:sid:i386

00:00:48

passed #1629800
linux amd64
unit:gcc:softhsm2.4

00:00:37

passed #1629801
linux amd64
unit:gcc:softhsm2.6

00:00:40

passed #1629787
linux amd64
unit:gcc:stretch:amd64

00:00:38

passed #1629796
linux amd64
unit:gcc:tsan

00:01:45

passed #1629791
linux amd64
unit:gcc:tumbleweed:amd64

00:00:36

passed #1629792
linux amd64
unit:gcc:xenial:amd64

00:00:37

passed #1629804
linux amd64
unit:nolibtool:sid:amd64

00:00:55

 
  System
failed #1629816
linux amd64
system:clang:asan

00:12:58

passed #1629820
linux amd64
system:clang:buster:amd64

00:11:46

passed #1629823
amd64 libvirt
system:clang:freebsd11:amd64

00:11:00

passed #1629824
amd64 libvirt
system:clang:freebsd12:amd64

00:10:52

failed #1629818
linux amd64
system:clang:tsan

00:14:37

failed #1629805
linux amd64
system:gcc:alpine3.13:amd64

00:12:02

passed #1629815
linux amd64
system:gcc:asan

00:13:34

passed #1629809
linux amd64
system:gcc:buster:amd64

00:12:48

failed #1629806
linux amd64
system:gcc:centos7:amd64

00:12:00

passed #1629807
linux amd64
system:gcc:centos8:amd64

00:11:38

passed #1629814
linux amd64
system:gcc:focal:amd64

00:11:59

passed #1629819
linux amd64
system:gcc:mutexatomics

00:11:23

passed #1629810
linux amd64
system:gcc:sid:amd64

00:11:36

passed #1629811
linux i386
system:gcc:sid:i386

00:09:43

passed #1629821
linux amd64
system:gcc:softhsm2.4

00:11:24

passed #1629822
linux amd64
system:gcc:softhsm2.6

00:11:20

passed #1629808
linux amd64
system:gcc:stretch:amd64

00:11:37

failed #1629817
linux amd64
system:gcc:tsan

00:15:23

passed #1629812
linux amd64
system:gcc:tumbleweed:amd64

00:11:50

passed #1629813
linux amd64
system:gcc:xenial:amd64

00:10:27

passed #1629825
linux amd64
system:nolibtool:sid:amd64

00:11:37

 
  Docs
passed #1629826
linux amd64
docs

00:02:16

 
  Postcheck
passed #1629830
linux amd64
cppcheck

00:00:22

passed #1629827
linux amd64
flake8

00:00:18

passed #1629831
linux amd64
gcov

00:00:33

75.0%
passed #1629828
linux amd64
pylint

00:00:21

passed #1629829
linux amd64
scan-build

00:09:20

 
Name Stage Failure
failed
system:gcc:tsan System
Running after_script
Running after script...
$ find bin -name 'tsan.*' -exec python3 util/parse_tsan.py {} \;
Uploading artifacts for failed job
Uploading artifacts...
untracked: found 1495 files

Uploading artifacts as "archive" to coordinator... ok
id=1629817 responseStatus=201 Created token=7avmSjhE
Cleaning up file based variables
ERROR: Job failed: exit code 1
failed
system:clang:asan System
I:The following system tests failed:
I: keymgr2kasp
make: *** [Makefile:489: test] Error 1
Uploading artifacts for failed job
Uploading artifacts...
untracked: found 1741 files

Uploading artifacts as "archive" to coordinator... ok
id=1629816 responseStatus=201 Created token=6z9Cx-fR
Cleaning up file based variables
ERROR: Job failed: exit code 1
failed
system:clang:tsan System
Running after_script
Running after script...
$ find bin -name 'tsan.*' -exec python3 util/parse_tsan.py {} \;
Uploading artifacts for failed job
Uploading artifacts...
untracked: found 1495 files

Uploading artifacts as "archive" to coordinator... ok
id=1629818 responseStatus=201 Created token=a8ETdp5q
Cleaning up file based variables
ERROR: Job failed: exit code 1
failed
system:gcc:alpine3.13:amd64 System
I:The following system tests failed:
I: serve-stale
make: *** [Makefile:489: test] Error 1
Uploading artifacts for failed job
Uploading artifacts...
untracked: found 1657 files

Uploading artifacts as "archive" to coordinator... ok
id=1629805 responseStatus=201 Created token=sHKahj4T
Cleaning up file based variables
ERROR: Job failed: exit code 1
failed
system:gcc:centos7:amd64 System
I:The following system tests failed:
I: keymgr2kasp
make: *** [test] Error 1
Uploading artifacts for failed job
Uploading artifacts...
untracked: found 1701 files

Uploading artifacts as "archive" to coordinator... ok
id=1629806 responseStatus=201 Created token=zvxAWM1Z
Cleaning up file based variables
ERROR: Job failed: exit code 1
failed
danger Precheck
 * branch            v9_16      -> FETCH_HEAD



Failing the build, there is 1 fail.
Feedback: https://gitlab.isc.org/isc-projects/bind9/merge_requests/4879#note_206252

Cleaning up file based variables
ERROR: Job failed: exit code 1