Whamcloud - gitweb
LU-17431 nodemap: add function to know if nodemap is on MGS
[fs/lustre-release.git] / lustre / ptlrpc / nodemap_internal.h
index 5d75fd7..ea76dc5 100644 (file)
@@ -22,7 +22,7 @@
 /*
  * Copyright (C) 2013, Trustees of Indiana University
  *
- * Copyright (c) 2013, 2014, Intel Corporation.
+ * Copyright (c) 2013, 2017, Intel Corporation.
  *
  * Author: Joshua Walgenbach <jjw@iu.edu>
  */
 #define _NODEMAP_INTERNAL_H
 
 #include <lustre_nodemap.h>
-#include <interval_tree.h>
+#include <lustre_disk.h>
+#include <linux/rbtree.h>
 
 #define DEFAULT_NODEMAP "default"
 
-/* Turn on proc debug interface to allow OSS and
- * MDS nodes to configure nodemap independently of
- * MGS (since the nodemap distribution is not written
- * yet */
-#define NODEMAP_PROC_DEBUG 1
-
-/* Default nobody uid and gid values */
-
-#define NODEMAP_NOBODY_UID 99
-#define NODEMAP_NOBODY_GID 99
+/* Default nobody uid, gid and projid values */
+#define NODEMAP_NOBODY_UID 65534
+#define NODEMAP_NOBODY_GID 65534
+#define NODEMAP_NOBODY_PROJID 65534
 
 struct lprocfs_static_vars;
 
@@ -63,8 +58,15 @@ struct lu_nid_range {
        struct lu_nodemap       *rn_nodemap;
        /* list for nodemap */
        struct list_head         rn_list;
+       /* list for nodemap config */
+       struct list_head         rn_collect;
        /* nid interval tree */
-       struct interval_node     rn_node;
+       struct lnet_nid          rn_start,
+                                rn_end;
+       lnet_nid_t               rn_subtree_last;
+       /* Large NID netmask */
+       u8                       rn_netmask;
+       struct rb_node           rn_rb;
 };
 
 struct lu_idmap {
@@ -78,28 +80,6 @@ struct lu_idmap {
        struct rb_node  id_fs_to_client;
 };
 
-/* first 4 bits of the nodemap_id is the index type */
-struct nodemap_key {
-       __u32 nk_nodemap_id;
-       union {
-               __u32 nk_range_id;
-               __u32 nk_id_client;
-               __u32 nk_unused;
-       };
-};
-
-enum nodemap_idx_type {
-       NODEMAP_EMPTY_IDX = 0,          /* index created with blank record */
-       NODEMAP_CLUSTER_IDX = 1,        /* a nodemap cluster of nodes */
-       NODEMAP_RANGE_IDX = 2,          /* nid range assigned to a nm cluster */
-       NODEMAP_UIDMAP_IDX = 3,         /* uid map assigned to a nm cluster */
-       NODEMAP_GIDMAP_IDX = 4,         /* gid map assigned to a nm cluster */
-       NODEMAP_GLOBAL_IDX = 15,        /* stores nodemap activation status */
-};
-
-#define NM_TYPE_MASK 0x0FFFFFFF
-#define NM_TYPE_SHIFT 28
-
 static inline enum nodemap_idx_type nm_idx_get_type(unsigned int id)
 {
        return id >> NM_TYPE_SHIFT;
@@ -122,27 +102,25 @@ void nodemap_procfs_exit(void);
 int lprocfs_nodemap_register(struct lu_nodemap *nodemap,
                             bool is_default_nodemap);
 void lprocfs_nodemap_remove(struct nodemap_pde *nodemap_pde);
-struct lu_nid_range *nodemap_range_find(lnet_nid_t start_nid,
-                                       lnet_nid_t end_nid);
-struct lu_nid_range *range_create(struct nodemap_range_tree *nm_range_tree,
-                                 lnet_nid_t start_nid, lnet_nid_t end_nid,
-                                 struct lu_nodemap *nodemap,
+struct lu_nid_range *range_create(struct nodemap_config *config,
+                                 const struct lnet_nid *start_nid,
+                                 const struct lnet_nid *end_nid,
+                                 u8 netmask, struct lu_nodemap *nodemap,
                                  unsigned int range_id);
 void range_destroy(struct lu_nid_range *range);
-int range_insert(struct nodemap_range_tree *nm_range_tree,
-                struct lu_nid_range *data);
-void range_delete(struct nodemap_range_tree *nm_range_tree,
-                 struct lu_nid_range *data);
-struct lu_nid_range *range_search(struct nodemap_range_tree *nm_range_tree,
-                                 lnet_nid_t nid);
-struct lu_nid_range *range_find(struct nodemap_range_tree *nm_range_tree,
-                               lnet_nid_t start_nid, lnet_nid_t end_nid);
-int range_parse_nidstring(char *range_string, lnet_nid_t *start_nid,
-                         lnet_nid_t *end_nid);
+int range_insert(struct nodemap_config *config, struct lu_nid_range *data);
+void range_delete(struct nodemap_config *config, struct lu_nid_range *data);
+struct lu_nid_range *range_search(struct nodemap_config *config,
+                                 struct lnet_nid *nid);
+struct lu_nid_range *range_find(struct nodemap_config *config,
+                               const struct lnet_nid *start_nid,
+                               const struct lnet_nid *end_nid,
+                               u8 netmask);
 void range_init_tree(void);
 struct lu_idmap *idmap_create(__u32 client_id, __u32 fs_id);
-void idmap_insert(enum nodemap_id_type id_type, struct lu_idmap *idmap,
-                struct lu_nodemap *nodemap);
+struct lu_idmap *idmap_insert(enum nodemap_id_type id_type,
+                             struct lu_idmap *idmap,
+                             struct lu_nodemap *nodemap);
 void idmap_delete(enum nodemap_id_type id_type,  struct lu_idmap *idmap,
                  struct lu_nodemap *nodemap);
 void idmap_delete_tree(struct lu_nodemap *nodemap);
@@ -153,7 +131,7 @@ struct lu_idmap *idmap_search(struct lu_nodemap *nodemap,
 int nm_member_add(struct lu_nodemap *nodemap, struct obd_export *exp);
 void nm_member_del(struct lu_nodemap *nodemap, struct obd_export *exp);
 void nm_member_delete_list(struct lu_nodemap *nodemap);
-struct lu_nodemap *nodemap_classify_nid(lnet_nid_t nid);
+struct lu_nodemap *nodemap_classify_nid(struct lnet_nid *nid);
 void nm_member_reclassify_nodemap(struct lu_nodemap *nodemap);
 void nm_member_revoke_locks(struct lu_nodemap *nodemap);
 void nm_member_revoke_locks_always(struct lu_nodemap *nodemap);
@@ -164,42 +142,32 @@ int nodemap_add_idmap_helper(struct lu_nodemap *nodemap,
                             const __u32 map[2]);
 int nodemap_add_range_helper(struct nodemap_config *config,
                             struct lu_nodemap *nodemap,
-                            const lnet_nid_t nid[2],
-                            unsigned int range_id);
+                            const struct lnet_nid nid[2],
+                            u8 netmask, unsigned int range_id);
 
-struct rb_node *nm_rb_next_postorder(const struct rb_node *node);
-struct rb_node *nm_rb_first_postorder(const struct rb_root *root);
 void nodemap_getref(struct lu_nodemap *nodemap);
 void nodemap_putref(struct lu_nodemap *nodemap);
 int nm_hash_list_cb(struct cfs_hash *hs, struct cfs_hash_bd *bd,
                    struct hlist_node *hnode,
                    void *nodemap_list_head);
 
-#define nm_rbtree_postorder_for_each_entry_safe(pos, n,                        \
-                                               root, field)            \
-       for (pos = nm_rb_first_postorder(root) ?                        \
-               rb_entry(nm_rb_first_postorder(root), typeof(*pos),     \
-               field) : NULL,                                          \
-               n = (pos && nm_rb_next_postorder(&pos->field)) ?        \
-               rb_entry(nm_rb_next_postorder(&pos->field),             \
-               typeof(*pos), field) : NULL;                            \
-               pos != NULL;                                            \
-               pos = n,                                                \
-               n = (pos && nm_rb_next_postorder(&pos->field)) ?        \
-               rb_entry(nm_rb_next_postorder(&pos->field),             \
-               typeof(*pos), field) : NULL)
-
+bool nodemap_mgs(void);
 int nodemap_idx_nodemap_add(const struct lu_nodemap *nodemap);
 int nodemap_idx_nodemap_update(const struct lu_nodemap *nodemap);
 int nodemap_idx_nodemap_del(const struct lu_nodemap *nodemap);
+int nodemap_idx_cluster_roles_add(const struct lu_nodemap *nodemap);
+int nodemap_idx_cluster_roles_update(const struct lu_nodemap *nodemap);
+int nodemap_idx_cluster_roles_del(const struct lu_nodemap *nodemap);
 int nodemap_idx_idmap_add(const struct lu_nodemap *nodemap,
                          enum nodemap_id_type id_type,
                          const __u32 map[2]);
 int nodemap_idx_idmap_del(const struct lu_nodemap *nodemap,
                          enum nodemap_id_type id_type,
                          const __u32 map[2]);
-int nodemap_idx_range_add(const struct lu_nid_range *range,
-                         const lnet_nid_t nid[2]);
+int nodemap_idx_range_add(const struct lu_nid_range *range);
 int nodemap_idx_range_del(const struct lu_nid_range *range);
 int nodemap_idx_nodemap_activate(bool value);
+int nodemap_index_read(struct lu_env *env, struct nm_config_file *ncf,
+                      struct idx_info *ii, const struct lu_rdpg *rdpg);
+
 #endif  /* _NODEMAP_INTERNAL_H */