* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
- * Copyright (c) 2011, 2016, Intel Corporation.
+ * Copyright (c) 2011, 2017, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
#define DEBUG_SUBSYSTEM S_OSC
#include <lustre_obdo.h>
+#include <lustre_osc.h>
-#include "osc_cl_internal.h"
+#include "osc_internal.h"
-/** \addtogroup osc
- * @{
+/** \addtogroup osc
+ * @{
*/
/*****************************************************************************
*
- * Type conversions.
- *
- */
-
-static struct osc_io *cl2osc_io(const struct lu_env *env,
- const struct cl_io_slice *slice)
-{
- struct osc_io *oio = container_of0(slice, struct osc_io, oi_cl);
- LINVRNT(oio == osc_env_io(env));
- return oio;
-}
-
-/*****************************************************************************
- *
* io operations.
*
*/
{
}
-static void osc_read_ahead_release(const struct lu_env *env,
- void *cbdata)
+void osc_read_ahead_release(const struct lu_env *env, void *cbdata)
{
struct ldlm_lock *dlmlock = cbdata;
struct lustre_handle lockh;
ldlm_lock_decref(&lockh, LCK_PR);
LDLM_LOCK_PUT(dlmlock);
}
+EXPORT_SYMBOL(osc_read_ahead_release);
static int osc_io_read_ahead(const struct lu_env *env,
const struct cl_io_slice *ios,
* or, if page is already submitted, changes osc flags through
* osc_set_async_flags().
*/
-static int osc_io_submit(const struct lu_env *env,
- const struct cl_io_slice *ios,
- enum cl_req_type crt, struct cl_2queue *queue)
+int osc_io_submit(const struct lu_env *env, const struct cl_io_slice *ios,
+ enum cl_req_type crt, struct cl_2queue *queue)
{
struct cl_page *page;
struct cl_page *tmp;
struct cl_page_list *qout = &queue->c2_qout;
unsigned int queued = 0;
int result = 0;
- int cmd;
int brw_flags;
unsigned int max_pages;
cli = osc_cli(osc);
max_pages = cli->cl_max_pages_per_rpc;
- cmd = crt == CRT_WRITE ? OBD_BRW_WRITE : OBD_BRW_READ;
brw_flags = osc_io_srvlock(cl2osc_io(env, ios)) ? OBD_BRW_SRVLOCK : 0;
+ brw_flags |= crt == CRT_WRITE ? OBD_BRW_WRITE : OBD_BRW_READ;
+ if (crt == CRT_READ && ios->cis_io->ci_ndelay)
+ brw_flags |= OBD_BRW_NDELAY;
/*
* NOTE: here @page is a top-level page. This is done to avoid
if (++queued == max_pages) {
queued = 0;
- result = osc_queue_sync_pages(env, osc, &list, cmd,
+ result = osc_queue_sync_pages(env, io, osc, &list,
brw_flags);
if (result < 0)
break;
}
if (queued > 0)
- result = osc_queue_sync_pages(env, osc, &list, cmd, brw_flags);
+ result = osc_queue_sync_pages(env, io, osc, &list, brw_flags);
/* Update c/mtime for sync write. LU-7310 */
- if (qout->pl_nr > 0 && result == 0) {
+ if (crt == CRT_WRITE && qout->pl_nr > 0 && result == 0) {
struct cl_object *obj = ios->cis_obj;
struct cl_attr *attr = &osc_env_info(env)->oti_attr;
cl_object_attr_lock(obj);
- attr->cat_mtime = attr->cat_ctime = LTIME_S(CURRENT_TIME);
+ attr->cat_mtime = attr->cat_ctime = ktime_get_real_seconds();
cl_object_attr_update(env, obj, attr, CAT_MTIME | CAT_CTIME);
cl_object_attr_unlock(obj);
}
CDEBUG(D_INFO, "%d/%d %d\n", qin->pl_nr, qout->pl_nr, result);
return qout->pl_nr > 0 ? 0 : result;
}
+EXPORT_SYMBOL(osc_io_submit);
/**
- * This is called when a page is accessed within file in a way that creates
- * new page, if one were missing (i.e., if there were a hole at that place in
- * the file, or accessed page is beyond the current file size).
+ * This is called to update the attributes when modifying a specific page,
+ * both when making new pages and when doing updates to existing cached pages.
*
* Expand stripe KMS if necessary.
*/
-static void osc_page_touch_at(const struct lu_env *env,
- struct cl_object *obj, pgoff_t idx, size_t to)
+void osc_page_touch_at(const struct lu_env *env, struct cl_object *obj,
+ pgoff_t idx, size_t to)
{
- struct lov_oinfo *loi = cl2osc(obj)->oo_oinfo;
- struct cl_attr *attr = &osc_env_info(env)->oti_attr;
- int valid;
- __u64 kms;
+ struct lov_oinfo *loi = cl2osc(obj)->oo_oinfo;
+ struct cl_attr *attr = &osc_env_info(env)->oti_attr;
+ int valid;
+ __u64 kms;
+
+ ENTRY;
- /* offset within stripe */
- kms = cl_offset(obj, idx) + to;
+ /* offset within stripe */
+ kms = cl_offset(obj, idx) + to;
- cl_object_attr_lock(obj);
- /*
- * XXX old code used
- *
- * ll_inode_size_lock(inode, 0); lov_stripe_lock(lsm);
- *
- * here
- */
+ cl_object_attr_lock(obj);
CDEBUG(D_INODE, "stripe KMS %sincreasing %llu->%llu %llu\n",
- kms > loi->loi_kms ? "" : "not ", loi->loi_kms, kms,
- loi->loi_lvb.lvb_size);
+ kms > loi->loi_kms ? "" : "not ", loi->loi_kms, kms,
+ loi->loi_lvb.lvb_size);
- attr->cat_mtime = attr->cat_ctime = LTIME_S(CURRENT_TIME);
+ attr->cat_mtime = attr->cat_ctime = ktime_get_real_seconds();
valid = CAT_MTIME | CAT_CTIME;
if (kms > loi->loi_kms) {
attr->cat_kms = kms;
}
cl_object_attr_update(env, obj, attr, valid);
cl_object_attr_unlock(obj);
+
+ EXIT;
}
-static int osc_io_commit_async(const struct lu_env *env,
- const struct cl_io_slice *ios,
- struct cl_page_list *qin, int from, int to,
- cl_commit_cbt cb)
+int osc_io_commit_async(const struct lu_env *env,
+ const struct cl_io_slice *ios,
+ struct cl_page_list *qin, int from, int to,
+ cl_commit_cbt cb)
{
struct cl_io *io = ios->cis_io;
struct osc_io *oio = cl2osc_io(env, ios);
opg = osc_cl_page_osc(page, osc);
oap = &opg->ops_oap;
+ LASSERTF(osc == oap->oap_obj,
+ "obj mismatch: %p / %p\n", osc, oap->oap_obj);
+
if (!list_empty(&oap->oap_rpc_item)) {
CDEBUG(D_CACHE, "Busy oap %p page %p for submit.\n",
oap, opg);
CDEBUG(D_INFO, "%d %d\n", qin->pl_nr, result);
RETURN(result);
}
+EXPORT_SYMBOL(osc_io_commit_async);
-static int osc_io_iter_init(const struct lu_env *env,
- const struct cl_io_slice *ios)
+int osc_io_iter_init(const struct lu_env *env, const struct cl_io_slice *ios)
{
struct osc_object *osc = cl2osc(ios->cis_obj);
struct obd_import *imp = osc_cli(osc)->cl_import;
return rc;
}
+EXPORT_SYMBOL(osc_io_iter_init);
-static int osc_io_write_iter_init(const struct lu_env *env,
- const struct cl_io_slice *ios)
+int osc_io_write_iter_init(const struct lu_env *env,
+ const struct cl_io_slice *ios)
{
struct cl_io *io = ios->cis_io;
struct osc_io *oio = osc_env_io(env);
if (cl_io_is_append(io))
RETURN(osc_io_iter_init(env, ios));
- npages = io->u.ci_rw.crw_count >> PAGE_SHIFT;
- if (io->u.ci_rw.crw_pos & ~PAGE_MASK)
+ npages = io->u.ci_rw.rw_range.cir_count >> PAGE_SHIFT;
+ if (io->u.ci_rw.rw_range.cir_pos & ~PAGE_MASK)
++npages;
oio->oi_lru_reserved = osc_lru_reserve(osc_cli(osc), npages);
RETURN(osc_io_iter_init(env, ios));
}
+EXPORT_SYMBOL(osc_io_write_iter_init);
-static void osc_io_iter_fini(const struct lu_env *env,
- const struct cl_io_slice *ios)
+void osc_io_iter_fini(const struct lu_env *env,
+ const struct cl_io_slice *ios)
{
struct osc_io *oio = osc_env_io(env);
wake_up_all(&osc->oo_io_waitq);
}
}
+EXPORT_SYMBOL(osc_io_iter_fini);
-static void osc_io_write_iter_fini(const struct lu_env *env,
- const struct cl_io_slice *ios)
+void osc_io_write_iter_fini(const struct lu_env *env,
+ const struct cl_io_slice *ios)
{
struct osc_io *oio = osc_env_io(env);
struct osc_object *osc = cl2osc(ios->cis_obj);
osc_io_iter_fini(env, ios);
}
+EXPORT_SYMBOL(osc_io_write_iter_fini);
-static int osc_io_fault_start(const struct lu_env *env,
- const struct cl_io_slice *ios)
+int osc_io_fault_start(const struct lu_env *env, const struct cl_io_slice *ios)
{
struct cl_io *io;
struct cl_fault_io *fio;
fio->ft_index, fio->ft_nob);
RETURN(0);
}
+EXPORT_SYMBOL(osc_io_fault_start);
+
static int osc_async_upcall(void *a, int rc)
{
__u64 size = io->u.ci_setattr.sa_attr.lvb_size;
unsigned int ia_valid = io->u.ci_setattr.sa_valid;
int result = 0;
+ ENTRY;
/* truncate cache dirty pages first */
if (cl_io_is_trunc(io))
oa->o_flags = OBD_FL_SRVLOCK;
oa->o_valid |= OBD_MD_FLFLAGS;
}
+
+ if (io->ci_layout_version > 0) {
+ /* verify layout version */
+ oa->o_valid |= OBD_MD_LAYOUT_VERSION;
+ oa->o_layout_version = io->ci_layout_version;
+ }
} else {
LASSERT(oio->oi_lockless == 0);
}
init_completion(&cbargs->opc_sync);
if (ia_valid & ATTR_SIZE)
- result = osc_punch_base(osc_export(cl2osc(obj)),
- oa, osc_async_upcall,
- cbargs, PTLRPCD_SET);
+ result = osc_punch_send(osc_export(cl2osc(obj)),
+ oa, osc_async_upcall, cbargs);
else
result = osc_setattr_async(osc_export(cl2osc(obj)),
oa, osc_async_upcall,
cbargs->opc_rpc_sent = result == 0;
}
- return result;
+ RETURN(result);
}
-static void osc_io_setattr_end(const struct lu_env *env,
- const struct cl_io_slice *slice)
+void osc_io_setattr_end(const struct lu_env *env,
+ const struct cl_io_slice *slice)
{
struct cl_io *io = slice->cis_io;
struct osc_io *oio = cl2osc_io(env, slice);
struct cl_object *obj = slice->cis_obj;
struct osc_async_cbargs *cbargs = &oio->oi_cbarg;
- int result = 0;
+ struct cl_attr *attr = &osc_env_info(env)->oti_attr;
+ struct obdo *oa = &oio->oi_oa;
+ unsigned int cl_valid = 0;
+ int result = 0;
if (cbargs->opc_rpc_sent) {
wait_for_completion(&cbargs->opc_sync);
result = io->ci_result = cbargs->opc_rc;
}
- if (result == 0) {
- if (oio->oi_lockless) {
- /* lockless truncate */
- struct osc_device *osd = lu2osc_dev(obj->co_lu.lo_dev);
-
- LASSERT(cl_io_is_trunc(io));
- /* XXX: Need a lock. */
- osd->od_stats.os_lockless_truncates++;
- }
- }
+
+ if (result == 0) {
+ if (oio->oi_lockless) {
+ /* lockless truncate */
+ struct osc_device *osd = lu2osc_dev(obj->co_lu.lo_dev);
+
+ LASSERT(cl_io_is_trunc(io));
+ /* XXX: Need a lock. */
+ osd->od_stats.os_lockless_truncates++;
+ }
+ }
if (cl_io_is_trunc(io)) {
__u64 size = io->u.ci_setattr.sa_attr.lvb_size;
+ cl_object_attr_lock(obj);
+ if (oa->o_valid & OBD_MD_FLBLOCKS) {
+ attr->cat_blocks = oa->o_blocks;
+ cl_valid |= CAT_BLOCKS;
+ }
+
+ cl_object_attr_update(env, obj, attr, cl_valid);
+ cl_object_attr_unlock(obj);
osc_trunc_check(env, io, oio, size);
osc_cache_truncate_end(env, oio->oi_trunc);
oio->oi_trunc = NULL;
}
}
+EXPORT_SYMBOL(osc_io_setattr_end);
struct osc_data_version_args {
struct osc_io *dva_oio;
if (cbargs->opc_rc != 0) {
slice->cis_io->ci_result = cbargs->opc_rc;
- } else if (!(oio->oi_oa.o_valid & OBD_MD_FLDATAVERSION)) {
- slice->cis_io->ci_result = -EOPNOTSUPP;
} else {
- dv->dv_data_version = oio->oi_oa.o_data_version;
slice->cis_io->ci_result = 0;
+ if (!(oio->oi_oa.o_valid &
+ (OBD_MD_LAYOUT_VERSION | OBD_MD_FLDATAVERSION)))
+ slice->cis_io->ci_result = -ENOTSUPP;
+
+ if (oio->oi_oa.o_valid & OBD_MD_LAYOUT_VERSION)
+ dv->dv_layout_version = oio->oi_oa.o_layout_version;
+ if (oio->oi_oa.o_valid & OBD_MD_FLDATAVERSION)
+ dv->dv_data_version = oio->oi_oa.o_data_version;
}
EXIT;
}
-static int osc_io_read_start(const struct lu_env *env,
- const struct cl_io_slice *slice)
+int osc_io_read_start(const struct lu_env *env,
+ const struct cl_io_slice *slice)
{
struct cl_object *obj = slice->cis_obj;
struct cl_attr *attr = &osc_env_info(env)->oti_attr;
RETURN(rc);
}
+EXPORT_SYMBOL(osc_io_read_start);
-static int osc_io_write_start(const struct lu_env *env,
- const struct cl_io_slice *slice)
+int osc_io_write_start(const struct lu_env *env,
+ const struct cl_io_slice *slice)
{
struct cl_object *obj = slice->cis_obj;
struct cl_attr *attr = &osc_env_info(env)->oti_attr;
RETURN(rc);
}
+EXPORT_SYMBOL(osc_io_write_start);
-static int osc_fsync_ost(const struct lu_env *env, struct osc_object *obj,
- struct cl_fsync_io *fio)
+int osc_fsync_ost(const struct lu_env *env, struct osc_object *obj,
+ struct cl_fsync_io *fio)
{
struct osc_io *oio = osc_env_io(env);
struct obdo *oa = &oio->oi_oa;
rc = osc_sync_base(obj, oa, osc_async_upcall, cbargs, PTLRPCD_SET);
RETURN(rc);
}
+EXPORT_SYMBOL(osc_fsync_ost);
-static int osc_io_fsync_start(const struct lu_env *env,
- const struct cl_io_slice *slice)
+int osc_io_fsync_start(const struct lu_env *env,
+ const struct cl_io_slice *slice)
{
struct cl_io *io = slice->cis_io;
struct cl_fsync_io *fio = &io->u.ci_fsync;
RETURN(result);
}
-static void osc_io_fsync_end(const struct lu_env *env,
- const struct cl_io_slice *slice)
+void osc_io_fsync_end(const struct lu_env *env,
+ const struct cl_io_slice *slice)
{
struct cl_fsync_io *fio = &slice->cis_io->u.ci_fsync;
struct cl_object *obj = slice->cis_obj;
}
slice->cis_io->ci_result = result;
}
+EXPORT_SYMBOL(osc_io_fsync_end);
static int osc_io_ladvise_start(const struct lu_env *env,
const struct cl_io_slice *slice)
slice->cis_io->ci_result = result;
}
-static void osc_io_end(const struct lu_env *env,
- const struct cl_io_slice *slice)
+void osc_io_end(const struct lu_env *env, const struct cl_io_slice *slice)
{
struct osc_io *oio = cl2osc_io(env, slice);
oio->oi_active = NULL;
}
}
+EXPORT_SYMBOL(osc_io_end);
static const struct cl_io_operations osc_io_ops = {
.op = {