From 21ec386df7314348e9d483008648524192b51054 Mon Sep 17 00:00:00 2001 From: James Simmons Date: Tue, 19 Feb 2013 12:29:29 -0500 Subject: [PATCH] LU-2158 lvfs: move obdclass related functions to obclass Currently a lot of functions exist in the lvfs layer that really belongs to different parts of the stack. This patch moves obdclass specific code that is located in the lvfs layer into the proper location. Signed-off-by: James Simmons Change-Id: I5be4dede1afdbbc4af0157cbcd13a5133ce7a1db Reviewed-on: http://review.whamcloud.com/5250 Reviewed-by: Andreas Dilger Tested-by: Hudson Tested-by: Maloo Reviewed-by: Oleg Drokin --- lustre/lvfs/lvfs_lib.c | 25 ----------------- lustre/lvfs/lvfs_linux.c | 44 ----------------------------- lustre/obdclass/class_obd.c | 68 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 67 insertions(+), 70 deletions(-) diff --git a/lustre/lvfs/lvfs_lib.c b/lustre/lvfs/lvfs_lib.c index 82e930b..31c2d51 100644 --- a/lustre/lvfs/lvfs_lib.c +++ b/lustre/lvfs/lvfs_lib.c @@ -47,29 +47,6 @@ #include #include -unsigned int obd_alloc_fail_rate = 0; - -int obd_alloc_fail(const void *ptr, const char *name, const char *type, - size_t size, const char *file, int line) -{ - if (ptr == NULL || - (cfs_rand() & OBD_ALLOC_FAIL_MASK) < obd_alloc_fail_rate) { - CERROR("%s%salloc of %s ("LPU64" bytes) failed at %s:%d\n", - ptr ? "force " :"", type, name, (__u64)size, file, - line); - CERROR(LPU64" total bytes and "LPU64" total pages " - "("LPU64" bytes) allocated by Lustre, " - "%d total bytes by LNET\n", - obd_memory_sum(), - obd_pages_sum() << CFS_PAGE_SHIFT, - obd_pages_sum(), - cfs_atomic_read(&libcfs_kmemory)); - return 1; - } - return 0; -} -EXPORT_SYMBOL(obd_alloc_fail); - #ifdef LPROCFS void lprocfs_counter_add(struct lprocfs_stats *stats, int idx, long amount) { @@ -198,5 +175,3 @@ int lprocfs_stats_alloc_one(struct lprocfs_stats *stats, unsigned int cpuid) } EXPORT_SYMBOL(lprocfs_stats_alloc_one); #endif /* LPROCFS */ - -EXPORT_SYMBOL(obd_alloc_fail_rate); diff --git a/lustre/lvfs/lvfs_linux.c b/lustre/lvfs/lvfs_linux.c index 525e660..a4f9340 100644 --- a/lustre/lvfs/lvfs_linux.c +++ b/lustre/lvfs/lvfs_linux.c @@ -58,11 +58,8 @@ #include #include -__u64 obd_max_pages = 0; -__u64 obd_max_alloc = 0; struct lprocfs_stats *obd_memory = NULL; EXPORT_SYMBOL(obd_memory); -DEFINE_SPINLOCK(obd_updatemax_lock); /* refine later and change to seqlock or simlar from libcfs */ /* Debugging check only needed during development */ @@ -246,47 +243,6 @@ struct l_file *l_dentry_open(struct lvfs_run_ctxt *ctxt, struct l_dentry *de, } EXPORT_SYMBOL(l_dentry_open); -void obd_update_maxusage() -{ - __u64 max1, max2; - - max1 = obd_pages_sum(); - max2 = obd_memory_sum(); - - spin_lock(&obd_updatemax_lock); - if (max1 > obd_max_pages) - obd_max_pages = max1; - if (max2 > obd_max_alloc) - obd_max_alloc = max2; - spin_unlock(&obd_updatemax_lock); - -} -EXPORT_SYMBOL(obd_update_maxusage); - -__u64 obd_memory_max(void) -{ - __u64 ret; - - spin_lock(&obd_updatemax_lock); - ret = obd_max_alloc; - spin_unlock(&obd_updatemax_lock); - - return ret; -} -EXPORT_SYMBOL(obd_memory_max); - -__u64 obd_pages_max(void) -{ - __u64 ret; - - spin_lock(&obd_updatemax_lock); - ret = obd_max_pages; - spin_unlock(&obd_updatemax_lock); - - return ret; -} -EXPORT_SYMBOL(obd_pages_max); - #ifdef LPROCFS __s64 lprocfs_read_helper(struct lprocfs_counter *lc, struct lprocfs_counter_header *header, diff --git a/lustre/obdclass/class_obd.c b/lustre/obdclass/class_obd.c index d9355ad..3470ba6 100644 --- a/lustre/obdclass/class_obd.c +++ b/lustre/obdclass/class_obd.c @@ -60,14 +60,17 @@ EXPORT_SYMBOL(obd_devs); cfs_list_t obd_types; DEFINE_RWLOCK(obd_dev_lock); -#ifndef __KERNEL__ __u64 obd_max_pages = 0; __u64 obd_max_alloc = 0; +#ifndef __KERNEL__ __u64 obd_alloc; __u64 obd_pages; #endif +DEFINE_SPINLOCK(obd_updatemax_lock); /* The following are visible and mutable through /proc/sys/lustre/. */ +unsigned int obd_alloc_fail_rate = 0; +EXPORT_SYMBOL(obd_alloc_fail_rate); unsigned int obd_debug_peer_on_timeout; EXPORT_SYMBOL(obd_debug_peer_on_timeout); unsigned int obd_dump_on_timeout; @@ -162,6 +165,27 @@ int lustre_get_jobid(char *jobid) } EXPORT_SYMBOL(lustre_get_jobid); +int obd_alloc_fail(const void *ptr, const char *name, const char *type, + size_t size, const char *file, int line) +{ + if (ptr == NULL || + (cfs_rand() & OBD_ALLOC_FAIL_MASK) < obd_alloc_fail_rate) { + CERROR("%s%salloc of %s ("LPU64" bytes) failed at %s:%d\n", + ptr ? "force " :"", type, name, (__u64)size, file, + line); + CERROR(LPU64" total bytes and "LPU64" total pages " + "("LPU64" bytes) allocated by Lustre, " + "%d total bytes by LNET\n", + obd_memory_sum(), + obd_pages_sum() << CFS_PAGE_SHIFT, + obd_pages_sum(), + cfs_atomic_read(&libcfs_kmemory)); + return 1; + } + return 0; +} +EXPORT_SYMBOL(obd_alloc_fail); + static inline void obd_data2conn(struct lustre_handle *conn, struct obd_ioctl_data *data) { @@ -588,6 +612,48 @@ int init_obdclass(void) return err; } +void obd_update_maxusage(void) +{ + __u64 max1, max2; + + max1 = obd_pages_sum(); + max2 = obd_memory_sum(); + + spin_lock(&obd_updatemax_lock); + if (max1 > obd_max_pages) + obd_max_pages = max1; + if (max2 > obd_max_alloc) + obd_max_alloc = max2; + spin_unlock(&obd_updatemax_lock); +} +EXPORT_SYMBOL(obd_update_maxusage); + +#ifdef LPROCFS +__u64 obd_memory_max(void) +{ + __u64 ret; + + spin_lock(&obd_updatemax_lock); + ret = obd_max_alloc; + spin_unlock(&obd_updatemax_lock); + + return ret; +} +EXPORT_SYMBOL(obd_memory_max); + +__u64 obd_pages_max(void) +{ + __u64 ret; + + spin_lock(&obd_updatemax_lock); + ret = obd_max_pages; + spin_unlock(&obd_updatemax_lock); + + return ret; +} +EXPORT_SYMBOL(obd_pages_max); +#endif + /* liblustre doesn't call cleanup_obdclass, apparently. we carry on in this * ifdef to the end of the file to cover module and versioning goo.*/ #ifdef __KERNEL__ -- 1.8.3.1