public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* Start of db 3.0.x support for nss_db
@ 2000-01-05  1:09 Andreas Jaeger
  2000-01-05  6:08 ` Mark Kettenis
  0 siblings, 1 reply; 6+ messages in thread
From: Andreas Jaeger @ 2000-01-05  1:09 UTC (permalink / raw)
  To: GNU libc hacker

I'm adding a first patch for db30 support.  I also need to update
makedb.c but like to hear your comments before I continue.

Andreas

2000-01-05  Andreas Jaeger  <aj@suse.de>

	Add support for Berkeley db 3.0.x:
	* nss/nss_db/db-open.c (libdb_version): Add db30.
	(libdb_db_create): New variable.
	(load_db): Support db 3.0.x.
	(unload_db): Clear libdb_db_create.
	(internal_setent): Support db 3.0.x.

	* nss/nss_db/dummy-db.h (struct db30): New.
	(struct dbc30): New.
	Added DB30* flags.

============================================================
Index: nss/nss_db/dummy-db.h
--- nss/nss_db/dummy-db.h	2000/01/04 17:48:37	1.3
+++ nss/nss_db/dummy-db.h	2000/01/05 09:06:42
@@ -173,3 +173,130 @@
 #define DB27_FIRST		7
 #define DB27_NEXT		15
 #define DB27_NOOVERWRITE	17
+
+/* Versions for 3.0, incompatible with version 2.x.  */
+struct db30
+{
+  size_t pgsize;
+  void (*db_feedback) (void *, int, int);
+  void *(*db_malloc) (size_t);
+  void *(*db_realloc) (void *, size_t);
+  int (*dup_compare) (const DBT *, const DBT *);
+  void *dbenv;
+  enum { dummy30 } type;
+  void *mpf;
+  void	*mutexp;
+  u_int8_t fileid[20];
+  int32_t log_fileid;
+  void *open_txn;
+  void *saved_open_fhp;
+  struct
+  {
+    void *tqh_first;
+    void **tqh_last;
+  } free_queue;
+  struct
+  {
+    void *tqh_first;
+    void **tqh_last;
+  } active_queue;
+  void	*bt_internal;
+  void	*cj_internal;
+  void	*h_internal;
+  void	*q_internal;
+  void	*xa_internal;
+  /* Functions.  */
+  int  (*close) (void *, uint32_t);
+  int  (*cursor) (void *, void *, void **, uint32_t);
+  int  (*del) (void *, void *, DBT *, uint32_t);
+  void (*err) (void *, int, const char *, ...);
+  void (*errx) (void *, const char *, ...);
+  int  (*fd) (void *, int *);
+  int  (*get) (void *, void *, DBT *, DBT *, uint32_t);
+  int  (*get_byteswapped) (void *);
+  int (*get_type) (void *);
+  int  (*join) (void *, void **, void **, uint32_t);
+  int  (*open) (void *,	const char *, const char *, int, uint32_t, int);
+  int  (*put) (void *, void *, DBT *, DBT *, uint32_t);
+  int  (*remove) (void *, const char *, const char *, uint32_t);
+  int  (*set_cachesize) (void *, uint32_t, uint32_t, int);
+  int  (*set_dup_compare) (void *, int (*)(const DBT *, const DBT *));
+  void (*set_errcall) (void *, void (*)(const char *, char *));
+  void (*set_errfile) (void *, void *);
+  void (*set_errpfx) (void *, const char *);
+  void (*set_feedback) (void *, void (*)(void *, int, int));
+  int  (*set_flags) (void *, uint32_t);
+  int  (*set_lorder) (void *, int);
+  int  (*set_malloc) (void *, void *(*)(size_t));
+  int  (*set_pagesize) (void *, uint32_t);
+  void (*set_paniccall) (void *, void (*)(void *, int));
+  int  (*set_realloc) (void *, void *(*)(void *, size_t));
+  int  (*stat) (void *, void *, void *(*)(size_t), uint32_t);
+  int  (*sync) (void *, uint32_t);
+  int  (*upgrade) (void *, const char *, uint32_t);
+  
+  int  (*set_bt_compare) (void *, int (*)(const DBT *, const DBT *));
+  int  (*set_bt_maxkey) (void *, uint32_t);
+  int  (*set_bt_minkey) (void *, uint32_t);
+  int  (*set_bt_prefix) (void *, size_t (*)(const DBT *, const DBT *));
+  
+  int  (*set_h_ffactor) (void *, uint32_t);
+  int  (*set_h_hash) (void *, uint32_t (*)(const void *, uint32_t));
+  int  (*set_h_nelem) (void *, uint32_t);
+  
+  int  (*set_re_delim) (void *, int);
+  int  (*set_re_len) (void *, uint32_t);
+  int  (*set_re_pad) (void *, int);
+  int  (*set_re_source) (void *, const char *);
+
+  uint32_t am_ok;
+  uint32_t flags;
+};
+
+
+struct dbc30
+{
+  void *dbp;
+  void *txn;
+  struct
+  {
+    void *tqe_next;
+    void **tqe_prev;
+  } links;
+  uint32_t lid;			/* Default process' locker id. */
+  uint32_t locker;		/* Locker for this operation. */
+  DBT lock_dbt;		/* DBT referencing lock. */
+  struct
+  {
+    uint32_t pgno;
+    uint8_t fileid[20];
+  } lock;
+  struct
+  {
+    size_t off;
+    uint32_t ndx;
+    uint32_t gen;
+  } mylock;
+  DBT rkey;
+  DBT rdata;
+  int (*c_close) (void *);
+  int (*c_del) (void *, uint32_t);
+  int (*c_dup) (void *, void **, uint32_t);
+  int (*c_get) (void *, DBT *, DBT *, uint32_t);
+  int (*c_put) (void *, DBT *, DBT *, uint32_t);
+  int (*c_am_close) (void *);
+  int (*c_am_destroy) (void *);
+  void *internal;
+  uint32_t flags;
+};
+
+/* Flags which changed.  */
+#define DB30_TRUNCATE	0x020000
+
+/* Access methods.  */
+#define DB30_FIRST		9
+#define DB30_NEXT		17
+#define DB30_NOOVERWRITE	20
+
+/* Permission flags are changed.  */
+#define DB30_RDONLY	0x000010
============================================================
Index: nss/nss_db/db-open.c
--- nss/nss_db/db-open.c	2000/01/04 17:48:26	1.3
+++ nss/nss_db/db-open.c	2000/01/05 09:06:43
@@ -41,30 +41,42 @@
 enum {
   nodb,
   db24,
-  db27
+  db27,
+  db30
 } libdb_version;
 static int (*libdb_db_open) (const char *, int,
 			     uint32_t, int, void *, void *, void **);
 
+static int (*libdb_db_create) (void *, void *, uint32_t);
+
 /* Locks the static variables in this file.  */
 __libc_lock_define_initialized (static, lock)
 
 /* Dynamically load the database library.
-   We try libdb2.so.3, maybe others in the future.  */
+   We try currently:
+   - libdb.so.3: the name used by glibc 2.1
+   - libdb-3.0.so: the name used by db-3.0.x
+   and maybe others in the future.  */
 static int
 load_db (void)
 {
-  static const char *libnames[] = { "libdb.so.3" };
+  static const char *libnames[] = { "libdb.so.3", "libdb-3.0.so" };
   int x;
-
-  for(x = 0; x < sizeof (libnames) / sizeof (libnames[0]); ++x)
+  
+  for (x = 0; x < sizeof (libnames) / sizeof (libnames[0]); ++x)
     {
       libdb_handle = dlopen (libnames[x], RTLD_LAZY);
       if (libdb_handle == NULL)
 	continue;
 
-      libdb_db_open = dlsym (libdb_handle, "db_open");
-      if (libdb_db_open != NULL)
+      /* db 3.0 has db_create instead of db_open.  */
+      libdb_db_create = dlsym (libdb_handle, "db_create");
+
+      if (libdb_db_create == NULL)
+	/* db 2.x uses db_open.  */
+	libdb_db_open = dlsym (libdb_handle, "db_open");
+      
+      if (libdb_db_open != NULL || libdb_db_create != NULL)
 	{
 	  /* Alright, we got a library.  Now find out which version it is.  */
 	  const char *(*db_version) (int *, int *, int *);
@@ -76,19 +88,34 @@
 	      int major, minor, subminor;
 
 	      DL_CALL_FCT (db_version, (&major, &minor, &subminor));
-	      if (major == 2)
+	      switch (major)
 		{
-		  /* We currently cannot handle other versions than the
-		     2.x series.  */
-		  if (minor < 6 || (minor == 6 && subminor < 4))
-		    libdb_version = db24;
-		  else
-		    libdb_version = db27;
+		case 2:
+		  /* Sanity check: Do we have db_open?  */
+		  if (libdb_db_open != NULL)
+		    {
+		      if (minor < 6 || (minor == 6 && subminor < 4))
+			libdb_version = db24;
+		      else
+			libdb_version = db27;
+		    }
+		  break;
+		case 3:
+		  /* Sanity check: Do we have db_create?  */
+		  if (libdb_db_create != NULL)
+		    libdb_version = db30;
+		  break;
+		default:
+		  break;
 		}
 	    }
 
 	  if (libdb_version != nodb)
 	    return 0;
+
+	  /* Clear variables.  */
+	  libdb_db_open = NULL;
+	  libdb_db_create = NULL;
 	}
 
       dlclose (libdb_handle);
@@ -106,6 +133,7 @@
   if (libdb_handle != NULL)
     {
       libdb_db_open = NULL;
+      libdb_db_create = NULL;
       libdb_version = nodb;
       dlclose (libdb_handle);
     }
@@ -124,7 +152,7 @@
 
   if (*dbp == NULL)
     {
-      if (libdb_db_open == NULL)
+      if (libdb_db_open == NULL && libdb_db_create == NULL)
 	{
 	  __libc_lock_lock (lock);
 
@@ -135,17 +163,39 @@
 	  if (err != 0)
 	    return NSS_STATUS_UNAVAIL;
 	}
-
-      /* Open the database.  Fortunately this interface seems to be the
-	 same for all supported versions.  */
-      err = DL_CALL_FCT (libdb_db_open,
-			 (file, DB_BTREE, DB_RDONLY, 0, NULL, NULL, &db));
 
-      if (err != 0)
+      /* Open the database.  */
+      switch (libdb_version)
 	{
-	  __set_errno (err);
-	  *dbp = NULL;
-	  return err == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
+	case db24:
+	case db27:
+	  err = DL_CALL_FCT (libdb_db_open,
+			     (file, DB_BTREE, DB_RDONLY, 0, NULL, NULL, &db));
+	  if (err != 0)
+	    {
+	      __set_errno (err);
+	      return err == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
+	    }
+	  break;
+	case db30:
+	  err = DL_CALL_FCT (libdb_db_create, (&db, NULL, 0));
+	  if (err != 0)
+	    {
+	      __set_errno (err);
+	      return err == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
+	    }
+	  err = ((struct db30 *) db)->open (db, file, NULL, DB_BTREE,
+					    DB30_RDONLY, 0);
+	  if (err != 0)
+	    {
+	      __set_errno (err);
+	      /* Free all resources.  */
+	      ((struct db30 *) db)->close (db, 0);
+	      return err == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
+	    }
+	  break;
+	default:
+	  abort ();
 	}
       
       /* Construct the object we pass up.  */
@@ -176,6 +226,15 @@
 	  (*dbp)->get =
 	    (int (*) (void *, void *, void *, void *, uint32_t))
 	    ((struct db27 *) db)->get;
+	  break;
+	case db30:
+	  (*dbp)->close =
+	    (int (*) (void *, uint32_t)) ((struct db30 *) db)->close;
+	  (*dbp)->fd =
+	    (int (*) (void *, int *)) ((struct db30 *) db)->fd;
+	  (*dbp)->get =
+	    (int (*) (void *, void *, void *, void *, uint32_t))
+	    ((struct db30 *) db)->get;
 	  break;
 	default:
 	  abort ();

-- 
 Andreas Jaeger
  SuSE Labs aj@suse.de
   private aj@arthur.rhein-neckar.de

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Start of db 3.0.x support for nss_db
  2000-01-05  1:09 Start of db 3.0.x support for nss_db Andreas Jaeger
@ 2000-01-05  6:08 ` Mark Kettenis
  2000-01-05  6:33   ` Andreas Jaeger
  2000-01-05  8:53   ` Ulrich Drepper
  0 siblings, 2 replies; 6+ messages in thread
From: Mark Kettenis @ 2000-01-05  6:08 UTC (permalink / raw)
  To: aj; +Cc: libc-hacker

   From: Andreas Jaeger <aj@suse.de>
   Date: 05 Jan 2000 10:07:56 +0100

   I'm adding a first patch for db30 support.  I also need to update
   makedb.c but like to hear your comments before I continue.

Unfortunately, the DB error return codes (DB_KEYEMPTY and DB_NOTFOUND)
were also changed in DB 3.X.

Fortunately, the release notes for 3.0.55 say:

   The Berkeley DB interfaces have been reworked in the 3.0.55 release
   for two reasons. The goals were as follows: to make the Berkeley DB
   structures opaque so future releases of Berkeley DB can be binary
   compatible with each other, ...

so the interfaces may stabilize, and adding support for DB 3.X seems
to be a good move!

However, I'm not sure whether having a fixed list of library names is
such a good idea.  The format of the databases on disk depens in the
DB version.  A hard-coded list means that if the DB library is
upgraded, the nss_db module might stop working.  This can be fixed by
regenerating the databases, but what if the someone uses a different
LD_LIBRARY_PATH from time to time, or worse, has applications with
different RPATH's?  I think we should allow the user to specify the
path of the DB library in a configuration file to make sure there will
be no nasty surprises.

Mark

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Start of db 3.0.x support for nss_db
  2000-01-05  6:08 ` Mark Kettenis
@ 2000-01-05  6:33   ` Andreas Jaeger
  2000-01-05  7:08     ` Mark Kettenis
  2000-01-05  8:53   ` Ulrich Drepper
  1 sibling, 1 reply; 6+ messages in thread
From: Andreas Jaeger @ 2000-01-05  6:33 UTC (permalink / raw)
  To: Mark Kettenis; +Cc: libc-hacker

>>>>> Mark Kettenis writes:

Mark>    From: Andreas Jaeger <aj@suse.de>
Mark>    Date: 05 Jan 2000 10:07:56 +0100

Mark>    I'm adding a first patch for db30 support.  I also need to update
Mark>    makedb.c but like to hear your comments before I continue.

Mark> Unfortunately, the DB error return codes (DB_KEYEMPTY and DB_NOTFOUND)
Mark> were also changed in DB 3.X.

I know :-( but nearly forgot it.  Thanks for reminding me.

Mark> Fortunately, the release notes for 3.0.55 say:

Mark>    The Berkeley DB interfaces have been reworked in the 3.0.55 release
Mark>    for two reasons. The goals were as follows: to make the Berkeley DB
Mark>    structures opaque so future releases of Berkeley DB can be binary
Mark>    compatible with each other, ...

Mark> so the interfaces may stabilize, and adding support for DB 3.X seems
Mark> to be a good move!

Mark> However, I'm not sure whether having a fixed list of library names is
Mark> such a good idea.  The format of the databases on disk depens in the
Mark> DB version.  A hard-coded list means that if the DB library is
Mark> upgraded, the nss_db module might stop working.  This can be fixed by
Mark> regenerating the databases, but what if the someone uses a different
Mark> LD_LIBRARY_PATH from time to time, or worse, has applications with
Mark> different RPATH's?  I think we should allow the user to specify the
Mark> path of the DB library in a configuration file to make sure there will
Mark> be no nasty surprises.

I agree.  The question is: What's the name of the configuration file
and how should it be specified?  Can we add this to
/etc/nsswitch.conf?

Andreas
-- 
 Andreas Jaeger
  SuSE Labs aj@suse.de
   private aj@arthur.rhein-neckar.de

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Start of db 3.0.x support for nss_db
  2000-01-05  6:33   ` Andreas Jaeger
@ 2000-01-05  7:08     ` Mark Kettenis
  2000-01-05  7:37       ` Andreas Jaeger
  0 siblings, 1 reply; 6+ messages in thread
From: Mark Kettenis @ 2000-01-05  7:08 UTC (permalink / raw)
  To: aj; +Cc: libc-hacker

   From: Andreas Jaeger <aj@suse.de>
   Date: 05 Jan 2000 15:30:38 +0100

   I agree.  The question is: What's the name of the configuration file
   and how should it be specified?  Can we add this to
   /etc/nsswitch.conf?

It's probably better to use a different file.  We need a separate
parser in the nss_db module since there is no way to pass the
information from libc to the nss modules.  If we store the info in
/etc/nsswitch.conf we'd also make the parser in libc know about it,
and make sure it stays in sync with the parser in the nss_db module.
/etc/db.conf would be an obvious choice, but it may already be in use
somewhere.

Mark

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Start of db 3.0.x support for nss_db
  2000-01-05  7:08     ` Mark Kettenis
@ 2000-01-05  7:37       ` Andreas Jaeger
  0 siblings, 0 replies; 6+ messages in thread
From: Andreas Jaeger @ 2000-01-05  7:37 UTC (permalink / raw)
  To: Mark Kettenis; +Cc: libc-hacker

>>>>> Mark Kettenis writes:

 >    From: Andreas Jaeger <aj@suse.de>
 >    Date: 05 Jan 2000 15:30:38 +0100

 >    I agree.  The question is: What's the name of the configuration file
 >    and how should it be specified?  Can we add this to
 >    /etc/nsswitch.conf?

 > It's probably better to use a different file.  We need a separate
 > parser in the nss_db module since there is no way to pass the
 > information from libc to the nss modules.  If we store the info in
 > /etc/nsswitch.conf we'd also make the parser in libc know about it,
 > and make sure it stays in sync with the parser in the nss_db module.
 > /etc/db.conf would be an obvious choice, but it may already be in use
 > somewhere.
/etc/nss_db.conf

What do we need to write in it?  Just the name (or complete path) of
the library which can be passed directly to dbopen?

Since this information is to be used by makedb and by the nss_db
module, it might be good to rearrange files a bit.

Mark, if you like to do this, just tell me.  I would appreciate if
somebody else would develop this ;-).

Andreas
-- 
 Andreas Jaeger
  SuSE Labs aj@suse.de
   private aj@arthur.rhein-neckar.de

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Start of db 3.0.x support for nss_db
  2000-01-05  6:08 ` Mark Kettenis
  2000-01-05  6:33   ` Andreas Jaeger
@ 2000-01-05  8:53   ` Ulrich Drepper
  1 sibling, 0 replies; 6+ messages in thread
From: Ulrich Drepper @ 2000-01-05  8:53 UTC (permalink / raw)
  To: Mark Kettenis; +Cc: aj, libc-hacker

Mark Kettenis <kettenis@wins.uva.nl> writes:

> However, I'm not sure whether having a fixed list of library names is
> such a good idea.  The format of the databases on disk depens in the
> DB version.

I don't consider this a problem at all.  The .db files can be very
easily regenerated.  Just run the makefile.  Therefore those who are
updating the libdb can regenerate the .db files.  And while they have
not done it the system still runs sine it falls back on the normal
files.

-- 
---------------.      drepper at gnu.org  ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Cygnus Solutions `--' drepper at cygnus.com   `------------------------

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2000-01-05  8:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-01-05  1:09 Start of db 3.0.x support for nss_db Andreas Jaeger
2000-01-05  6:08 ` Mark Kettenis
2000-01-05  6:33   ` Andreas Jaeger
2000-01-05  7:08     ` Mark Kettenis
2000-01-05  7:37       ` Andreas Jaeger
2000-01-05  8:53   ` Ulrich Drepper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).