X-Git-Url: http://git.samba.org/?p=samba.git;a=blobdiff_plain;f=lib%2Ftdb%2Fcommon%2Fopen.c;h=2e6a707497b85003159d7a02a7fa278859e64df8;hp=e58c8ca7ff3c5b309a164199d5dc457b34686054;hb=4fc9f9c3f943cdeb27e37f0ee068cdd0da7cb00c;hpb=e17df483fbedb81aededdef5fbb6ae1d034bc2dd diff --git a/lib/tdb/common/open.c b/lib/tdb/common/open.c index e58c8ca7ff3..2e6a707497b 100644 --- a/lib/tdb/common/open.c +++ b/lib/tdb/common/open.c @@ -405,11 +405,12 @@ void *tdb_get_logging_private(struct tdb_context *tdb) return tdb->log.log_private; } -/* reopen a tdb - this can be used after a fork to ensure that we have an independent - seek pointer from our parent and to re-establish locks */ -int tdb_reopen(struct tdb_context *tdb) +static int tdb_reopen_internal(struct tdb_context *tdb, bool active_lock) { +#if !defined(LIBREPLACE_PREAD_NOT_REPLACED) || \ + !defined(LIBREPLACE_PWRITE_NOT_REPLACED) struct stat st; +#endif if (tdb->flags & TDB_INTERNAL) { return 0; /* Nothing to do. */ @@ -425,6 +426,9 @@ int tdb_reopen(struct tdb_context *tdb) goto fail; } +/* If we have real pread & pwrite, we can skip reopen. */ +#if !defined(LIBREPLACE_PREAD_NOT_REPLACED) || \ + !defined(LIBREPLACE_PWRITE_NOT_REPLACED) if (tdb_munmap(tdb) != 0) { TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_reopen: munmap failed (%s)\n", strerror(errno))); goto fail; @@ -436,11 +440,6 @@ int tdb_reopen(struct tdb_context *tdb) TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_reopen: open failed (%s)\n", strerror(errno))); goto fail; } - if ((tdb->flags & TDB_CLEAR_IF_FIRST) && - (tdb->methods->tdb_brlock(tdb, ACTIVE_LOCK, F_RDLCK, F_SETLKW, 0, 1) == -1)) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_reopen: failed to obtain active lock\n")); - goto fail; - } if (fstat(tdb->fd, &st) != 0) { TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_reopen: fstat failed (%s)\n", strerror(errno))); goto fail; @@ -450,6 +449,13 @@ int tdb_reopen(struct tdb_context *tdb) goto fail; } tdb_mmap(tdb); +#endif /* fake pread or pwrite */ + + if (active_lock && + (tdb->methods->tdb_brlock(tdb, ACTIVE_LOCK, F_RDLCK, F_SETLKW, 0, 1) == -1)) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_reopen: failed to obtain active lock\n")); + goto fail; + } return 0; @@ -458,16 +464,21 @@ fail: return -1; } +/* reopen a tdb - this can be used after a fork to ensure that we have an independent + seek pointer from our parent and to re-establish locks */ +int tdb_reopen(struct tdb_context *tdb) +{ + return tdb_reopen_internal(tdb, tdb->flags & TDB_CLEAR_IF_FIRST); +} + /* reopen all tdb's */ int tdb_reopen_all(int parent_longlived) { -#if defined(LIBREPLACE_PREAD_NOT_REPLACED) && \ - defined(LIBREPLACE_PWRITE_NOT_REPLACED) - return 0; -#else struct tdb_context *tdb; for (tdb=tdbs; tdb; tdb = tdb->next) { + bool active_lock = (tdb->flags & TDB_CLEAR_IF_FIRST); + /* * If the parent is longlived (ie. a * parent daemon architecture), we know @@ -481,13 +492,12 @@ int tdb_reopen_all(int parent_longlived) */ if (parent_longlived) { /* Ensure no clear-if-first. */ - tdb->flags &= ~TDB_CLEAR_IF_FIRST; + active_lock = false; } - if (tdb_reopen(tdb) != 0) + if (tdb_reopen_internal(tdb, active_lock) != 0) return -1; } -#endif return 0; }