Whamcloud - gitweb
LU-3692 api: More flexible logging API.
[fs/lustre-release.git] / lustre / ofd / ofd_dev.c
index 4c2fec3..b7d5348 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, Intel Corporation.
+ * Copyright (c) 2012, 2013, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 #include <obd_class.h>
 #include <lustre_param.h>
 #include <lustre_fid.h>
+#include <lustre_lfsck.h>
 
 #include "ofd_internal.h"
 
 /* Slab for OFD object allocation */
-static cfs_mem_cache_t *ofd_object_kmem;
+static struct kmem_cache *ofd_object_kmem;
 
 static struct lu_kmem_descr ofd_caches[] = {
        {
@@ -313,7 +314,7 @@ static struct lu_object *ofd_object_alloc(const struct lu_env *env,
 
        ENTRY;
 
-       OBD_SLAB_ALLOC_PTR_GFP(of, ofd_object_kmem, CFS_ALLOC_IO);
+       OBD_SLAB_ALLOC_PTR_GFP(of, ofd_object_kmem, __GFP_IO);
        if (of != NULL) {
                struct lu_object        *o;
                struct lu_object_header *h;
@@ -335,11 +336,12 @@ extern int ost_handle(struct ptlrpc_request *req);
 static int ofd_prepare(const struct lu_env *env, struct lu_device *pdev,
                       struct lu_device *dev)
 {
-       struct ofd_thread_info *info;
-       struct ofd_device       *ofd = ofd_dev(dev);
-       struct obd_device       *obd = ofd_obd(ofd);
-       struct lu_device        *next = &ofd->ofd_osd->dd_lu_dev;
-       int                      rc;
+       struct ofd_thread_info          *info;
+       struct ofd_device               *ofd = ofd_dev(dev);
+       struct obd_device               *obd = ofd_obd(ofd);
+       struct lu_device                *next = &ofd->ofd_osd->dd_lu_dev;
+       struct lfsck_start_param         lsp;
+       int                              rc;
 
        ENTRY;
 
@@ -355,6 +357,24 @@ static int ofd_prepare(const struct lu_env *env, struct lu_device *pdev,
 
        /* initialize lower device */
        rc = next->ld_ops->ldo_prepare(env, dev, next);
+       if (rc != 0)
+               RETURN(rc);
+
+       rc = lfsck_register(env, ofd->ofd_osd, &ofd->ofd_dt_dev, false);
+       if (rc != 0) {
+               CERROR("%s: failed to initialize lfsck: rc = %d\n",
+                      obd->obd_name, rc);
+               RETURN(rc);
+       }
+
+       lsp.lsp_start = NULL;
+       lsp.lsp_namespace = ofd->ofd_namespace;
+       rc = lfsck_start(env, ofd->ofd_osd, &lsp);
+       if (rc != 0) {
+               CWARN("%s: auto trigger paused LFSCK failed: rc = %d\n",
+                     obd->obd_name, rc);
+               rc = 0;
+       }
 
        target_recovery_init(&ofd->ofd_lut, ost_handle);
        LASSERT(obd->obd_no_conn);
@@ -373,17 +393,17 @@ static int ofd_recovery_complete(const struct lu_env *env,
 {
        struct ofd_device       *ofd = ofd_dev(dev);
        struct lu_device        *next = &ofd->ofd_osd->dd_lu_dev;
-       int                      rc = 0;
+       int                      rc = 0, max_precreate;
 
        ENTRY;
 
        /* Grant space for object precreation on the self export.
-        * This initial reserved space (i.e. 20MB for zfs and 560KB for ldiskfs)
-        * is enough to create 20k objects. It is then adapted based on the
-        * precreate request size (see ofd_grant_create()
+        * This initial reserved space (i.e. 10MB for zfs and 280KB for ldiskfs)
+        * is enough to create 10k objects. More space is then acquired for
+        * precreation in ofd_grant_create().
         */
-       ofd_grant_connect(env, dev->ld_obd->obd_self_export,
-                         OST_MAX_PRECREATE * ofd->ofd_dt_conf.ddp_inodespace,
+       max_precreate = OST_MAX_PRECREATE * ofd->ofd_dt_conf.ddp_inodespace / 2;
+       ofd_grant_connect(env, dev->ld_obd->obd_self_export, max_precreate,
                          false);
        rc = next->ld_ops->ldo_recovery_complete(env, next);
        RETURN(rc);
@@ -428,6 +448,8 @@ static int ofd_procfs_init(struct ofd_device *ofd)
        lprocfs_counter_init(obd->obd_stats, LPROC_OFD_WRITE_BYTES,
                             LPROCFS_CNTR_AVGMINMAX, "write_bytes", "bytes");
 
+       obd->obd_uses_nid_stats = 1;
+
        entry = lprocfs_register("exports", obd->obd_proc_entry, NULL, NULL);
        if (IS_ERR(entry)) {
                rc = PTR_ERR(entry);
@@ -553,7 +575,7 @@ int ofd_fid_init(const struct lu_env *env, struct ofd_device *ofd)
 
        OBD_ALLOC_PTR(ss->ss_client_seq);
        if (ss->ss_client_seq == NULL)
-               GOTO(out_free, -ENOMEM);
+               GOTO(out_free, rc = -ENOMEM);
 
        snprintf(name, strlen(obd_name) + 6, "%p-super", obd_name);
        rc = seq_client_init(ss->ss_client_seq, NULL, LUSTRE_SEQ_DATA,
@@ -590,6 +612,22 @@ out_free:
        return rc;
 }
 
+static struct tgt_opc_slice ofd_common_slice[] = {
+       {
+               .tos_opc_start = UPDATE_OBJ,
+               .tos_opc_end   = UPDATE_LAST_OPC,
+               .tos_hs        = tgt_out_handlers
+       },
+       {
+               .tos_opc_start  = SEQ_FIRST_OPC,
+               .tos_opc_end    = SEQ_LAST_OPC,
+               .tos_hs         = seq_handlers
+       },
+       {
+               .tos_hs         = NULL
+       }
+};
+
 static int ofd_init0(const struct lu_env *env, struct ofd_device *m,
                     struct lu_device_type *ldt, struct lustre_cfg *cfg)
 {
@@ -728,7 +766,9 @@ static int ofd_init0(const struct lu_env *env, struct ofd_device *m,
        m->ofd_grant_ratio =
                ofd_grant_ratio_conv(m->ofd_dt_conf.ddp_grant_reserved);
 
-       rc = tgt_init(env, &m->ofd_lut, obd, m->ofd_osd);
+       rc = tgt_init(env, &m->ofd_lut, obd, m->ofd_osd, ofd_common_slice,
+                     OBD_FAIL_OST_ALL_REQUEST_NET,
+                     OBD_FAIL_OST_ALL_REPLY_NET);
        if (rc)
                GOTO(err_free_ns, rc);
 
@@ -754,6 +794,8 @@ static void ofd_fini(const struct lu_env *env, struct ofd_device *m)
        struct obd_device *obd = ofd_obd(m);
        struct lu_device  *d = &m->ofd_dt_dev.dd_lu_dev;
 
+       lfsck_stop(env, m->ofd_osd, true);
+       lfsck_degister(env, m->ofd_osd);
        target_recovery_fini(obd);
        obd_exports_barrier(obd);
        obd_zombie_barrier();