Whamcloud - gitweb
LU-7851 mdt: skip SOM related configuration
[fs/lustre-release.git] / lustre / mdt / mdt_handler.c
index 3f16666..acae122 100644 (file)
 #include <obd.h>
 #include <obd_support.h>
 
+#include <llog_swab.h>
+
 #include "mdt_internal.h"
 
 
 static unsigned int max_mod_rpcs_per_client = 8;
-CFS_MODULE_PARM(max_mod_rpcs_per_client, "i", uint, 0644,
-               "maximum number of modify RPCs in flight allowed per client");
+module_param(max_mod_rpcs_per_client, uint, 0644);
+MODULE_PARM_DESC(max_mod_rpcs_per_client, "maximum number of modify RPCs in flight allowed per client");
 
 mdl_mode_t mdt_mdl_lock_modes[] = {
         [LCK_MINMODE] = MDL_MINMODE,
@@ -266,11 +268,95 @@ static void mdt_lock_pdo_mode(struct mdt_thread_info *info, struct mdt_object *o
         EXIT;
 }
 
-static int mdt_getstatus(struct tgt_session_info *tsi)
+static int mdt_lookup_fileset(struct mdt_thread_info *info, const char *fileset,
+                             struct lu_fid *fid)
+{
+       struct mdt_device *mdt = info->mti_mdt;
+       struct lu_name *lname = &info->mti_name;
+       char *name = NULL;
+       struct mdt_object *parent;
+       u32 mode;
+       int rc = 0;
+
+       LASSERT(!info->mti_cross_ref);
+
+       OBD_ALLOC(name, NAME_MAX + 1);
+       if (name == NULL)
+               return -ENOMEM;
+       lname->ln_name = name;
+
+       /*
+        * We may want to allow this to mount a completely separate
+        * fileset from the MDT in the future, but keeping it to
+        * ROOT/ only for now avoid potential security issues.
+        */
+       *fid = mdt->mdt_md_root_fid;
+
+       while (rc == 0 && fileset != NULL && *fileset != '\0') {
+               const char *s1 = fileset;
+               const char *s2;
+
+               while (*++s1 == '/')
+                       ;
+               s2 = s1;
+               while (*s2 != '/' && *s2 != '\0')
+                       s2++;
+
+               if (s2 == s1)
+                       break;
+
+               fileset = s2;
+
+               lname->ln_namelen = s2 - s1;
+               if (lname->ln_namelen > NAME_MAX) {
+                       rc = -EINVAL;
+                       break;
+               }
+
+               /* reject .. as a path component */
+               if (lname->ln_namelen == 2 &&
+                   strncmp(s1, "..", 2) == 0) {
+                       rc = -EINVAL;
+                       break;
+               }
+
+               strncpy(name, s1, lname->ln_namelen);
+               name[lname->ln_namelen] = '\0';
+
+               parent = mdt_object_find(info->mti_env, mdt, fid);
+               if (IS_ERR(parent)) {
+                       rc = PTR_ERR(parent);
+                       break;
+               }
+               /* Only got the fid of this obj by name */
+               fid_zero(fid);
+               rc = mdo_lookup(info->mti_env, mdt_object_child(parent), lname,
+                               fid, &info->mti_spec);
+               mdt_object_put(info->mti_env, parent);
+       }
+       if (!rc) {
+               parent = mdt_object_find(info->mti_env, mdt, fid);
+               if (IS_ERR(parent))
+                       rc = PTR_ERR(parent);
+               else {
+                       mode = lu_object_attr(&parent->mot_obj);
+                       mdt_object_put(info->mti_env, parent);
+                       if (!S_ISDIR(mode))
+                               rc = -ENOTDIR;
+               }
+       }
+
+       OBD_FREE(name, NAME_MAX + 1);
+
+       return rc;
+}
+
+static int mdt_get_root(struct tgt_session_info *tsi)
 {
        struct mdt_thread_info  *info = tsi2mdt_info(tsi);
        struct mdt_device       *mdt = info->mti_mdt;
        struct mdt_body         *repbody;
+       char                    *fileset;
        int                      rc;
 
        ENTRY;
@@ -279,11 +365,21 @@ static int mdt_getstatus(struct tgt_session_info *tsi)
        if (rc)
                GOTO(out, rc = err_serious(rc));
 
-       if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK))
+       if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GET_ROOT_PACK))
                GOTO(out, rc = err_serious(-ENOMEM));
 
        repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
-       repbody->mbo_fid1 = mdt->mdt_md_root_fid;
+       if (req_capsule_get_size(info->mti_pill, &RMF_NAME, RCL_CLIENT) > 0) {
+               fileset = req_capsule_client_get(info->mti_pill, &RMF_NAME);
+               if (fileset == NULL)
+                       GOTO(out, rc = err_serious(-EFAULT));
+
+               rc = mdt_lookup_fileset(info, fileset, &repbody->mbo_fid1);
+               if (rc < 0)
+                       GOTO(out, rc = err_serious(rc));
+       } else {
+               repbody->mbo_fid1 = mdt->mdt_md_root_fid;
+       }
        repbody->mbo_valid |= OBD_MD_FLID;
 
        EXIT;
@@ -4241,7 +4337,7 @@ TGT_RPC_HANDLER(MDS_FIRST_OPC,
                HABEO_REFERO,           MDS_SET_INFO,   mdt_set_info,
                &RQF_OBD_SET_INFO, LUSTRE_MDS_VERSION),
 TGT_MDT_HDL(0,                         MDS_GET_INFO,   mdt_get_info),
-TGT_MDT_HDL(0          | HABEO_REFERO, MDS_GETSTATUS,  mdt_getstatus),
+TGT_MDT_HDL(0          | HABEO_REFERO, MDS_GET_ROOT,   mdt_get_root),
 TGT_MDT_HDL(HABEO_CORPUS,              MDS_GETATTR,    mdt_getattr),
 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO,        MDS_GETATTR_NAME,
                                                        mdt_getattr_name),
@@ -4648,6 +4744,7 @@ static struct cfg_interop_param mdt_interop_param[] = {
        { "mdt.group_upcall",   NULL },
        { "mdt.quota_type",     NULL },
        { "mdd.quota_type",     NULL },
+       { "mdt.som",            NULL },
        { "mdt.rootsquash",     "mdt.root_squash" },
        { "mdt.nosquash_nid",   "mdt.nosquash_nids" },
        { NULL }
@@ -5347,6 +5444,7 @@ int mdt_links_read(struct mdt_thread_info *info, struct mdt_object *mdt_obj,
  * \param[in]     info  Per-thread common data shared by MDT level handlers.
  * \param[in]     obj   Object to do path lookup of
  * \param[in,out] fp    User-provided struct to store path information
+ * \param[in]     root_fid Root FID of current path should reach
  *
  * \retval 0 Lookup successful, path information stored in fp
  * \retval -EAGAIN Lookup failed, usually because object is being moved
@@ -5354,7 +5452,8 @@ int mdt_links_read(struct mdt_thread_info *info, struct mdt_object *mdt_obj,
  */
 static int mdt_path_current(struct mdt_thread_info *info,
                            struct mdt_object *obj,
-                           struct getinfo_fid2path *fp)
+                           struct getinfo_fid2path *fp,
+                           struct lu_fid *root_fid)
 {
        struct mdt_device       *mdt = info->mti_mdt;
        struct mdt_object       *mdt_obj;
@@ -5377,16 +5476,18 @@ static int mdt_path_current(struct mdt_thread_info *info,
                RETURN(-ENOMEM);
 
        ldata.ld_buf = buf;
-       ptr = fp->gf_path + fp->gf_pathlen - 1;
+       ptr = fp->gf_u.gf_path + fp->gf_pathlen - 1;
        *ptr = 0;
        --ptr;
        *tmpfid = fp->gf_fid = *mdt_object_fid(obj);
 
-       /* root FID only exists on MDT0, and fid2path should also ends at MDT0,
-        * so checking root_fid can only happen on MDT0. */
-       while (!lu_fid_eq(&mdt->mdt_md_root_fid, &fp->gf_fid)) {
+       while (!lu_fid_eq(root_fid, &fp->gf_fid)) {
                struct lu_buf           lmv_buf;
 
+               if (!lu_fid_eq(root_fid, &mdt->mdt_md_root_fid) &&
+                   lu_fid_eq(&mdt->mdt_md_root_fid, &fp->gf_fid))
+                       GOTO(out, rc = -ENOENT);
+
                mdt_obj = mdt_object_find(info->mti_env, mdt, tmpfid);
                if (IS_ERR(mdt_obj))
                        GOTO(out, rc = PTR_ERR(mdt_obj));
@@ -5447,7 +5548,7 @@ static int mdt_path_current(struct mdt_thread_info *info,
 
                /* Pack the name in the end of the buffer */
                ptr -= tmpname->ln_namelen;
-               if (ptr - 1 <= fp->gf_path)
+               if (ptr - 1 <= fp->gf_u.gf_path)
                        GOTO(out, rc = -EOVERFLOW);
                strncpy(ptr, tmpname->ln_name, tmpname->ln_namelen);
                *(--ptr) = '/';
@@ -5462,7 +5563,8 @@ static int mdt_path_current(struct mdt_thread_info *info,
 
 remote_out:
        ptr++; /* skip leading / */
-       memmove(fp->gf_path, ptr, fp->gf_path + fp->gf_pathlen - ptr);
+       memmove(fp->gf_u.gf_path, ptr,
+               fp->gf_u.gf_path + fp->gf_pathlen - ptr);
 
 out:
        RETURN(rc);
@@ -5484,7 +5586,7 @@ out:
  * \retval negative errno if there was a problem
  */
 static int mdt_path(struct mdt_thread_info *info, struct mdt_object *obj,
-                   struct getinfo_fid2path *fp)
+                   struct getinfo_fid2path *fp, struct lu_fid *root_fid)
 {
        struct mdt_device       *mdt = info->mti_mdt;
        int                     tries = 3;
@@ -5494,14 +5596,17 @@ static int mdt_path(struct mdt_thread_info *info, struct mdt_object *obj,
        if (fp->gf_pathlen < 3)
                RETURN(-EOVERFLOW);
 
-       if (lu_fid_eq(&mdt->mdt_md_root_fid, mdt_object_fid(obj))) {
-               fp->gf_path[0] = '\0';
+       if (root_fid == NULL)
+               root_fid = &mdt->mdt_md_root_fid;
+
+       if (lu_fid_eq(root_fid, mdt_object_fid(obj))) {
+               fp->gf_u.gf_path[0] = '\0';
                RETURN(0);
        }
 
        /* Retry multiple times in case file is being moved */
        while (tries-- && rc == -EAGAIN)
-               rc = mdt_path_current(info, obj, fp);
+               rc = mdt_path_current(info, obj, fp, root_fid);
 
        RETURN(rc);
 }
@@ -5523,6 +5628,7 @@ static int mdt_path(struct mdt_thread_info *info, struct mdt_object *obj,
  * \retval negative errno if there was a problem
  */
 static int mdt_fid2path(struct mdt_thread_info *info,
+                       struct lu_fid *root_fid,
                        struct getinfo_fid2path *fp)
 {
        struct mdt_device *mdt = info->mti_mdt;
@@ -5565,20 +5671,22 @@ static int mdt_fid2path(struct mdt_thread_info *info,
                RETURN(rc);
        }
 
-       rc = mdt_path(info, obj, fp);
+       rc = mdt_path(info, obj, fp, root_fid);
 
        CDEBUG(D_INFO, "fid "DFID", path %s recno "LPX64" linkno %u\n",
-              PFID(&fp->gf_fid), fp->gf_path, fp->gf_recno, fp->gf_linkno);
+              PFID(&fp->gf_fid), fp->gf_u.gf_path,
+              fp->gf_recno, fp->gf_linkno);
 
        mdt_object_put(info->mti_env, obj);
 
        RETURN(rc);
 }
 
-static int mdt_rpc_fid2path(struct mdt_thread_info *info, void *key,
+static int mdt_rpc_fid2path(struct mdt_thread_info *info, void *key, int keylen,
                            void *val, int vallen)
 {
        struct getinfo_fid2path *fpout, *fpin;
+       struct lu_fid *root_fid = NULL;
        int rc = 0;
 
        fpin = key + cfs_size_round(sizeof(KEY_FID2PATH));
@@ -5591,7 +5699,18 @@ static int mdt_rpc_fid2path(struct mdt_thread_info *info, void *key,
        if (fpout->gf_pathlen != vallen - sizeof(*fpin))
                RETURN(-EINVAL);
 
-       rc = mdt_fid2path(info, fpout);
+       if (keylen >= cfs_size_round(sizeof(KEY_FID2PATH)) + sizeof(*fpin) +
+                     sizeof(struct lu_fid)) {
+               /* client sent its root FID, which is normally fileset FID */
+               root_fid = fpin->gf_u.gf_root_fid;
+               if (ptlrpc_req_need_swab(info->mti_pill->rc_req))
+                       lustre_swab_lu_fid(root_fid);
+
+               if (root_fid != NULL && !fid_is_sane(root_fid))
+                       RETURN(-EINVAL);
+       }
+
+       rc = mdt_fid2path(info, root_fid, fpout);
        RETURN(rc);
 }
 
@@ -5636,7 +5755,7 @@ int mdt_get_info(struct tgt_session_info *tsi)
        if (KEY_IS(KEY_FID2PATH)) {
                struct mdt_thread_info  *info = tsi2mdt_info(tsi);
 
-               rc = mdt_rpc_fid2path(info, key, valout, *vallen);
+               rc = mdt_rpc_fid2path(info, key, keylen, valout, *vallen);
                mdt_thread_info_fini(info);
        } else {
                rc = -EINVAL;