dbwrap_fetch_locked_timeout?

Volker Lendecke Volker.Lendecke at SerNet.DE
Tue Jun 4 04:53:20 MDT 2013


Hi, Rusty!

With f6eb187fdab you added $SUBJECT. Right now I don't see a
user of this API. The attached patch removes the code. Okay?

If such a feature is required, I would rather implement a
fetch_locked_send/recv pair. You can do the timeout variant
with tevent_req_send_endtime and a nested event context if
required.

With best regards,

Volker Lendecke

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
-------------- next part --------------
From e00289c1993924959f8b7a4b243c9513c1fc286b Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 4 Jun 2013 12:29:32 +0200
Subject: [PATCH] Revert "dbwrap: dbwrap_fetch_locked_timeout()."

This reverts commit f6eb187fdab6b8088bb065e418fe604c4eba7751.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 lib/dbwrap/dbwrap.c         |   27 -----------
 lib/dbwrap/dbwrap.h         |    5 --
 lib/dbwrap/dbwrap_ntdb.c    |  108 -------------------------------------------
 lib/dbwrap/dbwrap_private.h |    4 --
 lib/dbwrap/dbwrap_tdb.c     |   16 -------
 5 files changed, 160 deletions(-)

diff --git a/lib/dbwrap/dbwrap.c b/lib/dbwrap/dbwrap.c
index f03514d..44e20bc 100644
--- a/lib/dbwrap/dbwrap.c
+++ b/lib/dbwrap/dbwrap.c
@@ -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;
diff --git a/lib/dbwrap/dbwrap.h b/lib/dbwrap/dbwrap.h
index e394296..8bf3286 100644
--- a/lib/dbwrap/dbwrap.h
+++ b/lib/dbwrap/dbwrap.h
@@ -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,
diff --git a/lib/dbwrap/dbwrap_ntdb.c b/lib/dbwrap/dbwrap_ntdb.c
index 658c487..48fe39e 100644
--- a/lib/dbwrap/dbwrap_ntdb.c
+++ b/lib/dbwrap/dbwrap_ntdb.c
@@ -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;
diff --git a/lib/dbwrap/dbwrap_private.h b/lib/dbwrap/dbwrap_private.h
index d49a568..da904f0 100644
--- a/lib/dbwrap/dbwrap_private.h
+++ b/lib/dbwrap/dbwrap_private.h
@@ -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),
diff --git a/lib/dbwrap/dbwrap_tdb.c b/lib/dbwrap/dbwrap_tdb.c
index b62dcdf..3f21192 100644
--- a/lib/dbwrap/dbwrap_tdb.c
+++ b/lib/dbwrap/dbwrap_tdb.c
@@ -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;
-- 
1.7.9.5



More information about the samba-technical mailing list