Whamcloud - gitweb
LU-3843 clio: add debug message in osc_completion()
[fs/lustre-release.git] / lustre / osc / osc_cache.c
index 4e7c535..4cabaca 100644 (file)
@@ -120,7 +120,7 @@ static const char *oes_strings[] = {
                /* ----- part 2 ----- */                                      \
                __ext->oe_grants, __ext->oe_nr_pages,                         \
                list_empty_marker(&__ext->oe_pages),                          \
-               cfs_waitq_active(&__ext->oe_waitq) ? '+' : '-',               \
+               waitqueue_active(&__ext->oe_waitq) ? '+' : '-',               \
                __ext->oe_osclock, __ext->oe_mppr, __ext->oe_owner,           \
                /* ----- part 4 ----- */                                      \
                ## __VA_ARGS__);                                              \
@@ -302,7 +302,7 @@ static void osc_extent_state_set(struct osc_extent *ext, int state)
 
        /* TODO: validate the state machine */
        ext->oe_state = state;
-       cfs_waitq_broadcast(&ext->oe_waitq);
+       wake_up_all(&ext->oe_waitq);
 }
 
 static struct osc_extent *osc_extent_alloc(struct osc_object *obj)
@@ -320,7 +320,7 @@ static struct osc_extent *osc_extent_alloc(struct osc_object *obj)
        CFS_INIT_LIST_HEAD(&ext->oe_link);
        ext->oe_state = OES_INV;
        CFS_INIT_LIST_HEAD(&ext->oe_pages);
-       cfs_waitq_init(&ext->oe_waitq);
+       init_waitqueue_head(&ext->oe_waitq);
        ext->oe_osclock = NULL;
 
        return ext;
@@ -896,7 +896,7 @@ static int osc_extent_wait(const struct lu_env *env, struct osc_extent *ext,
                        "%s: wait ext to %d timedout, recovery in progress?\n",
                        osc_export(obj)->exp_obd->obd_name, state);
 
-               lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL);
+               lwi = LWI_INTR(NULL, NULL);
                rc = l_wait_event(ext->oe_waitq, extent_wait_cb(ext, state),
                                  &lwi);
        }
@@ -964,7 +964,7 @@ static int osc_extent_truncate(struct osc_extent *ext, pgoff_t trunc_index,
                cfs_list_del_init(&oap->oap_pending_item);
 
                cl_page_get(page);
-               lu_ref_add(&page->cp_reference, "truncate", cfs_current());
+               lu_ref_add(&page->cp_reference, "truncate", current);
 
                if (cl_page_own(env, io, page) == 0) {
                        cl_page_unmap(env, io, page);
@@ -975,7 +975,7 @@ static int osc_extent_truncate(struct osc_extent *ext, pgoff_t trunc_index,
                        LASSERT(0);
                }
 
-               lu_ref_del(&page->cp_reference, "truncate", cfs_current());
+               lu_ref_del(&page->cp_reference, "truncate", current);
                cl_page_put(env, page);
 
                --ext->oe_nr_pages;
@@ -1079,7 +1079,9 @@ static int osc_extent_make_ready(const struct lu_env *env,
                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);
+               spin_lock(&last->oap_lock);
                last->oap_async_flags |= ASYNC_COUNT_STABLE;
+               spin_unlock(&last->oap_lock);
        }
 
        /* for the rest of pages, we don't need to call osf_refresh_count()
@@ -1087,7 +1089,9 @@ static int osc_extent_make_ready(const struct lu_env *env,
        cfs_list_for_each_entry(oap, &ext->oe_pages, oap_pending_item) {
                if (!(oap->oap_async_flags & ASYNC_COUNT_STABLE)) {
                        oap->oap_count = PAGE_CACHE_SIZE - oap->oap_page_off;
+                       spin_lock(&oap->oap_lock);
                        oap->oap_async_flags |= ASYNC_COUNT_STABLE;
+                       spin_unlock(&oap->oap_lock);
                }
        }
 
@@ -1259,8 +1263,10 @@ static int osc_completion(const struct lu_env *env, struct osc_async_page *oap,
        ENTRY;
 
        cmd &= ~OBD_BRW_NOQUOTA;
-       LASSERT(equi(page->cp_state == CPS_PAGEIN,  cmd == OBD_BRW_READ));
-       LASSERT(equi(page->cp_state == CPS_PAGEOUT, cmd == OBD_BRW_WRITE));
+       LASSERTF(equi(page->cp_state == CPS_PAGEIN,  cmd == OBD_BRW_READ),
+                "cp_state:%u, cmd:%d\n", page->cp_state, cmd);
+       LASSERTF(equi(page->cp_state == CPS_PAGEOUT, cmd == OBD_BRW_WRITE),
+               "cp_state:%u, cmd:%d\n", page->cp_state, cmd);
        LASSERT(opg->ops_transfer_pinned);
 
        /*
@@ -1309,15 +1315,19 @@ static int osc_completion(const struct lu_env *env, struct osc_async_page *oap,
        RETURN(0);
 }
 
-#define OSC_DUMP_GRANT(cli, fmt, args...) do {                               \
+#define OSC_DUMP_GRANT(lvl, cli, fmt, args...) do {                          \
        struct client_obd *__tmp = (cli);                                     \
-       CDEBUG(D_CACHE, "%s: { dirty: %ld/%ld dirty_pages: %d/%d "            \
-              "dropped: %ld avail: %ld, reserved: %ld, flight: %d } " fmt,   \
+       CDEBUG(lvl, "%s: grant { dirty: %ld/%ld dirty_pages: %d/%d "          \
+              "dropped: %ld avail: %ld, reserved: %ld, flight: %d } "        \
+              "lru {in list: %d, left: %d, waiters: %d }" fmt,               \
               __tmp->cl_import->imp_obd->obd_name,                           \
               __tmp->cl_dirty, __tmp->cl_dirty_max,                          \
               cfs_atomic_read(&obd_dirty_pages), obd_max_dirty_pages,        \
               __tmp->cl_lost_grant, __tmp->cl_avail_grant,                   \
-              __tmp->cl_reserved_grant, __tmp->cl_w_in_flight, ##args);      \
+              __tmp->cl_reserved_grant, __tmp->cl_w_in_flight,               \
+              cfs_atomic_read(&__tmp->cl_lru_in_list),                       \
+              cfs_atomic_read(&__tmp->cl_lru_busy),                          \
+              cfs_atomic_read(&__tmp->cl_lru_shrinkers), ##args);            \
 } while (0)
 
 /* caller must hold loi_list_lock */
@@ -1458,7 +1468,7 @@ static int osc_enter_cache_try(struct client_obd *cli,
 {
        int rc;
 
-       OSC_DUMP_GRANT(cli, "need:%d.\n", bytes);
+       OSC_DUMP_GRANT(D_CACHE, cli, "need:%d.\n", bytes);
 
        rc = osc_reserve_grant(cli, bytes);
        if (rc < 0)
@@ -1502,11 +1512,12 @@ static int osc_enter_cache(const struct lu_env *env, struct client_obd *cli,
        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_INTR(LWI_ON_SIGNAL_NOOP, NULL);
+       struct l_wait_info lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(600), NULL,
+                                                 LWI_ON_SIGNAL_NOOP, NULL);
        int rc = -EDQUOT;
        ENTRY;
 
-       OSC_DUMP_GRANT(cli, "need:%d.\n", bytes);
+       OSC_DUMP_GRANT(D_CACHE, cli, "need:%d.\n", bytes);
 
        client_obd_list_lock(&cli->cl_loi_list_lock);
 
@@ -1527,7 +1538,7 @@ static int osc_enter_cache(const struct lu_env *env, struct client_obd *cli,
         * RPC size will be.
         * The exiting condition is no avail grants and no dirty pages caching,
         * that really means there is no space on the OST. */
-       cfs_waitq_init(&ocw.ocw_waitq);
+       init_waitqueue_head(&ocw.ocw_waitq);
        ocw.ocw_oap   = oap;
        ocw.ocw_grant = bytes;
        while (cli->cl_dirty > 0 || cli->cl_w_in_flight > 0) {
@@ -1544,8 +1555,26 @@ static int osc_enter_cache(const struct lu_env *env, struct client_obd *cli,
 
                client_obd_list_lock(&cli->cl_loi_list_lock);
 
-               /* l_wait_event is interrupted by signal */
+               /* 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;
+                       }
                        cfs_list_del_init(&ocw.ocw_entry);
                        GOTO(out, rc);
                }
@@ -1561,7 +1590,7 @@ static int osc_enter_cache(const struct lu_env *env, struct client_obd *cli,
        EXIT;
 out:
        client_obd_list_unlock(&cli->cl_loi_list_lock);
-       OSC_DUMP_GRANT(cli, "returned %d.\n", rc);
+       OSC_DUMP_GRANT(D_CACHE, cli, "returned %d.\n", rc);
        RETURN(rc);
 }
 
@@ -1595,7 +1624,7 @@ 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);
 
-               cfs_waitq_signal(&ocw->ocw_waitq);
+               wake_up(&ocw->ocw_waitq);
        }
 
        EXIT;
@@ -1805,7 +1834,7 @@ static int try_to_add_extent_for_io(struct client_obd *cli,
                RETURN(0);
 
        cfs_list_for_each_entry(tmp, rpclist, oe_link) {
-               EASSERT(tmp->oe_owner == cfs_current(), tmp);
+               EASSERT(tmp->oe_owner == current, tmp);
 #if 0
                if (overlapped(tmp, ext)) {
                        OSC_EXTENT_DUMP(D_ERROR, tmp, "overlapped %p.\n", ext);
@@ -1823,7 +1852,7 @@ static int try_to_add_extent_for_io(struct client_obd *cli,
 
        *pc += ext->oe_nr_pages;
        cfs_list_move_tail(&ext->oe_link, rpclist);
-       ext->oe_owner = cfs_current();
+       ext->oe_owner = current;
        RETURN(1);
 }
 
@@ -2076,7 +2105,7 @@ static void osc_check_rpcs(const struct lu_env *env, struct client_obd *cli,
                cl_object_get(obj);
                client_obd_list_unlock(&cli->cl_loi_list_lock);
                lu_object_ref_add_at(&obj->co_lu, &link, "check",
-                                    cfs_current());
+                                    current);
 
                /* attempt some read/write balancing by alternating between
                 * reads and writes in an object.  The makes_rpc checks here
@@ -2118,7 +2147,7 @@ static void osc_check_rpcs(const struct lu_env *env, struct client_obd *cli,
 
                osc_list_maint(cli, osc);
                lu_object_ref_del_at(&obj->co_lu, &link, "check",
-                                    cfs_current());
+                                    current);
                cl_object_put(env, obj);
 
                client_obd_list_lock(&cli->cl_loi_list_lock);
@@ -2250,6 +2279,8 @@ int osc_queue_async_io(const struct lu_env *env, struct cl_io *io,
        oap->oap_cmd = cmd;
        oap->oap_page_off = ops->ops_from;
        oap->oap_count = ops->ops_to - ops->ops_from;
+       /* No need to hold a lock here,
+        * since this page is not in any list yet. */
        oap->oap_async_flags = 0;
        oap->oap_brw_flags = brw_flags;
 
@@ -2850,7 +2881,7 @@ int osc_cache_writeback_range(const struct lu_env *env, struct osc_object *obj,
                                EASSERT(ext->oe_start >= start &&
                                        ext->oe_max_end <= end, ext);
                                osc_extent_state_set(ext, OES_LOCKING);
-                               ext->oe_owner = cfs_current();
+                               ext->oe_owner = current;
                                cfs_list_move_tail(&ext->oe_link,
                                                   &discard_list);
                                osc_update_pending(obj, OBD_BRW_WRITE,
@@ -2911,7 +2942,7 @@ int osc_cache_writeback_range(const struct lu_env *env, struct osc_object *obj,
                        result = rc;
        }
 
-       OSC_IO_DEBUG(obj, "cache page out.\n");
+       OSC_IO_DEBUG(obj, "pageout [%lu, %lu], %d.\n", start, end, result);
        RETURN(result);
 }