X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Fobdecho%2Fecho.c;h=76288a1877889929860a10a46700c8349402d492;hp=c3ed9846a47084b6f58e339fde8c21ddb0ba13a8;hb=b5bf04fb27d8e3e455aec024d8b908a10434519f;hpb=090c677210ee2946d99c71412e4ff762bb300f4f diff --git a/lustre/obdecho/echo.c b/lustre/obdecho/echo.c index c3ed984..76288a1 100644 --- a/lustre/obdecho/echo.c +++ b/lustre/obdecho/echo.c @@ -5,54 +5,43 @@ * Author: Peter Braam * Author: Andreas Dilger * - * This file is part of Lustre, http://www.lustre.org. + * This file is part of the Lustre file system, http://www.lustre.org + * Lustre is a trademark of Cluster File Systems, Inc. * - * Lustre is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. + * You may have signed or agreed to another license before downloading + * this software. If so, you are bound by the terms and conditions + * of that agreement, and the following does not apply to you. See the + * LICENSE file included with this distribution for more information. * - * Lustre is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * If you did not agree to a different license, then this copy of Lustre + * is open source software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. * - * You should have received a copy of the GNU General Public License - * along with Lustre; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * In either case, Lustre is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * license text for more details. */ #ifndef EXPORT_SYMTAB # define EXPORT_SYMTAB #endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #define DEBUG_SUBSYSTEM S_ECHO -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #define ECHO_INIT_OBJID 0x1000000000000000ULL #define ECHO_HANDLE_MAGIC 0xabcd0123fedc9876ULL -#define ECHO_PERSISTENT_PAGES (ECHO_PERSISTENT_SIZE/PAGE_SIZE) -static struct page *echo_persistent_pages[ECHO_PERSISTENT_PAGES]; +#define ECHO_PERSISTENT_PAGES (ECHO_PERSISTENT_SIZE >> CFS_PAGE_SHIFT) +static cfs_page_t *echo_persistent_pages[ECHO_PERSISTENT_PAGES]; enum { LPROC_ECHO_READ_BYTES = 1, @@ -60,31 +49,43 @@ enum { LPROC_ECHO_LAST = LPROC_ECHO_WRITE_BYTES +1 }; -static int echo_connect(struct lustre_handle *conn, struct obd_device *obd, - struct obd_uuid *cluuid) +static int echo_connect(const struct lu_env *env, + struct lustre_handle *conn, struct obd_device *obd, + struct obd_uuid *cluuid, struct obd_connect_data *data, + void *localdata) { + data->ocd_connect_flags &= ECHO_CONNECT_SUPPORTED; return class_connect(conn, obd, cluuid); } -static int echo_disconnect(struct obd_export *exp, int flags) +static int echo_disconnect(struct obd_export *exp) { - unsigned long irqflags; - LASSERT (exp != NULL); ldlm_cancel_locks_for_export(exp); - spin_lock_irqsave(&exp->exp_lock, irqflags); - exp->exp_flags = flags; - spin_unlock_irqrestore(&exp->exp_lock, irqflags); + /* complete all outstanding replies */ + spin_lock(&exp->exp_lock); + while (!list_empty(&exp->exp_outstanding_replies)) { + struct ptlrpc_reply_state *rs = + list_entry(exp->exp_outstanding_replies.next, + struct ptlrpc_reply_state, rs_exp_list); + struct ptlrpc_service *svc = rs->rs_service; + + spin_lock(&svc->srv_lock); + list_del_init(&rs->rs_exp_list); + ptlrpc_schedule_difficult_reply(rs); + spin_unlock(&svc->srv_lock); + } + spin_unlock(&exp->exp_lock); - return class_disconnect(exp, flags); + return class_disconnect(exp); } static int echo_destroy_export(struct obd_export *exp) { ENTRY; - + target_destroy_export(exp); RETURN(0); @@ -107,7 +108,7 @@ int echo_create(struct obd_export *exp, struct obdo *oa, struct obd_device *obd = class_exp2obd(exp); if (!obd) { - CERROR("invalid client cookie "LPX64"\n", + CERROR("invalid client cookie "LPX64"\n", exp->exp_handle.h_cookie); return -EINVAL; } @@ -118,30 +119,31 @@ int echo_create(struct obd_export *exp, struct obdo *oa, } if (!(oa->o_valid & OBD_MD_FLTYPE)) { - CERROR("invalid o_valid %08x\n", oa->o_valid); + CERROR("invalid o_valid "LPX64"\n", oa->o_valid); return -EINVAL; } oa->o_id = echo_next_id(obd); oa->o_valid = OBD_MD_FLID; - atomic_inc(&obd->u.echo.eo_create); return 0; } int echo_destroy(struct obd_export *exp, struct obdo *oa, - struct lov_stripe_md *ea, struct obd_trans_info *oti) + struct lov_stripe_md *ea, struct obd_trans_info *oti, + struct obd_export *md_exp) { struct obd_device *obd = class_exp2obd(exp); + ENTRY; if (!obd) { - CERROR("invalid client cookie "LPX64"\n", + CERROR("invalid client cookie "LPX64"\n", exp->exp_handle.h_cookie); RETURN(-EINVAL); } if (!(oa->o_valid & OBD_MD_FLID)) { - CERROR("obdo missing FLID valid flag: %08x\n", oa->o_valid); + CERROR("obdo missing FLID valid flag: "LPX64"\n", oa->o_valid); RETURN(-EINVAL); } @@ -150,63 +152,69 @@ int echo_destroy(struct obd_export *exp, struct obdo *oa, RETURN(-EINVAL); } - atomic_inc(&obd->u.echo.eo_destroy); - - return 0; + RETURN(0); } -static int echo_getattr(struct obd_export *exp, struct obdo *oa, - struct lov_stripe_md *md) +static int echo_getattr(struct obd_export *exp, struct obd_info *oinfo) { struct obd_device *obd = class_exp2obd(exp); - obd_id id = oa->o_id; + obd_id id = oinfo->oi_oa->o_id; + ENTRY; if (!obd) { - CERROR("invalid client cookie "LPX64"\n", + CERROR("invalid client cookie "LPX64"\n", exp->exp_handle.h_cookie); RETURN(-EINVAL); } - if (!(oa->o_valid & OBD_MD_FLID)) { - CERROR("obdo missing FLID valid flag: %08x\n", oa->o_valid); + if (!(oinfo->oi_oa->o_valid & OBD_MD_FLID)) { + CERROR("obdo missing FLID valid flag: "LPX64"\n", + oinfo->oi_oa->o_valid); RETURN(-EINVAL); } - obdo_cpy_md(oa, &obd->u.echo.oa, oa->o_valid); - oa->o_id = id; + obdo_cpy_md(oinfo->oi_oa, &obd->u.echo.eo_oa, oinfo->oi_oa->o_valid); + oinfo->oi_oa->o_id = id; - return 0; + RETURN(0); } -static int echo_setattr(struct obd_export *exp, struct obdo *oa, - struct lov_stripe_md *md, struct obd_trans_info *oti) +static int echo_setattr(struct obd_export *exp, struct obd_info *oinfo, + struct obd_trans_info *oti) { struct obd_device *obd = class_exp2obd(exp); + ENTRY; if (!obd) { - CERROR("invalid client cookie "LPX64"\n", + CERROR("invalid client cookie "LPX64"\n", exp->exp_handle.h_cookie); RETURN(-EINVAL); } - if (!(oa->o_valid & OBD_MD_FLID)) { - CERROR("obdo missing FLID valid flag: %08x\n", oa->o_valid); + if (!(oinfo->oi_oa->o_valid & OBD_MD_FLID)) { + CERROR("obdo missing FLID valid flag: "LPX64"\n", + oinfo->oi_oa->o_valid); RETURN(-EINVAL); } - memcpy(&obd->u.echo.oa, oa, sizeof(*oa)); + memcpy(&obd->u.echo.eo_oa, oinfo->oi_oa, sizeof(*oinfo->oi_oa)); - atomic_inc(&obd->u.echo.eo_setattr); + if (oinfo->oi_oa->o_id & 4) { + /* Save lock to force ACKed reply */ + ldlm_lock_addref (&obd->u.echo.eo_nl_lock, LCK_NL); + oti->oti_ack_locks[0].mode = LCK_NL; + oti->oti_ack_locks[0].lock = obd->u.echo.eo_nl_lock; + } - return 0; + RETURN(0); } static void -echo_page_debug_setup(struct page *page, int rw, obd_id id, +echo_page_debug_setup(cfs_page_t *page, int rw, obd_id id, __u64 offset, int len) { - int page_offset = offset & (PAGE_SIZE - 1); - char *addr = ((char *)kmap(page)) + page_offset; + int page_offset = offset & ~CFS_PAGE_MASK; + char *addr = ((char *)cfs_kmap(page)) + page_offset; if (len % OBD_ECHO_BLOCK_SIZE != 0) CERROR("Unexpected block size %d\n", len); @@ -219,21 +227,21 @@ echo_page_debug_setup(struct page *page, int rw, obd_id id, block_debug_setup(addr, OBD_ECHO_BLOCK_SIZE, 0xecc0ecc0ecc0ecc0ULL, 0xecc0ecc0ecc0ecc0ULL); - + addr += OBD_ECHO_BLOCK_SIZE; offset += OBD_ECHO_BLOCK_SIZE; len -= OBD_ECHO_BLOCK_SIZE; } - kunmap(page); + cfs_kunmap(page); } static int -echo_page_debug_check(struct page *page, obd_id id, +echo_page_debug_check(cfs_page_t *page, obd_id id, __u64 offset, int len) { - int page_offset = offset & (PAGE_SIZE - 1); - char *addr = ((char *)kmap(page)) + page_offset; + int page_offset = offset & ~CFS_PAGE_MASK; + char *addr = ((char *)cfs_kmap(page)) + page_offset; int rc = 0; int rc2; @@ -246,13 +254,13 @@ echo_page_debug_check(struct page *page, obd_id id, if (rc2 != 0 && rc == 0) rc = rc2; - + addr += OBD_ECHO_BLOCK_SIZE; offset += OBD_ECHO_BLOCK_SIZE; len -= OBD_ECHO_BLOCK_SIZE; } - kunmap(page); + cfs_kunmap(page); return (rc); } @@ -263,7 +271,7 @@ echo_page_debug_check(struct page *page, obd_id id, int echo_preprw(int cmd, struct obd_export *export, 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_trans_info *oti, struct lustre_capa *unused) { struct obd_device *obd; struct niobuf_local *r = res; @@ -288,20 +296,23 @@ int echo_preprw(int cmd, struct obd_export *export, struct obdo *oa, oti->oti_handle = (void *)DESC_PRIV; for (i = 0; i < objcount; i++, obj++) { - int gfp_mask = (obj->ioo_id & 1) ? GFP_HIGHUSER : GFP_KERNEL; + int gfp_mask = (obj->ioo_id & 1) ? CFS_ALLOC_HIGHUSER : CFS_ALLOC_STD; int ispersistent = obj->ioo_id == ECHO_PERSISTENT_OBJID; + int debug_setup = (!ispersistent && + (oa->o_valid & OBD_MD_FLFLAGS) != 0 && + (oa->o_flags & OBD_FL_DEBUG_CHECK) != 0); int j; for (j = 0 ; j < obj->ioo_bufcnt ; j++, nb++, r++) { if (ispersistent && - (nb->offset >> PAGE_SHIFT) < ECHO_PERSISTENT_PAGES) { + (nb->offset >> CFS_PAGE_SHIFT) < ECHO_PERSISTENT_PAGES) { r->page = echo_persistent_pages[nb->offset >> - PAGE_SHIFT]; + CFS_PAGE_SHIFT]; /* Take extra ref so __free_pages() can be called OK */ - get_page (r->page); + cfs_get_page (r->page); } else { - r->page = alloc_pages(gfp_mask, 0); + OBD_PAGE_ALLOC(r->page, gfp_mask); if (r->page == NULL) { CERROR("can't get page %u/%u for id " LPU64"\n", @@ -316,7 +327,7 @@ int echo_preprw(int cmd, struct obd_export *export, struct obdo *oa, r->offset = nb->offset; r->len = nb->len; - LASSERT((r->offset & ~PAGE_MASK) + r->len <= PAGE_SIZE); + LASSERT((r->offset & ~CFS_PAGE_MASK) + r->len <= CFS_PAGE_SIZE); CDEBUG(D_PAGE, "$$$$ get page %p @ "LPU64" for %d\n", r->page, r->offset, r->len); @@ -324,7 +335,7 @@ int echo_preprw(int cmd, struct obd_export *export, struct obdo *oa, if (cmd & OBD_BRW_READ) r->rc = r->len; - if (!ispersistent) + if (debug_setup) echo_page_debug_setup(r->page, cmd, obj->ioo_id, r->offset, r->len); } @@ -349,10 +360,10 @@ preprw_cleanup: */ CERROR("cleaning up %ld pages (%d obdos)\n", (long)(r - res), objcount); while (r-- > res) { - kunmap(r->page); + cfs_kunmap(r->page); /* NB if this is a persistent page, __free_pages will just * lose the extra ref gained above */ - __free_pages(r->page, 0); + OBD_PAGE_FREE(r->page); atomic_dec(&obd->u.echo.eo_prep); } memset(res, 0, sizeof(*res) * niocount); @@ -393,11 +404,13 @@ int echo_commitrw(int cmd, struct obd_export *export, struct obdo *oa, for (i = 0; i < objcount; i++, obj++) { int verify = (rc == 0 && - obj->ioo_id != ECHO_PERSISTENT_OBJID); + obj->ioo_id != ECHO_PERSISTENT_OBJID && + (oa->o_valid & OBD_MD_FLFLAGS) != 0 && + (oa->o_flags & OBD_FL_DEBUG_CHECK) != 0); int j; for (j = 0 ; j < obj->ioo_bufcnt ; j++, r++) { - struct page *page = r->page; + cfs_page_t *page = r->page; void *addr; if (page == NULL) { @@ -406,22 +419,22 @@ int echo_commitrw(int cmd, struct obd_export *export, struct obdo *oa, GOTO(commitrw_cleanup, rc = -EFAULT); } - addr = kmap(page); + addr = cfs_kmap(page); CDEBUG(D_PAGE, "$$$$ use page %p, addr %p@"LPU64"\n", r->page, addr, r->offset); if (verify) { - vrc = echo_page_debug_check(page, obj->ioo_id, + vrc = echo_page_debug_check(page, obj->ioo_id, r->offset, r->len); /* check all the pages always */ if (vrc != 0 && rc == 0) rc = vrc; } - kunmap(page); + cfs_kunmap(page); /* NB see comment above regarding persistent pages */ - __free_pages(page, 0); + OBD_PAGE_FREE(page); atomic_dec(&obd->u.echo.eo_prep); } } @@ -433,89 +446,94 @@ commitrw_cleanup: CERROR("cleaning up %ld pages (%d obdos)\n", niocount - (long)(r - res) - 1, objcount); while (++r < res + niocount) { - struct page *page = r->page; + cfs_page_t *page = r->page; /* NB see comment above regarding persistent pages */ - __free_pages(page, 0); + OBD_PAGE_FREE(page); atomic_dec(&obd->u.echo.eo_prep); } return rc; } -static int echo_setup(struct obd_device *obddev, obd_count len, void *buf) +static int echo_setup(struct obd_device *obd, struct lustre_cfg *lcfg) { + struct lprocfs_static_vars lvars; + int rc; + int lock_flags = 0; + struct ldlm_res_id res_id = {.name = {1}}; ENTRY; - spin_lock_init(&obddev->u.echo.eo_lock); - obddev->u.echo.eo_lastino = ECHO_INIT_OBJID; + spin_lock_init(&obd->u.echo.eo_lock); + obd->u.echo.eo_lastino = ECHO_INIT_OBJID; - obddev->obd_namespace = - ldlm_namespace_new("echo-tgt", LDLM_NAMESPACE_SERVER); - if (obddev->obd_namespace == NULL) { + obd->obd_namespace = ldlm_namespace_new(obd, "echo-tgt", + LDLM_NAMESPACE_SERVER, + LDLM_NAMESPACE_MODEST); + if (obd->obd_namespace == NULL) { LBUG(); RETURN(-ENOMEM); } + rc = ldlm_cli_enqueue_local(obd->obd_namespace, &res_id, LDLM_PLAIN, + NULL, LCK_NL, &lock_flags, NULL, + ldlm_completion_ast, NULL, NULL, + 0, NULL, &obd->u.echo.eo_nl_lock); + LASSERT (rc == ELDLM_OK); + + lprocfs_echo_init_vars(&lvars); + if (lprocfs_obd_setup(obd, lvars.obd_vars) == 0 && + lprocfs_alloc_obd_stats(obd, LPROC_ECHO_LAST) == 0) { + lprocfs_counter_init(obd->obd_stats, LPROC_ECHO_READ_BYTES, + LPROCFS_CNTR_AVGMINMAX, + "read_bytes", "bytes"); + lprocfs_counter_init(obd->obd_stats, LPROC_ECHO_WRITE_BYTES, + LPROCFS_CNTR_AVGMINMAX, + "write_bytes", "bytes"); + } + ptlrpc_init_client (LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL, - "echo_ldlm_cb_client", &obddev->obd_ldlm_client); + "echo_ldlm_cb_client", &obd->obd_ldlm_client); RETURN(0); } -static int echo_cleanup(struct obd_device *obddev, int flags) +static int echo_cleanup(struct obd_device *obd) { - int leaked; + int leaked; ENTRY; - ldlm_namespace_free(obddev->obd_namespace, flags & OBD_OPT_FORCE); + lprocfs_obd_cleanup(obd); + lprocfs_free_obd_stats(obd); - leaked = atomic_read(&obddev->u.echo.eo_prep); - if (leaked != 0) - CERROR("%d prep/commitrw pages leaked\n", leaked); + ldlm_lock_decref (&obd->u.echo.eo_nl_lock, LCK_NL); - RETURN(0); -} + /* XXX Bug 3413; wait for a bit to ensure the BL callback has + * happened before calling ldlm_namespace_free() */ + set_current_state (TASK_UNINTERRUPTIBLE); + cfs_schedule_timeout (CFS_TASK_UNINT, cfs_time_seconds(1)); -int echo_attach(struct obd_device *obd, obd_count len, void *data) -{ - struct lprocfs_static_vars lvars; - int rc; + ldlm_namespace_free(obd->obd_namespace, NULL, obd->obd_force); + obd->obd_namespace = NULL; - lprocfs_init_vars(echo, &lvars); - rc = lprocfs_obd_attach(obd, lvars.obd_vars); - if (rc != 0) - return rc; - rc = lprocfs_alloc_obd_stats(obd, LPROC_ECHO_LAST); - if (rc != 0) - return rc; - - lprocfs_counter_init(obd->obd_stats, LPROC_ECHO_READ_BYTES, - LPROCFS_CNTR_AVGMINMAX, "read_bytes", "bytes"); - lprocfs_counter_init(obd->obd_stats, LPROC_ECHO_WRITE_BYTES, - LPROCFS_CNTR_AVGMINMAX, "write_bytes", "bytes"); - return rc; -} + leaked = atomic_read(&obd->u.echo.eo_prep); + if (leaked != 0) + CERROR("%d prep/commitrw pages leaked\n", leaked); -int echo_detach(struct obd_device *dev) -{ - lprocfs_free_obd_stats(dev); - return lprocfs_obd_detach(dev); + RETURN(0); } static struct obd_ops echo_obd_ops = { - o_owner: THIS_MODULE, - o_attach: echo_attach, - o_detach: echo_detach, - o_connect: echo_connect, - o_disconnect: echo_disconnect, - o_destroy_export: echo_destroy_export, - o_create: echo_create, - o_destroy: echo_destroy, - o_getattr: echo_getattr, - o_setattr: echo_setattr, - o_preprw: echo_preprw, - o_commitrw: echo_commitrw, - o_setup: echo_setup, - o_cleanup: echo_cleanup + .o_owner = THIS_MODULE, + .o_connect = echo_connect, + .o_disconnect = echo_disconnect, + .o_destroy_export = echo_destroy_export, + .o_create = echo_create, + .o_destroy = echo_destroy, + .o_getattr = echo_getattr, + .o_setattr = echo_setattr, + .o_preprw = echo_preprw, + .o_commitrw = echo_commitrw, + .o_setup = echo_setup, + .o_cleanup = echo_cleanup }; extern int echo_client_init(void); @@ -528,7 +546,7 @@ echo_persistent_pages_fini (void) for (i = 0; i < ECHO_PERSISTENT_PAGES; i++) if (echo_persistent_pages[i] != NULL) { - __free_pages (echo_persistent_pages[i], 0); + OBD_PAGE_FREE(echo_persistent_pages[i]); echo_persistent_pages[i] = NULL; } } @@ -536,21 +554,21 @@ echo_persistent_pages_fini (void) static int echo_persistent_pages_init (void) { - struct page *pg; + cfs_page_t *pg; int i; for (i = 0; i < ECHO_PERSISTENT_PAGES; i++) { int gfp_mask = (i < ECHO_PERSISTENT_PAGES/2) ? - GFP_KERNEL : GFP_HIGHUSER; + CFS_ALLOC_STD : CFS_ALLOC_HIGHUSER; - pg = alloc_pages (gfp_mask, 0); + OBD_PAGE_ALLOC(pg, gfp_mask); if (pg == NULL) { echo_persistent_pages_fini (); return (-ENOMEM); } - memset (kmap (pg), 0, PAGE_SIZE); - kunmap (pg); + memset (cfs_kmap (pg), 0, CFS_PAGE_SIZE); + cfs_kunmap (pg); echo_persistent_pages[i] = pg; } @@ -563,18 +581,19 @@ static int __init obdecho_init(void) struct lprocfs_static_vars lvars; int rc; + ENTRY; printk(KERN_INFO "Lustre: Echo OBD driver; info@clusterfs.com\n"); - LASSERT(PAGE_SIZE % OBD_ECHO_BLOCK_SIZE == 0); + LASSERT(CFS_PAGE_SIZE % OBD_ECHO_BLOCK_SIZE == 0); - lprocfs_init_vars(echo, &lvars); + lprocfs_echo_init_vars(&lvars); rc = echo_persistent_pages_init (); if (rc != 0) goto failed_0; rc = class_register_type(&echo_obd_ops, NULL, lvars.module_vars, - OBD_ECHO_DEVICENAME); + LUSTRE_ECHO_NAME, NULL); if (rc != 0) goto failed_1; @@ -582,7 +601,7 @@ static int __init obdecho_init(void) if (rc == 0) RETURN (0); - class_unregister_type(OBD_ECHO_DEVICENAME); + class_unregister_type(LUSTRE_ECHO_NAME); failed_1: echo_persistent_pages_fini (); failed_0: @@ -592,7 +611,7 @@ static int __init obdecho_init(void) static void /*__exit*/ obdecho_exit(void) { echo_client_exit(); - class_unregister_type(OBD_ECHO_DEVICENAME); + class_unregister_type(LUSTRE_ECHO_NAME); echo_persistent_pages_fini (); } @@ -600,5 +619,4 @@ MODULE_AUTHOR("Cluster File Systems, Inc. "); MODULE_DESCRIPTION("Lustre Testing Echo OBD driver"); MODULE_LICENSE("GPL"); -module_init(obdecho_init); -module_exit(obdecho_exit); +cfs_module(obdecho, "1.0.0", obdecho_init, obdecho_exit);