From: Amir Shehata Date: Wed, 9 Oct 2013 18:30:04 +0000 (-0700) Subject: LU-2456 lnet: Dynamic LNet Configuration (DLC) IOCTL changes X-Git-Tag: 2.6.52~5 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=da677c1c4f37886ff7b8d31396645b12365c0e88;hp=11220ac2f0d1245e14306f116f1c262662037740 LU-2456 lnet: Dynamic LNet Configuration (DLC) IOCTL changes This is the fourth patch of a set of patches that enables DLC. This patch changes the IOCTL infrastructure in preparation of adding extra IOCTL communication between user and kernel space. The changes include: - adding a common header to be passed to ioctl infra functions instead of passing an exact structure. This header is meant to be included in all structures to be passed through that interface. The IOCTL handler casts this header to a particular type that it expects - All sanity testing on the past in structure is performed in the generic ioctl infrastructure code. - All ioctl handlers changed to take the header instead of a particular structure type Signed-off-by: Amir Shehata Change-Id: I144706a14293637cd5f381d2c020faa0e9c21f6b Reviewed-on: http://review.whamcloud.com/8021 Tested-by: Jenkins Reviewed-by: Doug Oucharek Reviewed-by: James Simmons Reviewed-by: John L. Hammond Tested-by: Maloo Reviewed-by: Oleg Drokin --- diff --git a/libcfs/include/libcfs/libcfs_ioctl.h b/libcfs/include/libcfs/libcfs_ioctl.h index ceb948e..732a181 100644 --- a/libcfs/include/libcfs/libcfs_ioctl.h +++ b/libcfs/include/libcfs/libcfs_ioctl.h @@ -41,61 +41,59 @@ #ifndef __LIBCFS_IOCTL_H__ #define __LIBCFS_IOCTL_H__ - #define LIBCFS_IOCTL_VERSION 0x0001000a +struct libcfs_ioctl_hdr { + __u32 ioc_len; + __u32 ioc_version; +}; + struct libcfs_ioctl_data { - __u32 ioc_len; - __u32 ioc_version; + struct libcfs_ioctl_hdr ioc_hdr; - __u64 ioc_nid; - __u64 ioc_u64[1]; + __u64 ioc_nid; + __u64 ioc_u64[1]; - __u32 ioc_flags; - __u32 ioc_count; - __u32 ioc_net; - __u32 ioc_u32[7]; + __u32 ioc_flags; + __u32 ioc_count; + __u32 ioc_net; + __u32 ioc_u32[7]; - __u32 ioc_inllen1; - char *ioc_inlbuf1; - __u32 ioc_inllen2; - char *ioc_inlbuf2; + __u32 ioc_inllen1; + char *ioc_inlbuf1; + __u32 ioc_inllen2; + char *ioc_inlbuf2; - __u32 ioc_plen1; /* buffers in userspace */ - char *ioc_pbuf1; - __u32 ioc_plen2; /* buffers in userspace */ - char *ioc_pbuf2; + __u32 ioc_plen1; /* buffers in userspace */ + char *ioc_pbuf1; + __u32 ioc_plen2; /* buffers in userspace */ + char *ioc_pbuf2; - char ioc_bulk[0]; + char ioc_bulk[0]; }; #define ioc_priority ioc_u32[0] -struct libcfs_ioctl_hdr { - __u32 ioc_len; - __u32 ioc_version; -}; - struct libcfs_debug_ioctl_data { - struct libcfs_ioctl_hdr hdr; - unsigned int subs; - unsigned int debug; + struct libcfs_ioctl_hdr hdr; + unsigned int subs; + unsigned int debug; }; -#define LIBCFS_IOC_INIT(data) \ -do { \ - memset(&data, 0, sizeof(data)); \ - data.ioc_version = LIBCFS_IOCTL_VERSION; \ - data.ioc_len = sizeof(data); \ +#define LIBCFS_IOC_INIT(data) \ +do { \ + memset(&data, 0, sizeof(data)); \ + data.ioc_hdr.ioc_version = LIBCFS_IOCTL_VERSION; \ + data.ioc_hdr.ioc_len = sizeof(data); \ } while (0) #ifdef __KERNEL__ struct libcfs_ioctl_handler { struct list_head item; - int (*handle_ioctl)(unsigned int cmd, struct libcfs_ioctl_data *data); + int (*handle_ioctl)(unsigned int cmd, struct libcfs_ioctl_hdr *hdr); }; #define DECLARE_IOCTL_HANDLER(ident, func) \ @@ -151,75 +149,79 @@ struct libcfs_ioctl_handler { static inline int libcfs_ioctl_packlen(struct libcfs_ioctl_data *data) { - int len = sizeof(*data); - len += cfs_size_round(data->ioc_inllen1); - len += cfs_size_round(data->ioc_inllen2); - return len; + int len = sizeof(*data); + len += cfs_size_round(data->ioc_inllen1); + len += cfs_size_round(data->ioc_inllen2); + return len; } -static inline int libcfs_ioctl_is_invalid(struct libcfs_ioctl_data *data) +static inline bool libcfs_ioctl_is_invalid(struct libcfs_ioctl_data *data) { - if (data->ioc_len > (1<<30)) { - CERROR ("LIBCFS ioctl: ioc_len larger than 1<<30\n"); - return 1; - } - if (data->ioc_inllen1 > (1<<30)) { - CERROR ("LIBCFS ioctl: ioc_inllen1 larger than 1<<30\n"); - return 1; - } - if (data->ioc_inllen2 > (1<<30)) { - CERROR ("LIBCFS ioctl: ioc_inllen2 larger than 1<<30\n"); - return 1; - } - if (data->ioc_inlbuf1 && !data->ioc_inllen1) { - CERROR ("LIBCFS ioctl: inlbuf1 pointer but 0 length\n"); - return 1; - } - if (data->ioc_inlbuf2 && !data->ioc_inllen2) { - CERROR ("LIBCFS ioctl: inlbuf2 pointer but 0 length\n"); - return 1; - } - if (data->ioc_pbuf1 && !data->ioc_plen1) { - CERROR ("LIBCFS ioctl: pbuf1 pointer but 0 length\n"); - return 1; - } - if (data->ioc_pbuf2 && !data->ioc_plen2) { - CERROR ("LIBCFS ioctl: pbuf2 pointer but 0 length\n"); - return 1; - } - if (data->ioc_plen1 && !data->ioc_pbuf1) { - CERROR ("LIBCFS ioctl: plen1 nonzero but no pbuf1 pointer\n"); - return 1; - } - if (data->ioc_plen2 && !data->ioc_pbuf2) { - CERROR ("LIBCFS ioctl: plen2 nonzero but no pbuf2 pointer\n"); - return 1; - } - if ((__u32)libcfs_ioctl_packlen(data) != data->ioc_len ) { - CERROR ("LIBCFS ioctl: packlen != ioc_len\n"); - return 1; - } - if (data->ioc_inllen1 && - data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') { - CERROR ("LIBCFS ioctl: inlbuf1 not 0 terminated\n"); - return 1; - } - if (data->ioc_inllen2 && - data->ioc_bulk[cfs_size_round(data->ioc_inllen1) + - data->ioc_inllen2 - 1] != '\0') { - CERROR ("LIBCFS ioctl: inlbuf2 not 0 terminated\n"); - return 1; - } - return 0; + if (data->ioc_hdr.ioc_len > (1<<30)) { + CERROR("LIBCFS ioctl: ioc_len larger than 1<<30\n"); + return 1; + } + if (data->ioc_inllen1 > (1<<30)) { + CERROR("LIBCFS ioctl: ioc_inllen1 larger than 1<<30\n"); + return 1; + } + if (data->ioc_inllen2 > (1<<30)) { + CERROR("LIBCFS ioctl: ioc_inllen2 larger than 1<<30\n"); + return 1; + } + if (data->ioc_inlbuf1 && data->ioc_inllen1 == 0) { + CERROR("LIBCFS ioctl: inlbuf1 pointer but 0 length\n"); + return 1; + } + if (data->ioc_inlbuf2 && data->ioc_inllen2 == 0) { + CERROR("LIBCFS ioctl: inlbuf2 pointer but 0 length\n"); + return 1; + } + if (data->ioc_pbuf1 && data->ioc_plen1 == 0) { + CERROR("LIBCFS ioctl: pbuf1 pointer but 0 length\n"); + return 1; + } + if (data->ioc_pbuf2 && data->ioc_plen2 == 0) { + CERROR("LIBCFS ioctl: pbuf2 pointer but 0 length\n"); + return 1; + } + if (data->ioc_plen1 && data->ioc_pbuf1 == 0) { + CERROR("LIBCFS ioctl: plen1 nonzero but no pbuf1 pointer\n"); + return 1; + } + if (data->ioc_plen2 && data->ioc_pbuf2 == 0) { + CERROR("LIBCFS ioctl: plen2 nonzero but no pbuf2 pointer\n"); + return 1; + } + if ((__u32)libcfs_ioctl_packlen(data) != data->ioc_hdr.ioc_len) { + CERROR("LIBCFS ioctl: packlen != ioc_len\n"); + return 1; + } + if (data->ioc_inllen1 && + data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') { + CERROR("LIBCFS ioctl: inlbuf1 not 0 terminated\n"); + return 1; + } + if (data->ioc_inllen2 && + data->ioc_bulk[cfs_size_round(data->ioc_inllen1) + + data->ioc_inllen2 - 1] != '\0') { + CERROR("LIBCFS ioctl: inlbuf2 not 0 terminated\n"); + return 1; + } + return 0; } #ifdef __KERNEL__ extern int libcfs_register_ioctl(struct libcfs_ioctl_handler *hand); extern int libcfs_deregister_ioctl(struct libcfs_ioctl_handler *hand); -extern int libcfs_ioctl_getdata(char *buf, char *end, void *arg); +extern int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr *buf, __u32 buf_len, + const void __user *arg); +extern int libcfs_ioctl_getdata_len(const struct libcfs_ioctl_hdr __user *arg, + __u32 *buf_len); extern int libcfs_ioctl_popdata(void *arg, void *buf, int size); +#endif -#endif +extern int libcfs_ioctl_data_adjust(struct libcfs_ioctl_data *data); #endif /* __LIBCFS_IOCTL_H__ */ diff --git a/libcfs/libcfs/linux/linux-module.c b/libcfs/libcfs/linux/linux-module.c index f98ba64..0008125 100644 --- a/libcfs/libcfs/linux/linux-module.c +++ b/libcfs/libcfs/linux/linux-module.c @@ -40,53 +40,52 @@ #define LNET_MINOR 240 -int libcfs_ioctl_getdata(char *buf, char *end, void *arg) +int libcfs_ioctl_data_adjust(struct libcfs_ioctl_data *data) { - struct libcfs_ioctl_hdr *hdr; - struct libcfs_ioctl_data *data; - int err; - ENTRY; + if (libcfs_ioctl_is_invalid(data)) { + CERROR("LNET: ioctl not correctly formatted\n"); + RETURN(-EINVAL); + } - hdr = (struct libcfs_ioctl_hdr *)buf; - data = (struct libcfs_ioctl_data *)buf; + if (data->ioc_inllen1 != 0) + data->ioc_inlbuf1 = &data->ioc_bulk[0]; - err = copy_from_user(buf, (void *)arg, sizeof(*hdr)); - if (err) - RETURN(err); + if (data->ioc_inllen2 != 0) + data->ioc_inlbuf2 = &data->ioc_bulk[0] + + cfs_size_round(data->ioc_inllen1); - if (hdr->ioc_version != LIBCFS_IOCTL_VERSION) { - CERROR("PORTALS: version mismatch kernel vs application\n"); - RETURN(-EINVAL); - } + RETURN(0); +} - if (hdr->ioc_len + buf >= end) { - CERROR("PORTALS: user buffer exceeds kernel buffer\n"); - RETURN(-EINVAL); - } +int libcfs_ioctl_getdata_len(const struct libcfs_ioctl_hdr __user *arg, + __u32 *len) +{ + struct libcfs_ioctl_hdr hdr; + ENTRY; + if (copy_from_user(&hdr, arg, sizeof(hdr))) + RETURN(-EFAULT); - if (hdr->ioc_len < sizeof(struct libcfs_ioctl_data)) { - CERROR("PORTALS: user buffer too small for ioctl\n"); - RETURN(-EINVAL); - } + if (hdr.ioc_version != LIBCFS_IOCTL_VERSION) { + CERROR("LNET: version mismatch expected %#x, got %#x\n", + LIBCFS_IOCTL_VERSION, hdr.ioc_version); + RETURN(-EINVAL); + } - err = copy_from_user(buf, (void *)arg, hdr->ioc_len); - if (err) - RETURN(err); + *len = hdr.ioc_len; - if (libcfs_ioctl_is_invalid(data)) { - CERROR("PORTALS: ioctl not correctly formatted\n"); - RETURN(-EINVAL); - } + RETURN(0); +} - if (data->ioc_inllen1) - data->ioc_inlbuf1 = &data->ioc_bulk[0]; +int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr *buf, __u32 buf_len, + const void __user *arg) +{ + ENTRY; - if (data->ioc_inllen2) - data->ioc_inlbuf2 = &data->ioc_bulk[0] + - cfs_size_round(data->ioc_inllen1); + if (copy_from_user(buf, arg, buf_len)) + RETURN(-EINVAL); - RETURN(0); + RETURN(0); } int libcfs_ioctl_popdata(void *arg, void *data, int size) diff --git a/libcfs/libcfs/module.c b/libcfs/libcfs/module.c index efd4213..8eeca56 100644 --- a/libcfs/libcfs/module.c +++ b/libcfs/libcfs/module.c @@ -35,6 +35,11 @@ */ #define DEBUG_SUBSYSTEM S_LNET +/* TODO - This will be completed in the subsequent patches. + * For this patch the MAX is hardcoded, in the next patch + * the value will be set to the largest data structure that + * can be sent from user space */ +#define LIBCFS_MAX_IOCTL_BUF_LEN 2048 #include #include @@ -218,41 +223,54 @@ int libcfs_deregister_ioctl(struct libcfs_ioctl_handler *hand) } EXPORT_SYMBOL(libcfs_deregister_ioctl); -static int libcfs_ioctl_int(struct cfs_psdev_file *pfile,unsigned long cmd, - void *arg, struct libcfs_ioctl_data *data) +static int libcfs_ioctl_handle(struct cfs_psdev_file *pfile, unsigned long cmd, + void *arg, struct libcfs_ioctl_hdr *hdr) { - int err = -EINVAL; - ENTRY; - - switch (cmd) { - case IOC_LIBCFS_CLEAR_DEBUG: - libcfs_debug_clear_buffer(); - RETURN(0); - /* - * case IOC_LIBCFS_PANIC: - * Handled in arch/cfs_module.c - */ - case IOC_LIBCFS_MARK_DEBUG: - if (data->ioc_inlbuf1 == NULL || - data->ioc_inlbuf1[data->ioc_inllen1 - 1] != '\0') - RETURN(-EINVAL); - libcfs_debug_mark_buffer(data->ioc_inlbuf1); - RETURN(0); - case IOC_LIBCFS_MEMHOG: - if (pfile->private_data == NULL) { - err = -EINVAL; - } else { - kportal_memhog_free(pfile->private_data); - /* XXX The ioc_flags is not GFP flags now, need to be fixed */ - err = kportal_memhog_alloc(pfile->private_data, - data->ioc_count, - data->ioc_flags); - if (err != 0) - kportal_memhog_free(pfile->private_data); - } - break; - - case IOC_LIBCFS_PING_TEST: { + struct libcfs_ioctl_data *data = NULL; + int err; + ENTRY; + + /* TODO: this is going to change in subsequent patches + * to exclude messages which use the new data structures */ + if ((cmd <= IOC_LIBCFS_LNETST) || + (cmd >= IOC_LIBCFS_REGISTER_MYNID)) { + data = container_of(hdr, struct libcfs_ioctl_data, ioc_hdr); + err = libcfs_ioctl_data_adjust(data); + if (err != 0) { + RETURN(err); + } + } + + switch (cmd) { + case IOC_LIBCFS_CLEAR_DEBUG: + libcfs_debug_clear_buffer(); + RETURN(0); + /* + * case IOC_LIBCFS_PANIC: + * Handled in arch/cfs_module.c + */ + case IOC_LIBCFS_MARK_DEBUG: + if (data->ioc_inlbuf1 == NULL || + data->ioc_inlbuf1[data->ioc_inllen1 - 1] != '\0') + RETURN(-EINVAL); + libcfs_debug_mark_buffer(data->ioc_inlbuf1); + RETURN(0); + case IOC_LIBCFS_MEMHOG: + if (pfile->private_data == NULL) { + err = -EINVAL; + } else { + kportal_memhog_free(pfile->private_data); + /* XXX The ioc_flags is not GFP flags now, need to + * be fixed */ + err = kportal_memhog_alloc(pfile->private_data, + data->ioc_count, + data->ioc_flags); + if (err != 0) + kportal_memhog_free(pfile->private_data); + } + break; + + case IOC_LIBCFS_PING_TEST: { extern void (kping_client)(struct libcfs_ioctl_data *); void (*ping)(struct libcfs_ioctl_data *); @@ -269,17 +287,17 @@ static int libcfs_ioctl_int(struct cfs_psdev_file *pfile,unsigned long cmd, RETURN(0); } - default: { + default: { struct libcfs_ioctl_handler *hand; err = -EINVAL; down_read(&ioctl_list_sem); list_for_each_entry(hand, &ioctl_list, item) { - err = hand->handle_ioctl(cmd, data); + err = hand->handle_ioctl(cmd, hdr); if (err != -EINVAL) { if (err == 0) err = libcfs_ioctl_popdata(arg, - data, sizeof (*data)); + hdr, hdr->ioc_len); break; } } @@ -294,27 +312,39 @@ static int libcfs_ioctl_int(struct cfs_psdev_file *pfile,unsigned long cmd, static int libcfs_ioctl(struct cfs_psdev_file *pfile, unsigned long cmd, void *arg) { - char *buf; - struct libcfs_ioctl_data *data; + struct libcfs_ioctl_hdr *hdr; int err = 0; + __u32 buf_len; ENTRY; - LIBCFS_ALLOC_GFP(buf, 1024, GFP_IOFS); - if (buf == NULL) + err = libcfs_ioctl_getdata_len(arg, &buf_len); + if (err != 0) + RETURN(err); + + /* + * do a check here to restrict the size of the memory + * to allocate to guard against DoS attacks. + */ + if (buf_len > LIBCFS_MAX_IOCTL_BUF_LEN) { + CERROR("LNET: user buffer exceeds kernel buffer\n"); + RETURN(-EINVAL); + } + + LIBCFS_ALLOC_GFP(hdr, buf_len, GFP_IOFS); + if (hdr == NULL) RETURN(-ENOMEM); - /* 'cmd' and permissions get checked in our arch-specific caller */ - if (libcfs_ioctl_getdata(buf, buf + 800, (void *)arg)) { - CERROR("PORTALS ioctl: data error\n"); - GOTO(out, err = -EINVAL); - } - data = (struct libcfs_ioctl_data *)buf; + /* 'cmd' and permissions get checked in our arch-specific caller */ + if (libcfs_ioctl_getdata(hdr, buf_len, arg)) { + CERROR("LNET ioctl: data error\n"); + GOTO(out, err = -EINVAL); + } - err = libcfs_ioctl_int(pfile, cmd, arg, data); + err = libcfs_ioctl_handle(pfile, cmd, arg, hdr); out: - LIBCFS_FREE(buf, 1024); - RETURN(err); + LIBCFS_FREE(hdr, buf_len); + RETURN(err); } diff --git a/libcfs/libcfs/util/l_ioctl.c b/libcfs/libcfs/util/l_ioctl.c index dfdd8ab..9dcf1db 100644 --- a/libcfs/libcfs/util/l_ioctl.c +++ b/libcfs/libcfs/util/l_ioctl.c @@ -316,29 +316,28 @@ jt_ioc_dump(int argc, char **argv) int libcfs_ioctl_pack(struct libcfs_ioctl_data *data, char **pbuf, int max) { - char *ptr; - struct libcfs_ioctl_data *overlay; - data->ioc_len = libcfs_ioctl_packlen(data); - data->ioc_version = LIBCFS_IOCTL_VERSION; - - if (*pbuf && libcfs_ioctl_packlen(data) > max) - return 1; - if (*pbuf == NULL) { - *pbuf = malloc(data->ioc_len); - } - if (!*pbuf) - return 1; - overlay = (struct libcfs_ioctl_data *)*pbuf; - memcpy(*pbuf, data, sizeof(*data)); - - ptr = overlay->ioc_bulk; - if (data->ioc_inlbuf1) - LOGL(data->ioc_inlbuf1, data->ioc_inllen1, ptr); - if (data->ioc_inlbuf2) - LOGL(data->ioc_inlbuf2, data->ioc_inllen2, ptr); - if (libcfs_ioctl_is_invalid(overlay)) - return 1; + char *ptr; + struct libcfs_ioctl_data *overlay; + data->ioc_hdr.ioc_len = libcfs_ioctl_packlen(data); + data->ioc_hdr.ioc_version = LIBCFS_IOCTL_VERSION; + + if (*pbuf != NULL && libcfs_ioctl_packlen(data) > max) + return 1; + if (*pbuf == NULL) + *pbuf = malloc(data->ioc_hdr.ioc_len); + if (*pbuf == NULL) + return 1; + overlay = (struct libcfs_ioctl_data *)*pbuf; + memcpy(*pbuf, data, sizeof(*data)); + + ptr = overlay->ioc_bulk; + if (data->ioc_inlbuf1 != NULL) + LOGL(data->ioc_inlbuf1, data->ioc_inllen1, ptr); + if (data->ioc_inlbuf2 != NULL) + LOGL(data->ioc_inlbuf2, data->ioc_inllen2, ptr); + if (libcfs_ioctl_is_invalid(overlay)) + return 1; - return 0; + return 0; } diff --git a/lnet/lnet/module.c b/lnet/lnet/module.c index 9d57479..aaad649 100644 --- a/lnet/lnet/module.c +++ b/lnet/lnet/module.c @@ -84,28 +84,28 @@ lnet_unconfigure (void) } int -lnet_ioctl(unsigned int cmd, struct libcfs_ioctl_data *data) +lnet_ioctl(unsigned int cmd, struct libcfs_ioctl_hdr *hdr) { - int rc; - - switch (cmd) { - case IOC_LIBCFS_CONFIGURE: - return lnet_configure(NULL); - - case IOC_LIBCFS_UNCONFIGURE: - return lnet_unconfigure(); - - default: - /* Passing LNET_PID_ANY only gives me a ref if the net is up - * already; I'll need it to ensure the net can't go down while - * I'm called into it */ - rc = LNetNIInit(LNET_PID_ANY); - if (rc >= 0) { - rc = LNetCtl(cmd, data); - LNetNIFini(); - } - return rc; - } + int rc; + + switch (cmd) { + case IOC_LIBCFS_CONFIGURE: + return lnet_configure(NULL); + + case IOC_LIBCFS_UNCONFIGURE: + return lnet_unconfigure(); + + default: + /* Passing LNET_PID_ANY only gives me a ref if the net is up + * already; I'll need it to ensure the net can't go down while + * I'm called into it */ + rc = LNetNIInit(LNET_PID_ANY); + if (rc >= 0) { + rc = LNetCtl(cmd, hdr); + LNetNIFini(); + } + return rc; + } } DECLARE_IOCTL_HANDLER(lnet_ioctl_handler, lnet_ioctl); diff --git a/lnet/selftest/conctl.c b/lnet/selftest/conctl.c index 7fe5fb2..2285afd 100644 --- a/lnet/selftest/conctl.c +++ b/lnet/selftest/conctl.c @@ -35,7 +35,7 @@ * * lnet/selftest/conctl.c * - * IOC handle in kernel + * IOC handle in kernel * * Author: Liang Zhen */ @@ -810,15 +810,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; @@ -834,83 +839,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(); - - if (console_session.ses_shutdown) { - rc = -ESHUTDOWN; - goto out; - } + console_session.ses_laststamp = cfs_time_current_sec(); - 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))) diff --git a/lnet/selftest/console.c b/lnet/selftest/console.c index 8179f10..73031a5 100644 --- a/lnet/selftest/console.c +++ b/lnet/selftest/console.c @@ -2015,7 +2015,7 @@ void lstcon_init_acceptor_service(void) lstcon_acceptor_service.sv_wi_total = SFW_FRWK_WI_MAX; } -extern int lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data); +int lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_hdr *hdr); DECLARE_IOCTL_HANDLER(lstcon_ioctl_handler, lstcon_ioctl_entry); diff --git a/lnet/utils/debug.c b/lnet/utils/debug.c index b87b43c..e1dd37b 100644 --- a/lnet/utils/debug.c +++ b/lnet/utils/debug.c @@ -752,18 +752,19 @@ int jt_dbg_mark_debug_buf(int argc, char **argv) data.ioc_inllen1 = strlen(text) + 1; data.ioc_inlbuf1 = text; - if (libcfs_ioctl_pack(&data, &buf, max) != 0) { - fprintf(stderr, "libcfs_ioctl_pack failed.\n"); - return -1; - } - rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_MARK_DEBUG, buf); - if (rc) { - fprintf(stderr, "IOC_LIBCFS_MARK_DEBUG failed: %s\n", - strerror(errno)); - return -1; - } - return 0; + if (libcfs_ioctl_pack(&data, &buf, max) != 0) { + fprintf(stderr, "libcfs_ioctl_pack failed.\n"); + return -1; + } + + rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_MARK_DEBUG, buf); + if (rc) { + fprintf(stderr, "IOC_LIBCFS_MARK_DEBUG failed: %s\n", + strerror(errno)); + return -1; + } + return 0; } static struct mod_paths {