Whamcloud - gitweb
LU-13811 client: don't panic for mgs evictions
[fs/lustre-release.git] / lustre / fid / fid_store.c
index bb5836b..e73e849 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
  */
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2013, Intel Corporation.
+ * Copyright (c) 2011, 2017, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
  *
  * lustre/fid/fid_store.c
  *
 #include <libcfs/libcfs.h>
 #include <dt_object.h>
 #include <obd_support.h>
-#include <lustre_capa.h>
 #include <lustre_fid.h>
 #include <lustre_fld.h>
 #include "fid_internal.h"
 
 static struct lu_buf *seq_store_buf(struct seq_thread_info *info)
 {
-        struct lu_buf *buf;
+       struct lu_buf *buf;
 
-        buf = &info->sti_buf;
-        buf->lb_buf = &info->sti_space;
-        buf->lb_len = sizeof(info->sti_space);
-        return buf;
+       buf = &info->sti_buf;
+       buf->lb_buf = &info->sti_space;
+       buf->lb_len = sizeof(info->sti_space);
+       return buf;
 }
 
 struct seq_update_callback {
-        struct dt_txn_commit_cb suc_cb;
-        struct lu_server_seq   *suc_seq;
+       struct dt_txn_commit_cb suc_cb;
+       struct lu_server_seq   *suc_seq;
 };
 
 void seq_update_cb(struct lu_env *env, struct thandle *th,
@@ -70,7 +64,7 @@ void seq_update_cb(struct lu_env *env, struct thandle *th,
 {
        struct seq_update_callback *ccb;
 
-       ccb = container_of0(cb, struct seq_update_callback, suc_cb);
+       ccb = container_of(cb, struct seq_update_callback, suc_cb);
 
        LASSERT(ccb->suc_seq != NULL);
 
@@ -81,17 +75,17 @@ void seq_update_cb(struct lu_env *env, struct thandle *th,
 int seq_update_cb_add(struct thandle *th, struct lu_server_seq *seq)
 {
        struct seq_update_callback *ccb;
-       struct dt_txn_commit_cb    *dcb;
-       int                        rc;
+       struct dt_txn_commit_cb *dcb;
+       int rc;
 
        OBD_ALLOC_PTR(ccb);
-       if (ccb == NULL)
+       if (!ccb)
                return -ENOMEM;
 
-       ccb->suc_seq       = seq;
+       ccb->suc_seq = seq;
        seq->lss_need_sync = 1;
 
-       dcb            = &ccb->suc_cb;
+       dcb = &ccb->suc_cb;
        dcb->dcb_func  = seq_update_cb;
        INIT_LIST_HEAD(&dcb->dcb_linkage);
        strlcpy(dcb->dcb_name, "seq_update_cb", sizeof(dcb->dcb_name));
@@ -104,7 +98,7 @@ int seq_update_cb_add(struct thandle *th, struct lu_server_seq *seq)
 
 /* This function implies that caller takes care about locking. */
 int seq_store_update(const struct lu_env *env, struct lu_server_seq *seq,
-                     struct lu_seq_range *out, int sync)
+                    struct lu_seq_range *out, int sync)
 {
        struct dt_device *dt_dev = lu2dt_dev(seq->lss_obj->do_lu.lo_dev);
        struct seq_thread_info *info;
@@ -112,6 +106,9 @@ int seq_store_update(const struct lu_env *env, struct lu_server_seq *seq,
        loff_t pos = 0;
        int rc;
 
+       if (dt_dev->dd_rdonly)
+               RETURN(0);
+
        info = lu_context_key_get(&env->le_ctx, &seq_thread_key);
        LASSERT(info != NULL);
 
@@ -127,7 +124,7 @@ int seq_store_update(const struct lu_env *env, struct lu_server_seq *seq,
        if (rc)
                GOTO(exit, rc);
 
-       if (out != NULL) {
+       if (out) {
                rc = fld_declare_server_create(env,
                                               seq->lss_site->ss_server_fld,
                                               out, th);
@@ -144,7 +141,7 @@ int seq_store_update(const struct lu_env *env, struct lu_server_seq *seq,
                CERROR("%s: Can't write space data, rc %d\n",
                       seq->lss_name, rc);
                GOTO(exit, rc);
-       } else if (out != NULL) {
+       } else if (out) {
                rc = fld_server_create(env, seq->lss_site->ss_server_fld, out,
                                       th);
                if (rc) {
@@ -153,8 +150,10 @@ int seq_store_update(const struct lu_env *env, struct lu_server_seq *seq,
                        GOTO(exit, rc);
                }
        }
-       /* next sequence update will need sync until this update is committed
-        * in case of sync operation this is not needed obviously */
+       /*
+        * next sequence update will need sync until this update is committed
+        * in case of sync operation this is not needed obviously
+        */
        if (!sync)
                /* if callback can't be added then sync always */
                sync = !!seq_update_cb_add(th, seq);
@@ -170,47 +169,45 @@ exit:
  * needed (init time).
  */
 int seq_store_read(struct lu_server_seq *seq,
-                   const struct lu_env *env)
+                  const struct lu_env *env)
 {
-        struct seq_thread_info *info;
-        loff_t pos = 0;
-        int rc;
-        ENTRY;
-
-        info = lu_context_key_get(&env->le_ctx, &seq_thread_key);
-        LASSERT(info != NULL);
-
-       rc = seq->lss_obj->do_body_ops->dbo_read(env, seq->lss_obj,
-                                                seq_store_buf(info),
-                                                &pos, BYPASS_CAPA);
-
-        if (rc == sizeof(info->sti_space)) {
-                range_le_to_cpu(&seq->lss_space, &info->sti_space);
-                CDEBUG(D_INFO, "%s: Space - "DRANGE"\n",
-                       seq->lss_name, PRANGE(&seq->lss_space));
-                rc = 0;
-        } else if (rc == 0) {
-                rc = -ENODATA;
+       struct seq_thread_info *info;
+       loff_t pos = 0;
+       int rc;
+       ENTRY;
+
+       info = lu_context_key_get(&env->le_ctx, &seq_thread_key);
+       LASSERT(info != NULL);
+
+       rc = dt_read(env, seq->lss_obj, seq_store_buf(info), &pos);
+
+       if (rc == sizeof(info->sti_space)) {
+               range_le_to_cpu(&seq->lss_space, &info->sti_space);
+               CDEBUG(D_INFO, "%s: Space - "DRANGE"\n",
+                      seq->lss_name, PRANGE(&seq->lss_space));
+               rc = 0;
+       } else if (rc == 0) {
+               rc = -ENODATA;
        } else if (rc > 0) {
-                CERROR("%s: Read only %d bytes of %d\n", seq->lss_name,
-                       rc, (int)sizeof(info->sti_space));
-                rc = -EIO;
-        }
+               CERROR("%s: Read only %d bytes of %d\n", seq->lss_name,
+                      rc, (int)sizeof(info->sti_space));
+               rc = -EIO;
+       }
 
-        RETURN(rc);
+       RETURN(rc);
 }
 
 int seq_store_init(struct lu_server_seq *seq,
-                   const struct lu_env *env,
-                   struct dt_device *dt)
+                  const struct lu_env *env,
+                  struct dt_device *dt)
 {
-        struct dt_object *dt_obj;
+       struct dt_object *dt_obj;
        struct lu_fid fid;
        struct lu_attr attr;
        struct dt_object_format dof;
-        const char *name;
-        int rc;
-        ENTRY;
+       const char *name;
+       int rc;
+       ENTRY;
 
        name = seq->lss_type == LUSTRE_SEQ_SERVER ?
                LUSTRE_SEQ_SRV_NAME : LUSTRE_SEQ_CTL_NAME;
@@ -226,28 +223,27 @@ int seq_store_init(struct lu_server_seq *seq,
        dof.dof_type = DFT_REGULAR;
 
        dt_obj = dt_find_or_create(env, dt, &fid, &dof, &attr);
-        if (!IS_ERR(dt_obj)) {
-                seq->lss_obj = dt_obj;
-                rc = 0;
-        } else {
-                CERROR("%s: Can't find \"%s\" obj %d\n",
-                       seq->lss_name, name, (int)PTR_ERR(dt_obj));
-                rc = PTR_ERR(dt_obj);
-        }
-
-        RETURN(rc);
+       if (!IS_ERR(dt_obj)) {
+               seq->lss_obj = dt_obj;
+               rc = 0;
+       } else {
+               CERROR("%s: Can't find \"%s\" obj %d\n",
+                      seq->lss_name, name, (int)PTR_ERR(dt_obj));
+               rc = PTR_ERR(dt_obj);
+       }
+
+       RETURN(rc);
 }
 
-void seq_store_fini(struct lu_server_seq *seq,
-                    const struct lu_env *env)
+void seq_store_fini(struct lu_server_seq *seq, const struct lu_env *env)
 {
-        ENTRY;
+       ENTRY;
 
-        if (seq->lss_obj != NULL) {
-                if (!IS_ERR(seq->lss_obj))
-                        lu_object_put(env, &seq->lss_obj->do_lu);
-                seq->lss_obj = NULL;
-        }
+       if (seq->lss_obj) {
+               if (!IS_ERR(seq->lss_obj))
+                       dt_object_put(env, seq->lss_obj);
+               seq->lss_obj = NULL;
+       }
 
-        EXIT;
+       EXIT;
 }