-/**
- * Add a NID range to nodemap.
- *
- * \param[in] file proc file
- * \param[in] buffer string, "<nodemap name> <nid range>"
- * \param[in] count \a buffer length
- * \param[in] off unused
- * \retval \a count on success
- * \retval negative number on error
- */
-static ssize_t
-lprocfs_add_nodemap_range_seq_write(struct file *file,
- const char __user *buffer,
- size_t count, loff_t *off)
-{
- char name_range[LUSTRE_NODEMAP_NAME_LENGTH +
- LNET_NIDSTR_SIZE * 2 + 2];
- char *cpybuf = NULL;
- char *name;
- char *rangestr = NULL;
- lnet_nid_t nids[2];
- int rc;
-
- if (count == 0)
- return 0;
-
- if (count >= sizeof(name_range))
- GOTO(out, rc = -EINVAL);
-
- if (copy_from_user(name_range, buffer, count))
- GOTO(out, rc = -EFAULT);
-
- name_range[count] = '\0';
-
- cpybuf = name_range;
- name = strsep(&cpybuf, " ");
- if (name == NULL)
- GOTO(out, rc = -EINVAL);
-
- rangestr = strsep(&cpybuf, " \n");
- if (rangestr == NULL)
- GOTO(out, rc = -EINVAL);
-
- rc = parse_nids(rangestr, nids);
- if (rc != 0)
- GOTO(out, rc = rc);
-
- rc = nodemap_add_range(name, nids);
- if (rc != 0)
- GOTO(out, rc = -EINVAL);
-
- if (rc == 0)
- rc = count;
-
-out:
- return rc;
-}
-LPROC_SEQ_FOPS_WO_TYPE(nodemap, add_nodemap_range);
-
-/**
- * Delete a NID range from nodemap.
- *
- * \param[in] file proc file
- * \param[in] buffer string, "<nodemap name> <nid range>"
- * \param[in] count \a buffer length
- * \param[in] off unused
- * \retval \a count on success
- * \retval negative number on error
- */
-static ssize_t
-lprocfs_del_nodemap_range_seq_write(struct file *file,
- const char __user *buffer,
- size_t count, loff_t *off)
-{
- char name_range[LUSTRE_NODEMAP_NAME_LENGTH +
- LNET_NIDSTR_SIZE * 2 + 2];
- char *cpybuf = NULL;
- char *name;
- char *rangestr = NULL;
- lnet_nid_t nids[2];
- int rc;
-
- if (count == 0)
- return 0;
-
- if (count >= sizeof(name_range))
- GOTO(out, rc = -EINVAL);
-
- if (copy_from_user(name_range, buffer, count))
- GOTO(out, rc = -EFAULT);
-
- name_range[count] = '\0';
-
- cpybuf = name_range;
- name = strsep(&cpybuf, " ");
- if (name == NULL)
- GOTO(out, rc = -EINVAL);
-
- rangestr = strsep(&cpybuf, " \n");
- if (rangestr == NULL)
- GOTO(out, rc = -EINVAL);
-
- rc = parse_nids(rangestr, nids);
- if (rc != 0)
- GOTO(out, rc = rc);
-
- rc = nodemap_del_range(name, nids);
- if (rc != 0)
- GOTO(out, rc = -EINVAL);
-
- if (rc == 0)
- rc = count;
-
-out:
- return rc;
-}
-LPROC_SEQ_FOPS_WO_TYPE(nodemap, del_nodemap_range);
-
-/**
- * Add an idmap to nodemap.
- *
- * \param[in] file proc file
- * \param[in] buffer string, "<nodemap name> <uid|gid> <idmap>"
- * \param[in] count \a buffer length
- * \param[in] off unused
- * \retval \a count on success
- * \retval negative number on error
- */
-static ssize_t
-lprocfs_add_nodemap_idmap_seq_write(struct file *file,
- const char __user *buffer,
- size_t count, loff_t *off)
-{
- char name_idmapstr[LUSTRE_NODEMAP_NAME_LENGTH + 16];
- char *cpybuf = NULL;
- char *name;
- char *idtypestr = NULL;
- char *idmapstr = NULL;
- __u32 idmap[2];
- int rc = count;
-
- if (count == 0)
- return 0;
-
- if (count >= sizeof(name_idmapstr))
- GOTO(out, rc = -EINVAL);
-
- if (copy_from_user(name_idmapstr, buffer, count))
- GOTO(out, rc = -EFAULT);
-
- name_idmapstr[count] = '\0';
-
- cpybuf = name_idmapstr;
- name = strsep(&cpybuf, " ");
- if (name == NULL)
- GOTO(out, rc = -EINVAL);
-
- idtypestr = strsep(&cpybuf, " ");
- if (idtypestr == NULL)
- GOTO(out, rc = -EINVAL);
-
- idmapstr = strsep(&cpybuf, " \n");
- if (idmapstr == NULL)
- GOTO(out, rc = -EINVAL);
-
- rc = nodemap_parse_idmap(idmapstr, idmap);
- if (rc != 0)
- GOTO(out, rc = -EINVAL);
-
- if (strcmp(idtypestr, "uid") == 0)
- rc = nodemap_add_idmap(name, NODEMAP_UID, idmap);
- else if (strcmp(idtypestr, "gid") == 0)
- rc = nodemap_add_idmap(name, NODEMAP_GID, idmap);
- else
- GOTO(out, rc = -EINVAL);
-
- if (rc != 0)
- GOTO(out, rc = -EINVAL);
-
- if (rc == 0)
- rc = count;
-
-out:
- return rc;
-}
-LPROC_SEQ_FOPS_WO_TYPE(nodemap, add_nodemap_idmap);
-
-/**
- * Delete an idmap from nodemap.
- *
- * \param[in] file proc file
- * \param[in] buffer string, "<nodemap name> <uid|gid> <idmap>"
- * \param[in] count \a buffer length
- * \param[in] off unused
- * \retval \a count on success
- * \retval negative number on error
- */
-static ssize_t
-lprocfs_del_nodemap_idmap_seq_write(struct file *file,
- const char __user *buffer,
- size_t count, loff_t *off)
-{
- char name_idmapstr[LUSTRE_NODEMAP_NAME_LENGTH + 16];
- char *cpybuf = NULL;
- char *name;
- char *idtypestr = NULL;
- char *idmapstr = NULL;
- __u32 idmap[2];
- int rc = count;
-
- if (count == 0)
- return 0;
-
- if (count >= sizeof(name_idmapstr))
- GOTO(out, rc = -EINVAL);
-
- if (copy_from_user(name_idmapstr, buffer, count))
- GOTO(out, rc = -EFAULT);
-
- name_idmapstr[count] = '\0';
-
- cpybuf = name_idmapstr;
- name = strsep(&cpybuf, " ");
- if (name == NULL)
- GOTO(out, rc = -EINVAL);
-
- idtypestr = strsep(&cpybuf, " ");
- if (idtypestr == NULL)
- GOTO(out, rc = -EINVAL);
-
- idmapstr = strsep(&cpybuf, " \n");
- if (idmapstr == NULL)
- GOTO(out, rc = -EINVAL);
-
- rc = nodemap_parse_idmap(idmapstr, idmap);
- if (rc != 0)
- GOTO(out, rc = -EINVAL);
-
- if (strcmp(idtypestr, "uid") == 0)
- rc = nodemap_del_idmap(name, NODEMAP_UID, idmap);
- else if (strcmp(idtypestr, "gid") == 0)
- rc = nodemap_del_idmap(name, NODEMAP_GID, idmap);
- else
- GOTO(out, rc = -EINVAL);
-
- if (rc != 0)
- GOTO(out, rc = -EINVAL);
-
- if (rc == 0)
- rc = count;
-
-out:
- return rc;
-}
-LPROC_SEQ_FOPS_WO_TYPE(nodemap, del_nodemap_idmap);
-#endif /* NODEMAP_PROC_DEBUG */
-