Revert "dbwrap: dbwrap_fetch_locked_timeout()."
authorVolker Lendecke <vl@samba.org>
Tue, 4 Jun 2013 10:29:32 +0000 (12:29 +0200)
committerVolker Lendecke <vl@samba.org>
Thu, 6 Jun 2013 12:26:26 +0000 (14:26 +0200)
This reverts commit f6eb187fdab6b8088bb065e418fe604c4eba7751.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Rusty Russell <rusty@rustcorp.com.au>
Autobuild-User(master): Volker Lendecke <vl@samba.org>
Autobuild-Date(master): Thu Jun  6 14:26:26 CEST 2013 on sn-devel-104

lib/dbwrap/dbwrap.c
lib/dbwrap/dbwrap.h
lib/dbwrap/dbwrap_ntdb.c
lib/dbwrap/dbwrap_private.h
lib/dbwrap/dbwrap_tdb.c

index f03514dc3548d4455f661cfee5608a26bf70bebf..44e20bce5f48d5b40df895c10c1acea3ba4f05e6 100644 (file)
@@ -256,33 +256,6 @@ struct db_record *dbwrap_try_fetch_locked(struct db_context *db,
                ? db->try_fetch_locked : db->fetch_locked);
 }
 
-struct db_record *dbwrap_fetch_locked_timeout(struct db_context *db,
-                                             TALLOC_CTX *mem_ctx,
-                                             TDB_DATA key,
-                                             unsigned int timeout)
-{
-       struct db_record *rec;
-       struct dbwrap_lock_order_state *lock_order;
-       TALLOC_CTX *frame = talloc_stackframe();
-
-       lock_order = dbwrap_check_lock_order(db, frame);
-       if (lock_order == NULL) {
-               TALLOC_FREE(frame);
-               return NULL;
-       }
-       rec = db->fetch_locked_timeout
-               ? db->fetch_locked_timeout(db, mem_ctx, key, timeout)
-               : db->fetch_locked(db, mem_ctx, key);
-       if (rec == NULL) {
-               TALLOC_FREE(frame);
-               return NULL;
-       }
-       (void)talloc_steal(rec, lock_order);
-       rec->db = db;
-       TALLOC_FREE(frame);
-       return rec;
-}
-
 struct db_context *dbwrap_record_get_db(struct db_record *rec)
 {
        return rec->db;
index e394296a9bccbcabbc5aed06f8c82e1f2b990c04..8bf3286f70a6a8bd7aba28dfda5fdc702b98342b 100644 (file)
@@ -44,11 +44,6 @@ struct db_record *dbwrap_fetch_locked(struct db_context *db,
 struct db_record *dbwrap_try_fetch_locked(struct db_context *db,
                                          TALLOC_CTX *mem_ctx,
                                          TDB_DATA key);
-struct db_record *dbwrap_fetch_locked_timeout(struct db_context *db,
-                                             TALLOC_CTX *mem_ctx,
-                                             TDB_DATA key,
-                                             unsigned int timeout);
-
 struct db_context *dbwrap_record_get_db(struct db_record *rec);
 void dbwrap_set_stored_callback(
        struct db_context *db,
index 658c48734106b5e2da6f888e3b48f8a00b02ee51..48fe39e05864a79e7395b2f942fa8183d0541245 100644 (file)
@@ -269,113 +269,6 @@ static struct db_record *db_ntdb_try_fetch_locked(
        return db_ntdb_fetch_locked_internal(db, mem_ctx, key);
 }
 
-static struct flock flock_struct;
-
-/* Return a value which is none of v1, v2 or v3. */
-static inline short int invalid_value(short int v1, short int v2, short int v3)
-{
-       short int try = (v1+v2+v3)^((v1+v2+v3) << 16);
-       while (try == v1 || try == v2 || try == v3)
-               try++;
-       return try;
-}
-
-/* We invalidate in as many ways as we can, so the OS rejects it */
-static void invalidate_flock_struct(int signum)
-{
-       flock_struct.l_type = invalid_value(F_RDLCK, F_WRLCK, F_UNLCK);
-       flock_struct.l_whence = invalid_value(SEEK_SET, SEEK_CUR, SEEK_END);
-       flock_struct.l_start = -1;
-       /* A large negative. */
-       flock_struct.l_len = (((off_t)1 << (sizeof(off_t)*CHAR_BIT - 1)) + 1);
-}
-
-static int timeout_lock(int fd, int rw, off_t off, off_t len, bool waitflag,
-                       void *_timeout)
-{
-       int ret, saved_errno;
-       unsigned int timeout = *(unsigned int *)_timeout;
-
-       flock_struct.l_type = rw;
-       flock_struct.l_whence = SEEK_SET;
-       flock_struct.l_start = off;
-       flock_struct.l_len = len;
-
-       CatchSignal(SIGALRM, invalidate_flock_struct);
-       alarm(timeout);
-
-       for (;;) {
-               if (waitflag)
-                       ret = fcntl(fd, F_SETLKW, &flock_struct);
-               else
-                       ret = fcntl(fd, F_SETLK, &flock_struct);
-
-               if (ret == 0)
-                       break;
-
-               /* Not signalled?  Something else went wrong. */
-               if (flock_struct.l_len == len) {
-                       if (errno == EAGAIN || errno == EINTR)
-                               continue;
-                       saved_errno = errno;
-                       break;
-               } else {
-                       saved_errno = EINTR;
-                       break;
-               }
-       }
-
-       alarm(0);
-       if (ret != 0) {
-               errno = saved_errno;
-       }
-       return ret;
-}
-
-static int ntdb_chainlock_timeout(struct ntdb_context *ntdb,
-                                 NTDB_DATA key,
-                                 unsigned int timeout)
-{
-       union ntdb_attribute locking;
-       enum NTDB_ERROR ecode;
-
-       locking.base.attr = NTDB_ATTRIBUTE_FLOCK;
-       ecode = ntdb_get_attribute(ntdb, &locking);
-       if (ecode != NTDB_SUCCESS) {
-               return -1;
-       }
-
-       /* Replace locking function with our own. */
-       locking.flock.data = &timeout;
-       locking.flock.lock = timeout_lock;
-
-       ecode = ntdb_set_attribute(ntdb, &locking);
-       if (ecode != NTDB_SUCCESS) {
-               return -1;
-       }
-
-       ecode = ntdb_chainlock(ntdb, key);
-
-       ntdb_unset_attribute(ntdb, NTDB_ATTRIBUTE_FLOCK);
-       return ecode == NTDB_SUCCESS ? 0 : -1;
-}
-
-static struct db_record *db_ntdb_fetch_locked_timeout(
-       struct db_context *db, TALLOC_CTX *mem_ctx, TDB_DATA key,
-       unsigned int timeout)
-{
-       struct db_ntdb_ctx *ctx = talloc_get_type_abort(db->private_data,
-                                                      struct db_ntdb_ctx);
-
-       db_ntdb_log_key("Trying to lock", key);
-       if (ntdb_chainlock_timeout(ctx->ntdb, key, timeout) != 0) {
-               DEBUG(3, ("ntdb_chainlock_timeout failed\n"));
-               return NULL;
-       }
-       return db_ntdb_fetch_locked_internal(db, mem_ctx, key);
-}
-
-
 static int db_ntdb_exists(struct db_context *db, TDB_DATA key)
 {
        struct db_ntdb_ctx *ctx = talloc_get_type_abort(
@@ -663,7 +556,6 @@ struct db_context *db_open_ntdb(TALLOC_CTX *mem_ctx,
        db_ntdb->id.ino = st.st_ino;
 
        result->fetch_locked = db_ntdb_fetch_locked;
-       result->fetch_locked_timeout = db_ntdb_fetch_locked_timeout;
        result->try_fetch_locked = db_ntdb_try_fetch_locked;
        result->traverse = db_ntdb_traverse;
        result->traverse_read = db_ntdb_traverse_read;
index d49a568cd0ecfbfd8760027c1216daa0236e9ca5..da904f00e49bf6958d55ef310aefc7bd3fd21063 100644 (file)
@@ -38,10 +38,6 @@ struct db_context {
        struct db_record *(*try_fetch_locked)(struct db_context *db,
                                              TALLOC_CTX *mem_ctx,
                                              TDB_DATA key);
-       struct db_record *(*fetch_locked_timeout)(struct db_context *db,
-                                                 TALLOC_CTX *mem_ctx,
-                                                 TDB_DATA key,
-                                                 unsigned int timeout);
        int (*traverse)(struct db_context *db,
                        int (*f)(struct db_record *rec,
                                 void *private_data),
index b62dcdf418343798096a8a858bec6b3082faf409..3f21192233a3a50b2039e4e10215271498dc5384 100644 (file)
@@ -159,21 +159,6 @@ static struct db_record *db_tdb_fetch_locked(
        return db_tdb_fetch_locked_internal(db, mem_ctx, key);
 }
 
-static struct db_record *db_tdb_fetch_locked_timeout(
-       struct db_context *db, TALLOC_CTX *mem_ctx, TDB_DATA key,
-       unsigned int timeout)
-{
-       struct db_tdb_ctx *ctx = talloc_get_type_abort(db->private_data,
-                                                      struct db_tdb_ctx);
-
-       db_tdb_log_key("Locking with timeout ", key);
-       if (tdb_chainlock_with_timeout(ctx->wtdb->tdb, key, timeout) != 0) {
-               DEBUG(3, ("tdb_chainlock_with_timeout failed\n"));
-               return NULL;
-       }
-       return db_tdb_fetch_locked_internal(db, mem_ctx, key);
-}
-
 static struct db_record *db_tdb_try_fetch_locked(
        struct db_context *db, TALLOC_CTX *mem_ctx, TDB_DATA key)
 {
@@ -458,7 +443,6 @@ struct db_context *db_open_tdb(TALLOC_CTX *mem_ctx,
        db_tdb->id.ino = st.st_ino;
 
        result->fetch_locked = db_tdb_fetch_locked;
-       result->fetch_locked_timeout = db_tdb_fetch_locked_timeout;
        result->try_fetch_locked = db_tdb_try_fetch_locked;
        result->traverse = db_tdb_traverse;
        result->traverse_read = db_tdb_traverse_read;