From: James Simmons Date: Fri, 20 Apr 2018 15:28:25 +0000 (-0400) Subject: LU-8837 obd: remove linux directory X-Git-Tag: 2.11.52~20 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=6f8d0e2905286cadda1564ace6c2e6b034f0dfd6 LU-8837 obd: remove linux directory With only two files in obdclass/linux we can move the code around. Rename linux-obdo.c to obdo_server.c since its only server code. Move the ioctl handling in linux-module.c to class_obd.c and rename linux-module.c to obd_sysfs.c since it only contains sysfs/ debugfs code. Test-Parameters: trivial Change-Id: Ie4b99cf37f83158f9d43eb38c971c1602f805c6f Signed-off-by: James Simmons Reviewed-on: https://review.whamcloud.com/32100 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: John L. Hammond Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin --- diff --git a/lustre/autoconf/lustre-core.m4 b/lustre/autoconf/lustre-core.m4 index 485cfbf..b1f17d0 100644 --- a/lustre/autoconf/lustre-core.m4 +++ b/lustre/autoconf/lustre-core.m4 @@ -3390,7 +3390,6 @@ lustre/fld/Makefile lustre/fld/autoMakefile lustre/obdclass/Makefile lustre/obdclass/autoMakefile -lustre/obdclass/linux/Makefile lustre/obdecho/Makefile lustre/obdecho/autoMakefile lustre/ofd/Makefile diff --git a/lustre/obdclass/Makefile.in b/lustre/obdclass/Makefile.in index 4b2ea1e..1414ae9 100644 --- a/lustre/obdclass/Makefile.in +++ b/lustre/obdclass/Makefile.in @@ -1,15 +1,12 @@ MODULES := obdclass llog_test -obdclass-linux-objs := linux-module.o linux-obdo.o -obdclass-linux-objs := $(addprefix linux/,$(obdclass-linux-objs)) - default: all obdclass-all-objs := llog.o llog_cat.o llog_obd.o llog_swab.o llog_osd.o obdclass-all-objs += class_obd.o debug.o genops.o llog_ioctl.o obdclass-all-objs += lprocfs_status.o lprocfs_counters.o obdclass-all-objs += lustre_handles.o lustre_peer.o local_storage.o -obdclass-all-objs += statfs_pack.o obdo.o obd_config.o obd_mount.o +obdclass-all-objs += statfs_pack.o obdo.o obd_config.o obd_mount.o obd_sysfs.o obdclass-all-objs += lu_object.o dt_object.o obdclass-all-objs += cl_object.o cl_page.o cl_lock.o cl_io.o lu_ref.o obdclass-all-objs += linkea.o @@ -23,9 +20,10 @@ obdclass-all-objs += kernelcomm.o jobid.o @SERVER_TRUE@obdclass-all-objs += lu_ucred.o @SERVER_TRUE@obdclass-all-objs += md_attrs.o @SERVER_TRUE@obdclass-all-objs += obd_mount_server.o +@SERVER_TRUE@obdclass-all-objs += obdo_server.o @SERVER_TRUE@obdclass-all-objs += scrub.o -obdclass-objs := $(obdclass-linux-objs) $(obdclass-all-objs) +obdclass-objs := $(obdclass-all-objs) EXTRA_PRE_CFLAGS := -I@LINUX@/fs -I@LDISKFS_DIR@ -I@LDISKFS_DIR@/ldiskfs @@ -40,6 +38,7 @@ EXTRA_DIST += cl_internal.h local_storage.h @SERVER_FALSE@EXTRA_DIST += lu_ucred.c @SERVER_FALSE@EXTRA_DIST += md_attrs.c @SERVER_FALSE@EXTRA_DIST += obd_mount_server.c +@SERVER_FALSE@EXTRA_DIST += obdo_server.c @SERVER_FALSE@EXTRA_DIST += scrub.c @INCLUDE_RULES@ diff --git a/lustre/obdclass/autoMakefile.am b/lustre/obdclass/autoMakefile.am index f290acf..962a416 100644 --- a/lustre/obdclass/autoMakefile.am +++ b/lustre/obdclass/autoMakefile.am @@ -1,6 +1,3 @@ -SUBDIRS = linux -DIST_SUBDIRS = linux - if MODULES if LINUX @@ -13,4 +10,3 @@ endif # LINUX endif # MODULES MOSTLYCLEANFILES := @MOSTLYCLEANFILES@ -MOSTLYCLEANFILES += linux/*.o diff --git a/lustre/obdclass/class_obd.c b/lustre/obdclass/class_obd.c index 59be17a..9bb407c 100644 --- a/lustre/obdclass/class_obd.c +++ b/lustre/obdclass/class_obd.c @@ -133,6 +133,159 @@ out: RETURN(rc); } +#define OBD_MAX_IOCTL_BUFFER 8192 + +static int obd_ioctl_is_invalid(struct obd_ioctl_data *data) +{ + if (data->ioc_len > BIT(30)) { + CERROR("OBD ioctl: ioc_len larger than 1<<30\n"); + return 1; + } + + if (data->ioc_inllen1 > BIT(30)) { + CERROR("OBD ioctl: ioc_inllen1 larger than 1<<30\n"); + return 1; + } + + if (data->ioc_inllen2 > BIT(30)) { + CERROR("OBD ioctl: ioc_inllen2 larger than 1<<30\n"); + return 1; + } + + if (data->ioc_inllen3 > BIT(30)) { + CERROR("OBD ioctl: ioc_inllen3 larger than 1<<30\n"); + return 1; + } + + if (data->ioc_inllen4 > BIT(30)) { + CERROR("OBD ioctl: ioc_inllen4 larger than 1<<30\n"); + return 1; + } + + if (data->ioc_inlbuf1 && data->ioc_inllen1 == 0) { + CERROR("OBD ioctl: inlbuf1 pointer but 0 length\n"); + return 1; + } + + if (data->ioc_inlbuf2 && data->ioc_inllen2 == 0) { + CERROR("OBD ioctl: inlbuf2 pointer but 0 length\n"); + return 1; + } + + if (data->ioc_inlbuf3 && data->ioc_inllen3 == 0) { + CERROR("OBD ioctl: inlbuf3 pointer but 0 length\n"); + return 1; + } + + if (data->ioc_inlbuf4 && data->ioc_inllen4 == 0) { + CERROR("OBD ioctl: inlbuf4 pointer but 0 length\n"); + return 1; + } + + if (data->ioc_pbuf1 && data->ioc_plen1 == 0) { + CERROR("OBD ioctl: pbuf1 pointer but 0 length\n"); + return 1; + } + + if (data->ioc_pbuf2 && data->ioc_plen2 == 0) { + CERROR("OBD ioctl: pbuf2 pointer but 0 length\n"); + return 1; + } + + if (!data->ioc_pbuf1 && data->ioc_plen1 != 0) { + CERROR("OBD ioctl: plen1 set but NULL pointer\n"); + return 1; + } + + if (!data->ioc_pbuf2 && data->ioc_plen2 != 0) { + CERROR("OBD ioctl: plen2 set but NULL pointer\n"); + return 1; + } + + if (obd_ioctl_packlen(data) > data->ioc_len) { + CERROR("OBD ioctl: packlen exceeds ioc_len (%d > %d)\n", + obd_ioctl_packlen(data), data->ioc_len); + return 1; + } + + return 0; +} + +/* buffer MUST be at least the size of obd_ioctl_hdr */ +int obd_ioctl_getdata(char **buf, int *len, void __user *arg) +{ + struct obd_ioctl_hdr hdr; + struct obd_ioctl_data *data; + int offset = 0; + + ENTRY; + if (copy_from_user(&hdr, arg, sizeof(hdr))) + RETURN(-EFAULT); + + if (hdr.ioc_version != OBD_IOCTL_VERSION) { + CERROR("Version mismatch kernel (%x) vs application (%x)\n", + OBD_IOCTL_VERSION, hdr.ioc_version); + RETURN(-EINVAL); + } + + if (hdr.ioc_len > OBD_MAX_IOCTL_BUFFER) { + CERROR("User buffer len %d exceeds %d max buffer\n", + hdr.ioc_len, OBD_MAX_IOCTL_BUFFER); + RETURN(-EINVAL); + } + + if (hdr.ioc_len < sizeof(struct obd_ioctl_data)) { + CERROR("User buffer too small for ioctl (%d)\n", hdr.ioc_len); + RETURN(-EINVAL); + } + + /* When there are lots of processes calling vmalloc on multi-core + * system, the high lock contention will hurt performance badly, + * obdfilter-survey is an example, which relies on ioctl. So we'd + * better avoid vmalloc on ioctl path. LU-66 + */ + OBD_ALLOC_LARGE(*buf, hdr.ioc_len); + if (!*buf) { + CERROR("Cannot allocate control buffer of len %d\n", + hdr.ioc_len); + RETURN(-EINVAL); + } + *len = hdr.ioc_len; + data = (struct obd_ioctl_data *)*buf; + + if (copy_from_user(*buf, arg, hdr.ioc_len)) { + OBD_FREE_LARGE(*buf, hdr.ioc_len); + RETURN(-EFAULT); + } + + if (obd_ioctl_is_invalid(data)) { + CERROR("ioctl not correctly formatted\n"); + OBD_FREE_LARGE(*buf, hdr.ioc_len); + RETURN(-EINVAL); + } + + if (data->ioc_inllen1) { + data->ioc_inlbuf1 = &data->ioc_bulk[0]; + offset += cfs_size_round(data->ioc_inllen1); + } + + if (data->ioc_inllen2) { + data->ioc_inlbuf2 = &data->ioc_bulk[0] + offset; + offset += cfs_size_round(data->ioc_inllen2); + } + + if (data->ioc_inllen3) { + data->ioc_inlbuf3 = &data->ioc_bulk[0] + offset; + offset += cfs_size_round(data->ioc_inllen3); + } + + if (data->ioc_inllen4) + data->ioc_inlbuf4 = &data->ioc_bulk[0] + offset; + + RETURN(0); +} +EXPORT_SYMBOL(obd_ioctl_getdata); + int class_handle_ioctl(unsigned int cmd, unsigned long arg) { char *buf = NULL; @@ -348,6 +501,57 @@ out: RETURN(err); } /* class_handle_ioctl */ +/* opening /dev/obd */ +static int obd_class_open(struct inode * inode, struct file * file) +{ + ENTRY; + try_module_get(THIS_MODULE); + RETURN(0); +} + +/* closing /dev/obd */ +static int obd_class_release(struct inode * inode, struct file * file) +{ + ENTRY; + + module_put(THIS_MODULE); + RETURN(0); +} + +/* to control /dev/obd */ +static long obd_class_ioctl(struct file *filp, unsigned int cmd, + unsigned long arg) +{ + int err = 0; + + ENTRY; + /* Allow non-root access for OBD_IOC_PING_TARGET - used by lfs check */ + if (!cfs_capable(CFS_CAP_SYS_ADMIN) && (cmd != OBD_IOC_PING_TARGET)) + RETURN(err = -EACCES); + + if ((cmd & 0xffffff00) == ((int)'T') << 8) /* ignore all tty ioctls */ + RETURN(err = -ENOTTY); + + err = class_handle_ioctl(cmd, (unsigned long)arg); + + RETURN(err); +} + +/* declare character device */ +static struct file_operations obd_psdev_fops = { + .owner = THIS_MODULE, + .unlocked_ioctl = obd_class_ioctl, /* unlocked_ioctl */ + .open = obd_class_open, /* open */ + .release = obd_class_release, /* release */ +}; + +/* modules setup */ +struct miscdevice obd_psdev = { + .minor = MISC_DYNAMIC_MINOR, + .name = OBD_DEV_NAME, + .fops = &obd_psdev_fops, +}; + static int obd_init_checks(void) { __u64 u64val, div64val; diff --git a/lustre/obdclass/linux/.gitignore b/lustre/obdclass/linux/.gitignore deleted file mode 100644 index 10a7e8d..0000000 --- a/lustre/obdclass/linux/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/Makefile.in diff --git a/lustre/obdclass/linux/Makefile.am b/lustre/obdclass/linux/Makefile.am deleted file mode 100644 index 7d1d31d..0000000 --- a/lustre/obdclass/linux/Makefile.am +++ /dev/null @@ -1,3 +0,0 @@ -EXTRA_DIST = \ - linux-module.c \ - linux-obdo.c diff --git a/lustre/obdclass/linux/linux-module.c b/lustre/obdclass/obd_sysfs.c similarity index 70% rename from lustre/obdclass/linux/linux-module.c rename to lustre/obdclass/obd_sysfs.c index 464d288..64ab464 100644 --- a/lustre/obdclass/linux/linux-module.c +++ b/lustre/obdclass/obd_sysfs.c @@ -29,7 +29,7 @@ * This file is part of Lustre, http://www.lustre.org/ * Lustre is a trademark of Sun Microsystems, Inc. * - * lustre/obdclass/linux/linux-module.c + * lustre/obdclass/obd_sysfs.c * * Object Devices Class Driver * These are the only exported functions, they provide some generic @@ -70,209 +70,6 @@ #include #include -#define OBD_MAX_IOCTL_BUFFER 8192 - -static int obd_ioctl_is_invalid(struct obd_ioctl_data *data) -{ - if (data->ioc_len > BIT(30)) { - CERROR("OBD ioctl: ioc_len larger than 1<<30\n"); - return 1; - } - - if (data->ioc_inllen1 > BIT(30)) { - CERROR("OBD ioctl: ioc_inllen1 larger than 1<<30\n"); - return 1; - } - - if (data->ioc_inllen2 > BIT(30)) { - CERROR("OBD ioctl: ioc_inllen2 larger than 1<<30\n"); - return 1; - } - - if (data->ioc_inllen3 > BIT(30)) { - CERROR("OBD ioctl: ioc_inllen3 larger than 1<<30\n"); - return 1; - } - - if (data->ioc_inllen4 > BIT(30)) { - CERROR("OBD ioctl: ioc_inllen4 larger than 1<<30\n"); - return 1; - } - - if (data->ioc_inlbuf1 && data->ioc_inllen1 == 0) { - CERROR("OBD ioctl: inlbuf1 pointer but 0 length\n"); - return 1; - } - - if (data->ioc_inlbuf2 && data->ioc_inllen2 == 0) { - CERROR("OBD ioctl: inlbuf2 pointer but 0 length\n"); - return 1; - } - - if (data->ioc_inlbuf3 && data->ioc_inllen3 == 0) { - CERROR("OBD ioctl: inlbuf3 pointer but 0 length\n"); - return 1; - } - - if (data->ioc_inlbuf4 && data->ioc_inllen4 == 0) { - CERROR("OBD ioctl: inlbuf4 pointer but 0 length\n"); - return 1; - } - - if (data->ioc_pbuf1 && data->ioc_plen1 == 0) { - CERROR("OBD ioctl: pbuf1 pointer but 0 length\n"); - return 1; - } - - if (data->ioc_pbuf2 && data->ioc_plen2 == 0) { - CERROR("OBD ioctl: pbuf2 pointer but 0 length\n"); - return 1; - } - - if (!data->ioc_pbuf1 && data->ioc_plen1 != 0) { - CERROR("OBD ioctl: plen1 set but NULL pointer\n"); - return 1; - } - - if (!data->ioc_pbuf2 && data->ioc_plen2 != 0) { - CERROR("OBD ioctl: plen2 set but NULL pointer\n"); - return 1; - } - - if (obd_ioctl_packlen(data) > data->ioc_len) { - CERROR("OBD ioctl: packlen exceeds ioc_len (%d > %d)\n", - obd_ioctl_packlen(data), data->ioc_len); - return 1; - } - - return 0; -} - -/* buffer MUST be at least the size of obd_ioctl_hdr */ -int obd_ioctl_getdata(char **buf, int *len, void __user *arg) -{ - struct obd_ioctl_hdr hdr; - struct obd_ioctl_data *data; - int offset = 0; - ENTRY; - - if (copy_from_user(&hdr, arg, sizeof(hdr))) - RETURN(-EFAULT); - - if (hdr.ioc_version != OBD_IOCTL_VERSION) { - CERROR("Version mismatch kernel (%x) vs application (%x)\n", - OBD_IOCTL_VERSION, hdr.ioc_version); - RETURN(-EINVAL); - } - - if (hdr.ioc_len > OBD_MAX_IOCTL_BUFFER) { - CERROR("User buffer len %d exceeds %d max buffer\n", - hdr.ioc_len, OBD_MAX_IOCTL_BUFFER); - RETURN(-EINVAL); - } - - if (hdr.ioc_len < sizeof(struct obd_ioctl_data)) { - CERROR("User buffer too small for ioctl (%d)\n", hdr.ioc_len); - RETURN(-EINVAL); - } - - /* When there are lots of processes calling vmalloc on multi-core - * system, the high lock contention will hurt performance badly, - * obdfilter-survey is an example, which relies on ioctl. So we'd - * better avoid vmalloc on ioctl path. LU-66 */ - OBD_ALLOC_LARGE(*buf, hdr.ioc_len); - if (*buf == NULL) { - CERROR("Cannot allocate control buffer of len %d\n", - hdr.ioc_len); - RETURN(-EINVAL); - } - *len = hdr.ioc_len; - data = (struct obd_ioctl_data *)*buf; - - if (copy_from_user(*buf, arg, hdr.ioc_len)) { - OBD_FREE_LARGE(*buf, hdr.ioc_len); - RETURN(-EFAULT); - } - - if (obd_ioctl_is_invalid(data)) { - CERROR("ioctl not correctly formatted\n"); - OBD_FREE_LARGE(*buf, hdr.ioc_len); - RETURN(-EINVAL); - } - - if (data->ioc_inllen1) { - data->ioc_inlbuf1 = &data->ioc_bulk[0]; - offset += cfs_size_round(data->ioc_inllen1); - } - - if (data->ioc_inllen2) { - data->ioc_inlbuf2 = &data->ioc_bulk[0] + offset; - offset += cfs_size_round(data->ioc_inllen2); - } - - if (data->ioc_inllen3) { - data->ioc_inlbuf3 = &data->ioc_bulk[0] + offset; - offset += cfs_size_round(data->ioc_inllen3); - } - - if (data->ioc_inllen4) - data->ioc_inlbuf4 = &data->ioc_bulk[0] + offset; - - RETURN(0); -} -EXPORT_SYMBOL(obd_ioctl_getdata); - -/* opening /dev/obd */ -static int obd_class_open(struct inode * inode, struct file * file) -{ - ENTRY; - - try_module_get(THIS_MODULE); - RETURN(0); -} - -/* closing /dev/obd */ -static int obd_class_release(struct inode * inode, struct file * file) -{ - ENTRY; - - module_put(THIS_MODULE); - RETURN(0); -} - -/* to control /dev/obd */ -static long obd_class_ioctl(struct file *filp, unsigned int cmd, - unsigned long arg) -{ - int err = 0; - ENTRY; - - /* Allow non-root access for OBD_IOC_PING_TARGET - used by lfs check */ - if (!cfs_capable(CFS_CAP_SYS_ADMIN) && (cmd != OBD_IOC_PING_TARGET)) - RETURN(err = -EACCES); - if ((cmd & 0xffffff00) == ((int)'T') << 8) /* ignore all tty ioctls */ - RETURN(err = -ENOTTY); - - err = class_handle_ioctl(cmd, (unsigned long)arg); - - RETURN(err); -} - -/* declare character device */ -static struct file_operations obd_psdev_fops = { - .owner = THIS_MODULE, - .unlocked_ioctl = obd_class_ioctl, /* unlocked_ioctl */ - .open = obd_class_open, /* open */ - .release = obd_class_release, /* release */ -}; - -/* modules setup */ -struct miscdevice obd_psdev = { - .minor = MISC_DYNAMIC_MINOR, - .name = OBD_DEV_NAME, - .fops = &obd_psdev_fops, -}; - struct static_lustre_uintvalue_attr { struct { struct attribute attr; diff --git a/lustre/obdclass/linux/linux-obdo.c b/lustre/obdclass/obdo_server.c similarity index 100% rename from lustre/obdclass/linux/linux-obdo.c rename to lustre/obdclass/obdo_server.c