#include <obd_support.h>
#include "nodemap_internal.h"
-/* list of registered nodemap index files */
+/* list of registered nodemap index files, except MGS */
static LIST_HEAD(ncf_list_head);
static DEFINE_MUTEX(ncf_list_lock);
+/* MGS index is different than others, others are listeners to MGS idx */
+static struct nm_config_file *nodemap_mgs_ncf;
+
/* lu_nodemap flags */
enum nm_flag_shifts {
NM_FL_ALLOW_ROOT_ACCESS = 0x1,
dt_version_set(env, nodemap_idx, ver + 1, th);
}
-static int nodemap_idx_insert(struct lu_env *env,
+static int nodemap_idx_insert(const struct lu_env *env,
struct dt_object *idx,
const struct nodemap_key *nk,
const union nodemap_rec *nr)
return rc;
}
-static int nodemap_idx_update(struct lu_env *env,
+static int nodemap_idx_update(const struct lu_env *env,
struct dt_object *idx,
const struct nodemap_key *nk,
const union nodemap_rec *nr)
return rc;
}
-static int nodemap_idx_delete(struct lu_env *env,
+static int nodemap_idx_delete(const struct lu_env *env,
struct dt_object *idx,
const struct nodemap_key *nk,
const union nodemap_rec *unused)
return rc;
}
-typedef int (*nm_idx_cb_t)(struct lu_env *env,
- struct dt_object *idx,
- const struct nodemap_key *nk,
- const union nodemap_rec *nr);
-
-/**
- * Iterates through all the registered nodemap_config_files and calls the
- * given callback with the ncf as a parameter, as well as the given key and rec.
- *
- * \param cb_f callback function to call
- * \param nk key of the record to act upon
- * \param nr record to act upon, NULL for the delete action
- */
-static int nodemap_idx_action(nm_idx_cb_t cb_f, struct nodemap_key *nk,
- union nodemap_rec *nr)
-{
- struct nm_config_file *ncf;
- struct lu_env env;
- int rc = 0;
- int rc2 = 0;
-
- rc = lu_env_init(&env, LCT_LOCAL);
- if (rc != 0)
- return rc;
-
- mutex_lock(&ncf_list_lock);
- list_for_each_entry(ncf, &ncf_list_head, ncf_list) {
- rc2 = cb_f(&env, ncf->ncf_obj, nk, nr);
- if (rc2 < 0) {
- CWARN("%s: error writing to nodemap config: rc = %d\n",
- ncf->ncf_obj->do_lu.lo_dev->ld_obd->obd_name, rc);
- rc = rc2;
- }
- }
- mutex_unlock(&ncf_list_lock);
- lu_env_fini(&env);
-
- return 0;
-}
-
enum nm_add_update {
NM_ADD = 0,
NM_UPDATE = 1,
static int nodemap_idx_nodemap_add_update(const struct lu_nodemap *nodemap,
enum nm_add_update update)
{
- struct nodemap_key nk;
- union nodemap_rec nr;
+ struct nodemap_key nk;
+ union nodemap_rec nr;
+ struct lu_env env;
int rc = 0;
ENTRY;
+ if (nodemap_mgs_ncf == NULL) {
+ CERROR("cannot add nodemap config to non-existing MGS.\n");
+ return -EINVAL;
+ }
+
+ rc = lu_env_init(&env, LCT_LOCAL);
+ if (rc)
+ RETURN(rc);
+
nodemap_cluster_key_init(&nk, nodemap->nm_id);
nodemap_cluster_rec_init(&nr, nodemap);
if (update == NM_UPDATE)
- rc = nodemap_idx_action(nodemap_idx_update, &nk, &nr);
+ rc = nodemap_idx_update(&env, nodemap_mgs_ncf->ncf_obj,
+ &nk, &nr);
else
- rc = nodemap_idx_action(nodemap_idx_insert, &nk, &nr);
+ rc = nodemap_idx_insert(&env, nodemap_mgs_ncf->ncf_obj,
+ &nk, &nr);
+
+ lu_env_fini(&env);
RETURN(rc);
}
struct lu_nid_range *range;
struct lu_nid_range *range_temp;
struct nodemap_key nk;
+ struct lu_env env;
int rc = 0;
int rc2 = 0;
ENTRY;
+ if (nodemap_mgs_ncf == NULL) {
+ CERROR("cannot add nodemap config to non-existing MGS.\n");
+ return -EINVAL;
+ }
+
+ rc = lu_env_init(&env, LCT_LOCAL);
+ if (rc != 0)
+ RETURN(rc);
+
root = nodemap->nm_fs_to_client_uidmap;
nm_rbtree_postorder_for_each_entry_safe(idmap, temp, &root,
id_fs_to_client) {
nodemap_idmap_key_init(&nk, nodemap->nm_id, NODEMAP_UID,
idmap->id_client);
- rc2 = nodemap_idx_action(nodemap_idx_delete, &nk, NULL);
+ rc2 = nodemap_idx_delete(&env, nodemap_mgs_ncf->ncf_obj,
+ &nk, NULL);
if (rc2 < 0)
rc = rc2;
}
id_client_to_fs) {
nodemap_idmap_key_init(&nk, nodemap->nm_id, NODEMAP_GID,
idmap->id_client);
- rc2 = nodemap_idx_action(nodemap_idx_delete, &nk, NULL);
+ rc2 = nodemap_idx_delete(&env, nodemap_mgs_ncf->ncf_obj,
+ &nk, NULL);
if (rc2 < 0)
rc = rc2;
}
list_for_each_entry_safe(range, range_temp, &nodemap->nm_ranges,
rn_list) {
nodemap_range_key_init(&nk, nodemap->nm_id, range->rn_id);
- rc2 = nodemap_idx_action(nodemap_idx_delete, &nk, NULL);
+ rc2 = nodemap_idx_delete(&env, nodemap_mgs_ncf->ncf_obj,
+ &nk, NULL);
if (rc2 < 0)
rc = rc2;
}
nodemap_cluster_key_init(&nk, nodemap->nm_id);
- rc2 = nodemap_idx_action(nodemap_idx_delete, &nk, NULL);
+ rc2 = nodemap_idx_delete(&env, nodemap_mgs_ncf->ncf_obj, &nk, NULL);
if (rc2 < 0)
rc = rc2;
+ lu_env_fini(&env);
+
RETURN(rc);
}
{
struct nodemap_key nk;
union nodemap_rec nr;
+ struct lu_env env;
+ int rc = 0;
ENTRY;
+ if (nodemap_mgs_ncf == NULL) {
+ CERROR("cannot add nodemap config to non-existing MGS.\n");
+ return -EINVAL;
+ }
+
+ rc = lu_env_init(&env, LCT_LOCAL);
+ if (rc != 0)
+ RETURN(rc);
+
nodemap_range_key_init(&nk, range->rn_nodemap->nm_id, range->rn_id);
nodemap_range_rec_init(&nr, nid);
- RETURN(nodemap_idx_action(nodemap_idx_insert, &nk, &nr));
+ rc = nodemap_idx_insert(&env, nodemap_mgs_ncf->ncf_obj, &nk, &nr);
+ lu_env_fini(&env);
+
+ RETURN(rc);
}
int nodemap_idx_range_del(const struct lu_nid_range *range)
{
struct nodemap_key nk;
+ struct lu_env env;
+ int rc = 0;
ENTRY;
+ if (nodemap_mgs_ncf == NULL) {
+ CERROR("cannot add nodemap config to non-existing MGS.\n");
+ return -EINVAL;
+ }
+
+ rc = lu_env_init(&env, LCT_LOCAL);
+ if (rc != 0)
+ RETURN(rc);
+
nodemap_range_key_init(&nk, range->rn_nodemap->nm_id, range->rn_id);
- RETURN(nodemap_idx_action(nodemap_idx_delete, &nk, NULL));
+ rc = nodemap_idx_delete(&env, nodemap_mgs_ncf->ncf_obj, &nk, NULL);
+ lu_env_fini(&env);
+
+ RETURN(rc);
}
int nodemap_idx_idmap_add(const struct lu_nodemap *nodemap,
{
struct nodemap_key nk;
union nodemap_rec nr;
+ struct lu_env env;
+ int rc = 0;
ENTRY;
+ if (nodemap_mgs_ncf == NULL) {
+ CERROR("cannot add nodemap config to non-existing MGS.\n");
+ return -EINVAL;
+ }
+
+ rc = lu_env_init(&env, LCT_LOCAL);
+ if (rc != 0)
+ RETURN(rc);
+
nodemap_idmap_key_init(&nk, nodemap->nm_id, id_type, map[0]);
nodemap_idmap_rec_init(&nr, map[1]);
- RETURN(nodemap_idx_action(nodemap_idx_insert, &nk, &nr));
+ rc = nodemap_idx_insert(&env, nodemap_mgs_ncf->ncf_obj, &nk, &nr);
+ lu_env_fini(&env);
+
+ RETURN(rc);
}
int nodemap_idx_idmap_del(const struct lu_nodemap *nodemap,
const u32 map[2])
{
struct nodemap_key nk;
+ struct lu_env env;
+ int rc = 0;
ENTRY;
+ if (nodemap_mgs_ncf == NULL) {
+ CERROR("cannot add nodemap config to non-existing MGS.\n");
+ return -EINVAL;
+ }
+
+ rc = lu_env_init(&env, LCT_LOCAL);
+ if (rc != 0)
+ RETURN(rc);
+
nodemap_idmap_key_init(&nk, nodemap->nm_id, id_type, map[0]);
- RETURN(nodemap_idx_action(nodemap_idx_delete, &nk, NULL));
+ rc = nodemap_idx_delete(&env, nodemap_mgs_ncf->ncf_obj, &nk, NULL);
+ lu_env_fini(&env);
+
+ RETURN(rc);
}
static int nodemap_idx_global_add_update(bool value, enum nm_add_update update)
{
struct nodemap_key nk;
union nodemap_rec nr;
+ struct lu_env env;
+ int rc = 0;
ENTRY;
+ if (nodemap_mgs_ncf == NULL) {
+ CERROR("cannot add nodemap config to non-existing MGS.\n");
+ return -EINVAL;
+ }
+
+ rc = lu_env_init(&env, LCT_LOCAL);
+ if (rc != 0)
+ RETURN(rc);
+
nodemap_global_key_init(&nk);
nodemap_global_rec_init(&nr, value);
if (update == NM_UPDATE)
- RETURN(nodemap_idx_action(nodemap_idx_update, &nk, &nr));
+ rc = nodemap_idx_update(&env, nodemap_mgs_ncf->ncf_obj,
+ &nk, &nr);
else
- RETURN(nodemap_idx_action(nodemap_idx_insert, &nk, &nr));
+ rc = nodemap_idx_insert(&env, nodemap_mgs_ncf->ncf_obj,
+ &nk, &nr);
+
+ lu_env_fini(&env);
+
+ RETURN(rc);
}
int nodemap_idx_nodemap_activate(bool value)
CERROR("got keyrec pair for unknown type %d\n", type);
break;
}
+
rc = type;
out:
GOTO(out_iops, rc = 0);
}
- /* acquires active config lock */
new_config = nodemap_config_alloc();
if (IS_ERR(new_config)) {
rc = PTR_ERR(new_config);
}
/* new nodemap config won't have an active/inactive record */
- if (rc == 0 && loaded_global_idx == false)
- rc = nodemap_idx_global_add_update(false, NM_ADD);
+ if (rc == 0 && loaded_global_idx == false) {
+ struct nodemap_key nk;
+ union nodemap_rec nr;
+
+ nodemap_global_key_init(&nk);
+ nodemap_global_rec_init(&nr, false);
+ rc = nodemap_idx_insert(env, nodemap_idx, &nk, &nr);
+ }
if (rc == 0)
nodemap_config_set_active(new_config);
RETURN(rc);
}
+/* tracks if config still needs to be loaded, either from disk or network */
+static bool nodemap_config_loaded;
+static DEFINE_MUTEX(nodemap_config_loaded_lock);
+
+/**
+ * Ensures that configs loaded over the wire are prioritized over those loaded
+ * from disk.
+ *
+ * \param config config to set as the active config
+ */
+void nodemap_config_set_active_mgc(struct nodemap_config *config)
+{
+ mutex_lock(&nodemap_config_loaded_lock);
+ nodemap_config_set_active(config);
+ nodemap_config_loaded = true;
+ mutex_unlock(&nodemap_config_loaded_lock);
+}
+EXPORT_SYMBOL(nodemap_config_set_active_mgc);
+
/**
* Register a dt_object representing the config index file. This should be
* called by targets in order to load the nodemap configuration from disk. The
* \retval -EINVAL error loading nodemap config
*/
struct nm_config_file *nm_config_file_register(const struct lu_env *env,
- struct dt_object *obj)
+ struct dt_object *obj,
+ struct local_oid_storage *los,
+ enum nm_config_file_type ncf_type)
{
struct nm_config_file *ncf;
- bool load_entries = false;
- int rc;
+ int rc = 0;
ENTRY;
OBD_ALLOC_PTR(ncf);
RETURN(ERR_PTR(-ENOMEM));
ncf->ncf_obj = obj;
- mutex_lock(&ncf_list_lock);
-
- /* if this is first config file, we load it from disk */
- if (list_empty(&ncf_list_head))
- load_entries = true;
+ ncf->ncf_los = los;
- list_add(&ncf->ncf_list, &ncf_list_head);
- mutex_unlock(&ncf_list_lock);
+ if (ncf_type == NCFT_MGS) {
+ nodemap_mgs_ncf = ncf;
+ } else {
+ mutex_lock(&ncf_list_lock);
+ list_add(&ncf->ncf_list, &ncf_list_head);
+ mutex_unlock(&ncf_list_lock);
+ }
- if (load_entries) {
+ /* prevent activation of config loaded from MGS until disk is loaded
+ * so disk config is overwritten by MGS config.
+ */
+ mutex_lock(&nodemap_config_loaded_lock);
+ if (ncf_type == NCFT_MGS || !nodemap_config_loaded)
rc = nodemap_load_entries(env, obj);
- if (rc < 0) {
+ nodemap_config_loaded = true;
+ mutex_unlock(&nodemap_config_loaded_lock);
+
+ if (rc < 0) {
+ if (ncf_type == NCFT_MGS) {
+ nodemap_mgs_ncf = NULL;
+ } else {
mutex_lock(&ncf_list_lock);
list_del(&ncf->ncf_list);
mutex_unlock(&ncf_list_lock);
- OBD_FREE_PTR(ncf);
- RETURN(ERR_PTR(rc));
}
+
+ OBD_FREE_PTR(ncf);
+ RETURN(ERR_PTR(rc));
}
RETURN(ncf);
* \param ncf config file to deregister
*/
void nm_config_file_deregister(const struct lu_env *env,
- struct nm_config_file *ncf)
+ struct nm_config_file *ncf,
+ enum nm_config_file_type ncf_type)
{
ENTRY;
- lu_object_put(env, &ncf->ncf_obj->do_lu);
+ if (ncf->ncf_obj)
+ lu_object_put(env, &ncf->ncf_obj->do_lu);
- mutex_lock(&ncf_list_lock);
- list_del(&ncf->ncf_list);
- mutex_unlock(&ncf_list_lock);
+ if (ncf_type == NCFT_TGT) {
+ mutex_lock(&ncf_list_lock);
+ list_del(&ncf->ncf_list);
+ mutex_unlock(&ncf_list_lock);
+ } else {
+ nodemap_mgs_ncf = NULL;
+ }
OBD_FREE_PTR(ncf);
EXIT;
int rc = 0;
int size = dt_nodemap_features.dif_keysize_max +
dt_nodemap_features.dif_recsize_max;
+ ENTRY;
for (j = 0; j < LU_PAGE_COUNT; j++) {
if (lip->lp_idx.lip_magic != LIP_MAGIC)
}
lip++;
}
+
+ EXIT;
return 0;
}
EXPORT_SYMBOL(nodemap_process_idx_pages);