Whamcloud - gitweb
LU-5521 grant: quiet message on grant waiting timeout
[fs/lustre-release.git] / lustre / osc / osc_cache.c
index f2bad36..99a18dc 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, 2013, Intel Corporation.
+ * Copyright (c) 2012, 2014, Intel Corporation.
  *
  */
 /*
@@ -48,7 +48,7 @@ static int extent_debug; /* set it to be true for more debug */
 
 static void osc_update_pending(struct osc_object *obj, int cmd, int delta);
 static int osc_extent_wait(const struct lu_env *env, struct osc_extent *ext,
-                          int state);
+                          enum osc_extent_state state);
 static void osc_ap_completion(const struct lu_env *env, struct client_obd *cli,
                              struct osc_async_page *oap, int sent, int rc);
 static int osc_make_ready(const struct lu_env *env, struct osc_async_page *oap,
@@ -181,7 +181,7 @@ static int osc_extent_sanity_check0(struct osc_extent *ext,
 {
        struct osc_object *obj = ext->oe_obj;
        struct osc_async_page *oap;
-       int page_count;
+       size_t page_count;
        int rc = 0;
 
        if (!osc_object_is_locked(obj))
@@ -596,9 +596,9 @@ static inline int overlapped(struct osc_extent *ex1, struct osc_extent *ex2)
  * Find or create an extent which includes @index, core function to manage
  * extent tree.
  */
-struct osc_extent *osc_extent_find(const struct lu_env *env,
-                                  struct osc_object *obj, pgoff_t index,
-                                  int *grants)
+static struct osc_extent *osc_extent_find(const struct lu_env *env,
+                                         struct osc_object *obj, pgoff_t index,
+                                         unsigned int *grants)
 {
        struct client_obd *cli = osc_cli(obj);
        struct osc_lock   *olck;
@@ -609,10 +609,10 @@ struct osc_extent *osc_extent_find(const struct lu_env *env,
        struct osc_extent *found = NULL;
        pgoff_t    chunk;
        pgoff_t    max_end;
-       int        max_pages; /* max_pages_per_rpc */
-       int        chunksize;
+       unsigned int max_pages; /* max_pages_per_rpc */
+       unsigned int chunksize;
        int        ppc_bits; /* pages per chunk bits */
-       int        chunk_mask;
+       pgoff_t    chunk_mask;
        int        rc;
        ENTRY;
 
@@ -667,8 +667,8 @@ restart:
        if (ext == NULL)
                ext = first_extent(obj);
        while (ext != NULL) {
-               loff_t ext_chk_start = ext->oe_start >> ppc_bits;
-               loff_t ext_chk_end   = ext->oe_end   >> ppc_bits;
+               pgoff_t ext_chk_start = ext->oe_start >> ppc_bits;
+               pgoff_t ext_chk_end   = ext->oe_end   >> ppc_bits;
 
                LASSERT(sanity_check_nolock(ext) == 0);
                if (chunk > ext_chk_end + 1)
@@ -871,7 +871,7 @@ int osc_extent_finish(const struct lu_env *env, struct osc_extent *ext,
        RETURN(0);
 }
 
-static int extent_wait_cb(struct osc_extent *ext, int state)
+static int extent_wait_cb(struct osc_extent *ext, enum osc_extent_state state)
 {
        int ret;
 
@@ -886,7 +886,7 @@ static int extent_wait_cb(struct osc_extent *ext, int state)
  * Wait for the extent's state to become @state.
  */
 static int osc_extent_wait(const struct lu_env *env, struct osc_extent *ext,
-                          int state)
+                          enum osc_extent_state state)
 {
        struct osc_object *obj = ext->oe_obj;
        struct l_wait_info lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(600), NULL,
@@ -915,7 +915,7 @@ static int osc_extent_wait(const struct lu_env *env, struct osc_extent *ext,
        rc = l_wait_event(ext->oe_waitq, extent_wait_cb(ext, state), &lwi);
        if (rc == -ETIMEDOUT) {
                OSC_EXTENT_DUMP(D_ERROR, ext,
-                       "%s: wait ext to %d timedout, recovery in progress?\n",
+                       "%s: wait ext to %u timedout, recovery in progress?\n",
                        osc_export(obj)->exp_obd->obd_name, state);
 
                lwi = LWI_INTR(NULL, NULL);
@@ -1056,7 +1056,7 @@ static int osc_extent_make_ready(const struct lu_env *env,
        struct osc_async_page *oap;
        struct osc_async_page *last = NULL;
        struct osc_object *obj = ext->oe_obj;
-       int page_count = 0;
+       unsigned int page_count = 0;
        int rc;
        ENTRY;
 
@@ -1097,9 +1097,10 @@ static int osc_extent_make_ready(const struct lu_env *env,
        /* the last page is the only one we need to refresh its count by
         * the size of file. */
        if (!(last->oap_async_flags & ASYNC_COUNT_STABLE)) {
-               last->oap_count = osc_refresh_count(env, last, OBD_BRW_WRITE);
-               LASSERT(last->oap_count > 0);
-               LASSERT(last->oap_page_off + last->oap_count <= PAGE_CACHE_SIZE);
+               int last_oap_count = osc_refresh_count(env, last, OBD_BRW_WRITE);
+               LASSERT(last_oap_count > 0);
+               LASSERT(last->oap_page_off + last_oap_count <= PAGE_CACHE_SIZE);
+               last->oap_count = last_oap_count;
                spin_lock(&last->oap_lock);
                last->oap_async_flags |= ASYNC_COUNT_STABLE;
                spin_unlock(&last->oap_lock);
@@ -1130,7 +1131,8 @@ static int osc_extent_make_ready(const struct lu_env *env,
  * called to expand the extent for the same IO. To expand the extent, the
  * page index must be in the same or next chunk of ext->oe_end.
  */
-static int osc_extent_expand(struct osc_extent *ext, pgoff_t index, int *grants)
+static int osc_extent_expand(struct osc_extent *ext, pgoff_t index,
+                            unsigned int *grants)
 {
        struct osc_object *obj = ext->oe_obj;
        struct client_obd *cli = osc_cli(obj);
@@ -1139,7 +1141,7 @@ static int osc_extent_expand(struct osc_extent *ext, pgoff_t index, int *grants)
        pgoff_t chunk = index >> ppc_bits;
        pgoff_t end_chunk;
        pgoff_t end_index;
-       int chunksize = 1 << cli->cl_chunkbits;
+       unsigned int chunksize = 1 << cli->cl_chunkbits;
        int rc = 0;
        ENTRY;
 
@@ -1316,7 +1318,7 @@ static int osc_completion(const struct lu_env *env, struct osc_async_page *oap,
        if (rc == 0 && srvlock) {
                struct lu_device *ld    = opg->ops_cl.cpl_obj->co_lu.lo_dev;
                struct osc_stats *stats = &lu2osc_dev(ld)->od_stats;
-               int bytes = oap->oap_count;
+               size_t bytes = oap->oap_count;
 
                if (crt == CRT_READ)
                        stats->os_lockless_reads += bytes;
@@ -1423,8 +1425,8 @@ static void __osc_unreserve_grant(struct client_obd *cli,
        }
 }
 
-void osc_unreserve_grant(struct client_obd *cli,
-                        unsigned int reserved, unsigned int unused)
+static void osc_unreserve_grant(struct client_obd *cli,
+                               unsigned int reserved, unsigned int unused)
 {
        spin_lock(&cli->cl_loi_list_lock);
        __osc_unreserve_grant(cli, reserved, unused);
@@ -1449,7 +1451,7 @@ void osc_unreserve_grant(struct client_obd *cli,
 static void osc_free_grant(struct client_obd *cli, unsigned int nr_pages,
                           unsigned int lost_grant)
 {
-       int grant = (1 << cli->cl_chunkbits) + cli->cl_extent_tax;
+       unsigned long grant = (1 << cli->cl_chunkbits) + cli->cl_extent_tax;
 
        spin_lock(&cli->cl_loi_list_lock);
        atomic_long_sub(nr_pages, &obd_dirty_pages);
@@ -1489,7 +1491,7 @@ static int osc_enter_cache_try(struct client_obd *cli,
 {
        int rc;
 
-       OSC_DUMP_GRANT(D_CACHE, cli, "need:%d.\n", bytes);
+       OSC_DUMP_GRANT(D_CACHE, cli, "need:%d\n", bytes);
 
        rc = osc_reserve_grant(cli, bytes);
        if (rc < 0)
@@ -1530,15 +1532,17 @@ static int ocw_granted(struct client_obd *cli, struct osc_cache_waiter *ocw)
 static int osc_enter_cache(const struct lu_env *env, struct client_obd *cli,
                           struct osc_async_page *oap, int bytes)
 {
-       struct osc_object *osc = oap->oap_obj;
-       struct lov_oinfo  *loi = osc->oo_oinfo;
-       struct osc_cache_waiter ocw;
-       struct l_wait_info lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(600), NULL,
-                                                 LWI_ON_SIGNAL_NOOP, NULL);
-       int rc = -EDQUOT;
+       struct osc_object       *osc = oap->oap_obj;
+       struct lov_oinfo        *loi = osc->oo_oinfo;
+       struct osc_cache_waiter  ocw;
+       struct l_wait_info       lwi;
+       int                      rc = -EDQUOT;
        ENTRY;
 
-       OSC_DUMP_GRANT(D_CACHE, cli, "need:%d.\n", bytes);
+       lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(AT_OFF ? obd_timeout : at_max),
+                              NULL, LWI_ON_SIGNAL_NOOP, NULL);
+
+       OSC_DUMP_GRANT(D_CACHE, cli, "need:%d\n", bytes);
 
        spin_lock(&cli->cl_loi_list_lock);
 
@@ -1546,12 +1550,16 @@ static int osc_enter_cache(const struct lu_env *env, struct client_obd *cli,
         * of queued writes and create a discontiguous rpc stream */
        if (OBD_FAIL_CHECK(OBD_FAIL_OSC_NO_GRANT) ||
            cli->cl_dirty_max_pages == 0 ||
-           cli->cl_ar.ar_force_sync || loi->loi_ar.ar_force_sync)
+           cli->cl_ar.ar_force_sync || loi->loi_ar.ar_force_sync) {
+               OSC_DUMP_GRANT(D_CACHE, cli, "forced sync i/o\n");
                GOTO(out, rc = -EDQUOT);
+       }
 
        /* Hopefully normal case - cache space and write credits available */
-       if (osc_enter_cache_try(cli, oap, bytes, 0))
+       if (osc_enter_cache_try(cli, oap, bytes, 0)) {
+               OSC_DUMP_GRANT(D_CACHE, cli, "granted from cache\n");
                GOTO(out, rc = 0);
+       }
 
        /* We can get here for two reasons: too many dirty pages in cache, or
         * run out of grants. In both cases we should write dirty pages out.
@@ -1576,42 +1584,51 @@ static int osc_enter_cache(const struct lu_env *env, struct client_obd *cli,
 
                spin_lock(&cli->cl_loi_list_lock);
 
-               /* l_wait_event is interrupted by signal, or timed out */
                if (rc < 0) {
-                       switch (rc) {
-                       case -ETIMEDOUT:
-                               OSC_DUMP_GRANT(D_ERROR, cli,
-                                               "try to reserve %d.\n", bytes);
-                               osc_extent_tree_dump(D_ERROR, osc);
-                               rc = -EDQUOT;
-                               break;
-                       case -EINTR:
-                               /* Ensures restartability - LU-3581 */
-                               rc = -ERESTARTSYS;
-                               break;
-                       default:
-                               CDEBUG(D_CACHE, "%s: event for cache space @"
-                                      " %p never arrived due to %d\n",
-                                      cli->cl_import->imp_obd->obd_name,
-                                      &ocw, rc);
-                               break;
-                       }
+                       /* l_wait_event is interrupted by signal or timed out */
                        list_del_init(&ocw.ocw_entry);
-                       GOTO(out, rc);
+                       break;
                }
-
                LASSERT(list_empty(&ocw.ocw_entry));
                rc = ocw.ocw_rc;
 
                if (rc != -EDQUOT)
-                       GOTO(out, rc);
-               if (osc_enter_cache_try(cli, oap, bytes, 0))
-                       GOTO(out, rc = 0);
+                       break;
+               if (osc_enter_cache_try(cli, oap, bytes, 0)) {
+                       rc = 0;
+                       break;
+               }
+       }
+
+       switch (rc) {
+       case 0:
+               OSC_DUMP_GRANT(D_CACHE, cli, "finally got grant space\n");
+               break;
+       case -ETIMEDOUT:
+               OSC_DUMP_GRANT(D_CACHE, cli,
+                              "timeout, fall back to sync i/o\n");
+               osc_extent_tree_dump(D_CACHE, osc);
+               /* fall back to synchronous I/O */
+               rc = -EDQUOT;
+               break;
+       case -EINTR:
+               /* Ensures restartability - LU-3581 */
+               OSC_DUMP_GRANT(D_CACHE, cli, "interrupted\n");
+               rc = -ERESTARTSYS;
+               break;
+       case -EDQUOT:
+               OSC_DUMP_GRANT(D_CACHE, cli,
+                              "no grant space, fall back to sync i/o\n");
+               break;
+       default:
+               CDEBUG(D_CACHE, "%s: event for cache space @ %p never arrived "
+                      "due to %d, fall back to sync i/o\n",
+                      cli->cl_import->imp_obd->obd_name, &ocw, rc);
+               break;
        }
        EXIT;
 out:
        spin_unlock(&cli->cl_loi_list_lock);
-       OSC_DUMP_GRANT(D_CACHE, cli, "returned %d.\n", rc);
        RETURN(rc);
 }
 
@@ -1638,10 +1655,8 @@ void osc_wake_cache_waiters(struct client_obd *cli)
                        goto wakeup;
                }
 
-               ocw->ocw_rc = 0;
-               if (!osc_enter_cache_try(cli, ocw->ocw_oap, ocw->ocw_grant, 0))
-                       ocw->ocw_rc = -EDQUOT;
-
+               if (osc_enter_cache_try(cli, ocw->ocw_oap, ocw->ocw_grant, 0))
+                       ocw->ocw_rc = 0;
 wakeup:
                CDEBUG(D_CACHE, "wake up %p for oap %p, avail grant %ld, %d\n",
                       ocw, ocw->ocw_oap, cli->cl_avail_grant, ocw->ocw_rc);
@@ -1845,7 +1860,7 @@ static void osc_ap_completion(const struct lu_env *env, struct client_obd *cli,
 static int try_to_add_extent_for_io(struct client_obd *cli,
                                    struct osc_extent *ext,
                                    struct list_head *rpclist,
-                                   int *pc, unsigned int *max_pages)
+                                   unsigned int *pc, unsigned int *max_pages)
 {
        struct osc_extent *tmp;
        struct osc_async_page *oap = list_first_entry(&ext->oe_pages,
@@ -1904,11 +1919,12 @@ static int try_to_add_extent_for_io(struct client_obd *cli,
  * 5. Traverse the extent tree from the 1st extent;
  * 6. Above steps exit if there is no space in this RPC.
  */
-static int get_write_extents(struct osc_object *obj, struct list_head *rpclist)
+static unsigned int get_write_extents(struct osc_object *obj,
+                                     struct list_head *rpclist)
 {
        struct client_obd *cli = osc_cli(obj);
        struct osc_extent *ext;
-       int page_count = 0;
+       unsigned int page_count = 0;
        unsigned int max_pages = cli->cl_max_pages_per_rpc;
 
        LASSERT(osc_object_is_locked(obj));
@@ -1975,7 +1991,7 @@ __must_hold(osc)
        struct osc_extent *ext;
        struct osc_extent *tmp;
        struct osc_extent *first = NULL;
-       obd_count page_count = 0;
+       unsigned int page_count = 0;
        int srvlock = 0;
        int rc = 0;
        ENTRY;
@@ -2048,7 +2064,7 @@ __must_hold(osc)
        struct osc_extent *ext;
        struct osc_extent *next;
        struct list_head rpclist = LIST_HEAD_INIT(rpclist);
-       int page_count = 0;
+       unsigned int page_count = 0;
        unsigned int max_pages = cli->cl_max_pages_per_rpc;
        int rc = 0;
        ENTRY;
@@ -2266,7 +2282,8 @@ int osc_queue_async_io(const struct lu_env *env, struct cl_io *io,
        struct client_obd     *cli = oap->oap_cli;
        struct osc_object     *osc = oap->oap_obj;
        pgoff_t index;
-       int    grants = 0;
+       unsigned int tmp;
+       unsigned int grants = 0;
        int    brw_flags = OBD_BRW_ASYNC;
        int    cmd = OBD_BRW_WRITE;
        int    need_release = 0;
@@ -2347,7 +2364,7 @@ int osc_queue_async_io(const struct lu_env *env, struct cl_io *io,
                        grants = 0;
                        need_release = 1;
                } else if (ext->oe_end < index) {
-                       int tmp = grants;
+                       tmp = grants;
                        /* try to expand this extent */
                        rc = osc_extent_expand(ext, index, &tmp);
                        if (rc < 0) {
@@ -2372,7 +2389,7 @@ int osc_queue_async_io(const struct lu_env *env, struct cl_io *io,
        }
 
        if (ext == NULL) {
-               int tmp = (1 << cli->cl_chunkbits) + cli->cl_extent_tax;
+               tmp = (1 << cli->cl_chunkbits) + cli->cl_extent_tax;
 
                /* try to find new extent to cover this page */
                LASSERT(oio->oi_active == NULL);