Whamcloud - gitweb
New tag 2.15.91
[fs/lustre-release.git] / lustre / target / tgt_mount.c
index 29c8166..c62d76e 100644 (file)
 #include <linux/statfs.h>
 #include <linux/version.h>
 #include <linux/delay.h>
+#include <linux/file.h>
+#ifdef HAVE_FSMAP_H
+#include <linux/fsmap.h>
+#endif
+#include <linux/uaccess.h>
 
 #include <llog_swab.h>
 #include <lustre_disk.h>
@@ -227,8 +232,7 @@ static int server_start_mgs(struct super_block *sb)
        lmi = server_find_mount(LUSTRE_MGS_OBDNAME);
        if (lmi) {
                lsi = s2lsi(lmi->lmi_sb);
-               LCONSOLE_ERROR_MSG(0x15d,
-                                  "The MGS service was already started from server\n");
+               LCONSOLE_ERROR("The MGS service was already started from server\n");
                RETURN(-EALREADY);
        }
 
@@ -250,9 +254,8 @@ static int server_start_mgs(struct super_block *sb)
        if (rc < 0) {
                server_deregister_mount(LUSTRE_MGS_OBDNAME);
 report_err:
-               LCONSOLE_ERROR_MSG(0x15e,
-                                  "Failed to start MGS '%s' (%d). Is the 'mgs' module loaded?\n",
-                                  LUSTRE_MGS_OBDNAME, rc);
+               LCONSOLE_ERROR("Failed to start MGS '%s' (%d). Is the 'mgs' module loaded?\n",
+                              LUSTRE_MGS_OBDNAME, rc);
        }
        RETURN(rc);
 }
@@ -374,8 +377,7 @@ int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, u32 idx)
        GOTO(cleanup, rc = 0);
 
 cleanup:
-       if (fsname != NULL)
-               OBD_FREE(fsname, MTI_NAME_MAXLEN);
+       OBD_FREE(fsname, MTI_NAME_MAXLEN);
 
        return rc;
 }
@@ -617,10 +619,8 @@ static int lustre_lwp_connect(struct obd_device *lwp, bool is_mdt)
        GOTO(out, rc);
 
 out:
-       if (data != NULL)
-               OBD_FREE_PTR(data);
-       if (uuid != NULL)
-               OBD_FREE_PTR(uuid);
+       OBD_FREE_PTR(data);
+       OBD_FREE_PTR(uuid);
 
        lu_env_fini(&env);
        lu_context_exit(&session_ctx);
@@ -694,10 +694,8 @@ static int lustre_lwp_setup(struct lustre_cfg *lcfg, struct lustre_sb_info *lsi,
        list_add_tail(&obd->obd_lwp_list, &lsi->lsi_lwp_list);
        mutex_unlock(&lsi->lsi_lwp_mutex);
 out:
-       if (lwpname)
-               OBD_FREE(lwpname, MTI_NAME_MAXLEN);
-       if (lwpuuid)
-               OBD_FREE(lwpuuid, MTI_NAME_MAXLEN);
+       OBD_FREE(lwpname, MTI_NAME_MAXLEN);
+       OBD_FREE(lwpuuid, MTI_NAME_MAXLEN);
 
        return rc;
 }
@@ -772,15 +770,12 @@ static int lustre_lwp_add_conn(struct lustre_cfg *cfg,
        if (rc < 0)
                CERROR("%s: can't add conn: rc = %d\n", lwpname, rc);
 
-       if (lcfg)
-               OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount,
-                                             lcfg->lcfg_buflens));
+       OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount,
+                                     lcfg->lcfg_buflens));
 out_cfg:
-       if (bufs)
-               OBD_FREE_PTR(bufs);
+       OBD_FREE_PTR(bufs);
 out:
-       if (lwpname)
-               OBD_FREE(lwpname, MTI_NAME_MAXLEN);
+       OBD_FREE(lwpname, MTI_NAME_MAXLEN);
        RETURN(rc);
 }
 
@@ -1017,12 +1012,9 @@ static int lustre_disconnect_lwp(struct super_block *sb)
        GOTO(out, rc);
 
 out:
-       if (bufs)
-               OBD_FREE_PTR(bufs);
-       if (cfg)
-               OBD_FREE_PTR(cfg);
-       if (logname)
-               OBD_FREE(logname, MTI_NAME_MAXLEN);
+       OBD_FREE_PTR(bufs);
+       OBD_FREE_PTR(cfg);
+       OBD_FREE(logname, MTI_NAME_MAXLEN);
 
        return rc1 != 0 ? rc1 : rc;
 }
@@ -1099,8 +1091,7 @@ static int lustre_start_lwp(struct super_block *sb)
 
 out:
        OBD_FREE(logname, MTI_NAME_MAXLEN);
-       if (cfg)
-               OBD_FREE_PTR(cfg);
+       OBD_FREE_PTR(cfg);
 
        return rc;
 }
@@ -1276,9 +1267,9 @@ static struct mgs_target_info *server_lsi2mti(struct lustre_sb_info *lsi)
        if (!mti)
                GOTO(free_list, mti = ERR_PTR(-ENOMEM));
 
-       if (strlcpy(mti->mti_svname, lsi->lsi_svname, sizeof(mti->mti_svname))
-           >= sizeof(mti->mti_svname))
-               GOTO(free_mti, rc = -E2BIG);
+       rc = strscpy(mti->mti_svname, lsi->lsi_svname, sizeof(mti->mti_svname));
+       if (rc < 0)
+               GOTO(free_mti, rc);
 
        mti->mti_nid_count = nid_count;
        for (i = 0; i < mti->mti_nid_count; i++) {
@@ -1310,7 +1301,7 @@ static struct mgs_target_info *server_lsi2mti(struct lustre_sb_info *lsi)
        /* use NID strings instead */
        if (large_nid)
                mti->mti_flags |= LDD_F_LARGE_NID;
-       cplen = strlcpy(mti->mti_params, lsi->lsi_lmd->lmd_params,
+       cplen = strscpy(mti->mti_params, lsi->lsi_lmd->lmd_params,
                        sizeof(mti->mti_params));
        if (cplen >= sizeof(mti->mti_params))
                rc = -E2BIG;
@@ -1364,9 +1355,8 @@ again:
                                mti_len, mti, NULL);
        if (rc < 0) {
                if (mti->mti_flags & LDD_F_ERROR) {
-                       LCONSOLE_ERROR_MSG(0x160,
-                                          "%s: the MGS refuses to allow this server to start: rc = %d. Please see messages on the MGS.\n",
-                                          lsi->lsi_svname, rc);
+                       LCONSOLE_ERROR("%s: the MGS refuses to allow this server to start: rc = %d. Please see messages on the MGS.\n",
+                                      lsi->lsi_svname, rc);
                } else if (must_succeed) {
                        if ((rc == -ESHUTDOWN || rc == -EIO) && ++tried < 5) {
                                /* The connection with MGS is not established.
@@ -1377,9 +1367,8 @@ again:
                                        goto again;
                        }
 
-                       LCONSOLE_ERROR_MSG(0x15f,
-                                          "%s: cannot register this server with the MGS: rc = %d. Is the MGS running?\n",
-                                          lsi->lsi_svname, rc);
+                       LCONSOLE_ERROR("%s: cannot register this server with the MGS: rc = %d. Is the MGS running?\n",
+                                      lsi->lsi_svname, rc);
                } else {
                        CDEBUG(D_HA,
                               "%s: error registering with the MGS: rc = %d (not fatal)\n",
@@ -1631,13 +1620,13 @@ static int lsi_prepare(struct lustre_sb_info *lsi)
            strlen(fstype) >= sizeof(lsi->lsi_fstype))
                RETURN(-ENAMETOOLONG);
 
-       strlcpy(lsi->lsi_svname, lsi->lsi_lmd->lmd_profile,
+       strscpy(lsi->lsi_svname, lsi->lsi_lmd->lmd_profile,
                sizeof(lsi->lsi_svname));
-       strlcpy(lsi->lsi_osd_type, osd_type, sizeof(lsi->lsi_osd_type));
+       strscpy(lsi->lsi_osd_type, osd_type, sizeof(lsi->lsi_osd_type));
        /* XXX: a temp. solution for components using ldiskfs
         *      to be removed in one of the subsequent patches
         */
-       strlcpy(lsi->lsi_fstype, fstype, sizeof(lsi->lsi_fstype));
+       strscpy(lsi->lsi_fstype, fstype, sizeof(lsi->lsi_fstype));
 
        /* Determine server type */
        rc = server_name2index(lsi->lsi_svname, &index, NULL);
@@ -1965,7 +1954,7 @@ static int server_getattr(struct vfsmount *mnt, struct dentry *de,
        CDEBUG(D_SUPER, "%s: root_inode from %s ino=%lu, dev=%x\n",
               lsi->lsi_svname, root_inode == inode ? "lsi" : "vfsmnt",
               root_inode->i_ino, root_inode->i_rdev);
-       generic_fillattr(IDMAP_ARG root_inode, stat);
+       generic_fillattr(IDMAP_ARG RQMASK_ARG root_inode, stat);
        iput(root_inode);
 
        return 0;
@@ -2002,6 +1991,10 @@ static bool is_cmd_supported(unsigned int cmd)
                return true;
        case LL_IOC_RESIZE_FS:
                return true;
+#ifdef HAVE_FSMAP_H
+       case FS_IOC_GETFSMAP:
+               return true;
+#endif
        default:
                return false;
        }
@@ -2017,6 +2010,40 @@ static long server_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
        struct inode *root_inode;
        int err = -ENOTTY;
 
+       if (cmd == LL_IOC_FID2MDTIDX) {
+               union {
+                       struct lu_seq_range range;
+                       struct lu_fid fid;
+               } u;
+               struct lu_env *env;
+               int len;
+
+               if (copy_from_user(&u.fid, (struct lu_fid __user *)arg,
+                                  sizeof(u.fid)))
+                       RETURN(-EFAULT);
+
+               OBD_ALLOC_PTR(env);
+               if (env == NULL)
+                       return -ENOMEM;
+               err = lu_env_init(env, LCT_DT_THREAD);
+               if (err)
+                       GOTO(out, err = -ENOMEM);
+
+               /* XXX: check for size */
+               len = sizeof(struct lu_fid);
+               err = obd_get_info(env, lsi->lsi_osd_exp, sizeof(KEY_FID2IDX),
+                                  KEY_FID2IDX, &len, &u.fid);
+               if (err == 0) {
+                       err = -EINVAL;
+                       if (u.range.lsr_flags & LU_SEQ_RANGE_MDT)
+                               err = u.range.lsr_index;
+               }
+               lu_env_fini(env);
+out:
+               OBD_FREE_PTR(env);
+               return err;
+       }
+
        if (!is_cmd_supported(cmd))
                return err;
 
@@ -2188,9 +2215,8 @@ int server_fill_super(struct super_block *sb)
               lsi->lsi_svname, lsi->lsi_lmd->lmd_dev);
 
        if (class_name2obd(lsi->lsi_svname)) {
-               LCONSOLE_ERROR_MSG(0x161,
-                                  "The target named %s is already running. Double-mount may have compromised the disk journal.\n",
-                                  lsi->lsi_svname);
+               LCONSOLE_ERROR("The target named %s is already running. Double-mount may have compromised the disk journal.\n",
+                              lsi->lsi_svname);
                lustre_put_lsi(sb);
                RETURN(-EALREADY);
        }