Whamcloud - gitweb
LU-11158 mdt: grow lvb buffer to hold layout
[fs/lustre-release.git] / lustre / ofd / ofd_lvb.c
index ec1cae3..a48b4d5 100644 (file)
@@ -23,7 +23,7 @@
  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, 2014 Intel Corporation.
+ * Copyright (c) 2012, 2017, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -77,22 +77,23 @@ static int ofd_lvbo_free(struct ldlm_resource *res)
  *
  * Called with res->lr_lvb_sem held.
  *
- * \param[in] res      LDLM resource
+ * \param[in] lock     LDLM lock on resource
  *
  * \retval             0 on successful setup
  * \retval             negative value on error
  */
-static int ofd_lvbo_init(struct ldlm_resource *res)
+static int ofd_lvbo_init(const struct lu_env *env, struct ldlm_resource *res)
 {
        struct ost_lvb          *lvb;
        struct ofd_device       *ofd;
        struct ofd_object       *fo;
        struct ofd_thread_info  *info;
-       struct lu_env            env;
        int                      rc = 0;
 
        ENTRY;
 
+       LASSERT(env);
+       info = ofd_info(env);
        LASSERT(res);
        LASSERT(mutex_is_locked(&res->lr_lvb_mutex));
 
@@ -105,25 +106,20 @@ static int ofd_lvbo_init(struct ldlm_resource *res)
        if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_OST_LVB))
                RETURN(-ENOMEM);
 
-       rc = lu_env_init(&env, LCT_DT_THREAD);
-       if (rc)
-               RETURN(rc);
-
        OBD_ALLOC_PTR(lvb);
        if (lvb == NULL)
-               GOTO(out_env, rc = -ENOMEM);
+               GOTO(out, rc = -ENOMEM);
 
        res->lr_lvb_data = lvb;
        res->lr_lvb_len = sizeof(*lvb);
 
-       info = ofd_info_init(&env, NULL);
        ost_fid_from_resid(&info->fti_fid, &res->lr_name,
                           ofd->ofd_lut.lut_lsd.lsd_osd_index);
-       fo = ofd_object_find(&env, ofd, &info->fti_fid);
+       fo = ofd_object_find(env, ofd, &info->fti_fid);
        if (IS_ERR(fo))
                GOTO(out_lvb, rc = PTR_ERR(fo));
 
-       rc = ofd_attr_get(&env, fo, &info->fti_attr);
+       rc = ofd_attr_get(env, fo, &info->fti_attr);
        if (rc)
                GOTO(out_obj, rc);
 
@@ -133,19 +129,20 @@ static int ofd_lvbo_init(struct ldlm_resource *res)
        lvb->lvb_atime = info->fti_attr.la_atime;
        lvb->lvb_ctime = info->fti_attr.la_ctime;
 
-       CDEBUG(D_DLMTRACE, "res: "DFID" initial lvb size: "LPU64", "
-              "mtime: "LPX64", blocks: "LPX64"\n",
+       CDEBUG(D_DLMTRACE, "res: "DFID" initial lvb size: %llu, "
+              "mtime: %#llx, blocks: %#llx\n",
               PFID(&info->fti_fid), lvb->lvb_size,
               lvb->lvb_mtime, lvb->lvb_blocks);
 
+       info->fti_attr.la_valid = 0;
+
        EXIT;
 out_obj:
-       ofd_object_put(&env, fo);
+       ofd_object_put(env, fo);
 out_lvb:
        if (rc != 0)
                OST_LVB_SET_ERR(lvb->lvb_blocks, rc);
-out_env:
-       lu_env_fini(&env);
+out:
        /* Don't free lvb data on lookup error */
        return rc;
 }
@@ -172,42 +169,39 @@ out_env:
  *  \a req != NULL : called by the DLM itself after a glimpse callback
  *  \a req == NULL : called by the OFD after a disk write
  *
- * \param[in] res              LDLM resource
+ * \param[in] lock             LDLM lock
  * \param[in] req              PTLRPC request
  * \param[in] increase_only    don't allow LVB values to decrease
  *
  * \retval             0 on successful setup
  * \retval             negative value on error
  */
-static int ofd_lvbo_update(struct ldlm_resource *res,
-                          struct ptlrpc_request *req, int increase_only)
+static int ofd_lvbo_update(const struct lu_env *env, struct ldlm_resource *res,
+                          struct ldlm_lock *lock, struct ptlrpc_request *req,
+                          int increase_only)
 {
+       struct ofd_thread_info  *info;
        struct ofd_device       *ofd;
        struct ofd_object       *fo;
-       struct ofd_thread_info  *info;
        struct ost_lvb          *lvb;
-       struct lu_env            env;
        int                      rc = 0;
 
        ENTRY;
 
+       LASSERT(env);
+       info = ofd_info(env);
        LASSERT(res != NULL);
 
        ofd = ldlm_res_to_ns(res)->ns_lvbp;
        LASSERT(ofd != NULL);
 
-       rc = lu_env_init(&env, LCT_DT_THREAD);
-       if (rc)
-               RETURN(rc);
-
-       info = ofd_info_init(&env, NULL);
        fid_extract_from_res_name(&info->fti_fid, &res->lr_name);
 
        lvb = res->lr_lvb_data;
        if (lvb == NULL) {
                CERROR("%s: no LVB data for "DFID"\n",
                       ofd_name(ofd), PFID(&info->fti_fid));
-               GOTO(out_env, rc = 0);
+               GOTO(out, rc = 0);
        }
 
        /* Update the LVB from the network message */
@@ -244,31 +238,31 @@ static int ofd_lvbo_update(struct ldlm_resource *res,
                lock_res(res);
                if (rpc_lvb->lvb_size > lvb->lvb_size || !increase_only) {
                        CDEBUG(D_DLMTRACE, "res: "DFID" updating lvb size: "
-                              LPU64" -> "LPU64"\n", PFID(&info->fti_fid),
+                              "%llu -> %llu\n", PFID(&info->fti_fid),
                               lvb->lvb_size, rpc_lvb->lvb_size);
                        lvb->lvb_size = rpc_lvb->lvb_size;
                }
                if (rpc_lvb->lvb_mtime > lvb->lvb_mtime || !increase_only) {
                        CDEBUG(D_DLMTRACE, "res: "DFID" updating lvb mtime: "
-                              LPU64" -> "LPU64"\n", PFID(&info->fti_fid),
+                              "%llu -> %llu\n", PFID(&info->fti_fid),
                               lvb->lvb_mtime, rpc_lvb->lvb_mtime);
                        lvb->lvb_mtime = rpc_lvb->lvb_mtime;
                }
                if (rpc_lvb->lvb_atime > lvb->lvb_atime || !increase_only) {
                        CDEBUG(D_DLMTRACE, "res: "DFID" updating lvb atime: "
-                              LPU64" -> "LPU64"\n", PFID(&info->fti_fid),
+                              "%llu -> %llu\n", PFID(&info->fti_fid),
                               lvb->lvb_atime, rpc_lvb->lvb_atime);
                        lvb->lvb_atime = rpc_lvb->lvb_atime;
                }
                if (rpc_lvb->lvb_ctime > lvb->lvb_ctime || !increase_only) {
                        CDEBUG(D_DLMTRACE, "res: "DFID" updating lvb ctime: "
-                              LPU64" -> "LPU64"\n", PFID(&info->fti_fid),
+                              "%llu -> %llu\n", PFID(&info->fti_fid),
                               lvb->lvb_ctime, rpc_lvb->lvb_ctime);
                        lvb->lvb_ctime = rpc_lvb->lvb_ctime;
                }
                if (rpc_lvb->lvb_blocks > lvb->lvb_blocks || !increase_only) {
                        CDEBUG(D_DLMTRACE, "res: "DFID" updating lvb blocks: "
-                              LPU64" -> "LPU64"\n", PFID(&info->fti_fid),
+                              "%llu -> %llu\n", PFID(&info->fti_fid),
                               lvb->lvb_blocks, rpc_lvb->lvb_blocks);
                        lvb->lvb_blocks = rpc_lvb->lvb_blocks;
                }
@@ -279,52 +273,51 @@ disk_update:
        /* Update the LVB from the disk inode */
        ost_fid_from_resid(&info->fti_fid, &res->lr_name,
                           ofd->ofd_lut.lut_lsd.lsd_osd_index);
-       fo = ofd_object_find(&env, ofd, &info->fti_fid);
+       fo = ofd_object_find(env, ofd, &info->fti_fid);
        if (IS_ERR(fo))
-               GOTO(out_env, rc = PTR_ERR(fo));
+               GOTO(out, rc = PTR_ERR(fo));
 
-       rc = ofd_attr_get(&env, fo, &info->fti_attr);
+       rc = ofd_attr_get(env, fo, &info->fti_attr);
        if (rc)
                GOTO(out_obj, rc);
 
        lock_res(res);
        if (info->fti_attr.la_size > lvb->lvb_size || !increase_only) {
                CDEBUG(D_DLMTRACE, "res: "DFID" updating lvb size from disk: "
-                      LPU64" -> %llu\n", PFID(&info->fti_fid),
+                      "%llu -> %llu\n", PFID(&info->fti_fid),
                       lvb->lvb_size, info->fti_attr.la_size);
                lvb->lvb_size = info->fti_attr.la_size;
        }
 
        if (info->fti_attr.la_mtime >lvb->lvb_mtime || !increase_only) {
                CDEBUG(D_DLMTRACE, "res: "DFID" updating lvb mtime from disk: "
-                      LPU64" -> "LPU64"\n", PFID(&info->fti_fid),
+                      "%llu -> %llu\n", PFID(&info->fti_fid),
                       lvb->lvb_mtime, info->fti_attr.la_mtime);
                lvb->lvb_mtime = info->fti_attr.la_mtime;
        }
        if (info->fti_attr.la_atime >lvb->lvb_atime || !increase_only) {
                CDEBUG(D_DLMTRACE, "res: "DFID" updating lvb atime from disk: "
-                      LPU64" -> "LPU64"\n", PFID(&info->fti_fid),
+                      "%llu -> %llu\n", PFID(&info->fti_fid),
                       lvb->lvb_atime, info->fti_attr.la_atime);
                lvb->lvb_atime = info->fti_attr.la_atime;
        }
        if (info->fti_attr.la_ctime >lvb->lvb_ctime || !increase_only) {
                CDEBUG(D_DLMTRACE, "res: "DFID" updating lvb ctime from disk: "
-                      LPU64" -> "LPU64"\n", PFID(&info->fti_fid),
+                      "%llu -> %llu\n", PFID(&info->fti_fid),
                       lvb->lvb_ctime, info->fti_attr.la_ctime);
                lvb->lvb_ctime = info->fti_attr.la_ctime;
        }
        if (info->fti_attr.la_blocks > lvb->lvb_blocks || !increase_only) {
                CDEBUG(D_DLMTRACE, "res: "DFID" updating lvb blocks from disk: "
-                      LPU64" -> %llu\n", PFID(&info->fti_fid), lvb->lvb_blocks,
+                      "%llu -> %llu\n", PFID(&info->fti_fid), lvb->lvb_blocks,
                       (unsigned long long)info->fti_attr.la_blocks);
                lvb->lvb_blocks = info->fti_attr.la_blocks;
        }
        unlock_res(res);
 
 out_obj:
-       ofd_object_put(&env, fo);
-out_env:
-       lu_env_fini(&env);
+       ofd_object_put(env, fo);
+out:
        return rc;
 }
 
@@ -352,13 +345,15 @@ static int ofd_lvbo_size(struct ldlm_lock *lock)
  *
  * This function is called to fill the given RPC buffer \a buf with LVB data
  *
+ * \param[in] env      execution environment
  * \param[in] lock     LDLM lock
  * \param[in] buf      RPC buffer to fill
  * \param[in] buflen   buffer length
  *
  * \retval             size of LVB data written into \a buf buffer
  */
-static int ofd_lvbo_fill(struct ldlm_lock *lock, void *buf, int buflen)
+static int ofd_lvbo_fill(const struct lu_env *env, struct ldlm_lock *lock,
+                        void *buf, int *buflen)
 {
        struct ldlm_resource *res = lock->l_resource;
        int lvb_len;
@@ -370,8 +365,8 @@ static int ofd_lvbo_fill(struct ldlm_lock *lock, void *buf, int buflen)
        lvb_len = ofd_lvbo_size(lock);
        LASSERT(lvb_len <= res->lr_lvb_len);
 
-       if (lvb_len > buflen)
-               lvb_len = buflen;
+       if (lvb_len > *buflen)
+               lvb_len = *buflen;
 
        lock_res(res);
        memcpy(buf, res->lr_lvb_data, lvb_len);