Whamcloud - gitweb
LU-8726 osd-ldiskfs: bypass read for benchmarking
[fs/lustre-release.git] / lustre / lmv / lmv_obd.c
index 38b1888..f9ae025 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * GPL HEADER END
  */
@@ -27,7 +23,7 @@
  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2015, Intel Corporation.
+ * Copyright (c) 2011, 2016, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -62,6 +58,8 @@
 #include <lustre_kernelcomm.h>
 #include "lmv_internal.h"
 
+static int lmv_check_connect(struct obd_device *obd);
+
 static void lmv_activate_target(struct lmv_obd *lmv,
                                 struct lmv_tgt_desc *tgt,
                                 int activate)
@@ -101,7 +99,7 @@ static int lmv_set_mdc_active(struct lmv_obd *lmv,
                if (tgt == NULL || tgt->ltd_exp == NULL)
                        continue;
 
-               CDEBUG(D_INFO, "Target idx %d is %s conn "LPX64"\n", i,
+               CDEBUG(D_INFO, "Target idx %d is %s conn %#llx\n", i,
                       tgt->ltd_uuid.uuid, tgt->ltd_exp->exp_handle.h_cookie);
 
                if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
@@ -193,45 +191,28 @@ static int lmv_notify(struct obd_device *obd, struct obd_device *watched,
         RETURN(rc);
 }
 
-/**
- * This is fake connect function. Its purpose is to initialize lmv and say
- * caller that everything is okay. Real connection will be performed later.
- */
 static int lmv_connect(const struct lu_env *env,
-                       struct obd_export **exp, struct obd_device *obd,
-                       struct obd_uuid *cluuid, struct obd_connect_data *data,
-                       void *localdata)
+                      struct obd_export **pexp, struct obd_device *obd,
+                      struct obd_uuid *cluuid, struct obd_connect_data *data,
+                      void *localdata)
 {
-        struct lmv_obd        *lmv = &obd->u.lmv;
-        struct lustre_handle  conn = { 0 };
-        int                    rc = 0;
-        ENTRY;
-
-        /*
-         * We don't want to actually do the underlying connections more than
-         * once, so keep track.
-         */
-        lmv->refcount++;
-        if (lmv->refcount > 1) {
-                *exp = NULL;
-                RETURN(0);
-        }
-
-        rc = class_connect(&conn, obd, cluuid);
-        if (rc) {
-                CERROR("class_connection() returned %d\n", rc);
-                RETURN(rc);
-        }
+       struct lmv_obd *lmv = &obd->u.lmv;
+       struct lustre_handle conn = { 0 };
+       struct obd_export *exp;
+       int rc;
+       ENTRY;
 
-        *exp = class_conn2export(&conn);
-        class_export_get(*exp);
+       rc = class_connect(&conn, obd, cluuid);
+       if (rc) {
+               CERROR("class_connection() returned %d\n", rc);
+               RETURN(rc);
+       }
 
-        lmv->exp = *exp;
-        lmv->connected = 0;
-        lmv->cluuid = *cluuid;
+       exp = class_conn2export(&conn);
 
-        if (data)
-                lmv->conn_data = *data;
+       lmv->connected = 0;
+       lmv->cluuid = *cluuid;
+       lmv->conn_data = *data;
 
        if (lmv->targets_proc_entry == NULL) {
                lmv->targets_proc_entry = lprocfs_register("target_obds",
@@ -246,18 +227,21 @@ static int lmv_connect(const struct lu_env *env,
                }
        }
 
-        /*
-         * All real clients should perform actual connection right away, because
-         * it is possible, that LMV will not have opportunity to connect targets
-         * and MDC stuff will be called directly, for instance while reading
-         * ../mdc/../kbytesfree procfs file, etc.
-         */
-       if (data != NULL && (data->ocd_connect_flags & OBD_CONNECT_REAL))
-                rc = lmv_check_connect(obd);
+       rc = lmv_check_connect(obd);
+       if (rc != 0)
+               GOTO(out_proc, rc);
+
+       *pexp = exp;
 
-       if (rc && lmv->targets_proc_entry != NULL)
-               lprocfs_remove(&lmv->targets_proc_entry);
        RETURN(rc);
+
+out_proc:
+       if (lmv->targets_proc_entry != NULL)
+               lprocfs_remove(&lmv->targets_proc_entry);
+
+       class_disconnect(exp);
+
+       return rc;
 }
 
 static int lmv_init_ea_size(struct obd_export *exp, __u32 easize,
@@ -514,7 +498,7 @@ static int lmv_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
        RETURN(rc);
 }
 
-int lmv_check_connect(struct obd_device *obd)
+static int lmv_check_connect(struct obd_device *obd)
 {
        struct lmv_obd          *lmv = &obd->u.lmv;
        struct lmv_tgt_desc     *tgt;
@@ -559,7 +543,6 @@ int lmv_check_connect(struct obd_device *obd)
                        GOTO(out_disc, rc);
        }
 
-       class_export_put(lmv->exp);
        lmv->connected = 1;
        easize = lmv_mds_md_size(lmv->desc.ld_tgt_count, LMV_MAGIC);
        lmv_init_ea_size(obd->obd_self_export, easize, 0);
@@ -583,9 +566,10 @@ int lmv_check_connect(struct obd_device *obd)
                         }
                 }
         }
-        class_disconnect(lmv->exp);
+
        mutex_unlock(&lmv->lmv_init_mutex);
-        RETURN(rc);
+
+       RETURN(rc);
 }
 
 static int lmv_disconnect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
@@ -643,13 +627,6 @@ static int lmv_disconnect(struct obd_export *exp)
         if (!lmv->tgts)
                 goto out_local;
 
-        /*
-         * Only disconnect the underlying layers on the final disconnect.
-         */
-        lmv->refcount--;
-        if (lmv->refcount != 0)
-                goto out_local;
-
         for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
                if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
                         continue;
@@ -671,9 +648,9 @@ out_local:
         if (!lmv->connected)
                 class_export_put(exp);
         rc = class_disconnect(exp);
-        if (lmv->refcount == 0)
-                lmv->connected = 0;
-        RETURN(rc);
+       lmv->connected = 0;
+
+       RETURN(rc);
 }
 
 static int lmv_fid2path(struct obd_export *exp, int len, void *karg,
@@ -723,7 +700,7 @@ repeat_fid2path:
                *ptr = '/';
        }
 
-       CDEBUG(D_INFO, "%s: get path %s "DFID" rec: "LPU64" ln: %u\n",
+       CDEBUG(D_INFO, "%s: get path %s "DFID" rec: %llu ln: %u\n",
               tgt->ltd_exp->exp_obd->obd_name,
               gf->gf_u.gf_path, PFID(&gf->gf_fid), gf->gf_recno,
               gf->gf_linkno);
@@ -865,7 +842,7 @@ static int lmv_hsm_ct_register(struct lmv_obd *lmv, unsigned int cmd, int len,
                                /* permanent error */
                                CERROR("%s: iocontrol MDC %s on MDT"
                                       " idx %d cmd %x: err = %d\n",
-                                      class_exp2obd(lmv->exp)->obd_name,
+                                      lmv2obd_dev(lmv)->obd_name,
                                       tgt->ltd_uuid.uuid, i, cmd, err);
                                rc = err;
                                lk->lk_flags |= LK_FLG_STOP;
@@ -1189,7 +1166,9 @@ hsm_req_err:
 static int lmv_placement_policy(struct obd_device *obd,
                                struct md_op_data *op_data, u32 *mds)
 {
-       struct lmv_obd          *lmv = &obd->u.lmv;
+       struct lmv_obd     *lmv = &obd->u.lmv;
+       struct lmv_user_md *lum;
+
        ENTRY;
 
        LASSERT(mds != NULL);
@@ -1199,31 +1178,22 @@ static int lmv_placement_policy(struct obd_device *obd,
                RETURN(0);
        }
 
-       if (op_data->op_default_stripe_offset != -1) {
+       lum = op_data->op_data;
+       /* Choose MDS by
+        * 1. See if the stripe offset is specified by lum.
+        * 2. Then check if there is default stripe offset.
+        * 3. Finally choose MDS by name hash if the parent
+        *    is striped directory. (see lmv_locate_mds()). */
+       if (op_data->op_cli_flags & CLI_SET_MEA && lum != NULL &&
+           le32_to_cpu(lum->lum_stripe_offset) != (__u32)-1) {
+               *mds = le32_to_cpu(lum->lum_stripe_offset);
+       } else if (op_data->op_default_stripe_offset != (__u32)-1) {
                *mds = op_data->op_default_stripe_offset;
-               RETURN(0);
-       }
-
-       /**
-        * If stripe_offset is provided during setdirstripe
-        * (setdirstripe -i xx), xx MDS will be choosen.
-        */
-       if (op_data->op_cli_flags & CLI_SET_MEA && op_data->op_data != NULL) {
-               struct lmv_user_md *lum;
-
-               lum = op_data->op_data;
-
-               if (le32_to_cpu(lum->lum_stripe_offset) != (__u32)-1) {
-                       *mds = le32_to_cpu(lum->lum_stripe_offset);
-               } else {
-                       /* -1 means default, which will be in the same MDT with
-                        * the stripe */
-                       *mds = op_data->op_mds;
-                       lum->lum_stripe_offset = cpu_to_le32(op_data->op_mds);
-               }
+               op_data->op_mds = *mds;
+               /* Correct the stripe offset in lum */
+               if (lum != NULL)
+                       lum->lum_stripe_offset = cpu_to_le32(*mds);
        } else {
-               /* Allocate new fid on target according to operation type and
-                * parent home mds. */
                *mds = op_data->op_mds;
        }
 
@@ -1409,10 +1379,6 @@ static int lmv_statfs(const struct lu_env *env, struct obd_export *exp,
        __u32                    i;
        ENTRY;
 
-        rc = lmv_check_connect(obd);
-        if (rc)
-                RETURN(rc);
-
         OBD_ALLOC(temp, sizeof(*temp));
         if (temp == NULL)
                 RETURN(-ENOMEM);
@@ -1462,10 +1428,6 @@ static int lmv_get_root(struct obd_export *exp, const char *fileset,
         int                   rc;
         ENTRY;
 
-       rc = lmv_check_connect(obd);
-       if (rc)
-               RETURN(rc);
-
        rc = md_get_root(lmv->tgts[0]->ltd_exp, fileset, fid);
        RETURN(rc);
 }
@@ -1481,10 +1443,6 @@ static int lmv_getxattr(struct obd_export *exp, const struct lu_fid *fid,
         int                     rc;
         ENTRY;
 
-        rc = lmv_check_connect(obd);
-        if (rc)
-                RETURN(rc);
-
         tgt = lmv_find_target(lmv, fid);
         if (IS_ERR(tgt))
                 RETURN(PTR_ERR(tgt));
@@ -1507,10 +1465,6 @@ static int lmv_setxattr(struct obd_export *exp, const struct lu_fid *fid,
         int                     rc;
         ENTRY;
 
-        rc = lmv_check_connect(obd);
-        if (rc)
-                RETURN(rc);
-
         tgt = lmv_find_target(lmv, fid);
         if (IS_ERR(tgt))
                 RETURN(PTR_ERR(tgt));
@@ -1531,10 +1485,6 @@ static int lmv_getattr(struct obd_export *exp, struct md_op_data *op_data,
         int                      rc;
         ENTRY;
 
-        rc = lmv_check_connect(obd);
-        if (rc)
-                RETURN(rc);
-
         tgt = lmv_find_target(lmv, &op_data->op_fid1);
         if (IS_ERR(tgt))
                 RETURN(PTR_ERR(tgt));
@@ -1554,13 +1504,8 @@ static int lmv_null_inode(struct obd_export *exp, const struct lu_fid *fid)
         struct obd_device   *obd = exp->exp_obd;
         struct lmv_obd      *lmv = &obd->u.lmv;
        __u32                i;
-        int                  rc;
         ENTRY;
 
-        rc = lmv_check_connect(obd);
-        if (rc)
-                RETURN(rc);
-
         CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
 
        /*
@@ -1586,10 +1531,6 @@ static int lmv_close(struct obd_export *exp, struct md_op_data *op_data,
         int                    rc;
         ENTRY;
 
-        rc = lmv_check_connect(obd);
-        if (rc)
-                RETURN(rc);
-
         tgt = lmv_find_target(lmv, &op_data->op_fid1);
         if (IS_ERR(tgt))
                 RETURN(PTR_ERR(tgt));
@@ -1713,10 +1654,6 @@ int lmv_create(struct obd_export *exp, struct md_op_data *op_data,
        int                      rc;
        ENTRY;
 
-       rc = lmv_check_connect(obd);
-       if (rc)
-               RETURN(rc);
-
        if (!lmv->desc.ld_active_tgt_count)
                RETURN(-EIO);
 
@@ -1759,8 +1696,7 @@ int lmv_create(struct obd_export *exp, struct md_op_data *op_data,
 
 static int
 lmv_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
-           const union ldlm_policy_data *policy,
-           struct lookup_intent *it, struct md_op_data *op_data,
+           const union ldlm_policy_data *policy, struct md_op_data *op_data,
            struct lustre_handle *lockh, __u64 extra_lock_flags)
 {
        struct obd_device        *obd = exp->exp_obd;
@@ -1769,21 +1705,16 @@ lmv_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
        int                       rc;
        ENTRY;
 
-       rc = lmv_check_connect(obd);
-       if (rc)
-               RETURN(rc);
-
-       CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID"\n",
-              LL_IT2STR(it), PFID(&op_data->op_fid1));
+       CDEBUG(D_INODE, "ENQUEUE on "DFID"\n", PFID(&op_data->op_fid1));
 
        tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
        if (IS_ERR(tgt))
                RETURN(PTR_ERR(tgt));
 
-       CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID" -> mds #%u\n",
-              LL_IT2STR(it), PFID(&op_data->op_fid1), tgt->ltd_idx);
+       CDEBUG(D_INODE, "ENQUEUE on "DFID" -> mds #%u\n",
+              PFID(&op_data->op_fid1), tgt->ltd_idx);
 
-       rc = md_enqueue(tgt->ltd_exp, einfo, policy, it, op_data, lockh,
+       rc = md_enqueue(tgt->ltd_exp, einfo, policy, op_data, lockh,
                        extra_lock_flags);
 
        RETURN(rc);
@@ -1801,10 +1732,6 @@ lmv_getattr_name(struct obd_export *exp,struct md_op_data *op_data,
        int                      rc;
        ENTRY;
 
-       rc = lmv_check_connect(obd);
-       if (rc)
-               RETURN(rc);
-
        tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
        if (IS_ERR(tgt))
                RETURN(PTR_ERR(tgt));
@@ -1899,10 +1826,6 @@ static int lmv_link(struct obd_export *exp, struct md_op_data *op_data,
        int                      rc;
        ENTRY;
 
-       rc = lmv_check_connect(obd);
-       if (rc)
-               RETURN(rc);
-
        LASSERT(op_data->op_namelen != 0);
 
        CDEBUG(D_INODE, "LINK "DFID":%*s to "DFID"\n",
@@ -1964,10 +1887,6 @@ static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
               (int)newlen, new, PFID(&op_data->op_fid2),
               op_data->op_mea2 ? op_data->op_mea2->lsm_md_stripe_count : 0);
 
-       rc = lmv_check_connect(obd);
-       if (rc)
-               RETURN(rc);
-
        op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
        op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
        op_data->op_cap = cfs_curproc_cap_pack();
@@ -2126,10 +2045,6 @@ static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data,
        int                      rc = 0;
        ENTRY;
 
-       rc = lmv_check_connect(obd);
-       if (rc)
-               RETURN(rc);
-
        CDEBUG(D_INODE, "SETATTR for "DFID", valid 0x%x\n",
               PFID(&op_data->op_fid1), op_data->op_attr.ia_valid);
 
@@ -2152,10 +2067,6 @@ static int lmv_fsync(struct obd_export *exp, const struct lu_fid *fid,
        int                      rc;
        ENTRY;
 
-       rc = lmv_check_connect(obd);
-       if (rc != 0)
-               RETURN(rc);
-
        tgt = lmv_find_target(lmv, fid);
        if (IS_ERR(tgt))
                RETURN(PTR_ERR(tgt));
@@ -2261,7 +2172,7 @@ next:
                        stripe_hash = le64_to_cpu(dp->ldp_hash_end);
 
                        kunmap(page);
-                       page_cache_release(page);
+                       put_page(page);
                        page = NULL;
 
                        /* reach the end of current stripe, go to next stripe */
@@ -2276,12 +2187,12 @@ next:
                            le64_to_cpu(ent->lde_hash)) {
                                min_ent = ent;
                                kunmap(min_page);
-                               page_cache_release(min_page);
+                               put_page(min_page);
                                min_idx = i;
                                min_page = page;
                        } else {
                                kunmap(page);
-                               page_cache_release(page);
+                               put_page(page);
                                page = NULL;
                        }
                } else {
@@ -2294,7 +2205,7 @@ next:
 out:
        if (*ppage != NULL) {
                kunmap(*ppage);
-               page_cache_release(*ppage);
+               put_page(*ppage);
        }
        *stripe_offset = min_idx;
        *entp = min_ent;
@@ -2331,7 +2242,6 @@ static int lmv_read_striped_page(struct obd_export *exp,
                                 struct md_callback *cb_op,
                                 __u64 offset, struct page **ppage)
 {
-       struct obd_device       *obd = exp->exp_obd;
        struct lu_fid           master_fid = op_data->op_fid1;
        struct inode            *master_inode = op_data->op_data;
        __u64                   hash_offset = offset;
@@ -2347,10 +2257,6 @@ static int lmv_read_striped_page(struct obd_export *exp,
        int                     rc;
        ENTRY;
 
-       rc = lmv_check_connect(obd);
-       if (rc)
-               RETURN(rc);
-
        /* Allocate a page and read entries from all of stripes and fill
         * the page by hash order */
        ent_page = alloc_page(GFP_KERNEL);
@@ -2364,7 +2270,7 @@ static int lmv_read_striped_page(struct obd_export *exp,
        dp->ldp_flags |= LDF_COLLIDE;
 
        area = dp + 1;
-       left_bytes = PAGE_CACHE_SIZE - sizeof(*dp);
+       left_bytes = PAGE_SIZE - sizeof(*dp);
        ent = area;
        last_ent = ent;
        do {
@@ -2425,7 +2331,7 @@ static int lmv_read_striped_page(struct obd_export *exp,
 out:
        if (min_ent_page != NULL) {
                kunmap(min_ent_page);
-               page_cache_release(min_ent_page);
+               put_page(min_ent_page);
        }
 
        if (unlikely(rc != 0)) {
@@ -2462,10 +2368,6 @@ int lmv_read_page(struct obd_export *exp, struct md_op_data *op_data,
        int                     rc;
        ENTRY;
 
-       rc = lmv_check_connect(obd);
-       if (rc != 0)
-               RETURN(rc);
-
        if (unlikely(lsm != NULL)) {
                rc = lmv_read_striped_page(exp, op_data, cb_op, offset, ppage);
                RETURN(rc);
@@ -2517,9 +2419,6 @@ static int lmv_unlink(struct obd_export *exp, struct md_op_data *op_data,
        struct lmv_stripe_md    *lsm = op_data->op_mea1;
        ENTRY;
 
-       rc = lmv_check_connect(obd);
-       if (rc)
-               RETURN(rc);
 retry_unlink:
        /* For striped dir, we need to locate the parent as well */
        if (lsm != NULL) {
@@ -2695,7 +2594,7 @@ static int lmv_get_info(const struct lu_env *env, struct obd_export *exp,
 
         obd = class_exp2obd(exp);
         if (obd == NULL) {
-                CDEBUG(D_IOCTL, "Invalid client cookie "LPX64"\n",
+               CDEBUG(D_IOCTL, "Invalid client cookie %#llx\n",
                        exp->exp_handle.h_cookie);
                 RETURN(-EINVAL);
         }
@@ -2704,10 +2603,6 @@ static int lmv_get_info(const struct lu_env *env, struct obd_export *exp,
         if (keylen >= strlen("remote_flag") && !strcmp(key, "remote_flag")) {
                 int i;
 
-                rc = lmv_check_connect(obd);
-                if (rc)
-                        RETURN(rc);
-
                 LASSERT(*vallen == sizeof(__u32));
                for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
                        struct lmv_tgt_desc *tgt = lmv->tgts[i];
@@ -2725,10 +2620,6 @@ static int lmv_get_info(const struct lu_env *env, struct obd_export *exp,
        } else if (KEY_IS(KEY_MAX_EASIZE) ||
                   KEY_IS(KEY_DEFAULT_EASIZE) ||
                   KEY_IS(KEY_CONN_DATA)) {
-               rc = lmv_check_connect(obd);
-               if (rc)
-                       RETURN(rc);
-
                /*
                 * Forwarding this request to first MDS, it should know LOV
                 * desc.
@@ -2775,7 +2666,7 @@ int lmv_set_info_async(const struct lu_env *env, struct obd_export *exp,
 
        obd = class_exp2obd(exp);
        if (obd == NULL) {
-               CDEBUG(D_IOCTL, "Invalid client cookie "LPX64"\n",
+               CDEBUG(D_IOCTL, "Invalid client cookie %#llx\n",
                       exp->exp_handle.h_cookie);
                RETURN(-EINVAL);
        }
@@ -3090,10 +2981,6 @@ int lmv_intent_getattr_async(struct obd_export *exp,
        if (!fid_is_sane(&op_data->op_fid2))
                RETURN(-EINVAL);
 
-       rc = lmv_check_connect(obd);
-       if (rc)
-               RETURN(rc);
-
        ptgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
        if (IS_ERR(ptgt))
                RETURN(PTR_ERR(ptgt));
@@ -3124,10 +3011,6 @@ int lmv_revalidate_lock(struct obd_export *exp, struct lookup_intent *it,
         int                      rc;
         ENTRY;
 
-        rc = lmv_check_connect(obd);
-        if (rc)
-                RETURN(rc);
-
         tgt = lmv_find_target(lmv, fid);
         if (IS_ERR(tgt))
                 RETURN(PTR_ERR(tgt));