Whamcloud - gitweb
LU-6245 libcfs: remove libcfsutil.h
[fs/lustre-release.git] / lnet / selftest / conctl.c
index 5d3a3fd..bd438eb 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, Intel Corporation.
+ * Copyright (c) 2012, 2014, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
  *
  * lnet/selftest/conctl.c
  *
- * IOC handle in kernel 
+ * IOC handle in kernel
  *
  * Author: Liang Zhen <liangzhen@clusterfs.com>
  */
-#ifdef __KERNEL__
 
 #include <libcfs/libcfs.h>
 #include <lnet/lib-lnet.h>
 #include <lnet/lnetst.h>
 #include "console.h"
 
-int
+static int
 lst_session_new_ioctl(lstio_session_new_args_t *args)
 {
         char      *name;
@@ -82,7 +81,7 @@ lst_session_new_ioctl(lstio_session_new_args_t *args)
        return rc;
 }
 
-int
+static int
 lst_session_end_ioctl(lstio_session_end_args_t *args)
 {
         if (args->lstio_ses_key != console_session.ses_key)
@@ -91,7 +90,7 @@ lst_session_end_ioctl(lstio_session_end_args_t *args)
         return lstcon_session_end();
 }
 
-int
+static int
 lst_session_info_ioctl(lstio_session_info_args_t *args)
 {
         /* no checking of key */
@@ -113,7 +112,7 @@ lst_session_info_ioctl(lstio_session_info_args_t *args)
                                    args->lstio_ses_nmlen);
 }
 
-int
+static int
 lst_debug_ioctl(lstio_debug_args_t *args)
 {
         char   *name   = NULL;
@@ -194,7 +193,7 @@ out:
         return rc;
 }
 
-int
+static int
 lst_group_add_ioctl(lstio_group_add_args_t *args)
 {
         char           *name;
@@ -204,7 +203,7 @@ lst_group_add_ioctl(lstio_group_add_args_t *args)
                 return -EACCES;
 
         if (args->lstio_grp_namep == NULL||
-            args->lstio_grp_nmlen <= 0 || 
+           args->lstio_grp_nmlen <= 0 ||
             args->lstio_grp_nmlen > LST_NAME_SIZE)
                 return -EINVAL;
 
@@ -227,7 +226,7 @@ lst_group_add_ioctl(lstio_group_add_args_t *args)
         return rc;
 }
 
-int
+static int
 lst_group_del_ioctl(lstio_group_del_args_t *args)
 {
         int     rc;
@@ -260,7 +259,7 @@ lst_group_del_ioctl(lstio_group_del_args_t *args)
         return rc;
 }
 
-int
+static int
 lst_group_update_ioctl(lstio_group_update_args_t *args)
 {
         int     rc;
@@ -271,7 +270,7 @@ lst_group_update_ioctl(lstio_group_update_args_t *args)
 
         if (args->lstio_grp_resultp == NULL ||
             args->lstio_grp_namep == NULL ||
-            args->lstio_grp_nmlen <= 0 || 
+           args->lstio_grp_nmlen <= 0 ||
             args->lstio_grp_nmlen > LST_NAME_SIZE)
                 return -EINVAL;
 
@@ -317,7 +316,7 @@ lst_group_update_ioctl(lstio_group_update_args_t *args)
         return rc;
 }
 
-int
+static int
 lst_nodes_add_ioctl(lstio_group_nodes_args_t *args)
 {
        unsigned feats;
@@ -362,10 +361,10 @@ lst_nodes_add_ioctl(lstio_group_nodes_args_t *args)
         return rc;
 }
 
-int
+static int
 lst_group_list_ioctl(lstio_group_list_args_t *args)
 {
-        if (args->lstio_grp_key != console_session.ses_key) 
+       if (args->lstio_grp_key != console_session.ses_key)
                 return -EACCES;
 
         if (args->lstio_grp_idx   < 0 ||
@@ -379,7 +378,7 @@ lst_group_list_ioctl(lstio_group_list_args_t *args)
                               args->lstio_grp_namep);
 }
 
-int
+static int
 lst_group_info_ioctl(lstio_group_info_args_t *args)
 {
         char           *name;
@@ -431,7 +430,7 @@ lst_group_info_ioctl(lstio_group_info_args_t *args)
 
         LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
 
-        if (rc != 0) 
+       if (rc != 0)
                 return rc;
 
        if (args->lstio_grp_dentsp != NULL &&
@@ -442,7 +441,7 @@ lst_group_info_ioctl(lstio_group_info_args_t *args)
        return 0;
 }
 
-int
+static int
 lst_batch_add_ioctl(lstio_batch_add_args_t *args)
 {
         int             rc;
@@ -475,7 +474,7 @@ lst_batch_add_ioctl(lstio_batch_add_args_t *args)
         return rc;
 }
 
-int
+static int
 lst_batch_run_ioctl(lstio_batch_run_args_t *args)
 {
         int             rc;
@@ -509,7 +508,7 @@ lst_batch_run_ioctl(lstio_batch_run_args_t *args)
         return rc;
 }
 
-int
+static int
 lst_batch_stop_ioctl(lstio_batch_stop_args_t *args)
 {
         int             rc;
@@ -544,7 +543,7 @@ lst_batch_stop_ioctl(lstio_batch_stop_args_t *args)
         return rc;
 }
 
-int
+static int
 lst_batch_query_ioctl(lstio_batch_query_args_t *args)
 {
         char   *name;
@@ -585,7 +584,7 @@ lst_batch_query_ioctl(lstio_batch_query_args_t *args)
         return rc;
 }
 
-int
+static int
 lst_batch_list_ioctl(lstio_batch_list_args_t *args)
 {
         if (args->lstio_bat_key != console_session.ses_key)
@@ -602,7 +601,7 @@ lst_batch_list_ioctl(lstio_batch_list_args_t *args)
                               args->lstio_bat_namep);
 }
 
-int
+static int
 lst_batch_info_ioctl(lstio_batch_info_args_t *args)
 {
         char           *name;
@@ -667,53 +666,54 @@ lst_batch_info_ioctl(lstio_batch_info_args_t *args)
        return rc;
 }
 
-int
+static int
 lst_stat_query_ioctl(lstio_stat_args_t *args)
 {
         int             rc;
-        char           *name;
+       char           *name = NULL;
 
         /* TODO: not finished */
         if (args->lstio_sta_key != console_session.ses_key)
                 return -EACCES;
 
-        if (args->lstio_sta_resultp == NULL ||
-            (args->lstio_sta_namep  == NULL &&
-             args->lstio_sta_idsp   == NULL) ||
-            args->lstio_sta_nmlen <= 0 ||
-            args->lstio_sta_nmlen > LST_NAME_SIZE)
-                return -EINVAL;
-
-        if (args->lstio_sta_idsp != NULL &&
-            args->lstio_sta_count <= 0)
-                return -EINVAL;
-
-        LIBCFS_ALLOC(name, args->lstio_sta_nmlen + 1);
-        if (name == NULL)
-                return -ENOMEM;
+       if (args->lstio_sta_resultp == NULL)
+               return -EINVAL;
 
-       if (copy_from_user(name, args->lstio_sta_namep,
-                               args->lstio_sta_nmlen)) {
-                LIBCFS_FREE(name, args->lstio_sta_nmlen + 1);
-                return -EFAULT;
-        }
+       if (args->lstio_sta_idsp != NULL) {
+               if (args->lstio_sta_count <= 0)
+                       return -EINVAL;
 
-        if (args->lstio_sta_idsp == NULL) {
-                rc = lstcon_group_stat(name, args->lstio_sta_timeout,
-                                       args->lstio_sta_resultp);
-        } else {
-                rc = lstcon_nodes_stat(args->lstio_sta_count,
+               rc = lstcon_nodes_stat(args->lstio_sta_count,
                                        args->lstio_sta_idsp,
                                        args->lstio_sta_timeout,
                                        args->lstio_sta_resultp);
-        }
+       } else if (args->lstio_sta_namep != NULL) {
+               if (args->lstio_sta_nmlen <= 0 ||
+                   args->lstio_sta_nmlen > LST_NAME_SIZE)
+                       return -EINVAL;
 
-        LIBCFS_FREE(name, args->lstio_sta_nmlen + 1);
+               LIBCFS_ALLOC(name, args->lstio_sta_nmlen + 1);
+               if (name == NULL)
+                       return -ENOMEM;
 
-        return rc;
+               rc = copy_from_user(name, args->lstio_sta_namep,
+                                   args->lstio_sta_nmlen);
+               if (rc == 0)
+                       rc = lstcon_group_stat(name, args->lstio_sta_timeout,
+                                              args->lstio_sta_resultp);
+               else
+                       rc = -EFAULT;
+
+       } else {
+               rc = -EINVAL;
+       }
+
+       if (name != NULL)
+               LIBCFS_FREE(name, args->lstio_sta_nmlen + 1);
+       return rc;
 }
 
-int lst_test_add_ioctl(lstio_test_args_t *args)
+static int lst_test_add_ioctl(lstio_test_args_t *args)
 {
        char            *batch_name;
        char            *src_name = NULL;
@@ -757,13 +757,18 @@ int lst_test_add_ioctl(lstio_test_args_t *args)
                goto out;
 
        LIBCFS_ALLOC(dst_name, args->lstio_tes_dgrp_nmlen + 1);
-        if (dst_name == NULL)
+       if (dst_name == NULL)
                goto out;
 
        if (args->lstio_tes_param != NULL) {
                LIBCFS_ALLOC(param, args->lstio_tes_param_len);
                if (param == NULL)
                        goto out;
+               if (copy_from_user(param, args->lstio_tes_param,
+                                  args->lstio_tes_param_len)) {
+                       rc = -EFAULT;
+                       goto out;
+               }
        }
 
        rc = -EFAULT;
@@ -772,9 +777,7 @@ int lst_test_add_ioctl(lstio_test_args_t *args)
            copy_from_user(src_name, args->lstio_tes_sgrp_name,
                           args->lstio_tes_sgrp_nmlen) ||
            copy_from_user(dst_name, args->lstio_tes_dgrp_name,
-                          args->lstio_tes_dgrp_nmlen) ||
-           copy_from_user(param, args->lstio_tes_param,
-                             args->lstio_tes_param_len))
+                          args->lstio_tes_dgrp_nmlen))
                goto out;
 
        rc = lstcon_test_add(batch_name,
@@ -806,15 +809,20 @@ out:
 }
 
 int
-lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data)
+lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_hdr *hdr)
 {
        char   *buf;
-       int     opc = data->ioc_u32[0];
+       struct libcfs_ioctl_data *data;
+       int     opc;
        int     rc;
 
        if (cmd != IOC_LIBCFS_LNETST)
                return -EINVAL;
 
+       data = container_of(hdr, struct libcfs_ioctl_data, ioc_hdr);
+
+       opc = data->ioc_u32[0];
+
        if (data->ioc_plen1 > PAGE_CACHE_SIZE)
                return -EINVAL;
 
@@ -830,83 +838,83 @@ lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data)
 
        mutex_lock(&console_session.ses_mutex);
 
-        console_session.ses_laststamp = cfs_time_current_sec();
+       console_session.ses_laststamp = cfs_time_current_sec();
 
-        if (console_session.ses_shutdown) {
-                rc = -ESHUTDOWN;
-                goto out;
-        }
-
-        if (console_session.ses_expired)
-                lstcon_session_end();
+       if (console_session.ses_shutdown) {
+               rc = -ESHUTDOWN;
+               goto out;
+       }
 
-        if (opc != LSTIO_SESSION_NEW &&
-            console_session.ses_state == LST_SESSION_NONE) {
-                CDEBUG(D_NET, "LST no active session\n");
-                rc = -ESRCH;
-                goto out;
-        }
+       if (console_session.ses_expired)
+               lstcon_session_end();
 
-        memset(&console_session.ses_trans_stat, 0, sizeof(lstcon_trans_stat_t));
+       if (opc != LSTIO_SESSION_NEW &&
+           console_session.ses_state == LST_SESSION_NONE) {
+               CDEBUG(D_NET, "LST no active session\n");
+               rc = -ESRCH;
+               goto out;
+       }
 
-        switch (opc) {
-                case LSTIO_SESSION_NEW:
-                        rc = lst_session_new_ioctl((lstio_session_new_args_t *)buf);
-                        break;
-                case LSTIO_SESSION_END:
-                        rc = lst_session_end_ioctl((lstio_session_end_args_t *)buf);
-                        break;
-                case LSTIO_SESSION_INFO:
-                        rc = lst_session_info_ioctl((lstio_session_info_args_t *)buf);
-                        break;
-                case LSTIO_DEBUG:
-                        rc = lst_debug_ioctl((lstio_debug_args_t *)buf);
-                        break;
-                case LSTIO_GROUP_ADD:
-                        rc = lst_group_add_ioctl((lstio_group_add_args_t *)buf);
-                        break;
-                case LSTIO_GROUP_DEL:
-                        rc = lst_group_del_ioctl((lstio_group_del_args_t *)buf);
-                        break;
-                case LSTIO_GROUP_UPDATE:
-                        rc = lst_group_update_ioctl((lstio_group_update_args_t *)buf);
-                        break;
-                case LSTIO_NODES_ADD:
-                        rc = lst_nodes_add_ioctl((lstio_group_nodes_args_t *)buf);
-                        break;
-                case LSTIO_GROUP_LIST:
-                        rc = lst_group_list_ioctl((lstio_group_list_args_t *)buf);
-                        break;
-                case LSTIO_GROUP_INFO:
-                        rc = lst_group_info_ioctl((lstio_group_info_args_t *)buf);
-                        break;
-                case LSTIO_BATCH_ADD:
-                        rc = lst_batch_add_ioctl((lstio_batch_add_args_t *)buf);
-                        break;
-                case LSTIO_BATCH_START:
-                        rc = lst_batch_run_ioctl((lstio_batch_run_args_t *)buf);
-                        break;
-                case LSTIO_BATCH_STOP:
-                        rc = lst_batch_stop_ioctl((lstio_batch_stop_args_t *)buf);
-                        break;
-                case LSTIO_BATCH_QUERY:
-                        rc = lst_batch_query_ioctl((lstio_batch_query_args_t *)buf);
-                        break;
-                case LSTIO_BATCH_LIST:
-                        rc = lst_batch_list_ioctl((lstio_batch_list_args_t *)buf);
-                        break;
-                case LSTIO_BATCH_INFO:
-                        rc = lst_batch_info_ioctl((lstio_batch_info_args_t *)buf);
-                        break;
-                case LSTIO_TEST_ADD:
-                        rc = lst_test_add_ioctl((lstio_test_args_t *)buf);
-                        break;
-                case LSTIO_STAT_QUERY:
-                        rc = lst_stat_query_ioctl((lstio_stat_args_t *)buf);
-                        break;
-                default:
-                        rc = -EINVAL;
-        }
+       memset(&console_session.ses_trans_stat, 0, sizeof(lstcon_trans_stat_t));
+
+       switch (opc) {
+       case LSTIO_SESSION_NEW:
+               rc = lst_session_new_ioctl((lstio_session_new_args_t *)buf);
+               break;
+       case LSTIO_SESSION_END:
+               rc = lst_session_end_ioctl((lstio_session_end_args_t *)buf);
+               break;
+       case LSTIO_SESSION_INFO:
+               rc = lst_session_info_ioctl((lstio_session_info_args_t *)buf);
+               break;
+       case LSTIO_DEBUG:
+               rc = lst_debug_ioctl((lstio_debug_args_t *)buf);
+               break;
+       case LSTIO_GROUP_ADD:
+               rc = lst_group_add_ioctl((lstio_group_add_args_t *)buf);
+               break;
+       case LSTIO_GROUP_DEL:
+               rc = lst_group_del_ioctl((lstio_group_del_args_t *)buf);
+               break;
+       case LSTIO_GROUP_UPDATE:
+               rc = lst_group_update_ioctl((lstio_group_update_args_t *)buf);
+               break;
+       case LSTIO_NODES_ADD:
+               rc = lst_nodes_add_ioctl((lstio_group_nodes_args_t *)buf);
+               break;
+       case LSTIO_GROUP_LIST:
+               rc = lst_group_list_ioctl((lstio_group_list_args_t *)buf);
+               break;
+       case LSTIO_GROUP_INFO:
+               rc = lst_group_info_ioctl((lstio_group_info_args_t *)buf);
+               break;
+       case LSTIO_BATCH_ADD:
+               rc = lst_batch_add_ioctl((lstio_batch_add_args_t *)buf);
+               break;
+       case LSTIO_BATCH_START:
+               rc = lst_batch_run_ioctl((lstio_batch_run_args_t *)buf);
+               break;
+       case LSTIO_BATCH_STOP:
+               rc = lst_batch_stop_ioctl((lstio_batch_stop_args_t *)buf);
+               break;
+       case LSTIO_BATCH_QUERY:
+               rc = lst_batch_query_ioctl((lstio_batch_query_args_t *)buf);
+               break;
+       case LSTIO_BATCH_LIST:
+               rc = lst_batch_list_ioctl((lstio_batch_list_args_t *)buf);
+               break;
+       case LSTIO_BATCH_INFO:
+               rc = lst_batch_info_ioctl((lstio_batch_info_args_t *)buf);
+               break;
+       case LSTIO_TEST_ADD:
+               rc = lst_test_add_ioctl((lstio_test_args_t *)buf);
+               break;
+       case LSTIO_STAT_QUERY:
+               rc = lst_stat_query_ioctl((lstio_stat_args_t *)buf);
+               break;
+       default:
+               rc = -EINVAL;
+       }
 
        if (copy_to_user(data->ioc_pbuf2, &console_session.ses_trans_stat,
                         sizeof(lstcon_trans_stat_t)))
@@ -918,7 +926,3 @@ out:
 
        return rc;
 }
-
-EXPORT_SYMBOL(lstcon_ioctl_entry);
-
-#endif