Whamcloud - gitweb
LU-367 Handle DB->open errors without crashing 67/867/4
authorAndreas Dilger <adilger@whamcloud.com>
Tue, 31 May 2011 10:04:54 +0000 (04:04 -0600)
committerAndreas Dilger <adilger@whamcloud.com>
Tue, 31 May 2011 20:42:30 +0000 (14:42 -0600)
Remove the DB_INIT_LOCK call from the second db->open() call, since
this caused errors on the newer db4.  We shouldn't need this anyway
because the databases are never opened concurrently in r/w mode.

If there is an error opening the MDSDB or OSTDB, print out a consistent
error message.  In lfsck_run_checks() it didn't have enough function
arguments, so when the MDSDB failed to open (e.g. due to a different
version of db4 installed on the MDS, OSS, or client nodes) it caused
lfsck to crash afterward.

Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Change-Id: I65f9de6886c401315530d6b9e402ce8b1f84e8ce

patches/e2fsprogs-lfsck.patch

index 79fbeab..ce08e24 100644 (file)
@@ -839,7 +839,7 @@ Index: e2fsprogs/e2fsck/lfsck.c
 ===================================================================
 --- /dev/null
 +++ e2fsprogs/e2fsck/lfsck.c
-@@ -0,0 +1,2096 @@
+@@ -0,0 +1,2098 @@
 +/* -*- mode: c; c-basic-offset: 8; -*-
 + * vim:shiftwidth=8:tabstop=8:
 + *
@@ -871,6 +871,7 @@ Index: e2fsprogs/e2fsck/lfsck.c
 + * Copyright (c) 2004  Hewlett-Packard Co.
 + * Copyright 2004, 2010, Oracle and/or its affiliates. All rights reserved.
 + * Use is subject to license terms.
++ * Copyright (c) 2011  Whamcloud, Inc.
 + */
 +/***********************************************************************
 + * This program takes as input files generated by running e2fsck on
@@ -2060,7 +2061,8 @@ Index: e2fsprogs/e2fsck/lfsck.c
 +
 +      sprintf(dbname, "%s.%d", MDS_OSTDB, ost_idx);
 +      if ((rc = lfsck_opendb(mds_file, dbname, &mds_db, 1, 0, 0)) != 0) {
-+              log_write("failed to open mds db file %s\n", mds_file);
++              log_write("%s: failed to open mds db file %s: rc %d\n",
++                        progname, mds_file, rc);
 +              rc = -EINVAL;
 +              goto out;
 +      }
@@ -2128,8 +2130,8 @@ Index: e2fsprogs/e2fsck/lfsck.c
 +
 +      rc = lfsck_opendb(mds_file, dbname, &mds_ostdb, 1, 0, 0);
 +      if (rc != 0) {
-+              log_write("failed to open mds db file %s: %s\n",
-+                        mds_file, db_strerror(rc));
++              log_write("%s: failed to open mds db file %s: rc %d\n",
++                        progname, mds_file, rc);
 +              goto out;
 +      }
 +
@@ -2148,8 +2150,8 @@ Index: e2fsprogs/e2fsck/lfsck.c
 +              VERBOSE(2, "checking file %s\n", ost_files[i]);
 +              rc = lfsck_opendb(ost_files[i], OST_HDR, &ost_db, 0, 0, 0);
 +              if (rc != 0) {
-+                      log_write("Error opening ost_data_file %s: rc %d\n",
-+                              ost_files[i], rc);
++                      log_write("%s: error opening ost_data_file %s: rc %d\n",
++                                progname, ost_files[i], rc);
 +                      goto out;
 +              }
 +              memset(&key, 0, sizeof(key));
@@ -2194,8 +2196,8 @@ Index: e2fsprogs/e2fsck/lfsck.c
 +      }
 +      rc = lfsck_opendb(ost_files[i], OST_OSTDB, &ost_db, 0, 0, 0);
 +      if (rc != 0) {
-+              log_write("error opening ost_data_file %s: rc %d\n",
-+                      ost_files[i], rc);
++              log_write("%s: error opening ost_data_file %s: rc %d\n",
++                        progname, ost_files[i], rc);
 +              goto out;
 +      }
 +
@@ -2716,15 +2718,15 @@ Index: e2fsprogs/e2fsck/lfsck.c
 +
 +      rc = lfsck_opendb(mds_file, MDS_DIRINFO, &mds_direntdb, 0, 0, 0);
 +      if (rc != 0) {
-+              log_write("%s: error opening dirinfo db %s\n",
-+                        progname, mds_file);
++              log_write("%s: error opening dirinfo db %s: rc %d\n",
++                        progname, mds_file, rc);
 +              goto out;
 +      }
 +
 +      rc = lfsck_opendb(mds_file, MDS_SIZEINFO, &mds_sizeinfodb, 0, 0, 0);
 +      if (rc != 0) {
-+              log_write("%s: error opening sizeinfo db %s\n",
-+                        progname, mds_file);
++              log_write("%s: error opening sizeinfo db %s: rc %d\n",
++                        progname, mds_file, rc);
 +              goto out;
 +      }
 +
@@ -3268,7 +3270,7 @@ Index: e2fsprogs/e2fsck/lfsck_common.c
 ===================================================================
 --- /dev/null
 +++ e2fsprogs/e2fsck/lfsck_common.c
-@@ -0,0 +1,434 @@
+@@ -0,0 +1,429 @@
 +/*
 + * Copyright (c) 2004  Hewlett-Packard Co.
 + */
@@ -3450,13 +3452,8 @@ Index: e2fsprogs/e2fsck/lfsck_common.c
 +              }
 +      }
 +
-+#if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1) || (DB_VERSION_MAJOR > 4)
 +      if ((rc = dbp->open(dbp, NULL, fname, dbname, DB_HASH,
-+                          DB_CREATE | DB_INIT_LOCK | DB_THREAD, 0664)) != 0)
-+#else
-+      if ((rc = dbp->open(dbp, fname, dbname, DB_HASH,
-+                          DB_CREATE | DB_INIT_LOCK | DB_THREAD, 0664)) != 0)
-+#endif
++                          DB_CREATE | DB_THREAD, 0664)) != 0)
 +      {
 +              dbp->err(dbp, rc, "%s:%s\n", fname, dbname);
 +              dbp->close(dbp, 0);