Commit 56f4c5a8 authored by Liu Xuezhao's avatar Liu Xuezhao Committed by Greg Kroah-Hartman

staging/lustre/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.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-1330
Lustre-change: http://review.whamcloud.com/2673Signed-off-by: default avatarLiu Xuezhao <xuezhao.liu@emc.com>
Signed-off-by: default avatarJohn L. Hammond <john.hammond@intel.com>
Reviewed-by: default avatarAndreas Dilger <andreas.dilger@intel.com>
Reviewed-by: default avatarNathaniel Clark <nathaniel.l.clark@intel.com>
Signed-off-by: default avatarPeng Tao <tao.peng@emc.com>
Signed-off-by: default avatarAndreas Dilger <andreas.dilger@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 353471a6
obj-$(CONFIG_LUSTRE_FS) += fid.o
fid-y := fid_handler.o fid_store.o fid_request.o lproc_fid.o fid_lib.o
fid-y := fid_request.o lproc_fid.o fid_lib.o
ccflags-y := -I$(src)/../include
This diff is collapsed.
......@@ -41,44 +41,16 @@
#define __FID_INTERNAL_H
#include <lustre/lustre_idl.h>
#include <dt_object.h>
#include <linux/libcfs/libcfs.h>
struct seq_thread_info {
struct req_capsule *sti_pill;
struct lu_seq_range sti_space;
struct lu_buf sti_buf;
};
enum {
SEQ_TXN_STORE_CREDITS = 20
};
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);
/* Store API functions. */
int seq_store_init(struct lu_server_seq *seq,
const struct lu_env *env,
struct dt_device *dt);
void seq_store_fini(struct lu_server_seq *seq,
const struct lu_env *env);
int seq_store_read(struct lu_server_seq *seq,
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);
#ifdef LPROCFS
extern struct lprocfs_vars seq_server_proc_list[];
# ifdef LPROCFS
extern struct lprocfs_vars seq_client_proc_list[];
#endif
# endif
extern proc_dir_entry_t *seq_type_proc_dir;
extern struct proc_dir_entry *seq_type_proc_dir;
#endif /* __FID_INTERNAL_H */
......@@ -43,11 +43,9 @@
#define DEBUG_SUBSYSTEM S_FID
# include <linux/libcfs/libcfs.h>
# include <linux/module.h>
#include <obd.h>
#include <lu_object.h>
#include <linux/libcfs/libcfs.h>
#include <linux/module.h>
#include <lustre/lustre_idl.h>
#include <lustre_fid.h>
/**
......@@ -56,9 +54,9 @@
*
* Fid namespace:
* <pre>
* Normal FID: seq:64 [2^33,2^64-1] oid:32 ver:32
* IGIF : 0:32, ino:32 gen:32 0:32
* IDIF : 0:31, 1:1, ost-index:16, objd:48 0:32
* Normal FID: seq:64 [2^33,2^64-1] oid:32 ver:32
* IGIF : 0:32, ino:32 gen:32 0:32
* IDIF : 0:31, 1:1, ost-index:16, objd:48 0:32
* </pre>
*
* The first 0x400 sequences of normal FID are reserved for special purpose.
......
......@@ -27,7 +27,7 @@
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
* Copyright (c) 2011, 2012, Intel Corporation.
* Copyright (c) 2011, 2013, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
......@@ -42,15 +42,12 @@
#define DEBUG_SUBSYSTEM S_FID
# include <linux/libcfs/libcfs.h>
# include <linux/module.h>
#include <linux/libcfs/libcfs.h>
#include <linux/module.h>
#include <obd.h>
#include <obd_class.h>
#include <dt_object.h>
#include <md_object.h>
#include <obd_support.h>
#include <lustre_req_layout.h>
#include <lustre_fid.h>
/* mdc RPC locks */
#include <lustre_mdc.h>
......@@ -63,9 +60,9 @@ static int seq_client_rpc(struct lu_client_seq *seq,
struct obd_export *exp = seq->lcs_exp;
struct ptlrpc_request *req;
struct lu_seq_range *out, *in;
__u32 *op;
unsigned int debug_mask;
int rc;
__u32 *op;
unsigned int debug_mask;
int rc;
ENTRY;
req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), &RQF_SEQ_QUERY,
......@@ -153,9 +150,7 @@ int seq_client_alloc_super(struct lu_client_seq *seq,
mutex_lock(&seq->lcs_mutex);
if (seq->lcs_srv) {
LASSERT(env != NULL);
rc = seq_server_alloc_super(seq->lcs_srv, &seq->lcs_space,
env);
rc = 0;
} else {
/* Check whether the connection to seq controller has been
* setup (lcs_exp != NULL) */
......@@ -179,8 +174,7 @@ static int seq_client_alloc_meta(const struct lu_env *env,
ENTRY;
if (seq->lcs_srv) {
LASSERT(env != NULL);
rc = seq_server_alloc_meta(seq->lcs_srv, &seq->lcs_space, env);
rc = 0;
} else {
do {
/* If meta server return -EINPROGRESS or EAGAIN,
......@@ -191,6 +185,7 @@ static int seq_client_alloc_meta(const struct lu_env *env,
SEQ_ALLOC_META, "meta");
} while (rc == -EINPROGRESS || rc == -EAGAIN);
}
RETURN(rc);
}
......@@ -409,11 +404,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;
......@@ -441,29 +447,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)
{
#else /* LPROCFS */
return 0;
}
static void seq_client_proc_fini(struct lu_client_seq *seq)
{
return;
}
#endif
}
int seq_client_init(struct lu_client_seq *seq,
struct obd_export *exp,
......@@ -520,3 +508,76 @@ 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);
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);
return 0;
}
static void __exit fid_mod_exit(void)
{
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. <http://www.lustre.org/>");
MODULE_DESCRIPTION("Lustre FID Module");
MODULE_LICENSE("GPL");
cfs_module(fid, "0.1.0", fid_mod_init, fid_mod_exit);
/*
* GPL HEADER START
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 only,
* as published by the Free Software Foundation.
*
* This program 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 version 2 for more details (a copy is included
* in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU General Public License
* version 2 along with this program; If not, see
* http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
* GPL HEADER END
*/
/*
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
* Copyright (c) 2011, 2013, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
* Lustre is a trademark of Sun Microsystems, Inc.
*
* lustre/fid/fid_store.c
*
* Lustre Sequence Manager
*
* Author: Yury Umanets <umka@clusterfs.com>
*/
#define DEBUG_SUBSYSTEM S_FID
# include <linux/libcfs/libcfs.h>
# include <linux/module.h>
#include <obd.h>
#include <obd_class.h>
#include <dt_object.h>
#include <md_object.h>
#include <obd_support.h>
#include <lustre_req_layout.h>
#include <lustre_fid.h>
#include "fid_internal.h"
static struct lu_buf *seq_store_buf(struct seq_thread_info *info)
{
struct lu_buf *buf;
buf = &info->sti_buf;
buf->lb_buf = &info->sti_space;
buf->lb_len = sizeof(info->sti_space);
return buf;
}
struct seq_update_callback {
struct dt_txn_commit_cb suc_cb;
struct lu_server_seq *suc_seq;
};
void seq_update_cb(struct lu_env *env, struct thandle *th,
struct dt_txn_commit_cb *cb, int err)
{
struct seq_update_callback *ccb;
ccb = container_of0(cb, struct seq_update_callback, suc_cb);
LASSERT(ccb->suc_seq != NULL);
ccb->suc_seq->lss_need_sync = 0;
OBD_FREE_PTR(ccb);
}
int seq_update_cb_add(struct thandle *th, struct lu_server_seq *seq)
{
struct seq_update_callback *ccb;
struct dt_txn_commit_cb *dcb;
int rc;
OBD_ALLOC_PTR(ccb);
if (ccb == NULL)
return -ENOMEM;
ccb->suc_seq = seq;
seq->lss_need_sync = 1;
dcb = &ccb->suc_cb;
dcb->dcb_func = seq_update_cb;
INIT_LIST_HEAD(&dcb->dcb_linkage);
strncpy(dcb->dcb_name, "seq_update_cb", MAX_COMMIT_CB_STR_LEN);
dcb->dcb_name[MAX_COMMIT_CB_STR_LEN - 1] = '\0';
rc = dt_trans_cb_add(th, dcb);
if (rc)
OBD_FREE_PTR(ccb);
return rc;
}
/* This function implies that caller takes care about locking. */
int seq_store_update(const struct lu_env *env, struct lu_server_seq *seq,
struct lu_seq_range *out, int sync)
{
struct dt_device *dt_dev = lu2dt_dev(seq->lss_obj->do_lu.lo_dev);
struct seq_thread_info *info;
struct thandle *th;
loff_t pos = 0;
int rc;
info = lu_context_key_get(&env->le_ctx, &seq_thread_key);
LASSERT(info != NULL);
th = dt_trans_create(env, dt_dev);
if (IS_ERR(th))
RETURN(PTR_ERR(th));
rc = dt_declare_record_write(env, seq->lss_obj,
sizeof(struct lu_seq_range), 0, th);
if (rc)
GOTO(exit, rc);
if (out != NULL) {
rc = fld_declare_server_create(env,
seq->lss_site->ss_server_fld,
out, th);
if (rc)
GOTO(exit, rc);
}
rc = dt_trans_start_local(env, dt_dev, th);
if (rc)
GOTO(exit, rc);
/* Store ranges in le format. */
range_cpu_to_le(&info->sti_space, &seq->lss_space);
rc = dt_record_write(env, seq->lss_obj, seq_store_buf(info), &pos, th);
if (rc) {
CERROR("%s: Can't write space data, rc %d\n",
seq->lss_name, rc);
GOTO(exit, rc);
} else if (out != NULL) {
rc = fld_server_create(env, seq->lss_site->ss_server_fld, out,
th);
if (rc) {
CERROR("%s: Can't Update fld database, rc %d\n",
seq->lss_name, rc);
GOTO(exit, rc);
}
}
/* next sequence update will need sync until this update is committed
* in case of sync operation this is not needed obviously */
if (!sync)
/* if callback can't be added then sync always */
sync = !!seq_update_cb_add(th, seq);
th->th_sync |= sync;
exit:
dt_trans_stop(env, dt_dev, th);
return rc;
}
/*
* This function implies that caller takes care about locking or locking is not
* needed (init time).
*/
int seq_store_read(struct lu_server_seq *seq,
const struct lu_env *env)
{
struct seq_thread_info *info;
loff_t pos = 0;
int rc;
ENTRY;
info = lu_context_key_get(&env->le_ctx, &seq_thread_key);
LASSERT(info != NULL);
rc = seq->lss_obj->do_body_ops->dbo_read(env, seq->lss_obj,
seq_store_buf(info),
&pos, BYPASS_CAPA);
if (rc == sizeof(info->sti_space)) {
range_le_to_cpu(&seq->lss_space, &info->sti_space);
CDEBUG(D_INFO, "%s: Space - "DRANGE"\n",
seq->lss_name, PRANGE(&seq->lss_space));
rc = 0;
} else if (rc == 0) {
rc = -ENODATA;
} else if (rc > 0) {
CERROR("%s: Read only %d bytes of %d\n", seq->lss_name,
rc, (int)sizeof(info->sti_space));
rc = -EIO;
}
RETURN(rc);
}
int seq_store_init(struct lu_server_seq *seq,
const struct lu_env *env,
struct dt_device *dt)
{
struct dt_object *dt_obj;
struct lu_fid fid;
struct lu_attr attr;
struct dt_object_format dof;
const char *name;
int rc;
ENTRY;
name = seq->lss_type == LUSTRE_SEQ_SERVER ?
LUSTRE_SEQ_SRV_NAME : LUSTRE_SEQ_CTL_NAME;
if (seq->lss_type == LUSTRE_SEQ_SERVER)
lu_local_obj_fid(&fid, FID_SEQ_SRV_OID);
else
lu_local_obj_fid(&fid, FID_SEQ_CTL_OID);
memset(&attr, 0, sizeof(attr));
attr.la_valid = LA_MODE;
attr.la_mode = S_IFREG | 0666;
dof.dof_type = DFT_REGULAR;
dt_obj = dt_find_or_create(env, dt, &fid, &dof, &attr);
if (!IS_ERR(dt_obj)) {
seq->lss_obj = dt_obj;
rc = 0;
} else {
CERROR("%s: Can't find \"%s\" obj %d\n",
seq->lss_name, name, (int)PTR_ERR(dt_obj));
rc = PTR_ERR(dt_obj);
}
RETURN(rc);
}
void seq_store_fini(struct lu_server_seq *seq,
const struct lu_env *env)
{
ENTRY;
if (seq->lss_obj != NULL) {
if (!IS_ERR(seq->lss_obj))
lu_object_put(env, &seq->lss_obj->do_lu);
seq->lss_obj = NULL;
}
EXIT;
}
......@@ -204,9 +204,6 @@ lprocfs_fid_server_seq_show(struct seq_file *m, void *unused)
RETURN(rc);
}
struct lprocfs_vars seq_server_proc_list[] = {
};
LPROC_SEQ_FOPS(lprocfs_fid_space);
LPROC_SEQ_FOPS(lprocfs_fid_width);
LPROC_SEQ_FOPS_RO(lprocfs_fid_server);
......
......@@ -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.
* @{
......
......@@ -38,8 +38,8 @@
* Author: Yury Umanets <umka@clusterfs.com>
*/
#ifndef __LINUX_FID_H
#define __LINUX_FID_H
#ifndef __LUSTRE_FID_H
#define __LUSTRE_FID_H
/** \defgroup fid fid
*
......@@ -154,13 +154,12 @@
#include <linux/libcfs/libcfs.h>
#include <lustre/lustre_idl.h>
#include <lustre_req_layout.h>
#include <lustre_mdt.h>
#include <obd.h>
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 */
......@@ -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);
......
......@@ -52,6 +52,7 @@
#include <lu_ref.h>
#include <lustre_lib.h>
#include <lustre_export.h>
#include <lustre_fid.h>
#include <lustre_fld.h>
#include <lustre_capa.h>
......@@ -1232,12 +1233,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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment