Whamcloud - gitweb
b=21259 "lfs check" is only allowed for root.
authorDmitry Zogin <dmitry.zogin@sun.com>
Wed, 3 Feb 2010 14:41:27 +0000 (09:41 -0500)
committerRobert Read <rread@sun.com>
Wed, 3 Feb 2010 20:02:33 +0000 (12:02 -0800)
Code cleanup around obd_class_*() functions and sanity test for non-root lfs check

 i=adilger
 i=andrew.perepechko

lnet/include/lnet/lnetctl.h
lustre/include/obd_class.h
lustre/obdclass/class_obd.c
lustre/obdclass/darwin/darwin-module.c
lustre/obdclass/linux/linux-module.c
lustre/tests/sanity.sh

index 5b58e2a..3a12a70 100644 (file)
@@ -29,7 +29,8 @@
 #define LNET_DEV_MAJOR 10
 #define LNET_DEV_MINOR 240
 #define OBD_DEV_ID 1
 #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
 #define OBD_DEV_MAJOR 10
 #define OBD_DEV_MINOR 241
 #define SMFS_DEV_ID  2
index 4dc266f..f86dca8 100644 (file)
@@ -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 *);
 /* 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;
 
 
 struct lu_device_type;
 
index bf6fb32..7d2d3c9 100644 (file)
@@ -46,6 +46,7 @@
 
 #include <obd_support.h>
 #include <obd_class.h>
 
 #include <obd_support.h>
 #include <obd_class.h>
+#include <lnet/lnetctl.h>
 #include <lustre_debug.h>
 #include <lprocfs_status.h>
 #include <lustre/lustre_build_version.h>
 #include <lustre_debug.h>
 #include <lprocfs_status.h>
 #include <lustre/lustre_build_version.h>
@@ -94,24 +95,6 @@ unsigned long obd_print_fail_loc(void)
         CWARN("obd_fail_loc = %lx\n", obd_fail_loc);
         return obd_fail_loc;
 }
         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,
 #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__
 #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;
 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) {
 
         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;
         }
 
                 return err;
         }
 
index f67ae0e..39ad964 100644 (file)
@@ -145,26 +145,22 @@ int obd_ioctl_popdata(void *arg, void *data, int len)
                return err;
        }
 }
                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)
 {
 
 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)
 {
 }
 
 /*  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
 }
 
 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 (!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);
 }
 
        RETURN(err);
 }
index 3480e20..4aef32c 100644 (file)
@@ -81,6 +81,7 @@
 #include <libcfs/libcfs.h>
 #include <obd_support.h>
 #include <obd_class.h>
 #include <libcfs/libcfs.h>
 #include <obd_support.h>
 #include <obd_class.h>
+#include <lnet/lnetctl.h>
 #include <lprocfs_status.h>
 #include <lustre_ver.h>
 #include <lustre/lustre_build_version.h>
 #include <lprocfs_status.h>
 #include <lustre_ver.h>
 #include <lustre/lustre_build_version.h>
@@ -178,23 +179,22 @@ int obd_ioctl_popdata(void *arg, void *data, int len)
 EXPORT_SYMBOL(obd_ioctl_getdata);
 EXPORT_SYMBOL(obd_ioctl_popdata);
 
 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)
 {
 /*  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)
 {
 }
 
 /*  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 */
 }
 
 /* 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 ((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);
 }
 
         RETURN(err);
 }
@@ -228,8 +225,8 @@ static struct file_operations obd_psdev_fops = {
 
 /* modules setup */
 cfs_psdev_t obd_psdev = {
 
 /* 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,
 };
 
         .fops  = &obd_psdev_fops,
 };
 
index d93a55b..ae4ace0 100644 (file)
@@ -4350,7 +4350,7 @@ test_103 () {
 }
 run_test 103 "acl test ========================================="
 
 }
 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"
        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
 }
        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
 
 test_105a() {
        # doesn't work on 2.4 kernels