Whamcloud - gitweb
LU-8369 nodemap: ignore loopback NID when classifying 60/21160/2
authorKit Westneat <kit.westneat@gmail.com>
Tue, 5 Jul 2016 22:44:50 +0000 (18:44 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Tue, 12 Jul 2016 13:54:19 +0000 (13:54 +0000)
The loopback NID doesn't make sense in the nid range system
currently used by nodemap. In order to add the MGS to a nodemap,
this patch modifies nodemap_classify_nid to use the first non-lo nid
if it is given the loopback nid.

Signed-off-by: Kit Westneat <kit.westneat@gmail.com>
Change-Id: Iea91a54a14021e478782eedb28ae1a6c3e62d38c
Reviewed-on: http://review.whamcloud.com/21160
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/include/lustre_nodemap.h
lustre/mgs/mgs_handler.c
lustre/ptlrpc/nodemap_handler.c
lustre/ptlrpc/nodemap_member.c

index db10bda..3729253 100644 (file)
@@ -138,8 +138,8 @@ void nodemap_test_nid(lnet_nid_t nid, char *name_buf, size_t name_len);
 #else
 #define nodemap_test_nid(nid, name_buf, name_len) do {} while(0)
 #endif
-__u32 nodemap_test_id(lnet_nid_t nid, enum nodemap_id_type idtype,
-                     __u32 client_id);
+int nodemap_test_id(lnet_nid_t nid, enum nodemap_id_type idtype,
+                   __u32 client_id, __u32 *fs_id);
 
 enum nm_config_file_type {
        NCFT_MGS,
index c4ce666..06f5a08 100644 (file)
@@ -736,7 +736,9 @@ static int mgs_iocontrol_nodemap(const struct lu_env *env,
                if (rc != 0)
                        GOTO(out_lcfg, rc = -EINVAL);
 
-               fs_id = nodemap_test_id(nid, idtype, client_id);
+               rc = nodemap_test_id(nid, idtype, client_id, &fs_id);
+               if (rc < 0)
+                       GOTO(out_lcfg, rc = -EINVAL);
 
                if (data->ioc_plen1 < sizeof(fs_idstr))
                        GOTO(out_lcfg, rc = -EINVAL);
index 1c99301..e4f1124 100644 (file)
@@ -253,11 +253,30 @@ struct lu_nodemap *nodemap_lookup(const char *name)
  * \param      nid                     nid to classify
  * \retval     nodemap                 nodemap containing the nid
  * \retval     default_nodemap         default nodemap
+ * \retval     -EINVAL                 LO nid given without other local nid
  */
 struct lu_nodemap *nodemap_classify_nid(lnet_nid_t nid)
 {
        struct lu_nid_range     *range;
        struct lu_nodemap       *nodemap;
+       int rc;
+
+       ENTRY;
+
+       /* don't use 0@lo, use the first non-lo local NID instead */
+       if (LNET_NETTYP(LNET_NIDNET(nid)) == LOLND) {
+               lnet_process_id_t id;
+               int i = 0;
+
+               do {
+                       rc = LNetGetId(i++, &id);
+                       if (rc < 0)
+                               RETURN(ERR_PTR(-EINVAL));
+               } while (LNET_NETTYP(LNET_NIDNET(id.nid)) == LOLND);
+
+               nid = id.nid;
+               CDEBUG(D_INFO, "found nid %s\n", libcfs_nid2str(nid));
+       }
 
        range = range_search(&active_config->nmc_range_tree, nid);
        if (range != NULL)
@@ -268,7 +287,7 @@ struct lu_nodemap *nodemap_classify_nid(lnet_nid_t nid)
        LASSERT(nodemap != NULL);
        nodemap_getref(nodemap);
 
-       return nodemap;
+       RETURN(nodemap);
 }
 
 /**
@@ -356,25 +375,33 @@ EXPORT_SYMBOL(nodemap_parse_idmap);
  * \param      nid             nid to add to the members
  * \param      exp             obd_export structure for the connection
  *                             that is being added
- * \retval     -EINVAL         export is NULL
+ * \retval     -EINVAL         export is NULL, or has invalid NID
  * \retval     -EEXIST         export is already member of a nodemap
  */
 int nodemap_add_member(lnet_nid_t nid, struct obd_export *exp)
 {
        struct lu_nodemap *nodemap;
-       int rc;
+       int rc = 0;
        ENTRY;
 
        mutex_lock(&active_config_lock);
        down_read(&active_config->nmc_range_tree_lock);
 
        nodemap = nodemap_classify_nid(nid);
-       rc = nm_member_add(nodemap, exp);
+
+       if (IS_ERR(nodemap)) {
+               CWARN("%s: error adding to nodemap, no valid NIDs found\n",
+                         exp->exp_obd->obd_name);
+               rc = -EINVAL;
+       } else {
+               rc = nm_member_add(nodemap, exp);
+       }
 
        up_read(&active_config->nmc_range_tree_lock);
        mutex_unlock(&active_config_lock);
 
-       nodemap_putref(nodemap);
+       if (!IS_ERR(nodemap))
+               nodemap_putref(nodemap);
 
        RETURN(rc);
 }
@@ -1477,6 +1504,9 @@ void nodemap_test_nid(lnet_nid_t nid, char *name_buf, size_t name_len)
        up_read(&active_config->nmc_range_tree_lock);
        mutex_unlock(&active_config_lock);
 
+       if (IS_ERR(nodemap))
+               return;
+
        strncpy(name_buf, nodemap->nm_name, name_len);
        if (name_len > 0)
                name_buf[name_len - 1] = '\0';
@@ -1486,20 +1516,21 @@ void nodemap_test_nid(lnet_nid_t nid, char *name_buf, size_t name_len)
 EXPORT_SYMBOL(nodemap_test_nid);
 
 /**
- * Returns the id mapping for a given nid/id pair. Useful for testing the
+ * Passes back the id mapping for a given nid/id pair. Useful for testing the
  * nodemap configuration to make sure it is working as expected.
  *
  * \param      nid             nid to classify
  * \param      idtype          uid or gid
  * \param      client_id       id to map to fs
+ * \param      fs_id_buf       pointer to save mapped fs_id to
  *
- * \retval     the mapped fs_id of the given client_id
+ * \retval     0       success
+ * \retval     -EINVAL invalid NID
  */
-__u32 nodemap_test_id(lnet_nid_t nid, enum nodemap_id_type idtype,
-                     __u32 client_id)
+int nodemap_test_id(lnet_nid_t nid, enum nodemap_id_type idtype,
+                   __u32 client_id, __u32 *fs_id)
 {
        struct lu_nodemap       *nodemap;
-       __u32                    fs_id;
 
        mutex_lock(&active_config_lock);
        down_read(&active_config->nmc_range_tree_lock);
@@ -1507,10 +1538,13 @@ __u32 nodemap_test_id(lnet_nid_t nid, enum nodemap_id_type idtype,
        up_read(&active_config->nmc_range_tree_lock);
        mutex_unlock(&active_config_lock);
 
-       fs_id = nodemap_map_id(nodemap, idtype, NODEMAP_CLIENT_TO_FS,
+       if (IS_ERR(nodemap))
+               return PTR_ERR(nodemap);
+
+       *fs_id = nodemap_map_id(nodemap, idtype, NODEMAP_CLIENT_TO_FS,
                               client_id);
        nodemap_putref(nodemap);
 
-       return fs_id;
+       return 0;
 }
 EXPORT_SYMBOL(nodemap_test_id);
index ce97c47..5070807 100644 (file)
@@ -190,6 +190,8 @@ void nm_member_reclassify_nodemap(struct lu_nodemap *nodemap)
 
                /* nodemap_classify_nid requires nmc_range_tree_lock */
                new_nodemap = nodemap_classify_nid(nid);
+               if (IS_ERR(new_nodemap))
+                       continue;
 
                if (new_nodemap != nodemap) {
                        /* could deadlock if new_nodemap also reclassifying,