]> arthur.barton.de Git - netatalk.git/commitdiff
New option -n for scanning with -s: dont open CNID database,
authorfranklahm <franklahm>
Mon, 12 Oct 2009 11:30:52 +0000 (11:30 +0000)
committerfranklahm <franklahm>
Mon, 12 Oct 2009 11:30:52 +0000 (11:30 +0000)
only scan filesystem.

etc/cnid_dbd/cmd_dbd.c
etc/cnid_dbd/cmd_dbd.h
etc/cnid_dbd/cmd_dbd_scanvol.c

index ef79b5f910a76948ba13b79144726f683fc7a441..c77bf79a2eaa64aa4c7b7ca107f992fdb2b413f1 100644 (file)
@@ -1,5 +1,5 @@
 /* 
-   $Id: cmd_dbd.c,v 1.7 2009-09-14 01:24:40 didg Exp $
+   $Id: cmd_dbd.c,v 1.8 2009-10-12 11:30:52 franklahm Exp $
 
    Copyright (c) 2009 Frank Lahm <franklahm@gmail.com>
    
 #define LOCKFILENAME  "lock"
 #define DBOPTIONS (DB_CREATE | DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN)
 
-static DBD *dbd;
-
+int nocniddb = 0;               /* Dont open CNID database, only scan filesystem */
 volatile sig_atomic_t alarmed;
+
+static DBD *dbd;
 static int verbose;             /* Logging flag */
 static int exclusive;           /* Exclusive volume access */
 static struct db_param db_param = {
@@ -228,7 +229,7 @@ void free_lock(int lockfd)
 
 static void usage ()
 {
-    printf("Usage: dbd [-e|-v|-x|-u] -d [-i] | -s | -r [-f] <path to netatalk volume>\n"
+    printf("Usage: dbd [-e|-v|-x|-u] -d [-i] | -s [-n]| -r [-f] <path to netatalk volume>\n"
            "dbd can dump, scan, reindex and rebuild Netatalk dbd CNID databases.\n"
            "dbd must be run with appropiate permissions i.e. as root.\n\n"
            "Main commands are:\n"
@@ -242,6 +243,8 @@ static void usage ()
            "      5. Check for directories inside AppleDouble directories\n"
            "      6. Check name encoding by roundtripping, log on error\n"
            "      7. Check for orphaned CNIDs in database (requires -e)\n"
+           "      8. Open and close adouble files\n"
+           "      Option: -n Don't open CNID database, skip CNID checks\n"
            "   -r Rebuild volume:\n"
            "      1. Sync CNIDSs in database with volume\n"
            "      2. Make sure .AppleDouble dir exist, create if missing\n"
@@ -250,6 +253,7 @@ static void usage ()
            "      5. Check for directories inside AppleDouble directories\n"
            "      6. Check name encoding by roundtripping, log on error\n"
            "      7. Check for orphaned CNIDs in database (requires -e)\n"
+           "      8. Open and close adouble files\n"
            "      Option: -f wipe database and rebuild from IDs stored in AppleDouble files,\n"
            "                 only available for volumes with 'cachecnid' option. Implies -e.\n"
            "   -u Prepare upgrade:\n"
@@ -282,7 +286,7 @@ int main(int argc, char **argv)
         exit(EXIT_FAILURE);
     }
 
-    while ((c = getopt(argc, argv, ":dsruvxife")) != -1) {
+    while ((c = getopt(argc, argv, ":dsnruvxife")) != -1) {
         switch(c) {
         case 'd':
             dump = 1;
@@ -294,6 +298,9 @@ int main(int argc, char **argv)
             scan = 1;
             flags |= DBD_FLAGS_SCAN;
             break;
+        case 'n':
+            nocniddb = 1;
+            break;
         case 'r':
             rebuild = 1;
             break;
@@ -392,38 +399,42 @@ int main(int argc, char **argv)
     /* 
        Lets start with the BerkeleyDB stuff
     */
-    if ((dbd = dbif_init(dbpath, "cnid2.db")) == NULL)
-        goto exit_failure;
-
-    if (dbif_env_open(dbd, &db_param, exclusive ? (DBOPTIONS | DB_RECOVER) : DBOPTIONS) < 0) {
-        dbd_log( LOGSTD, "error opening database!");
-        goto exit_failure;
-    }
+    if ( ! nocniddb) {
+        if ((dbd = dbif_init(dbpath, "cnid2.db")) == NULL)
+            goto exit_failure;
+        
+        if (dbif_env_open(dbd, &db_param, exclusive ? (DBOPTIONS | DB_RECOVER) : DBOPTIONS) < 0) {
+            dbd_log( LOGSTD, "error opening database!");
+            goto exit_failure;
+        }
 
-    if (exclusive)
-        dbd_log( LOGDEBUG, "Finished recovery.");
+        if (exclusive)
+            dbd_log( LOGDEBUG, "Finished recovery.");
 
-    if (dbif_open(dbd, &db_param, rebuildindexes) < 0) {
-        dbif_close(dbd);
-        goto exit_failure;
-    }
+        if (dbif_open(dbd, &db_param, rebuildindexes) < 0) {
+            dbif_close(dbd);
+            goto exit_failure;
+        }
 
-    if (dbd_stamp(dbd) < 0) {
-        dbif_close(dbd);
-        goto exit_failure;
+        if (dbd_stamp(dbd) < 0) {
+            dbif_close(dbd);
+            goto exit_failure;
+        }
     }
 
-    if (dump) {
+    /* Now execute given command scan|rebuild|dump */
+    if (dump && ! nocniddb) {
         if (dbif_dump(dbd, dumpindexes) < 0) {
             dbd_log( LOGSTD, "Error dumping database");
         }
-    } else if (rebuild || scan) {
+    } else if ((rebuild && ! nocniddb) || (scan && nocniddb)) {
         if (cmd_dbd_scanvol(dbd, &volinfo, flags) < 0) {
             dbd_log( LOGSTD, "Error repairing database.");
         }
     }
 
-    if (dbif_close(dbd) < 0) {
+    /* Cleanup */
+    if (! nocniddb && dbif_close(dbd) < 0) {
         dbd_log( LOGSTD, "Error closing database");
         goto exit_failure;
     }
index 170b407eb09134fce727f40eb9724d06f19ac070..2d061a7aeb4e6de7c400aa1a9c74b8a1ca1dfb2e 100644 (file)
@@ -22,6 +22,7 @@ typedef unsigned int dbd_flags_t;
 #define STRCMP(a,b,c) \
         (strcmp(a,c) b 0)
 
+extern int nocniddb; /* Dont open CNID database, only scan filesystem */
 extern volatile sig_atomic_t alarmed;
 extern struct volinfo *volinfo;
 extern char cwdbuf[MAXPATHLEN+1];
index b4c6785e84b9b02ac59d3a373154a5a83e2d5929..f1d54ceb929f3abee58bceacf0c390c5a2ae46e9 100644 (file)
@@ -1,5 +1,5 @@
 /*
-  $Id: cmd_dbd_scanvol.c,v 1.8 2009-09-14 02:56:19 didg Exp $
+  $Id: cmd_dbd_scanvol.c,v 1.9 2009-10-12 11:30:52 franklahm Exp $
 
   Copyright (c) 2009 Frank Lahm <franklahm@gmail.com>
 
@@ -208,7 +208,7 @@ static int check_adfile(const char *fname, const struct stat *st)
             return -1;
         }
         /* Missing. Log and create it */
-        dbd_log(LOGSTD, "Missing AppleDoube file '%s/%s'", cwdbuf, adname);
+        dbd_log(LOGSTD, "Missing AppleDouble file '%s/%s'", cwdbuf, adname);
 
         if (dbd_flags & DBD_FLAGS_SCAN)
             /* Scan only requested, dont change anything */
@@ -220,6 +220,7 @@ static int check_adfile(const char *fname, const struct stat *st)
         if ((ret = ad_open_metadata( fname, adflags, O_CREAT, &ad)) != 0) {
             dbd_log( LOGSTD, "Error creating AppleDouble file '%s/%s': %s",
                      cwdbuf, adname, strerror(errno));
+
             return -1;
         }
 
@@ -233,6 +234,13 @@ static int check_adfile(const char *fname, const struct stat *st)
 #if 0
         chmod(adname, st->st_mode);
 #endif
+    } else {
+        ad_init(&ad, volinfo->v_adouble, volinfo->v_ad_options);
+        if (ad_open_metadata( fname, adflags, O_RDONLY, &ad) != 0) {
+            dbd_log( LOGSTD, "Error opening AppleDouble file for '%s/%s'", cwdbuf, fname);
+            return -1;
+        }
+        ad_close_metadata(&ad);
     }
     return 0;
 }
@@ -590,24 +598,26 @@ static int dbd_readdir(int volroot, cnid_t did)
         if (ADDIR_OK)
             adfile_ok = check_adfile(ep->d_name, &st);
 
-        /* Check CNIDs */
-        cnid = check_cnid(ep->d_name, did, &st, adfile_ok, adflags);
-
-        /* Now add this object to our rebuild dbd */
-        if (cnid) {
-            rqst.cnid = rply.cnid;
-            dbd_rebuild_add(dbd_rebuild, &rqst, &rply);
-            if (rply.result != CNID_DBD_RES_OK) {
-                dbd_log( LOGDEBUG, "Fatal error adding CNID: %u for '%s/%s' to in-memory rebuild-db",
-                         cnid, cwdbuf, ep->d_name);
-                exit(EXIT_FAILURE);
+        if ( ! nocniddb) {
+            /* Check CNIDs */
+            cnid = check_cnid(ep->d_name, did, &st, adfile_ok, adflags);
+
+            /* Now add this object to our rebuild dbd */
+            if (cnid) {
+                rqst.cnid = rply.cnid;
+                dbd_rebuild_add(dbd_rebuild, &rqst, &rply);
+                if (rply.result != CNID_DBD_RES_OK) {
+                    dbd_log( LOGDEBUG, "Fatal error adding CNID: %u for '%s/%s' to in-memory rebuild-db",
+                             cnid, cwdbuf, ep->d_name);
+                    exit(EXIT_FAILURE);
+                }
             }
         }
 
         /**************************************************************************
           Recursion
         **************************************************************************/
-        if (S_ISDIR(st.st_mode) && cnid) { /* If we have no cnid for it we cant recur */
+        if (S_ISDIR(st.st_mode) && (cnid || nocniddb)) { /* If we have no cnid for it we cant recur */
             strcat(cwdbuf, "/");
             strcat(cwdbuf, ep->d_name);
             dbd_log( LOGDEBUG, "Entering directory: %s", cwdbuf);
@@ -766,19 +776,21 @@ int cmd_dbd_scanvol(DBD *dbd_ref, struct volinfo *volinfo, dbd_flags_t flags)
         return -1;
     }
 
-    /* Get volume stamp */
-    dbd_getstamp(dbd, &rqst, &rply);
-    if (rply.result != CNID_DBD_RES_OK)
-        goto exit_cleanup;
-    memcpy(stamp, rply.name, CNID_DEV_LEN);
+    if (! nocniddb) {
+        /* Get volume stamp */
+        dbd_getstamp(dbd, &rqst, &rply);
+        if (rply.result != CNID_DBD_RES_OK)
+            goto exit_cleanup;
+        memcpy(stamp, rply.name, CNID_DEV_LEN);
 
-    /* open/create rebuild dbd, copy rootinfo key */
-    if (NULL == (dbd_rebuild = dbif_init(NULL, NULL)))
-        return -1;
-    if (0 != (dbif_open(dbd_rebuild, NULL, 0)))
-        return -1;
-    if (0 != (dbif_copy_rootinfokey(dbd, dbd_rebuild)))
-        goto exit_cleanup;
+        /* open/create rebuild dbd, copy rootinfo key */
+        if (NULL == (dbd_rebuild = dbif_init(NULL, NULL)))
+            return -1;
+        if (0 != (dbif_open(dbd_rebuild, NULL, 0)))
+            return -1;
+        if (0 != (dbif_copy_rootinfokey(dbd, dbd_rebuild)))
+            goto exit_cleanup;
+    }
 
     if (setjmp(jmp) != 0)
         goto exit_cleanup;      /* Got signal, jump from dbd_readdir */
@@ -787,12 +799,15 @@ int cmd_dbd_scanvol(DBD *dbd_ref, struct volinfo *volinfo, dbd_flags_t flags)
     if ( (scanvol(volinfo, flags)) != 0)
         return -1;
 
+    if (! nocniddb) {
     /* We can only do this in exclusive mode, otherwise we might delete CNIDs added from
        other clients in between our pass 1 and 2 */
-    if (flags & DBD_FLAGS_EXCL)
-        delete_orphaned_cnids(dbd, dbd_rebuild, flags);
+        if (flags & DBD_FLAGS_EXCL)
+            delete_orphaned_cnids(dbd, dbd_rebuild, flags);
+    }
 
 exit_cleanup:
-    dbif_close(dbd_rebuild);
+    if (! nocniddb)
+        dbif_close(dbd_rebuild);
     return ret;
 }