Whamcloud - gitweb
LU-3319 procfs: move ptlrpc proc handling over to seq_file
[fs/lustre-release.git] / lustre / obdclass / obd_mount_server.c
index 86d19d7..b617d4c 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) 2011, 2012, Intel Corporation.
+ * Copyright (c) 2013, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -47,8 +47,6 @@
 #define PRINT_MASK (D_SUPER | D_CONFIG)
 
 #include <obd.h>
-#include <lvfs.h>
-#include <lustre_fsfilt.h>
 #include <obd_class.h>
 #include <lustre/lustre_user.h>
 #include <linux/version.h>
@@ -58,6 +56,9 @@
 #ifdef HAVE_KERNEL_LOCKED
 #include <linux/smp_lock.h>
 #endif
+#ifdef HAVE_SELINUX_IS_ENABLED
+#include <linux/selinux.h>
+#endif
 
 /*********** mount lookup *********/
 
@@ -82,8 +83,7 @@ static struct lustre_mount_info *server_find_mount(const char *name)
 /* we must register an obd for a mount before we call the setup routine.
  *_setup will call lustre_get_mount to get the mnt struct
  by obd_name, since we can't pass the pointer to setup. */
-static int server_register_mount(const char *name, struct super_block *sb,
-                                struct vfsmount *mnt)
+static int server_register_mount(const char *name, struct super_block *sb)
 {
        struct lustre_mount_info *lmi;
        char *name_cp;
@@ -112,12 +112,11 @@ static int server_register_mount(const char *name, struct super_block *sb,
        }
        lmi->lmi_name = name_cp;
        lmi->lmi_sb = sb;
-       lmi->lmi_mnt = mnt;
        cfs_list_add(&lmi->lmi_list_chain, &server_mount_info_list);
 
        mutex_unlock(&lustre_mount_info_lock);
 
-       CDEBUG(D_MOUNT, "reg_mnt %p from %s\n", lmi->lmi_mnt, name);
+       CDEBUG(D_MOUNT, "register mount %p from %s\n", sb, name);
 
        RETURN(0);
 }
@@ -136,7 +135,7 @@ static int server_deregister_mount(const char *name)
                RETURN(-ENOENT);
        }
 
-       CDEBUG(D_MOUNT, "dereg_mnt %p from %s\n", lmi->lmi_mnt, name);
+       CDEBUG(D_MOUNT, "deregister mount %p from %s\n", lmi->lmi_sb, name);
 
        OBD_FREE(lmi->lmi_name, strlen(lmi->lmi_name) + 1);
        cfs_list_del(&lmi->lmi_list_chain);
@@ -166,7 +165,7 @@ struct lustre_mount_info *server_get_mount(const char *name)
 
        cfs_atomic_inc(&lsi->lsi_mounts);
 
-       CDEBUG(D_MOUNT, "get_mnt %p from %s, refs=%d\n", lmi->lmi_mnt,
+       CDEBUG(D_MOUNT, "get mount %p from %s, refs=%d\n", lmi->lmi_sb,
               name, cfs_atomic_read(&lsi->lsi_mounts));
 
        RETURN(lmi);
@@ -194,7 +193,7 @@ struct lustre_mount_info *server_get_mount_2(const char *name)
 EXPORT_SYMBOL(server_get_mount_2);
 
 /* to be called from obd_cleanup methods */
-int server_put_mount(const char *name, struct vfsmount *mnt)
+int server_put_mount(const char *name)
 {
        struct lustre_mount_info *lmi;
        struct lustre_sb_info *lsi;
@@ -209,12 +208,12 @@ int server_put_mount(const char *name, struct vfsmount *mnt)
        }
        lsi = s2lsi(lmi->lmi_sb);
 
-       CDEBUG(D_MOUNT, "put_mnt %p from %s, refs=%d\n",
-              lmi->lmi_mnt, name, cfs_atomic_read(&lsi->lsi_mounts));
+       CDEBUG(D_MOUNT, "put mount %p from %s, refs=%d\n",
+              lmi->lmi_sb, name, cfs_atomic_read(&lsi->lsi_mounts));
 
        if (lustre_put_lsi(lmi->lmi_sb))
-               CDEBUG(D_MOUNT, "Last put of mnt %p from %s\n",
-                      lmi->lmi_mnt, name);
+               CDEBUG(D_MOUNT, "Last put of mount %p from %s\n",
+                      lmi->lmi_sb, name);
 
        /* this obd should never need the mount again */
        server_deregister_mount(name);
@@ -235,7 +234,6 @@ EXPORT_SYMBOL(server_put_mount_2);
 static int server_start_mgs(struct super_block *sb)
 {
        struct lustre_sb_info    *lsi = s2lsi(sb);
-       struct vfsmount   *mnt = lsi->lsi_srv_mnt;
        struct lustre_mount_info *lmi;
        int    rc = 0;
        ENTRY;
@@ -252,15 +250,20 @@ static int server_start_mgs(struct super_block *sb)
 
        CDEBUG(D_CONFIG, "Start MGS service %s\n", LUSTRE_MGS_OBDNAME);
 
-       rc = server_register_mount(LUSTRE_MGS_OBDNAME, sb, mnt);
+       rc = server_register_mount(LUSTRE_MGS_OBDNAME, sb);
 
        if (!rc) {
                rc = lustre_start_simple(LUSTRE_MGS_OBDNAME, LUSTRE_MGS_NAME,
                                         LUSTRE_MGS_OBDNAME, 0, 0,
                                         lsi->lsi_osd_obdname, 0);
-               /* Do NOT call server_deregister_mount() here. This leads to
-                * inability cleanup cleanly and free lsi and other stuff when
-                * mgs calls server_put_mount() in error handling case. -umka */
+               /* server_deregister_mount() is not called previously, for lsi
+                * and other stuff can't be freed cleanly when mgs calls
+                * server_put_mount() in error handling case (see b=17758),
+                * this problem is caused by a bug in mgs_init0, which forgot
+                * calling server_put_mount in error case. */
+
+               if (rc)
+                       server_deregister_mount(LUSTRE_MGS_OBDNAME);
        }
 
        if (rc)
@@ -508,7 +511,7 @@ static int lustre_lwp_connect(struct obd_device *lwp)
        if (rc != 0)
                RETURN(rc);
 
-       lu_context_init(&session_ctx, LCT_SESSION);
+       lu_context_init(&session_ctx, LCT_SERVER_SESSION);
        session_ctx.lc_thread = NULL;
        lu_context_enter(&session_ctx);
        env.le_ses = &session_ctx;
@@ -522,8 +525,7 @@ static int lustre_lwp_connect(struct obd_device *lwp)
        data->ocd_connect_flags |= OBD_CONNECT_MDS_MDS | OBD_CONNECT_FID |
                OBD_CONNECT_AT | OBD_CONNECT_LRU_RESIZE |
                OBD_CONNECT_FULL20 | OBD_CONNECT_LVB_TYPE |
-               OBD_CONNECT_LIGHTWEIGHT |
-               OBD_CONNECT_PINGLESS;
+               OBD_CONNECT_LIGHTWEIGHT;
        OBD_ALLOC_PTR(uuid);
        if (uuid == NULL)
                GOTO(out, rc = -ENOMEM);
@@ -561,7 +563,6 @@ out:
  **/
 static int lustre_lwp_setup(struct lustre_cfg *lcfg, struct lustre_sb_info *lsi)
 {
-       struct obd_connect_data *data = NULL;
        struct obd_device       *obd;
        char                    *lwpname = NULL;
        char                    *lwpuuid = NULL;
@@ -606,8 +607,6 @@ static int lustre_lwp_setup(struct lustre_cfg *lcfg, struct lustre_sb_info *lsi)
        if (rc != 0)
                CERROR("%s: connect failed: rc = %d\n", lwpname, rc);
 out:
-       if (data != NULL)
-               OBD_FREE_PTR(data);
        if (lwpname != NULL)
                OBD_FREE(lwpname, MTI_NAME_MAXLEN);
        if (lwpuuid != NULL)
@@ -979,13 +978,9 @@ static int server_stop_servers(int lsiflags)
        }
 
        if (obd != NULL && (type == NULL || type->typ_refcnt == 0)) {
-               int err;
-
                obd->obd_force = 1;
                /* obd_fail doesn't mean much on a server obd */
-               err = class_manual_cleanup(obd);
-               if (rc != 0)
-                       rc = err;
+               rc = class_manual_cleanup(obd);
        }
 
        mutex_unlock(&server_start_lock);
@@ -1181,7 +1176,7 @@ out:
 
 /** Start server targets: MDTs and OSTs
  */
-static int server_start_targets(struct super_block *sb, struct vfsmount *mnt)
+static int server_start_targets(struct super_block *sb)
 {
        struct obd_device *obd;
        struct lustre_sb_info *lsi = s2lsi(sb);
@@ -1232,11 +1227,9 @@ static int server_start_targets(struct super_block *sb, struct vfsmount *mnt)
 
        /* Set the mgc fs to our server disk.  This allows the MGC to
         * read and write configs locally, in case it can't talk to the MGS. */
-       if (lsi->lsi_srv_mnt) {
-               rc = server_mgc_set_fs(lsi->lsi_mgc, sb);
-               if (rc)
-                       GOTO(out_stop_service, rc);
-       }
+       rc = server_mgc_set_fs(lsi->lsi_mgc, sb);
+       if (rc)
+               GOTO(out_stop_service, rc);
 
        /* Register with MGS */
        rc = server_register_target(lsi);
@@ -1245,7 +1238,7 @@ static int server_start_targets(struct super_block *sb, struct vfsmount *mnt)
 
        /* Let the target look up the mount using the target's name
           (we can't pass the sb or mnt through class_process_config.) */
-       rc = server_register_mount(lsi->lsi_svname, sb, mnt);
+       rc = server_register_mount(lsi->lsi_svname, sb);
        if (rc)
                GOTO(out_mgc, rc);
 
@@ -1292,7 +1285,7 @@ static int server_start_targets(struct super_block *sb, struct vfsmount *mnt)
                if (rc == 0) {
                        struct lu_context  session_ctx;
 
-                       lu_context_init(&session_ctx, LCT_SESSION);
+                       lu_context_init(&session_ctx, LCT_SERVER_SESSION);
                        session_ctx.lc_thread = NULL;
                        lu_context_enter(&session_ctx);
                        env.le_ses = &session_ctx;
@@ -1315,8 +1308,7 @@ static int server_start_targets(struct super_block *sb, struct vfsmount *mnt)
 
 out_mgc:
        /* Release the mgc fs for others to use */
-       if (lsi->lsi_srv_mnt)
-               server_mgc_clear_fs(lsi->lsi_mgc);
+       server_mgc_clear_fs(lsi->lsi_mgc);
 
 out_stop_service:
        if (rc != 0)
@@ -1356,7 +1348,7 @@ static int lsi_prepare(struct lustre_sb_info *lsi)
                strcpy(lsi->lsi_osd_type, LUSTRE_OSD_LDISKFS_NAME);
        }
 
-       /* XXX: a temp. solution for components using fsfilt
+       /* XXX: a temp. solution for components using ldiskfs
         *      to be removed in one of the subsequent patches */
        if (!strcmp(lsi->lsi_lmd->lmd_osd_type, "osd-ldiskfs"))
                strcpy(lsi->lsi_fstype, "ldiskfs");
@@ -1385,6 +1377,8 @@ static int lsi_prepare(struct lustre_sb_info *lsi)
                LDD_F_WRITECONF : 0;
        lsi->lsi_flags |= (lsi->lsi_lmd->lmd_flags & LMD_FLG_VIRGIN) ?
                LDD_F_VIRGIN : 0;
+       lsi->lsi_flags |= (lsi->lsi_lmd->lmd_flags & LMD_FLG_UPDATE) ?
+               LDD_F_UPDATE : 0;
        lsi->lsi_flags |= (lsi->lsi_lmd->lmd_flags & LMD_FLG_MGS) ?
                LDD_F_SV_TYPE_MGS : 0;
        lsi->lsi_flags |= (lsi->lsi_lmd->lmd_flags & LMD_FLG_NO_PRIMNODE) ?
@@ -1552,6 +1546,35 @@ static struct super_operations server_ops = {
        .statfs         = server_statfs,
 };
 
+/*
+ * Xattr support for Lustre servers
+ */
+static ssize_t lustre_getxattr(struct dentry *dentry, const char *name,
+                               void *buffer, size_t size)
+{
+       if (!selinux_is_enabled())
+               return -EOPNOTSUPP;
+       return -ENODATA;
+}
+
+static int lustre_setxattr(struct dentry *dentry, const char *name,
+                           const void *value, size_t size, int flags)
+{
+       return -EOPNOTSUPP;
+}
+
+static ssize_t lustre_listxattr(struct dentry *d_entry, char *name,
+                               size_t size)
+{
+       return -EOPNOTSUPP;
+}
+
+const struct inode_operations server_inode_operations = {
+       .setxattr       = lustre_setxattr,
+       .getxattr       = lustre_getxattr,
+       .listxattr      = lustre_listxattr,
+};
+
 #define log2(n) ffz(~(n))
 #define LUSTRE_SUPER_MAGIC 0x0BD00BD1
 
@@ -1579,7 +1602,7 @@ static int server_fill_super_common(struct super_block *sb)
        /* make_bad_inode(root); -- badness - can't umount */
        /* apparently we need to be a directory for the mount to finish */
        root->i_mode = S_IFDIR;
-
+       root->i_op = &server_inode_operations;
        sb->s_root = d_make_root(root);
        if (!sb->s_root) {
                CERROR("%s: can't make root dentry\n", sb->s_id);
@@ -1626,18 +1649,19 @@ static int osd_start(struct lustre_sb_info *lsi, unsigned long mflags)
                obd->obd_force = 1;
                class_manual_cleanup(obd);
                lsi->lsi_dt_dev = NULL;
+               RETURN(rc);
        }
 
-       /* XXX: to keep support old components relying on lsi_srv_mnt
-        *      we get this info from OSD just started */
        LASSERT(obd->obd_lu_dev);
+       lu_device_get(obd->obd_lu_dev);
        lsi->lsi_dt_dev = lu2dt_dev(obd->obd_lu_dev);
        LASSERT(lsi->lsi_dt_dev);
 
-       dt_conf_get(NULL, lsi->lsi_dt_dev, &p);
-
-       lsi->lsi_srv_mnt = p.ddp_mnt;
+       /* set disk context for llog usage */
+       OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
+       obd->obd_lvfs_ctxt.dt = lsi->lsi_dt_dev;
 
+       dt_conf_get(NULL, lsi->lsi_dt_dev, &p);
 out:
        RETURN(rc);
 }
@@ -1693,7 +1717,7 @@ int server_fill_super(struct super_block *sb)
        /* Set up all obd devices for service */
        if (!(lsi->lsi_lmd->lmd_flags & LMD_FLG_NOSVC) &&
            (IS_OST(lsi) || IS_MDT(lsi))) {
-               rc = server_start_targets(sb, lsi->lsi_srv_mnt);
+               rc = server_start_targets(sb);
                if (rc < 0) {
                        CERROR("Unable to start targets: %d\n", rc);
                        GOTO(out_mnt, rc);