down_read(&active_config->nmc_range_tree_lock);
nm_member_reclassify_nodemap(nodemap);
up_read(&active_config->nmc_range_tree_lock);
- mutex_unlock(&active_config_lock);
-
- if (!list_empty(&nodemap->nm_member_list))
- CWARN("nodemap_destroy failed to reclassify all members\n");
write_lock(&nodemap->nm_idmap_lock);
idmap_delete_tree(nodemap);
write_unlock(&nodemap->nm_idmap_lock);
+ mutex_unlock(&active_config_lock);
+
+ if (!list_empty(&nodemap->nm_member_list))
+ CWARN("nodemap_destroy failed to reclassify all members\n");
+
nm_member_delete_list(nodemap);
OBD_FREE_PTR(nodemap);
* \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)
else
nodemap = active_config->nmc_default_nodemap;
+ LASSERT(nodemap != NULL);
nodemap_getref(nodemap);
- return nodemap;
+ RETURN(nodemap);
}
/**
* \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;
+ RETURN(rc);
}
EXPORT_SYMBOL(nodemap_add_member);
EXPORT_SYMBOL(nodemap_del_range);
/**
+ * set fileset on nodemap
+ * \param name nodemap to set fileset on
+ * \param fileset string containing fileset
+ * \retval 0 on success
+ *
+ * set a fileset on the named nodemap
+ */
+static int nodemap_set_fileset_helper(struct nodemap_config *config,
+ struct lu_nodemap *nodemap,
+ const char *fileset)
+{
+ int rc = 0;
+
+ /* we allow fileset = "" which means clear fileset info */
+ if (fileset == NULL || (fileset[0] != 0 && fileset[0] != '/'))
+ rc = -EINVAL;
+ else if (strlcpy(nodemap->nm_fileset, fileset,
+ sizeof(nodemap->nm_fileset)) >=
+ sizeof(nodemap->nm_fileset))
+ rc = -ENAMETOOLONG;
+
+ return rc;
+}
+
+int nodemap_set_fileset(const char *name, const char *fileset)
+{
+ struct lu_nodemap *nodemap = NULL;
+ int rc = 0;
+
+ mutex_lock(&active_config_lock);
+ nodemap = nodemap_lookup(name);
+ if (IS_ERR(nodemap)) {
+ mutex_unlock(&active_config_lock);
+ GOTO(out, rc = PTR_ERR(nodemap));
+ }
+
+ if (is_default_nodemap(nodemap))
+ rc = -EINVAL;
+ else
+ rc = nodemap_set_fileset_helper(active_config, nodemap,
+ fileset);
+ mutex_unlock(&active_config_lock);
+
+ nodemap_putref(nodemap);
+out:
+ return rc;
+}
+EXPORT_SYMBOL(nodemap_set_fileset);
+
+/**
+ * get fileset defined on nodemap
+ * \param nodemap nodemap to get fileset from
+ * \retval fileset name, or NULL if not defined or not activated
+ *
+ * get the fileset defined on the nodemap
+ */
+char *nodemap_get_fileset(const struct lu_nodemap *nodemap)
+{
+ if (!nodemap_active || is_default_nodemap(nodemap))
+ return NULL;
+ else
+ return (char *)nodemap->nm_fileset;
+}
+EXPORT_SYMBOL(nodemap_get_fileset);
+
+/**
* Nodemap constructor
*
* Creates an lu_nodemap structure and assigns sane default
nodemap->nm_squash_uid = default_nodemap->nm_squash_uid;
nodemap->nm_squash_gid = default_nodemap->nm_squash_gid;
+ nodemap->nm_fileset[0] = 0;
}
return nodemap;
ENTRY;
LASSERT(active_config != config);
+ LASSERT(config->nmc_default_nodemap);
mutex_lock(&active_config_lock);
EXIT;
}
-EXPORT_SYMBOL(nodemap_config_set_active);
/**
* Cleanup nodemap module on exit
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';
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);
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);