/* -*- MODE: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
* vim:expandtab:shiftwidth=8:tabstop=8:
*
- * fld/fld.c
+ * fld/fld.c
*
* Copyright (C) 2006 Cluster File Systems, Inc.
* Author: WangDi <wangdi@clusterfs.com>
#include <linux/md_object.h>
#include <linux/lustre_mdc.h>
#include "fld_internal.h"
-
+
+static int fld_handle(struct lu_context *ctx,
+ struct fld *fld, __u32 opts, struct md_fld *mf);
+
/*XXX maybe these 2 items should go to sbi*/
struct fld_cache_info *fld_cache = NULL;
static int dht_mdt_hash(__u64 seq)
{
- return 0;
+ return 0;
}
struct obd_export* get_fld_exp(struct obd_export *exp, __u64 seq)
{
int seq_mds;
-
+
seq_mds = dht_mdt_hash(seq);
CDEBUG(D_INFO, "mds number %d\n", seq_mds);
-
+
/*get exp according to lu_seq*/
return exp;
}
-
+
enum {
FLD_HTABLE_BITS = 8,
FLD_HTABLE_SIZE = (1 << FLD_HTABLE_BITS),
}
-static int fld_cache_insert(struct fld_cache_info *fld_cache, __u64 lu_seq,
+static int fld_cache_insert(struct fld_cache_info *fld_cache, __u64 lu_seq,
__u64 mds_num)
{
struct fld_cache *fld;
INIT_HLIST_NODE(&fld->fld_list);
fld->fld_mds = mds_num;
- fld->fld_seq = lu_seq;
+ fld->fld_seq = lu_seq;
- spin_lock(&fld_cache->fld_lock);
+ spin_lock(&fld_cache->fld_lock);
hlist_for_each_entry(fld, scan, bucket, fld_list) {
if (fld->fld_seq == lu_seq) {
spin_unlock(&fld_cache->fld_lock);
hlist_add_head(&fld->fld_list, bucket);
spin_unlock(&fld_cache->fld_lock);
exit:
- if (rc != 0)
+ if (rc != 0)
OBD_FREE(fld, sizeof(*fld));
RETURN(rc);
}
-static struct fld_cache*
+static struct fld_cache*
fld_cache_lookup(struct fld_cache_info *fld_cache, __u64 lu_seq)
{
struct hlist_head *bucket;
bucket = fld_cache->fld_hash + (fld_hash(lu_seq) &
fld_cache->fld_hash_mask);
-
- spin_lock(&fld_cache->fld_lock);
+
+ spin_lock(&fld_cache->fld_lock);
hlist_for_each_entry(fld, scan, bucket, fld_list) {
if (fld->fld_seq == lu_seq) {
spin_unlock(&fld_cache->fld_lock);
bucket = fld_cache->fld_hash + (fld_hash(lu_seq) &
fld_cache->fld_hash_mask);
-
- spin_lock(&fld_cache->fld_lock);
+
+ spin_lock(&fld_cache->fld_lock);
hlist_for_each_entry(fld, scan, bucket, fld_list) {
if (fld->fld_seq == lu_seq) {
hlist_del_init(&fld->fld_list);
int fld_create(struct obd_export *exp, __u64 seq, __u64 mds_num)
{
struct obd_export *fld_exp;
- struct md_fld md_fld;
+ struct md_fld md_fld;
__u32 rc;
ENTRY;
int fld_delete(struct obd_export *exp, __u64 seq, __u64 mds_num)
{
struct obd_export *fld_exp;
- struct md_fld md_fld;
+ struct md_fld md_fld;
__u32 rc;
-
+
fld_cache_delete(fld_cache, seq);
fld_exp = get_fld_exp(exp, seq);
int fld_get(struct obd_export *exp, __u64 lu_seq, __u64 *mds_num)
{
struct obd_export *fld_exp;
- struct md_fld md_fld;
+ struct md_fld md_fld;
int vallen, rc;
-
+
fld_exp = get_fld_exp(exp, lu_seq);
if (!fld_exp);
RETURN(-EINVAL);
md_fld.mf_seq = lu_seq;
-
+
vallen = sizeof(struct md_fld);
-
+
rc = mdc_fld(fld_exp, &md_fld, FLD_GET);
-
+
*mds_num = md_fld.mf_mds;
-
+
RETURN(rc);
}
/*lookup fid in the namespace of pfid according to the name*/
int fld_lookup(struct obd_export *exp, __u64 lu_seq, __u64 *mds_num)
{
- struct fld_cache *fld;
+ struct fld_cache *fld;
int rc;
ENTRY;
*mds_num = fld->fld_mds;
RETURN(0);
}
- /*can not find it in the cache*/
+ /*can not find it in the cache*/
rc = fld_get(exp, lu_seq, mds_num);
if (rc)
- RETURN(rc);
-
+ RETURN(rc);
+
rc = fld_cache_insert(fld_cache, lu_seq, *mds_num);
-
+
RETURN(rc);
}
OBD_ALLOC_PTR(fld_cache);
if (fld_cache == NULL)
- RETURN(-ENOMEM);
-
+ RETURN(-ENOMEM);
+
/*init fld cache info*/
fld_cache->fld_hash_mask = FLD_HTABLE_MASK;
- OBD_ALLOC(fld_cache->fld_hash, FLD_HTABLE_SIZE *
+ OBD_ALLOC(fld_cache->fld_hash, FLD_HTABLE_SIZE *
sizeof fld_cache->fld_hash[0]);
spin_lock_init(&fld_cache->fld_lock);
-
+
RETURN(0);
}
sizeof fld_cache->fld_hash[0]);
OBD_FREE_PTR(fld_cache);
}
- return 0;
+ return 0;
}
static int __init fld_mod_init(void)
struct fld_list fld_list_head;
+static int fld_req_handle0(struct lu_context *ctx,
+ struct fld *fld, struct ptlrpc_request *req)
+{
+ struct md_fld *in;
+ struct md_fld *out;
+ int size = sizeof *in;
+ int rc;
+ __u32 *opt;
+
+ ENTRY;
+
+ rc = lustre_pack_reply(req, 1, &size, NULL);
+ if (rc)
+ RETURN(rc);
+
+ rc = -EPROTO;
+ opt = lustre_swab_reqbuf(req, 0, sizeof *opt, lustre_swab_generic_32s);
+ if (opt != NULL) {
+ in = lustre_swab_reqbuf(req, 1, sizeof *in, lustre_swab_md_fld);
+ if (in != NULL) {
+ out = lustre_msg_buf(req->rq_repmsg, 0, size);
+ LASSERT(out != NULL);
+ *out = *in;
+
+ rc = fld_handle(ctx, fld, *opt, out);
+ } else
+ CERROR("Cannot unpack mf\n");
+ } else
+ CERROR("Cannot unpack option\n");
+ RETURN(rc);
+}
+
+
+static int fld_req_handle(struct ptlrpc_request *req)
+{
+ int result;
+ struct lu_context *ctx;
+ struct lu_site *site;
+
+ ENTRY;
+
+ ctx = req->rq_svc_thread->t_ctx;
+ LASSERT(ctx != NULL);
+ LASSERT(ctx->lc_thread == req->rq_svc_thread);
+ result = -EPROTO;
+ if (req->rq_reqmsg->opc == FLD_QUERY) {
+ if (req->rq_export != NULL) {
+ site = req->rq_export->exp_obd->obd_lu_dev->ld_site;
+ LASSERT(site != NULL);
+ result = fld_req_handle0(ctx, site->ls_fld, req);
+ } else
+ CERROR("Unconnected request\n");
+ } else
+ CERROR("Wrong opcode: %d\n", req->rq_reqmsg->opc);
+
+ RETURN(result);
+}
+
int fld_server_init(struct fld *fld, struct dt_device *dt)
{
+ int result;
+ struct ptlrpc_service_conf fld_conf = {
+ .psc_nbufs = MDS_NBUFS,
+ .psc_bufsize = MDS_BUFSIZE,
+ .psc_max_req_size = MDS_MAXREQSIZE,
+ .psc_max_reply_size = MDS_MAXREPSIZE,
+ .psc_req_portal = MDS_FLD_PORTAL,
+ .psc_rep_portal = MDC_REPLY_PORTAL,
+ .psc_watchdog_timeout = FLD_SERVICE_WATCHDOG_TIMEOUT,
+ .psc_num_threads = FLD_NUM_THREADS
+ };
+
fld->fld_dt = dt;
+ lu_device_get(&dt->dd_lu_dev);
INIT_LIST_HEAD(&fld_list_head.fld_list);
spin_lock_init(&fld_list_head.fld_lock);
- return 0;
+
+ fld->fld_service =
+ ptlrpc_init_svc_conf(&fld_conf, fld_req_handle,
+ LUSTRE_FLD0_NAME,
+ fld->fld_proc_entry, NULL);
+ if (fld->fld_service != NULL)
+ result = ptlrpc_start_threads(NULL, fld->fld_service,
+ LUSTRE_FLD0_NAME);
+ else
+ result = -ENOMEM;
+ if (result != 0)
+ fld_server_fini(fld);
+ return result;
}
EXPORT_SYMBOL(fld_server_init);
void fld_server_fini(struct fld *fld)
{
struct list_head *pos, *n;
-
+
+ if (fld->fld_service != NULL) {
+ ptlrpc_unregister_service(fld->fld_service);
+ fld->fld_service = NULL;
+ }
+
spin_lock(&fld_list_head.fld_lock);
list_for_each_safe(pos, n, &fld_list_head.fld_list) {
struct fld_item *fld = list_entry(pos, struct fld_item,
list_del_init(&fld->fld_list);
OBD_FREE_PTR(fld);
}
- spin_unlock(&fld_list_head.fld_lock);
+ spin_unlock(&fld_list_head.fld_lock);
+ lu_device_put(&fld->fld_dt->dd_lu_dev);
+ fld->fld_dt = NULL;
}
EXPORT_SYMBOL(fld_server_fini);
static int fld_handle_create(struct fld *pfld, __u64 seq_num, __u64 mds_num)
{
struct fld_item *fld;
-
+
OBD_ALLOC_PTR(fld);
fld->fld_seq = seq_num;
fld->fld_mds = mds_num;
- INIT_LIST_HEAD(&fld->fld_list);
+ INIT_LIST_HEAD(&fld->fld_list);
spin_lock(&fld_list_head.fld_lock);
list_add_tail(&fld_list_head.fld_list, &fld->fld_list);
spin_unlock(&fld_list_head.fld_lock);
static int fld_handle_get(struct fld *pfld, __u64 seq_num, __u64 *mds_num)
{
struct list_head *pos, *n;
-
+
spin_lock(&fld_list_head.fld_lock);
list_for_each_safe(pos, n, &fld_list_head.fld_list) {
struct fld_item *fld = list_entry(pos, struct fld_item,
return -ENOENT;
}
-int fld_handle(struct fld *fld, __u32 opts, void *mf)
+static int fld_handle(struct lu_context *ctx,
+ struct fld *fld, __u32 opts, struct md_fld *mf)
{
- struct md_fld *pmf = mf;
int rc;
ENTRY;
switch (opts) {
case FLD_CREATE:
- rc = fld_handle_create(fld, pmf->mf_seq, pmf->mf_mds);
+ rc = fld_handle_create(fld, mf->mf_seq, mf->mf_mds);
break;
case FLD_DELETE:
- rc = fld_handle_delete(fld, pmf->mf_seq, pmf->mf_mds);
+ rc = fld_handle_delete(fld, mf->mf_seq, mf->mf_mds);
break;
case FLD_GET:
- rc = fld_handle_get(fld, pmf->mf_seq, &pmf->mf_mds);
+ rc = fld_handle_get(fld, mf->mf_seq, &mf->mf_mds);
break;
default:
rc = -EINVAL;
- break;
+ break;
}
RETURN(rc);
}
-EXPORT_SYMBOL(fld_handle);
MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
MODULE_DESCRIPTION("Lustre fld Prototype");
(long long)MDS_QUOTACHECK);
LASSERTF(MDS_QUOTACTL == 48, " found %lld\n",
(long long)MDS_QUOTACTL);
- LASSERTF(MDS_LAST_OPC == 52, " found %lld\n",
+ LASSERTF(MDS_LAST_OPC == 51, " found %lld\n",
(long long)MDS_LAST_OPC);
LASSERTF(REINT_SETATTR == 1, " found %lld\n",
(long long)REINT_SETATTR);
(long long)(int)sizeof(((struct obdo *)0)->o_inline));
LASSERTF(OBD_INLINESZ == 80, " found %lld\n",
(long long)OBD_INLINESZ);
- CLASSERT(OBD_MD_FLID == (0x00000001ULL));
- CLASSERT(OBD_MD_FLATIME == (0x00000002ULL));
- CLASSERT(OBD_MD_FLMTIME == (0x00000004ULL));
- CLASSERT(OBD_MD_FLCTIME == (0x00000008ULL));
- CLASSERT(OBD_MD_FLSIZE == (0x00000010ULL));
- CLASSERT(OBD_MD_FLBLOCKS == (0x00000020ULL));
- CLASSERT(OBD_MD_FLBLKSZ == (0x00000040ULL));
- CLASSERT(OBD_MD_FLMODE == (0x00000080ULL));
- CLASSERT(OBD_MD_FLTYPE == (0x00000100ULL));
- CLASSERT(OBD_MD_FLUID == (0x00000200ULL));
- CLASSERT(OBD_MD_FLGID == (0x00000400ULL));
- CLASSERT(OBD_MD_FLFLAGS == (0x00000800ULL));
- CLASSERT(OBD_MD_FLNLINK == (0x00002000ULL));
- CLASSERT(OBD_MD_FLGENER == (0x00004000ULL));
- CLASSERT(OBD_MD_FLINLINE == (0x00008000ULL));
- CLASSERT(OBD_MD_FLRDEV == (0x00010000ULL));
- CLASSERT(OBD_MD_FLEASIZE == (0x00020000ULL));
- CLASSERT(OBD_MD_LINKNAME == (0x00040000ULL));
- CLASSERT(OBD_MD_FLHANDLE == (0x00080000ULL));
- CLASSERT(OBD_MD_FLCKSUM == (0x00100000ULL));
- CLASSERT(OBD_MD_FLQOS == (0x00200000ULL));
- CLASSERT(OBD_MD_FLCOOKIE == (0x00800000ULL));
- CLASSERT(OBD_MD_FLGROUP == (0x01000000ULL));
- CLASSERT(OBD_MD_FLFID == (0x02000000ULL));
- CLASSERT(OBD_MD_FLEPOCH == (0x04000000ULL));
- CLASSERT(OBD_MD_FLGRANT == (0x08000000ULL));
- CLASSERT(OBD_MD_FLDIREA == (0x10000000ULL));
- CLASSERT(OBD_MD_FLUSRQUOTA == (0x20000000ULL));
- CLASSERT(OBD_MD_FLGRPQUOTA == (0x40000000ULL));
- CLASSERT(OBD_MD_FLMODEASIZE == (0x80000000ULL));
+ CLASSERT(OBD_MD_FLID == (0x0000000000000001ULL));
+ CLASSERT(OBD_MD_FLATIME == (0x0000000000000002ULL));
+ CLASSERT(OBD_MD_FLMTIME == (0x0000000000000004ULL));
+ CLASSERT(OBD_MD_FLCTIME == (0x0000000000000008ULL));
+ CLASSERT(OBD_MD_FLSIZE == (0x0000000000000010ULL));
+ CLASSERT(OBD_MD_FLBLOCKS == (0x0000000000000020ULL));
+ CLASSERT(OBD_MD_FLBLKSZ == (0x0000000000000040ULL));
+ CLASSERT(OBD_MD_FLMODE == (0x0000000000000080ULL));
+ CLASSERT(OBD_MD_FLTYPE == (0x0000000000000100ULL));
+ CLASSERT(OBD_MD_FLUID == (0x0000000000000200ULL));
+ CLASSERT(OBD_MD_FLGID == (0x0000000000000400ULL));
+ CLASSERT(OBD_MD_FLFLAGS == (0x0000000000000800ULL));
+ CLASSERT(OBD_MD_FLNLINK == (0x0000000000002000ULL));
+ CLASSERT(OBD_MD_FLGENER == (0x0000000000004000ULL));
+ CLASSERT(OBD_MD_FLINLINE == (0x0000000000008000ULL));
+ CLASSERT(OBD_MD_FLRDEV == (0x0000000000010000ULL));
+ CLASSERT(OBD_MD_FLEASIZE == (0x0000000000020000ULL));
+ CLASSERT(OBD_MD_LINKNAME == (0x0000000000040000ULL));
+ CLASSERT(OBD_MD_FLHANDLE == (0x0000000000080000ULL));
+ CLASSERT(OBD_MD_FLCKSUM == (0x0000000000100000ULL));
+ CLASSERT(OBD_MD_FLQOS == (0x0000000000200000ULL));
+ CLASSERT(OBD_MD_FLCOOKIE == (0x0000000000800000ULL));
+ CLASSERT(OBD_MD_FLGROUP == (0x0000000001000000ULL));
+ CLASSERT(OBD_MD_FLFID == (0x0000000002000000ULL));
+ CLASSERT(OBD_MD_FLEPOCH == (0x0000000004000000ULL));
+ CLASSERT(OBD_MD_FLGRANT == (0x0000000008000000ULL));
+ CLASSERT(OBD_MD_FLDIREA == (0x0000000010000000ULL));
+ CLASSERT(OBD_MD_FLUSRQUOTA == (0x0000000020000000ULL));
+ CLASSERT(OBD_MD_FLGRPQUOTA == (0x0000000040000000ULL));
+ CLASSERT(OBD_MD_FLMODEASIZE == (0x0000000080000000ULL));
CLASSERT(OBD_MD_MDS == (0x0000000100000000ULL));
CLASSERT(OBD_MD_REINT == (0x0000000200000000ULL));
CLASSERT(OBD_MD_FLXATTR == (0x0000001000000000ULL));
}
+
+
+