X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fobdecho%2Fecho.c;h=a32f2be7f9ae8015eeba5bcdd85de4c6d26ccb3d;hb=bb5c8e257d0d1ed111da68715c0a3a49849b4fdf;hp=5292cad8b8cbbe8f5988b713fc9b084718d263de;hpb=4f35d4cf58b1ef878713742225559757b06c91b3;p=fs%2Flustre-release.git diff --git a/lustre/obdecho/echo.c b/lustre/obdecho/echo.c index 5292cad..a32f2be 100644 --- a/lustre/obdecho/echo.c +++ b/lustre/obdecho/echo.c @@ -1,27 +1,38 @@ /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- * vim:expandtab:shiftwidth=8:tabstop=8: * - * linux/fs/obdecho/echo.c + * Copyright (c) 2001-2003 Cluster File Systems, Inc. + * Author: Peter Braam + * Author: Andreas Dilger * - * Copyright (C) 2001, 2002 Cluster File Systems, Inc. + * This file is part of Lustre, http://www.lustre.org. * - * This code is issued under the GNU General Public License. - * See the file COPYING in this distribution + * 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. * - * by Peter Braam - * and Andreas Dilger + * 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. + * + * 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. */ -static char rcsid[] __attribute ((unused)) = "$Id: echo.c,v 1.30 2002/09/03 20:19:20 adilger Exp $"; -#define OBDECHO_VERSION "$Revision: 1.30 $" - -#define EXPORT_SYMTAB +#ifndef EXPORT_SYMTAB +# define EXPORT_SYMTAB +#endif #include #include +#include +#include #include #include -#include +#include +#include #include #include #include @@ -35,104 +46,48 @@ static char rcsid[] __attribute ((unused)) = "$Id: echo.c,v 1.30 2002/09/03 20:1 #include #include #include +#include -extern struct obd_device obd_dev[MAX_OBD_DEVICES]; - -#define ECHO_PROC_STAT "sys/obdecho" - -int echo_proc_read(char *page, char **start, off_t off, int count, int *eof, - void *data) -{ - struct obd_device *obd; - long long attrs = 0; - long long pages = 0; - int len; - int i; - - *eof = 1; - if (off != 0) - return (0); - - for (i = 0, obd = obd_dev; i < MAX_OBD_DEVICES; i++, obd++) { - if (strcmp(obd->obd_type->typ_name, OBD_ECHO_DEVICENAME)) - continue; - attrs += atomic_read(&obd->u.echo.eo_getattr) + - atomic_read(&obd->u.echo.eo_setattr); - pages += atomic_read(&obd->u.echo.eo_read) + - atomic_read(&obd->u.echo.eo_write); - } - - len = sprintf(page, "%Ld %Ld\n", attrs, pages); +#define ECHO_INIT_OBJID 0x1000000000000000ULL +#define ECHO_HANDLE_MAGIC 0xabcd0123fedc9876ULL - *start = page; - return (len); -} +#define ECHO_OBJECT0_NPAGES 16 +static struct page *echo_object0_pages[ECHO_OBJECT0_NPAGES]; -int echo_proc_write(struct file *file, const char *ubuffer, - unsigned long count, void *data) -{ - struct obd_device *obd; - int i; - - for (i = 0, obd = obd_dev; i < MAX_OBD_DEVICES; i++, obd++) { - if (strcmp(obd->obd_type->typ_name, OBD_ECHO_DEVICENAME)) - continue; - - atomic_set(&obd->u.echo.eo_getattr, 0); - atomic_set(&obd->u.echo.eo_setattr, 0); - atomic_set(&obd->u.echo.eo_read, 0); - atomic_set(&obd->u.echo.eo_write, 0); - } - - /* Ignore what we've been asked to write, and just zero the counters */ - - return (count); -} +enum { + LPROC_ECHO_READ_BYTES = 1, + LPROC_ECHO_WRITE_BYTES = 2, + LPROC_ECHO_LAST = LPROC_ECHO_WRITE_BYTES +1 +}; -void echo_proc_init(void) +static int echo_connect(struct lustre_handle *conn, struct obd_device *obd, + struct obd_uuid *cluuid) { - struct proc_dir_entry *entry; - - entry = create_proc_entry(ECHO_PROC_STAT, S_IFREG|S_IRUGO|S_IWUSR,NULL); - - if (entry == NULL) { - CERROR("couldn't create proc entry %s\n", ECHO_PROC_STAT); - return; - } - - entry->data = NULL; - entry->read_proc = echo_proc_read; - entry->write_proc = echo_proc_write; + return class_connect(conn, obd, cluuid); } -void echo_proc_fini(void) +static int echo_disconnect(struct obd_export *exp, int flags) { - remove_proc_entry(ECHO_PROC_STAT, 0); -} + unsigned long irqflags; -static int echo_connect(struct lustre_handle *conn, struct obd_device *obd, - char *cluuid) -{ - int rc; + LASSERT (exp != NULL); - MOD_INC_USE_COUNT; - rc = class_connect(conn, obd, cluuid); + ldlm_cancel_locks_for_export(exp); - if (rc) - MOD_DEC_USE_COUNT; + spin_lock_irqsave(&exp->exp_lock, irqflags); + exp->exp_flags = flags; + spin_unlock_irqrestore(&exp->exp_lock, irqflags); - return rc; + return class_disconnect(exp, flags); } -static int echo_disconnect(struct lustre_handle *conn) +static int echo_destroy_export(struct obd_export *exp) { - int rc; - - rc = class_disconnect(conn); - if (!rc) - MOD_DEC_USE_COUNT; + ENTRY; + + target_destroy_export(exp); - return rc; + RETURN(0); } static __u64 echo_next_id(struct obd_device *obddev) @@ -146,22 +101,23 @@ static __u64 echo_next_id(struct obd_device *obddev) return id; } -int echo_create(struct lustre_handle *conn, struct obdo *oa, - struct lov_stripe_md **ea) +int echo_create(struct obd_export *exp, struct obdo *oa, + struct lov_stripe_md **ea, struct obd_trans_info *oti) { - struct obd_device *obd = class_conn2obd(conn); + struct obd_device *obd = class_exp2obd(exp); if (!obd) { - CERROR("invalid client %Lx\n", conn->addr); + CERROR("invalid client cookie "LPX64"\n", + exp->exp_handle.h_cookie); return -EINVAL; } if (!(oa->o_mode && S_IFMT)) { - CERROR("filter obd: no type!\n"); + CERROR("echo obd: no type!\n"); return -ENOENT; } - if (!(oa->o_valid & OBD_MD_FLMODE)) { + if (!(oa->o_valid & OBD_MD_FLTYPE)) { CERROR("invalid o_valid %08x\n", oa->o_valid); return -EINVAL; } @@ -173,13 +129,14 @@ int echo_create(struct lustre_handle *conn, struct obdo *oa, return 0; } -int echo_destroy(struct lustre_handle *conn, struct obdo *oa, - struct lov_stripe_md *ea) +int echo_destroy(struct obd_export *exp, struct obdo *oa, + struct lov_stripe_md *ea, struct obd_trans_info *oti) { - struct obd_device *obd = class_conn2obd(conn); + struct obd_device *obd = class_exp2obd(exp); if (!obd) { - CERROR("invalid client "LPX64"\n", conn->addr); + CERROR("invalid client cookie "LPX64"\n", + exp->exp_handle.h_cookie); RETURN(-EINVAL); } @@ -188,8 +145,8 @@ int echo_destroy(struct lustre_handle *conn, struct obdo *oa, RETURN(-EINVAL); } - if (oa->o_id > obd->u.echo.eo_lastino) { - CERROR("bad destroy objid: %Ld\n", (long long)oa->o_id); + if (oa->o_id > obd->u.echo.eo_lastino || oa->o_id < ECHO_INIT_OBJID) { + CERROR("bad destroy objid: "LPX64"\n", oa->o_id); RETURN(-EINVAL); } @@ -198,14 +155,15 @@ int echo_destroy(struct lustre_handle *conn, struct obdo *oa, return 0; } -static int echo_getattr(struct lustre_handle *conn, struct obdo *oa, +static int echo_getattr(struct obd_export *exp, struct obdo *oa, struct lov_stripe_md *md) { - struct obd_device *obd = class_conn2obd(conn); + struct obd_device *obd = class_exp2obd(exp); obd_id id = oa->o_id; if (!obd) { - CERROR("invalid client "LPX64"\n", conn->addr); + CERROR("invalid client cookie "LPX64"\n", + exp->exp_handle.h_cookie); RETURN(-EINVAL); } @@ -214,22 +172,20 @@ static int echo_getattr(struct lustre_handle *conn, struct obdo *oa, RETURN(-EINVAL); } - memcpy(oa, &obd->u.echo.oa, sizeof(*oa)); + obdo_cpy_md(oa, &obd->u.echo.oa, oa->o_valid); oa->o_id = id; - oa->o_valid |= OBD_MD_FLID; - - atomic_inc(&obd->u.echo.eo_getattr); return 0; } -static int echo_setattr(struct lustre_handle *conn, struct obdo *oa, - struct lov_stripe_md *md) +static int echo_setattr(struct obd_export *exp, struct obdo *oa, + struct lov_stripe_md *md, struct obd_trans_info *oti) { - struct obd_device *obd = class_conn2obd(conn); + struct obd_device *obd = class_exp2obd(exp); if (!obd) { - CERROR("invalid client "LPX64"\n", conn->addr); + CERROR("invalid client cookie "LPX64"\n", + exp->exp_handle.h_cookie); RETURN(-EINVAL); } @@ -248,60 +204,93 @@ static int echo_setattr(struct lustre_handle *conn, struct obdo *oa, /* This allows us to verify that desc_private is passed unmolested */ #define DESC_PRIV 0x10293847 -int echo_preprw(int cmd, struct lustre_handle *conn, int objcount, - struct obd_ioobj *obj, int niocount, struct niobuf_remote *nb, - struct niobuf_local *res, void **desc_private) +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_device *obd; struct niobuf_local *r = res; + int tot_bytes = 0; int rc = 0; int i; - ENTRY; - obd = class_conn2obd(conn); - if (!obd) { - CERROR("invalid client "LPX64"\n", conn->addr); + obd = export->exp_obd; + if (obd == NULL) RETURN(-EINVAL); - } + + /* Temp fix to stop falling foul of osc_announce_cached() */ + oa->o_valid &= ~(OBD_MD_FLBLOCKS | OBD_MD_FLRDEV); memset(res, 0, sizeof(*res) * niocount); CDEBUG(D_PAGE, "%s %d obdos with %d IOs\n", cmd == OBD_BRW_READ ? "reading" : "writing", objcount, niocount); - *desc_private = (void *)DESC_PRIV; + if (oti) + 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 verify = obj->ioo_id != 0; + int isobj0 = obj->ioo_id == 0; + int verify = !isobj0; int j; for (j = 0 ; j < obj->ioo_bufcnt ; j++, nb++, r++) { - r->page = alloc_pages(gfp_mask, 0); - if (!r->page) { - CERROR("can't get page %d/%d for id "LPU64"\n", - j, obj->ioo_bufcnt, obj->ioo_id); - GOTO(preprw_cleanup, rc = -ENOMEM); + + if (isobj0 && + (nb->offset >> PAGE_SHIFT) < ECHO_OBJECT0_NPAGES) { + r->page = echo_object0_pages[nb->offset >> + PAGE_SHIFT]; + /* Take extra ref so __free_pages() can be called OK */ + get_page (r->page); + } else { + r->page = alloc_pages(gfp_mask, 0); + if (r->page == NULL) { + CERROR("can't get page %u/%u for id " + LPU64"\n", + j, obj->ioo_bufcnt, obj->ioo_id); + GOTO(preprw_cleanup, rc = -ENOMEM); + } } + + tot_bytes += nb->len; + atomic_inc(&obd->u.echo.eo_prep); r->offset = nb->offset; - r->addr = kmap(r->page); r->len = nb->len; - - CDEBUG(D_PAGE, "$$$$ get page %p, addr %p@"LPU64"\n", - r->page, r->addr, r->offset); - - if (verify && cmd == OBD_BRW_READ) - page_debug_setup(r->addr, r->len, r->offset, - obj->ioo_id); - else if (verify) - page_debug_setup(r->addr, r->len, - 0xecc0ecc0ecc0ecc0, - 0xecc0ecc0ecc0ecc0); + LASSERT((r->offset & ~PAGE_MASK) + r->len <= PAGE_SIZE); + + CDEBUG(D_PAGE, "$$$$ get page %p @ "LPU64" for %d\n", + r->page, r->offset, r->len); + + if (cmd & OBD_BRW_READ) { + r->rc = r->len; + if (verify) { + page_debug_setup(kmap (r->page), r->len, + r->offset,obj->ioo_id); + kunmap (r->page); + } + r->rc = r->len; + } else { + if (verify) { + page_debug_setup(kmap (r->page), r->len, + 0xecc0ecc0ecc0ecc0ULL, + 0xecc0ecc0ecc0ecc0ULL); + kunmap (r->page); + } + } } } + if (cmd & OBD_BRW_READ) + lprocfs_counter_add(obd->obd_stats, LPROC_ECHO_READ_BYTES, + tot_bytes); + else + lprocfs_counter_add(obd->obd_stats, LPROC_ECHO_WRITE_BYTES, + tot_bytes); + CDEBUG(D_PAGE, "%d pages allocated after prep\n", atomic_read(&obd->u.echo.eo_prep)); @@ -316,6 +305,8 @@ preprw_cleanup: CERROR("cleaning up %ld pages (%d obdos)\n", (long)(r - res), objcount); while (r-- > res) { kunmap(r->page); + /* NB if this is an 'object0' page, __free_pages will just + * lose the extra ref gained above */ __free_pages(r->page, 0); atomic_dec(&obd->u.echo.eo_prep); } @@ -324,30 +315,25 @@ preprw_cleanup: return rc; } -int echo_commitrw(int cmd, struct lustre_handle *conn, int objcount, - struct obd_ioobj *obj, int niocount, struct niobuf_local *res, - void *desc_private) +int echo_commitrw(int cmd, struct obd_export *export, struct obdo *oa, + int objcount, struct obd_ioobj *obj, int niocount, + struct niobuf_local *res, struct obd_trans_info *oti) { struct obd_device *obd; struct niobuf_local *r = res; - int rc = 0; - int i; + int i, vrc = 0, rc = 0; ENTRY; - obd = class_conn2obd(conn); - if (!obd) { - CERROR("invalid client "LPX64"\n", conn->addr); + obd = export->exp_obd; + if (obd == NULL) RETURN(-EINVAL); - } if ((cmd & OBD_BRW_RWMASK) == OBD_BRW_READ) { CDEBUG(D_PAGE, "reading %d obdos with %d IOs\n", objcount, niocount); - atomic_inc(&obd->u.echo.eo_read); } else { CDEBUG(D_PAGE, "writing %d obdos with %d IOs\n", objcount, niocount); - atomic_inc(&obd->u.echo.eo_write); } if (niocount && !r) { @@ -355,7 +341,7 @@ int echo_commitrw(int cmd, struct lustre_handle *conn, int objcount, RETURN(-EINVAL); } - LASSERT(desc_private == (void *)DESC_PRIV); + LASSERT(oti == NULL || oti->oti_handle == (void *)DESC_PRIV); for (i = 0; i < objcount; i++, obj++) { int verify = obj->ioo_id != 0; @@ -365,31 +351,35 @@ int echo_commitrw(int cmd, struct lustre_handle *conn, int objcount, struct page *page = r->page; void *addr; - if (!page || !(addr = page_address(page)) || - !kern_addr_valid(addr)) { + if (!page || !(addr = kmap(page)) || + !kern_addr_valid((unsigned long)addr)) { CERROR("bad page objid "LPU64":%p, buf %d/%d\n", obj->ioo_id, page, j, obj->ioo_bufcnt); + kunmap(page); GOTO(commitrw_cleanup, rc = -EFAULT); } - atomic_inc(&obd->u.echo.eo_read); - CDEBUG(D_PAGE, "$$$$ use page %p, addr %p@"LPU64"\n", r->page, addr, r->offset); - if (verify) - page_debug_check("echo", addr, r->len, - r->offset, obj->ioo_id); + if (verify) { + vrc = page_debug_check("echo", addr, r->len, + r->offset, obj->ioo_id); + /* check all the pages always */ + if (vrc != 0 && rc == 0) + rc = vrc; + } kunmap(page); + /* NB see comment above regarding object0 pages */ __free_pages(page, 0); atomic_dec(&obd->u.echo.eo_prep); } } CDEBUG(D_PAGE, "%d pages remain after commit\n", atomic_read(&obd->u.echo.eo_prep)); - RETURN(0); + RETURN(rc); commitrw_cleanup: CERROR("cleaning up %ld pages (%d obdos)\n", @@ -397,7 +387,7 @@ commitrw_cleanup: while (++r < res + niocount) { struct page *page = r->page; - kunmap(page); + /* NB see comment above regarding object0 pages */ __free_pages(page, 0); atomic_dec(&obd->u.echo.eo_prep); } @@ -408,6 +398,9 @@ static int echo_setup(struct obd_device *obddev, obd_count len, void *buf) { ENTRY; + spin_lock_init(&obddev->u.echo.eo_lock); + obddev->u.echo.eo_lastino = ECHO_INIT_OBJID; + obddev->obd_namespace = ldlm_namespace_new("echo-tgt", LDLM_NAMESPACE_SERVER); if (obddev->obd_namespace == NULL) { @@ -415,61 +408,146 @@ static int echo_setup(struct obd_device *obddev, obd_count len, void *buf) RETURN(-ENOMEM); } + ptlrpc_init_client (LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL, + "echo_ldlm_cb_client", &obddev->obd_ldlm_client); RETURN(0); } -static int echo_cleanup(struct obd_device *obddev) +static int echo_cleanup(struct obd_device *obddev, int flags) { + int leaked; ENTRY; - ldlm_namespace_free(obddev->obd_namespace); - printk(KERN_INFO "%s: %u getattrs, %u setattrs\n", OBD_ECHO_DEVICENAME, - atomic_read(&obddev->u.echo.eo_getattr), - atomic_read(&obddev->u.echo.eo_setattr)); - printk(KERN_INFO "%s: %u reads, %u writes (%d leaked)\n", - OBD_ECHO_DEVICENAME, - atomic_read(&obddev->u.echo.eo_read), - atomic_read(&obddev->u.echo.eo_write), - atomic_read(&obddev->u.echo.eo_prep)); - printk(KERN_INFO "%s: %u creates, %u destroys\n", OBD_ECHO_DEVICENAME, - atomic_read(&obddev->u.echo.eo_create), - atomic_read(&obddev->u.echo.eo_destroy)); + ldlm_namespace_free(obddev->obd_namespace, flags & OBD_OPT_FORCE); + + leaked = atomic_read(&obddev->u.echo.eo_prep); + if (leaked != 0) + CERROR("%d prep/commitrw pages leaked\n", leaked); RETURN(0); } -struct obd_ops echo_obd_ops = { - o_connect: echo_connect, - o_disconnect: echo_disconnect, - 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 +int echo_attach(struct obd_device *obd, obd_count len, void *data) +{ + struct lprocfs_static_vars lvars; + int rc; + + 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; +} + +int echo_detach(struct obd_device *dev) +{ + lprocfs_free_obd_stats(dev); + return lprocfs_obd_detach(dev); +} + +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 }; -static int __init obdecho_init(void) +extern int echo_client_init(void); +extern void echo_client_exit(void); + +static void +echo_object0_pages_fini (void) +{ + int i; + + for (i = 0; i < ECHO_OBJECT0_NPAGES; i++) + if (echo_object0_pages[i] != NULL) { + __free_pages (echo_object0_pages[i], 0); + echo_object0_pages[i] = NULL; + } +} + +static int +echo_object0_pages_init (void) { - printk(KERN_INFO "Echo OBD driver " OBDECHO_VERSION - " info@clusterfs.com\n"); + struct page *pg; + int i; - echo_proc_init(); + for (i = 0; i < ECHO_OBJECT0_NPAGES; i++) { + int gfp_mask = (i < ECHO_OBJECT0_NPAGES/2) ? + GFP_KERNEL : GFP_HIGHUSER; + + pg = alloc_pages (gfp_mask, 0); + if (pg == NULL) { + echo_object0_pages_fini (); + return (-ENOMEM); + } + + memset (kmap (pg), 0, PAGE_SIZE); + kunmap (pg); + + echo_object0_pages[i] = pg; + } - return class_register_type(&echo_obd_ops, OBD_ECHO_DEVICENAME); + return (0); } -static void __exit obdecho_exit(void) +static int __init obdecho_init(void) { - echo_proc_fini(); + struct lprocfs_static_vars lvars; + int rc; + + printk(KERN_INFO "Lustre: Echo OBD driver; info@clusterfs.com\n"); + + lprocfs_init_vars(echo, &lvars); + + rc = echo_object0_pages_init (); + if (rc != 0) + goto failed_0; + + rc = class_register_type(&echo_obd_ops, lvars.module_vars, + OBD_ECHO_DEVICENAME); + if (rc != 0) + goto failed_1; + rc = echo_client_init(); + if (rc == 0) + RETURN (0); + + class_unregister_type(OBD_ECHO_DEVICENAME); + failed_1: + echo_object0_pages_fini (); + failed_0: + RETURN(rc); +} + +static void /*__exit*/ obdecho_exit(void) +{ + echo_client_exit(); class_unregister_type(OBD_ECHO_DEVICENAME); + echo_object0_pages_fini (); } -MODULE_AUTHOR("Cluster Filesystems Inc. "); -MODULE_DESCRIPTION("Lustre Testing Echo OBD driver " OBDECHO_VERSION); +MODULE_AUTHOR("Cluster File Systems, Inc. "); +MODULE_DESCRIPTION("Lustre Testing Echo OBD driver"); MODULE_LICENSE("GPL"); module_init(obdecho_init);