Whamcloud - gitweb
LU-11085 nodemap: switch interval tree to in-kernel impl.
[fs/lustre-release.git] / lustre / ptlrpc / nodemap_handler.c
index 6cea792..5fc80bf 100644 (file)
@@ -257,14 +257,14 @@ struct lu_nodemap *nodemap_lookup(const char *name)
  */
 struct lu_nodemap *nodemap_classify_nid(lnet_nid_t nid)
 {
-       struct lu_nid_range     *range;
-       struct lu_nodemap       *nodemap;
+       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) {
+       if (nid == LNET_NID_LO_0) {
                struct lnet_process_id id;
                int i = 0;
 
@@ -272,7 +272,7 @@ struct lu_nodemap *nodemap_classify_nid(lnet_nid_t nid)
                        rc = LNetGetId(i++, &id);
                        if (rc < 0)
                                RETURN(ERR_PTR(-EINVAL));
-               } while (LNET_NETTYP(LNET_NIDNET(id.nid)) == LOLND);
+               } while (id.nid == LNET_NID_LO_0);
 
                nid = id.nid;
                CDEBUG(D_INFO, "found nid %s\n", libcfs_nid2str(nid));
@@ -1129,9 +1129,8 @@ struct lu_nodemap *nodemap_create(const char *name,
 
        OBD_ALLOC_PTR(nodemap);
        if (nodemap == NULL) {
-               CERROR("cannot allocate memory (%zu bytes)"
-                      "for nodemap '%s'\n", sizeof(*nodemap),
-                      name);
+               CERROR("cannot allocate memory (%zu bytes) for nodemap '%s'\n",
+                      sizeof(*nodemap), name);
                GOTO(out, rc = -ENOMEM);
        }
 
@@ -1173,6 +1172,7 @@ struct lu_nodemap *nodemap_create(const char *name,
                nodemap->nmf_map_uid_only = 0;
                nodemap->nmf_map_gid_only = 0;
                nodemap->nmf_enable_audit = 1;
+               nodemap->nmf_forbid_encryption = 0;
 
                nodemap->nm_squash_uid = NODEMAP_NOBODY_UID;
                nodemap->nm_squash_gid = NODEMAP_NOBODY_GID;
@@ -1194,6 +1194,8 @@ struct lu_nodemap *nodemap_create(const char *name,
                                default_nodemap->nmf_map_gid_only;
                nodemap->nmf_enable_audit =
                        default_nodemap->nmf_enable_audit;
+               nodemap->nmf_forbid_encryption =
+                       default_nodemap->nmf_forbid_encryption;
 
                nodemap->nm_squash_uid = default_nodemap->nm_squash_uid;
                nodemap->nm_squash_gid = default_nodemap->nm_squash_gid;
@@ -1435,6 +1437,34 @@ out:
 }
 EXPORT_SYMBOL(nodemap_set_audit_mode);
 
+/**
+ * Set the nmf_forbid_encryption flag to true or false.
+ * \param      name                    nodemap name
+ * \param      forbid_encryption       if true, forbid encryption
+ * \retval     0 on success
+ *
+ */
+int nodemap_set_forbid_encryption(const char *name, bool forbid_encryption)
+{
+       struct lu_nodemap       *nodemap = NULL;
+       int                     rc = 0;
+
+       mutex_lock(&active_config_lock);
+       nodemap = nodemap_lookup(name);
+       mutex_unlock(&active_config_lock);
+       if (IS_ERR(nodemap))
+               GOTO(out, rc = PTR_ERR(nodemap));
+
+       nodemap->nmf_forbid_encryption = forbid_encryption;
+       rc = nodemap_idx_nodemap_update(nodemap);
+
+       nm_member_revoke_locks(nodemap);
+       nodemap_putref(nodemap);
+out:
+       return rc;
+}
+EXPORT_SYMBOL(nodemap_set_forbid_encryption);
+
 
 /**
  * Add a nodemap
@@ -1592,6 +1622,8 @@ struct nodemap_config *nodemap_config_alloc(void)
 
        init_rwsem(&config->nmc_range_tree_lock);
 
+       config->nmc_range_tree.nmrt_range_interval_root = INTERVAL_TREE_ROOT;
+
        return config;
 }
 EXPORT_SYMBOL(nodemap_config_alloc);