* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
- * Copyright (c) 2011, 2014, Intel Corporation.
+ * Copyright (c) 2011, 2015, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
{
struct osc_object *osc = lu2osc(obj);
const struct cl_object_conf *cconf = lu2cl_conf(conf);
- int i;
osc->oo_oinfo = cconf->u.coc_oinfo;
#ifdef CONFIG_LUSTRE_DEBUG_EXPENSIVE_CHECK
mutex_init(&osc->oo_debug_mutex);
#endif
- spin_lock_init(&osc->oo_seatbelt);
- for (i = 0; i < CRT_NR; ++i)
- INIT_LIST_HEAD(&osc->oo_inflight[i]);
-
INIT_LIST_HEAD(&osc->oo_ready_item);
INIT_LIST_HEAD(&osc->oo_hp_ready_item);
INIT_LIST_HEAD(&osc->oo_write_item);
spin_lock_init(&osc->oo_ol_spin);
INIT_LIST_HEAD(&osc->oo_ol_list);
+ atomic_set(&osc->oo_nr_ios, 0);
+ init_waitqueue_head(&osc->oo_io_waitq);
+
cl_object_page_init(lu2cl(obj), sizeof(struct osc_page));
return 0;
static void osc_object_free(const struct lu_env *env, struct lu_object *obj)
{
struct osc_object *osc = lu2osc(obj);
- int i;
-
- for (i = 0; i < CRT_NR; ++i)
- LASSERT(list_empty(&osc->oo_inflight[i]));
LASSERT(list_empty(&osc->oo_ready_item));
LASSERT(list_empty(&osc->oo_hp_ready_item));
LASSERT(atomic_read(&osc->oo_nr_reads) == 0);
LASSERT(atomic_read(&osc->oo_nr_writes) == 0);
LASSERT(list_empty(&osc->oo_ol_list));
+ LASSERT(atomic_read(&osc->oo_nr_ios) == 0);
lu_object_fini(obj);
OBD_SLAB_FREE_PTR(osc, osc_object_kmem);
struct osc_object *osc = cl2osc(obj);
struct ldlm_res_id *resname = &osc_env_info(env)->oti_resname;
- LASSERTF(osc->oo_npages == 0,
- DFID "still have %lu pages, obj: %p, osc: %p\n",
- PFID(lu_object_fid(&obj->co_lu)), osc->oo_npages, obj, osc);
-
/* DLM locks don't hold a reference of osc_object so we have to
* clear it before the object is being destroyed. */
ostid_build_res_name(&osc->oo_oinfo->loi_oi, resname);
struct ll_fiemap_info_key *fmkey,
struct fiemap *fiemap, size_t *buflen)
{
- struct obd_export *exp = osc_export(cl2osc(obj));
- struct ldlm_res_id resid;
- ldlm_policy_data_t policy;
- struct lustre_handle lockh;
- ldlm_mode_t mode = 0;
- struct ptlrpc_request *req;
- struct fiemap *reply;
- char *tmp;
- int rc;
+ struct obd_export *exp = osc_export(cl2osc(obj));
+ struct ldlm_res_id resid;
+ union ldlm_policy_data policy;
+ struct lustre_handle lockh;
+ enum ldlm_mode mode = LCK_MINMODE;
+ struct ptlrpc_request *req;
+ struct fiemap *reply;
+ char *tmp;
+ int rc;
ENTRY;
- fmkey->oa.o_oi = cl2osc(obj)->oo_oinfo->loi_oi;
- if (!(fmkey->fiemap.fm_flags & FIEMAP_FLAG_SYNC))
+ fmkey->lfik_oa.o_oi = cl2osc(obj)->oo_oinfo->loi_oi;
+ if (!(fmkey->lfik_fiemap.fm_flags & FIEMAP_FLAG_SYNC))
goto skip_locking;
- policy.l_extent.start = fmkey->fiemap.fm_start & PAGE_CACHE_MASK;
+ policy.l_extent.start = fmkey->lfik_fiemap.fm_start & PAGE_CACHE_MASK;
- if (OBD_OBJECT_EOF - fmkey->fiemap.fm_length <=
- fmkey->fiemap.fm_start + PAGE_CACHE_SIZE - 1)
+ if (OBD_OBJECT_EOF - fmkey->lfik_fiemap.fm_length <=
+ fmkey->lfik_fiemap.fm_start + PAGE_CACHE_SIZE - 1)
policy.l_extent.end = OBD_OBJECT_EOF;
else
- policy.l_extent.end = (fmkey->fiemap.fm_start +
- fmkey->fiemap.fm_length +
+ policy.l_extent.end = (fmkey->lfik_fiemap.fm_start +
+ fmkey->lfik_fiemap.fm_length +
PAGE_CACHE_SIZE - 1) & PAGE_CACHE_MASK;
- ostid_build_res_name(&fmkey->oa.o_oi, &resid);
+ ostid_build_res_name(&fmkey->lfik_oa.o_oi, &resid);
mode = ldlm_lock_match(exp->exp_obd->obd_namespace,
LDLM_FL_BLOCK_GRANTED | LDLM_FL_LVB_READY,
&resid, LDLM_EXTENT, &policy,
ldlm_lock_decref(&lockh, LCK_PW);
}
} else { /* no cached lock, needs acquire lock on server side */
- fmkey->oa.o_valid |= OBD_MD_FLFLAGS;
- fmkey->oa.o_flags |= OBD_FL_SRVLOCK;
+ fmkey->lfik_oa.o_valid |= OBD_MD_FLFLAGS;
+ fmkey->lfik_oa.o_flags |= OBD_FL_SRVLOCK;
}
skip_locking:
return 1;
}
+/**
+ * Implementation of struct cl_object_operations::coo_req_attr_set() for osc
+ * layer. osc is responsible for struct obdo::o_id and struct obdo::o_seq
+ * fields.
+ */
+static void osc_req_attr_set(const struct lu_env *env, struct cl_object *obj,
+ struct cl_req_attr *attr)
+{
+ struct lov_oinfo *oinfo;
+ struct obdo *oa;
+ struct ost_lvb *lvb;
+ u64 flags = attr->cra_flags;
+
+ oinfo = cl2osc(obj)->oo_oinfo;
+ lvb = &oinfo->loi_lvb;
+ oa = attr->cra_oa;
+
+ if ((flags & OBD_MD_FLMTIME) != 0) {
+ oa->o_mtime = lvb->lvb_mtime;
+ oa->o_valid |= OBD_MD_FLMTIME;
+ }
+ if ((flags & OBD_MD_FLATIME) != 0) {
+ oa->o_atime = lvb->lvb_atime;
+ oa->o_valid |= OBD_MD_FLATIME;
+ }
+ if ((flags & OBD_MD_FLCTIME) != 0) {
+ oa->o_ctime = lvb->lvb_ctime;
+ oa->o_valid |= OBD_MD_FLCTIME;
+ }
+ if (flags & OBD_MD_FLGROUP) {
+ ostid_set_seq(&oa->o_oi, ostid_seq(&oinfo->loi_oi));
+ oa->o_valid |= OBD_MD_FLGROUP;
+ }
+ if (flags & OBD_MD_FLID) {
+ ostid_set_id(&oa->o_oi, ostid_id(&oinfo->loi_oi));
+ oa->o_valid |= OBD_MD_FLID;
+ }
+ if (flags & OBD_MD_FLHANDLE) {
+ struct ldlm_lock *lock;
+ struct osc_page *opg;
+
+ opg = osc_cl_page_osc(attr->cra_page, cl2osc(obj));
+ lock = osc_dlmlock_at_pgoff(env, cl2osc(obj), osc_index(opg),
+ OSC_DAP_FL_TEST_LOCK | OSC_DAP_FL_CANCELING);
+ if (lock == NULL && !opg->ops_srvlock) {
+ struct ldlm_resource *res;
+ struct ldlm_res_id *resname;
+
+ CL_PAGE_DEBUG(D_ERROR, env, attr->cra_page,
+ "uncovered page!\n");
+
+ resname = &osc_env_info(env)->oti_resname;
+ ostid_build_res_name(&oinfo->loi_oi, resname);
+ res = ldlm_resource_get(
+ osc_export(cl2osc(obj))->exp_obd->obd_namespace,
+ NULL, resname, LDLM_EXTENT, 0);
+ ldlm_resource_dump(D_ERROR, res);
+
+ libcfs_debug_dumpstack(NULL);
+ LBUG();
+ }
+
+ /* check for lockless io. */
+ if (lock != NULL) {
+ oa->o_handle = lock->l_remote_handle;
+ oa->o_valid |= OBD_MD_FLHANDLE;
+ LDLM_LOCK_PUT(lock);
+ }
+ }
+}
+
static const struct cl_object_operations osc_ops = {
.coo_page_init = osc_page_init,
.coo_lock_init = osc_lock_init,
.coo_prune = osc_object_prune,
.coo_find_cbdata = osc_object_find_cbdata,
.coo_fiemap = osc_object_fiemap,
+ .coo_req_attr_set = osc_req_attr_set
};
static const struct lu_object_operations osc_lu_obj_ops = {
return obj;
}
+int osc_object_invalidate(const struct lu_env *env, struct osc_object *osc)
+{
+ struct l_wait_info lwi = { 0 };
+ ENTRY;
+
+ CDEBUG(D_INODE, "Invalidate osc object: %p, # of active IOs: %d\n",
+ osc, atomic_read(&osc->oo_nr_ios));
+
+ l_wait_event(osc->oo_io_waitq, atomic_read(&osc->oo_nr_ios) == 0, &lwi);
+
+ /* Discard all dirty pages of this object. */
+ osc_cache_truncate_start(env, osc, 0, NULL);
+
+ /* Discard all caching pages */
+ osc_lock_discard_pages(env, osc, 0, CL_PAGE_EOF, CLM_WRITE);
+
+ /* Clear ast data of dlm lock. Do this after discarding all pages */
+ osc_object_prune(env, osc2cl(osc));
+
+ RETURN(0);
+}
+
/** @} osc */