+ if (obd == NULL) {
+ CERROR("invalid client cookie "LPX64"\n",
+ exp->exp_handle.h_cookie);
+ return -EINVAL;
+ }
+ cobd_exp = cobd_get_exp(obd);
+ return obd_cancel(cobd_exp, ea, mode, lockh);
+}
+
+static int cobd_cancel_unused(struct obd_export *exp,
+ struct lov_stripe_md *ea, int flags,
+ void *opaque)
+{
+ struct obd_device *obd = class_exp2obd(exp);
+ struct obd_export *cobd_exp;
+
+ if (obd == NULL) {
+ CERROR("invalid client cookie "LPX64"\n",
+ exp->exp_handle.h_cookie);
+ return -EINVAL;
+ }
+ cobd_exp = cobd_get_exp(obd);
+ return obd_cancel_unused(cobd_exp, ea, flags, opaque);
+}
+
+static int cobd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
+ int objcount, struct obd_ioobj *obj,
+ int niocount, struct niobuf_remote *nb,
+ struct niobuf_local *res, struct obd_trans_info *oti)
+{
+ struct obd_device *obd = class_exp2obd(exp);
+ struct obd_export *cobd_exp;
+
+ if (obd == NULL) {
+ CERROR("invalid client cookie "LPX64"\n",
+ exp->exp_handle.h_cookie);
+ return -EINVAL;
+ }
+ cobd_exp = cobd_get_exp(obd);
+ return obd_preprw(cmd, cobd_exp, oa, objcount, obj, niocount, nb,
+ res, oti);
+}
+
+static int cobd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
+ int objcount, struct obd_ioobj *obj,
+ int niocount, struct niobuf_local *local,
+ struct obd_trans_info *oti, int rc)
+{
+ struct obd_device *obd = class_exp2obd(exp);
+ struct obd_export *cobd_exp;
+
+ if (obd == NULL) {
+ CERROR("invalid client cookie "LPX64"\n",
+ exp->exp_handle.h_cookie);
+ return -EINVAL;
+ }
+ cobd_exp = cobd_get_exp(obd);
+ return obd_commitrw(cmd, cobd_exp, oa, objcount, obj, niocount,
+ local, oti, rc);
+}
+
+static int cobd_flush(struct obd_device *obd)
+{
+ return 0;
+}
+
+static int cobd_iocontrol(unsigned int cmd, struct obd_export *exp,
+ int len, void *karg, void *uarg)
+{
+ struct obd_device *obd = class_exp2obd(exp);
+ struct cache_obd *cobd = &obd->u.cobd;
+ struct obd_export *cobd_exp;
+ int rc = 0;
+ ENTRY;
+
+ down(&cobd->sem);
+
+ switch (cmd) {
+ case OBD_IOC_COBD_CON:
+ if (!cobd->cache_on) {
+ struct lustre_handle conn = {0};
+
+ rc = client_obd_disconnect(obd, cobd->master_exp, 0);
+ rc = client_obd_connect(obd, cobd->cache_name, &conn,
+ NULL, 0);
+ if (rc)
+ GOTO(out, rc);
+ cobd->cache_exp = class_conn2export(&conn);
+ cobd->cache_on = 1;
+ }
+ break;
+ case OBD_IOC_COBD_COFF:
+ if (cobd->cache_on) {
+ struct lustre_handle conn = {0,};
+ struct obd_device *master = NULL;
+ struct obd_device *cache = NULL;
+ int easize, cooksize;
+
+ cache = class_exp2obd(cobd->cache_exp);
+ easize = cache->u.cli.cl_max_mds_easize;
+ cooksize = cache->u.cli.cl_max_mds_cookiesize;
+
+ rc = client_obd_disconnect(obd, cobd->cache_exp, 0);
+ rc = client_obd_connect(obd, cobd->master_name, &conn,
+ NULL, 0);
+ if (rc)
+ GOTO(out, rc);
+ cobd->master_exp = class_conn2export(&conn);
+
+ master = class_exp2obd(cobd->master_exp);
+ master->u.cli.cl_max_mds_easize = easize;
+ master->u.cli.cl_max_mds_cookiesize = cooksize;
+ cobd->cache_on = 0;
+ }
+ break;
+ case OBD_IOC_COBD_CFLUSH:
+ if (cobd->cache_on) {
+ cobd->cache_on = 0;
+ cobd_flush(obd);
+ } else {
+ CERROR("%s: cache is turned off\n", obd->obd_name);
+ }
+ break;
+ default:
+ cobd_exp = cobd_get_exp(obd);
+ rc = obd_iocontrol(cmd, cobd_exp, len, karg, uarg);
+ }
+
+ EXIT;
+out:
+ up(&cobd->sem);
+ return rc;
+}
+
+static int cobd_llog_init(struct obd_device *obd, struct obd_llogs *llogs,
+ struct obd_device *disk_obd, int count,
+ struct llog_catid *logid)
+{
+ struct obd_export *cobd_exp;
+ struct obd_device *cobd_obd;
+
+ cobd_exp = cobd_get_exp(obd);
+ cobd_obd = class_exp2obd(cobd_exp);
+
+ return obd_llog_init(cobd_obd, &cobd_obd->obd_llogs,
+ disk_obd, count, logid);
+}
+
+static int cobd_llog_finish(struct obd_device *obd, struct obd_llogs *llogs,
+ int count)
+{
+ struct obd_export *cobd_exp;
+ struct obd_device *cobd_obd;
+
+ cobd_exp = cobd_get_exp(obd);
+ cobd_obd = class_exp2obd(cobd_exp);
+
+ return obd_llog_finish(cobd_obd, &cobd_obd->obd_llogs, count);
+}
+
+static int cobd_notify(struct obd_device *obd, struct obd_device *watched,
+ int active, void *data)
+{
+ struct obd_export *cobd_exp;
+
+ cobd_exp = cobd_get_exp(obd);
+
+ return obd_notify(class_exp2obd(cobd_exp), watched, active, data);
+}
+
+static int cobd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
+ int type, struct obd_client_handle *handle, int flag)
+{
+ struct obd_device *obd = class_exp2obd(exp);
+ struct obd_export *cobd_exp;
+
+ if (obd == NULL) {
+ CERROR("invalid client cookie "LPX64"\n",
+ exp->exp_handle.h_cookie);
+ return -EINVAL;
+ }
+ cobd_exp = cobd_get_exp(obd);
+
+ return obd_pin(cobd_exp, ino, gen, type, handle, flag);
+}
+
+static int cobd_unpin(struct obd_export *exp,
+ struct obd_client_handle *handle, int flag)
+{
+ struct obd_device *obd = class_exp2obd(exp);
+ struct obd_export *cobd_exp;
+
+ if (obd == NULL) {
+ CERROR("invalid client cookie "LPX64"\n",
+ exp->exp_handle.h_cookie);
+ return -EINVAL;
+ }
+ cobd_exp = cobd_get_exp(obd);
+
+ return obd_unpin(cobd_exp, handle, flag);
+}
+
+static int cobd_init_ea_size(struct obd_export *exp, int easize, int cookiesize)
+{
+ struct obd_export *cobd_exp;
+
+ cobd_exp = cobd_get_exp(exp->exp_obd);
+ return obd_init_ea_size(cobd_exp, easize, cookiesize);
+}
+
+static int cobd_import_event(struct obd_device *obd,
+ struct obd_import *imp,
+ enum obd_import_event event)
+{
+ struct obd_export *cobd_exp;
+
+ cobd_exp = cobd_get_exp(obd);
+
+ obd_import_event(class_exp2obd(cobd_exp), imp, event);
+
+ return 0;
+}
+
+static int cobd_md_getattr(struct obd_export *exp, struct lustre_id *id,
+ __u64 valid, const char *ea_name, int ea_namelen,
+ unsigned int ea_size, struct ptlrpc_request **request)
+{
+ struct obd_device *obd = class_exp2obd(exp);
+ struct obd_export *cobd_exp;
+
+ if (obd == NULL) {
+ CERROR("invalid client cookie "LPX64"\n",
+ exp->exp_handle.h_cookie);
+ return -EINVAL;
+ }
+ cobd_exp = cobd_get_exp(obd);
+ return md_getattr(cobd_exp, id, valid, NULL, 0, ea_size, request);
+}
+
+static int cobd_md_req2lustre_md (struct obd_export *mdc_exp,
+ struct ptlrpc_request *req, unsigned int offset,
+ struct obd_export *osc_exp, struct lustre_md *md)
+{
+ struct obd_device *obd = class_exp2obd(mdc_exp);
+ struct obd_export *cobd_exp;
+
+ if (obd == NULL) {
+ CERROR("invalid client cookie "LPX64"\n",
+ mdc_exp->exp_handle.h_cookie);
+ return -EINVAL;
+ }
+ cobd_exp = cobd_get_exp(obd);
+ return md_req2lustre_md(cobd_exp, req, offset, osc_exp, md);
+}
+
+static int cobd_md_change_cbdata(struct obd_export *exp, struct lustre_id *id,
+ ldlm_iterator_t it, void *data)
+{
+ struct obd_device *obd = class_exp2obd(exp);
+ struct obd_export *cobd_exp;
+
+ if (obd == NULL) {
+ CERROR("invalid client cookie "LPX64"\n",
+ exp->exp_handle.h_cookie);
+ return -EINVAL;
+ }
+ cobd_exp = cobd_get_exp(obd);
+ return md_change_cbdata(cobd_exp, id, it, data);
+}
+
+static int cobd_md_getattr_lock(struct obd_export *exp, struct lustre_id *id,
+ char *filename, int namelen, __u64 valid,
+ unsigned int ea_size, struct ptlrpc_request **request)
+{
+ struct obd_device *obd = class_exp2obd(exp);
+ struct obd_export *cobd_exp;
+
+ if (obd == NULL) {
+ CERROR("invalid client cookie "LPX64"\n",
+ exp->exp_handle.h_cookie);
+ return -EINVAL;
+ }
+ cobd_exp = cobd_get_exp(obd);
+ return md_getattr_lock(cobd_exp, id, filename, namelen, valid,
+ ea_size, request);
+}
+
+static int cobd_md_create(struct obd_export *exp, struct mdc_op_data *op_data,
+ const void *data, int datalen, int mode,
+ __u32 uid, __u32 gid, __u64 rdev,
+ struct ptlrpc_request **request)
+{
+ struct obd_device *obd = class_exp2obd(exp);
+ struct obd_export *cobd_exp;
+
+ if (obd == NULL) {
+ CERROR("invalid client cookie "LPX64"\n",
+ exp->exp_handle.h_cookie);
+ return -EINVAL;
+ }
+ cobd_exp = cobd_get_exp(obd);
+ return md_create(cobd_exp, op_data, data, datalen, mode,
+ uid, gid, rdev, request);
+}
+
+static int cobd_md_unlink(struct obd_export *exp, struct mdc_op_data *data,
+ struct ptlrpc_request **request)
+{
+ struct obd_device *obd = class_exp2obd(exp);
+ struct obd_export *cobd_exp;
+
+ if (obd == NULL) {
+ CERROR("invalid client cookie "LPX64"\n",
+ exp->exp_handle.h_cookie);
+ return -EINVAL;
+ }
+ cobd_exp = cobd_get_exp(obd);
+ return md_unlink(cobd_exp, data, request);
+}
+
+static int cobd_md_valid_attrs(struct obd_export *exp,
+ struct lustre_id *id)
+{
+ struct obd_device *obd = class_exp2obd(exp);
+ struct obd_export *cobd_exp;
+
+ if (obd == NULL) {
+ CERROR("invalid client cookie "LPX64"\n",
+ exp->exp_handle.h_cookie);
+ return -EINVAL;
+ }
+ cobd_exp = cobd_get_exp(obd);
+ return md_valid_attrs(cobd_exp, id);
+}
+
+static int cobd_md_rename(struct obd_export *exp, struct mdc_op_data *data,
+ const char *old, int oldlen, const char *new,
+ int newlen, struct ptlrpc_request **request)
+{
+ struct obd_device *obd = class_exp2obd(exp);
+ struct obd_export *cobd_exp;
+
+ if (obd == NULL) {
+ CERROR("invalid client cookie "LPX64"\n",
+ exp->exp_handle.h_cookie);
+ return -EINVAL;
+ }
+ cobd_exp = cobd_get_exp(obd);
+ return md_rename(cobd_exp, data, old, oldlen, new, newlen, request);
+}
+
+static int cobd_md_link(struct obd_export *exp, struct mdc_op_data *data,
+ struct ptlrpc_request **request)
+{
+ struct obd_device *obd = class_exp2obd(exp);
+ struct obd_export *cobd_exp;
+
+ if (obd == NULL) {
+ CERROR("invalid client cookie "LPX64"\n",
+ exp->exp_handle.h_cookie);
+ return -EINVAL;
+ }
+ cobd_exp = cobd_get_exp(obd);
+ return md_link(cobd_exp, data, request);
+}
+
+static int cobd_md_setattr(struct obd_export *exp, struct mdc_op_data *data,
+ struct iattr *iattr, void *ea, int ealen, void *ea2,
+ int ea2len, struct ptlrpc_request **request)
+{
+ struct obd_device *obd = class_exp2obd(exp);
+ struct obd_export *cobd_exp;
+
+ if (obd == NULL) {
+ CERROR("invalid client cookie "LPX64"\n",
+ exp->exp_handle.h_cookie);
+ return -EINVAL;
+ }
+ cobd_exp = cobd_get_exp(obd);
+ return md_setattr(cobd_exp, data, iattr, ea, ealen, ea2, ea2len, request);
+}
+
+static int cobd_md_readpage(struct obd_export *exp,
+ struct lustre_id *mdc_id,
+ __u64 offset, struct page *page,
+ struct ptlrpc_request **request)
+{
+ struct obd_device *obd = class_exp2obd(exp);
+ struct obd_export *cobd_exp;
+
+ if (obd == NULL) {
+ CERROR("invalid client cookie "LPX64"\n",
+ exp->exp_handle.h_cookie);
+ return -EINVAL;
+ }
+ cobd_exp = cobd_get_exp(obd);
+ return md_readpage(cobd_exp, mdc_id, offset, page, request);
+}
+
+static int cobd_md_close(struct obd_export *exp, struct obdo *obdo,
+ struct obd_client_handle *och,
+ struct ptlrpc_request **request)
+{
+ struct obd_device *obd = class_exp2obd(exp);
+ struct obd_export *cobd_exp;
+
+ if (obd == NULL) {
+ CERROR("invalid client cookie "LPX64"\n",
+ exp->exp_handle.h_cookie);
+ return -EINVAL;
+ }
+ cobd_exp = cobd_get_exp(obd);
+ return md_close(cobd_exp, obdo, och, request);
+}
+
+static int cobd_md_done_writing(struct obd_export *exp, struct obdo *obdo)
+{
+ struct obd_device *obd = class_exp2obd(exp);
+ struct obd_export *cobd_exp;
+
+ if (obd == NULL) {
+ CERROR("invalid client cookie "LPX64"\n",
+ exp->exp_handle.h_cookie);
+ return -EINVAL;
+ }
+ cobd_exp = cobd_get_exp(obd);
+ return md_done_writing(cobd_exp, obdo);
+}
+
+static int cobd_md_sync(struct obd_export *exp, struct lustre_id *id,
+ struct ptlrpc_request **request)
+{
+ struct obd_device *obd = class_exp2obd(exp);
+ struct obd_export *cobd_exp;
+
+ if (obd == NULL) {
+ CERROR("invalid client cookie "LPX64"\n",
+ exp->exp_handle.h_cookie);
+ return -EINVAL;
+ }
+ cobd_exp = cobd_get_exp(obd);
+
+ return md_sync(cobd_exp, id, request);
+}
+
+static int cobd_md_set_open_replay_data(struct obd_export *exp,
+ struct obd_client_handle *och,
+ struct ptlrpc_request *open_req)
+{
+ struct obd_device *obd = class_exp2obd(exp);
+ struct obd_export *cobd_exp;
+
+ if (obd == NULL) {
+ CERROR("invalid client cookie "LPX64"\n",
+ exp->exp_handle.h_cookie);
+ return -EINVAL;
+ }
+ cobd_exp = cobd_get_exp(obd);
+
+ return md_set_open_replay_data(cobd_exp, och, open_req);
+}
+
+static int cobd_md_clear_open_replay_data(struct obd_export *exp,
+ struct obd_client_handle *och)
+{
+ struct obd_device *obd = class_exp2obd(exp);
+ struct obd_export *cobd_exp;
+
+ if (obd == NULL) {
+ CERROR("invalid client cookie "LPX64"\n",
+ exp->exp_handle.h_cookie);
+ return -EINVAL;
+ }
+ cobd_exp = cobd_get_exp(obd);
+
+ return md_clear_open_replay_data(cobd_exp, och);
+}
+
+static int cobd_md_store_inode_generation(struct obd_export *exp,
+ struct ptlrpc_request *req,
+ int reqoff, int repoff)
+{
+ struct obd_device *obd = class_exp2obd(exp);
+ struct obd_export *cobd_exp;
+
+ if (obd == NULL) {
+ CERROR("invalid client cookie "LPX64"\n",
+ exp->exp_handle.h_cookie);
+ return -EINVAL;
+ }
+ cobd_exp = cobd_get_exp(obd);
+
+ return md_store_inode_generation(cobd_exp, req, reqoff, repoff);
+}
+
+static int cobd_md_set_lock_data(struct obd_export *exp, __u64 *l, void *data)
+{
+ struct obd_device *obd = class_exp2obd(exp);
+ struct obd_export *cobd_exp;
+
+ if (obd == NULL) {
+ CERROR("invalid client cookie "LPX64"\n",
+ exp->exp_handle.h_cookie);
+ return -EINVAL;
+ }
+ cobd_exp = cobd_get_exp(obd);
+
+ return md_set_lock_data(cobd_exp, l, data);
+}
+
+static int cobd_md_enqueue(struct obd_export *exp, int lock_type,
+ struct lookup_intent *it, int lock_mode,
+ struct mdc_op_data *data, struct lustre_handle *lockh,
+ void *lmm, int lmmsize,
+ ldlm_completion_callback cb_completion,
+ ldlm_blocking_callback cb_blocking, void *cb_data)
+{
+ struct obd_device *obd = class_exp2obd(exp);
+ struct obd_export *cobd_exp;
+
+ if (obd == NULL) {
+ CERROR("invalid client cookie "LPX64"\n",
+ exp->exp_handle.h_cookie);
+ return -EINVAL;
+ }
+ cobd_exp = cobd_get_exp(obd);
+ return md_enqueue(cobd_exp, lock_type, it, lock_mode, data,
+ lockh, lmm, lmmsize, cb_completion, cb_blocking,
+ cb_data);
+}
+
+static int cobd_md_intent_lock(struct obd_export *exp, struct lustre_id *pid,
+ const char *name, int len, void *lmm, int lmmsize,
+ struct lustre_id *cid, struct lookup_intent *it,
+ int lookup_flags, struct ptlrpc_request **reqp,
+ ldlm_blocking_callback cb_blocking)
+{
+ struct obd_device *obd = class_exp2obd(exp);
+ struct obd_export *cobd_exp;
+
+ if (obd == NULL) {
+ CERROR("invalid client cookie "LPX64"\n",
+ exp->exp_handle.h_cookie);
+ return -EINVAL;
+ }
+ cobd_exp = cobd_get_exp(obd);
+ return md_intent_lock(cobd_exp, pid, name, len, lmm, lmmsize,
+ cid, it, lookup_flags, reqp, cb_blocking);
+}
+
+static struct obd_device *cobd_md_get_real_obd(struct obd_export *exp,
+ struct lustre_id *id)
+{
+ struct obd_device *obd = class_exp2obd(exp);
+ struct obd_export *cobd_exp;
+
+ if (obd == NULL) {
+ CERROR("invalid client cookie "LPX64"\n",
+ exp->exp_handle.h_cookie);
+ return NULL;
+ }
+ cobd_exp = cobd_get_exp(obd);
+ return md_get_real_obd(cobd_exp, id);
+}
+
+static int cobd_md_change_cbdata_name(struct obd_export *exp,
+ struct lustre_id *id, char *name,
+ int namelen, struct lustre_id *id2,
+ ldlm_iterator_t it, void *data)
+{
+ struct obd_device *obd = class_exp2obd(exp);
+ struct obd_export *cobd_exp;
+
+ if (obd == NULL) {
+ CERROR("invalid client cookie "LPX64"\n",
+ exp->exp_handle.h_cookie);
+ return -EINVAL;
+ }
+ cobd_exp = cobd_get_exp(obd);
+ return md_change_cbdata_name(cobd_exp, id, name, namelen,
+ id2, it, data);
+}
+static struct obd_ops cobd_obd_ops = {
+ .o_owner = THIS_MODULE,
+ .o_attach = cobd_attach,
+ .o_detach = cobd_detach,
+ .o_setup = cobd_setup,
+ .o_cleanup = cobd_cleanup,
+ .o_connect = cobd_connect,
+ .o_disconnect = cobd_disconnect,
+ .o_set_info = cobd_set_info,
+ .o_get_info = cobd_get_info,
+ .o_statfs = cobd_statfs,
+
+ .o_packmd = cobd_packmd,
+ .o_unpackmd = cobd_unpackmd,
+ .o_create = cobd_create,
+ .o_destroy = cobd_destroy,
+ .o_precleanup = cobd_precleanup,
+ .o_getattr = cobd_getattr,
+ .o_getattr_async = cobd_getattr_async,
+ .o_setattr = cobd_setattr,
+
+ .o_brw = cobd_brw,
+ .o_brw_async = cobd_brw_async,
+ .o_prep_async_page = cobd_prep_async_page,
+ .o_queue_async_io = cobd_queue_async_io,
+ .o_set_async_flags = cobd_set_async_flags,
+ .o_queue_group_io = cobd_queue_group_io,
+ .o_trigger_group_io = cobd_trigger_group_io,
+ .o_teardown_async_page = cobd_teardown_async_page,
+ .o_preprw = cobd_preprw,
+ .o_punch = cobd_punch,
+ .o_sync = cobd_sync,
+ .o_enqueue = cobd_enqueue,
+ .o_match = cobd_match,
+ .o_change_cbdata = cobd_change_cbdata,
+ .o_cancel = cobd_cancel,
+ .o_cancel_unused = cobd_cancel_unused,
+ .o_iocontrol = cobd_iocontrol,
+ .o_commitrw = cobd_commitrw,
+ .o_llog_init = cobd_llog_init,
+ .o_llog_finish = cobd_llog_finish,
+ .o_notify = cobd_notify,
+ .o_pin = cobd_pin,
+ .o_unpin = cobd_unpin,
+ .o_import_event = cobd_import_event,
+ .o_init_ea_size = cobd_init_ea_size,
+};