Whamcloud - gitweb
Revert "LU-8922 lod: check master stripes properly"
[fs/lustre-release.git] / lustre / mgs / mgs_llog.c
index 22e0e8d..5d9c535 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * GPL HEADER END
  */
@@ -27,7 +23,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2015, Intel Corporation.
+ * Copyright (c) 2011, 2016, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -100,6 +96,15 @@ int class_dentry_readdir(const struct lu_env *env,
                                goto next;
                }
 
+               /* filter out ".bak" files */
+               /* sizeof(".bak") - 1 == 3 */
+               if (key_sz >= 3 &&
+                   !memcmp(".bak", key + key_sz - 3, 3)) {
+                       CDEBUG(D_MGS, "Skipping backup file %.*s\n",
+                              key_sz, key);
+                       goto next;
+               }
+
                de = mgs_direntry_alloc(key_sz + 1);
                if (de == NULL) {
                        rc = -ENOMEM;
@@ -256,10 +261,12 @@ static int mgs_get_fsdb_from_llog(const struct lu_env *env,
                                  struct mgs_device *mgs,
                                  struct fs_db *fsdb)
 {
-       char                            *logname;
-       struct llog_handle              *loghandle;
-       struct llog_ctxt                *ctxt;
-       struct mgs_fsdb_handler_data     d = { fsdb, 0 };
+       char *logname;
+       struct llog_handle *loghandle;
+       struct llog_ctxt *ctxt;
+       struct mgs_fsdb_handler_data d = {
+               .fsdb = fsdb,
+       };
        int rc;
 
        ENTRY;
@@ -589,8 +596,12 @@ static int mgs_set_index(const struct lu_env *env,
        set_bit(mti->mti_stripe_index, imap);
        clear_bit(FSDB_LOG_EMPTY, &fsdb->fsdb_flags);
        mutex_unlock(&fsdb->fsdb_mutex);
-       server_make_name(mti->mti_flags & ~(LDD_F_VIRGIN | LDD_F_WRITECONF),
-                        mti->mti_stripe_index, mti->mti_fsname, mti->mti_svname);
+       if (server_make_name(mti->mti_flags & ~(LDD_F_VIRGIN | LDD_F_WRITECONF),
+                            mti->mti_stripe_index, mti->mti_fsname,
+                            mti->mti_svname)) {
+               CERROR("unknown server type %#x\n", mti->mti_flags);
+               return -EINVAL;
+       }
 
         CDEBUG(D_MGS, "Set index for %s to %d\n", mti->mti_svname,
                mti->mti_stripe_index);
@@ -606,6 +617,116 @@ struct mgs_modify_lookup {
         int               mml_modified;
 };
 
+static int mgs_check_record_match(const struct lu_env *env,
+                               struct llog_handle *llh,
+                               struct llog_rec_hdr *rec, void *data)
+{
+       struct cfg_marker *mc_marker = data;
+       struct cfg_marker *marker;
+       struct lustre_cfg *lcfg = REC_DATA(rec);
+       int cfg_len = REC_DATA_LEN(rec);
+       int rc;
+       ENTRY;
+
+
+       if (rec->lrh_type != OBD_CFG_REC) {
+               CDEBUG(D_ERROR, "Unhandled lrh_type: %#x\n", rec->lrh_type);
+               RETURN(-EINVAL);
+       }
+
+       rc = lustre_cfg_sanity_check(lcfg, cfg_len);
+       if (rc) {
+               CDEBUG(D_ERROR, "Insane cfg\n");
+               RETURN(rc);
+       }
+
+       /* We only care about markers */
+       if (lcfg->lcfg_command != LCFG_MARKER)
+               RETURN(0);
+
+       marker = lustre_cfg_buf(lcfg, 1);
+
+       if (marker->cm_flags & CM_SKIP)
+               RETURN(0);
+
+       if ((strcmp(mc_marker->cm_comment, marker->cm_comment) == 0) &&
+               (strcmp(mc_marker->cm_tgtname, marker->cm_tgtname) == 0)) {
+               /* Found a non-skipped marker match */
+               CDEBUG(D_MGS, "Matched rec %u marker %d flag %x %s %s\n",
+                       rec->lrh_index, marker->cm_step,
+                       marker->cm_flags, marker->cm_tgtname,
+                       marker->cm_comment);
+               rc = LLOG_PROC_BREAK;
+       }
+
+       RETURN(rc);
+}
+
+/**
+ * Check an existing config log record with matching comment and device
+ * Return code:
+ * 0 - checked successfully,
+ * LLOG_PROC_BREAK - record matches
+ * negative - error
+ */
+static int mgs_check_marker(const struct lu_env *env, struct mgs_device *mgs,
+               struct fs_db *fsdb, struct mgs_target_info *mti,
+               char *logname, char *devname, char *comment)
+{
+       struct llog_handle *loghandle;
+       struct llog_ctxt *ctxt;
+       struct cfg_marker *mc_marker;
+       int rc;
+
+       ENTRY;
+
+       LASSERT(mutex_is_locked(&fsdb->fsdb_mutex));
+       CDEBUG(D_MGS, "mgs check %s/%s/%s\n", logname, devname, comment);
+
+       ctxt = llog_get_context(mgs->mgs_obd, LLOG_CONFIG_ORIG_CTXT);
+       LASSERT(ctxt != NULL);
+       rc = llog_open(env, ctxt, &loghandle, NULL, logname, LLOG_OPEN_EXISTS);
+       if (rc < 0) {
+               if (rc == -ENOENT)
+                       rc = 0;
+               GOTO(out_pop, rc);
+       }
+
+       rc = llog_init_handle(env, loghandle, LLOG_F_IS_PLAIN, NULL);
+       if (rc)
+               GOTO(out_close, rc);
+
+       if (llog_get_size(loghandle) <= 1)
+               GOTO(out_close, rc = 0);
+
+       OBD_ALLOC_PTR(mc_marker);
+       if (!mc_marker)
+               GOTO(out_close, rc = -ENOMEM);
+       if (strlcpy(mc_marker->cm_comment, comment,
+               sizeof(mc_marker->cm_comment)) >=
+               sizeof(mc_marker->cm_comment))
+               GOTO(out_free, rc = -E2BIG);
+       if (strlcpy(mc_marker->cm_tgtname, devname,
+               sizeof(mc_marker->cm_tgtname)) >=
+               sizeof(mc_marker->cm_tgtname))
+               GOTO(out_free, rc = -E2BIG);
+
+       rc = llog_process(env, loghandle, mgs_check_record_match,
+                       (void *)mc_marker, NULL);
+
+out_free:
+       OBD_FREE_PTR(mc_marker);
+
+out_close:
+       llog_close(env, loghandle);
+out_pop:
+       if (rc && rc != LLOG_PROC_BREAK)
+               CDEBUG(D_ERROR, "%s: mgs check %s/%s failed: rc = %d\n",
+                       mgs->mgs_obd->obd_name, mti->mti_svname, comment, rc);
+       llog_ctxt_put(ctxt);
+       RETURN(rc);
+}
+
 static int mgs_modify_handler(const struct lu_env *env,
                              struct llog_handle *llh,
                              struct llog_rec_hdr *rec, void *data)
@@ -3289,7 +3410,7 @@ static int mgs_write_log_param(const struct lu_env *env,
        struct mgs_thread_info *mgi = mgs_env_info(env);
         char *logname;
         char *tmp;
-        int rc = 0, rc2 = 0;
+       int rc = 0;
         ENTRY;
 
         /* For various parameter settings, we have to figure out which logs
@@ -3704,47 +3825,12 @@ active_err:
        }
 
         LCONSOLE_WARN("Ignoring unrecognized param '%s'\n", ptr);
-        rc2 = -ENOSYS;
 
 end:
         if (rc)
                 CERROR("err %d on param '%s'\n", rc, ptr);
 
-        RETURN(rc ?: rc2);
-}
-
-/* Not implementing automatic failover nid addition at this time. */
-int mgs_check_failnid(const struct lu_env *env, struct mgs_device *mgs,
-                     struct mgs_target_info *mti)
-{
-#if 0
-        struct fs_db *fsdb;
-        int rc;
-        ENTRY;
-
-        rc = mgs_find_or_make_fsdb(obd, fsname, &fsdb);
-        if (rc)
-                RETURN(rc);
-
-        if (mgs_log_is_empty(obd, mti->mti_svname))
-                /* should never happen */
-                RETURN(-ENOENT);
-
-        CDEBUG(D_MGS, "Checking for new failnids for %s\n", mti->mti_svname);
-
-        /* FIXME We can just check mti->params to see if we're already in
-           the failover list.  Modify mti->params for rewriting back at
-           server_register_target(). */
-
-       mutex_lock(&fsdb->fsdb_mutex);
-        rc = mgs_write_log_add_failnid(obd, fsdb, mti);
-       mutex_unlock(&fsdb->fsdb_mutex);
-       char    *buf, *params;
-       int      rc = -EINVAL;
-
-        RETURN(rc);
-#endif
-        return 0;
+       RETURN(rc);
 }
 
 int mgs_write_log_target(const struct lu_env *env, struct mgs_device *mgs,
@@ -4163,6 +4249,10 @@ int mgs_nodemap_cmd(const struct lu_env *env, struct mgs_device *mgs,
                bool_switch = simple_strtoul(param, NULL, 10);
                rc = nodemap_set_allow_root(nodemap_name, bool_switch);
                break;
+       case LCFG_NODEMAP_DENY_UNKNOWN:
+               bool_switch = simple_strtoul(param, NULL, 10);
+               rc = nodemap_set_deny_unknown(nodemap_name, bool_switch);
+               break;
        case LCFG_NODEMAP_TRUSTED:
                bool_switch = simple_strtoul(param, NULL, 10);
                rc = nodemap_set_trust_client_ids(nodemap_name, bool_switch);
@@ -4219,6 +4309,7 @@ int mgs_pool_cmd(const struct lu_env *env, struct mgs_device *mgs,
         char *label = NULL, *canceled_label = NULL;
         int label_sz;
         struct mgs_target_info *mti = NULL;
+       bool checked = false;
         int rc, i;
         ENTRY;
 
@@ -4281,11 +4372,10 @@ int mgs_pool_cmd(const struct lu_env *env, struct mgs_device *mgs,
                 break;
         }
 
-        if (canceled_label != NULL) {
-                OBD_ALLOC_PTR(mti);
-                if (mti == NULL)
-                       GOTO(out_cancel, rc = -ENOMEM);
-        }
+       OBD_ALLOC_PTR(mti);
+       if (mti == NULL)
+               GOTO(out_cancel, rc = -ENOMEM);
+       strncpy(mti->mti_svname, "lov pool", sizeof(mti->mti_svname));
 
        mutex_lock(&fsdb->fsdb_mutex);
         /* write pool def to all MDT logs */
@@ -4297,12 +4387,24 @@ int mgs_pool_cmd(const struct lu_env *env, struct mgs_device *mgs,
                                mutex_unlock(&fsdb->fsdb_mutex);
                                GOTO(out_mti, rc);
                        }
-                        if (canceled_label != NULL) {
-                                strcpy(mti->mti_svname, "lov pool");
+
+                       if (!checked && (canceled_label == NULL)) {
+                               rc = mgs_check_marker(env, mgs, fsdb, mti,
+                                               logname, lovname, label);
+                               if (rc) {
+                                       name_destroy(&logname);
+                                       name_destroy(&lovname);
+                                       mutex_unlock(&fsdb->fsdb_mutex);
+                                       GOTO(out_mti,
+                                               rc = (rc == LLOG_PROC_BREAK ?
+                                                       -EEXIST : rc));
+                               }
+                               checked = true;
+                       }
+                       if (canceled_label != NULL)
                                rc = mgs_modify(env, mgs, fsdb, mti, logname,
                                                lovname, canceled_label,
                                                CM_SKIP);
-                        }
 
                        if (rc >= 0)
                                rc = mgs_write_log_pool(env, mgs, logname,
@@ -4323,6 +4425,17 @@ int mgs_pool_cmd(const struct lu_env *env, struct mgs_device *mgs,
                mutex_unlock(&fsdb->fsdb_mutex);
                GOTO(out_mti, rc);
        }
+
+       if (!checked && (canceled_label == NULL)) {
+               rc = mgs_check_marker(env, mgs, fsdb, mti, logname,
+                               fsdb->fsdb_clilov, label);
+               if (rc) {
+                       name_destroy(&logname);
+                       mutex_unlock(&fsdb->fsdb_mutex);
+                       GOTO(out_mti, rc = (rc == LLOG_PROC_BREAK ?
+                               -EEXIST : rc));
+               }
+       }
        if (canceled_label != NULL) {
                rc = mgs_modify(env, mgs, fsdb, mti, logname,
                                fsdb->fsdb_clilov, canceled_label, CM_SKIP);