]> git.ozlabs.org Git - ccan/blob - ccan/tdb2/tdb1_open.c
tdb2: test: import tdb1's tests.
[ccan] / ccan / tdb2 / tdb1_open.c
1  /*
2    Unix SMB/CIFS implementation.
3
4    trivial database library
5
6    Copyright (C) Andrew Tridgell              1999-2005
7    Copyright (C) Paul `Rusty' Russell              2000
8    Copyright (C) Jeremy Allison                    2000-2003
9
10      ** NOTE! The following LGPL license applies to the tdb
11      ** library. This does NOT imply that all of Samba is released
12      ** under the LGPL
13
14    This library is free software; you can redistribute it and/or
15    modify it under the terms of the GNU Lesser General Public
16    License as published by the Free Software Foundation; either
17    version 3 of the License, or (at your option) any later version.
18
19    This library is distributed in the hope that it will be useful,
20    but WITHOUT ANY WARRANTY; without even the implied warranty of
21    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22    Lesser General Public License for more details.
23
24    You should have received a copy of the GNU Lesser General Public
25    License along with this library; if not, see <http://www.gnu.org/licenses/>.
26 */
27
28 #include "tdb1_private.h"
29
30 /* all contexts, to ensure no double-opens (fcntl locks don't nest!) */
31 static struct tdb1_context *tdb1s = NULL;
32
33 /* We use two hashes to double-check they're using the right hash function. */
34 void tdb1_header_hash(struct tdb1_context *tdb,
35                      uint32_t *magic1_hash, uint32_t *magic2_hash)
36 {
37         TDB1_DATA hash_key;
38         uint32_t tdb1_magic = TDB1_MAGIC;
39
40         hash_key.dptr = (unsigned char *)TDB1_MAGIC_FOOD;
41         hash_key.dsize = sizeof(TDB1_MAGIC_FOOD);
42         *magic1_hash = tdb->hash_fn(&hash_key);
43
44         hash_key.dptr = (unsigned char *)TDB1_CONV(tdb1_magic);
45         hash_key.dsize = sizeof(tdb1_magic);
46         *magic2_hash = tdb->hash_fn(&hash_key);
47
48         /* Make sure at least one hash is non-zero! */
49         if (*magic1_hash == 0 && *magic2_hash == 0)
50                 *magic1_hash = 1;
51 }
52
53 /* initialise a new database with a specified hash size */
54 static int tdb1_new_database(struct tdb1_context *tdb, int hash_size)
55 {
56         struct tdb1_header *newdb;
57         size_t size;
58         int ret = -1;
59
60         /* We make it up in memory, then write it out if not internal */
61         size = sizeof(struct tdb1_header) + (hash_size+1)*sizeof(tdb1_off_t);
62         if (!(newdb = (struct tdb1_header *)calloc(size, 1))) {
63                 tdb->ecode = TDB1_ERR_OOM;
64                 return -1;
65         }
66
67         /* Fill in the header */
68         newdb->version = TDB1_VERSION;
69         newdb->hash_size = hash_size;
70
71         tdb1_header_hash(tdb, &newdb->magic1_hash, &newdb->magic2_hash);
72
73         /* Make sure older tdbs (which don't check the magic hash fields)
74          * will refuse to open this TDB. */
75         if (tdb->flags & TDB1_INCOMPATIBLE_HASH)
76                 newdb->rwlocks = TDB1_HASH_RWLOCK_MAGIC;
77
78         if (tdb->flags & TDB1_INTERNAL) {
79                 tdb->map_size = size;
80                 tdb->map_ptr = (char *)newdb;
81                 memcpy(&tdb->header, newdb, sizeof(tdb->header));
82                 /* Convert the `ondisk' version if asked. */
83                 TDB1_CONV(*newdb);
84                 return 0;
85         }
86         if (lseek(tdb->fd, 0, SEEK_SET) == -1)
87                 goto fail;
88
89         if (ftruncate(tdb->fd, 0) == -1)
90                 goto fail;
91
92         /* This creates an endian-converted header, as if read from disk */
93         TDB1_CONV(*newdb);
94         memcpy(&tdb->header, newdb, sizeof(tdb->header));
95         /* Don't endian-convert the magic food! */
96         memcpy(newdb->magic_food, TDB1_MAGIC_FOOD, strlen(TDB1_MAGIC_FOOD)+1);
97         /* we still have "ret == -1" here */
98         if (tdb1_write_all(tdb->fd, newdb, size))
99                 ret = 0;
100
101   fail:
102         SAFE_FREE(newdb);
103         return ret;
104 }
105
106
107
108 static int tdb1_already_open(dev_t device,
109                             ino_t ino)
110 {
111         struct tdb1_context *i;
112
113         for (i = tdb1s; i; i = i->next) {
114                 if (i->device == device && i->inode == ino) {
115                         return 1;
116                 }
117         }
118
119         return 0;
120 }
121
122 /* open the database, creating it if necessary
123
124    The open_flags and mode are passed straight to the open call on the
125    database file. A flags value of O_WRONLY is invalid. The hash size
126    is advisory, use zero for a default value.
127
128    Return is NULL on error, in which case errno is also set.  Don't
129    try to call tdb1_error or tdb1_errname, just do strerror(errno).
130
131    @param name may be NULL for internal databases. */
132 _PUBLIC_ struct tdb1_context *tdb1_open(const char *name, int hash_size, int tdb1_flags,
133                       int open_flags, mode_t mode)
134 {
135         return tdb1_open_ex(name, hash_size, tdb1_flags, open_flags, mode, NULL, NULL);
136 }
137
138 /* a default logging function */
139 static void null_log_fn(struct tdb1_context *tdb, enum tdb1_debug_level level, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
140 static void null_log_fn(struct tdb1_context *tdb, enum tdb1_debug_level level, const char *fmt, ...)
141 {
142 }
143
144 static bool check_header_hash(struct tdb1_context *tdb,
145                               bool default_hash, uint32_t *m1, uint32_t *m2)
146 {
147         tdb1_header_hash(tdb, m1, m2);
148         if (tdb->header.magic1_hash == *m1 &&
149             tdb->header.magic2_hash == *m2) {
150                 return true;
151         }
152
153         /* If they explicitly set a hash, always respect it. */
154         if (!default_hash)
155                 return false;
156
157         /* Otherwise, try the other inbuilt hash. */
158         if (tdb->hash_fn == tdb1_old_hash)
159                 tdb->hash_fn = tdb1_jenkins_hash;
160         else
161                 tdb->hash_fn = tdb1_old_hash;
162         return check_header_hash(tdb, false, m1, m2);
163 }
164
165 _PUBLIC_ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flags,
166                                 int open_flags, mode_t mode,
167                                 const struct tdb1_logging_context *log_ctx,
168                                 tdb1_hash_func hash_fn)
169 {
170         struct tdb1_context *tdb;
171         struct stat st;
172         int rev = 0, locked = 0;
173         unsigned char *vp;
174         uint32_t vertest;
175         unsigned v;
176         const char *hash_alg;
177         uint32_t magic1, magic2;
178
179         if (!(tdb = (struct tdb1_context *)calloc(1, sizeof *tdb))) {
180                 /* Can't log this */
181                 errno = ENOMEM;
182                 goto fail;
183         }
184         tdb1_io_init(tdb);
185         tdb->fd = -1;
186         tdb->name = NULL;
187         tdb->map_ptr = NULL;
188         tdb->flags = tdb1_flags;
189         tdb->open_flags = open_flags;
190         if (log_ctx) {
191                 tdb->log = *log_ctx;
192         } else {
193                 tdb->log.log_fn = null_log_fn;
194                 tdb->log.log_private = NULL;
195         }
196
197         if (name == NULL && (tdb1_flags & TDB1_INTERNAL)) {
198                 name = "__TDB1_INTERNAL__";
199         }
200
201         if (name == NULL) {
202                 tdb->name = (char *)"__NULL__";
203                 TDB1_LOG((tdb, TDB1_DEBUG_FATAL, "tdb1_open_ex: called with name == NULL\n"));
204                 tdb->name = NULL;
205                 errno = EINVAL;
206                 goto fail;
207         }
208
209         /* now make a copy of the name, as the caller memory might went away */
210         if (!(tdb->name = (char *)strdup(name))) {
211                 /*
212                  * set the name as the given string, so that tdb1_name() will
213                  * work in case of an error.
214                  */
215                 tdb->name = (char *)name;
216                 TDB1_LOG((tdb, TDB1_DEBUG_ERROR, "tdb1_open_ex: can't strdup(%s)\n",
217                          name));
218                 tdb->name = NULL;
219                 errno = ENOMEM;
220                 goto fail;
221         }
222
223         if (hash_fn) {
224                 tdb->hash_fn = hash_fn;
225                 hash_alg = "the user defined";
226         } else {
227                 /* This controls what we use when creating a tdb. */
228                 if (tdb->flags & TDB1_INCOMPATIBLE_HASH) {
229                         tdb->hash_fn = tdb1_jenkins_hash;
230                 } else {
231                         tdb->hash_fn = tdb1_old_hash;
232                 }
233                 hash_alg = "either default";
234         }
235
236         /* cache the page size */
237         tdb->page_size = getpagesize();
238         if (tdb->page_size <= 0) {
239                 tdb->page_size = 0x2000;
240         }
241
242         tdb->max_dead_records = (tdb1_flags & TDB1_VOLATILE) ? 5 : 0;
243
244         if ((open_flags & O_ACCMODE) == O_WRONLY) {
245                 TDB1_LOG((tdb, TDB1_DEBUG_ERROR, "tdb1_open_ex: can't open tdb %s write-only\n",
246                          name));
247                 errno = EINVAL;
248                 goto fail;
249         }
250
251         if (hash_size == 0)
252                 hash_size = TDB1_DEFAULT_HASH_SIZE;
253         if ((open_flags & O_ACCMODE) == O_RDONLY) {
254                 tdb->read_only = 1;
255                 /* read only databases don't do locking or clear if first */
256                 tdb->flags |= TDB1_NOLOCK;
257                 tdb->flags &= ~TDB1_CLEAR_IF_FIRST;
258         }
259
260         if ((tdb->flags & TDB1_ALLOW_NESTING) &&
261             (tdb->flags & TDB1_DISALLOW_NESTING)) {
262                 tdb->ecode = TDB1_ERR_NESTING;
263                 TDB1_LOG((tdb, TDB1_DEBUG_FATAL, "tdb1_open_ex: "
264                         "allow_nesting and disallow_nesting are not allowed together!"));
265                 errno = EINVAL;
266                 goto fail;
267         }
268
269         if (getenv("TDB_NO_FSYNC")) {
270                 tdb->flags |= TDB1_NOSYNC;
271         }
272
273         /*
274          * TDB1_ALLOW_NESTING is the default behavior.
275          * Note: this may change in future versions!
276          */
277         if (!(tdb->flags & TDB1_DISALLOW_NESTING)) {
278                 tdb->flags |= TDB1_ALLOW_NESTING;
279         }
280
281         /* internal databases don't mmap or lock, and start off cleared */
282         if (tdb->flags & TDB1_INTERNAL) {
283                 tdb->flags |= (TDB1_NOLOCK | TDB1_NOMMAP);
284                 tdb->flags &= ~TDB1_CLEAR_IF_FIRST;
285                 if (tdb1_new_database(tdb, hash_size) != 0) {
286                         TDB1_LOG((tdb, TDB1_DEBUG_ERROR, "tdb1_open_ex: tdb1_new_database failed!"));
287                         goto fail;
288                 }
289                 goto internal;
290         }
291
292         if ((tdb->fd = open(name, open_flags, mode)) == -1) {
293                 TDB1_LOG((tdb, TDB1_DEBUG_WARNING, "tdb1_open_ex: could not open file %s: %s\n",
294                          name, strerror(errno)));
295                 goto fail;      /* errno set by open(2) */
296         }
297
298         /* on exec, don't inherit the fd */
299         v = fcntl(tdb->fd, F_GETFD, 0);
300         fcntl(tdb->fd, F_SETFD, v | FD_CLOEXEC);
301
302         /* ensure there is only one process initialising at once */
303         if (tdb1_nest_lock(tdb, TDB1_OPEN_LOCK, F_WRLCK, TDB1_LOCK_WAIT) == -1) {
304                 TDB1_LOG((tdb, TDB1_DEBUG_ERROR, "tdb1_open_ex: failed to get open lock on %s: %s\n",
305                          name, strerror(errno)));
306                 goto fail;      /* errno set by tdb1_brlock */
307         }
308
309         /* we need to zero database if we are the only one with it open */
310         if ((tdb1_flags & TDB1_CLEAR_IF_FIRST) &&
311             (!tdb->read_only) &&
312             (locked = (tdb1_nest_lock(tdb, TDB1_ACTIVE_LOCK, F_WRLCK, TDB1_LOCK_NOWAIT|TDB1_LOCK_PROBE) == 0))) {
313                 open_flags |= O_CREAT;
314                 if (ftruncate(tdb->fd, 0) == -1) {
315                         TDB1_LOG((tdb, TDB1_DEBUG_FATAL, "tdb1_open_ex: "
316                                  "failed to truncate %s: %s\n",
317                                  name, strerror(errno)));
318                         goto fail; /* errno set by ftruncate */
319                 }
320         }
321
322         errno = 0;
323         if (read(tdb->fd, &tdb->header, sizeof(tdb->header)) != sizeof(tdb->header)
324             || strcmp(tdb->header.magic_food, TDB1_MAGIC_FOOD) != 0) {
325                 if (!(open_flags & O_CREAT) || tdb1_new_database(tdb, hash_size) == -1) {
326                         if (errno == 0) {
327                                 errno = EIO; /* ie bad format or something */
328                         }
329                         goto fail;
330                 }
331                 rev = (tdb->flags & TDB1_CONVERT);
332         } else if (tdb->header.version != TDB1_VERSION
333                    && !(rev = (tdb->header.version==TDB1_BYTEREV(TDB1_VERSION)))) {
334                 /* wrong version */
335                 errno = EIO;
336                 goto fail;
337         }
338         vp = (unsigned char *)&tdb->header.version;
339         vertest = (((uint32_t)vp[0]) << 24) | (((uint32_t)vp[1]) << 16) |
340                   (((uint32_t)vp[2]) << 8) | (uint32_t)vp[3];
341         tdb->flags |= (vertest==TDB1_VERSION) ? TDB1_BIGENDIAN : 0;
342         if (!rev)
343                 tdb->flags &= ~TDB1_CONVERT;
344         else {
345                 tdb->flags |= TDB1_CONVERT;
346                 tdb1_convert(&tdb->header, sizeof(tdb->header));
347         }
348         if (fstat(tdb->fd, &st) == -1)
349                 goto fail;
350
351         if (tdb->header.rwlocks != 0 &&
352             tdb->header.rwlocks != TDB1_HASH_RWLOCK_MAGIC) {
353                 TDB1_LOG((tdb, TDB1_DEBUG_ERROR, "tdb1_open_ex: spinlocks no longer supported\n"));
354                 goto fail;
355         }
356
357         if ((tdb->header.magic1_hash == 0) && (tdb->header.magic2_hash == 0)) {
358                 /* older TDB without magic hash references */
359                 tdb->hash_fn = tdb1_old_hash;
360         } else if (!check_header_hash(tdb, !hash_fn, &magic1, &magic2)) {
361                 TDB1_LOG((tdb, TDB1_DEBUG_FATAL, "tdb1_open_ex: "
362                          "%s was not created with %s hash function we are using\n"
363                          "magic1_hash[0x%08X %s 0x%08X] "
364                          "magic2_hash[0x%08X %s 0x%08X]\n",
365                          name, hash_alg,
366                          tdb->header.magic1_hash,
367                          (tdb->header.magic1_hash == magic1) ? "==" : "!=",
368                          magic1,
369                          tdb->header.magic2_hash,
370                          (tdb->header.magic2_hash == magic2) ? "==" : "!=",
371                          magic2));
372                 errno = EINVAL;
373                 goto fail;
374         }
375
376         /* Is it already in the open list?  If so, fail. */
377         if (tdb1_already_open(st.st_dev, st.st_ino)) {
378                 TDB1_LOG((tdb, TDB1_DEBUG_ERROR, "tdb1_open_ex: "
379                          "%s (%d,%d) is already open in this process\n",
380                          name, (int)st.st_dev, (int)st.st_ino));
381                 errno = EBUSY;
382                 goto fail;
383         }
384
385         tdb->map_size = st.st_size;
386         tdb->device = st.st_dev;
387         tdb->inode = st.st_ino;
388         tdb1_mmap(tdb);
389         if (locked) {
390                 if (tdb1_nest_unlock(tdb, TDB1_ACTIVE_LOCK, F_WRLCK, false) == -1) {
391                         TDB1_LOG((tdb, TDB1_DEBUG_ERROR, "tdb1_open_ex: "
392                                  "failed to release ACTIVE_LOCK on %s: %s\n",
393                                  name, strerror(errno)));
394                         goto fail;
395                 }
396
397         }
398
399         /* We always need to do this if the CLEAR_IF_FIRST flag is set, even if
400            we didn't get the initial exclusive lock as we need to let all other
401            users know we're using it. */
402
403         if (tdb1_flags & TDB1_CLEAR_IF_FIRST) {
404                 /* leave this lock in place to indicate it's in use */
405                 if (tdb1_nest_lock(tdb, TDB1_ACTIVE_LOCK, F_RDLCK, TDB1_LOCK_WAIT) == -1) {
406                         goto fail;
407                 }
408         }
409
410         /* if needed, run recovery */
411         if (tdb1_transaction_recover(tdb) == -1) {
412                 goto fail;
413         }
414
415  internal:
416         /* Internal (memory-only) databases skip all the code above to
417          * do with disk files, and resume here by releasing their
418          * open lock and hooking into the active list. */
419         if (tdb1_nest_unlock(tdb, TDB1_OPEN_LOCK, F_WRLCK, false) == -1) {
420                 goto fail;
421         }
422         tdb->next = tdb1s;
423         tdb1s = tdb;
424         return tdb;
425
426  fail:
427         { int save_errno = errno;
428
429         if (!tdb)
430                 return NULL;
431
432         if (tdb->map_ptr) {
433                 if (tdb->flags & TDB1_INTERNAL)
434                         SAFE_FREE(tdb->map_ptr);
435                 else
436                         tdb1_munmap(tdb);
437         }
438         if (tdb->fd != -1)
439                 if (close(tdb->fd) != 0)
440                         TDB1_LOG((tdb, TDB1_DEBUG_ERROR, "tdb1_open_ex: failed to close tdb->fd on error!\n"));
441         SAFE_FREE(tdb->lockrecs);
442         SAFE_FREE(tdb->name);
443         SAFE_FREE(tdb);
444         errno = save_errno;
445         return NULL;
446         }
447 }
448
449 /*
450  * Set the maximum number of dead records per hash chain
451  */
452
453 _PUBLIC_ void tdb1_set_max_dead(struct tdb1_context *tdb, int max_dead)
454 {
455         tdb->max_dead_records = max_dead;
456 }
457
458 /**
459  * Close a database.
460  *
461  * @returns -1 for error; 0 for success.
462  **/
463 _PUBLIC_ int tdb1_close(struct tdb1_context *tdb)
464 {
465         struct tdb1_context **i;
466         int ret = 0;
467
468         if (tdb->transaction) {
469                 tdb1_transaction_cancel(tdb);
470         }
471
472         if (tdb->map_ptr) {
473                 if (tdb->flags & TDB1_INTERNAL)
474                         SAFE_FREE(tdb->map_ptr);
475                 else
476                         tdb1_munmap(tdb);
477         }
478         SAFE_FREE(tdb->name);
479         if (tdb->fd != -1) {
480                 ret = close(tdb->fd);
481                 tdb->fd = -1;
482         }
483         SAFE_FREE(tdb->lockrecs);
484
485         /* Remove from contexts list */
486         for (i = &tdb1s; *i; i = &(*i)->next) {
487                 if (*i == tdb) {
488                         *i = tdb->next;
489                         break;
490                 }
491         }
492
493         memset(tdb, 0, sizeof(*tdb));
494         SAFE_FREE(tdb);
495
496         return ret;
497 }
498
499 /* register a loging function */
500 _PUBLIC_ void tdb1_set_logging_function(struct tdb1_context *tdb,
501                                        const struct tdb1_logging_context *log_ctx)
502 {
503         tdb->log = *log_ctx;
504 }
505
506 _PUBLIC_ void *tdb1_get_logging_private(struct tdb1_context *tdb)
507 {
508         return tdb->log.log_private;
509 }
510
511 static int tdb1_reopen_internal(struct tdb1_context *tdb, bool active_lock)
512 {
513 #if !defined(LIBREPLACE_PREAD_NOT_REPLACED) || \
514         !defined(LIBREPLACE_PWRITE_NOT_REPLACED)
515         struct stat st;
516 #endif
517
518         if (tdb->flags & TDB1_INTERNAL) {
519                 return 0; /* Nothing to do. */
520         }
521
522         if (tdb1_have_extra_locks(tdb)) {
523                 TDB1_LOG((tdb, TDB1_DEBUG_ERROR, "tdb1_reopen: reopen not allowed with locks held\n"));
524                 goto fail;
525         }
526
527         if (tdb->transaction != 0) {
528                 TDB1_LOG((tdb, TDB1_DEBUG_ERROR, "tdb1_reopen: reopen not allowed inside a transaction\n"));
529                 goto fail;
530         }
531
532 /* If we have real pread & pwrite, we can skip reopen. */
533 #if !defined(LIBREPLACE_PREAD_NOT_REPLACED) || \
534         !defined(LIBREPLACE_PWRITE_NOT_REPLACED)
535         if (tdb1_munmap(tdb) != 0) {
536                 TDB1_LOG((tdb, TDB1_DEBUG_FATAL, "tdb1_reopen: munmap failed (%s)\n", strerror(errno)));
537                 goto fail;
538         }
539         if (close(tdb->fd) != 0)
540                 TDB1_LOG((tdb, TDB1_DEBUG_FATAL, "tdb1_reopen: WARNING closing tdb->fd failed!\n"));
541         tdb->fd = open(tdb->name, tdb->open_flags & ~(O_CREAT|O_TRUNC), 0);
542         if (tdb->fd == -1) {
543                 TDB1_LOG((tdb, TDB1_DEBUG_FATAL, "tdb1_reopen: open failed (%s)\n", strerror(errno)));
544                 goto fail;
545         }
546         if (fstat(tdb->fd, &st) != 0) {
547                 TDB1_LOG((tdb, TDB1_DEBUG_FATAL, "tdb1_reopen: fstat failed (%s)\n", strerror(errno)));
548                 goto fail;
549         }
550         if (st.st_ino != tdb->inode || st.st_dev != tdb->device) {
551                 TDB1_LOG((tdb, TDB1_DEBUG_FATAL, "tdb1_reopen: file dev/inode has changed!\n"));
552                 goto fail;
553         }
554         tdb1_mmap(tdb);
555 #endif /* fake pread or pwrite */
556
557         /* We may still think we hold the active lock. */
558         tdb->num_lockrecs = 0;
559         SAFE_FREE(tdb->lockrecs);
560
561         if (active_lock && tdb1_nest_lock(tdb, TDB1_ACTIVE_LOCK, F_RDLCK, TDB1_LOCK_WAIT) == -1) {
562                 TDB1_LOG((tdb, TDB1_DEBUG_FATAL, "tdb1_reopen: failed to obtain active lock\n"));
563                 goto fail;
564         }
565
566         return 0;
567
568 fail:
569         tdb1_close(tdb);
570         return -1;
571 }
572
573 /* reopen a tdb - this can be used after a fork to ensure that we have an independent
574    seek pointer from our parent and to re-establish locks */
575 _PUBLIC_ int tdb1_reopen(struct tdb1_context *tdb)
576 {
577         return tdb1_reopen_internal(tdb, tdb->flags & TDB1_CLEAR_IF_FIRST);
578 }
579
580 /* reopen all tdb's */
581 _PUBLIC_ int tdb1_reopen_all(int parent_longlived)
582 {
583         struct tdb1_context *tdb;
584
585         for (tdb=tdb1s; tdb; tdb = tdb->next) {
586                 bool active_lock = (tdb->flags & TDB1_CLEAR_IF_FIRST);
587
588                 /*
589                  * If the parent is longlived (ie. a
590                  * parent daemon architecture), we know
591                  * it will keep it's active lock on a
592                  * tdb opened with CLEAR_IF_FIRST. Thus
593                  * for child processes we don't have to
594                  * add an active lock. This is essential
595                  * to improve performance on systems that
596                  * keep POSIX locks as a non-scalable data
597                  * structure in the kernel.
598                  */
599                 if (parent_longlived) {
600                         /* Ensure no clear-if-first. */
601                         active_lock = false;
602                 }
603
604                 if (tdb1_reopen_internal(tdb, active_lock) != 0)
605                         return -1;
606         }
607
608         return 0;
609 }