Whamcloud - gitweb
LU-5342 lmv: fix some byte order issues
[fs/lustre-release.git] / lustre / lmv / lmv_obd.c
index 368057a..5c452db 100644 (file)
@@ -35,7 +35,6 @@
  */
 
 #define DEBUG_SUBSYSTEM S_LMV
-#ifdef __KERNEL__
 #include <linux/slab.h>
 #include <linux/module.h>
 #include <linux/init.h>
@@ -45,9 +44,6 @@
 #include <linux/math64.h>
 #include <linux/seq_file.h>
 #include <linux/namei.h>
-#else
-#include <liblustre.h>
-#endif
 
 #include <lustre/lustre_idl.h>
 #include <obd_support.h>
@@ -303,8 +299,10 @@ static int lmv_connect(const struct lu_env *env,
                                                        obd->obd_proc_entry,
                                                        NULL, NULL);
                if (IS_ERR(lmv->targets_proc_entry)) {
-                       CERROR("could not register /proc/fs/lustre/%s/%s/target_obds.",
-                              obd->obd_type->typ_name, obd->obd_name);
+                       CERROR("%s: cannot register "
+                              "/proc/fs/lustre/%s/%s/target_obds\n",
+                              obd->obd_name, obd->obd_type->typ_name,
+                              obd->obd_name);
                        lmv->targets_proc_entry = NULL;
                }
        }
@@ -390,7 +388,7 @@ static int lmv_init_ea_size(struct obd_export *exp, int easize,
                                     cookiesize, def_cookiesize);
                if (rc) {
                        CERROR("%s: obd_init_ea_size() failed on MDT target %d:"
-                              " rc = %d.\n", obd->obd_name, i, rc);
+                              " rc = %d\n", obd->obd_name, i, rc);
                        break;
                }
        }
@@ -490,8 +488,8 @@ int lmv_connect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
                                                  mdc_obd->obd_type->typ_name,
                                                  mdc_obd->obd_name);
                if (mdc_symlink == NULL) {
-                       CERROR("Could not register LMV target "
-                              "/proc/fs/lustre/%s/%s/target_obds/%s.",
+                       CERROR("cannot register LMV target "
+                              "/proc/fs/lustre/%s/%s/target_obds/%s\n",
                               obd->obd_type->typ_name, obd->obd_name,
                               mdc_obd->obd_name);
                }
@@ -1122,6 +1120,19 @@ static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
                rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
                break;
        }
+       case LL_IOC_FID2MDTIDX: {
+               struct lu_fid *fid = karg;
+               int             mdt_index;
+
+               rc = lmv_fld_lookup(lmv, fid, &mdt_index);
+               if (rc != 0)
+                       RETURN(rc);
+
+               /* Note: this is from llite(see ll_dir_ioctl()), @uarg does not
+                * point to user space memory for FID2MDTIDX. */
+               *(__u32 *)uarg = mdt_index;
+               break;
+       }
        case OBD_IOC_FID2PATH: {
                rc = lmv_fid2path(exp, len, karg, uarg);
                break;
@@ -1809,13 +1820,41 @@ lmv_locate_target_for_name(struct lmv_obd *lmv, struct lmv_stripe_md *lsm,
  * retval              pointer to the lmv_tgt_desc if succeed.
  *                      ERR_PTR(errno) if failed.
  */
-struct lmv_tgt_desc
-*lmv_locate_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
-               struct lu_fid *fid)
+struct lmv_tgt_desc*
+lmv_locate_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
+              struct lu_fid *fid)
 {
        struct lmv_stripe_md    *lsm = op_data->op_mea1;
        struct lmv_tgt_desc     *tgt;
 
+       /* During creating VOLATILE file, it should honor the mdt
+        * index if the file under striped dir is being restored, see
+        * ct_restore(). */
+       if (op_data->op_bias & MDS_CREATE_VOLATILE &&
+           (int)op_data->op_mds != -1 && lsm != NULL) {
+               int i;
+               tgt = lmv_get_target(lmv, op_data->op_mds, NULL);
+               if (IS_ERR(tgt))
+                       return tgt;
+
+               /* refill the right parent fid */
+               for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
+                       struct lmv_oinfo *oinfo;
+
+                       oinfo = &lsm->lsm_md_oinfo[i];
+                       if (oinfo->lmo_mds == op_data->op_mds) {
+                               *fid = oinfo->lmo_fid;
+                               break;
+                       }
+               }
+
+               /* Hmm, can not find the stripe by mdt_index(op_mds) */
+               if (i == lsm->lsm_md_stripe_count)
+                       tgt = ERR_PTR(-EINVAL);
+
+               return tgt;
+       }
+
        if (lsm == NULL || op_data->op_namelen == 0) {
                tgt = lmv_find_target(lmv, fid);
                if (IS_ERR(tgt))
@@ -2261,109 +2300,6 @@ static int lmv_fsync(struct obd_export *exp, const struct lu_fid *fid,
        RETURN(rc);
 }
 
-/*
- * Adjust a set of pages, each page containing an array of lu_dirpages,
- * so that each page can be used as a single logical lu_dirpage.
- *
- * A lu_dirpage is laid out as follows, where s = ldp_hash_start,
- * e = ldp_hash_end, f = ldp_flags, p = padding, and each "ent" is a
- * struct lu_dirent.  It has size up to LU_PAGE_SIZE. The ldp_hash_end
- * value is used as a cookie to request the next lu_dirpage in a
- * directory listing that spans multiple pages (two in this example):
- *   ________
- *  |        |
- * .|--------v-------   -----.
- * |s|e|f|p|ent|ent| ... |ent|
- * '--|--------------   -----'   Each CFS_PAGE contains a single
- *    '------.                   lu_dirpage.
- * .---------v-------   -----.
- * |s|e|f|p|ent| 0 | ... | 0 |
- * '-----------------   -----'
- *
- * However, on hosts where the native VM page size (PAGE_CACHE_SIZE) is
- * larger than LU_PAGE_SIZE, a single host page may contain multiple
- * lu_dirpages. After reading the lu_dirpages from the MDS, the
- * ldp_hash_end of the first lu_dirpage refers to the one immediately
- * after it in the same CFS_PAGE (arrows simplified for brevity, but
- * in general e0==s1, e1==s2, etc.):
- *
- * .--------------------   -----.
- * |s0|e0|f0|p|ent|ent| ... |ent|
- * |---v----------------   -----|
- * |s1|e1|f1|p|ent|ent| ... |ent|
- * |---v----------------   -----|  Here, each CFS_PAGE contains
- *             ...                 multiple lu_dirpages.
- * |---v----------------   -----|
- * |s'|e'|f'|p|ent|ent| ... |ent|
- * '---|----------------   -----'
- *     v
- * .----------------------------.
- * |        next CFS_PAGE       |
- *
- * This structure is transformed into a single logical lu_dirpage as follows:
- *
- * - Replace e0 with e' so the request for the next lu_dirpage gets the page
- *   labeled 'next CFS_PAGE'.
- *
- * - Copy the LDF_COLLIDE flag from f' to f0 to correctly reflect whether
- *   a hash collision with the next page exists.
- *
- * - Adjust the lde_reclen of the ending entry of each lu_dirpage to span
- *   to the first entry of the next lu_dirpage.
- */
-#if PAGE_CACHE_SIZE > LU_PAGE_SIZE
-static void lmv_adjust_dirpages(struct page **pages, int ncfspgs, int nlupgs)
-{
-       int i;
-
-       for (i = 0; i < ncfspgs; i++) {
-               struct lu_dirpage       *dp = kmap(pages[i]);
-               struct lu_dirpage       *first = dp;
-               struct lu_dirent        *end_dirent = NULL;
-               struct lu_dirent        *ent;
-               __u64                   hash_end = dp->ldp_hash_end;
-               __u32                   flags = dp->ldp_flags;
-
-               while (--nlupgs > 0) {
-                       ent = lu_dirent_start(dp);
-                       for (end_dirent = ent; ent != NULL;
-                            end_dirent = ent, ent = lu_dirent_next(ent));
-
-                       /* Advance dp to next lu_dirpage. */
-                       dp = (struct lu_dirpage *)((char *)dp + LU_PAGE_SIZE);
-
-                       /* Check if we've reached the end of the CFS_PAGE. */
-                       if (!((unsigned long)dp & ~CFS_PAGE_MASK))
-                               break;
-
-                       /* Save the hash and flags of this lu_dirpage. */
-                       hash_end = dp->ldp_hash_end;
-                       flags = dp->ldp_flags;
-
-                       /* Check if lu_dirpage contains no entries. */
-                       if (!end_dirent)
-                               break;
-
-                       /* Enlarge the end entry lde_reclen from 0 to
-                        * first entry of next lu_dirpage. */
-                       LASSERT(le16_to_cpu(end_dirent->lde_reclen) == 0);
-                       end_dirent->lde_reclen =
-                               cpu_to_le16((char *)(dp->ldp_entries) -
-                                           (char *)end_dirent);
-               }
-
-               first->ldp_hash_end = hash_end;
-               first->ldp_flags &= ~cpu_to_le32(LDF_COLLIDE);
-               first->ldp_flags |= flags & cpu_to_le32(LDF_COLLIDE);
-
-               kunmap(pages[i]);
-       }
-       LASSERTF(nlupgs == 0, "left = %d", nlupgs);
-}
-#else
-#define lmv_adjust_dirpages(pages, ncfspgs, nlupgs) do {} while (0)
-#endif /* PAGE_CACHE_SIZE > LU_PAGE_SIZE */
-
 /**
  * Get current minimum entry from striped directory
  *
@@ -2830,7 +2766,7 @@ try_next_stripe:
 
        /* Not cross-ref case, just get out of here. */
        if (likely(!(body->mbo_valid & OBD_MD_MDS)))
-               RETURN(0);
+               RETURN(rc);
 
        CDEBUG(D_INODE, "%s: try unlink to another MDT for "DFID"\n",
               exp->exp_obd->obd_name, PFID(&body->mbo_fid1));
@@ -3088,13 +3024,9 @@ static int lmv_unpack_md_v1(struct obd_export *exp, struct lmv_stripe_md *lsm,
        else
                lsm->lsm_md_hash_type = le32_to_cpu(lmm1->lmv_hash_type);
        lsm->lsm_md_layout_version = le32_to_cpu(lmm1->lmv_layout_version);
-       fid_le_to_cpu(&lsm->lsm_md_master_fid, &lmm1->lmv_master_fid);
        cplen = strlcpy(lsm->lsm_md_pool_name, lmm1->lmv_pool_name,
                        sizeof(lsm->lsm_md_pool_name));
 
-       if (!fid_is_sane(&lsm->lsm_md_master_fid))
-               RETURN(-EPROTO);
-
        if (cplen >= sizeof(lsm->lsm_md_pool_name))
                RETURN(-E2BIG);
 
@@ -3104,7 +3036,7 @@ static int lmv_unpack_md_v1(struct obd_export *exp, struct lmv_stripe_md *lsm,
               lsm->lsm_md_layout_version);
 
        stripe_count = le32_to_cpu(lmm1->lmv_stripe_count);
-       for (i = 0; i < le32_to_cpu(stripe_count); i++) {
+       for (i = 0; i < stripe_count; i++) {
                fid_le_to_cpu(&lsm->lsm_md_oinfo[i].lmo_fid,
                              &lmm1->lmv_stripe_fids[i]);
                rc = lmv_fld_lookup(lmv, &lsm->lsm_md_oinfo[i].lmo_fid,
@@ -3132,7 +3064,6 @@ int lmv_unpack_md(struct obd_export *exp, struct lmv_stripe_md **lsmp,
        lsm = *lsmp;
        /* Free memmd */
        if (lsm != NULL && lmm == NULL) {
-#ifdef __KERNEL__
                int i;
                for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
                        /* For migrating inode, the master stripe and master
@@ -3142,7 +3073,6 @@ int lmv_unpack_md(struct obd_export *exp, struct lmv_stripe_md **lsmp,
                              i == 0) && lsm->lsm_md_oinfo[i].lmo_root != NULL)
                                iput(lsm->lsm_md_oinfo[i].lmo_root);
                }
-#endif
                lsm_size = lmv_stripe_md_size(lsm->lsm_md_stripe_count);
                OBD_FREE(lsm, lsm_size);
                *lsmp = NULL;
@@ -3595,7 +3525,6 @@ int lmv_update_lsm_md(struct obd_export *exp, struct lmv_stripe_md *lsm,
 int lmv_merge_attr(struct obd_export *exp, const struct lmv_stripe_md *lsm,
                   struct cl_attr *attr)
 {
-#ifdef __KERNEL__
        int i;
 
        for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
@@ -3624,7 +3553,6 @@ int lmv_merge_attr(struct obd_export *exp, const struct lmv_stripe_md *lsm,
                if (attr->cat_mtime < LTIME_S(inode->i_mtime))
                        attr->cat_mtime = LTIME_S(inode->i_mtime);
        }
-#endif
        return 0;
 }
 
@@ -3694,7 +3622,6 @@ int __init lmv_init(void)
                                   LUSTRE_LMV_NAME, NULL);
 }
 
-#ifdef __KERNEL__
 static void lmv_exit(void)
 {
         class_unregister_type(LUSTRE_LMV_NAME);
@@ -3706,4 +3633,3 @@ MODULE_LICENSE("GPL");
 
 module_init(lmv_init);
 module_exit(lmv_exit);
-#endif