/* don't use 0@lo, use the first non-lo local NID instead */
if (nid == LNET_NID_LO_0) {
- struct lnet_process_id id;
+ struct lnet_processid id;
int i = 0;
do {
rc = LNetGetId(i++, &id);
if (rc < 0)
RETURN(ERR_PTR(-EINVAL));
- } while (id.nid == LNET_NID_LO_0);
+ } while (nid_is_lo0(&id.nid));
- nid = id.nid;
+ nid = lnet_nid_to_nid4(&id.nid);
CDEBUG(D_INFO, "found nid %s\n", libcfs_nid2str(nid));
}
}
rc = range_insert(&config->nmc_range_tree, range);
- if (rc != 0) {
- CERROR("cannot insert nodemap range into '%s': rc = %d\n",
- nodemap->nm_name, rc);
+ if (rc) {
+ CDEBUG_LIMIT(rc == -EEXIST ? D_INFO : D_ERROR,
+ "cannot insert nodemap range into '%s': rc = %d\n",
+ nodemap->nm_name, rc);
up_write(&config->nmc_range_tree_lock);
list_del(&range->rn_list);
range_destroy(range);
- GOTO(out, rc = -ENOMEM);
+ GOTO(out, rc);
}
list_add(&range->rn_list, &nodemap->nm_ranges);
out:
return rc;
}
+
int nodemap_add_range(const char *name, const lnet_nid_t nid[2])
{
struct lu_nodemap *nodemap = NULL;
nodemap->nmf_map_mode = NODEMAP_MAP_ALL;
nodemap->nmf_enable_audit = 1;
nodemap->nmf_forbid_encryption = 0;
+ nodemap->nmf_readonly_mount = 0;
nodemap->nm_squash_uid = NODEMAP_NOBODY_UID;
nodemap->nm_squash_gid = NODEMAP_NOBODY_GID;
nodemap->nmf_enable_audit = default_nodemap->nmf_enable_audit;
nodemap->nmf_forbid_encryption =
default_nodemap->nmf_forbid_encryption;
+ nodemap->nmf_readonly_mount =
+ default_nodemap->nmf_readonly_mount;
nodemap->nm_squash_uid = default_nodemap->nm_squash_uid;
nodemap->nm_squash_gid = default_nodemap->nm_squash_gid;
EXPORT_SYMBOL(nodemap_set_squash_projid);
/**
- * Returns true if this nodemap has root user access. Always returns true if
- * nodemaps are not active.
+ * Check if nodemap allows setting quota.
+ *
+ * If nodemap is not active, always allow.
+ * For user and group quota, allow if the nodemap allows root access.
+ * For project quota, allow if project id is not squashed or deny_unknown
+ * is not set.
*
* \param nodemap nodemap to check access for
+ * \param qc_type quota type
+ * \param id client id to map
+ * \retval true is setquota is allowed, false otherwise
*/
-bool nodemap_can_setquota(const struct lu_nodemap *nodemap)
+bool nodemap_can_setquota(struct lu_nodemap *nodemap, __u32 qc_type, __u32 id)
{
- return !nodemap_active || (nodemap && nodemap->nmf_allow_root_access);
+ if (!nodemap_active)
+ return true;
+
+ if (!nodemap || !nodemap->nmf_allow_root_access)
+ return false;
+
+ if (qc_type == PRJQUOTA) {
+ id = nodemap_map_id(nodemap, NODEMAP_PROJID,
+ NODEMAP_CLIENT_TO_FS, id);
+
+ if (id == nodemap->nm_squash_projid &&
+ nodemap->nmf_deny_unknown)
+ return false;
+ }
+
+ return true;
}
EXPORT_SYMBOL(nodemap_can_setquota);
}
EXPORT_SYMBOL(nodemap_set_forbid_encryption);
+/**
+ * Set the nmf_readonly_mount flag to true or false.
+ * \param name nodemap name
+ * \param readonly_mount if true, forbid rw mount
+ * \retval 0 on success
+ *
+ */
+int nodemap_set_readonly_mount(const char *name, bool readonly_mount)
+{
+ 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_readonly_mount = readonly_mount;
+ rc = nodemap_idx_nodemap_update(nodemap);
+
+ nm_member_revoke_locks(nodemap);
+ nodemap_putref(nodemap);
+out:
+ return rc;
+}
+EXPORT_SYMBOL(nodemap_set_readonly_mount);
/**
* Add a nodemap