📄 conctl.c
字号:
/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- * vim:expandtab:shiftwidth=8:tabstop=8: * * Author: Liang Zhen <liangzhen@clusterfs.com> * * This file is part of Lustre, http://www.lustre.org * * IOC handle in kernel */#ifdef __KERNEL__#include <libcfs/libcfs.h>#include <lnet/lib-lnet.h>#include <lnet/lnetst.h>#include "console.h"intlst_session_new_ioctl(lstio_session_new_args_t *args) { char *name; int rc; if (args->lstio_ses_idp == NULL || /* address for output sid */ args->lstio_ses_key == 0 || /* no key is specified */ args->lstio_ses_namep == NULL || /* session name */ args->lstio_ses_nmlen <= 0 || args->lstio_ses_nmlen > LST_NAME_SIZE) return -EINVAL; LIBCFS_ALLOC(name, args->lstio_ses_nmlen + 1); if (name == NULL) return -ENOMEM; if (copy_from_user(name, args->lstio_ses_namep, args->lstio_ses_nmlen)) { LIBCFS_FREE(name, args->lstio_ses_nmlen + 1); return -EFAULT; } name[args->lstio_ses_nmlen] = 0; rc = lstcon_session_new(name, args->lstio_ses_key, args->lstio_ses_timeout, args->lstio_ses_force, args->lstio_ses_idp); LIBCFS_FREE(name, args->lstio_ses_nmlen + 1); return rc;}intlst_session_end_ioctl(lstio_session_end_args_t *args){ if (args->lstio_ses_key != console_session.ses_key) return -EACCES; return lstcon_session_end();}intlst_session_info_ioctl(lstio_session_info_args_t *args){ /* no checking of key */ if (args->lstio_ses_idp == NULL || /* address for ouput sid */ args->lstio_ses_keyp == NULL || /* address for ouput key */ args->lstio_ses_ndinfo == NULL || /* address for output ndinfo */ args->lstio_ses_namep == NULL || /* address for ouput name */ args->lstio_ses_nmlen <= 0 || args->lstio_ses_nmlen > LST_NAME_SIZE) return -EINVAL; return lstcon_session_info(args->lstio_ses_idp, args->lstio_ses_keyp, args->lstio_ses_ndinfo, args->lstio_ses_namep, args->lstio_ses_nmlen);}intlst_debug_ioctl(lstio_debug_args_t *args){ char *name = NULL; int client = 1; int rc; if (args->lstio_dbg_key != console_session.ses_key) return -EACCES; if (args->lstio_dbg_resultp == NULL) return -EINVAL; if (args->lstio_dbg_namep != NULL && /* name of batch/group */ (args->lstio_dbg_nmlen <= 0 || args->lstio_dbg_nmlen > LST_NAME_SIZE)) return -EINVAL; if (args->lstio_dbg_namep != NULL) { LIBCFS_ALLOC(name, args->lstio_dbg_nmlen + 1); if (name == NULL) return -ENOMEM; if (copy_from_user(name, args->lstio_dbg_namep, args->lstio_dbg_nmlen)) { LIBCFS_FREE(name, args->lstio_dbg_nmlen + 1); return -EFAULT; } name[args->lstio_dbg_nmlen] = 0; } rc = -EINVAL; switch (args->lstio_dbg_type) { case LST_OPC_SESSION: rc = lstcon_session_debug(args->lstio_dbg_timeout, args->lstio_dbg_resultp); break; case LST_OPC_BATCHSRV: client = 0; case LST_OPC_BATCHCLI: if (name == NULL) goto out; rc = lstcon_batch_debug(args->lstio_dbg_timeout, name, client, args->lstio_dbg_resultp); break; case LST_OPC_GROUP: if (name == NULL) goto out; rc = lstcon_group_debug(args->lstio_dbg_timeout, name, args->lstio_dbg_resultp); break; case LST_OPC_NODES: if (args->lstio_dbg_count <= 0 || args->lstio_dbg_idsp == NULL) goto out; rc = lstcon_nodes_debug(args->lstio_dbg_timeout, args->lstio_dbg_count, args->lstio_dbg_idsp, args->lstio_dbg_resultp); break; default: break; }out: if (name != NULL) LIBCFS_FREE(name, args->lstio_dbg_nmlen + 1); return rc;}intlst_group_add_ioctl(lstio_group_add_args_t *args){ char *name; int rc; if (args->lstio_grp_key != console_session.ses_key) return -EACCES; if (args->lstio_grp_namep == NULL|| args->lstio_grp_nmlen <= 0 || args->lstio_grp_nmlen > LST_NAME_SIZE) return -EINVAL; LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1); if (name == NULL) return -ENOMEM; if (copy_from_user(name, args->lstio_grp_namep, args->lstio_grp_nmlen)) { LIBCFS_FREE(name, args->lstio_grp_nmlen); return -EFAULT; } name[args->lstio_grp_nmlen] = 0; rc = lstcon_group_add(name); LIBCFS_FREE(name, args->lstio_grp_nmlen + 1); return rc;}intlst_group_del_ioctl(lstio_group_del_args_t *args){ int rc; char *name; if (args->lstio_grp_key != console_session.ses_key) return -EACCES; if (args->lstio_grp_namep == NULL || args->lstio_grp_nmlen <= 0 || args->lstio_grp_nmlen > LST_NAME_SIZE) return -EINVAL; LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1); if (name == NULL) return -ENOMEM; if (copy_from_user(name, args->lstio_grp_namep, args->lstio_grp_nmlen)) { LIBCFS_FREE(name, args->lstio_grp_nmlen + 1); return -EFAULT; } name[args->lstio_grp_nmlen] = 0; rc = lstcon_group_del(name); LIBCFS_FREE(name, args->lstio_grp_nmlen + 1); return rc;}intlst_group_update_ioctl(lstio_group_update_args_t *args){ int rc; char *name; if (args->lstio_grp_key != console_session.ses_key) return -EACCES; if (args->lstio_grp_resultp == NULL || args->lstio_grp_namep == NULL || args->lstio_grp_nmlen <= 0 || args->lstio_grp_nmlen > LST_NAME_SIZE) return -EINVAL; LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1); if (name == NULL) return -ENOMEM; if (copy_from_user(name, args->lstio_grp_namep, args->lstio_grp_nmlen)) { LIBCFS_FREE(name, args->lstio_grp_nmlen + 1); return -EFAULT; } name[args->lstio_grp_nmlen] = 0; switch (args->lstio_grp_opc) { case LST_GROUP_CLEAN: rc = lstcon_group_clean(name, args->lstio_grp_args); break; case LST_GROUP_REFRESH: rc = lstcon_group_refresh(name, args->lstio_grp_resultp); break; case LST_GROUP_RMND: if (args->lstio_grp_count <= 0 || args->lstio_grp_idsp == NULL) { rc = -EINVAL; break; } rc = lstcon_nodes_remove(name, args->lstio_grp_count, args->lstio_grp_idsp, args->lstio_grp_resultp); break; default: rc = -EINVAL; break; } LIBCFS_FREE(name, args->lstio_grp_nmlen + 1); return rc;}intlst_nodes_add_ioctl(lstio_group_nodes_args_t *args){ int rc; char *name; if (args->lstio_grp_key != console_session.ses_key) return -EACCES; if (args->lstio_grp_idsp == NULL || /* array of ids */ args->lstio_grp_count <= 0 || args->lstio_grp_resultp == NULL || args->lstio_grp_namep == NULL || args->lstio_grp_nmlen <= 0 || args->lstio_grp_nmlen > LST_NAME_SIZE) return -EINVAL; LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1); if (name == NULL) return -ENOMEM; if (copy_from_user(name, args->lstio_grp_namep, args->lstio_grp_nmlen)) { LIBCFS_FREE(name, args->lstio_grp_nmlen + 1); return -EFAULT; } name[args->lstio_grp_nmlen] = 0; rc = lstcon_nodes_add(name, args->lstio_grp_count, args->lstio_grp_idsp, args->lstio_grp_resultp); LIBCFS_FREE(name, args->lstio_grp_nmlen + 1); return rc;}intlst_group_list_ioctl(lstio_group_list_args_t *args){ if (args->lstio_grp_key != console_session.ses_key) return -EACCES; if (args->lstio_grp_idx < 0 || args->lstio_grp_namep == NULL || args->lstio_grp_nmlen <= 0 || args->lstio_grp_nmlen > LST_NAME_SIZE) return -EINVAL; return lstcon_group_list(args->lstio_grp_idx, args->lstio_grp_nmlen, args->lstio_grp_namep);}intlst_group_info_ioctl(lstio_group_info_args_t *args){ char *name; int ndent; int index; int rc; if (args->lstio_grp_key != console_session.ses_key) return -EACCES; if (args->lstio_grp_namep == NULL || args->lstio_grp_nmlen <= 0 || args->lstio_grp_nmlen > LST_NAME_SIZE) return -EINVAL; if (args->lstio_grp_entp == NULL && /* output: group entry */ args->lstio_grp_dentsp == NULL) /* output: node entry */ return -EINVAL; if (args->lstio_grp_dentsp != NULL) { /* have node entry */ if (args->lstio_grp_idxp == NULL || /* node index */ args->lstio_grp_ndentp == NULL) /* # of node entry */ return -EINVAL; if (copy_from_user(&ndent, args->lstio_grp_ndentp, sizeof(ndent)) || copy_from_user(&index, args->lstio_grp_idxp, sizeof(index))) return -EFAULT; if (ndent <= 0 || index < 0) return -EINVAL; } LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1); if (name == NULL) return -ENOMEM; if (copy_from_user(name, args->lstio_grp_namep, args->lstio_grp_nmlen)) { LIBCFS_FREE(name, args->lstio_grp_nmlen + 1); return -EFAULT; } name[args->lstio_grp_nmlen] = 0; rc = lstcon_group_info(name, args->lstio_grp_entp, &index, &ndent, args->lstio_grp_dentsp); LIBCFS_FREE(name, args->lstio_grp_nmlen + 1); if (rc != 0) return rc; if (args->lstio_grp_dentsp != NULL && (copy_to_user(args->lstio_grp_idxp, &index, sizeof(index)) || copy_to_user(args->lstio_grp_ndentp, &ndent, sizeof(ndent)))) rc = -EFAULT; return 0;}intlst_batch_add_ioctl(lstio_batch_add_args_t *args){ int rc; char *name; if (args->lstio_bat_key != console_session.ses_key) return -EACCES; if (args->lstio_bat_namep == NULL || args->lstio_bat_nmlen <= 0 || args->lstio_bat_nmlen > LST_NAME_SIZE) return -EINVAL; LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1); if (name == NULL) return -ENOMEM; if (copy_from_user(name, args->lstio_bat_namep, args->lstio_bat_nmlen)) { LIBCFS_FREE(name, args->lstio_bat_nmlen + 1); return -EFAULT; } name[args->lstio_bat_nmlen] = 0; rc = lstcon_batch_add(name); LIBCFS_FREE(name, args->lstio_bat_nmlen + 1); return rc;}int
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -