From 56cc9aeb7151f908ab9cac034ceaf11098bac6a4 Mon Sep 17 00:00:00 2001 From: Dmitry Zogin Date: Wed, 3 Feb 2010 09:41:27 -0500 Subject: [PATCH] b=21259 "lfs check" is only allowed for root. Code cleanup around obd_class_*() functions and sanity test for non-root lfs check i=adilger i=andrew.perepechko --- lnet/include/lnet/lnetctl.h | 3 ++- lustre/include/obd_class.h | 1 + lustre/obdclass/class_obd.c | 38 ++-------------------------------- lustre/obdclass/darwin/darwin-module.c | 22 +++++++------------- lustre/obdclass/linux/linux-module.c | 27 +++++++++++------------- lustre/tests/sanity.sh | 15 ++++++++++++-- 6 files changed, 38 insertions(+), 68 deletions(-) diff --git a/lnet/include/lnet/lnetctl.h b/lnet/include/lnet/lnetctl.h index 5b58e2a..3a12a70 100644 --- a/lnet/include/lnet/lnetctl.h +++ b/lnet/include/lnet/lnetctl.h @@ -29,7 +29,8 @@ #define LNET_DEV_MAJOR 10 #define LNET_DEV_MINOR 240 #define OBD_DEV_ID 1 -#define OBD_DEV_PATH "/dev/obd" +#define OBD_DEV_NAME "obd" +#define OBD_DEV_PATH "/dev/" OBD_DEV_NAME #define OBD_DEV_MAJOR 10 #define OBD_DEV_MINOR 241 #define SMFS_DEV_ID 2 diff --git a/lustre/include/obd_class.h b/lustre/include/obd_class.h index 4dc266f..f86dca8 100644 --- a/lustre/include/obd_class.h +++ b/lustre/include/obd_class.h @@ -65,6 +65,7 @@ extern cfs_spinlock_t obd_dev_lock; /* OBD Operations Declarations */ extern struct obd_device *class_conn2obd(struct lustre_handle *); extern struct obd_device *class_exp2obd(struct obd_export *); +extern int class_handle_ioctl(unsigned int cmd, unsigned long arg); struct lu_device_type; diff --git a/lustre/obdclass/class_obd.c b/lustre/obdclass/class_obd.c index bf6fb32..7d2d3c9 100644 --- a/lustre/obdclass/class_obd.c +++ b/lustre/obdclass/class_obd.c @@ -46,6 +46,7 @@ #include #include +#include #include #include #include @@ -94,24 +95,6 @@ unsigned long obd_print_fail_loc(void) CWARN("obd_fail_loc = %lx\n", obd_fail_loc); return obd_fail_loc; } - -/* opening /dev/obd */ -static int obd_class_open(unsigned long flags, void *args) -{ - ENTRY; - - PORTAL_MODULE_USE; - RETURN(0); -} - -/* closing /dev/obd */ -static int obd_class_release(unsigned long flags, void *args) -{ - ENTRY; - - PORTAL_MODULE_UNUSE; - RETURN(0); -} #endif static inline void obd_data2conn(struct lustre_handle *conn, @@ -372,24 +355,7 @@ int class_handle_ioctl(unsigned int cmd, unsigned long arg) -#define OBD_MINOR 241 #ifdef __KERNEL__ -/* to control /dev/obd */ -static int obd_class_ioctl (struct cfs_psdev_file *pfile, unsigned long cmd, - void *arg) -{ - return class_handle_ioctl(cmd, (unsigned long)arg); -} - -/* declare character device */ -struct cfs_psdev_ops obd_psdev_ops = { - /* .p_open = */ obd_class_open, /* open */ - /* .p_close = */ obd_class_release, /* release */ - /* .p_read = */ NULL, - /* .p_write = */ NULL, - /* .p_ioctl = */ obd_class_ioctl /* ioctl */ -}; - extern cfs_psdev_t obd_psdev; #else void *obd_psdev = NULL; @@ -591,7 +557,7 @@ int init_obdclass(void) err = cfs_psdev_register(&obd_psdev); if (err) { - CERROR("cannot register %d err %d\n", OBD_MINOR, err); + CERROR("cannot register %d err %d\n", OBD_DEV_MINOR, err); return err; } diff --git a/lustre/obdclass/darwin/darwin-module.c b/lustre/obdclass/darwin/darwin-module.c index f67ae0e..39ad964 100644 --- a/lustre/obdclass/darwin/darwin-module.c +++ b/lustre/obdclass/darwin/darwin-module.c @@ -145,26 +145,22 @@ int obd_ioctl_popdata(void *arg, void *data, int len) return err; } } -/* - * cfs pseudo device - */ -extern struct cfs_psdev_ops obd_psdev_ops; static int obd_class_open(dev_t dev, int flags, int devtype, struct proc *p) { - if (obd_psdev_ops.p_open != NULL) - return -obd_psdev_ops.p_open(0, NULL); - return EPERM; + ENTRY; + + RETURN(0); } /* closing /dev/obd */ static int obd_class_release(dev_t dev, int flags, int mode, struct proc *p) { - if (obd_psdev_ops.p_close != NULL) - return -obd_psdev_ops.p_close(0, NULL); - return EPERM; + ENTRY; + + RETURN(0); } static int @@ -175,10 +171,8 @@ obd_class_ioctl(dev_t dev, u_long cmd, caddr_t arg, int flag, struct proc *p) if (!is_suser()) RETURN (EPERM); - if (obd_psdev_ops.p_ioctl != NULL) - err = -obd_psdev_ops.p_ioctl(NULL, cmd, (void *)arg); - else - err = EPERM; + + err = class_handle_ioctl(cmd, (unsigned long)arg); RETURN(err); } diff --git a/lustre/obdclass/linux/linux-module.c b/lustre/obdclass/linux/linux-module.c index 3480e20..4aef32c 100644 --- a/lustre/obdclass/linux/linux-module.c +++ b/lustre/obdclass/linux/linux-module.c @@ -81,6 +81,7 @@ #include #include #include +#include #include #include #include @@ -178,23 +179,22 @@ int obd_ioctl_popdata(void *arg, void *data, int len) EXPORT_SYMBOL(obd_ioctl_getdata); EXPORT_SYMBOL(obd_ioctl_popdata); -#define OBD_MINOR 241 -extern struct cfs_psdev_ops obd_psdev_ops; - /* opening /dev/obd */ static int obd_class_open(struct inode * inode, struct file * file) { - if (obd_psdev_ops.p_open != NULL) - return obd_psdev_ops.p_open(0, NULL); - return -EPERM; + ENTRY; + + PORTAL_MODULE_USE; + RETURN(0); } /* closing /dev/obd */ static int obd_class_release(struct inode * inode, struct file * file) { - if (obd_psdev_ops.p_close != NULL) - return obd_psdev_ops.p_close(0, NULL); - return -EPERM; + ENTRY; + + PORTAL_MODULE_UNUSE; + RETURN(0); } /* to control /dev/obd */ @@ -210,10 +210,7 @@ static int obd_class_ioctl(struct inode *inode, struct file *filp, if ((cmd & 0xffffff00) == ((int)'T') << 8) /* ignore all tty ioctls */ RETURN(err = -ENOTTY); - if (obd_psdev_ops.p_ioctl != NULL) - err = obd_psdev_ops.p_ioctl(NULL, cmd, (void *)arg); - else - err = -EPERM; + err = class_handle_ioctl(cmd, (unsigned long)arg); RETURN(err); } @@ -228,8 +225,8 @@ static struct file_operations obd_psdev_fops = { /* modules setup */ cfs_psdev_t obd_psdev = { - .minor = OBD_MINOR, - .name = "obd_psdev", + .minor = OBD_DEV_MINOR, + .name = OBD_DEV_NAME, .fops = &obd_psdev_fops, }; diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index d93a55b..ae4ace0 100644 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -4350,7 +4350,7 @@ test_103 () { } run_test 103 "acl test =========================================" -test_104() { +test_104a() { touch $DIR/$tfile lfs df || error "lfs df failed" lfs df -ih || error "lfs df -ih failed" @@ -4366,7 +4366,18 @@ test_104() { lfs df || error "lfs df with reactivated OSC failed" rm -f $DIR/$tfile } -run_test 104 "lfs df [-ih] [path] test =========================" +run_test 104a "lfs df [-ih] [path] test =========================" + +test_104b() { + [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return + chmod 666 /dev/obd + denied_cnt=$((`$RUNAS $LFS check servers 2>&1 | grep "Permission denied" | wc -l`)) + if [ $denied_cnt -ne 0 ]; + then + error "lfs check servers test failed" + fi +} +run_test 104b "$RUNAS lfs check servers test ====================" test_105a() { # doesn't work on 2.4 kernels -- 1.8.3.1