Whamcloud - gitweb
LU-14090 mgs: no local logs flag
[fs/lustre-release.git] / lustre / obdclass / obd_mount.c
index 53e3c8b..be1521f 100644 (file)
 
 #include <obd.h>
 #include <obd_class.h>
+#include <linux/random.h>
+#include <libcfs/linux/linux-uuid.h>
 #include <linux/version.h>
 #include <lustre_log.h>
 #include <lustre_disk.h>
 #include <uapi/linux/lustre/lustre_param.h>
-
-static int (*client_fill_super)(struct super_block *sb,
-                               struct vfsmount *mnt);
-
-static void (*kill_super_cb)(struct super_block *sb);
+#include <libcfs/crypto/llcrypt.h>
 
 /**************** config llog ********************/
 
@@ -222,7 +220,7 @@ int lustre_start_mgc(struct super_block *sb)
        struct obd_device *obd;
        struct obd_export *exp;
        struct obd_uuid *uuid = NULL;
-       class_uuid_t uuidc;
+       uuid_t uuidc;
        lnet_nid_t nid;
        char nidstr[LNET_NIDSTR_SIZE];
        char *mgcname = NULL, *niduuid = NULL, *mgssec = NULL;
@@ -245,7 +243,7 @@ int lustre_start_mgc(struct super_block *sb)
                        struct lnet_process_id id;
 
                        while ((rc = LNetGetId(i++, &id)) != -ENOENT) {
-                               if (LNET_NETTYP(LNET_NIDNET(id.nid)) == LOLND)
+                               if (id.nid == LNET_NID_LO_0)
                                        continue;
                                nid = id.nid;
                                i++;
@@ -405,8 +403,8 @@ int lustre_start_mgc(struct super_block *sb)
        if (uuid == NULL)
                GOTO(out_free, rc = -ENOMEM);
 
-       ll_generate_random_uuid(uuidc);
-       class_uuid_unparse(uuidc, uuid);
+       generate_random_uuid(uuidc.b);
+       snprintf(uuid->uuid, sizeof(*uuid), "%pU", uuidc.b);
 
        /* Start the MGC */
        rc = lustre_start_simple(mgcname, LUSTRE_MGC_NAME,
@@ -466,10 +464,6 @@ int lustre_start_mgc(struct super_block *sb)
                                  OBD_CONNECT_LVB_TYPE |
                                  OBD_CONNECT_BULK_MBITS | OBD_CONNECT_BARRIER;
 
-#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
-       data->ocd_connect_flags |= OBD_CONNECT_MNE_SWAB;
-#endif
-
        if (lmd_is_client(lsi->lsi_lmd) &&
            lsi->lsi_lmd->lmd_flags & LMD_FLG_NOIR)
                data->ocd_connect_flags &= ~OBD_CONNECT_IMP_RECOV;
@@ -501,6 +495,7 @@ out_free:
                OBD_FREE(niduuid, len + 2);
        RETURN(rc);
 }
+EXPORT_SYMBOL(lustre_start_mgc);
 
 static int lustre_stop_mgc(struct super_block *sb)
 {
@@ -584,7 +579,7 @@ out:
 
 /***************** lustre superblock **************/
 
-static struct lustre_sb_info *lustre_init_lsi(struct super_block *sb)
+struct lustre_sb_info *lustre_init_lsi(struct super_block *sb)
 {
        struct lustre_sb_info *lsi;
 
@@ -599,9 +594,6 @@ static struct lustre_sb_info *lustre_init_lsi(struct super_block *sb)
                RETURN(NULL);
        }
 
-       lsi->lsi_lmd->lmd_exclude_count = 0;
-       lsi->lsi_lmd->lmd_recovery_time_soft = 0;
-       lsi->lsi_lmd->lmd_recovery_time_hard = 0;
        s2lsi_nocast(sb) = lsi;
        /* we take 1 extra ref for our setup */
        atomic_set(&lsi->lsi_mounts, 1);
@@ -609,10 +601,11 @@ static struct lustre_sb_info *lustre_init_lsi(struct super_block *sb)
        /* Default umount style */
        lsi->lsi_flags = LSI_UMOUNT_FAILOVER;
        INIT_LIST_HEAD(&lsi->lsi_lwp_list);
-       spin_lock_init(&lsi->lsi_lwp_lock);
+       mutex_init(&lsi->lsi_lwp_mutex);
 
        RETURN(lsi);
 }
+EXPORT_SYMBOL(lustre_init_lsi);
 
 static int lustre_free_lsi(struct super_block *sb)
 {
@@ -626,6 +619,7 @@ static int lustre_free_lsi(struct super_block *sb)
        /* someone didn't call server_put_mount. */
        LASSERT(atomic_read(&lsi->lsi_mounts) == 0);
 
+       llcrypt_sb_free(sb);
        if (lsi->lsi_lmd != NULL) {
                if (lsi->lsi_lmd->lmd_dev != NULL)
                        OBD_FREE(lsi->lsi_lmd->lmd_dev,
@@ -695,6 +689,7 @@ int lustre_put_lsi(struct super_block *sb)
        }
        RETURN(0);
 }
+EXPORT_SYMBOL(lustre_put_lsi);
 
 /*
  * The goal of this function is to extract the file system name
@@ -891,6 +886,9 @@ int target_name2index(const char *tgtname, __u32 *idx, const char **endptr)
        if (idx != NULL)
                *idx = index;
 
+       if (index > 0xffff)
+               return -ERANGE;
+
        return rc;
 }
 EXPORT_SYMBOL(target_name2index);
@@ -1028,7 +1026,7 @@ static int lmd_make_exclusion(struct lustre_mount_data *lmd, const char *ptr)
        devmax = strlen(ptr) / 8 + 1;
 
        /* temp storage until we figure out how many we have */
-       OBD_ALLOC(exclude_list, sizeof(index) * devmax);
+       OBD_ALLOC_PTR_ARRAY(exclude_list, devmax);
        if (!exclude_list)
                RETURN(-ENOMEM);
 
@@ -1059,8 +1057,8 @@ static int lmd_make_exclusion(struct lustre_mount_data *lmd, const char *ptr)
 
        if (lmd->lmd_exclude_count) {
                /* permanent, freed in lustre_free_lsi */
-               OBD_ALLOC(lmd->lmd_exclude, sizeof(index) *
-                         lmd->lmd_exclude_count);
+               OBD_ALLOC_PTR_ARRAY(lmd->lmd_exclude,
+                                   lmd->lmd_exclude_count);
                if (lmd->lmd_exclude) {
                        memcpy(lmd->lmd_exclude, exclude_list,
                               sizeof(index) * lmd->lmd_exclude_count);
@@ -1069,7 +1067,7 @@ static int lmd_make_exclusion(struct lustre_mount_data *lmd, const char *ptr)
                        lmd->lmd_exclude_count = 0;
                }
        }
-       OBD_FREE(exclude_list, sizeof(index) * devmax);
+       OBD_FREE_PTR_ARRAY(exclude_list, devmax);
        RETURN(rc);
 }
 
@@ -1259,7 +1257,7 @@ try_again:
  */
 static int lmd_parse_nidlist(char *buf, char **endh)
 {
-       struct list_head nidlist;
+       LIST_HEAD(nidlist);
        char *endp = buf;
        char tmp;
        int rc = 0;
@@ -1277,7 +1275,6 @@ static int lmd_parse_nidlist(char *buf, char **endh)
        tmp = *endp;
        *endp = '\0';
 
-       INIT_LIST_HEAD(&nidlist);
        if (cfs_parse_nidlist(buf, strlen(buf), &nidlist) <= 0)
                rc = 1;
        cfs_free_nidlist(&nidlist);
@@ -1293,9 +1290,9 @@ static int lmd_parse_nidlist(char *buf, char **endh)
 /**
  * Parse mount line options
  * e.g. mount -v -t lustre -o abort_recov uml1:uml2:/lustre-client /mnt/lustre
- * dev is passed as device=uml1:/lustre by mount.lustre
+ * dev is passed as device=uml1:/lustre by mount.lustre_tgt
  */
-static int lmd_parse(char *options, struct lustre_mount_data *lmd)
+int lmd_parse(char *options, struct lustre_mount_data *lmd)
 {
        char *s1, *s2, *devname = NULL;
        struct lustre_mount_data *raw = (struct lustre_mount_data *)options;
@@ -1306,14 +1303,14 @@ static int lmd_parse(char *options, struct lustre_mount_data *lmd)
        LASSERT(lmd);
        if (!options) {
                LCONSOLE_ERROR_MSG(0x162,
-                                  "Missing mount data: check /sbin/mount.lustre is installed.\n");
+                                  "Missing mount data: check /sbin/mount.lustre_tgt is installed.\n");
                RETURN(-EINVAL);
        }
 
        /* Options should be a string - try to detect old lmd data */
        if ((raw->lmd_magic & 0xffffff00) == (LMD_MAGIC & 0xffffff00)) {
                LCONSOLE_ERROR_MSG(0x163,
-                                  "Using an old version of /sbin/mount lustre. Please install version %s\n",
+                                  "Using an old version of /sbin/mount.lustre. Please install version %s\n",
                                   LUSTRE_VERSION_STRING);
                RETURN(-EINVAL);
        }
@@ -1349,6 +1346,9 @@ static int lmd_parse(char *options, struct lustre_mount_data *lmd)
                if (strncmp(s1, "abort_recov", 11) == 0) {
                        lmd->lmd_flags |= LMD_FLG_ABORT_RECOV;
                        clear++;
+               } else if (strncmp(s1, "abort_recov_mdt", 15) == 0) {
+                       lmd->lmd_flags |= LMD_FLG_ABORT_RECOV_MDT;
+                       clear++;
                } else if (strncmp(s1, "recovery_time_soft=", 19) == 0) {
                        lmd->lmd_recovery_time_soft =
                                max_t(int, simple_strtoul(s1 + 19, NULL, 10),
@@ -1359,6 +1359,9 @@ static int lmd_parse(char *options, struct lustre_mount_data *lmd)
                                max_t(int, simple_strtoul(s1 + 19, NULL, 10),
                                      time_min);
                        clear++;
+               } else if (strncmp(s1, "no_precreate", 12) == 0) {
+                       lmd->lmd_flags |= LMD_FLG_NO_PRECREATE;
+                       clear++;
                } else if (strncmp(s1, "noir", 4) == 0) {
                        lmd->lmd_flags |= LMD_FLG_NOIR; /* test purpose only. */
                        clear++;
@@ -1392,6 +1395,9 @@ static int lmd_parse(char *options, struct lustre_mount_data *lmd)
                } else if (strncmp(s1, "writeconf", 9) == 0) {
                        lmd->lmd_flags |= LMD_FLG_WRITECONF;
                        clear++;
+               } else if (strncmp(s1, "nolocallogs", 11) == 0) {
+                       lmd->lmd_flags |= LMD_FLG_NO_LOCAL_LOGS;
+                       clear++;
                } else if (strncmp(s1, "update", 6) == 0) {
                        lmd->lmd_flags |= LMD_FLG_UPDATE;
                        clear++;
@@ -1446,6 +1452,9 @@ static int lmd_parse(char *options, struct lustre_mount_data *lmd)
                        strlcat(lmd->lmd_params, " ", LMD_PARAMS_MAXLEN);
                        s3 = s1 + 6 + length;
                        clear++;
+               } else if (strncmp(s1, "localrecov", 10) == 0) {
+                       lmd->lmd_flags |= LMD_FLG_LOCAL_RECOV;
+                       clear++;
                } else if (strncmp(s1, "osd=", 4) == 0) {
                        rc = lmd_parse_string(&lmd->lmd_osd_type, s1 + 4);
                        if (rc)
@@ -1575,22 +1584,19 @@ invalid:
        CERROR("Bad mount options %s\n", options);
        RETURN(-EINVAL);
 }
+EXPORT_SYMBOL(lmd_parse);
 
-struct lustre_mount_data2 {
-       void *lmd2_data;
-       struct vfsmount *lmd2_mnt;
-};
-
+#ifdef HAVE_SERVER_SUPPORT
 /**
  * This is the entry point for the mount call into Lustre.
- * This is called when a server or client is mounted,
+ * This is called when a server target is mounted,
  * and this is where we start setting things up.
  * @param data Mount options (e.g. -o flock,abort_recov)
  */
-static int lustre_fill_super(struct super_block *sb, void *data, int silent)
+static int lustre_tgt_fill_super(struct super_block *sb, void *lmd2_data,
+                                int silent)
 {
        struct lustre_mount_data *lmd;
-       struct lustre_mount_data2 *lmd2 = data;
        struct lustre_sb_info *lsi;
        int rc;
 
@@ -1615,52 +1621,31 @@ static int lustre_fill_super(struct super_block *sb, void *data, int silent)
        obd_zombie_barrier();
 
        /* Figure out the lmd from the mount options */
-       if (lmd_parse((char *)(lmd2->lmd2_data), lmd)) {
+       if (lmd_parse(lmd2_data, lmd)) {
                lustre_put_lsi(sb);
                GOTO(out, rc = -EINVAL);
        }
 
        if (lmd_is_client(lmd)) {
-               CDEBUG(D_MOUNT, "Mounting client %s\n", lmd->lmd_profile);
-               if (client_fill_super == NULL)
-                       request_module("lustre");
-               if (client_fill_super == NULL) {
-                       LCONSOLE_ERROR_MSG(0x165,
-                                          "Nothing registered for client mount! Is the 'lustre' module loaded?\n");
-                       lustre_put_lsi(sb);
-                       rc = -ENODEV;
-               } else {
-                       rc = lustre_start_mgc(sb);
-                       if (rc) {
-                               lustre_common_put_super(sb);
-                               GOTO(out, rc);
-                       }
-                       /* Connect and start */
-                       /* (should always be ll_fill_super) */
-                       rc = (*client_fill_super)(sb, lmd2->lmd2_mnt);
-                       /* c_f_s will call lustre_common_put_super on failure */
-               }
-       } else {
-#ifdef HAVE_SERVER_SUPPORT
-               CDEBUG(D_MOUNT, "Mounting server from %s\n", lmd->lmd_dev);
-               rc = server_fill_super(sb);
-               /*
-                * s_f_s calls lustre_start_mgc after the mount because we need
-                * the MGS NIDs which are stored on disk.  Plus, we may
-                * need to start the MGS first.
-                */
-               /* s_f_s will call server_put_super on failure */
-#else
-               CERROR("client-side-only module, cannot handle server mount\n");
-               rc = -EINVAL;
-#endif
+               rc = -ENODEV;
+               CERROR("%s: attempting to mount a client with -t lustre_tgt' which is only for server-side mounts: rc = %d\n",
+                      lmd->lmd_dev, rc);
+               lustre_put_lsi(sb);
+               GOTO(out, rc);
        }
 
+       CDEBUG(D_MOUNT, "Mounting server from %s\n", lmd->lmd_dev);
+       rc = server_fill_super(sb);
        /*
+        * server_fill_super calls lustre_start_mgc after the mount
+        * because we need the MGS NIDs which are stored on disk.
+        * Plus, we may need to start the MGS first.
+        *
+        * server_fill_super will call server_put_super on failure
+        *
         * If error happens in fill_super() call, @lsi will be killed there.
         * This is why we do not put it here.
         */
-       GOTO(out, rc);
 out:
        if (rc) {
                CERROR("Unable to mount %s (%d)\n",
@@ -1673,78 +1658,41 @@ out:
        return rc;
 }
 
-
-/*
- * We can't call ll_fill_super by name because it lives in a module that
- * must be loaded after this one.
- */
-void lustre_register_client_fill_super(int (*cfs)(struct super_block *sb,
-                                                 struct vfsmount *mnt))
-{
-       client_fill_super = cfs;
-}
-EXPORT_SYMBOL(lustre_register_client_fill_super);
-
-void lustre_register_kill_super_cb(void (*cfs)(struct super_block *sb))
-{
-       kill_super_cb = cfs;
-}
-EXPORT_SYMBOL(lustre_register_kill_super_cb);
-
 /***************** FS registration ******************/
-#ifdef HAVE_FSTYPE_MOUNT
-static struct dentry *lustre_mount(struct file_system_type *fs_type, int flags,
-                                  const char *devname, void *data)
-{
-       struct lustre_mount_data2 lmd2 = {
-               .lmd2_data = data,
-       };
-
-       return mount_nodev(fs_type, flags, &lmd2, lustre_fill_super);
-}
-#else
-static int lustre_get_sb(struct file_system_type *fs_type, int flags,
-                        const char *devname, void *data, struct vfsmount *mnt)
+static struct dentry *lustre_tgt_mount(struct file_system_type *fs_type,
+                                      int flags, const char *devname,
+                                      void *data)
 {
-       struct lustre_mount_data2 lmd2 = {
-               .lmd2_data = data,
-               .lmd2_mnt = mnt,
-       };
-
-       return get_sb_nodev(fs_type, flags, &lmd2, lustre_fill_super, mnt);
+       return mount_nodev(fs_type, flags, data, lustre_tgt_fill_super);
 }
-#endif
-
-static void lustre_kill_super(struct super_block *sb)
-{
-       struct lustre_sb_info *lsi = s2lsi(sb);
-
-       if (kill_super_cb && lsi && !IS_SERVER(lsi))
-               (*kill_super_cb)(sb);
 
-       kill_anon_super(sb);
-}
-
-/* Register the "lustre" fs type */
-static struct file_system_type lustre_fs_type = {
-       .owner        = THIS_MODULE,
-       .name         = "lustre",
-#ifdef HAVE_FSTYPE_MOUNT
-       .mount        = lustre_mount,
-#else
-       .get_sb       = lustre_get_sb,
-#endif
-       .kill_sb      = lustre_kill_super,
-       .fs_flags     = FS_REQUIRES_DEV | FS_HAS_FIEMAP | FS_RENAME_DOES_D_MOVE,
+/* Register the "lustre_tgt" fs type.
+ *
+ * Right now this isn't any different than the normal "lustre" filesystem
+ * type, but it is added so that there is some compatibility to allow
+ * changing documentation and scripts to start using the "lustre_tgt" type
+ * at mount time. That will simplify test interop, and in case of upgrades
+ * that change to the new type and then need to roll back for some reason.
+ *
+ * The long-term goal is to disentangle the client and server mount code.
+ */
+static struct file_system_type lustre_tgt_fstype = {
+       .owner          = THIS_MODULE,
+       .name           = "lustre_tgt",
+       .mount          = lustre_tgt_mount,
+       .kill_sb        = kill_anon_super,
+       .fs_flags       = FS_REQUIRES_DEV | FS_RENAME_DOES_D_MOVE,
 };
-MODULE_ALIAS_FS("lustre");
+MODULE_ALIAS_FS("lustre_tgt");
 
-int lustre_register_fs(void)
+int lustre_tgt_register_fs(void)
 {
-       return register_filesystem(&lustre_fs_type);
+       return register_filesystem(&lustre_tgt_fstype);
 }
 
-int lustre_unregister_fs(void)
+void lustre_tgt_unregister_fs(void)
 {
-       return unregister_filesystem(&lustre_fs_type);
+       unregister_filesystem(&lustre_tgt_fstype);
 }
+
+#endif /* HAVE_SERVER_SUPPORT */