Whamcloud - gitweb
LU-11961 nodemap: nodemap_create() handles default nodemap
[fs/lustre-release.git] / lustre / ptlrpc / nodemap_storage.c
index 4855df7..0a7602e 100644 (file)
@@ -22,7 +22,7 @@
 /*
  * Copyright (C) 2015, Trustees of Indiana University
  *
- * Copyright (c) 2014, Intel Corporation.
+ * Copyright (c) 2017, Intel Corporation.
  *
  * Author: Joshua Walgenbach <jjw@iu.edu>
  * Author: Kit Westneat <cwestnea@iu.edu>
@@ -50,8 +50,8 @@
 #include <linux/mutex.h>
 #include <linux/string.h>
 #include <linux/types.h>
-#include <lnet/types.h>
-#include <lustre/lustre_idl.h>
+#include <uapi/linux/lnet/lnet-types.h>
+#include <uapi/linux/lustre/lustre_idl.h>
 #include <dt_object.h>
 #include <lu_object.h>
 #include <lustre_net.h>
@@ -72,6 +72,9 @@ enum nm_flag_shifts {
        NM_FL_ALLOW_ROOT_ACCESS = 0x1,
        NM_FL_TRUST_CLIENT_IDS = 0x2,
        NM_FL_DENY_UNKNOWN = 0x4,
+       NM_FL_MAP_UID_ONLY = 0x8,
+       NM_FL_MAP_GID_ONLY = 0x10,
+       NM_FL_ENABLE_AUDIT = 0x20,
 };
 
 static void nodemap_cluster_key_init(struct nodemap_key *nk, unsigned int nm_id)
@@ -84,9 +87,9 @@ static void nodemap_cluster_key_init(struct nodemap_key *nk, unsigned int nm_id)
 static void nodemap_cluster_rec_init(union nodemap_rec *nr,
                                     const struct lu_nodemap *nodemap)
 {
-       CLASSERT(sizeof(nr->ncr.ncr_name) == sizeof(nodemap->nm_name));
+       BUILD_BUG_ON(sizeof(nr->ncr.ncr_name) != sizeof(nodemap->nm_name));
 
-       strncpy(nr->ncr.ncr_name, nodemap->nm_name, sizeof(nodemap->nm_name));
+       strncpy(nr->ncr.ncr_name, nodemap->nm_name, sizeof(nr->ncr.ncr_name));
        nr->ncr.ncr_squash_uid = cpu_to_le32(nodemap->nm_squash_uid);
        nr->ncr.ncr_squash_gid = cpu_to_le32(nodemap->nm_squash_gid);
        nr->ncr.ncr_flags = cpu_to_le32(
@@ -95,7 +98,13 @@ static void nodemap_cluster_rec_init(union nodemap_rec *nr,
                (nodemap->nmf_allow_root_access ?
                        NM_FL_ALLOW_ROOT_ACCESS : 0) |
                (nodemap->nmf_deny_unknown ?
-                       NM_FL_DENY_UNKNOWN : 0));
+                       NM_FL_DENY_UNKNOWN : 0) |
+               (nodemap->nmf_map_uid_only ?
+                       NM_FL_MAP_UID_ONLY : 0) |
+               (nodemap->nmf_map_gid_only ?
+                       NM_FL_MAP_GID_ONLY : 0) |
+               (nodemap->nmf_enable_audit ?
+                       NM_FL_ENABLE_AUDIT : 0));
 }
 
 static void nodemap_idmap_key_init(struct nodemap_key *nk, unsigned int nm_id,
@@ -213,7 +222,7 @@ again:
                 * rewrite the config
                 */
                if (rc < 0) {
-                       lu_object_put(env, &nm_obj->do_lu);
+                       dt_object_put(env, nm_obj);
 
                        if (create_new == NCFC_CREATE_NEW)
                                GOTO(out_root, nm_obj = ERR_PTR(rc));
@@ -226,7 +235,7 @@ again:
        }
 
 out_root:
-       lu_object_put(env, &root_obj->do_lu);
+       dt_object_put(env, root_obj);
 out:
        return nm_obj;
 }
@@ -236,11 +245,11 @@ static int nodemap_idx_insert(const struct lu_env *env,
                              const struct nodemap_key *nk,
                              const union nodemap_rec *nr)
 {
-       struct thandle          *th;
-       struct dt_device        *dev = lu2dt_dev(idx->do_lu.lo_dev);
-       int                      rc;
+       struct thandle *th;
+       struct dt_device *dev = lu2dt_dev(idx->do_lu.lo_dev);
+       int rc;
 
-       CLASSERT(sizeof(union nodemap_rec) == 32);
+       BUILD_BUG_ON(sizeof(union nodemap_rec) != 32);
 
        th = dt_trans_create(env, dev);
 
@@ -264,7 +273,7 @@ static int nodemap_idx_insert(const struct lu_env *env,
        dt_write_lock(env, idx, 0);
 
        rc = dt_insert(env, idx, (const struct dt_rec *)nr,
-                      (const struct dt_key *)nk, th, 1);
+                      (const struct dt_key *)nk, th);
 
        nodemap_inc_version(env, idx, th);
        dt_write_unlock(env, idx);
@@ -312,7 +321,7 @@ static int nodemap_idx_update(const struct lu_env *env,
                GOTO(out_lock, rc);
 
        rc = dt_insert(env, idx, (const struct dt_rec *)nr,
-                      (const struct dt_key *)nk, th, 1);
+                      (const struct dt_key *)nk, th);
        if (rc != 0)
                GOTO(out_lock, rc);
 
@@ -651,18 +660,18 @@ static int nodemap_process_keyrec(struct nodemap_config *config,
                                  const union nodemap_rec *rec,
                                  struct lu_nodemap **recent_nodemap)
 {
-       struct lu_nodemap       *nodemap = NULL;
-       enum nodemap_idx_type    type;
-       enum nodemap_id_type     id_type;
-       u8                       flags;
-       u32                      nodemap_id;
-       lnet_nid_t               nid[2];
-       u32                      map[2];
-       int                      rc;
+       struct lu_nodemap *nodemap = NULL;
+       enum nodemap_idx_type type;
+       enum nodemap_id_type id_type;
+       u8 flags;
+       u32 nodemap_id;
+       lnet_nid_t nid[2];
+       u32 map[2];
+       int rc;
 
        ENTRY;
 
-       CLASSERT(sizeof(union nodemap_rec) == 32);
+       BUILD_BUG_ON(sizeof(union nodemap_rec) != 32);
 
        nodemap_id = le32_to_cpu(key->nk_nodemap_id);
        type = nodemap_get_key_type(key);
@@ -704,14 +713,15 @@ static int nodemap_process_keyrec(struct nodemap_config *config,
                              " nodemap_id=%d. nodemap config file corrupt?\n",
                              nodemap_id);
                break;
-       case NODEMAP_CLUSTER_IDX:
+       case NODEMAP_CLUSTER_IDX: {
+               struct lu_nodemap *old_nm = NULL;
+
                nodemap = cfs_hash_lookup(config->nmc_nodemap_hash,
                                          rec->ncr.ncr_name);
                if (nodemap == NULL) {
                        if (nodemap_id == LUSTRE_NODEMAP_DEFAULT_ID) {
                                nodemap = nodemap_create(rec->ncr.ncr_name,
                                                         config, 1);
-                               config->nmc_default_nodemap = nodemap;
                        } else {
                                nodemap = nodemap_create(rec->ncr.ncr_name,
                                                         config, 0);
@@ -741,6 +751,23 @@ static int nodemap_process_keyrec(struct nodemap_config *config,
                                        flags & NM_FL_TRUST_CLIENT_IDS;
                nodemap->nmf_deny_unknown =
                                        flags & NM_FL_DENY_UNKNOWN;
+               nodemap->nmf_map_uid_only =
+                                       flags & NM_FL_MAP_UID_ONLY;
+               nodemap->nmf_map_gid_only =
+                                       flags & NM_FL_MAP_GID_ONLY;
+               nodemap->nmf_enable_audit =
+                                       flags & NM_FL_ENABLE_AUDIT;
+
+               /* The fileset should be saved otherwise it will be empty
+                * every time in case of "NODEMAP_CLUSTER_IDX". */
+               mutex_lock(&active_config_lock);
+               old_nm = nodemap_lookup(rec->ncr.ncr_name);
+               if (!IS_ERR(old_nm) && old_nm->nm_fileset[0] != '\0')
+                       strlcpy(nodemap->nm_fileset, old_nm->nm_fileset,
+                               sizeof(nodemap->nm_fileset));
+               mutex_unlock(&active_config_lock);
+               if (!IS_ERR(old_nm))
+                       nodemap_putref(old_nm);
 
                if (*recent_nodemap == NULL) {
                        *recent_nodemap = nodemap;
@@ -751,6 +778,7 @@ static int nodemap_process_keyrec(struct nodemap_config *config,
                }
                nodemap_putref(nodemap);
                break;
+       }
        case NODEMAP_RANGE_IDX:
                nid[0] = le64_to_cpu(rec->nrr.nrr_start_nid);
                nid[1] = le64_to_cpu(rec->nrr.nrr_end_nid);
@@ -908,10 +936,10 @@ out:
 
        if (new_config->nmc_default_nodemap == NULL) {
                /* new MGS won't have a default nm on disk, so create it here */
-               new_config->nmc_default_nodemap =
+               struct lu_nodemap *nodemap =
                        nodemap_create(DEFAULT_NODEMAP, new_config, 1);
-               if (IS_ERR(new_config->nmc_default_nodemap)) {
-                       rc = PTR_ERR(new_config->nmc_default_nodemap);
+               if (IS_ERR(nodemap)) {
+                       rc = PTR_ERR(nodemap);
                } else {
                        rc = nodemap_idx_nodemap_add_update(
                                        new_config->nmc_default_nodemap,
@@ -1032,7 +1060,7 @@ struct dt_object *nodemap_save_config_cache(const struct lu_env *env,
        mutex_unlock(&active_config_lock);
 
        if (rc < 0) {
-               lu_object_put(env, &o->do_lu);
+               dt_object_put(env, o);
                o = ERR_PTR(rc);
        }
 
@@ -1059,7 +1087,7 @@ static void nodemap_save_all_caches(void)
                struct dt_object *o;
 
                /* put current config file so save conf can rewrite it */
-               lu_object_put_nocache(&env, &ncf->ncf_obj->do_lu);
+               dt_object_put_nocache(&env, ncf->ncf_obj);
                ncf->ncf_obj = NULL;
 
                o = nodemap_save_config_cache(&env, dev, ncf->ncf_los);
@@ -1214,7 +1242,7 @@ void nm_config_file_deregister_mgs(const struct lu_env *env,
 
        nodemap_mgs_ncf = NULL;
        if (ncf->ncf_obj)
-               lu_object_put(env, &ncf->ncf_obj->do_lu);
+               dt_object_put(env, ncf->ncf_obj);
 
        OBD_FREE_PTR(ncf);
 
@@ -1235,7 +1263,7 @@ void nm_config_file_deregister_tgt(const struct lu_env *env,
        mutex_unlock(&ncf_list_lock);
 
        if (ncf->ncf_obj)
-               lu_object_put(env, &ncf->ncf_obj->do_lu);
+               dt_object_put(env, ncf->ncf_obj);
 
        OBD_FREE_PTR(ncf);
 
@@ -1431,12 +1459,12 @@ EXPORT_SYMBOL(nodemap_index_read);
 int nodemap_get_config_req(struct obd_device *mgs_obd,
                           struct ptlrpc_request *req)
 {
+       const struct ptlrpc_bulk_frag_ops *frag_ops = &ptlrpc_bulk_kiov_pin_ops;
        struct mgs_config_body *body;
        struct mgs_config_res *res;
        struct lu_rdpg rdpg;
        struct idx_info nodemap_ii;
        struct ptlrpc_bulk_desc *desc;
-       struct l_wait_info lwi;
        struct tg_export_data *rqexp_ted = &req->rq_export->exp_target_data;
        int i;
        int page_count;
@@ -1494,18 +1522,17 @@ int nodemap_get_config_req(struct obd_device *mgs_obd,
        desc = ptlrpc_prep_bulk_exp(req, page_count, 1,
                                    PTLRPC_BULK_PUT_SOURCE |
                                        PTLRPC_BULK_BUF_KIOV,
-                                   MGS_BULK_PORTAL,
-                                   &ptlrpc_bulk_kiov_pin_ops);
+                                   MGS_BULK_PORTAL, frag_ops);
        if (desc == NULL)
                GOTO(out, rc = -ENOMEM);
 
        for (i = 0; i < page_count && bytes > 0; i++) {
-               ptlrpc_prep_bulk_page_pin(desc, rdpg.rp_pages[i], 0,
-                                         min_t(int, bytes, PAGE_SIZE));
+               frag_ops->add_kiov_frag(desc, rdpg.rp_pages[i], 0,
+                                       min_t(int, bytes, PAGE_SIZE));
                bytes -= PAGE_SIZE;
        }
 
-       rc = target_bulk_io(req->rq_export, desc, &lwi);
+       rc = target_bulk_io(req->rq_export, desc);
        ptlrpc_free_bulk(desc);
 
 out: