From 65d63035c60086a89d932c6f9f1691cf93728d74 Mon Sep 17 00:00:00 2001 From: Liu Xuezhao Date: Wed, 3 Apr 2013 16:47:20 -0500 Subject: [PATCH] LU-1330 fid: prepare FID module for client server split Split FID server from client, fid_{handler,store,lib}.c are not compliled unless server support is enabled. Generally cleanup includes in lustre/fid/ and reduce the need for client code to directly or indirectly include {dt,md}_object.h. Signed-off-by: Liu Xuezhao Signed-off-by: John L. Hammond Change-Id: Ie25abffc41922d9f6001b9e38a8e39b387ccf660 Reviewed-on: http://review.whamcloud.com/2673 Tested-by: Hudson Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Nathaniel Clark --- lustre/fid/Makefile.in | 4 +- lustre/fid/autoMakefile.am | 2 +- lustre/fid/fid_handler.c | 109 +++++--------------------------- lustre/fid/fid_internal.h | 44 ++++++++----- lustre/fid/fid_lib.c | 12 +--- lustre/fid/fid_request.c | 143 ++++++++++++++++++++++++++++++++---------- lustre/fid/fid_store.c | 16 +---- lustre/fid/lproc_fid.c | 31 +++++---- lustre/include/lu_object.h | 5 ++ lustre/include/lustre_fid.h | 24 ++++--- lustre/include/md_object.h | 5 -- lustre/include/obd.h | 7 +-- lustre/lod/lod_dev.c | 1 + lustre/ofd/ofd_internal.h | 1 + lustre/osd-zfs/osd_internal.h | 1 + lustre/osp/osp_internal.h | 1 + 16 files changed, 204 insertions(+), 202 deletions(-) diff --git a/lustre/fid/Makefile.in b/lustre/fid/Makefile.in index e4908e5..8b0c6e4 100644 --- a/lustre/fid/Makefile.in +++ b/lustre/fid/Makefile.in @@ -1,4 +1,4 @@ MODULES := fid -fid-objs := fid_handler.o fid_store.o fid_request.o lproc_fid.o fid_lib.o - +fid-objs := fid_request.o lproc_fid.o +@SERVER_TRUE@fid-objs += fid_handler.o fid_store.o fid_lib.o @INCLUDE_RULES@ diff --git a/lustre/fid/autoMakefile.am b/lustre/fid/autoMakefile.am index cb079c4..9f21c2c 100644 --- a/lustre/fid/autoMakefile.am +++ b/lustre/fid/autoMakefile.am @@ -36,7 +36,7 @@ if LIBLUSTRE noinst_LIBRARIES = libfid.a -libfid_a_SOURCES = fid_handler.c fid_store.c fid_request.c lproc_fid.c fid_lib.c fid_internal.h +libfid_a_SOURCES = fid_request.c fid_internal.h libfid_a_CPPFLAGS = $(LLCPPFLAGS) libfid_a_CFLAGS = $(LLCFLAGS) endif diff --git a/lustre/fid/fid_handler.c b/lustre/fid/fid_handler.c index 262d3d6..efdd33c 100644 --- a/lustre/fid/fid_handler.c +++ b/lustre/fid/fid_handler.c @@ -42,13 +42,8 @@ #define DEBUG_SUBSYSTEM S_FID -#ifdef __KERNEL__ -# include -# include -#else /* __KERNEL__ */ -# include -#endif - +#include +#include #include #include #include @@ -56,56 +51,9 @@ #include #include #include +#include /* err_serious() */ #include "fid_internal.h" -int client_fid_init(struct obd_device *obd, - struct obd_export *exp, enum lu_cli_type type) -{ - struct client_obd *cli = &obd->u.cli; - char *prefix; - int rc; - ENTRY; - - OBD_ALLOC_PTR(cli->cl_seq); - if (cli->cl_seq == NULL) - RETURN(-ENOMEM); - - OBD_ALLOC(prefix, MAX_OBD_NAME + 5); - if (prefix == NULL) - GOTO(out_free_seq, rc = -ENOMEM); - - snprintf(prefix, MAX_OBD_NAME + 5, "cli-%s", obd->obd_name); - - /* Init client side sequence-manager */ - rc = seq_client_init(cli->cl_seq, exp, type, prefix, NULL); - OBD_FREE(prefix, MAX_OBD_NAME + 5); - if (rc) - GOTO(out_free_seq, rc); - - RETURN(rc); -out_free_seq: - OBD_FREE_PTR(cli->cl_seq); - cli->cl_seq = NULL; - return rc; -} -EXPORT_SYMBOL(client_fid_init); - -int client_fid_fini(struct obd_device *obd) -{ - struct client_obd *cli = &obd->u.cli; - ENTRY; - - if (cli->cl_seq != NULL) { - seq_client_fini(cli->cl_seq); - OBD_FREE_PTR(cli->cl_seq); - cli->cl_seq = NULL; - } - - RETURN(0); -} -EXPORT_SYMBOL(client_fid_fini); - -#ifdef __KERNEL__ static void seq_server_proc_fini(struct lu_server_seq *seq); /* Assigns client to sequence controller node. */ @@ -463,10 +411,10 @@ int seq_query(struct com_thread_info *info) } EXPORT_SYMBOL(seq_query); - -#ifdef LPROCFS static int seq_server_proc_init(struct lu_server_seq *seq) { +#ifdef LPROCFS + int rc; ENTRY; @@ -491,10 +439,14 @@ static int seq_server_proc_init(struct lu_server_seq *seq) out_cleanup: seq_server_proc_fini(seq); return rc; +#else /* LPROCFS */ + return 0; +#endif } static void seq_server_proc_fini(struct lu_server_seq *seq) { +#ifdef LPROCFS ENTRY; if (seq->lss_proc_dir != NULL) { if (!IS_ERR(seq->lss_proc_dir)) @@ -502,20 +454,9 @@ static void seq_server_proc_fini(struct lu_server_seq *seq) seq->lss_proc_dir = NULL; } EXIT; -} -#else -static int seq_server_proc_init(struct lu_server_seq *seq) -{ - return 0; +#endif /* LPROCFS */ } -static void seq_server_proc_fini(struct lu_server_seq *seq) -{ - return; -} -#endif - - int seq_server_init(struct lu_server_seq *seq, struct dt_device *dev, const char *prefix, @@ -635,33 +576,13 @@ int seq_site_fini(const struct lu_env *env, struct seq_server_site *ss) } EXPORT_SYMBOL(seq_site_fini); -cfs_proc_dir_entry_t *seq_type_proc_dir = NULL; - -static int __init fid_mod_init(void) +int fid_server_mod_init(void) { - seq_type_proc_dir = lprocfs_register(LUSTRE_SEQ_NAME, - proc_lustre_root, - NULL, NULL); - if (IS_ERR(seq_type_proc_dir)) - return PTR_ERR(seq_type_proc_dir); - - LU_CONTEXT_KEY_INIT(&seq_thread_key); - lu_context_key_register(&seq_thread_key); - return 0; + LU_CONTEXT_KEY_INIT(&seq_thread_key); + return lu_context_key_register(&seq_thread_key); } -static void __exit fid_mod_exit(void) +void fid_server_mod_exit(void) { - lu_context_key_degister(&seq_thread_key); - if (seq_type_proc_dir != NULL && !IS_ERR(seq_type_proc_dir)) { - lprocfs_remove(&seq_type_proc_dir); - seq_type_proc_dir = NULL; - } + lu_context_key_degister(&seq_thread_key); } - -MODULE_AUTHOR("Sun Microsystems, Inc. "); -MODULE_DESCRIPTION("Lustre FID Module"); -MODULE_LICENSE("GPL"); - -cfs_module(fid, "0.1.0", fid_mod_init, fid_mod_exit); -#endif diff --git a/lustre/fid/fid_internal.h b/lustre/fid/fid_internal.h index 87c5636..e4d3de4 100644 --- a/lustre/fid/fid_internal.h +++ b/lustre/fid/fid_internal.h @@ -41,11 +41,14 @@ #define __FID_INTERNAL_H #include -#include - #include #ifdef __KERNEL__ +# ifdef HAVE_SERVER_SUPPORT +# define HAVE_SEQ_SERVER + +struct req_capsule; + struct seq_thread_info { struct req_capsule *sti_pill; struct lu_seq_range sti_space; @@ -58,31 +61,42 @@ enum { extern struct lu_context_key seq_thread_key; -/* Functions used internally in module. */ -int seq_client_alloc_super(struct lu_client_seq *seq, - const struct lu_env *env); +# ifdef LPROCFS +extern struct lprocfs_vars seq_server_proc_list[]; +# endif /* Store API functions. */ +struct dt_device; + int seq_store_init(struct lu_server_seq *seq, - const struct lu_env *env, - struct dt_device *dt); + const struct lu_env *env, + struct dt_device *dt); void seq_store_fini(struct lu_server_seq *seq, - const struct lu_env *env); + const struct lu_env *env); int seq_store_read(struct lu_server_seq *seq, - const struct lu_env *env); + const struct lu_env *env); int seq_store_update(const struct lu_env *env, struct lu_server_seq *seq, - struct lu_seq_range *out, int sync); + struct lu_seq_range *out, int sync); -#ifdef LPROCFS -extern struct lprocfs_vars seq_server_proc_list[]; +int fid_server_mod_init(void); + +void fid_server_mod_exit(void); + +# endif /* HAVE_SERVER_SUPPORT */ + +/* Functions used internally in module. */ +int seq_client_alloc_super(struct lu_client_seq *seq, + const struct lu_env *env); + +# ifdef LPROCFS extern struct lprocfs_vars seq_client_proc_list[]; -#endif +# endif -#endif +#endif /* __KERNEL__ */ -extern cfs_proc_dir_entry_t *seq_type_proc_dir; +extern struct proc_dir_entry *seq_type_proc_dir; #endif /* __FID_INTERNAL_H */ diff --git a/lustre/fid/fid_lib.c b/lustre/fid/fid_lib.c index 77285cc..6764394 100644 --- a/lustre/fid/fid_lib.c +++ b/lustre/fid/fid_lib.c @@ -43,15 +43,9 @@ #define DEBUG_SUBSYSTEM S_FID -#ifdef __KERNEL__ -# include -# include -#else /* __KERNEL__ */ -# include -#endif - -#include -#include +#include +#include +#include #include /** diff --git a/lustre/fid/fid_request.c b/lustre/fid/fid_request.c index a929833..d0da85e 100644 --- a/lustre/fid/fid_request.c +++ b/lustre/fid/fid_request.c @@ -51,10 +51,7 @@ #include #include -#include -#include #include -#include #include /* mdc RPC locks */ #include @@ -156,13 +153,15 @@ int seq_client_alloc_super(struct lu_client_seq *seq, mutex_lock(&seq->lcs_mutex); -#ifdef __KERNEL__ if (seq->lcs_srv) { +#ifdef HAVE_SEQ_SERVER LASSERT(env != NULL); rc = seq_server_alloc_super(seq->lcs_srv, &seq->lcs_space, env); - } else { +#else + rc = 0; #endif + } else { /* Check whether the connection to seq controller has been * setup (lcs_exp != NULL) */ if (seq->lcs_exp == NULL) { @@ -172,9 +171,7 @@ int seq_client_alloc_super(struct lu_client_seq *seq, rc = seq_client_rpc(seq, &seq->lcs_space, SEQ_ALLOC_SUPER, "super"); -#ifdef __KERNEL__ } -#endif mutex_unlock(&seq->lcs_mutex); RETURN(rc); } @@ -186,12 +183,14 @@ static int seq_client_alloc_meta(const struct lu_env *env, int rc; ENTRY; -#ifdef __KERNEL__ if (seq->lcs_srv) { +#ifdef HAVE_SEQ_SERVER LASSERT(env != NULL); rc = seq_server_alloc_meta(seq->lcs_srv, &seq->lcs_space, env); - } else { +#else + rc = 0; #endif + } else { do { /* If meta server return -EINPROGRESS or EAGAIN, * it means meta server might not be ready to @@ -200,9 +199,8 @@ static int seq_client_alloc_meta(const struct lu_env *env, rc = seq_client_rpc(seq, &seq->lcs_space, SEQ_ALLOC_META, "meta"); } while (rc == -EINPROGRESS || rc == -EAGAIN); -#ifdef __KERNEL__ } -#endif + RETURN(rc); } @@ -421,11 +419,22 @@ void seq_client_flush(struct lu_client_seq *seq) } EXPORT_SYMBOL(seq_client_flush); -static void seq_client_proc_fini(struct lu_client_seq *seq); - +static void seq_client_proc_fini(struct lu_client_seq *seq) +{ #ifdef LPROCFS + ENTRY; + if (seq->lcs_proc_dir) { + if (!IS_ERR(seq->lcs_proc_dir)) + lprocfs_remove(&seq->lcs_proc_dir); + seq->lcs_proc_dir = NULL; + } + EXIT; +#endif /* LPROCFS */ +} + static int seq_client_proc_init(struct lu_client_seq *seq) { +#ifdef LPROCFS int rc; ENTRY; @@ -453,29 +462,11 @@ static int seq_client_proc_init(struct lu_client_seq *seq) out_cleanup: seq_client_proc_fini(seq); return rc; -} - -static void seq_client_proc_fini(struct lu_client_seq *seq) -{ - ENTRY; - if (seq->lcs_proc_dir) { - if (!IS_ERR(seq->lcs_proc_dir)) - lprocfs_remove(&seq->lcs_proc_dir); - seq->lcs_proc_dir = NULL; - } - EXIT; -} -#else -static int seq_client_proc_init(struct lu_client_seq *seq) -{ - return 0; -} -static void seq_client_proc_fini(struct lu_client_seq *seq) -{ - return; -} +#else /* LPROCFS */ + return 0; #endif +} int seq_client_init(struct lu_client_seq *seq, struct obd_export *exp, @@ -532,3 +523,87 @@ void seq_client_fini(struct lu_client_seq *seq) EXIT; } EXPORT_SYMBOL(seq_client_fini); + +int client_fid_init(struct obd_device *obd, + struct obd_export *exp, enum lu_cli_type type) +{ + struct client_obd *cli = &obd->u.cli; + char *prefix; + int rc; + ENTRY; + + OBD_ALLOC_PTR(cli->cl_seq); + if (cli->cl_seq == NULL) + RETURN(-ENOMEM); + + OBD_ALLOC(prefix, MAX_OBD_NAME + 5); + if (prefix == NULL) + GOTO(out_free_seq, rc = -ENOMEM); + + snprintf(prefix, MAX_OBD_NAME + 5, "cli-%s", obd->obd_name); + + /* Init client side sequence-manager */ + rc = seq_client_init(cli->cl_seq, exp, type, prefix, NULL); + OBD_FREE(prefix, MAX_OBD_NAME + 5); + if (rc) + GOTO(out_free_seq, rc); + + RETURN(rc); +out_free_seq: + OBD_FREE_PTR(cli->cl_seq); + cli->cl_seq = NULL; + return rc; +} +EXPORT_SYMBOL(client_fid_init); + +int client_fid_fini(struct obd_device *obd) +{ + struct client_obd *cli = &obd->u.cli; + ENTRY; + + if (cli->cl_seq != NULL) { + seq_client_fini(cli->cl_seq); + OBD_FREE_PTR(cli->cl_seq); + cli->cl_seq = NULL; + } + + RETURN(0); +} +EXPORT_SYMBOL(client_fid_fini); + +#ifdef __KERNEL__ +struct proc_dir_entry *seq_type_proc_dir; + +static int __init fid_mod_init(void) +{ + seq_type_proc_dir = lprocfs_register(LUSTRE_SEQ_NAME, + proc_lustre_root, + NULL, NULL); + if (IS_ERR(seq_type_proc_dir)) + return PTR_ERR(seq_type_proc_dir); + +# ifdef HAVE_SERVER_SUPPORT + fid_server_mod_init(); +# endif + + return 0; +} + +static void __exit fid_mod_exit(void) +{ +# ifdef HAVE_SERVER_SUPPORT + fid_server_mod_exit(); +# endif + + if (seq_type_proc_dir != NULL && !IS_ERR(seq_type_proc_dir)) { + lprocfs_remove(&seq_type_proc_dir); + seq_type_proc_dir = NULL; + } +} + +MODULE_AUTHOR("Sun Microsystems, Inc. "); +MODULE_DESCRIPTION("Lustre FID Module"); +MODULE_LICENSE("GPL"); + +cfs_module(fid, "0.1.0", fid_mod_init, fid_mod_exit); +#endif /* __KERNEL__ */ diff --git a/lustre/fid/fid_store.c b/lustre/fid/fid_store.c index 0ba88b8..5ae8307 100644 --- a/lustre/fid/fid_store.c +++ b/lustre/fid/fid_store.c @@ -42,24 +42,15 @@ #define DEBUG_SUBSYSTEM S_FID -#ifdef __KERNEL__ -# include -# include -#else /* __KERNEL__ */ -# include -#endif - -#include -#include +#include #include #include #include -#include +#include #include +#include #include "fid_internal.h" -#ifdef __KERNEL__ - static struct lu_buf *seq_store_buf(struct seq_thread_info *info) { struct lu_buf *buf; @@ -262,4 +253,3 @@ void seq_store_fini(struct lu_server_seq *seq, EXIT; } -#endif diff --git a/lustre/fid/lproc_fid.c b/lustre/fid/lproc_fid.c index 7040c49..67cf63c 100644 --- a/lustre/fid/lproc_fid.c +++ b/lustre/fid/lproc_fid.c @@ -42,20 +42,13 @@ #define DEBUG_SUBSYSTEM S_FID -#ifdef __KERNEL__ -# include -# include -#else /* __KERNEL__ */ -# include -#endif - +#include +#include #include #include -#include -#include #include -#include #include +#include #include "fid_internal.h" #ifdef LPROCFS @@ -97,6 +90,7 @@ seq_proc_read_common(char *page, char **start, off_t off, RETURN(rc); } +#ifdef HAVE_SERVER_SUPPORT /* * Server side procfs stuff. */ @@ -214,6 +208,17 @@ seq_server_proc_read_width(char *page, char **start, off_t off, RETURN(rc); } +struct lprocfs_vars seq_server_proc_list[] = { + { "space", + seq_server_proc_read_space, seq_server_proc_write_space, NULL }, + { "width", + seq_server_proc_read_width, seq_server_proc_write_width, NULL }, + { "server", + seq_server_proc_read_server, NULL, NULL }, + { NULL } +}; +#endif /* HAVE_SERVER_SUPPORT */ + /* Client side procfs stuff */ static int seq_client_proc_write_space(struct file *file, const char *buffer, @@ -349,12 +354,6 @@ seq_client_proc_read_server(char *page, char **start, off_t off, RETURN(rc); } -struct lprocfs_vars seq_server_proc_list[] = { - { "space", seq_server_proc_read_space, seq_server_proc_write_space, NULL }, - { "width", seq_server_proc_read_width, seq_server_proc_write_width, NULL }, - { "server", seq_server_proc_read_server, NULL, NULL }, - { NULL }}; - struct lprocfs_vars seq_client_proc_list[] = { { "space", seq_client_proc_read_space, seq_client_proc_write_space, NULL }, { "width", seq_client_proc_read_width, seq_client_proc_write_width, NULL }, diff --git a/lustre/include/lu_object.h b/lustre/include/lu_object.h index 553022d..c093d31 100644 --- a/lustre/include/lu_object.h +++ b/lustre/include/lu_object.h @@ -665,6 +665,11 @@ lu_site_bkt_from_fid(struct lu_site *site, struct lu_fid *fid) return cfs_hash_bd_extra_get(site->ls_obj_hash, &bd); } +static inline struct seq_server_site *lu_site2seq(const struct lu_site *s) +{ + return s->ld_seq_site; +} + /** \name ctors * Constructors/destructors. * @{ diff --git a/lustre/include/lustre_fid.h b/lustre/include/lustre_fid.h index a048bdb..26bc9c3 100644 --- a/lustre/include/lustre_fid.h +++ b/lustre/include/lustre_fid.h @@ -38,8 +38,8 @@ * Author: Yury Umanets */ -#ifndef __LINUX_FID_H -#define __LINUX_FID_H +#ifndef __LUSTRE_FID_H +#define __LUSTRE_FID_H /** \defgroup fid fid * @@ -154,13 +154,12 @@ #include #include -#include -#include -#include - +struct lu_env; struct lu_site; struct lu_context; +struct obd_device; +struct obd_export; /* Whole sequences space range and zero range definitions */ extern const struct lu_seq_range LUSTRE_SEQ_SPACE_RANGE; @@ -320,6 +319,12 @@ static inline void lu_last_id_fid(struct lu_fid *fid, __u64 seq) fid->f_ver = 0; } +/* seq client type */ +enum lu_cli_type { + LUSTRE_SEQ_METADATA = 1, + LUSTRE_SEQ_DATA +}; + enum lu_mgr_type { LUSTRE_SEQ_SERVER, LUSTRE_SEQ_CONTROLLER @@ -426,10 +431,14 @@ struct lu_server_seq { struct seq_server_site *lss_site; }; +struct com_thread_info; int seq_query(struct com_thread_info *info); + +struct ptlrpc_request; int seq_handle(struct ptlrpc_request *req); /* Server methods */ + int seq_server_init(struct lu_server_seq *seq, struct dt_device *dev, const char *prefix, @@ -472,6 +481,7 @@ int seq_site_fini(const struct lu_env *env, struct seq_server_site *ss); int fid_is_local(const struct lu_env *env, struct lu_site *site, const struct lu_fid *fid); +enum lu_cli_type; int client_fid_init(struct obd_device *obd, struct obd_export *exp, enum lu_cli_type type); int client_fid_fini(struct obd_device *obd); @@ -760,4 +770,4 @@ static inline void range_be_to_cpu(struct lu_seq_range *dst, const struct lu_seq /** @} fid */ -#endif /* __LINUX_FID_H */ +#endif /* __LUSTRE_FID_H */ diff --git a/lustre/include/md_object.h b/lustre/include/md_object.h index e10e45b..0f72f8e 100644 --- a/lustre/include/md_object.h +++ b/lustre/include/md_object.h @@ -503,11 +503,6 @@ static inline struct md_device *md_obj2dev(const struct md_object *o) return container_of0(o->mo_lu.lo_dev, struct md_device, md_lu_dev); } -static inline struct seq_server_site *lu_site2seq(const struct lu_site *s) -{ - return s->ld_seq_site; -} - static inline int md_device_init(struct md_device *md, struct lu_device_type *t) { return lu_device_init(&md->md_lu_dev, t); diff --git a/lustre/include/obd.h b/lustre/include/obd.h index b208efd..7e866e9 100644 --- a/lustre/include/obd.h +++ b/lustre/include/obd.h @@ -63,6 +63,7 @@ #include #include #include +#include #include #include @@ -1254,12 +1255,6 @@ typedef int (* md_enqueue_cb_t)(struct ptlrpc_request *req, struct md_enqueue_info *minfo, int rc); -/* seq client type */ -enum lu_cli_type { - LUSTRE_SEQ_METADATA = 1, - LUSTRE_SEQ_DATA -}; - struct md_enqueue_info { struct md_op_data mi_data; struct lookup_intent mi_it; diff --git a/lustre/lod/lod_dev.c b/lustre/lod/lod_dev.c index f766fba..99791c5 100644 --- a/lustre/lod/lod_dev.c +++ b/lustre/lod/lod_dev.c @@ -44,6 +44,7 @@ #define DEBUG_SUBSYSTEM S_MDS #include +#include #include #include #include diff --git a/lustre/ofd/ofd_internal.h b/lustre/ofd/ofd_internal.h index 9ae635b..f653b49 100644 --- a/lustre/ofd/ofd_internal.h +++ b/lustre/ofd/ofd_internal.h @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include diff --git a/lustre/osd-zfs/osd_internal.h b/lustre/osd-zfs/osd_internal.h index c3730a2..15f488c 100644 --- a/lustre/osd-zfs/osd_internal.h +++ b/lustre/osd-zfs/osd_internal.h @@ -47,6 +47,7 @@ #define _OSD_INTERNAL_H #include +#include #include #include diff --git a/lustre/osp/osp_internal.h b/lustre/osp/osp_internal.h index 1658e58..953987f 100644 --- a/lustre/osp/osp_internal.h +++ b/lustre/osp/osp_internal.h @@ -44,6 +44,7 @@ #include #include #include +#include #include /* -- 1.8.3.1