*/
/*
* Copyright (C) 2013, Trustees of Indiana University
+ *
+ * Copyright (c) 2013, 2014, Intel Corporation.
+ *
* Author: Joshua Walgenbach <jjw@iu.edu>
*/
#include <lustre_nodemap.h>
#include <interval_tree.h>
-#define MODULE_STRING "nodemap"
+#define DEFAULT_NODEMAP "default"
/* Default nobody uid and gid values */
extern struct proc_dir_entry *proc_lustre_nodemap_root;
/* flag if nodemap is active */
extern bool nodemap_active;
-/* lock for range interval tree, used in nodemap_lproc.c */
-extern rwlock_t nm_range_tree_lock;
+
+extern struct mutex active_config_lock;
+extern struct nodemap_config *active_config;
struct lu_nid_range {
- /* unique id set my mgs */
+ /* unique id set by mgs */
unsigned int rn_id;
/* lu_nodemap containing this range */
struct lu_nodemap *rn_nodemap;
struct rb_node id_fs_to_client;
};
+struct nodemap_range_tree {
+ struct interval_node *nmrt_range_interval_root;
+ unsigned int nmrt_range_highest_id;
+};
+
+struct nodemap_config {
+ /* Highest numerical lu_nodemap.nm_id defined */
+ unsigned int nmc_nodemap_highest_id;
+
+ /* Simple flag to determine if nodemaps are active */
+ bool nmc_nodemap_is_active;
+
+ /* Pointer to default nodemap as it is needed more often */
+ struct lu_nodemap *nmc_default_nodemap;
+
+ /**
+ * Lock required to access the range tree.
+ */
+ struct rw_semaphore nmc_range_tree_lock;
+ struct nodemap_range_tree nmc_range_tree;
+
+ /**
+ * Hash keyed on nodemap name containing all
+ * nodemaps
+ */
+ struct cfs_hash *nmc_nodemap_hash;
+};
+
+/* 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;
+}
+
+static inline __u32 nm_idx_set_type(unsigned int id, enum nodemap_idx_type t)
+{
+ return (id & NM_TYPE_MASK) | (t << NM_TYPE_SHIFT);
+}
+
+struct nodemap_config *nodemap_config_alloc(void);
+void nodemap_config_dealloc(struct nodemap_config *config);
+void nodemap_config_set_active(struct nodemap_config *config);
+struct lu_nodemap *nodemap_create(const char *name,
+ struct nodemap_config *config,
+ bool is_default);
+void nodemap_putref(struct lu_nodemap *nodemap);
+struct lu_nodemap *nodemap_lookup(const char *name);
+
int nodemap_procfs_init(void);
-int lprocfs_nodemap_register(const char *name, bool is_default_nodemap,
- struct lu_nodemap *nodemap);
-struct lu_nid_range *range_create(lnet_nid_t min, lnet_nid_t max,
- struct lu_nodemap *nodemap);
+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,
+ unsigned int range_id);
void range_destroy(struct lu_nid_range *range);
-int range_insert(struct lu_nid_range *data);
-void range_delete(struct lu_nid_range *data);
-struct lu_nid_range *range_search(lnet_nid_t nid);
-struct lu_nid_range *range_find(lnet_nid_t start_nid, lnet_nid_t end_nid);
+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);
void range_init_tree(void);
enum nodemap_tree_type,
enum nodemap_id_type id_type,
__u32 id);
-int nodemap_cleanup_nodemaps(void);
-int nm_member_init_hash(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_hash(struct lu_nodemap *nodemap);
+void nm_member_delete_list(struct lu_nodemap *nodemap);
+struct lu_nodemap *nodemap_classify_nid(lnet_nid_t nid);
void nm_member_reclassify_nodemap(struct lu_nodemap *nodemap);
void nm_member_revoke_locks(struct lu_nodemap *nodemap);
void nm_member_revoke_all(void);
+int nodemap_add_idmap_helper(struct lu_nodemap *nodemap,
+ enum nodemap_id_type id_type,
+ 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);
+
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_putref(struct lu_nodemap *nodemap);
#define nm_rbtree_postorder_for_each_entry_safe(pos, n, \
root, field) \
n = (pos && nm_rb_next_postorder(&pos->field)) ? \
rb_entry(nm_rb_next_postorder(&pos->field), \
typeof(*pos), field) : NULL)
+
+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_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_del(const struct lu_nid_range *range);
+int nodemap_idx_nodemap_activate(bool value);
#endif /* _NODEMAP_INTERNAL_H */