Whamcloud - gitweb
LU-4353 strncmp: Replace incorrect strncmp()s with strcmp()
[fs/lustre-release.git] / lustre / mgs / mgs_llog.c
index baaec4a..f88c10b 100644 (file)
@@ -67,9 +67,6 @@ int class_dentry_readdir(const struct lu_env *env,
 
        CFS_INIT_LIST_HEAD(list);
 
-       if (!dt_try_as_dir(env, dir))
-               GOTO(out, rc = -ENOTDIR);
-
        LASSERT(dir);
        LASSERT(dir->do_index_ops);
 
@@ -122,7 +119,6 @@ next:
 
 fini:
        iops->fini(env, it);
-out:
        if (rc)
                CERROR("%s: key failed when listing %s: rc = %d\n",
                       mgs->mgs_obd->obd_name, MOUNT_CONFIGS_DIR, rc);
@@ -697,8 +693,14 @@ static int mgs_modify(const struct lu_env *env, struct mgs_device *mgs,
         OBD_ALLOC_PTR(mml);
         if (!mml)
                 GOTO(out_close, rc = -ENOMEM);
-        strcpy(mml->mml_marker.cm_comment, comment);
-        strcpy(mml->mml_marker.cm_tgtname, devname);
+       if (strlcpy(mml->mml_marker.cm_comment, comment,
+                   sizeof(mml->mml_marker.cm_comment)) >=
+           sizeof(mml->mml_marker.cm_comment))
+               GOTO(out_free, rc = -E2BIG);
+       if (strlcpy(mml->mml_marker.cm_tgtname, devname,
+                   sizeof(mml->mml_marker.cm_tgtname)) >=
+           sizeof(mml->mml_marker.cm_tgtname))
+               GOTO(out_free, rc = -E2BIG);
         /* Modify mostly means cancel */
         mml->mml_marker.cm_flags = flags;
         mml->mml_marker.cm_canceltime = flags ? cfs_time_current_sec() : 0;
@@ -707,6 +709,8 @@ static int mgs_modify(const struct lu_env *env, struct mgs_device *mgs,
                          NULL);
        if (!rc && !mml->mml_modified)
                rc = 1;
+
+out_free:
         OBD_FREE_PTR(mml);
 
 out_close:
@@ -1463,7 +1467,8 @@ int mgs_write_log_direct_all(const struct lu_env *env,
        if (mgs_log_is_empty(env, mgs, logname)) {
                struct llog_handle *llh = NULL;
                rc = record_start_log(env, mgs, &llh, logname);
-               record_end_log(env, &llh);
+               if (rc == 0)
+                       record_end_log(env, &llh);
         }
         name_destroy(&logname);
         if (rc)
@@ -1918,11 +1923,13 @@ static int mgs_write_log_failnids(const struct lu_env *env,
                                failnodeuuid, cliname);
                        rc = record_add_uuid(env, llh, nid, failnodeuuid);
                 }
-               if (failnodeuuid)
+               if (failnodeuuid) {
                        rc = record_add_conn(env, llh, cliname, failnodeuuid);
+                       name_destroy(&failnodeuuid);
+                       failnodeuuid = NULL;
+               }
         }
 
-       name_destroy(&failnodeuuid);
         return rc;
 }
 
@@ -2711,8 +2718,13 @@ static int mgs_wlp_lcfg(const struct lu_env *env,
                 return rc;
 
         lustre_cfg_bufs_reset(bufs, tgtname);
-        lustre_cfg_bufs_set_string(bufs, 1, ptr);
-        lcfg = lustre_cfg_new(LCFG_PARAM, bufs);
+       lustre_cfg_bufs_set_string(bufs, 1, ptr);
+       if (mti->mti_flags & LDD_F_PARAM2)
+               lustre_cfg_bufs_set_string(bufs, 2, LCTL_UPCALL);
+
+       lcfg = lustre_cfg_new((mti->mti_flags & LDD_F_PARAM2) ?
+                             LCFG_SET_PARAM : LCFG_PARAM, bufs);
+
         if (!lcfg)
                 return -ENOMEM;
        rc = mgs_write_log_direct(env, mgs, fsdb, logname,lcfg,tgtname,comment);
@@ -2720,6 +2732,22 @@ static int mgs_wlp_lcfg(const struct lu_env *env,
         return rc;
 }
 
+static int mgs_write_log_param2(const struct lu_env *env,
+                               struct mgs_device *mgs,
+                               struct fs_db *fsdb,
+                               struct mgs_target_info *mti, char *ptr)
+{
+       struct lustre_cfg_bufs  bufs;
+       int                     rc = 0;
+       ENTRY;
+
+       CDEBUG(D_MGS, "next param '%s'\n", ptr);
+       rc = mgs_wlp_lcfg(env, mgs, fsdb, mti, PARAMS_FILENAME, &bufs,
+                         mti->mti_svname, ptr);
+
+       RETURN(rc);
+}
+
 /* write global variable settings into log */
 static int mgs_write_log_sys(const struct lu_env *env,
                             struct mgs_device *mgs, struct fs_db *fsdb,
@@ -3463,17 +3491,18 @@ static int mgs_write_log_param(const struct lu_env *env,
                 GOTO(end, rc);
         }
 
-        /* All mdd., ost. params in proc */
-        if ((class_match_param(ptr, PARAM_MDD, NULL) == 0) ||
-            (class_match_param(ptr, PARAM_OST, NULL) == 0)) {
-                CDEBUG(D_MGS, "%.3s param %s\n", ptr, ptr + 4);
+       /* All mdd., ost. and osd. params in proc */
+       if ((class_match_param(ptr, PARAM_MDD, NULL) == 0) ||
+           (class_match_param(ptr, PARAM_OST, NULL) == 0) ||
+           (class_match_param(ptr, PARAM_OSD, NULL) == 0)) {
+               CDEBUG(D_MGS, "%.3s param %s\n", ptr, ptr + 4);
                if (mgs_log_is_empty(env, mgs, mti->mti_svname))
-                        GOTO(end, rc = -ENODEV);
+                       GOTO(end, rc = -ENODEV);
 
                rc = mgs_wlp_lcfg(env, mgs, fsdb, mti, mti->mti_svname,
                                  &mgi->mgi_bufs, mti->mti_svname, ptr);
-                GOTO(end, rc);
-        }
+               GOTO(end, rc);
+       }
 
         LCONSOLE_WARN("Ignoring unrecognized param '%s'\n", ptr);
         rc2 = -ENOSYS;
@@ -3664,6 +3693,43 @@ int mgs_erase_logs(const struct lu_env *env, struct mgs_device *mgs, char *fsnam
         RETURN(rc);
 }
 
+/* list all logs for the given fs */
+int mgs_list_logs(const struct lu_env *env, struct mgs_device *mgs,
+                 struct obd_ioctl_data *data)
+{
+       cfs_list_t               list;
+       struct mgs_direntry     *dirent, *n;
+       char                    *out, *suffix;
+       int                      l, remains, rc;
+
+       ENTRY;
+
+       /* Find all the logs in the CONFIGS directory */
+       rc = class_dentry_readdir(env, mgs, &list);
+       if (rc) {
+               CERROR("%s: can't read %s dir = %d\n",
+                      mgs->mgs_obd->obd_name, MOUNT_CONFIGS_DIR, rc);
+               RETURN(rc);
+       }
+
+       out = data->ioc_bulk;
+       remains = data->ioc_inllen1;
+       cfs_list_for_each_entry_safe(dirent, n, &list, list) {
+               cfs_list_del(&dirent->list);
+               suffix = strrchr(dirent->name, '-');
+               if (suffix != NULL) {
+                       l = snprintf(out, remains, "config log: $%s\n",
+                                    dirent->name);
+                       out += l;
+                       remains -= l;
+               }
+               mgs_direntry_free(dirent);
+               if (remains <= 0)
+                       break;
+       }
+       RETURN(rc);
+}
+
 /* from llog_swab */
 static void print_lustre_cfg(struct lustre_cfg *lcfg)
 {
@@ -3728,7 +3794,7 @@ int mgs_setparam(const struct lu_env *env, struct mgs_device *mgs,
        if (rc == 0 && !mgs_parse_devname(devname, NULL, &index)) {
                 /* param related to llite isn't allowed to set by OST or MDT */
                if (rc == 0 && strncmp(param, PARAM_LLITE,
-                                  sizeof(PARAM_LLITE)) == 0)
+                                      sizeof(PARAM_LLITE) - 1) == 0)
                         RETURN(-EINVAL);
         } else {
                 /* assume devname is the fsname */
@@ -3738,10 +3804,14 @@ int mgs_setparam(const struct lu_env *env, struct mgs_device *mgs,
         }
         CDEBUG(D_MGS, "setparam fs='%s' device='%s'\n", fsname, devname);
 
-       rc = mgs_find_or_make_fsdb(env, mgs, fsname, &fsdb);
-        if (rc)
-                RETURN(rc);
-       if (!test_bit(FSDB_MGS_SELF, &fsdb->fsdb_flags) &&
+       rc = mgs_find_or_make_fsdb(env, mgs,
+                                  lcfg->lcfg_command == LCFG_SET_PARAM ?
+                                  PARAMS_FILENAME : fsname, &fsdb);
+       if (rc)
+               RETURN(rc);
+
+       if (lcfg->lcfg_command != LCFG_SET_PARAM &&
+           !test_bit(FSDB_MGS_SELF, &fsdb->fsdb_flags) &&
            test_bit(FSDB_LOG_EMPTY, &fsdb->fsdb_flags)) {
                 CERROR("No filesystem targets for %s.  cfg_device from lctl "
                        "is '%s'\n", fsname, devname);
@@ -3771,20 +3841,26 @@ int mgs_setparam(const struct lu_env *env, struct mgs_device *mgs,
                 if (server_make_name(rc, mti->mti_stripe_index, mti->mti_fsname,
                                      mti->mti_svname))
                         GOTO(out, rc = -EINVAL);
+       /*
+        * Revoke lock so everyone updates.  Should be alright if
+        * someone was already reading while we were updating the logs,
+        * so we don't really need to hold the lock while we're
+        * writing (above).
+        */
+       if (lcfg->lcfg_command == LCFG_SET_PARAM) {
+               mti->mti_flags = rc | LDD_F_PARAM2;
+               mutex_lock(&fsdb->fsdb_mutex);
+               rc = mgs_write_log_param2(env, mgs, fsdb, mti, mti->mti_params);
+               mutex_unlock(&fsdb->fsdb_mutex);
+               mgs_revoke_lock(mgs, fsdb, CONFIG_T_PARAMS);
+       } else {
+               mti->mti_flags = rc | LDD_F_PARAM;
+               mutex_lock(&fsdb->fsdb_mutex);
+               rc = mgs_write_log_param(env, mgs, fsdb, mti, mti->mti_params);
+               mutex_unlock(&fsdb->fsdb_mutex);
+               mgs_revoke_lock(mgs, fsdb, CONFIG_T_CONFIG);
+       }
 
-        mti->mti_flags = rc | LDD_F_PARAM;
-
-       mutex_lock(&fsdb->fsdb_mutex);
-       rc = mgs_write_log_param(env, mgs, fsdb, mti, mti->mti_params);
-       mutex_unlock(&fsdb->fsdb_mutex);
-
-        /*
-         * Revoke lock so everyone updates.  Should be alright if
-         * someone was already reading while we were updating the logs,
-         * so we don't really need to hold the lock while we're
-         * writing (above).
-         */
-       mgs_revoke_lock(mgs, fsdb, CONFIG_T_CONFIG);
 out:
         OBD_FREE_PTR(mti);
         RETURN(rc);
@@ -3792,9 +3868,9 @@ out:
 
 static int mgs_write_log_pool(const struct lu_env *env,
                              struct mgs_device *mgs, char *logname,
-                              struct fs_db *fsdb, char *lovname,
+                             struct fs_db *fsdb, char *tgtname,
                               enum lcfg_command_type cmd,
-                              char *poolname, char *fsname,
+                             char *fsname, char *poolname,
                               char *ostname, char *comment)
 {
         struct llog_handle *llh = NULL;
@@ -3803,18 +3879,40 @@ static int mgs_write_log_pool(const struct lu_env *env,
        rc = record_start_log(env, mgs, &llh, logname);
        if (rc)
                return rc;
-       rc = record_marker(env, llh, fsdb, CM_START, lovname, comment);
+       rc = record_marker(env, llh, fsdb, CM_START, tgtname, comment);
        if (rc)
                goto out;
-       rc = record_base(env, llh, lovname, 0, cmd, poolname, fsname, ostname, 0);
+       rc = record_base(env, llh, tgtname, 0, cmd,
+                        fsname, poolname, ostname, 0);
        if (rc)
                goto out;
-       rc = record_marker(env, llh, fsdb, CM_END, lovname, comment);
+       rc = record_marker(env, llh, fsdb, CM_END, tgtname, comment);
 out:
        record_end_log(env, &llh);
         return rc;
 }
 
+int mgs_nodemap_cmd(const struct lu_env *env, struct mgs_device *mgs,
+                   enum lcfg_command_type cmd, const char *nodemap_name,
+                   const char *param)
+{
+       int rc = 0;
+       ENTRY;
+
+       switch (cmd) {
+       case LCFG_NODEMAP_ADD:
+               rc = nodemap_add(nodemap_name);
+               break;
+       case LCFG_NODEMAP_DEL:
+               rc = nodemap_del(nodemap_name);
+               break;
+       default:
+               rc = -EINVAL;
+       }
+
+       RETURN(rc);
+}
+
 int mgs_pool_cmd(const struct lu_env *env, struct mgs_device *mgs,
                 enum lcfg_command_type cmd, char *fsname,
                 char *poolname, char *ostname)
@@ -3887,14 +3985,13 @@ int mgs_pool_cmd(const struct lu_env *env, struct mgs_device *mgs,
                 break;
         }
 
-       mutex_lock(&fsdb->fsdb_mutex);
-
         if (canceled_label != NULL) {
                 OBD_ALLOC_PTR(mti);
                 if (mti == NULL)
                        GOTO(out_cancel, rc = -ENOMEM);
         }
 
+       mutex_lock(&fsdb->fsdb_mutex);
         /* write pool def to all MDT logs */
         for (i = 0; i < INDEX_MAP_SIZE * 8; i++) {
                if (test_bit(i,  fsdb->fsdb_mdt_index_map)) {