]> arthur.barton.de Git - netatalk.git/commitdiff
Change the dbd CNID backend to store dev/ino in 8 byte network order.
authorlenneis <lenneis>
Tue, 25 Nov 2003 00:41:30 +0000 (00:41 +0000)
committerlenneis <lenneis>
Tue, 25 Nov 2003 00:41:30 +0000 (00:41 +0000)
Added a new dbd backend function dbd_getstamp to handle cnid_getstamp requests.

12 files changed:
etc/cnid_dbd/Makefile.am
etc/cnid_dbd/README
etc/cnid_dbd/dbd.h
etc/cnid_dbd/dbd_add.c
etc/cnid_dbd/dbd_getstamp.c [new file with mode: 0644]
etc/cnid_dbd/dbd_lookup.c
etc/cnid_dbd/dbd_resolve.c
etc/cnid_dbd/dbd_update.c
etc/cnid_dbd/main.c
etc/cnid_dbd/pack.c
include/atalk/cnid_dbd_private.h
libatalk/cnid/dbd/cnid_dbd.c

index d376bca849371e036733d76d50be627d4deb8a7b..432d643b5f887061a68e215ac77126da2f73b38e 100644 (file)
@@ -8,7 +8,7 @@ endif
 
 cnid_dbd_SOURCES = dbif.c pack.c comm.c usockfd.c db_param.c main.c \
                    dbd_add.c dbd_get.c dbd_resolve.c dbd_lookup.c \
-                   dbd_update.c dbd_delete.c
+                   dbd_update.c dbd_delete.c dbd_getstamp.c
 
 cnid_dbd_LDADD = $(top_builddir)/libatalk/libatalk.la
 
index 106a08b9a5bc87ba39a107bf8a960521c9e519b0..f34d4a800f2dd19d171726edf7f6405593fd3a60 100644 (file)
@@ -65,17 +65,17 @@ In order to turn on cnid_dbd backend support for a given volume, set
 the option -cnidscheme:dbd in your AppleVolumes.default file or
 equivalent. The default for this parameter is -cnidscheme:cdb.
 
-There are two executeables that will be built in etc/cnid_dbd and 
+There are two executeables that will be built in etc/cnid_dbd and
 installed into the systems binaries directories of netatalk
-(e.g. /usr/local/netatalk/sbin or whatever you specify with 
---sbindir to configure): cnid_metad and cnid_dbd. cnid_metad should
-run all the time with root permissions. It will be notified when an
-instance of afpd starts up and will in turn make sure that a cnid_dbd
-daemon is started for the volume that afpd wishes to access. The
-daemon runs forever and services any other instances of afpd that
-access the volume. You can safely kill it with SIGTERM, it will be
-restarted automatically by cnid_metad as soon as the volume is
-accessed again. 
+(e.g. /usr/local/netatalk/sbin or whatever you specify with --sbindir
+to configure): cnid_metad and cnid_dbd. cnid_metad should run all the
+time with root permissions. It will be notified when an instance of
+afpd starts up and will in turn make sure that a cnid_dbd daemon is
+started for the volume that afpd wishes to access. The daemon runs as
+long as necessary (see the idle_timeout option below) and services any
+other instances of afpd that access the volume. You can safely kill it
+with SIGTERM, it will be restarted automatically by cnid_metad as soon
+as the volume is accessed again.
 
 cnid_metad needs one command line argument, the name of the cnid_dbd
 executeable. You can either specify "cnid_dbd" if it is in the path
@@ -105,6 +105,7 @@ flush_frequency    100
 flush_interval     30
 usock_file         <databasedirectory>/usock
 fd_table_size      16
+idle_timeout       600
 
 
 "backlog" specifies the maximum number of connection requests that can
index 8e3669b876f126ec1a97cc2df31aca1a178fd07c..0ba68f9877543d6af9feca03fb385b18c19fc4e3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: dbd.h,v 1.1.4.1 2003-09-09 16:42:20 didg Exp $
+ * $Id: dbd.h,v 1.1.4.2 2003-11-25 00:41:31 lenneis Exp $
  *
  * Copyright (C) Joerg Lenneis 2003
  * All Rights Reserved.  See COPYRIGHT.
@@ -18,5 +18,6 @@ extern int      dbd_resolve  __P((struct cnid_dbd_rqst *, struct cnid_dbd_rply *
 extern int      dbd_lookup  __P((struct cnid_dbd_rqst *, struct cnid_dbd_rply *));
 extern int      dbd_update  __P((struct cnid_dbd_rqst *, struct cnid_dbd_rply *));
 extern int      dbd_delete  __P((struct cnid_dbd_rqst *, struct cnid_dbd_rply *));
+extern int      dbd_getstamp  __P((struct cnid_dbd_rqst *, struct cnid_dbd_rply *));
 
 #endif /* CNID_DBD_DBD_H */
index b9b99020c4f6522fd8657d210fe0188deabd365b..0dcb896b7bada5ede5629f45e7fe761f83e41957 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: dbd_add.c,v 1.1.4.2 2003-10-21 16:24:58 didg Exp $
+ * $Id: dbd_add.c,v 1.1.4.3 2003-11-25 00:41:31 lenneis Exp $
  *
  * Copyright (C) Joerg Lenneis 2003
  * All Rights Reserved.  See COPYRIGHT.
@@ -34,7 +34,6 @@
 #include "pack.h"
 #include "dbd.h"
 
-/* FIXME assume dev_t == ino_t == 8 */
 /*                         cnid   - dev        - inode     - type  - did  - name */
 #define ROOTINFO_DATA    "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0RootInfo"
 #define ROOTINFO_DATALEN (3*4 +2*8  +9)
@@ -66,6 +65,7 @@ static int add_cnid(struct cnid_dbd_rqst *rqst, struct cnid_dbd_rply *rply)
             rply->result = CNID_DBD_RES_ERR_DUPLCNID;
             break;
         case -1:
+           /* FIXME: Should that not be logged for case 1:? */
             LOG(log_error, logtype_cnid, "add_cnid: duplicate %x %s", rply->cnid
              , data.data + CNID_NAME_OFS);
             
diff --git a/etc/cnid_dbd/dbd_getstamp.c b/etc/cnid_dbd/dbd_getstamp.c
new file mode 100644 (file)
index 0000000..8b6d9d6
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * $Id: dbd_getstamp.c,v 1.1.2.1 2003-11-25 00:41:31 lenneis Exp $
+ *
+ * Copyright (C) Joerg Lenneis 2003
+ * All Rights Reserved.  See COPYRIGHT.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+#include <string.h>
+#include <atalk/logger.h>
+#include <errno.h>
+#include <netatalk/endian.h>
+#include <atalk/cnid_dbd_private.h>
+
+#include "dbif.h"
+#include "dbd.h"
+#include "pack.h"
+
+/* Return the unique stamp associated with this database */
+
+int dbd_getstamp(struct cnid_dbd_rqst *rqst, struct cnid_dbd_rply *rply)
+{
+    DBT key, data;
+    int rc;
+
+
+    memset(&key, 0, sizeof(key));
+    memset(&data, 0, sizeof(data));
+
+    rply->namelen = 0;
+
+    key.data = ROOTINFO_KEY;
+    key.size = ROOTINFO_KEYLEN;
+
+    if ((rc = dbif_get(DBIF_IDX_CNID, &key, &data, 0)) < 0) {
+        LOG(log_error, logtype_cnid, "dbd_getstamp: Error getting rootinfo record");
+        rply->result = CNID_DBD_RES_ERR_DB;
+        return -1;
+    }
+     
+    if (rc == 0) {
+       LOG(log_error, logtype_cnid, "dbd_getstamp: No rootinfo record found");
+        rply->result = CNID_DBD_RES_NOTFOUND;
+        return 1;
+    }
+    
+    rply->namelen = CNID_DEV_LEN;
+    rply->name = data.data + CNID_DEV_OFS;    
+    
+#ifdef DEBUG
+    LOG(log_info, logtype_cnid, "cnid_getstamp: Returning stamp");
+#endif
+    rply->result = CNID_DBD_RES_OK;
+    return 1;
+}
index 87b2e51f39005022787afd37785ebe35c09345f1..f54286b2a5fdd5e47e16d81185fc515a747220d8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: dbd_lookup.c,v 1.1.4.3 2003-10-30 10:03:19 bfernhomberg Exp $
+ * $Id: dbd_lookup.c,v 1.1.4.4 2003-11-25 00:41:31 lenneis Exp $
  *
  * Copyright (C) Joerg Lenneis 2003
  * All Rights Reserved.  See COPYRIGHT.
@@ -31,8 +31,8 @@ int dbd_lookup(struct cnid_dbd_rqst *rqst, struct cnid_dbd_rply *rply)
 {
     char *buf;
     DBT key, devdata, diddata;
-    dev_t  dev;
-    ino_t  ino;
+    char dev[CNID_DEV_LEN];
+    char ino[CNID_INO_LEN];
     int devino = 1, didname = 1; 
     int rc;
     cnid_t id_devino, id_didname;
@@ -49,8 +49,9 @@ int dbd_lookup(struct cnid_dbd_rqst *rqst, struct cnid_dbd_rply *rply)
     rply->cnid = 0;
     
     buf = pack_cnid_data(rqst); 
-    memcpy(&dev, buf + CNID_DEV_OFS, sizeof(dev));
-    memcpy(&ino, buf + CNID_INO_OFS, sizeof(ino));
+    memcpy(dev, buf + CNID_DEV_OFS, CNID_DEV_LEN);
+    /* FIXME: ino is not needed later on, remove? */
+    memcpy(ino, buf + CNID_INO_OFS, CNID_INO_LEN);
 
     /* Look for a CNID.  We have two options: dev/ino or did/name.  If we
        only get a match in one of them, that means a file has moved. */
@@ -72,6 +73,7 @@ int dbd_lookup(struct cnid_dbd_rqst *rqst, struct cnid_dbd_rply *rply)
         type_devino = ntohl(type_devino);
     }
     
+    /* FIXME: This second call to pack_cnid_data() is redundant, any reason it is here? */
     buf = pack_cnid_data(rqst); 
     key.data = buf +CNID_DID_OFS;
     key.size = CNID_DID_LEN + rqst->namelen + 1;
@@ -110,7 +112,7 @@ int dbd_lookup(struct cnid_dbd_rqst *rqst, struct cnid_dbd_rply *rply)
          * if it's the same dev or not the same type
          * just delete it
         */
-        if (!memcmp(&dev, (char *)diddata.data + CNID_DEV_OFS, sizeof(dev)) ||
+        if (!memcmp(dev, (char *)diddata.data + CNID_DEV_OFS, CNID_DEV_LEN) ||
                    type_didname != rqst->type) {
             if (dbd_delete(rqst, rply) < 0) {
                 return -1;
index 4a6b49718d5540675679f81b12f2819eea60b64f..cc8dad6906535e119f8503230edf47c67e9dd5dd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: dbd_resolve.c,v 1.1.4.3 2003-10-30 10:03:19 bfernhomberg Exp $
+ * $Id: dbd_resolve.c,v 1.1.4.4 2003-11-25 00:41:31 lenneis Exp $
  *
  * Copyright (C) Joerg Lenneis 2003
  * All Rights Reserved.  See COPYRIGHT.
@@ -44,13 +44,9 @@ int dbd_resolve(struct cnid_dbd_rqst *rqst, struct cnid_dbd_rply *rply)
         rply->result = CNID_DBD_RES_NOTFOUND;
         return 1;
     }
-    /* FIXME hack */
-    if (!rqst->cnid) {
-       memcpy(&rply->did, (char *) data.data + CNID_DEV_OFS, sizeof(cnid_t));
-    }
-    else {
-       memcpy(&rply->did, (char *) data.data + CNID_DID_OFS, sizeof(cnid_t));
-    }
+
+    memcpy(&rply->did, (char *) data.data + CNID_DID_OFS, sizeof(cnid_t));
+
     rply->namelen = data.size - CNID_NAME_OFS;
     rply->name = data.data + CNID_NAME_OFS;
 
index ac55749398ba04fed92c4043f416cad6ac11fa45..f5cd389309ca5f6faaafcba17f425e929953bbae 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: dbd_update.c,v 1.1.4.4 2003-10-30 10:03:19 bfernhomberg Exp $
+ * $Id: dbd_update.c,v 1.1.4.5 2003-11-25 00:41:31 lenneis Exp $
  *
  * Copyright (C) Joerg Lenneis 2003
  * All Rights Reserved.  See COPYRIGHT.
@@ -46,7 +46,8 @@ int dbd_update(struct cnid_dbd_rqst *rqst, struct cnid_dbd_rply *rply)
     if ((rc = dbif_pget(DBIF_IDX_DEVINO, &key, &pkey, &data, 0)) < 0 ) {
         goto err_db;
     }
-    else if  (rc > 0) {
+    else if  (rc > 0) { 
+       /* FIXME: pkey.data points to the CNID? */
         if ((rc = dbif_del(DBIF_IDX_DEVINO, &pkey, 0)) < 0 ) {
             goto err_db;
         }
@@ -64,6 +65,7 @@ int dbd_update(struct cnid_dbd_rqst *rqst, struct cnid_dbd_rply *rply)
         goto err_db;
     }
     else if  (rc > 0) {
+       /* FIXME: pkey.data points to the CNID? */
         if ((rc = dbif_del(DBIF_IDX_DIDNAME, &pkey, 0)) < 0) {
             goto err_db;
         }
index 68f284fbbbec8fe4b815f6faa6b4ce3c7605779e..00061cc99586f009a3088a86f01bc7e016ecce39 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: main.c,v 1.1.4.3 2003-11-03 20:56:59 lenneis Exp $
+ * $Id: main.c,v 1.1.4.4 2003-11-25 00:41:31 lenneis Exp $
  *
  * Copyright (C) Joerg Lenneis 2003
  * All Rights Reserved.  See COPYRIGHT.
@@ -160,6 +160,9 @@ static int loop(struct db_param *dbp)
         case CNID_DBD_OP_DELETE:
             ret = dbd_delete(&rqst, &rply);
             break;
+        case CNID_DBD_OP_GETSTAMP:
+            ret = dbd_getstamp(&rqst, &rply);
+            break;
         default:
             LOG(log_error, logtype_cnid, "loop: unknow op %d", rqst.op);
             break;
index 25951ec2418394759a0450f366edfcae775cd805..6de64725568a2f1131f43455a5631a9adcaf5e59 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: pack.c,v 1.1.4.3 2003-10-30 10:03:19 bfernhomberg Exp $
+ * $Id: pack.c,v 1.1.4.4 2003-11-25 00:41:31 lenneis Exp $
  *
  * Copyright (C) Joerg Lenneis 2003
  * All Rights Reserved.  See COPYRIGHT.
 #include <netatalk/endian.h>
 #include "pack.h"
 
+/* --------------- */
+static void pack_devino(unsigned char *buf, dev_t dev, ino_t ino)
+{
+    buf[CNID_DEV_LEN - 1] = dev; dev >>= 8;
+    buf[CNID_DEV_LEN - 2] = dev; dev >>= 8;
+    buf[CNID_DEV_LEN - 3] = dev; dev >>= 8;
+    buf[CNID_DEV_LEN - 4] = dev; dev >>= 8;
+    buf[CNID_DEV_LEN - 5] = dev; dev >>= 8;
+    buf[CNID_DEV_LEN - 6] = dev; dev >>= 8;
+    buf[CNID_DEV_LEN - 7] = dev; dev >>= 8;
+    buf[CNID_DEV_LEN - 8] = dev;
+
+    buf[CNID_DEV_LEN + CNID_INO_LEN - 1] = ino; ino >>= 8;
+    buf[CNID_DEV_LEN + CNID_INO_LEN - 2] = ino; ino >>= 8;
+    buf[CNID_DEV_LEN + CNID_INO_LEN - 3] = ino; ino >>= 8;
+    buf[CNID_DEV_LEN + CNID_INO_LEN - 4] = ino; ino >>= 8;
+    buf[CNID_DEV_LEN + CNID_INO_LEN - 5] = ino; ino >>= 8;
+    buf[CNID_DEV_LEN + CNID_INO_LEN - 6] = ino; ino >>= 8;
+    buf[CNID_DEV_LEN + CNID_INO_LEN - 7] = ino; ino >>= 8;
+    buf[CNID_DEV_LEN + CNID_INO_LEN - 8] = ino;    
+}
+
 /* --------------- */
 int didname(dbp, pkey, pdata, skey)
 DB *dbp;
@@ -58,11 +80,8 @@ char *pack_cnid_data(struct cnid_dbd_rqst *rqst)
     char *buf = start +CNID_LEN;
     u_int32_t i;
 
-    memcpy(buf, &rqst->dev, sizeof(rqst->dev));
-    buf += sizeof(rqst->dev);
-
-    memcpy(buf, &rqst->ino, sizeof(rqst->ino));
-    buf += sizeof(rqst->ino);
+    pack_devino(buf, rqst->dev, rqst->ino);
+    buf += CNID_DEVINO_LEN;
 
     i = htonl(rqst->type);
     memcpy(buf, &i, sizeof(i));
index 58819e3cccad6e929fab196abf5cb66e4f3a0933..e6cd13629a8af3e1b04ba5b59daec9480ed60073 100644 (file)
@@ -22,6 +22,7 @@
 #define CNID_DBD_OP_DELETE      0x08
 #define CNID_DBD_OP_MANGLE_ADD  0x09
 #define CNID_DBD_OP_MANGLE_GET  0x0a
+#define CNID_DBD_OP_GETSTAMP    0x0b
 
 #define CNID_DBD_RES_OK            0x00
 #define CNID_DBD_RES_NOTFOUND      0x01
index 9b899841c87878fb006f5c1eeaf04569a311d45a..129a7b83fc16e2086ece7804ba8656a5997a7132 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: cnid_dbd.c,v 1.1.4.7 2003-11-12 16:00:10 didg Exp $
+ * $Id: cnid_dbd.c,v 1.1.4.8 2003-11-25 00:41:31 lenneis Exp $
  *
  * Copyright (C) Joerg Lenneis 2003
  * All Rights Reserved.  See COPYRIGHT.
@@ -487,58 +487,6 @@ char *cnid_dbd_resolve(struct _cnid_db *cdb, cnid_t *id, void *buffer, u_int32_t
     return name;
 }
 
-/* ---------------------- */
-int cnid_dbd_getstamp(struct _cnid_db *cdb, void *buffer, const int len)
-{
-    CNID_private *db;
-    struct cnid_dbd_rqst rqst;
-    struct cnid_dbd_rply rply;
-    cnid_t id = 0;
-    char temp[12 + MAXPATHLEN + 1];
-
-    if (!cdb || !(db = cdb->_private)) {
-        LOG(log_error, logtype_cnid, "cnid_getstamp: Parameter error");
-        errno = CNID_ERR_PARAM;                
-        return -1;
-    }
-
-    /* TODO: We should maybe also check len. At the moment we rely on the caller
-       to provide a buffer that is large enough for MAXPATHLEN plus
-       CNID_HEADER_LEN plus 1 byte, which is large enough for the maximum that
-       can come from the database. */
-
-    RQST_RESET(&rqst);
-    rqst.op = CNID_DBD_OP_RESOLVE;
-    rqst.cnid = id;
-
-    memset(buffer, 0, len);
-
-    /* This mimicks the behaviour of the "regular" cnid_resolve. So far,
-       nobody uses the content of buffer. It only provides space for the
-       name in the caller. */
-    rply.name = temp + CNID_HEADER_LEN;
-
-    if (transmit(db, &rqst, &rply) < 0) {
-        errno = CNID_ERR_DB;
-        return -1;
-    }
-
-    switch (rply.result) {
-    case CNID_DBD_RES_OK:
-        memcpy(buffer, &rply.did, sizeof(cnid_t));
-        break;
-    case CNID_DBD_RES_NOTFOUND:
-        return -1;
-    case CNID_DBD_RES_ERR_DB:
-        errno = CNID_ERR_DB;
-        return -1;
-    default:
-        abort();
-    }
-
-    return 0;
-}
-
 /* ---------------------- */
 cnid_t cnid_dbd_lookup(struct _cnid_db *cdb, const struct stat *st, const cnid_t did,
                    const char *name, const int len)
@@ -675,6 +623,52 @@ int cnid_dbd_delete(struct _cnid_db *cdb, const cnid_t id)
     }
 }
 
+/* ---------------------- */
+int cnid_dbd_getstamp(struct _cnid_db *cdb, void *buffer, const int len)
+{
+    CNID_private *db;
+    struct cnid_dbd_rqst rqst;
+    struct cnid_dbd_rply rply;
+
+    /* FIXME: We rely on len == ADEDLEN_PRIVSYN == CNID_DEV_LEN here as well as
+       in the backend. There should really be a constant for that value that is
+       used throughout. Also, returning the stamp via the name field is somewhat
+       fishy. */
+
+    if (!cdb || !(db = cdb->_private)) {
+        LOG(log_error, logtype_cnid, "cnid_getstamp: Parameter error");
+        errno = CNID_ERR_PARAM;                
+        return -1;
+    }
+
+
+    RQST_RESET(&rqst);
+    rqst.op = CNID_DBD_OP_GETSTAMP;
+
+    memset(buffer, 0, len);
+
+    rply.name = buffer;
+
+    if (transmit(db, &rqst, &rply) < 0) {
+        errno = CNID_ERR_DB;
+        return -1;
+    }
+
+    switch (rply.result) {
+    case CNID_DBD_RES_OK:
+        break;
+    case CNID_DBD_RES_NOTFOUND:
+        return -1;
+    case CNID_DBD_RES_ERR_DB:
+        errno = CNID_ERR_DB;
+        return -1;
+    default:
+        abort();
+    }
+
+    return 0;
+}
+
 struct _cnid_module cnid_dbd_module = {
     "dbd",
     {NULL, NULL},
@@ -682,4 +676,3 @@ struct _cnid_module cnid_dbd_module = {
 };
 
 #endif /* CNID_DBD */
-