RETURN(0);
}
+static int extent_wait_cb(struct osc_extent *ext, int state)
+{
+ int ret;
+
+ osc_object_lock(ext->oe_obj);
+ ret = ext->oe_state == state;
+ osc_object_unlock(ext->oe_obj);
+
+ return ret;
+}
+
/**
* Wait for the extent's state to become @state.
*/
int state)
{
struct osc_object *obj = ext->oe_obj;
- 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 = 0;
ENTRY;
osc_extent_release(env, ext);
/* wait for the extent until its state becomes @state */
- rc = l_wait_event(ext->oe_waitq, ext->oe_state == state, &lwi);
+ 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",
+ osc_export(obj)->exp_obd->obd_name, state);
+
+ lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL);
+ rc = l_wait_event(ext->oe_waitq, extent_wait_cb(ext, state),
+ &lwi);
+ }
if (rc == 0 && ext->oe_rc < 0)
rc = ext->oe_rc;
RETURN(rc);
* Discard pages with index greater than @size. If @ext is overlapped with
* @size, then partial truncate happens.
*/
-static int osc_extent_truncate(struct osc_extent *ext, pgoff_t trunc_index)
+static int osc_extent_truncate(struct osc_extent *ext, pgoff_t trunc_index,
+ bool partial)
{
struct cl_env_nest nest;
struct lu_env *env;
/* only discard the pages with their index greater than
* trunc_index, and ... */
- if (sub->cp_index < trunc_index) {
+ if (sub->cp_index < trunc_index ||
+ (sub->cp_index == trunc_index && partial)) {
/* accounting how many pages remaining in the chunk
* so that we can calculate grants correctly. */
if (sub->cp_index >> ppc_bits == trunc_chunk)
--ext->oe_nr_pages;
++nr_pages;
}
- EASSERTF(ergo(ext->oe_start >= trunc_index, ext->oe_nr_pages == 0),
- ext, "trunc_index %lu\n", trunc_index);
+ EASSERTF(ergo(ext->oe_start >= trunc_index + !!partial,
+ ext->oe_nr_pages == 0),
+ ext, "trunc_index %lu, partial %d\n", trunc_index, partial);
osc_object_lock(obj);
if (ext->oe_nr_pages == 0) {
struct cl_page *cp = ops->ops_cl.cpl_page;
pgoff_t index = cp->cp_index;
struct osc_async_page *oap = &ops->ops_oap;
- int unplug = 0;
+ bool unplug = false;
int rc = 0;
ENTRY;
OSC_EXTENT_DUMP(D_CACHE, ext,
"flush page %p make it urgent.\n", oap);
cfs_list_add_tail(&ext->oe_link, &obj->oo_urgent_exts);
- unplug = 1;
+ unplug = true;
}
rc = 0;
EXIT;
pgoff_t index;
CFS_LIST_HEAD(list);
int result = 0;
+ bool partial;
ENTRY;
/* pages with index greater or equal to index will be truncated. */
- index = cl_index(osc2cl(obj), size + CFS_PAGE_SIZE - 1);
+ index = cl_index(osc2cl(obj), size);
+ partial = size > cl_offset(osc2cl(obj), index);
again:
osc_object_lock(obj);
if (ext->oe_state != OES_TRUNC)
osc_extent_wait(env, ext, OES_TRUNC);
- rc = osc_extent_truncate(ext, index);
+ rc = osc_extent_truncate(ext, index, partial);
if (rc < 0) {
if (result == 0)
result = rc;
/* this must be an overlapped extent which means only
* part of pages in this extent have been truncated.
*/
- EASSERTF(ext->oe_start < index, ext,
- "trunc index = %lu.\n", index);
+ EASSERTF(ext->oe_start <= index, ext,
+ "trunc index = %lu/%d.\n", index, partial);
/* fix index to skip this partially truncated extent */
index = ext->oe_end + 1;
+ partial = false;
/* we need to hold this extent in OES_TRUNC state so
* that no writeback will happen. This is to avoid
oio->oi_trunc = NULL;
if (ext != NULL) {
+ bool unplug = false;
+
EASSERT(ext->oe_nr_pages > 0, ext);
EASSERT(ext->oe_state == OES_TRUNC, ext);
EASSERT(!ext->oe_urgent, ext);
if (ext->oe_fsync_wait && !ext->oe_urgent) {
ext->oe_urgent = 1;
cfs_list_move_tail(&ext->oe_link, &obj->oo_urgent_exts);
+ unplug = true;
}
osc_update_pending(obj, OBD_BRW_WRITE, ext->oe_nr_pages);
osc_object_unlock(obj);
osc_extent_put(env, ext);
- osc_list_maint(osc_cli(obj), obj);
+ if (unplug)
+ osc_io_unplug_async(env, osc_cli(obj), obj);
}
}
* The caller must have called osc_cache_writeback_range() to issue IO
* otherwise it will take a long time for this function to finish.
*
- * Caller must hold inode_mutex and i_alloc_sem, or cancel exclusive
- * dlm lock so that nobody else can dirty this range of file while we're
- * waiting for extents to be written.
+ * Caller must hold inode_mutex , or cancel exclusive dlm lock so that
+ * nobody else can dirty this range of file while we're waiting for
+ * extents to be written.
*/
int osc_cache_wait_range(const struct lu_env *env, struct osc_object *obj,
pgoff_t start, pgoff_t end)
{
struct osc_extent *ext;
CFS_LIST_HEAD(discard_list);
- int unplug = 0;
+ bool unplug = false;
int result = 0;
ENTRY;
}
if (list != NULL) {
cfs_list_move_tail(&ext->oe_link, list);
- unplug = 1;
+ unplug = true;
}
} else {
/* the only discarder is lock cancelling, so